From 8293d21280fd6ddfc9bb54068cf87794fc6be207 Mon Sep 17 00:00:00 2001 From: Amar Tumballi Date: Thu, 6 Dec 2018 12:29:25 +0530 Subject: all: remove code which is not being considered in build These xlators are now removed from build as per discussion/announcement done at https://lists.gluster.org/pipermail/gluster-users/2018-July/034400.html * move rot-13 to playground, as it is used only as demo purpose, and is documented in many places. * Removed code of below xlators: - cluster/stripe - cluster/tier - features/changetimerecorder - features/glupy - performance/symlink-cache - encryption/crypt - storage/bd - experimental/posix2 - experimental/dht2 - experimental/fdl - experimental/jbr updates: bz#1635688 Change-Id: I1d2d63c32535e149bc8dcb2daa76236c707996e8 Signed-off-by: Amar Tumballi --- xlators/cluster/dht/src/tier-common.c | 1199 ------ xlators/cluster/dht/src/tier-common.h | 55 - xlators/cluster/dht/src/tier.c | 3090 -------------- xlators/cluster/dht/src/tier.h | 110 - xlators/cluster/dht/src/tier.sym | 9 - xlators/cluster/stripe/Makefile.am | 3 - xlators/cluster/stripe/src/Makefile.am | 22 - xlators/cluster/stripe/src/stripe-helpers.c | 658 --- xlators/cluster/stripe/src/stripe-mem-types.h | 29 - xlators/cluster/stripe/src/stripe.c | 5612 ------------------------- xlators/cluster/stripe/src/stripe.h | 291 -- 11 files changed, 11078 deletions(-) delete mode 100644 xlators/cluster/dht/src/tier-common.c delete mode 100644 xlators/cluster/dht/src/tier-common.h delete mode 100644 xlators/cluster/dht/src/tier.c delete mode 100644 xlators/cluster/dht/src/tier.h delete mode 100644 xlators/cluster/dht/src/tier.sym delete mode 100644 xlators/cluster/stripe/Makefile.am delete mode 100644 xlators/cluster/stripe/src/Makefile.am delete mode 100644 xlators/cluster/stripe/src/stripe-helpers.c delete mode 100644 xlators/cluster/stripe/src/stripe-mem-types.h delete mode 100644 xlators/cluster/stripe/src/stripe.c delete mode 100644 xlators/cluster/stripe/src/stripe.h (limited to 'xlators/cluster') diff --git a/xlators/cluster/dht/src/tier-common.c b/xlators/cluster/dht/src/tier-common.c deleted file mode 100644 index b22f4776ada..00000000000 --- a/xlators/cluster/dht/src/tier-common.c +++ /dev/null @@ -1,1199 +0,0 @@ -/* - Copyright (c) 2015 Red Hat, Inc. - This file is part of GlusterFS. - - 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. -*/ - -#include -#include -#include "libxlator.h" -#include "dht-common.h" -#include -#include "tier-common.h" -#include "tier.h" - -int -dht_link_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, dict_t *xdata); - -int -tier_link_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, dict_t *xdata) -{ - dht_local_t *local = NULL; - loc_t *oldloc = NULL; - loc_t *newloc = NULL; - - local = frame->local; - - oldloc = &local->loc; - newloc = &local->loc2; - - if (op_ret == -1) { - /* No continuation on DHT inode missing errors, as we should - * then have a good stbuf that states P2 happened. We would - * get inode missing if, the file completed migrated between - * the lookup and the link call */ - goto out; - } - - if (local->call_cnt != 1) { - goto out; - } - - local->call_cnt = 2; - - /* Do this on the hot tier now */ - - STACK_WIND(frame, tier_link_cbk, local->cached_subvol, - local->cached_subvol->fops->link, oldloc, newloc, xdata); - - return 0; - -out: - DHT_STRIP_PHASE1_FLAGS(stbuf); - - DHT_STACK_UNWIND(link, frame, op_ret, op_errno, inode, stbuf, preparent, - postparent, NULL); - - return 0; -} - -int -tier_link(call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc, - dict_t *xdata) -{ - xlator_t *cached_subvol = NULL; - xlator_t *hashed_subvol = NULL; - int op_errno = -1; - int ret = -1; - dht_local_t *local = NULL; - dht_conf_t *conf = NULL; - - VALIDATE_OR_GOTO(frame, err); - VALIDATE_OR_GOTO(this, err); - VALIDATE_OR_GOTO(oldloc, err); - VALIDATE_OR_GOTO(newloc, err); - - conf = this->private; - - local = dht_local_init(frame, oldloc, NULL, GF_FOP_LINK); - if (!local) { - op_errno = ENOMEM; - goto err; - } - local->call_cnt = 1; - - cached_subvol = local->cached_subvol; - - if (!cached_subvol) { - gf_msg_debug(this->name, 0, "no cached subvolume for path=%s", - oldloc->path); - op_errno = ENOENT; - goto err; - } - - hashed_subvol = TIER_HASHED_SUBVOL; - - ret = loc_copy(&local->loc2, newloc); - if (ret == -1) { - op_errno = ENOMEM; - goto err; - } - - if (hashed_subvol == cached_subvol) { - STACK_WIND(frame, dht_link_cbk, cached_subvol, - cached_subvol->fops->link, oldloc, newloc, xdata); - return 0; - } - - /* Create hardlinks to both the data file on the hot tier - and the linkto file on the cold tier */ - - gf_uuid_copy(local->gfid, oldloc->inode->gfid); - - STACK_WIND(frame, tier_link_cbk, hashed_subvol, hashed_subvol->fops->link, - oldloc, newloc, xdata); - - return 0; -err: - op_errno = (op_errno == -1) ? errno : op_errno; - DHT_STACK_UNWIND(link, frame, -1, op_errno, NULL, NULL, NULL, NULL, NULL); - return 0; -} - -int -tier_create_unlink_stale_linkto_cbk(call_frame_t *frame, void *cookie, - xlator_t *this, int op_ret, int op_errno, - struct iatt *preparent, - struct iatt *postparent, dict_t *xdata) -{ - dht_local_t *local = NULL; - - local = frame->local; - - if (local->params) { - dict_del(local->params, GLUSTERFS_INTERNAL_FOP_KEY); - } - - DHT_STACK_UNWIND(create, frame, -1, local->op_errno, NULL, NULL, NULL, NULL, - NULL, NULL); - - return 0; -} - -int -tier_create_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret, - int op_errno, fd_t *fd, inode_t *inode, struct iatt *stbuf, - struct iatt *preparent, struct iatt *postparent, dict_t *xdata) -{ - xlator_t *prev = NULL; - int ret = -1; - dht_local_t *local = NULL; - xlator_t *hashed_subvol = NULL; - dht_conf_t *conf = NULL; - - local = frame->local; - conf = this->private; - - hashed_subvol = TIER_HASHED_SUBVOL; - - if (!local) { - op_ret = -1; - op_errno = EINVAL; - goto out; - } - - if (op_ret == -1) { - if (local->linked == _gf_true && local->xattr_req) { - local->op_errno = op_errno; - local->op_ret = op_ret; - ret = dht_fill_dict_to_avoid_unlink_of_migrating_file( - local->xattr_req); - if (ret) { - gf_msg(this->name, GF_LOG_WARNING, 0, DHT_MSG_DICT_SET_FAILED, - "Failed to set dictionary value to " - "unlink of migrating file"); - goto out; - } - - STACK_WIND(frame, tier_create_unlink_stale_linkto_cbk, - hashed_subvol, hashed_subvol->fops->unlink, &local->loc, - 0, local->xattr_req); - return 0; - } - goto out; - } - - prev = cookie; - - if (local->loc.parent) { - dht_inode_ctx_time_update(local->loc.parent, this, preparent, 0); - - dht_inode_ctx_time_update(local->loc.parent, this, postparent, 1); - } - - ret = dht_layout_preset(this, prev, inode); - if (ret != 0) { - gf_msg_debug(this->name, 0, "could not set preset layout for subvol %s", - prev->name); - op_ret = -1; - op_errno = EINVAL; - goto out; - } - - local->op_errno = op_errno; - - if (local->linked == _gf_true) { - local->stbuf = *stbuf; - dht_linkfile_attr_heal(frame, this); - } -out: - if (local) { - if (local->xattr_req) { - dict_del(local->xattr_req, TIER_LINKFILE_GFID); - } - } - - DHT_STRIP_PHASE1_FLAGS(stbuf); - - DHT_STACK_UNWIND(create, frame, op_ret, op_errno, fd, inode, stbuf, - preparent, postparent, xdata); - - return 0; -} - -int -tier_create_linkfile_create_cbk(call_frame_t *frame, void *cookie, - xlator_t *this, int32_t op_ret, - int32_t op_errno, inode_t *inode, - struct iatt *stbuf, struct iatt *preparent, - struct iatt *postparent, dict_t *xdata) -{ - dht_local_t *local = NULL; - xlator_t *cached_subvol = NULL; - dht_conf_t *conf = NULL; - int ret = -1; - unsigned char *gfid = NULL; - - local = frame->local; - if (!local) { - op_errno = EINVAL; - goto err; - } - - if (op_ret == -1) { - local->op_errno = op_errno; - goto err; - } - - conf = this->private; - if (!conf) { - local->op_errno = EINVAL; - op_errno = EINVAL; - goto err; - } - - cached_subvol = TIER_UNHASHED_SUBVOL; - - if (local->params) { - dict_del(local->params, conf->link_xattr_name); - dict_del(local->params, GLUSTERFS_INTERNAL_FOP_KEY); - } - - /* - * We will delete the linkfile if data file creation fails. - * When deleting this stale linkfile, there is a possibility - * for a race between this linkfile deletion and a stale - * linkfile deletion triggered by another lookup from different - * client. - * - * For eg: - * - * Client 1 Client 2 - * - * 1 linkfile created for foo - * - * 2 data file creation failed - * - * 3 creating a file with same name - * - * 4 lookup before creation deleted - * the linkfile created by client1 - * considering as a stale linkfile. - * - * 5 New linkfile created for foo - * with different gfid. - * - * 6 Trigger linkfile deletion as - * data file creation failed. - * - * 7 Linkfile deleted which is - * created by client2. - * - * 8 Data file created. - * - * With this race, we will end up having a file in a non-hashed subvol - * without a linkfile in hashed subvol. - * - * To avoid this, we store the gfid of linkfile created by client, So - * If we delete the linkfile , we validate gfid of existing file with - * stored value from posix layer. - * - * Storing this value in local->xattr_req as local->params was also used - * to create the data file. During the linkfile deletion we will use - * local->xattr_req dictionary. - */ - if (!local->xattr_req) { - local->xattr_req = dict_new(); - if (!local->xattr_req) { - local->op_errno = ENOMEM; - op_errno = ENOMEM; - goto err; - } - } - - gfid = GF_MALLOC(sizeof(uuid_t), gf_common_mt_char); - if (!gfid) { - local->op_errno = ENOMEM; - op_errno = ENOMEM; - goto err; - } - - gf_uuid_copy(gfid, stbuf->ia_gfid); - ret = dict_set_dynptr(local->xattr_req, TIER_LINKFILE_GFID, gfid, - sizeof(uuid_t)); - if (ret) { - GF_FREE(gfid); - gf_msg(this->name, GF_LOG_WARNING, 0, DHT_MSG_DICT_SET_FAILED, - "Failed to set dictionary value" - " : key = %s", - TIER_LINKFILE_GFID); - } - - STACK_WIND_COOKIE(frame, tier_create_cbk, cached_subvol, cached_subvol, - cached_subvol->fops->create, &local->loc, local->flags, - local->mode, local->umask, local->fd, local->params); - - return 0; -err: - DHT_STACK_UNWIND(create, frame, -1, op_errno, NULL, NULL, NULL, NULL, NULL, - NULL); - return 0; -} - -gf_boolean_t -tier_is_hot_tier_decommissioned(xlator_t *this) -{ - dht_conf_t *conf = NULL; - xlator_t *hot_tier = NULL; - int i = 0; - - conf = this->private; - hot_tier = conf->subvolumes[1]; - - if (conf->decommission_subvols_cnt) { - for (i = 0; i < conf->subvolume_cnt; i++) { - if (conf->decommissioned_bricks[i] && - conf->decommissioned_bricks[i] == hot_tier) - return _gf_true; - } - } - - return _gf_false; -} - -int -tier_create(call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags, - mode_t mode, mode_t umask, fd_t *fd, dict_t *params) -{ - int op_errno = -1; - dht_local_t *local = NULL; - dht_conf_t *conf = NULL; - xlator_t *hot_subvol = NULL; - xlator_t *cold_subvol = NULL; - - VALIDATE_OR_GOTO(frame, err); - VALIDATE_OR_GOTO(this, err); - VALIDATE_OR_GOTO(loc, err); - - conf = this->private; - - dht_get_du_info(frame, this, loc); - - local = dht_local_init(frame, loc, fd, GF_FOP_CREATE); - if (!local) { - op_errno = ENOMEM; - goto err; - } - - cold_subvol = TIER_HASHED_SUBVOL; - hot_subvol = TIER_UNHASHED_SUBVOL; - - if (conf->subvolumes[0] != cold_subvol) { - hot_subvol = conf->subvolumes[0]; - } - /* - * if hot tier full, write to cold. - * Also if hot tier is full, create in cold - */ - if (dht_is_subvol_filled(this, hot_subvol) || - tier_is_hot_tier_decommissioned(this)) { - gf_msg_debug(this->name, 0, "creating %s on %s", loc->path, - cold_subvol->name); - - STACK_WIND_COOKIE(frame, tier_create_cbk, cold_subvol, cold_subvol, - cold_subvol->fops->create, loc, flags, mode, umask, - fd, params); - } else { - local->params = dict_ref(params); - local->flags = flags; - local->mode = mode; - local->umask = umask; - local->cached_subvol = hot_subvol; - local->hashed_subvol = cold_subvol; - - gf_msg_debug(this->name, 0, "creating %s on %s (link at %s)", loc->path, - hot_subvol->name, cold_subvol->name); - - dht_linkfile_create(frame, tier_create_linkfile_create_cbk, this, - hot_subvol, cold_subvol, loc); - - goto out; - } -out: - return 0; - -err: - - op_errno = (op_errno == -1) ? errno : op_errno; - DHT_STACK_UNWIND(create, frame, -1, op_errno, NULL, NULL, NULL, NULL, NULL, - NULL); - - return 0; -} - -int -tier_unlink_nonhashed_linkfile_cbk(call_frame_t *frame, void *cookie, - xlator_t *this, int op_ret, int op_errno, - struct iatt *preparent, - struct iatt *postparent, dict_t *xdata) -{ - dht_local_t *local = NULL; - xlator_t *prev = NULL; - - local = frame->local; - prev = cookie; - - LOCK(&frame->lock); - { - if ((op_ret == -1) && (op_errno != ENOENT)) { - local->op_errno = op_errno; - local->op_ret = op_ret; - gf_msg_debug(this->name, op_errno, - "Unlink link: subvolume %s" - " returned -1", - prev->name); - goto unlock; - } - - local->op_ret = 0; - } -unlock: - UNLOCK(&frame->lock); - - if (local->op_ret == -1) - goto err; - DHT_STACK_UNWIND(unlink, frame, local->op_ret, local->op_errno, - &local->preparent, &local->postparent, NULL); - - return 0; - -err: - DHT_STACK_UNWIND(unlink, frame, -1, local->op_errno, NULL, NULL, NULL); - return 0; -} - -int -tier_unlink_lookup_cbk(call_frame_t *frame, void *cookie, xlator_t *this, - int op_ret, int op_errno, inode_t *inode, - struct iatt *preparent, dict_t *xdata, - struct iatt *postparent) -{ - dht_local_t *local = NULL; - xlator_t *prev = NULL; - dht_conf_t *conf = NULL; - xlator_t *hot_subvol = NULL; - - local = frame->local; - prev = cookie; - conf = this->private; - hot_subvol = TIER_UNHASHED_SUBVOL; - - if (!op_ret) { - /* - * linkfile present on hot tier. unlinking the linkfile - */ - STACK_WIND_COOKIE(frame, tier_unlink_nonhashed_linkfile_cbk, hot_subvol, - hot_subvol, hot_subvol->fops->unlink, &local->loc, - local->flags, NULL); - return 0; - } - - LOCK(&frame->lock); - { - if (op_errno == ENOENT) { - local->op_ret = 0; - local->op_errno = op_errno; - } else { - local->op_ret = op_ret; - local->op_errno = op_errno; - } - gf_msg_debug(this->name, op_errno, "Lookup : subvolume %s returned -1", - prev->name); - } - - UNLOCK(&frame->lock); - - DHT_STACK_UNWIND(unlink, frame, local->op_ret, local->op_errno, - &local->preparent, &local->postparent, xdata); - - return 0; -} - -int -tier_unlink_linkfile_cbk(call_frame_t *frame, void *cookie, xlator_t *this, - int op_ret, int op_errno, struct iatt *preparent, - struct iatt *postparent, dict_t *xdata) -{ - dht_local_t *local = NULL; - xlator_t *prev = NULL; - - local = frame->local; - prev = cookie; - - LOCK(&frame->lock); - { - /* Ignore EINVAL for tier to ignore error when the file - does not exist on the other tier */ - if ((op_ret == -1) && !((op_errno == ENOENT) || (op_errno == EINVAL))) { - local->op_errno = op_errno; - local->op_ret = op_ret; - gf_msg_debug(this->name, op_errno, - "Unlink link: subvolume %s" - " returned -1", - prev->name); - goto unlock; - } - - local->op_ret = 0; - } -unlock: - UNLOCK(&frame->lock); - - if (local->op_ret == -1) - goto err; - - DHT_STACK_UNWIND(unlink, frame, local->op_ret, local->op_errno, - &local->preparent, &local->postparent, xdata); - - return 0; - -err: - DHT_STACK_UNWIND(unlink, frame, -1, local->op_errno, NULL, NULL, NULL); - return 0; -} - -int32_t -tier_unlink_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret, - int op_errno, struct iatt *preparent, struct iatt *postparent, - dict_t *xdata) -{ - dht_local_t *local = NULL; - xlator_t *prev = NULL; - struct iatt *stbuf = NULL; - dht_conf_t *conf = NULL; - int ret = -1; - xlator_t *hot_tier = NULL; - xlator_t *cold_tier = NULL; - - local = frame->local; - prev = cookie; - conf = this->private; - - cold_tier = TIER_HASHED_SUBVOL; - hot_tier = TIER_UNHASHED_SUBVOL; - - LOCK(&frame->lock); - { - if (op_ret == -1) { - if (op_errno == ENOENT) { - local->op_ret = 0; - } else { - local->op_ret = -1; - local->op_errno = op_errno; - } - gf_msg_debug(this->name, op_errno, - "Unlink: subvolume %s returned -1" - " with errno = %d", - prev->name, op_errno); - goto unlock; - } - - local->op_ret = 0; - - local->postparent = *postparent; - local->preparent = *preparent; - - if (local->loc.parent) { - dht_inode_ctx_time_update(local->loc.parent, this, - &local->preparent, 0); - dht_inode_ctx_time_update(local->loc.parent, this, - &local->postparent, 1); - } - } -unlock: - UNLOCK(&frame->lock); - - if (local->op_ret) - goto out; - - if (cold_tier != local->cached_subvol) { - /* - * File is present in hot tier, so there will be - * a link file on cold tier, deleting the linkfile - * from cold tier - */ - STACK_WIND_COOKIE(frame, tier_unlink_linkfile_cbk, cold_tier, cold_tier, - cold_tier->fops->unlink, &local->loc, local->flags, - xdata); - return 0; - } - - ret = dict_get_bin(xdata, DHT_IATT_IN_XDATA_KEY, (void **)&stbuf); - if (!ret && stbuf && - ((IS_DHT_MIGRATION_PHASE2(stbuf)) || IS_DHT_MIGRATION_PHASE1(stbuf))) { - /* - * File is migrating from cold to hot tier. - * Delete the destination linkfile. - */ - STACK_WIND_COOKIE(frame, tier_unlink_lookup_cbk, hot_tier, hot_tier, - hot_tier->fops->lookup, &local->loc, NULL); - return 0; - } - -out: - DHT_STACK_UNWIND(unlink, frame, local->op_ret, local->op_errno, - &local->preparent, &local->postparent, xdata); - - return 0; -} - -int -tier_unlink(call_frame_t *frame, xlator_t *this, loc_t *loc, int xflag, - dict_t *xdata) -{ - xlator_t *cached_subvol = NULL; - xlator_t *hashed_subvol = NULL; - dht_conf_t *conf = NULL; - int op_errno = -1; - dht_local_t *local = NULL; - int ret = -1; - - VALIDATE_OR_GOTO(frame, err); - VALIDATE_OR_GOTO(this, err); - VALIDATE_OR_GOTO(loc, err); - - conf = this->private; - - local = dht_local_init(frame, loc, NULL, GF_FOP_UNLINK); - if (!local) { - op_errno = ENOMEM; - - goto err; - } - - hashed_subvol = TIER_HASHED_SUBVOL; - - cached_subvol = local->cached_subvol; - if (!cached_subvol) { - gf_msg_debug(this->name, 0, "no cached subvolume for path=%s", - loc->path); - op_errno = EINVAL; - goto err; - } - - local->flags = xflag; - if (IA_ISREG(loc->inode->ia_type) && (hashed_subvol == cached_subvol)) { - /* - * File resides in cold tier. We need to stat - * the file to see if it is being promoted. - * If yes we need to delete the destination - * file as well. - * - * Currently we are doing this check only for - * regular files. - */ - xdata = xdata ? dict_ref(xdata) : dict_new(); - if (xdata) { - ret = dict_set_int8(xdata, DHT_IATT_IN_XDATA_KEY, 1); - if (ret) { - gf_msg_debug(this->name, 0, "Failed to set dictionary key %s", - DHT_IATT_IN_XDATA_KEY); - } - } - } - - /* - * File is on hot tier, delete the data file first, then - * linkfile from cold. - */ - STACK_WIND_COOKIE(frame, tier_unlink_cbk, cached_subvol, cached_subvol, - cached_subvol->fops->unlink, loc, xflag, xdata); - if (xdata) - dict_unref(xdata); - return 0; -err: - op_errno = (op_errno == -1) ? errno : op_errno; - DHT_STACK_UNWIND(unlink, frame, -1, op_errno, NULL, NULL, NULL); - - return 0; -} - -int -tier_readdir_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret, - int op_errno, gf_dirent_t *orig_entries, dict_t *xdata) -{ - gf_dirent_t entries; - gf_dirent_t *orig_entry = NULL; - gf_dirent_t *entry = NULL; - int count = 0; - - INIT_LIST_HEAD(&entries.list); - - if (op_ret < 0) - goto unwind; - - list_for_each_entry(orig_entry, (&orig_entries->list), list) - { - entry = gf_dirent_for_name(orig_entry->d_name); - if (!entry) { - gf_msg(this->name, GF_LOG_ERROR, ENOMEM, DHT_MSG_NO_MEMORY, - "Memory allocation failed "); - goto unwind; - } - - entry->d_off = orig_entry->d_off; - entry->d_ino = orig_entry->d_ino; - entry->d_type = orig_entry->d_type; - entry->d_len = orig_entry->d_len; - - list_add_tail(&entry->list, &entries.list); - count++; - } - op_ret = count; - -unwind: - if (op_ret < 0) - op_ret = 0; - - DHT_STACK_UNWIND(readdir, frame, op_ret, op_errno, &entries, NULL); - - gf_dirent_free(&entries); - - return 0; -} - -int -tier_readdirp_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret, - int op_errno, gf_dirent_t *orig_entries, dict_t *xdata) -{ - dht_local_t *local = NULL; - gf_dirent_t entries; - gf_dirent_t *orig_entry = NULL; - gf_dirent_t *entry = NULL; - xlator_t *prev = NULL; - xlator_t *next_subvol = NULL; - off_t next_offset = 0; - int count = 0; - dht_conf_t *conf = NULL; - int ret = 0; - inode_table_t *itable = NULL; - inode_t *inode = NULL; - - INIT_LIST_HEAD(&entries.list); - prev = cookie; - local = frame->local; - itable = local->fd ? local->fd->inode->table : NULL; - - conf = this->private; - GF_VALIDATE_OR_GOTO(this->name, conf, unwind); - - if (op_ret < 0) - goto done; - - list_for_each_entry(orig_entry, (&orig_entries->list), list) - { - next_offset = orig_entry->d_off; - - if (IA_ISINVAL(orig_entry->d_stat.ia_type)) { - /*stat failed somewhere- ignore this entry*/ - continue; - } - - entry = gf_dirent_for_name(orig_entry->d_name); - if (!entry) { - goto unwind; - } - - entry->d_off = orig_entry->d_off; - entry->d_stat = orig_entry->d_stat; - entry->d_ino = orig_entry->d_ino; - entry->d_type = orig_entry->d_type; - entry->d_len = orig_entry->d_len; - - if (orig_entry->dict) - entry->dict = dict_ref(orig_entry->dict); - - if (check_is_linkfile(NULL, (&orig_entry->d_stat), orig_entry->dict, - conf->link_xattr_name)) { - goto entries; - - } else if (IA_ISDIR(entry->d_stat.ia_type)) { - if (orig_entry->inode) { - dht_inode_ctx_time_update(orig_entry->inode, this, - &entry->d_stat, 1); - } - } else { - if (orig_entry->inode) { - ret = dht_layout_preset(this, prev, orig_entry->inode); - if (ret) - gf_msg(this->name, GF_LOG_WARNING, 0, - DHT_MSG_LAYOUT_SET_FAILED, - "failed to link the layout " - "in inode"); - - entry->inode = inode_ref(orig_entry->inode); - } else if (itable) { - /* - * orig_entry->inode might be null if any upper - * layer xlators below client set to null, to - * force a lookup on the inode even if the inode - * is present in the inode table. In that case - * we just update the ctx to make sure we didn't - * missed anything. - */ - inode = inode_find(itable, orig_entry->d_stat.ia_gfid); - if (inode) { - ret = dht_layout_preset(this, TIER_HASHED_SUBVOL, inode); - if (ret) - gf_msg(this->name, GF_LOG_WARNING, 0, - DHT_MSG_LAYOUT_SET_FAILED, - "failed to link the layout" - " in inode"); - inode_unref(inode); - inode = NULL; - } - } - } - - entries: - list_add_tail(&entry->list, &entries.list); - count++; - } - op_ret = count; - -done: - if (count == 0) { - /* non-zero next_offset means that - EOF is not yet hit on the current subvol - */ - if (next_offset != 0) { - next_subvol = prev; - } else { - goto unwind; - } - - STACK_WIND_COOKIE(frame, tier_readdirp_cbk, next_subvol, next_subvol, - next_subvol->fops->readdirp, local->fd, local->size, - next_offset, local->xattr); - return 0; - } - -unwind: - if (op_ret < 0) - op_ret = 0; - - DHT_STACK_UNWIND(readdirp, frame, op_ret, op_errno, &entries, NULL); - - gf_dirent_free(&entries); - - return 0; -} - -int -tier_do_readdir(call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, - off_t yoff, int whichop, dict_t *dict) -{ - dht_local_t *local = NULL; - int op_errno = -1; - xlator_t *hashed_subvol = NULL; - int ret = 0; - dht_conf_t *conf = NULL; - - VALIDATE_OR_GOTO(frame, err); - VALIDATE_OR_GOTO(this, err); - VALIDATE_OR_GOTO(fd, err); - VALIDATE_OR_GOTO(this->private, err); - - conf = this->private; - - local = dht_local_init(frame, NULL, NULL, whichop); - if (!local) { - op_errno = ENOMEM; - goto err; - } - - local->fd = fd_ref(fd); - local->size = size; - local->xattr_req = (dict) ? dict_ref(dict) : NULL; - - hashed_subvol = TIER_HASHED_SUBVOL; - - /* TODO: do proper readdir */ - if (whichop == GF_FOP_READDIRP) { - if (dict) - local->xattr = dict_ref(dict); - else - local->xattr = dict_new(); - - if (local->xattr) { - ret = dict_set_uint32(local->xattr, conf->link_xattr_name, 256); - if (ret) - gf_msg(this->name, GF_LOG_WARNING, 0, DHT_MSG_DICT_SET_FAILED, - "Failed to set dictionary value" - " : key = %s", - conf->link_xattr_name); - } - - STACK_WIND_COOKIE(frame, tier_readdirp_cbk, hashed_subvol, - hashed_subvol, hashed_subvol->fops->readdirp, fd, - size, yoff, local->xattr); - - } else { - STACK_WIND_COOKIE(frame, tier_readdir_cbk, hashed_subvol, hashed_subvol, - hashed_subvol->fops->readdir, fd, size, yoff, - local->xattr); - } - - return 0; - -err: - op_errno = (op_errno == -1) ? errno : op_errno; - DHT_STACK_UNWIND(readdir, frame, -1, op_errno, NULL, NULL); - - return 0; -} - -int -tier_readdir(call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, - off_t yoff, dict_t *xdata) -{ - int op = GF_FOP_READDIR; - dht_conf_t *conf = NULL; - int i = 0; - - conf = this->private; - if (!conf) - goto out; - - for (i = 0; i < conf->subvolume_cnt; i++) { - if (!conf->subvolume_status[i]) { - op = GF_FOP_READDIRP; - break; - } - } - - if (conf->use_readdirp) - op = GF_FOP_READDIRP; - -out: - tier_do_readdir(frame, this, fd, size, yoff, op, 0); - return 0; -} - -int -tier_readdirp(call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, - off_t yoff, dict_t *dict) -{ - tier_do_readdir(frame, this, fd, size, yoff, GF_FOP_READDIRP, dict); - return 0; -} - -int -tier_statfs_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret, - int op_errno, struct statvfs *statvfs, dict_t *xdata) -{ - gf_boolean_t event = _gf_false; - qdstatfs_action_t action = qdstatfs_action_OFF; - dht_local_t *local = NULL; - int this_call_cnt = 0; - int bsize = 0; - int frsize = 0; - GF_UNUSED int ret = 0; - unsigned long new_usage = 0; - unsigned long cur_usage = 0; - xlator_t *prev = NULL; - dht_conf_t *conf = NULL; - tier_statvfs_t *tier_stat = NULL; - - prev = cookie; - local = frame->local; - GF_ASSERT(local); - - conf = this->private; - - if (xdata) - ret = dict_get_int8(xdata, "quota-deem-statfs", (int8_t *)&event); - - tier_stat = &local->tier_statvfs; - - LOCK(&frame->lock); - { - if (op_ret == -1) { - local->op_errno = op_errno; - goto unlock; - } - if (!statvfs) { - op_errno = EINVAL; - local->op_ret = -1; - goto unlock; - } - local->op_ret = 0; - - if (local->quota_deem_statfs) { - if (event == _gf_true) { - action = qdstatfs_action_COMPARE; - } else { - action = qdstatfs_action_NEGLECT; - } - } else { - if (event == _gf_true) { - action = qdstatfs_action_REPLACE; - local->quota_deem_statfs = _gf_true; - } - } - - if (local->quota_deem_statfs) { - switch (action) { - case qdstatfs_action_NEGLECT: - goto unlock; - - case qdstatfs_action_REPLACE: - local->statvfs = *statvfs; - goto unlock; - - case qdstatfs_action_COMPARE: - new_usage = statvfs->f_blocks - statvfs->f_bfree; - cur_usage = local->statvfs.f_blocks - - local->statvfs.f_bfree; - - /* Take the max of the usage from subvols */ - if (new_usage >= cur_usage) - local->statvfs = *statvfs; - goto unlock; - - default: - break; - } - } - - if (local->statvfs.f_bsize != 0) { - bsize = max(local->statvfs.f_bsize, statvfs->f_bsize); - frsize = max(local->statvfs.f_frsize, statvfs->f_frsize); - dht_normalize_stats(&local->statvfs, bsize, frsize); - dht_normalize_stats(statvfs, bsize, frsize); - } else { - local->statvfs.f_bsize = statvfs->f_bsize; - local->statvfs.f_frsize = statvfs->f_frsize; - } - - if (prev == TIER_HASHED_SUBVOL) { - local->statvfs.f_blocks = statvfs->f_blocks; - local->statvfs.f_files = statvfs->f_files; - local->statvfs.f_fsid = statvfs->f_fsid; - local->statvfs.f_flag = statvfs->f_flag; - local->statvfs.f_namemax = statvfs->f_namemax; - tier_stat->blocks_used = (statvfs->f_blocks - statvfs->f_bfree); - tier_stat->pblocks_used = (statvfs->f_blocks - statvfs->f_bavail); - tier_stat->files_used = (statvfs->f_files - statvfs->f_ffree); - tier_stat->pfiles_used = (statvfs->f_files - statvfs->f_favail); - tier_stat->hashed_fsid = statvfs->f_fsid; - } else { - tier_stat->unhashed_fsid = statvfs->f_fsid; - tier_stat->unhashed_blocks_used = (statvfs->f_blocks - - statvfs->f_bfree); - tier_stat->unhashed_pblocks_used = (statvfs->f_blocks - - statvfs->f_bavail); - tier_stat->unhashed_files_used = (statvfs->f_files - - statvfs->f_ffree); - tier_stat->unhashed_pfiles_used = (statvfs->f_files - - statvfs->f_favail); - } - } -unlock: - UNLOCK(&frame->lock); - - this_call_cnt = dht_frame_return(frame); - if (is_last_call(this_call_cnt)) { - if (tier_stat->unhashed_fsid != tier_stat->hashed_fsid) { - tier_stat->blocks_used += tier_stat->unhashed_blocks_used; - tier_stat->pblocks_used += tier_stat->unhashed_pblocks_used; - tier_stat->files_used += tier_stat->unhashed_files_used; - tier_stat->pfiles_used += tier_stat->unhashed_pfiles_used; - } - local->statvfs.f_bfree = local->statvfs.f_blocks - - tier_stat->blocks_used; - local->statvfs.f_bavail = local->statvfs.f_blocks - - tier_stat->pblocks_used; - local->statvfs.f_ffree = local->statvfs.f_files - tier_stat->files_used; - local->statvfs.f_favail = local->statvfs.f_files - - tier_stat->pfiles_used; - DHT_STACK_UNWIND(statfs, frame, local->op_ret, local->op_errno, - &local->statvfs, xdata); - } - - return 0; -} - -int -tier_statfs(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata) -{ - dht_local_t *local = NULL; - dht_conf_t *conf = NULL; - int op_errno = -1; - int i = -1; - inode_t *inode = NULL; - inode_table_t *itable = NULL; - uuid_t root_gfid = { - 0, - }; - loc_t newloc = { - 0, - }; - - VALIDATE_OR_GOTO(frame, err); - VALIDATE_OR_GOTO(this, err); - VALIDATE_OR_GOTO(loc, err); - VALIDATE_OR_GOTO(this->private, err); - - conf = this->private; - - local = dht_local_init(frame, NULL, NULL, GF_FOP_STATFS); - if (!local) { - op_errno = ENOMEM; - goto err; - } - - if (loc->inode && !IA_ISDIR(loc->inode->ia_type)) { - itable = loc->inode->table; - if (!itable) { - op_errno = EINVAL; - goto err; - } - - loc = &local->loc2; - root_gfid[15] = 1; - - inode = inode_find(itable, root_gfid); - if (!inode) { - op_errno = EINVAL; - goto err; - } - - dht_build_root_loc(inode, &newloc); - loc = &newloc; - } - - local->call_cnt = conf->subvolume_cnt; - - for (i = 0; i < conf->subvolume_cnt; i++) { - STACK_WIND_COOKIE(frame, tier_statfs_cbk, conf->subvolumes[i], - conf->subvolumes[i], - conf->subvolumes[i]->fops->statfs, loc, xdata); - } - - return 0; - -err: - op_errno = (op_errno == -1) ? errno : op_errno; - DHT_STACK_UNWIND(statfs, frame, -1, op_errno, NULL, NULL); - - return 0; -} diff --git a/xlators/cluster/dht/src/tier-common.h b/xlators/cluster/dht/src/tier-common.h deleted file mode 100644 index b1ebaa8004d..00000000000 --- a/xlators/cluster/dht/src/tier-common.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - Copyright (c) 2015 Red Hat, Inc. - This file is part of GlusterFS. - - 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 _TIER_COMMON_H_ -#define _TIER_COMMON_H_ -/* Function definitions */ -int -tier_create_unlink_stale_linkto_cbk(call_frame_t *frame, void *cookie, - xlator_t *this, int op_ret, int op_errno, - struct iatt *preparent, - struct iatt *postparent, dict_t *xdata); - -int -tier_create_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret, - int op_errno, fd_t *fd, inode_t *inode, struct iatt *stbuf, - struct iatt *preparent, struct iatt *postparent, dict_t *xdata); - -int -tier_create_linkfile_create_cbk(call_frame_t *frame, void *cookie, - xlator_t *this, int32_t op_ret, - int32_t op_errno, inode_t *inode, - struct iatt *stbuf, struct iatt *preparent, - struct iatt *postparent, dict_t *xdata); - -int -tier_create(call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags, - mode_t mode, mode_t umask, fd_t *fd, dict_t *params); - -int32_t -tier_unlink(call_frame_t *frame, xlator_t *this, loc_t *loc, int xflag, - dict_t *xdata); - -int32_t -tier_readdirp(call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, - off_t off, dict_t *dict); - -int -tier_readdir(call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, - off_t yoff, dict_t *xdata); - -int -tier_link(call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc, - dict_t *xdata); - -int -tier_statfs(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata); - -#endif diff --git a/xlators/cluster/dht/src/tier.c b/xlators/cluster/dht/src/tier.c deleted file mode 100644 index a8cccaf019e..00000000000 --- a/xlators/cluster/dht/src/tier.c +++ /dev/null @@ -1,3090 +0,0 @@ -/* - Copyright (c) 2015 Red Hat, Inc. - This file is part of GlusterFS. - - 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. -*/ - -#include - -#include "dht-common.h" -#include "tier.h" -#include "tier-common.h" -#include -#include -#include "tier-ctr-interface.h" - -/*Hard coded DB info*/ -static gfdb_db_type_t dht_tier_db_type = GFDB_SQLITE3; -/*Hard coded DB info*/ - -/*Mutex for updating the data movement stats*/ -static pthread_mutex_t dm_stat_mutex = PTHREAD_MUTEX_INITIALIZER; - -/* Stores the path location of promotion query files */ -static char *promotion_qfile; -/* Stores the path location of demotion query files */ -static char *demotion_qfile; - -static void *libhandle; -static gfdb_methods_t gfdb_methods; - -#define DB_QUERY_RECORD_SIZE 4096 - -/* - * Closes all the fds and frees the qfile_array - * */ -static void -qfile_array_free(tier_qfile_array_t *qfile_array) -{ - ssize_t i = 0; - - if (qfile_array) { - if (qfile_array->fd_array) { - for (i = 0; i < qfile_array->array_size; i++) { - if (qfile_array->fd_array[i] != -1) { - sys_close(qfile_array->fd_array[i]); - } - } - } - GF_FREE(qfile_array->fd_array); - } - GF_FREE(qfile_array); -} - -/* Create a new query file list with given size */ -static tier_qfile_array_t * -qfile_array_new(ssize_t array_size) -{ - int ret = -1; - tier_qfile_array_t *qfile_array = NULL; - ssize_t i = 0; - - GF_VALIDATE_OR_GOTO("tier", (array_size > 0), out); - - qfile_array = GF_CALLOC(1, sizeof(tier_qfile_array_t), - gf_tier_mt_qfile_array_t); - if (!qfile_array) { - gf_msg("tier", GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "Failed to allocate memory for tier_qfile_array_t"); - goto out; - } - - qfile_array->fd_array = GF_MALLOC(array_size * sizeof(int), - gf_dht_mt_int32_t); - if (!qfile_array->fd_array) { - gf_msg("tier", GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "Failed to allocate memory for " - "tier_qfile_array_t->fd_array"); - goto out; - } - - /* Init all the fds to -1 */ - for (i = 0; i < array_size; i++) { - qfile_array->fd_array[i] = -1; - } - - qfile_array->array_size = array_size; - qfile_array->next_index = 0; - - /* Set exhausted count to list size as the list is empty */ - qfile_array->exhausted_count = qfile_array->array_size; - - ret = 0; -out: - if (ret) { - qfile_array_free(qfile_array); - qfile_array = NULL; - } - return qfile_array; -} - -/* Checks if the query file list is empty or totally exhausted. */ -static gf_boolean_t -is_qfile_array_empty(tier_qfile_array_t *qfile_array) -{ - return (qfile_array->exhausted_count == qfile_array->array_size) - ? _gf_true - : _gf_false; -} - -/* Shifts the next_fd pointer to the next available fd in the list */ -static void -shift_next_index(tier_qfile_array_t *qfile_array) -{ - int qfile_fd = 0; - int spin_count = 0; - - if (is_qfile_array_empty(qfile_array)) { - return; - } - - do { - /* change next_index in a rotional manner */ - (qfile_array->next_index == (qfile_array->array_size - 1)) - ? qfile_array->next_index = 0 - : qfile_array->next_index++; - - qfile_fd = (qfile_array->fd_array[qfile_array->next_index]); - - spin_count++; - - } while ((qfile_fd == -1) && (spin_count < qfile_array->array_size)); -} - -/* - * This is a non-thread safe function to read query records - * from a list of query files in a Round-Robin manner. - * As in when the query files get exhuasted they are closed. - * Returns: - * 0 if all the query records in all the query files of the list are - * exhausted. - * > 0 if a query record is successfully read. Indicates the size of the query - * record read. - * < 0 if there was failure - * */ -static int -read_query_record_list(tier_qfile_array_t *qfile_array, - gfdb_query_record_t **query_record) -{ - int ret = -1; - int qfile_fd = 0; - - GF_VALIDATE_OR_GOTO("tier", qfile_array, out); - GF_VALIDATE_OR_GOTO("tier", qfile_array->fd_array, out); - - do { - if (is_qfile_array_empty(qfile_array)) { - ret = 0; - break; - } - - qfile_fd = qfile_array->fd_array[qfile_array->next_index]; - ret = gfdb_methods.gfdb_read_query_record(qfile_fd, query_record); - if (ret <= 0) { - /*The qfile_fd has reached EOF or - * there was an error. - * 1. Close the exhausted fd - * 2. increment the exhausted count - * 3. shift next_qfile to next qfile - **/ - sys_close(qfile_fd); - qfile_array->fd_array[qfile_array->next_index] = -1; - qfile_array->exhausted_count++; - /* shift next_qfile to next qfile */ - shift_next_index(qfile_array); - continue; - } else { - /* shift next_qfile to next qfile */ - shift_next_index(qfile_array); - break; - } - } while (1); -out: - return ret; -} - -/* Check and update the watermark every WM_INTERVAL seconds */ -#define WM_INTERVAL 5 -#define WM_INTERVAL_EMERG 1 - -static int -tier_check_same_node(xlator_t *this, loc_t *loc, gf_defrag_info_t *defrag) -{ - int ret = -1; - dict_t *dict = NULL; - char *uuid_str = NULL; - uuid_t node_uuid = { - 0, - }; - - GF_VALIDATE_OR_GOTO("tier", this, out); - GF_VALIDATE_OR_GOTO(this->name, loc, out); - GF_VALIDATE_OR_GOTO(this->name, defrag, out); - - if (syncop_getxattr(this, loc, &dict, GF_XATTR_NODE_UUID_KEY, NULL, NULL)) { - gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "Unable to get NODE_UUID_KEY %s %s\n", loc->name, loc->path); - goto out; - } - - if (dict_get_str(dict, GF_XATTR_NODE_UUID_KEY, &uuid_str) < 0) { - gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "Failed to get node-uuids for %s", loc->path); - goto out; - } - - if (gf_uuid_parse(uuid_str, node_uuid)) { - gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "uuid_parse failed for %s", loc->path); - goto out; - } - - if (gf_uuid_compare(node_uuid, defrag->node_uuid)) { - gf_msg_debug(this->name, 0, "%s does not belong to this node", - loc->path); - ret = 1; - goto out; - } - - ret = 0; -out: - if (dict) - dict_unref(dict); - - return ret; -} - -int -tier_get_fs_stat(xlator_t *this, loc_t *root_loc) -{ - int ret = 0; - gf_defrag_info_t *defrag = NULL; - dht_conf_t *conf = NULL; - dict_t *xdata = NULL; - struct statvfs statfs = { - 0, - }; - gf_tier_conf_t *tier_conf = NULL; - - conf = this->private; - if (!conf) { - gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_STATUS, - "conf is NULL"); - ret = -1; - goto exit; - } - - defrag = conf->defrag; - if (!defrag) { - gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_STATUS, - "defrag is NULL"); - ret = -1; - goto exit; - } - - tier_conf = &defrag->tier_conf; - - xdata = dict_new(); - if (!xdata) { - gf_msg(this->name, GF_LOG_ERROR, ENOMEM, DHT_MSG_NO_MEMORY, - "failed to allocate dictionary"); - ret = -1; - goto exit; - } - - ret = dict_set_int8(xdata, GF_INTERNAL_IGNORE_DEEM_STATFS, 1); - if (ret) { - gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_DICT_SET_FAILED, - "Failed to set " GF_INTERNAL_IGNORE_DEEM_STATFS " in dict"); - ret = -1; - goto exit; - } - - /* Find how much free space is on the hot subvolume. - * Then see if that value */ - /* is less than or greater than user defined watermarks. - * Stash results in */ - /* the tier_conf data structure. */ - - ret = syncop_statfs(conf->subvolumes[1], root_loc, &statfs, xdata, NULL); - if (ret) { - gf_msg(this->name, GF_LOG_ERROR, -ret, DHT_MSG_LOG_TIER_STATUS, - "Unable to obtain statfs."); - goto exit; - } - - pthread_mutex_lock(&dm_stat_mutex); - - tier_conf->block_size = statfs.f_bsize; - tier_conf->blocks_total = statfs.f_blocks; - tier_conf->blocks_used = statfs.f_blocks - statfs.f_bfree; - - tier_conf->percent_full = GF_PERCENTAGE(tier_conf->blocks_used, - statfs.f_blocks); - pthread_mutex_unlock(&dm_stat_mutex); - -exit: - if (xdata) - dict_unref(xdata); - return ret; -} - -static void -tier_send_watermark_event(const char *volname, tier_watermark_op_t old_wm, - tier_watermark_op_t new_wm) -{ - if (old_wm == TIER_WM_LOW || old_wm == TIER_WM_NONE) { - if (new_wm == TIER_WM_MID) { - gf_event(EVENT_TIER_WATERMARK_RAISED_TO_MID, "vol=%s", volname); - } else if (new_wm == TIER_WM_HI) { - gf_event(EVENT_TIER_WATERMARK_HI, "vol=%s", volname); - } - } else if (old_wm == TIER_WM_MID) { - if (new_wm == TIER_WM_LOW) { - gf_event(EVENT_TIER_WATERMARK_DROPPED_TO_LOW, "vol=%s", volname); - } else if (new_wm == TIER_WM_HI) { - gf_event(EVENT_TIER_WATERMARK_HI, "vol=%s", volname); - } - } else if (old_wm == TIER_WM_HI) { - if (new_wm == TIER_WM_MID) { - gf_event(EVENT_TIER_WATERMARK_DROPPED_TO_MID, "vol=%s", volname); - } else if (new_wm == TIER_WM_LOW) { - gf_event(EVENT_TIER_WATERMARK_DROPPED_TO_LOW, "vol=%s", volname); - } - } -} - -int -tier_check_watermark(xlator_t *this) -{ - int ret = -1; - gf_defrag_info_t *defrag = NULL; - dht_conf_t *conf = NULL; - gf_tier_conf_t *tier_conf = NULL; - tier_watermark_op_t wm = TIER_WM_NONE; - - conf = this->private; - if (!conf) - goto exit; - - defrag = conf->defrag; - if (!defrag) - goto exit; - - tier_conf = &defrag->tier_conf; - - if (tier_conf->percent_full < tier_conf->watermark_low) { - wm = TIER_WM_LOW; - - } else if (tier_conf->percent_full < tier_conf->watermark_hi) { - wm = TIER_WM_MID; - - } else { - wm = TIER_WM_HI; - } - - if (wm != tier_conf->watermark_last) { - tier_send_watermark_event(tier_conf->volname, tier_conf->watermark_last, - wm); - - tier_conf->watermark_last = wm; - gf_msg(this->name, GF_LOG_INFO, 0, DHT_MSG_LOG_TIER_STATUS, - "Tier watermark now %d", wm); - } - - ret = 0; - -exit: - return ret; -} - -static gf_boolean_t -is_hot_tier_full(gf_tier_conf_t *tier_conf) -{ - if (tier_conf && (tier_conf->mode == TIER_MODE_WM) && - (tier_conf->watermark_last == TIER_WM_HI)) - return _gf_true; - - return _gf_false; -} - -int -tier_do_migration(xlator_t *this, int promote) -{ - gf_defrag_info_t *defrag = NULL; - dht_conf_t *conf = NULL; - long rand = 0; - int migrate = 0; - gf_tier_conf_t *tier_conf = NULL; - - conf = this->private; - if (!conf) - goto exit; - - defrag = conf->defrag; - if (!defrag) - goto exit; - - if (tier_check_watermark(this) != 0) { - gf_msg(this->name, GF_LOG_CRITICAL, errno, DHT_MSG_LOG_TIER_ERROR, - "Failed to get watermark"); - goto exit; - } - - tier_conf = &defrag->tier_conf; - - switch (tier_conf->watermark_last) { - case TIER_WM_LOW: - migrate = promote ? 1 : 0; - break; - case TIER_WM_HI: - migrate = promote ? 0 : 1; - break; - case TIER_WM_MID: - /* coverity[DC.WEAK_CRYPTO] */ - rand = random() % 100; - if (promote) { - migrate = (rand > tier_conf->percent_full); - } else { - migrate = (rand <= tier_conf->percent_full); - } - break; - } - -exit: - return migrate; -} - -int -tier_migrate(xlator_t *this, int is_promotion, dict_t *migrate_data, loc_t *loc, - gf_tier_conf_t *tier_conf) -{ - int ret = -1; - - pthread_mutex_lock(&tier_conf->pause_mutex); - if (is_promotion) - tier_conf->promote_in_progress = 1; - else - tier_conf->demote_in_progress = 1; - pthread_mutex_unlock(&tier_conf->pause_mutex); - - /* Data migration */ - ret = syncop_setxattr(this, loc, migrate_data, 0, NULL, NULL); - - pthread_mutex_lock(&tier_conf->pause_mutex); - if (is_promotion) - tier_conf->promote_in_progress = 0; - else - tier_conf->demote_in_progress = 0; - pthread_mutex_unlock(&tier_conf->pause_mutex); - - return ret; -} - -/* returns _gf_true: if file can be promoted - * returns _gf_false: if file cannot be promoted - */ -static gf_boolean_t -tier_can_promote_file(xlator_t *this, char const *file_name, - struct iatt *current, gf_defrag_info_t *defrag) -{ - gf_boolean_t ret = _gf_false; - fsblkcnt_t estimated_usage = 0; - - if (defrag->tier_conf.tier_max_promote_size && - (current->ia_size > defrag->tier_conf.tier_max_promote_size)) { - gf_msg(this->name, GF_LOG_INFO, 0, DHT_MSG_LOG_TIER_STATUS, - "File %s (gfid:%s) with size (%" PRIu64 - ") exceeds maxsize " - "(%d) for promotion. File will not be promoted.", - file_name, uuid_utoa(current->ia_gfid), current->ia_size, - defrag->tier_conf.tier_max_promote_size); - goto err; - } - - /* bypass further validations for TEST mode */ - if (defrag->tier_conf.mode != TIER_MODE_WM) { - ret = _gf_true; - goto err; - } - - /* convert the file size to blocks as per the block size of the - * destination tier - * NOTE: add (block_size - 1) to get the correct block size when - * there is a remainder after a modulo - */ - estimated_usage = ((current->ia_size + defrag->tier_conf.block_size - 1) / - defrag->tier_conf.block_size) + - defrag->tier_conf.blocks_used; - - /* test if the estimated block usage goes above HI watermark */ - if (GF_PERCENTAGE(estimated_usage, defrag->tier_conf.blocks_total) >= - defrag->tier_conf.watermark_hi) { - gf_msg(this->name, GF_LOG_INFO, 0, DHT_MSG_LOG_TIER_STATUS, - "Estimated block count consumption on " - "hot tier (%" PRIu64 - ") exceeds hi watermark (%d%%). " - "File will not be promoted.", - estimated_usage, defrag->tier_conf.watermark_hi); - goto err; - } - ret = _gf_true; -err: - return ret; -} - -static int -tier_set_migrate_data(dict_t *migrate_data) -{ - int failed = 1; - - failed = dict_set_str(migrate_data, GF_XATTR_FILE_MIGRATE_KEY, "force"); - if (failed) { - goto bail_out; - } - - /* Flag to suggest the xattr call is from migrator */ - failed = dict_set_str(migrate_data, "from.migrator", "yes"); - if (failed) { - goto bail_out; - } - - /* Flag to suggest its a tiering migration - * The reason for this dic key-value is that - * promotions and demotions are multithreaded - * so the original frame from gf_defrag_start() - * is not carried. A new frame will be created when - * we do syncop_setxattr(). This does not have the - * frame->root->pid of the original frame. So we pass - * this dic key-value when we do syncop_setxattr() to do - * data migration and set the frame->root->pid to - * GF_CLIENT_PID_TIER_DEFRAG in dht_setxattr() just before - * calling dht_start_rebalance_task() */ - failed = dict_set_str(migrate_data, TIERING_MIGRATION_KEY, "yes"); - if (failed) { - goto bail_out; - } - - failed = 0; - -bail_out: - return failed; -} - -static char * -tier_get_parent_path(xlator_t *this, loc_t *p_loc, struct iatt *par_stbuf, - int *per_link_status) -{ - int ret = -1; - char *parent_path = NULL; - dict_t *xdata_request = NULL; - dict_t *xdata_response = NULL; - - xdata_request = dict_new(); - if (!xdata_request) { - gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "Failed to create xdata_request dict"); - goto err; - } - ret = dict_set_int32(xdata_request, GET_ANCESTRY_PATH_KEY, 42); - if (ret) { - gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "Failed to set value to dict : key %s \n", - GET_ANCESTRY_PATH_KEY); - goto err; - } - - ret = syncop_lookup(this, p_loc, par_stbuf, NULL, xdata_request, - &xdata_response); - /* When the parent gfid is a stale entry, the lookup - * will fail and stop the demotion process. - * The parent gfid can be stale when a huge folder is - * deleted while the files within it are being migrated - */ - if (ret == -ESTALE) { - gf_msg(this->name, GF_LOG_WARNING, -ret, DHT_MSG_STALE_LOOKUP, - "Stale entry in parent lookup for %s", uuid_utoa(p_loc->gfid)); - *per_link_status = 1; - goto err; - } else if (ret) { - gf_msg(this->name, GF_LOG_ERROR, -ret, DHT_MSG_LOG_TIER_ERROR, - "Error in parent lookup for %s", uuid_utoa(p_loc->gfid)); - *per_link_status = -1; - goto err; - } - ret = dict_get_str(xdata_response, GET_ANCESTRY_PATH_KEY, &parent_path); - if (ret || !parent_path) { - gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "Failed to get parent path for %s", uuid_utoa(p_loc->gfid)); - *per_link_status = -1; - goto err; - } - -err: - if (xdata_request) { - dict_unref(xdata_request); - } - - if (xdata_response) { - dict_unref(xdata_response); - xdata_response = NULL; - } - - return parent_path; -} - -static int -tier_get_file_name_and_path(xlator_t *this, uuid_t gfid, - gfdb_link_info_t *link_info, - char const *parent_path, loc_t *loc, - int *per_link_status) -{ - int ret = -1; - - loc->name = gf_strdup(link_info->file_name); - if (!loc->name) { - gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "Memory " - "allocation failed for %s", - uuid_utoa(gfid)); - *per_link_status = -1; - goto err; - } - ret = gf_asprintf((char **)&(loc->path), "%s/%s", parent_path, loc->name); - if (ret < 0) { - gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "Failed to " - "construct file path for %s %s\n", - parent_path, loc->name); - *per_link_status = -1; - goto err; - } - - ret = 0; - -err: - return ret; -} - -static int -tier_lookup_file(xlator_t *this, loc_t *p_loc, loc_t *loc, struct iatt *current, - int *per_link_status) -{ - int ret = -1; - - ret = syncop_lookup(this, loc, current, NULL, NULL, NULL); - - /* The file may be deleted even when the parent - * is available and the lookup will - * return a stale entry which would stop the - * migration. so if its a stale entry, then skip - * the file and keep migrating. - */ - if (ret == -ESTALE) { - gf_msg(this->name, GF_LOG_WARNING, -ret, DHT_MSG_STALE_LOOKUP, - "Stale lookup for %s", uuid_utoa(p_loc->gfid)); - *per_link_status = 1; - goto err; - } else if (ret) { - gf_msg(this->name, GF_LOG_ERROR, -ret, DHT_MSG_LOG_TIER_ERROR, - "Failed to " - "lookup file %s\n", - loc->name); - *per_link_status = -1; - goto err; - } - ret = 0; - -err: - return ret; -} - -static gf_boolean_t -tier_is_file_already_at_destination(xlator_t *src_subvol, - query_cbk_args_t *query_cbk_args, - dht_conf_t *conf, int *per_link_status) -{ - gf_boolean_t at_destination = _gf_true; - - if (src_subvol == NULL) { - *per_link_status = 1; - goto err; - } - if (query_cbk_args->is_promotion && src_subvol == conf->subvolumes[1]) { - *per_link_status = 1; - goto err; - } - - if (!query_cbk_args->is_promotion && src_subvol == conf->subvolumes[0]) { - *per_link_status = 1; - goto err; - } - at_destination = _gf_false; - -err: - return at_destination; -} - -static void -tier_update_migration_counters(query_cbk_args_t *query_cbk_args, - gf_defrag_info_t *defrag, - uint64_t *total_migrated_bytes, int *total_files) -{ - if (query_cbk_args->is_promotion) { - defrag->total_files_promoted++; - *total_migrated_bytes += defrag->tier_conf.st_last_promoted_size; - pthread_mutex_lock(&dm_stat_mutex); - defrag->tier_conf.blocks_used += defrag->tier_conf - .st_last_promoted_size; - pthread_mutex_unlock(&dm_stat_mutex); - } else { - defrag->total_files_demoted++; - *total_migrated_bytes += defrag->tier_conf.st_last_demoted_size; - pthread_mutex_lock(&dm_stat_mutex); - defrag->tier_conf.blocks_used -= defrag->tier_conf.st_last_demoted_size; - pthread_mutex_unlock(&dm_stat_mutex); - } - if (defrag->tier_conf.blocks_total) { - pthread_mutex_lock(&dm_stat_mutex); - defrag->tier_conf.percent_full = GF_PERCENTAGE( - defrag->tier_conf.blocks_used, defrag->tier_conf.blocks_total); - pthread_mutex_unlock(&dm_stat_mutex); - } - - (*total_files)++; -} - -static int -tier_migrate_link(xlator_t *this, dht_conf_t *conf, uuid_t gfid, - gfdb_link_info_t *link_info, gf_defrag_info_t *defrag, - query_cbk_args_t *query_cbk_args, dict_t *migrate_data, - int *per_link_status, int *total_files, - uint64_t *total_migrated_bytes) -{ - int ret = -1; - struct iatt current = { - 0, - }; - struct iatt par_stbuf = { - 0, - }; - loc_t p_loc = { - 0, - }; - loc_t loc = { - 0, - }; - xlator_t *src_subvol = NULL; - inode_t *linked_inode = NULL; - char *parent_path = NULL; - - /* Lookup for parent and get the path of parent */ - gf_uuid_copy(p_loc.gfid, link_info->pargfid); - p_loc.inode = inode_new(defrag->root_inode->table); - if (!p_loc.inode) { - gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "Failed to create reference to inode" - " for %s", - uuid_utoa(p_loc.gfid)); - - *per_link_status = -1; - goto err; - } - - parent_path = tier_get_parent_path(this, &p_loc, &par_stbuf, - per_link_status); - if (!parent_path) { - goto err; - } - - linked_inode = inode_link(p_loc.inode, NULL, NULL, &par_stbuf); - inode_unref(p_loc.inode); - p_loc.inode = linked_inode; - - /* Preparing File Inode */ - gf_uuid_copy(loc.gfid, gfid); - loc.inode = inode_new(defrag->root_inode->table); - gf_uuid_copy(loc.pargfid, link_info->pargfid); - loc.parent = inode_ref(p_loc.inode); - - /* Get filename and Construct file path */ - if (tier_get_file_name_and_path(this, gfid, link_info, parent_path, &loc, - per_link_status) != 0) { - goto err; - } - gf_uuid_copy(loc.parent->gfid, link_info->pargfid); - - /* lookup file inode */ - if (tier_lookup_file(this, &p_loc, &loc, ¤t, per_link_status) != 0) { - goto err; - } - - if (query_cbk_args->is_promotion) { - if (!tier_can_promote_file(this, link_info->file_name, ¤t, - defrag)) { - *per_link_status = 1; - goto err; - } - } - - linked_inode = inode_link(loc.inode, NULL, NULL, ¤t); - inode_unref(loc.inode); - loc.inode = linked_inode; - - /* - * Do not promote/demote if file already is where it - * should be. It means another brick moved the file - * so is not an error. So we set per_link_status = 1 - * so that we ignore counting this. - */ - src_subvol = dht_subvol_get_cached(this, loc.inode); - - if (tier_is_file_already_at_destination(src_subvol, query_cbk_args, conf, - per_link_status)) { - goto err; - } - - gf_msg_debug(this->name, 0, "Tier %s: src_subvol %s file %s", - (query_cbk_args->is_promotion ? "promote" : "demote"), - src_subvol->name, loc.path); - - ret = tier_check_same_node(this, &loc, defrag); - if (ret != 0) { - if (ret < 0) { - *per_link_status = -1; - goto err; - } - ret = 0; - /* By setting per_link_status to 1 we are - * ignoring this status and will not be counting - * this file for migration */ - *per_link_status = 1; - goto err; - } - - gf_uuid_copy(loc.gfid, loc.inode->gfid); - - if (gf_defrag_get_pause_state(&defrag->tier_conf) != TIER_RUNNING) { - gf_msg(this->name, GF_LOG_INFO, 0, DHT_MSG_LOG_TIER_STATUS, - "Tiering paused. " - "Exiting tier_migrate_link"); - goto err; - } - - ret = tier_migrate(this, query_cbk_args->is_promotion, migrate_data, &loc, - &defrag->tier_conf); - - if (ret) { - gf_msg(this->name, GF_LOG_ERROR, -ret, DHT_MSG_LOG_TIER_ERROR, - "Failed to " - "migrate %s ", - loc.path); - *per_link_status = -1; - goto err; - } - - tier_update_migration_counters(query_cbk_args, defrag, total_migrated_bytes, - total_files); - - ret = 0; - -err: - GF_FREE((char *)loc.name); - loc.name = NULL; - loc_wipe(&loc); - loc_wipe(&p_loc); - - if ((*total_files >= defrag->tier_conf.max_migrate_files) || - (*total_migrated_bytes > defrag->tier_conf.max_migrate_bytes)) { - gf_msg(this->name, GF_LOG_INFO, 0, DHT_MSG_LOG_TIER_STATUS, - "Reached cycle migration limit." - "migrated bytes %" PRId64 " files %d", - *total_migrated_bytes, *total_files); - ret = -1; - } - - return ret; -} - -static int -tier_migrate_using_query_file(void *_args) -{ - int ret = -1; - query_cbk_args_t *query_cbk_args = (query_cbk_args_t *)_args; - xlator_t *this = NULL; - gf_defrag_info_t *defrag = NULL; - gfdb_query_record_t *query_record = NULL; - gfdb_link_info_t *link_info = NULL; - dict_t *migrate_data = NULL; - /* - * per_file_status and per_link_status - * 0 : success - * -1 : failure - * 1 : ignore the status and don't count for migration - * */ - int per_file_status = 0; - int per_link_status = 0; - int total_status = 0; - dht_conf_t *conf = NULL; - uint64_t total_migrated_bytes = 0; - int total_files = 0; - loc_t root_loc = {0}; - gfdb_time_t start_time = {0}; - gfdb_time_t current_time = {0}; - int total_time = 0; - int max_time = 0; - gf_boolean_t emergency_demote_mode = _gf_false; - - GF_VALIDATE_OR_GOTO("tier", query_cbk_args, out); - GF_VALIDATE_OR_GOTO("tier", query_cbk_args->this, out); - this = query_cbk_args->this; - GF_VALIDATE_OR_GOTO(this->name, query_cbk_args->defrag, out); - GF_VALIDATE_OR_GOTO(this->name, query_cbk_args->qfile_array, out); - GF_VALIDATE_OR_GOTO(this->name, this->private, out); - - conf = this->private; - - defrag = query_cbk_args->defrag; - migrate_data = dict_new(); - if (!migrate_data) - goto out; - - emergency_demote_mode = (!query_cbk_args->is_promotion && - is_hot_tier_full(&defrag->tier_conf)); - - if (tier_set_migrate_data(migrate_data) != 0) { - goto out; - } - - dht_build_root_loc(defrag->root_inode, &root_loc); - - ret = gettimeofday(&start_time, NULL); - if (query_cbk_args->is_promotion) { - max_time = defrag->tier_conf.tier_promote_frequency; - } else { - max_time = defrag->tier_conf.tier_demote_frequency; - } - - /* Per file */ - while ((ret = read_query_record_list(query_cbk_args->qfile_array, - &query_record)) != 0) { - if (ret < 0) { - gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "Failed to fetch query record " - "from query file"); - goto out; - } - - if (defrag->defrag_status != GF_DEFRAG_STATUS_STARTED) { - ret = -1; - gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "Exiting tier migration as" - "defrag status is not started"); - goto out; - } - - ret = gettimeofday(¤t_time, NULL); - if (ret < 0) { - gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "Could not get current time."); - goto out; - } - - total_time = current_time.tv_sec - start_time.tv_sec; - if (total_time > max_time) { - gf_msg(this->name, GF_LOG_INFO, 0, DHT_MSG_LOG_TIER_STATUS, - "Max cycle time reached. Exiting migration."); - goto out; - } - - per_file_status = 0; - per_link_status = 0; - - if (gf_defrag_get_pause_state(&defrag->tier_conf) != TIER_RUNNING) { - gf_msg(this->name, GF_LOG_INFO, 0, DHT_MSG_LOG_TIER_STATUS, - "Tiering paused. " - "Exiting tier_migrate_using_query_file"); - break; - } - - if (defrag->tier_conf.mode == TIER_MODE_WM) { - ret = tier_get_fs_stat(this, &root_loc); - if (ret != 0) { - gfdb_methods.gfdb_query_record_free(query_record); - query_record = NULL; - gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_STATUS, - "tier_get_fs_stat() FAILED ... " - "skipping file migrations until next cycle"); - break; - } - - if (!tier_do_migration(this, query_cbk_args->is_promotion)) { - gfdb_methods.gfdb_query_record_free(query_record); - query_record = NULL; - - /* We have crossed the high watermark. Stop processing - * files if this is a promotion cycle so demotion gets - * a chance to start if not already running*/ - - if (query_cbk_args->is_promotion && - is_hot_tier_full(&defrag->tier_conf)) { - gf_msg(this->name, GF_LOG_INFO, 0, DHT_MSG_LOG_TIER_STATUS, - "High watermark crossed during " - "promotion. Exiting " - "tier_migrate_using_query_file"); - break; - } - continue; - } - } - - per_link_status = 0; - - /* For now we only support single link migration. And we will - * ignore other hard links in the link info list of query record - * TODO: Multiple hard links migration */ - if (!list_empty(&query_record->link_list)) { - link_info = list_first_entry(&query_record->link_list, - gfdb_link_info_t, list); - } - if (link_info != NULL) { - if (tier_migrate_link(this, conf, query_record->gfid, link_info, - defrag, query_cbk_args, migrate_data, - &per_link_status, &total_files, - &total_migrated_bytes) != 0) { - gf_msg( - this->name, GF_LOG_INFO, 0, DHT_MSG_LOG_TIER_STATUS, - "%s failed for %s(gfid:%s)", - (query_cbk_args->is_promotion ? "Promotion" : "Demotion"), - link_info->file_name, uuid_utoa(query_record->gfid)); - } - } - per_file_status = per_link_status; - - if (per_file_status < 0) { /* Failure */ - pthread_mutex_lock(&dm_stat_mutex); - defrag->total_failures++; - pthread_mutex_unlock(&dm_stat_mutex); - } else if (per_file_status == 0) { /* Success */ - pthread_mutex_lock(&dm_stat_mutex); - defrag->total_files++; - pthread_mutex_unlock(&dm_stat_mutex); - } else if (per_file_status == 1) { /* Ignore */ - per_file_status = 0; - /* Since this attempt was ignored we - * decrement the lookup count*/ - pthread_mutex_lock(&dm_stat_mutex); - defrag->num_files_lookedup--; - pthread_mutex_unlock(&dm_stat_mutex); - } - total_status = total_status + per_file_status; - per_link_status = 0; - per_file_status = 0; - - gfdb_methods.gfdb_query_record_free(query_record); - query_record = NULL; - - /* If we are demoting and the entry watermark was HI, then - * we are done with emergency demotions if the current - * watermark has fallen below hi-watermark level - */ - if (emergency_demote_mode) { - if (tier_check_watermark(this) == 0) { - if (!is_hot_tier_full(&defrag->tier_conf)) { - break; - } - } - } - } - -out: - if (migrate_data) - dict_unref(migrate_data); - - gfdb_methods.gfdb_query_record_free(query_record); - query_record = NULL; - - return total_status; -} - -/* This is the call back function per record/file from data base */ -static int -tier_gf_query_callback(gfdb_query_record_t *gfdb_query_record, void *_args) -{ - int ret = -1; - query_cbk_args_t *query_cbk_args = _args; - - GF_VALIDATE_OR_GOTO("tier", query_cbk_args, out); - GF_VALIDATE_OR_GOTO("tier", query_cbk_args->defrag, out); - GF_VALIDATE_OR_GOTO("tier", (query_cbk_args->query_fd > 0), out); - - ret = gfdb_methods.gfdb_write_query_record(query_cbk_args->query_fd, - gfdb_query_record); - if (ret) { - gf_msg("tier", GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "Failed writing query record to query file"); - goto out; - } - - pthread_mutex_lock(&dm_stat_mutex); - query_cbk_args->defrag->num_files_lookedup++; - pthread_mutex_unlock(&dm_stat_mutex); - - ret = 0; -out: - return ret; -} - -/* Create query file in tier process */ -static int -tier_process_self_query(tier_brick_list_t *local_brick, void *args) -{ - int ret = -1; - char *db_path = NULL; - query_cbk_args_t *query_cbk_args = NULL; - xlator_t *this = NULL; - gfdb_conn_node_t *conn_node = NULL; - dict_t *params_dict = NULL; - dict_t *ctr_ipc_dict = NULL; - gfdb_brick_info_t *gfdb_brick_info = args; - - /*Init of all the essentials*/ - GF_VALIDATE_OR_GOTO("tier", gfdb_brick_info, out); - query_cbk_args = gfdb_brick_info->_query_cbk_args; - - GF_VALIDATE_OR_GOTO("tier", query_cbk_args->this, out); - this = query_cbk_args->this; - - GF_VALIDATE_OR_GOTO(this->name, gfdb_brick_info->_query_cbk_args, out); - - GF_VALIDATE_OR_GOTO(this->name, local_brick, out); - - GF_VALIDATE_OR_GOTO(this->name, local_brick->xlator, out); - - GF_VALIDATE_OR_GOTO(this->name, local_brick->brick_db_path, out); - - db_path = local_brick->brick_db_path; - - /*Preparing DB parameters before init_db i.e getting db connection*/ - params_dict = dict_new(); - if (!params_dict) { - gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "DB Params cannot initialized"); - goto out; - } - SET_DB_PARAM_TO_DICT(this->name, params_dict, - (char *)gfdb_methods.get_db_path_key(), db_path, ret, - out); - - /*Get the db connection*/ - conn_node = gfdb_methods.init_db((void *)params_dict, dht_tier_db_type); - if (!conn_node) { - gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "FATAL: Failed initializing db operations"); - goto out; - } - - /* Query for eligible files from db */ - query_cbk_args->query_fd = open(local_brick->qfile_path, - O_WRONLY | O_CREAT | O_APPEND, - S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); - if (query_cbk_args->query_fd < 0) { - gf_msg(this->name, GF_LOG_ERROR, errno, DHT_MSG_LOG_TIER_ERROR, - "Failed to open query file %s", local_brick->qfile_path); - goto out; - } - if (!gfdb_brick_info->_gfdb_promote) { - if (query_cbk_args->defrag->tier_conf.watermark_last == TIER_WM_HI) { - /* emergency demotion mode */ - ret = gfdb_methods.find_all( - conn_node, tier_gf_query_callback, (void *)query_cbk_args, - query_cbk_args->defrag->tier_conf.query_limit); - } else { - if (query_cbk_args->defrag->write_freq_threshold == 0 && - query_cbk_args->defrag->read_freq_threshold == 0) { - ret = gfdb_methods.find_unchanged_for_time( - conn_node, tier_gf_query_callback, (void *)query_cbk_args, - gfdb_brick_info->time_stamp); - } else { - ret = gfdb_methods.find_unchanged_for_time_freq( - conn_node, tier_gf_query_callback, (void *)query_cbk_args, - gfdb_brick_info->time_stamp, - query_cbk_args->defrag->write_freq_threshold, - query_cbk_args->defrag->read_freq_threshold, _gf_false); - } - } - } else { - if (query_cbk_args->defrag->write_freq_threshold == 0 && - query_cbk_args->defrag->read_freq_threshold == 0) { - ret = gfdb_methods.find_recently_changed_files( - conn_node, tier_gf_query_callback, (void *)query_cbk_args, - gfdb_brick_info->time_stamp); - } else { - ret = gfdb_methods.find_recently_changed_files_freq( - conn_node, tier_gf_query_callback, (void *)query_cbk_args, - gfdb_brick_info->time_stamp, - query_cbk_args->defrag->write_freq_threshold, - query_cbk_args->defrag->read_freq_threshold, _gf_false); - } - } - if (ret) { - gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "FATAL: query from db failed"); - goto out; - } - - /*Clear the heat on the DB entries*/ - /*Preparing ctr_ipc_dict*/ - ctr_ipc_dict = dict_new(); - if (!ctr_ipc_dict) { - gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "ctr_ipc_dict cannot initialized"); - goto out; - } - - SET_DB_PARAM_TO_DICT(this->name, ctr_ipc_dict, GFDB_IPC_CTR_KEY, - GFDB_IPC_CTR_CLEAR_OPS, ret, out); - - ret = syncop_ipc(local_brick->xlator, GF_IPC_TARGET_CTR, ctr_ipc_dict, - NULL); - if (ret) { - gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "Failed clearing the heat " - "on db %s error %d", - local_brick->brick_db_path, ret); - goto out; - } - - ret = 0; -out: - if (params_dict) { - dict_unref(params_dict); - params_dict = NULL; - } - - if (ctr_ipc_dict) { - dict_unref(ctr_ipc_dict); - ctr_ipc_dict = NULL; - } - - if (query_cbk_args && query_cbk_args->query_fd >= 0) { - sys_close(query_cbk_args->query_fd); - query_cbk_args->query_fd = -1; - } - gfdb_methods.fini_db(conn_node); - - return ret; -} - -/*Ask CTR to create the query file*/ -static int -tier_process_ctr_query(tier_brick_list_t *local_brick, void *args) -{ - int ret = -1; - query_cbk_args_t *query_cbk_args = NULL; - xlator_t *this = NULL; - dict_t *ctr_ipc_in_dict = NULL; - dict_t *ctr_ipc_out_dict = NULL; - gfdb_brick_info_t *gfdb_brick_info = args; - gfdb_ipc_ctr_params_t *ipc_ctr_params = NULL; - int count = 0; - - /*Init of all the essentials*/ - GF_VALIDATE_OR_GOTO("tier", gfdb_brick_info, out); - query_cbk_args = gfdb_brick_info->_query_cbk_args; - - GF_VALIDATE_OR_GOTO("tier", query_cbk_args->this, out); - this = query_cbk_args->this; - - GF_VALIDATE_OR_GOTO(this->name, gfdb_brick_info->_query_cbk_args, out); - - GF_VALIDATE_OR_GOTO(this->name, local_brick, out); - - GF_VALIDATE_OR_GOTO(this->name, local_brick->xlator, out); - - GF_VALIDATE_OR_GOTO(this->name, local_brick->brick_db_path, out); - - /*Preparing ctr_ipc_in_dict*/ - ctr_ipc_in_dict = dict_new(); - if (!ctr_ipc_in_dict) { - gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "ctr_ipc_in_dict cannot initialized"); - goto out; - } - - ipc_ctr_params = GF_CALLOC(1, sizeof(gfdb_ipc_ctr_params_t), - gf_tier_mt_ipc_ctr_params_t); - if (!ipc_ctr_params) { - goto out; - } - - /* set all the query params*/ - ipc_ctr_params->is_promote = gfdb_brick_info->_gfdb_promote; - - ipc_ctr_params->write_freq_threshold = query_cbk_args->defrag - ->write_freq_threshold; - - ipc_ctr_params->read_freq_threshold = query_cbk_args->defrag - ->read_freq_threshold; - - ipc_ctr_params->query_limit = query_cbk_args->defrag->tier_conf.query_limit; - - ipc_ctr_params->emergency_demote = (!gfdb_brick_info->_gfdb_promote && - query_cbk_args->defrag->tier_conf - .watermark_last == TIER_WM_HI); - - memcpy(&ipc_ctr_params->time_stamp, gfdb_brick_info->time_stamp, - sizeof(gfdb_time_t)); - - SET_DB_PARAM_TO_DICT(this->name, ctr_ipc_in_dict, GFDB_IPC_CTR_KEY, - GFDB_IPC_CTR_QUERY_OPS, ret, out); - - SET_DB_PARAM_TO_DICT(this->name, ctr_ipc_in_dict, - GFDB_IPC_CTR_GET_QFILE_PATH, local_brick->qfile_path, - ret, out); - - ret = dict_set_bin(ctr_ipc_in_dict, GFDB_IPC_CTR_GET_QUERY_PARAMS, - ipc_ctr_params, sizeof(*ipc_ctr_params)); - if (ret) { - gf_msg(this->name, GF_LOG_ERROR, 0, LG_MSG_SET_PARAM_FAILED, - "Failed setting %s to params dictionary", - GFDB_IPC_CTR_GET_QUERY_PARAMS); - GF_FREE(ipc_ctr_params); - goto out; - } - ipc_ctr_params = NULL; - - ret = syncop_ipc(local_brick->xlator, GF_IPC_TARGET_CTR, ctr_ipc_in_dict, - &ctr_ipc_out_dict); - if (ret) { - gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_IPC_TIER_ERROR, - "Failed query on %s ret %d", local_brick->brick_db_path, ret); - goto out; - } - - ret = dict_get_int32(ctr_ipc_out_dict, GFDB_IPC_CTR_RET_QUERY_COUNT, - &count); - if (ret) { - gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "Failed getting count " - "of records on %s", - local_brick->brick_db_path); - goto out; - } - - if (count < 0) { - gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "Failed query on %s", local_brick->brick_db_path); - ret = -1; - goto out; - } - - pthread_mutex_lock(&dm_stat_mutex); - query_cbk_args->defrag->num_files_lookedup = count; - pthread_mutex_unlock(&dm_stat_mutex); - - ret = 0; -out: - - if (ctr_ipc_in_dict) { - dict_unref(ctr_ipc_in_dict); - ctr_ipc_in_dict = NULL; - } - - if (ctr_ipc_out_dict) { - dict_unref(ctr_ipc_out_dict); - ctr_ipc_out_dict = NULL; - } - - GF_FREE(ipc_ctr_params); - - return ret; -} - -/* This is the call back function for each brick from hot/cold bricklist - * It picks up each bricks db and queries for eligible files for migration. - * The list of eligible files are populated in appropriate query files*/ -static int -tier_process_brick(tier_brick_list_t *local_brick, void *args) -{ - int ret = -1; - dict_t *ctr_ipc_in_dict = NULL; - dict_t *ctr_ipc_out_dict = NULL; - char *strval = NULL; - - GF_VALIDATE_OR_GOTO("tier", local_brick, out); - - GF_VALIDATE_OR_GOTO("tier", local_brick->xlator, out); - - if (dht_tier_db_type == GFDB_SQLITE3) { - /*Preparing ctr_ipc_in_dict*/ - ctr_ipc_in_dict = dict_new(); - if (!ctr_ipc_in_dict) { - gf_msg("tier", GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "ctr_ipc_in_dict cannot initialized"); - goto out; - } - - ret = dict_set_str(ctr_ipc_in_dict, GFDB_IPC_CTR_KEY, - GFDB_IPC_CTR_GET_DB_PARAM_OPS); - if (ret) { - gf_msg("tier", GF_LOG_ERROR, 0, LG_MSG_SET_PARAM_FAILED, - "Failed to set %s " - "to params dictionary", - GFDB_IPC_CTR_KEY); - goto out; - } - - ret = dict_set_str(ctr_ipc_in_dict, GFDB_IPC_CTR_GET_DB_PARAM_OPS, ""); - if (ret) { - gf_msg("tier", GF_LOG_ERROR, 0, LG_MSG_SET_PARAM_FAILED, - "Failed to set %s " - "to params dictionary", - GFDB_IPC_CTR_GET_DB_PARAM_OPS); - goto out; - } - - ret = dict_set_str(ctr_ipc_in_dict, GFDB_IPC_CTR_GET_DB_KEY, - "journal_mode"); - if (ret) { - gf_msg("tier", GF_LOG_ERROR, 0, LG_MSG_SET_PARAM_FAILED, - "Failed to set %s " - "to params dictionary", - GFDB_IPC_CTR_GET_DB_KEY); - goto out; - } - - ret = syncop_ipc(local_brick->xlator, GF_IPC_TARGET_CTR, - ctr_ipc_in_dict, &ctr_ipc_out_dict); - if (ret || ctr_ipc_out_dict == NULL) { - gf_msg("tier", GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "Failed to get " - "journal_mode of sql db %s", - local_brick->brick_db_path); - goto out; - } - - ret = dict_get_str(ctr_ipc_out_dict, "journal_mode", &strval); - if (ret) { - gf_msg("tier", GF_LOG_ERROR, 0, LG_MSG_GET_PARAM_FAILED, - "Failed to get %s " - "from params dictionary" - "journal_mode", - strval); - goto out; - } - - if (strval && (strncmp(strval, "wal", SLEN("wal")) == 0)) { - ret = tier_process_self_query(local_brick, args); - if (ret) { - goto out; - } - } else { - ret = tier_process_ctr_query(local_brick, args); - if (ret) { - goto out; - } - } - ret = 0; - - } else { - ret = tier_process_self_query(local_brick, args); - if (ret) { - goto out; - } - } - - ret = 0; -out: - if (ctr_ipc_in_dict) - dict_unref(ctr_ipc_in_dict); - - if (ctr_ipc_out_dict) - dict_unref(ctr_ipc_out_dict); - - return ret; -} - -static int -tier_build_migration_qfile(migration_args_t *args, - query_cbk_args_t *query_cbk_args, - gf_boolean_t is_promotion) -{ - gfdb_time_t current_time; - gfdb_brick_info_t gfdb_brick_info; - gfdb_time_t time_in_past; - int ret = -1; - tier_brick_list_t *local_brick = NULL; - int i = 0; - time_in_past.tv_sec = args->freq_time; - time_in_past.tv_usec = 0; - - ret = gettimeofday(¤t_time, NULL); - if (ret == -1) { - gf_msg(args->this->name, GF_LOG_ERROR, errno, - DHT_MSG_SYS_CALL_GET_TIME_FAILED, "Failed to get current time"); - goto out; - } - time_in_past.tv_sec = current_time.tv_sec - time_in_past.tv_sec; - - /* The migration daemon may run a varying numberof usec after the */ - /* sleep call triggers. A file may be registered in CTR some number */ - /* of usec X after the daemon started and missed in the subsequent */ - /* cycle if the daemon starts Y usec after the period in seconds */ - /* where Y>X. Normalize away this problem by always setting usec */ - /* to 0. */ - time_in_past.tv_usec = 0; - - gfdb_brick_info.time_stamp = &time_in_past; - gfdb_brick_info._gfdb_promote = is_promotion; - gfdb_brick_info._query_cbk_args = query_cbk_args; - - list_for_each_entry(local_brick, args->brick_list, list) - { - /* Construct query file path for this brick - * i.e - * /var/run/gluster/xlator_name/ - * {promote/demote}-brickname-indexinbricklist - * So that no two query files will have same path even - * bricks have the same name - * */ - snprintf(local_brick->qfile_path, PATH_MAX, "%s-%s-%d", - GET_QFILE_PATH(gfdb_brick_info._gfdb_promote), - local_brick->brick_name, i); - - /* Delete any old query files for this brick */ - sys_unlink(local_brick->qfile_path); - - ret = tier_process_brick(local_brick, &gfdb_brick_info); - if (ret) { - gf_msg(args->this->name, GF_LOG_ERROR, 0, - DHT_MSG_BRICK_QUERY_FAILED, "Brick %s query failed\n", - local_brick->brick_db_path); - } - i++; - } - ret = 0; -out: - return ret; -} - -static int -tier_migrate_files_using_qfile(migration_args_t *comp, - query_cbk_args_t *query_cbk_args) -{ - int ret = -1; - tier_brick_list_t *local_brick = NULL; - tier_brick_list_t *temp = NULL; - gfdb_time_t current_time = { - 0, - }; - ssize_t qfile_array_size = 0; - int count = 0; - int temp_fd = 0; - gf_tier_conf_t *tier_conf = NULL; - - tier_conf = &(query_cbk_args->defrag->tier_conf); - - /* Time for error query files */ - gettimeofday(¤t_time, NULL); - - /* Build the qfile list */ - list_for_each_entry_safe(local_brick, temp, comp->brick_list, list) - { - qfile_array_size++; - } - query_cbk_args->qfile_array = qfile_array_new(qfile_array_size); - if (!query_cbk_args->qfile_array) { - gf_msg("tier", GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "Failed to create new " - "qfile_array"); - goto out; - } - - /*Open all qfiles*/ - count = 0; - query_cbk_args->qfile_array->exhausted_count = 0; - list_for_each_entry_safe(local_brick, temp, comp->brick_list, list) - { - temp_fd = query_cbk_args->qfile_array->fd_array[count]; - temp_fd = open(local_brick->qfile_path, O_RDONLY, - S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); - if (temp_fd < 0) { - gf_msg("tier", GF_LOG_ERROR, errno, DHT_MSG_LOG_TIER_ERROR, - "Failed to open " - "%s to the query file", - local_brick->qfile_path); - query_cbk_args->qfile_array->exhausted_count++; - } - query_cbk_args->qfile_array->fd_array[count] = temp_fd; - count++; - } - - /* Moving the query file index to the next, so that we won't the same - * query file every cycle as the first one */ - query_cbk_args->qfile_array - ->next_index = (query_cbk_args->is_promotion) - ? tier_conf->last_promote_qfile_index - : tier_conf->last_demote_qfile_index; - shift_next_index(query_cbk_args->qfile_array); - if (query_cbk_args->is_promotion) { - tier_conf->last_promote_qfile_index = query_cbk_args->qfile_array - ->next_index; - } else { - tier_conf->last_demote_qfile_index = query_cbk_args->qfile_array - ->next_index; - } - - /* Migrate files using query file list */ - ret = tier_migrate_using_query_file((void *)query_cbk_args); -out: - qfile_array_free(query_cbk_args->qfile_array); - - /* If there is an error rename all the query files to .err files - * with a timestamp for better debugging */ - if (ret) { - struct tm tm = { - 0, - }; - char time_str[128] = { - 0, - }; - char query_file_path_err[PATH_MAX] = { - 0, - }; - int32_t len = 0; - - /* Time format for error query files */ - gmtime_r(¤t_time.tv_sec, &tm); - strftime(time_str, sizeof(time_str), "%F-%T", &tm); - - list_for_each_entry_safe(local_brick, temp, comp->brick_list, list) - { - /* rename error qfile*/ - len = snprintf(query_file_path_err, sizeof(query_file_path_err), - "%s-%s.err", local_brick->qfile_path, time_str); - if ((len >= 0) && (len < sizeof(query_file_path_err))) { - if (sys_rename(local_brick->qfile_path, query_file_path_err) == - -1) - gf_msg_debug("tier", 0, - "rename " - "failed"); - } - } - } - - query_cbk_args->qfile_array = NULL; - - return ret; -} - -int -tier_demote(migration_args_t *demotion_args) -{ - query_cbk_args_t query_cbk_args; - int ret = -1; - - GF_VALIDATE_OR_GOTO("tier", demotion_args, out); - GF_VALIDATE_OR_GOTO("tier", demotion_args->this, out); - GF_VALIDATE_OR_GOTO(demotion_args->this->name, demotion_args->brick_list, - out); - GF_VALIDATE_OR_GOTO(demotion_args->this->name, demotion_args->defrag, out); - - THIS = demotion_args->this; - - query_cbk_args.this = demotion_args->this; - query_cbk_args.defrag = demotion_args->defrag; - query_cbk_args.is_promotion = 0; - - /*Build the query file using bricklist*/ - ret = tier_build_migration_qfile(demotion_args, &query_cbk_args, _gf_false); - if (ret) - goto out; - - /* Migrate files using the query file */ - ret = tier_migrate_files_using_qfile(demotion_args, &query_cbk_args); - if (ret) - goto out; - -out: - demotion_args->return_value = ret; - return ret; -} - -int -tier_promote(migration_args_t *promotion_args) -{ - int ret = -1; - query_cbk_args_t query_cbk_args; - - GF_VALIDATE_OR_GOTO("tier", promotion_args->this, out); - GF_VALIDATE_OR_GOTO(promotion_args->this->name, promotion_args->brick_list, - out); - GF_VALIDATE_OR_GOTO(promotion_args->this->name, promotion_args->defrag, - out); - - THIS = promotion_args->this; - - query_cbk_args.this = promotion_args->this; - query_cbk_args.defrag = promotion_args->defrag; - query_cbk_args.is_promotion = 1; - - /*Build the query file using bricklist*/ - ret = tier_build_migration_qfile(promotion_args, &query_cbk_args, _gf_true); - if (ret) - goto out; - - /* Migrate files using the query file */ - ret = tier_migrate_files_using_qfile(promotion_args, &query_cbk_args); - if (ret) - goto out; - -out: - promotion_args->return_value = ret; - return ret; -} - -/* - * Command the CTR on a brick to compact the local database using an IPC - */ -static int -tier_process_self_compact(tier_brick_list_t *local_brick, void *args) -{ - int ret = -1; - char *db_path = NULL; - query_cbk_args_t *query_cbk_args = NULL; - xlator_t *this = NULL; - gfdb_conn_node_t *conn_node = NULL; - dict_t *params_dict = NULL; - dict_t *ctr_ipc_dict = NULL; - gfdb_brick_info_t *gfdb_brick_info = args; - - /*Init of all the essentials*/ - GF_VALIDATE_OR_GOTO("tier", gfdb_brick_info, out); - query_cbk_args = gfdb_brick_info->_query_cbk_args; - - GF_VALIDATE_OR_GOTO("tier", query_cbk_args->this, out); - this = query_cbk_args->this; - - GF_VALIDATE_OR_GOTO(this->name, gfdb_brick_info->_query_cbk_args, out); - - GF_VALIDATE_OR_GOTO(this->name, local_brick, out); - - GF_VALIDATE_OR_GOTO(this->name, local_brick->xlator, out); - - GF_VALIDATE_OR_GOTO(this->name, local_brick->brick_db_path, out); - - db_path = local_brick->brick_db_path; - - /*Preparing DB parameters before init_db i.e getting db connection*/ - params_dict = dict_new(); - if (!params_dict) { - gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "DB Params cannot initialized"); - goto out; - } - SET_DB_PARAM_TO_DICT(this->name, params_dict, - (char *)gfdb_methods.get_db_path_key(), db_path, ret, - out); - - /*Get the db connection*/ - conn_node = gfdb_methods.init_db((void *)params_dict, dht_tier_db_type); - if (!conn_node) { - gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "FATAL: Failed initializing db operations"); - goto out; - } - - ret = 0; - - /*Preparing ctr_ipc_dict*/ - ctr_ipc_dict = dict_new(); - if (!ctr_ipc_dict) { - gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "ctr_ipc_dict cannot initialized"); - goto out; - } - - ret = dict_set_int32(ctr_ipc_dict, "compact_active", - query_cbk_args->defrag->tier_conf.compact_active); - - if (ret) { - gf_msg("tier", GF_LOG_ERROR, 0, LG_MSG_SET_PARAM_FAILED, - "Failed to set %s " - "to params dictionary", - "compact_active"); - goto out; - } - - ret = dict_set_int32( - ctr_ipc_dict, "compact_mode_switched", - query_cbk_args->defrag->tier_conf.compact_mode_switched); - - if (ret) { - gf_msg("tier", GF_LOG_ERROR, 0, LG_MSG_SET_PARAM_FAILED, - "Failed to set %s " - "to params dictionary", - "compact_mode_switched"); - goto out; - } - - SET_DB_PARAM_TO_DICT(this->name, ctr_ipc_dict, GFDB_IPC_CTR_KEY, - GFDB_IPC_CTR_SET_COMPACT_PRAGMA, ret, out); - - gf_msg(this->name, GF_LOG_TRACE, 0, DHT_MSG_LOG_TIER_STATUS, - "Starting Compaction IPC"); - - ret = syncop_ipc(local_brick->xlator, GF_IPC_TARGET_CTR, ctr_ipc_dict, - NULL); - - gf_msg(this->name, GF_LOG_TRACE, 0, DHT_MSG_LOG_TIER_STATUS, - "Ending Compaction IPC"); - - if (ret) { - gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "Failed compaction " - "on db %s error %d", - local_brick->brick_db_path, ret); - goto out; - } - - gf_msg(this->name, GF_LOG_TRACE, 0, DHT_MSG_LOG_TIER_STATUS, - "SUCCESS: %s Compaction", local_brick->brick_name); - - ret = 0; -out: - if (params_dict) { - dict_unref(params_dict); - params_dict = NULL; - } - - if (ctr_ipc_dict) { - dict_unref(ctr_ipc_dict); - ctr_ipc_dict = NULL; - } - - gfdb_methods.fini_db(conn_node); - - return ret; -} - -/* - * This is the call back function for each brick from hot/cold bricklist. - * It determines the database type on each brick and calls the corresponding - * function to prepare the compaction IPC. - */ -static int -tier_compact_db_brick(tier_brick_list_t *local_brick, void *args) -{ - int ret = -1; - - GF_VALIDATE_OR_GOTO("tier", local_brick, out); - - GF_VALIDATE_OR_GOTO("tier", local_brick->xlator, out); - - ret = tier_process_self_compact(local_brick, args); - if (ret) { - gf_msg("tier", GF_LOG_INFO, 0, DHT_MSG_LOG_TIER_STATUS, - "Brick %s did not compact", local_brick->brick_name); - goto out; - } - - ret = 0; - -out: - - return ret; -} - -static int -tier_send_compact(migration_args_t *args, query_cbk_args_t *query_cbk_args) -{ - gfdb_time_t current_time; - gfdb_brick_info_t gfdb_brick_info; - gfdb_time_t time_in_past; - int ret = -1; - tier_brick_list_t *local_brick = NULL; - - time_in_past.tv_sec = args->freq_time; - time_in_past.tv_usec = 0; - - ret = gettimeofday(¤t_time, NULL); - if (ret == -1) { - gf_msg(args->this->name, GF_LOG_ERROR, errno, - DHT_MSG_SYS_CALL_GET_TIME_FAILED, "Failed to get current time"); - goto out; - } - time_in_past.tv_sec = current_time.tv_sec - time_in_past.tv_sec; - - /* The migration daemon may run a varying numberof usec after the sleep - call triggers. A file may be registered in CTR some number of usec X - after the daemon started and missed in the subsequent cycle if the - daemon starts Y usec after the period in seconds where Y>X. Normalize - away this problem by always setting usec to 0. */ - time_in_past.tv_usec = 0; - - gfdb_brick_info.time_stamp = &time_in_past; - - /* This is meant to say we are always compacting at this point */ - /* We simply borrow the promotion flag to do this */ - gfdb_brick_info._gfdb_promote = 1; - - gfdb_brick_info._query_cbk_args = query_cbk_args; - - list_for_each_entry(local_brick, args->brick_list, list) - { - gf_msg(args->this->name, GF_LOG_TRACE, 0, DHT_MSG_LOG_TIER_STATUS, - "Start compaction for %s", local_brick->brick_name); - - ret = tier_compact_db_brick(local_brick, &gfdb_brick_info); - if (ret) { - gf_msg(args->this->name, GF_LOG_ERROR, 0, - DHT_MSG_BRICK_QUERY_FAILED, "Brick %s compaction failed\n", - local_brick->brick_db_path); - } - - gf_msg(args->this->name, GF_LOG_TRACE, 0, DHT_MSG_LOG_TIER_STATUS, - "End compaction for %s", local_brick->brick_name); - } - ret = 0; -out: - return ret; -} - -static int -tier_compact(void *args) -{ - int ret = -1; - query_cbk_args_t query_cbk_args; - migration_args_t *compaction_args = args; - - GF_VALIDATE_OR_GOTO("tier", compaction_args->this, out); - GF_VALIDATE_OR_GOTO(compaction_args->this->name, - compaction_args->brick_list, out); - GF_VALIDATE_OR_GOTO(compaction_args->this->name, compaction_args->defrag, - out); - - THIS = compaction_args->this; - - query_cbk_args.this = compaction_args->this; - query_cbk_args.defrag = compaction_args->defrag; - query_cbk_args.is_compaction = 1; - - /* Send the compaction pragma out to all the bricks on the bricklist. */ - /* tier_get_bricklist ensures all bricks on the list are local to */ - /* this node. */ - ret = tier_send_compact(compaction_args, &query_cbk_args); - if (ret) - goto out; - - ret = 0; -out: - compaction_args->return_value = ret; - return ret; -} - -static int -tier_get_bricklist(xlator_t *xl, struct list_head *local_bricklist_head) -{ - xlator_list_t *child = NULL; - char *rv = NULL; - char *rh = NULL; - char *brickname = NULL; - char db_name[PATH_MAX] = ""; - int ret = 0; - tier_brick_list_t *local_brick = NULL; - int32_t len = 0; - - GF_VALIDATE_OR_GOTO("tier", xl, out); - GF_VALIDATE_OR_GOTO("tier", local_bricklist_head, out); - - /* - * This function obtains remote subvolumes and filters out only - * those running on the same node as the tier daemon. - */ - if (strcmp(xl->type, "protocol/client") == 0) { - ret = dict_get_str(xl->options, "remote-host", &rh); - if (ret < 0) - goto out; - - if (gf_is_local_addr(rh)) { - local_brick = GF_CALLOC(1, sizeof(tier_brick_list_t), - gf_tier_mt_bricklist_t); - if (!local_brick) { - goto out; - } - - ret = dict_get_str(xl->options, "remote-subvolume", &rv); - if (ret < 0) - goto out; - - brickname = strrchr(rv, '/') + 1; - snprintf(db_name, sizeof(db_name), "%s.db", brickname); - - local_brick->brick_db_path = GF_MALLOC(PATH_MAX, gf_common_mt_char); - if (!local_brick->brick_db_path) { - gf_msg("tier", GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_STATUS, - "Failed to allocate memory for" - " bricklist."); - ret = -1; - goto out; - } - - len = snprintf(local_brick->brick_db_path, PATH_MAX, "%s/%s/%s", rv, - GF_HIDDEN_PATH, db_name); - if ((len < 0) || (len >= PATH_MAX)) { - gf_msg("tier", GF_LOG_ERROR, EINVAL, DHT_MSG_LOG_TIER_STATUS, - "DB path too long"); - ret = -1; - goto out; - } - - local_brick->xlator = xl; - - snprintf(local_brick->brick_name, NAME_MAX, "%s", brickname); - - list_add_tail(&(local_brick->list), local_bricklist_head); - - ret = 0; - goto out; - } - } - - for (child = xl->children; child; child = child->next) { - ret = tier_get_bricklist(child->xlator, local_bricklist_head); - if (ret) { - goto out; - } - } - - ret = 0; -out: - - if (ret) { - if (local_brick) { - GF_FREE(local_brick->brick_db_path); - } - GF_FREE(local_brick); - } - - return ret; -} - -int -tier_get_freq_demote(gf_tier_conf_t *tier_conf) -{ - if ((tier_conf->mode == TIER_MODE_WM) && - (tier_conf->watermark_last == TIER_WM_HI)) - return DEFAULT_DEMOTE_DEGRADED; - else - return tier_conf->tier_demote_frequency; -} - -int -tier_get_freq_promote(gf_tier_conf_t *tier_conf) -{ - return tier_conf->tier_promote_frequency; -} - -int -tier_get_freq_compact_hot(gf_tier_conf_t *tier_conf) -{ - return tier_conf->tier_compact_hot_frequency; -} - -int -tier_get_freq_compact_cold(gf_tier_conf_t *tier_conf) -{ - return tier_conf->tier_compact_cold_frequency; -} - -static int -tier_check_demote(gfdb_time_t current_time, int freq) -{ - return ((current_time.tv_sec % freq) == 0) ? _gf_true : _gf_false; -} - -static gf_boolean_t -tier_check_promote(gf_tier_conf_t *tier_conf, gfdb_time_t current_time, - int freq) -{ - if ((tier_conf->mode == TIER_MODE_WM) && - (tier_conf->watermark_last == TIER_WM_HI)) - return _gf_false; - - else - return ((current_time.tv_sec % freq) == 0) ? _gf_true : _gf_false; -} - -static gf_boolean_t -tier_check_compact(gf_tier_conf_t *tier_conf, gfdb_time_t current_time, - int freq_compact) -{ - if (!(tier_conf->compact_active || tier_conf->compact_mode_switched)) - return _gf_false; - - return ((current_time.tv_sec % freq_compact) == 0) ? _gf_true : _gf_false; -} - -void -clear_bricklist(struct list_head *brick_list) -{ - tier_brick_list_t *local_brick = NULL; - tier_brick_list_t *temp = NULL; - - if (list_empty(brick_list)) { - return; - } - - list_for_each_entry_safe(local_brick, temp, brick_list, list) - { - list_del(&local_brick->list); - GF_FREE(local_brick->brick_db_path); - GF_FREE(local_brick); - } -} - -static void -set_brick_list_qpath(struct list_head *brick_list, gf_boolean_t is_cold) -{ - tier_brick_list_t *local_brick = NULL; - int i = 0; - - GF_VALIDATE_OR_GOTO("tier", brick_list, out); - - list_for_each_entry(local_brick, brick_list, list) - { - /* Construct query file path for this brick - * i.e - * /var/run/gluster/xlator_name/ - * {promote/demote}-brickname-indexinbricklist - * So that no two query files will have same path even - * bricks have the same name - * */ - snprintf(local_brick->qfile_path, PATH_MAX, "%s-%s-%d", - GET_QFILE_PATH(is_cold), local_brick->brick_name, i); - i++; - } -out: - return; -} - -static int -tier_prepare_compact(migration_args_t *args, gfdb_time_t current_time) -{ - xlator_t *this = NULL; - dht_conf_t *conf = NULL; - gf_defrag_info_t *defrag = NULL; - gf_tier_conf_t *tier_conf = NULL; - gf_boolean_t is_hot_tier = args->is_hot_tier; - int freq = 0; - int ret = -1; - const char *tier_type = is_hot_tier ? "hot" : "cold"; - - this = args->this; - - conf = this->private; - - defrag = conf->defrag; - - tier_conf = &defrag->tier_conf; - - freq = is_hot_tier ? tier_get_freq_compact_hot(tier_conf) - : tier_get_freq_compact_cold(tier_conf); - - defrag->tier_conf.compact_mode_switched = - is_hot_tier ? defrag->tier_conf.compact_mode_switched_hot - : defrag->tier_conf.compact_mode_switched_cold; - - gf_msg(this->name, GF_LOG_TRACE, 0, DHT_MSG_LOG_TIER_STATUS, - "Compact mode %i", defrag->tier_conf.compact_mode_switched); - - if (tier_check_compact(tier_conf, current_time, freq)) { - gf_msg(this->name, GF_LOG_INFO, 0, DHT_MSG_LOG_TIER_STATUS, - "Start compaction on %s tier", tier_type); - - args->freq_time = freq; - ret = tier_compact(args); - if (ret) { - gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "Compaction failed on " - "%s tier", - tier_type); - goto out; - } - - gf_msg(this->name, GF_LOG_INFO, 0, DHT_MSG_LOG_TIER_STATUS, - "End compaction on %s tier", tier_type); - - if (is_hot_tier) { - defrag->tier_conf.compact_mode_switched_hot = _gf_false; - } else { - defrag->tier_conf.compact_mode_switched_cold = _gf_false; - } - } - -out: - return ret; -} - -static int -tier_get_wm_interval(tier_mode_t mode, tier_watermark_op_t wm) -{ - if (mode == TIER_MODE_WM && wm == TIER_WM_HI) - return WM_INTERVAL_EMERG; - - return WM_INTERVAL; -} - -/* - * Main tiering loop. This is called from the promotion and the - * demotion threads spawned in tier_start(). - * - * Every second, wake from sleep to perform tasks. - * 1. Check trigger to migrate data. - * 2. Check for state changes (pause, unpause, stop). - */ -static void * -tier_run(void *in_args) -{ - dht_conf_t *conf = NULL; - gfdb_time_t current_time = {0}; - int freq = 0; - int ret = 0; - xlator_t *any = NULL; - xlator_t *xlator = NULL; - gf_tier_conf_t *tier_conf = NULL; - loc_t root_loc = {0}; - int check_watermark = 0; - gf_defrag_info_t *defrag = NULL; - xlator_t *this = NULL; - migration_args_t *args = in_args; - GF_VALIDATE_OR_GOTO("tier", args, out); - GF_VALIDATE_OR_GOTO("tier", args->brick_list, out); - - this = args->this; - GF_VALIDATE_OR_GOTO("tier", this, out); - - conf = this->private; - GF_VALIDATE_OR_GOTO("tier", conf, out); - - defrag = conf->defrag; - GF_VALIDATE_OR_GOTO("tier", defrag, out); - - if (list_empty(args->brick_list)) { - gf_msg(this->name, GF_LOG_INFO, 0, DHT_MSG_LOG_TIER_ERROR, - "Brick list for tier is empty. Exiting."); - goto out; - } - - defrag->defrag_status = GF_DEFRAG_STATUS_STARTED; - tier_conf = &defrag->tier_conf; - - dht_build_root_loc(defrag->root_inode, &root_loc); - - while (1) { - /* - * Check if a graph switch occurred. If so, stop migration - * thread. It will need to be restarted manually. - */ - any = THIS->ctx->active->first; - xlator = xlator_search_by_name(any, this->name); - - if (xlator != this) { - gf_msg(this->name, GF_LOG_INFO, 0, DHT_MSG_LOG_TIER_STATUS, - "Detected graph switch. Exiting migration " - "daemon."); - goto out; - } - - gf_defrag_check_pause_tier(tier_conf); - - sleep(1); - - if (defrag->defrag_status != GF_DEFRAG_STATUS_STARTED) { - ret = 1; - gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "defrag->defrag_status != " - "GF_DEFRAG_STATUS_STARTED"); - goto out; - } - - if (defrag->cmd == GF_DEFRAG_CMD_START_DETACH_TIER || - defrag->cmd == GF_DEFRAG_CMD_DETACH_START) { - ret = 0; - defrag->defrag_status = GF_DEFRAG_STATUS_COMPLETE; - gf_msg(this->name, GF_LOG_DEBUG, 0, DHT_MSG_LOG_TIER_ERROR, - "defrag->defrag_cmd == " - "GF_DEFRAG_CMD_START_DETACH_TIER"); - goto out; - } - - if (gf_defrag_get_pause_state(&defrag->tier_conf) != TIER_RUNNING) - continue; - - /* To have proper synchronization amongst all - * brick holding nodes, so that promotion and demotions - * start atomically w.r.t promotion/demotion frequency - * period, all nodes should have their system time - * in-sync with each other either manually set or - * using a NTP server*/ - ret = gettimeofday(¤t_time, NULL); - if (ret == -1) { - gf_msg(this->name, GF_LOG_ERROR, errno, - DHT_MSG_SYS_CALL_GET_TIME_FAILED, - "Failed to get current time"); - goto out; - } - - check_watermark++; - - /* emergency demotion requires frequent watermark monitoring */ - if (check_watermark >= - tier_get_wm_interval(tier_conf->mode, tier_conf->watermark_last)) { - check_watermark = 0; - if (tier_conf->mode == TIER_MODE_WM) { - ret = tier_get_fs_stat(this, &root_loc); - if (ret != 0) { - continue; - } - ret = tier_check_watermark(this); - if (ret != 0) { - gf_msg(this->name, GF_LOG_CRITICAL, errno, - DHT_MSG_LOG_TIER_ERROR, "Failed to get watermark"); - continue; - } - } - } - - if (args->is_promotion) { - freq = tier_get_freq_promote(tier_conf); - - if (tier_check_promote(tier_conf, current_time, freq)) { - args->freq_time = freq; - ret = tier_promote(args); - if (ret) { - gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "Promotion failed"); - } - } - } else if (args->is_compaction) { - tier_prepare_compact(args, current_time); - } else { - freq = tier_get_freq_demote(tier_conf); - - if (tier_check_demote(current_time, freq)) { - args->freq_time = freq; - ret = tier_demote(args); - if (ret) { - gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "Demotion failed"); - } - } - } - - /* Check the statfs immediately after the processing threads - return */ - check_watermark = WM_INTERVAL; - } - - ret = 0; -out: - - args->return_value = ret; - - return NULL; -} - -int -tier_start(xlator_t *this, gf_defrag_info_t *defrag) -{ - pthread_t promote_thread; - pthread_t demote_thread; - pthread_t hot_compact_thread; - pthread_t cold_compact_thread; - int ret = -1; - struct list_head bricklist_hot = {0}; - struct list_head bricklist_cold = {0}; - migration_args_t promotion_args = {0}; - migration_args_t demotion_args = {0}; - migration_args_t hot_compaction_args = {0}; - migration_args_t cold_compaction_args = {0}; - dht_conf_t *conf = NULL; - - INIT_LIST_HEAD((&bricklist_hot)); - INIT_LIST_HEAD((&bricklist_cold)); - - conf = this->private; - - tier_get_bricklist(conf->subvolumes[1], &bricklist_hot); - set_brick_list_qpath(&bricklist_hot, _gf_false); - - demotion_args.this = this; - demotion_args.brick_list = &bricklist_hot; - demotion_args.defrag = defrag; - demotion_args.is_promotion = _gf_false; - demotion_args.is_compaction = _gf_false; - - ret = gf_thread_create(&demote_thread, NULL, &tier_run, &demotion_args, - "tierdem"); - if (ret) { - gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "Failed to start demotion thread."); - defrag->defrag_status = GF_DEFRAG_STATUS_FAILED; - goto cleanup; - } - - tier_get_bricklist(conf->subvolumes[0], &bricklist_cold); - set_brick_list_qpath(&bricklist_cold, _gf_true); - - promotion_args.this = this; - promotion_args.brick_list = &bricklist_cold; - promotion_args.defrag = defrag; - promotion_args.is_promotion = _gf_true; - - ret = gf_thread_create(&promote_thread, NULL, &tier_run, &promotion_args, - "tierpro"); - if (ret) { - gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "Failed to start promotion thread."); - defrag->defrag_status = GF_DEFRAG_STATUS_FAILED; - goto waitforspawned; - } - - hot_compaction_args.this = this; - hot_compaction_args.brick_list = &bricklist_hot; - hot_compaction_args.defrag = defrag; - hot_compaction_args.is_promotion = _gf_false; - hot_compaction_args.is_compaction = _gf_true; - hot_compaction_args.is_hot_tier = _gf_true; - - ret = gf_thread_create(&hot_compact_thread, NULL, &tier_run, - &hot_compaction_args, "tierhcom"); - if (ret) { - gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "Failed to start compaction thread."); - defrag->defrag_status = GF_DEFRAG_STATUS_FAILED; - goto waitforspawnedpromote; - } - - cold_compaction_args.this = this; - cold_compaction_args.brick_list = &bricklist_cold; - cold_compaction_args.defrag = defrag; - cold_compaction_args.is_promotion = _gf_false; - cold_compaction_args.is_compaction = _gf_true; - cold_compaction_args.is_hot_tier = _gf_false; - - ret = gf_thread_create(&cold_compact_thread, NULL, &tier_run, - &cold_compaction_args, "tierccom"); - if (ret) { - gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "Failed to start compaction thread."); - defrag->defrag_status = GF_DEFRAG_STATUS_FAILED; - goto waitforspawnedhotcompact; - } - pthread_join(cold_compact_thread, NULL); - -waitforspawnedhotcompact: - pthread_join(hot_compact_thread, NULL); - -waitforspawnedpromote: - pthread_join(promote_thread, NULL); - -waitforspawned: - pthread_join(demote_thread, NULL); - -cleanup: - clear_bricklist(&bricklist_cold); - clear_bricklist(&bricklist_hot); - return ret; -} - -int32_t -tier_migration_needed(xlator_t *this) -{ - gf_defrag_info_t *defrag = NULL; - dht_conf_t *conf = NULL; - int ret = 0; - - conf = this->private; - - GF_VALIDATE_OR_GOTO(this->name, conf, out); - GF_VALIDATE_OR_GOTO(this->name, conf->defrag, out); - - defrag = conf->defrag; - - if ((defrag->cmd == GF_DEFRAG_CMD_START_TIER) || - (defrag->cmd == GF_DEFRAG_CMD_START_DETACH_TIER)) - ret = 1; -out: - return ret; -} - -int32_t -tier_migration_get_dst(xlator_t *this, dht_local_t *local) -{ - dht_conf_t *conf = NULL; - int32_t ret = -1; - gf_defrag_info_t *defrag = NULL; - - GF_VALIDATE_OR_GOTO("tier", this, out); - GF_VALIDATE_OR_GOTO(this->name, this->private, out); - - conf = this->private; - - defrag = conf->defrag; - - if (defrag && defrag->cmd == GF_DEFRAG_CMD_START_DETACH_TIER) { - local->rebalance.target_node = conf->subvolumes[0]; - - } else if (conf->subvolumes[0] == local->cached_subvol) - local->rebalance.target_node = conf->subvolumes[1]; - else - local->rebalance.target_node = conf->subvolumes[0]; - - if (local->rebalance.target_node) - ret = 0; - -out: - return ret; -} - -xlator_t * -tier_search(xlator_t *this, dht_layout_t *layout, const char *name) -{ - xlator_t *subvol = NULL; - dht_conf_t *conf = NULL; - - GF_VALIDATE_OR_GOTO("tier", this, out); - GF_VALIDATE_OR_GOTO(this->name, this->private, out); - - conf = this->private; - - subvol = TIER_HASHED_SUBVOL; - -out: - return subvol; -} - -static int -tier_load_externals(xlator_t *this) -{ - int ret = -1; - char *libpathfull = (LIBDIR "/libgfdb.so.0"); - get_gfdb_methods_t get_gfdb_methods; - - GF_VALIDATE_OR_GOTO("this", this, out); - - libhandle = dlopen(libpathfull, RTLD_NOW); - if (!libhandle) { - gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "Error loading libgfdb.so %s\n", dlerror()); - ret = -1; - goto out; - } - - get_gfdb_methods = dlsym(libhandle, "get_gfdb_methods"); - if (!get_gfdb_methods) { - gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "Error loading get_gfdb_methods()"); - ret = -1; - goto out; - } - - get_gfdb_methods(&gfdb_methods); - - ret = 0; - -out: - if (ret && libhandle) - dlclose(libhandle); - - return ret; -} - -static tier_mode_t -tier_validate_mode(char *mode) -{ - int ret = -1; - - if (strcmp(mode, "test") == 0) { - ret = TIER_MODE_TEST; - } else { - ret = TIER_MODE_WM; - } - - return ret; -} - -static gf_boolean_t -tier_validate_compact_mode(char *mode) -{ - gf_boolean_t ret = _gf_false; - - gf_msg("tier", GF_LOG_INFO, 0, DHT_MSG_LOG_TIER_STATUS, - "tier_validate_compact_mode: mode = %s", mode); - - if (!strcmp(mode, "on")) { - ret = _gf_true; - } else { - ret = _gf_false; - } - - gf_msg("tier", GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_STATUS, - "tier_validate_compact_mode: ret = %i", ret); - - return ret; -} - -int -tier_init_methods(xlator_t *this) -{ - int ret = -1; - dht_conf_t *conf = NULL; - dht_methods_t *methods = NULL; - - GF_VALIDATE_OR_GOTO("tier", this, err); - - conf = this->private; - - methods = &(conf->methods); - - methods->migration_get_dst_subvol = tier_migration_get_dst; - methods->migration_other = tier_start; - methods->migration_needed = tier_migration_needed; - methods->layout_search = tier_search; - - ret = 0; -err: - return ret; -} - -static void -tier_save_vol_name(xlator_t *this) -{ - dht_conf_t *conf = NULL; - gf_defrag_info_t *defrag = NULL; - char *suffix = NULL; - int name_len = 0; - - conf = this->private; - defrag = conf->defrag; - - suffix = strstr(this->name, "-tier-dht"); - - if (suffix) - name_len = suffix - this->name; - else - name_len = strlen(this->name); - - if (name_len > GD_VOLUME_NAME_MAX) - name_len = GD_VOLUME_NAME_MAX; - - strncpy(defrag->tier_conf.volname, this->name, name_len); - defrag->tier_conf.volname[name_len] = 0; -} - -int -tier_init(xlator_t *this) -{ - int ret = -1; - int freq = 0; - int maxsize = 0; - dht_conf_t *conf = NULL; - gf_defrag_info_t *defrag = NULL; - char *voldir = NULL; - char *mode = NULL; - char *paused = NULL; - tier_mode_t tier_mode = DEFAULT_TIER_MODE; - gf_boolean_t compact_mode = _gf_false; - - ret = dht_init(this); - if (ret) { - gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "tier_init failed"); - goto out; - } - - conf = this->private; - - ret = tier_init_methods(this); - if (ret) { - gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "tier_init_methods failed"); - goto out; - } - - if (conf->subvolume_cnt != 2) { - gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "Invalid number of subvolumes %d", conf->subvolume_cnt); - goto out; - } - - /* if instatiated from client side initialization is complete. */ - if (!conf->defrag) { - ret = 0; - goto out; - } - - /* if instatiated from server side, load db libraries */ - ret = tier_load_externals(this); - if (ret) { - gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "Could not load externals. Aborting"); - goto out; - } - - defrag = conf->defrag; - - defrag->tier_conf.last_demote_qfile_index = 0; - defrag->tier_conf.last_promote_qfile_index = 0; - - defrag->tier_conf.is_tier = 1; - defrag->this = this; - - ret = dict_get_int32(this->options, "tier-max-promote-file-size", &maxsize); - if (ret) { - maxsize = 0; - } - - defrag->tier_conf.tier_max_promote_size = maxsize; - - ret = dict_get_int32(this->options, "tier-promote-frequency", &freq); - if (ret) { - freq = DEFAULT_PROMOTE_FREQ_SEC; - } - - defrag->tier_conf.tier_promote_frequency = freq; - - ret = dict_get_int32(this->options, "tier-demote-frequency", &freq); - if (ret) { - freq = DEFAULT_DEMOTE_FREQ_SEC; - } - - defrag->tier_conf.tier_demote_frequency = freq; - - ret = dict_get_int32(this->options, "tier-hot-compact-frequency", &freq); - if (ret) { - freq = DEFAULT_HOT_COMPACT_FREQ_SEC; - } - - defrag->tier_conf.tier_compact_hot_frequency = freq; - - ret = dict_get_int32(this->options, "tier-cold-compact-frequency", &freq); - if (ret) { - freq = DEFAULT_COLD_COMPACT_FREQ_SEC; - } - - defrag->tier_conf.tier_compact_cold_frequency = freq; - - ret = dict_get_int32(this->options, "watermark-hi", &freq); - if (ret) { - freq = DEFAULT_WM_HI; - } - - defrag->tier_conf.watermark_hi = freq; - - ret = dict_get_int32(this->options, "watermark-low", &freq); - if (ret) { - freq = DEFAULT_WM_LOW; - } - - defrag->tier_conf.watermark_low = freq; - - ret = dict_get_int32(this->options, "write-freq-threshold", &freq); - if (ret) { - freq = DEFAULT_WRITE_FREQ_SEC; - } - - defrag->write_freq_threshold = freq; - - ret = dict_get_int32(this->options, "read-freq-threshold", &freq); - if (ret) { - freq = DEFAULT_READ_FREQ_SEC; - } - - defrag->read_freq_threshold = freq; - - ret = dict_get_int32(this->options, "tier-max-mb", &freq); - if (ret) { - freq = DEFAULT_TIER_MAX_MIGRATE_MB; - } - - defrag->tier_conf.max_migrate_bytes = (uint64_t)freq * 1024 * 1024; - - ret = dict_get_int32(this->options, "tier-max-files", &freq); - if (ret) { - freq = DEFAULT_TIER_MAX_MIGRATE_FILES; - } - - defrag->tier_conf.max_migrate_files = freq; - - ret = dict_get_int32(this->options, "tier-query-limit", - &(defrag->tier_conf.query_limit)); - if (ret) { - defrag->tier_conf.query_limit = DEFAULT_TIER_QUERY_LIMIT; - } - - ret = dict_get_str(this->options, "tier-compact", &mode); - - if (ret) { - defrag->tier_conf.compact_active = DEFAULT_COMP_MODE; - } else { - compact_mode = tier_validate_compact_mode(mode); - /* If compaction is now active, we need to inform the bricks on - the hot and cold tier of this. See dht-common.h for more. */ - defrag->tier_conf.compact_active = compact_mode; - if (compact_mode) { - defrag->tier_conf.compact_mode_switched_hot = _gf_true; - defrag->tier_conf.compact_mode_switched_cold = _gf_true; - } - } - - ret = dict_get_str(this->options, "tier-mode", &mode); - if (ret) { - defrag->tier_conf.mode = DEFAULT_TIER_MODE; - } else { - tier_mode = tier_validate_mode(mode); - defrag->tier_conf.mode = tier_mode; - } - - pthread_mutex_init(&defrag->tier_conf.pause_mutex, 0); - - gf_defrag_set_pause_state(&defrag->tier_conf, TIER_RUNNING); - - ret = dict_get_str(this->options, "tier-pause", &paused); - - if (paused && strcmp(paused, "on") == 0) - gf_defrag_set_pause_state(&defrag->tier_conf, TIER_REQUEST_PAUSE); - - ret = gf_asprintf(&voldir, "%s/%s", DEFAULT_VAR_RUN_DIRECTORY, this->name); - if (ret < 0) - goto out; - - ret = mkdir_p(voldir, 0777, _gf_true); - if (ret == -1 && errno != EEXIST) { - gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "tier_init failed"); - - GF_FREE(voldir); - goto out; - } - - GF_FREE(voldir); - - ret = gf_asprintf(&promotion_qfile, "%s/%s/promote", - DEFAULT_VAR_RUN_DIRECTORY, this->name); - if (ret < 0) - goto out; - - ret = gf_asprintf(&demotion_qfile, "%s/%s/demote", - DEFAULT_VAR_RUN_DIRECTORY, this->name); - if (ret < 0) { - GF_FREE(promotion_qfile); - goto out; - } - - gf_msg(this->name, GF_LOG_INFO, 0, DHT_MSG_LOG_TIER_STATUS, - "Promote/demote frequency %d/%d " - "Write/Read freq thresholds %d/%d", - defrag->tier_conf.tier_promote_frequency, - defrag->tier_conf.tier_demote_frequency, - defrag->write_freq_threshold, defrag->read_freq_threshold); - - tier_save_vol_name(this); - - ret = 0; - -out: - - return ret; -} - -int -tier_cli_pause_done(int op_ret, call_frame_t *sync_frame, void *data) -{ - gf_msg("tier", GF_LOG_INFO, 0, DHT_MSG_TIER_PAUSED, - "Migrate file paused with op_ret %d", op_ret); - - return op_ret; -} - -int -tier_cli_pause(void *data) -{ - gf_defrag_info_t *defrag = NULL; - xlator_t *this = NULL; - dht_conf_t *conf = NULL; - int ret = -1; - - this = data; - - conf = this->private; - GF_VALIDATE_OR_GOTO(this->name, conf, exit); - - defrag = conf->defrag; - GF_VALIDATE_OR_GOTO(this->name, defrag, exit); - - gf_defrag_pause_tier(this, defrag); - - ret = 0; -exit: - return ret; -} - -int -tier_reconfigure(xlator_t *this, dict_t *options) -{ - dht_conf_t *conf = NULL; - gf_defrag_info_t *defrag = NULL; - char *mode = NULL; - int migrate_mb = 0; - gf_boolean_t req_pause = _gf_false; - int ret = 0; - call_frame_t *frame = NULL; - gf_boolean_t last_compact_setting = _gf_false; - - conf = this->private; - - if (conf->defrag) { - defrag = conf->defrag; - GF_OPTION_RECONF("tier-max-promote-file-size", - defrag->tier_conf.tier_max_promote_size, options, - int32, out); - - GF_OPTION_RECONF("tier-promote-frequency", - defrag->tier_conf.tier_promote_frequency, options, - int32, out); - - GF_OPTION_RECONF("tier-demote-frequency", - defrag->tier_conf.tier_demote_frequency, options, - int32, out); - - GF_OPTION_RECONF("write-freq-threshold", defrag->write_freq_threshold, - options, int32, out); - - GF_OPTION_RECONF("read-freq-threshold", defrag->read_freq_threshold, - options, int32, out); - - GF_OPTION_RECONF("watermark-hi", defrag->tier_conf.watermark_hi, - options, int32, out); - - GF_OPTION_RECONF("watermark-low", defrag->tier_conf.watermark_low, - options, int32, out); - - last_compact_setting = defrag->tier_conf.compact_active; - - GF_OPTION_RECONF("tier-compact", defrag->tier_conf.compact_active, - options, bool, out); - - if (last_compact_setting != defrag->tier_conf.compact_active) { - defrag->tier_conf.compact_mode_switched_hot = _gf_true; - defrag->tier_conf.compact_mode_switched_cold = _gf_true; - gf_msg(this->name, GF_LOG_INFO, 0, DHT_MSG_LOG_TIER_STATUS, - "compact mode switched"); - } - - GF_OPTION_RECONF("tier-hot-compact-frequency", - defrag->tier_conf.tier_compact_hot_frequency, options, - int32, out); - - GF_OPTION_RECONF("tier-cold-compact-frequency", - defrag->tier_conf.tier_compact_cold_frequency, options, - int32, out); - - GF_OPTION_RECONF("tier-mode", mode, options, str, out); - defrag->tier_conf.mode = tier_validate_mode(mode); - - GF_OPTION_RECONF("tier-max-mb", migrate_mb, options, int32, out); - defrag->tier_conf.max_migrate_bytes = (uint64_t)migrate_mb * 1024 * - 1024; - - GF_OPTION_RECONF("tier-max-files", defrag->tier_conf.max_migrate_files, - options, int32, out); - - GF_OPTION_RECONF("tier-query-limit", defrag->tier_conf.query_limit, - options, int32, out); - - GF_OPTION_RECONF("tier-pause", req_pause, options, bool, out); - - if (req_pause == _gf_true) { - frame = create_frame(this, this->ctx->pool); - if (!frame) - goto out; - - frame->root->pid = GF_CLIENT_PID_DEFRAG; - - ret = synctask_new(this->ctx->env, tier_cli_pause, - tier_cli_pause_done, frame, this); - - if (ret) { - gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "pause tier failed on reconfigure"); - } - } else { - ret = gf_defrag_resume_tier(this, defrag); - if (ret) { - gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR, - "resume tier failed on reconfigure"); - } - } - } - -out: - return dht_reconfigure(this, options); -} - -void -tier_fini(xlator_t *this) -{ - if (libhandle) - dlclose(libhandle); - - GF_FREE(demotion_qfile); - GF_FREE(promotion_qfile); - - dht_fini(this); -} - -class_methods_t class_methods = {.init = tier_init, - .fini = tier_fini, - .reconfigure = tier_reconfigure, - .notify = dht_notify}; - -struct xlator_fops fops = { - - .lookup = dht_lookup, - .create = tier_create, - .mknod = dht_mknod, - - .open = dht_open, - .statfs = tier_statfs, - .opendir = dht_opendir, - .readdir = tier_readdir, - .readdirp = tier_readdirp, - .fsyncdir = dht_fsyncdir, - .symlink = dht_symlink, - .unlink = tier_unlink, - .link = tier_link, - .mkdir = dht_mkdir, - .rmdir = dht_rmdir, - .rename = dht_rename, - .entrylk = dht_entrylk, - .fentrylk = dht_fentrylk, - - /* Inode read operations */ - .stat = dht_stat, - .fstat = dht_fstat, - .access = dht_access, - .readlink = dht_readlink, - .getxattr = dht_getxattr, - .fgetxattr = dht_fgetxattr, - .readv = dht_readv, - .flush = dht_flush, - .fsync = dht_fsync, - .inodelk = dht_inodelk, - .finodelk = dht_finodelk, - .lk = dht_lk, - - /* Inode write operations */ - .fremovexattr = dht_fremovexattr, - .removexattr = dht_removexattr, - .setxattr = dht_setxattr, - .fsetxattr = dht_fsetxattr, - .truncate = dht_truncate, - .ftruncate = dht_ftruncate, - .writev = dht_writev, - .xattrop = dht_xattrop, - .fxattrop = dht_fxattrop, - .setattr = dht_setattr, - .fsetattr = dht_fsetattr, - .fallocate = dht_fallocate, - .discard = dht_discard, - .zerofill = dht_zerofill, -}; - -struct xlator_cbks cbks = {.release = dht_release, .forget = dht_forget}; diff --git a/xlators/cluster/dht/src/tier.h b/xlators/cluster/dht/src/tier.h deleted file mode 100644 index a20b1db07e0..00000000000 --- a/xlators/cluster/dht/src/tier.h +++ /dev/null @@ -1,110 +0,0 @@ -/* - Copyright (c) 2015 Red Hat, Inc. - This file is part of GlusterFS. - - 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 _TIER_H_ -#define _TIER_H_ - -/******************************************************************************/ -/* This is from dht-rebalancer.c as we don't have dht-rebalancer.h */ -#include "dht-common.h" -#include -#include -#include -#include - -/* - * Size of timer wheel. We would not promote or demote less - * frequently than this number. - */ -#define TIMER_SECS 3600 - -#include "gfdb_data_store.h" -#include -#include - -#define PROMOTION_QFILE "promotequeryfile" -#define DEMOTION_QFILE "demotequeryfile" - -#define TIER_HASHED_SUBVOL conf->subvolumes[0] -#define TIER_UNHASHED_SUBVOL conf->subvolumes[1] - -#define GET_QFILE_PATH(is_promotion) \ - (is_promotion) ? promotion_qfile : demotion_qfile - -typedef struct tier_qfile_array { - int *fd_array; - ssize_t array_size; - ssize_t next_index; - /* Indicate the number of exhuasted FDs*/ - ssize_t exhausted_count; -} tier_qfile_array_t; - -typedef struct _query_cbk_args { - xlator_t *this; - gf_defrag_info_t *defrag; - /* This is write */ - int query_fd; - int is_promotion; - int is_compaction; - /* This is for read */ - tier_qfile_array_t *qfile_array; -} query_cbk_args_t; - -int -gf_run_tier(xlator_t *this, gf_defrag_info_t *defrag); - -typedef struct gfdb_brick_info { - gfdb_time_t *time_stamp; - gf_boolean_t _gfdb_promote; - query_cbk_args_t *_query_cbk_args; -} gfdb_brick_info_t; - -typedef struct brick_list { - xlator_t *xlator; - char *brick_db_path; - char brick_name[NAME_MAX]; - char qfile_path[PATH_MAX]; - struct list_head list; -} tier_brick_list_t; - -typedef struct _dm_thread_args { - xlator_t *this; - gf_defrag_info_t *defrag; - struct list_head *brick_list; - int freq_time; - int return_value; - int is_promotion; - int is_compaction; - gf_boolean_t is_hot_tier; -} migration_args_t; - -typedef enum tier_watermark_op_ { - TIER_WM_NONE = 0, - TIER_WM_LOW, - TIER_WM_HI, - TIER_WM_MID -} tier_watermark_op_t; - -#define DEFAULT_PROMOTE_FREQ_SEC 120 -#define DEFAULT_DEMOTE_FREQ_SEC 120 -#define DEFAULT_HOT_COMPACT_FREQ_SEC 604800 -#define DEFAULT_COLD_COMPACT_FREQ_SEC 604800 -#define DEFAULT_DEMOTE_DEGRADED 1 -#define DEFAULT_WRITE_FREQ_SEC 0 -#define DEFAULT_READ_FREQ_SEC 0 -#define DEFAULT_WM_LOW 75 -#define DEFAULT_WM_HI 90 -#define DEFAULT_TIER_MODE TIER_MODE_TEST -#define DEFAULT_COMP_MODE _gf_true -#define DEFAULT_TIER_MAX_MIGRATE_MB 1000 -#define DEFAULT_TIER_MAX_MIGRATE_FILES 5000 -#define DEFAULT_TIER_QUERY_LIMIT 100 - -#endif diff --git a/xlators/cluster/dht/src/tier.sym b/xlators/cluster/dht/src/tier.sym deleted file mode 100644 index 60205d145b6..00000000000 --- a/xlators/cluster/dht/src/tier.sym +++ /dev/null @@ -1,9 +0,0 @@ -fops -cbks -class_methods -dht_methods -tier_methods -options -mem_acct_init -reconfigure -dumpops diff --git a/xlators/cluster/stripe/Makefile.am b/xlators/cluster/stripe/Makefile.am deleted file mode 100644 index d471a3f9243..00000000000 --- a/xlators/cluster/stripe/Makefile.am +++ /dev/null @@ -1,3 +0,0 @@ -SUBDIRS = src - -CLEANFILES = diff --git a/xlators/cluster/stripe/src/Makefile.am b/xlators/cluster/stripe/src/Makefile.am deleted file mode 100644 index 2b594567db1..00000000000 --- a/xlators/cluster/stripe/src/Makefile.am +++ /dev/null @@ -1,22 +0,0 @@ -xlator_LTLIBRARIES = stripe.la -xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator/cluster - -stripe_la_LDFLAGS = -module $(GF_XLATOR_DEFAULT_LDFLAGS) - - -stripe_la_SOURCES = stripe.c stripe-helpers.c \ - $(top_builddir)/xlators/lib/src/libxlator.c - -stripe_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la - -noinst_HEADERS = stripe.h stripe-mem-types.h \ - $(top_builddir)/xlators/lib/src/libxlator.h - -AM_CPPFLAGS = $(GF_CPPFLAGS) -I$(top_srcdir)/libglusterfs/src \ - -I$(top_srcdir)/xlators/lib/src \ - -I$(top_srcdir)/rpc/xdr/src -I$(top_builddir)/rpc/xdr/src - -AM_CFLAGS = -Wall $(GF_CFLAGS) - -CLEANFILES = - diff --git a/xlators/cluster/stripe/src/stripe-helpers.c b/xlators/cluster/stripe/src/stripe-helpers.c deleted file mode 100644 index 35342378985..00000000000 --- a/xlators/cluster/stripe/src/stripe-helpers.c +++ /dev/null @@ -1,658 +0,0 @@ -/* - Copyright (c) 2008-2012 Red Hat, Inc. - This file is part of GlusterFS. - - 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. -*/ - -#include - -#include "stripe.h" -#include -#include -#include - -void -stripe_local_wipe(stripe_local_t *local) -{ - if (!local) - goto out; - - loc_wipe(&local->loc); - loc_wipe(&local->loc2); - - if (local->fd) - fd_unref(local->fd); - - if (local->inode) - inode_unref(local->inode); - - if (local->xattr) - dict_unref(local->xattr); - - if (local->xdata) - dict_unref(local->xdata); - -out: - return; -} - -int -stripe_aggregate(dict_t *this, char *key, data_t *value, void *data) -{ - dict_t *dst = NULL; - int64_t *ptr = 0, *size = NULL; - int32_t ret = -1; - - dst = data; - - if (strcmp(key, QUOTA_SIZE_KEY) == 0) { - ret = dict_get_bin(dst, key, (void **)&size); - if (ret < 0) { - size = GF_CALLOC(1, sizeof(int64_t), gf_common_mt_char); - if (size == NULL) { - gf_log("stripe", GF_LOG_WARNING, "memory allocation failed"); - goto out; - } - ret = dict_set_bin(dst, key, size, sizeof(int64_t)); - if (ret < 0) { - gf_log("stripe", GF_LOG_WARNING, - "stripe aggregate dict set failed"); - GF_FREE(size); - goto out; - } - } - - ptr = data_to_bin(value); - if (ptr == NULL) { - gf_log("stripe", GF_LOG_WARNING, "data to bin failed"); - goto out; - } - - *size = hton64(ntoh64(*size) + ntoh64(*ptr)); - } else if (strcmp(key, GF_CONTENT_KEY)) { - /* No need to aggregate 'CONTENT' data */ - ret = dict_set(dst, key, value); - if (ret) - gf_log("stripe", GF_LOG_WARNING, "xattr dict set failed"); - } - -out: - return 0; -} - -void -stripe_aggregate_xattr(dict_t *dst, dict_t *src) -{ - if ((dst == NULL) || (src == NULL)) { - goto out; - } - - dict_foreach(src, stripe_aggregate, dst); -out: - return; -} - -int32_t -stripe_xattr_aggregate(char *buffer, stripe_local_t *local, int32_t *total) -{ - int32_t i = 0; - int32_t ret = -1; - int32_t len = 0; - char *sbuf = NULL; - stripe_xattr_sort_t *xattr = NULL; - - if (!buffer || !local || !local->xattr_list) - goto out; - - sbuf = buffer; - - for (i = 0; i < local->nallocs; i++) { - xattr = local->xattr_list + i; - len = xattr->xattr_len - 1; /* length includes \0 */ - - if (len && xattr && xattr->xattr_value) { - memcpy(buffer, xattr->xattr_value, len); - buffer += len; - *buffer++ = ' '; - } - } - - *--buffer = '\0'; - if (total) - *total = buffer - sbuf; - ret = 0; - -out: - return ret; -} - -int32_t -stripe_free_xattr_str(stripe_local_t *local) -{ - int32_t i = 0; - int32_t ret = -1; - stripe_xattr_sort_t *xattr = NULL; - - if (!local || !local->xattr_list) - goto out; - - for (i = 0; i < local->nallocs; i++) { - xattr = local->xattr_list + i; - - if (xattr && xattr->xattr_value) - GF_FREE(xattr->xattr_value); - } - - ret = 0; -out: - return ret; -} - -int32_t -stripe_fill_lockinfo_xattr(xlator_t *this, stripe_local_t *local, - void **xattr_serz) -{ - int32_t ret = -1, i = 0, len = 0; - dict_t *tmp1 = NULL, *tmp2 = NULL; - char *buf = NULL; - stripe_xattr_sort_t *xattr = NULL; - - if (xattr_serz == NULL) { - goto out; - } - - tmp2 = dict_new(); - - if (tmp2 == NULL) { - goto out; - } - - for (i = 0; i < local->nallocs; i++) { - xattr = local->xattr_list + i; - len = xattr->xattr_len; - - if (len && xattr && xattr->xattr_value) { - ret = dict_reset(tmp2); - if (ret < 0) { - gf_log(this->name, GF_LOG_DEBUG, "dict_reset failed (%s)", - strerror(-ret)); - } - - ret = dict_unserialize(xattr->xattr_value, xattr->xattr_len, &tmp2); - if (ret < 0) { - gf_log(this->name, GF_LOG_WARNING, - "dict_unserialize failed (%s)", strerror(-ret)); - ret = -1; - goto out; - } - - tmp1 = dict_copy(tmp2, tmp1); - if (tmp1 == NULL) { - gf_log(this->name, GF_LOG_WARNING, "dict_copy failed (%s)", - strerror(-ret)); - ret = -1; - goto out; - } - } - } - - len = dict_serialized_length(tmp1); - if (len > 0) { - buf = GF_CALLOC(1, len, gf_common_mt_dict_t); - if (buf == NULL) { - ret = -1; - goto out; - } - - ret = dict_serialize(tmp1, buf); - if (ret < 0) { - gf_log(this->name, GF_LOG_WARNING, "dict_serialize failed (%s)", - strerror(-ret)); - GF_FREE(buf); - ret = -1; - goto out; - } - - *xattr_serz = buf; - } - - ret = 0; -out: - if (tmp1 != NULL) { - dict_unref(tmp1); - } - - if (tmp2 != NULL) { - dict_unref(tmp2); - } - - return ret; -} - -int32_t -stripe_fill_pathinfo_xattr(xlator_t *this, stripe_local_t *local, - char **xattr_serz) -{ - int ret = -1; - int32_t padding = 0; - int32_t tlen = 0; - int len = 0; - char stripe_size_str[20] = { - 0, - }; - char *pathinfo_serz = NULL; - - if (!local) { - gf_log(this->name, GF_LOG_ERROR, "Possible NULL deref"); - goto out; - } - - len = snprintf(stripe_size_str, sizeof(stripe_size_str), "%" PRId64, - local->fctx ? local->fctx->stripe_size : 0); - if (len < 0 || len >= sizeof(stripe_size_str)) - goto out; - /* extra bytes for decorations (brackets and <>'s) */ - padding = strlen(this->name) + SLEN(STRIPE_PATHINFO_HEADER) + len + 7; - local->xattr_total_len += (padding + 2); - - pathinfo_serz = GF_MALLOC(local->xattr_total_len, gf_common_mt_char); - if (!pathinfo_serz) - goto out; - - /* xlator info */ - (void)sprintf(pathinfo_serz, "(<" STRIPE_PATHINFO_HEADER "%s:[%s]> ", - this->name, stripe_size_str); - - ret = stripe_xattr_aggregate(pathinfo_serz + padding, local, &tlen); - if (ret) { - gf_log(this->name, GF_LOG_ERROR, "Cannot aggregate pathinfo list"); - GF_FREE(pathinfo_serz); - goto out; - } - - *(pathinfo_serz + padding + tlen) = ')'; - *(pathinfo_serz + padding + tlen + 1) = '\0'; - - *xattr_serz = pathinfo_serz; - - ret = 0; -out: - return ret; -} - -/** - * stripe_get_matching_bs - Get the matching block size for the given path. - */ -int32_t -stripe_get_matching_bs(const char *path, stripe_private_t *priv) -{ - struct stripe_options *trav = NULL; - uint64_t block_size = 0; - - GF_VALIDATE_OR_GOTO("stripe", priv, out); - GF_VALIDATE_OR_GOTO("stripe", path, out); - - LOCK(&priv->lock); - { - block_size = priv->block_size; - trav = priv->pattern; - while (trav) { - if (!fnmatch(trav->path_pattern, path, FNM_NOESCAPE)) { - block_size = trav->block_size; - break; - } - trav = trav->next; - } - } - UNLOCK(&priv->lock); - -out: - return block_size; -} - -int32_t -stripe_ctx_handle(xlator_t *this, call_frame_t *prev, stripe_local_t *local, - dict_t *dict) -{ - char key[256] = { - 0, - }; - data_t *data = NULL; - int32_t index = 0; - stripe_private_t *priv = NULL; - - priv = this->private; - - if (!local->fctx) { - local->fctx = GF_CALLOC(1, sizeof(stripe_fd_ctx_t), - gf_stripe_mt_stripe_fd_ctx_t); - if (!local->fctx) { - local->op_errno = ENOMEM; - local->op_ret = -1; - goto out; - } - - local->fctx->static_array = 0; - } - /* Stripe block size */ - sprintf(key, "trusted.%s.stripe-size", this->name); - data = dict_get(dict, key); - if (!data) { - local->xattr_self_heal_needed = 1; - gf_log(this->name, GF_LOG_ERROR, "Failed to get stripe-size"); - goto out; - } else { - if (!local->fctx->stripe_size) { - local->fctx->stripe_size = data_to_int64(data); - } - - if (local->fctx->stripe_size != data_to_int64(data)) { - gf_log(this->name, GF_LOG_WARNING, - "stripe-size mismatch in blocks"); - local->xattr_self_heal_needed = 1; - } - } - - /* Stripe count */ - sprintf(key, "trusted.%s.stripe-count", this->name); - data = dict_get(dict, key); - - if (!data) { - local->xattr_self_heal_needed = 1; - gf_log(this->name, GF_LOG_ERROR, "Failed to get stripe-count"); - goto out; - } - if (!local->fctx->xl_array) { - local->fctx->stripe_count = data_to_int32(data); - if (!local->fctx->stripe_count) { - gf_log(this->name, GF_LOG_ERROR, "error with stripe-count xattr"); - local->op_ret = -1; - local->op_errno = EIO; - goto out; - } - - local->fctx->xl_array = GF_CALLOC(local->fctx->stripe_count, - sizeof(xlator_t *), - gf_stripe_mt_xlator_t); - - if (!local->fctx->xl_array) { - local->op_errno = ENOMEM; - local->op_ret = -1; - goto out; - } - } - if (local->fctx->stripe_count != data_to_int32(data)) { - gf_log(this->name, GF_LOG_ERROR, - "error with stripe-count xattr (%d != %d)", - local->fctx->stripe_count, data_to_int32(data)); - local->op_ret = -1; - local->op_errno = EIO; - goto out; - } - - /* index */ - sprintf(key, "trusted.%s.stripe-index", this->name); - data = dict_get(dict, key); - if (!data) { - local->xattr_self_heal_needed = 1; - gf_log(this->name, GF_LOG_ERROR, "Failed to get stripe-index"); - goto out; - } - index = data_to_int32(data); - if (index > priv->child_count) { - gf_log(this->name, GF_LOG_ERROR, "error with stripe-index xattr (%d)", - index); - local->op_ret = -1; - local->op_errno = EIO; - goto out; - } - if (local->fctx->xl_array) { - if (!local->fctx->xl_array[index]) - local->fctx->xl_array[index] = prev->this; - } - - sprintf(key, "trusted.%s.stripe-coalesce", this->name); - data = dict_get(dict, key); - if (!data) { - /* - * The file was probably created prior to coalesce support. - * Assume non-coalesce mode for this file to maintain backwards - * compatibility. - */ - gf_log(this->name, GF_LOG_DEBUG, - "missing stripe-coalesce " - "attr, assume non-coalesce mode"); - local->fctx->stripe_coalesce = 0; - } else { - local->fctx->stripe_coalesce = data_to_int32(data); - } - -out: - return 0; -} - -int32_t -stripe_xattr_request_build(xlator_t *this, dict_t *dict, uint64_t stripe_size, - uint32_t stripe_count, uint32_t stripe_index, - uint32_t stripe_coalesce) -{ - char key[256] = { - 0, - }; - int32_t ret = -1; - - sprintf(key, "trusted.%s.stripe-size", this->name); - ret = dict_set_int64(dict, key, stripe_size); - if (ret) { - gf_log(this->name, GF_LOG_WARNING, "failed to set %s in xattr_req dict", - key); - goto out; - } - - sprintf(key, "trusted.%s.stripe-count", this->name); - ret = dict_set_int32(dict, key, stripe_count); - if (ret) { - gf_log(this->name, GF_LOG_WARNING, "failed to set %s in xattr_req dict", - key); - goto out; - } - - sprintf(key, "trusted.%s.stripe-index", this->name); - ret = dict_set_int32(dict, key, stripe_index); - if (ret) { - gf_log(this->name, GF_LOG_WARNING, "failed to set %s in xattr_req dict", - key); - goto out; - } - - sprintf(key, "trusted.%s.stripe-coalesce", this->name); - ret = dict_set_int32(dict, key, stripe_coalesce); - if (ret) { - gf_log(this->name, GF_LOG_WARNING, "failed to set %s in xattr_req_dict", - key); - goto out; - } -out: - return ret; -} - -static int -set_default_block_size(stripe_private_t *priv, char *num) -{ - int ret = -1; - GF_VALIDATE_OR_GOTO("stripe", THIS, out); - GF_VALIDATE_OR_GOTO(THIS->name, priv, out); - GF_VALIDATE_OR_GOTO(THIS->name, num, out); - - if (gf_string2bytesize_uint64(num, &priv->block_size) != 0) { - gf_log(THIS->name, GF_LOG_ERROR, "invalid number format \"%s\"", num); - goto out; - } - - ret = 0; - -out: - return ret; -} - -int -set_stripe_block_size(xlator_t *this, stripe_private_t *priv, char *data) -{ - int ret = -1; - char *tmp_str = NULL; - char *tmp_str1 = NULL; - char *dup_str = NULL; - char *stripe_str = NULL; - char *pattern = NULL; - char *num = NULL; - struct stripe_options *temp_stripeopt = NULL; - struct stripe_options *stripe_opt = NULL; - - if (!this || !priv || !data) - goto out; - - /* Get the pattern for striping. - "option block-size *avi:10MB" etc */ - stripe_str = strtok_r(data, ",", &tmp_str); - while (stripe_str) { - dup_str = gf_strdup(stripe_str); - stripe_opt = GF_CALLOC(1, sizeof(struct stripe_options), - gf_stripe_mt_stripe_options); - if (!stripe_opt) { - goto out; - } - - pattern = strtok_r(dup_str, ":", &tmp_str1); - num = strtok_r(NULL, ":", &tmp_str1); - if (!num) { - num = pattern; - pattern = "*"; - ret = set_default_block_size(priv, num); - if (ret) - goto out; - } - if (gf_string2bytesize_uint64(num, &stripe_opt->block_size) != 0) { - gf_log(this->name, GF_LOG_ERROR, "invalid number format \"%s\"", - num); - goto out; - } - - if (stripe_opt->block_size < STRIPE_MIN_BLOCK_SIZE) { - gf_log(this->name, GF_LOG_ERROR, - "Invalid Block-size: " - "%s. Should be at least %llu bytes", - num, STRIPE_MIN_BLOCK_SIZE); - goto out; - } - if (stripe_opt->block_size % 512) { - gf_log(this->name, GF_LOG_ERROR, - "Block-size: %s should" - " be a multiple of 512 bytes", - num); - goto out; - } - - memcpy(stripe_opt->path_pattern, pattern, strlen(pattern)); - - gf_log(this->name, GF_LOG_DEBUG, - "block-size : pattern %s : size %" PRId64, - stripe_opt->path_pattern, stripe_opt->block_size); - - if (priv->pattern) - temp_stripeopt = NULL; - else - temp_stripeopt = priv->pattern; - - stripe_opt->next = temp_stripeopt; - - priv->pattern = stripe_opt; - stripe_opt = NULL; - - GF_FREE(dup_str); - dup_str = NULL; - - stripe_str = strtok_r(NULL, ",", &tmp_str); - } - - ret = 0; -out: - - GF_FREE(dup_str); - - GF_FREE(stripe_opt); - - return ret; -} - -int32_t -stripe_iatt_merge(struct iatt *from, struct iatt *to) -{ - if (to->ia_size < from->ia_size) - to->ia_size = from->ia_size; - if (to->ia_mtime < from->ia_mtime) - to->ia_mtime = from->ia_mtime; - if (to->ia_ctime < from->ia_ctime) - to->ia_ctime = from->ia_ctime; - if (to->ia_atime < from->ia_atime) - to->ia_atime = from->ia_atime; - return 0; -} - -off_t -coalesced_offset(off_t offset, uint64_t stripe_size, int stripe_count) -{ - size_t line_size = 0; - uint64_t stripe_num = 0; - off_t coalesced_offset = 0; - - line_size = stripe_size * stripe_count; - stripe_num = offset / line_size; - - coalesced_offset = (stripe_num * stripe_size) + (offset % stripe_size); - - return coalesced_offset; -} - -off_t -uncoalesced_size(off_t size, uint64_t stripe_size, int stripe_count, - int stripe_index) -{ - uint64_t nr_full_stripe_chunks = 0, mod = 0; - - if (!size) - return size; - - /* - * Estimate the number of fully written stripes from the - * local file size. Each stripe_size chunk corresponds to - * a stripe. - */ - nr_full_stripe_chunks = (size / stripe_size) * stripe_count; - mod = size % stripe_size; - - if (!mod) { - /* - * There is no remainder, thus we could have overestimated - * the size of the file in terms of chunks. Trim the number - * of chunks by the following stripe members and leave it - * up to those nodes to respond with a larger size (if - * necessary). - */ - nr_full_stripe_chunks -= stripe_count - (stripe_index + 1); - size = nr_full_stripe_chunks * stripe_size; - } else { - /* - * There is a remainder and thus we own the last chunk of the - * file. Add the preceding stripe members of the final stripe - * along with the remainder to calculate the exact size. - */ - nr_full_stripe_chunks += stripe_index; - size = nr_full_stripe_chunks * stripe_size + mod; - } - - return size; -} diff --git a/xlators/cluster/stripe/src/stripe-mem-types.h b/xlators/cluster/stripe/src/stripe-mem-types.h deleted file mode 100644 index 3ca6ecc7a41..00000000000 --- a/xlators/cluster/stripe/src/stripe-mem-types.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - Copyright (c) 2008-2012 Red Hat, Inc. - This file is part of GlusterFS. - - 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 __STRIPE_MEM_TYPES_H__ -#define __STRIPE_MEM_TYPES_H__ - -#include - -enum gf_stripe_mem_types_ { - gf_stripe_mt_iovec = gf_common_mt_end + 1, - gf_stripe_mt_stripe_replies, - gf_stripe_mt_stripe_fd_ctx_t, - gf_stripe_mt_char, - gf_stripe_mt_int8_t, - gf_stripe_mt_int32_t, - gf_stripe_mt_xlator_t, - gf_stripe_mt_stripe_private_t, - gf_stripe_mt_stripe_options, - gf_stripe_mt_xattr_sort_t, - gf_stripe_mt_end -}; -#endif diff --git a/xlators/cluster/stripe/src/stripe.c b/xlators/cluster/stripe/src/stripe.c deleted file mode 100644 index 557a8185352..00000000000 --- a/xlators/cluster/stripe/src/stripe.c +++ /dev/null @@ -1,5612 +0,0 @@ -/* - Copyright (c) 2008-2012 Red Hat, Inc. - This file is part of GlusterFS. - - 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. -*/ - -/** - * xlators/cluster/stripe: - * Stripe translator, stripes the data across its child nodes, - * as per the options given in the volfile. The striping works - * fairly simple. It writes files at different offset as per - * calculation. So, 'ls -l' output at the real posix level will - * show file size bigger than the actual size. But when one does - * 'df' or 'du ', real size of the file on the server is shown. - * - * WARNING: - * Stripe translator can't regenerate data if a child node gets disconnected. - * So, no 'self-heal' for stripe. Hence the advice, use stripe only when its - * very much necessary, or else, use it in combination with AFR, to have a - * backup copy. - */ -#include -#include "stripe.h" -#include "libxlator.h" -#include -#include - -struct volume_options options[]; - -int32_t -stripe_sh_chown_cbk(call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct iatt *preop, - struct iatt *postop, dict_t *xdata) -{ - int callcnt = -1; - stripe_local_t *local = NULL; - - if (!this || !frame || !frame->local) { - gf_log("stripe", GF_LOG_DEBUG, "possible NULL deref"); - goto out; - } - - local = frame->local; - - LOCK(&frame->lock); - { - callcnt = --local->call_count; - } - UNLOCK(&frame->lock); - - if (!callcnt) { - STRIPE_STACK_DESTROY(frame); - } -out: - return 0; -} - -int32_t -stripe_sh_make_entry_cbk(call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, inode_t *inode, - struct iatt *buf, struct iatt *preparent, - struct iatt *postparent, dict_t *xdata) -{ - stripe_local_t *local = NULL; - call_frame_t *prev = NULL; - - if (!frame || !frame->local || !cookie || !this) { - gf_log("stripe", GF_LOG_DEBUG, "possible NULL deref"); - goto out; - } - - prev = cookie; - local = frame->local; - - STACK_WIND(frame, stripe_sh_chown_cbk, prev->this, - prev->this->fops->setattr, &local->loc, &local->stbuf, - (GF_SET_ATTR_UID | GF_SET_ATTR_GID), NULL); - -out: - return 0; -} - -int32_t -stripe_entry_self_heal(call_frame_t *frame, xlator_t *this, - stripe_local_t *local) -{ - xlator_list_t *trav = NULL; - call_frame_t *rframe = NULL; - stripe_local_t *rlocal = NULL; - stripe_private_t *priv = NULL; - dict_t *xdata = NULL; - int ret = 0; - - if (!local || !this || !frame) { - gf_log("stripe", GF_LOG_DEBUG, "possible NULL deref"); - goto out; - } - - if (!(IA_ISREG(local->stbuf.ia_type) || IA_ISDIR(local->stbuf.ia_type))) - return 0; - - priv = this->private; - trav = this->children; - rframe = copy_frame(frame); - if (!rframe) { - goto out; - } - rlocal = mem_get0(this->local_pool); - if (!rlocal) { - goto out; - } - rframe->local = rlocal; - rlocal->call_count = priv->child_count; - loc_copy(&rlocal->loc, &local->loc); - memcpy(&rlocal->stbuf, &local->stbuf, sizeof(struct iatt)); - - xdata = dict_new(); - if (!xdata) - goto out; - - ret = dict_set_gfuuid(xdata, "gfid-req", local->stbuf.ia_gfid, true); - if (ret) - gf_log(this->name, GF_LOG_WARNING, "%s: failed to set gfid-req", - local->loc.path); - - while (trav) { - if (IA_ISREG(local->stbuf.ia_type)) { - STACK_WIND( - rframe, stripe_sh_make_entry_cbk, trav->xlator, - trav->xlator->fops->mknod, &local->loc, - st_mode_from_ia(local->stbuf.ia_prot, local->stbuf.ia_type), 0, - 0, xdata); - } - if (IA_ISDIR(local->stbuf.ia_type)) { - STACK_WIND( - rframe, stripe_sh_make_entry_cbk, trav->xlator, - trav->xlator->fops->mkdir, &local->loc, - st_mode_from_ia(local->stbuf.ia_prot, local->stbuf.ia_type), 0, - xdata); - } - trav = trav->next; - } - - if (xdata) - dict_unref(xdata); - return 0; - -out: - if (rframe) - STRIPE_STACK_DESTROY(rframe); - - return 0; -} - -int32_t -stripe_lookup_cbk(call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, inode_t *inode, - struct iatt *buf, dict_t *xdata, struct iatt *postparent) -{ - int32_t callcnt = 0; - stripe_local_t *local = NULL; - call_frame_t *prev = NULL; - int ret = 0; - - if (!this || !frame || !frame->local || !cookie) { - gf_log("stripe", GF_LOG_DEBUG, "possible NULL deref"); - goto out; - } - - prev = cookie; - local = frame->local; - - LOCK(&frame->lock); - { - callcnt = --local->call_count; - - if (op_ret == -1) { - if ((op_errno != ENOENT) && (op_errno != ESTALE)) - gf_log(this->name, GF_LOG_DEBUG, "%s returned error %s", - prev->this->name, strerror(op_errno)); - if (local->op_errno != ESTALE) - local->op_errno = op_errno; - if (((op_errno != ENOENT) && (op_errno != ENOTCONN) && - (op_errno != ESTALE)) || - (prev->this == FIRST_CHILD(this))) - local->failed = 1; - if (op_errno == ENOENT) - local->entry_self_heal_needed = 1; - } - - if (op_ret >= 0) { - local->op_ret = 0; - if (IA_ISREG(buf->ia_type)) { - ret = stripe_ctx_handle(this, prev, local, xdata); - if (ret) - gf_log(this->name, GF_LOG_ERROR, - "Error getting fctx info from" - " dict"); - } - - if (FIRST_CHILD(this) == prev->this) { - local->stbuf = *buf; - local->postparent = *postparent; - local->inode = inode_ref(inode); - if (xdata) - local->xdata = dict_ref(xdata); - if (local->xattr) { - stripe_aggregate_xattr(local->xdata, local->xattr); - dict_unref(local->xattr); - local->xattr = NULL; - } - } - - if (!local->xdata && !local->xattr) { - local->xattr = dict_ref(xdata); - } else if (local->xdata) { - stripe_aggregate_xattr(local->xdata, xdata); - } else if (local->xattr) { - stripe_aggregate_xattr(local->xattr, xdata); - } - - local->stbuf_blocks += buf->ia_blocks; - local->postparent_blocks += postparent->ia_blocks; - - correct_file_size(buf, local->fctx, prev); - - if (local->stbuf_size < buf->ia_size) - local->stbuf_size = buf->ia_size; - if (local->postparent_size < postparent->ia_size) - local->postparent_size = postparent->ia_size; - - if (gf_uuid_is_null(local->ia_gfid)) - gf_uuid_copy(local->ia_gfid, buf->ia_gfid); - - /* Make sure the gfid on all the nodes are same */ - if (gf_uuid_compare(local->ia_gfid, buf->ia_gfid)) { - gf_log(this->name, GF_LOG_WARNING, - "%s: gfid different on subvolume %s", local->loc.path, - prev->this->name); - } - } - } - UNLOCK(&frame->lock); - - if (!callcnt) { - if (local->op_ret == 0 && local->entry_self_heal_needed && - !gf_uuid_is_null(local->loc.inode->gfid)) - stripe_entry_self_heal(frame, this, local); - - if (local->failed) - local->op_ret = -1; - - if (local->op_ret != -1) { - local->stbuf.ia_blocks = local->stbuf_blocks; - local->stbuf.ia_size = local->stbuf_size; - local->postparent.ia_blocks = local->postparent_blocks; - local->postparent.ia_size = local->postparent_size; - inode_ctx_put(local->inode, this, (uint64_t)(long)local->fctx); - } - - STRIPE_STACK_UNWIND(lookup, frame, local->op_ret, local->op_errno, - local->inode, &local->stbuf, local->xdata, - &local->postparent); - } -out: - return 0; -} - -int32_t -stripe_lookup(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata) -{ - stripe_local_t *local = NULL; - xlator_list_t *trav = NULL; - stripe_private_t *priv = NULL; - int32_t op_errno = EINVAL; - int64_t filesize = 0; - int ret = 0; - uint64_t tmpctx = 0; - - VALIDATE_OR_GOTO(frame, err); - VALIDATE_OR_GOTO(this, err); - VALIDATE_OR_GOTO(loc, err); - VALIDATE_OR_GOTO(loc->inode, err); - - priv = this->private; - trav = this->children; - - /* Initialization */ - local = mem_get0(this->local_pool); - if (!local) { - op_errno = ENOMEM; - goto err; - } - local->op_ret = -1; - frame->local = local; - loc_copy(&local->loc, loc); - - inode_ctx_get(local->inode, this, &tmpctx); - if (tmpctx) - local->fctx = (stripe_fd_ctx_t *)(long)tmpctx; - - /* quick-read friendly changes */ - if (xdata && dict_get(xdata, GF_CONTENT_KEY)) { - ret = dict_get_int64(xdata, GF_CONTENT_KEY, &filesize); - if (!ret && (filesize > priv->block_size)) - dict_del(xdata, GF_CONTENT_KEY); - } - - /* get stripe-size xattr on lookup. This would be required for - * open/read/write/pathinfo calls. Hence we send down the request - * even when type == IA_INVAL */ - - /* - * We aren't guaranteed to have xdata here. We need the format info for - * the file, so allocate xdata if necessary. - */ - if (!xdata) - xdata = dict_new(); - else - xdata = dict_ref(xdata); - - if (xdata && - (IA_ISREG(loc->inode->ia_type) || (loc->inode->ia_type == IA_INVAL))) { - ret = stripe_xattr_request_build(this, xdata, 8, 4, 4, 0); - if (ret) - gf_log(this->name, GF_LOG_ERROR, - "Failed to build" - " xattr request for %s", - loc->path); - } - - /* Every time in stripe lookup, all child nodes - should be looked up */ - local->call_count = priv->child_count; - while (trav) { - STACK_WIND(frame, stripe_lookup_cbk, trav->xlator, - trav->xlator->fops->lookup, loc, xdata); - trav = trav->next; - } - - dict_unref(xdata); - - return 0; -err: - STRIPE_STACK_UNWIND(lookup, frame, -1, op_errno, NULL, NULL, NULL, NULL); - return 0; -} - -int32_t -stripe_stat_cbk(call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct iatt *buf, - dict_t *xdata) -{ - int32_t callcnt = 0; - stripe_local_t *local = NULL; - call_frame_t *prev = NULL; - - if (!this || !frame || !frame->local || !cookie) { - gf_log("stripe", GF_LOG_DEBUG, "possible NULL deref"); - goto out; - } - prev = cookie; - local = frame->local; - - LOCK(&frame->lock); - { - callcnt = --local->call_count; - - if (op_ret == -1) { - gf_log(this->name, GF_LOG_DEBUG, "%s returned error %s", - prev->this->name, strerror(op_errno)); - local->op_errno = op_errno; - if ((op_errno != ENOENT) || (prev->this == FIRST_CHILD(this))) - local->failed = 1; - } - - if (op_ret == 0) { - local->op_ret = 0; - - if (FIRST_CHILD(this) == prev->this) { - local->stbuf = *buf; - } - - local->stbuf_blocks += buf->ia_blocks; - - correct_file_size(buf, local->fctx, prev); - - if (local->stbuf_size < buf->ia_size) - local->stbuf_size = buf->ia_size; - } - } - UNLOCK(&frame->lock); - - if (!callcnt) { - if (local->failed) - local->op_ret = -1; - - if (local->op_ret != -1) { - local->stbuf.ia_size = local->stbuf_size; - local->stbuf.ia_blocks = local->stbuf_blocks; - } - - STRIPE_STACK_UNWIND(stat, frame, local->op_ret, local->op_errno, - &local->stbuf, NULL); - } -out: - return 0; -} - -int32_t -stripe_stat(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata) -{ - xlator_list_t *trav = NULL; - stripe_local_t *local = NULL; - stripe_private_t *priv = NULL; - stripe_fd_ctx_t *fctx = NULL; - int32_t op_errno = EINVAL; - - VALIDATE_OR_GOTO(frame, err); - VALIDATE_OR_GOTO(this, err); - VALIDATE_OR_GOTO(loc, err); - VALIDATE_OR_GOTO(loc->path, err); - VALIDATE_OR_GOTO(loc->inode, err); - - priv = this->private; - trav = this->children; - - if (priv->first_child_down) { - op_errno = ENOTCONN; - goto err; - } - - /* Initialization */ - local = mem_get0(this->local_pool); - if (!local) { - op_errno = ENOMEM; - goto err; - } - local->op_ret = -1; - frame->local = local; - local->call_count = priv->child_count; - - if (IA_ISREG(loc->inode->ia_type)) { - inode_ctx_get(loc->inode, this, (uint64_t *)&fctx); - if (!fctx) - goto err; - local->fctx = fctx; - } - - while (trav) { - STACK_WIND(frame, stripe_stat_cbk, trav->xlator, - trav->xlator->fops->stat, loc, NULL); - trav = trav->next; - } - - return 0; - -err: - STRIPE_STACK_UNWIND(stat, frame, -1, op_errno, NULL, NULL); - return 0; -} - -int32_t -stripe_statfs_cbk(call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct statvfs *stbuf, - dict_t *xdata) -{ - stripe_local_t *local = NULL; - int32_t callcnt = 0; - - if (!this || !frame || !frame->local) { - gf_log("stripe", GF_LOG_DEBUG, "possible NULL deref"); - goto out; - } - local = frame->local; - - LOCK(&frame->lock); - { - callcnt = --local->call_count; - - if (op_ret && (op_errno != ENOTCONN)) { - local->op_errno = op_errno; - } - if (op_ret == 0) { - struct statvfs *dict_buf = &local->statvfs_buf; - dict_buf->f_bsize = stbuf->f_bsize; - dict_buf->f_frsize = stbuf->f_frsize; - dict_buf->f_blocks += stbuf->f_blocks; - dict_buf->f_bfree += stbuf->f_bfree; - dict_buf->f_bavail += stbuf->f_bavail; - dict_buf->f_files += stbuf->f_files; - dict_buf->f_ffree += stbuf->f_ffree; - dict_buf->f_favail += stbuf->f_favail; - dict_buf->f_fsid = stbuf->f_fsid; - dict_buf->f_flag = stbuf->f_flag; - dict_buf->f_namemax = stbuf->f_namemax; - local->op_ret = 0; - } - } - UNLOCK(&frame->lock); - - if (!callcnt) { - STRIPE_STACK_UNWIND(statfs, frame, local->op_ret, local->op_errno, - &local->statvfs_buf, NULL); - } -out: - return 0; -} - -int32_t -stripe_statfs(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata) -{ - stripe_local_t *local = NULL; - xlator_list_t *trav = NULL; - stripe_private_t *priv = NULL; - int32_t op_errno = EINVAL; - - VALIDATE_OR_GOTO(frame, err); - VALIDATE_OR_GOTO(this, err); - VALIDATE_OR_GOTO(loc, err); - - trav = this->children; - priv = this->private; - - /* Initialization */ - local = mem_get0(this->local_pool); - if (!local) { - op_errno = ENOMEM; - goto err; - } - local->op_ret = -1; - local->op_errno = ENOTCONN; - frame->local = local; - - local->call_count = priv->child_count; - while (trav) { - STACK_WIND(frame, stripe_statfs_cbk, trav->xlator, - trav->xlator->fops->statfs, loc, NULL); - trav = trav->next; - } - - return 0; -err: - STRIPE_STACK_UNWIND(statfs, frame, -1, op_errno, NULL, NULL); - return 0; -} - -int32_t -stripe_truncate_cbk(call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct iatt *prebuf, - struct iatt *postbuf, dict_t *xdata) -{ - int32_t callcnt = 0; - stripe_local_t *local = NULL; - call_frame_t *prev = NULL; - - if (!this || !frame || !frame->local || !cookie) { - gf_log("stripe", GF_LOG_DEBUG, "possible NULL deref"); - goto out; - } - - prev = cookie; - local = frame->local; - - LOCK(&frame->lock); - { - callcnt = --local->call_count; - - if (op_ret == -1) { - gf_log(this->name, GF_LOG_DEBUG, "%s returned error %s", - prev->this->name, strerror(op_errno)); - local->op_errno = op_errno; - if ((op_errno != ENOENT) || (prev->this == FIRST_CHILD(this))) - local->failed = 1; - } - - if (op_ret == 0) { - local->op_ret = 0; - if (FIRST_CHILD(this) == prev->this) { - local->pre_buf = *prebuf; - local->post_buf = *postbuf; - } - - local->prebuf_blocks += prebuf->ia_blocks; - local->postbuf_blocks += postbuf->ia_blocks; - - correct_file_size(prebuf, local->fctx, prev); - correct_file_size(postbuf, local->fctx, prev); - - if (local->prebuf_size < prebuf->ia_size) - local->prebuf_size = prebuf->ia_size; - - if (local->postbuf_size < postbuf->ia_size) - local->postbuf_size = postbuf->ia_size; - } - } - UNLOCK(&frame->lock); - - if (!callcnt) { - if (local->failed) - local->op_ret = -1; - - if (local->op_ret != -1) { - local->pre_buf.ia_blocks = local->prebuf_blocks; - local->pre_buf.ia_size = local->prebuf_size; - local->post_buf.ia_blocks = local->postbuf_blocks; - local->post_buf.ia_size = local->postbuf_size; - } - - STRIPE_STACK_UNWIND(truncate, frame, local->op_ret, local->op_errno, - &local->pre_buf, &local->post_buf, NULL); - } -out: - return 0; -} - -int32_t -stripe_truncate(call_frame_t *frame, xlator_t *this, loc_t *loc, off_t offset, - dict_t *xdata) -{ - stripe_local_t *local = NULL; - stripe_private_t *priv = NULL; - stripe_fd_ctx_t *fctx = NULL; - int32_t op_errno = EINVAL; - int i, eof_idx; - off_t dest_offset, tmp_offset; - - VALIDATE_OR_GOTO(frame, err); - VALIDATE_OR_GOTO(this, err); - VALIDATE_OR_GOTO(loc, err); - VALIDATE_OR_GOTO(loc->path, err); - VALIDATE_OR_GOTO(loc->inode, err); - - priv = this->private; - - if (priv->first_child_down) { - op_errno = ENOTCONN; - goto err; - } - - /* Initialization */ - local = mem_get0(this->local_pool); - if (!local) { - op_errno = ENOMEM; - goto err; - } - local->op_ret = -1; - frame->local = local; - local->call_count = priv->child_count; - - inode_ctx_get(loc->inode, this, (uint64_t *)&fctx); - if (!fctx) { - gf_log(this->name, GF_LOG_ERROR, "no stripe context"); - op_errno = EINVAL; - goto err; - } - - local->fctx = fctx; - eof_idx = (offset / fctx->stripe_size) % fctx->stripe_count; - - for (i = 0; i < fctx->stripe_count; i++) { - if (!fctx->xl_array[i]) { - gf_log(this->name, GF_LOG_ERROR, "no xlator at index %d", i); - op_errno = EINVAL; - goto err; - } - - if (fctx->stripe_coalesce) { - /* - * The node that owns EOF is truncated to the exact - * coalesced offset. Nodes prior to this index should - * be rounded up to the size of the complete stripe, - * while nodes after this index should be rounded down - * to the size of the previous stripe. - */ - if (i < eof_idx) - tmp_offset = gf_roof(offset, - fctx->stripe_size * fctx->stripe_count); - else if (i > eof_idx) - tmp_offset = gf_floor(offset, - fctx->stripe_size * fctx->stripe_count); - else - tmp_offset = offset; - - dest_offset = coalesced_offset(tmp_offset, fctx->stripe_size, - fctx->stripe_count); - } else { - dest_offset = offset; - } - - STACK_WIND(frame, stripe_truncate_cbk, fctx->xl_array[i], - fctx->xl_array[i]->fops->truncate, loc, dest_offset, NULL); - } - - return 0; -err: - STRIPE_STACK_UNWIND(truncate, frame, -1, op_errno, NULL, NULL, NULL); - return 0; -} - -int32_t -stripe_setattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct iatt *preop, - struct iatt *postop, dict_t *xdata) -{ - int32_t callcnt = 0; - stripe_local_t *local = NULL; - call_frame_t *prev = NULL; - - if (!this || !frame || !frame->local || !cookie) { - gf_log("stripe", GF_LOG_DEBUG, "possible NULL deref"); - goto out; - } - - prev = cookie; - local = frame->local; - - LOCK(&frame->lock); - { - callcnt = --local->call_count; - - if (op_ret == -1) { - gf_log(this->name, GF_LOG_DEBUG, "%s returned error %s", - prev->this->name, strerror(op_errno)); - local->op_errno = op_errno; - if ((op_errno != ENOENT) || (prev->this == FIRST_CHILD(this))) - local->failed = 1; - } - - if (op_ret == 0) { - local->op_ret = 0; - - if (FIRST_CHILD(this) == prev->this) { - local->pre_buf = *preop; - local->post_buf = *postop; - } - - local->prebuf_blocks += preop->ia_blocks; - local->postbuf_blocks += postop->ia_blocks; - - correct_file_size(preop, local->fctx, prev); - correct_file_size(postop, local->fctx, prev); - - if (local->prebuf_size < preop->ia_size) - local->prebuf_size = preop->ia_size; - if (local->postbuf_size < postop->ia_size) - local->postbuf_size = postop->ia_size; - } - } - UNLOCK(&frame->lock); - - if (!callcnt) { - if (local->failed) - local->op_ret = -1; - - if (local->op_ret != -1) { - local->pre_buf.ia_blocks = local->prebuf_blocks; - local->pre_buf.ia_size = local->prebuf_size; - local->post_buf.ia_blocks = local->postbuf_blocks; - local->post_buf.ia_size = local->postbuf_size; - } - - STRIPE_STACK_UNWIND(setattr, frame, local->op_ret, local->op_errno, - &local->pre_buf, &local->post_buf, NULL); - } -out: - return 0; -} - -int32_t -stripe_setattr(call_frame_t *frame, xlator_t *this, loc_t *loc, - struct iatt *stbuf, int32_t valid, dict_t *xdata) -{ - xlator_list_t *trav = NULL; - stripe_local_t *local = NULL; - stripe_private_t *priv = NULL; - stripe_fd_ctx_t *fctx = NULL; - int32_t op_errno = EINVAL; - - VALIDATE_OR_GOTO(frame, err); - VALIDATE_OR_GOTO(this, err); - VALIDATE_OR_GOTO(loc, err); - VALIDATE_OR_GOTO(loc->path, err); - VALIDATE_OR_GOTO(loc->inode, err); - - priv = this->private; - trav = this->children; - - if (priv->first_child_down) { - op_errno = ENOTCONN; - goto err; - } - - /* Initialization */ - local = mem_get0(this->local_pool); - if (!local) { - op_errno = ENOMEM; - goto err; - } - local->op_ret = -1; - frame->local = local; - if (!IA_ISDIR(loc->inode->ia_type) && !IA_ISREG(loc->inode->ia_type)) { - local->call_count = 1; - STACK_WIND(frame, stripe_setattr_cbk, FIRST_CHILD(this), - FIRST_CHILD(this)->fops->setattr, loc, stbuf, valid, NULL); - return 0; - } - - if (IA_ISREG(loc->inode->ia_type)) { - inode_ctx_get(loc->inode, this, (uint64_t *)&fctx); - if (!fctx) - goto err; - local->fctx = fctx; - } - - local->call_count = priv->child_count; - while (trav) { - STACK_WIND(frame, stripe_setattr_cbk, trav->xlator, - trav->xlator->fops->setattr, loc, stbuf, valid, NULL); - trav = trav->next; - } - - return 0; -err: - STRIPE_STACK_UNWIND(setattr, frame, -1, op_errno, NULL, NULL, NULL); - return 0; -} - -int32_t -stripe_fsetattr(call_frame_t *frame, xlator_t *this, fd_t *fd, - struct iatt *stbuf, int32_t valid, dict_t *xdata) -{ - stripe_local_t *local = NULL; - stripe_private_t *priv = NULL; - xlator_list_t *trav = NULL; - int32_t op_errno = EINVAL; - - VALIDATE_OR_GOTO(frame, err); - VALIDATE_OR_GOTO(this, err); - VALIDATE_OR_GOTO(fd, err); - VALIDATE_OR_GOTO(fd->inode, err); - - priv = this->private; - trav = this->children; - - /* Initialization */ - local = mem_get0(this->local_pool); - if (!local) { - op_errno = ENOMEM; - goto err; - } - local->op_ret = -1; - frame->local = local; - local->call_count = priv->child_count; - - while (trav) { - STACK_WIND(frame, stripe_setattr_cbk, trav->xlator, - trav->xlator->fops->fsetattr, fd, stbuf, valid, NULL); - trav = trav->next; - } - - return 0; -err: - STRIPE_STACK_UNWIND(fsetattr, frame, -1, op_errno, NULL, NULL, NULL); - return 0; -} - -int32_t -stripe_stack_rename_cbk(call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct iatt *buf, - struct iatt *preoldparent, struct iatt *postoldparent, - struct iatt *prenewparent, struct iatt *postnewparent, - dict_t *xdata) -{ - int32_t callcnt = 0; - stripe_local_t *local = NULL; - call_frame_t *prev = NULL; - - if (!this || !frame || !frame->local || !cookie) { - gf_log("stripe", GF_LOG_DEBUG, "possible NULL deref"); - goto out; - } - - prev = cookie; - local = frame->local; - - LOCK(&frame->lock); - { - callcnt = --local->call_count; - - if (op_ret == -1) { - gf_log(this->name, GF_LOG_DEBUG, "%s returned error %s", - prev->this->name, strerror(op_errno)); - local->op_errno = op_errno; - if ((op_errno != ENOENT) || (prev->this == FIRST_CHILD(this))) - local->failed = 1; - } - - if (op_ret == 0) { - local->op_ret = 0; - - local->stbuf.ia_blocks += buf->ia_blocks; - local->preparent.ia_blocks += preoldparent->ia_blocks; - local->postparent.ia_blocks += postoldparent->ia_blocks; - local->pre_buf.ia_blocks += prenewparent->ia_blocks; - local->post_buf.ia_blocks += postnewparent->ia_blocks; - - correct_file_size(buf, local->fctx, prev); - - if (local->stbuf.ia_size < buf->ia_size) - local->stbuf.ia_size = buf->ia_size; - - if (local->preparent.ia_size < preoldparent->ia_size) - local->preparent.ia_size = preoldparent->ia_size; - - if (local->postparent.ia_size < postoldparent->ia_size) - local->postparent.ia_size = postoldparent->ia_size; - - if (local->pre_buf.ia_size < prenewparent->ia_size) - local->pre_buf.ia_size = prenewparent->ia_size; - - if (local->post_buf.ia_size < postnewparent->ia_size) - local->post_buf.ia_size = postnewparent->ia_size; - } - } - UNLOCK(&frame->lock); - - if (!callcnt) { - if (local->failed) - local->op_ret = -1; - - STRIPE_STACK_UNWIND(rename, frame, local->op_ret, local->op_errno, - &local->stbuf, &local->preparent, - &local->postparent, &local->pre_buf, - &local->post_buf, NULL); - } -out: - return 0; -} - -int32_t -stripe_first_rename_cbk(call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct iatt *buf, - struct iatt *preoldparent, struct iatt *postoldparent, - struct iatt *prenewparent, struct iatt *postnewparent, - dict_t *xdata) -{ - stripe_local_t *local = NULL; - xlator_list_t *trav = NULL; - - if (!this || !frame || !frame->local) { - gf_log("stripe", GF_LOG_DEBUG, "possible NULL deref"); - op_errno = EINVAL; - goto unwind; - } - - if (op_ret == -1) { - goto unwind; - } - - local = frame->local; - trav = this->children; - - local->stbuf = *buf; - local->preparent = *preoldparent; - local->postparent = *postoldparent; - local->pre_buf = *prenewparent; - local->post_buf = *postnewparent; - - local->op_ret = 0; - local->call_count--; - - trav = trav->next; /* Skip first child */ - while (trav) { - STACK_WIND(frame, stripe_stack_rename_cbk, trav->xlator, - trav->xlator->fops->rename, &local->loc, &local->loc2, NULL); - trav = trav->next; - } - return 0; - -unwind: - STRIPE_STACK_UNWIND(rename, frame, -1, op_errno, buf, preoldparent, - postoldparent, prenewparent, postnewparent, NULL); - return 0; -} - -int32_t -stripe_rename(call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc, - dict_t *xdata) -{ - stripe_private_t *priv = NULL; - stripe_local_t *local = NULL; - xlator_list_t *trav = NULL; - stripe_fd_ctx_t *fctx = NULL; - int32_t op_errno = EINVAL; - - VALIDATE_OR_GOTO(frame, err); - VALIDATE_OR_GOTO(this, err); - VALIDATE_OR_GOTO(oldloc, err); - VALIDATE_OR_GOTO(oldloc->path, err); - VALIDATE_OR_GOTO(oldloc->inode, err); - VALIDATE_OR_GOTO(newloc, err); - - priv = this->private; - trav = this->children; - - /* If any one node is down, don't allow rename */ - if (priv->nodes_down) { - op_errno = ENOTCONN; - goto err; - } - - /* Initialization */ - local = mem_get0(this->local_pool); - if (!local) { - op_errno = ENOMEM; - goto err; - } - - frame->local = local; - - local->op_ret = -1; - loc_copy(&local->loc, oldloc); - loc_copy(&local->loc2, newloc); - - local->call_count = priv->child_count; - - if (IA_ISREG(oldloc->inode->ia_type)) { - inode_ctx_get(oldloc->inode, this, (uint64_t *)&fctx); - if (!fctx) - goto err; - local->fctx = fctx; - } - - STACK_WIND(frame, stripe_first_rename_cbk, trav->xlator, - trav->xlator->fops->rename, oldloc, newloc, NULL); - - return 0; -err: - STRIPE_STACK_UNWIND(rename, frame, -1, op_errno, NULL, NULL, NULL, NULL, - NULL, NULL); - return 0; -} -int32_t -stripe_first_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, - dict_t *xdata) -{ - stripe_local_t *local = NULL; - call_frame_t *prev = NULL; - - if (!this || !frame || !frame->local || !cookie) { - gf_log("stripe", GF_LOG_DEBUG, "possible NULL deref"); - goto out; - } - - prev = cookie; - local = frame->local; - - if (op_ret == -1) { - gf_log(this->name, GF_LOG_DEBUG, "%s returned %s", prev->this->name, - strerror(op_errno)); - goto out; - } - local->op_ret = 0; - local->preparent = *preparent; - local->postparent = *postparent; - local->preparent_blocks += preparent->ia_blocks; - local->postparent_blocks += postparent->ia_blocks; - - STRIPE_STACK_UNWIND(unlink, frame, local->op_ret, local->op_errno, - &local->preparent, &local->postparent, xdata); - return 0; -out: - STRIPE_STACK_UNWIND(unlink, frame, -1, op_errno, NULL, NULL, NULL); - - return 0; -} - -int32_t -stripe_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, dict_t *xdata) -{ - int32_t callcnt = 0; - stripe_local_t *local = NULL; - call_frame_t *prev = NULL; - - if (!this || !frame || !frame->local || !cookie) { - gf_log("stripe", GF_LOG_DEBUG, "possible NULL deref"); - goto out; - } - - prev = cookie; - local = frame->local; - - LOCK(&frame->lock); - { - callcnt = --local->call_count; - - if (op_ret == -1) { - gf_log(this->name, GF_LOG_DEBUG, "%s returned %s", prev->this->name, - strerror(op_errno)); - local->op_errno = op_errno; - if (op_errno != ENOENT) { - local->failed = 1; - local->op_ret = op_ret; - } - } - } - UNLOCK(&frame->lock); - - if (callcnt == 1) { - if (local->failed) { - op_errno = local->op_errno; - goto out; - } - STACK_WIND(frame, stripe_first_unlink_cbk, FIRST_CHILD(this), - FIRST_CHILD(this)->fops->unlink, &local->loc, local->xflag, - local->xdata); - } - return 0; -out: - STRIPE_STACK_UNWIND(unlink, frame, -1, op_errno, NULL, NULL, NULL); - - return 0; -} - -int32_t -stripe_unlink(call_frame_t *frame, xlator_t *this, loc_t *loc, int xflag, - dict_t *xdata) -{ - xlator_list_t *trav = NULL; - stripe_local_t *local = NULL; - stripe_private_t *priv = NULL; - int32_t op_errno = EINVAL; - - VALIDATE_OR_GOTO(frame, err); - VALIDATE_OR_GOTO(this, err); - VALIDATE_OR_GOTO(loc, err); - VALIDATE_OR_GOTO(loc->path, err); - VALIDATE_OR_GOTO(loc->inode, err); - - priv = this->private; - trav = this->children; - - if (priv->first_child_down) { - op_errno = ENOTCONN; - goto err; - } - - /* Don't unlink a file if a node is down */ - if (priv->nodes_down) { - op_errno = ENOTCONN; - goto err; - } - - /* Initialization */ - local = mem_get0(this->local_pool); - if (!local) { - op_errno = ENOMEM; - goto err; - } - local->op_ret = -1; - loc_copy(&local->loc, loc); - local->xflag = xflag; - - if (xdata) - local->xdata = dict_ref(xdata); - - frame->local = local; - local->call_count = priv->child_count; - trav = trav->next; /* Skip the first child */ - - while (trav) { - STACK_WIND(frame, stripe_unlink_cbk, trav->xlator, - trav->xlator->fops->unlink, loc, xflag, xdata); - trav = trav->next; - } - - return 0; -err: - STRIPE_STACK_UNWIND(unlink, frame, -1, op_errno, NULL, NULL, NULL); - return 0; -} - -int32_t -stripe_first_rmdir_cbk(call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct iatt *preparent, - struct iatt *postparent, dict_t *xdata) -{ - stripe_local_t *local = NULL; - - if (!this || !frame || !frame->local) { - gf_log("stripe", GF_LOG_DEBUG, "possible NULL deref"); - op_errno = EINVAL; - goto err; - } - - if (op_ret == -1) { - goto err; - } - - local = frame->local; - local->op_ret = 0; - - local->call_count--; /* First child successful */ - - local->preparent = *preparent; - local->postparent = *postparent; - local->preparent_size = preparent->ia_size; - local->postparent_size = postparent->ia_size; - local->preparent_blocks += preparent->ia_blocks; - local->postparent_blocks += postparent->ia_blocks; - - STRIPE_STACK_UNWIND(rmdir, frame, local->op_ret, local->op_errno, - &local->preparent, &local->postparent, xdata); - return 0; -err: - STRIPE_STACK_UNWIND(rmdir, frame, op_ret, op_errno, NULL, NULL, NULL); - return 0; -} - -int32_t -stripe_rmdir_cbk(call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct iatt *preparent, - struct iatt *postparent, dict_t *xdata) -{ - int32_t callcnt = 0; - stripe_local_t *local = NULL; - call_frame_t *prev = NULL; - - if (!this || !frame || !frame->local || !cookie) { - gf_log("stripe", GF_LOG_DEBUG, "possible NULL deref"); - goto out; - } - - prev = cookie; - local = frame->local; - - LOCK(&frame->lock); - { - callcnt = --local->call_count; - - if (op_ret == -1) { - gf_log(this->name, GF_LOG_DEBUG, "%s returned %s", prev->this->name, - strerror(op_errno)); - if (op_errno != ENOENT) - local->failed = 1; - } - } - UNLOCK(&frame->lock); - - if (callcnt == 1) { - if (local->failed) - goto out; - STACK_WIND(frame, stripe_first_rmdir_cbk, FIRST_CHILD(this), - FIRST_CHILD(this)->fops->rmdir, &local->loc, local->flags, - NULL); - } - return 0; -out: - STRIPE_STACK_UNWIND(rmdir, frame, -1, op_errno, NULL, NULL, NULL); - return 0; -} - -int32_t -stripe_rmdir(call_frame_t *frame, xlator_t *this, loc_t *loc, int flags, - dict_t *xdata) -{ - xlator_list_t *trav = NULL; - stripe_local_t *local = NULL; - stripe_private_t *priv = NULL; - int32_t op_errno = EINVAL; - - VALIDATE_OR_GOTO(frame, err); - VALIDATE_OR_GOTO(this, err); - VALIDATE_OR_GOTO(loc, err); - VALIDATE_OR_GOTO(loc->path, err); - VALIDATE_OR_GOTO(loc->inode, err); - - priv = this->private; - trav = this->children; - - /* don't delete a directory if any of the subvolume is down */ - if (priv->nodes_down) { - op_errno = ENOTCONN; - goto err; - } - - /* Initialization */ - local = mem_get0(this->local_pool); - if (!local) { - op_errno = ENOMEM; - goto err; - } - local->op_ret = -1; - frame->local = local; - loc_copy(&local->loc, loc); - local->flags = flags; - local->call_count = priv->child_count; - trav = trav->next; /* skip the first child */ - - while (trav) { - STACK_WIND(frame, stripe_rmdir_cbk, trav->xlator, - trav->xlator->fops->rmdir, loc, flags, NULL); - trav = trav->next; - } - - return 0; -err: - STRIPE_STACK_UNWIND(rmdir, frame, -1, op_errno, NULL, NULL, NULL); - return 0; -} - -int32_t -stripe_mknod_ifreg_fail_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, dict_t *xdata) -{ - int32_t callcnt = 0; - stripe_local_t *local = NULL; - - if (!this || !frame || !frame->local) { - gf_log("stripe", GF_LOG_DEBUG, "possible NULL deref"); - goto out; - } - - local = frame->local; - - LOCK(&frame->lock); - { - callcnt = --local->call_count; - } - UNLOCK(&frame->lock); - - if (!callcnt) { - STRIPE_STACK_UNWIND(mknod, frame, local->op_ret, local->op_errno, - local->inode, &local->stbuf, &local->preparent, - &local->postparent, NULL); - } -out: - return 0; -} - -/** - */ -int32_t -stripe_mknod_ifreg_setxattr_cbk(call_frame_t *frame, void *cookie, - xlator_t *this, int32_t op_ret, - int32_t op_errno, dict_t *xdata) -{ - int32_t callcnt = 0; - stripe_local_t *local = NULL; - stripe_private_t *priv = NULL; - xlator_list_t *trav = NULL; - call_frame_t *prev = NULL; - - if (!this || !frame || !frame->local || !cookie) { - gf_log("stripe", GF_LOG_DEBUG, "possible NULL deref"); - goto out; - } - - prev = cookie; - priv = this->private; - local = frame->local; - - LOCK(&frame->lock); - { - callcnt = --local->call_count; - - if (op_ret == -1) { - gf_log(this->name, GF_LOG_DEBUG, "%s returned error %s", - prev->this->name, strerror(op_errno)); - local->op_ret = -1; - local->op_errno = op_errno; - } - } - UNLOCK(&frame->lock); - - if (!callcnt) { - if (local->op_ret == -1) { - local->call_count = priv->child_count; - while (trav) { - STACK_WIND(frame, stripe_mknod_ifreg_fail_unlink_cbk, - trav->xlator, trav->xlator->fops->unlink, - &local->loc, 0, NULL); - trav = trav->next; - } - return 0; - } - - STRIPE_STACK_UNWIND(mknod, frame, local->op_ret, local->op_errno, - local->inode, &local->stbuf, &local->preparent, - &local->postparent, NULL); - } -out: - return 0; -} - -int32_t -stripe_mknod_ifreg_cbk(call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, inode_t *inode, - struct iatt *buf, struct iatt *preparent, - struct iatt *postparent, dict_t *xdata) -{ - int32_t callcnt = 0; - stripe_local_t *local = NULL; - stripe_private_t *priv = NULL; - call_frame_t *prev = NULL; - xlator_list_t *trav = NULL; - - if (!this || !frame || !frame->local || !cookie) { - gf_log("stripe", GF_LOG_DEBUG, "possible NULL deref"); - goto out; - } - - prev = cookie; - priv = this->private; - local = frame->local; - - LOCK(&frame->lock); - { - callcnt = --local->call_count; - - if (op_ret == -1) { - gf_log(this->name, GF_LOG_DEBUG, "%s returned error %s", - prev->this->name, strerror(op_errno)); - if ((op_errno != ENOENT) || (prev->this == FIRST_CHILD(this))) - local->failed = 1; - local->op_errno = op_errno; - } - if (op_ret >= 0) { - local->op_ret = op_ret; - - /* Can be used as a mechanism to understand if mknod - was successful in at least one place */ - if (gf_uuid_is_null(local->ia_gfid)) - gf_uuid_copy(local->ia_gfid, buf->ia_gfid); - - if (stripe_ctx_handle(this, prev, local, xdata)) - gf_log(this->name, GF_LOG_ERROR, - "Error getting fctx info from dict"); - - local->stbuf_blocks += buf->ia_blocks; - local->preparent_blocks += preparent->ia_blocks; - local->postparent_blocks += postparent->ia_blocks; - - correct_file_size(buf, local->fctx, prev); - - if (local->stbuf_size < buf->ia_size) - local->stbuf_size = buf->ia_size; - if (local->preparent_size < preparent->ia_size) - local->preparent_size = preparent->ia_size; - if (local->postparent_size < postparent->ia_size) - local->postparent_size = postparent->ia_size; - } - } - UNLOCK(&frame->lock); - - if (!callcnt) { - if (local->failed) - local->op_ret = -1; - - if ((local->op_ret == -1) && !gf_uuid_is_null(local->ia_gfid)) { - /* ia_gfid set means, at least on one node 'mknod' - is successful */ - local->call_count = priv->child_count; - trav = this->children; - while (trav) { - STACK_WIND(frame, stripe_mknod_ifreg_fail_unlink_cbk, - trav->xlator, trav->xlator->fops->unlink, - &local->loc, 0, NULL); - trav = trav->next; - } - return 0; - } - - if (local->op_ret != -1) { - local->preparent.ia_blocks = local->preparent_blocks; - local->preparent.ia_size = local->preparent_size; - local->postparent.ia_blocks = local->postparent_blocks; - local->postparent.ia_size = local->postparent_size; - local->stbuf.ia_size = local->stbuf_size; - local->stbuf.ia_blocks = local->stbuf_blocks; - inode_ctx_put(local->inode, this, (uint64_t)(long)local->fctx); - } - STRIPE_STACK_UNWIND(mknod, frame, local->op_ret, local->op_errno, - local->inode, &local->stbuf, &local->preparent, - &local->postparent, NULL); - } -out: - return 0; -} - -int32_t -stripe_mknod_first_ifreg_cbk(call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, inode_t *inode, - struct iatt *buf, struct iatt *preparent, - struct iatt *postparent, dict_t *xdata) -{ - stripe_local_t *local = NULL; - stripe_private_t *priv = NULL; - call_frame_t *prev = NULL; - xlator_list_t *trav = NULL; - int i = 1; - dict_t *dict = NULL; - int ret = 0; - int need_unref = 0; - - if (!this || !frame || !frame->local || !cookie) { - gf_log("stripe", GF_LOG_DEBUG, "possible NULL deref"); - goto out; - } - - prev = cookie; - priv = this->private; - local = frame->local; - trav = this->children; - - local->call_count--; - - if (op_ret == -1) { - gf_log(this->name, GF_LOG_DEBUG, "%s returned error %s", - prev->this->name, strerror(op_errno)); - local->failed = 1; - local->op_errno = op_errno; - goto out; - } - - local->op_ret = op_ret; - - local->stbuf = *buf; - local->preparent = *preparent; - local->postparent = *postparent; - - if (gf_uuid_is_null(local->ia_gfid)) - gf_uuid_copy(local->ia_gfid, buf->ia_gfid); - local->preparent.ia_blocks = local->preparent_blocks; - local->preparent.ia_size = local->preparent_size; - local->postparent.ia_blocks = local->postparent_blocks; - local->postparent.ia_size = local->postparent_size; - local->stbuf.ia_size = local->stbuf_size; - local->stbuf.ia_blocks = local->stbuf_blocks; - - trav = trav->next; - while (trav) { - if (priv->xattr_supported) { - dict = dict_new(); - if (!dict) { - gf_log(this->name, GF_LOG_ERROR, "failed to allocate dict %s", - local->loc.path); - } - need_unref = 1; - - dict_copy(local->xattr, dict); - - ret = stripe_xattr_request_build(this, dict, local->stripe_size, - priv->child_count, i, - priv->coalesce); - if (ret) - gf_log(this->name, GF_LOG_ERROR, - "Failed to build xattr request"); - - } else { - dict = local->xattr; - } - - STACK_WIND(frame, stripe_mknod_ifreg_cbk, trav->xlator, - trav->xlator->fops->mknod, &local->loc, local->mode, - local->rdev, 0, dict); - trav = trav->next; - i++; - - if (dict && need_unref) - dict_unref(dict); - } - - return 0; - -out: - - STRIPE_STACK_UNWIND(mknod, frame, op_ret, op_errno, NULL, NULL, NULL, NULL, - NULL); - return 0; -} - -int32_t -stripe_single_mknod_cbk(call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, inode_t *inode, - struct iatt *buf, struct iatt *preparent, - struct iatt *postparent, dict_t *xdata) -{ - STRIPE_STACK_UNWIND(mknod, frame, op_ret, op_errno, inode, buf, preparent, - postparent, xdata); - return 0; -} - -int -stripe_mknod(call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode, - dev_t rdev, mode_t umask, dict_t *xdata) -{ - stripe_private_t *priv = NULL; - stripe_local_t *local = NULL; - int32_t op_errno = EINVAL; - int32_t i = 0; - dict_t *dict = NULL; - int ret = 0; - int need_unref = 0; - - VALIDATE_OR_GOTO(frame, err); - VALIDATE_OR_GOTO(this, err); - VALIDATE_OR_GOTO(loc, err); - VALIDATE_OR_GOTO(loc->path, err); - VALIDATE_OR_GOTO(loc->inode, err); - - priv = this->private; - - if (priv->first_child_down) { - op_errno = ENOTCONN; - goto err; - } - - if (S_ISREG(mode)) { - /* NOTE: on older kernels (older than 2.6.9), - creat() fops is sent as mknod() + open(). Hence handling - S_IFREG files is necessary */ - if (priv->nodes_down) { - gf_log(this->name, GF_LOG_WARNING, "Some node down, returning EIO"); - op_errno = EIO; - goto err; - } - - /* Initialization */ - local = mem_get0(this->local_pool); - if (!local) { - op_errno = ENOMEM; - goto err; - } - local->op_ret = -1; - local->op_errno = ENOTCONN; - local->stripe_size = stripe_get_matching_bs(loc->path, priv); - frame->local = local; - local->inode = inode_ref(loc->inode); - loc_copy(&local->loc, loc); - local->xattr = dict_copy_with_ref(xdata, NULL); - local->mode = mode; - local->umask = umask; - local->rdev = rdev; - - /* Every time in stripe lookup, all child nodes should - be looked up */ - local->call_count = priv->child_count; - - if (priv->xattr_supported) { - dict = dict_new(); - if (!dict) { - gf_log(this->name, GF_LOG_ERROR, "failed to allocate dict %s", - loc->path); - } - need_unref = 1; - - dict_copy(xdata, dict); - - ret = stripe_xattr_request_build(this, dict, local->stripe_size, - priv->child_count, i, - priv->coalesce); - if (ret) - gf_log(this->name, GF_LOG_ERROR, - "failed to build xattr request"); - } else { - dict = xdata; - } - - STACK_WIND(frame, stripe_mknod_first_ifreg_cbk, FIRST_CHILD(this), - FIRST_CHILD(this)->fops->mknod, loc, mode, rdev, umask, - dict); - - if (dict && need_unref) - dict_unref(dict); - return 0; - } - - STACK_WIND(frame, stripe_single_mknod_cbk, FIRST_CHILD(this), - FIRST_CHILD(this)->fops->mknod, loc, mode, rdev, umask, xdata); - - return 0; -err: - STRIPE_STACK_UNWIND(mknod, frame, -1, op_errno, NULL, NULL, NULL, NULL, - NULL); - return 0; -} - -int32_t -stripe_mkdir_cbk(call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, inode_t *inode, - struct iatt *buf, struct iatt *preparent, - struct iatt *postparent, dict_t *xdata) -{ - int32_t callcnt = 0; - stripe_local_t *local = NULL; - call_frame_t *prev = NULL; - - if (!this || !frame || !frame->local || !cookie) { - gf_log("stripe", GF_LOG_DEBUG, "possible NULL deref"); - goto out; - } - - prev = cookie; - local = frame->local; - - LOCK(&frame->lock); - { - callcnt = --local->call_count; - - if (op_ret == -1) { - gf_log(this->name, GF_LOG_DEBUG, "%s returned error %s", - prev->this->name, strerror(op_errno)); - local->op_errno = op_errno; - if ((op_errno != ENOENT) || (prev->this == FIRST_CHILD(this))) - local->failed = 1; - } - - if (op_ret >= 0) { - local->op_ret = 0; - - local->stbuf_blocks += buf->ia_blocks; - local->preparent_blocks += preparent->ia_blocks; - local->postparent_blocks += postparent->ia_blocks; - - if (local->stbuf_size < buf->ia_size) - local->stbuf_size = buf->ia_size; - if (local->preparent_size < preparent->ia_size) - local->preparent_size = preparent->ia_size; - if (local->postparent_size < postparent->ia_size) - local->postparent_size = postparent->ia_size; - } - } - UNLOCK(&frame->lock); - - if (!callcnt) { - if (local->failed != -1) { - local->preparent.ia_blocks = local->preparent_blocks; - local->preparent.ia_size = local->preparent_size; - local->postparent.ia_blocks = local->postparent_blocks; - local->postparent.ia_size = local->postparent_size; - local->stbuf.ia_size = local->stbuf_size; - local->stbuf.ia_blocks = local->stbuf_blocks; - } - STRIPE_STACK_UNWIND(mkdir, frame, local->op_ret, local->op_errno, - local->inode, &local->stbuf, &local->preparent, - &local->postparent, NULL); - } -out: - return 0; -} - -int32_t -stripe_first_mkdir_cbk(call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, inode_t *inode, - struct iatt *buf, struct iatt *preparent, - struct iatt *postparent, dict_t *xdata) -{ - stripe_local_t *local = NULL; - call_frame_t *prev = NULL; - xlator_list_t *trav = NULL; - - if (!this || !frame || !frame->local || !cookie) { - gf_log("stripe", GF_LOG_DEBUG, "possible NULL deref"); - goto out; - } - - prev = cookie; - local = frame->local; - trav = this->children; - - local->call_count--; /* first child is successful */ - trav = trav->next; /* skip first child */ - - if (op_ret == -1) { - gf_log(this->name, GF_LOG_DEBUG, "%s returned error %s", - prev->this->name, strerror(op_errno)); - local->op_errno = op_errno; - goto out; - } - - local->op_ret = 0; - - local->inode = inode_ref(inode); - local->stbuf = *buf; - local->postparent = *postparent; - local->preparent = *preparent; - - local->stbuf_blocks += buf->ia_blocks; - local->preparent_blocks += preparent->ia_blocks; - local->postparent_blocks += postparent->ia_blocks; - - local->stbuf_size = buf->ia_size; - local->preparent_size = preparent->ia_size; - local->postparent_size = postparent->ia_size; - - while (trav) { - STACK_WIND(frame, stripe_mkdir_cbk, trav->xlator, - trav->xlator->fops->mkdir, &local->loc, local->mode, - local->umask, local->xdata); - trav = trav->next; - } - return 0; -out: - STRIPE_STACK_UNWIND(mkdir, frame, -1, op_errno, NULL, NULL, NULL, NULL, - NULL); - - return 0; -} - -int -stripe_mkdir(call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode, - mode_t umask, dict_t *xdata) -{ - stripe_private_t *priv = NULL; - stripe_local_t *local = NULL; - xlator_list_t *trav = NULL; - int32_t op_errno = 1; - - VALIDATE_OR_GOTO(frame, err); - VALIDATE_OR_GOTO(this, err); - VALIDATE_OR_GOTO(loc, err); - VALIDATE_OR_GOTO(loc->path, err); - VALIDATE_OR_GOTO(loc->inode, err); - - priv = this->private; - trav = this->children; - - if (priv->first_child_down) { - op_errno = ENOTCONN; - goto err; - } - - /* Initialization */ - local = mem_get0(this->local_pool); - if (!local) { - op_errno = ENOMEM; - goto err; - } - local->op_ret = -1; - local->call_count = priv->child_count; - if (xdata) - local->xdata = dict_ref(xdata); - local->mode = mode; - local->umask = umask; - loc_copy(&local->loc, loc); - frame->local = local; - - /* Every time in stripe lookup, all child nodes should be looked up */ - STACK_WIND(frame, stripe_first_mkdir_cbk, trav->xlator, - trav->xlator->fops->mkdir, loc, mode, umask, xdata); - - return 0; -err: - STRIPE_STACK_UNWIND(mkdir, frame, -1, op_errno, NULL, NULL, NULL, NULL, - NULL); - return 0; -} - -int32_t -stripe_link_cbk(call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, inode_t *inode, - struct iatt *buf, struct iatt *preparent, - struct iatt *postparent, dict_t *xdata) -{ - int32_t callcnt = 0; - stripe_local_t *local = NULL; - call_frame_t *prev = NULL; - stripe_fd_ctx_t *fctx = NULL; - - if (!this || !frame || !frame->local || !cookie) { - gf_log("stripe", GF_LOG_DEBUG, "possible NULL deref"); - goto out; - } - - prev = cookie; - local = frame->local; - - LOCK(&frame->lock); - { - callcnt = --local->call_count; - - if (op_ret == -1) { - gf_log(this->name, GF_LOG_DEBUG, "%s returned error %s", - prev->this->name, strerror(op_errno)); - local->op_errno = op_errno; - if ((op_errno != ENOENT) || (prev->this == FIRST_CHILD(this))) - local->failed = 1; - } - - if (op_ret >= 0) { - local->op_ret = 0; - - if (IA_ISREG(inode->ia_type)) { - inode_ctx_get(inode, this, (uint64_t *)&fctx); - if (!fctx) { - gf_log(this->name, GF_LOG_ERROR, - "failed to get stripe context"); - op_ret = -1; - op_errno = EINVAL; - } - } - - if (FIRST_CHILD(this) == prev->this) { - local->inode = inode_ref(inode); - local->stbuf = *buf; - local->postparent = *postparent; - local->preparent = *preparent; - } - local->stbuf_blocks += buf->ia_blocks; - local->preparent_blocks += preparent->ia_blocks; - local->postparent_blocks += postparent->ia_blocks; - - correct_file_size(buf, fctx, prev); - - if (local->stbuf_size < buf->ia_size) - local->stbuf_size = buf->ia_size; - if (local->preparent_size < preparent->ia_size) - local->preparent_size = preparent->ia_size; - if (local->postparent_size < postparent->ia_size) - local->postparent_size = postparent->ia_size; - } - } - UNLOCK(&frame->lock); - - if (!callcnt) { - if (local->failed) - local->op_ret = -1; - - if (local->op_ret != -1) { - local->preparent.ia_blocks = local->preparent_blocks; - local->preparent.ia_size = local->preparent_size; - local->postparent.ia_blocks = local->postparent_blocks; - local->postparent.ia_size = local->postparent_size; - local->stbuf.ia_size = local->stbuf_size; - local->stbuf.ia_blocks = local->stbuf_blocks; - } - STRIPE_STACK_UNWIND(link, frame, local->op_ret, local->op_errno, - local->inode, &local->stbuf, &local->preparent, - &local->postparent, NULL); - } -out: - return 0; -} - -int32_t -stripe_link(call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc, - dict_t *xdata) -{ - xlator_list_t *trav = NULL; - stripe_local_t *local = NULL; - stripe_private_t *priv = NULL; - int32_t op_errno = 1; - - VALIDATE_OR_GOTO(frame, err); - VALIDATE_OR_GOTO(this, err); - VALIDATE_OR_GOTO(oldloc, err); - VALIDATE_OR_GOTO(oldloc->path, err); - VALIDATE_OR_GOTO(oldloc->inode, err); - - priv = this->private; - trav = this->children; - - /* If any one node is down, don't allow link operation */ - if (priv->nodes_down) { - op_errno = ENOTCONN; - goto err; - } - - /* Initialization */ - local = mem_get0(this->local_pool); - if (!local) { - op_errno = ENOMEM; - goto err; - } - local->op_ret = -1; - frame->local = local; - local->call_count = priv->child_count; - - /* Every time in stripe lookup, all child - nodes should be looked up */ - while (trav) { - STACK_WIND(frame, stripe_link_cbk, trav->xlator, - trav->xlator->fops->link, oldloc, newloc, NULL); - trav = trav->next; - } - - return 0; -err: - STRIPE_STACK_UNWIND(link, frame, -1, op_errno, NULL, NULL, NULL, NULL, - NULL); - return 0; -} - -int32_t -stripe_create_fail_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, - dict_t *xdata) -{ - int32_t callcnt = 0; - stripe_local_t *local = NULL; - - if (!this || !frame || !frame->local) { - gf_log("stripe", GF_LOG_DEBUG, "possible NULL deref"); - goto out; - } - - local = frame->local; - - LOCK(&frame->lock); - { - callcnt = --local->call_count; - } - UNLOCK(&frame->lock); - - if (!callcnt) { - STRIPE_STACK_UNWIND(create, frame, local->op_ret, local->op_errno, - local->fd, local->inode, &local->stbuf, - &local->preparent, &local->postparent, NULL); - } -out: - return 0; -} - -int32_t -stripe_create_cbk(call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, fd_t *fd, inode_t *inode, - struct iatt *buf, struct iatt *preparent, - struct iatt *postparent, dict_t *xdata) -{ - int32_t callcnt = 0; - stripe_local_t *local = NULL; - stripe_private_t *priv = NULL; - call_frame_t *prev = NULL; - xlator_list_t *trav = NULL; - - if (!this || !frame || !frame->local || !cookie) { - gf_log("stripe", GF_LOG_DEBUG, "possible NULL deref"); - goto out; - } - - prev = cookie; - priv = this->private; - local = frame->local; - - LOCK(&frame->lock); - { - callcnt = --local->call_count; - - if (op_ret == -1) { - gf_log(this->name, GF_LOG_DEBUG, "%s returned error %s", - prev->this->name, strerror(op_errno)); - local->failed = 1; - local->op_errno = op_errno; - } - - if (op_ret >= 0) { - if (IA_ISREG(buf->ia_type)) { - if (stripe_ctx_handle(this, prev, local, xdata)) - gf_log(this->name, GF_LOG_ERROR, - "Error getting fctx info from " - "dict"); - } - - local->op_ret = op_ret; - - local->stbuf_blocks += buf->ia_blocks; - local->preparent_blocks += preparent->ia_blocks; - local->postparent_blocks += postparent->ia_blocks; - - correct_file_size(buf, local->fctx, prev); - - if (local->stbuf_size < buf->ia_size) - local->stbuf_size = buf->ia_size; - if (local->preparent_size < preparent->ia_size) - local->preparent_size = preparent->ia_size; - if (local->postparent_size < postparent->ia_size) - local->postparent_size = postparent->ia_size; - } - } - UNLOCK(&frame->lock); - - if (!callcnt) { - if (local->failed) - local->op_ret = -1; - - if (local->op_ret == -1) { - local->call_count = priv->child_count; - trav = this->children; - while (trav) { - STACK_WIND(frame, stripe_create_fail_unlink_cbk, trav->xlator, - trav->xlator->fops->unlink, &local->loc, 0, NULL); - trav = trav->next; - } - - return 0; - } - - if (local->op_ret >= 0) { - local->preparent.ia_blocks = local->preparent_blocks; - local->preparent.ia_size = local->preparent_size; - local->postparent.ia_blocks = local->postparent_blocks; - local->postparent.ia_size = local->postparent_size; - local->stbuf.ia_size = local->stbuf_size; - local->stbuf.ia_blocks = local->stbuf_blocks; - - stripe_copy_xl_array(local->fctx->xl_array, priv->xl_array, - local->fctx->stripe_count); - inode_ctx_put(local->inode, this, (uint64_t)(uintptr_t)local->fctx); - } - - /* Create itself has failed.. so return - without setxattring */ - STRIPE_STACK_UNWIND(create, frame, local->op_ret, local->op_errno, - local->fd, local->inode, &local->stbuf, - &local->preparent, &local->postparent, NULL); - } - -out: - return 0; -} - -int32_t -stripe_first_create_cbk(call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, fd_t *fd, - inode_t *inode, struct iatt *buf, - struct iatt *preparent, struct iatt *postparent, - dict_t *xdata) -{ - stripe_local_t *local = NULL; - stripe_private_t *priv = NULL; - call_frame_t *prev = NULL; - xlator_list_t *trav = NULL; - int i = 1; - dict_t *dict = NULL; - loc_t *loc = NULL; - int32_t need_unref = 0; - int32_t ret = -1; - - if (!this || !frame || !frame->local || !cookie) { - gf_log("stripe", GF_LOG_DEBUG, "possible NULL deref"); - goto out; - } - - prev = cookie; - priv = this->private; - local = frame->local; - trav = this->children; - loc = &local->loc; - - --local->call_count; - - if (op_ret == -1) { - gf_log(this->name, GF_LOG_DEBUG, "%s returned error %s", - prev->this->name, strerror(op_errno)); - local->failed = 1; - local->op_errno = op_errno; - } - - local->op_ret = 0; - /* Get the mapping in inode private */ - /* Get the stat buf right */ - local->stbuf = *buf; - local->preparent = *preparent; - local->postparent = *postparent; - - local->stbuf_blocks += buf->ia_blocks; - local->preparent_blocks += preparent->ia_blocks; - local->postparent_blocks += postparent->ia_blocks; - - if (local->stbuf_size < buf->ia_size) - local->stbuf_size = buf->ia_size; - if (local->preparent_size < preparent->ia_size) - local->preparent_size = preparent->ia_size; - if (local->postparent_size < postparent->ia_size) - local->postparent_size = postparent->ia_size; - - if (local->failed) - local->op_ret = -1; - - if (local->op_ret == -1) { - local->call_count = 1; - STACK_WIND(frame, stripe_create_fail_unlink_cbk, FIRST_CHILD(this), - FIRST_CHILD(this)->fops->unlink, &local->loc, 0, NULL); - return 0; - } - - if (local->op_ret >= 0) { - local->preparent.ia_blocks = local->preparent_blocks; - local->preparent.ia_size = local->preparent_size; - local->postparent.ia_blocks = local->postparent_blocks; - local->postparent.ia_size = local->postparent_size; - local->stbuf.ia_size = local->stbuf_size; - local->stbuf.ia_blocks = local->stbuf_blocks; - } - - /* Send a setxattr request to nodes where the - files are created */ - trav = trav->next; - while (trav) { - if (priv->xattr_supported) { - dict = dict_new(); - if (!dict) { - gf_log(this->name, GF_LOG_ERROR, "failed to allocate dict %s", - loc->path); - } - need_unref = 1; - - dict_copy(local->xattr, dict); - - ret = stripe_xattr_request_build(this, dict, local->stripe_size, - priv->child_count, i, - priv->coalesce); - if (ret) - gf_log(this->name, GF_LOG_ERROR, - "failed to build xattr request"); - } else { - dict = local->xattr; - } - - STACK_WIND(frame, stripe_create_cbk, trav->xlator, - trav->xlator->fops->create, &local->loc, local->flags, - local->mode, local->umask, local->fd, dict); - trav = trav->next; - if (need_unref && dict) - dict_unref(dict); - i++; - } - -out: - return 0; -} - -/** - * stripe_create - If a block-size is specified for the 'name', create the - * file in all the child nodes. If not, create it in only first child. - * - * @name- complete path of the file to be created. - */ -int32_t -stripe_create(call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags, - mode_t mode, mode_t umask, fd_t *fd, dict_t *xdata) -{ - stripe_private_t *priv = NULL; - stripe_local_t *local = NULL; - int32_t op_errno = EINVAL; - int ret = 0; - int need_unref = 0; - int i = 0; - dict_t *dict = NULL; - - VALIDATE_OR_GOTO(frame, err); - VALIDATE_OR_GOTO(this, err); - VALIDATE_OR_GOTO(loc, err); - VALIDATE_OR_GOTO(loc->path, err); - VALIDATE_OR_GOTO(loc->inode, err); - - priv = this->private; - - /* files created in O_APPEND mode does not allow lseek() on fd */ - flags &= ~O_APPEND; - - if (priv->first_child_down || priv->nodes_down) { - gf_log(this->name, GF_LOG_DEBUG, "First node down, returning EIO"); - op_errno = EIO; - goto err; - } - - /* Initialization */ - local = mem_get0(this->local_pool); - if (!local) { - op_errno = ENOMEM; - goto err; - } - local->op_ret = -1; - local->op_errno = ENOTCONN; - local->stripe_size = stripe_get_matching_bs(loc->path, priv); - frame->local = local; - local->inode = inode_ref(loc->inode); - loc_copy(&local->loc, loc); - local->fd = fd_ref(fd); - local->flags = flags; - local->mode = mode; - local->umask = umask; - if (xdata) - local->xattr = dict_ref(xdata); - - local->call_count = priv->child_count; - /* Send a setxattr request to nodes where the - files are created */ - - if (priv->xattr_supported) { - dict = dict_new(); - if (!dict) { - gf_log(this->name, GF_LOG_ERROR, "failed to allocate dict %s", - loc->path); - } - need_unref = 1; - - dict_copy(xdata, dict); - - ret = stripe_xattr_request_build(this, dict, local->stripe_size, - priv->child_count, i, priv->coalesce); - if (ret) - gf_log(this->name, GF_LOG_ERROR, "failed to build xattr request"); - } else { - dict = xdata; - } - - STACK_WIND(frame, stripe_first_create_cbk, FIRST_CHILD(this), - FIRST_CHILD(this)->fops->create, loc, flags, mode, umask, fd, - dict); - - if (need_unref && dict) - dict_unref(dict); - - return 0; -err: - STRIPE_STACK_UNWIND(create, frame, -1, op_errno, NULL, NULL, NULL, NULL, - NULL, xdata); - return 0; -} - -int32_t -stripe_open_cbk(call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, fd_t *fd, dict_t *xdata) -{ - int32_t callcnt = 0; - stripe_local_t *local = NULL; - call_frame_t *prev = NULL; - - if (!this || !frame || !frame->local || !cookie) { - gf_log("stripe", GF_LOG_DEBUG, "possible NULL deref"); - goto out; - } - - prev = cookie; - local = frame->local; - - LOCK(&frame->lock); - { - callcnt = --local->call_count; - - if (op_ret == -1) { - gf_log(this->name, GF_LOG_DEBUG, "%s returned error %s", - prev->this->name, strerror(op_errno)); - if ((op_errno != ENOENT) || (prev->this == FIRST_CHILD(this))) - local->failed = 1; - local->op_errno = op_errno; - } - - if (op_ret >= 0) - local->op_ret = op_ret; - } - UNLOCK(&frame->lock); - - if (!callcnt) { - if (local->failed) - local->op_ret = -1; - - STRIPE_STACK_UNWIND(open, frame, local->op_ret, local->op_errno, - local->fd, xdata); - } -out: - return 0; -} - -/** - * stripe_open - - */ -int32_t -stripe_open(call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags, - fd_t *fd, dict_t *xdata) -{ - stripe_local_t *local = NULL; - stripe_private_t *priv = NULL; - xlator_list_t *trav = NULL; - int32_t op_errno = 1; - - VALIDATE_OR_GOTO(frame, err); - VALIDATE_OR_GOTO(this, err); - VALIDATE_OR_GOTO(loc, err); - VALIDATE_OR_GOTO(loc->path, err); - VALIDATE_OR_GOTO(loc->inode, err); - - priv = this->private; - trav = this->children; - - if (priv->first_child_down) { - op_errno = ENOTCONN; - goto err; - } - - /* Initialization */ - local = mem_get0(this->local_pool); - if (!local) { - op_errno = ENOMEM; - goto err; - } - - /* files opened in O_APPEND mode does not allow lseek() on fd */ - flags &= ~O_APPEND; - - local->fd = fd_ref(fd); - frame->local = local; - loc_copy(&local->loc, loc); - - /* Striped files */ - local->flags = flags; - local->call_count = priv->child_count; - local->stripe_size = stripe_get_matching_bs(loc->path, priv); - - while (trav) { - STACK_WIND(frame, stripe_open_cbk, trav->xlator, - trav->xlator->fops->open, &local->loc, local->flags, - local->fd, xdata); - trav = trav->next; - } - return 0; -err: - STRIPE_STACK_UNWIND(open, frame, -1, op_errno, NULL, NULL); - return 0; -} - -int32_t -stripe_opendir_cbk(call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, fd_t *fd, dict_t *xdata) -{ - int32_t callcnt = 0; - stripe_local_t *local = NULL; - call_frame_t *prev = NULL; - - if (!this || !frame || !frame->local || !cookie) { - gf_log("stripe", GF_LOG_DEBUG, "possible NULL deref"); - goto out; - } - - prev = cookie; - local = frame->local; - - LOCK(&frame->lock); - { - callcnt = --local->call_count; - - if (op_ret == -1) { - gf_log(this->name, GF_LOG_DEBUG, "%s returned error %s", - prev->this->name, strerror(op_errno)); - local->op_ret = -1; - local->op_errno = op_errno; - } - - if (op_ret >= 0) - local->op_ret = op_ret; - } - UNLOCK(&frame->lock); - - if (!callcnt) { - STRIPE_STACK_UNWIND(opendir, frame, local->op_ret, local->op_errno, - local->fd, NULL); - } -out: - return 0; -} - -int32_t -stripe_opendir(call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd, - dict_t *xdata) -{ - xlator_list_t *trav = NULL; - stripe_local_t *local = NULL; - stripe_private_t *priv = NULL; - int32_t op_errno = EINVAL; - - VALIDATE_OR_GOTO(frame, err); - VALIDATE_OR_GOTO(this, err); - VALIDATE_OR_GOTO(loc, err); - VALIDATE_OR_GOTO(loc->path, err); - VALIDATE_OR_GOTO(loc->inode, err); - - priv = this->private; - trav = this->children; - - if (priv->first_child_down) { - op_errno = ENOTCONN; - goto err; - } - - /* Initialization */ - local = mem_get0(this->local_pool); - if (!local) { - op_errno = ENOMEM; - goto err; - } - frame->local = local; - local->call_count = priv->child_count; - local->fd = fd_ref(fd); - - while (trav) { - STACK_WIND(frame, stripe_opendir_cbk, trav->xlator, - trav->xlator->fops->opendir, loc, fd, NULL); - trav = trav->next; - } - - return 0; -err: - STRIPE_STACK_UNWIND(opendir, frame, -1, op_errno, NULL, NULL); - return 0; -} - -int32_t -stripe_lk_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, - int32_t op_errno, struct gf_flock *lock, dict_t *xdata) -{ - int32_t callcnt = 0; - stripe_local_t *local = NULL; - call_frame_t *prev = NULL; - - if (!this || !frame || !frame->local || !cookie) { - gf_log("stripe", GF_LOG_DEBUG, "possible NULL deref"); - goto out; - } - - prev = cookie; - local = frame->local; - - LOCK(&frame->lock); - { - callcnt = --local->call_count; - if (op_ret == -1) { - gf_log(this->name, GF_LOG_DEBUG, "%s returned error %s", - prev->this->name, strerror(op_errno)); - local->op_errno = op_errno; - if ((op_errno != ENOENT) || (prev->this == FIRST_CHILD(this))) - local->failed = 1; - } - if (op_ret >= 0) { - if (FIRST_CHILD(this) == prev->this) { - /* First successful call, copy the *lock */ - local->op_ret = op_ret; - local->lock = *lock; - } - } - } - UNLOCK(&frame->lock); - - if (!callcnt) { - if (local->failed) - local->op_ret = -1; - STRIPE_STACK_UNWIND(lk, frame, local->op_ret, local->op_errno, - &local->lock, NULL); - } -out: - return 0; -} - -int32_t -stripe_lk(call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t cmd, - struct gf_flock *lock, dict_t *xdata) -{ - stripe_local_t *local = NULL; - xlator_list_t *trav = NULL; - stripe_private_t *priv = NULL; - int32_t op_errno = EINVAL; - - VALIDATE_OR_GOTO(frame, err); - VALIDATE_OR_GOTO(this, err); - VALIDATE_OR_GOTO(fd, err); - VALIDATE_OR_GOTO(fd->inode, err); - - trav = this->children; - priv = this->private; - - /* Initialization */ - local = mem_get0(this->local_pool); - if (!local) { - op_errno = ENOMEM; - goto err; - } - local->op_ret = -1; - frame->local = local; - local->call_count = priv->child_count; - - while (trav) { - STACK_WIND(frame, stripe_lk_cbk, trav->xlator, trav->xlator->fops->lk, - fd, cmd, lock, NULL); - trav = trav->next; - } - - return 0; -err: - STRIPE_STACK_UNWIND(lk, frame, -1, op_errno, NULL, NULL); - return 0; -} - -int32_t -stripe_flush_cbk(call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, dict_t *xdata) -{ - int32_t callcnt = 0; - stripe_local_t *local = NULL; - call_frame_t *prev = NULL; - - if (!this || !frame || !frame->local || !cookie) { - gf_log("stripe", GF_LOG_DEBUG, "possible NULL deref"); - goto out; - } - - prev = cookie; - local = frame->local; - - LOCK(&frame->lock); - { - callcnt = --local->call_count; - - if (op_ret == -1) { - gf_log(this->name, GF_LOG_DEBUG, "%s returned %s", prev->this->name, - strerror(op_errno)); - local->op_errno = op_errno; - if ((op_errno != ENOENT) || (prev->this == FIRST_CHILD(this))) - local->failed = 1; - } - if (op_ret >= 0) - local->op_ret = op_ret; - } - UNLOCK(&frame->lock); - - if (!callcnt) { - if (local->failed) - local->op_ret = -1; - - STRIPE_STACK_UNWIND(flush, frame, local->op_ret, local->op_errno, NULL); - } -out: - return 0; -} - -int32_t -stripe_flush(call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xdata) -{ - stripe_local_t *local = NULL; - stripe_private_t *priv = NULL; - xlator_list_t *trav = NULL; - int32_t op_errno = 1; - - VALIDATE_OR_GOTO(frame, err); - VALIDATE_OR_GOTO(this, err); - VALIDATE_OR_GOTO(fd, err); - VALIDATE_OR_GOTO(fd->inode, err); - - priv = this->private; - trav = this->children; - - if (priv->first_child_down) { - op_errno = ENOTCONN; - goto err; - } - /* Initialization */ - local = mem_get0(this->local_pool); - if (!local) { - op_errno = ENOMEM; - goto err; - } - local->op_ret = -1; - frame->local = local; - local->call_count = priv->child_count; - - while (trav) { - STACK_WIND(frame, stripe_flush_cbk, trav->xlator, - trav->xlator->fops->flush, fd, NULL); - trav = trav->next; - } - - return 0; -err: - STRIPE_STACK_UNWIND(flush, frame, -1, op_errno, NULL); - return 0; -} - -int32_t -stripe_fsync_cbk(call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct iatt *prebuf, - struct iatt *postbuf, dict_t *xdata) -{ - int32_t callcnt = 0; - stripe_local_t *local = NULL; - call_frame_t *prev = NULL; - - if (!this || !frame || !frame->local || !cookie) { - gf_log("stripe", GF_LOG_DEBUG, "possible NULL deref"); - goto out; - } - - prev = cookie; - local = frame->local; - - LOCK(&frame->lock); - { - callcnt = --local->call_count; - - if (op_ret == -1) { - gf_log(this->name, GF_LOG_DEBUG, "%s returned %s", prev->this->name, - strerror(op_errno)); - local->op_errno = op_errno; - if ((op_errno != ENOENT) || (prev->this == FIRST_CHILD(this))) - local->failed = 1; - } - if (op_ret >= 0) { - local->op_ret = op_ret; - if (FIRST_CHILD(this) == prev->this) { - local->pre_buf = *prebuf; - local->post_buf = *postbuf; - } - local->prebuf_blocks += prebuf->ia_blocks; - local->postbuf_blocks += postbuf->ia_blocks; - - correct_file_size(prebuf, local->fctx, prev); - correct_file_size(postbuf, local->fctx, prev); - - if (local->prebuf_size < prebuf->ia_size) - local->prebuf_size = prebuf->ia_size; - - if (local->postbuf_size < postbuf->ia_size) - local->postbuf_size = postbuf->ia_size; - } - } - UNLOCK(&frame->lock); - - if (!callcnt) { - if (local->failed) - local->op_ret = -1; - - if (local->op_ret != -1) { - local->pre_buf.ia_blocks = local->prebuf_blocks; - local->pre_buf.ia_size = local->prebuf_size; - local->post_buf.ia_blocks = local->postbuf_blocks; - local->post_buf.ia_size = local->postbuf_size; - } - - STRIPE_STACK_UNWIND(fsync, frame, local->op_ret, local->op_errno, - &local->pre_buf, &local->post_buf, NULL); - } -out: - return 0; -} - -int32_t -stripe_fsync(call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t flags, - dict_t *xdata) -{ - stripe_local_t *local = NULL; - stripe_private_t *priv = NULL; - xlator_list_t *trav = NULL; - stripe_fd_ctx_t *fctx = NULL; - int32_t op_errno = 1; - - VALIDATE_OR_GOTO(frame, err); - VALIDATE_OR_GOTO(this, err); - VALIDATE_OR_GOTO(fd, err); - VALIDATE_OR_GOTO(fd->inode, err); - - priv = this->private; - trav = this->children; - - /* Initialization */ - local = mem_get0(this->local_pool); - if (!local) { - op_errno = ENOMEM; - goto err; - } - - frame->local = local; - - inode_ctx_get(fd->inode, this, (uint64_t *)&fctx); - if (!fctx) { - op_errno = EINVAL; - goto err; - } - local->fctx = fctx; - local->op_ret = -1; - local->call_count = priv->child_count; - - while (trav) { - STACK_WIND(frame, stripe_fsync_cbk, trav->xlator, - trav->xlator->fops->fsync, fd, flags, NULL); - trav = trav->next; - } - - return 0; -err: - STRIPE_STACK_UNWIND(fsync, frame, -1, op_errno, NULL, NULL, NULL); - return 0; -} - -int32_t -stripe_fstat_cbk(call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct iatt *buf, - dict_t *xdata) -{ - int32_t callcnt = 0; - stripe_local_t *local = NULL; - call_frame_t *prev = NULL; - - if (!this || !frame || !frame->local || !cookie) { - gf_log("stripe", GF_LOG_DEBUG, "possible NULL deref"); - goto out; - } - - prev = cookie; - local = frame->local; - - LOCK(&frame->lock); - { - callcnt = --local->call_count; - - if (op_ret == -1) { - gf_log(this->name, GF_LOG_DEBUG, "%s returned error %s", - prev->this->name, strerror(op_errno)); - local->op_errno = op_errno; - if ((op_errno != ENOENT) || (prev->this == FIRST_CHILD(this))) - local->failed = 1; - } - - if (op_ret == 0) { - local->op_ret = 0; - - if (FIRST_CHILD(this) == prev->this) - local->stbuf = *buf; - - local->stbuf_blocks += buf->ia_blocks; - - correct_file_size(buf, local->fctx, prev); - - if (local->stbuf_size < buf->ia_size) - local->stbuf_size = buf->ia_size; - } - } - UNLOCK(&frame->lock); - - if (!callcnt) { - if (local->failed) - local->op_ret = -1; - - if (local->op_ret != -1) { - local->stbuf.ia_size = local->stbuf_size; - local->stbuf.ia_blocks = local->stbuf_blocks; - } - - STRIPE_STACK_UNWIND(fstat, frame, local->op_ret, local->op_errno, - &local->stbuf, NULL); - } - -out: - return 0; -} - -int32_t -stripe_fstat(call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xdata) -{ - stripe_local_t *local = NULL; - stripe_private_t *priv = NULL; - xlator_list_t *trav = NULL; - stripe_fd_ctx_t *fctx = NULL; - int32_t op_errno = 1; - - VALIDATE_OR_GOTO(frame, err); - VALIDATE_OR_GOTO(this, err); - VALIDATE_OR_GOTO(fd, err); - VALIDATE_OR_GOTO(fd->inode, err); - - priv = this->private; - trav = this->children; - - /* Initialization */ - local = mem_get0(this->local_pool); - if (!local) { - op_errno = ENOMEM; - goto err; - } - local->op_ret = -1; - frame->local = local; - local->call_count = priv->child_count; - - if (IA_ISREG(fd->inode->ia_type)) { - inode_ctx_get(fd->inode, this, (uint64_t *)&fctx); - if (!fctx) - goto err; - local->fctx = fctx; - } - - while (trav) { - STACK_WIND(frame, stripe_fstat_cbk, trav->xlator, - trav->xlator->fops->fstat, fd, NULL); - trav = trav->next; - } - - return 0; -err: - STRIPE_STACK_UNWIND(fstat, frame, -1, op_errno, NULL, NULL); - return 0; -} - -int32_t -stripe_ftruncate(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset, - dict_t *xdata) -{ - stripe_local_t *local = NULL; - stripe_private_t *priv = NULL; - stripe_fd_ctx_t *fctx = NULL; - int i, eof_idx; - off_t dest_offset, tmp_offset; - int32_t op_errno = 1; - - VALIDATE_OR_GOTO(frame, err); - VALIDATE_OR_GOTO(this, err); - VALIDATE_OR_GOTO(fd, err); - VALIDATE_OR_GOTO(fd->inode, err); - - priv = this->private; - - /* Initialization */ - local = mem_get0(this->local_pool); - if (!local) { - op_errno = ENOMEM; - goto err; - } - local->op_ret = -1; - frame->local = local; - local->call_count = priv->child_count; - - inode_ctx_get(fd->inode, this, (uint64_t *)&fctx); - if (!fctx) { - gf_log(this->name, GF_LOG_ERROR, "no stripe context"); - op_errno = EINVAL; - goto err; - } - if (!fctx->stripe_count) { - gf_log(this->name, GF_LOG_ERROR, "no stripe count"); - op_errno = EINVAL; - goto err; - } - - local->fctx = fctx; - eof_idx = (offset / fctx->stripe_size) % fctx->stripe_count; - - for (i = 0; i < fctx->stripe_count; i++) { - if (!fctx->xl_array[i]) { - gf_log(this->name, GF_LOG_ERROR, - "no xlator at index " - "%d", - i); - op_errno = EINVAL; - goto err; - } - - if (fctx->stripe_coalesce) { - if (i < eof_idx) - tmp_offset = gf_roof(offset, - fctx->stripe_size * fctx->stripe_count); - else if (i > eof_idx) - tmp_offset = gf_floor(offset, - fctx->stripe_size * fctx->stripe_count); - else - tmp_offset = offset; - - dest_offset = coalesced_offset(tmp_offset, fctx->stripe_size, - fctx->stripe_count); - } else { - dest_offset = offset; - } - - STACK_WIND(frame, stripe_truncate_cbk, fctx->xl_array[i], - fctx->xl_array[i]->fops->ftruncate, fd, dest_offset, NULL); - } - - return 0; -err: - STRIPE_STACK_UNWIND(ftruncate, frame, -1, op_errno, NULL, NULL, NULL); - return 0; -} - -int32_t -stripe_fsyncdir_cbk(call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, dict_t *xdata) -{ - int32_t callcnt = 0; - stripe_local_t *local = NULL; - call_frame_t *prev = NULL; - - if (!this || !frame || !frame->local || !cookie) { - gf_log("stripe", GF_LOG_DEBUG, "possible NULL deref"); - goto out; - } - - prev = cookie; - local = frame->local; - - LOCK(&frame->lock); - { - callcnt = --local->call_count; - - if (op_ret == -1) { - gf_log(this->name, GF_LOG_DEBUG, "%s returned %s", prev->this->name, - strerror(op_errno)); - local->op_errno = op_errno; - if ((op_errno != ENOENT) || (prev->this == FIRST_CHILD(this))) - local->failed = 1; - } - if (op_ret >= 0) - local->op_ret = op_ret; - } - UNLOCK(&frame->lock); - - if (!callcnt) { - if (local->failed) - local->op_ret = -1; - - STRIPE_STACK_UNWIND(fsyncdir, frame, local->op_ret, local->op_errno, - NULL); - } -out: - return 0; -} - -int32_t -stripe_fsyncdir(call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t flags, - dict_t *xdata) -{ - stripe_local_t *local = NULL; - stripe_private_t *priv = NULL; - xlator_list_t *trav = NULL; - int32_t op_errno = 1; - - VALIDATE_OR_GOTO(frame, err); - VALIDATE_OR_GOTO(this, err); - VALIDATE_OR_GOTO(fd, err); - VALIDATE_OR_GOTO(fd->inode, err); - - priv = this->private; - trav = this->children; - - /* Initialization */ - local = mem_get0(this->local_pool); - if (!local) { - op_errno = ENOMEM; - goto err; - } - local->op_ret = -1; - frame->local = local; - local->call_count = priv->child_count; - - while (trav) { - STACK_WIND(frame, stripe_fsyncdir_cbk, trav->xlator, - trav->xlator->fops->fsyncdir, fd, flags, NULL); - trav = trav->next; - } - - return 0; -err: - STRIPE_STACK_UNWIND(fsyncdir, frame, -1, op_errno, NULL); - return 0; -} - -int32_t -stripe_readv_fstat_cbk(call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct iatt *buf, - dict_t *xdata) -{ - int32_t i = 0; - int32_t callcnt = 0; - int32_t count = 0; - stripe_local_t *local = NULL; - struct iovec *vec = NULL; - struct iatt tmp_stbuf = { - 0, - }; - struct iobref *tmp_iobref = NULL; - struct iobuf *iobuf = NULL; - call_frame_t *prev = NULL; - - if (!this || !frame || !frame->local) { - gf_log("stripe", GF_LOG_DEBUG, "possible NULL deref"); - goto out; - } - - local = frame->local; - prev = cookie; - - LOCK(&frame->lock); - { - callcnt = --local->call_count; - if (op_ret != -1) { - correct_file_size(buf, local->fctx, prev); - if (local->stbuf_size < buf->ia_size) - local->stbuf_size = buf->ia_size; - } - } - UNLOCK(&frame->lock); - - if (!callcnt) { - op_ret = 0; - - /* Keep extra space for filling in '\0's */ - vec = GF_CALLOC((local->count * 2), sizeof(struct iovec), - gf_stripe_mt_iovec); - if (!vec) { - op_ret = -1; - goto done; - } - - for (i = 0; i < local->wind_count; i++) { - if (local->replies[i].op_ret) { - memcpy((vec + count), local->replies[i].vector, - (local->replies[i].count * sizeof(struct iovec))); - count += local->replies[i].count; - op_ret += local->replies[i].op_ret; - } - if ((local->replies[i].op_ret < local->replies[i].requested_size) && - (local->stbuf_size > (local->offset + op_ret))) { - /* Fill in 0s here */ - vec[count].iov_len = (local->replies[i].requested_size - - local->replies[i].op_ret); - iobuf = iobuf_get2(this->ctx->iobuf_pool, vec[count].iov_len); - if (!iobuf) { - gf_log(this->name, GF_LOG_ERROR, "Out of memory."); - op_ret = -1; - op_errno = ENOMEM; - goto done; - } - memset(iobuf->ptr, 0, vec[count].iov_len); - vec[count].iov_base = iobuf->ptr; - - iobref_add(local->iobref, iobuf); - iobuf_unref(iobuf); - - op_ret += vec[count].iov_len; - count++; - } - GF_FREE(local->replies[i].vector); - } - - /* ENOENT signals EOF to the NFS-server */ - if (op_ret != -1 && op_ret < local->readv_size && - (local->offset + op_ret == buf->ia_size)) - op_errno = ENOENT; - - /* FIXME: notice that st_ino, and st_dev (gen) will be - * different than what inode will have. Make sure this doesn't - * cause any bugs at higher levels */ - memcpy(&tmp_stbuf, &local->replies[0].stbuf, sizeof(struct iatt)); - tmp_stbuf.ia_size = local->stbuf_size; - - done: - GF_FREE(local->replies); - tmp_iobref = local->iobref; - STRIPE_STACK_UNWIND(readv, frame, op_ret, op_errno, vec, count, - &tmp_stbuf, tmp_iobref, NULL); - - iobref_unref(tmp_iobref); - GF_FREE(vec); - } -out: - return 0; -} - -/** - * stripe_readv_cbk - get all the striped reads, and order it properly, send it - * to above layer after putting it in a single vector. - */ -int32_t -stripe_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 *stbuf, struct iobref *iobref, - dict_t *xdata) -{ - int32_t index = 0; - int32_t callcnt = 0; - int32_t final_count = 0; - int32_t need_to_check_proper_size = 0; - call_frame_t *mframe = NULL; - stripe_local_t *mlocal = NULL; - stripe_local_t *local = NULL; - struct iovec *final_vec = NULL; - struct iatt tmp_stbuf = { - 0, - }; - struct iatt *tmp_stbuf_p = NULL; // need it for a warning - struct iobref *tmp_iobref = NULL; - stripe_fd_ctx_t *fctx = NULL; - call_frame_t *prev = NULL; - - if (!this || !frame || !frame->local || !cookie) { - gf_log("stripe", GF_LOG_DEBUG, "possible NULL deref"); - goto end; - } - - local = frame->local; - index = local->node_index; - prev = cookie; - mframe = local->orig_frame; - if (!mframe) - goto out; - - mlocal = mframe->local; - if (!mlocal) - goto out; - - fctx = mlocal->fctx; - - LOCK(&mframe->lock); - { - mlocal->replies[index].op_ret = op_ret; - mlocal->replies[index].op_errno = op_errno; - mlocal->replies[index].requested_size = local->readv_size; - if (op_ret >= 0) { - mlocal->replies[index].stbuf = *stbuf; - mlocal->replies[index].count = count; - mlocal->replies[index].vector = iov_dup(vector, count); - - correct_file_size(stbuf, fctx, prev); - - if (local->stbuf_size < stbuf->ia_size) - local->stbuf_size = stbuf->ia_size; - local->stbuf_blocks += stbuf->ia_blocks; - - if (!mlocal->iobref) - mlocal->iobref = iobref_new(); - iobref_merge(mlocal->iobref, iobref); - } - callcnt = ++mlocal->call_count; - } - UNLOCK(&mframe->lock); - - if (callcnt == mlocal->wind_count) { - op_ret = 0; - - for (index = 0; index < mlocal->wind_count; index++) { - /* check whether each stripe returned - * 'expected' number of bytes */ - if (mlocal->replies[index].op_ret == -1) { - op_ret = -1; - op_errno = mlocal->replies[index].op_errno; - break; - } - /* TODO: handle the 'holes' within the read range - properly */ - if (mlocal->replies[index].op_ret < - mlocal->replies[index].requested_size) { - need_to_check_proper_size = 1; - } - - op_ret += mlocal->replies[index].op_ret; - mlocal->count += mlocal->replies[index].count; - } - if (op_ret == -1) - goto done; - if (need_to_check_proper_size) - goto check_size; - - final_vec = GF_CALLOC(mlocal->count, sizeof(struct iovec), - gf_stripe_mt_iovec); - - if (!final_vec) { - op_ret = -1; - goto done; - } - - for (index = 0; index < mlocal->wind_count; index++) { - memcpy((final_vec + final_count), mlocal->replies[index].vector, - (mlocal->replies[index].count * sizeof(struct iovec))); - final_count += mlocal->replies[index].count; - GF_FREE(mlocal->replies[index].vector); - } - - /* FIXME: notice that st_ino, and st_dev (gen) will be - * different than what inode will have. Make sure this doesn't - * cause any bugs at higher levels */ - memcpy(&tmp_stbuf, &mlocal->replies[0].stbuf, sizeof(struct iatt)); - tmp_stbuf.ia_size = local->stbuf_size; - tmp_stbuf.ia_blocks = local->stbuf_blocks; - - done: - /* */ - GF_FREE(mlocal->replies); - tmp_iobref = mlocal->iobref; - /* work around for nfs truncated read. Bug 3774 */ - tmp_stbuf_p = &tmp_stbuf; - WIPE(tmp_stbuf_p); - STRIPE_STACK_UNWIND(readv, mframe, op_ret, op_errno, final_vec, - final_count, &tmp_stbuf, tmp_iobref, NULL); - - iobref_unref(tmp_iobref); - GF_FREE(final_vec); - } - - goto out; - -check_size: - mlocal->call_count = fctx->stripe_count; - - for (index = 0; index < fctx->stripe_count; index++) { - STACK_WIND(mframe, stripe_readv_fstat_cbk, (fctx->xl_array[index]), - (fctx->xl_array[index])->fops->fstat, mlocal->fd, NULL); - } - -out: - STRIPE_STACK_DESTROY(frame); -end: - return 0; -} - -int32_t -stripe_readv(call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, - off_t offset, uint32_t flags, dict_t *xdata) -{ - int32_t op_errno = EINVAL; - int32_t idx = 0; - int32_t index = 0; - int32_t num_stripe = 0; - int32_t off_index = 0; - size_t frame_size = 0; - off_t rounded_end = 0; - uint64_t tmp_fctx = 0; - uint64_t stripe_size = 0; - off_t rounded_start = 0; - off_t frame_offset = offset; - off_t dest_offset = 0; - stripe_local_t *local = NULL; - call_frame_t *rframe = NULL; - stripe_local_t *rlocal = NULL; - stripe_fd_ctx_t *fctx = NULL; - - VALIDATE_OR_GOTO(frame, err); - VALIDATE_OR_GOTO(this, err); - VALIDATE_OR_GOTO(fd, err); - VALIDATE_OR_GOTO(fd->inode, err); - - inode_ctx_get(fd->inode, this, &tmp_fctx); - if (!tmp_fctx) { - op_errno = EBADFD; - goto err; - } - fctx = (stripe_fd_ctx_t *)(long)tmp_fctx; - stripe_size = fctx->stripe_size; - - STRIPE_VALIDATE_FCTX(fctx, err); - - if (!stripe_size) { - gf_log(this->name, GF_LOG_DEBUG, "Wrong stripe size for the file"); - goto err; - } - /* The file is stripe across the child nodes. Send the read request - * to the child nodes appropriately after checking which region of - * the file is in which child node. Always '0-' part of - * the file resides in the first child. - */ - rounded_start = gf_floor(offset, stripe_size); - rounded_end = gf_roof(offset + size, stripe_size); - num_stripe = (rounded_end - rounded_start) / stripe_size; - - local = mem_get0(this->local_pool); - if (!local) { - op_errno = ENOMEM; - goto err; - } - frame->local = local; - - /* This is where all the vectors should be copied. */ - local->replies = GF_CALLOC(num_stripe, sizeof(struct stripe_replies), - gf_stripe_mt_stripe_replies); - if (!local->replies) { - op_errno = ENOMEM; - goto err; - } - - off_index = (offset / stripe_size) % fctx->stripe_count; - local->wind_count = num_stripe; - local->readv_size = size; - local->offset = offset; - local->fd = fd_ref(fd); - local->fctx = fctx; - - for (index = off_index; index < (num_stripe + off_index); index++) { - rframe = copy_frame(frame); - rlocal = mem_get0(this->local_pool); - if (!rlocal) { - op_errno = ENOMEM; - goto err; - } - - frame_size = min(gf_roof(frame_offset + 1, stripe_size), - (offset + size)) - - frame_offset; - - rlocal->node_index = index - off_index; - rlocal->orig_frame = frame; - rlocal->readv_size = frame_size; - rframe->local = rlocal; - idx = (index % fctx->stripe_count); - - if (fctx->stripe_coalesce) - dest_offset = coalesced_offset(frame_offset, stripe_size, - fctx->stripe_count); - else - dest_offset = frame_offset; - - STACK_WIND(rframe, stripe_readv_cbk, fctx->xl_array[idx], - fctx->xl_array[idx]->fops->readv, fd, frame_size, - dest_offset, flags, xdata); - - frame_offset += frame_size; - } - - return 0; -err: - if (rframe) - STRIPE_STACK_DESTROY(rframe); - - STRIPE_STACK_UNWIND(readv, frame, -1, op_errno, NULL, 0, NULL, NULL, NULL); - return 0; -} - -int32_t -stripe_writev_cbk(call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct iatt *prebuf, - struct iatt *postbuf, dict_t *xdata) -{ - int32_t callcnt = 0; - stripe_local_t *local = NULL; - stripe_local_t *mlocal = NULL; - call_frame_t *prev = NULL; - call_frame_t *mframe = NULL; - struct stripe_replies *reply = NULL; - int32_t i = 0; - - if (!this || !frame || !frame->local || !cookie) { - gf_log("stripe", GF_LOG_DEBUG, "possible NULL deref"); - goto out; - } - - prev = cookie; - local = frame->local; - mframe = local->orig_frame; - mlocal = mframe->local; - - LOCK(&frame->lock); - { - callcnt = ++mlocal->call_count; - - mlocal->replies[local->node_index].op_ret = op_ret; - mlocal->replies[local->node_index].op_errno = op_errno; - - if (op_ret >= 0) { - mlocal->post_buf = *postbuf; - mlocal->pre_buf = *prebuf; - - mlocal->prebuf_blocks += prebuf->ia_blocks; - mlocal->postbuf_blocks += postbuf->ia_blocks; - - correct_file_size(prebuf, mlocal->fctx, prev); - correct_file_size(postbuf, mlocal->fctx, prev); - - if (mlocal->prebuf_size < prebuf->ia_size) - mlocal->prebuf_size = prebuf->ia_size; - if (mlocal->postbuf_size < postbuf->ia_size) - mlocal->postbuf_size = postbuf->ia_size; - } - } - UNLOCK(&frame->lock); - - if ((callcnt == mlocal->wind_count) && mlocal->unwind) { - mlocal->pre_buf.ia_size = mlocal->prebuf_size; - mlocal->pre_buf.ia_blocks = mlocal->prebuf_blocks; - mlocal->post_buf.ia_size = mlocal->postbuf_size; - mlocal->post_buf.ia_blocks = mlocal->postbuf_blocks; - - /* - * Only return the number of consecutively written bytes up until - * the first error. Only return an error if it occurs first. - * - * When a short write occurs, the application should retry at the - * appropriate offset, at which point we'll potentially pass back - * the error. - */ - for (i = 0, reply = mlocal->replies; i < mlocal->wind_count; - i++, reply++) { - if (reply->op_ret == -1) { - gf_log(this->name, GF_LOG_DEBUG, - "reply %d " - "returned error %s", - i, strerror(reply->op_errno)); - if (!mlocal->op_ret) { - mlocal->op_ret = -1; - mlocal->op_errno = reply->op_errno; - } - break; - } - - mlocal->op_ret += reply->op_ret; - - if (reply->op_ret < reply->requested_size) - break; - } - - GF_FREE(mlocal->replies); - - STRIPE_STACK_UNWIND(writev, mframe, mlocal->op_ret, mlocal->op_errno, - &mlocal->pre_buf, &mlocal->post_buf, NULL); - } -out: - if (frame) - STRIPE_STACK_DESTROY(frame); - return 0; -} - -int32_t -stripe_writev(call_frame_t *frame, xlator_t *this, fd_t *fd, - struct iovec *vector, int32_t count, off_t offset, uint32_t flags, - struct iobref *iobref, dict_t *xdata) -{ - struct iovec *tmp_vec = NULL; - stripe_local_t *local = NULL; - stripe_fd_ctx_t *fctx = NULL; - int32_t op_errno = 1; - int32_t idx = 0; - int32_t total_size = 0; - int32_t offset_offset = 0; - int32_t remaining_size = 0; - int32_t tmp_count = count; - off_t fill_size = 0; - uint64_t stripe_size = 0; - uint64_t tmp_fctx = 0; - off_t dest_offset = 0; - off_t rounded_start = 0; - off_t rounded_end = 0; - int32_t total_chunks = 0; - call_frame_t *wframe = NULL; - stripe_local_t *wlocal = NULL; - - VALIDATE_OR_GOTO(frame, err); - VALIDATE_OR_GOTO(this, err); - VALIDATE_OR_GOTO(fd, err); - VALIDATE_OR_GOTO(fd->inode, err); - - inode_ctx_get(fd->inode, this, &tmp_fctx); - if (!tmp_fctx) { - op_errno = EINVAL; - goto err; - } - fctx = (stripe_fd_ctx_t *)(long)tmp_fctx; - stripe_size = fctx->stripe_size; - - STRIPE_VALIDATE_FCTX(fctx, err); - - /* File has to be stripped across the child nodes */ - total_size = iov_length(vector, count); - remaining_size = total_size; - - local = mem_get0(this->local_pool); - if (!local) { - op_errno = ENOMEM; - goto err; - } - frame->local = local; - local->stripe_size = stripe_size; - local->fctx = fctx; - - if (!stripe_size) { - gf_log(this->name, GF_LOG_DEBUG, "Wrong stripe size for the file"); - op_errno = EINVAL; - goto err; - } - - rounded_start = gf_floor(offset, stripe_size); - rounded_end = gf_roof(offset + total_size, stripe_size); - total_chunks = (rounded_end - rounded_start) / stripe_size; - local->replies = GF_CALLOC(total_chunks, sizeof(struct stripe_replies), - gf_stripe_mt_stripe_replies); - if (!local->replies) { - op_errno = ENOMEM; - goto err; - } - - total_chunks = 0; - while (1) { - wframe = copy_frame(frame); - wlocal = mem_get0(this->local_pool); - if (!wlocal) { - op_errno = ENOMEM; - goto err; - } - wlocal->orig_frame = frame; - wframe->local = wlocal; - - /* Send striped chunk of the vector to child - nodes appropriately. */ - idx = (((offset + offset_offset) / local->stripe_size) % - fctx->stripe_count); - - fill_size = (local->stripe_size - - ((offset + offset_offset) % local->stripe_size)); - if (fill_size > remaining_size) - fill_size = remaining_size; - - remaining_size -= fill_size; - - tmp_count = iov_subset(vector, count, offset_offset, - offset_offset + fill_size, NULL); - tmp_vec = GF_CALLOC(tmp_count, sizeof(struct iovec), - gf_stripe_mt_iovec); - if (!tmp_vec) { - op_errno = ENOMEM; - goto err; - } - tmp_count = iov_subset(vector, count, offset_offset, - offset_offset + fill_size, tmp_vec); - - local->wind_count++; - if (remaining_size == 0) - local->unwind = 1; - - /* - * Store off the request index (with respect to the chunk of the - * initial offset) and the size of the request. This is required - * in the callback to calculate an appropriate return value in - * the event of a write failure in one or more requests. - */ - wlocal->node_index = total_chunks; - local->replies[total_chunks].requested_size = fill_size; - - dest_offset = offset + offset_offset; - if (fctx->stripe_coalesce) - dest_offset = coalesced_offset(dest_offset, local->stripe_size, - fctx->stripe_count); - - STACK_WIND(wframe, stripe_writev_cbk, fctx->xl_array[idx], - fctx->xl_array[idx]->fops->writev, fd, tmp_vec, tmp_count, - dest_offset, flags, iobref, xdata); - - GF_FREE(tmp_vec); - offset_offset += fill_size; - total_chunks++; - if (remaining_size == 0) - break; - } - - return 0; -err: - if (wframe) - STRIPE_STACK_DESTROY(wframe); - - STRIPE_STACK_UNWIND(writev, frame, -1, op_errno, NULL, NULL, NULL); - return 0; -} - -int32_t -stripe_fallocate_cbk(call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct iatt *prebuf, - struct iatt *postbuf, dict_t *xdata) -{ - int32_t callcnt = 0; - stripe_local_t *local = NULL; - stripe_local_t *mlocal = NULL; - call_frame_t *prev = NULL; - call_frame_t *mframe = NULL; - - if (!this || !frame || !frame->local || !cookie) { - gf_log("stripe", GF_LOG_DEBUG, "possible NULL deref"); - goto out; - } - - prev = cookie; - local = frame->local; - mframe = local->orig_frame; - mlocal = mframe->local; - - LOCK(&frame->lock); - { - callcnt = ++mlocal->call_count; - - if (op_ret == 0) { - mlocal->post_buf = *postbuf; - mlocal->pre_buf = *prebuf; - - mlocal->prebuf_blocks += prebuf->ia_blocks; - mlocal->postbuf_blocks += postbuf->ia_blocks; - - correct_file_size(prebuf, mlocal->fctx, prev); - correct_file_size(postbuf, mlocal->fctx, prev); - - if (mlocal->prebuf_size < prebuf->ia_size) - mlocal->prebuf_size = prebuf->ia_size; - if (mlocal->postbuf_size < postbuf->ia_size) - mlocal->postbuf_size = postbuf->ia_size; - } - - /* return the first failure */ - if (mlocal->op_ret == 0) { - mlocal->op_ret = op_ret; - mlocal->op_errno = op_errno; - } - } - UNLOCK(&frame->lock); - - if ((callcnt == mlocal->wind_count) && mlocal->unwind) { - mlocal->pre_buf.ia_size = mlocal->prebuf_size; - mlocal->pre_buf.ia_blocks = mlocal->prebuf_blocks; - mlocal->post_buf.ia_size = mlocal->postbuf_size; - mlocal->post_buf.ia_blocks = mlocal->postbuf_blocks; - - STRIPE_STACK_UNWIND(fallocate, mframe, mlocal->op_ret, mlocal->op_errno, - &mlocal->pre_buf, &mlocal->post_buf, NULL); - } -out: - if (frame) - STRIPE_STACK_DESTROY(frame); - return 0; -} - -int32_t -stripe_fallocate(call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t mode, - off_t offset, size_t len, dict_t *xdata) -{ - stripe_local_t *local = NULL; - stripe_fd_ctx_t *fctx = NULL; - int32_t op_errno = 1; - int32_t idx = 0; - int32_t offset_offset = 0; - int32_t remaining_size = 0; - off_t fill_size = 0; - uint64_t stripe_size = 0; - uint64_t tmp_fctx = 0; - off_t dest_offset = 0; - call_frame_t *fframe = NULL; - stripe_local_t *flocal = NULL; - - VALIDATE_OR_GOTO(frame, err); - VALIDATE_OR_GOTO(this, err); - VALIDATE_OR_GOTO(fd, err); - VALIDATE_OR_GOTO(fd->inode, err); - - inode_ctx_get(fd->inode, this, &tmp_fctx); - if (!tmp_fctx) { - op_errno = EINVAL; - goto err; - } - fctx = (stripe_fd_ctx_t *)(long)tmp_fctx; - stripe_size = fctx->stripe_size; - - STRIPE_VALIDATE_FCTX(fctx, err); - - remaining_size = len; - - local = mem_get0(this->local_pool); - if (!local) { - op_errno = ENOMEM; - goto err; - } - frame->local = local; - local->stripe_size = stripe_size; - local->fctx = fctx; - - if (!stripe_size) { - gf_log(this->name, GF_LOG_DEBUG, "Wrong stripe size for the file"); - op_errno = EINVAL; - goto err; - } - - while (1) { - fframe = copy_frame(frame); - flocal = mem_get0(this->local_pool); - if (!flocal) { - op_errno = ENOMEM; - goto err; - } - flocal->orig_frame = frame; - fframe->local = flocal; - - /* send fallocate request to the associated child node */ - idx = (((offset + offset_offset) / local->stripe_size) % - fctx->stripe_count); - - fill_size = (local->stripe_size - - ((offset + offset_offset) % local->stripe_size)); - if (fill_size > remaining_size) - fill_size = remaining_size; - - remaining_size -= fill_size; - - local->wind_count++; - if (remaining_size == 0) - local->unwind = 1; - - dest_offset = offset + offset_offset; - if (fctx->stripe_coalesce) - dest_offset = coalesced_offset(dest_offset, local->stripe_size, - fctx->stripe_count); - - /* - * TODO: Create a separate handler for coalesce mode that sends a - * single fallocate per-child (since the ranges are linear). - */ - STACK_WIND(fframe, stripe_fallocate_cbk, fctx->xl_array[idx], - fctx->xl_array[idx]->fops->fallocate, fd, mode, dest_offset, - fill_size, xdata); - - offset_offset += fill_size; - if (remaining_size == 0) - break; - } - - return 0; -err: - if (fframe) - STRIPE_STACK_DESTROY(fframe); - - STRIPE_STACK_UNWIND(fallocate, frame, -1, op_errno, NULL, NULL, NULL); - return 0; -} - -int32_t -stripe_discard_cbk(call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct iatt *prebuf, - struct iatt *postbuf, dict_t *xdata) -{ - int32_t callcnt = 0; - stripe_local_t *local = NULL; - stripe_local_t *mlocal = NULL; - call_frame_t *prev = NULL; - call_frame_t *mframe = NULL; - - if (!this || !frame || !frame->local || !cookie) { - gf_log("stripe", GF_LOG_DEBUG, "possible NULL deref"); - goto out; - } - - prev = cookie; - local = frame->local; - mframe = local->orig_frame; - mlocal = mframe->local; - - LOCK(&frame->lock); - { - callcnt = ++mlocal->call_count; - - if (op_ret == 0) { - mlocal->post_buf = *postbuf; - mlocal->pre_buf = *prebuf; - - mlocal->prebuf_blocks += prebuf->ia_blocks; - mlocal->postbuf_blocks += postbuf->ia_blocks; - - correct_file_size(prebuf, mlocal->fctx, prev); - correct_file_size(postbuf, mlocal->fctx, prev); - - if (mlocal->prebuf_size < prebuf->ia_size) - mlocal->prebuf_size = prebuf->ia_size; - if (mlocal->postbuf_size < postbuf->ia_size) - mlocal->postbuf_size = postbuf->ia_size; - } - - /* return the first failure */ - if (mlocal->op_ret == 0) { - mlocal->op_ret = op_ret; - mlocal->op_errno = op_errno; - } - } - UNLOCK(&frame->lock); - - if ((callcnt == mlocal->wind_count) && mlocal->unwind) { - mlocal->pre_buf.ia_size = mlocal->prebuf_size; - mlocal->pre_buf.ia_blocks = mlocal->prebuf_blocks; - mlocal->post_buf.ia_size = mlocal->postbuf_size; - mlocal->post_buf.ia_blocks = mlocal->postbuf_blocks; - - STRIPE_STACK_UNWIND(discard, mframe, mlocal->op_ret, mlocal->op_errno, - &mlocal->pre_buf, &mlocal->post_buf, NULL); - } -out: - if (frame) - STRIPE_STACK_DESTROY(frame); - - return 0; -} - -int32_t -stripe_discard(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset, - size_t len, dict_t *xdata) -{ - stripe_local_t *local = NULL; - stripe_fd_ctx_t *fctx = NULL; - int32_t op_errno = 1; - int32_t idx = 0; - int32_t offset_offset = 0; - int32_t remaining_size = 0; - off_t fill_size = 0; - uint64_t stripe_size = 0; - uint64_t tmp_fctx = 0; - off_t dest_offset = 0; - call_frame_t *fframe = NULL; - stripe_local_t *flocal = NULL; - - VALIDATE_OR_GOTO(frame, err); - VALIDATE_OR_GOTO(this, err); - VALIDATE_OR_GOTO(fd, err); - VALIDATE_OR_GOTO(fd->inode, err); - - inode_ctx_get(fd->inode, this, &tmp_fctx); - if (!tmp_fctx) { - op_errno = EINVAL; - goto err; - } - fctx = (stripe_fd_ctx_t *)(long)tmp_fctx; - stripe_size = fctx->stripe_size; - - STRIPE_VALIDATE_FCTX(fctx, err); - - remaining_size = len; - - local = mem_get0(this->local_pool); - if (!local) { - op_errno = ENOMEM; - goto err; - } - frame->local = local; - local->stripe_size = stripe_size; - local->fctx = fctx; - - if (!stripe_size) { - gf_log(this->name, GF_LOG_DEBUG, "Wrong stripe size for the file"); - op_errno = EINVAL; - goto err; - } - - while (1) { - fframe = copy_frame(frame); - flocal = mem_get0(this->local_pool); - if (!flocal) { - op_errno = ENOMEM; - goto err; - } - flocal->orig_frame = frame; - fframe->local = flocal; - - /* send discard request to the associated child node */ - idx = (((offset + offset_offset) / local->stripe_size) % - fctx->stripe_count); - - fill_size = (local->stripe_size - - ((offset + offset_offset) % local->stripe_size)); - if (fill_size > remaining_size) - fill_size = remaining_size; - - remaining_size -= fill_size; - - local->wind_count++; - if (remaining_size == 0) - local->unwind = 1; - - dest_offset = offset + offset_offset; - if (fctx->stripe_coalesce) - dest_offset = coalesced_offset(dest_offset, local->stripe_size, - fctx->stripe_count); - - /* - * TODO: Create a separate handler for coalesce mode that sends a - * single discard per-child (since the ranges are linear). - */ - STACK_WIND(fframe, stripe_discard_cbk, fctx->xl_array[idx], - fctx->xl_array[idx]->fops->discard, fd, dest_offset, - fill_size, xdata); - - offset_offset += fill_size; - if (remaining_size == 0) - break; - } - - return 0; -err: - if (fframe) - STRIPE_STACK_DESTROY(fframe); - - STRIPE_STACK_UNWIND(discard, frame, -1, op_errno, NULL, NULL, NULL); - return 0; -} - -int32_t -stripe_zerofill_cbk(call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct iatt *prebuf, - struct iatt *postbuf, dict_t *xdata) -{ - int32_t callcnt = 0; - stripe_local_t *local = NULL; - stripe_local_t *mlocal = NULL; - call_frame_t *prev = NULL; - call_frame_t *mframe = NULL; - - GF_ASSERT(frame); - - if (!this || !frame->local || !cookie) { - gf_log("stripe", GF_LOG_DEBUG, "possible NULL deref"); - goto out; - } - - prev = cookie; - local = frame->local; - mframe = local->orig_frame; - mlocal = mframe->local; - - LOCK(&frame->lock); - { - callcnt = ++mlocal->call_count; - - if (op_ret == 0) { - mlocal->post_buf = *postbuf; - mlocal->pre_buf = *prebuf; - - mlocal->prebuf_blocks += prebuf->ia_blocks; - mlocal->postbuf_blocks += postbuf->ia_blocks; - - correct_file_size(prebuf, mlocal->fctx, prev); - correct_file_size(postbuf, mlocal->fctx, prev); - - if (mlocal->prebuf_size < prebuf->ia_size) - mlocal->prebuf_size = prebuf->ia_size; - if (mlocal->postbuf_size < postbuf->ia_size) - mlocal->postbuf_size = postbuf->ia_size; - } - - /* return the first failure */ - if (mlocal->op_ret == 0) { - mlocal->op_ret = op_ret; - mlocal->op_errno = op_errno; - } - } - UNLOCK(&frame->lock); - - if ((callcnt == mlocal->wind_count) && mlocal->unwind) { - mlocal->pre_buf.ia_size = mlocal->prebuf_size; - mlocal->pre_buf.ia_blocks = mlocal->prebuf_blocks; - mlocal->post_buf.ia_size = mlocal->postbuf_size; - mlocal->post_buf.ia_blocks = mlocal->postbuf_blocks; - - STRIPE_STACK_UNWIND(zerofill, mframe, mlocal->op_ret, mlocal->op_errno, - &mlocal->pre_buf, &mlocal->post_buf, NULL); - } -out: - STRIPE_STACK_DESTROY(frame); - return 0; -} - -int32_t -stripe_zerofill(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset, - off_t len, dict_t *xdata) -{ - stripe_local_t *local = NULL; - stripe_fd_ctx_t *fctx = NULL; - int32_t op_errno = 1; - int32_t idx = 0; - int32_t offset_offset = 0; - int32_t remaining_size = 0; - off_t fill_size = 0; - uint64_t stripe_size = 0; - uint64_t tmp_fctx = 0; - off_t dest_offset = 0; - call_frame_t *fframe = NULL; - stripe_local_t *flocal = NULL; - - VALIDATE_OR_GOTO(frame, err); - VALIDATE_OR_GOTO(this, err); - VALIDATE_OR_GOTO(fd, err); - VALIDATE_OR_GOTO(fd->inode, err); - - inode_ctx_get(fd->inode, this, &tmp_fctx); - if (!tmp_fctx) { - op_errno = EINVAL; - goto err; - } - fctx = (stripe_fd_ctx_t *)(long)tmp_fctx; - stripe_size = fctx->stripe_size; - - STRIPE_VALIDATE_FCTX(fctx, err); - - remaining_size = len; - - local = mem_get0(this->local_pool); - if (!local) { - op_errno = ENOMEM; - goto err; - } - frame->local = local; - local->stripe_size = stripe_size; - local->fctx = fctx; - - if (!stripe_size) { - gf_log(this->name, GF_LOG_DEBUG, "Wrong stripe size for the file"); - op_errno = EINVAL; - goto err; - } - - while (1) { - fframe = copy_frame(frame); - flocal = mem_get0(this->local_pool); - if (!flocal) { - op_errno = ENOMEM; - goto err; - } - flocal->orig_frame = frame; - fframe->local = flocal; - - idx = (((offset + offset_offset) / local->stripe_size) % - fctx->stripe_count); - - fill_size = (local->stripe_size - - ((offset + offset_offset) % local->stripe_size)); - if (fill_size > remaining_size) - fill_size = remaining_size; - - remaining_size -= fill_size; - - local->wind_count++; - if (remaining_size == 0) - local->unwind = 1; - - dest_offset = offset + offset_offset; - if (fctx->stripe_coalesce) - dest_offset = coalesced_offset(dest_offset, local->stripe_size, - fctx->stripe_count); - - STACK_WIND(fframe, stripe_zerofill_cbk, fctx->xl_array[idx], - fctx->xl_array[idx]->fops->zerofill, fd, dest_offset, - fill_size, xdata); - offset_offset += fill_size; - if (remaining_size == 0) - break; - } - - return 0; -err: - if (fframe) - STRIPE_STACK_DESTROY(fframe); - - STRIPE_STACK_UNWIND(zerofill, frame, -1, op_errno, NULL, NULL, NULL); - return 0; -} - -int32_t -stripe_seek(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset, - gf_seek_what_t what, dict_t *xdata) -{ - /* TBD */ - gf_log(this->name, GF_LOG_INFO, "seek called on %s.", - uuid_utoa(fd->inode->gfid)); - STRIPE_STACK_UNWIND(seek, frame, -1, ENOTSUP, 0, NULL); - return 0; -} - -int32_t -stripe_release(xlator_t *this, fd_t *fd) -{ - return 0; -} - -int -stripe_forget(xlator_t *this, inode_t *inode) -{ - uint64_t tmp_fctx = 0; - stripe_fd_ctx_t *fctx = NULL; - - VALIDATE_OR_GOTO(this, err); - VALIDATE_OR_GOTO(inode, err); - - (void)inode_ctx_del(inode, this, &tmp_fctx); - if (!tmp_fctx) { - goto err; - } - - fctx = (stripe_fd_ctx_t *)(long)tmp_fctx; - - if (!fctx->static_array) - GF_FREE(fctx->xl_array); - - GF_FREE(fctx); -err: - return 0; -} - -int32_t -notify(xlator_t *this, int32_t event, void *data, ...) -{ - stripe_private_t *priv = NULL; - int down_client = 0; - int i = 0; - gf_boolean_t heard_from_all_children = _gf_false; - - if (!this) - return 0; - - priv = this->private; - if (!priv) - return 0; - - switch (event) { - case GF_EVENT_CHILD_UP: { - /* get an index number to set */ - for (i = 0; i < priv->child_count; i++) { - if (data == priv->xl_array[i]) - break; - } - - if (priv->child_count == i) { - gf_log(this->name, GF_LOG_ERROR, - "got GF_EVENT_CHILD_UP bad subvolume %s", - data ? ((xlator_t *)data)->name : NULL); - break; - } - - LOCK(&priv->lock); - { - if (data == FIRST_CHILD(this)) - priv->first_child_down = 0; - priv->last_event[i] = event; - } - UNLOCK(&priv->lock); - } break; - case GF_EVENT_CHILD_CONNECTING: { - // 'CONNECTING' doesn't ensure its CHILD_UP, so do nothing - goto out; - } - case GF_EVENT_CHILD_DOWN: { - /* get an index number to set */ - for (i = 0; i < priv->child_count; i++) { - if (data == priv->xl_array[i]) - break; - } - - if (priv->child_count == i) { - gf_log(this->name, GF_LOG_ERROR, - "got GF_EVENT_CHILD_DOWN bad subvolume %s", - data ? ((xlator_t *)data)->name : NULL); - break; - } - - LOCK(&priv->lock); - { - if (data == FIRST_CHILD(this)) - priv->first_child_down = 1; - priv->last_event[i] = event; - } - UNLOCK(&priv->lock); - } break; - - default: { - /* */ - default_notify(this, event, data); - goto out; - } break; - } - - // Consider child as down if it's last_event is not CHILD_UP - for (i = 0, down_client = 0; i < priv->child_count; i++) - if (priv->last_event[i] != GF_EVENT_CHILD_UP) - down_client++; - - LOCK(&priv->lock); - { - priv->nodes_down = down_client; - } - UNLOCK(&priv->lock); - - heard_from_all_children = _gf_true; - for (i = 0; i < priv->child_count; i++) - if (!priv->last_event[i]) - heard_from_all_children = _gf_false; - - if (heard_from_all_children) - default_notify(this, event, data); -out: - return 0; -} - -int -stripe_setxattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this, - int op_ret, int op_errno, dict_t *xdata) -{ - int ret = -1; - int call_cnt = 0; - stripe_local_t *local = NULL; - - if (!frame || !frame->local || !this) { - gf_log("", GF_LOG_ERROR, "Possible NULL deref"); - return ret; - } - - local = frame->local; - - LOCK(&frame->lock); - { - call_cnt = --local->wind_count; - - /** - * We overwrite ->op_* values here for subsequent failure - * conditions, hence we propagate the last errno down the - * stack. - */ - if (op_ret < 0) { - local->op_ret = op_ret; - local->op_errno = op_errno; - goto unlock; - } - } - -unlock: - UNLOCK(&frame->lock); - - if (!call_cnt) { - STRIPE_STACK_UNWIND(setxattr, frame, local->op_ret, local->op_errno, - xdata); - } - - return 0; -} - -#ifdef HAVE_BD_XLATOR -int -stripe_is_bd(dict_t *this, char *key, data_t *value, void *data) -{ - gf_boolean_t *is_bd = data; - - if (data == NULL) - return 0; - - if (XATTR_IS_BD(key)) - *is_bd = _gf_true; - - return 0; -} - -static gf_boolean_t -stripe_setxattr_is_bd(dict_t *dict) -{ - gf_boolean_t is_bd = _gf_false; - - if (dict == NULL) - goto out; - - dict_foreach(dict, stripe_is_bd, &is_bd); -out: - return is_bd; -} -#else -#define stripe_setxattr_is_bd(dict) _gf_false -#endif - -int -stripe_setxattr(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *dict, - int flags, dict_t *xdata) -{ - int32_t op_errno = EINVAL; - xlator_list_t *trav = NULL; - stripe_private_t *priv = NULL; - stripe_local_t *local = NULL; - int i = 0; - gf_boolean_t is_bd = _gf_false; - - VALIDATE_OR_GOTO(frame, err); - VALIDATE_OR_GOTO(this, err); - VALIDATE_OR_GOTO(loc, err); - VALIDATE_OR_GOTO(loc->inode, err); - - GF_IF_INTERNAL_XATTR_GOTO("trusted.*stripe*", dict, op_errno, err); - - priv = this->private; - trav = this->children; - - local = mem_get0(this->local_pool); - if (!local) { - op_errno = ENOMEM; - goto err; - } - - frame->local = local; - local->wind_count = priv->child_count; - local->op_ret = local->op_errno = 0; - - is_bd = stripe_setxattr_is_bd(dict); - - /** - * Set xattrs for directories on all subvolumes. Additionally - * this power is only given to a special client. Bd xlator - * also needs xattrs for regular files (ie LVs) - */ - if (((frame->root->pid == GF_CLIENT_PID_GSYNCD) && - IA_ISDIR(loc->inode->ia_type)) || - is_bd) { - for (i = 0; i < priv->child_count; i++, trav = trav->next) { - STACK_WIND(frame, stripe_setxattr_cbk, trav->xlator, - trav->xlator->fops->setxattr, loc, dict, flags, xdata); - } - } else { - local->wind_count = 1; - STACK_WIND(frame, stripe_setxattr_cbk, FIRST_CHILD(this), - FIRST_CHILD(this)->fops->setxattr, loc, dict, flags, xdata); - } - - return 0; -err: - STRIPE_STACK_UNWIND(setxattr, frame, -1, op_errno, NULL); - return 0; -} - -int -stripe_fsetxattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this, - int op_ret, int op_errno, dict_t *xdata) -{ - STRIPE_STACK_UNWIND(fsetxattr, frame, op_ret, op_errno, xdata); - return 0; -} - -int -stripe_is_special_key(dict_t *this, char *key, data_t *value, void *data) -{ - gf_boolean_t *is_special = NULL; - - if (data == NULL) { - goto out; - } - - is_special = data; - - if (XATTR_IS_LOCKINFO(key) || XATTR_IS_BD(key)) - *is_special = _gf_true; - -out: - return 0; -} - -int32_t -stripe_fsetxattr_everyone_cbk(call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, dict_t *xdata) -{ - int call_count = 0; - stripe_local_t *local = NULL; - - local = frame->local; - - LOCK(&frame->lock); - { - call_count = --local->wind_count; - - if (op_ret < 0) { - local->op_ret = op_ret; - local->op_errno = op_errno; - } - } - UNLOCK(&frame->lock); - - if (call_count == 0) { - STRIPE_STACK_UNWIND(fsetxattr, frame, local->op_ret, local->op_errno, - NULL); - } - return 0; -} - -int -stripe_fsetxattr_to_everyone(call_frame_t *frame, xlator_t *this, fd_t *fd, - dict_t *dict, int flags, dict_t *xdata) -{ - xlator_list_t *trav = NULL; - stripe_private_t *priv = NULL; - int ret = -1; - stripe_local_t *local = NULL; - - priv = this->private; - - local = mem_get0(this->local_pool); - if (local == NULL) { - goto out; - } - - frame->local = local; - - local->wind_count = priv->child_count; - - trav = this->children; - - while (trav) { - STACK_WIND(frame, stripe_fsetxattr_everyone_cbk, trav->xlator, - trav->xlator->fops->fsetxattr, fd, dict, flags, xdata); - trav = trav->next; - } - - ret = 0; -out: - return ret; -} - -static gf_boolean_t -stripe_fsetxattr_is_special(dict_t *dict) -{ - gf_boolean_t is_spl = _gf_false; - - if (dict == NULL) { - goto out; - } - - dict_foreach(dict, stripe_is_special_key, &is_spl); - -out: - return is_spl; -} - -int -stripe_fsetxattr(call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *dict, - int flags, dict_t *xdata) -{ - int32_t op_ret = -1, ret = -1, op_errno = EINVAL; - gf_boolean_t is_spl = _gf_false; - - VALIDATE_OR_GOTO(frame, err); - VALIDATE_OR_GOTO(this, err); - VALIDATE_OR_GOTO(fd, err); - - GF_IF_INTERNAL_XATTR_GOTO("trusted.*stripe*", dict, op_errno, err); - - is_spl = stripe_fsetxattr_is_special(dict); - if (is_spl) { - ret = stripe_fsetxattr_to_everyone(frame, this, fd, dict, flags, xdata); - if (ret < 0) { - op_errno = ENOMEM; - goto err; - } - - goto out; - } - - STACK_WIND(frame, stripe_fsetxattr_cbk, FIRST_CHILD(this), - FIRST_CHILD(this)->fops->fsetxattr, fd, dict, flags, xdata); -out: - return 0; -err: - STRIPE_STACK_UNWIND(fsetxattr, frame, op_ret, op_errno, NULL); - return 0; -} - -int -stripe_removexattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, dict_t *xdata) -{ - STRIPE_STACK_UNWIND(removexattr, frame, op_ret, op_errno, xdata); - return 0; -} - -int -stripe_removexattr(call_frame_t *frame, xlator_t *this, loc_t *loc, - const char *name, dict_t *xdata) -{ - int32_t op_errno = EINVAL; - - VALIDATE_OR_GOTO(this, err); - - GF_IF_NATIVE_XATTR_GOTO("trusted.*stripe*", name, op_errno, err); - - VALIDATE_OR_GOTO(frame, err); - VALIDATE_OR_GOTO(loc, err); - - STACK_WIND(frame, stripe_removexattr_cbk, FIRST_CHILD(this), - FIRST_CHILD(this)->fops->removexattr, loc, name, xdata); - return 0; -err: - STRIPE_STACK_UNWIND(removexattr, frame, -1, op_errno, NULL); - return 0; -} - -int -stripe_fremovexattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, dict_t *xdata) -{ - STRIPE_STACK_UNWIND(fremovexattr, frame, op_ret, op_errno, xdata); - return 0; -} - -int -stripe_fremovexattr(call_frame_t *frame, xlator_t *this, fd_t *fd, - const char *name, dict_t *xdata) -{ - int32_t op_ret = -1; - int32_t op_errno = EINVAL; - - VALIDATE_OR_GOTO(frame, err); - VALIDATE_OR_GOTO(this, err); - VALIDATE_OR_GOTO(fd, err); - - GF_IF_NATIVE_XATTR_GOTO("trusted.*stripe*", name, op_errno, err); - - STACK_WIND(frame, stripe_fremovexattr_cbk, FIRST_CHILD(this), - FIRST_CHILD(this)->fops->fremovexattr, fd, name, xdata); - return 0; -err: - STRIPE_STACK_UNWIND(fremovexattr, frame, op_ret, op_errno, xdata); - return 0; -} - -int32_t -stripe_readdirp_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 *parent) -{ - stripe_local_t *local = NULL; - call_frame_t *main_frame = NULL; - stripe_local_t *main_local = NULL; - gf_dirent_t *entry = NULL; - call_frame_t *prev = NULL; - int done = 0; - - local = frame->local; - prev = cookie; - - entry = local->dirent; - - main_frame = local->orig_frame; - main_local = main_frame->local; - LOCK(&frame->lock); - { - local->call_count--; - if (!local->call_count) - done = 1; - if (op_ret == -1) { - local->op_errno = op_errno; - local->op_ret = op_ret; - goto unlock; - } - - if (stripe_ctx_handle(this, prev, local, xattr)) - gf_log(this->name, GF_LOG_ERROR, - "Error getting fctx info from dict."); - - correct_file_size(stbuf, local->fctx, prev); - - stripe_iatt_merge(stbuf, &entry->d_stat); - local->stbuf_blocks += stbuf->ia_blocks; - } -unlock: - UNLOCK(&frame->lock); - - if (done) { - inode_ctx_put(entry->inode, this, (uint64_t)(long)local->fctx); - - done = 0; - LOCK(&main_frame->lock); - { - main_local->wind_count--; - if (!main_local->wind_count) - done = 1; - if (local->op_ret == -1) { - main_local->op_errno = local->op_errno; - main_local->op_ret = local->op_ret; - } - entry->d_stat.ia_blocks = local->stbuf_blocks; - } - UNLOCK(&main_frame->lock); - if (done) { - main_frame->local = NULL; - STRIPE_STACK_UNWIND(readdir, main_frame, main_local->op_ret, - main_local->op_errno, &main_local->entries, - NULL); - gf_dirent_free(&main_local->entries); - stripe_local_wipe(main_local); - mem_put(main_local); - } - frame->local = NULL; - stripe_local_wipe(local); - mem_put(local); - STRIPE_STACK_DESTROY(frame); - } - - return 0; -} - -int32_t -stripe_readdirp_cbk(call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, gf_dirent_t *orig_entries, - dict_t *xdata) -{ - stripe_local_t *local = NULL; - call_frame_t *prev = NULL; - gf_dirent_t *local_entry = NULL; - gf_dirent_t *tmp_entry = NULL; - xlator_list_t *trav = NULL; - loc_t loc = { - 0, - }; - int32_t count = 0; - stripe_private_t *priv = NULL; - int32_t subvols = 0; - dict_t *xattrs = NULL; - call_frame_t *local_frame = NULL; - stripe_local_t *local_ent = NULL; - - if (!this || !frame->local || !cookie) { - gf_log("stripe", GF_LOG_DEBUG, "possible NULL deref"); - goto out; - } - prev = cookie; - local = frame->local; - trav = this->children; - priv = this->private; - - subvols = priv->child_count; - - LOCK(&frame->lock); - { - local->op_errno = op_errno; - local->op_ret = op_ret; - - if (op_ret != -1) { - list_splice_init(&orig_entries->list, &local->entries.list); - local->wind_count = op_ret; - } - } - UNLOCK(&frame->lock); - - if (op_ret == -1) { - gf_log(this->name, GF_LOG_WARNING, "%s returned error %s", - prev->this->name, strerror(op_errno)); - goto out; - } - - xattrs = dict_new(); - if (xattrs) - (void)stripe_xattr_request_build(this, xattrs, 0, 0, 0, 0); - count = op_ret; - list_for_each_entry_safe(local_entry, tmp_entry, (&local->entries.list), - list) - { - if (!local_entry) - break; - if (!IA_ISREG(local_entry->d_stat.ia_type) || !local_entry->inode) { - LOCK(&frame->lock); - { - local->wind_count--; - count = local->wind_count; - } - UNLOCK(&frame->lock); - continue; - } - - local_frame = copy_frame(frame); - - if (!local_frame) { - op_errno = ENOMEM; - op_ret = -1; - goto out; - } - - local_ent = mem_get0(this->local_pool); - if (!local_ent) { - op_errno = ENOMEM; - op_ret = -1; - goto out; - } - - loc.inode = inode_ref(local_entry->inode); - - gf_uuid_copy(loc.gfid, local_entry->d_stat.ia_gfid); - - local_ent->orig_frame = frame; - - local_ent->call_count = subvols; - - local_ent->dirent = local_entry; - - local_frame->local = local_ent; - - trav = this->children; - while (trav) { - STACK_WIND(local_frame, stripe_readdirp_lookup_cbk, trav->xlator, - trav->xlator->fops->lookup, &loc, xattrs); - trav = trav->next; - } - loc_wipe(&loc); - } -out: - if (!count) { - /* all entries are directories */ - frame->local = NULL; - STRIPE_STACK_UNWIND(readdir, frame, (local ? local->op_ret : -1), - (local ? local->op_errno : EINVAL), - (local ? &local->entries : NULL), NULL); - gf_dirent_free(&local->entries); - stripe_local_wipe(local); - mem_put(local); - } - if (xattrs) - dict_unref(xattrs); - return 0; -} -int32_t -stripe_readdirp(call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, - off_t off, dict_t *xdata) -{ - stripe_local_t *local = NULL; - stripe_private_t *priv = NULL; - xlator_list_t *trav = NULL; - int op_errno = -1; - - VALIDATE_OR_GOTO(frame, err); - VALIDATE_OR_GOTO(this, err); - VALIDATE_OR_GOTO(fd, err); - - priv = this->private; - trav = this->children; - - if (priv->first_child_down) { - op_errno = ENOTCONN; - goto err; - } - - /* Initialization */ - local = mem_get0(this->local_pool); - if (!local) { - op_errno = ENOMEM; - goto err; - } - - frame->local = local; - - local->fd = fd_ref(fd); - - local->wind_count = 0; - - local->count = 0; - local->op_ret = -1; - INIT_LIST_HEAD(&local->entries); - - if (!trav) - goto err; - - STACK_WIND(frame, stripe_readdirp_cbk, trav->xlator, - trav->xlator->fops->readdirp, fd, size, off, xdata); - return 0; -err: - op_errno = (op_errno == -1) ? errno : op_errno; - STRIPE_STACK_UNWIND(readdir, frame, -1, op_errno, NULL, NULL); - - return 0; -} - -int32_t -mem_acct_init(xlator_t *this) -{ - int ret = -1; - - if (!this) - goto out; - - ret = xlator_mem_acct_init(this, gf_stripe_mt_end + 1); - - if (ret != 0) { - gf_log(this->name, GF_LOG_ERROR, - "Memory accounting init" - "failed"); - goto out; - } - -out: - return ret; -} - -static int -clear_pattern_list(stripe_private_t *priv) -{ - struct stripe_options *prev = NULL; - struct stripe_options *trav = NULL; - int ret = -1; - - GF_VALIDATE_OR_GOTO("stripe", priv, out); - - trav = priv->pattern; - priv->pattern = NULL; - while (trav) { - prev = trav; - trav = trav->next; - GF_FREE(prev); - } - - ret = 0; -out: - return ret; -} - -int -reconfigure(xlator_t *this, dict_t *options) -{ - stripe_private_t *priv = NULL; - data_t *data = NULL; - int ret = -1; - volume_option_t *opt = NULL; - - GF_ASSERT(this); - GF_ASSERT(this->private); - - priv = this->private; - - ret = 0; - LOCK(&priv->lock); - { - ret = clear_pattern_list(priv); - if (ret) - goto unlock; - - data = dict_get(options, "block-size"); - if (data) { - ret = set_stripe_block_size(this, priv, data->data); - if (ret) - goto unlock; - } else { - opt = xlator_volume_option_get(this, "block-size"); - if (!opt) { - gf_log(this->name, GF_LOG_WARNING, - "option 'block-size' not found"); - ret = -1; - goto unlock; - } - - if (gf_string2bytesize_uint64(opt->default_value, - &priv->block_size)) { - gf_log(this->name, GF_LOG_ERROR, - "Unable to set default block-size "); - ret = -1; - goto unlock; - } - } - - GF_OPTION_RECONF("coalesce", priv->coalesce, options, bool, unlock); - } -unlock: - UNLOCK(&priv->lock); - if (ret) - goto out; - - ret = 0; -out: - return ret; -} - -/** - * init - This function is called when xlator-graph gets initialized. - * The option given in volfiles are parsed here. - * @this - - */ -int32_t -init(xlator_t *this) -{ - stripe_private_t *priv = NULL; - volume_option_t *opt = NULL; - xlator_list_t *trav = NULL; - data_t *data = NULL; - int32_t count = 0; - int ret = -1; - - if (!this) - goto out; - - trav = this->children; - while (trav) { - count++; - trav = trav->next; - } - - if (!count) { - gf_log(this->name, GF_LOG_ERROR, - "stripe configured without \"subvolumes\" option. " - "exiting"); - goto out; - } - - if (!this->parents) { - gf_log(this->name, GF_LOG_WARNING, "dangling volume. check volfile "); - } - - if (count == 1) { - gf_log(this->name, GF_LOG_ERROR, - "stripe configured with only one \"subvolumes\" option." - " please check the volume. exiting"); - goto out; - } - - priv = GF_CALLOC(1, sizeof(stripe_private_t), - gf_stripe_mt_stripe_private_t); - - if (!priv) - goto out; - priv->xl_array = GF_CALLOC(count, sizeof(xlator_t *), - gf_stripe_mt_xlator_t); - if (!priv->xl_array) - goto out; - - priv->last_event = GF_CALLOC(count, sizeof(int), gf_stripe_mt_int32_t); - if (!priv->last_event) - goto out; - - priv->child_count = count; - LOCK_INIT(&priv->lock); - - trav = this->children; - count = 0; - while (trav) { - priv->xl_array[count++] = trav->xlator; - trav = trav->next; - } - - if (count > 256) { - gf_log(this->name, GF_LOG_ERROR, - "maximum number of stripe subvolumes supported " - "is 256"); - goto out; - } - - ret = 0; - LOCK(&priv->lock); - { - opt = xlator_volume_option_get(this, "block-size"); - if (!opt) { - gf_log(this->name, GF_LOG_WARNING, "option 'block-size' not found"); - ret = -1; - goto unlock; - } - if (gf_string2bytesize_uint64(opt->default_value, &priv->block_size)) { - gf_log(this->name, GF_LOG_ERROR, - "Unable to set default block-size "); - ret = -1; - goto unlock; - } - /* option stripe-pattern *avi:1GB,*pdf:16K */ - data = dict_get(this->options, "block-size"); - if (data) { - ret = set_stripe_block_size(this, priv, data->data); - if (ret) - goto unlock; - } - } -unlock: - UNLOCK(&priv->lock); - if (ret) - goto out; - - GF_OPTION_INIT("use-xattr", priv->xattr_supported, bool, out); - /* notify related */ - priv->nodes_down = priv->child_count; - - GF_OPTION_INIT("coalesce", priv->coalesce, bool, out); - - this->local_pool = mem_pool_new(stripe_local_t, 128); - if (!this->local_pool) { - ret = -1; - gf_log(this->name, GF_LOG_ERROR, - "failed to create local_t's memory pool"); - goto out; - } - - this->private = priv; - - ret = 0; -out: - if (ret) { - if (priv) { - GF_FREE(priv->xl_array); - GF_FREE(priv); - } - } - return ret; -} - -/** - * fini - Free all the private variables - * @this - - */ -void -fini(xlator_t *this) -{ - stripe_private_t *priv = NULL; - struct stripe_options *prev = NULL; - struct stripe_options *trav = NULL; - - if (!this) - goto out; - - priv = this->private; - if (priv) { - this->private = NULL; - GF_FREE(priv->xl_array); - - trav = priv->pattern; - while (trav) { - prev = trav; - trav = trav->next; - GF_FREE(prev); - } - GF_FREE(priv->last_event); - LOCK_DESTROY(&priv->lock); - GF_FREE(priv); - } - -out: - return; -} - -int32_t -stripe_getxattr_unwind(call_frame_t *frame, int op_ret, int op_errno, - dict_t *dict, dict_t *xdata) - -{ - STRIPE_STACK_UNWIND(getxattr, frame, op_ret, op_errno, dict, xdata); - return 0; -} - -int -stripe_internal_getxattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this, - int op_ret, int op_errno, dict_t *xattr, - dict_t *xdata) -{ - char size_key[256] = { - 0, - }; - char index_key[256] = { - 0, - }; - char count_key[256] = { - 0, - }; - char coalesce_key[256] = { - 0, - }; - - VALIDATE_OR_GOTO(frame, out); - VALIDATE_OR_GOTO(frame->local, out); - - if (!xattr || (op_ret == -1)) - goto out; - - sprintf(size_key, "trusted.%s.stripe-size", this->name); - sprintf(count_key, "trusted.%s.stripe-count", this->name); - sprintf(index_key, "trusted.%s.stripe-index", this->name); - sprintf(coalesce_key, "trusted.%s.stripe-coalesce", this->name); - - dict_del(xattr, size_key); - dict_del(xattr, count_key); - dict_del(xattr, index_key); - dict_del(xattr, coalesce_key); - -out: - STRIPE_STACK_UNWIND(getxattr, frame, op_ret, op_errno, xattr, xdata); - - return 0; -} - -int -stripe_getxattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this, - int op_ret, int op_errno, dict_t *xattr, dict_t *xdata) -{ - int call_cnt = 0; - stripe_local_t *local = NULL; - - VALIDATE_OR_GOTO(frame, out); - VALIDATE_OR_GOTO(frame->local, out); - - local = frame->local; - - LOCK(&frame->lock); - { - call_cnt = --local->wind_count; - } - UNLOCK(&frame->lock); - - if (!xattr || (op_ret < 0)) - goto out; - - local->op_ret = 0; - - if (!local->xattr) { - local->xattr = dict_ref(xattr); - } else { - stripe_aggregate_xattr(local->xattr, xattr); - } - -out: - if (!call_cnt) { - STRIPE_STACK_UNWIND(getxattr, frame, (local ? local->op_ret : -1), - op_errno, (local ? local->xattr : NULL), xdata); - } - - return 0; -} - -int32_t -stripe_vgetxattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, dict_t *dict, - dict_t *xdata) -{ - stripe_local_t *local = NULL; - int32_t callcnt = 0; - int32_t ret = -1; - long cky = 0; - void *xattr_val = NULL; - void *xattr_serz = NULL; - stripe_xattr_sort_t *xattr = NULL; - dict_t *stripe_xattr = NULL; - - if (!frame || !frame->local || !this) { - gf_log("", GF_LOG_ERROR, "Possible NULL deref"); - return ret; - } - - local = frame->local; - cky = (long)cookie; - - if (local->xsel[0] == '\0') { - gf_log(this->name, GF_LOG_ERROR, "Empty xattr in cbk"); - return ret; - } - - LOCK(&frame->lock); - { - callcnt = --local->wind_count; - - if (!dict || (op_ret < 0)) - goto out; - - if (!local->xattr_list) - local->xattr_list = (stripe_xattr_sort_t *)GF_CALLOC( - local->nallocs, sizeof(stripe_xattr_sort_t), - gf_stripe_mt_xattr_sort_t); - - if (local->xattr_list) { - xattr = local->xattr_list + (int32_t)cky; - - ret = dict_get_ptr_and_len(dict, local->xsel, &xattr_val, - &xattr->xattr_len); - if (xattr->xattr_len == 0) - goto out; - - xattr->pos = cky; - xattr->xattr_value = gf_memdup(xattr_val, xattr->xattr_len); - - if (xattr->xattr_value != NULL) - local->xattr_total_len += xattr->xattr_len + 1; - } - } -out: - UNLOCK(&frame->lock); - - if (!callcnt) { - if (!local->xattr_total_len) - goto unwind; - - stripe_xattr = dict_new(); - if (!stripe_xattr) - goto unwind; - - /* select filler based on ->xsel */ - if (XATTR_IS_PATHINFO(local->xsel)) - ret = stripe_fill_pathinfo_xattr(this, local, (char **)&xattr_serz); - else if (XATTR_IS_LOCKINFO(local->xsel)) { - ret = stripe_fill_lockinfo_xattr(this, local, &xattr_serz); - } else { - gf_log(this->name, GF_LOG_WARNING, - "Unknown xattr in xattr request"); - goto unwind; - } - - if (!ret) { - ret = dict_set_dynptr(stripe_xattr, local->xsel, xattr_serz, - local->xattr_total_len); - if (ret) - gf_log(this->name, GF_LOG_ERROR, "Can't set %s key in dict", - local->xsel); - } - - unwind: - /* - * Among other things, STRIPE_STACK_UNWIND will free "local" - * for us. That means we can't dereference it afterward. - * Fortunately, the actual result is in stripe_xattr now, so we - * can simply clean up before unwinding. - */ - ret = stripe_free_xattr_str(local); - GF_FREE(local->xattr_list); - local->xattr_list = NULL; - - STRIPE_STACK_UNWIND(getxattr, frame, op_ret, op_errno, stripe_xattr, - NULL); - - if (stripe_xattr) - dict_unref(stripe_xattr); - } - - return ret; -} - -int -stripe_marker_populate_args(call_frame_t *frame, int type, int *gauge, - xlator_t **subvols) -{ - xlator_t *this = frame->this; - stripe_private_t *priv = this->private; - stripe_local_t *local = frame->local; - int count = 0; - - count = priv->child_count; - if (MARKER_XTIME_TYPE == type) { - if (!IA_FILE_OR_DIR(local->loc.inode->ia_type)) - count = 1; - } - memcpy(subvols, priv->xl_array, sizeof(*subvols) * count); - - return count; -} - -int32_t -stripe_getxattr(call_frame_t *frame, xlator_t *this, loc_t *loc, - const char *name, dict_t *xdata) -{ - stripe_local_t *local = NULL; - xlator_list_t *trav = NULL; - stripe_private_t *priv = NULL; - int32_t op_errno = EINVAL; - int i = 0; - int ret = 0; - - VALIDATE_OR_GOTO(frame, err); - VALIDATE_OR_GOTO(this, err); - VALIDATE_OR_GOTO(loc, err); - VALIDATE_OR_GOTO(loc->path, err); - VALIDATE_OR_GOTO(loc->inode, err); - - priv = this->private; - trav = this->children; - - /* Initialization */ - local = mem_get0(this->local_pool); - if (!local) { - op_errno = ENOMEM; - goto err; - } - local->op_ret = -1; - frame->local = local; - loc_copy(&local->loc, loc); - - if (name && strncmp(name, QUOTA_SIZE_KEY, SLEN(QUOTA_SIZE_KEY)) == 0) { - local->wind_count = priv->child_count; - - for (i = 0, trav = this->children; i < priv->child_count; - i++, trav = trav->next) { - STACK_WIND(frame, stripe_getxattr_cbk, trav->xlator, - trav->xlator->fops->getxattr, loc, name, xdata); - } - - return 0; - } - - if (name && (XATTR_IS_PATHINFO(name))) { - if (IA_ISREG(loc->inode->ia_type)) { - ret = inode_ctx_get(loc->inode, this, (uint64_t *)&local->fctx); - if (ret) - gf_log(this->name, GF_LOG_ERROR, - "stripe size unavailable from fctx" - " relying on pathinfo could lead to" - " wrong results"); - } - - local->nallocs = local->wind_count = priv->child_count; - (void)strncpy(local->xsel, name, strlen(name)); - - /** - * for xattrs that need info from all children, fill ->xsel - * as above and call the filler function in cbk based on - * it - */ - for (i = 0, trav = this->children; i < priv->child_count; - i++, trav = trav->next) { - STACK_WIND_COOKIE(frame, stripe_vgetxattr_cbk, (void *)(long)i, - trav->xlator, trav->xlator->fops->getxattr, loc, - name, xdata); - } - - return 0; - } - - if (cluster_handle_marker_getxattr(frame, loc, name, priv->vol_uuid, - stripe_getxattr_unwind, - stripe_marker_populate_args) == 0) - return 0; - - STACK_WIND(frame, stripe_internal_getxattr_cbk, FIRST_CHILD(this), - FIRST_CHILD(this)->fops->getxattr, loc, name, xdata); - - return 0; - -err: - STRIPE_STACK_UNWIND(getxattr, frame, -1, op_errno, NULL, NULL); - return 0; -} - -static gf_boolean_t -stripe_is_special_xattr(const char *name) -{ - gf_boolean_t is_spl = _gf_false; - - if (!name) { - goto out; - } - - if (!strncmp(name, GF_XATTR_LOCKINFO_KEY, SLEN(GF_XATTR_LOCKINFO_KEY)) || - XATTR_IS_PATHINFO(name)) - is_spl = _gf_true; -out: - return is_spl; -} - -int32_t -stripe_fgetxattr_from_everyone(call_frame_t *frame, xlator_t *this, fd_t *fd, - const char *name, dict_t *xdata) -{ - stripe_local_t *local = NULL; - stripe_private_t *priv = NULL; - int32_t ret = -1, op_errno = 0; - int i = 0; - xlator_list_t *trav = NULL; - - priv = this->private; - - local = mem_get0(this->local_pool); - if (!local) { - op_errno = ENOMEM; - goto err; - } - - local->op_ret = -1; - frame->local = local; - - strncpy(local->xsel, name, strlen(name)); - local->nallocs = local->wind_count = priv->child_count; - - for (i = 0, trav = this->children; i < priv->child_count; - i++, trav = trav->next) { - STACK_WIND_COOKIE(frame, stripe_vgetxattr_cbk, (void *)(long)i, - trav->xlator, trav->xlator->fops->fgetxattr, fd, name, - xdata); - } - - return 0; - -err: - STACK_UNWIND_STRICT(fgetxattr, frame, -1, op_errno, NULL, NULL); - return ret; -} - -int32_t -stripe_fgetxattr(call_frame_t *frame, xlator_t *this, fd_t *fd, - const char *name, dict_t *xdata) -{ - if (stripe_is_special_xattr(name)) { - stripe_fgetxattr_from_everyone(frame, this, fd, name, xdata); - goto out; - } - - STACK_WIND(frame, stripe_internal_getxattr_cbk, FIRST_CHILD(this), - FIRST_CHILD(this)->fops->fgetxattr, fd, name, xdata); - -out: - return 0; -} - -int32_t -stripe_priv_dump(xlator_t *this) -{ - char key[GF_DUMP_MAX_BUF_LEN]; - int i = 0; - stripe_private_t *priv = NULL; - int ret = -1; - struct stripe_options *options = NULL; - - GF_VALIDATE_OR_GOTO("stripe", this, out); - - priv = this->private; - if (!priv) - goto out; - - ret = TRY_LOCK(&priv->lock); - if (ret != 0) - goto out; - - gf_proc_dump_add_section("xlator.cluster.stripe.%s.priv", this->name); - gf_proc_dump_write("child_count", "%d", priv->child_count); - - for (i = 0; i < priv->child_count; i++) { - sprintf(key, "subvolumes[%d]", i); - gf_proc_dump_write(key, "%s.%s", priv->xl_array[i]->type, - priv->xl_array[i]->name); - } - - options = priv->pattern; - while (options != NULL) { - gf_proc_dump_write("path_pattern", "%s", priv->pattern->path_pattern); - gf_proc_dump_write("options_block_size", "%ul", options->block_size); - - options = options->next; - } - - gf_proc_dump_write("block_size", "%ul", priv->block_size); - gf_proc_dump_write("nodes-down", "%d", priv->nodes_down); - gf_proc_dump_write("first-child_down", "%d", priv->first_child_down); - gf_proc_dump_write("xattr_supported", "%d", priv->xattr_supported); - - UNLOCK(&priv->lock); - -out: - return ret; -} - -struct xlator_fops fops = { - .stat = stripe_stat, - .unlink = stripe_unlink, - .rename = stripe_rename, - .link = stripe_link, - .truncate = stripe_truncate, - .create = stripe_create, - .open = stripe_open, - .readv = stripe_readv, - .writev = stripe_writev, - .statfs = stripe_statfs, - .flush = stripe_flush, - .fsync = stripe_fsync, - .ftruncate = stripe_ftruncate, - .fstat = stripe_fstat, - .mkdir = stripe_mkdir, - .rmdir = stripe_rmdir, - .lk = stripe_lk, - .opendir = stripe_opendir, - .fsyncdir = stripe_fsyncdir, - .setattr = stripe_setattr, - .fsetattr = stripe_fsetattr, - .lookup = stripe_lookup, - .mknod = stripe_mknod, - .setxattr = stripe_setxattr, - .fsetxattr = stripe_fsetxattr, - .getxattr = stripe_getxattr, - .fgetxattr = stripe_fgetxattr, - .removexattr = stripe_removexattr, - .fremovexattr = stripe_fremovexattr, - .readdirp = stripe_readdirp, - .fallocate = stripe_fallocate, - .discard = stripe_discard, - .zerofill = stripe_zerofill, - .seek = stripe_seek, -}; - -struct xlator_cbks cbks = { - .release = stripe_release, - .forget = stripe_forget, -}; - -struct xlator_dumpops dumpops = { - .priv = stripe_priv_dump, -}; - -struct volume_options options[] = { - { - .key = {"block-size"}, - .type = GF_OPTION_TYPE_SIZE_LIST, - .default_value = "128KB", - .min = STRIPE_MIN_BLOCK_SIZE, - .description = "Size of the stripe unit that would be read " - "from or written to the striped servers.", - .op_version = {1}, - .tags = {"stripe"}, - .flags = OPT_FLAG_CLIENT_OPT | OPT_FLAG_SETTABLE, - }, - { - .key = {"use-xattr"}, - .type = GF_OPTION_TYPE_BOOL, - .default_value = "true", - .description = "handle the stripe without the xattr", - .tags = {"stripe", "dev-only"}, - .flags = OPT_FLAG_CLIENT_OPT, - }, - { - .key = {"coalesce"}, - .type = GF_OPTION_TYPE_BOOL, - .default_value = "true", - .description = "Enable/Disable coalesce mode to flatten striped " - "files as stored on the server (i.e., eliminate holes " - "caused by the traditional format).", - .op_version = {1}, - .flags = OPT_FLAG_CLIENT_OPT | OPT_FLAG_SETTABLE, - .tags = {"stripe"}, - }, - {.key = {NULL}}, -}; diff --git a/xlators/cluster/stripe/src/stripe.h b/xlators/cluster/stripe/src/stripe.h deleted file mode 100644 index 88c24b682b8..00000000000 --- a/xlators/cluster/stripe/src/stripe.h +++ /dev/null @@ -1,291 +0,0 @@ -/* - Copyright (c) 2008-2012 Red Hat, Inc. - This file is part of GlusterFS. - - 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 _STRIPE_H_ -#define _STRIPE_H_ - -#include -#include -#include -#include -#include -#include -#include "stripe-mem-types.h" -#include "libxlator.h" -#include -#include - -#define STRIPE_PATHINFO_HEADER "STRIPE:" -#define STRIPE_MIN_BLOCK_SIZE (16 * GF_UNIT_KB) - -#define STRIPE_STACK_UNWIND(fop, frame, params...) \ - do { \ - stripe_local_t *__local = NULL; \ - if (frame) { \ - __local = frame->local; \ - frame->local = NULL; \ - } \ - STACK_UNWIND_STRICT(fop, frame, params); \ - if (__local) { \ - stripe_local_wipe(__local); \ - mem_put(__local); \ - } \ - } while (0) - -#define STRIPE_STACK_DESTROY(frame) \ - do { \ - stripe_local_t *__local = NULL; \ - __local = frame->local; \ - frame->local = NULL; \ - STACK_DESTROY(frame->root); \ - if (__local) { \ - stripe_local_wipe(__local); \ - mem_put(__local); \ - } \ - } while (0) - -#define STRIPE_VALIDATE_FCTX(fctx, label) \ - do { \ - int idx = 0; \ - if (!fctx) { \ - op_errno = EINVAL; \ - goto label; \ - } \ - for (idx = 0; idx < fctx->stripe_count; idx++) { \ - if (!fctx->xl_array[idx]) { \ - gf_log(this->name, GF_LOG_ERROR, "fctx->xl_array[%d] is NULL", \ - idx); \ - op_errno = ESTALE; \ - goto label; \ - } \ - } \ - } while (0) - -typedef struct stripe_xattr_sort { - int pos; - int xattr_len; - char *xattr_value; -} stripe_xattr_sort_t; - -/** - * struct stripe_options : This keeps the pattern and the block-size - * information, which is used for striping on a file. - */ -struct stripe_options { - struct stripe_options *next; - char path_pattern[256]; - uint64_t block_size; -}; - -/** - * Private structure for stripe translator - */ -struct stripe_private { - struct stripe_options *pattern; - xlator_t **xl_array; - uint64_t block_size; - gf_lock_t lock; - uint8_t nodes_down; - int8_t first_child_down; - int *last_event; - int8_t child_count; - gf_boolean_t xattr_supported; /* default yes */ - gf_boolean_t coalesce; - char vol_uuid[UUID_SIZE + 1]; -}; - -/** - * Used to keep info about the replies received from readv/writev calls - */ -struct stripe_replies { - struct iovec *vector; - int32_t count; // count of vector - int32_t op_ret; // op_ret of readv - int32_t op_errno; - int32_t requested_size; - struct iatt stbuf; /* 'stbuf' is also a part of reply */ -}; - -typedef struct _stripe_fd_ctx { - off_t stripe_size; - int stripe_count; - int stripe_coalesce; - int static_array; - xlator_t **xl_array; -} stripe_fd_ctx_t; - -/** - * Local structure to be passed with all the frames in case of STACK_WIND - */ -struct stripe_local; /* this itself is used inside the structure; */ - -struct stripe_local { - struct stripe_local *next; - call_frame_t *orig_frame; - - stripe_fd_ctx_t *fctx; - - /* Used by _cbk functions */ - struct iatt stbuf; - struct iatt pre_buf; - struct iatt post_buf; - struct iatt preparent; - struct iatt postparent; - - off_t stbuf_size; - off_t prebuf_size; - off_t postbuf_size; - off_t preparent_size; - off_t postparent_size; - - blkcnt_t stbuf_blocks; - blkcnt_t prebuf_blocks; - blkcnt_t postbuf_blocks; - blkcnt_t preparent_blocks; - blkcnt_t postparent_blocks; - - struct stripe_replies *replies; - struct statvfs statvfs_buf; - dir_entry_t *entry; - - int8_t revalidate; - int8_t failed; - int8_t unwind; - - size_t readv_size; - int32_t entry_count; - int32_t node_index; - int32_t call_count; - int32_t wind_count; /* used instead of child_cound - in case of read and write */ - int32_t op_ret; - int32_t op_errno; - int32_t count; - int32_t flags; - char *name; - inode_t *inode; - - loc_t loc; - loc_t loc2; - - mode_t mode; - dev_t rdev; - /* For File I/O fops */ - dict_t *xdata; - - stripe_xattr_sort_t *xattr_list; - int32_t xattr_total_len; - int32_t nallocs; - char xsel[256]; - - /* General usage */ - off_t offset; - off_t stripe_size; - - int xattr_self_heal_needed; - int entry_self_heal_needed; - - int8_t *list; - struct gf_flock lock; - fd_t *fd; - void *value; - struct iobref *iobref; - gf_dirent_t entries; - gf_dirent_t *dirent; - dict_t *xattr; - uuid_t ia_gfid; - - int xflag; - mode_t umask; -}; - -typedef struct stripe_local stripe_local_t; -typedef struct stripe_private stripe_private_t; - -/* - * Determine the stripe index of a particular frame based on the translator. - */ -static inline int32_t -stripe_get_frame_index(stripe_fd_ctx_t *fctx, call_frame_t *prev) -{ - int32_t i, idx = -1; - - for (i = 0; i < fctx->stripe_count; i++) { - if (fctx->xl_array[i] == prev->this) { - idx = i; - break; - } - } - - return idx; -} - -static inline void -stripe_copy_xl_array(xlator_t **dst, xlator_t **src, int count) -{ - int i; - - for (i = 0; i < count; i++) - dst[i] = src[i]; -} - -void -stripe_local_wipe(stripe_local_t *local); -int32_t -stripe_ctx_handle(xlator_t *this, call_frame_t *prev, stripe_local_t *local, - dict_t *dict); -void -stripe_aggregate_xattr(dict_t *dst, dict_t *src); -int32_t -stripe_xattr_request_build(xlator_t *this, dict_t *dict, uint64_t stripe_size, - uint32_t stripe_count, uint32_t stripe_index, - uint32_t stripe_coalesce); -int32_t -stripe_get_matching_bs(const char *path, stripe_private_t *priv); -int -set_stripe_block_size(xlator_t *this, stripe_private_t *priv, char *data); -int32_t -stripe_iatt_merge(struct iatt *from, struct iatt *to); -int32_t -stripe_fill_pathinfo_xattr(xlator_t *this, stripe_local_t *local, - char **xattr_serz); -int32_t -stripe_free_xattr_str(stripe_local_t *local); -int32_t -stripe_xattr_aggregate(char *buffer, stripe_local_t *local, int32_t *total); -off_t -coalesced_offset(off_t offset, uint64_t stripe_size, int stripe_count); -off_t -uncoalesced_size(off_t size, uint64_t stripe_size, int stripe_count, - int stripe_index); -int32_t -stripe_fill_lockinfo_xattr(xlator_t *this, stripe_local_t *local, - void **xattr_serz); - -/* - * Adjust the size attribute for files if coalesce is enabled. - */ -static inline void -correct_file_size(struct iatt *buf, stripe_fd_ctx_t *fctx, call_frame_t *prev) -{ - int index; - - if (!IA_ISREG(buf->ia_type)) - return; - - if (!fctx || !fctx->stripe_coalesce) - return; - - index = stripe_get_frame_index(fctx, prev); - buf->ia_size = uncoalesced_size(buf->ia_size, fctx->stripe_size, - fctx->stripe_count, index); -} - -#endif /* _STRIPE_H_ */ -- cgit