diff options
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-snapshot.c')
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-snapshot.c | 320 |
1 files changed, 214 insertions, 106 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot.c b/xlators/mgmt/glusterd/src/glusterd-snapshot.c index cd9ed3f23..1f6930718 100644 --- a/xlators/mgmt/glusterd/src/glusterd-snapshot.c +++ b/xlators/mgmt/glusterd/src/glusterd-snapshot.c @@ -395,20 +395,21 @@ out: } int -snap_max_limits_validate (dict_t *dict, char *key, - char **op_errstr) +snap_max_limits_validate (dict_t *dict, char *volname, char *key, + uint64_t value, char **op_errstr) { char err_str[PATH_MAX] = ""; glusterd_conf_t *conf = NULL; + glusterd_volinfo_t *volinfo = NULL; int ret = -1; - uint64_t value = 0; - uint64_t max_limit = GLUSTERD_SNAPS_MAX_LIMIT; + uint64_t max_limit = GLUSTERD_SNAPS_MAX_HARD_LIMIT; xlator_t *this = NULL; this = THIS; GF_ASSERT (this); GF_ASSERT (dict); + GF_ASSERT (volname); GF_ASSERT (key); GF_ASSERT (op_errstr); @@ -416,13 +417,31 @@ snap_max_limits_validate (dict_t *dict, char *key, GF_ASSERT (conf); - 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 = 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 (!strcmp (key, "snap-max-hard-limit")) { + max_limit = GLUSTERD_SNAPS_MAX_HARD_LIMIT; + if ((max_limit > conf->snap_max_hard_limit) && + (strncmp (volname, "all", strlen(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) || @@ -431,13 +450,15 @@ snap_max_limits_validate (dict_t *dict, char *key, snprintf (err_str, PATH_MAX, "Invalid %s " "%"PRIu64 ". Expected range 0 - %"PRIu64, key, value, max_limit); - *op_errstr = gf_strdup (err_str); - gf_log (this->name, GF_LOG_ERROR, "%s", err_str); goto out; } ret = 0; out: + if (ret) { + *op_errstr = gf_strdup (err_str); + gf_log (this->name, GF_LOG_ERROR, "%s", err_str); + } return ret; } @@ -452,6 +473,7 @@ glusterd_snapshot_config_prevalidate (dict_t *dict, char **op_errstr) int config_command = 0; char err_str[PATH_MAX] = {0,}; glusterd_conf_t *conf = NULL; + uint64_t value = 0; this = THIS; @@ -471,34 +493,27 @@ glusterd_snapshot_config_prevalidate (dict_t *dict, char **op_errstr) } ret = dict_get_str (dict, "config-key", &key); - - 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-hard-limit and snap-max-soft-limit */ - ret = snap_max_limits_validate (dict, key, op_errstr); - if (ret) { - gf_log (this->name, GF_LOG_ERROR, - "%s validation failed.", key); - goto out; - } - } - break; - - case GF_SNAP_CONFIG_DISPLAY: - ret = dict_get_str (dict, "volname", &volname); + if (!ret) { + ret = dict_get_uint64 (dict, key, &value); if (ret) { snprintf (err_str, PATH_MAX,"Failed to get the" - " volume name"); + " value for %s", key); *op_errstr = gf_strdup (err_str); gf_log (this->name, GF_LOG_ERROR, "%s", err_str); goto out; } - if (!strncmp (volname, "all", strlen(volname))) { - ret = 0; - goto out; - } + } + + 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; + } + + if (strncmp (volname, "all", strlen(volname))) { ret = glusterd_volinfo_find (volname, &volinfo); if (ret) { snprintf (err_str, PATH_MAX,"Volume %s does not exist.", @@ -507,7 +522,23 @@ glusterd_snapshot_config_prevalidate (dict_t *dict, char **op_errstr) gf_log (this->name, GF_LOG_ERROR, "%s", err_str); goto out; } + } + + 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 (ret) { + gf_log (this->name, GF_LOG_ERROR, + "%s validation failed.", key); + goto out; + } + } break; + default: break; } @@ -4094,14 +4125,13 @@ out: } int -snap_max_limits_set_commit (dict_t *dict, char *key, char *volname, - char **op_errstr) +snap_max_hard_limit_set_commit (dict_t *dict, char *key, uint64_t value, + char *volname, char **op_errstr) { char err_str[PATH_MAX] = ""; glusterd_conf_t *conf = NULL; glusterd_volinfo_t *volinfo = NULL; int ret = -1; - uint64_t value = 0; xlator_t *this = NULL; this = THIS; @@ -4116,20 +4146,10 @@ snap_max_limits_set_commit (dict_t *dict, char *key, char *volname, GF_ASSERT (conf); - ret = dict_get_uint64 (dict, key, &value); - if (ret) { - snprintf (err_str, PATH_MAX,"Failed to get the" - " value for %s", key); - goto out; - } - /* TODO: Initiate auto deletion when there is a limit change */ if (!strncmp (volname, "all", strlen(volname))) { /* For system limit */ - if (!strncmp (key, "snap-max-hard-limit", strlen(key))) - conf->snap_max_hard_limit = value; - else - conf->snap_max_soft_limit = value; + conf->snap_max_hard_limit = value; ret = glusterd_store_global_info (this); if (ret) { @@ -4146,10 +4166,7 @@ snap_max_limits_set_commit (dict_t *dict, char *key, char *volname, goto out; } - if (!strncmp (key, "snap-max-hard-limit", strlen(key))) - volinfo->snap_max_hard_limit = value; - else - volinfo->snap_max_soft_limit = value; + volinfo->snap_max_hard_limit = value; ret = glusterd_store_volinfo (volinfo, GLUSTERD_VOLINFO_VER_AC_INCREMENT); @@ -4166,26 +4183,28 @@ out: *op_errstr = gf_strdup (err_str); gf_log (this->name, GF_LOG_ERROR, "%s", err_str); } - return ret; } int -snap_max_limits_display_commit (dict_t *rsp_dict, char *key, char *volname, +snap_max_limits_display_commit (dict_t *rsp_dict, char *volname, char **op_errstr) { char err_str[PATH_MAX] = ""; + char buf[PATH_MAX] = ""; glusterd_conf_t *conf = NULL; glusterd_volinfo_t *volinfo = NULL; int ret = -1; - uint64_t value = 0; + uint64_t active_hard_limit = 0; + uint64_t snap_max_limit = 0; + uint64_t soft_limit_value = -1; + uint64_t count = 0; xlator_t *this = NULL; this = THIS; GF_ASSERT (this); GF_ASSERT (rsp_dict); - GF_ASSERT (key); GF_ASSERT (volname); GF_ASSERT (op_errstr); @@ -4195,38 +4214,122 @@ snap_max_limits_display_commit (dict_t *rsp_dict, char *key, char *volname, if (!strncmp (volname, "all", strlen(volname))) { /* For system limit */ - if (!strncmp (key, "snap-max-hard-limit", strlen(key))) - value = conf->snap_max_hard_limit; - else - value = conf->snap_max_soft_limit; + list_for_each_entry (volinfo, &conf->volumes, vol_list) { + if (volinfo->is_snap_volume == _gf_true) + continue; + snap_max_limit = 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); + ret = dict_set_str (rsp_dict, buf, volinfo->volname); + if (ret) { + snprintf (err_str, PATH_MAX, + "Failed to set %s", buf); + goto out; + } + + snprintf (buf, sizeof(buf), + "volume%ld-snap-max-hard-limit", count); + ret = dict_set_uint64 (rsp_dict, buf, snap_max_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-value", 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); + if (ret) { + snprintf (err_str, PATH_MAX, + "Failed to set voldisplaycount"); + goto out; + } } else { - /* For one volume */ + /* For one volume */ ret = glusterd_volinfo_find (volname, &volinfo); if (ret) { snprintf (err_str, PATH_MAX,"Failed to get the" " volinfo for volume %s", volname); - *op_errstr = gf_strdup (err_str); - gf_log (this->name, GF_LOG_ERROR, "%s", err_str); goto out; } - if (!strncmp (key, "snap-max-hard-limit", strlen(key))) - value = volinfo->snap_max_hard_limit; - else - value = volinfo->snap_max_soft_limit; + snap_max_limit = volinfo->snap_max_hard_limit; + soft_limit_value = (volinfo->snap_max_hard_limit * + conf->snap_max_soft_limit) / 100; + + snprintf (buf, sizeof(buf), "volume%ld-volname", count); + ret = dict_set_str (rsp_dict, buf, volinfo->volname); + if (ret) { + snprintf (err_str, PATH_MAX, + "Failed to set %s", buf); + goto out; + } + + snprintf (buf, sizeof(buf), + "volume%ld-snap-max-hard-limit", count); + ret = dict_set_uint64 (rsp_dict, buf, snap_max_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-value", 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); + if (ret) { + snprintf (err_str, PATH_MAX, + "Failed to set voldisplaycount"); + goto out; + } + } - ret = dict_set_uint64 (rsp_dict, key, value); + ret = dict_set_uint64 (rsp_dict, "snap-max-hard-limit", + conf->snap_max_hard_limit); if (ret) { - snprintf (err_str, PATH_MAX,"Failed to set %s " - "for volume %s", key, volname); - *op_errstr = gf_strdup (err_str); - gf_log (this->name, GF_LOG_ERROR, "%s", err_str); + snprintf (err_str, PATH_MAX, + "Failed to set sys-snap-max-hard-limit "); + goto out; + } + + ret = dict_set_uint64 (rsp_dict, "snap-max-soft-limit", + conf->snap_max_soft_limit); + if (ret) { + snprintf (err_str, PATH_MAX, + "Failed to set sys-snap-max-hard-limit "); goto out; } ret = 0; out: + if (ret) { + *op_errstr = gf_strdup (err_str); + gf_log (this->name, GF_LOG_ERROR, "%s", err_str); + } return ret; } @@ -4241,12 +4344,12 @@ glusterd_snapshot_config_commit (dict_t *dict, char **op_errstr, char err_str[PATH_MAX] = {0,}; glusterd_conf_t *conf = NULL; int config_command = 0; + uint64_t value = 0; this = THIS; GF_ASSERT (this); GF_ASSERT (dict); - GF_ASSERT (rsp_dict); GF_ASSERT (op_errstr); conf = this->private; @@ -4270,51 +4373,56 @@ glusterd_snapshot_config_commit (dict_t *dict, char **op_errstr, } 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; + } + } 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)))) { - /* Commit ops for snap-max-hard-limit and snap-max-soft-limit */ - ret = snap_max_limits_set_commit (dict, key, volname, op_errstr); + if (!strncmp (key, "snap-max-hard-limit", strlen(key))) { + /* Commit ops for snap-max-hard-limit */ + ret = snap_max_hard_limit_set_commit (dict, key, value, + volname, op_errstr); if (ret) { gf_log (this->name, GF_LOG_ERROR, "%s set commit failed.", key); goto out; } - } - break; + } else if (!strncmp (key, "snap-max-soft-limit", strlen(key))) { + /* For system limit */ + conf->snap_max_soft_limit = value; - case GF_SNAP_CONFIG_DISPLAY: - if (!key) { - /* For all options */ - ret = snap_max_limits_display_commit (rsp_dict, "snap-max-hard-limit", - volname, op_errstr); + ret = glusterd_store_global_info (this); if (ret) { - gf_log (this->name, GF_LOG_ERROR, - "snap-max-hard-limit " - "display commit failed."); + snprintf (err_str, PATH_MAX,"Failed to store %s " + "for system", key); + *op_errstr = gf_strdup (err_str); + gf_log (this->name, GF_LOG_ERROR, "%s", err_str); goto out; } + } + break; - ret = snap_max_limits_display_commit (rsp_dict, "snap-max-soft-limit", - volname, op_errstr); - if (ret) { - gf_log (this->name, GF_LOG_ERROR, - "snap-max-soft-limit " - "display commit failed."); - goto out; - } - } else if ((!strncmp (key, "snap-max-hard-limit", strlen(key))) || - (!strncmp (key, "snap-max-soft-limit", strlen(key)))) { - /* Commit ops for snap-max-hard-limit or snap-max-soft-limit */ - ret = snap_max_limits_display_commit (rsp_dict, key, - volname, op_errstr); - if (ret) { - gf_log (this->name, GF_LOG_ERROR, - "%s display commit failed.", key); - goto out; - } + case GF_SNAP_CONFIG_DISPLAY: + /* Reading data from local node only */ + if (!is_origin_glusterd (dict)) { + ret = 0; + break; + } + + ret = snap_max_limits_display_commit (rsp_dict, volname, op_errstr); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, + "snap-max-limit " + "display commit failed."); + goto out; } break; default: |