summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt/glusterd
diff options
context:
space:
mode:
authorSachin Pandit <spandit@redhat.com>2014-03-17 07:22:03 +0530
committerRajesh Joseph <rjoseph@redhat.com>2014-03-25 06:37:12 -0700
commitc36c95a79c2f73f35727c6f8cba0586714663fd9 (patch)
tree3e81ca9cae265acd9c68ccb1f74a1d44c0bd7c90 /xlators/mgmt/glusterd
parentc553246c30290efcead1f32e4464ce86070ac9f2 (diff)
snapshot/config : snapshot config changes.
Syntax : gluster snapshot config [volname] [snap-max-hard-limit <value>] [snap-max-soft-limit <value>] 1)If volume name is not specified, then the value is set system wide. 2)If volume name is specified, then the value is set to that particular volume. *NOTE : snap-max-soft-limit cannot be specified to individual volumes. case 1) When system limit is greater than volume limit. Sample output : Snapshot System Configuration: snap-max-hard-limit : 200 snap-max-soft-limit : 50% Snapshot Volume Configuration: Volume : vol2 snap-max-hard-limit : 100 Effective snap-max-hard-limit : 100 Effective snap-max-soft-limit : 50 (50%) Volume : vol1 snap-max-hard-limit : 150 Effective snap-max-hard-limit : 150 Effective snap-max-soft-limit : 75 (50%) case 2) When system limit is lesser than volume limit. Sample output : Snapshot System Configuration: snap-max-hard-limit : 50 snap-max-soft-limit : 50% Snapshot Volume Configuration: Volume : vol2 snap-max-hard-limit : 100 Effective snap-max-hard-limit : 50 Effective snap-max-soft-limit : 25 (50%) Volume : vol1 snap-max-hard-limit : 150 Effective snap-max-hard-limit : 50 Effective snap-max-soft-limit : 25 (50%) Change-Id: I97b5daefec7205bb9ab7b5b51d38f504cc5ee940 BUG: 1075034 Signed-off-by: Sachin Pandit <spandit@redhat.com> Reviewed-on: http://review.gluster.org/7303 Reviewed-by: Rajesh Joseph <rjoseph@redhat.com> Tested-by: Rajesh Joseph <rjoseph@redhat.com>
Diffstat (limited to 'xlators/mgmt/glusterd')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-snapshot.c202
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.c17
2 files changed, 129 insertions, 90 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot.c b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
index 7434b7abd..7068a04bb 100644
--- a/xlators/mgmt/glusterd/src/glusterd-snapshot.c
+++ b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
@@ -244,7 +244,7 @@ out:
}
int
-snap_max_limits_validate (dict_t *dict, char *volname, char *key,
+snap_max_hard_limits_validate (dict_t *dict, char *volname,
uint64_t value, char **op_errstr)
{
char err_str[PATH_MAX] = "";
@@ -258,47 +258,37 @@ snap_max_limits_validate (dict_t *dict, char *volname, char *key,
GF_ASSERT (this);
GF_ASSERT (dict);
- GF_ASSERT (volname);
- GF_ASSERT (key);
GF_ASSERT (op_errstr);
conf = this->private;
GF_ASSERT (conf);
- ret = glusterd_volinfo_find (volname, &volinfo);
- if (!ret) {
- if (volinfo->is_snap_volume) {
- ret = -1;
- snprintf (err_str, PATH_MAX,"%s is a snap volume. "
- "Configuring %s for a snap volume is "
- "prohibited.", volname, key);
- goto out;
+ if (volname) {
+ ret = glusterd_volinfo_find (volname, &volinfo);
+ if (!ret) {
+ if (volinfo->is_snap_volume) {
+ ret = -1;
+ snprintf (err_str, PATH_MAX,
+ "%s is a snap volume. Configuring "
+ "snap-max-hard-limit for a snap "
+ "volume is prohibited.", volname);
+ goto out;
+ }
}
}
- if (!strcmp (key, "snap-max-hard-limit")) {
+ if (value) {
max_limit = GLUSTERD_SNAPS_MAX_HARD_LIMIT;
- if ((max_limit > conf->snap_max_hard_limit) &&
- (strncmp (volname, "all", strlen(volname))))
+ if ((max_limit > conf->snap_max_hard_limit) && volname)
max_limit = conf->snap_max_hard_limit;
- } else {
- max_limit = GLUSTERD_SNAPS_MAX_SOFT_LIMIT_PERCENT;
- if (strncmp (volname, "all", strlen(volname))) {
- ret = -1;
- snprintf (err_str, PATH_MAX, "%s is not configurable "
- "for individual volumes. Configure %s for "
- "system.", key, key);
- goto out;
- }
}
- if ((value < 0) ||
- (value > max_limit)) {
+ if ((value < 0) || (value > max_limit)) {
ret = -1;
- snprintf (err_str, PATH_MAX, "Invalid %s "
+ snprintf (err_str, PATH_MAX, "Invalid snap-max-hard-limit"
"%"PRIu64 ". Expected range 0 - %"PRIu64,
- key, value, max_limit);
+ value, max_limit);
goto out;
}
@@ -315,7 +305,6 @@ int
glusterd_snapshot_config_prevalidate (dict_t *dict, char **op_errstr)
{
char *volname = NULL;
- char *key = NULL;
glusterd_volinfo_t *volinfo = NULL;
xlator_t *this = NULL;
int ret = -1;
@@ -323,7 +312,10 @@ glusterd_snapshot_config_prevalidate (dict_t *dict, char **op_errstr)
char err_str[PATH_MAX] = {0,};
glusterd_conf_t *conf = NULL;
uint64_t value = 0;
+ uint64_t hard_limit = 0;
+ uint64_t soft_limit = 0;
gf_loglevel_t loglevel = GF_LOG_ERROR;
+ uint64_t max_limit = GLUSTERD_SNAPS_MAX_HARD_LIMIT;
this = THIS;
@@ -342,25 +334,13 @@ glusterd_snapshot_config_prevalidate (dict_t *dict, char **op_errstr)
goto out;
}
- ret = dict_get_str (dict, "config-key", &key);
- if (!ret) {
- ret = dict_get_uint64 (dict, key, &value);
- if (ret) {
- snprintf (err_str, sizeof (err_str), "Failed to get the"
- " value for %s", key);
+ ret = dict_get_uint64 (dict, "snap-max-hard-limit", &hard_limit);
- goto out;
- }
- }
+ ret = dict_get_uint64 (dict, "snap-max-soft-limit", &soft_limit);
ret = dict_get_str (dict, "volname", &volname);
- if (ret) {
- snprintf (err_str, sizeof (err_str), "Failed to get the"
- " volume name");
- goto out;
- }
- if (strncmp (volname, "all", strlen(volname))) {
+ if (volname) {
ret = glusterd_volinfo_find (volname, &volinfo);
if (ret) {
snprintf (err_str, sizeof (err_str),
@@ -371,22 +351,35 @@ glusterd_snapshot_config_prevalidate (dict_t *dict, char **op_errstr)
switch (config_command) {
case GF_SNAP_CONFIG_TYPE_SET:
- if ((!strncmp (key, "snap-max-hard-limit", strlen(key))) ||
- (!strncmp (key, "snap-max-soft-limit", strlen(key)))) {
- /* Validations for snap-max-limits */
- ret = snap_max_limits_validate (dict, volname,
- key, value, op_errstr);
+ if (hard_limit) {
+ /* Validations for snap-max-hard-limits */
+ ret = snap_max_hard_limits_validate (dict, volname,
+ hard_limit, op_errstr);
if (ret) {
gf_log (this->name, GF_LOG_ERROR,
- "%s validation failed.", key);
+ "snap-max-hard-limit validation "
+ "failed.");
goto out;
}
}
- break;
+ if (soft_limit) {
+ max_limit = GLUSTERD_SNAPS_MAX_SOFT_LIMIT_PERCENT;
+ if ((soft_limit < 0) || (soft_limit > max_limit)) {
+ ret = -1;
+ snprintf (err_str, PATH_MAX, "Invalid "
+ "snap-max-soft-limit ""%"
+ PRIu64 ". Expected range 0 - %"PRIu64,
+ value, max_limit);
+ goto out;
+ }
+ break;
+ }
default:
break;
}
+
+ ret = 0; /* Success */
out:
if (ret && err_str[0] != '\0') {
@@ -3386,7 +3379,7 @@ out:
}
int
-snap_max_hard_limit_set_commit (dict_t *dict, char *key, uint64_t value,
+snap_max_hard_limit_set_commit (dict_t *dict, uint64_t value,
char *volname, char **op_errstr)
{
char err_str[PATH_MAX] = "";
@@ -3399,7 +3392,6 @@ snap_max_hard_limit_set_commit (dict_t *dict, char *key, uint64_t value,
GF_ASSERT (this);
GF_ASSERT (dict);
- GF_ASSERT (key);
GF_ASSERT (volname);
GF_ASSERT (op_errstr);
@@ -3408,14 +3400,14 @@ snap_max_hard_limit_set_commit (dict_t *dict, char *key, uint64_t value,
GF_ASSERT (conf);
/* TODO: Initiate auto deletion when there is a limit change */
- if (!strncmp (volname, "all", strlen(volname))) {
+ if (!volname) {
/* For system limit */
conf->snap_max_hard_limit = value;
ret = glusterd_store_global_info (this);
if (ret) {
- snprintf (err_str, PATH_MAX,"Failed to store %s "
- "for system", key);
+ snprintf (err_str, PATH_MAX,"Failed to store "
+ "snap-max-hard-limit for system");
goto out;
}
} else {
@@ -3432,8 +3424,8 @@ snap_max_hard_limit_set_commit (dict_t *dict, char *key, uint64_t value,
ret = glusterd_store_volinfo (volinfo,
GLUSTERD_VOLINFO_VER_AC_INCREMENT);
if (ret) {
- snprintf (err_str, PATH_MAX,"Failed to store %s "
- "for volume %s", key, volname);
+ snprintf (err_str, PATH_MAX,"Failed to store "
+ "snap-max-hard-limit for volume %s", volname);
goto out;
}
}
@@ -3473,7 +3465,7 @@ snap_max_limits_display_commit (dict_t *rsp_dict, char *volname,
GF_ASSERT (conf);
- if (!strncmp (volname, "all", strlen(volname))) {
+ if (!volname) {
/* For system limit */
list_for_each_entry (volinfo, &conf->volumes, vol_list) {
if (volinfo->is_snap_volume == _gf_true)
@@ -3504,7 +3496,16 @@ snap_max_limits_display_commit (dict_t *rsp_dict, char *volname,
}
snprintf (buf, sizeof(buf),
- "volume%ld-snap-max-soft-limit-value", count);
+ "volume%ld-active-hard-limit", count);
+ ret = dict_set_uint64 (rsp_dict, buf, active_hard_limit);
+ if (ret) {
+ snprintf (err_str, PATH_MAX,
+ "Failed to set %s", buf);
+ goto out;
+ }
+
+ snprintf (buf, sizeof(buf),
+ "volume%ld-snap-max-soft-limit", count);
ret = dict_set_uint64 (rsp_dict, buf, soft_limit_value);
if (ret) {
snprintf (err_str, PATH_MAX,
@@ -3530,7 +3531,12 @@ snap_max_limits_display_commit (dict_t *rsp_dict, char *volname,
}
snap_max_limit = volinfo->snap_max_hard_limit;
- soft_limit_value = (volinfo->snap_max_hard_limit *
+ if (snap_max_limit > conf->snap_max_hard_limit)
+ active_hard_limit = conf->snap_max_hard_limit;
+ else
+ active_hard_limit = snap_max_limit;
+
+ soft_limit_value = (active_hard_limit *
conf->snap_max_soft_limit) / 100;
snprintf (buf, sizeof(buf), "volume%ld-volname", count);
@@ -3551,13 +3557,23 @@ snap_max_limits_display_commit (dict_t *rsp_dict, char *volname,
}
snprintf (buf, sizeof(buf),
- "volume%ld-snap-max-soft-limit-value", count);
+ "volume%ld-active-hard-limit", count);
+ ret = dict_set_uint64 (rsp_dict, buf, active_hard_limit);
+ if (ret) {
+ snprintf (err_str, PATH_MAX,
+ "Failed to set %s", buf);
+ goto out;
+ }
+
+ snprintf (buf, sizeof(buf),
+ "volume%ld-snap-max-soft-limit", count);
ret = dict_set_uint64 (rsp_dict, buf, soft_limit_value);
if (ret) {
snprintf (err_str, PATH_MAX,
"Failed to set %s", buf);
goto out;
}
+
count++;
ret = dict_set_uint64 (rsp_dict, "voldisplaycount", count);
@@ -3599,13 +3615,13 @@ glusterd_snapshot_config_commit (dict_t *dict, char **op_errstr,
dict_t *rsp_dict)
{
char *volname = NULL;
- char *key = NULL;
xlator_t *this = NULL;
int ret = -1;
char err_str[PATH_MAX] = {0,};
glusterd_conf_t *conf = NULL;
int config_command = 0;
- uint64_t value = 0;
+ uint64_t hard_limit = 0;
+ uint64_t soft_limit = 0;
this = THIS;
@@ -3624,46 +3640,37 @@ glusterd_snapshot_config_commit (dict_t *dict, char **op_errstr,
goto out;
}
+ /* Ignore the return value of the following dict_get,
+ * as they are optional
+ */
ret = dict_get_str (dict, "volname", &volname);
- if (ret) {
- snprintf (err_str, PATH_MAX,"Failed to get the"
- " volume name");
- *op_errstr = gf_strdup (err_str);
- gf_log (this->name, GF_LOG_ERROR, "%s", err_str);
- goto out;
- }
- ret = dict_get_str (dict, "config-key", &key);
- if (!ret) {
- ret = dict_get_uint64 (dict, key, &value);
- if (ret) {
- snprintf (err_str, PATH_MAX,"Failed to get the"
- " value for %s", key);
- *op_errstr = gf_strdup (err_str);
- gf_log (this->name, GF_LOG_ERROR, "%s", err_str);
- goto out;
- }
- }
+ ret = dict_get_uint64 (dict, "snap-max-hard-limit", &hard_limit);
+
+ ret = dict_get_uint64 (dict, "snap-max-soft-limit", &soft_limit);
switch (config_command) {
case GF_SNAP_CONFIG_TYPE_SET:
- if (!strncmp (key, "snap-max-hard-limit", strlen(key))) {
+ if (hard_limit) {
/* Commit ops for snap-max-hard-limit */
- ret = snap_max_hard_limit_set_commit (dict, key, value,
+ ret = snap_max_hard_limit_set_commit (dict, hard_limit,
volname, op_errstr);
if (ret) {
gf_log (this->name, GF_LOG_ERROR,
- "%s set commit failed.", key);
+ "snap-max-hard-limit set "
+ "commit failed.");
goto out;
}
- } else if (!strncmp (key, "snap-max-soft-limit", strlen(key))) {
+ }
+
+ if (soft_limit) {
/* For system limit */
- conf->snap_max_soft_limit = value;
+ conf->snap_max_soft_limit = soft_limit;
ret = glusterd_store_global_info (this);
if (ret) {
- snprintf (err_str, PATH_MAX,"Failed to store %s "
- "for system", key);
+ snprintf (err_str, PATH_MAX,"Failed to store "
+ "snap-max-soft-limit for system");
*op_errstr = gf_strdup (err_str);
gf_log (this->name, GF_LOG_ERROR, "%s", err_str);
goto out;
@@ -3678,7 +3685,8 @@ glusterd_snapshot_config_commit (dict_t *dict, char **op_errstr,
break;
}
- ret = snap_max_limits_display_commit (rsp_dict, volname, op_errstr);
+ ret = snap_max_limits_display_commit (rsp_dict, volname,
+ op_errstr);
if (ret) {
gf_log (this->name, GF_LOG_ERROR,
"snap-max-limit "
@@ -4612,6 +4620,7 @@ glusterd_handle_snapshot_fn (rpcsvc_request_t *req)
char *host_uuid = NULL;
char err_str[2048] = {0,};
xlator_t *this = NULL;
+ char *volname = NULL;
GF_ASSERT (req);
@@ -4707,6 +4716,21 @@ glusterd_handle_snapshot_fn (rpcsvc_request_t *req)
}
break;
case GF_SNAP_OPTION_TYPE_CONFIG:
+ /* TODO : Type of lock to be taken when we are setting
+ * limits system wide
+ */
+ ret = dict_get_str (dict, "volname", &volname);
+ if (!volname) {
+ ret = dict_set_int32 (dict, "hold_vol_locks",
+ _gf_false);
+ if (ret) {
+ gf_log ("cli", GF_LOG_ERROR,
+ "Unable to set hold_vol_locks value "
+ "as _gf_false");
+ goto out;
+ }
+
+ }
ret = glusterd_mgmt_v3_initiate_all_phases (req, cli_op, dict);
break;
case GF_SNAP_OPTION_TYPE_DELETE:
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
index a398058d5..7f1f49461 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
@@ -7758,7 +7758,22 @@ glusterd_snap_config_use_rsp_dict (dict_t *dst, dict_t *src)
}
snprintf (buf, sizeof(buf),
- "volume%ld-snap-max-soft-limit-value", i);
+ "volume%ld-active-hard-limit", i);
+ ret = dict_get_uint64 (src, buf, &value);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR,
+ "Unable to get %s", buf);
+ goto out;
+ }
+ ret = dict_set_uint64 (dst, buf, value);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR,
+ "Unable to set %s", buf);
+ goto out;
+ }
+
+ snprintf (buf, sizeof(buf),
+ "volume%ld-snap-max-soft-limit", i);
ret = dict_get_uint64 (src, buf, &value);
if (ret) {
gf_log ("", GF_LOG_ERROR,