summaryrefslogtreecommitdiffstats
path: root/xlators/storage/posix
diff options
context:
space:
mode:
authorVikas Gorur <vikas@gluster.com>2009-10-29 07:32:26 +0000
committerAnand V. Avati <avati@dev.gluster.com>2009-10-29 09:45:37 -0700
commit32c963cfea91e196ee1ebf98a5579989c53fdc6c (patch)
treeb8f244e9c9424cd8e8a3d77cf0599b8c49c9011a /xlators/storage/posix
parent6e2dba2c418cd09206b390fad0f413fc287b93ee (diff)
storage/posix: Refactor xattrop
Move common code into do_xattrop. Signed-off-by: Vikas Gorur <vikas@gluster.com> Signed-off-by: Anand V. Avati <avati@dev.gluster.com> BUG: 326 ([2.0.8rc9] Spurious self-heal) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=326
Diffstat (limited to 'xlators/storage/posix')
-rw-r--r--xlators/storage/posix/src/posix.c186
1 files changed, 64 insertions, 122 deletions
diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c
index b901b673f..e98a039c4 100644
--- a/xlators/storage/posix/src/posix.c
+++ b/xlators/storage/posix/src/posix.c
@@ -3466,8 +3466,8 @@ __add_array (int32_t *dest, int32_t *src, int count)
*/
int
-posix_xattrop (call_frame_t *frame, xlator_t *this,
- loc_t *loc, gf_xattrop_flags_t optype, dict_t *xattr)
+do_xattrop (call_frame_t *frame, xlator_t *this,
+ loc_t *loc, fd_t *fd, gf_xattrop_flags_t optype, dict_t *xattr)
{
char *real_path = NULL;
int32_t *array = NULL;
@@ -3477,23 +3477,53 @@ posix_xattrop (call_frame_t *frame, xlator_t *this,
int op_ret = 0;
int op_errno = 0;
+ int ret = 0;
+ int _fd = -1;
+ struct posix_fd *pfd = NULL;
+
data_pair_t *trav = NULL;
+ char *path = NULL;
+
VALIDATE_OR_GOTO (frame, out);
VALIDATE_OR_GOTO (xattr, out);
VALIDATE_OR_GOTO (this, out);
trav = xattr->members_list;
- if (loc->path)
+ if (fd) {
+ ret = fd_ctx_get (fd, this, (uint64_t *)&pfd);
+ if (ret < 0) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "failed to get pfd from fd=%p",
+ fd);
+ op_ret = -1;
+ op_errno = EBADFD;
+ goto out;
+ }
+ _fd = pfd->fd;
+ }
+
+ if (loc && loc->path)
MAKE_REAL_PATH (real_path, this, loc->path);
+ if (loc) {
+ path = strdup (loc->path);
+ } else {
+ inode_path (fd->inode, NULL, &path);
+ }
+
while (trav) {
count = trav->value->len / sizeof (int32_t);
array = CALLOC (count, sizeof (int32_t));
-
- size = sys_lgetxattr (real_path, trav->key, (char *)array,
- trav->value->len);
+
+ if (loc) {
+ size = sys_lgetxattr (real_path, trav->key, (char *)array,
+ trav->value->len);
+ } else {
+ size = sys_fgetxattr (_fd, trav->key, (char *)array,
+ trav->value->len);
+ }
op_errno = errno;
if ((size == -1) && (op_errno != ENODATA) &&
@@ -3506,7 +3536,7 @@ posix_xattrop (call_frame_t *frame, xlator_t *this,
} else {
gf_log (this->name, GF_LOG_ERROR,
"getxattr failed on %s while doing "
- "xattrop: %s", loc->path,
+ "xattrop: %s", path,
strerror (op_errno));
}
goto out;
@@ -3523,20 +3553,25 @@ posix_xattrop (call_frame_t *frame, xlator_t *this,
gf_log (this->name, GF_LOG_ERROR,
"Unknown xattrop type (%d) on %s. Please send "
"a bug report to gluster-devel@nongnu.org",
- optype, loc->path);
+ optype, path);
op_ret = -1;
op_errno = EINVAL;
goto out;
}
- size = sys_lsetxattr (real_path, trav->key, array,
- trav->value->len, 0);
+ if (loc) {
+ size = sys_lsetxattr (real_path, trav->key, array,
+ trav->value->len, 0);
+ } else {
+ size = sys_fsetxattr (_fd, trav->key, (char *)array,
+ trav->value->len, 0);
+ }
op_errno = errno;
if (size == -1) {
gf_log (this->name, GF_LOG_ERROR,
"setxattr failed on %s while doing xattrop: "
- "key=%s (%s)", loc->path,
+ "key=%s (%s)", path,
trav->key, strerror (op_errno));
op_ret = -1;
goto out;
@@ -3547,7 +3582,7 @@ posix_xattrop (call_frame_t *frame, xlator_t *this,
if (size != 0) {
gf_log (this->name, GF_LOG_DEBUG,
"dict_set_bin failed (path=%s): "
- "key=%s (%s)", loc->path,
+ "key=%s (%s)", path,
trav->key, strerror (-size));
op_ret = -1;
op_errno = EINVAL;
@@ -3555,131 +3590,38 @@ posix_xattrop (call_frame_t *frame, xlator_t *this,
}
array = NULL;
}
-
+
array = NULL;
trav = trav->next;
}
-
+
out:
if (array)
FREE (array);
+
+ if (path)
+ FREE (path);
+
STACK_UNWIND_STRICT (xattrop, frame, op_ret, op_errno, xattr);
return 0;
}
int
-posix_fxattrop (call_frame_t *frame, xlator_t *this,
- fd_t *fd, gf_xattrop_flags_t optype, dict_t *xattr)
+posix_xattrop (call_frame_t *frame, xlator_t *this,
+ loc_t *loc, gf_xattrop_flags_t optype, dict_t *xattr)
{
- int32_t *array = NULL;
- int size = 0;
- int count = 0;
-
- int op_ret = 0;
- int op_errno = 0;
-
- int _fd = -1;
- struct posix_fd *pfd = NULL;
-
- data_pair_t *trav = NULL;
- int32_t ret = -1;
-
- VALIDATE_OR_GOTO (frame, out);
- VALIDATE_OR_GOTO (xattr, out);
- VALIDATE_OR_GOTO (this, out);
-
- trav = xattr->members_list;
-
- if (fd) {
- ret = fd_ctx_get (fd, this, (uint64_t *)&pfd);
- if (ret < 0) {
- gf_log (this->name, GF_LOG_DEBUG,
- "failed to get pfd from fd=%p",
- fd);
- op_ret = -1;
- op_errno = EBADFD;
- goto out;
- }
- _fd = pfd->fd;
- }
-
- while (trav) {
- count = trav->value->len / sizeof (int32_t);
- array = CALLOC (count, sizeof (int32_t));
-
- size = sys_fgetxattr (_fd, trav->key, (char *)array,
- trav->value->len);
-
- op_errno = errno;
- if ((size == -1) && ((op_errno != ENODATA) &&
- (op_errno != ENOATTR))) {
- if (op_errno == ENOTSUP) {
- GF_LOG_OCCASIONALLY(gf_posix_xattr_enotsup_log,
- this->name,GF_LOG_WARNING,
- "extended attributes not "
- "supported by filesystem");
- } else {
- gf_log (this->name, GF_LOG_ERROR,
- "fgetxattr failed on fd=%d while: "
- "doing xattrop: %s", _fd,
- strerror (op_errno));
- }
- goto out;
- }
-
- switch (optype) {
- case GF_XATTROP_ADD_ARRAY:
- __add_array (array, (int32_t *) trav->value->data,
- trav->value->len / 4);
- break;
- default:
- gf_log (this->name, GF_LOG_ERROR,
- "Unknown xattrop type (%d) on fd=%d."
- "Please send a bug report to "
- "gluster-devel@nongnu.org",
- optype, _fd);
- op_ret = -1;
- op_errno = EINVAL;
- goto out;
- }
-
- size = sys_fsetxattr (_fd, trav->key, (char *)array,
- trav->value->len, 0);
+ do_xattrop (frame, this, loc, NULL, optype, xattr);
+ return 0;
+}
- op_errno = errno;
- if (size == -1) {
- gf_log (this->name, GF_LOG_ERROR,
- "fsetxattr failed on fd=%d while doing: "
- "xattrop. key=%s (%s)", _fd,
- trav->key, strerror (op_errno));
- op_ret = -1;
- goto out;
- } else {
- size = dict_set_bin (xattr, trav->key, array,
- trav->value->len);
- if (size != 0) {
- gf_log (this->name, GF_LOG_DEBUG,
- "dict_set_bin failed (fd=%d): "
- "key=%s (%s)", _fd,
- trav->key, strerror (-size));
- op_ret = -1;
- op_errno = EINVAL;
- goto out;
- }
- array = NULL;
- }
-
- array = NULL;
- trav = trav->next;
- }
-
-out:
- if (array)
- FREE (array);
- STACK_UNWIND_STRICT (fxattrop, frame, op_ret, op_errno, xattr);
- return 0;
+int
+posix_fxattrop (call_frame_t *frame, xlator_t *this,
+ fd_t *fd, gf_xattrop_flags_t optype, dict_t *xattr)
+{
+ do_xattrop (frame, this, NULL, fd, optype, xattr);
+ return 0;
}