summaryrefslogtreecommitdiffstats
path: root/xlators/storage
diff options
context:
space:
mode:
authorAmar Tumballi <amarts@redhat.com>2012-09-06 00:13:04 +0530
committerAnand Avati <avati@redhat.com>2012-09-06 00:34:15 -0700
commitd6c99b6134f1eb90b3a8020c3538101df266e9b5 (patch)
treea5ec27bcf3136ddfda5ce5f21917bea50ad3be58 /xlators/storage
parent54b71368ef290bc579f113e683a82b09893fb50a (diff)
libglusterfs/dict: make 'dict_t' a opaque object
* ie, don't dereference dict_t pointer, instead use APIs everywhere * other than dict_t only 'data_t' should be the valid export from dict.h * added 'dict_foreach_fnmatch()' API * changed dict_lookup() to use data_t, instead of data_pair_t Change-Id: I400bb0dd55519a7c5d2a107e67c8e7a7207228dc Signed-off-by: Amar Tumballi <amarts@redhat.com> BUG: 850917 Reviewed-on: http://review.gluster.org/3829 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Anand Avati <avati@redhat.com>
Diffstat (limited to 'xlators/storage')
-rw-r--r--xlators/storage/posix/src/posix-helpers.c79
-rw-r--r--xlators/storage/posix/src/posix.c88
-rw-r--r--xlators/storage/posix/src/posix.h11
3 files changed, 85 insertions, 93 deletions
diff --git a/xlators/storage/posix/src/posix-helpers.c b/xlators/storage/posix/src/posix-helpers.c
index ea3ad429af9..4169429bd0f 100644
--- a/xlators/storage/posix/src/posix-helpers.c
+++ b/xlators/storage/posix/src/posix-helpers.c
@@ -108,7 +108,7 @@ out:
return ignore;
}
-static void
+static int
_posix_xattr_get_set (dict_t *xattr_req,
char *key,
data_t *data,
@@ -202,7 +202,7 @@ _posix_xattr_get_set (dict_t *xattr_req,
value = GF_CALLOC (1, xattr_size + 1,
gf_posix_mt_char);
if (!value)
- return;
+ return -1;
xattr_size = sys_lgetxattr (filler->real_path, key, value,
xattr_size);
@@ -211,7 +211,7 @@ _posix_xattr_get_set (dict_t *xattr_req,
"getxattr failed. path: %s, key: %s",
filler->real_path, key);
GF_FREE (value);
- return;
+ return -1;
}
value[xattr_size] = '\0';
@@ -226,7 +226,7 @@ _posix_xattr_get_set (dict_t *xattr_req,
}
}
out:
- return;
+ return 0;
}
@@ -493,8 +493,8 @@ out:
int
-posix_set_file_contents (xlator_t *this, const char *path, data_pair_t *trav,
- int flags)
+posix_set_file_contents (xlator_t *this, const char *path, char *keyp,
+ data_t *value, int flags)
{
char * key = NULL;
char real_path[PATH_MAX];
@@ -506,7 +506,7 @@ posix_set_file_contents (xlator_t *this, const char *path, data_pair_t *trav,
/* XXX: does not handle assigning GFID to created files */
return -1;
- key = &(trav->key[15]);
+ key = &(keyp[15]);
sprintf (real_path, "%s/%s", path, key);
if (flags & XATTR_REPLACE) {
@@ -518,9 +518,8 @@ posix_set_file_contents (xlator_t *this, const char *path, data_pair_t *trav,
goto create;
}
- if (trav->value->len) {
- ret = write (file_fd, trav->value->data,
- trav->value->len);
+ if (value->len) {
+ ret = write (file_fd, value->data, value->len);
if (ret == -1) {
op_ret = -errno;
gf_log (this->name, GF_LOG_ERROR,
@@ -552,7 +551,7 @@ posix_set_file_contents (xlator_t *this, const char *path, data_pair_t *trav,
goto out;
}
- ret = write (file_fd, trav->value->data, trav->value->len);
+ ret = write (file_fd, value->data, value->len);
if (ret == -1) {
op_ret = -errno;
gf_log (this->name, GF_LOG_ERROR,
@@ -648,17 +647,17 @@ static int gf_xattr_enotsup_log;
int
posix_handle_pair (xlator_t *this, const char *real_path,
- data_pair_t *trav, int flags)
+ char *key, data_t *value, int flags)
{
int sys_ret = -1;
int ret = 0;
- if (ZR_FILE_CONTENT_REQUEST(trav->key)) {
- ret = posix_set_file_contents (this, real_path, trav, flags);
+ if (ZR_FILE_CONTENT_REQUEST(key)) {
+ ret = posix_set_file_contents (this, real_path, key, value,
+ flags);
} else {
- sys_ret = sys_lsetxattr (real_path, trav->key,
- trav->value->data,
- trav->value->len, flags);
+ sys_ret = sys_lsetxattr (real_path, key, value->data,
+ value->len, flags);
if (sys_ret < 0) {
if (errno == ENOTSUP) {
@@ -670,7 +669,7 @@ posix_handle_pair (xlator_t *this, const char *real_path,
"flag)");
} else if (errno == ENOENT) {
if (!posix_special_xattr (marker_xattrs,
- trav->key)) {
+ key)) {
gf_log (this->name, GF_LOG_ERROR,
"setxattr on %s failed: %s",
real_path, strerror (errno));
@@ -682,12 +681,12 @@ posix_handle_pair (xlator_t *this, const char *real_path,
((errno == EINVAL) ?
GF_LOG_DEBUG : GF_LOG_ERROR),
"%s: key:%s error:%s",
- real_path, trav->key,
+ real_path, key,
strerror (errno));
#else /* ! DARWIN */
gf_log (this->name, GF_LOG_ERROR,
"%s: key:%s error:%s",
- real_path, trav->key,
+ real_path, key,
strerror (errno));
#endif /* DARWIN */
}
@@ -702,13 +701,13 @@ out:
int
posix_fhandle_pair (xlator_t *this, int fd,
- data_pair_t *trav, int flags)
+ char *key, data_t *value, int flags)
{
int sys_ret = -1;
int ret = 0;
- sys_ret = sys_fsetxattr (fd, trav->key, trav->value->data,
- trav->value->len, flags);
+ sys_ret = sys_fsetxattr (fd, key, value->data,
+ value->len, flags);
if (sys_ret < 0) {
if (errno == ENOTSUP) {
@@ -729,13 +728,11 @@ posix_fhandle_pair (xlator_t *this, int fd,
((errno == EINVAL) ?
GF_LOG_DEBUG : GF_LOG_ERROR),
"fd=%d: key:%s error:%s",
- fd, trav->key,
- strerror (errno));
+ fd, key, strerror (errno));
#else /* ! DARWIN */
gf_log (this->name, GF_LOG_ERROR,
"fd=%d: key:%s error:%s",
- fd, trav->key,
- strerror (errno));
+ fd, key, strerror (errno));
#endif /* DARWIN */
}
@@ -934,33 +931,31 @@ int
posix_entry_create_xattr_set (xlator_t *this, const char *path,
dict_t *dict)
{
- data_pair_t *trav = NULL;
int ret = -1;
if (!dict)
goto out;
- trav = dict->members_list;
- while (trav) {
- if (!strcmp (GFID_XATTR_KEY, trav->key) ||
- !strcmp ("gfid-req", trav->key) ||
- !strcmp ("system.posix_acl_default", trav->key) ||
- !strcmp ("system.posix_acl_access", trav->key) ||
- ZR_FILE_CONTENT_REQUEST(trav->key)) {
- trav = trav->next;
- continue;
+ int _handle_keyvalue_pair (dict_t *d, char *k, data_t *v,
+ void *tmp)
+ {
+ if (!strcmp (GFID_XATTR_KEY, k) ||
+ !strcmp ("gfid-req", k) ||
+ !strcmp ("system.posix_acl_default", k) ||
+ !strcmp ("system.posix_acl_access", k) ||
+ ZR_FILE_CONTENT_REQUEST(k)) {
+ return 0;
}
- ret = posix_handle_pair (this, path, trav, XATTR_CREATE);
+ ret = posix_handle_pair (this, path, k, v, XATTR_CREATE);
if (ret < 0) {
errno = -ret;
- ret = -1;
- goto out;
+ return -1;
}
- trav = trav->next;
+ return 0;
}
- ret = 0;
+ ret = dict_foreach (dict, _handle_keyvalue_pair, NULL);
out:
return ret;
diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c
index df0dce72711..64cfca0c023 100644
--- a/xlators/storage/posix/src/posix.c
+++ b/xlators/storage/posix/src/posix.c
@@ -2375,7 +2375,6 @@ posix_setxattr (call_frame_t *frame, xlator_t *this,
int32_t op_ret = -1;
int32_t op_errno = 0;
char * real_path = NULL;
- data_pair_t * trav = NULL;
int ret = -1;
DECLARE_OLD_FS_ID_VAR;
@@ -2391,18 +2390,17 @@ posix_setxattr (call_frame_t *frame, xlator_t *this,
op_ret = -1;
dict_del (dict, GFID_XATTR_KEY);
- trav = dict->members_list;
- while (trav) {
- ret = posix_handle_pair (this, real_path, trav, flags);
+ int _handle_every_keyvalue_pair (dict_t *d, char *k, data_t *v,
+ void *tmp)
+ {
+ ret = posix_handle_pair (this, real_path, k, v, flags);
if (ret < 0) {
op_errno = -ret;
- goto out;
}
- trav = trav->next;
+ return ret;
}
-
- op_ret = 0;
+ op_ret = dict_foreach (dict, _handle_every_keyvalue_pair, NULL);
out:
SET_TO_OLD_FS_ID ();
@@ -2895,7 +2893,6 @@ posix_fsetxattr (call_frame_t *frame, xlator_t *this,
int32_t op_errno = 0;
struct posix_fd * pfd = NULL;
int _fd = -1;
- data_pair_t * trav = NULL;
int ret = -1;
DECLARE_OLD_FS_ID_VAR;
@@ -2917,18 +2914,17 @@ posix_fsetxattr (call_frame_t *frame, xlator_t *this,
dict_del (dict, GFID_XATTR_KEY);
- trav = dict->members_list;
-
- while (trav) {
- ret = posix_fhandle_pair (this, _fd, trav, flags);
+ int _handle_every_keyvalue_pair (dict_t *d, char *k, data_t *v,
+ void *tmp)
+ {
+ ret = posix_fhandle_pair (this, _fd, k, v, flags);
if (ret < 0) {
op_errno = -ret;
- goto out;
}
- trav = trav->next;
+ return ret;
}
- op_ret = 0;
+ op_ret = dict_foreach (dict, _handle_every_keyvalue_pair, NULL);
out:
SET_TO_OLD_FS_ID ();
@@ -3123,8 +3119,6 @@ do_xattrop (call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd,
int _fd = -1;
struct posix_fd *pfd = NULL;
- data_pair_t *trav = NULL;
-
char * path = NULL;
inode_t * inode = NULL;
@@ -3132,8 +3126,6 @@ do_xattrop (call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd,
VALIDATE_OR_GOTO (xattr, out);
VALIDATE_OR_GOTO (this, out);
- trav = xattr->members_list;
-
if (fd) {
ret = posix_fd_ctx_get (fd, this, &pfd);
if (ret < 0) {
@@ -3157,19 +3149,21 @@ do_xattrop (call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd,
inode = fd->inode;
}
- while (trav && inode) {
- count = trav->value->len;
- array = GF_CALLOC (count, sizeof (char),
- gf_posix_mt_char);
+ int _handle_every_keyvalue_pair (dict_t *d, char *k, data_t *v,
+ void *tmp)
+ {
+
+ count = v->len;
+ array = GF_CALLOC (count, sizeof (char), gf_posix_mt_char);
LOCK (&inode->lock);
{
if (loc) {
- size = sys_lgetxattr (real_path, trav->key, (char *)array,
- trav->value->len);
+ size = sys_lgetxattr (real_path, k,
+ (char *)array, v->len);
} else {
- size = sys_fgetxattr (_fd, trav->key, (char *)array,
- trav->value->len);
+ size = sys_fgetxattr (_fd, k, (char *)array,
+ v->len);
}
op_errno = errno;
@@ -3182,17 +3176,17 @@ do_xattrop (call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd,
"supported by filesystem");
} else if (op_errno != ENOENT ||
!posix_special_xattr (marker_xattrs,
- trav->key)) {
+ k)) {
if (loc)
gf_log (this->name, GF_LOG_ERROR,
"getxattr failed on %s while doing "
"xattrop: Key:%s (%s)", path,
- trav->key, strerror (op_errno));
+ k, strerror (op_errno));
else
gf_log (this->name, GF_LOG_ERROR,
"fgetxattr failed on fd=%d while doing "
"xattrop: Key:%s (%s)", _fd,
- trav->key, strerror (op_errno));
+ k, strerror (op_errno));
}
op_ret = -1;
@@ -3202,13 +3196,13 @@ do_xattrop (call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd,
switch (optype) {
case GF_XATTROP_ADD_ARRAY:
- __add_array ((int32_t *) array, (int32_t *) trav->value->data,
- trav->value->len / 4);
+ __add_array ((int32_t *) array, (int32_t *) v->data,
+ v->len / 4);
break;
case GF_XATTROP_ADD_ARRAY64:
- __add_long_array ((int64_t *) array, (int64_t *) trav->value->data,
- trav->value->len / 8);
+ __add_long_array ((int64_t *) array, (int64_t *) v->data,
+ v->len / 8);
break;
default:
@@ -3222,11 +3216,11 @@ do_xattrop (call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd,
}
if (loc) {
- size = sys_lsetxattr (real_path, trav->key, array,
- trav->value->len, 0);
+ size = sys_lsetxattr (real_path, k, array,
+ v->len, 0);
} else {
- size = sys_fsetxattr (_fd, trav->key, (char *)array,
- trav->value->len, 0);
+ size = sys_fsetxattr (_fd, k, (char *)array,
+ v->len, 0);
}
}
unlock:
@@ -3241,30 +3235,29 @@ do_xattrop (call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd,
gf_log (this->name, GF_LOG_ERROR,
"setxattr failed on %s while doing xattrop: "
"key=%s (%s)", path,
- trav->key, strerror (op_errno));
+ k, strerror (op_errno));
else
gf_log (this->name, GF_LOG_ERROR,
"fsetxattr failed on fd=%d while doing xattrop: "
"key=%s (%s)", _fd,
- trav->key, strerror (op_errno));
+ k, strerror (op_errno));
op_ret = -1;
goto out;
} else {
- size = dict_set_bin (xattr, trav->key, array,
- trav->value->len);
+ size = dict_set_bin (xattr, k, array, v->len);
if (size != 0) {
if (loc)
gf_log (this->name, GF_LOG_DEBUG,
"dict_set_bin failed (path=%s): "
"key=%s (%s)", path,
- trav->key, strerror (-size));
+ k, strerror (-size));
else
gf_log (this->name, GF_LOG_DEBUG,
"dict_set_bin failed (fd=%d): "
"key=%s (%s)", _fd,
- trav->key, strerror (-size));
+ k, strerror (-size));
op_ret = -1;
op_errno = EINVAL;
@@ -3274,8 +3267,11 @@ do_xattrop (call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd,
}
array = NULL;
- trav = trav->next;
+
+ out:
+ return op_ret;
}
+ op_ret = dict_foreach (xattr, _handle_every_keyvalue_pair, NULL);
out:
GF_FREE (array);
diff --git a/xlators/storage/posix/src/posix.h b/xlators/storage/posix/src/posix.h
index 669bd5cbb29..84ad85e8ada 100644
--- a/xlators/storage/posix/src/posix.h
+++ b/xlators/storage/posix/src/posix.h
@@ -142,14 +142,15 @@ int posix_pstat (xlator_t *this, uuid_t gfid, const char *real_path,
struct iatt *iatt);
dict_t *posix_lookup_xattr_fill (xlator_t *this, const char *path,
loc_t *loc, dict_t *xattr, struct iatt *buf);
-int posix_handle_pair (xlator_t *this, const char *real_path,
- data_pair_t *trav, int flags);
-int posix_fhandle_pair (xlator_t *this, int fd, data_pair_t *trav, int flags);
+int posix_handle_pair (xlator_t *this, const char *real_path, char *key,
+ data_t *value, int flags);
+int posix_fhandle_pair (xlator_t *this, int fd, char *key, data_t *value,
+ int flags);
void posix_spawn_janitor_thread (xlator_t *this);
int posix_get_file_contents (xlator_t *this, uuid_t pargfid,
const char *name, char **contents);
-int posix_set_file_contents (xlator_t *this, const char *path,
- data_pair_t *trav, int flags);
+int posix_set_file_contents (xlator_t *this, const char *path, char *key,
+ data_t *value, int flags);
int posix_acl_xattr_set (xlator_t *this, const char *path, dict_t *xattr_req);
int posix_gfid_heal (xlator_t *this, const char *path, dict_t *xattr_req);
int posix_entry_create_xattr_set (xlator_t *this, const char *path,