From 8d22afce10157fa473b169754829b7646d10e108 Mon Sep 17 00:00:00 2001 From: Raghavendra Bhat Date: Fri, 4 May 2018 12:25:48 -0400 Subject: make posix return errors when gfid2path key is absent Change-Id: I3a8d452d00560dac5e0b7ff0b1835d1f20a59f91 updates: bz#1580540 Signed-off-by: Raghavendra Bhat (cherry picked from commit c2cf3f686f3ea0efd936d2eafc404fc9d2e0acc7) --- xlators/storage/posix/src/posix-gfid-path.c | 26 ++++++++++++++++++++++++++ xlators/storage/posix/src/posix-gfid-path.h | 1 + 2 files changed, 27 insertions(+) (limited to 'xlators/storage') diff --git a/xlators/storage/posix/src/posix-gfid-path.c b/xlators/storage/posix/src/posix-gfid-path.c index 2834c2fc4fd..9873e7e5a84 100644 --- a/xlators/storage/posix/src/posix-gfid-path.c +++ b/xlators/storage/posix/src/posix-gfid-path.c @@ -123,6 +123,7 @@ posix_get_gfid2path (xlator_t *this, inode_t *inode, const char *real_path, gf_boolean_t have_val = _gf_false; struct posix_private *priv = NULL; char pargfid_str[UUID_CANONICAL_FORM_LEN + 1] = {0,}; + gf_boolean_t found = _gf_false; priv = this->private; @@ -141,6 +142,7 @@ posix_get_gfid2path (xlator_t *this, inode_t *inode, const char *real_path, "value for key (%s)", GFID2PATH_VIRT_XATTR_KEY); goto err; } + found = _gf_true; } else { have_val = _gf_false; memset (value_buf, '\0', sizeof(value_buf)); @@ -202,6 +204,7 @@ posix_get_gfid2path (xlator_t *this, inode_t *inode, const char *real_path, goto ignore; } + found = _gf_true; memset (value_buf, '\0', sizeof(value_buf)); size = sys_lgetxattr (real_path, keybuffer, value_buf, sizeof (value_buf) - 1); @@ -231,6 +234,29 @@ ignore: list_offset += strlen (keybuffer) + 1; } /* while (remaining_size > 0) */ + /* gfid2path xattr is absent in the list of xattrs */ + if (!found) { + ret = -1; + /* + * ENODATA because xattr is not present in the + * list of xattrs. Thus the consumer should + * face error instead of a success and a empty + * string in the dict for the key. + */ + *op_errno = ENODATA; + goto err; + } + + /* + * gfid2path xattr is found in list of xattrs, but getxattr + * on the 1st gfid2path xattr itself failed and the while + * loop above broke. So there is nothing in the value. So + * it would be better not to send "" as the value for any + * key, as it is not true. + */ + if (found && !i) + goto err; /* both errno and ret are set before beak */ + /* Calculate memory to be allocated */ for (j = 0; j < i; j++) { bytes += strlen(paths[j]); diff --git a/xlators/storage/posix/src/posix-gfid-path.h b/xlators/storage/posix/src/posix-gfid-path.h index ac3d03e14c3..59799125bbb 100644 --- a/xlators/storage/posix/src/posix-gfid-path.h +++ b/xlators/storage/posix/src/posix-gfid-path.h @@ -13,6 +13,7 @@ #include "xlator.h" #include "common-utils.h" +#include "compat-errno.h" #define MAX_GFID2PATH_LINK_SUP 500 -- cgit