a3470f
From 0499970747a7897bd9190484b5ab6868b19f393f Mon Sep 17 00:00:00 2001
a3470f
From: Poornima G <pgurusid@redhat.com>
a3470f
Date: Thu, 4 Jan 2018 19:38:05 +0530
a3470f
Subject: [PATCH 132/139] posix: In getxattr, honor the wildcard '*'
a3470f
a3470f
Currently, the posix_xattr_fill performas a sys_getxattr
a3470f
on all the keys requested, there are requirements where
a3470f
the keys could contain a wildcard, in which case sys_getxattr
a3470f
would return ENODATA, eg: if the xattr requested is user.*
a3470f
all the xattrs with prefix user. should be returned, with their
a3470f
values.
a3470f
a3470f
This patch, changes posix_xattr_fill, to honor wildcard in the keys
a3470f
requested.
a3470f
a3470f
Updates #297
a3470f
a3470f
> Signed-off-by: Poornima G <pgurusid@redhat.com>
a3470f
> Change-Id: I3d52da2957ac386fca3c156e26ff4cdf0b2c79a9
a3470f
> Reviewed-on: https://review.gluster.org/19170
a3470f
> Smoke: Gluster Build System <jenkins@build.gluster.org>
a3470f
> Reviewed-by: Amar Tumballi
a3470f
> Tested-by: Poornima G <pgurusid@redhat.com>
a3470f
> CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
a3470f
> (cherry picked from commit 8fc9c6a8fc7c73b2b4c65a8ddbe988bca10e89b6)
a3470f
a3470f
BUG: 1446125
a3470f
Change-Id: I3d52da2957ac386fca3c156e26ff4cdf0b2c79a9
a3470f
Signed-off-by: Poornima G <pgurusid@redhat.com>
a3470f
Reviewed-on: https://code.engineering.redhat.com/gerrit/128480
a3470f
Tested-by: RHGS Build Bot <nigelb@redhat.com>
a3470f
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
a3470f
---
a3470f
 xlators/storage/posix/src/posix-helpers.c | 64 ++++++++++++++++++++-----------
a3470f
 xlators/storage/posix/src/posix.h         |  2 +
a3470f
 2 files changed, 43 insertions(+), 23 deletions(-)
a3470f
a3470f
diff --git a/xlators/storage/posix/src/posix-helpers.c b/xlators/storage/posix/src/posix-helpers.c
a3470f
index 77affc4..f8d8fed 100644
a3470f
--- a/xlators/storage/posix/src/posix-helpers.c
a3470f
+++ b/xlators/storage/posix/src/posix-helpers.c
a3470f
@@ -387,7 +387,9 @@ _posix_xattr_get_set (dict_t *xattr_req, char *key, data_t *data,
a3470f
         int       _fd      = -1;
a3470f
         loc_t    *loc      = NULL;
a3470f
         ssize_t  req_size  = 0;
a3470f
-
a3470f
+        int32_t  list_offset = 0;
a3470f
+        ssize_t  remaining_size = 0;
a3470f
+        char     *xattr    = NULL;
a3470f
 
a3470f
         if (posix_xattr_ignorable (key))
a3470f
                 goto out;
a3470f
@@ -507,13 +509,20 @@ _posix_xattr_get_set (dict_t *xattr_req, char *key, data_t *data,
a3470f
                                                filler->stbuf->ia_size);
a3470f
                 }
a3470f
         } else {
a3470f
-                ret = _posix_xattr_get_set_from_backend (filler, key);
a3470f
+                remaining_size = filler->list_size;
a3470f
+                while (remaining_size > 0) {
a3470f
+                        xattr = filler->list + list_offset;
a3470f
+                        if (fnmatch (key, xattr, 0) == 0)
a3470f
+                                ret = _posix_xattr_get_set_from_backend (filler,
a3470f
+                                                                         xattr);
a3470f
+                        remaining_size -= strlen (xattr) + 1;
a3470f
+                        list_offset += strlen (xattr) + 1;
a3470f
+                }
a3470f
         }
a3470f
 out:
a3470f
         return 0;
a3470f
 }
a3470f
 
a3470f
-
a3470f
 int
a3470f
 posix_fill_gfid_path (xlator_t *this, const char *path, struct iatt *iatt)
a3470f
 {
a3470f
@@ -712,42 +721,50 @@ out:
a3470f
         return ret;
a3470f
 }
a3470f
 
a3470f
+
a3470f
 static void
a3470f
-_handle_list_xattr (dict_t *xattr_req, const char *real_path, int fdnum,
a3470f
-                    posix_xattr_filler_t *filler)
a3470f
+_get_list_xattr (posix_xattr_filler_t *filler)
a3470f
 {
a3470f
         ssize_t               size                  = 0;
a3470f
-        char                 *list                  = NULL;
a3470f
-        int32_t               list_offset           = 0;
a3470f
-        ssize_t               remaining_size        = 0;
a3470f
-        char                  *key                  = NULL;
a3470f
 
a3470f
-        if ((!real_path) && (fdnum < 0))
a3470f
+        if ((!filler) && (!filler->real_path) && (filler->fdnum < 0))
a3470f
                 goto out;
a3470f
 
a3470f
-        if (real_path)
a3470f
-                size = sys_llistxattr (real_path, NULL, 0);
a3470f
+        if (filler->real_path)
a3470f
+                size = sys_llistxattr (filler->real_path, NULL, 0);
a3470f
         else
a3470f
-                size = sys_flistxattr (fdnum, NULL, 0);
a3470f
+                size = sys_flistxattr (filler->fdnum, NULL, 0);
a3470f
 
a3470f
         if (size <= 0)
a3470f
                 goto out;
a3470f
 
a3470f
-        list = alloca (size);
a3470f
-        if (!list)
a3470f
+        filler->list = GF_CALLOC (1, size, gf_posix_mt_char);
a3470f
+        if (!filler->list)
a3470f
                 goto out;
a3470f
 
a3470f
-        if (real_path)
a3470f
-                remaining_size = sys_llistxattr (real_path, list, size);
a3470f
+        if (filler->real_path)
a3470f
+                size = sys_llistxattr (filler->real_path, filler->list, size);
a3470f
         else
a3470f
-                remaining_size = sys_flistxattr (fdnum, list, size);
a3470f
+                size = sys_flistxattr (filler->fdnum, filler->list, size);
a3470f
 
a3470f
-        if (remaining_size <= 0)
a3470f
-                goto out;
a3470f
+        filler->list_size = size;
a3470f
+out:
a3470f
+        return;
a3470f
+}
a3470f
+
a3470f
+
a3470f
+static void
a3470f
+_handle_list_xattr (dict_t *xattr_req, const char *real_path, int fdnum,
a3470f
+                    posix_xattr_filler_t *filler)
a3470f
+{
a3470f
+        int32_t               list_offset           = 0;
a3470f
+        ssize_t               remaining_size        = 0;
a3470f
+        char                  *key                  = NULL;
a3470f
 
a3470f
         list_offset = 0;
a3470f
+        remaining_size = filler->list_size;
a3470f
         while (remaining_size > 0) {
a3470f
-                key = list + list_offset;
a3470f
+                key = filler->list + list_offset;
a3470f
 
a3470f
                 if (gf_get_index_by_elem (list_xattr_ignore_xattrs, key) >= 0)
a3470f
                         goto next;
a3470f
@@ -770,7 +787,6 @@ next:
a3470f
                 list_offset += strlen (key) + 1;
a3470f
 
a3470f
         } /* while (remaining_size > 0) */
a3470f
-out:
a3470f
         return;
a3470f
 }
a3470f
 
a3470f
@@ -798,12 +814,14 @@ posix_xattr_fill (xlator_t *this, const char *real_path, loc_t *loc, fd_t *fd,
a3470f
         filler.stbuf     = buf;
a3470f
         filler.loc       = loc;
a3470f
         filler.fd        = fd;
a3470f
-        filler.fdnum    = fdnum;
a3470f
+        filler.fdnum     = fdnum;
a3470f
 
a3470f
+        _get_list_xattr (&filler);
a3470f
         dict_foreach (xattr_req, _posix_xattr_get_set, &filler);
a3470f
         if (list)
a3470f
                 _handle_list_xattr (xattr_req, real_path, fdnum, &filler);
a3470f
 
a3470f
+        GF_FREE (filler.list);
a3470f
 out:
a3470f
         return xattr;
a3470f
 }
a3470f
diff --git a/xlators/storage/posix/src/posix.h b/xlators/storage/posix/src/posix.h
a3470f
index 777adac..ae9fb08 100644
a3470f
--- a/xlators/storage/posix/src/posix.h
a3470f
+++ b/xlators/storage/posix/src/posix.h
a3470f
@@ -240,6 +240,8 @@ typedef struct {
a3470f
         int          fdnum;
a3470f
         int          flags;
a3470f
         int32_t     op_errno;
a3470f
+        char        *list;
a3470f
+        size_t       list_size;
a3470f
 } posix_xattr_filler_t;
a3470f
 
a3470f
 typedef struct {
a3470f
-- 
a3470f
1.8.3.1
a3470f