diff options
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-store.c')
| -rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-store.c | 1562 |
1 files changed, 731 insertions, 831 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-store.c b/xlators/mgmt/glusterd/src/glusterd-store.c index 124ca2741af..d94dceb10b7 100644 --- a/xlators/mgmt/glusterd/src/glusterd-store.c +++ b/xlators/mgmt/glusterd/src/glusterd-store.c @@ -48,6 +48,23 @@ #include "mntent_compat.h" #endif +#define GLUSTERD_GET_BRICK_DIR(path, volinfo, priv) \ + do { \ + int32_t _brick_len; \ + if (volinfo->is_snap_volume) { \ + _brick_len = snprintf(path, PATH_MAX, "%s/snaps/%s/%s/%s", \ + priv->workdir, volinfo->snapshot->snapname, \ + volinfo->volname, GLUSTERD_BRICK_INFO_DIR); \ + } else { \ + _brick_len = snprintf(path, PATH_MAX, "%s/%s/%s/%s", \ + priv->workdir, GLUSTERD_VOLUME_DIR_PREFIX, \ + volinfo->volname, GLUSTERD_BRICK_INFO_DIR); \ + } \ + if ((_brick_len < 0) || (_brick_len >= PATH_MAX)) { \ + path[0] = 0; \ + } \ + } while (0) + void glusterd_replace_slash_with_hyphen(char *str) { @@ -57,7 +74,7 @@ glusterd_replace_slash_with_hyphen(char *str) while (ptr) { *ptr = '-'; - ptr = strchr(str, '/'); + ptr = strchr(ptr, '/'); } } @@ -239,9 +256,10 @@ out: int32_t glusterd_store_volinfo_brick_fname_write(int vol_fd, glusterd_brickinfo_t *brickinfo, - int32_t brick_count) + int32_t brick_count, + int is_thin_arbiter) { - char key[PATH_MAX] = { + char key[64] = { 0, }; char brickfname[PATH_MAX] = { @@ -249,8 +267,13 @@ glusterd_store_volinfo_brick_fname_write(int vol_fd, }; int32_t ret = -1; - snprintf(key, sizeof(key), "%s-%d", GLUSTERD_STORE_KEY_VOL_BRICK, - brick_count); + if (!is_thin_arbiter) { + snprintf(key, sizeof(key), "%s-%d", GLUSTERD_STORE_KEY_VOL_BRICK, + brick_count); + } else { + snprintf(key, sizeof(key), "%s-%d", GLUSTERD_STORE_KEY_VOL_TA_BRICK, + brick_count); + } glusterd_store_brickinfofname_set(brickinfo, brickfname, sizeof(brickfname)); ret = gf_store_save_value(vol_fd, key, brickfname); @@ -295,15 +318,14 @@ glusterd_store_create_snapd_shandle_on_absence(glusterd_volinfo_t *volinfo) * The snapshot details will be stored only if the cluster op-version is * greater than or equal to 4 */ -int +static int gd_store_brick_snap_details_write(int fd, glusterd_brickinfo_t *brickinfo) { int ret = -1; xlator_t *this = NULL; glusterd_conf_t *conf = NULL; - char value[PATH_MAX] = { - 0, - }; + char value[5 * PATH_MAX]; + uint total_len = 0; this = THIS; GF_ASSERT(this != NULL); @@ -318,102 +340,104 @@ gd_store_brick_snap_details_write(int fd, glusterd_brickinfo_t *brickinfo) goto out; } - if (strlen(brickinfo->device_path) > 0) { - snprintf(value, sizeof(value), "%s", brickinfo->device_path); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_BRICK_DEVICE_PATH, - value); - if (ret) - goto out; + if (brickinfo->device_path[0] != '\0') { + ret = snprintf(value + total_len, sizeof(value) - total_len, "%s=%s\n", + GLUSTERD_STORE_KEY_BRICK_DEVICE_PATH, + brickinfo->device_path); + if (ret < 0 || ret >= sizeof(value) - total_len) { + ret = -1; + goto err; + } + total_len += ret; } - if (strlen(brickinfo->mount_dir) > 0) { - snprintf(value, sizeof(value), "%s", brickinfo->mount_dir); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_BRICK_MOUNT_DIR, - value); - if (ret) - goto out; + if (brickinfo->mount_dir[0] != '\0') { + ret = snprintf(value + total_len, sizeof(value) - total_len, "%s=%s\n", + GLUSTERD_STORE_KEY_BRICK_MOUNT_DIR, + brickinfo->mount_dir); + if (ret < 0 || ret >= sizeof(value) - total_len) { + ret = -1; + goto err; + } + total_len += ret; } - if (strlen(brickinfo->fstype) > 0) { - snprintf(value, sizeof(value), "%s", brickinfo->fstype); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_BRICK_FSTYPE, value); - if (ret) { - gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_FS_LABEL_UPDATE_FAIL, - "Failed to save " - "brick fs type of brick %s", - brickinfo->path); - goto out; + if (brickinfo->fstype[0] != '\0') { + ret = snprintf(value + total_len, sizeof(value) - total_len, "%s=%s\n", + GLUSTERD_STORE_KEY_BRICK_FSTYPE, brickinfo->fstype); + if (ret < 0 || ret >= sizeof(value) - total_len) { + ret = -1; + goto err; } + total_len += ret; } - if (strlen(brickinfo->mnt_opts) > 0) { - snprintf(value, sizeof(value), "%s", brickinfo->mnt_opts); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_BRICK_MNTOPTS, value); - if (ret) { - gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_BRK_MOUNTOPTS_FAIL, - "Failed to save " - "brick mnt opts of brick %s", - brickinfo->path); - goto out; + if (brickinfo->mnt_opts[0] != '\0') { + ret = snprintf(value + total_len, sizeof(value) - total_len, "%s=%s\n", + GLUSTERD_STORE_KEY_BRICK_MNTOPTS, brickinfo->mnt_opts); + if (ret < 0 || ret >= sizeof(value) - total_len) { + ret = -1; + goto err; } + total_len += ret; } - snprintf(value, sizeof(value), "%d", brickinfo->snap_status); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_BRICK_SNAP_STATUS, value); - if (ret) - goto out; + ret = snprintf(value + total_len, sizeof(value) - total_len, "%s=%d\n", + GLUSTERD_STORE_KEY_BRICK_SNAP_STATUS, + brickinfo->snap_status); + if (ret < 0 || ret >= sizeof(value) - total_len) { + ret = -1; + goto err; + } + total_len += ret; - snprintf(value, sizeof(value), "%" PRIu64, brickinfo->statfs_fsid); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_BRICK_FSID, value); + ret = snprintf(value + total_len, sizeof(value) - total_len, + "%s=%" PRIu64 "\n", GLUSTERD_STORE_KEY_BRICK_FSID, + brickinfo->statfs_fsid); + if (ret < 0 || ret >= sizeof(value) - total_len) { + ret = -1; + goto err; + } + ret = gf_store_save_items(fd, value); +err: + if (ret) { + gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_FS_LABEL_UPDATE_FAIL, + "Failed to save " + "snap detils of brick %s", + brickinfo->path); + } out: return ret; } -int32_t +static int32_t glusterd_store_brickinfo_write(int fd, glusterd_brickinfo_t *brickinfo) { - char value[256] = { - 0, - }; - int32_t ret = 0; + char value[5 * PATH_MAX]; + int32_t ret = -1; GF_ASSERT(brickinfo); GF_ASSERT(fd > 0); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_BRICK_UUID, - uuid_utoa(brickinfo->uuid)); - if (ret) - goto out; - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_BRICK_HOSTNAME, - brickinfo->hostname); - if (ret) - goto out; - - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_BRICK_PATH, - brickinfo->path); - if (ret) - goto out; - - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_BRICK_REAL_PATH, - brickinfo->path); - if (ret) - goto out; - - snprintf(value, sizeof(value), "%d", brickinfo->port); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_BRICK_PORT, value); - - snprintf(value, sizeof(value), "%d", brickinfo->rdma_port); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_BRICK_RDMA_PORT, value); - - snprintf(value, sizeof(value), "%d", brickinfo->decommissioned); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_BRICK_DECOMMISSIONED, - value); - if (ret) + ret = snprintf(value, sizeof(value), + "%s=%s\n%s=%s\n%s=%s\n%s=%s\n%s=%d\n%s=%d\n%s=%d\n%s=%s\n", + GLUSTERD_STORE_KEY_BRICK_UUID, uuid_utoa(brickinfo->uuid), + GLUSTERD_STORE_KEY_BRICK_HOSTNAME, brickinfo->hostname, + GLUSTERD_STORE_KEY_BRICK_PATH, brickinfo->path, + GLUSTERD_STORE_KEY_BRICK_REAL_PATH, brickinfo->path, + GLUSTERD_STORE_KEY_BRICK_PORT, brickinfo->port, + GLUSTERD_STORE_KEY_BRICK_RDMA_PORT, brickinfo->rdma_port, + GLUSTERD_STORE_KEY_BRICK_DECOMMISSIONED, + brickinfo->decommissioned, GLUSTERD_STORE_KEY_BRICK_ID, + brickinfo->brick_id); + + if (ret < 0 || ret >= sizeof(value)) { + ret = -1; goto out; + } - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_BRICK_ID, - brickinfo->brick_id); + ret = gf_store_save_items(fd, value); if (ret) goto out; @@ -434,7 +458,7 @@ out: int32_t glusterd_store_snapd_write(int fd, glusterd_volinfo_t *volinfo) { - char value[256] = { + char value[64] = { 0, }; int32_t ret = 0; @@ -458,7 +482,7 @@ glusterd_store_snapd_write(int fd, glusterd_volinfo_t *volinfo) return ret; } -int32_t +static int32_t glusterd_store_perform_brick_store(glusterd_brickinfo_t *brickinfo) { int fd = -1; @@ -470,14 +494,14 @@ glusterd_store_perform_brick_store(glusterd_brickinfo_t *brickinfo) ret = -1; goto out; } - ret = glusterd_store_brickinfo_write(fd, brickinfo); if (ret) goto out; out: - if (ret && (fd > 0)) + if (ret && (fd > 0)) { gf_store_unlink_tmppath(brickinfo->shandle); + } gf_msg_debug(THIS->name, 0, "Returning %d", ret); return ret; } @@ -522,22 +546,18 @@ out: return ret; } -int32_t +static int32_t glusterd_store_brickinfo(glusterd_volinfo_t *volinfo, glusterd_brickinfo_t *brickinfo, int32_t brick_count, - int vol_fd) + int vol_fd, int is_thin_arbiter) { int32_t ret = -1; GF_ASSERT(volinfo); GF_ASSERT(brickinfo); - ret = glusterd_store_volinfo_brick_fname_write(vol_fd, brickinfo, - brick_count); - if (ret) - goto out; - - ret = glusterd_store_create_brick_dir(volinfo); + ret = glusterd_store_volinfo_brick_fname_write( + vol_fd, brickinfo, brick_count, is_thin_arbiter); if (ret) goto out; @@ -639,154 +659,73 @@ out: return ret; } -int32_t -glusterd_store_remove_bricks(glusterd_volinfo_t *volinfo, char *delete_path) -{ - int32_t ret = 0; - glusterd_brickinfo_t *tmp = NULL; - glusterd_conf_t *priv = NULL; - xlator_t *this = NULL; - DIR *dir = NULL; - struct dirent *entry = NULL; - struct dirent scratch[2] = { - { - 0, - }, - }; - char path[PATH_MAX] = { - 0, - }; - char brickdir[PATH_MAX] = { - 0, - }; - int32_t len = 0; - - this = THIS; - GF_ASSERT(this); - - GF_ASSERT(volinfo); - - cds_list_for_each_entry(tmp, &volinfo->bricks, brick_list) - { - ret = glusterd_store_delete_brick(tmp, delete_path); - if (ret) - goto out; - } - - priv = this->private; - GF_ASSERT(priv); - - len = snprintf(brickdir, sizeof(brickdir), "%s/%s", delete_path, - GLUSTERD_BRICK_INFO_DIR); - if ((len < 0) || (len >= sizeof(brickdir))) { - ret = -1; - goto out; - } - - dir = sys_opendir(brickdir); - - GF_SKIP_IRRELEVANT_ENTRIES(entry, dir, scratch); - - while (entry) { - len = snprintf(path, sizeof(path), "%s/%s", brickdir, entry->d_name); - if ((len >= 0) && (len < sizeof(path))) { - ret = sys_unlink(path); - if (ret && errno != ENOENT) { - gf_msg_debug(this->name, 0, "Unable to unlink %s", path); - } - } - GF_SKIP_IRRELEVANT_ENTRIES(entry, dir, scratch); - } - - sys_closedir(dir); - - ret = sys_rmdir(brickdir); - -out: - gf_msg_debug(this->name, 0, "Returning with %d", ret); - return ret; -} - static int -_storeslaves(dict_t *this, char *key, data_t *value, void *data) -{ - int32_t ret = 0; - gf_store_handle_t *shandle = NULL; - xlator_t *xl = NULL; - - xl = THIS; - GF_ASSERT(xl); - - shandle = (gf_store_handle_t *)data; - - GF_ASSERT(shandle); - GF_ASSERT(shandle->fd > 0); - GF_ASSERT(shandle->path); - GF_ASSERT(key); - GF_ASSERT(value); - GF_ASSERT(value->data); - - gf_msg_debug(xl->name, 0, "Storing in volinfo:key= %s, val=%s", key, - value->data); - - ret = gf_store_save_value(shandle->fd, key, (char *)value->data); - if (ret) { - gf_msg(xl->name, GF_LOG_ERROR, 0, GD_MSG_STORE_HANDLE_WRITE_FAIL, - "Unable to write into store" - " handle for path: %s", - shandle->path); - return -1; - } - return 0; -} - -int -_storeopts(dict_t *this, char *key, data_t *value, void *data) +_storeopts(dict_t *dict_value, char *key, data_t *value, void *data) { int32_t ret = 0; int32_t exists = 0; + int32_t option_len = 0; gf_store_handle_t *shandle = NULL; - xlator_t *xl = NULL; + glusterd_volinfo_data_store_t *dict_data = NULL; + xlator_t *this = NULL; - xl = THIS; - GF_ASSERT(xl); + this = THIS; + GF_ASSERT(this); - shandle = (gf_store_handle_t *)data; + dict_data = (glusterd_volinfo_data_store_t *)data; + shandle = dict_data->shandle; GF_ASSERT(shandle); GF_ASSERT(shandle->fd > 0); - GF_ASSERT(shandle->path); GF_ASSERT(key); GF_ASSERT(value); GF_ASSERT(value->data); - if (is_key_glusterd_hooks_friendly(key)) { - exists = 1; + if (dict_data->key_check == 1) { + if (is_key_glusterd_hooks_friendly(key)) { + exists = 1; - } else { - exists = glusterd_check_option_exists(key, NULL); + } else { + exists = glusterd_check_option_exists(key, NULL); + } } - - if (1 == exists) { - gf_msg_debug(xl->name, 0, - "Storing in volinfo:key= %s, " + if (exists == 1 || dict_data->key_check == 0) { + gf_msg_debug(this->name, 0, + "Storing in buffer for volinfo:key= %s, " "val=%s", key, value->data); - } else { - gf_msg_debug(xl->name, 0, "Discarding:key= %s, val=%s", key, + gf_msg_debug(this->name, 0, "Discarding:key= %s, val=%s", key, value->data); return 0; } - ret = gf_store_save_value(shandle->fd, key, (char *)value->data); - if (ret) { - gf_msg(xl->name, GF_LOG_ERROR, 0, GD_MSG_STORE_HANDLE_WRITE_FAIL, - "Unable to write into store" - " handle for path: %s", - shandle->path); + /* + * The option_len considers the length of the key value + * pair and along with that '=' and '\n', but as value->len + * already considers a NULL at the end of the data, adding + * just 1. + */ + option_len = strlen(key) + value->len + 1; + + if ((VOLINFO_BUFFER_SIZE - dict_data->buffer_len - 1) < option_len) { + ret = gf_store_save_items(shandle->fd, dict_data->buffer); + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, 0, GD_MSG_FILE_OP_FAILED, NULL); + return -1; + } + dict_data->buffer_len = 0; + dict_data->buffer[0] = '\0'; + } + ret = snprintf(dict_data->buffer + dict_data->buffer_len, option_len + 1, + "%s=%s\n", key, value->data); + if (ret < 0 || ret > option_len + 1) { + gf_smsg(this->name, GF_LOG_ERROR, EINVAL, GD_MSG_COPY_FAIL, NULL); return -1; } + + dict_data->buffer_len += ret; + return 0; } @@ -795,7 +734,7 @@ _storeopts(dict_t *this, char *key, data_t *value, void *data) * The snapshot details will be stored only if the cluster op-version is * greater than or equal to 4 */ -int +static int glusterd_volume_write_snap_details(int fd, glusterd_volinfo_t *volinfo) { int ret = -1; @@ -818,229 +757,163 @@ glusterd_volume_write_snap_details(int fd, glusterd_volinfo_t *volinfo) goto out; } - snprintf(buf, sizeof(buf), "%s", volinfo->parent_volname); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_PARENT_VOLNAME, buf); - if (ret) { - gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_STORE_FAIL, - "Failed to store " GLUSTERD_STORE_KEY_PARENT_VOLNAME); - goto out; - } - - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_VOL_RESTORED_SNAP, - uuid_utoa(volinfo->restored_from_snap)); - if (ret) { - gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_STORE_HANDLE_WRITE_FAIL, - "Unable to write restored_from_snap"); - goto out; + ret = snprintf(buf, sizeof(buf), "%s=%s\n%s=%s\n%s=%" PRIu64 "\n", + GLUSTERD_STORE_KEY_PARENT_VOLNAME, volinfo->parent_volname, + GLUSTERD_STORE_KEY_VOL_RESTORED_SNAP, + uuid_utoa(volinfo->restored_from_snap), + GLUSTERD_STORE_KEY_SNAP_MAX_HARD_LIMIT, + volinfo->snap_max_hard_limit); + if (ret < 0 || ret >= sizeof(buf)) { + ret = -1; + goto err; } - snprintf(buf, sizeof(buf), "%" PRIu64, volinfo->snap_max_hard_limit); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_SNAP_MAX_HARD_LIMIT, buf); + ret = gf_store_save_items(fd, buf); if (ret) { - gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_HARD_LIMIT_SET_FAIL, - "Unable to write snap-max-hard-limit"); - goto out; + goto err; } - ret = glusterd_store_snapd_info(volinfo); - if (ret) - gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_SNAPD_INFO_STORE_FAIL, - "snapd info store failed " - "volume: %s", - volinfo->volname); - -out: +err: if (ret) gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_SNAPINFO_WRITE_FAIL, "Failed to write snap details" " for volume %s", volinfo->volname); - return ret; -} - -int32_t -glusterd_volume_write_tier_details(int fd, glusterd_volinfo_t *volinfo) -{ - int32_t ret = -1; - char buf[PATH_MAX] = ""; - - if (volinfo->type != GF_CLUSTER_TYPE_TIER) { - ret = 0; - goto out; - } - - snprintf(buf, sizeof(buf), "%d", volinfo->tier_info.cold_brick_count); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_COLD_COUNT, buf); - if (ret) - goto out; - - snprintf(buf, sizeof(buf), "%d", volinfo->tier_info.cold_replica_count); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_COLD_REPLICA_COUNT, buf); - if (ret) - goto out; - - snprintf(buf, sizeof(buf), "%d", volinfo->tier_info.cold_disperse_count); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_COLD_DISPERSE_COUNT, buf); - if (ret) - goto out; - - snprintf(buf, sizeof(buf), "%d", volinfo->tier_info.cold_redundancy_count); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_COLD_REDUNDANCY_COUNT, - buf); - if (ret) - goto out; - - snprintf(buf, sizeof(buf), "%d", volinfo->tier_info.hot_brick_count); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_HOT_COUNT, buf); - if (ret) - goto out; - - snprintf(buf, sizeof(buf), "%d", volinfo->tier_info.hot_replica_count); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_HOT_REPLICA_COUNT, buf); - if (ret) - goto out; - - snprintf(buf, sizeof(buf), "%d", volinfo->tier_info.hot_type); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_HOT_TYPE, buf); - if (ret) - goto out; - - snprintf(buf, sizeof(buf), "%d", volinfo->tier_info.cold_type); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_COLD_TYPE, buf); - if (ret) - goto out; - out: return ret; } -int32_t +static int32_t glusterd_volume_exclude_options_write(int fd, glusterd_volinfo_t *volinfo) { char *str = NULL; - char buf[PATH_MAX] = ""; + char buf[PATH_MAX]; + uint total_len = 0; int32_t ret = -1; - xlator_t *this = NULL; + xlator_t *this = THIS; glusterd_conf_t *conf = NULL; - this = THIS; GF_ASSERT(this); GF_ASSERT(fd > 0); GF_ASSERT(volinfo); conf = this->private; GF_VALIDATE_OR_GOTO(this->name, (conf != NULL), out); - snprintf(buf, sizeof(buf), "%d", volinfo->type); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_VOL_TYPE, buf); - if (ret) - goto out; - - snprintf(buf, sizeof(buf), "%d", volinfo->brick_count); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_VOL_COUNT, buf); - if (ret) - goto out; - - snprintf(buf, sizeof(buf), "%d", volinfo->status); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_VOL_STATUS, buf); - if (ret) - goto out; - - snprintf(buf, sizeof(buf), "%d", volinfo->sub_count); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_VOL_SUB_COUNT, buf); - if (ret) - goto out; - - snprintf(buf, sizeof(buf), "%d", volinfo->stripe_count); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_VOL_STRIPE_CNT, buf); - if (ret) - goto out; - - snprintf(buf, sizeof(buf), "%d", volinfo->replica_count); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_VOL_REPLICA_CNT, buf); - if (ret) + ret = snprintf(buf + total_len, sizeof(buf) - total_len, + "%s=%d\n%s=%d\n%s=%d\n%s=%d\n%s=%d\n%s=%d\n", + GLUSTERD_STORE_KEY_VOL_TYPE, volinfo->type, + GLUSTERD_STORE_KEY_VOL_COUNT, volinfo->brick_count, + GLUSTERD_STORE_KEY_VOL_STATUS, volinfo->status, + GLUSTERD_STORE_KEY_VOL_SUB_COUNT, volinfo->sub_count, + GLUSTERD_STORE_KEY_VOL_STRIPE_CNT, volinfo->stripe_count, + GLUSTERD_STORE_KEY_VOL_REPLICA_CNT, volinfo->replica_count); + if (ret < 0 || ret >= sizeof(buf) - total_len) { + ret = -1; goto out; + } + total_len += ret; if ((conf->op_version >= GD_OP_VERSION_3_7_6) && volinfo->arbiter_count) { - snprintf(buf, sizeof(buf), "%d", volinfo->arbiter_count); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_VOL_ARBITER_CNT, buf); - if (ret) + ret = snprintf(buf + total_len, sizeof(buf) - total_len, "%s=%d\n", + GLUSTERD_STORE_KEY_VOL_ARBITER_CNT, + volinfo->arbiter_count); + if (ret < 0 || ret >= sizeof(buf) - total_len) { + ret = -1; goto out; + } + total_len += ret; } if (conf->op_version >= GD_OP_VERSION_3_6_0) { - snprintf(buf, sizeof(buf), "%d", volinfo->disperse_count); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_VOL_DISPERSE_CNT, buf); - if (ret) - goto out; - - snprintf(buf, sizeof(buf), "%d", volinfo->redundancy_count); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_VOL_REDUNDANCY_CNT, - buf); - if (ret) + ret = snprintf( + buf + total_len, sizeof(buf) - total_len, "%s=%d\n%s=%d\n", + GLUSTERD_STORE_KEY_VOL_DISPERSE_CNT, volinfo->disperse_count, + GLUSTERD_STORE_KEY_VOL_REDUNDANCY_CNT, volinfo->redundancy_count); + if (ret < 0 || ret >= sizeof(buf) - total_len) { + ret = -1; goto out; + } + total_len += ret; } - snprintf(buf, sizeof(buf), "%d", volinfo->version); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_VOL_VERSION, buf); - if (ret) - goto out; - - snprintf(buf, sizeof(buf), "%d", volinfo->transport_type); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_VOL_TRANSPORT, buf); - if (ret) - goto out; - - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_VOL_ID, - uuid_utoa(volinfo->volume_id)); - if (ret) + ret = snprintf(buf + total_len, sizeof(buf) - total_len, + "%s=%d\n%s=%d\n%s=%s\n", GLUSTERD_STORE_KEY_VOL_VERSION, + volinfo->version, GLUSTERD_STORE_KEY_VOL_TRANSPORT, + volinfo->transport_type, GLUSTERD_STORE_KEY_VOL_ID, + uuid_utoa(volinfo->volume_id)); + if (ret < 0 || ret >= sizeof(buf) - total_len) { + ret = -1; goto out; + } + total_len += ret; str = glusterd_auth_get_username(volinfo); if (str) { - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_USERNAME, str); - if (ret) + ret = snprintf(buf + total_len, sizeof(buf) - total_len, "%s=%s\n", + GLUSTERD_STORE_KEY_USERNAME, str); + if (ret < 0 || ret >= sizeof(buf) - total_len) { + ret = -1; goto out; + } + total_len += ret; } str = glusterd_auth_get_password(volinfo); if (str) { - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_PASSWORD, str); - if (ret) + ret = snprintf(buf + total_len, sizeof(buf) - total_len, "%s=%s\n", + GLUSTERD_STORE_KEY_PASSWORD, str); + if (ret < 0 || ret >= sizeof(buf) - total_len) { + ret = -1; goto out; + } + total_len += ret; } - snprintf(buf, sizeof(buf), "%d", volinfo->op_version); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_VOL_OP_VERSION, buf); - if (ret) - goto out; - - snprintf(buf, sizeof(buf), "%d", volinfo->client_op_version); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_VOL_CLIENT_OP_VERSION, - buf); - if (ret) + ret = snprintf(buf + total_len, sizeof(buf) - total_len, "%s=%d\n%s=%d\n", + GLUSTERD_STORE_KEY_VOL_OP_VERSION, volinfo->op_version, + GLUSTERD_STORE_KEY_VOL_CLIENT_OP_VERSION, + volinfo->client_op_version); + if (ret < 0 || ret >= sizeof(buf) - total_len) { + ret = -1; goto out; - if (volinfo->caps) { - snprintf(buf, sizeof(buf), "%d", volinfo->caps); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_VOL_CAPS, buf); - if (ret) - goto out; } + total_len += ret; if (conf->op_version >= GD_OP_VERSION_3_7_6) { - snprintf(buf, sizeof(buf), "%d", volinfo->quota_xattr_version); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_VOL_QUOTA_VERSION, - buf); - if (ret) + ret = snprintf(buf + total_len, sizeof(buf) - total_len, "%s=%d\n", + GLUSTERD_STORE_KEY_VOL_QUOTA_VERSION, + volinfo->quota_xattr_version); + if (ret < 0 || ret >= sizeof(buf) - total_len) { + ret = -1; goto out; + } + total_len += ret; } if (conf->op_version >= GD_OP_VERSION_3_10_0) { - snprintf(buf, sizeof(buf), "%d", volinfo->is_tier_enabled); - ret = gf_store_save_value(fd, GF_TIER_ENABLED, buf); - if (ret) + ret = snprintf(buf + total_len, sizeof(buf) - total_len, "%s=0\n", + GF_TIER_ENABLED); + if (ret < 0 || ret >= sizeof(buf) - total_len) { + ret = -1; + goto out; + } + total_len += ret; + } + + if ((conf->op_version >= GD_OP_VERSION_7_0) && + volinfo->thin_arbiter_count) { + ret = snprintf(buf + total_len, sizeof(buf) - total_len, "%s=%d\n", + GLUSTERD_STORE_KEY_VOL_THIN_ARBITER_CNT, + volinfo->thin_arbiter_count); + if (ret < 0 || ret >= sizeof(buf) - total_len) { + ret = -1; goto out; + } + total_len += ret; } - ret = glusterd_volume_write_tier_details(fd, volinfo); + ret = gf_store_save_items(fd, buf); + if (ret) + goto out; ret = glusterd_volume_write_snap_details(fd, volinfo); @@ -1078,36 +951,26 @@ glusterd_store_piddirpath_set(glusterd_volinfo_t *volinfo, char *piddirpath) } static int32_t -glusterd_store_create_volume_dir(glusterd_volinfo_t *volinfo) -{ - int32_t ret = -1; - char voldirpath[PATH_MAX] = { - 0, - }; - - GF_ASSERT(volinfo); - - glusterd_store_voldirpath_set(volinfo, voldirpath); - ret = gf_store_mkdir(voldirpath); - - gf_msg_debug(THIS->name, 0, "Returning with %d", ret); - return ret; -} - -static int32_t -glusterd_store_create_volume_run_dir(glusterd_volinfo_t *volinfo) +glusterd_store_create_volume_dirs(glusterd_volinfo_t *volinfo) { int32_t ret = -1; - char piddirpath[PATH_MAX] = { + char dirpath[PATH_MAX] = { 0, }; GF_ASSERT(volinfo); - glusterd_store_piddirpath_set(volinfo, piddirpath); + glusterd_store_voldirpath_set(volinfo, dirpath); + ret = gf_store_mkdir(dirpath); + if (ret) + goto out; - ret = gf_store_mkdir(piddirpath); + glusterd_store_piddirpath_set(volinfo, dirpath); + ret = gf_store_mkdir(dirpath); + if (ret) + goto out; +out: gf_msg_debug(THIS->name, 0, "Returning with %d", ret); return ret; } @@ -1137,7 +1000,7 @@ glusterd_store_create_snap_dir(glusterd_snap_t *snap) return ret; } -int32_t +static int32_t glusterd_store_volinfo_write(int fd, glusterd_volinfo_t *volinfo) { int32_t ret = -1; @@ -1145,28 +1008,57 @@ glusterd_store_volinfo_write(int fd, glusterd_volinfo_t *volinfo) GF_ASSERT(fd > 0); GF_ASSERT(volinfo); GF_ASSERT(volinfo->shandle); + xlator_t *this = NULL; + glusterd_volinfo_data_store_t *dict_data = NULL; + + this = THIS; + GF_ASSERT(this); shandle = volinfo->shandle; + + dict_data = GF_CALLOC(1, sizeof(glusterd_volinfo_data_store_t), + gf_gld_mt_volinfo_dict_data_t); + if (dict_data == NULL) { + gf_smsg(this->name, GF_LOG_ERROR, 0, GD_MSG_NO_MEMORY, NULL); + return -1; + } + ret = glusterd_volume_exclude_options_write(fd, volinfo); - if (ret) + if (ret) { goto out; + } + + dict_data->shandle = shandle; + dict_data->key_check = 1; shandle->fd = fd; - dict_foreach(volinfo->dict, _storeopts, shandle); + dict_foreach(volinfo->dict, _storeopts, (void *)dict_data); + + dict_data->key_check = 0; + dict_foreach(volinfo->gsync_slaves, _storeopts, (void *)dict_data); + + if (dict_data->buffer_len > 0) { + ret = gf_store_save_items(fd, dict_data->buffer); + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, 0, GD_MSG_FILE_OP_FAILED, NULL); + goto out; + } + } - dict_foreach(volinfo->gsync_slaves, _storeslaves, shandle); shandle->fd = 0; out: - gf_msg_debug(THIS->name, 0, "Returning %d", ret); + GF_FREE(dict_data); + gf_msg_debug(this->name, 0, "Returning %d", ret); return ret; } -int32_t +static int32_t glusterd_store_snapinfo_write(glusterd_snap_t *snap) { int32_t ret = -1; int fd = 0; - char buf[PATH_MAX] = ""; + char buf[PATH_MAX]; + uint total_len = 0; GF_ASSERT(snap); @@ -1174,30 +1066,34 @@ glusterd_store_snapinfo_write(glusterd_snap_t *snap) if (fd <= 0) goto out; - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_SNAP_ID, - uuid_utoa(snap->snap_id)); - if (ret) - goto out; - - snprintf(buf, sizeof(buf), "%d", snap->snap_status); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_SNAP_STATUS, buf); - if (ret) - goto out; - - snprintf(buf, sizeof(buf), "%d", snap->snap_restored); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_SNAP_RESTORED, buf); - if (ret) + ret = snprintf(buf + total_len, sizeof(buf) - total_len, + "%s=%s\n%s=%d\n%s=%d\n", GLUSTERD_STORE_KEY_SNAP_ID, + uuid_utoa(snap->snap_id), GLUSTERD_STORE_KEY_SNAP_STATUS, + snap->snap_status, GLUSTERD_STORE_KEY_SNAP_RESTORED, + snap->snap_restored); + if (ret < 0 || ret >= sizeof(buf) - total_len) { + ret = -1; goto out; + } + total_len += ret; if (snap->description) { - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_SNAP_DESC, - snap->description); - if (ret) + ret = snprintf(buf + total_len, sizeof(buf) - total_len, "%s=%s\n", + GLUSTERD_STORE_KEY_SNAP_DESC, snap->description); + if (ret < 0 || ret >= sizeof(buf) - total_len) { + ret = -1; goto out; + } + total_len += ret; } - snprintf(buf, sizeof(buf), "%ld", snap->time_stamp); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_SNAP_TIMESTAMP, buf); + ret = snprintf(buf + total_len, sizeof(buf) - total_len, "%s=%ld\n", + GLUSTERD_STORE_KEY_SNAP_TIMESTAMP, snap->time_stamp); + if (ret < 0 || ret >= sizeof(buf) - total_len) { + ret = -1; + goto out; + } + ret = gf_store_save_items(fd, buf); out: gf_msg_debug(THIS->name, 0, "Returning %d", ret); @@ -1360,112 +1256,34 @@ glusterd_store_create_snap_shandle_on_absence(glusterd_snap_t *snap) return ret; } -int32_t +static int32_t glusterd_store_brickinfos(glusterd_volinfo_t *volinfo, int vol_fd) { int32_t ret = 0; glusterd_brickinfo_t *brickinfo = NULL; + glusterd_brickinfo_t *ta_brickinfo = NULL; int32_t brick_count = 0; + int32_t ta_brick_count = 0; GF_ASSERT(volinfo); cds_list_for_each_entry(brickinfo, &volinfo->bricks, brick_list) { - ret = glusterd_store_brickinfo(volinfo, brickinfo, brick_count, vol_fd); + ret = glusterd_store_brickinfo(volinfo, brickinfo, brick_count, vol_fd, + 0); if (ret) goto out; brick_count++; } -out: - gf_msg_debug(THIS->name, 0, "Returning %d", ret); - return ret; -} - -int -_gd_store_rebalance_dict(dict_t *dict, char *key, data_t *value, void *data) -{ - int ret = -1; - int fd = 0; - - fd = *(int *)data; - - ret = gf_store_save_value(fd, key, value->data); - - return ret; -} - -int32_t -glusterd_store_state_tier_write(int fd, glusterd_volinfo_t *volinfo) -{ - int ret = -1; - char buf[PATH_MAX] = { - 0, - }; - - GF_VALIDATE_OR_GOTO(THIS->name, (fd > 0), out); - GF_VALIDATE_OR_GOTO(THIS->name, volinfo, out); - - /*tier counter values are stored here. so that after restart - * of glusterd tier resumes at the state is was brought down - */ - - if (volinfo->tier.defrag_cmd == GF_DEFRAG_CMD_STATUS) { - ret = 0; - goto out; + if (volinfo->thin_arbiter_count == 1) { + ta_brickinfo = list_first_entry(&volinfo->ta_bricks, + glusterd_brickinfo_t, brick_list); + ret = glusterd_store_brickinfo(volinfo, ta_brickinfo, ta_brick_count, + vol_fd, 1); + if (ret) + goto out; } - snprintf(buf, sizeof(buf), "%d", volinfo->tier.defrag_status); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_VOL_TIER_STATUS, buf); - if (ret) - goto out; - - snprintf(buf, sizeof(buf), "%d", volinfo->tier.op); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_TIER_DETACH_OP, buf); - if (ret) - goto out; - - snprintf(buf, sizeof(buf), "%" PRIu64, volinfo->tier.rebalance_files); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_VOL_MIGRATED_FILES, buf); - if (ret) - goto out; - - snprintf(buf, sizeof(buf), "%" PRIu64, volinfo->tier.rebalance_data); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_VOL_MIGRATED_SIZE, buf); - if (ret) - goto out; - - snprintf(buf, sizeof(buf), "%" PRIu64, volinfo->tier.lookedup_files); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_VOL_MIGRATIONS_SCANNED, - buf); - if (ret) - goto out; - - snprintf(buf, sizeof(buf), "%" PRIu64, volinfo->tier.rebalance_failures); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_VOL_MIGRATIONS_FAILURES, - buf); - if (ret) - goto out; - - snprintf(buf, sizeof(buf), "%" PRIu64, volinfo->tier.skipped_files); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_VOL_MIGRATIONS_SKIPPED, - buf); - if (ret) - goto out; - - snprintf(buf, sizeof(buf), "%f", volinfo->tier.rebalance_time); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_VOL_MIGRATION_RUN_TIME, - buf); - if (ret) - goto out; - - gf_uuid_unparse(volinfo->tier.rebalance_id, buf); - ret = gf_store_save_value(fd, GF_TIER_TID_KEY, buf); - if (ret) - goto out; - - if (volinfo->tier.dict) { - dict_foreach(volinfo->tier.dict, _gd_store_rebalance_dict, &fd); - } out: gf_msg_debug(THIS->name, 0, "Returning %d", ret); return ret; @@ -1475,9 +1293,15 @@ int32_t glusterd_store_node_state_write(int fd, glusterd_volinfo_t *volinfo) { int ret = -1; - char buf[PATH_MAX] = { - 0, - }; + char buf[PATH_MAX]; + char uuid[UUID_SIZE + 1]; + uint total_len = 0; + glusterd_volinfo_data_store_t *dict_data = NULL; + gf_store_handle_t shandle; + xlator_t *this = NULL; + + this = THIS; + GF_ASSERT(this); GF_ASSERT(fd > 0); GF_ASSERT(volinfo); @@ -1487,61 +1311,63 @@ glusterd_store_node_state_write(int fd, glusterd_volinfo_t *volinfo) goto out; } - snprintf(buf, sizeof(buf), "%d", volinfo->rebal.defrag_cmd); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_VOL_DEFRAG, buf); - if (ret) - goto out; - - snprintf(buf, sizeof(buf), "%d", volinfo->rebal.defrag_status); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_VOL_DEFRAG_STATUS, buf); - if (ret) - goto out; - - snprintf(buf, sizeof(buf), "%d", volinfo->rebal.op); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_DEFRAG_OP, buf); - if (ret) - goto out; - - gf_uuid_unparse(volinfo->rebal.rebalance_id, buf); - ret = gf_store_save_value(fd, GF_REBALANCE_TID_KEY, buf); - if (ret) - goto out; - - snprintf(buf, sizeof(buf), "%" PRIu64, volinfo->rebal.rebalance_files); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_VOL_DEFRAG_REB_FILES, buf); - if (ret) - goto out; - - snprintf(buf, sizeof(buf), "%" PRIu64, volinfo->rebal.rebalance_data); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_VOL_DEFRAG_SIZE, buf); - if (ret) - goto out; - - snprintf(buf, sizeof(buf), "%" PRIu64, volinfo->rebal.lookedup_files); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_VOL_DEFRAG_SCANNED, buf); - if (ret) - goto out; - - snprintf(buf, sizeof(buf), "%" PRIu64, volinfo->rebal.rebalance_failures); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_VOL_DEFRAG_FAILURES, buf); - if (ret) + gf_uuid_unparse(volinfo->rebal.rebalance_id, uuid); + ret = snprintf(buf + total_len, sizeof(buf) - total_len, + "%s=%d\n%s=%d\n%s=%d\n%s=%s\n", + GLUSTERD_STORE_KEY_VOL_DEFRAG, volinfo->rebal.defrag_cmd, + GLUSTERD_STORE_KEY_VOL_DEFRAG_STATUS, + volinfo->rebal.defrag_status, GLUSTERD_STORE_KEY_DEFRAG_OP, + volinfo->rebal.op, GF_REBALANCE_TID_KEY, uuid); + if (ret < 0 || ret >= sizeof(buf) - total_len) { + ret = -1; goto out; - - snprintf(buf, sizeof(buf), "%" PRIu64, volinfo->rebal.skipped_files); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_VOL_DEFRAG_SKIPPED, buf); - if (ret) + } + total_len += ret; + + ret = snprintf( + buf + total_len, sizeof(buf) - total_len, + "%s=%" PRIu64 "\n%s=%" PRIu64 "\n%s=%" PRIu64 "\n%s=%" PRIu64 + "\n%s=%" PRIu64 "\n%s=%lf\n", + GLUSTERD_STORE_KEY_VOL_DEFRAG_REB_FILES, volinfo->rebal.rebalance_files, + GLUSTERD_STORE_KEY_VOL_DEFRAG_SIZE, volinfo->rebal.rebalance_data, + GLUSTERD_STORE_KEY_VOL_DEFRAG_SCANNED, volinfo->rebal.lookedup_files, + GLUSTERD_STORE_KEY_VOL_DEFRAG_FAILURES, + volinfo->rebal.rebalance_failures, + GLUSTERD_STORE_KEY_VOL_DEFRAG_SKIPPED, volinfo->rebal.skipped_files, + GLUSTERD_STORE_KEY_VOL_DEFRAG_RUN_TIME, volinfo->rebal.rebalance_time); + if (ret < 0 || ret >= sizeof(buf) - total_len) { + ret = -1; goto out; + } - snprintf(buf, sizeof(buf), "%lf", volinfo->rebal.rebalance_time); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_VOL_DEFRAG_RUN_TIME, buf); - if (ret) + ret = gf_store_save_items(fd, buf); + if (ret) { goto out; + } if (volinfo->rebal.dict) { - dict_foreach(volinfo->rebal.dict, _gd_store_rebalance_dict, &fd); + dict_data = GF_CALLOC(1, sizeof(glusterd_volinfo_data_store_t), + gf_gld_mt_volinfo_dict_data_t); + if (dict_data == NULL) { + gf_smsg(this->name, GF_LOG_ERROR, 0, GD_MSG_NO_MEMORY, NULL); + return -1; + } + dict_data->shandle = &shandle; + shandle.fd = fd; + dict_foreach(volinfo->rebal.dict, _storeopts, (void *)dict_data); + if (dict_data->buffer_len > 0) { + ret = gf_store_save_items(fd, dict_data->buffer); + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, 0, GD_MSG_FILE_OP_FAILED, + NULL); + goto out; + ; + } + } } out: - gf_msg_debug(THIS->name, 0, "Returning %d", ret); + GF_FREE(dict_data); + gf_msg_debug(this->name, 0, "Returning %d", ret); return ret; } @@ -1562,12 +1388,6 @@ glusterd_store_perform_node_state_store(glusterd_volinfo_t *volinfo) if (ret) goto out; - if (volinfo->type == GF_CLUSTER_TYPE_TIER) { - ret = glusterd_store_state_tier_write(fd, volinfo); - if (ret) - goto out; - } - ret = gf_store_rename_tmppath(volinfo->node_state_shandle); if (ret) goto out; @@ -1579,7 +1399,7 @@ out: return ret; } -int32_t +static int32_t glusterd_store_perform_volume_store(glusterd_volinfo_t *volinfo) { int fd = -1; @@ -1596,6 +1416,10 @@ glusterd_store_perform_volume_store(glusterd_volinfo_t *volinfo) if (ret) goto out; + ret = glusterd_store_create_brick_dir(volinfo); + if (ret) + goto out; + ret = glusterd_store_brickinfos(volinfo, fd); if (ret) goto out; @@ -1657,6 +1481,7 @@ glusterd_store_brickinfos_atomic_update(glusterd_volinfo_t *volinfo) { int ret = -1; glusterd_brickinfo_t *brickinfo = NULL; + glusterd_brickinfo_t *ta_brickinfo = NULL; GF_ASSERT(volinfo); @@ -1666,6 +1491,15 @@ glusterd_store_brickinfos_atomic_update(glusterd_volinfo_t *volinfo) if (ret) goto out; } + + if (volinfo->thin_arbiter_count == 1) { + ta_brickinfo = list_first_entry(&volinfo->ta_bricks, + glusterd_brickinfo_t, brick_list); + ret = gf_store_rename_tmppath(ta_brickinfo->shandle); + if (ret) + goto out; + } + out: return ret; } @@ -1781,11 +1615,8 @@ glusterd_store_volinfo(glusterd_volinfo_t *volinfo, pthread_mutex_lock(&volinfo->store_volinfo_lock); { glusterd_perform_volinfo_version_action(volinfo, ac); - ret = glusterd_store_create_volume_dir(volinfo); - if (ret) - goto unlock; - ret = glusterd_store_create_volume_run_dir(volinfo); + ret = glusterd_store_create_volume_dirs(volinfo); if (ret) goto unlock; @@ -1820,6 +1651,7 @@ glusterd_store_volinfo(glusterd_volinfo_t *volinfo, unlock: pthread_mutex_unlock(&volinfo->store_volinfo_lock); pthread_mutex_unlock(&ctx->cleanup_lock); + if (ret) glusterd_store_volume_cleanup_tmp(volinfo); @@ -1869,7 +1701,7 @@ glusterd_store_delete_volume(glusterd_volinfo_t *volinfo) goto out; } - ret = sys_mkdir(trashdir, 0777); + ret = sys_mkdir(trashdir, 0755); if (ret && errno != EEXIST) { gf_msg(this->name, GF_LOG_ERROR, errno, GD_MSG_CREATE_DIR_FAILED, "Failed to create trash " @@ -1956,7 +1788,7 @@ glusterd_store_delete_snap(glusterd_snap_t *snap) goto out; } - ret = sys_mkdir(trashdir, 0777); + ret = sys_mkdir(trashdir, 0755); if (ret && errno != EEXIST) { gf_msg(this->name, GF_LOG_ERROR, errno, GD_MSG_CREATE_DIR_FAILED, "Failed to create trash " @@ -1981,8 +1813,9 @@ glusterd_store_delete_snap(glusterd_snap_t *snap) goto out; } - GF_SKIP_IRRELEVANT_ENTRIES(entry, dir, scratch); - while (entry) { + while ((entry = sys_readdir(dir, scratch))) { + if (gf_irrelevant_entry(entry)) + continue; len = snprintf(path, PATH_MAX, "%s/%s", delete_path, entry->d_name); if ((len < 0) || (len >= PATH_MAX)) { goto stat_failed; @@ -2012,7 +1845,6 @@ glusterd_store_delete_snap(glusterd_snap_t *snap) ret ? "Failed to remove" : "Removed", entry->d_name); stat_failed: memset(path, 0, sizeof(path)); - GF_SKIP_IRRELEVANT_ENTRIES(entry, dir, scratch); } ret = sys_closedir(dir); @@ -2045,15 +1877,10 @@ glusterd_store_global_info(xlator_t *this) { int ret = -1; glusterd_conf_t *conf = NULL; - char op_version_str[15] = { - 0, - }; - char path[PATH_MAX] = { - 0, - }; + char buf[PATH_MAX]; + uint total_len = 0; gf_store_handle_t *handle = NULL; char *uuid_str = NULL; - int32_t len = 0; conf = this->private; @@ -2062,12 +1889,13 @@ glusterd_store_global_info(xlator_t *this) goto out; if (!conf->handle) { - len = snprintf(path, PATH_MAX, "%s/%s", conf->workdir, + ret = snprintf(buf, sizeof(buf), "%s/%s", conf->workdir, GLUSTERD_INFO_FILE); - if ((len < 0) || (len >= PATH_MAX)) { + if ((ret < 0) || (ret >= sizeof(buf))) { + ret = -1; goto out; } - ret = gf_store_handle_new(path, &handle); + ret = gf_store_handle_new(buf, &handle); if (ret) { gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_STORE_HANDLE_GET_FAIL, "Unable to get store handle"); @@ -2091,23 +1919,26 @@ glusterd_store_global_info(xlator_t *this) ret = -1; goto out; } - pthread_mutex_lock(&conf->mutex); - { - ret = gf_store_save_value(handle->fd, GLUSTERD_STORE_UUID_KEY, - uuid_str); + + ret = snprintf(buf, sizeof(buf), "%s=%s\n", GLUSTERD_STORE_UUID_KEY, + uuid_str); + if (ret < 0 || ret >= sizeof(buf)) { + ret = -1; + goto out; } - pthread_mutex_unlock(&conf->mutex); - if (ret) { - gf_msg(this->name, GF_LOG_CRITICAL, 0, GD_MSG_UUID_SET_FAIL, - "Storing uuid failed ret = %d", ret); + total_len += ret; + + ret = snprintf(buf + total_len, sizeof(buf) - total_len, "%s=%d\n", + GD_OP_VERSION_KEY, conf->op_version); + if (ret < 0 || ret >= sizeof(buf) - total_len) { + ret = -1; goto out; } - snprintf(op_version_str, sizeof(op_version_str), "%d", conf->op_version); - ret = gf_store_save_value(handle->fd, GD_OP_VERSION_KEY, op_version_str); + ret = gf_store_save_items(handle->fd, buf); if (ret) { - gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_OP_VERS_STORE_FAIL, - "Storing op-version failed ret = %d", ret); + gf_msg(this->name, GF_LOG_CRITICAL, 0, GD_MSG_OP_VERS_STORE_FAIL, + "Storing glusterd global-info failed ret = %d", ret); goto out; } @@ -2310,68 +2141,6 @@ out: } int -glusterd_retrieve_sys_snap_max_limit(xlator_t *this, uint64_t *limit, char *key) -{ - char *limit_str = NULL; - glusterd_conf_t *priv = NULL; - int ret = -1; - uint64_t tmp_limit = 0; - char *tmp = NULL; - char path[PATH_MAX] = { - 0, - }; - gf_store_handle_t *handle = NULL; - int32_t len = 0; - - GF_ASSERT(this); - priv = this->private; - - GF_ASSERT(priv); - GF_ASSERT(limit); - GF_ASSERT(key); - - if (!priv->handle) { - len = snprintf(path, PATH_MAX, "%s/%s", priv->workdir, - GLUSTERD_INFO_FILE); - if ((len < 0) || (len >= PATH_MAX)) { - goto out; - } - ret = gf_store_handle_retrieve(path, &handle); - - if (ret) { - gf_msg_debug(this->name, 0, - "Unable to get store " - "handle!"); - goto out; - } - - priv->handle = handle; - } - - ret = gf_store_retrieve_value(priv->handle, key, &limit_str); - if (ret) { - gf_msg_debug(this->name, 0, "No previous %s present", key); - goto out; - } - - tmp_limit = strtoul(limit_str, &tmp, 10); - if ((tmp_limit <= 0) || (tmp && strlen(tmp) > 1)) { - gf_msg(this->name, GF_LOG_WARNING, EINVAL, GD_MSG_UNSUPPORTED_VERSION, - "invalid version number"); - goto out; - } - - *limit = tmp_limit; - - ret = 0; -out: - if (limit_str) - GF_FREE(limit_str); - - return ret; -} - -int glusterd_restore_op_version(xlator_t *this) { glusterd_conf_t *conf = NULL; @@ -2572,7 +2341,7 @@ glusterd_store_retrieve_snapd(glusterd_volinfo_t *volinfo) ret = 0; out: - if (gf_store_iter_destroy(iter)) { + if (gf_store_iter_destroy(&iter)) { gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_STORE_ITER_DESTROY_FAIL, "Failed to destroy store iter"); ret = -1; @@ -2586,6 +2355,7 @@ glusterd_store_retrieve_bricks(glusterd_volinfo_t *volinfo) { int32_t ret = 0; glusterd_brickinfo_t *brickinfo = NULL; + glusterd_brickinfo_t *ta_brickinfo = NULL; gf_store_iter_t *iter = NULL; char *key = NULL; char *value = NULL; @@ -2597,7 +2367,8 @@ glusterd_store_retrieve_bricks(glusterd_volinfo_t *volinfo) }; glusterd_conf_t *priv = NULL; int32_t brick_count = 0; - char tmpkey[4096] = { + int32_t ta_brick_count = 0; + char tmpkey[32] = { 0, }; gf_store_iter_t *tmpiter = NULL; @@ -2606,6 +2377,10 @@ glusterd_store_retrieve_bricks(glusterd_volinfo_t *volinfo) struct pmap_registry *pmap = NULL; xlator_t *this = NULL; int brickid = 0; + /* ta_brick_id initialization with 2 since ta-brick id starts with + * volname-ta-2 + */ + int ta_brick_id = 2; gf_store_op_errno_t op_errno = GD_STORE_SUCCESS; int32_t len = 0; @@ -2687,7 +2462,13 @@ glusterd_store_retrieve_bricks(glusterd_volinfo_t *volinfo) } } else if (!strncmp(key, GLUSTERD_STORE_KEY_BRICK_PORT, SLEN(GLUSTERD_STORE_KEY_BRICK_PORT))) { - gf_string2int(value, &brickinfo->port); + ret = gf_string2int(value, &brickinfo->port); + if (ret == -1) { + gf_msg(this->name, GF_LOG_ERROR, EINVAL, + GD_MSG_INCOMPATIBLE_VALUE, + "Failed to convert " + "string to integer"); + } if (brickinfo->port < priv->base_port) { /* This is required to adhere to the @@ -2702,7 +2483,13 @@ glusterd_store_retrieve_bricks(glusterd_volinfo_t *volinfo) } } else if (!strncmp(key, GLUSTERD_STORE_KEY_BRICK_RDMA_PORT, SLEN(GLUSTERD_STORE_KEY_BRICK_RDMA_PORT))) { - gf_string2int(value, &brickinfo->rdma_port); + ret = gf_string2int(value, &brickinfo->rdma_port); + if (ret == -1) { + gf_msg(this->name, GF_LOG_ERROR, EINVAL, + GD_MSG_INCOMPATIBLE_VALUE, + "Failed to convert " + "string to integer"); + } if (brickinfo->rdma_port < priv->base_port) { /* This is required to adhere to the @@ -2878,25 +2665,203 @@ glusterd_store_retrieve_bricks(glusterd_volinfo_t *volinfo) brickinfo->path); /* No need for treating it as an error, lets continue with just a message */ + } else { + brickinfo->statfs_fsid = brickstat.f_fsid; } - brickinfo->statfs_fsid = brickstat.f_fsid; } cds_list_add_tail(&brickinfo->brick_list, &volinfo->bricks); brick_count++; } + if (gf_store_iter_destroy(&tmpiter)) { + gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_STORE_ITER_DESTROY_FAIL, + "Failed to destroy store iter"); + ret = -1; + goto out; + } + + ret = gf_store_iter_new(volinfo->shandle, &tmpiter); + + if (ret) + goto out; + + if (volinfo->thin_arbiter_count == 1) { + snprintf(tmpkey, sizeof(tmpkey), "%s-%d", + GLUSTERD_STORE_KEY_VOL_TA_BRICK, 0); + while (ta_brick_count < volinfo->subvol_count) { + ret = glusterd_brickinfo_new(&ta_brickinfo); + if (ret) + goto out; + + ret = gf_store_iter_get_matching(tmpiter, tmpkey, &tmpvalue); + + len = snprintf(path, sizeof(path), "%s/%s", brickdir, tmpvalue); + GF_FREE(tmpvalue); + tmpvalue = NULL; + if ((len < 0) || (len >= sizeof(path))) { + ret = -1; + goto out; + } + + ret = gf_store_handle_retrieve(path, &ta_brickinfo->shandle); + + if (ret) + goto out; + + ret = gf_store_iter_new(ta_brickinfo->shandle, &iter); + + if (ret) + goto out; + + ret = gf_store_iter_get_next(iter, &key, &value, &op_errno); + if (ret) { + gf_msg("glusterd", GF_LOG_ERROR, op_errno, + GD_MSG_STORE_ITER_GET_FAIL, + "Unable to iterate " + "the store for brick: %s", + path); + goto out; + } + + while (!ret) { + if (!strncmp(key, GLUSTERD_STORE_KEY_BRICK_HOSTNAME, + SLEN(GLUSTERD_STORE_KEY_BRICK_HOSTNAME))) { + if (snprintf(ta_brickinfo->hostname, + sizeof(ta_brickinfo->hostname), "%s", + value) >= sizeof(ta_brickinfo->hostname)) { + gf_msg("glusterd", GF_LOG_ERROR, op_errno, + GD_MSG_PARSE_BRICKINFO_FAIL, + "brick hostname truncated: %s", + ta_brickinfo->hostname); + goto out; + } + } else if (!strncmp(key, GLUSTERD_STORE_KEY_BRICK_PATH, + SLEN(GLUSTERD_STORE_KEY_BRICK_PATH))) { + if (snprintf(ta_brickinfo->path, sizeof(ta_brickinfo->path), + "%s", value) >= sizeof(ta_brickinfo->path)) { + gf_msg("glusterd", GF_LOG_ERROR, op_errno, + GD_MSG_PARSE_BRICKINFO_FAIL, + "brick path truncated: %s", ta_brickinfo->path); + goto out; + } + } else if (!strncmp(key, GLUSTERD_STORE_KEY_BRICK_REAL_PATH, + SLEN(GLUSTERD_STORE_KEY_BRICK_REAL_PATH))) { + if (snprintf(ta_brickinfo->real_path, + sizeof(ta_brickinfo->real_path), "%s", + value) >= sizeof(ta_brickinfo->real_path)) { + gf_msg("glusterd", GF_LOG_ERROR, op_errno, + GD_MSG_PARSE_BRICKINFO_FAIL, + "real_path truncated: %s", + ta_brickinfo->real_path); + goto out; + } + } else if (!strncmp(key, GLUSTERD_STORE_KEY_BRICK_PORT, + SLEN(GLUSTERD_STORE_KEY_BRICK_PORT))) { + ret = gf_string2int(value, &ta_brickinfo->port); + if (ret == -1) { + gf_msg(this->name, GF_LOG_ERROR, EINVAL, + GD_MSG_INCOMPATIBLE_VALUE, + "Failed to convert " + "string to integer"); + } + + if (ta_brickinfo->port < priv->base_port) { + /* This is required to adhere to the + IANA standards */ + ta_brickinfo->port = 0; + } + } else if (!strncmp(key, GLUSTERD_STORE_KEY_BRICK_RDMA_PORT, + SLEN(GLUSTERD_STORE_KEY_BRICK_RDMA_PORT))) { + ret = gf_string2int(value, &ta_brickinfo->rdma_port); + if (ret == -1) { + gf_msg(this->name, GF_LOG_ERROR, EINVAL, + GD_MSG_INCOMPATIBLE_VALUE, + "Failed to convert " + "string to integer"); + } + + if (ta_brickinfo->rdma_port < priv->base_port) { + /* This is required to adhere to the + IANA standards */ + ta_brickinfo->rdma_port = 0; + } + } else if (!strncmp( + key, GLUSTERD_STORE_KEY_BRICK_DECOMMISSIONED, + SLEN(GLUSTERD_STORE_KEY_BRICK_DECOMMISSIONED))) { + ret = gf_string2int(value, &ta_brickinfo->decommissioned); + if (ret == -1) { + gf_msg(this->name, GF_LOG_ERROR, EINVAL, + GD_MSG_INCOMPATIBLE_VALUE, + "Failed to convert " + "string to integer"); + } + + } else if (!strcmp(key, GLUSTERD_STORE_KEY_BRICK_ID)) { + if (snprintf(ta_brickinfo->brick_id, + sizeof(ta_brickinfo->brick_id), "%s", + value) >= sizeof(ta_brickinfo->brick_id)) { + gf_msg("glusterd", GF_LOG_ERROR, op_errno, + GD_MSG_PARSE_BRICKINFO_FAIL, + "brick_id truncated: %s", + ta_brickinfo->brick_id); + goto out; + } + } else if (!strncmp(key, GLUSTERD_STORE_KEY_BRICK_FSID, + SLEN(GLUSTERD_STORE_KEY_BRICK_FSID))) { + ret = gf_string2uint64(value, &ta_brickinfo->statfs_fsid); + if (ret) { + gf_msg(this->name, GF_LOG_ERROR, 0, + GD_MSG_INVALID_ENTRY, + "%s " + "is not a valid uint64_t value", + value); + } + } else if (!strcmp(key, GLUSTERD_STORE_KEY_BRICK_UUID)) { + gf_uuid_parse(value, brickinfo->uuid); + } else if (!strncmp( + key, GLUSTERD_STORE_KEY_BRICK_SNAP_STATUS, + SLEN(GLUSTERD_STORE_KEY_BRICK_SNAP_STATUS))) { + ret = gf_string2int(value, &ta_brickinfo->snap_status); + if (ret == -1) { + gf_msg(this->name, GF_LOG_ERROR, EINVAL, + GD_MSG_INCOMPATIBLE_VALUE, + "Failed to convert " + "string to integer"); + } + + } else { + gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_UNKNOWN_KEY, + "Unknown key: %s", key); + } + + GF_FREE(key); + GF_FREE(value); + key = NULL; + value = NULL; + ret = gf_store_iter_get_next(iter, &key, &value, &op_errno); + } + + GLUSTERD_ASSIGN_BRICKID_TO_TA_BRICKINFO(ta_brickinfo, volinfo, + ta_brick_id); + ta_brick_id += 3; + + cds_list_add_tail(&ta_brickinfo->brick_list, &volinfo->ta_bricks); + ta_brick_count++; + } + } + assign_brick_groups(volinfo); ret = 0; out: - if (gf_store_iter_destroy(tmpiter)) { + if (gf_store_iter_destroy(&tmpiter)) { gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_STORE_ITER_DESTROY_FAIL, "Failed to destroy store iter"); ret = -1; } - if (gf_store_iter_destroy(iter)) { + if (gf_store_iter_destroy(&iter)) { gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_STORE_ITER_DESTROY_FAIL, "Failed to destroy store iter"); ret = -1; @@ -2969,52 +2934,22 @@ glusterd_store_retrieve_node_state(glusterd_volinfo_t *volinfo) volinfo->rebal.op = atoi(value); } else if (!strncmp(key, GLUSTERD_STORE_KEY_VOL_DEFRAG_REB_FILES, SLEN(GLUSTERD_STORE_KEY_VOL_DEFRAG_REB_FILES))) { - volinfo->rebal.rebalance_files = atoi(value); + sscanf(value, "%" PRIu64, &volinfo->rebal.rebalance_files); } else if (!strncmp(key, GLUSTERD_STORE_KEY_VOL_DEFRAG_SIZE, SLEN(GLUSTERD_STORE_KEY_VOL_DEFRAG_SIZE))) { - volinfo->rebal.rebalance_data = atoi(value); + sscanf(value, "%" PRIu64, &volinfo->rebal.rebalance_data); } else if (!strncmp(key, GLUSTERD_STORE_KEY_VOL_DEFRAG_SCANNED, SLEN(GLUSTERD_STORE_KEY_VOL_DEFRAG_SCANNED))) { - volinfo->rebal.lookedup_files = atoi(value); + sscanf(value, "%" PRIu64, &volinfo->rebal.lookedup_files); } else if (!strncmp(key, GLUSTERD_STORE_KEY_VOL_DEFRAG_FAILURES, SLEN(GLUSTERD_STORE_KEY_VOL_DEFRAG_FAILURES))) { - volinfo->rebal.rebalance_failures = atoi(value); + sscanf(value, "%" PRIu64, &volinfo->rebal.rebalance_failures); } else if (!strncmp(key, GLUSTERD_STORE_KEY_VOL_DEFRAG_SKIPPED, SLEN(GLUSTERD_STORE_KEY_VOL_DEFRAG_SKIPPED))) { - volinfo->rebal.skipped_files = atoi(value); + sscanf(value, "%" PRIu64, &volinfo->rebal.skipped_files); } else if (!strncmp(key, GLUSTERD_STORE_KEY_VOL_DEFRAG_RUN_TIME, SLEN(GLUSTERD_STORE_KEY_VOL_DEFRAG_RUN_TIME))) { volinfo->rebal.rebalance_time = atoi(value); - - /* if none of the above keys match then its related to tier - * so we get the values and store it on volinfo->tier - */ - } else if (!strncmp(key, GLUSTERD_STORE_KEY_VOL_TIER_STATUS, - SLEN(GLUSTERD_STORE_KEY_VOL_TIER_STATUS))) { - volinfo->tier.defrag_status = atoi(value); - } else if (!strncmp(key, GF_TIER_TID_KEY, SLEN(GF_TIER_TID_KEY))) { - gf_uuid_parse(value, volinfo->tier.rebalance_id); - } else if (!strncmp(key, GLUSTERD_STORE_KEY_TIER_DETACH_OP, - SLEN(GLUSTERD_STORE_KEY_TIER_DETACH_OP))) { - volinfo->tier.op = atoi(value); - } else if (!strncmp(key, GLUSTERD_STORE_KEY_VOL_MIGRATED_FILES, - SLEN(GLUSTERD_STORE_KEY_VOL_MIGRATED_FILES))) { - volinfo->tier.rebalance_files = atoi(value); - } else if (!strncmp(key, GLUSTERD_STORE_KEY_VOL_MIGRATED_SIZE, - SLEN(GLUSTERD_STORE_KEY_VOL_MIGRATED_SIZE))) { - volinfo->tier.rebalance_data = atoi(value); - } else if (!strncmp(key, GLUSTERD_STORE_KEY_VOL_MIGRATIONS_SCANNED, - SLEN(GLUSTERD_STORE_KEY_VOL_MIGRATIONS_SCANNED))) { - volinfo->tier.lookedup_files = atoi(value); - } else if (!strncmp(key, GLUSTERD_STORE_KEY_VOL_MIGRATIONS_FAILURES, - SLEN(GLUSTERD_STORE_KEY_VOL_MIGRATIONS_FAILURES))) { - volinfo->tier.rebalance_failures = atoi(value); - } else if (!strncmp(key, GLUSTERD_STORE_KEY_VOL_MIGRATIONS_SKIPPED, - SLEN(GLUSTERD_STORE_KEY_VOL_MIGRATIONS_SKIPPED))) { - volinfo->tier.skipped_files = atoi(value); - } else if (!strncmp(key, GLUSTERD_STORE_KEY_VOL_MIGRATION_RUN_TIME, - SLEN(GLUSTERD_STORE_KEY_VOL_MIGRATION_RUN_TIME))) { - volinfo->tier.rebalance_time = atoi(value); } else { if (!tmp_dict) { tmp_dict = dict_new(); @@ -3048,10 +2983,7 @@ glusterd_store_retrieve_node_state(glusterd_volinfo_t *volinfo) ret = gf_store_iter_get_next(iter, &key, &value, &op_errno); } if (tmp_dict) { - if (volinfo->type == GF_CLUSTER_TYPE_TIER) - volinfo->tier.dict = dict_ref(tmp_dict); - else - volinfo->rebal.dict = dict_ref(tmp_dict); + volinfo->rebal.dict = dict_ref(tmp_dict); } if (op_errno != GD_STORE_EOF) { @@ -3062,7 +2994,7 @@ glusterd_store_retrieve_node_state(glusterd_volinfo_t *volinfo) ret = 0; out: - if (gf_store_iter_destroy(iter)) { + if (gf_store_iter_destroy(&iter)) { gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_STORE_ITER_DESTROY_FAIL, "Failed to destroy store iter"); ret = -1; @@ -3073,8 +3005,6 @@ out: if (ret) { if (volinfo->rebal.dict) dict_unref(volinfo->rebal.dict); - else if (volinfo->tier.dict) - dict_unref(volinfo->tier.dict); } if (tmp_dict) dict_unref(tmp_dict); @@ -3167,6 +3097,8 @@ glusterd_store_update_volinfo(glusterd_volinfo_t *volinfo) volinfo->replica_count = atoi(value); } else if (!strcmp(key, GLUSTERD_STORE_KEY_VOL_ARBITER_CNT)) { volinfo->arbiter_count = atoi(value); + } else if (!strcmp(key, GLUSTERD_STORE_KEY_VOL_THIN_ARBITER_CNT)) { + volinfo->thin_arbiter_count = atoi(value); } else if (!strncmp(key, GLUSTERD_STORE_KEY_VOL_DISPERSE_CNT, SLEN(GLUSTERD_STORE_KEY_VOL_DISPERSE_CNT))) { volinfo->disperse_count = atoi(value); @@ -3211,9 +3143,6 @@ glusterd_store_update_volinfo(glusterd_volinfo_t *volinfo) } else if (!strncmp(key, GLUSTERD_STORE_KEY_VOL_CLIENT_OP_VERSION, SLEN(GLUSTERD_STORE_KEY_VOL_CLIENT_OP_VERSION))) { volinfo->client_op_version = atoi(value); - } else if (!strncmp(key, GLUSTERD_STORE_KEY_VOL_CAPS, - SLEN(GLUSTERD_STORE_KEY_VOL_CAPS))) { - volinfo->caps = atoi(value); } else if (!strncmp(key, GLUSTERD_STORE_KEY_SNAP_MAX_HARD_LIMIT, SLEN(GLUSTERD_STORE_KEY_SNAP_MAX_HARD_LIMIT))) { volinfo->snap_max_hard_limit = (uint64_t)atoll(value); @@ -3233,28 +3162,6 @@ glusterd_store_update_volinfo(glusterd_volinfo_t *volinfo) "parent_volname truncated: %s", volinfo->parent_volname); goto out; } - } else if (!strncmp(key, GF_TIER_ENABLED, SLEN(GF_TIER_ENABLED))) { - volinfo->is_tier_enabled = atoi(value); - } else if (!strncmp(key, GLUSTERD_STORE_KEY_COLD_COUNT, strlen(key))) { - volinfo->tier_info.cold_brick_count = atoi(value); - } else if (!strncmp(key, GLUSTERD_STORE_KEY_COLD_REPLICA_COUNT, - strlen(key))) { - volinfo->tier_info.cold_replica_count = atoi(value); - } else if (!strncmp(key, GLUSTERD_STORE_KEY_COLD_DISPERSE_COUNT, - strlen(key))) { - volinfo->tier_info.cold_disperse_count = atoi(value); - } else if (!strncmp(key, GLUSTERD_STORE_KEY_COLD_REDUNDANCY_COUNT, - strlen(key))) { - volinfo->tier_info.cold_redundancy_count = atoi(value); - } else if (!strncmp(key, GLUSTERD_STORE_KEY_HOT_COUNT, strlen(key))) { - volinfo->tier_info.hot_brick_count = atoi(value); - } else if (!strncmp(key, GLUSTERD_STORE_KEY_HOT_REPLICA_COUNT, - strlen(key))) { - volinfo->tier_info.hot_replica_count = atoi(value); - } else if (!strncmp(key, GLUSTERD_STORE_KEY_HOT_TYPE, strlen(key))) { - volinfo->tier_info.hot_type = atoi(value); - } else if (!strncmp(key, GLUSTERD_STORE_KEY_COLD_TYPE, strlen(key))) { - volinfo->tier_info.cold_type = atoi(value); } else if (!strncmp(key, GLUSTERD_STORE_KEY_VOL_QUOTA_VERSION, SLEN(GLUSTERD_STORE_KEY_VOL_QUOTA_VERSION))) { volinfo->quota_xattr_version = atoi(value); @@ -3273,8 +3180,11 @@ glusterd_store_update_volinfo(glusterd_volinfo_t *volinfo) case 0: /*Ignore GLUSTERD_STORE_KEY_VOL_BRICK since - glusterd_store_retrieve_bricks gets it later*/ - if (!strstr(key, GLUSTERD_STORE_KEY_VOL_BRICK)) + glusterd_store_retrieve_bricks gets it later. + also, ignore tier-enabled key as we deprecated + tier xlator*/ + if (!strstr(key, GLUSTERD_STORE_KEY_VOL_BRICK) || + !strstr(key, GF_TIER_ENABLED)) gf_msg(this->name, GF_LOG_WARNING, 0, GD_MSG_UNKNOWN_KEY, "Unknown key: %s", key); break; @@ -3330,7 +3240,6 @@ glusterd_store_update_volinfo(glusterd_volinfo_t *volinfo) GF_ASSERT(volinfo->redundancy_count > 0); break; - case GF_CLUSTER_TYPE_TIER: case GF_CLUSTER_TYPE_STRIPE: case GF_CLUSTER_TYPE_STRIPE_REPLICATE: gf_msg(this->name, GF_LOG_CRITICAL, ENOTSUP, @@ -3361,7 +3270,7 @@ glusterd_store_update_volinfo(glusterd_volinfo_t *volinfo) ret = 0; out: - if (gf_store_iter_destroy(iter)) { + if (gf_store_iter_destroy(&iter)) { gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_STORE_ITER_DESTROY_FAIL, "Failed to destroy store iter"); ret = -1; @@ -3466,20 +3375,6 @@ glusterd_store_set_options_path(glusterd_conf_t *conf, char *path, size_t len) snprintf(path, len, "%s/options", conf->workdir); } -int -_store_global_opts(dict_t *this, char *key, data_t *value, void *data) -{ - gf_store_handle_t *shandle = data; - - if (gf_store_save_value(shandle->fd, key, (char *)value->data)) { - gf_msg(THIS->name, GF_LOG_ERROR, 0, GD_MSG_STORE_HANDLE_WRITE_FAIL, - "Unable to write into store handle for key : %s, value %s", key, - (char *)value->data); - } - - return 0; -} - int32_t glusterd_store_options(xlator_t *this, dict_t *opts) { @@ -3488,13 +3383,15 @@ glusterd_store_options(xlator_t *this, dict_t *opts) char path[PATH_MAX] = {0}; int fd = -1; int32_t ret = -1; + glusterd_volinfo_data_store_t *dict_data = NULL; conf = this->private; glusterd_store_set_options_path(conf, path, sizeof(path)); ret = gf_store_handle_new(path, &shandle); - if (ret) + if (ret) { goto out; + } fd = gf_store_mkstemp(shandle); if (fd <= 0) { @@ -3502,15 +3399,30 @@ glusterd_store_options(xlator_t *this, dict_t *opts) goto out; } + dict_data = GF_CALLOC(1, sizeof(glusterd_volinfo_data_store_t), + gf_gld_mt_volinfo_dict_data_t); + if (dict_data == NULL) { + gf_smsg(this->name, GF_LOG_ERROR, 0, GD_MSG_NO_MEMORY, NULL); + return -1; + } + dict_data->shandle = shandle; shandle->fd = fd; - dict_foreach(opts, _store_global_opts, shandle); - shandle->fd = 0; + dict_foreach(opts, _storeopts, (void *)dict_data); + if (dict_data->buffer_len > 0) { + ret = gf_store_save_items(fd, dict_data->buffer); + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, 0, GD_MSG_FILE_OP_FAILED, NULL); + goto out; + } + } + ret = gf_store_rename_tmppath(shandle); - if (ret) - goto out; out: - if ((ret < 0) && (fd > 0)) + shandle->fd = 0; + GF_FREE(dict_data); + if ((ret < 0) && (fd > 0)) { gf_store_unlink_tmppath(shandle); + } gf_store_handle_destroy(shandle); return ret; } @@ -3556,7 +3468,7 @@ glusterd_store_retrieve_options(xlator_t *this) goto out; ret = 0; out: - (void)gf_store_iter_destroy(iter); + (void)gf_store_iter_destroy(&iter); gf_store_handle_destroy(shandle); return ret; } @@ -3608,28 +3520,28 @@ glusterd_store_retrieve_volumes(xlator_t *this, glusterd_snap_t *snap) goto out; } - GF_SKIP_IRRELEVANT_ENTRIES(entry, dir, scratch); - - while (entry) { + while ((entry = sys_readdir(dir, scratch))) { + if (gf_irrelevant_entry(entry)) + continue; if (snap && ((!strcmp(entry->d_name, "geo-replication")) || (!strcmp(entry->d_name, "info")))) - goto next; + continue; len = snprintf(entry_path, PATH_MAX, "%s/%s", path, entry->d_name); - if ((len < 0) || (len >= PATH_MAX)) { - goto next; - } + if ((len < 0) || (len >= PATH_MAX)) + continue; + ret = sys_lstat(entry_path, &st); if (ret == -1) { gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_INVALID_ENTRY, "Failed to stat entry %s : %s", path, strerror(errno)); - goto next; + continue; } if (!S_ISDIR(st.st_mode)) { gf_msg_debug(this->name, 0, "%s is not a valid volume", entry->d_name); - goto next; + continue; } volinfo = glusterd_store_retrieve_volume(entry->d_name, snap); @@ -3652,8 +3564,6 @@ glusterd_store_retrieve_volumes(xlator_t *this, glusterd_snap_t *snap) glusterd_store_create_nodestate_sh_on_absence(volinfo); glusterd_store_perform_node_state_store(volinfo); } - next: - GF_SKIP_IRRELEVANT_ENTRIES(entry, dir, scratch); } ret = 0; @@ -3827,7 +3737,7 @@ glusterd_recreate_vol_brick_mounts(xlator_t *this, glusterd_volinfo_t *volinfo) ret = sys_lstat(brickinfo->path, &st_buf); if (ret) { if (errno == ENOENT) { - ret = mkdir_p(brick_mount_path, 0777, _gf_true); + ret = mkdir_p(brick_mount_path, 0755, _gf_true); if (ret) { gf_msg(this->name, GF_LOG_ERROR, errno, GD_MSG_CREATE_DIR_FAILED, "Failed to create %s. ", @@ -4008,7 +3918,7 @@ glusterd_store_update_snap(glusterd_snap_t *snap) ret = 0; out: - if (gf_store_iter_destroy(iter)) { + if (gf_store_iter_destroy(&iter)) { gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_STORE_ITER_DESTROY_FAIL, "Failed to destroy store iter"); ret = -1; @@ -4074,7 +3984,6 @@ out: int32_t glusterd_store_retrieve_missed_snaps_list(xlator_t *this) { - char buf[PATH_MAX] = ""; char path[PATH_MAX] = ""; char *snap_vol_id = NULL; char *missed_node_info = NULL; @@ -4111,8 +4020,8 @@ glusterd_store_retrieve_missed_snaps_list(xlator_t *this) } do { - ret = gf_store_read_and_tokenize( - fp, buf, sizeof(buf), &missed_node_info, &value, &store_errno); + ret = gf_store_read_and_tokenize(fp, &missed_node_info, &value, + &store_errno); if (ret) { if (store_errno == GD_STORE_EOF) { gf_msg_debug(this->name, 0, "EOF for missed_snap_list"); @@ -4204,9 +4113,9 @@ glusterd_store_retrieve_snaps(xlator_t *this) goto out; } - GF_SKIP_IRRELEVANT_ENTRIES(entry, dir, scratch); - - while (entry) { + while ((entry = sys_readdir(dir, scratch))) { + if (gf_irrelevant_entry(entry)) + continue; if (strcmp(entry->d_name, GLUSTERD_MISSED_SNAPS_LIST_FILE)) { ret = glusterd_store_retrieve_snap(entry->d_name); if (ret) { @@ -4215,7 +4124,6 @@ glusterd_store_retrieve_snaps(xlator_t *this) goto out; } } - GF_SKIP_IRRELEVANT_ENTRIES(entry, dir, scratch); } /* Retrieve missed_snaps_list */ @@ -4237,8 +4145,8 @@ out: int32_t glusterd_store_write_missed_snapinfo(int32_t fd) { - char key[PATH_MAX] = ""; - char value[PATH_MAX] = ""; + char key[(UUID_SIZE * 2) + 2]; + char value[PATH_MAX]; int32_t ret = -1; glusterd_conf_t *priv = NULL; glusterd_missed_snap_info *missed_snapinfo = NULL; @@ -4527,41 +4435,39 @@ glusterd_store_create_peer_shandle(glusterd_peerinfo_t *peerinfo) return ret; } -int32_t +static int32_t glusterd_store_peer_write(int fd, glusterd_peerinfo_t *peerinfo) { - char buf[50] = {0}; + char buf[PATH_MAX]; + uint total_len = 0; int32_t ret = 0; int32_t i = 1; glusterd_peer_hostname_t *hostname = NULL; - char *key = NULL; - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_PEER_UUID, - uuid_utoa(peerinfo->uuid)); - if (ret) - goto out; - - snprintf(buf, sizeof(buf), "%d", peerinfo->state.state); - ret = gf_store_save_value(fd, GLUSTERD_STORE_KEY_PEER_STATE, buf); - if (ret) + ret = snprintf(buf + total_len, sizeof(buf) - total_len, "%s=%s\n%s=%d\n", + GLUSTERD_STORE_KEY_PEER_UUID, uuid_utoa(peerinfo->uuid), + GLUSTERD_STORE_KEY_PEER_STATE, peerinfo->state.state); + if (ret < 0 || ret >= sizeof(buf) - total_len) { + ret = -1; goto out; + } + total_len += ret; cds_list_for_each_entry(hostname, &peerinfo->hostnames, hostname_list) { - ret = gf_asprintf(&key, GLUSTERD_STORE_KEY_PEER_HOSTNAME "%d", i); - if (ret < 0) - goto out; - ret = gf_store_save_value(fd, key, hostname->hostname); - if (ret) + ret = snprintf(buf + total_len, sizeof(buf) - total_len, + GLUSTERD_STORE_KEY_PEER_HOSTNAME "%d=%s\n", i, + hostname->hostname); + if (ret < 0 || ret >= sizeof(buf) - total_len) { + ret = -1; goto out; - GF_FREE(key); - key = NULL; + } + total_len += ret; i++; } + ret = gf_store_save_items(fd, buf); out: - if (key) - GF_FREE(key); gf_msg_debug("glusterd", 0, "Returning with %d", ret); return ret; } @@ -4664,11 +4570,9 @@ glusterd_store_retrieve_peers(xlator_t *this) goto out; } - for (;;) { - GF_SKIP_IRRELEVANT_ENTRIES(entry, dir, scratch); - if (!entry) { - break; - } + while ((entry = sys_readdir(dir, scratch))) { + if (gf_irrelevant_entry(entry)) + continue; if (gf_uuid_parse(entry->d_name, tmp_uuid) != 0) { gf_log(this->name, GF_LOG_WARNING, "skipping non-peer file %s", entry->d_name); @@ -4746,10 +4650,6 @@ glusterd_store_retrieve_peers(xlator_t *this) */ address = cds_list_entry(peerinfo->hostnames.next, glusterd_peer_hostname_t, hostname_list); - if (!address) { - ret = -1; - goto next; - } peerinfo->hostname = gf_strdup(address->hostname); ret = glusterd_friend_add_from_peerinfo(peerinfo, 1, NULL); @@ -4760,7 +4660,7 @@ glusterd_store_retrieve_peers(xlator_t *this) is_ok = _gf_true; next: - (void)gf_store_iter_destroy(iter); + (void)gf_store_iter_destroy(&iter); if (!is_ok) { gf_log(this->name, GF_LOG_WARNING, @@ -4943,7 +4843,9 @@ glusterd_resolve_all_bricks(xlator_t *this) "peer=%s;volume=%s;brick=%s", brickinfo->hostname, volinfo->volname, brickinfo->path); gf_msg("glusterd", GF_LOG_ERROR, 0, GD_MSG_RESOLVE_BRICK_FAIL, - "resolve brick failed in restore"); + "Failed to resolve brick %s with host %s of volume %s" + " in restore", + brickinfo->path, brickinfo->hostname, volinfo->volname); goto out; } } @@ -5092,10 +4994,10 @@ glusterd_store_save_quota_version_and_cksum(glusterd_volinfo_t *volinfo) glusterd_conf_t *conf = NULL; xlator_t *this = NULL; char path[PATH_MAX] = {0}; - char cksum_path[PATH_MAX] = { + char cksum_path[PATH_MAX + 32] = { 0, }; - char buf[256] = {0}; + char buf[64] = {0}; int fd = -1; int32_t ret = -1; int32_t len = 0; @@ -5120,19 +5022,17 @@ glusterd_store_save_quota_version_and_cksum(glusterd_volinfo_t *volinfo) goto out; } - snprintf(buf, sizeof(buf) - 1, "%u", volinfo->quota_conf_cksum); - ret = gf_store_save_value(fd, "cksum", buf); - if (ret) { - gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_CKSUM_STORE_FAIL, - "Failed to store cksum"); + ret = snprintf(buf, sizeof(buf), "cksum=%u\nversion=%u\n", + volinfo->quota_conf_cksum, volinfo->quota_conf_version); + if (ret < 0 || ret >= sizeof(buf)) { + ret = -1; goto out; } - snprintf(buf, sizeof(buf) - 1, "%u", volinfo->quota_conf_version); - ret = gf_store_save_value(fd, "version", buf); + ret = gf_store_save_items(fd, buf); if (ret) { - gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_VERS_STORE_FAIL, - "Failed to store version"); + gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_CKSUM_STORE_FAIL, + "Failed to store quota cksum and version"); goto out; } |
