From: Xiubo Li Date: Wed, 31 Aug 2022 07:27:01 +0000 (+0800) Subject: client: fix incorrectly showing the .snap size for stat X-Git-Tag: v16.2.11~230^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=de769a30af47dff053b960c350fbf8081f43a1e5;p=ceph.git client: fix incorrectly showing the .snap size for stat We should set the 'stat->size' to the real number of snapshots for snapdirs. Fixes: https://tracker.ceph.com/issues/57344 Signed-off-by: Xiubo Li (cherry picked from commit aa918d2e383eb9da2f6f837d731cc18bbad21e44) --- diff --git a/src/client/Client.cc b/src/client/Client.cc index a08fd41be1ce..99c46f8ee99b 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -8205,10 +8205,17 @@ int Client::fill_stat(Inode *in, struct stat *st, frag_info_t *dirstat, nest_inf stat_set_mtime_sec(st, in->mtime.sec()); stat_set_mtime_nsec(st, in->mtime.nsec()); if (in->is_dir()) { - if (cct->_conf->client_dirsize_rbytes) + if (cct->_conf->client_dirsize_rbytes) { st->st_size = in->rstat.rbytes; - else + } else if (in->snapid == CEPH_SNAPDIR) { + SnapRealm *realm = get_snap_realm_maybe(in->vino().ino); + if (realm) { + st->st_size = realm->my_snaps.size(); + put_snap_realm(realm); + } + } else { st->st_size = in->dirstat.size(); + } // The Windows "stat" structure provides just a subset of the fields that are // available on Linux. #ifndef _WIN32 @@ -8290,10 +8297,17 @@ void Client::fill_statx(Inode *in, unsigned int mask, struct ceph_statx *stx) in->mtime.to_timespec(&stx->stx_mtime); if (in->is_dir()) { - if (cct->_conf->client_dirsize_rbytes) + if (cct->_conf->client_dirsize_rbytes) { stx->stx_size = in->rstat.rbytes; - else + } else if (in->snapid == CEPH_SNAPDIR) { + SnapRealm *realm = get_snap_realm_maybe(in->vino().ino); + if (realm) { + stx->stx_size = realm->my_snaps.size(); + put_snap_realm(realm); + } + } else { stx->stx_size = in->dirstat.size(); + } stx->stx_blocks = 1; } else { stx->stx_size = in->size;