Blob Blame History Raw
From a5d7a8c92bceedd554b593950fc14c865fd4db7f Mon Sep 17 00:00:00 2001
From: Poornima G <pgurusid@redhat.com>
Date: Thu, 8 Dec 2016 16:08:40 +0530
Subject: [PATCH 360/361] Readdir-ahead : Honor readdir-optimise option of dht

mainline:
> BUG: 1401812
> Reviewed-on: https://review.gluster.org/16071
> Smoke: Gluster Build System <jenkins@build.gluster.org>
> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
> CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
> Reviewed-by: Raghavendra G <rgowdapp@redhat.com>
(cherry picked from commit 7c6538f6c8f9a015663b4fc57c640a7c451c87f7)

BUG: 1427096
Change-Id: I9c5e65b32e316e6a2fc7e1f5c79fce79386b78e2
Signed-off-by: Poornima G <pgurusid@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/101420
Tested-by: Milind Changire <mchangir@redhat.com>
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
---
 xlators/cluster/dht/src/dht-common.c                    | 13 +++++++++++++
 .../readdir-ahead/src/readdir-ahead-messages.h          |  3 ++-
 xlators/performance/readdir-ahead/src/readdir-ahead.c   | 17 +++++++++++++++++
 xlators/performance/readdir-ahead/src/readdir-ahead.h   |  1 +
 4 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/xlators/cluster/dht/src/dht-common.c b/xlators/cluster/dht/src/dht-common.c
index 131a4b1..77d0e48 100644
--- a/xlators/cluster/dht/src/dht-common.c
+++ b/xlators/cluster/dht/src/dht-common.c
@@ -4857,6 +4857,7 @@ dht_opendir (call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd,
         dht_conf_t   *conf = NULL;
         int           op_errno = -1;
         int           i = -1;
+        int           ret = 0;
 
         VALIDATE_OR_GOTO (frame, err);
         VALIDATE_OR_GOTO (this, err);
@@ -4888,6 +4889,18 @@ dht_opendir (call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd,
         } else {
                 local->call_cnt = conf->local_subvols_cnt;
                 for (i = 0; i < conf->local_subvols_cnt; i++) {
+                        if (conf->readdir_optimize == _gf_true) {
+                                if (conf->local_subvols[i] != local->first_up_subvol)
+                                        ret = dict_set_int32 (local->xattr,
+                                                              GF_READDIR_SKIP_DIRS, 1);
+                                         if (ret)
+                                                 gf_msg (this->name, GF_LOG_ERROR, 0,
+                                                         DHT_MSG_DICT_SET_FAILED,
+                                                         "Failed to set dictionary"
+                                                         " value :key = %s, ret:%d",
+                                                         GF_READDIR_SKIP_DIRS, ret);
+
+                        }
                         STACK_WIND_COOKIE (frame, dht_fd_cbk,
                                            conf->local_subvols[i],
                                            conf->local_subvols[i],
diff --git a/xlators/performance/readdir-ahead/src/readdir-ahead-messages.h b/xlators/performance/readdir-ahead/src/readdir-ahead-messages.h
index 0e19348..0a21bac 100644
--- a/xlators/performance/readdir-ahead/src/readdir-ahead-messages.h
+++ b/xlators/performance/readdir-ahead/src/readdir-ahead-messages.h
@@ -40,7 +40,7 @@
  */
 
 #define GLFS_READDIR_AHEAD_BASE                   GLFS_MSGID_COMP_READDIR_AHEAD
-#define GLFS_READDIR_AHEAD_NUM_MESSAGES           5
+#define GLFS_READDIR_AHEAD_NUM_MESSAGES           6
 #define GLFS_MSGID_END          (GLFS_READDIR_AHEAD_BASE +\
         GLFS_READDIR_AHEAD_NUM_MESSAGES + 1)
 
@@ -97,6 +97,7 @@
 
 #define READDIR_AHEAD_MSG_OUT_OF_SEQUENCE        (GLFS_READDIR_AHEAD_BASE + 5)
 
+#define READDIR_AHEAD_MSG_DICT_OP_FAILED        (GLFS_READDIR_AHEAD_BASE + 6)
 
 /*------------*/
 #define glfs_msg_end_x GLFS_MSGID_END, "Invalid: End of messages"
diff --git a/xlators/performance/readdir-ahead/src/readdir-ahead.c b/xlators/performance/readdir-ahead/src/readdir-ahead.c
index dcbab53..17569c2 100644
--- a/xlators/performance/readdir-ahead/src/readdir-ahead.c
+++ b/xlators/performance/readdir-ahead/src/readdir-ahead.c
@@ -407,6 +407,7 @@ rda_fill_fd(call_frame_t *frame, xlator_t *this, fd_t *fd)
 	struct rda_fd_ctx *ctx;
 	off_t offset;
 	struct rda_priv *priv = this->private;
+        int ret = 0;
 
 	ctx = get_rda_fd_ctx(fd, this);
 	if (!ctx)
@@ -452,6 +453,15 @@ rda_fill_fd(call_frame_t *frame, xlator_t *this, fd_t *fd)
 	}
 
 	local->offset = offset;
+        if (local->skip_dir) {
+                ret = dict_set_int32 (ctx->xattrs, GF_READDIR_SKIP_DIRS, 1);
+                if (ret < 0) {
+                        gf_msg (this->name, GF_LOG_ERROR,
+                                0, READDIR_AHEAD_MSG_DICT_OP_FAILED,
+                                "Dict set of key:%s failed with :%d",
+                                GF_READDIR_SKIP_DIRS, ret);
+                }
+        }
 
 	UNLOCK(&ctx->lock);
 
@@ -558,6 +568,13 @@ rda_opendir(call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd,
                 }
 
                 local->xattrs = xdata_from_req;
+                ret = dict_get_int32 (xdata, GF_READDIR_SKIP_DIRS, &local->skip_dir);
+                if (ret < 0) {
+                        gf_msg (this->name, GF_LOG_ERROR,
+                                0, READDIR_AHEAD_MSG_DICT_OP_FAILED,
+                                "Dict get of key:%s failed with :%d",
+                                GF_READDIR_SKIP_DIRS, ret);
+                }
                 frame->local = local;
         }
 
diff --git a/xlators/performance/readdir-ahead/src/readdir-ahead.h b/xlators/performance/readdir-ahead/src/readdir-ahead.h
index 6b65a62..9f9df05 100644
--- a/xlators/performance/readdir-ahead/src/readdir-ahead.h
+++ b/xlators/performance/readdir-ahead/src/readdir-ahead.h
@@ -37,6 +37,7 @@ struct rda_local {
 	fd_t *fd;
 	off_t offset;
         dict_t *xattrs;      /* md-cache keys to be sent in readdirp() */
+        int32_t skip_dir;
 };
 
 struct rda_priv {
-- 
1.8.3.1