From e9b9b38caabe778fad4b6f2fd9ba9d8cc100c7df 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-store.c | 72 +++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) diff --git a/xlators/mgmt/glusterd/src/glusterd-store.c b/xlators/mgmt/glusterd/src/glusterd-store.c index 70c50803f..7739f2f37 100644 --- a/xlators/mgmt/glusterd/src/glusterd-store.c +++ b/xlators/mgmt/glusterd/src/glusterd-store.c @@ -1680,7 +1680,11 @@ glusterd_store_volinfo_atomic_update (glusterd_volinfo_t *volinfo) ret = gf_store_rename_tmppath (volinfo->shandle); 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, "Couldn't rename " @@ -1970,6 +1974,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; @@ -2022,6 +2027,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)) @@ -2093,6 +2106,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) { @@ -2140,6 +2204,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; @@ -2645,6 +2712,9 @@ glusterd_store_retrieve_volume (char *volname, glusterd_snap_t *snap) } else if (!strncmp (key, GLUSTERD_STORE_KEY_VOL_CAPS, strlen (GLUSTERD_STORE_KEY_VOL_CAPS))) { volinfo->caps = 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)) { -- cgit