12a457
From 73b2f3f9cdee6940caa861d489c9cd8d923e12f2 Mon Sep 17 00:00:00 2001
12a457
From: Pranith Kumar K <pkarampu@redhat.com>
12a457
Date: Thu, 25 Feb 2016 18:45:20 +0530
12a457
Subject: [PATCH 70/80] features/index: Get gfid type in readdir
12a457
12a457
 >Change-Id: I2a6174e1af70a94a52b0b735fd8504800a7ea173
12a457
 >BUG: 1313135
12a457
 >Signed-off-by: Pranith Kumar K <pkarampu@redhat.com>
12a457
 >Reviewed-on: http://review.gluster.org/13553
12a457
 >Reviewed-by: Krutika Dhananjay <kdhananj@redhat.com>
12a457
 >Smoke: Gluster Build System <jenkins@build.gluster.com>
12a457
 >NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
12a457
 >Reviewed-by: Anuradha Talur <atalur@redhat.com>
12a457
 >CentOS-regression: Gluster Build System <jenkins@build.gluster.com>
12a457
 >(cherry picked from commit 459d0a5e173f9d9f597aec89f81e5377425eb8fb)
12a457
12a457
 >Change-Id: I3384906201129d3e03a56bc4b071302028f6953b
12a457
 >BUG: 1322516
12a457
 >Signed-off-by: Pranith Kumar K <pkarampu@redhat.com>
12a457
 >Reviewed-on: http://review.gluster.org/13858
12a457
 >Smoke: Gluster Build System <jenkins@build.gluster.com>
12a457
 >CentOS-regression: Gluster Build System <jenkins@build.gluster.com>
12a457
 >NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
12a457
 >Reviewed-by: Anuradha Talur <atalur@redhat.com>
12a457
12a457
BUG: 1314724
12a457
Change-Id: Ia9e4e9f02ef65f67677f52940b0dccb7e228807b
12a457
Signed-off-by: Pranith Kumar K <pkarampu@redhat.com>
12a457
Reviewed-on: https://code.engineering.redhat.com/gerrit/72368
12a457
---
12a457
 xlators/features/index/src/index.c |   47 +++++++++++++++++++++++++++++++++++-
12a457
 1 files changed, 46 insertions(+), 1 deletions(-)
12a457
12a457
diff --git a/xlators/features/index/src/index.c b/xlators/features/index/src/index.c
12a457
index 18df622..84c22c0 100644
12a457
--- a/xlators/features/index/src/index.c
12a457
+++ b/xlators/features/index/src/index.c
12a457
@@ -16,10 +16,16 @@
12a457
 #include "options.h"
12a457
 #include "glusterfs3-xdr.h"
12a457
 #include "syscall.h"
12a457
+#include "syncop.h"
12a457
 
12a457
 #define XATTROP_SUBDIR "xattrop"
12a457
 #define DIRTY_SUBDIR "dirty"
12a457
 
12a457
+struct index_syncop_args {
12a457
+        inode_t *parent;
12a457
+        gf_dirent_t *entries;
12a457
+};
12a457
+
12a457
 call_stub_t *
12a457
 __index_dequeue (struct list_head *callstubs)
12a457
 {
12a457
@@ -1181,6 +1187,38 @@ done:
12a457
         return 0;
12a457
 }
12a457
 
12a457
+int
12a457
+index_get_gfid_type (void *opaque)
12a457
+{
12a457
+        gf_dirent_t              *entry = NULL;
12a457
+        inode_t                  *inode = NULL;
12a457
+        xlator_t                 *this  = THIS;
12a457
+        struct index_syncop_args *args  = opaque;
12a457
+        loc_t                    loc    = {0};
12a457
+        struct iatt              iatt   = {0};
12a457
+        int                      ret    = 0;
12a457
+
12a457
+        list_for_each_entry (entry, &args->entries->list, list) {
12a457
+                loc_wipe (&loc;;
12a457
+                gf_uuid_parse (entry->d_name, loc.gfid);
12a457
+                entry->d_type = IA_INVAL;
12a457
+                loc.inode = inode_find (args->parent->table, loc.gfid);
12a457
+                if (loc.inode) {
12a457
+                        entry->d_type = loc.inode->ia_type;
12a457
+                        continue;
12a457
+                }
12a457
+                loc.inode = inode_new (args->parent->table);
12a457
+                if (!loc.inode)
12a457
+                        continue;
12a457
+                ret = syncop_lookup (FIRST_CHILD (this), &loc, &iatt, 0, 0, 0);
12a457
+                if (ret == 0)
12a457
+                        entry->d_type = iatt.ia_type;
12a457
+        }
12a457
+        loc_wipe (&loc;;
12a457
+
12a457
+        return 0;
12a457
+}
12a457
+
12a457
 int32_t
12a457
 index_readdir_wrapper (call_frame_t *frame, xlator_t *this,
12a457
                        fd_t *fd, size_t size, off_t off, dict_t *xdata)
12a457
@@ -1192,6 +1230,7 @@ index_readdir_wrapper (call_frame_t *frame, xlator_t *this,
12a457
         int32_t               op_errno       = 0;
12a457
         int                   count          = 0;
12a457
         gf_dirent_t           entries;
12a457
+        struct index_syncop_args args = {0};
12a457
 
12a457
         INIT_LIST_HEAD (&entries.list);
12a457
 
12a457
@@ -1217,8 +1256,14 @@ index_readdir_wrapper (call_frame_t *frame, xlator_t *this,
12a457
         /* pick ENOENT to indicate EOF */
12a457
         op_errno = errno;
12a457
         op_ret = count;
12a457
+        if (xdata && dict_get (xdata, "get-gfid-type")) {
12a457
+                args.parent = fd->inode;
12a457
+                args.entries = &entries;
12a457
+                ret = synctask_new (this->ctx->env, index_get_gfid_type,
12a457
+                                    NULL, NULL, &args);
12a457
+        }
12a457
 done:
12a457
-        STACK_UNWIND_STRICT (readdir, frame, op_ret, op_errno, &entries, xdata);
12a457
+        STACK_UNWIND_STRICT (readdir, frame, op_ret, op_errno, &entries, NULL);
12a457
         gf_dirent_free (&entries);
12a457
         return 0;
12a457
 }
12a457
-- 
12a457
1.7.1
12a457