From 5a471fca7da256a3f67b13646d087b94c29dbf80 Mon Sep 17 00:00:00 2001 From: shishir gowda Date: Wed, 30 Oct 2013 09:13:22 +0530 Subject: mgmt/glusterd: save snapshot config values in store Change-Id: Ia755e5c4af84827cc9b8876054cc48cfdc598876 Signed-off-by: shishir gowda --- xlators/mgmt/glusterd/src/glusterd-snapshot.c | 21 ++++++-- xlators/mgmt/glusterd/src/glusterd-store.c | 72 ++++++++++++++++++++++++++- xlators/mgmt/glusterd/src/glusterd-store.h | 1 + 3 files changed, 90 insertions(+), 4 deletions(-) diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot.c b/xlators/mgmt/glusterd/src/glusterd-snapshot.c index 6c365230b..810bce0ab 100644 --- a/xlators/mgmt/glusterd/src/glusterd-snapshot.c +++ b/xlators/mgmt/glusterd/src/glusterd-snapshot.c @@ -2436,8 +2436,14 @@ glusterd_snapshot_config_commit (dict_t *dict, char **op_errstr, goto out; } conf->snap_max_limit = limit; - // TODO: do store - + ret = glusterd_store_global_info (this); + if (ret) { + snprintf (err_str, PATH_MAX,"Failed to store the" + " snapshot limit volinfo for system"); + *op_errstr = gf_strdup (err_str); + gf_log (this->name, GF_LOG_ERROR, "%s", err_str); + goto out; + } break; case GF_SNAP_CONFIG_VOL_MAX: @@ -2468,7 +2474,16 @@ glusterd_snapshot_config_commit (dict_t *dict, char **op_errstr, goto out; } volinfo->snap_max_limit = limit; - //TODO: do store + ret = glusterd_store_volinfo (volinfo, + GLUSTERD_VOLINFO_VER_AC_INCREMENT); + if (ret) { + snprintf (err_str, PATH_MAX,"Failed to store the" + " snapshot limit volinfo for volume %s", + volname); + *op_errstr = gf_strdup (err_str); + gf_log (this->name, GF_LOG_ERROR, "%s", err_str); + goto out; + } break; case GF_SNAP_CONFIG_CG_MAX: diff --git a/xlators/mgmt/glusterd/src/glusterd-store.c b/xlators/mgmt/glusterd/src/glusterd-store.c index 83c2a2fba..0640c9f93 100644 --- a/xlators/mgmt/glusterd/src/glusterd-store.c +++ b/xlators/mgmt/glusterd/src/glusterd-store.c @@ -690,7 +690,11 @@ glusterd_volume_exclude_options_write (int fd, glusterd_volinfo_t *volinfo) buf); if (ret) goto out; - + snprintf (buf, sizeof (buf), "%"PRIu64, volinfo->snap_max_limit); + ret = gf_store_save_value (fd, GLUSTERD_STORE_KEY_SNAP_MAX_LIMIT, + buf); + if (ret) + goto out; out: if (ret) gf_log (THIS->name, GF_LOG_ERROR, "Unable to write volume " @@ -1966,6 +1970,7 @@ glusterd_store_global_info (xlator_t *this) char path[PATH_MAX] = {0,}; gf_store_handle_t *handle = NULL; char *uuid_str = NULL; + char buf[256] = {0, }; conf = this->private; @@ -2018,6 +2023,14 @@ glusterd_store_global_info (xlator_t *this) goto out; } + snprintf (buf, sizeof (buf), "%"PRIu64, conf->snap_max_limit); + ret = gf_store_save_value (handle->fd, + GLUSTERD_STORE_KEY_SNAP_MAX_LIMIT, buf); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, + "Storing snap-max-limit failed ret = %d", ret); + goto out; + } ret = gf_store_rename_tmppath (handle); out: if (ret && (handle->fd > 0)) @@ -2089,6 +2102,57 @@ out: return ret; } +int +glusterd_retrieve_sys_snap_max_limit (xlator_t *this, uint64_t *limit) +{ + 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; + + priv = this->private; + + if (!priv->handle) { + snprintf (path, PATH_MAX, "%s/%s", priv->workdir, + GLUSTERD_INFO_FILE); + ret = gf_store_handle_retrieve (path, &handle); + + if (ret) { + gf_log ("", GF_LOG_DEBUG, "Unable to get store " + "handle!"); + goto out; + } + + priv->handle = handle; + } + + ret = gf_store_retrieve_value (priv->handle, + GLUSTERD_STORE_KEY_SNAP_MAX_LIMIT, + &limit_str); + if (ret) { + gf_log (this->name, GF_LOG_DEBUG, + "No previous snap limit present"); + goto out; + } + + tmp_limit = strtoul (limit_str, &tmp, 10); + if ((tmp_limit <= 0) || (tmp && strlen (tmp) > 1)) { + gf_log (this->name, GF_LOG_WARNING, "invalid version number"); + goto out; + } + + *limit = tmp_limit; + + ret = 0; +out: + if (limit_str) + GF_FREE (limit_str); + + return ret; +} static int glusterd_restore_op_version (xlator_t *this) { @@ -2136,6 +2200,9 @@ glusterd_restore_op_version (xlator_t *this) " op-version to minimum : %d", GD_OP_VERSION_MIN); conf->op_version = GD_OP_VERSION_MIN; } + ret = glusterd_retrieve_sys_snap_max_limit (this, &conf->snap_max_limit); + if (ret) + conf->snap_max_limit = GLUSTERD_SNAPS_MAX_LIMIT; ret = 0; out: return ret; @@ -2637,6 +2704,9 @@ glusterd_store_retrieve_volume (char *volname, glusterd_snap_t *snap) } else if (!strncmp (key, GLUSTERD_STORE_KEY_VOL_CLIENT_OP_VERSION, strlen (GLUSTERD_STORE_KEY_VOL_CLIENT_OP_VERSION))) { volinfo->client_op_version = atoi (value); + } else if (!strncmp (key, GLUSTERD_STORE_KEY_SNAP_MAX_LIMIT, + strlen (GLUSTERD_STORE_KEY_SNAP_MAX_LIMIT))) { + volinfo->snap_max_limit = (uint64_t) atoll (value); } else { if (is_key_glusterd_hooks_friendly (key)) { diff --git a/xlators/mgmt/glusterd/src/glusterd-store.h b/xlators/mgmt/glusterd/src/glusterd-store.h index 5772809d7..2c7de0387 100644 --- a/xlators/mgmt/glusterd/src/glusterd-store.h +++ b/xlators/mgmt/glusterd/src/glusterd-store.h @@ -67,6 +67,7 @@ typedef enum glusterd_store_ver_ac_{ #define GLUSTERD_STORE_KEY_SNAP_STATUS "status" #define GLUSTERD_STORE_KEY_SNAP_COUNT "count" #define GLUSTERD_STORE_KEY_CG_VOL_COUNT "count" +#define GLUSTERD_STORE_KEY_SNAP_MAX_LIMIT "snap-max-limit" #define GLUSTERD_STORE_KEY_BRICK_HOSTNAME "hostname" #define GLUSTERD_STORE_KEY_BRICK_PATH "path" -- cgit