diff options
Diffstat (limited to 'xlators/cluster/dht/src/dht-linkfile.c')
| -rw-r--r-- | xlators/cluster/dht/src/dht-linkfile.c | 342 |
1 files changed, 143 insertions, 199 deletions
diff --git a/xlators/cluster/dht/src/dht-linkfile.c b/xlators/cluster/dht/src/dht-linkfile.c index 82419a68b..dbc9d0b3c 100644 --- a/xlators/cluster/dht/src/dht-linkfile.c +++ b/xlators/cluster/dht/src/dht-linkfile.c @@ -1,20 +1,11 @@ /* - Copyright (c) 2008-2010 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + This file is licensed to you under your choice of the GNU Lesser + General Public License, version 3 or any later version (LGPLv3 or + later), or the GNU General Public License, version 2 (GPLv2), in all + cases as published by the Free Software Foundation. */ #ifndef _CONFIG_H @@ -28,130 +19,154 @@ #include "compat.h" #include "dht-common.h" - - int -dht_linkfile_xattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int op_ret, int op_errno) +dht_linkfile_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int op_ret, int op_errno, + inode_t *inode, struct iatt *stbuf, dict_t *xattr, + struct iatt *postparent) { - dht_local_t *local = NULL; + char is_linkfile = 0; + dht_conf_t *conf = NULL; + dht_local_t *local = NULL; + call_frame_t *prev = NULL; local = frame->local; - local->linkfile.linkfile_cbk (frame, cookie, this, op_ret, op_errno, - local->linkfile.inode, - &local->linkfile.stbuf, NULL, NULL); + prev = cookie; + conf = this->private; + + if (op_ret) + goto out; + is_linkfile = check_is_linkfile (inode, stbuf, xattr, + conf->link_xattr_name); + if (!is_linkfile) + gf_log (this->name, GF_LOG_WARNING, "got non-linkfile %s:%s", + prev->this->name, local->loc.path); +out: + local->linkfile.linkfile_cbk (frame, cookie, this, op_ret, op_errno, + inode, stbuf, postparent, postparent, + xattr); return 0; } - +#define is_equal(a, b) (a == b) int dht_linkfile_create_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int op_ret, int op_errno, inode_t *inode, struct iatt *stbuf, struct iatt *preparent, - struct iatt *postparent) + struct iatt *postparent, dict_t *xdata) { dht_local_t *local = NULL; + xlator_t *subvol = NULL; call_frame_t *prev = NULL; - dict_t *xattr = NULL; - data_t *str_data = NULL; + dict_t *xattrs = NULL; + dht_conf_t *conf = NULL; int ret = -1; local = frame->local; - prev = cookie; - - if (op_ret == -1) { - gf_log (this->name, GF_LOG_WARNING, - "%s: failed to create link file (%s)", - local->linkfile.loc.path, strerror (op_errno)); - goto err; - } - - xattr = get_new_dict (); - if (!xattr) { - op_errno = ENOMEM; - goto err; - } - - local->linkfile.xattr = dict_ref (xattr); - local->linkfile.inode = inode_ref (inode); - str_data = str_to_data (local->linkfile.srcvol->name); - if (!str_data) { - op_errno = ENOMEM; - goto err; - } - - ret = dict_set (xattr, "trusted.glusterfs.dht.linkto", str_data); - if (ret < 0) { - gf_log (this->name, GF_LOG_INFO, - "%s: failed to initialize linkfile data", - local->linkfile.loc.path); - } - str_data = NULL; - - local->linkfile.stbuf = *stbuf; - - if (uuid_is_null (local->linkfile.loc.inode->gfid)) - uuid_copy (local->linkfile.loc.gfid, stbuf->ia_gfid); + if (!op_ret) + local->linked = _gf_true; - STACK_WIND (frame, dht_linkfile_xattr_cbk, - prev->this, prev->this->fops->setxattr, - &local->linkfile.loc, local->linkfile.xattr, 0); + FRAME_SU_UNDO (frame, dht_local_t); - return 0; + if (op_ret && (op_errno == EEXIST)) { + conf = this->private; + prev = cookie; + subvol = prev->this; + if (!subvol) + goto out; + xattrs = dict_new (); + if (!xattrs) + goto out; + ret = dict_set_uint32 (xattrs, conf->link_xattr_name, 256); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, + "Failed to set linkto key"); + goto out; + } -err: - if (str_data) { - data_destroy (str_data); - str_data = NULL; + STACK_WIND (frame, dht_linkfile_lookup_cbk, subvol, + subvol->fops->lookup, &local->loc, xattrs); + if (xattrs) + dict_unref (xattrs); + return 0; } - +out: local->linkfile.linkfile_cbk (frame, cookie, this, op_ret, op_errno, - inode, stbuf, preparent, postparent); + inode, stbuf, preparent, postparent, + xdata); + if (xattrs) + dict_unref (xattrs); return 0; } int dht_linkfile_create (call_frame_t *frame, fop_mknod_cbk_t linkfile_cbk, + xlator_t *this, xlator_t *tovol, xlator_t *fromvol, loc_t *loc) { dht_local_t *local = NULL; dict_t *dict = NULL; + int need_unref = 0; int ret = 0; + dht_conf_t *conf = this->private; local = frame->local; local->linkfile.linkfile_cbk = linkfile_cbk; local->linkfile.srcvol = tovol; - loc_copy (&local->linkfile.loc, loc); - if (!uuid_is_null (local->gfid)) { + local->linked = _gf_false; + + dict = local->params; + if (!dict) { dict = dict_new (); if (!dict) goto out; + need_unref = 1; + } + + if (!uuid_is_null (local->gfid)) { ret = dict_set_static_bin (dict, "gfid-req", local->gfid, 16); if (ret) gf_log ("dht-linkfile", GF_LOG_INFO, "%s: gfid set failed", loc->path); - } else if (local->params) { - dict = dict_ref (local->params); } - if (!dict) + + ret = dict_set_str (dict, GLUSTERFS_INTERNAL_FOP_KEY, "yes"); + if (ret) + gf_log ("dht-linkfile", GF_LOG_INFO, + "%s: internal-fop set failed", loc->path); + + ret = dict_set_str (dict, conf->link_xattr_name, tovol->name); + + if (ret < 0) { gf_log (frame->this->name, GF_LOG_INFO, - "dict is NULL, need to make sure gfid's are same"); + "%s: failed to initialize linkfile data", + loc->path); + goto out; + } + local->link_subvol = fromvol; + /* Always create as root:root. dht_linkfile_attr_heal fixes the + * ownsership */ + FRAME_SU_DO (frame, dht_local_t); STACK_WIND (frame, dht_linkfile_create_cbk, fromvol, fromvol->fops->mknod, loc, - S_IFREG | DHT_LINKFILE_MODE, 0, dict); + S_IFREG | DHT_LINKFILE_MODE, 0, 0, dict); - if (dict) + if (need_unref && dict) dict_unref (dict); return 0; out: local->linkfile.linkfile_cbk (frame, NULL, frame->this, -1, ENOMEM, - loc->inode, NULL, NULL, NULL); + loc->inode, NULL, NULL, NULL, NULL); + + if (need_unref && dict) + dict_unref (dict); + return 0; } @@ -159,7 +174,8 @@ out: int dht_linkfile_unlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, - struct iatt *preparent, struct iatt *postparent) + struct iatt *preparent, struct iatt *postparent, + dict_t *xdata) { dht_local_t *local = NULL; call_frame_t *prev = NULL; @@ -193,16 +209,17 @@ dht_linkfile_unlink (call_frame_t *frame, xlator_t *this, goto err; } - unlink_local = dht_local_init (unlink_frame); + /* Using non-fop value here, as anyways, 'local->fop' is not used in + this particular case */ + unlink_local = dht_local_init (unlink_frame, loc, NULL, + GF_FOP_MAXVALUE); if (!unlink_local) { goto err; } - loc_copy (&unlink_local->loc, loc); - STACK_WIND (unlink_frame, dht_linkfile_unlink_cbk, subvol, subvol->fops->unlink, - &unlink_local->loc); + &unlink_local->loc, 0, NULL); return 0; err: @@ -227,7 +244,7 @@ dht_linkfile_subvol (xlator_t *this, inode_t *inode, struct iatt *stbuf, if (!xattr) goto out; - ret = dict_get_ptr (xattr, "trusted.glusterfs.dht.linkto", &volname); + ret = dict_get_ptr (xattr, conf->link_xattr_name, &volname); if ((-1 == ret) || !volname) goto out; @@ -244,141 +261,68 @@ out: } int -dht_recreate_linkfile_unlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, - struct iatt *preparent, struct iatt *postparent) +dht_linkfile_setattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int op_ret, int op_errno, struct iatt *statpre, + struct iatt *statpost, dict_t *xdata) { - dht_local_t *local = NULL; - xlator_t *subvol = NULL; - xlator_t *src_cached = NULL; - xlator_t *dst_hashed = NULL; - call_frame_t *prev = NULL; - loc_t *loc = NULL; - - GF_VALIDATE_OR_GOTO ("dht", frame, err); - GF_VALIDATE_OR_GOTO ("dht", this, err); - GF_VALIDATE_OR_GOTO ("dht", frame->local, err); + dht_local_t *local = NULL; + loc_t *loc = NULL; local = frame->local; - prev = cookie; - subvol = prev->this; - src_cached = local->src_cached; - dst_hashed = local->dst_hashed; loc = &local->loc; - if (!src_cached || !dst_hashed) { - gf_log (this->name, GF_LOG_ERROR, "src_cached or dst_hashed" - "subvol is null"); - local->op_ret = -1; - local->op_errno = EINVAL; - goto out; - } + if (op_ret) + gf_log (this->name, GF_LOG_ERROR, "setattr of uid/gid on %s" + " :<gfid:%s> failed (%s)", + (loc->path? loc->path: "NULL"), + uuid_utoa(local->gfid), strerror(op_errno)); - if (op_ret == -1) { - gf_log (this->name, GF_LOG_ERROR, - "unlinking linkfile %s on %s failed (%s)", - loc->path, subvol->name, strerror (op_errno)); - local->op_ret = op_ret; - local->op_errno = op_errno; - goto out; - } - gf_log (this->name, GF_LOG_DEBUG, "unlink successfull. Proceeding with" - " creation of link file %s", loc->path); - dht_linkfile_create (frame, local->linkfile.linkfile_cbk, - src_cached, dst_hashed, loc); + DHT_STACK_DESTROY (frame); - return 0; -out: - local->linkfile.linkfile_cbk (frame, NULL, frame->this, -1, EINVAL, - local->loc.inode, NULL, NULL, NULL); -err: - return -1; + return 0; } int -dht_linkfile_recreate_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int op_ret, int op_errno, - inode_t *inode, struct iatt *stbuf, dict_t *xattr, - struct iatt *postparent) +dht_linkfile_attr_heal (call_frame_t *frame, xlator_t *this) { - dht_local_t *local = NULL; - xlator_t *src_cached = NULL; - xlator_t *dst_hashed = NULL; - loc_t *loc = NULL; - - GF_VALIDATE_OR_GOTO ("dht", frame, err); - GF_VALIDATE_OR_GOTO ("dht", this, err); - GF_VALIDATE_OR_GOTO ("dht", frame->local, err); + int ret = -1; + call_frame_t *copy = NULL; + dht_local_t *local = NULL; + dht_local_t *copy_local = NULL; + xlator_t *subvol = NULL; + struct iatt stbuf = {0,}; local = frame->local; - loc = &local->loc; - src_cached = local->src_cached; - dst_hashed = local->dst_hashed; + GF_VALIDATE_OR_GOTO ("dht", local, out); + GF_VALIDATE_OR_GOTO ("dht", local->link_subvol, out); - if (!src_cached || !dst_hashed) { - gf_log (this->name, GF_LOG_ERROR, "src_cached or dst_hashed" - " or hashed_subvol is null"); - local->op_ret = -1; - local->op_errno = EINVAL; - goto out; - } + if (local->stbuf.ia_type == IA_INVAL) + return 0; - /* if link_file exists, remove it, else create it*/ - if (!op_ret) { - if (!check_is_linkfile (inode, stbuf, xattr)) - goto out; - gf_log (this->name, GF_LOG_DEBUG, "link file exists." - " Calling unlink on %s", loc->path); - STACK_WIND (frame, dht_recreate_linkfile_unlink_cbk, - dst_hashed, dst_hashed->fops->unlink, - loc); - - } else if (op_errno == ENOENT) { - gf_log (this->name, GF_LOG_DEBUG, "link file does not exist." - " Proceeding to creation of linkfile %s", loc->path); - dht_linkfile_create (frame, local->linkfile.linkfile_cbk, - src_cached, dst_hashed, loc); - } else { - gf_log (this->name, GF_LOG_ERROR, "returned error %s", - strerror(op_errno)); - local->op_ret = op_ret; - local->op_errno = op_errno; - goto out; - } + uuid_copy (local->loc.gfid, local->stbuf.ia_gfid); - return 0; -out: - local->linkfile.linkfile_cbk (frame, NULL, frame->this, -1, EINVAL, - loc->inode, NULL, NULL, NULL); -err: - return -1; -} + copy = copy_frame (frame); -int -dht_linkfile_recreate (call_frame_t *frame, fop_mknod_cbk_t linkfile_cbk, - xlator_t *tovol, xlator_t *fromvol, loc_t *loc) -{ - dht_local_t *local = NULL; + if (!copy) + goto out; - GF_VALIDATE_OR_GOTO ("dht", frame, out); - GF_VALIDATE_OR_GOTO ("dht", loc, out); - GF_VALIDATE_OR_GOTO ("dht", tovol, out); - GF_VALIDATE_OR_GOTO ("dht", fromvol, out); + copy_local = dht_local_init (copy, &local->loc, NULL, 0); - local = frame->local; - local->linkfile.linkfile_cbk = linkfile_cbk; - local->linkfile.srcvol = tovol; - loc_copy (&local->linkfile.loc, loc); + if (!copy_local) + goto out; - STACK_WIND (frame, dht_linkfile_recreate_cbk, - fromvol, fromvol->fops->lookup, loc, NULL); + stbuf = local->stbuf; + subvol = local->link_subvol; - return 0; + copy->local = copy_local; -out: - linkfile_cbk (frame, NULL, frame->this, -1, EINVAL, loc->inode, NULL, - NULL, NULL); + FRAME_SU_DO (copy, dht_local_t); - return -1; + STACK_WIND (copy, dht_linkfile_setattr_cbk, subvol, + subvol->fops->setattr, ©_local->loc, + &stbuf, (GF_SET_ATTR_UID | GF_SET_ATTR_GID), NULL); + ret = 0; +out: + return ret; } |
