Blob Blame History Raw
From 0499970747a7897bd9190484b5ab6868b19f393f Mon Sep 17 00:00:00 2001
From: Poornima G <pgurusid@redhat.com>
Date: Thu, 4 Jan 2018 19:38:05 +0530
Subject: [PATCH 132/139] posix: In getxattr, honor the wildcard '*'

Currently, the posix_xattr_fill performas a sys_getxattr
on all the keys requested, there are requirements where
the keys could contain a wildcard, in which case sys_getxattr
would return ENODATA, eg: if the xattr requested is user.*
all the xattrs with prefix user. should be returned, with their
values.

This patch, changes posix_xattr_fill, to honor wildcard in the keys
requested.

Updates #297

> Signed-off-by: Poornima G <pgurusid@redhat.com>
> Change-Id: I3d52da2957ac386fca3c156e26ff4cdf0b2c79a9
> Reviewed-on: https://review.gluster.org/19170
> Smoke: Gluster Build System <jenkins@build.gluster.org>
> Reviewed-by: Amar Tumballi
> Tested-by: Poornima G <pgurusid@redhat.com>
> CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
> (cherry picked from commit 8fc9c6a8fc7c73b2b4c65a8ddbe988bca10e89b6)

BUG: 1446125
Change-Id: I3d52da2957ac386fca3c156e26ff4cdf0b2c79a9
Signed-off-by: Poornima G <pgurusid@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/128480
Tested-by: RHGS Build Bot <nigelb@redhat.com>
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
---
 xlators/storage/posix/src/posix-helpers.c | 64 ++++++++++++++++++++-----------
 xlators/storage/posix/src/posix.h         |  2 +
 2 files changed, 43 insertions(+), 23 deletions(-)

diff --git a/xlators/storage/posix/src/posix-helpers.c b/xlators/storage/posix/src/posix-helpers.c
index 77affc4..f8d8fed 100644
--- a/xlators/storage/posix/src/posix-helpers.c
+++ b/xlators/storage/posix/src/posix-helpers.c
@@ -387,7 +387,9 @@ _posix_xattr_get_set (dict_t *xattr_req, char *key, data_t *data,
         int       _fd      = -1;
         loc_t    *loc      = NULL;
         ssize_t  req_size  = 0;
-
+        int32_t  list_offset = 0;
+        ssize_t  remaining_size = 0;
+        char     *xattr    = NULL;
 
         if (posix_xattr_ignorable (key))
                 goto out;
@@ -507,13 +509,20 @@ _posix_xattr_get_set (dict_t *xattr_req, char *key, data_t *data,
                                                filler->stbuf->ia_size);
                 }
         } else {
-                ret = _posix_xattr_get_set_from_backend (filler, key);
+                remaining_size = filler->list_size;
+                while (remaining_size > 0) {
+                        xattr = filler->list + list_offset;
+                        if (fnmatch (key, xattr, 0) == 0)
+                                ret = _posix_xattr_get_set_from_backend (filler,
+                                                                         xattr);
+                        remaining_size -= strlen (xattr) + 1;
+                        list_offset += strlen (xattr) + 1;
+                }
         }
 out:
         return 0;
 }
 
-
 int
 posix_fill_gfid_path (xlator_t *this, const char *path, struct iatt *iatt)
 {
@@ -712,42 +721,50 @@ out:
         return ret;
 }
 
+
 static void
-_handle_list_xattr (dict_t *xattr_req, const char *real_path, int fdnum,
-                    posix_xattr_filler_t *filler)
+_get_list_xattr (posix_xattr_filler_t *filler)
 {
         ssize_t               size                  = 0;
-        char                 *list                  = NULL;
-        int32_t               list_offset           = 0;
-        ssize_t               remaining_size        = 0;
-        char                  *key                  = NULL;
 
-        if ((!real_path) && (fdnum < 0))
+        if ((!filler) && (!filler->real_path) && (filler->fdnum < 0))
                 goto out;
 
-        if (real_path)
-                size = sys_llistxattr (real_path, NULL, 0);
+        if (filler->real_path)
+                size = sys_llistxattr (filler->real_path, NULL, 0);
         else
-                size = sys_flistxattr (fdnum, NULL, 0);
+                size = sys_flistxattr (filler->fdnum, NULL, 0);
 
         if (size <= 0)
                 goto out;
 
-        list = alloca (size);
-        if (!list)
+        filler->list = GF_CALLOC (1, size, gf_posix_mt_char);
+        if (!filler->list)
                 goto out;
 
-        if (real_path)
-                remaining_size = sys_llistxattr (real_path, list, size);
+        if (filler->real_path)
+                size = sys_llistxattr (filler->real_path, filler->list, size);
         else
-                remaining_size = sys_flistxattr (fdnum, list, size);
+                size = sys_flistxattr (filler->fdnum, filler->list, size);
 
-        if (remaining_size <= 0)
-                goto out;
+        filler->list_size = size;
+out:
+        return;
+}
+
+
+static void
+_handle_list_xattr (dict_t *xattr_req, const char *real_path, int fdnum,
+                    posix_xattr_filler_t *filler)
+{
+        int32_t               list_offset           = 0;
+        ssize_t               remaining_size        = 0;
+        char                  *key                  = NULL;
 
         list_offset = 0;
+        remaining_size = filler->list_size;
         while (remaining_size > 0) {
-                key = list + list_offset;
+                key = filler->list + list_offset;
 
                 if (gf_get_index_by_elem (list_xattr_ignore_xattrs, key) >= 0)
                         goto next;
@@ -770,7 +787,6 @@ next:
                 list_offset += strlen (key) + 1;
 
         } /* while (remaining_size > 0) */
-out:
         return;
 }
 
@@ -798,12 +814,14 @@ posix_xattr_fill (xlator_t *this, const char *real_path, loc_t *loc, fd_t *fd,
         filler.stbuf     = buf;
         filler.loc       = loc;
         filler.fd        = fd;
-        filler.fdnum    = fdnum;
+        filler.fdnum     = fdnum;
 
+        _get_list_xattr (&filler);
         dict_foreach (xattr_req, _posix_xattr_get_set, &filler);
         if (list)
                 _handle_list_xattr (xattr_req, real_path, fdnum, &filler);
 
+        GF_FREE (filler.list);
 out:
         return xattr;
 }
diff --git a/xlators/storage/posix/src/posix.h b/xlators/storage/posix/src/posix.h
index 777adac..ae9fb08 100644
--- a/xlators/storage/posix/src/posix.h
+++ b/xlators/storage/posix/src/posix.h
@@ -240,6 +240,8 @@ typedef struct {
         int          fdnum;
         int          flags;
         int32_t     op_errno;
+        char        *list;
+        size_t       list_size;
 } posix_xattr_filler_t;
 
 typedef struct {
-- 
1.8.3.1