From 9d3af972f516b6ba38d2736ce2016e34a452d569 Mon Sep 17 00:00:00 2001 From: Amar Tumballi Date: Tue, 20 Mar 2012 17:22:24 +0530 Subject: core: adding extra data for fops with this change, the xlator APIs will have a dictionary as extra argument, which is passed between all the layers. This can be utilized for overloading in some of the operations. Change-Id: I58a8186b3ef647650280e63f3e5e9b9de7827b40 Signed-off-by: Amar Tumballi BUG: 782265 Reviewed-on: http://review.gluster.com/2960 Tested-by: Gluster Build System Reviewed-by: Anand Avati --- xlators/cluster/afr/src/afr-inode-read.c | 249 ++++++++++++++++--------------- 1 file changed, 129 insertions(+), 120 deletions(-) (limited to 'xlators/cluster/afr/src/afr-inode-read.c') diff --git a/xlators/cluster/afr/src/afr-inode-read.c b/xlators/cluster/afr/src/afr-inode-read.c index 41ffcb913..097bba16e 100644 --- a/xlators/cluster/afr/src/afr-inode-read.c +++ b/xlators/cluster/afr/src/afr-inode-read.c @@ -58,7 +58,7 @@ int32_t afr_access_cbk (call_frame_t *frame, void *cookie, - xlator_t *this, int32_t op_ret, int32_t op_errno) + xlator_t *this, int32_t op_ret, int32_t op_errno, dict_t *xdata) { afr_private_t * priv = NULL; afr_local_t * local = NULL; @@ -92,12 +92,13 @@ afr_access_cbk (call_frame_t *frame, void *cookie, (void *) (long) read_child, children[next_call_child], children[next_call_child]->fops->access, - &local->loc, local->cont.access.mask); + &local->loc, local->cont.access.mask, + NULL); } out: if (unwind) { - AFR_STACK_UNWIND (access, frame, op_ret, op_errno); + AFR_STACK_UNWIND (access, frame, op_ret, op_errno, xdata); } return 0; @@ -105,7 +106,8 @@ out: int32_t -afr_access (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t mask) +afr_access (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t mask, + dict_t *xdata) { afr_private_t *priv = NULL; xlator_t **children = NULL; @@ -156,12 +158,12 @@ afr_access (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t mask) (void *) (long) call_child, children[call_child], children[call_child]->fops->access, - loc, mask); + loc, mask, xdata); ret = 0; out: if (ret < 0) - AFR_STACK_UNWIND (access, frame, -1, op_errno); + AFR_STACK_UNWIND (access, frame, -1, op_errno, NULL); return 0; } @@ -173,7 +175,7 @@ out: int32_t afr_stat_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, - struct iatt *buf) + struct iatt *buf, dict_t *xdata) { afr_private_t * priv = NULL; afr_local_t * local = NULL; @@ -207,12 +209,12 @@ afr_stat_cbk (call_frame_t *frame, void *cookie, (void *) (long) read_child, children[next_call_child], children[next_call_child]->fops->stat, - &local->loc); + &local->loc, NULL); } out: if (unwind) { - AFR_STACK_UNWIND (stat, frame, op_ret, op_errno, buf); + AFR_STACK_UNWIND (stat, frame, op_ret, op_errno, buf, xdata); } return 0; @@ -220,7 +222,7 @@ out: int32_t -afr_stat (call_frame_t *frame, xlator_t *this, loc_t *loc) +afr_stat (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata) { afr_private_t *priv = NULL; afr_local_t *local = NULL; @@ -267,12 +269,12 @@ afr_stat (call_frame_t *frame, xlator_t *this, loc_t *loc) STACK_WIND_COOKIE (frame, afr_stat_cbk, (void *) (long) call_child, children[call_child], children[call_child]->fops->stat, - loc); + loc, xdata); ret = 0; out: if (ret < 0) - AFR_STACK_UNWIND (stat, frame, -1, op_errno, NULL); + AFR_STACK_UNWIND (stat, frame, -1, op_errno, NULL, NULL); return 0; } @@ -284,7 +286,8 @@ out: int32_t afr_fstat_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct iatt *buf) + int32_t op_ret, int32_t op_errno, struct iatt *buf, + dict_t *xdata) { afr_private_t *priv = NULL; afr_local_t *local = NULL; @@ -318,12 +321,12 @@ afr_fstat_cbk (call_frame_t *frame, void *cookie, xlator_t *this, (void *) (long) read_child, children[next_call_child], children[next_call_child]->fops->fstat, - local->fd); + local->fd, NULL); } out: if (unwind) { - AFR_STACK_UNWIND (fstat, frame, op_ret, op_errno, buf); + AFR_STACK_UNWIND (fstat, frame, op_ret, op_errno, buf, xdata); } return 0; @@ -332,7 +335,7 @@ out: int32_t afr_fstat (call_frame_t *frame, xlator_t *this, - fd_t *fd) + fd_t *fd, dict_t *xdata) { afr_private_t *priv = NULL; afr_local_t *local = NULL; @@ -391,12 +394,12 @@ afr_fstat (call_frame_t *frame, xlator_t *this, STACK_WIND_COOKIE (frame, afr_fstat_cbk, (void *) (long) call_child, children[call_child], children[call_child]->fops->fstat, - fd); + fd, xdata); ret = 0; out: if (ret < 0) - AFR_STACK_UNWIND (fstat, frame, -1, op_errno, NULL); + AFR_STACK_UNWIND (fstat, frame, -1, op_errno, NULL, NULL); return 0; } @@ -408,7 +411,7 @@ out: int32_t afr_readlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, - const char *buf, struct iatt *sbuf) + const char *buf, struct iatt *sbuf, dict_t *xdata) { afr_private_t * priv = NULL; afr_local_t * local = NULL; @@ -442,12 +445,13 @@ afr_readlink_cbk (call_frame_t *frame, void *cookie, children[next_call_child], children[next_call_child]->fops->readlink, &local->loc, - local->cont.readlink.size); + local->cont.readlink.size, NULL); } out: if (unwind) { - AFR_STACK_UNWIND (readlink, frame, op_ret, op_errno, buf, sbuf); + AFR_STACK_UNWIND (readlink, frame, op_ret, op_errno, buf, sbuf, + xdata); } return 0; @@ -456,7 +460,7 @@ out: int32_t afr_readlink (call_frame_t *frame, xlator_t *this, - loc_t *loc, size_t size) + loc_t *loc, size_t size, dict_t *xdata) { afr_private_t *priv = NULL; xlator_t **children = NULL; @@ -506,12 +510,12 @@ afr_readlink (call_frame_t *frame, xlator_t *this, (void *) (long) call_child, children[call_child], children[call_child]->fops->readlink, - loc, size); + loc, size, xdata); ret = 0; out: if (ret < 0) - AFR_STACK_UNWIND (readlink, frame, -1, op_errno, NULL, NULL); + AFR_STACK_UNWIND (readlink, frame, -1, op_errno, NULL, NULL, NULL); return 0; } @@ -574,7 +578,7 @@ __filter_xattrs (dict_t *dict) int32_t afr_getxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, - dict_t *dict) + dict_t *dict, dict_t *xdata) { afr_private_t * priv = NULL; afr_local_t * local = NULL; @@ -608,7 +612,8 @@ afr_getxattr_cbk (call_frame_t *frame, void *cookie, children[next_call_child], children[next_call_child]->fops->getxattr, &local->loc, - local->cont.getxattr.name); + local->cont.getxattr.name, + NULL); } out: @@ -616,25 +621,25 @@ out: if (op_ret >= 0 && dict) __filter_xattrs (dict); - AFR_STACK_UNWIND (getxattr, frame, op_ret, op_errno, dict); + AFR_STACK_UNWIND (getxattr, frame, op_ret, op_errno, dict, xdata); } return 0; } int32_t -afr_getxattr_unwind (call_frame_t *frame, - int op_ret, int op_errno, dict_t *dict) +afr_getxattr_unwind (call_frame_t *frame, int op_ret, int op_errno, + dict_t *dict, dict_t *xdata) { - AFR_STACK_UNWIND (getxattr, frame, op_ret, op_errno, dict); + AFR_STACK_UNWIND (getxattr, frame, op_ret, op_errno, dict, xdata); return 0; } int32_t afr_getxattr_clrlk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, - dict_t *dict) + dict_t *dict, dict_t *xdata) { afr_local_t *local = NULL; afr_private_t *priv = NULL; @@ -711,7 +716,7 @@ unlock: local->child_errno[cky] = op_errno; op_errno = afr_resultant_errno_get (NULL, local->child_errno, priv->child_count); - AFR_STACK_UNWIND (getxattr, frame, op_ret, op_errno, xattr); + AFR_STACK_UNWIND (getxattr, frame, op_ret, op_errno, xattr, xdata); if (xattr) dict_unref (xattr); @@ -726,7 +731,7 @@ unlock: int32_t afr_getxattr_node_uuid_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, - dict_t *dict) + dict_t *dict, dict_t *xdata) { afr_private_t *priv = NULL; afr_local_t *local = NULL; @@ -759,12 +764,13 @@ afr_getxattr_node_uuid_cbk (call_frame_t *frame, void *cookie, children[curr_call_child], children[curr_call_child]->fops->getxattr, &local->loc, - local->cont.getxattr.name); + local->cont.getxattr.name, + NULL); } unwind: if (unwind) - AFR_STACK_UNWIND (getxattr, frame, op_ret, op_errno, dict); + AFR_STACK_UNWIND (getxattr, frame, op_ret, op_errno, dict, NULL); return 0; } @@ -772,7 +778,7 @@ afr_getxattr_node_uuid_cbk (call_frame_t *frame, void *cookie, int32_t afr_getxattr_pathinfo_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, - dict_t *dict) + dict_t *dict, dict_t *xdata) { afr_local_t *local = NULL; int32_t callcnt = 0; @@ -871,7 +877,8 @@ afr_getxattr_pathinfo_cbk (call_frame_t *frame, void *cookie, " key in dict"); unwind: - AFR_STACK_UNWIND (getxattr, frame, op_ret, op_errno, nxattr); + AFR_STACK_UNWIND (getxattr, frame, op_ret, op_errno, nxattr, + xdata); if (nxattr) dict_unref (nxattr); @@ -924,14 +931,14 @@ afr_getxattr_frm_all_children (xlator_t *this, call_frame_t *frame, STACK_WIND_COOKIE (frame, cbk, (void *) (long) i, children[i], children[i]->fops->getxattr, - loc, name); + loc, name, NULL); } return; } int32_t afr_getxattr (call_frame_t *frame, xlator_t *this, - loc_t *loc, const char *name) + loc_t *loc, const char *name, dict_t *xdata) { afr_private_t *priv = NULL; xlator_t **children = NULL; @@ -963,22 +970,71 @@ afr_getxattr (call_frame_t *frame, xlator_t *this, goto out; loc_copy (&local->loc, loc); - if (name) - local->cont.getxattr.name = gf_strdup (name); + if (!name) + goto no_name; + + local->cont.getxattr.name = gf_strdup (name); + + if (!strncmp (name, AFR_XATTR_PREFIX, + strlen (AFR_XATTR_PREFIX))) { + gf_log (this->name, GF_LOG_INFO, + "%s: no data present for key %s", + loc->path, name); + op_errno = ENODATA; + goto out; + } + if ((strcmp (GF_XATTR_MARKER_KEY, name) == 0) + && (-1 == frame->root->pid)) { + + local->marker.call_count = priv->child_count; + + sub_volumes = alloca ( priv->child_count * sizeof (xlator_t *)); + for (i = 0, trav = this->children; trav ; + trav = trav->next, i++) { + + *(sub_volumes + i) = trav->xlator; + } + if (cluster_getmarkerattr (frame, this, loc, name, + local, afr_getxattr_unwind, + sub_volumes, + priv->child_count, + MARKER_UUID_TYPE, + priv->vol_uuid)) { - if (name) { - if (!strncmp (name, AFR_XATTR_PREFIX, - strlen (AFR_XATTR_PREFIX))) { gf_log (this->name, GF_LOG_INFO, - "%s: no data present for key %s", + "%s: failed to get marker attr (%s)", loc->path, name); - op_errno = ENODATA; + op_errno = EINVAL; goto out; } - if ((strcmp (GF_XATTR_MARKER_KEY, name) == 0) - && (-1 == frame->root->pid)) { + return 0; + } + + /* + * if we are doing getxattr with pathinfo as the key then we + * collect information from all childs + */ + if (afr_is_special_xattr (name, &cbk)) { + afr_getxattr_frm_all_children (this, frame, name, + loc, cbk); + return 0; + } + + if (XATTR_IS_NODE_UUID (name)) { + i = 0; + STACK_WIND_COOKIE (frame, afr_getxattr_node_uuid_cbk, + (void *) (long) i, + children[i], + children[i]->fops->getxattr, + loc, name, xdata); + return 0; + } + + if (*priv->vol_uuid) { + if ((match_uuid_local (name, priv->vol_uuid) == 0) + && (-1 == frame->root->pid)) { local->marker.call_count = priv->child_count; sub_volumes = alloca ( priv->child_count * sizeof (xlator_t *)); @@ -986,15 +1042,16 @@ afr_getxattr (call_frame_t *frame, xlator_t *this, trav = trav->next, i++) { *(sub_volumes + i) = trav->xlator; + } - if (cluster_getmarkerattr (frame, this, loc, name, - local, afr_getxattr_unwind, + if (cluster_getmarkerattr (frame, this, loc, + name, local, + afr_getxattr_unwind, sub_volumes, priv->child_count, - MARKER_UUID_TYPE, + MARKER_XTIME_TYPE, priv->vol_uuid)) { - gf_log (this->name, GF_LOG_INFO, "%s: failed to get marker attr (%s)", loc->path, name); @@ -1004,60 +1061,9 @@ afr_getxattr (call_frame_t *frame, xlator_t *this, return 0; } - - /* - * if we are doing getxattr with pathinfo as the key then we - * collect information from all childs - */ - if (afr_is_special_xattr (name, &cbk)) { - afr_getxattr_frm_all_children (this, frame, name, - loc, cbk); - return 0; - } - - if (XATTR_IS_NODE_UUID (name)) { - i = 0; - STACK_WIND_COOKIE (frame, afr_getxattr_node_uuid_cbk, - (void *) (long) i, - children[i], - children[i]->fops->getxattr, - loc, name); - return 0; - } - - if (*priv->vol_uuid) { - if ((match_uuid_local (name, priv->vol_uuid) == 0) - && (-1 == frame->root->pid)) { - - local->marker.call_count = priv->child_count; - - sub_volumes = alloca ( priv->child_count * sizeof (xlator_t *)); - for (i = 0, trav = this->children; trav ; - trav = trav->next, i++) { - - *(sub_volumes + i) = trav->xlator; - - } - - if (cluster_getmarkerattr (frame, this, loc, - name, local, - afr_getxattr_unwind, - sub_volumes, - priv->child_count, - MARKER_XTIME_TYPE, - priv->vol_uuid)) { - gf_log (this->name, GF_LOG_INFO, - "%s: failed to get marker attr (%s)", - loc->path, name); - op_errno = EINVAL; - goto out; - } - - return 0; - } - } } +no_name: local->fresh_children = afr_children_create (priv->child_count); if (!local->fresh_children) { op_errno = ENOMEM; @@ -1078,12 +1084,12 @@ afr_getxattr (call_frame_t *frame, xlator_t *this, (void *) (long) call_child, children[call_child], children[call_child]->fops->getxattr, - loc, name); + loc, name, xdata); ret = 0; out: if (ret < 0) - AFR_STACK_UNWIND (getxattr, frame, -1, op_errno, NULL); + AFR_STACK_UNWIND (getxattr, frame, -1, op_errno, NULL, NULL); return 0; } @@ -1093,7 +1099,7 @@ out: int32_t afr_fgetxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, - dict_t *dict) + dict_t *dict, dict_t *xdata) { afr_private_t * priv = NULL; afr_local_t * local = NULL; @@ -1127,7 +1133,8 @@ afr_fgetxattr_cbk (call_frame_t *frame, void *cookie, children[next_call_child], children[next_call_child]->fops->fgetxattr, local->fd, - local->cont.getxattr.name); + local->cont.getxattr.name, + NULL); } out: @@ -1135,7 +1142,8 @@ out: if (op_ret >= 0 && dict) __filter_xattrs (dict); - AFR_STACK_UNWIND (fgetxattr, frame, op_ret, op_errno, dict); + AFR_STACK_UNWIND (fgetxattr, frame, op_ret, op_errno, dict, + xdata); } return 0; @@ -1143,16 +1151,16 @@ out: int32_t afr_fgetxattr_unwind (call_frame_t *frame, - int op_ret, int op_errno, dict_t *dict) + int op_ret, int op_errno, dict_t *dict, dict_t *xdata) { - AFR_STACK_UNWIND (fgetxattr, frame, op_ret, op_errno, dict); + AFR_STACK_UNWIND (fgetxattr, frame, op_ret, op_errno, dict, xdata); return 0; } int32_t afr_fgetxattr (call_frame_t *frame, xlator_t *this, - fd_t *fd, const char *name) + fd_t *fd, const char *name, dict_t *xdata) { afr_private_t *priv = NULL; xlator_t **children = NULL; @@ -1208,12 +1216,12 @@ afr_fgetxattr (call_frame_t *frame, xlator_t *this, (void *) (long) call_child, children[call_child], children[call_child]->fops->fgetxattr, - fd, name); + fd, name, xdata); op_ret = 0; out: if (op_ret == -1) { - AFR_STACK_UNWIND (fgetxattr, frame, op_ret, op_errno, NULL); + AFR_STACK_UNWIND (fgetxattr, frame, op_ret, op_errno, NULL, NULL); } return 0; } @@ -1239,7 +1247,7 @@ int32_t afr_readv_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, struct iovec *vector, int32_t count, struct iatt *buf, - struct iobref *iobref) + struct iobref *iobref, dict_t *xdata) { afr_private_t * priv = NULL; afr_local_t * local = NULL; @@ -1281,13 +1289,14 @@ afr_readv_cbk (call_frame_t *frame, void *cookie, children[next_call_child]->fops->readv, local->fd, local->cont.readv.size, local->cont.readv.offset, - local->cont.readv.flags); + local->cont.readv.flags, + NULL); } out: if (unwind) { AFR_STACK_UNWIND (readv, frame, op_ret, op_errno, - vector, count, buf, iobref); + vector, count, buf, iobref, xdata); } return 0; @@ -1296,7 +1305,7 @@ out: int32_t afr_readv (call_frame_t *frame, xlator_t *this, - fd_t *fd, size_t size, off_t offset, uint32_t flags) + fd_t *fd, size_t size, off_t offset, uint32_t flags, dict_t *xdata) { afr_private_t * priv = NULL; afr_local_t * local = NULL; @@ -1352,13 +1361,13 @@ afr_readv (call_frame_t *frame, xlator_t *this, (void *) (long) call_child, children[call_child], children[call_child]->fops->readv, - fd, size, offset, flags); + fd, size, offset, flags, xdata); ret = 0; out: if (ret < 0) { AFR_STACK_UNWIND (readv, frame, -1, op_errno, NULL, 0, NULL, - NULL); + NULL, NULL); } return 0; } -- cgit