diff options
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-utils.c')
| -rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-utils.c | 3387 |
1 files changed, 2032 insertions, 1355 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c index 2deda2945c0..90ef2cf4c9c 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.c +++ b/xlators/mgmt/glusterd/src/glusterd-utils.c @@ -20,20 +20,20 @@ #include <libxml/xmlwriter.h> #endif -#include "glusterfs.h" -#include "compat.h" -#include "dict.h" -#include "xlator.h" -#include "logging.h" +#include <glusterfs/glusterfs.h> +#include <glusterfs/compat.h> +#include <glusterfs/dict.h> +#include <glusterfs/xlator.h> +#include <glusterfs/logging.h> #include "glusterd-messages.h" -#include "timer.h" -#include "defaults.h" -#include "compat.h" -#include "syncop.h" -#include "run.h" -#include "compat-errno.h" -#include "statedump.h" -#include "syscall.h" +#include <glusterfs/timer.h> +#include <glusterfs/defaults.h> +#include <glusterfs/compat.h> +#include <glusterfs/syncop.h> +#include <glusterfs/run.h> +#include <glusterfs/compat-errno.h> +#include <glusterfs/statedump.h> +#include <glusterfs/syscall.h> #include "glusterd-mem-types.h" #include "glusterd.h" #include "glusterd-op-sm.h" @@ -43,7 +43,7 @@ #include "glusterd-store.h" #include "glusterd-volgen.h" #include "glusterd-pmap.h" -#include "glusterfs-acl.h" +#include <glusterfs/glusterfs-acl.h> #include "glusterd-syncop.h" #include "glusterd-mgmt.h" #include "glusterd-locks.h" @@ -53,14 +53,14 @@ #include "glusterd-svc-mgmt.h" #include "glusterd-svc-helper.h" #include "glusterd-shd-svc.h" -#include "glusterd-nfs-svc.h" #include "glusterd-quotad-svc.h" #include "glusterd-snapd-svc.h" #include "glusterd-bitd-svc.h" #include "glusterd-gfproxyd-svc.h" #include "glusterd-server-quorum.h" -#include "quota-common-utils.h" -#include "common-utils.h" +#include <glusterfs/quota-common-utils.h> +#include <glusterfs/common-utils.h> +#include "glusterd-shd-svc-helper.h" #include "xdr-generic.h" #include <sys/resource.h> @@ -74,14 +74,19 @@ #include <fnmatch.h> #include <sys/statvfs.h> #include <ifaddrs.h> -#ifdef HAVE_BD_XLATOR -#include <lvm2app.h> -#endif #ifdef GF_SOLARIS_HOST_OS #include <sys/sockio.h> #endif +#ifdef __FreeBSD__ +#include <sys/sysctl.h> +#include <sys/param.h> +#include <sys/queue.h> +#include <libprocstat.h> +#include <libutil.h> +#endif + #define NFS_PROGRAM 100003 #define NFSV3_VERSION 3 @@ -93,6 +98,28 @@ #define NLMV4_VERSION 4 #define NLMV1_VERSION 1 +#ifdef BUILD_GNFS +#define GLUSTERD_GET_NFS_PIDFILE(pidfile, priv) \ + do { \ + int32_t _nfs_pid_len; \ + _nfs_pid_len = snprintf(pidfile, PATH_MAX, "%s/nfs/nfs.pid", \ + priv->rundir); \ + if ((_nfs_pid_len < 0) || (_nfs_pid_len >= PATH_MAX)) { \ + pidfile[0] = 0; \ + } \ + } while (0) +#endif + +#define GLUSTERD_GET_QUOTAD_PIDFILE(pidfile, priv) \ + do { \ + int32_t _quotad_pid_len; \ + _quotad_pid_len = snprintf(pidfile, PATH_MAX, "%s/quotad/quotad.pid", \ + priv->rundir); \ + if ((_quotad_pid_len < 0) || (_quotad_pid_len >= PATH_MAX)) { \ + pidfile[0] = 0; \ + } \ + } while (0) + gf_boolean_t is_brick_mx_enabled(void) { @@ -139,15 +166,8 @@ get_mux_limit_per_process(int *mux_limit) ret = dict_get_strn(priv->opts, GLUSTERD_BRICKMUX_LIMIT_KEY, SLEN(GLUSTERD_BRICKMUX_LIMIT_KEY), &value); if (ret) { - gf_msg_debug(this->name, 0, - "Limit for number of bricks per " - "brick process not yet set in dict. Returning " - "limit as 0 denoting that multiplexing can " - "happen with no limit set."); - ret = 0; - goto out; + value = GLUSTERD_BRICKMUX_LIMIT_DFLT_VALUE; } - ret = gf_string2int(value, &max_bricks_per_proc); if (ret) goto out; @@ -161,6 +181,47 @@ out: return ret; } +int +get_gd_vol_thread_limit(int *thread_limit) +{ + char *value = NULL; + int ret = -1; + int vol_per_thread_limit = 0; + xlator_t *this = NULL; + glusterd_conf_t *priv = NULL; + + this = THIS; + GF_VALIDATE_OR_GOTO("glusterd", this, out); + + priv = this->private; + GF_VALIDATE_OR_GOTO(this->name, priv, out); + + if (!is_brick_mx_enabled()) { + vol_per_thread_limit = 1; + ret = 0; + goto out; + } + + ret = dict_get_strn(priv->opts, GLUSTERD_VOL_CNT_PER_THRD, + SLEN(GLUSTERD_VOL_CNT_PER_THRD), &value); + if (ret) { + value = GLUSTERD_VOL_CNT_PER_THRD_DEFAULT_VALUE; + } + ret = gf_string2int(value, &vol_per_thread_limit); + if (ret) + goto out; + +out: + *thread_limit = vol_per_thread_limit; + + gf_msg_debug("glusterd", 0, + "Per Thread volume limit set to %d glusterd to populate dict " + "data parallel", + *thread_limit); + + return ret; +} + extern struct volopt_map_entry glusterd_volopt_map[]; extern glusterd_all_vol_opts valid_all_vol_opts[]; @@ -219,53 +280,9 @@ glusterd_volume_brick_for_each(glusterd_volinfo_t *volinfo, void *data, glusterd_brickinfo_t *, dict_t *mod_dict, void *)) { - dict_t *mod_dict = NULL; - glusterd_volinfo_t *dup_volinfo = NULL; - int ret = 0; - gd_set_shared_brick_count(volinfo); - if (volinfo->type != GF_CLUSTER_TYPE_TIER) { - ret = _brick_for_each(volinfo, NULL, data, fn); - if (ret) - goto out; - } else { - ret = glusterd_create_sub_tier_volinfo(volinfo, &dup_volinfo, _gf_true, - volinfo->volname); - if (ret) - goto out; - - mod_dict = dict_new(); - if (!mod_dict) { - ret = -1; - goto out; - } - - ret = dict_set_nstrn(mod_dict, "hot-brick", SLEN("hot-brick"), "on", - SLEN("on")); - if (ret) - goto out; - - ret = _brick_for_each(dup_volinfo, mod_dict, data, fn); - if (ret) - goto out; - GF_FREE(dup_volinfo); - dup_volinfo = NULL; - ret = glusterd_create_sub_tier_volinfo(volinfo, &dup_volinfo, _gf_false, - volinfo->volname); - if (ret) - goto out; - ret = _brick_for_each(dup_volinfo, NULL, data, fn); - if (ret) - goto out; - } -out: - if (dup_volinfo) - glusterd_volinfo_delete(dup_volinfo); - - if (mod_dict) - dict_unref(mod_dict); - return ret; + return _brick_for_each(volinfo, NULL, data, fn); } int32_t @@ -434,6 +451,8 @@ glusterd_submit_request(struct rpc_clnt *rpc, void *req, call_frame_t *frame, if (!iobref) { iobref = iobref_new(); if (!iobref) { + gf_smsg("glusterd", GF_LOG_ERROR, ENOMEM, GD_MSG_NO_MEMORY, + NULL); goto out; } @@ -578,25 +597,21 @@ out: return ret; } -gf_boolean_t -glusterd_check_volume_exists(char *volname) -{ - glusterd_volinfo_t *volinfo = NULL; - - return (glusterd_volinfo_find(volname, &volinfo) == 0); -} - glusterd_volinfo_t * glusterd_volinfo_unref(glusterd_volinfo_t *volinfo) { int refcnt = -1; + glusterd_conf_t *conf = THIS->private; - pthread_mutex_lock(&volinfo->reflock); + pthread_mutex_lock(&conf->volume_lock); { - refcnt = --volinfo->refcnt; + pthread_mutex_lock(&volinfo->reflock); + { + refcnt = --volinfo->refcnt; + } + pthread_mutex_unlock(&volinfo->reflock); } - pthread_mutex_unlock(&volinfo->reflock); - + pthread_mutex_unlock(&conf->volume_lock); if (!refcnt) { glusterd_volinfo_delete(volinfo); return NULL; @@ -635,10 +650,12 @@ glusterd_volinfo_new(glusterd_volinfo_t **volinfo) CDS_INIT_LIST_HEAD(&new_volinfo->vol_list); CDS_INIT_LIST_HEAD(&new_volinfo->snapvol_list); CDS_INIT_LIST_HEAD(&new_volinfo->bricks); + CDS_INIT_LIST_HEAD(&new_volinfo->ta_bricks); CDS_INIT_LIST_HEAD(&new_volinfo->snap_volumes); new_volinfo->dict = dict_new(); if (!new_volinfo->dict) { + gf_smsg("glusterd", GF_LOG_ERROR, errno, GD_MSG_DICT_CREATE_FAIL, NULL); GF_FREE(new_volinfo); goto out; @@ -646,6 +663,7 @@ glusterd_volinfo_new(glusterd_volinfo_t **volinfo) new_volinfo->gsync_slaves = dict_new(); if (!new_volinfo->gsync_slaves) { + gf_smsg("glusterd", GF_LOG_ERROR, errno, GD_MSG_DICT_CREATE_FAIL, NULL); dict_unref(new_volinfo->dict); GF_FREE(new_volinfo); goto out; @@ -653,6 +671,7 @@ glusterd_volinfo_new(glusterd_volinfo_t **volinfo) new_volinfo->gsync_active_slaves = dict_new(); if (!new_volinfo->gsync_active_slaves) { + gf_smsg("glusterd", GF_LOG_ERROR, errno, GD_MSG_DICT_CREATE_FAIL, NULL); dict_unref(new_volinfo->dict); dict_unref(new_volinfo->gsync_slaves); GF_FREE(new_volinfo); @@ -666,10 +685,12 @@ glusterd_volinfo_new(glusterd_volinfo_t **volinfo) new_volinfo->xl = THIS; glusterd_snapdsvc_build(&new_volinfo->snapd.svc); - glusterd_tierdsvc_build(&new_volinfo->tierd.svc); glusterd_gfproxydsvc_build(&new_volinfo->gfproxyd.svc); + glusterd_shdsvc_build(&new_volinfo->shd.svc); + pthread_mutex_init(&new_volinfo->store_volinfo_lock, NULL); pthread_mutex_init(&new_volinfo->reflock, NULL); + *volinfo = glusterd_volinfo_ref(new_volinfo); ret = 0; @@ -722,7 +743,6 @@ glusterd_volinfo_dup(glusterd_volinfo_t *volinfo, new_volinfo->subvol_count = volinfo->subvol_count; new_volinfo->transport_type = volinfo->transport_type; new_volinfo->brick_count = volinfo->brick_count; - new_volinfo->tier_info = volinfo->tier_info; new_volinfo->quota_conf_version = volinfo->quota_conf_version; new_volinfo->quota_xattr_version = volinfo->quota_xattr_version; new_volinfo->snap_max_hard_limit = volinfo->snap_max_hard_limit; @@ -798,89 +818,6 @@ glusterd_brickinfo_dup(glusterd_brickinfo_t *brickinfo, out: return ret; } -int32_t -glusterd_create_sub_tier_volinfo(glusterd_volinfo_t *volinfo, - glusterd_volinfo_t **dup_volinfo, - gf_boolean_t is_hot_tier, - const char *new_volname) -{ - glusterd_brickinfo_t *brickinfo = NULL; - glusterd_brickinfo_t *brickinfo_dup = NULL; - gd_tier_info_t *tier_info = NULL; - int i = 0; - int ret = -1; - - tier_info = &(volinfo->tier_info); - - ret = glusterd_volinfo_dup(volinfo, dup_volinfo, _gf_true); - if (ret) { - gf_msg("glusterd", GF_LOG_ERROR, 0, GD_MSG_VOL_OP_FAILED, - "Failed to create volinfo"); - return ret; - } - - gf_uuid_copy((*dup_volinfo)->volume_id, volinfo->volume_id); - (*dup_volinfo)->is_snap_volume = volinfo->is_snap_volume; - (*dup_volinfo)->status = volinfo->status; - (*dup_volinfo)->snapshot = volinfo->snapshot; - - if (snprintf((*dup_volinfo)->volname, sizeof((*dup_volinfo)->volname), "%s", - new_volname) >= sizeof((*dup_volinfo)->volname)) { - ret = -1; - goto out; - } - - memcpy(&(*dup_volinfo)->tier_info, &volinfo->tier_info, - sizeof(volinfo->tier_info)); - - cds_list_for_each_entry(brickinfo, &volinfo->bricks, brick_list) - { - i++; - - if (is_hot_tier) { - if (i > volinfo->tier_info.hot_brick_count) - break; - } else { - if (i <= volinfo->tier_info.hot_brick_count) - continue; - } - - ret = glusterd_brickinfo_new(&brickinfo_dup); - if (ret) { - gf_msg("glusterd", GF_LOG_ERROR, 0, GD_MSG_BRICK_NEW_INFO_FAIL, - "Failed to create " - "new brickinfo"); - goto out; - } - - glusterd_brickinfo_dup(brickinfo, brickinfo_dup); - cds_list_add_tail(&brickinfo_dup->brick_list, - &((*dup_volinfo)->bricks)); - } - - if (is_hot_tier) { - (*dup_volinfo)->type = tier_info->hot_type; - (*dup_volinfo)->replica_count = tier_info->hot_replica_count; - (*dup_volinfo)->brick_count = tier_info->hot_brick_count; - (*dup_volinfo)->dist_leaf_count = glusterd_get_dist_leaf_count( - *dup_volinfo); - - } else { - (*dup_volinfo)->type = tier_info->cold_type; - (*dup_volinfo)->replica_count = tier_info->cold_replica_count; - (*dup_volinfo)->disperse_count = tier_info->cold_disperse_count; - (*dup_volinfo)->redundancy_count = tier_info->cold_redundancy_count; - (*dup_volinfo)->dist_leaf_count = tier_info->cold_dist_leaf_count; - (*dup_volinfo)->brick_count = tier_info->cold_brick_count; - } -out: - if (ret && *dup_volinfo) { - glusterd_volinfo_delete(*dup_volinfo); - *dup_volinfo = NULL; - } - - return ret; -} /* * gd_vol_is_geo_rep_active: @@ -1024,7 +961,6 @@ glusterd_volinfo_delete(glusterd_volinfo_t *volinfo) /* Destroy the connection object for per volume svc daemons */ glusterd_conn_term(&volinfo->snapd.svc.conn); - glusterd_conn_term(&volinfo->tierd.svc.conn); glusterd_conn_term(&volinfo->gfproxyd.svc.conn); gf_store_handle_destroy(volinfo->quota_conf_shandle); @@ -1033,11 +969,14 @@ glusterd_volinfo_delete(glusterd_volinfo_t *volinfo) gf_store_handle_destroy(volinfo->snapd.handle); glusterd_auth_cleanup(volinfo); + glusterd_shd_svcproc_cleanup(&volinfo->shd); + pthread_mutex_destroy(&volinfo->store_volinfo_lock); pthread_mutex_destroy(&volinfo->reflock); + LOCK_DESTROY(&volinfo->lock); + GF_FREE(volinfo); ret = 0; - out: gf_msg_debug(THIS->name, 0, "Returning %d", ret); return ret; @@ -1186,7 +1125,8 @@ glusterd_get_brick_mount_dir(char *brickpath, char *hostname, char *mount_dir) } brick_dir = &brickpath[strlen(mnt_pt)]; - brick_dir++; + if (brick_dir[0] == '/') + brick_dir++; snprintf(mount_dir, VALID_GLUSTERD_PATHMAX, "/%s", brick_dir); } @@ -1208,9 +1148,6 @@ glusterd_brickinfo_new_from_brick(char *brick, glusterd_brickinfo_t **brickinfo, char *path = NULL; char *tmp_host = NULL; char *tmp_path = NULL; -#ifdef HAVE_BD_XLATOR - char *vg = NULL; -#endif int32_t ret = -1; glusterd_brickinfo_t *new_brickinfo = NULL; xlator_t *this = NULL; @@ -1235,18 +1172,6 @@ glusterd_brickinfo_new_from_brick(char *brick, glusterd_brickinfo_t **brickinfo, if (ret) goto out; -#ifdef HAVE_BD_XLATOR - vg = strchr(path, '?'); - /* ? is used as a delimiter for vg */ - if (vg) { - if (snprintf(new_brickinfo->vg, PATH_MAX, "%s", vg + 1) >= PATH_MAX) { - ret = -1; - goto out; - } - *vg = '\0'; - } - new_brickinfo->caps = CAPS_BD; -#endif ret = gf_canonicalize_path(path); if (ret) goto out; @@ -1415,63 +1340,6 @@ out: return available; } -#ifdef HAVE_BD_XLATOR -/* - * Sets the tag of the format "trusted.glusterfs.volume-id:<uuid>" in - * the brick VG. It is used to avoid using same VG for another brick. - * @volume-id - gfid, @brick - brick info, @msg - Error message returned - * to the caller - */ -int -glusterd_bd_set_vg_tag(unsigned char *volume_id, glusterd_brickinfo_t *brick, - char *msg, int msg_size) -{ - lvm_t handle = NULL; - vg_t vg = NULL; - char *uuid = NULL; - int ret = -1; - - gf_asprintf(&uuid, "%s:%s", GF_XATTR_VOL_ID_KEY, uuid_utoa(volume_id)); - if (!uuid) { - snprintf(msg, sizeof(*msg), - "Could not allocate memory " - "for tag"); - return -1; - } - - handle = lvm_init(NULL); - if (!handle) { - snprintf(msg, sizeof(*msg), "lvm_init failed"); - goto out; - } - - vg = lvm_vg_open(handle, brick->vg, "w", 0); - if (!vg) { - snprintf(msg, sizeof(*msg), "Could not open VG %s", brick->vg); - goto out; - } - - if (lvm_vg_add_tag(vg, uuid) < 0) { - snprintf(msg, sizeof(*msg), - "Could not set tag %s for " - "VG %s", - uuid, brick->vg); - goto out; - } - lvm_vg_write(vg); - ret = 0; -out: - GF_FREE(uuid); - - if (vg) - lvm_vg_close(vg); - if (handle) - lvm_quit(handle); - - return ret; -} -#endif - int glusterd_validate_and_create_brickpath(glusterd_brickinfo_t *brickinfo, uuid_t volume_id, char *volname, @@ -1494,7 +1362,7 @@ glusterd_validate_and_create_brickpath(glusterd_brickinfo_t *brickinfo, char glusterfs_dir_path[PATH_MAX] = ""; int32_t len = 0; - ret = sys_mkdir(brickinfo->path, 0777); + ret = sys_mkdir(brickinfo->path, 0755); if (ret) { if (errno != EEXIST) { len = snprintf(msg, sizeof(msg), @@ -1503,6 +1371,10 @@ glusterd_validate_and_create_brickpath(glusterd_brickinfo_t *brickinfo, "Reason : %s ", brickinfo->hostname, brickinfo->path, strerror(errno)); + gf_smsg( + "glusterd", GF_LOG_ERROR, errno, GD_MSG_CREATE_BRICK_DIR_FAILED, + "Brick_hostname=%s, Brick_path=%s, Reason=%s", + brickinfo->hostname, brickinfo->path, strerror(errno), NULL); goto out; } } else { @@ -1515,6 +1387,9 @@ glusterd_validate_and_create_brickpath(glusterd_brickinfo_t *brickinfo, "lstat failed on %s. " "Reason : %s", brickinfo->path, strerror(errno)); + gf_smsg("glusterd", GF_LOG_ERROR, errno, GD_MSG_LSTAT_FAIL, + "Failed on Brick_path=%s, Reason=%s", brickinfo->path, + strerror(errno), NULL); goto out; } @@ -1523,6 +1398,8 @@ glusterd_validate_and_create_brickpath(glusterd_brickinfo_t *brickinfo, "The provided path %s " "which is already present, is not a directory", brickinfo->path); + gf_smsg("glusterd", GF_LOG_ERROR, errno, GD_MSG_DIR_OP_FAILED, + "Brick_path=%s", brickinfo->path, NULL); ret = -1; goto out; } @@ -1539,6 +1416,8 @@ glusterd_validate_and_create_brickpath(glusterd_brickinfo_t *brickinfo, "lstat failed on /. " "Reason : %s", strerror(errno)); + gf_smsg("glusterd", GF_LOG_ERROR, errno, GD_MSG_LSTAT_FAIL, + "Failed on /, Reason=%s", strerror(errno), NULL); goto out; } @@ -1548,6 +1427,9 @@ glusterd_validate_and_create_brickpath(glusterd_brickinfo_t *brickinfo, "lstat failed on %s. " "Reason : %s", parentdir, strerror(errno)); + gf_smsg("glusterd", GF_LOG_ERROR, errno, GD_MSG_LSTAT_FAIL, + "Failed on parentdir=%s, Reason=%s", parentdir, strerror(errno), + NULL); goto out; } if (strncmp(volname, GLUSTER_SHARED_STORAGE, @@ -1558,6 +1440,8 @@ glusterd_validate_and_create_brickpath(glusterd_brickinfo_t *brickinfo, len = snprintf(msg, sizeof(msg), "Brick isn't allowed to be " "created inside glusterd's working directory."); + gf_smsg("glusterd", GF_LOG_ERROR, errno, GD_MSG_BRICK_CREATION_FAIL, + NULL); ret = -1; goto out; } @@ -1573,6 +1457,10 @@ glusterd_validate_and_create_brickpath(glusterd_brickinfo_t *brickinfo, "command if you want to override this " "behavior.", brickinfo->hostname, brickinfo->path); + gf_smsg("glusterd", GF_LOG_ERROR, errno, GD_MSG_BRICK_CREATE_MNTPNT, + "Use 'force' at the end of the command if you want to " + "override this behavior, Brick_hostname=%s, Brick_path=%s", + brickinfo->hostname, brickinfo->path, NULL); ret = -1; goto out; } else if (parent_st.st_dev == root_st.st_dev) { @@ -1586,6 +1474,10 @@ glusterd_validate_and_create_brickpath(glusterd_brickinfo_t *brickinfo, "command if you want to override this " "behavior.", brickinfo->hostname, brickinfo->path); + gf_smsg("glusterd", GF_LOG_ERROR, errno, GD_MSG_BRICK_CREATE_ROOT, + "Use 'force' at the end of the command if you want to " + "override this behavior, Brick_hostname=%s, Brick_path=%s", + brickinfo->hostname, brickinfo->path, NULL); /* If --wignore-partition flag is used, ignore warnings * related to bricks being on root partition when 'force' @@ -1597,13 +1489,6 @@ glusterd_validate_and_create_brickpath(glusterd_brickinfo_t *brickinfo, } } -#ifdef HAVE_BD_XLATOR - if (brickinfo->vg[0]) { - ret = glusterd_bd_set_vg_tag(volume_id, brickinfo, msg, sizeof(msg)); - if (ret) - goto out; - } -#endif ret = glusterd_check_and_set_brick_xattr( brickinfo->hostname, brickinfo->path, volume_id, op_errstr, is_force); if (ret) @@ -1624,6 +1509,10 @@ glusterd_validate_and_create_brickpath(glusterd_brickinfo_t *brickinfo, ".glusterfs directory for brick %s:%s. " "Reason : %s ", brickinfo->hostname, brickinfo->path, strerror(errno)); + gf_smsg("glusterd", GF_LOG_ERROR, errno, + GD_MSG_CREATE_GLUSTER_DIR_FAILED, + "Brick_hostname=%s, Brick_path=%s, Reason=%s", + brickinfo->hostname, brickinfo->path, strerror(errno), NULL); goto out; } @@ -1686,6 +1575,37 @@ out: } int32_t +glusterd_volume_ta_brickinfo_get(uuid_t uuid, char *hostname, char *path, + glusterd_volinfo_t *volinfo, + glusterd_brickinfo_t **ta_brickinfo) +{ + glusterd_brickinfo_t *ta_brickiter = NULL; + int32_t ret = -1; + xlator_t *this = NULL; + + this = THIS; + + ret = -1; + + cds_list_for_each_entry(ta_brickiter, &volinfo->ta_bricks, brick_list) + { + if (strcmp(ta_brickiter->path, path) == 0 && + strcmp(ta_brickiter->hostname, hostname) == 0) { + gf_msg_debug(this->name, 0, LOGSTR_FOUND_BRICK, + ta_brickiter->hostname, ta_brickiter->path, + volinfo->volname); + ret = 0; + if (ta_brickinfo) + *ta_brickinfo = ta_brickiter; + break; + } + } + + gf_msg_debug(this->name, 0, "Returning %d", ret); + return ret; +} + +int32_t glusterd_volume_brickinfo_get_by_brick(char *brick, glusterd_volinfo_t *volinfo, glusterd_brickinfo_t **brickinfo, gf_boolean_t construct_real_path) @@ -1735,8 +1655,10 @@ glusterd_volinfo_find_by_volume_id(uuid_t volume_id, glusterd_volinfo_t *voliter = NULL; glusterd_conf_t *priv = NULL; - if (!volume_id) + if (!volume_id) { + gf_smsg("glusterd", GF_LOG_ERROR, errno, GD_MSG_INVALID_ARGUMENT, NULL); return -1; + } this = THIS; priv = this->private; @@ -1782,6 +1704,33 @@ glusterd_volinfo_find(const char *volname, glusterd_volinfo_t **volinfo) return ret; } +gf_boolean_t +glusterd_volume_exists(const char *volname) +{ + glusterd_volinfo_t *tmp_volinfo = NULL; + gf_boolean_t volume_found = _gf_false; + xlator_t *this = NULL; + glusterd_conf_t *priv = NULL; + + GF_ASSERT(volname); + this = THIS; + GF_ASSERT(this); + + priv = this->private; + GF_ASSERT(priv); + + cds_list_for_each_entry(tmp_volinfo, &priv->volumes, vol_list) + { + if (!strcmp(tmp_volinfo->volname, volname)) { + gf_msg_debug(this->name, 0, "Volume %s found", volname); + volume_found = _gf_true; + break; + } + } + + return volume_found; +} + int32_t glusterd_service_stop(const char *service, char *pidfile, int sig, gf_boolean_t force_kill) @@ -1896,7 +1845,6 @@ glusterd_service_stop_nolock(const char *service, char *pidfile, int sig, "Unable to find pid:%d, " "must be dead already. Ignoring.", pid); - ret = 0; } else { gf_msg(this->name, GF_LOG_ERROR, errno, GD_MSG_PID_KILL_FAIL, "Unable to kill pid:%d, " @@ -1981,7 +1929,14 @@ glusterd_brick_connect(glusterd_volinfo_t *volinfo, * The default timeout of 30mins used for unreliable network * connections is too long for unix domain socket connections. */ - ret = rpc_transport_unix_options_build(&options, socketpath, 600); + options = dict_new(); + if (!options) { + gf_smsg("glusterd", GF_LOG_ERROR, errno, GD_MSG_DICT_CREATE_FAIL, + NULL); + goto out; + } + + ret = rpc_transport_unix_options_build(options, socketpath, 600); if (ret) goto out; @@ -2000,7 +1955,8 @@ glusterd_brick_connect(glusterd_volinfo_t *volinfo, brickinfo->rpc = rpc; } out: - + if (options) + dict_unref(options); gf_msg_debug("glusterd", 0, "Returning %d", ret); return ret; } @@ -2016,7 +1972,7 @@ _mk_rundir_p(glusterd_volinfo_t *volinfo) this = THIS; priv = this->private; GLUSTERD_GET_VOLUME_PID_DIR(rundir, volinfo, priv); - ret = mkdir_p(rundir, 0777, _gf_true); + ret = mkdir_p(rundir, 0755, _gf_true); if (ret) gf_msg(this->name, GF_LOG_ERROR, errno, GD_MSG_CREATE_DIR_FAILED, "Failed to create rundir"); @@ -2051,6 +2007,9 @@ glusterd_volume_start_glusterfs(glusterd_volinfo_t *volinfo, int pid = -1; int32_t len = 0; glusterd_brick_proc_t *brick_proc = NULL; + char *inet_family = NULL; + char *global_threading = NULL; + bool threading = false; GF_ASSERT(volinfo); GF_ASSERT(brickinfo); @@ -2118,23 +2077,28 @@ glusterd_volume_start_glusterfs(glusterd_volinfo_t *volinfo, retry: runinit(&runner); - if (this->ctx->cmd_args.valgrind) { - /* Run bricks with valgrind */ + if (this->ctx->cmd_args.vgtool != _gf_none) { + /* Run bricks with valgrind. */ if (volinfo->logdir) { len = snprintf(valgrind_logfile, PATH_MAX, "%s/valgrind-%s-%s.log", volinfo->logdir, volinfo->volname, exp_path); } else { - len = snprintf( - valgrind_logfile, PATH_MAX, "%s/bricks/valgrind-%s-%s.log", - DEFAULT_LOG_FILE_DIRECTORY, volinfo->volname, exp_path); + len = snprintf(valgrind_logfile, PATH_MAX, + "%s/bricks/valgrind-%s-%s.log", priv->logdir, + volinfo->volname, exp_path); } if ((len < 0) || (len >= PATH_MAX)) { ret = -1; goto out; } - runner_add_args(&runner, "valgrind", "--leak-check=full", - "--trace-children=yes", "--track-origins=yes", NULL); + if (this->ctx->cmd_args.vgtool == _gf_memcheck) + runner_add_args(&runner, "valgrind", "--leak-check=full", + "--trace-children=yes", "--track-origins=yes", + NULL); + else + runner_add_args(&runner, "valgrind", "--tool=drd", NULL); + runner_argprintf(&runner, "--log-file=%s", valgrind_logfile); } @@ -2156,8 +2120,8 @@ retry: len = snprintf(logfile, PATH_MAX, "%s/%s.log", volinfo->logdir, exp_path); } else { - len = snprintf(logfile, PATH_MAX, "%s/bricks/%s.log", - DEFAULT_LOG_FILE_DIRECTORY, exp_path); + len = snprintf(logfile, PATH_MAX, "%s/bricks/%s.log", priv->logdir, + exp_path); } if ((len < 0) || (len >= PATH_MAX)) { ret = -1; @@ -2209,6 +2173,15 @@ retry: volinfo->volname, rdma_port); } + if (dict_get_strn(volinfo->dict, VKEY_CONFIG_GLOBAL_THREADING, + SLEN(VKEY_CONFIG_GLOBAL_THREADING), + &global_threading) == 0) { + if ((gf_string2boolean(global_threading, &threading) == 0) && + threading) { + runner_add_arg(&runner, "--global-threading"); + } + } + runner_add_arg(&runner, "--xlator-option"); runner_argprintf(&runner, "%s-server.listen-port=%d", volinfo->volname, port); @@ -2226,10 +2199,19 @@ retry: else if (volinfo->transport_type == GF_TRANSPORT_BOTH_TCP_RDMA) runner_argprintf(&runner, "--volfile-server-transport=socket,rdma"); + ret = dict_get_str(this->options, "transport.address-family", &inet_family); + if (!ret) { + runner_add_arg(&runner, "--xlator-option"); + runner_argprintf(&runner, "transport.address-family=%s", inet_family); + } + if (volinfo->memory_accounting) runner_add_arg(&runner, "--mem-accounting"); - runner_log(&runner, "", 0, "Starting GlusterFS"); + if (is_brick_mx_enabled()) + runner_add_arg(&runner, "--brick-mux"); + + runner_log(&runner, "", GF_LOG_DEBUG, "Starting GlusterFS"); brickinfo->port = port; brickinfo->rdma_port = rdma_port; @@ -2238,7 +2220,10 @@ retry: if (wait) { synclock_unlock(&priv->big_lock); + errno = 0; ret = runner_run(&runner); + if (errno != 0) + ret = errno; synclock_lock(&priv->big_lock); if (ret == EADDRINUSE) { @@ -2367,6 +2352,13 @@ unsafe_option(dict_t *this, char *key, data_t *value, void *arg) return _gf_false; } + if (fnmatch("*diagnostics.client-log*", key, 0) == 0) { + return _gf_false; + } + if (fnmatch("user.*", key, 0) == 0) { + return _gf_false; + } + return _gf_true; } @@ -2550,8 +2542,6 @@ glusterd_volume_stop_glusterfs(glusterd_volinfo_t *volinfo, conf = this->private; GF_VALIDATE_OR_GOTO(this->name, conf, out); - ret = 0; - ret = glusterd_brick_process_remove_brick(brickinfo, &last_brick); if (ret) { gf_msg_debug(this->name, 0, @@ -2644,7 +2634,7 @@ free_lines(char **line, size_t n) GF_FREE(line); } -char ** +static char ** glusterd_readin_file(const char *filepath, int *line_count) { int ret = -1; @@ -2682,6 +2672,7 @@ glusterd_readin_file(const char *filepath, int *line_count) /* Reduce allocation to minimal size. */ p = GF_REALLOC(lines, (counter + 1) * sizeof(char *)); if (!p) { + /* coverity[TAINTED_SCALAR] */ free_lines(lines, counter); lines = NULL; goto out; @@ -2707,7 +2698,7 @@ glusterd_compare_lines(const void *a, const void *b) return strcmp(*(char *const *)a, *(char *const *)b); } -int +static int glusterd_sort_and_redirect(const char *src_filepath, int dest_fd) { int ret = -1; @@ -2739,7 +2730,7 @@ out: return ret; } -int +static int glusterd_volume_compute_cksum(glusterd_volinfo_t *volinfo, char *cksum_path, char *filepath, gf_boolean_t is_quota_conf, uint32_t *cs) @@ -2749,20 +2740,16 @@ glusterd_volume_compute_cksum(glusterd_volinfo_t *volinfo, char *cksum_path, int fd = -1; int sort_fd = 0; char sort_filepath[PATH_MAX] = ""; - char *cksum_path_final = NULL; - char buf[4096] = ""; + char buf[32]; gf_boolean_t unlink_sortfile = _gf_false; - glusterd_conf_t *priv = NULL; - xlator_t *this = NULL; + glusterd_conf_t *priv = THIS->private; + xlator_t *this = THIS; mode_t orig_umask = 0; GF_ASSERT(volinfo); - this = THIS; - priv = THIS->private; GF_ASSERT(priv); fd = open(cksum_path, O_RDWR | O_APPEND | O_CREAT | O_TRUNC, 0600); - if (-1 == fd) { gf_msg(this->name, GF_LOG_ERROR, errno, GD_MSG_FILE_OP_FAILED, "Unable to open %s," @@ -2779,7 +2766,7 @@ glusterd_volume_compute_cksum(glusterd_volinfo_t *volinfo, char *cksum_path, orig_umask = umask(S_IRWXG | S_IRWXO); sort_fd = mkstemp(sort_filepath); umask(orig_umask); - if (sort_fd < 0) { + if (-1 == sort_fd) { gf_msg(this->name, GF_LOG_ERROR, errno, GD_MSG_FILE_OP_FAILED, "Could not generate " "temp file, reason: %s for volume: %s", @@ -2802,30 +2789,39 @@ glusterd_volume_compute_cksum(glusterd_volinfo_t *volinfo, char *cksum_path, ret = sys_close(sort_fd); if (ret) goto out; - } - cksum_path_final = is_quota_conf ? filepath : sort_filepath; + ret = get_checksum_for_path(sort_filepath, &cksum, priv->op_version); + if (ret) { + gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_CKSUM_GET_FAIL, + "unable to get " + "checksum for path: %s", + sort_filepath); + goto out; + } - ret = get_checksum_for_path(cksum_path_final, &cksum); - if (ret) { - gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_CKSUM_GET_FAIL, - "unable to get " - "checksum for path: %s", - cksum_path_final); - goto out; - } - if (!is_quota_conf) { - snprintf(buf, sizeof(buf), "%s=%u\n", "info", cksum); - ret = sys_write(fd, buf, strlen(buf)); + ret = snprintf(buf, sizeof(buf), "info=%u\n", cksum); + ret = sys_write(fd, buf, ret); if (ret <= 0) { ret = -1; goto out; } + } else if (priv->op_version < GD_OP_VERSION_7_0) { + ret = get_checksum_for_path(filepath, &cksum, priv->op_version); + if (ret) { + gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_CKSUM_GET_FAIL, + "unable to get " + "checksum for path: %s", + filepath); + goto out; + } } - ret = get_checksum_for_file(fd, &cksum); - if (ret) + ret = get_checksum_for_file(fd, &cksum, priv->op_version); + if (ret) { + gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_CKSUM_GET_FAIL, + "unable to get checksum for path: %s", filepath); goto out; + } *cs = cksum; @@ -2895,22 +2891,25 @@ out: return ret; } -int +static int _add_dict_to_prdict(dict_t *this, char *key, data_t *value, void *data) { - glusterd_dict_ctx_t *ctx = NULL; - char optkey[512] = ""; + glusterd_dict_ctx_t *ctx = data; + char optkey[64]; /* optkey are usually quite small */ int ret = -1; - ctx = data; ret = snprintf(optkey, sizeof(optkey), "%s.%s%d", ctx->prefix, ctx->key_name, ctx->opt_count); + if (ret < 0 || ret >= sizeof(optkey)) + return -1; ret = dict_set_strn(ctx->dict, optkey, ret, key); if (ret) gf_msg("glusterd", GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "option add for %s%d %s", ctx->key_name, ctx->opt_count, key); ret = snprintf(optkey, sizeof(optkey), "%s.%s%d", ctx->prefix, ctx->val_name, ctx->opt_count); + if (ret < 0 || ret >= sizeof(optkey)) + return -1; ret = dict_set_strn(ctx->dict, optkey, ret, value->data); if (ret) gf_msg("glusterd", GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, @@ -2934,13 +2933,19 @@ glusterd_add_bricks_hname_path_to_dict(dict_t *dict, { ret = snprintf(key, sizeof(key), "%d-hostname", index); ret = dict_set_strn(dict, key, ret, brickinfo->hostname); - if (ret) + if (ret) { + gf_smsg("glusterd", GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, + "Key=%s", key, NULL); goto out; + } ret = snprintf(key, sizeof(key), "%d-path", index); ret = dict_set_strn(dict, key, ret, brickinfo->path); - if (ret) + if (ret) { + gf_smsg("glusterd", GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, + "Key=%s", key, NULL); goto out; + } index++; } @@ -2957,10 +2962,11 @@ glusterd_add_volume_to_dict(glusterd_volinfo_t *volinfo, dict_t *dict, int32_t count, char *prefix) { int32_t ret = -1; - char pfx[512] = ""; - char key[512] = ""; + char pfx[32] = ""; /* prefix should be quite small */ + char key[64] = ""; int keylen; glusterd_brickinfo_t *brickinfo = NULL; + glusterd_brickinfo_t *ta_brickinfo = NULL; int32_t i = 1; char *volume_id_str = NULL; char *str = NULL; @@ -2975,145 +2981,118 @@ glusterd_add_volume_to_dict(glusterd_volinfo_t *volinfo, dict_t *dict, GF_ASSERT(volinfo); GF_ASSERT(prefix); - keylen = snprintf(key, sizeof(key), "%s%d.name", prefix, count); + ret = snprintf(pfx, sizeof(pfx), "%s%d", prefix, count); + if (ret < 0 || ret >= sizeof(pfx)) { + ret = -1; + goto out; + } + + keylen = snprintf(key, sizeof(key), "%s.name", pfx); ret = dict_set_strn(dict, key, keylen, volinfo->volname); if (ret) goto out; - keylen = snprintf(key, sizeof(key), "%s%d.type", prefix, count); + keylen = snprintf(key, sizeof(key), "%s.type", pfx); ret = dict_set_int32n(dict, key, keylen, volinfo->type); if (ret) goto out; - keylen = snprintf(key, sizeof(key), "%s%d.brick_count", prefix, count); + keylen = snprintf(key, sizeof(key), "%s.brick_count", pfx); ret = dict_set_int32n(dict, key, keylen, volinfo->brick_count); if (ret) goto out; - keylen = snprintf(key, sizeof(key), "%s%d.version", prefix, count); + keylen = snprintf(key, sizeof(key), "%s.version", pfx); ret = dict_set_int32n(dict, key, keylen, volinfo->version); if (ret) goto out; - keylen = snprintf(key, sizeof(key), "%s%d.status", prefix, count); + keylen = snprintf(key, sizeof(key), "%s.status", pfx); ret = dict_set_int32n(dict, key, keylen, volinfo->status); if (ret) goto out; - keylen = snprintf(key, sizeof(key), "%s%d.sub_count", prefix, count); + keylen = snprintf(key, sizeof(key), "%s.sub_count", pfx); ret = dict_set_int32n(dict, key, keylen, volinfo->sub_count); if (ret) goto out; - keylen = snprintf(key, sizeof(key), "%s%d.stripe_count", prefix, count); + keylen = snprintf(key, sizeof(key), "%s.subvol_count", pfx); + ret = dict_set_int32n(dict, key, keylen, volinfo->subvol_count); + if (ret) + goto out; + + keylen = snprintf(key, sizeof(key), "%s.stripe_count", pfx); ret = dict_set_int32n(dict, key, keylen, volinfo->stripe_count); if (ret) goto out; - keylen = snprintf(key, sizeof(key), "%s%d.replica_count", prefix, count); + keylen = snprintf(key, sizeof(key), "%s.replica_count", pfx); ret = dict_set_int32n(dict, key, keylen, volinfo->replica_count); if (ret) goto out; - keylen = snprintf(key, sizeof(key), "%s%d.arbiter_count", prefix, count); + keylen = snprintf(key, sizeof(key), "%s.arbiter_count", pfx); ret = dict_set_int32n(dict, key, keylen, volinfo->arbiter_count); if (ret) goto out; - keylen = snprintf(key, sizeof(key), "%s%d.disperse_count", prefix, count); + keylen = snprintf(key, sizeof(key), "%s.thin_arbiter_count", pfx); + ret = dict_set_int32n(dict, key, keylen, volinfo->thin_arbiter_count); + if (ret) + goto out; + + keylen = snprintf(key, sizeof(key), "%s.disperse_count", pfx); ret = dict_set_int32n(dict, key, keylen, volinfo->disperse_count); if (ret) goto out; - keylen = snprintf(key, sizeof(key), "%s%d.redundancy_count", prefix, count); + keylen = snprintf(key, sizeof(key), "%s.redundancy_count", pfx); ret = dict_set_int32n(dict, key, keylen, volinfo->redundancy_count); if (ret) goto out; - keylen = snprintf(key, sizeof(key), "%s%d.dist_count", prefix, count); + keylen = snprintf(key, sizeof(key), "%s.dist_count", pfx); ret = dict_set_int32n(dict, key, keylen, volinfo->dist_leaf_count); if (ret) goto out; - snprintf(key, sizeof(key), "%s%d.ckusm", prefix, count); + snprintf(key, sizeof(key), "%s.ckusm", pfx); ret = dict_set_int64(dict, key, volinfo->cksum); if (ret) goto out; - snprintf(key, sizeof(key), "%s%d.transport_type", prefix, count); + snprintf(key, sizeof(key), "%s.transport_type", pfx); ret = dict_set_uint32(dict, key, volinfo->transport_type); if (ret) goto out; - snprintf(key, sizeof(key), "%s%d.stage_deleted", prefix, count); + snprintf(key, sizeof(key), "%s.stage_deleted", pfx); ret = dict_set_uint32(dict, key, (uint32_t)volinfo->stage_deleted); if (ret) goto out; - /* tiering related variables */ - - snprintf(key, sizeof(key), "%s%d.cold_brick_count", prefix, count); - ret = dict_set_uint32(dict, key, volinfo->tier_info.cold_brick_count); - if (ret) - goto out; - - snprintf(key, sizeof(key), "%s%d.cold_type", prefix, count); - ret = dict_set_uint32(dict, key, volinfo->tier_info.cold_type); - if (ret) - goto out; - - snprintf(key, sizeof(key), "%s%d.cold_replica_count", prefix, count); - ret = dict_set_uint32(dict, key, volinfo->tier_info.cold_replica_count); - if (ret) - goto out; - - snprintf(key, sizeof(key), "%s%d.cold_disperse_count", prefix, count); - ret = dict_set_uint32(dict, key, volinfo->tier_info.cold_disperse_count); - if (ret) - goto out; - - snprintf(key, sizeof(key), "%s%d.cold_redundancy_count", prefix, count); - ret = dict_set_uint32(dict, key, volinfo->tier_info.cold_redundancy_count); - if (ret) - goto out; - - snprintf(key, sizeof(key), "%s%d.cold_dist_count", prefix, count); - ret = dict_set_uint32(dict, key, volinfo->tier_info.cold_dist_leaf_count); - if (ret) - goto out; - - snprintf(key, sizeof(key), "%s%d.hot_brick_count", prefix, count); - ret = dict_set_uint32(dict, key, volinfo->tier_info.hot_brick_count); - if (ret) - goto out; - - snprintf(key, sizeof(key), "%s%d.hot_type", prefix, count); - ret = dict_set_uint32(dict, key, volinfo->tier_info.hot_type); - if (ret) - goto out; - - snprintf(key, sizeof(key), "%s%d.hot_replica_count", prefix, count); - ret = dict_set_uint32(dict, key, volinfo->tier_info.hot_replica_count); - if (ret) - goto out; - - snprintf(key, sizeof(key), "%s%d", prefix, count); - ret = gd_add_vol_snap_details_to_dict(dict, key, volinfo); - if (ret) + ret = gd_add_vol_snap_details_to_dict(dict, pfx, volinfo); + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, + "vol snap details", NULL); goto out; + } volume_id_str = gf_strdup(uuid_utoa(volinfo->volume_id)); if (!volume_id_str) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_STRDUP_FAILED, + "volume id=%s", volinfo->volume_id, NULL); ret = -1; goto out; } - keylen = snprintf(key, sizeof(key), "%s%d.volume_id", prefix, count); + keylen = snprintf(key, sizeof(key), "%s.volume_id", pfx); ret = dict_set_dynstrn(dict, key, keylen, volume_id_str); if (ret) goto out; volume_id_str = NULL; - keylen = snprintf(key, sizeof(key), "%s%d.username", prefix, count); + keylen = snprintf(key, sizeof(key), "%s.username", pfx); str = glusterd_auth_get_username(volinfo); if (str) { ret = dict_set_dynstrn(dict, key, keylen, gf_strdup(str)); @@ -3121,7 +3100,7 @@ glusterd_add_volume_to_dict(glusterd_volinfo_t *volinfo, dict_t *dict, goto out; } - keylen = snprintf(key, sizeof(key), "%s%d.password", prefix, count); + keylen = snprintf(key, sizeof(key), "%s.password", pfx); str = glusterd_auth_get_password(volinfo); if (str) { ret = dict_set_dynstrn(dict, key, keylen, gf_strdup(str)); @@ -3129,29 +3108,30 @@ glusterd_add_volume_to_dict(glusterd_volinfo_t *volinfo, dict_t *dict, goto out; } - keylen = snprintf(key, sizeof(key), "%s%d.rebalance", prefix, count); + keylen = snprintf(key, sizeof(key), "%s.rebalance", pfx); ret = dict_set_int32n(dict, key, keylen, volinfo->rebal.defrag_cmd); if (ret) goto out; rebalance_id_str = gf_strdup(uuid_utoa(volinfo->rebal.rebalance_id)); if (!rebalance_id_str) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_STRDUP_FAILED, + "rebalance_id=%s", volinfo->rebal.rebalance_id, NULL); ret = -1; goto out; } - keylen = snprintf(key, sizeof(key), "%s%d.rebalance-id", prefix, count); + keylen = snprintf(key, sizeof(key), "%s.rebalance-id", pfx); ret = dict_set_dynstrn(dict, key, keylen, rebalance_id_str); if (ret) goto out; rebalance_id_str = NULL; - snprintf(key, sizeof(key), "%s%d.rebalance-op", prefix, count); + snprintf(key, sizeof(key), "%s.rebalance-op", pfx); ret = dict_set_uint32(dict, key, volinfo->rebal.op); if (ret) goto out; if (volinfo->rebal.dict) { - snprintf(pfx, sizeof(pfx), "%s%d", prefix, count); ctx.dict = dict; ctx.prefix = pfx; ctx.opt_count = 1; @@ -3166,7 +3146,6 @@ glusterd_add_volume_to_dict(glusterd_volinfo_t *volinfo, dict_t *dict, goto out; } - snprintf(pfx, sizeof(pfx), "%s%d", prefix, count); ctx.dict = dict; ctx.prefix = pfx; ctx.opt_count = 1; @@ -3176,7 +3155,7 @@ glusterd_add_volume_to_dict(glusterd_volinfo_t *volinfo, dict_t *dict, dict_foreach(volinfo->dict, _add_dict_to_prdict, &ctx); ctx.opt_count--; - keylen = snprintf(key, sizeof(key), "%s%d.opt-count", prefix, count); + keylen = snprintf(key, sizeof(key), "%s.opt-count", pfx); ret = dict_set_int32n(dict, key, keylen, ctx.opt_count); if (ret) goto out; @@ -3191,43 +3170,40 @@ glusterd_add_volume_to_dict(glusterd_volinfo_t *volinfo, dict_t *dict, dict_foreach(volinfo->gsync_slaves, _add_dict_to_prdict, &ctx); ctx.opt_count--; - keylen = snprintf(key, sizeof(key), "%s%d.gsync-count", prefix, count); + keylen = snprintf(key, sizeof(key), "%s.gsync-count", pfx); ret = dict_set_int32n(dict, key, keylen, ctx.opt_count); if (ret) goto out; cds_list_for_each_entry(brickinfo, &volinfo->bricks, brick_list) { - keylen = snprintf(key, sizeof(key), "%s%d.brick%d.hostname", prefix, - count, i); + keylen = snprintf(key, sizeof(key), "%s.brick%d.hostname", pfx, i); ret = dict_set_strn(dict, key, keylen, brickinfo->hostname); if (ret) goto out; - keylen = snprintf(key, sizeof(key), "%s%d.brick%d.path", prefix, count, - i); + keylen = snprintf(key, sizeof(key), "%s.brick%d.path", pfx, i); ret = dict_set_strn(dict, key, keylen, brickinfo->path); if (ret) goto out; - keylen = snprintf(key, sizeof(key), "%s%d.brick%d.decommissioned", - prefix, count, i); + keylen = snprintf(key, sizeof(key), "%s.brick%d.decommissioned", pfx, + i); ret = dict_set_int32n(dict, key, keylen, brickinfo->decommissioned); if (ret) goto out; - keylen = snprintf(key, sizeof(key), "%s%d.brick%d.brick_id", prefix, - count, i); + keylen = snprintf(key, sizeof(key), "%s.brick%d.brick_id", pfx, i); ret = dict_set_strn(dict, key, keylen, brickinfo->brick_id); if (ret) goto out; - snprintf(key, sizeof(key), "%s%d.brick%d.uuid", prefix, count, i); + snprintf(key, sizeof(key), "%s.brick%d.uuid", pfx, i); ret = dict_set_dynstr_with_alloc(dict, key, uuid_utoa(brickinfo->uuid)); if (ret) goto out; - snprintf(key, sizeof(key), "%s%d.brick%d", prefix, count, i); + snprintf(key, sizeof(key), "%s.brick%d", pfx, i); ret = gd_add_brick_snap_details_to_dict(dict, key, brickinfo); if (ret) goto out; @@ -3235,31 +3211,66 @@ glusterd_add_volume_to_dict(glusterd_volinfo_t *volinfo, dict_t *dict, i++; } + i = 1; + if (volinfo->thin_arbiter_count == 1) { + cds_list_for_each_entry(ta_brickinfo, &volinfo->ta_bricks, brick_list) + { + keylen = snprintf(key, sizeof(key), "%s.ta-brick%d.hostname", pfx, + i); + ret = dict_set_strn(dict, key, keylen, ta_brickinfo->hostname); + if (ret) + goto out; + + keylen = snprintf(key, sizeof(key), "%s.ta-brick%d.path", pfx, i); + ret = dict_set_strn(dict, key, keylen, ta_brickinfo->path); + if (ret) + goto out; + + keylen = snprintf(key, sizeof(key), "%s.ta-brick%d.decommissioned", + pfx, i); + ret = dict_set_int32n(dict, key, keylen, + ta_brickinfo->decommissioned); + if (ret) + goto out; + + keylen = snprintf(key, sizeof(key), "%s.ta-brick%d.brick_id", pfx, + i); + ret = dict_set_strn(dict, key, keylen, ta_brickinfo->brick_id); + if (ret) + goto out; + + snprintf(key, sizeof(key), "%s.ta-brick%d.uuid", pfx, i); + ret = dict_set_dynstr_with_alloc(dict, key, + uuid_utoa(ta_brickinfo->uuid)); + if (ret) + goto out; + + i++; + } + } + /* Add volume op-versions to dict. This prevents volume inconsistencies * in the cluster */ - keylen = snprintf(key, sizeof(key), "%s%d.op-version", prefix, count); + keylen = snprintf(key, sizeof(key), "%s.op-version", pfx); ret = dict_set_int32n(dict, key, keylen, volinfo->op_version); if (ret) goto out; - keylen = snprintf(key, sizeof(key), "%s%d.client-op-version", prefix, - count); + keylen = snprintf(key, sizeof(key), "%s.client-op-version", pfx); ret = dict_set_int32n(dict, key, keylen, volinfo->client_op_version); if (ret) goto out; - /*Add volume Capability (BD Xlator) to dict*/ - keylen = snprintf(key, sizeof(key), "%s%d.caps", prefix, count); - ret = dict_set_int32n(dict, key, keylen, volinfo->caps); - - keylen = snprintf(key, sizeof(key), "%s%d.quota-xattr-version", prefix, - count); + keylen = snprintf(key, sizeof(key), "%s.quota-xattr-version", pfx); ret = dict_set_int32n(dict, key, keylen, volinfo->quota_xattr_version); out: GF_FREE(volume_id_str); GF_FREE(rebalance_id_str); GF_FREE(rb_id_str); + if (key[0] != '\0' && ret != 0) + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, + "Key=%s", key, NULL); gf_msg_debug(this->name, 0, "Returning with %d", ret); return ret; } @@ -3274,7 +3285,8 @@ glusterd_vol_add_quota_conf_to_dict(glusterd_volinfo_t *volinfo, dict_t *load, { int fd = -1; unsigned char buf[16] = ""; - char key[PATH_MAX] = ""; + char key[64]; + char key_prefix[32]; int gfid_idx = 0; int ret = -1; xlator_t *this = NULL; @@ -3299,6 +3311,11 @@ glusterd_vol_add_quota_conf_to_dict(glusterd_volinfo_t *volinfo, dict_t *load, if (ret) goto out; + ret = snprintf(key_prefix, sizeof(key_prefix), "%s%d", prefix, vol_idx); + if (ret < 0 || ret >= sizeof(key_prefix)) { + ret = -1; + goto out; + } for (gfid_idx = 0;; gfid_idx++) { ret = quota_conf_read_gfid(fd, buf, &type, version); if (ret == 0) { @@ -3310,33 +3327,46 @@ glusterd_vol_add_quota_conf_to_dict(glusterd_volinfo_t *volinfo, dict_t *load, goto out; } - snprintf(key, sizeof(key) - 1, "%s%d.gfid%d", prefix, vol_idx, - gfid_idx); + snprintf(key, sizeof(key) - 1, "%s.gfid%d", key_prefix, gfid_idx); ret = dict_set_dynstr_with_alloc(load, key, uuid_utoa(buf)); - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, + "Key=%s", key, NULL); goto out; + } - snprintf(key, sizeof(key) - 1, "%s%d.gfid-type%d", prefix, vol_idx, - gfid_idx); + snprintf(key, sizeof(key) - 1, "%s.gfid-type%d", key_prefix, gfid_idx); ret = dict_set_int8(load, key, type); - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, + "Key=%s", key, NULL); goto out; + } } - ret = snprintf(key, sizeof(key), "%s%d.gfid-count", prefix, vol_idx); + ret = snprintf(key, sizeof(key), "%s.gfid-count", key_prefix); ret = dict_set_int32n(load, key, ret, gfid_idx); - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, + "Key=%s", key, NULL); goto out; + } - snprintf(key, sizeof(key), "%s%d.quota-cksum", prefix, vol_idx); + snprintf(key, sizeof(key), "%s.quota-cksum", key_prefix); ret = dict_set_uint32(load, key, volinfo->quota_conf_cksum); - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, + "Key=%s", key, NULL); goto out; + } - snprintf(key, sizeof(key), "%s%d.quota-version", prefix, vol_idx); + snprintf(key, sizeof(key), "%s.quota-version", key_prefix); ret = dict_set_uint32(load, key, volinfo->quota_conf_version); - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, + "Key=%s", key, NULL); goto out; + } ret = 0; out: @@ -3345,33 +3375,50 @@ out: return ret; } -int32_t -glusterd_add_volumes_to_export_dict(dict_t **peer_data) +void * +glusterd_add_bulk_volumes_create_thread(void *data) { int32_t ret = -1; - dict_t *dict = NULL; glusterd_conf_t *priv = NULL; glusterd_volinfo_t *volinfo = NULL; int32_t count = 0; - glusterd_dict_ctx_t ctx = {0}; xlator_t *this = NULL; + glusterd_add_dict_args_t *arg = NULL; + dict_t *dict = NULL; + int start = 0; + int end = 0; - this = THIS; - GF_ASSERT(this); + GF_ASSERT(data); + + arg = data; + dict = arg->voldict; + start = arg->start; + end = arg->end; + this = arg->this; + THIS = arg->this; priv = this->private; GF_ASSERT(priv); - dict = dict_new(); - if (!dict) - goto out; - cds_list_for_each_entry(volinfo, &priv->volumes, vol_list) { count++; + + /* Skip volumes if index count is less than start + index to handle volume for specific thread + */ + if (count < start) + continue; + + /* No need to process volume if index count is greater + than end index + */ + if (count > end) + break; + ret = glusterd_add_volume_to_dict(volinfo, dict, count, "volume"); if (ret) goto out; - if (!glusterd_is_volume_quota_enabled(volinfo)) + if (!dict_get_sizen(volinfo->dict, VKEY_FEATURES_QUOTA)) continue; ret = glusterd_vol_add_quota_conf_to_dict(volinfo, dict, count, "volume"); @@ -3379,37 +3426,260 @@ glusterd_add_volumes_to_export_dict(dict_t **peer_data) goto out; } - ret = dict_set_int32n(dict, "count", SLEN("count"), count); +out: + GF_ATOMIC_DEC(priv->thread_count); + free(arg); + return NULL; +} + +int +glusterd_dict_searialize(dict_t *dict_arr[], int count, int totcount, char *buf) +{ + int i = 0; + int32_t keylen = 0; + int64_t netword = 0; + data_pair_t *pair = NULL; + int dict_count = 0; + int ret = 0; + + netword = hton32(totcount); + memcpy(buf, &netword, sizeof(netword)); + buf += DICT_HDR_LEN; + + for (i = 0; i < count; i++) { + if (dict_arr[i]) { + dict_count = dict_arr[i]->count; + pair = dict_arr[i]->members_list; + while (dict_count) { + if (!pair) { + gf_msg("glusterd", GF_LOG_ERROR, 0, + LG_MSG_PAIRS_LESS_THAN_COUNT, + "less than count data pairs found!"); + ret = -1; + goto out; + } + + if (!pair->key) { + gf_msg("glusterd", GF_LOG_ERROR, 0, LG_MSG_NULL_PTR, + "pair->key is null!"); + ret = -1; + goto out; + } + + keylen = strlen(pair->key); + netword = hton32(keylen); + memcpy(buf, &netword, sizeof(netword)); + buf += DICT_DATA_HDR_KEY_LEN; + if (!pair->value) { + gf_msg("glusterd", GF_LOG_ERROR, 0, LG_MSG_NULL_PTR, + "pair->value is null!"); + ret = -1; + goto out; + } + + netword = hton32(pair->value->len); + memcpy(buf, &netword, sizeof(netword)); + buf += DICT_DATA_HDR_VAL_LEN; + + memcpy(buf, pair->key, keylen); + buf += keylen; + *buf++ = '\0'; + + if (pair->value->data) { + memcpy(buf, pair->value->data, pair->value->len); + buf += pair->value->len; + } + + pair = pair->next; + dict_count--; + } + } + } + +out: + for (i = 0; i < count; i++) { + if (dict_arr[i]) + dict_unref(dict_arr[i]); + } + return ret; +} + +int +glusterd_dict_arr_serialize(dict_t *dict_arr[], int count, char **buf, + u_int *length) +{ + ssize_t len = 0; + int i = 0; + int totcount = 0; + int ret = 0; + + for (i = 0; i < count; i++) { + if (dict_arr[i]) { + len += dict_serialized_length_lk(dict_arr[i]); + totcount += dict_arr[i]->count; + } + } + + // Subtract HDR_LEN except one dictionary + len = len - ((count - 1) * DICT_HDR_LEN); + + *buf = GF_MALLOC(len, gf_common_mt_char); + if (*buf == NULL) { + ret = -ENOMEM; + goto out; + } + + if (length != NULL) { + *length = len; + } + + ret = glusterd_dict_searialize(dict_arr, count, totcount, *buf); + +out: + return ret; +} + +int32_t +glusterd_add_volumes_to_export_dict(dict_t *peer_data, char **buf, + u_int *length) +{ + int32_t ret = -1; + dict_t *dict_arr[128] = { + 0, + }; + glusterd_conf_t *priv = NULL; + glusterd_volinfo_t *volinfo = NULL; + int32_t count = 0; + glusterd_dict_ctx_t ctx = {0}; + xlator_t *this = NULL; + int totthread = 0; + int volcnt = 0; + int start = 1; + int endindex = 0; + int vol_per_thread_limit = 0; + glusterd_add_dict_args_t *arg = NULL; + pthread_t th_id = { + 0, + }; + int th_ret = 0; + int i = 0; + + this = THIS; + GF_ASSERT(this); + priv = this->private; + GF_ASSERT(priv); + + /* Count the total number of volumes */ + cds_list_for_each_entry(volinfo, &priv->volumes, vol_list) volcnt++; + + get_gd_vol_thread_limit(&vol_per_thread_limit); + + if ((vol_per_thread_limit == 1) || (vol_per_thread_limit == 0) || + (vol_per_thread_limit > 100)) { + totthread = 0; + } else { + totthread = volcnt / vol_per_thread_limit; + if (totthread) { + endindex = volcnt % vol_per_thread_limit; + if (endindex) + totthread++; + } + } + + if (totthread == 0) { + cds_list_for_each_entry(volinfo, &priv->volumes, vol_list) + { + count++; + ret = glusterd_add_volume_to_dict(volinfo, peer_data, count, + "volume"); + if (ret) + goto out; + + if (!dict_get_sizen(volinfo->dict, VKEY_FEATURES_QUOTA)) + continue; + + ret = glusterd_vol_add_quota_conf_to_dict(volinfo, peer_data, count, + "volume"); + if (ret) + goto out; + } + } else { + for (i = 0; i < totthread; i++) { + arg = calloc(1, sizeof(*arg)); + dict_arr[i] = dict_new(); + arg->this = this; + arg->voldict = dict_arr[i]; + arg->start = start; + if ((i + 1) != totthread) { + arg->end = ((i + 1) * vol_per_thread_limit); + } else { + arg->end = (((i + 1) * vol_per_thread_limit) + endindex); + } + th_ret = gf_thread_create_detached( + &th_id, glusterd_add_bulk_volumes_create_thread, arg, + "bulkvoldict"); + if (th_ret) { + gf_log(this->name, GF_LOG_ERROR, + "glusterd_add_bulk_volume %s" + " thread creation failed", + "bulkvoldict"); + free(arg); + goto out; + } + + start = start + vol_per_thread_limit; + GF_ATOMIC_INC(priv->thread_count); + gf_log(this->name, GF_LOG_INFO, + "Create thread %d to populate dict data for volume" + " start index is %d end index is %d", + (i + 1), arg->start, arg->end); + } + while (GF_ATOMIC_GET(priv->thread_count)) { + sleep(1); + } + + gf_log(this->name, GF_LOG_INFO, + "Finished dictionary population in all threads"); + } + + ret = dict_set_int32n(peer_data, "count", SLEN("count"), volcnt); if (ret) goto out; - ctx.dict = dict; + ctx.dict = peer_data; ctx.prefix = "global"; ctx.opt_count = 1; ctx.key_name = "key"; ctx.val_name = "val"; dict_foreach(priv->opts, _add_dict_to_prdict, &ctx); ctx.opt_count--; - ret = dict_set_int32n(dict, "global-opt-count", SLEN("global-opt-count"), - ctx.opt_count); + ret = dict_set_int32n(peer_data, "global-opt-count", + SLEN("global-opt-count"), ctx.opt_count); if (ret) goto out; - *peer_data = dict; + if (totthread) { + gf_log(this->name, GF_LOG_INFO, + "Merged multiple dictionaries into a single one"); + dict_arr[totthread++] = dict_ref(peer_data); + ret = glusterd_dict_arr_serialize(dict_arr, totthread, buf, length); + gf_log(this->name, GF_LOG_INFO, "Serialize dictionary data returned %d", + ret); + } + out: - if (ret) - dict_unref(dict); gf_msg_trace(this->name, 0, "Returning %d", ret); return ret; } -int32_t +static int32_t glusterd_compare_friend_volume(dict_t *peer_data, int32_t count, int32_t *status, char *hostname) { int32_t ret = -1; char key[64] = ""; + char key_prefix[32]; int keylen; glusterd_volinfo_t *volinfo = NULL; char *volname = NULL; @@ -3426,37 +3696,43 @@ glusterd_compare_friend_volume(dict_t *peer_data, int32_t count, this = THIS; GF_ASSERT(this); - keylen = snprintf(key, sizeof(key), "volume%d.name", count); + snprintf(key_prefix, sizeof(key_prefix), "volume%d", count); + keylen = snprintf(key, sizeof(key), "%s.name", key_prefix); ret = dict_get_strn(peer_data, key, keylen, &volname); - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, + "Key=%s", key, NULL); goto out; + } ret = glusterd_volinfo_find(volname, &volinfo); if (ret) { - snprintf(key, sizeof(key), "volume%d.stage_deleted", count); + snprintf(key, sizeof(key), "%s.stage_deleted", key_prefix); ret = dict_get_uint32(peer_data, key, &stage_deleted); /* stage_deleted = 1 means the volume is still in the process of * deleting a volume, so we shouldn't be trying to create a * fresh volume here which would lead to a stale entry */ - if (stage_deleted == 0) + if (!ret && stage_deleted == 0) *status = GLUSTERD_VOL_COMP_UPDATE_REQ; - ret = 0; goto out; } - keylen = snprintf(key, sizeof(key), "volume%d.version", count); + keylen = snprintf(key, sizeof(key), "%s.version", key_prefix); ret = dict_get_int32n(peer_data, key, keylen, &version); - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, + "Key=%s", key, NULL); goto out; + } if (version > volinfo->version) { // Mismatch detected - ret = 0; gf_msg(this->name, GF_LOG_INFO, 0, GD_MSG_VOL_VERS_MISMATCH, "Version of volume %s differ. local version = %d, " "remote version = %d on peer %s", volinfo->volname, volinfo->version, version, hostname); + GF_ATOMIC_INIT(volinfo->volpeerupdate, 1); *status = GLUSTERD_VOL_COMP_UPDATE_REQ; goto out; } else if (version < volinfo->version) { @@ -3466,13 +3742,15 @@ glusterd_compare_friend_volume(dict_t *peer_data, int32_t count, // Now, versions are same, compare cksums. // - snprintf(key, sizeof(key), "volume%d.ckusm", count); + snprintf(key, sizeof(key), "%s.ckusm", key_prefix); ret = dict_get_uint32(peer_data, key, &cksum); - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, + "Key=%s", key, NULL); goto out; + } if (cksum != volinfo->cksum) { - ret = 0; gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_CKSUM_VERS_MISMATCH, "Version of Cksums %s differ. local cksum = %u, remote " "cksum = %u on peer %s", @@ -3481,18 +3759,19 @@ glusterd_compare_friend_volume(dict_t *peer_data, int32_t count, goto out; } - snprintf(key, sizeof(key), "volume%d.quota-version", count); + if (!dict_get_sizen(volinfo->dict, VKEY_FEATURES_QUOTA)) + goto skip_quota; + + snprintf(key, sizeof(key), "%s.quota-version", key_prefix); ret = dict_get_uint32(peer_data, key, "a_version); if (ret) { gf_msg_debug(this->name, 0, "quota-version key absent for" " volume %s in peer %s's response", volinfo->volname, hostname); - ret = 0; } else { if (quota_version > volinfo->quota_conf_version) { // Mismatch detected - ret = 0; gf_msg(this->name, GF_LOG_INFO, 0, GD_MSG_QUOTA_CONFIG_VERS_MISMATCH, "Quota configuration versions of volume %s " @@ -3510,17 +3789,15 @@ glusterd_compare_friend_volume(dict_t *peer_data, int32_t count, // Now, versions are same, compare cksums. // - snprintf(key, sizeof(key), "volume%d.quota-cksum", count); + snprintf(key, sizeof(key), "%s.quota-cksum", key_prefix); ret = dict_get_uint32(peer_data, key, "a_cksum); if (ret) { gf_msg_debug(this->name, 0, "quota checksum absent for " "volume %s in peer %s's response", volinfo->volname, hostname); - ret = 0; } else { if (quota_cksum != volinfo->quota_conf_cksum) { - ret = 0; gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_QUOTA_CONFIG_CKSUM_MISMATCH, "Cksums of " @@ -3532,10 +3809,12 @@ glusterd_compare_friend_volume(dict_t *peer_data, int32_t count, goto out; } } + +skip_quota: *status = GLUSTERD_VOL_COMP_SCS; out: - keylen = snprintf(key, sizeof(key), "volume%d.update", count); + keylen = snprintf(key, sizeof(key), "%s.update", key_prefix); if (*status == GLUSTERD_VOL_COMP_UPDATE_REQ) { ret = dict_set_int32n(peer_data, key, keylen, 1); @@ -3612,31 +3891,33 @@ glusterd_spawn_daemons(void *opaque) glusterd_conf_t *conf = THIS->private; int ret = -1; - synclock_lock(&conf->big_lock); - glusterd_restart_bricks(); + /* glusterd_restart_brick() will take the sync_lock. */ + glusterd_restart_bricks(NULL); glusterd_restart_gsyncds(conf); glusterd_restart_rebalance(conf); ret = glusterd_snapdsvc_restart(); - ret = glusterd_tierdsvc_restart(); ret = glusterd_gfproxydsvc_restart(); + ret = glusterd_shdsvc_restart(); return ret; } -int32_t +static int32_t glusterd_import_friend_volume_opts(dict_t *peer_data, int count, glusterd_volinfo_t *volinfo, char *prefix) { - char key[512] = ""; + char key[64]; int keylen; int32_t ret = -1; int opt_count = 0; char msg[2048] = ""; - char volume_prefix[1024] = ""; + char volume_prefix[32]; GF_ASSERT(peer_data); GF_ASSERT(volinfo); - keylen = snprintf(key, sizeof(key), "%s%d.opt-count", prefix, count); + snprintf(volume_prefix, sizeof(volume_prefix), "%s%d", prefix, count); + + keylen = snprintf(key, sizeof(key), "%s.opt-count", volume_prefix); ret = dict_get_int32n(peer_data, key, keylen, &opt_count); if (ret) { snprintf(msg, sizeof(msg), @@ -3646,7 +3927,6 @@ glusterd_import_friend_volume_opts(dict_t *peer_data, int count, goto out; } - snprintf(volume_prefix, sizeof(volume_prefix), "%s%d", prefix, count); ret = import_prdict_dict(peer_data, volinfo->dict, "key", "value", opt_count, volume_prefix); if (ret) { @@ -3657,7 +3937,7 @@ glusterd_import_friend_volume_opts(dict_t *peer_data, int count, goto out; } - keylen = snprintf(key, sizeof(key), "%s%d.gsync-count", prefix, count); + keylen = snprintf(key, sizeof(key), "%s.gsync-count", volume_prefix); ret = dict_get_int32n(peer_data, key, keylen, &opt_count); if (ret) { snprintf(msg, sizeof(msg), @@ -3685,18 +3965,111 @@ out: return ret; } +static int32_t +glusterd_import_new_ta_brick(dict_t *peer_data, int32_t vol_count, + int32_t brick_count, + glusterd_brickinfo_t **ta_brickinfo, char *prefix) +{ + char key[128]; + char key_prefix[64]; + int keylen; + int ret = -1; + char *hostname = NULL; + char *path = NULL; + char *brick_id = NULL; + int decommissioned = 0; + glusterd_brickinfo_t *new_ta_brickinfo = NULL; + char msg[256] = ""; + char *brick_uuid_str = NULL; + + GF_ASSERT(peer_data); + GF_ASSERT(vol_count >= 0); + GF_ASSERT(ta_brickinfo); + GF_ASSERT(prefix); + + ret = snprintf(key_prefix, sizeof(key_prefix), "%s%d.ta-brick%d", prefix, + vol_count, brick_count); + + if (ret < 0 || ret >= sizeof(key_prefix)) { + ret = -1; + snprintf(msg, sizeof(msg), "key_prefix too long"); + goto out; + } + + keylen = snprintf(key, sizeof(key), "%s.hostname", key_prefix); + ret = dict_get_strn(peer_data, key, keylen, &hostname); + if (ret) { + snprintf(msg, sizeof(msg), "%s missing in payload", key); + goto out; + } + + keylen = snprintf(key, sizeof(key), "%s.path", key_prefix); + ret = dict_get_strn(peer_data, key, keylen, &path); + if (ret) { + snprintf(msg, sizeof(msg), "%s missing in payload", key); + goto out; + } + + keylen = snprintf(key, sizeof(key), "%s.brick_id", key_prefix); + ret = dict_get_strn(peer_data, key, keylen, &brick_id); + + keylen = snprintf(key, sizeof(key), "%s.decommissioned", key_prefix); + ret = dict_get_int32n(peer_data, key, keylen, &decommissioned); + if (ret) { + /* For backward compatibility */ + ret = 0; + } + + ret = glusterd_brickinfo_new(&new_ta_brickinfo); + if (ret) + goto out; + + ret = snprintf(new_ta_brickinfo->path, sizeof(new_ta_brickinfo->path), "%s", + path); + if (ret < 0 || ret >= sizeof(new_ta_brickinfo->path)) { + ret = -1; + goto out; + } + ret = snprintf(new_ta_brickinfo->hostname, + sizeof(new_ta_brickinfo->hostname), "%s", hostname); + if (ret < 0 || ret >= sizeof(new_ta_brickinfo->hostname)) { + ret = -1; + goto out; + } + new_ta_brickinfo->decommissioned = decommissioned; + if (brick_id) + (void)snprintf(new_ta_brickinfo->brick_id, + sizeof(new_ta_brickinfo->brick_id), "%s", brick_id); + keylen = snprintf(key, sizeof(key), "%s.uuid", key_prefix); + ret = dict_get_strn(peer_data, key, keylen, &brick_uuid_str); + if (ret) + goto out; + gf_uuid_parse(brick_uuid_str, new_ta_brickinfo->uuid); + + *ta_brickinfo = new_ta_brickinfo; + +out: + if (msg[0]) { + gf_msg("glusterd", GF_LOG_ERROR, 0, GD_MSG_BRICK_IMPORT_FAIL, "%s", + msg); + gf_event(EVENT_IMPORT_BRICK_FAILED, "peer=%s;ta-brick=%s", + new_ta_brickinfo->hostname, new_ta_brickinfo->path); + } + gf_msg_debug("glusterd", 0, "Returning with %d", ret); + return ret; +} + /* The prefix represents the type of volume to be added. * It will be "volume" for normal volumes, and snap# like * snap1, snap2, for snapshot volumes */ -int32_t +static int32_t glusterd_import_new_brick(dict_t *peer_data, int32_t vol_count, int32_t brick_count, glusterd_brickinfo_t **brickinfo, char *prefix) { - char key[512] = { - 0, - }; + char key[128]; + char key_prefix[64]; int keylen; int ret = -1; char *hostname = NULL; @@ -3704,7 +4077,7 @@ glusterd_import_new_brick(dict_t *peer_data, int32_t vol_count, char *brick_id = NULL; int decommissioned = 0; glusterd_brickinfo_t *new_brickinfo = NULL; - char msg[2048] = ""; + char msg[256] = ""; char *brick_uuid_str = NULL; GF_ASSERT(peer_data); @@ -3712,28 +4085,31 @@ glusterd_import_new_brick(dict_t *peer_data, int32_t vol_count, GF_ASSERT(brickinfo); GF_ASSERT(prefix); - keylen = snprintf(key, sizeof(key), "%s%d.brick%d.hostname", prefix, - vol_count, brick_count); + ret = snprintf(key_prefix, sizeof(key_prefix), "%s%d.brick%d", prefix, + vol_count, brick_count); + if (ret < 0 || ret >= sizeof(key_prefix)) { + ret = -1; + snprintf(msg, sizeof(msg), "key_prefix too long"); + goto out; + } + keylen = snprintf(key, sizeof(key), "%s.hostname", key_prefix); ret = dict_get_strn(peer_data, key, keylen, &hostname); if (ret) { snprintf(msg, sizeof(msg), "%s missing in payload", key); goto out; } - keylen = snprintf(key, sizeof(key), "%s%d.brick%d.path", prefix, vol_count, - brick_count); + keylen = snprintf(key, sizeof(key), "%s.path", key_prefix); ret = dict_get_strn(peer_data, key, keylen, &path); if (ret) { snprintf(msg, sizeof(msg), "%s missing in payload", key); goto out; } - keylen = snprintf(key, sizeof(key), "%s%d.brick%d.brick_id", prefix, - vol_count, brick_count); + keylen = snprintf(key, sizeof(key), "%s.brick_id", key_prefix); ret = dict_get_strn(peer_data, key, keylen, &brick_id); - keylen = snprintf(key, sizeof(key), "%s%d.brick%d.decommissioned", prefix, - vol_count, brick_count); + keylen = snprintf(key, sizeof(key), "%s.decommissioned", key_prefix); ret = dict_get_int32n(peer_data, key, keylen, &decommissioned); if (ret) { /* For backward compatibility */ @@ -3761,13 +4137,12 @@ glusterd_import_new_brick(dict_t *peer_data, int32_t vol_count, (void)snprintf(new_brickinfo->brick_id, sizeof(new_brickinfo->brick_id), "%s", brick_id); - snprintf(key, sizeof(key), "%s%d.brick%d", prefix, vol_count, brick_count); - ret = gd_import_new_brick_snap_details(peer_data, key, new_brickinfo); + ret = gd_import_new_brick_snap_details(peer_data, key_prefix, + new_brickinfo); if (ret) goto out; - keylen = snprintf(key, sizeof(key), "%s%d.brick%d.uuid", prefix, vol_count, - brick_count); + keylen = snprintf(key, sizeof(key), "%s.uuid", key_prefix); ret = dict_get_strn(peer_data, key, keylen, &brick_uuid_str); if (ret) goto out; @@ -3778,8 +4153,9 @@ out: if (msg[0]) { gf_msg("glusterd", GF_LOG_ERROR, 0, GD_MSG_BRICK_IMPORT_FAIL, "%s", msg); - gf_event(EVENT_IMPORT_BRICK_FAILED, "peer=%s;brick=%s", - new_brickinfo->hostname, new_brickinfo->path); + if (new_brickinfo) + gf_event(EVENT_IMPORT_BRICK_FAILED, "peer=%s;brick=%s", + new_brickinfo->hostname, new_brickinfo->path); } gf_msg_debug("glusterd", 0, "Returning with %d", ret); return ret; @@ -3795,8 +4171,10 @@ glusterd_import_bricks(dict_t *peer_data, int32_t vol_count, { int ret = -1; int brick_count = 1; + int ta_brick_count = 1; int brickid = 0; glusterd_brickinfo_t *new_brickinfo = NULL; + glusterd_brickinfo_t *new_ta_brickinfo = NULL; GF_ASSERT(peer_data); GF_ASSERT(vol_count >= 0); @@ -3815,6 +4193,19 @@ glusterd_import_bricks(dict_t *peer_data, int32_t vol_count, cds_list_add_tail(&new_brickinfo->brick_list, &new_volinfo->bricks); brick_count++; } + + if (new_volinfo->thin_arbiter_count == 1) { + while (ta_brick_count <= new_volinfo->subvol_count) { + ret = glusterd_import_new_ta_brick(peer_data, vol_count, + ta_brick_count, + &new_ta_brickinfo, prefix); + if (ret) + goto out; + cds_list_add_tail(&new_ta_brickinfo->brick_list, + &new_volinfo->ta_bricks); + ta_brick_count++; + } + } ret = 0; out: gf_msg_debug("glusterd", 0, "Returning with %d", ret); @@ -3833,7 +4224,8 @@ glusterd_import_quota_conf(dict_t *peer_data, int vol_idx, int gfid_count = 0; int ret = -1; int fd = -1; - char key[PATH_MAX] = ""; + char key[128]; + char key_prefix[64]; int keylen; char *gfid_str = NULL; uuid_t gfid = { @@ -3862,37 +4254,47 @@ glusterd_import_quota_conf(dict_t *peer_data, int vol_idx, goto out; } - snprintf(key, sizeof(key), "%s%d.quota-cksum", prefix, vol_idx); + ret = snprintf(key_prefix, sizeof(key_prefix), "%s%d", prefix, vol_idx); + if (ret < 0 || ret >= sizeof(key_prefix)) { + ret = -1; + gf_msg_debug(this->name, 0, "Failed to set key_prefix for quota conf"); + goto out; + } + snprintf(key, sizeof(key), "%s.quota-cksum", key_prefix); ret = dict_get_uint32(peer_data, key, &new_volinfo->quota_conf_cksum); if (ret) gf_msg_debug(this->name, 0, "Failed to get quota cksum"); - snprintf(key, sizeof(key), "%s%d.quota-version", prefix, vol_idx); + snprintf(key, sizeof(key), "%s.quota-version", key_prefix); ret = dict_get_uint32(peer_data, key, &new_volinfo->quota_conf_version); if (ret) gf_msg_debug(this->name, 0, "Failed to get quota " "version"); - keylen = snprintf(key, sizeof(key), "%s%d.gfid-count", prefix, vol_idx); + keylen = snprintf(key, sizeof(key), "%s.gfid-count", key_prefix); ret = dict_get_int32n(peer_data, key, keylen, &gfid_count); - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, + "Key=%s", key, NULL); goto out; + } ret = glusterd_quota_conf_write_header(fd); if (ret) goto out; - gfid_idx = 0; for (gfid_idx = 0; gfid_idx < gfid_count; gfid_idx++) { - keylen = snprintf(key, sizeof(key) - 1, "%s%d.gfid%d", prefix, vol_idx, + keylen = snprintf(key, sizeof(key) - 1, "%s.gfid%d", key_prefix, gfid_idx); ret = dict_get_strn(peer_data, key, keylen, &gfid_str); - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, + "Key=%s", key, NULL); goto out; + } - snprintf(key, sizeof(key) - 1, "%s%d.gfid-type%d", prefix, vol_idx, - gfid_idx); + snprintf(key, sizeof(key) - 1, "%s.gfid-type%d", key_prefix, gfid_idx); ret = dict_get_int8(peer_data, key, &gfid_type); if (ret) gfid_type = GF_QUOTA_CONF_TYPE_USAGE; @@ -3947,32 +4349,37 @@ gd_import_friend_volume_rebal_dict(dict_t *dict, int count, int ret = -1; char key[64] = ""; int dict_count = 0; - char prefix[64] = ""; + char key_prefix[32]; GF_ASSERT(dict); GF_ASSERT(volinfo); + xlator_t *this = THIS; + GF_ASSERT(this); - ret = snprintf(key, sizeof(key), "volume%d.rebal-dict-count", count); + snprintf(key_prefix, sizeof(key_prefix), "volume%d", count); + ret = snprintf(key, sizeof(key), "%s.rebal-dict-count", key_prefix); ret = dict_get_int32n(dict, key, ret, &dict_count); if (ret) { /* Older peers will not have this dict */ + gf_smsg(this->name, GF_LOG_INFO, errno, GD_MSG_DICT_GET_FAILED, + "Key=%s", key, NULL); ret = 0; goto out; } volinfo->rebal.dict = dict_new(); if (!volinfo->rebal.dict) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_CREATE_FAIL, NULL); ret = -1; goto out; } - snprintf(prefix, sizeof(prefix), "volume%d", count); ret = import_prdict_dict(dict, volinfo->rebal.dict, "rebal-dict-key", - "rebal-dict-value", dict_count, prefix); + "rebal-dict-value", dict_count, key_prefix); out: if (ret && volinfo->rebal.dict) dict_unref(volinfo->rebal.dict); - gf_msg_debug(THIS->name, 0, "Returning with %d", ret); + gf_msg_debug(this->name, 0, "Returning with %d", ret); return ret; } @@ -3985,7 +4392,8 @@ glusterd_import_volinfo(dict_t *peer_data, int count, glusterd_volinfo_t **volinfo, char *prefix) { int ret = -1; - char key[256] = ""; + char key[64] = ""; + char key_prefix[32]; int keylen; char *parent_volname = NULL; char *volname = NULL; @@ -4002,21 +4410,27 @@ glusterd_import_volinfo(dict_t *peer_data, int count, GF_ASSERT(volinfo); GF_ASSERT(prefix); - keylen = snprintf(key, sizeof(key), "%s%d.name", prefix, count); + ret = snprintf(key_prefix, sizeof(key_prefix), "%s%d", prefix, count); + if (ret < 0 || ret >= sizeof(key_prefix)) { + ret = -1; + snprintf(msg, sizeof(msg), "key_prefix too big"); + goto out; + } + + keylen = snprintf(key, sizeof(key), "%s.name", key_prefix); ret = dict_get_strn(peer_data, key, keylen, &volname); if (ret) { snprintf(msg, sizeof(msg), "%s missing in payload", key); goto out; } - snprintf(key, sizeof(key), "%s%d.stage_deleted", prefix, count); + snprintf(key, sizeof(key), "%s.stage_deleted", key_prefix); ret = dict_get_uint32(peer_data, key, &stage_deleted); /* stage_deleted = 1 means the volume is still in the process of * deleting a volume, so we shouldn't be trying to create a * fresh volume here which would lead to a stale entry */ if (stage_deleted) { - ret = 0; goto out; } @@ -4029,7 +4443,7 @@ glusterd_import_volinfo(dict_t *peer_data, int count, ret = -1; goto out; } - keylen = snprintf(key, sizeof(key), "%s%d.type", prefix, count); + keylen = snprintf(key, sizeof(key), "%s.type", key_prefix); ret = dict_get_int32n(peer_data, key, keylen, &new_volinfo->type); if (ret) { snprintf(msg, sizeof(msg), "%s missing in payload for %s", key, @@ -4037,7 +4451,7 @@ glusterd_import_volinfo(dict_t *peer_data, int count, goto out; } - keylen = snprintf(key, sizeof(key), "%s%d.parent_volname", prefix, count); + keylen = snprintf(key, sizeof(key), "%s.parent_volname", key_prefix); ret = dict_get_strn(peer_data, key, keylen, &parent_volname); if (!ret) { ret = snprintf(new_volinfo->parent_volname, @@ -4048,7 +4462,7 @@ glusterd_import_volinfo(dict_t *peer_data, int count, goto out; } } - keylen = snprintf(key, sizeof(key), "%s%d.brick_count", prefix, count); + keylen = snprintf(key, sizeof(key), "%s.brick_count", key_prefix); ret = dict_get_int32n(peer_data, key, keylen, &new_volinfo->brick_count); if (ret) { snprintf(msg, sizeof(msg), "%s missing in payload for %s", key, @@ -4056,7 +4470,7 @@ glusterd_import_volinfo(dict_t *peer_data, int count, goto out; } - keylen = snprintf(key, sizeof(key), "%s%d.version", prefix, count); + keylen = snprintf(key, sizeof(key), "%s.version", key_prefix); ret = dict_get_int32n(peer_data, key, keylen, &new_volinfo->version); if (ret) { snprintf(msg, sizeof(msg), "%s missing in payload for %s", key, @@ -4064,7 +4478,7 @@ glusterd_import_volinfo(dict_t *peer_data, int count, goto out; } - keylen = snprintf(key, sizeof(key), "%s%d.status", prefix, count); + keylen = snprintf(key, sizeof(key), "%s.status", key_prefix); ret = dict_get_int32n(peer_data, key, keylen, (int32_t *)&new_volinfo->status); if (ret) { @@ -4073,7 +4487,7 @@ glusterd_import_volinfo(dict_t *peer_data, int count, goto out; } - keylen = snprintf(key, sizeof(key), "%s%d.sub_count", prefix, count); + keylen = snprintf(key, sizeof(key), "%s.sub_count", key_prefix); ret = dict_get_int32n(peer_data, key, keylen, &new_volinfo->sub_count); if (ret) { snprintf(msg, sizeof(msg), "%s missing in payload for %s", key, @@ -4081,9 +4495,17 @@ glusterd_import_volinfo(dict_t *peer_data, int count, goto out; } + keylen = snprintf(key, sizeof(key), "%s.subvol_count", key_prefix); + ret = dict_get_int32n(peer_data, key, keylen, &new_volinfo->subvol_count); + if (ret) { + snprintf(msg, sizeof(msg), "%s missing in payload for %s", key, + volname); + goto out; + } + /* not having a 'stripe_count' key is not a error (as peer may be of old version) */ - keylen = snprintf(key, sizeof(key), "%s%d.stripe_count", prefix, count); + keylen = snprintf(key, sizeof(key), "%s.stripe_count", key_prefix); ret = dict_get_int32n(peer_data, key, keylen, &new_volinfo->stripe_count); if (ret) gf_msg(THIS->name, GF_LOG_INFO, 0, GD_MSG_DICT_GET_FAILED, @@ -4091,7 +4513,7 @@ glusterd_import_volinfo(dict_t *peer_data, int count, /* not having a 'replica_count' key is not a error (as peer may be of old version) */ - keylen = snprintf(key, sizeof(key), "%s%d.replica_count", prefix, count); + keylen = snprintf(key, sizeof(key), "%s.replica_count", key_prefix); ret = dict_get_int32n(peer_data, key, keylen, &new_volinfo->replica_count); if (ret) gf_msg(THIS->name, GF_LOG_INFO, 0, GD_MSG_DICT_GET_FAILED, @@ -4099,15 +4521,24 @@ glusterd_import_volinfo(dict_t *peer_data, int count, /* not having a 'arbiter_count' key is not a error (as peer may be of old version) */ - keylen = snprintf(key, sizeof(key), "%s%d.arbiter_count", prefix, count); + keylen = snprintf(key, sizeof(key), "%s.arbiter_count", key_prefix); ret = dict_get_int32n(peer_data, key, keylen, &new_volinfo->arbiter_count); if (ret) gf_msg(THIS->name, GF_LOG_INFO, 0, GD_MSG_DICT_GET_FAILED, "peer is possibly old version"); + /* not having a 'thin_arbiter_count' key is not a error + (as peer may be of old version) */ + keylen = snprintf(key, sizeof(key), "%s.thin_arbiter_count", key_prefix); + ret = dict_get_int32n(peer_data, key, keylen, + &new_volinfo->thin_arbiter_count); + if (ret) + gf_msg(THIS->name, GF_LOG_INFO, 0, GD_MSG_DICT_GET_FAILED, + "peer is possibly old version"); + /* not having a 'disperse_count' key is not a error (as peer may be of old version) */ - keylen = snprintf(key, sizeof(key), "%s%d.disperse_count", prefix, count); + keylen = snprintf(key, sizeof(key), "%s.disperse_count", key_prefix); ret = dict_get_int32n(peer_data, key, keylen, &new_volinfo->disperse_count); if (ret) gf_msg(THIS->name, GF_LOG_INFO, 0, GD_MSG_DICT_GET_FAILED, @@ -4115,7 +4546,7 @@ glusterd_import_volinfo(dict_t *peer_data, int count, /* not having a 'redundancy_count' key is not a error (as peer may be of old version) */ - keylen = snprintf(key, sizeof(key), "%s%d.redundancy_count", prefix, count); + keylen = snprintf(key, sizeof(key), "%s.redundancy_count", key_prefix); ret = dict_get_int32n(peer_data, key, keylen, &new_volinfo->redundancy_count); if (ret) @@ -4124,92 +4555,16 @@ glusterd_import_volinfo(dict_t *peer_data, int count, /* not having a 'dist_count' key is not a error (as peer may be of old version) */ - keylen = snprintf(key, sizeof(key), "%s%d.dist_count", prefix, count); + keylen = snprintf(key, sizeof(key), "%s.dist_count", key_prefix); ret = dict_get_int32n(peer_data, key, keylen, &new_volinfo->dist_leaf_count); if (ret) gf_msg(THIS->name, GF_LOG_INFO, 0, GD_MSG_DICT_GET_FAILED, "peer is possibly old version"); - /* not having a 'hot_brick_count' key is not a error - (as peer may be of old version) */ - keylen = snprintf(key, sizeof(key), "%s%d.hot_brick_count", prefix, count); - ret = dict_get_int32n(peer_data, key, keylen, - &new_volinfo->tier_info.hot_brick_count); - if (ret) - gf_msg_debug(THIS->name, 0, "peer is possibly old version"); - - /* not having a 'hot_type' key is not a error - (as peer may be of old version) */ - keylen = snprintf(key, sizeof(key), "%s%d.hot_type", prefix, count); - ret = dict_get_int32n(peer_data, key, keylen, - &new_volinfo->tier_info.hot_type); - if (ret) - gf_msg_debug(THIS->name, 0, "peer is possibly old version"); - - /* not having a 'hot_replica_count' key is not a error - (as peer may be of old version) */ - keylen = snprintf(key, sizeof(key), "%s%d.hot_replica_count", prefix, - count); - ret = dict_get_int32n(peer_data, key, keylen, - &new_volinfo->tier_info.hot_replica_count); - if (ret) - gf_msg_debug(THIS->name, 0, "peer is possibly old version"); - - /* not having a 'cold_brick_count' key is not a error - (as peer may be of old version) */ - keylen = snprintf(key, sizeof(key), "%s%d.cold_brick_count", prefix, count); - ret = dict_get_int32n(peer_data, key, keylen, - &new_volinfo->tier_info.cold_brick_count); - if (ret) - gf_msg_debug(THIS->name, 0, "peer is possibly old version"); - - /* not having a 'cold_type' key is not a error - (as peer may be of old version) */ - keylen = snprintf(key, sizeof(key), "%s%d.cold_type", prefix, count); - ret = dict_get_int32n(peer_data, key, keylen, - &new_volinfo->tier_info.cold_type); - if (ret) - gf_msg_debug(THIS->name, 0, "peer is possibly old version"); - - /* not having a 'cold_replica_count' key is not a error - (as peer may be of old version) */ - keylen = snprintf(key, sizeof(key), "%s%d.cold_replica_count", prefix, - count); - ret = dict_get_int32n(peer_data, key, keylen, - &new_volinfo->tier_info.cold_replica_count); - if (ret) - gf_msg_debug(THIS->name, 0, "peer is possibly old version"); - - /* not having a 'cold_disperse_count' key is not a error - (as peer may be of old version) */ - keylen = snprintf(key, sizeof(key), "%s%d.cold_disperse_count", prefix, - count); - ret = dict_get_int32n(peer_data, key, keylen, - &new_volinfo->tier_info.cold_disperse_count); - if (ret) - gf_msg_debug(THIS->name, 0, "peer is possibly old version"); - - /* not having a 'cold_redundancy_count' key is not a error - (as peer may be of old version) */ - keylen = snprintf(key, sizeof(key), "%s%d.cold_redundancy_count", prefix, - count); - ret = dict_get_int32n(peer_data, key, keylen, - &new_volinfo->tier_info.cold_redundancy_count); - if (ret) - gf_msg_debug(THIS->name, 0, "peer is possibly old version"); - - /* not having a 'cold_dist_count' key is not a error - (as peer may be of old version) */ - keylen = snprintf(key, sizeof(key), "%s%d.cold_dist_count", prefix, count); - ret = dict_get_int32n(peer_data, key, keylen, - &new_volinfo->tier_info.cold_dist_leaf_count); - if (ret) - gf_msg_debug(THIS->name, 0, "peer is possibly old version"); - new_volinfo->subvol_count = new_volinfo->brick_count / glusterd_get_dist_leaf_count(new_volinfo); - snprintf(key, sizeof(key), "%s%d.ckusm", prefix, count); + snprintf(key, sizeof(key), "%s.ckusm", key_prefix); ret = dict_get_uint32(peer_data, key, &new_volinfo->cksum); if (ret) { snprintf(msg, sizeof(msg), "%s missing in payload for %s", key, @@ -4217,7 +4572,7 @@ glusterd_import_volinfo(dict_t *peer_data, int count, goto out; } - keylen = snprintf(key, sizeof(key), "%s%d.volume_id", prefix, count); + keylen = snprintf(key, sizeof(key), "%s.volume_id", key_prefix); ret = dict_get_strn(peer_data, key, keylen, &volume_id_str); if (ret) { snprintf(msg, sizeof(msg), "%s missing in payload for %s", key, @@ -4227,7 +4582,7 @@ glusterd_import_volinfo(dict_t *peer_data, int count, gf_uuid_parse(volume_id_str, new_volinfo->volume_id); - keylen = snprintf(key, sizeof(key), "%s%d.username", prefix, count); + keylen = snprintf(key, sizeof(key), "%s.username", key_prefix); ret = dict_get_strn(peer_data, key, keylen, &str); if (!ret) { ret = glusterd_auth_set_username(new_volinfo, str); @@ -4235,7 +4590,7 @@ glusterd_import_volinfo(dict_t *peer_data, int count, goto out; } - keylen = snprintf(key, sizeof(key), "%s%d.password", prefix, count); + keylen = snprintf(key, sizeof(key), "%s.password", key_prefix); ret = dict_get_strn(peer_data, key, keylen, &str); if (!ret) { ret = glusterd_auth_set_password(new_volinfo, str); @@ -4243,7 +4598,7 @@ glusterd_import_volinfo(dict_t *peer_data, int count, goto out; } - snprintf(key, sizeof(key), "%s%d.transport_type", prefix, count); + snprintf(key, sizeof(key), "%s.transport_type", key_prefix); ret = dict_get_uint32(peer_data, key, &new_volinfo->transport_type); if (ret) { snprintf(msg, sizeof(msg), "%s missing in payload for %s", key, @@ -4251,7 +4606,7 @@ glusterd_import_volinfo(dict_t *peer_data, int count, goto out; } - snprintf(key, sizeof(key), "%s%d.rebalance", prefix, count); + snprintf(key, sizeof(key), "%s.rebalance", key_prefix); ret = dict_get_uint32(peer_data, key, &new_volinfo->rebal.defrag_cmd); if (ret) { snprintf(msg, sizeof(msg), "%s missing in payload for %s", key, @@ -4259,7 +4614,7 @@ glusterd_import_volinfo(dict_t *peer_data, int count, goto out; } - keylen = snprintf(key, sizeof(key), "%s%d.rebalance-id", prefix, count); + keylen = snprintf(key, sizeof(key), "%s.rebalance-id", key_prefix); ret = dict_get_strn(peer_data, key, keylen, &rebalance_id_str); if (ret) { /* This is not present in older glusterfs versions, @@ -4270,14 +4625,12 @@ glusterd_import_volinfo(dict_t *peer_data, int count, gf_uuid_parse(rebalance_id_str, new_volinfo->rebal.rebalance_id); } - snprintf(key, sizeof(key), "%s%d.rebalance-op", prefix, count); + snprintf(key, sizeof(key), "%s.rebalance-op", key_prefix); + /* This is not present in older glusterfs versions, + * so don't error out + */ ret = dict_get_uint32(peer_data, key, (uint32_t *)&new_volinfo->rebal.op); - if (ret) { - /* This is not present in older glusterfs versions, - * so don't error out - */ - ret = 0; - } + ret = gd_import_friend_volume_rebal_dict(peer_data, count, new_volinfo); if (ret) { snprintf(msg, sizeof(msg), @@ -4286,8 +4639,8 @@ glusterd_import_volinfo(dict_t *peer_data, int count, goto out; } - snprintf(key, sizeof(key), "%s%d", prefix, count); - ret = gd_import_volume_snap_details(peer_data, new_volinfo, key, volname); + ret = gd_import_volume_snap_details(peer_data, new_volinfo, key_prefix, + volname); if (ret) { gf_msg("glusterd", GF_LOG_ERROR, 0, GD_MSG_SNAP_DETAILS_IMPORT_FAIL, "Failed to import snapshot " @@ -4309,12 +4662,11 @@ glusterd_import_volinfo(dict_t *peer_data, int count, * Either both the volume op-versions should be absent or both should be * present. Only one being present is a failure */ - keylen = snprintf(key, sizeof(key), "%s%d.op-version", prefix, count); + keylen = snprintf(key, sizeof(key), "%s.op-version", key_prefix); ret = dict_get_int32n(peer_data, key, keylen, &op_version); if (ret) ret = 0; - keylen = snprintf(key, sizeof(key), "%s%d.client-op-version", prefix, - count); + keylen = snprintf(key, sizeof(key), "%s.client-op-version", key_prefix); ret = dict_get_int32n(peer_data, key, keylen, &client_op_version); if (ret) ret = 0; @@ -4333,12 +4685,7 @@ glusterd_import_volinfo(dict_t *peer_data, int count, new_volinfo->client_op_version = 1; } - keylen = snprintf(key, sizeof(key), "%s%d.caps", prefix, count); - /*This is not present in older glusterfs versions, so ignore ret value*/ - ret = dict_get_int32n(peer_data, key, keylen, &new_volinfo->caps); - - keylen = snprintf(key, sizeof(key), "%s%d.quota-xattr-version", prefix, - count); + keylen = snprintf(key, sizeof(key), "%s.quota-xattr-version", key_prefix); /*This is not present in older glusterfs versions, so ignore ret value*/ ret = dict_get_int32n(peer_data, key, keylen, &new_volinfo->quota_xattr_version); @@ -4402,6 +4749,8 @@ glusterd_volinfo_copy_brickinfo(glusterd_volinfo_t *old_volinfo, { glusterd_brickinfo_t *new_brickinfo = NULL; glusterd_brickinfo_t *old_brickinfo = NULL; + glusterd_brickinfo_t *new_ta_brickinfo = NULL; + glusterd_brickinfo_t *old_ta_brickinfo = NULL; glusterd_conf_t *priv = NULL; int ret = 0; xlator_t *this = NULL; @@ -4450,6 +4799,46 @@ glusterd_volinfo_copy_brickinfo(glusterd_volinfo_t *old_volinfo, } } } + if (new_volinfo->thin_arbiter_count == 1) { + cds_list_for_each_entry(new_ta_brickinfo, &new_volinfo->ta_bricks, + brick_list) + { + ret = glusterd_volume_ta_brickinfo_get( + new_ta_brickinfo->uuid, new_ta_brickinfo->hostname, + new_ta_brickinfo->path, old_volinfo, &old_ta_brickinfo); + if (ret == 0) { + new_ta_brickinfo->port = old_ta_brickinfo->port; + + if (old_ta_brickinfo->real_path[0] == '\0') { + if (!realpath(new_ta_brickinfo->path, abspath)) { + /* Here an ENOENT should also be a + * failure as the brick is expected to + * be in existence + */ + gf_msg(this->name, GF_LOG_CRITICAL, errno, + GD_MSG_BRICKINFO_CREATE_FAIL, + "realpath () failed for brick " + "%s. The underlying filesystem " + "may be in bad state", + new_brickinfo->path); + ret = -1; + goto out; + } + if (strlen(abspath) >= + sizeof(new_ta_brickinfo->real_path)) { + ret = -1; + goto out; + } + (void)strncpy(new_ta_brickinfo->real_path, abspath, + sizeof(new_ta_brickinfo->real_path)); + } else { + (void)strncpy(new_ta_brickinfo->real_path, + old_ta_brickinfo->real_path, + sizeof(new_ta_brickinfo->real_path)); + } + } + } + } ret = 0; out: @@ -4474,10 +4863,11 @@ glusterd_volinfo_stop_stale_bricks(glusterd_volinfo_t *new_volinfo, old_brickinfo->uuid, old_brickinfo->hostname, old_brickinfo->path, new_volinfo, &new_brickinfo); /* If the brick is stale, i.e it's not a part of the new volume - * or if it's part of the new volume and is pending a snap, - * then stop the brick process + * or if it's part of the new volume and is pending a snap or if it's + * brick multiplexing enabled, then stop the brick process */ - if (ret || (new_brickinfo->snap_status == -1)) { + if (ret || (new_brickinfo->snap_status == -1) || + GF_ATOMIC_GET(old_volinfo->volpeerupdate)) { /*TODO: may need to switch to 'atomic' flavour of * brick_stop, once we make peer rpc program also * synctask enabled*/ @@ -4569,6 +4959,9 @@ glusterd_delete_stale_volume(glusterd_volinfo_t *stale_volinfo, svc = &(stale_volinfo->snapd.svc); (void)svc->manager(svc, stale_volinfo, PROC_START_NO_WAIT); } + svc = &(stale_volinfo->shd.svc); + (void)svc->manager(svc, stale_volinfo, PROC_START_NO_WAIT); + (void)glusterd_volinfo_remove(stale_volinfo); return 0; @@ -4615,14 +5008,14 @@ gd_check_and_update_rebalance_info(glusterd_volinfo_t *old_volinfo, new->rebalance_time = old->rebalance_time; /* glusterd_rebalance_t.{op, id, defrag_cmd} are copied during volume - * import - * a new defrag object should come to life with rebalance being restarted + * import a new defrag object should come to life with rebalance being + * restarted */ out: return ret; } -int32_t +static int32_t glusterd_import_friend_volume(dict_t *peer_data, int count) { int32_t ret = -1; @@ -4643,8 +5036,15 @@ glusterd_import_friend_volume(dict_t *peer_data, int count) ret = snprintf(key, sizeof(key), "volume%d.update", count); ret = dict_get_int32n(peer_data, key, ret, &update); - if (ret || !update) { + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, + "Key=%s", key, NULL); + goto out; + } + + if (!update) { /* if update is 0 that means the volume is not imported */ + gf_smsg(this->name, GF_LOG_INFO, 0, GD_MSG_VOLUME_NOT_IMPORTED, NULL); goto out; } @@ -4683,16 +5083,6 @@ glusterd_import_friend_volume(dict_t *peer_data, int count) glusterd_volinfo_unref(old_volinfo); } - if (glusterd_is_volume_started(new_volinfo)) { - (void)glusterd_start_bricks(new_volinfo); - if (glusterd_is_snapd_enabled(new_volinfo)) { - svc = &(new_volinfo->snapd.svc); - if (svc->manager(svc, new_volinfo, PROC_START_NO_WAIT)) { - gf_event(EVENT_SVC_MANAGER_FAILED, "svc_name=%s", svc->name); - } - } - } - ret = glusterd_store_volinfo(new_volinfo, GLUSTERD_VOLINFO_VER_AC_NONE); if (ret) { gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_VOLINFO_STORE_FAIL, @@ -4702,19 +5092,35 @@ glusterd_import_friend_volume(dict_t *peer_data, int count) goto out; } - ret = glusterd_create_volfiles_and_notify_services(new_volinfo); + ret = glusterd_create_volfiles(new_volinfo); if (ret) goto out; + glusterd_list_add_order(&new_volinfo->vol_list, &priv->volumes, + glusterd_compare_volume_name); + + if (glusterd_is_volume_started(new_volinfo)) { + (void)glusterd_start_bricks(new_volinfo); + if (glusterd_is_snapd_enabled(new_volinfo)) { + svc = &(new_volinfo->snapd.svc); + if (svc->manager(svc, new_volinfo, PROC_START_NO_WAIT)) { + gf_event(EVENT_SVC_MANAGER_FAILED, "svc_name=%s", svc->name); + } + } + svc = &(new_volinfo->shd.svc); + if (svc->manager(svc, new_volinfo, PROC_START_NO_WAIT)) { + gf_event(EVENT_SVC_MANAGER_FAILED, "svc_name=%s", svc->name); + } + } + ret = glusterd_import_quota_conf(peer_data, count, new_volinfo, "volume"); if (ret) { gf_event(EVENT_IMPORT_QUOTA_CONF_FAILED, "volume=%s", new_volinfo->volname); goto out; } - glusterd_list_add_order(&new_volinfo->vol_list, &priv->volumes, - glusterd_compare_volume_name); + ret = glusterd_fetchspec_notify(this); out: gf_msg_debug("glusterd", 0, "Returning with ret: %d", ret); return ret; @@ -4729,6 +5135,7 @@ glusterd_import_friend_volumes_synctask(void *opaque) xlator_t *this = NULL; glusterd_conf_t *conf = NULL; dict_t *peer_data = NULL; + glusterd_friend_synctask_args_t *arg = NULL; this = THIS; GF_ASSERT(this); @@ -4736,12 +5143,30 @@ glusterd_import_friend_volumes_synctask(void *opaque) conf = this->private; GF_ASSERT(conf); - peer_data = (dict_t *)opaque; - GF_ASSERT(peer_data); + arg = opaque; + if (!arg) + goto out; + + peer_data = dict_new(); + if (!peer_data) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_CREATE_FAIL, NULL); + goto out; + } + + ret = dict_unserialize(arg->dict_buf, arg->dictlen, &peer_data); + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_UNSERIALIZE_FAIL, + NULL); + errno = ENOMEM; + goto out; + } ret = dict_get_int32n(peer_data, "count", SLEN("count"), &count); - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, + "Key=count", NULL); goto out; + } synclock_lock(&conf->big_lock); @@ -4750,25 +5175,30 @@ glusterd_import_friend_volumes_synctask(void *opaque) * restarted (refer glusterd_restart_bricks ()) */ while (conf->restart_bricks) { - synclock_unlock(&conf->big_lock); - sleep(2); - synclock_lock(&conf->big_lock); + synccond_wait(&conf->cond_restart_bricks, &conf->big_lock); } conf->restart_bricks = _gf_true; while (i <= count) { ret = glusterd_import_friend_volume(peer_data, i); if (ret) { - conf->restart_bricks = _gf_false; - goto out; + break; } i++; } - glusterd_svcs_manager(NULL); + if (i > count) { + glusterd_svcs_manager(NULL); + } conf->restart_bricks = _gf_false; + synccond_broadcast(&conf->cond_restart_bricks); out: if (peer_data) dict_unref(peer_data); + if (arg) { + if (arg->dict_buf) + GF_FREE(arg->dict_buf); + GF_FREE(arg); + } gf_msg_debug("glusterd", 0, "Returning with %d", ret); return ret; @@ -4784,8 +5214,11 @@ glusterd_import_friend_volumes(dict_t *peer_data) GF_ASSERT(peer_data); ret = dict_get_int32n(peer_data, "count", SLEN("count"), &count); - if (ret) + if (ret) { + gf_smsg("glusterd", GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, + "Key=count", NULL); goto out; + } while (i <= count) { ret = glusterd_import_friend_volume(peer_data, i); @@ -4804,11 +5237,16 @@ glusterd_get_global_server_quorum_ratio(dict_t *opts, double *quorum) { int ret = -1; char *quorum_str = NULL; + xlator_t *this = THIS; + GF_ASSERT(this); ret = dict_get_strn(opts, GLUSTERD_QUORUM_RATIO_KEY, SLEN(GLUSTERD_QUORUM_RATIO_KEY), &quorum_str); - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, + "Key=%s", GLUSTERD_QUORUM_RATIO_KEY, NULL); goto out; + } ret = gf_string2percent(quorum_str, quorum); if (ret) @@ -4823,11 +5261,16 @@ glusterd_get_global_opt_version(dict_t *opts, uint32_t *version) { int ret = -1; char *version_str = NULL; + xlator_t *this = THIS; + GF_ASSERT(this); ret = dict_get_strn(opts, GLUSTERD_GLOBAL_OPT_VERSION, SLEN(GLUSTERD_GLOBAL_OPT_VERSION), &version_str); - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, + "Key=%s", GLUSTERD_GLOBAL_OPT_VERSION, NULL); goto out; + } ret = gf_string2uint(version_str, version); if (ret) @@ -4876,13 +5319,17 @@ glusterd_import_global_opts(dict_t *friend_data) SLEN("global-opt-count"), &count); if (ret) { // old version peer + gf_smsg(this->name, GF_LOG_INFO, errno, GD_MSG_DICT_GET_FAILED, + "Key=global-opt-count", NULL); ret = 0; goto out; } import_options = dict_new(); - if (!import_options) + if (!import_options) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_CREATE_FAIL, NULL); goto out; + } ret = import_prdict_dict(friend_data, import_options, "key", "val", count, "global"); if (ret) { @@ -4935,7 +5382,7 @@ glusterd_compare_friend_data(dict_t *peer_data, int32_t *status, char *hostname) gf_boolean_t update = _gf_false; xlator_t *this = NULL; glusterd_conf_t *priv = NULL; - dict_t *peer_data_copy = NULL; + glusterd_friend_synctask_args_t *arg = NULL; this = THIS; GF_ASSERT(this); @@ -4953,8 +5400,11 @@ glusterd_compare_friend_data(dict_t *peer_data, int32_t *status, char *hostname) } ret = dict_get_int32n(peer_data, "count", SLEN("count"), &count); - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, + "Key=count", NULL); goto out; + } while (i <= count) { ret = glusterd_compare_friend_volume(peer_data, i, status, hostname); @@ -4977,12 +5427,23 @@ glusterd_compare_friend_data(dict_t *peer_data, int32_t *status, char *hostname) * first brick to come up before attaching the subsequent bricks * in case brick multiplexing is enabled */ - peer_data_copy = dict_copy_with_ref(peer_data, NULL); - glusterd_launch_synctask(glusterd_import_friend_volumes_synctask, - peer_data_copy); + arg = GF_CALLOC(1, sizeof(*arg), gf_common_mt_char); + ret = dict_allocate_and_serialize(peer_data, &arg->dict_buf, + &arg->dictlen); + if (ret < 0) { + gf_log(this->name, GF_LOG_ERROR, + "dict_serialize failed while handling " + " import friend volume request"); + goto out; + } + + glusterd_launch_synctask(glusterd_import_friend_volumes_synctask, arg); } out: + if (ret && arg) { + GF_FREE(arg); + } gf_msg_debug(this->name, 0, "Returning with ret: %d, status: %d", ret, *status); return ret; @@ -5049,9 +5510,6 @@ glusterd_pending_node_get_rpc(glusterd_pending_node_t *pending_node) } else if (pending_node->type == GD_NODE_SNAPD) { volinfo = pending_node->node; rpc = volinfo->snapd.svc.conn.rpc; - } else if (pending_node->type == GD_NODE_TIERD) { - volinfo = pending_node->node; - rpc = volinfo->tierd.svc.conn.rpc; } else { GF_ASSERT(0); } @@ -5071,10 +5529,6 @@ glusterd_pending_node_put_rpc(glusterd_pending_node_t *pending_node) glusterd_defrag_rpc_put(volinfo->rebal.defrag); break; - case GD_NODE_TIERD: - volinfo = pending_node->node; - glusterd_defrag_rpc_put(volinfo->tier.defrag); - break; default: break; } @@ -5174,12 +5628,12 @@ glusterd_add_node_to_dict(char *server, dict_t *dict, int count, glusterd_svc_build_pidfile_path(server, priv->rundir, pidfile, sizeof(pidfile)); - if (strcmp(server, priv->shd_svc.name) == 0) - svc = &(priv->shd_svc); + if (strcmp(server, priv->quotad_svc.name) == 0) + svc = &(priv->quotad_svc); +#ifdef BUILD_GNFS else if (strcmp(server, priv->nfs_svc.name) == 0) svc = &(priv->nfs_svc); - else if (strcmp(server, priv->quotad_svc.name) == 0) - svc = &(priv->quotad_svc); +#endif else if (strcmp(server, priv->bitd_svc.name) == 0) svc = &(priv->bitd_svc); else if (strcmp(server, priv->scrub_svc.name) == 0) @@ -5204,29 +5658,35 @@ glusterd_add_node_to_dict(char *server, dict_t *dict, int count, */ keylen = snprintf(key, sizeof(key), "brick%d.hostname", count); - if (!strcmp(server, priv->nfs_svc.name)) - ret = dict_set_nstrn(dict, key, keylen, "NFS Server", - SLEN("NFS Server")); - else if (!strcmp(server, priv->shd_svc.name)) - ret = dict_set_nstrn(dict, key, keylen, "Self-heal Daemon", - SLEN("Self-heal Daemon")); - else if (!strcmp(server, priv->quotad_svc.name)) + if (!strcmp(server, priv->quotad_svc.name)) ret = dict_set_nstrn(dict, key, keylen, "Quota Daemon", SLEN("Quota Daemon")); +#ifdef BUILD_GNFS + else if (!strcmp(server, priv->nfs_svc.name)) + ret = dict_set_nstrn(dict, key, keylen, "NFS Server", + SLEN("NFS Server")); +#endif else if (!strcmp(server, priv->bitd_svc.name)) ret = dict_set_nstrn(dict, key, keylen, "Bitrot Daemon", SLEN("Bitrot Daemon")); else if (!strcmp(server, priv->scrub_svc.name)) ret = dict_set_nstrn(dict, key, keylen, "Scrubber Daemon", SLEN("Scrubber Daemon")); - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, + "Key=%s", key, NULL); goto out; + } keylen = snprintf(key, sizeof(key), "brick%d.path", count); ret = dict_set_dynstrn(dict, key, keylen, gf_strdup(uuid_utoa(MY_UUID))); - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, + "Key=%s", key, NULL); goto out; + } +#ifdef BUILD_GNFS /* Port is available only for the NFS server. * Self-heal daemon doesn't provide any port for access * by entities other than gluster. @@ -5235,25 +5695,38 @@ glusterd_add_node_to_dict(char *server, dict_t *dict, int count, if (dict_getn(vol_opts, "nfs.port", SLEN("nfs.port"))) { ret = dict_get_int32n(vol_opts, "nfs.port", SLEN("nfs.port"), &port); - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, + "Key=nfs.port", NULL); goto out; + } } else port = GF_NFS3_PORT; } +#endif keylen = snprintf(key, sizeof(key), "brick%d.port", count); ret = dict_set_int32n(dict, key, keylen, port); - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, + "Key=%s", key, NULL); goto out; + } keylen = snprintf(key, sizeof(key), "brick%d.pid", count); ret = dict_set_int32n(dict, key, keylen, pid); - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, + "Key=%s", key, NULL); goto out; + } keylen = snprintf(key, sizeof(key), "brick%d.status", count); ret = dict_set_int32n(dict, key, keylen, running); - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, + "Key=%s", key, NULL); goto out; + } out: gf_msg_debug(THIS->name, 0, "Returning %d", ret); @@ -5435,7 +5908,9 @@ my_callback(struct rpc_req *req, struct iovec *iov, int count, void *v_frame) call_frame_t *frame = v_frame; glusterd_conf_t *conf = frame->this->private; - GF_ATOMIC_DEC(conf->blockers); + if (GF_ATOMIC_DEC(conf->blockers) == 0) { + synccond_broadcast(&conf->cond_blockers); + } STACK_DESTROY(frame->root); return 0; @@ -5502,7 +5977,13 @@ attach_brick_callback(struct rpc_req *req, struct iovec *iov, int count, /* PID file is copied once brick has attached successfully */ - glusterd_copy_file(pidfile1, pidfile2); + ret = glusterd_copy_file(pidfile1, pidfile2); + if (ret) { + gf_msg(this->name, GF_LOG_ERROR, ENOMEM, GD_MSG_NO_MEMORY, + "Could not copy file %s to %s", pidfile1, pidfile2); + goto out; + } + brickinfo->status = GF_BRICK_STARTED; brickinfo->rpc = rpc_clnt_ref(other_brick->rpc); gf_log(THIS->name, GF_LOG_INFO, "brick %s is attached successfully", @@ -5531,7 +6012,9 @@ attach_brick_callback(struct rpc_req *req, struct iovec *iov, int count, } } out: - GF_ATOMIC_DEC(conf->blockers); + if (GF_ATOMIC_DEC(conf->blockers) == 0) { + synccond_broadcast(&conf->cond_blockers); + } STACK_DESTROY(frame->root); return 0; } @@ -5572,6 +6055,8 @@ send_attach_req(xlator_t *this, struct rpc_clnt *rpc, char *path, brick_req.name = path; brick_req.input.input_val = NULL; brick_req.input.input_len = 0; + brick_req.dict.dict_val = NULL; + brick_req.dict.dict_len = 0; req_size = xdr_sizeof((xdrproc_t)xdr_gd1_mgmt_brick_op_req, req); iobuf = iobuf_get2(rpc->ctx->iobuf_pool, req_size); @@ -5585,12 +6070,15 @@ send_attach_req(xlator_t *this, struct rpc_clnt *rpc, char *path, iobref = iobref_new(); if (!iobref) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_NO_MEMORY, NULL); goto *errlbl; } errlbl = &&free_iobref; frame = create_frame(this, this->ctx->pool); if (!frame) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_FRAME_CREATE_FAIL, + NULL); goto *errlbl; } @@ -5621,7 +6109,6 @@ send_attach_req(xlator_t *this, struct rpc_clnt *rpc, char *path, GF_ATOMIC_INC(conf->blockers); ret = rpc_clnt_submit(rpc, &gd_brick_prog, op, cbkfn, &iov, 1, NULL, 0, iobref, frame, NULL, 0, NULL, 0, NULL); - return ret; free_iobref: iobref_unref(iobref); @@ -5630,12 +6117,12 @@ maybe_free_iobuf: iobuf_unref(iobuf); } err: - return -1; + return ret; } extern size_t build_volfile_path(char *volume_id, char *path, size_t path_len, - char *trusted_str); + char *trusted_str, dict_t *dict); static int attach_brick(xlator_t *this, glusterd_brickinfo_t *brickinfo, @@ -5643,8 +6130,6 @@ attach_brick(xlator_t *this, glusterd_brickinfo_t *brickinfo, glusterd_volinfo_t *other_vol) { glusterd_conf_t *conf = this->private; - char pidfile1[PATH_MAX] = ""; - char pidfile2[PATH_MAX] = ""; char unslashed[PATH_MAX] = { '\0', }; @@ -5664,9 +6149,6 @@ attach_brick(xlator_t *this, glusterd_brickinfo_t *brickinfo, GLUSTERD_REMOVE_SLASH_FROM_PATH(brickinfo->path, unslashed); - GLUSTERD_GET_BRICK_PIDFILE(pidfile1, other_vol, other_brick, conf); - GLUSTERD_GET_BRICK_PIDFILE(pidfile2, volinfo, brickinfo, conf); - if (volinfo->is_snap_volume) { len = snprintf(full_id, sizeof(full_id), "/%s/%s/%s/%s.%s.%s", GLUSTERD_VOL_SNAP_DIR_PREFIX, @@ -5680,7 +6162,7 @@ attach_brick(xlator_t *this, glusterd_brickinfo_t *brickinfo, goto out; } - (void)build_volfile_path(full_id, path, sizeof(path), NULL); + (void)build_volfile_path(full_id, path, sizeof(path), NULL, NULL); for (tries = 15; tries > 0; --tries) { rpc = rpc_clnt_ref(other_brick->rpc); @@ -5719,7 +6201,7 @@ attach_brick(xlator_t *this, glusterd_brickinfo_t *brickinfo, * TBD: see if there's a better way */ synclock_unlock(&conf->big_lock); - sleep(1); + synctask_sleep(1); synclock_lock(&conf->big_lock); } @@ -5859,7 +6341,7 @@ find_compat_brick_in_vol(glusterd_conf_t *conf, "brick %s is still" " starting, waiting for 2 seconds ", other_brick->path); - sleep(2); + synctask_sleep(2); synclock_lock(&conf->big_lock); retries--; } @@ -5963,7 +6445,6 @@ find_compatible_brick(glusterd_conf_t *conf, glusterd_volinfo_t *volinfo, int glusterd_get_sock_from_brick_pid(int pid, char *sockpath, size_t len) { - char fname[128] = ""; char buf[1024] = ""; char cmdline[2048] = ""; xlator_t *this = NULL; @@ -5978,6 +6459,22 @@ glusterd_get_sock_from_brick_pid(int pid, char *sockpath, size_t len) this = THIS; GF_ASSERT(this); +#ifdef __FreeBSD__ + blen = sizeof(buf); + int mib[4]; + + mib[0] = CTL_KERN; + mib[1] = KERN_PROC; + mib[2] = KERN_PROC_ARGS; + mib[3] = pid; + + if (sys_sysctl(mib, 4, buf, &blen, NULL, blen) != 0) { + gf_log(this->name, GF_LOG_ERROR, "brick process %d is not running", + pid); + return ret; + } +#else + char fname[128] = ""; snprintf(fname, sizeof(fname), "/proc/%d/cmdline", pid); if (sys_access(fname, R_OK) != 0) { @@ -5994,6 +6491,7 @@ glusterd_get_sock_from_brick_pid(int pid, char *sockpath, size_t len) strerror(errno), fname); return ret; } +#endif /* convert cmdline to single string */ for (i = 0, j = 0; i < blen; i++) { @@ -6042,6 +6540,43 @@ glusterd_get_sock_from_brick_pid(int pid, char *sockpath, size_t len) char * search_brick_path_from_proc(pid_t brick_pid, char *brickpath) { + char *brick_path = NULL; +#ifdef __FreeBSD__ + struct filestat *fst; + struct procstat *ps; + struct kinfo_proc *kp; + struct filestat_list *head; + + ps = procstat_open_sysctl(); + if (ps == NULL) + goto out; + + kp = kinfo_getproc(brick_pid); + if (kp == NULL) + goto out; + + head = procstat_getfiles(ps, (void *)kp, 0); + if (head == NULL) + goto out; + + STAILQ_FOREACH(fst, head, next) + { + if (fst->fs_fd < 0) + continue; + + if (!strcmp(fst->fs_path, brickpath)) { + brick_path = gf_strdup(fst->fs_path); + break; + } + } + +out: + if (head != NULL) + procstat_freefiles(ps, head); + if (kp != NULL) + free(kp); + procstat_close(ps); +#else struct dirent *dp = NULL; DIR *dirp = NULL; size_t len = 0; @@ -6052,7 +6587,6 @@ search_brick_path_from_proc(pid_t brick_pid, char *brickpath) 0, }, }; - char *brick_path = NULL; if (!brickpath) goto out; @@ -6088,7 +6622,9 @@ search_brick_path_from_proc(pid_t brick_pid, char *brickpath) } } out: - sys_closedir(dirp); + if (dirp) + sys_closedir(dirp); +#endif return brick_path; } @@ -6116,8 +6652,10 @@ glusterd_brick_start(glusterd_volinfo_t *volinfo, GF_ASSERT(this); conf = this->private; - if ((!brickinfo) || (!volinfo)) + if ((!brickinfo) || (!volinfo)) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_INVALID_ARGUMENT, NULL); goto out; + } if (gf_uuid_is_null(brickinfo->uuid)) { ret = glusterd_resolve_brick(brickinfo); @@ -6142,7 +6680,8 @@ glusterd_brick_start(glusterd_volinfo_t *volinfo, * three different triggers for an attempt to start the brick process * due to the quorum handling code in glusterd_friend_sm. */ - if (brickinfo->status == GF_BRICK_STARTING || brickinfo->start_triggered) { + if (brickinfo->status == GF_BRICK_STARTING || brickinfo->start_triggered || + GF_ATOMIC_GET(volinfo->volpeerupdate)) { gf_msg_debug(this->name, 0, "brick %s is already in starting " "phase", @@ -6341,14 +6880,14 @@ glusterd_restart_bricks(void *opaque) conf = this->private; GF_VALIDATE_OR_GOTO(this->name, conf, return_block); + synclock_lock(&conf->big_lock); + /* We need to ensure that restarting the bricks during glusterd restart * shouldn't race with the import volume thread (refer * glusterd_compare_friend_data ()) */ while (conf->restart_bricks) { - synclock_unlock(&conf->big_lock); - sleep(2); - synclock_lock(&conf->big_lock); + synccond_wait(&conf->cond_restart_bricks, &conf->big_lock); } conf->restart_bricks = _gf_true; @@ -6438,6 +6977,7 @@ glusterd_restart_bricks(void *opaque) if (!brickinfo->start_triggered) { pthread_mutex_lock(&brickinfo->restart_mutex); { + /* coverity[SLEEP] */ glusterd_brick_start(volinfo, brickinfo, _gf_false, _gf_false); } @@ -6461,9 +7001,12 @@ glusterd_restart_bricks(void *opaque) ret = 0; out: - GF_ATOMIC_DEC(conf->blockers); conf->restart_done = _gf_true; conf->restart_bricks = _gf_false; + if (GF_ATOMIC_DEC(conf->blockers) == 0) { + synccond_broadcast(&conf->cond_blockers); + } + synccond_broadcast(&conf->cond_restart_bricks); return_block: return ret; @@ -6801,22 +7344,26 @@ glusterd_get_brick_root(char *path, char **mount_point) char *mnt_pt = NULL; struct stat brickstat = {0}; struct stat buf = {0}; + xlator_t *this = THIS; + GF_ASSERT(this); - if (!path) + if (!path) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_INVALID_ARGUMENT, NULL); goto err; + } mnt_pt = gf_strdup(path); - if (!mnt_pt) + if (!mnt_pt) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_INVALID_ARGUMENT, NULL); goto err; + } if (sys_stat(mnt_pt, &brickstat)) goto err; while ((ptr = strrchr(mnt_pt, '/')) && ptr != mnt_pt) { *ptr = '\0'; if (sys_stat(mnt_pt, &buf)) { - gf_msg(THIS->name, GF_LOG_ERROR, errno, GD_MSG_FILE_OP_FAILED, - "error in " - "stat: %s", - strerror(errno)); + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_FILE_OP_FAILED, + "Error in stat=%s", strerror(errno), NULL); goto err; } @@ -6828,10 +7375,8 @@ glusterd_get_brick_root(char *path, char **mount_point) if (ptr == mnt_pt) { if (sys_stat("/", &buf)) { - gf_msg(THIS->name, GF_LOG_ERROR, errno, GD_MSG_FILE_OP_FAILED, - "error in " - "stat: %s", - strerror(errno)); + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_FILE_OP_FAILED, + "Error in stat=%s", strerror(errno), NULL); goto err; } if (brickstat.st_dev == buf.st_dev) @@ -6885,7 +7430,7 @@ static int glusterd_add_inode_size_to_dict(dict_t *dict, int count) { int ret = -1; - char key[1024] = ""; + char key[64]; char buffer[4096] = ""; char *device = NULL; char *fs_name = NULL; @@ -6896,11 +7441,16 @@ glusterd_add_inode_size_to_dict(dict_t *dict, int count) }; struct fs_info *fs = NULL; static dict_t *cached_fs = NULL; + xlator_t *this = THIS; + GF_ASSERT(this); ret = snprintf(key, sizeof(key), "brick%d.device", count); ret = dict_get_strn(dict, key, ret, &device); - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, + "Key=%s", key, NULL); goto out; + } if (cached_fs) { if (dict_get_str(cached_fs, device, &cur_word) == 0) { @@ -6912,8 +7462,11 @@ glusterd_add_inode_size_to_dict(dict_t *dict, int count) ret = snprintf(key, sizeof(key), "brick%d.fs_name", count); ret = dict_get_strn(dict, key, ret, &fs_name); - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, + "Key=%s", key, NULL); goto out; + } runinit(&runner); runner_redir(&runner, STDOUT_FILENO, RUN_PIPE); @@ -6922,11 +7475,9 @@ glusterd_add_inode_size_to_dict(dict_t *dict, int count) if (strcmp(fs_name, fs->fs_type_name) == 0) { if (!fs->fs_tool_name) { /* dynamic inodes */ - gf_msg(THIS->name, GF_LOG_INFO, 0, GD_MSG_INODE_SIZE_GET_FAIL, - "the " - "brick on %s (%s) uses dynamic inode " - "sizes", - device, fs_name); + gf_smsg(this->name, GF_LOG_INFO, 0, GD_MSG_INODE_SIZE_GET_FAIL, + "The brick on device uses dynamic inode sizes", + "Device=%s (%s)", device, fs_name, NULL); cur_word = "N/A"; goto cached; } @@ -6940,19 +7491,17 @@ glusterd_add_inode_size_to_dict(dict_t *dict, int count) runner_add_arg(&runner, fs->fs_tool_arg); runner_add_arg(&runner, device); } else { - gf_msg(THIS->name, GF_LOG_ERROR, 0, GD_MSG_INODE_SIZE_GET_FAIL, - "could not find %s to get" - "inode size for %s (%s): %s package missing?", - fs->fs_tool_name, device, fs_name, fs->fs_tool_pkg); + gf_smsg(this->name, GF_LOG_ERROR, 0, GD_MSG_INODE_SIZE_GET_FAIL, + "Could not find tool to get inode size for device", "Tool=%s", + fs->fs_tool_name, "Device=%s (%s)", device, fs_name, + "Missing package=%s ?", fs->fs_tool_pkg, NULL); goto out; } ret = runner_start(&runner); if (ret) { - gf_msg(THIS->name, GF_LOG_ERROR, errno, GD_MSG_CMD_EXEC_FAIL, - "failed to execute " - "\"%s\"", - fs->fs_tool_name); + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_CMD_EXEC_FAIL, + "Failed to execute \"%s\"", fs->fs_tool_name, NULL); /* * Runner_start might return an error after the child has * been forked, e.g. if the program isn't there. In that @@ -6980,21 +7529,22 @@ glusterd_add_inode_size_to_dict(dict_t *dict, int count) ret = runner_end(&runner); if (ret) { - gf_msg(THIS->name, GF_LOG_ERROR, errno, GD_MSG_CMD_EXEC_FAIL, - "%s exited with non-zero exit status", fs->fs_tool_name); + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_CMD_EXEC_FAIL, + "Tool exited with non-zero exit status", "Tool=%s", + fs->fs_tool_name, NULL); goto out; } if (!cur_word) { ret = -1; - gf_msg(THIS->name, GF_LOG_ERROR, 0, GD_MSG_INODE_SIZE_GET_FAIL, - "Unable to retrieve inode size using %s", fs->fs_tool_name); + gf_smsg(this->name, GF_LOG_ERROR, 0, GD_MSG_INODE_SIZE_GET_FAIL, + "Using Tool=%s", fs->fs_tool_name, NULL); goto out; } if (dict_set_dynstr_with_alloc(cached_fs, device, cur_word)) { /* not fatal if not entered into the cache */ - gf_msg_debug(THIS->name, 0, "failed to cache fs inode size for %s", + gf_msg_debug(this->name, 0, "failed to cache fs inode size for %s", device); } @@ -7005,8 +7555,7 @@ cached: out: if (ret) - gf_msg(THIS->name, GF_LOG_ERROR, 0, GD_MSG_INODE_SIZE_GET_FAIL, - "failed to get inode size"); + gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_INODE_SIZE_GET_FAIL, NULL); return ret; } @@ -7056,22 +7605,29 @@ glusterd_add_brick_mount_details(glusterd_brickinfo_t *brickinfo, dict_t *dict, int count) { int ret = -1; - char key[1024] = ""; + char key[64] = ""; char buff[PATH_MAX] = ""; char base_key[32] = ""; struct mntent save_entry = {0}; char *mnt_pt = NULL; struct mntent *entry = NULL; + xlator_t *this = THIS; + GF_ASSERT(this); snprintf(base_key, sizeof(base_key), "brick%d", count); ret = glusterd_get_brick_root(brickinfo->path, &mnt_pt); - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_BRICKPATH_ROOT_GET_FAIL, + NULL); goto out; + } entry = glusterd_get_mnt_entry_info(mnt_pt, buff, sizeof(buff), &save_entry); if (!entry) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_GET_MNT_ENTRY_INFO_FAIL, + NULL); ret = -1; goto out; } @@ -7080,15 +7636,21 @@ glusterd_add_brick_mount_details(glusterd_brickinfo_t *brickinfo, dict_t *dict, snprintf(key, sizeof(key), "%s.device", base_key); ret = dict_set_dynstr_with_alloc(dict, key, entry->mnt_fsname); - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, + "Key=%s", key, NULL); goto out; + } /* fs type */ snprintf(key, sizeof(key), "%s.fs_name", base_key); ret = dict_set_dynstr_with_alloc(dict, key, entry->mnt_type); - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, + "Key=%s", key, NULL); goto out; + } /* mount options */ snprintf(key, sizeof(key), "%s.mnt_options", base_key); @@ -7159,8 +7721,8 @@ glusterd_add_brick_detail_to_dict(glusterd_volinfo_t *volinfo, uint64_t inodes_total = 0; uint64_t inodes_free = 0; uint64_t block_size = 0; - char key[1024 + 16] = ""; - char base_key[1024] = ""; + char key[64]; + char base_key[32]; struct statvfs brickstat = {0}; xlator_t *this = NULL; @@ -7182,43 +7744,61 @@ glusterd_add_brick_detail_to_dict(glusterd_volinfo_t *volinfo, block_size = brickstat.f_bsize; snprintf(key, sizeof(key), "%s.block_size", base_key); ret = dict_set_uint64(dict, key, block_size); - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, + "Key=%s", key, NULL); goto out; + } /* free space in brick */ memfree = brickstat.f_bfree * brickstat.f_bsize; snprintf(key, sizeof(key), "%s.free", base_key); ret = dict_set_uint64(dict, key, memfree); - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, + "Key=%s", key, NULL); goto out; + } /* total space of brick */ memtotal = brickstat.f_blocks * brickstat.f_bsize; snprintf(key, sizeof(key), "%s.total", base_key); ret = dict_set_uint64(dict, key, memtotal); - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, + "Key=%s", key, NULL); goto out; + } /* inodes: total and free counts only for ext2/3/4 and xfs */ inodes_total = brickstat.f_files; if (inodes_total) { snprintf(key, sizeof(key), "%s.total_inodes", base_key); ret = dict_set_uint64(dict, key, inodes_total); - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, + "Key=%s", key, NULL); goto out; + } } inodes_free = brickstat.f_ffree; if (inodes_free) { snprintf(key, sizeof(key), "%s.free_inodes", base_key); ret = dict_set_uint64(dict, key, inodes_free); - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, + "Key=%s", key, NULL); goto out; + } } ret = glusterd_add_brick_mount_details(brickinfo, dict, count); - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_ADD_BRICK_MNT_INFO_FAIL, + NULL); goto out; + } ret = glusterd_add_inode_size_to_dict(dict, count); out: @@ -7237,9 +7817,9 @@ glusterd_add_brick_to_dict(glusterd_volinfo_t *volinfo, { int ret = -1; int32_t pid = -1; - char key[2048] = ""; + char key[64]; int keylen; - char base_key[1024] = ""; + char base_key[32]; char pidfile[PATH_MAX] = ""; xlator_t *this = NULL; glusterd_conf_t *priv = NULL; @@ -7324,8 +7904,11 @@ glusterd_add_brick_to_dict(glusterd_volinfo_t *volinfo, ret = dict_set_int32n(dict, key, keylen, brick_online); out: - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, + "Key=%s", key, NULL); gf_msg_debug(this->name, 0, "Returning %d", ret); + } return ret; } @@ -7406,8 +7989,10 @@ glusterd_brick_stop(glusterd_volinfo_t *volinfo, conf = this->private; GF_ASSERT(conf); - if ((!brickinfo) || (!volinfo)) + if ((!brickinfo) || (!volinfo)) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_INVALID_ARGUMENT, NULL); goto out; + } if (gf_uuid_is_null(brickinfo->uuid)) { ret = glusterd_resolve_brick(brickinfo); @@ -7442,32 +8027,9 @@ out: return ret; } -gf_boolean_t -glusterd_is_tier_daemon_running(glusterd_volinfo_t *volinfo) -{ - if (volinfo->type != GF_CLUSTER_TYPE_TIER) - return _gf_false; - - if (volinfo->rebal.defrag && - volinfo->rebal.defrag_cmd == GF_DEFRAG_CMD_START_TIER) { - return _gf_true; - } - - return _gf_false; -} - int glusterd_is_defrag_on(glusterd_volinfo_t *volinfo) { - /* - * Do not need to consider tier daemon as a rebalance - * daemon and with current design rebalance is not supported - * on a tiered volume. - */ - - if (glusterd_is_tier_daemon_running(volinfo)) - return 0; - return (volinfo->rebal.defrag != NULL); } @@ -7573,8 +8135,10 @@ glusterd_rb_check_bricks(glusterd_volinfo_t *volinfo, glusterd_brickinfo_t *src, rb = &volinfo->rep_brick; - if (!rb->src_brick || !rb->dst_brick) + if (!rb->src_brick || !rb->dst_brick) { + gf_smsg("glusterd", GF_LOG_ERROR, errno, GD_MSG_INVALID_ARGUMENT, NULL); return -1; + } if (strcmp(rb->src_brick->hostname, src->hostname) || strcmp(rb->src_brick->path, src->path)) { @@ -7720,6 +8284,8 @@ glusterd_check_and_set_brick_xattr(char *host, char *path, uuid_t uuid, char msg[2048] = ""; gf_boolean_t in_use = _gf_false; int flags = 0; + xlator_t *this = THIS; + GF_ASSERT(this); /* Check for xattr support in backend fs */ ret = sys_lsetxattr(path, "trusted.glusterfs.test", "working", 8, 0); @@ -7730,6 +8296,8 @@ glusterd_check_and_set_brick_xattr(char *host, char *path, uuid_t uuid, " extended attributes failed, reason:" " %s.", host, path, strerror(errno)); + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_SET_XATTR_BRICK_FAIL, + "Host=%s, Path=%s", host, path, NULL); goto out; } else { @@ -7739,6 +8307,8 @@ glusterd_check_and_set_brick_xattr(char *host, char *path, uuid_t uuid, "Removing test extended" " attribute failed, reason: %s", strerror(errno)); + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_REMOVE_XATTR_FAIL, + NULL); goto out; } } @@ -7761,6 +8331,8 @@ glusterd_check_and_set_brick_xattr(char *host, char *path, uuid_t uuid, "Failed to set extended " "attributes %s, reason: %s", GF_XATTR_VOL_ID_KEY, strerror(errno)); + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_SET_XATTR_FAIL, + "Attriutes=%s", GF_XATTR_VOL_ID_KEY, NULL); goto out; } @@ -7772,7 +8344,7 @@ out: return ret; } -int +static int glusterd_sm_tr_log_transition_add_to_dict(dict_t *dict, glusterd_sm_tr_log_t *log, int i, int count) @@ -7780,7 +8352,7 @@ glusterd_sm_tr_log_transition_add_to_dict(dict_t *dict, int ret = -1; char key[64] = ""; int keylen; - char timestr[64] = ""; + char timestr[GF_TIMESTR_SIZE] = ""; char *str = NULL; GF_ASSERT(dict); @@ -7812,6 +8384,9 @@ glusterd_sm_tr_log_transition_add_to_dict(dict_t *dict, goto out; out: + if (key[0] != '\0' && ret != 0) + gf_smsg("glusterd", GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, + "Key=%s", key, NULL); gf_msg_debug("glusterd", 0, "returning %d", ret); return ret; } @@ -7920,7 +8495,8 @@ glusterd_sm_tr_log_transition_add(glusterd_sm_tr_log_t *log, int old_state, transitions[next].old_state = old_state; transitions[next].new_state = new_state; transitions[next].event = event; - time(&transitions[next].time); + transitions[next].time = gf_time(); + log->current = next; if (log->count < log->size) log->count++; @@ -8036,8 +8612,10 @@ glusterd_get_local_brickpaths(glusterd_volinfo_t *volinfo, char **pathlist) int i = 0; glusterd_brickinfo_t *brickinfo = NULL; - if ((!volinfo) || (!pathlist)) + if ((!volinfo) || (!pathlist)) { + gf_smsg("glusterd", GF_LOG_ERROR, errno, GD_MSG_INVALID_ARGUMENT, NULL); goto out; + } path_tokens = GF_CALLOC(sizeof(char *), volinfo->brick_count, gf_gld_mt_charptr); @@ -8279,12 +8857,6 @@ glusterd_is_replica_volume(int type) gf_boolean_t glusterd_is_volume_replicate(glusterd_volinfo_t *volinfo) { - gf_boolean_t replicates = _gf_false; - if (volinfo->type == GF_CLUSTER_TYPE_TIER) { - replicates = glusterd_is_replica_volume(volinfo->tier_info.cold_type) | - glusterd_is_replica_volume(volinfo->tier_info.hot_type); - return replicates; - } return glusterd_is_replica_volume((volinfo->type)); } @@ -8302,13 +8874,6 @@ glusterd_is_shd_compatible_type(int type) gf_boolean_t glusterd_is_shd_compatible_volume(glusterd_volinfo_t *volinfo) { - int ret = 0; - - if (volinfo->type == GF_CLUSTER_TYPE_TIER) { - ret = glusterd_is_shd_compatible_type(volinfo->tier_info.cold_type) | - glusterd_is_shd_compatible_type(volinfo->tier_info.hot_type); - return ret; - } return glusterd_is_shd_compatible_type(volinfo->type); } @@ -8341,6 +8906,10 @@ glusterd_set_dump_options(char *dumpoptions_path, char *options, int option_cnt) goto out; } dup_options = gf_strdup(options); + + if (!dup_options) { + goto out; + } gf_msg("glusterd", GF_LOG_INFO, 0, GD_MSG_STATEDUMP_OPTS_RCVD, "Received following statedump options: %s", dup_options); option = strtok_r(dup_options, " ", &tmpptr); @@ -8469,6 +9038,7 @@ glusterd_brick_terminate(glusterd_volinfo_t *volinfo, op_errstr, SIGTERM); } +#ifdef BUILD_GNFS int glusterd_nfs_statedump(char *options, int option_cnt, char **op_errstr) { @@ -8476,7 +9046,6 @@ glusterd_nfs_statedump(char *options, int option_cnt, char **op_errstr) xlator_t *this = NULL; glusterd_conf_t *conf = NULL; char pidfile_path[PATH_MAX] = ""; - char path[PATH_MAX] = ""; FILE *pidfile = NULL; pid_t pid = -1; char dumpoptions_path[PATH_MAX] = ""; @@ -8491,18 +9060,23 @@ glusterd_nfs_statedump(char *options, int option_cnt, char **op_errstr) GF_ASSERT(conf); dup_options = gf_strdup(options); + + if (!dup_options) { + goto out; + } option = strtok_r(dup_options, " ", &tmpptr); if (strcmp(option, conf->nfs_svc.name)) { snprintf(msg, sizeof(msg), "for nfs statedump, options should" " be after the key nfs"); + gf_smsg("glusterd", GF_LOG_ERROR, errno, GD_MSG_INVALID_ENTRY, + "Options misplaced", NULL); *op_errstr = gf_strdup(msg); ret = -1; goto out; } - GLUSTERD_GET_NFS_DIR(path, conf); - GLUSTERD_GET_NFS_PIDFILE(pidfile_path, path, conf); + GLUSTERD_GET_NFS_PIDFILE(pidfile_path, conf); pidfile = fopen(pidfile_path, "r"); if (!pidfile) { @@ -8539,7 +9113,7 @@ glusterd_nfs_statedump(char *options, int option_cnt, char **op_errstr) kill(pid, SIGUSR1); sleep(1); - + /* coverity[TAINTED_STRING] */ sys_unlink(dumpoptions_path); ret = 0; out: @@ -8548,6 +9122,7 @@ out: GF_FREE(dup_options); return ret; } +#endif int glusterd_client_statedump(char *volname, char *options, int option_cnt, @@ -8562,11 +9137,18 @@ glusterd_client_statedump(char *volname, char *options, int option_cnt, char *pid = NULL; dup_options = gf_strdup(options); + if (!dup_options) { + gf_smsg("glusterd", GF_LOG_ERROR, errno, GD_MSG_STRDUP_FAILED, + "options=%s", options, NULL); + goto out; + } option = strtok_r(dup_options, " ", &tmpptr); if (strcmp(option, "client")) { snprintf(msg, sizeof(msg), "for gluster client statedump, options " "should be after the key 'client'"); + gf_smsg("glusterd", GF_LOG_ERROR, errno, GD_MSG_INVALID_ENTRY, + "Options misplaced", NULL); *op_errstr = gf_strdup(msg); ret = -1; goto out; @@ -8574,6 +9156,8 @@ glusterd_client_statedump(char *volname, char *options, int option_cnt, target_ip = strtok_r(NULL, " ", &tmpptr); if (target_ip == NULL) { snprintf(msg, sizeof(msg), "ip address not specified"); + gf_smsg("glusterd", GF_LOG_ERROR, errno, GD_MSG_INVALID_ENTRY, msg, + NULL); *op_errstr = gf_strdup(msg); ret = -1; goto out; @@ -8582,6 +9166,8 @@ glusterd_client_statedump(char *volname, char *options, int option_cnt, pid = strtok_r(NULL, " ", &tmpptr); if (pid == NULL) { snprintf(msg, sizeof(msg), "pid not specified"); + gf_smsg("glusterd", GF_LOG_ERROR, errno, GD_MSG_INVALID_ENTRY, msg, + NULL); *op_errstr = gf_strdup(msg); ret = -1; goto out; @@ -8600,7 +9186,6 @@ glusterd_quotad_statedump(char *options, int option_cnt, char **op_errstr) xlator_t *this = NULL; glusterd_conf_t *conf = NULL; char pidfile_path[PATH_MAX] = ""; - char path[PATH_MAX] = ""; FILE *pidfile = NULL; pid_t pid = -1; char dumpoptions_path[PATH_MAX] = ""; @@ -8615,18 +9200,22 @@ glusterd_quotad_statedump(char *options, int option_cnt, char **op_errstr) GF_ASSERT(conf); dup_options = gf_strdup(options); + if (!dup_options) { + goto out; + } option = strtok_r(dup_options, " ", &tmpptr); if (strcmp(option, conf->quotad_svc.name)) { snprintf(msg, sizeof(msg), "for quotad statedump, options " "should be after the key 'quotad'"); + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_INVALID_ENTRY, + "Options misplaced", NULL); *op_errstr = gf_strdup(msg); ret = -1; goto out; } - GLUSTERD_GET_QUOTAD_DIR(path, conf); - GLUSTERD_GET_QUOTAD_PIDFILE(pidfile_path, path, conf); + GLUSTERD_GET_QUOTAD_PIDFILE(pidfile_path, conf); pidfile = fopen(pidfile_path, "r"); if (!pidfile) { @@ -8665,6 +9254,7 @@ glusterd_quotad_statedump(char *options, int option_cnt, char **op_errstr) sleep(1); + /* coverity[TAINTED_STRING] */ sys_unlink(dumpoptions_path); ret = 0; out: @@ -8773,13 +9363,18 @@ glusterd_friend_remove_cleanup_vols(uuid_t uuid) "to stop snapd daemon service"); } } - if (volinfo->type == GF_CLUSTER_TYPE_TIER) { - svc = &(volinfo->tierd.svc); + + if (glusterd_is_shd_compatible_volume(volinfo)) { + /* + * Sending stop request for all volumes. So it is fine + * to send stop for mux shd + */ + svc = &(volinfo->shd.svc); ret = svc->stop(svc, SIGTERM); if (ret) { gf_msg(THIS->name, GF_LOG_ERROR, 0, GD_MSG_SVC_STOP_FAIL, "Failed " - "to stop tierd daemon service"); + "to stop shd daemon service"); } } } @@ -8798,7 +9393,7 @@ glusterd_friend_remove_cleanup_vols(uuid_t uuid) } /* Reconfigure all daemon services upon peer detach */ - ret = glusterd_svcs_reconfigure(); + ret = glusterd_svcs_reconfigure(NULL); if (ret) { gf_msg(THIS->name, GF_LOG_ERROR, 0, GD_MSG_SVC_STOP_FAIL, "Failed to reconfigure all daemon services."); @@ -8899,32 +9494,6 @@ glusterd_get_trusted_client_filepath(char *filepath, return ret; } -void -glusterd_update_tier_status(glusterd_volinfo_t *volinfo) -{ - glusterd_rebalance_t *rebal = NULL; - - rebal = &volinfo->rebal; - - if (volinfo->type != GF_CLUSTER_TYPE_TIER) - return; - - /* - * If tier process status is stopped or failed, then - * manually changing the status. - */ - - switch (rebal->defrag_status) { - case GF_DEFRAG_STATUS_FAILED: - case GF_DEFRAG_STATUS_STOPPED: - rebal->defrag_status = GF_DEFRAG_STATUS_STARTED; - break; - default: - break; - } - return; -} - int glusterd_get_dummy_client_filepath(char *filepath, glusterd_volinfo_t *volinfo, gf_transport_type type) @@ -8973,12 +9542,6 @@ glusterd_volume_defrag_restart(glusterd_volinfo_t *volinfo, char *op_errstr, * start the rebalance process */ - /* - * Changing the status of tier process to start the daemon - * forcefully. - */ - glusterd_update_tier_status(volinfo); - switch (volinfo->rebal.defrag_status) { case GF_DEFRAG_STATUS_COMPLETE: case GF_DEFRAG_STATUS_STOPPED: @@ -9084,9 +9647,6 @@ glusterd_restart_rebalance_for_volume(glusterd_volinfo_t *volinfo) * work correctly. */ volinfo->rebal.defrag_status = GF_DEFRAG_STATUS_NOT_STARTED; - if (volinfo->type == GF_CLUSTER_TYPE_TIER) - glusterd_store_perform_node_state_store(volinfo); - return 0; } if (!volinfo->rebal.defrag_cmd) { @@ -9260,76 +9820,25 @@ glusterd_defrag_volume_status_update(glusterd_volinfo_t *volinfo, if (ret2) gf_msg_trace(this->name, 0, "failed to get time left"); - if (cmd == GF_DEFRAG_CMD_STATUS_TIER) { - if (files) - volinfo->tier.rebalance_files = files; - if (size) - volinfo->tier.rebalance_data = size; - if (lookup) - volinfo->tier.lookedup_files = lookup; - if (status) - volinfo->tier.defrag_status = status; - if (failures) - volinfo->tier.rebalance_failures = failures; - if (skipped) - volinfo->tier.skipped_files = skipped; - if (run_time) - volinfo->tier.rebalance_time = run_time; - } else { - if (files) - volinfo->rebal.rebalance_files = files; - if (size) - volinfo->rebal.rebalance_data = size; - if (lookup) - volinfo->rebal.lookedup_files = lookup; - if (status) - volinfo->rebal.defrag_status = status; - if (failures) - volinfo->rebal.rebalance_failures = failures; - if (skipped) - volinfo->rebal.skipped_files = skipped; - if (run_time) - volinfo->rebal.rebalance_time = run_time; - if (!ret2) - volinfo->rebal.time_left = time_left; - } - - if (promoted) - volinfo->tier_info.promoted = promoted; - if (demoted) - volinfo->tier_info.demoted = demoted; + if (files) + volinfo->rebal.rebalance_files = files; + if (size) + volinfo->rebal.rebalance_data = size; + if (lookup) + volinfo->rebal.lookedup_files = lookup; + if (status) + volinfo->rebal.defrag_status = status; + if (failures) + volinfo->rebal.rebalance_failures = failures; + if (skipped) + volinfo->rebal.skipped_files = skipped; + if (run_time) + volinfo->rebal.rebalance_time = run_time; + if (!ret2) + volinfo->rebal.time_left = time_left; return ret; } -/* - The function is required to take dict ref for every xlator at graph. - At the time of compare graph topology create a graph and populate - key values in the dictionary, after finished graph comparison we do destroy - the new graph.At the time of construct graph we don't take any reference - so to avoid leak due to ref counter underflow we need to call dict_ref here. - -*/ - -void -glusterd_graph_take_reference(xlator_t *tree) -{ - xlator_t *trav = tree; - xlator_t *prev = tree; - - if (!tree) { - gf_msg("parser", GF_LOG_ERROR, 0, LG_MSG_TREE_NOT_FOUND, - "Translator tree not found"); - return; - } - - while (prev) { - trav = prev->next; - if (prev->options) - dict_ref(prev->options); - prev = trav; - } - return; -} int glusterd_check_topology_identical(const char *filename1, const char *filename2, @@ -9376,15 +9885,11 @@ glusterd_check_topology_identical(const char *filename1, const char *filename2, if (grph1 == NULL) goto out; - glusterd_graph_take_reference(grph1->first); - /* create the graph for filename2 */ grph2 = glusterfs_graph_construct(fp2); if (grph2 == NULL) goto out; - glusterd_graph_take_reference(grph2->first); - /* compare the graph topology */ *identical = is_graph_topology_equal(grph1, grph2); ret = 0; /* SUCCESS */ @@ -9416,12 +9921,16 @@ glusterd_check_files_identical(char *filename1, char *filename2, uint32_t cksum1 = 0; uint32_t cksum2 = 0; xlator_t *this = NULL; + glusterd_conf_t *priv = NULL; GF_ASSERT(filename1); GF_ASSERT(filename2); GF_ASSERT(identical); this = THIS; + GF_VALIDATE_OR_GOTO("glusterd", this, out); + priv = this->private; + GF_VALIDATE_OR_GOTO(this->name, priv, out); ret = sys_stat(filename1, &buf1); @@ -9448,11 +9957,11 @@ glusterd_check_files_identical(char *filename1, char *filename2, goto out; } - ret = get_checksum_for_path(filename1, &cksum1); + ret = get_checksum_for_path(filename1, &cksum1, priv->op_version); if (ret) goto out; - ret = get_checksum_for_path(filename2, &cksum2); + ret = get_checksum_for_path(filename2, &cksum2, priv->op_version); if (ret) goto out; @@ -9563,6 +10072,8 @@ glusterd_append_gsync_status(dict_t *dst, dict_t *src) ret = dict_get_strn(src, "gsync-status", SLEN("gsync-status"), &stop_msg); if (ret) { + gf_smsg("glusterd", GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, + "Key=gsync-status", NULL); ret = 0; goto out; } @@ -9817,8 +10328,11 @@ glusterd_sync_use_rsp_dict(dict_t *aggr, dict_t *rsp_dict) int ret = 0; GF_ASSERT(rsp_dict); + xlator_t *this = THIS; + GF_ASSERT(this); if (!rsp_dict) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_CREATE_FAIL, NULL); goto out; } @@ -9866,6 +10380,8 @@ glusterd_profile_volume_use_rsp_dict(dict_t *aggr, dict_t *rsp_dict) ret = dict_get_int32n(rsp_dict, "count", SLEN("count"), &brick_count); if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, + "Key=count", NULL); ret = 0; // no bricks in the rsp goto out; } @@ -9925,7 +10441,7 @@ glusterd_volume_status_add_peer_rsp(dict_t *this, char *key, data_t *value, if (len < 0 || len >= sizeof(new_key)) goto out; - ret = dict_set(rsp_ctx->dict, new_key, new_value); + ret = dict_setn(rsp_ctx->dict, new_key, len, new_value); out: if (ret) { data_unref(new_value); @@ -10145,6 +10661,8 @@ glusterd_volume_status_copy_to_op_ctx_dict(dict_t *aggr, dict_t *rsp_dict) glusterd_volinfo_t *volinfo = NULL; GF_ASSERT(rsp_dict); + xlator_t *this = THIS; + GF_ASSERT(this); if (aggr) { ctx_dict = aggr; @@ -10154,8 +10672,11 @@ glusterd_volume_status_copy_to_op_ctx_dict(dict_t *aggr, dict_t *rsp_dict) } ret = dict_get_int32n(ctx_dict, "cmd", SLEN("cmd"), &cmd); - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, "Key=cmd", + NULL); goto out; + } if (cmd & GF_CLI_STATUS_ALL && is_origin_glusterd(ctx_dict)) { ret = dict_get_int32n(rsp_dict, "vol_count", SLEN("vol_count"), @@ -10163,18 +10684,27 @@ glusterd_volume_status_copy_to_op_ctx_dict(dict_t *aggr, dict_t *rsp_dict) if (ret == 0) { ret = dict_set_int32n(ctx_dict, "vol_count", SLEN("vol_count"), vol_count); - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, + "Key=vol_count", NULL); goto out; + } for (i = 0; i < vol_count; i++) { keylen = snprintf(key, sizeof(key), "vol%d", i); ret = dict_get_strn(rsp_dict, key, keylen, &volname); - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, + "Key=%s", key, NULL); goto out; + } ret = dict_set_strn(ctx_dict, key, keylen, volname); - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, + "Key=%s", key, NULL); goto out; + } } } else { /* Ignore the error as still the aggregation applies in @@ -10188,6 +10718,8 @@ glusterd_volume_status_copy_to_op_ctx_dict(dict_t *aggr, dict_t *rsp_dict) ret = dict_get_int32n(rsp_dict, "count", SLEN("count"), &rsp_node_count); if (ret) { + gf_smsg(this->name, GF_LOG_INFO, 0, GD_MSG_DICT_GET_FAILED, "Key=count", + NULL); ret = 0; // no bricks in the rsp goto out; } @@ -10195,8 +10727,8 @@ glusterd_volume_status_copy_to_op_ctx_dict(dict_t *aggr, dict_t *rsp_dict) ret = dict_get_int32n(rsp_dict, "other-count", SLEN("other-count"), &rsp_other_count); if (ret) { - gf_msg(THIS->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, - "Failed to get other count from rsp_dict"); + gf_smsg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, + "Key=other-count", NULL); goto out; } @@ -10206,18 +10738,27 @@ glusterd_volume_status_copy_to_op_ctx_dict(dict_t *aggr, dict_t *rsp_dict) if (!dict_getn(ctx_dict, "brick-index-max", SLEN("brick-index-max"))) { ret = dict_get_int32n(rsp_dict, "brick-index-max", SLEN("brick-index-max"), &brick_index_max); - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, + "Key=brick-index-max", NULL); goto out; + } ret = dict_set_int32n(ctx_dict, "brick-index-max", SLEN("brick-index-max"), brick_index_max); - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, + "Key=brick-index-max", NULL); goto out; + } } else { ret = dict_get_int32n(ctx_dict, "brick-index-max", SLEN("brick-index-max"), &brick_index_max); - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, + "Key=brick-index-max", NULL); goto out; + } } rsp_ctx.count = node_count; @@ -10230,62 +10771,45 @@ glusterd_volume_status_copy_to_op_ctx_dict(dict_t *aggr, dict_t *rsp_dict) ret = dict_set_int32n(ctx_dict, "count", SLEN("count"), node_count + rsp_node_count); if (ret) { - gf_msg(THIS->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, - "Failed to update node count"); + gf_smsg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, + "Key=count", NULL); goto out; } ret = dict_set_int32n(ctx_dict, "other-count", SLEN("other-count"), (other_count + rsp_other_count)); if (ret) { - gf_msg(THIS->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, - "Failed to update other-count"); + gf_smsg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, + "Key=other-count", NULL); goto out; } ret = dict_get_strn(ctx_dict, "volname", SLEN("volname"), &volname); if (ret) { - gf_msg(THIS->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, - "Failed to get volname"); + gf_smsg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, + "Key=volname", NULL); goto out; } ret = glusterd_volinfo_find(volname, &volinfo); if (ret) { - gf_msg(THIS->name, GF_LOG_ERROR, 0, GD_MSG_VOLINFO_GET_FAIL, - "Failed to get volinfo for volume: %s", volname); + gf_smsg(this->name, GF_LOG_ERROR, 0, GD_MSG_VOLINFO_GET_FAIL, + "Volume=%s", volname, NULL); goto out; } - if (volinfo->type == GF_CLUSTER_TYPE_TIER) { - ret = dict_get_int32n(rsp_dict, "hot_brick_count", - SLEN("hot_brick_count"), &hot_brick_count); - if (ret) { - gf_msg(THIS->name, GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, - "Failed to get hot brick count from rsp_dict"); - goto out; - } - - ret = dict_get_int32n(rsp_dict, "type", SLEN("type"), &type); - if (ret) { - gf_msg(THIS->name, GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED, - "Failed to get type from rsp_dict"); - goto out; - } - } - ret = dict_set_int32n(ctx_dict, "hot_brick_count", SLEN("hot_brick_count"), hot_brick_count); if (ret) { - gf_msg(THIS->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, - "Failed to update hot_brick_count"); + gf_smsg(THIS->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, + "Key=hot_brick_count", NULL); goto out; } ret = dict_set_int32n(ctx_dict, "type", SLEN("type"), type); if (ret) { - gf_msg(THIS->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, - "Failed to update type"); + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, + "Key=type", NULL); goto out; } @@ -10814,7 +11338,7 @@ glusterd_volume_rebalance_use_rsp_dict(dict_t *aggr, dict_t *rsp_dict) int ret = 0; int32_t index = 0; int32_t count = 0; - int32_t current_index = 2; + int32_t current_index = 1; int32_t value32 = 0; uint64_t value = 0; char *peer_uuid_str = NULL; @@ -10825,6 +11349,8 @@ glusterd_volume_rebalance_use_rsp_dict(dict_t *aggr, dict_t *rsp_dict) GF_ASSERT(this); conf = this->private; + if (conf->op_version < GD_OP_VERSION_6_0) + current_index = 2; if (aggr) { ctx_dict = aggr; @@ -10849,7 +11375,7 @@ glusterd_volume_rebalance_use_rsp_dict(dict_t *aggr, dict_t *rsp_dict) ret = dict_get_int32n(rsp_dict, "count", SLEN("count"), &index); if (ret) gf_msg("glusterd", GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, - "failed to get index"); + "failed to get index from rsp dict"); keylen = snprintf(key, sizeof(key), "node-uuid-%d", index); ret = dict_get_strn(rsp_dict, key, keylen, &node_uuid); @@ -10857,7 +11383,7 @@ glusterd_volume_rebalance_use_rsp_dict(dict_t *aggr, dict_t *rsp_dict) node_uuid_str = gf_strdup(node_uuid); /* Finding the index of the node-uuid in the peer-list */ - rcu_read_lock(); + RCU_READ_LOCK; cds_list_for_each_entry_rcu(peerinfo, &conf->peers, uuid_list) { peer_uuid_str = gd_peer_uuid_str(peerinfo); @@ -10866,7 +11392,7 @@ glusterd_volume_rebalance_use_rsp_dict(dict_t *aggr, dict_t *rsp_dict) current_index++; } - rcu_read_unlock(); + RCU_READ_UNLOCK; /* Setting the largest index value as the total count. */ ret = dict_get_int32n(ctx_dict, "count", SLEN("count"), &count); @@ -10990,189 +11516,6 @@ out: } int -glusterd_volume_tier_use_rsp_dict(dict_t *aggr, dict_t *rsp_dict) -{ - char key[64] = ""; - int keylen; - char *node_uuid = NULL; - char *node_uuid_str = NULL; - char *volname = NULL; - dict_t *ctx_dict = NULL; - double elapsed_time = 0; - glusterd_volinfo_t *volinfo = NULL; - int ret = 0; - int32_t index = 0; - int32_t count = 0; - int32_t value32 = 0; - uint64_t value = 0; - xlator_t *this = NULL; - char *task_id_str = NULL; - - this = THIS; - GF_VALIDATE_OR_GOTO("glusterd", this, out); - GF_VALIDATE_OR_GOTO(this->name, rsp_dict, out); - - if (aggr) { - ctx_dict = aggr; - - } else { - gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_OPCTX_GET_FAIL, - "Operation Context is not present"); - goto out; - } - - ret = dict_get_strn(ctx_dict, "volname", SLEN("volname"), &volname); - if (ret) { - gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, - "Unable to get volume name"); - goto out; - } - - ret = glusterd_volinfo_find(volname, &volinfo); - - if (ret) - goto out; - - ret = dict_get_int32n(rsp_dict, "count", SLEN("count"), &index); - if (ret) - gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, - "failed to get index"); - - keylen = snprintf(key, sizeof(key), "node-uuid-%d", index); - ret = dict_get_strn(rsp_dict, key, keylen, &node_uuid); - if (!ret) { - node_uuid_str = gf_strdup(node_uuid); - } - ret = dict_get_int32n(ctx_dict, "count", SLEN("count"), &count); - count++; - ret = dict_set_int32n(ctx_dict, "count", SLEN("count"), count); - if (ret) - gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, - "Failed to set count"); - - keylen = snprintf(key, sizeof(key), "node-uuid-%d", count); - ret = dict_set_dynstrn(ctx_dict, key, keylen, node_uuid_str); - if (ret) { - gf_msg_debug(this->name, 0, "failed to set node-uuid"); - } - - snprintf(key, sizeof(key), "files-%d", index); - ret = dict_get_uint64(rsp_dict, key, &value); - if (!ret) { - snprintf(key, sizeof(key), "files-%d", count); - ret = dict_set_uint64(ctx_dict, key, value); - if (ret) { - gf_msg_debug(this->name, 0, "failed to set the file count"); - } - } - - snprintf(key, sizeof(key), "size-%d", index); - ret = dict_get_uint64(rsp_dict, key, &value); - if (!ret) { - snprintf(key, sizeof(key), "size-%d", count); - ret = dict_set_uint64(ctx_dict, key, value); - if (ret) { - gf_msg_debug(this->name, 0, "failed to set the size of migration"); - } - } - - snprintf(key, sizeof(key), "lookups-%d", index); - ret = dict_get_uint64(rsp_dict, key, &value); - if (!ret) { - snprintf(key, sizeof(key), "lookups-%d", count); - ret = dict_set_uint64(ctx_dict, key, value); - if (ret) { - gf_msg_debug(this->name, 0, "failed to set looked up file count"); - } - } - - keylen = snprintf(key, sizeof(key), "status-%d", index); - ret = dict_get_int32n(rsp_dict, key, keylen, &value32); - if (!ret) { - keylen = snprintf(key, sizeof(key), "status-%d", count); - ret = dict_set_int32n(ctx_dict, key, keylen, value32); - if (ret) { - gf_msg_debug(this->name, 0, "failed to set status"); - } - } - - snprintf(key, sizeof(key), "failures-%d", index); - ret = dict_get_uint64(rsp_dict, key, &value); - if (!ret) { - snprintf(key, sizeof(key), "failures-%d", count); - ret = dict_set_uint64(ctx_dict, key, value); - if (ret) { - gf_msg_debug(this->name, 0, "failed to set failure count"); - } - } - - snprintf(key, sizeof(key), "skipped-%d", index); - ret = dict_get_uint64(rsp_dict, key, &value); - if (!ret) { - snprintf(key, sizeof(key), "skipped-%d", count); - ret = dict_set_uint64(ctx_dict, key, value); - if (ret) { - gf_msg_debug(this->name, 0, "failed to set skipped count"); - } - } - snprintf(key, sizeof(key), "run-time-%d", index); - ret = dict_get_double(rsp_dict, key, &elapsed_time); - if (!ret) { - snprintf(key, sizeof(key), "run-time-%d", count); - ret = dict_set_double(ctx_dict, key, elapsed_time); - if (ret) { - gf_msg_debug(this->name, 0, "failed to set run-time"); - } - } - - snprintf(key, sizeof(key), "demoted-%d", index); - ret = dict_get_uint64(rsp_dict, key, &value); - if (!ret) { - snprintf(key, sizeof(key), "demoted-%d", count); - ret = dict_set_uint64(ctx_dict, key, value); - if (ret) { - gf_msg_debug(this->name, 0, "failed to set demoted count"); - } - } - snprintf(key, sizeof(key), "promoted-%d", index); - ret = dict_get_uint64(rsp_dict, key, &value); - if (!ret) { - snprintf(key, sizeof(key), "promoted-%d", count); - ret = dict_set_uint64(ctx_dict, key, value); - if (ret) { - gf_msg_debug(this->name, 0, "failed to set promoted count"); - } - } - - snprintf(key, sizeof(key), "time-left-%d", index); - ret = dict_get_uint64(rsp_dict, key, &value); - if (!ret) { - snprintf(key, sizeof(key), "time-left-%d", count); - ret = dict_set_uint64(ctx_dict, key, value); - if (ret) { - gf_msg_debug(THIS->name, 0, "failed to set time-left"); - } - } - - ret = dict_get_strn(rsp_dict, GF_REMOVE_BRICK_TID_KEY, - SLEN(GF_REMOVE_BRICK_TID_KEY), &task_id_str); - if (ret) { - gf_msg_debug(this->name, errno, "Missing remove-brick-id"); - } else { - ret = dict_set_strn(ctx_dict, GF_REMOVE_BRICK_TID_KEY, - SLEN(GF_REMOVE_BRICK_TID_KEY), task_id_str); - if (ret) - gf_msg_debug(this->name, errno, - "Failed to set remove brick task ID"); - } - - ret = 0; - -out: - return ret; -} - -int glusterd_sys_exec_output_rsp_dict(dict_t *dst, dict_t *src) { char output_name[64] = ""; @@ -11702,7 +12045,6 @@ glusterd_status_volume_client_list(dict_t *rsp_dict, dict_t *op_ctx, int32_t count = 0; int32_t fuse_count = 0; int32_t gfapi_count = 0; - int32_t tierd_count = 0; int32_t rebalance_count = 0; int32_t glustershd_count = 0; int32_t quotad_count = 0; @@ -11761,15 +12103,6 @@ glusterd_status_volume_client_list(dict_t *rsp_dict, dict_t *op_ctx, gfapi_count++; continue; - } else if (!strcmp(process, "tierd")) { - ret = dict_get_int32n(op_ctx, "tierd-count", SLEN("tierd-count"), - &count); - if (ret) { - gf_msg(THIS->name, GF_LOG_INFO, 0, GD_MSG_DICT_GET_FAILED, - "Couldn't get tierd-count"); - } - tierd_count++; - continue; } else if (!strcmp(process, "rebalance")) { ret = dict_get_int32n(op_ctx, "rebalance-count", SLEN("rebalance-count"), &count); @@ -11826,15 +12159,6 @@ glusterd_status_volume_client_list(dict_t *rsp_dict, dict_t *op_ctx, goto out; } } - if (tierd_count) { - ret = dict_set_int32n(op_ctx, "tierd-count", SLEN("tierd-count"), - tierd_count); - if (ret) { - gf_msg(THIS->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, - "Couldn't set tierd-count"); - goto out; - } - } if (rebalance_count) { ret = dict_set_int32n(op_ctx, "rebalance-count", SLEN("rebalance-count"), rebalance_count); @@ -11877,8 +12201,7 @@ out: } int -glusterd_tier_or_rebalance_rsp(dict_t *op_ctx, glusterd_rebalance_t *index, - int32_t i) +glusterd_rebalance_rsp(dict_t *op_ctx, glusterd_rebalance_t *index, int32_t i) { int ret = 0; char key[64] = ""; @@ -11939,7 +12262,7 @@ glusterd_defrag_volume_node_rsp(dict_t *req_dict, dict_t *rsp_dict, char key[64] = ""; int keylen; int32_t i = 0; - char buf[1024] = ""; + char buf[64] = ""; char *node_str = NULL; int32_t cmd = 0; @@ -11988,10 +12311,7 @@ glusterd_defrag_volume_node_rsp(dict_t *req_dict, dict_t *rsp_dict, gf_msg(THIS->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "failed to set node-uuid"); - if (cmd == GF_DEFRAG_CMD_STATUS_TIER) - glusterd_tier_or_rebalance_rsp(op_ctx, &volinfo->tier, i); - else - glusterd_tier_or_rebalance_rsp(op_ctx, &volinfo->rebal, i); + glusterd_rebalance_rsp(op_ctx, &volinfo->rebal, i); snprintf(key, sizeof(key), "time-left-%d", i); ret = dict_set_uint64(op_ctx, key, volinfo->rebal.time_left); @@ -11999,18 +12319,6 @@ glusterd_defrag_volume_node_rsp(dict_t *req_dict, dict_t *rsp_dict, gf_msg(THIS->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, "failed to set time left"); - snprintf(key, sizeof(key), "promoted-%d", i); - ret = dict_set_uint64(op_ctx, key, volinfo->tier_info.promoted); - if (ret) - gf_msg(THIS->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, - "failed to set lookedup file count"); - - snprintf(key, sizeof(key), "demoted-%d", i); - ret = dict_set_uint64(op_ctx, key, volinfo->tier_info.demoted); - if (ret) - gf_msg(THIS->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, - "failed to set lookedup file count"); - out: return ret; } @@ -12038,8 +12346,6 @@ glusterd_handle_node_rsp(dict_t *req_dict, void *pending_entry, ret = glusterd_status_volume_brick_rsp(rsp_dict, op_ctx, op_errstr); break; - case GD_OP_TIER_STATUS: - case GD_OP_DETACH_TIER_STATUS: case GD_OP_DEFRAG_BRICK_VOLUME: glusterd_defrag_volume_node_rsp(req_dict, rsp_dict, op_ctx); break; @@ -12185,20 +12491,22 @@ glusterd_copy_uuid_to_dict(uuid_t uuid, dict_t *dict, char *key, return 0; } -int +static int _update_volume_op_versions(dict_t *this, char *key, data_t *value, void *data) { int op_version = 0; glusterd_volinfo_t *ctx = NULL; gf_boolean_t enabled = _gf_true; int ret = -1; + struct volopt_map_entry *vmep = NULL; GF_ASSERT(data); ctx = data; - op_version = glusterd_get_op_version_for_key(key); + vmep = gd_get_vmep(key); + op_version = glusterd_get_op_version_from_vmep(vmep); - if (gd_is_xlator_option(key) || gd_is_boolean_option(key)) { + if (gd_is_xlator_option(vmep) || gd_is_boolean_option(vmep)) { ret = gf_string2boolean(value->data, &enabled); if (ret) return 0; @@ -12210,7 +12518,7 @@ _update_volume_op_versions(dict_t *this, char *key, data_t *value, void *data) if (op_version > ctx->op_version) ctx->op_version = op_version; - if (gd_is_client_option(key) && (op_version > ctx->client_op_version)) + if (gd_is_client_option(vmep) && (op_version > ctx->client_op_version)) ctx->client_op_version = op_version; return 0; @@ -12399,22 +12707,6 @@ glusterd_is_volume_inode_quota_enabled(glusterd_volinfo_t *volinfo) } int -glusterd_is_tierd_supposed_to_be_enabled(glusterd_volinfo_t *volinfo) -{ - if ((volinfo->type != GF_CLUSTER_TYPE_TIER) || - (volinfo->tier.op == GD_OP_DETACH_TIER)) - return _gf_false; - else - return _gf_true; -} - -int -glusterd_is_tierd_enabled(glusterd_volinfo_t *volinfo) -{ - return volinfo->is_tier_enabled; -} - -int glusterd_is_bitrot_enabled(glusterd_volinfo_t *volinfo) { return glusterd_volinfo_get_boolean(volinfo, VKEY_FEATURES_BITROT); @@ -12720,6 +13012,11 @@ glusterd_enable_default_options(glusterd_volinfo_t *volinfo, char *option) int ret = 0; xlator_t *this = NULL; glusterd_conf_t *conf = NULL; +#ifdef IPV6_DEFAULT + char *addr_family = "inet6"; +#else + char *addr_family = "inet"; +#endif this = THIS; GF_ASSERT(this); @@ -12780,23 +13077,36 @@ glusterd_enable_default_options(glusterd_volinfo_t *volinfo, char *option) } } } + } - if (!option || !strcmp("features.ctr-enabled", option)) { - if (volinfo->type == GF_CLUSTER_TYPE_TIER) { - ret = dict_set_dynstr_with_alloc(volinfo->dict, - "features.ctr-enabled", "on"); + if (conf->op_version >= GD_OP_VERSION_3_9_0) { + if (!option || !strcmp("transport.address-family", option)) { + if (volinfo->transport_type == GF_TRANSPORT_TCP) { + ret = dict_set_dynstr_with_alloc( + volinfo->dict, "transport.address-family", addr_family); if (ret) { gf_msg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, - "Failed to set option " - "'features.ctr-enabled' " - "on volume %s", + "failed to set transport." + "address-family on %s", volinfo->volname); goto out; } } } } + + if (conf->op_version >= GD_OP_VERSION_7_0) { + ret = dict_set_dynstr_with_alloc(volinfo->dict, + "storage.fips-mode-rchecksum", "on"); + if (ret) { + gf_msg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, + "Failed to set option 'storage.fips-mode-rchecksum' " + "on volume %s", + volinfo->volname); + goto out; + } + } out: return ret; } @@ -12812,6 +13122,7 @@ glusterd_get_gfproxy_client_volfile(glusterd_volinfo_t *volinfo, char *path, switch (volinfo->transport_type) { case GF_TRANSPORT_TCP: + case GF_TRANSPORT_BOTH_TCP_RDMA: snprintf(path, path_len, "%s/trusted-%s.tcp-gfproxy-fuse.vol", workdir, volinfo->volname); break; @@ -12940,7 +13251,7 @@ glusterd_get_value_for_vme_entry(struct volopt_map_entry *vme, char **def_val) ret = xlator_option_info_list(&vol_opt_handle, key, &local_def_val, &descr); if (ret) { /*Swallow Error if option not found*/ - gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_GET_KEY_FAILED, + gf_msg(this->name, GF_LOG_WARNING, 0, GD_MSG_GET_KEY_FAILED, "Failed to get option for %s " "key", key); @@ -13069,7 +13380,7 @@ glusterd_get_global_options_for_all_vols(rpcsvc_request_t *req, dict_t *ctx, if (key_fixed) key = key_fixed; } - + /* coverity[CONSTANT_EXPRESSION_RESULT] */ ALL_VOLUME_OPTION_CHECK("all", _gf_true, key, ret, op_errstr, out); for (i = 0; valid_all_vol_opts[i].option; i++) { @@ -13097,7 +13408,9 @@ glusterd_get_global_options_for_all_vols(rpcsvc_request_t *req, dict_t *ctx, gf_asprintf(&def_val, "%d", priv->op_version); need_free = _gf_true; } else { - def_val = valid_all_vol_opts[i].dflt_val; + gf_asprintf(&def_val, "%s (DEFAULT)", + valid_all_vol_opts[i].dflt_val); + need_free = _gf_true; } } @@ -13183,9 +13496,11 @@ glusterd_get_default_val_for_volopt(dict_t *ctx, gf_boolean_t all_opts, int count = 0; xlator_t *this = NULL; char *def_val = NULL; + char *def_val_str = NULL; char dict_key[50] = ""; int keylen; gf_boolean_t key_found = _gf_false; + gf_boolean_t get_value_vme = _gf_false; glusterd_conf_t *priv = NULL; dict_t *vol_dict = NULL; @@ -13208,6 +13523,7 @@ glusterd_get_default_val_for_volopt(dict_t *ctx, gf_boolean_t all_opts, if (!all_opts && strcmp(vme->key, input_key)) continue; key_found = _gf_true; + get_value_vme = _gf_false; /* First look for the key in the priv->opts for global option * and then into vol_dict, if its not present then look for * translator default value */ @@ -13222,6 +13538,7 @@ glusterd_get_default_val_for_volopt(dict_t *ctx, gf_boolean_t all_opts, def_val = vme->value; } else { ret = glusterd_get_value_for_vme_entry(vme, &def_val); + get_value_vme = _gf_true; if (!all_opts && ret) goto out; else if (ret == -2) @@ -13240,7 +13557,13 @@ glusterd_get_default_val_for_volopt(dict_t *ctx, gf_boolean_t all_opts, goto out; } sprintf(dict_key, "value%d", count); - ret = dict_set_dynstr_with_alloc(ctx, dict_key, def_val); + if (get_value_vme) { // the value was never changed - DEFAULT is used + gf_asprintf(&def_val_str, "%s (DEFAULT)", def_val); + ret = dict_set_dynstr_with_alloc(ctx, dict_key, def_val_str); + GF_FREE(def_val_str); + def_val_str = NULL; + } else + ret = dict_set_dynstr_with_alloc(ctx, dict_key, def_val); if (ret) { gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Failed to " @@ -13248,6 +13571,9 @@ glusterd_get_default_val_for_volopt(dict_t *ctx, gf_boolean_t all_opts, def_val, vme->key); goto out; } + if (get_value_vme) + GF_FREE(def_val); + def_val = NULL; if (!all_opts) break; @@ -13545,6 +13871,34 @@ out: return ret; } +void +glusterd_brick_get_status_str(glusterd_brickinfo_t *brickinfo, char *status_str) +{ + GF_VALIDATE_OR_GOTO(THIS->name, brickinfo, out); + GF_VALIDATE_OR_GOTO(THIS->name, status_str, out); + + switch (brickinfo->status) { + case GF_BRICK_STOPPED: + sprintf(status_str, "%s", "Stopped"); + break; + case GF_BRICK_STARTED: + sprintf(status_str, "%s", "Started"); + break; + case GF_BRICK_STARTING: + sprintf(status_str, "%s", "Starting"); + break; + case GF_BRICK_STOPPING: + sprintf(status_str, "%s", "Stopping"); + break; + default: + sprintf(status_str, "%s", "None"); + break; + } + +out: + return; +} + int glusterd_volume_get_transport_type_str(glusterd_volinfo_t *volinfo, char *transport_type_str) @@ -13644,52 +13998,6 @@ out: return ret; } -int -glusterd_volume_get_hot_tier_type_str(glusterd_volinfo_t *volinfo, - char **hot_tier_type_str) -{ - int ret = -1; - int hot_tier_type = 0; - int hot_dist_count = 0; - - GF_VALIDATE_OR_GOTO(THIS->name, volinfo, out); - GF_VALIDATE_OR_GOTO(THIS->name, hot_tier_type_str, out); - - hot_dist_count = volinfo->tier_info.hot_replica_count - ? volinfo->tier_info.hot_replica_count - : 1; - - hot_tier_type = get_vol_type(volinfo->tier_info.hot_type, hot_dist_count, - volinfo->tier_info.hot_brick_count); - - *hot_tier_type_str = vol_type_str[hot_tier_type]; - - ret = 0; -out: - return ret; -} - -int -glusterd_volume_get_cold_tier_type_str(glusterd_volinfo_t *volinfo, - char **cold_tier_type_str) -{ - int ret = -1; - int cold_tier_type = 0; - - GF_VALIDATE_OR_GOTO(THIS->name, volinfo, out); - GF_VALIDATE_OR_GOTO(THIS->name, cold_tier_type_str, out); - - cold_tier_type = get_vol_type(volinfo->tier_info.cold_type, - volinfo->tier_info.cold_dist_leaf_count, - volinfo->tier_info.cold_brick_count); - - *cold_tier_type_str = vol_type_str[cold_tier_type]; - - ret = 0; -out: - return ret; -} - /* This function will insert the element to the list in a order. Order will be based on the compare function provided as a input. If element to be inserted in ascending order compare should return: @@ -13712,78 +14020,6 @@ glusterd_list_add_order(struct cds_list_head *new, struct cds_list_head *head, cds_list_add_rcu(new, rcu_dereference(pos->prev)); } -int -glusterd_disallow_op_for_tier(glusterd_volinfo_t *volinfo, glusterd_op_t op, - int cmd) -{ - xlator_t *this = NULL; - int ret = 0; - - this = THIS; - GF_VALIDATE_OR_GOTO(this->name, volinfo, out); - - if (volinfo->type != GF_CLUSTER_TYPE_TIER) - goto out; - - switch (op) { - case GD_OP_ADD_BRICK: - case GD_OP_REPLACE_BRICK: - case GD_OP_RESET_BRICK: - ret = -1; - gf_msg_debug(this->name, 0, - "Operation not " - "permitted on tiered volume %s", - volinfo->volname); - break; - case GD_OP_REBALANCE: - switch (cmd) { - case GF_DEFRAG_CMD_START_TIER: - case GF_DEFRAG_CMD_STATUS_TIER: - case GF_DEFRAG_CMD_START_DETACH_TIER: - case GF_DEFRAG_CMD_STOP_DETACH_TIER: - case GF_DEFRAG_CMD_STATUS: - case GF_DEFRAG_CMD_DETACH_STATUS: - case GF_DEFRAG_CMD_STOP_TIER: - case GF_DEFRAG_CMD_DETACH_START: - case GF_DEFRAG_CMD_DETACH_COMMIT: - case GF_DEFRAG_CMD_DETACH_COMMIT_FORCE: - case GF_DEFRAG_CMD_DETACH_STOP: - ret = 0; - break; - default: - gf_msg_debug(this->name, 0, - "Rebalance Operation not permitted" - " on tiered volume %s", - volinfo->volname); - ret = -1; - break; - } - break; - case GD_OP_REMOVE_BRICK: - switch (cmd) { - case GF_DEFRAG_CMD_DETACH_START: - case GF_OP_CMD_DETACH_COMMIT_FORCE: - case GF_OP_CMD_DETACH_COMMIT: - case GF_OP_CMD_DETACH_START: - case GF_DEFRAG_CMD_STOP_DETACH_TIER: - ret = 0; - break; - default: - gf_msg_debug(this->name, 0, - "Remove brick operation not " - "permitted on tiered volume %s", - volinfo->volname); - ret = -1; - break; - } - break; - default: - break; - } -out: - return ret; -} - int32_t glusterd_count_connected_peers(int32_t *count) { @@ -13800,7 +14036,7 @@ glusterd_count_connected_peers(int32_t *count) *count = 1; - rcu_read_lock(); + RCU_READ_LOCK; cds_list_for_each_entry_rcu(peerinfo, &conf->peers, uuid_list) { /* Find peer who is connected and is a friend */ @@ -13809,7 +14045,7 @@ glusterd_count_connected_peers(int32_t *count) (*count)++; } } - rcu_read_unlock(); + RCU_READ_UNLOCK; ret = 0; out: @@ -13852,41 +14088,41 @@ glusterd_handle_replicate_brick_ops(glusterd_volinfo_t *volinfo, char vpath[PATH_MAX] = ""; char *volfileserver = NULL; - priv = THIS->private; - GF_VALIDATE_OR_GOTO(THIS->name, priv, out); + xlator_t *this = THIS; + GF_ASSERT(this); + priv = this->private; + GF_VALIDATE_OR_GOTO(this->name, priv, out); dirty[2] = hton32(1); ret = sys_lsetxattr(brickinfo->path, GF_AFR_DIRTY, dirty, sizeof(dirty), 0); if (ret == -1) { - gf_msg(THIS->name, GF_LOG_ERROR, errno, GD_MSG_SETXATTR_FAIL, - "Failed to set extended" - " attribute %s : %s.", - GF_AFR_DIRTY, strerror(errno)); + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_SET_XATTR_FAIL, + "Attribute=%s", GF_AFR_DIRTY, "Reason=%s", strerror(errno), + NULL); goto out; } if (mkdtemp(tmpmount) == NULL) { - gf_msg(THIS->name, GF_LOG_ERROR, errno, GD_MSG_DIR_OP_FAILED, - "failed to create a temporary mount directory."); + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_CREATE_DIR_FAILED, + NULL); ret = -1; goto out; } - ret = gf_asprintf(&pid, "%d", GF_CLIENT_PID_SELF_HEALD); + ret = gf_asprintf(&pid, "%d", GF_CLIENT_PID_ADD_REPLICA_MOUNT); if (ret < 0) goto out; switch (op) { case GD_OP_REPLACE_BRICK: - if (dict_get_strn(THIS->options, "transport.socket.bind-address", + if (dict_get_strn(this->options, "transport.socket.bind-address", SLEN("transport.socket.bind-address"), &volfileserver) != 0) volfileserver = "localhost"; - snprintf(logfile, sizeof(logfile), - DEFAULT_LOG_FILE_DIRECTORY "/%s-replace-brick-mount.log", - volinfo->volname); + snprintf(logfile, sizeof(logfile), "%s/%s-replace-brick-mount.log", + priv->logdir, volinfo->volname); if (!*logfile) { ret = -1; goto out; @@ -13898,9 +14134,8 @@ glusterd_handle_replicate_brick_ops(glusterd_volinfo_t *volinfo, break; case GD_OP_ADD_BRICK: - snprintf(logfile, sizeof(logfile), - DEFAULT_LOG_FILE_DIRECTORY "/%s-add-brick-mount.log", - volinfo->volname); + snprintf(logfile, sizeof(logfile), "%s/%s-add-brick-mount.log", + priv->logdir, volinfo->volname); if (!*logfile) { ret = -1; goto out; @@ -13924,7 +14159,7 @@ glusterd_handle_replicate_brick_ops(glusterd_volinfo_t *volinfo, ret = runner_run(&runner); if (ret) { - gf_log(THIS->name, GF_LOG_ERROR, + gf_log(this->name, GF_LOG_ERROR, "mount command" " failed."); goto lock; @@ -13934,19 +14169,18 @@ glusterd_handle_replicate_brick_ops(glusterd_volinfo_t *volinfo, (op == GD_OP_REPLACE_BRICK) ? GF_AFR_REPLACE_BRICK : GF_AFR_ADD_BRICK, brickinfo->brick_id, sizeof(brickinfo->brick_id), 0); if (ret == -1) - gf_msg(THIS->name, GF_LOG_ERROR, errno, GD_MSG_SETXATTR_FAIL, - "Failed to set extended" - " attribute %s : %s", - (op == GD_OP_REPLACE_BRICK) ? GF_AFR_REPLACE_BRICK - : GF_AFR_ADD_BRICK, - strerror(errno)); - gf_umount_lazy(THIS->name, tmpmount, 1); + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_SET_XATTR_FAIL, + "Attribute=%s, Reason=%s", + (op == GD_OP_REPLACE_BRICK) ? GF_AFR_REPLACE_BRICK + : GF_AFR_ADD_BRICK, + strerror(errno), NULL); + gf_umount_lazy(this->name, tmpmount, 1); lock: synclock_lock(&priv->big_lock); out: if (pid) GF_FREE(pid); - gf_msg_debug("glusterd", 0, "Returning with ret"); + gf_msg_debug(this->name, 0, "Returning with ret"); return ret; } @@ -14100,17 +14334,6 @@ glusterd_brick_op_prerequisites(dict_t *dict, char **op, glusterd_op_t *gd_op, goto out; } - ret = glusterd_disallow_op_for_tier(*volinfo, *gd_op, -1); - if (ret) { - snprintf(msg, sizeof(msg), - "%sbrick commands are not " - "supported on tiered volume %s", - (*gd_op == GD_OP_REPLACE_BRICK) ? "replace-" : "reset-", - *volname); - *op_errstr = gf_strdup(msg); - goto out; - } - /* If geo-rep is configured, for this volume, it should be stopped. */ param.volinfo = *volinfo; ret = glusterd_check_geo_rep_running(¶m, op_errstr); @@ -14166,6 +14389,8 @@ glusterd_brick_op_prerequisites(dict_t *dict, char **op, glusterd_op_t *gd_op, "brick: %s does not exist in " "volume: %s", *src_brick, *volname); + gf_smsg(this->name, GF_LOG_ERROR, 0, GD_MSG_BRICK_NOT_FOUND, + "Brick=%s, Volume=%s", *src_brick, *volname, NULL); *op_errstr = gf_strdup(msg); goto out; } @@ -14367,3 +14592,455 @@ glusterd_is_profile_on(glusterd_volinfo_t *volinfo) return _gf_true; return _gf_false; } + +int32_t +glusterd_add_shd_to_dict(glusterd_volinfo_t *volinfo, dict_t *dict, + int32_t count) +{ + int ret = -1; + int32_t pid = -1; + int32_t brick_online = -1; + char key[64] = {0}; + int keylen; + char *pidfile = NULL; + xlator_t *this = NULL; + char *uuid_str = NULL; + + this = THIS; + GF_VALIDATE_OR_GOTO(THIS->name, this, out); + + GF_VALIDATE_OR_GOTO(this->name, volinfo, out); + GF_VALIDATE_OR_GOTO(this->name, dict, out); + + keylen = snprintf(key, sizeof(key), "brick%d.hostname", count); + ret = dict_set_nstrn(dict, key, keylen, "Self-heal Daemon", + SLEN("Self-heal Daemon")); + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Key=%s", + key, NULL); + goto out; + } + + keylen = snprintf(key, sizeof(key), "brick%d.path", count); + uuid_str = gf_strdup(uuid_utoa(MY_UUID)); + if (!uuid_str) { + ret = -1; + goto out; + } + ret = dict_set_dynstrn(dict, key, keylen, uuid_str); + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Key=%s", + key, NULL); + goto out; + } + uuid_str = NULL; + + /* shd doesn't have a port. but the cli needs a port key with + * a zero value to parse. + * */ + + keylen = snprintf(key, sizeof(key), "brick%d.port", count); + ret = dict_set_int32n(dict, key, keylen, 0); + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Key=%s", + key, NULL); + goto out; + } + + pidfile = volinfo->shd.svc.proc.pidfile; + + brick_online = gf_is_service_running(pidfile, &pid); + + /* If shd is not running, then don't print the pid */ + if (!brick_online) + pid = -1; + keylen = snprintf(key, sizeof(key), "brick%d.pid", count); + ret = dict_set_int32n(dict, key, keylen, pid); + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED, "Key=%s", + key, NULL); + goto out; + } + + keylen = snprintf(key, sizeof(key), "brick%d.status", count); + ret = dict_set_int32n(dict, key, keylen, brick_online); + +out: + if (uuid_str) + GF_FREE(uuid_str); + if (ret) + gf_msg(this ? this->name : "glusterd", GF_LOG_ERROR, 0, + GD_MSG_DICT_SET_FAILED, + "Returning %d. adding values to dict failed", ret); + + return ret; +} + +static gf_ai_compare_t +glusterd_compare_addrinfo(struct addrinfo *first, struct addrinfo *next) +{ + int ret = -1; + struct addrinfo *tmp1 = NULL; + struct addrinfo *tmp2 = NULL; + char firstip[NI_MAXHOST] = {0.}; + char nextip[NI_MAXHOST] = { + 0, + }; + + for (tmp1 = first; tmp1 != NULL; tmp1 = tmp1->ai_next) { + ret = getnameinfo(tmp1->ai_addr, tmp1->ai_addrlen, firstip, NI_MAXHOST, + NULL, 0, NI_NUMERICHOST); + if (ret) + return GF_AI_COMPARE_ERROR; + for (tmp2 = next; tmp2 != NULL; tmp2 = tmp2->ai_next) { + ret = getnameinfo(tmp2->ai_addr, tmp2->ai_addrlen, nextip, + NI_MAXHOST, NULL, 0, NI_NUMERICHOST); + if (ret) + return GF_AI_COMPARE_ERROR; + if (!strcmp(firstip, nextip)) { + return GF_AI_COMPARE_MATCH; + } + } + } + return GF_AI_COMPARE_NO_MATCH; +} + +/* Check for non optimal brick order for Replicate/Disperse : + * Checks if bricks belonging to a replicate or disperse + * volume are present on the same server + */ +int32_t +glusterd_check_brick_order(dict_t *dict, char *err_str, int32_t type, + char **volname, char **brick_list, + int32_t *brick_count, int32_t sub_count) +{ + int ret = -1; + int i = 0; + int j = 0; + int k = 0; + xlator_t *this = NULL; + addrinfo_list_t *ai_list = NULL; + addrinfo_list_t *ai_list_tmp1 = NULL; + addrinfo_list_t *ai_list_tmp2 = NULL; + char *brick = NULL; + char *brick_list_dup = NULL; + char *brick_list_ptr = NULL; + char *tmpptr = NULL; + struct addrinfo *ai_info = NULL; + char brick_addr[128] = { + 0, + }; + int addrlen = 0; + + const char failed_string[2048] = + "Failed to perform brick order " + "check. Use 'force' at the end of the command" + " if you want to override this behavior. "; + const char found_string[2048] = + "Multiple bricks of a %s " + "volume are present on the same server. This " + "setup is not optimal. Bricks should be on " + "different nodes to have best fault tolerant " + "configuration. Use 'force' at the end of the " + "command if you want to override this " + "behavior. "; + + this = THIS; + + GF_ASSERT(this); + + ai_list = MALLOC(sizeof(addrinfo_list_t)); + ai_list->info = NULL; + CDS_INIT_LIST_HEAD(&ai_list->list); + + if (!(*volname)) { + ret = dict_get_strn(dict, "volname", SLEN("volname"), &(*volname)); + if (ret) { + gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, + "Unable to get volume name"); + goto out; + } + } + + if (!(*brick_list)) { + ret = dict_get_strn(dict, "bricks", SLEN("bricks"), &(*brick_list)); + if (ret) { + gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, + "Bricks check : Could not " + "retrieve bricks list"); + goto out; + } + } + + if (!(*brick_count)) { + ret = dict_get_int32n(dict, "count", SLEN("count"), &(*brick_count)); + if (ret) { + gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED, + "Bricks check : Could not " + "retrieve brick count"); + goto out; + } + } + + brick_list_dup = brick_list_ptr = gf_strdup(*brick_list); + /* Resolve hostnames and get addrinfo */ + while (i < *brick_count) { + ++i; + brick = strtok_r(brick_list_dup, " \n", &tmpptr); + brick_list_dup = tmpptr; + if (brick == NULL) + goto check_failed; + tmpptr = strrchr(brick, ':'); + if (tmpptr == NULL) + goto check_failed; + addrlen = strlen(brick) - strlen(tmpptr); + strncpy(brick_addr, brick, addrlen); + brick_addr[addrlen] = '\0'; + ret = getaddrinfo(brick_addr, NULL, NULL, &ai_info); + if (ret != 0) { + ret = 0; + gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_HOSTNAME_RESOLVE_FAIL, + "unable to resolve host name for addr %s", brick_addr); + goto out; + } + ai_list_tmp1 = MALLOC(sizeof(addrinfo_list_t)); + if (ai_list_tmp1 == NULL) { + ret = 0; + gf_msg(this->name, GF_LOG_ERROR, ENOMEM, GD_MSG_NO_MEMORY, + "failed to allocate " + "memory"); + freeaddrinfo(ai_info); + goto out; + } + ai_list_tmp1->info = ai_info; + cds_list_add_tail(&ai_list_tmp1->list, &ai_list->list); + ai_list_tmp1 = NULL; + } + + i = 0; + ai_list_tmp1 = cds_list_entry(ai_list->list.next, addrinfo_list_t, list); + + if (*brick_count < sub_count) { + sub_count = *brick_count; + } + + /* Check for bad brick order */ + while (i < *brick_count) { + ++i; + ai_info = ai_list_tmp1->info; + ai_list_tmp1 = cds_list_entry(ai_list_tmp1->list.next, addrinfo_list_t, + list); + if (0 == i % sub_count) { + j = 0; + continue; + } + ai_list_tmp2 = ai_list_tmp1; + k = j; + while (k < sub_count - 1) { + ++k; + ret = glusterd_compare_addrinfo(ai_info, ai_list_tmp2->info); + if (GF_AI_COMPARE_ERROR == ret) + goto check_failed; + if (GF_AI_COMPARE_MATCH == ret) + goto found_bad_brick_order; + ai_list_tmp2 = cds_list_entry(ai_list_tmp2->list.next, + addrinfo_list_t, list); + } + ++j; + } + gf_msg_debug(this->name, 0, "Brick order okay"); + ret = 0; + goto out; + +check_failed: + gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_BAD_BRKORDER_CHECK_FAIL, + "Failed bad brick order check"); + snprintf(err_str, sizeof(failed_string), failed_string); + ret = -1; + goto out; + +found_bad_brick_order: + gf_msg(this->name, GF_LOG_INFO, 0, GD_MSG_BAD_BRKORDER, + "Bad brick order found"); + if (type == GF_CLUSTER_TYPE_DISPERSE) { + snprintf(err_str, sizeof(found_string), found_string, "disperse"); + } else { + snprintf(err_str, sizeof(found_string), found_string, "replicate"); + } + + ret = -1; +out: + ai_list_tmp2 = NULL; + GF_FREE(brick_list_ptr); + cds_list_for_each_entry(ai_list_tmp1, &ai_list->list, list) + { + if (ai_list_tmp1->info) + freeaddrinfo(ai_list_tmp1->info); + free(ai_list_tmp2); + ai_list_tmp2 = ai_list_tmp1; + } + free(ai_list); + free(ai_list_tmp2); + gf_msg_debug("glusterd", 0, "Returning %d", ret); + return ret; +} + +static gf_boolean_t +search_peer_in_auth_list(char *peer_hostname, char *auth_allow_list) +{ + if (strstr(auth_allow_list, peer_hostname)) { + return _gf_true; + } + + return _gf_false; +} + +/* glusterd_add_peers_to_auth_list() adds peers into auth.allow list + * if auth.allow list is not empty. This is called for add-brick and + * replica brick operations to avoid failing the temporary mount. New + * volfiles will be generated and clients are notified reg new volfiles. + */ +void +glusterd_add_peers_to_auth_list(char *volname) +{ + int ret = 0; + glusterd_volinfo_t *volinfo = NULL; + glusterd_peerinfo_t *peerinfo = NULL; + xlator_t *this = NULL; + glusterd_conf_t *conf = NULL; + int32_t len = 0; + char *auth_allow_list = NULL; + char *new_auth_allow_list = NULL; + + this = THIS; + GF_ASSERT(this); + conf = this->private; + GF_ASSERT(conf); + + GF_VALIDATE_OR_GOTO(this->name, volname, out); + + ret = glusterd_volinfo_find(volname, &volinfo); + if (ret) { + gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_VOL_NOT_FOUND, + "Unable to find volume: %s", volname); + goto out; + } + + ret = dict_get_str_sizen(volinfo->dict, "auth.allow", &auth_allow_list); + if (ret) { + gf_msg(this->name, GF_LOG_INFO, errno, GD_MSG_DICT_GET_FAILED, + "auth allow list is not set"); + goto out; + } + cds_list_for_each_entry_rcu(peerinfo, &conf->peers, uuid_list) + { + len += strlen(peerinfo->hostname); + } + len += strlen(auth_allow_list) + 1; + + new_auth_allow_list = GF_CALLOC(1, len, gf_common_mt_char); + + new_auth_allow_list = strncat(new_auth_allow_list, auth_allow_list, + strlen(auth_allow_list)); + cds_list_for_each_entry_rcu(peerinfo, &conf->peers, uuid_list) + { + ret = search_peer_in_auth_list(peerinfo->hostname, new_auth_allow_list); + if (!ret) { + gf_log(this->name, GF_LOG_DEBUG, + "peer %s not found in auth.allow list", peerinfo->hostname); + new_auth_allow_list = strcat(new_auth_allow_list, ","); + new_auth_allow_list = strncat(new_auth_allow_list, + peerinfo->hostname, + strlen(peerinfo->hostname)); + } + } + if (strcmp(new_auth_allow_list, auth_allow_list) != 0) { + /* In case, new_auth_allow_list is not same as auth_allow_list, + * we need to update the volinfo->dict with new_auth_allow_list. + * we delete the auth_allow_list and replace it with + * new_auth_allow_list. for reverting the changes in post commit, we + * keep the copy of auth_allow_list as old_auth_allow_list in + * volinfo->dict. + */ + dict_del_sizen(volinfo->dict, "auth.allow"); + ret = dict_set_strn(volinfo->dict, "auth.allow", SLEN("auth.allow"), + new_auth_allow_list); + if (ret) { + gf_msg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, + "Unable to set new auth.allow list"); + goto out; + } + ret = dict_set_strn(volinfo->dict, "old.auth.allow", + SLEN("old.auth.allow"), auth_allow_list); + if (ret) { + gf_msg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, + "Unable to set old auth.allow list"); + goto out; + } + ret = glusterd_create_volfiles_and_notify_services(volinfo); + if (ret) { + gf_msg(this->name, GF_LOG_WARNING, 0, GD_MSG_VOLFILE_CREATE_FAIL, + "failed to create volfiles"); + goto out; + } + } +out: + GF_FREE(new_auth_allow_list); + return; +} + +int +glusterd_replace_old_auth_allow_list(char *volname) +{ + int ret = 0; + glusterd_volinfo_t *volinfo = NULL; + xlator_t *this = NULL; + char *old_auth_allow_list = NULL; + + this = THIS; + GF_ASSERT(this); + + GF_VALIDATE_OR_GOTO(this->name, volname, out); + + ret = glusterd_volinfo_find(volname, &volinfo); + if (ret) { + gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_VOL_NOT_FOUND, + "Unable to find volume: %s", volname); + goto out; + } + + ret = dict_get_str_sizen(volinfo->dict, "old.auth.allow", + &old_auth_allow_list); + if (ret) { + gf_msg(this->name, GF_LOG_INFO, errno, GD_MSG_DICT_GET_FAILED, + "old auth allow list is not set, no need to replace the list"); + ret = 0; + goto out; + } + + dict_del_sizen(volinfo->dict, "auth.allow"); + ret = dict_set_strn(volinfo->dict, "auth.allow", SLEN("auth.allow"), + old_auth_allow_list); + if (ret) { + gf_msg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, + "Unable to replace auth.allow list"); + goto out; + } + + dict_del_sizen(volinfo->dict, "old.auth.allow"); + + ret = glusterd_create_volfiles_and_notify_services(volinfo); + if (ret) { + gf_msg(this->name, GF_LOG_WARNING, 0, GD_MSG_VOLFILE_CREATE_FAIL, + "failed to create volfiles"); + goto out; + } + ret = glusterd_store_volinfo(volinfo, GLUSTERD_VOLINFO_VER_AC_INCREMENT); + if (ret) { + gf_msg(this->name, GF_LOG_WARNING, 0, GD_MSG_VOLINFO_STORE_FAIL, + "failed to store volinfo"); + goto out; + } +out: + return ret; +} |
