summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRavishankar N <ravishankar@redhat.com>2014-08-29 10:42:02 +0000
committerVijay Bellur <vbellur@redhat.com>2014-09-29 01:13:08 -0700
commit2a2f1130689d388f26b41f5df3e0bf572e0addb5 (patch)
tree7cef3f717baaea3969348d7c9668f6971416c503
parent7113d873af1f129effd8c6da21b49e797de8eab0 (diff)
glusterfs: allow setxattr of keys with null values.
Disk based file systems allow to get/set extended attribute key-value pairs where value can be null. Fuse/libgfapi clients must be able to do the same on a gluster volume. Change-Id: Ifc11134cc07f1a3ede43f9d027554dcd10b5c930 BUG: 1135514 Signed-off-by: Ravishankar N <ravishankar@redhat.com> Reviewed-on: http://review.gluster.org/8567 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Pranith Kumar Karampuri <pkarampu@redhat.com> Reviewed-by: Jeff Darcy <jdarcy@redhat.com> Reviewed-by: Vijay Bellur <vbellur@redhat.com>
-rw-r--r--libglusterfs/src/dict.c9
-rw-r--r--tests/bugs/bug-1135514-allow-setxattr-with-null-value.t18
-rw-r--r--xlators/mount/fuse/src/fuse-bridge.c3
-rw-r--r--xlators/storage/posix/src/posix-helpers.c4
-rw-r--r--xlators/storage/posix/src/posix.c4
5 files changed, 25 insertions, 13 deletions
diff --git a/libglusterfs/src/dict.c b/libglusterfs/src/dict.c
index cf4a3ce..5062f50 100644
--- a/libglusterfs/src/dict.c
+++ b/libglusterfs/src/dict.c
@@ -2452,13 +2452,10 @@ _dict_serialize (dict_t *this, char *buf)
buf += keylen;
*buf++ = '\0';
- if (!pair->value->data) {
- gf_log ("dict", GF_LOG_ERROR,
- "pair->value->data is null!");
- goto out;
+ if (pair->value->data) {
+ memcpy (buf, pair->value->data, vallen);
+ buf += vallen;
}
- memcpy (buf, pair->value->data, vallen);
- buf += vallen;
pair = pair->next;
count--;
diff --git a/tests/bugs/bug-1135514-allow-setxattr-with-null-value.t b/tests/bugs/bug-1135514-allow-setxattr-with-null-value.t
new file mode 100644
index 0000000..cea0566
--- /dev/null
+++ b/tests/bugs/bug-1135514-allow-setxattr-with-null-value.t
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+. $(dirname $0)/../include.rc
+. $(dirname $0)/../volume.rc
+
+#Test
+cleanup;
+
+TEST glusterd
+TEST pidof glusterd
+TEST $CLI volume create $V0 $H0:$B0/${V0}0
+TEST $CLI volume start $V0
+TEST glusterfs --volfile-id=/$V0 --volfile-server=$H0 $M0 --attribute-timeout=0 --entry-timeout=0
+TEST touch $M0/file
+TEST setfattr -n user.attribute1 $M0/file
+TEST getfattr -n user.attribute1 $M0/file
+cleanup
+
diff --git a/xlators/mount/fuse/src/fuse-bridge.c b/xlators/mount/fuse/src/fuse-bridge.c
index 1733549..380093a 100644
--- a/xlators/mount/fuse/src/fuse-bridge.c
+++ b/xlators/mount/fuse/src/fuse-bridge.c
@@ -3192,9 +3192,6 @@ fuse_setxattr (xlator_t *this, fuse_in_header_t *finh, void *msg)
if (fsi->size > 0) {
dict_value = memdup (value, fsi->size);
- } else {
- gf_log (THIS->name, GF_LOG_ERROR, "value size zero");
- dict_value = NULL;
}
dict_set (state->xattr, newkey,
data_from_dynptr ((void *)dict_value, fsi->size));
diff --git a/xlators/storage/posix/src/posix-helpers.c b/xlators/storage/posix/src/posix-helpers.c
index 5f8984c..8584a68 100644
--- a/xlators/storage/posix/src/posix-helpers.c
+++ b/xlators/storage/posix/src/posix-helpers.c
@@ -130,7 +130,7 @@ _posix_xattr_get_set_from_backend (posix_xattr_filler_t *filler, char *key)
xattr_size = sys_lgetxattr (filler->real_path, key, NULL, 0);
- if (xattr_size > 0) {
+ if (xattr_size != -1) {
value = GF_CALLOC (1, xattr_size + 1,
gf_posix_mt_char);
if (!value)
@@ -138,7 +138,7 @@ _posix_xattr_get_set_from_backend (posix_xattr_filler_t *filler, char *key)
xattr_size = sys_lgetxattr (filler->real_path, key, value,
xattr_size);
- if (xattr_size <= 0) {
+ if (xattr_size == -1) {
gf_log (filler->this->name, GF_LOG_WARNING,
"getxattr failed. path: %s, key: %s",
filler->real_path, key);
diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c
index 090e53f..43bd3fc 100644
--- a/xlators/storage/posix/src/posix.c
+++ b/xlators/storage/posix/src/posix.c
@@ -3703,7 +3703,7 @@ posix_getxattr (call_frame_t *frame, xlator_t *this,
}
#endif
size = sys_lgetxattr (real_path, key, NULL, 0);
- if (size <= 0) {
+ if (size == -1) {
op_errno = errno;
if ((op_errno == ENOTSUP) || (op_errno == ENOSYS)) {
GF_LOG_OCCASIONALLY (gf_posix_xattr_enotsup_log,
@@ -3928,7 +3928,7 @@ posix_fgetxattr (call_frame_t *frame, xlator_t *this,
}
#endif
size = sys_fgetxattr (_fd, key, NULL, 0);
- if (size <= 0) {
+ if (size == -1) {
op_errno = errno;
gf_log (this->name,
((errno == ENODATA || errno == ENOATTR) ?