21ab4e
From a5d7a8c92bceedd554b593950fc14c865fd4db7f Mon Sep 17 00:00:00 2001
21ab4e
From: Poornima G <pgurusid@redhat.com>
21ab4e
Date: Thu, 8 Dec 2016 16:08:40 +0530
21ab4e
Subject: [PATCH 360/361] Readdir-ahead : Honor readdir-optimise option of dht
21ab4e
21ab4e
mainline:
21ab4e
> BUG: 1401812
21ab4e
> Reviewed-on: https://review.gluster.org/16071
21ab4e
> Smoke: Gluster Build System <jenkins@build.gluster.org>
21ab4e
> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
21ab4e
> CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
21ab4e
> Reviewed-by: Raghavendra G <rgowdapp@redhat.com>
21ab4e
(cherry picked from commit 7c6538f6c8f9a015663b4fc57c640a7c451c87f7)
21ab4e
21ab4e
BUG: 1427096
21ab4e
Change-Id: I9c5e65b32e316e6a2fc7e1f5c79fce79386b78e2
21ab4e
Signed-off-by: Poornima G <pgurusid@redhat.com>
21ab4e
Reviewed-on: https://code.engineering.redhat.com/gerrit/101420
21ab4e
Tested-by: Milind Changire <mchangir@redhat.com>
21ab4e
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
21ab4e
---
21ab4e
 xlators/cluster/dht/src/dht-common.c                    | 13 +++++++++++++
21ab4e
 .../readdir-ahead/src/readdir-ahead-messages.h          |  3 ++-
21ab4e
 xlators/performance/readdir-ahead/src/readdir-ahead.c   | 17 +++++++++++++++++
21ab4e
 xlators/performance/readdir-ahead/src/readdir-ahead.h   |  1 +
21ab4e
 4 files changed, 33 insertions(+), 1 deletion(-)
21ab4e
21ab4e
diff --git a/xlators/cluster/dht/src/dht-common.c b/xlators/cluster/dht/src/dht-common.c
21ab4e
index 131a4b1..77d0e48 100644
21ab4e
--- a/xlators/cluster/dht/src/dht-common.c
21ab4e
+++ b/xlators/cluster/dht/src/dht-common.c
21ab4e
@@ -4857,6 +4857,7 @@ dht_opendir (call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd,
21ab4e
         dht_conf_t   *conf = NULL;
21ab4e
         int           op_errno = -1;
21ab4e
         int           i = -1;
21ab4e
+        int           ret = 0;
21ab4e
 
21ab4e
         VALIDATE_OR_GOTO (frame, err);
21ab4e
         VALIDATE_OR_GOTO (this, err);
21ab4e
@@ -4888,6 +4889,18 @@ dht_opendir (call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd,
21ab4e
         } else {
21ab4e
                 local->call_cnt = conf->local_subvols_cnt;
21ab4e
                 for (i = 0; i < conf->local_subvols_cnt; i++) {
21ab4e
+                        if (conf->readdir_optimize == _gf_true) {
21ab4e
+                                if (conf->local_subvols[i] != local->first_up_subvol)
21ab4e
+                                        ret = dict_set_int32 (local->xattr,
21ab4e
+                                                              GF_READDIR_SKIP_DIRS, 1);
21ab4e
+                                         if (ret)
21ab4e
+                                                 gf_msg (this->name, GF_LOG_ERROR, 0,
21ab4e
+                                                         DHT_MSG_DICT_SET_FAILED,
21ab4e
+                                                         "Failed to set dictionary"
21ab4e
+                                                         " value :key = %s, ret:%d",
21ab4e
+                                                         GF_READDIR_SKIP_DIRS, ret);
21ab4e
+
21ab4e
+                        }
21ab4e
                         STACK_WIND_COOKIE (frame, dht_fd_cbk,
21ab4e
                                            conf->local_subvols[i],
21ab4e
                                            conf->local_subvols[i],
21ab4e
diff --git a/xlators/performance/readdir-ahead/src/readdir-ahead-messages.h b/xlators/performance/readdir-ahead/src/readdir-ahead-messages.h
21ab4e
index 0e19348..0a21bac 100644
21ab4e
--- a/xlators/performance/readdir-ahead/src/readdir-ahead-messages.h
21ab4e
+++ b/xlators/performance/readdir-ahead/src/readdir-ahead-messages.h
21ab4e
@@ -40,7 +40,7 @@
21ab4e
  */
21ab4e
 
21ab4e
 #define GLFS_READDIR_AHEAD_BASE                   GLFS_MSGID_COMP_READDIR_AHEAD
21ab4e
-#define GLFS_READDIR_AHEAD_NUM_MESSAGES           5
21ab4e
+#define GLFS_READDIR_AHEAD_NUM_MESSAGES           6
21ab4e
 #define GLFS_MSGID_END          (GLFS_READDIR_AHEAD_BASE +\
21ab4e
         GLFS_READDIR_AHEAD_NUM_MESSAGES + 1)
21ab4e
 
21ab4e
@@ -97,6 +97,7 @@
21ab4e
 
21ab4e
 #define READDIR_AHEAD_MSG_OUT_OF_SEQUENCE        (GLFS_READDIR_AHEAD_BASE + 5)
21ab4e
 
21ab4e
+#define READDIR_AHEAD_MSG_DICT_OP_FAILED        (GLFS_READDIR_AHEAD_BASE + 6)
21ab4e
 
21ab4e
 /*------------*/
21ab4e
 #define glfs_msg_end_x GLFS_MSGID_END, "Invalid: End of messages"
21ab4e
diff --git a/xlators/performance/readdir-ahead/src/readdir-ahead.c b/xlators/performance/readdir-ahead/src/readdir-ahead.c
21ab4e
index dcbab53..17569c2 100644
21ab4e
--- a/xlators/performance/readdir-ahead/src/readdir-ahead.c
21ab4e
+++ b/xlators/performance/readdir-ahead/src/readdir-ahead.c
21ab4e
@@ -407,6 +407,7 @@ rda_fill_fd(call_frame_t *frame, xlator_t *this, fd_t *fd)
21ab4e
 	struct rda_fd_ctx *ctx;
21ab4e
 	off_t offset;
21ab4e
 	struct rda_priv *priv = this->private;
21ab4e
+        int ret = 0;
21ab4e
 
21ab4e
 	ctx = get_rda_fd_ctx(fd, this);
21ab4e
 	if (!ctx)
21ab4e
@@ -452,6 +453,15 @@ rda_fill_fd(call_frame_t *frame, xlator_t *this, fd_t *fd)
21ab4e
 	}
21ab4e
 
21ab4e
 	local->offset = offset;
21ab4e
+        if (local->skip_dir) {
21ab4e
+                ret = dict_set_int32 (ctx->xattrs, GF_READDIR_SKIP_DIRS, 1);
21ab4e
+                if (ret < 0) {
21ab4e
+                        gf_msg (this->name, GF_LOG_ERROR,
21ab4e
+                                0, READDIR_AHEAD_MSG_DICT_OP_FAILED,
21ab4e
+                                "Dict set of key:%s failed with :%d",
21ab4e
+                                GF_READDIR_SKIP_DIRS, ret);
21ab4e
+                }
21ab4e
+        }
21ab4e
 
21ab4e
 	UNLOCK(&ctx->lock);
21ab4e
 
21ab4e
@@ -558,6 +568,13 @@ rda_opendir(call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd,
21ab4e
                 }
21ab4e
 
21ab4e
                 local->xattrs = xdata_from_req;
21ab4e
+                ret = dict_get_int32 (xdata, GF_READDIR_SKIP_DIRS, &local->skip_dir);
21ab4e
+                if (ret < 0) {
21ab4e
+                        gf_msg (this->name, GF_LOG_ERROR,
21ab4e
+                                0, READDIR_AHEAD_MSG_DICT_OP_FAILED,
21ab4e
+                                "Dict get of key:%s failed with :%d",
21ab4e
+                                GF_READDIR_SKIP_DIRS, ret);
21ab4e
+                }
21ab4e
                 frame->local = local;
21ab4e
         }
21ab4e
 
21ab4e
diff --git a/xlators/performance/readdir-ahead/src/readdir-ahead.h b/xlators/performance/readdir-ahead/src/readdir-ahead.h
21ab4e
index 6b65a62..9f9df05 100644
21ab4e
--- a/xlators/performance/readdir-ahead/src/readdir-ahead.h
21ab4e
+++ b/xlators/performance/readdir-ahead/src/readdir-ahead.h
21ab4e
@@ -37,6 +37,7 @@ struct rda_local {
21ab4e
 	fd_t *fd;
21ab4e
 	off_t offset;
21ab4e
         dict_t *xattrs;      /* md-cache keys to be sent in readdirp() */
21ab4e
+        int32_t skip_dir;
21ab4e
 };
21ab4e
 
21ab4e
 struct rda_priv {
21ab4e
-- 
21ab4e
1.8.3.1
21ab4e