]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
client: fix incorrectly showing the .snap size for stat 48413/head
authorXiubo Li <xiubli@redhat.com>
Wed, 31 Aug 2022 07:27:01 +0000 (15:27 +0800)
committerVenky Shankar <vshankar@redhat.com>
Mon, 10 Oct 2022 09:20:45 +0000 (14:50 +0530)
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 <xiubli@redhat.com>
(cherry picked from commit aa918d2e383eb9da2f6f837d731cc18bbad21e44)

src/client/Client.cc

index a08fd41be1cef297c2a4a69da137f59738f8d1dc..99c46f8ee99b9cbaa291d9712eb85a0348be859d 100644 (file)
@@ -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;