12a457
From 1d3d7b556a3624bafb1f0d9d621eb7aa559a1bf0 Mon Sep 17 00:00:00 2001
12a457
From: Jeff Darcy <jdarcy@redhat.com>
12a457
Date: Thu, 17 Mar 2016 13:33:34 -0400
12a457
Subject: [PATCH 33/80] dht: report constant directory size
12a457
12a457
Directory size is meaningless.  Every filesystem has its own
12a457
unpredictable way of increasing or decreasing it, based on internal data
12a457
structures and even transient conditions.  Some filesystems (e.g. ext4)
12a457
never decrease it at all.  Others (e.g. btrfs) don't even report it.
12a457
Very few programs look at it, and those that do are broken.
12a457
Unfortunately, one such program is GNU tar, which will complain when it
12a457
sees different values because at different times we got the value from
12a457
different DHT subvolumes.  To avoid such problems, just report a
12a457
constant value.
12a457
12a457
Change-Id: Id64ce917c75b5f7ff50cb55b6e997f3b3556e7e3
12a457
BUG: 1298724
12a457
Original-author: Shyam <srangana@redhat.com>
12a457
Signed-off-by: Jeff Darcy <jdarcy@redhat.com>
12a457
Signed-off-by: N Balachandran <nbalacha@redhat.com>
12a457
Reviewed-on: http://review.gluster.org/13770
12a457
Smoke: Gluster Build System <jenkins@build.gluster.com>
12a457
NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
12a457
CentOS-regression: Gluster Build System <jenkins@build.gluster.com>
12a457
Reviewed-by: Shyamsundar Ranganathan <srangana@redhat.com>
12a457
Reviewed-by: Vijay Bellur <vbellur@redhat.com>
12a457
Reviewed-on: https://code.engineering.redhat.com/gerrit/70837
12a457
Reviewed-by: Raghavendra Gowdappa <rgowdapp@redhat.com>
12a457
Tested-by: Raghavendra Gowdappa <rgowdapp@redhat.com>
12a457
---
12a457
 xlators/cluster/dht/src/dht-common.c |   63 +++++++++++++++++++++++++++++++++-
12a457
 xlators/cluster/dht/src/dht-common.h |    7 ++++
12a457
 xlators/cluster/dht/src/dht-helper.c |    6 +++
12a457
 xlators/cluster/dht/src/dht-rename.c |    6 +++
12a457
 4 files changed, 81 insertions(+), 1 deletions(-)
12a457
12a457
diff --git a/xlators/cluster/dht/src/dht-common.c b/xlators/cluster/dht/src/dht-common.c
12a457
index fc7b272..7755eba 100644
12a457
--- a/xlators/cluster/dht/src/dht-common.c
12a457
+++ b/xlators/cluster/dht/src/dht-common.c
12a457
@@ -31,6 +31,8 @@
12a457
 
12a457
 int run_defrag = 0;
12a457
 
12a457
+
12a457
+
12a457
 int dht_link2 (xlator_t *this, xlator_t *dst_node, call_frame_t *frame,
12a457
                int ret);
12a457
 
12a457
@@ -42,6 +44,21 @@ int
12a457
 dht_setxattr2 (xlator_t *this, xlator_t *subvol, call_frame_t *frame,
12a457
                int ret);
12a457
 
12a457
+
12a457
+/* Sets the blocks and size values to fixed values. This is to be called
12a457
+ * only for dirs. The caller is responsible for checking the type
12a457
+ */
12a457
+int32_t dht_set_fixed_dir_stat (struct iatt *stat)
12a457
+{
12a457
+        if (stat) {
12a457
+                stat->ia_blocks = DHT_DIR_STAT_BLOCKS;
12a457
+                stat->ia_size = DHT_DIR_STAT_SIZE;
12a457
+                return 0;
12a457
+        }
12a457
+        return -1;
12a457
+}
12a457
+
12a457
+
12a457
 int
12a457
 dht_aggregate_quota_xattr (dict_t *dst, char *key, data_t *value)
12a457
 {
12a457
@@ -210,6 +227,7 @@ dht_lookup_selfheal_cbk (call_frame_t *frame, void *cookie,
12a457
         }
12a457
 
12a457
         DHT_STRIP_PHASE1_FLAGS (&local->stbuf);
12a457
+        dht_set_fixed_dir_stat (&local->postparent);
12a457
 
12a457
         DHT_STACK_UNWIND (lookup, frame, ret, local->op_errno, local->inode,
12a457
                           &local->stbuf, local->xattr, &local->postparent);
12a457
@@ -369,6 +387,7 @@ cleanup:
12a457
 
12a457
         }
12a457
 done:
12a457
+        dht_set_fixed_dir_stat (&local->postparent);
12a457
         DHT_STACK_UNWIND (lookup, main_frame, local->op_ret, local->op_errno,
12a457
                           local->inode, &local->stbuf, local->xattr,
12a457
                           &local->postparent);
12a457
@@ -719,6 +738,7 @@ unlock:
12a457
                 }
12a457
 
12a457
                 DHT_STRIP_PHASE1_FLAGS (&local->stbuf);
12a457
+                dht_set_fixed_dir_stat (&local->postparent);
12a457
                 DHT_STACK_UNWIND (lookup, frame, local->op_ret, local->op_errno,
12a457
                                   local->inode, &local->stbuf, local->xattr,
12a457
                                   &local->postparent);
12a457
@@ -976,6 +996,7 @@ cont:
12a457
                 }
12a457
 
12a457
                 DHT_STRIP_PHASE1_FLAGS (&local->stbuf);
12a457
+                dht_set_fixed_dir_stat (&local->postparent);
12a457
                 DHT_STACK_UNWIND (lookup, frame, local->op_ret, local->op_errno,
12a457
                                   local->inode, &local->stbuf, local->xattr,
12a457
                                   &local->postparent);
12a457
@@ -1046,6 +1067,8 @@ unwind:
12a457
                 dht_linkfile_attr_heal (frame, this);
12a457
 
12a457
 
12a457
+        dht_set_fixed_dir_stat (&local->postparent);
12a457
+
12a457
         DHT_STRIP_PHASE1_FLAGS (&local->stbuf);
12a457
         DHT_STACK_UNWIND (lookup, frame, local->op_ret, local->op_errno,
12a457
                           local->inode, &local->stbuf, local->xattr,
12a457
@@ -1511,6 +1534,7 @@ preset_layout:
12a457
                 }
12a457
 
12a457
                 DHT_STRIP_PHASE1_FLAGS (&local->stbuf);
12a457
+                dht_set_fixed_dir_stat (&local->postparent);
12a457
                 DHT_STACK_UNWIND (lookup, frame, local->op_ret,
12a457
                                   local->op_errno, local->inode,
12a457
                                   &local->stbuf, local->xattr,
12a457
@@ -1547,6 +1571,7 @@ preset_layout:
12a457
                 }
12a457
 
12a457
                 DHT_STRIP_PHASE1_FLAGS (&local->stbuf);
12a457
+                dht_set_fixed_dir_stat (&local->postparent);
12a457
                 DHT_STACK_UNWIND (lookup, frame, local->op_ret,
12a457
                                   local->op_errno, local->inode,
12a457
                                   &local->stbuf, local->xattr,
12a457
@@ -1567,6 +1592,7 @@ preset_layout:
12a457
 
12a457
 unwind_hashed_and_cached:
12a457
         DHT_STRIP_PHASE1_FLAGS (&local->stbuf);
12a457
+        dht_set_fixed_dir_stat (&local->postparent);
12a457
         DHT_STACK_UNWIND (lookup, frame, local->op_ret, local->op_errno,
12a457
                           local->loc.inode, &local->stbuf, local->xattr,
12a457
                           &local->postparent);
12a457
@@ -1912,6 +1938,7 @@ dht_lookup_linkfile_cbk (call_frame_t *frame, void *cookie,
12a457
 
12a457
 unwind:
12a457
         DHT_STRIP_PHASE1_FLAGS (stbuf);
12a457
+        dht_set_fixed_dir_stat (postparent);
12a457
         DHT_STACK_UNWIND (lookup, frame, op_ret, op_errno, inode, stbuf, xattr,
12a457
                           postparent);
12a457
 
12a457
@@ -2158,6 +2185,7 @@ out:
12a457
         }
12a457
 
12a457
         DHT_STRIP_PHASE1_FLAGS (stbuf);
12a457
+        dht_set_fixed_dir_stat (postparent);
12a457
         DHT_STACK_UNWIND (lookup, frame, op_ret, op_errno, inode, stbuf, xattr,
12a457
                           postparent);
12a457
 err:
12a457
@@ -2473,7 +2501,8 @@ dht_unlink_linkfile_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
12a457
 unlock:
12a457
         UNLOCK (&frame->lock);
12a457
 
12a457
-
12a457
+        dht_set_fixed_dir_stat (&local->preparent);
12a457
+        dht_set_fixed_dir_stat (&local->postparent);
12a457
         DHT_STACK_UNWIND (unlink, frame, local->op_ret, local->op_errno,
12a457
                           &local->preparent, &local->postparent, xdata);
12a457
 
12a457
@@ -2539,6 +2568,8 @@ unlock:
12a457
                 }
12a457
         }
12a457
 
12a457
+        dht_set_fixed_dir_stat (&local->preparent);
12a457
+        dht_set_fixed_dir_stat (&local->postparent);
12a457
         DHT_STACK_UNWIND (unlink, frame, local->op_ret, local->op_errno,
12a457
                           &local->preparent, &local->postparent, xdata);
12a457
 
12a457
@@ -4712,6 +4743,8 @@ list:
12a457
                    currently possible only for non-directories, so for
12a457
                    directories don't set entry inodes */
12a457
                 if (IA_ISDIR(entry->d_stat.ia_type)) {
12a457
+                        entry->d_stat.ia_blocks = DHT_DIR_STAT_BLOCKS;
12a457
+                        entry->d_stat.ia_size = DHT_DIR_STAT_SIZE;
12a457
                         if (orig_entry->inode) {
12a457
                                 dht_inode_ctx_time_update (orig_entry->inode,
12a457
                                                            this, &entry->d_stat,
12a457
@@ -5164,6 +5197,8 @@ out:
12a457
          * See dht_iatt_merge for reference.
12a457
          */
12a457
         DHT_STRIP_PHASE1_FLAGS (stbuf);
12a457
+        dht_set_fixed_dir_stat (postparent);
12a457
+        dht_set_fixed_dir_stat (preparent);
12a457
 
12a457
         if (local && local->lock.locks) {
12a457
                 /* store op_errno for failure case*/
12a457
@@ -5774,6 +5809,8 @@ dht_link_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
12a457
 out:
12a457
         DHT_STRIP_PHASE1_FLAGS (stbuf);
12a457
 
12a457
+        dht_set_fixed_dir_stat (preparent);
12a457
+        dht_set_fixed_dir_stat (postparent);
12a457
         DHT_STACK_UNWIND (link, frame, op_ret, op_errno, inode, stbuf,
12a457
                           preparent, postparent, NULL);
12a457
 
12a457
@@ -5798,6 +5835,9 @@ dht_link2 (xlator_t *this, xlator_t *subvol, call_frame_t *frame, int ret)
12a457
                  * pass on the original mode bits so the higher DHT layer
12a457
                  * can handle this.
12a457
                  */
12a457
+                dht_set_fixed_dir_stat (&local->preparent);
12a457
+                dht_set_fixed_dir_stat (&local->postparent);
12a457
+
12a457
                 DHT_STACK_UNWIND (link, frame, local->op_ret, op_errno,
12a457
                                   local->inode,
12a457
                                   &local->stbuf, &local->preparent,
12a457
@@ -5815,6 +5855,8 @@ dht_link2 (xlator_t *this, xlator_t *subvol, call_frame_t *frame, int ret)
12a457
          * migrating subvol, which could be the new hashed subvol */
12a457
         if (local->link_subvol == subvol) {
12a457
                 DHT_STRIP_PHASE1_FLAGS (&local->stbuf);
12a457
+                dht_set_fixed_dir_stat (&local->preparent);
12a457
+                dht_set_fixed_dir_stat (&local->postparent);
12a457
                 DHT_STACK_UNWIND (link, frame, 0, 0, local->inode,
12a457
                                   &local->stbuf, &local->preparent,
12a457
                                   &local->postparent, NULL);
12a457
@@ -5858,6 +5900,8 @@ dht_link_linkfile_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
12a457
 
12a457
 err:
12a457
         DHT_STRIP_PHASE1_FLAGS (stbuf);
12a457
+        dht_set_fixed_dir_stat (preparent);
12a457
+        dht_set_fixed_dir_stat (postparent);
12a457
         DHT_STACK_UNWIND (link, frame, op_ret, op_errno, inode, stbuf, preparent,
12a457
                           postparent, NULL);
12a457
 
12a457
@@ -5980,6 +6024,8 @@ dht_create_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
12a457
 out:
12a457
 
12a457
         DHT_STRIP_PHASE1_FLAGS (stbuf);
12a457
+        dht_set_fixed_dir_stat (preparent);
12a457
+        dht_set_fixed_dir_stat (postparent);
12a457
 
12a457
         if (local && local->lock.locks) {
12a457
                 /* store op_errno for failure case*/
12a457
@@ -6491,6 +6537,9 @@ dht_mkdir_selfheal_cbk (call_frame_t *frame, void *cookie,
12a457
         local = frame->local;
12a457
         layout = local->selfheal.layout;
12a457
 
12a457
+        dht_set_fixed_dir_stat (&local->preparent);
12a457
+        dht_set_fixed_dir_stat (&local->postparent);
12a457
+
12a457
         if (op_ret == 0) {
12a457
                 dht_layout_set (this, local->inode, layout);
12a457
 
12a457
@@ -6739,6 +6788,9 @@ dht_rmdir_selfheal_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
12a457
 
12a457
         local = frame->local;
12a457
 
12a457
+        dht_set_fixed_dir_stat (&local->preparent);
12a457
+        dht_set_fixed_dir_stat (&local->postparent);
12a457
+
12a457
         DHT_STACK_UNWIND (rmdir, frame, local->op_ret, local->op_errno,
12a457
                           &local->preparent, &local->postparent, NULL);
12a457
 
12a457
@@ -6816,6 +6868,9 @@ unlock:
12a457
                                                            1);
12a457
                         }
12a457
 
12a457
+                        dht_set_fixed_dir_stat (&local->preparent);
12a457
+                        dht_set_fixed_dir_stat (&local->postparent);
12a457
+
12a457
                         DHT_STACK_UNWIND (rmdir, frame, local->op_ret,
12a457
                                           local->op_errno, &local->preparent,
12a457
                                           &local->postparent, NULL);
12a457
@@ -6918,6 +6973,9 @@ unlock:
12a457
 
12a457
                         }
12a457
 
12a457
+                        dht_set_fixed_dir_stat (&local->preparent);
12a457
+                        dht_set_fixed_dir_stat (&local->postparent);
12a457
+
12a457
                         DHT_STACK_UNWIND (rmdir, frame, local->op_ret,
12a457
                                           local->op_errno, &local->preparent,
12a457
                                           &local->postparent, NULL);
12a457
@@ -6985,6 +7043,9 @@ dht_rmdir_do (call_frame_t *frame, xlator_t *this)
12a457
         return 0;
12a457
 
12a457
 err:
12a457
+        dht_set_fixed_dir_stat (&local->preparent);
12a457
+        dht_set_fixed_dir_stat (&local->postparent);
12a457
+
12a457
         DHT_STACK_UNWIND (rmdir, frame, local->op_ret, local->op_errno,
12a457
                           &local->preparent, &local->postparent, NULL);
12a457
         return 0;
12a457
diff --git a/xlators/cluster/dht/src/dht-common.h b/xlators/cluster/dht/src/dht-common.h
12a457
index 31b8b68..53d1489 100644
12a457
--- a/xlators/cluster/dht/src/dht-common.h
12a457
+++ b/xlators/cluster/dht/src/dht-common.h
12a457
@@ -36,6 +36,9 @@
12a457
 #define DHT_LAYOUT_HASH_INVALID     1
12a457
 #define TIERING_MIGRATION_KEY       "tiering.migration"
12a457
 
12a457
+#define DHT_DIR_STAT_BLOCKS          8
12a457
+#define DHT_DIR_STAT_SIZE            4096
12a457
+
12a457
 #include <fnmatch.h>
12a457
 
12a457
 typedef int (*dht_selfheal_dir_cbk_t) (call_frame_t *frame, void *cookie,
12a457
@@ -1172,4 +1175,8 @@ dht_fd_ctx_destroy (xlator_t *this, fd_t *fd);
12a457
 
12a457
 int32_t
12a457
 dht_release (xlator_t *this, fd_t *fd);
12a457
+
12a457
+
12a457
+int32_t
12a457
+dht_set_fixed_dir_stat (struct iatt *stat);
12a457
 #endif/* _DHT_H */
12a457
diff --git a/xlators/cluster/dht/src/dht-helper.c b/xlators/cluster/dht/src/dht-helper.c
12a457
index d980a4d..df31cdb 100644
12a457
--- a/xlators/cluster/dht/src/dht-helper.c
12a457
+++ b/xlators/cluster/dht/src/dht-helper.c
12a457
@@ -920,6 +920,10 @@ dht_iatt_merge (xlator_t *this, struct iatt *to,
12a457
         to->ia_blksize  = from->ia_blksize;
12a457
         to->ia_blocks  += from->ia_blocks;
12a457
 
12a457
+        if (IA_ISDIR (from->ia_type)) {
12a457
+                to->ia_blocks = DHT_DIR_STAT_BLOCKS;
12a457
+                to->ia_size = DHT_DIR_STAT_SIZE;
12a457
+        }
12a457
         set_if_greater (to->ia_uid, from->ia_uid);
12a457
         set_if_greater (to->ia_gid, from->ia_gid);
12a457
 
12a457
@@ -2259,6 +2263,8 @@ dht_heal_full_path_done (int op_ret, call_frame_t *heal_frame, void *data)
12a457
         main_frame = local->main_frame;
12a457
         local->main_frame = NULL;
12a457
 
12a457
+        dht_set_fixed_dir_stat (&local->postparent);
12a457
+
12a457
         DHT_STACK_UNWIND (lookup, main_frame, 0, 0,
12a457
                           local->inode, &local->stbuf, local->xattr,
12a457
                           &local->postparent);
12a457
diff --git a/xlators/cluster/dht/src/dht-rename.c b/xlators/cluster/dht/src/dht-rename.c
12a457
index dc879b0..79b8706 100644
12a457
--- a/xlators/cluster/dht/src/dht-rename.c
12a457
+++ b/xlators/cluster/dht/src/dht-rename.c
12a457
@@ -162,6 +162,7 @@ unwind:
12a457
         WIPE (&local->postparent);
12a457
 
12a457
         DHT_STRIP_PHASE1_FLAGS (&local->stbuf);
12a457
+
12a457
         DHT_STACK_UNWIND (rename, frame, local->op_ret, local->op_errno,
12a457
                           &local->stbuf, &local->preoldparent,
12a457
                           &local->postoldparent,
12a457
@@ -426,6 +427,11 @@ dht_rename_unlock_cbk (call_frame_t *frame, void *cookie,
12a457
         local = frame->local;
12a457
 
12a457
         DHT_STRIP_PHASE1_FLAGS (&local->stbuf);
12a457
+        dht_set_fixed_dir_stat (&local->preoldparent);
12a457
+        dht_set_fixed_dir_stat (&local->postoldparent);
12a457
+        dht_set_fixed_dir_stat (&local->preparent);
12a457
+        dht_set_fixed_dir_stat (&local->postparent);
12a457
+
12a457
         DHT_STACK_UNWIND (rename, frame, local->op_ret, local->op_errno,
12a457
                           &local->stbuf, &local->preoldparent,
12a457
                           &local->postoldparent, &local->preparent,
12a457
-- 
12a457
1.7.1
12a457