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