summaryrefslogtreecommitdiffstats
path: root/xlators/storage/posix/src/posix.c
diff options
context:
space:
mode:
authorVikas Gorur <vikas@gluster.com>2009-10-29 07:43:57 +0000
committerAnand V. Avati <avati@dev.gluster.com>2009-10-29 12:02:46 -0700
commitf1f80d5f037800fd8c653c6985fe0874c1d7bca6 (patch)
tree5c471583291980aee359fedabe1944c32b3ccb88 /xlators/storage/posix/src/posix.c
parentd3a1b1e45d83d66eeb4fbd630dfe716b263b437c (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/src/posix.c')
-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 d52f90d..5ffda9f 100644
--- a/xlators/storage/posix/src/posix.c
+++ b/xlators/storage/posix/src/posix.c
@@ -3075,8 +3075,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;
@@ -3086,23 +3086,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) &&
@@ -3115,7 +3145,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;
@@ -3132,20 +3162,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;
@@ -3156,7 +3191,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;
@@ -3164,131 +3199,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 (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 (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;
}