summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cli/src/cli-cmd-parser.c137
-rw-r--r--cli/src/cli-cmd-snapshot.c2
-rw-r--r--cli/src/cli-rpc-ops.c147
-rw-r--r--cli/src/cli.h5
-rw-r--r--rpc/xdr/src/cli1-xdr.h6
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-snapshot.c456
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-store.c85
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-store.h3
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.c34
-rw-r--r--xlators/mgmt/glusterd/src/glusterd.c3
-rw-r--r--xlators/mgmt/glusterd/src/glusterd.h6
11 files changed, 550 insertions, 334 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c
index d1afa72a4..2762f0cf4 100644
--- a/cli/src/cli-cmd-parser.c
+++ b/cli/src/cli-cmd-parser.c
@@ -28,6 +28,23 @@
#define MAX_SNAP_DESCRIPTION_LEN 1024
+struct snap_config_opt_vals_ snap_confopt_vals[] = {
+ {.op_name = "snap-max-hard-limit",
+ .question = "Changing snapshot-max-hard-limit "
+ "will lead deletion of snapshots "
+ "if they exceed the new limit.\n"
+ "Do you want to continue?"
+ },
+ {.op_name = "snap-max-soft-limit",
+ .question = "Changing snapshot-max-soft-limit "
+ "will lead deletion of snapshots "
+ "if they exceed the new limit.\n"
+ "Do you want to continue?"
+ },
+ {.op_name = NULL,
+ }
+};
+
static const char *
id_sel (void *wcon)
{
@@ -3171,24 +3188,22 @@ int32_t
cli_snap_config_parse (const char **words, int wordcount, dict_t *options,
struct cli_state *state)
{
- char *volname = NULL;
- int ret = -1;
- char *key = NULL;
- char *value = NULL;
- uint64_t limit = 0;
- gf1_cli_snapshot type = GF_SNAP_OPTION_TYPE_NONE;
- gf_answer_t answer = GF_ANSWER_NO;
- const char *question = "Changing snapshot-max-limit"
- " will lead deletion of snap"
- "shots if they exceed the "
- "new limit.\nDo you want to"
- " continue?";
+ char *volname = NULL;
+ int ret = -1;
+ int i = -1;
+ char *key = NULL;
+ char *value = NULL;
+ uint64_t limit = 0;
+ gf1_cli_snapshot type = GF_SNAP_OPTION_TYPE_NONE;
+ gf_answer_t answer = GF_ANSWER_NO;
+ struct snap_config_opt_vals_ *conf_vals = NULL;
+ gf_boolean_t op_match = _gf_true;
GF_ASSERT (words);
GF_ASSERT (options);
GF_ASSERT (state);
- if ((wordcount != 3) && (wordcount != 5))
+ if ((wordcount < 3) || (wordcount > 5))
goto out;
volname = (char *)words[2];
@@ -3210,47 +3225,79 @@ cli_snap_config_parse (const char **words, int wordcount, dict_t *options,
goto out;
}
- /* snapshot config <volname | all> [snap_max_limit <count>] */
+ /* snapshot config <volname | all> [snap-max-hard-limit <count>
+ * | snap-max-soft-limit <count>] */
- if (wordcount == 3) {
- ret = dict_set_int32 (options, "config-command",
- GF_SNAP_CONFIG_DISPLAY);
- goto out;
+ if (wordcount > 3) {
+ key = (char *) words[3];
+ value = (char *) words[4];
}
- key = (char *) words[3];
- value = (char *) words[4];
- if ( !key || !value) {
- ret = -1;
- goto out;
- }
- if (strncmp (key, "snap-max-limit", 14)) {
- gf_log ("", GF_LOG_ERROR, "Invalid key");
- goto out;
+ if (key) {
+ /* Check options in snap_confopt_vals for invalid keys */
+ for (conf_vals = snap_confopt_vals; conf_vals->op_name;
+ conf_vals++) {
+ op_match = _gf_true;
+ for (i = 0; conf_vals->op_name[i] && key[i]; i++) {
+ if (conf_vals->op_name[i] == key[i] ||
+ (conf_vals->op_name[i] == '-' &&
+ key[i] == '_'))
+ continue;
+ op_match = _gf_false;
+ break;
+ }
+
+ if (op_match)
+ break;
+ }
+
+ if (!op_match) {
+ gf_log ("", GF_LOG_ERROR, "Invalid key");
+ ret = -1;
+ goto out;
+ }
+
+ ret = dict_set_str (options, "config-key", conf_vals->op_name);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "Unable to set config-key");
+ goto out;
+ }
}
- if (!strncmp (volname, "all", 3)) {
+
+ if (!value) {
ret = dict_set_int32 (options, "config-command",
- GF_SNAP_CONFIG_SYS_MAX);
+ GF_SNAP_CONFIG_DISPLAY);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "Unable to set config-command");
+ ret = -1;
+ goto out;
+ }
} else {
ret = dict_set_int32 (options, "config-command",
- GF_SNAP_CONFIG_VOL_MAX);
- }
+ GF_SNAP_CONFIG_TYPE_SET);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "Unable to set config-command");
+ ret = -1;
+ goto out;
+ }
- limit = (uint64_t) atoll (value);
- ret = dict_set_uint64 (options, "limit", limit);
- if (ret) {
- gf_log ("", GF_LOG_ERROR,
- "Failed to set limit.");
- goto out;
+ limit = (uint64_t) atoll (value);
+ ret = dict_set_uint64 (options, conf_vals->op_name, limit);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR,
+ "Failed to set %s.", key);
+ goto out;
+ }
}
- if (ret)
- goto out;
- answer = cli_cmd_get_confirmation (state, question);
-
- if (GF_ANSWER_NO == answer) {
- ret = -1;
- goto out;
+ /* Ask question only for a set op */
+ if (value && conf_vals && conf_vals->question) {
+ answer = cli_cmd_get_confirmation (state,
+ conf_vals->question);
+ if (GF_ANSWER_NO == answer) {
+ ret = -1;
+ goto out;
+ }
}
out:
return ret;
@@ -3572,7 +3619,7 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options,
}
case GF_SNAP_OPTION_TYPE_CONFIG:
{
- /* snapshot config <volname | all> [snap_max_limit <count>] */
+ /* snapshot config <volname | all> [snap-max-hard-limit <count> | snap-max-soft-limit <count>] */
ret = cli_snap_config_parse (words, wordcount, dict,
state);
if (ret) {
diff --git a/cli/src/cli-cmd-snapshot.c b/cli/src/cli-cmd-snapshot.c
index 6aac4d29f..556278931 100644
--- a/cli/src/cli-cmd-snapshot.c
+++ b/cli/src/cli-cmd-snapshot.c
@@ -90,7 +90,7 @@ struct cli_cmd snapshot_cmds[] = {
cli_cmd_snapshot_cbk,
"Snapshot List."
},
- {"snapshot config < volname | all > [ snap-max-limit <count> ]",
+ {"snapshot config < volname | all > [ snap-max-hard-limit <count> | snap-max-soft-limit <count> ]",
cli_cmd_snapshot_cbk,
"Snapshot Config."
},
diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c
index 31fd616ff..926c01b70 100644
--- a/cli/src/cli-rpc-ops.c
+++ b/cli/src/cli-rpc-ops.c
@@ -7896,6 +7896,106 @@ out:
}
int
+cli_snapshot_config_display (dict_t *dict, gf_cli_rsp *rsp)
+{
+ char *volname = NULL;
+ char *key = NULL;
+ int ret = -1;
+ int config_command = 0;
+ uint64_t value = 0;
+
+ GF_ASSERT (dict);
+ GF_ASSERT (rsp);
+
+ if (rsp->op_ret) {
+ cli_err ("Snapshot Config : failed: %s",
+ rsp->op_errstr ? rsp->op_errstr :
+ "Please check log file for details");
+ ret = rsp->op_ret;
+ goto out;
+ }
+
+ ret = dict_get_int32 (dict, "config-command", &config_command);
+ if (ret) {
+ gf_log("", GF_LOG_DEBUG, "Could not fetch config type");
+ ret = -1;
+ goto out;
+ }
+
+ ret = dict_get_str (dict, "volname", &volname);
+ if (ret) {
+ gf_log("", GF_LOG_ERROR, "Could not fetch "
+ "volname");
+ ret = -1;
+ goto out;
+ }
+
+ if (!strcmp (volname, "all")) {
+ volname = "System";
+ }
+
+ ret = dict_get_str (dict, "config-key", &key);
+ if (ret)
+ gf_log("", GF_LOG_ERROR, "No config-key set");
+
+ switch (config_command) {
+ case GF_SNAP_CONFIG_TYPE_SET:
+ cli_out ("snapshot config: %s "
+ "for %s set successfully", key, volname);
+ break;
+
+ case GF_SNAP_CONFIG_DISPLAY :
+ if (!key) {
+ /* For all options */
+ ret = dict_get_uint64 (dict, "snap-max-hard-limit",
+ &value);
+ if (ret) {
+ gf_log("", GF_LOG_DEBUG, "Could not fetch "
+ "snap_max_hard_limit for %s", volname);
+ ret = -1;
+ goto out;
+ }
+ cli_out ("snapshot config: snap-max-hard-limit for "
+ "%s set to %"PRIu64,
+ volname, value);
+
+ ret = dict_get_uint64 (dict, "snap-max-soft-limit",
+ &value);
+ if (ret) {
+ gf_log("", GF_LOG_DEBUG, "Could not fetch "
+ "snap-max-soft-limit for %s", volname);
+ ret = -1;
+ goto out;
+ }
+ cli_out ("snapshot config: snap-max-soft-limit for "
+ "%s set to %"PRIu64,
+ volname, value);
+ } else {
+ if ((!strncmp (key, "snap-max-hard-limit", strlen(key))) ||
+ (!strncmp (key, "snap-max-soft-limit", strlen(key)))) {
+ ret = dict_get_uint64 (dict, key, &value);
+ if (ret) {
+ gf_log("", GF_LOG_DEBUG, "Could not fetch "
+ "%s for %s", key, volname);
+ ret = -1;
+ goto out;
+ }
+ cli_out ("snapshot config: %s for "
+ "%s set to %"PRIu64, key,
+ volname, value);
+ }
+ }
+ break;
+ default :
+ break;
+ }
+
+ ret = 0;
+out:
+ return ret;
+}
+
+int
gf_cli_snapshot_cbk (struct rpc_req *req, struct iovec *iov,
int count, void *myframe)
{
@@ -7907,9 +8007,6 @@ gf_cli_snapshot_cbk (struct rpc_req *req, struct iovec *iov,
int32_t type = 0;
int64_t volcount = -1;
call_frame_t *frame = NULL;
- uint64_t limit = 0;
- int32_t config_command = 0;
- char *volname = NULL;
if (req->rpc_status == -1) {
ret = -1;
@@ -8056,50 +8153,12 @@ gf_cli_snapshot_cbk (struct rpc_req *req, struct iovec *iov,
break;
case GF_SNAP_OPTION_TYPE_CONFIG:
- if (rsp.op_ret) {
- cli_err ("Snapshot Config : failed: %s",
- rsp.op_errstr ? rsp.op_errstr :
- "Please check log file for details");
- ret = rsp.op_ret;
- goto out;
- }
-
- ret = dict_get_int32 (dict, "config-command", &config_command);
-
+ ret = cli_snapshot_config_display (dict, &rsp);
if (ret) {
- gf_log("", GF_LOG_DEBUG, "Could not fetch config type");
- ret = -1;
- goto out;
- }
-
- ret = dict_get_str (dict, "volname", &volname);
- if (ret) {
- gf_log("", GF_LOG_DEBUG, "Could not fetch "
- "volname");
- ret = -1;
+ gf_log ("", GF_LOG_ERROR, "Failed to display snapshot "
+ "config output.");
goto out;
}
-
- if (!strcmp (volname, "all")) {
- volname = "System";
- }
-
- if (config_command == GF_SNAP_CONFIG_DISPLAY) {
-
- ret = dict_get_uint64 (dict, "limit", &limit);
- if (ret) {
- gf_log("", GF_LOG_DEBUG, "Could not fetch "
- "limit for %s", volname);
- ret = -1;
- goto out;
- }
- cli_out ("snapshot config: snap-max-limit for "
- "%s set to %"PRIu64,
- volname, limit);
- } else {
- cli_out ("snapshot config: snap-max-limit "
- "for %s set successfully", volname);
- }
break;
case GF_SNAP_OPTION_TYPE_DELETE:
diff --git a/cli/src/cli.h b/cli/src/cli.h
index 3d987a8bc..8daa4b741 100644
--- a/cli/src/cli.h
+++ b/cli/src/cli.h
@@ -166,6 +166,11 @@ struct cli_volume_status {
#endif
};
+struct snap_config_opt_vals_ {
+ char *op_name;
+ char *question;
+};
+
typedef struct gf_cli_gsync_detailed_status_ gf_cli_gsync_status_t;
typedef struct cli_volume_status cli_volume_status_t;
diff --git a/rpc/xdr/src/cli1-xdr.h b/rpc/xdr/src/cli1-xdr.h
index 4c4cb0f18..dfde3e20d 100644
--- a/rpc/xdr/src/cli1-xdr.h
+++ b/rpc/xdr/src/cli1-xdr.h
@@ -184,10 +184,8 @@ typedef enum gf1_cli_snapshot gf1_cli_snapshot;
enum gf1_cli_snapshot_config {
GF_SNAP_CONFIG_TYPE_NONE = 0,
- GF_SNAP_CONFIG_SYS_MAX = 0 + 1,
- GF_SNAP_CONFIG_VOL_MAX = 0 + 2,
- GF_SNAP_CONFIG_DISPLAY = 0 + 3,
- GF_SNAP_CONFIG_CG_MAX = 0 + 4,
+ GF_SNAP_CONFIG_TYPE_SET = 0 + 1,
+ GF_SNAP_CONFIG_DISPLAY = 0 + 2
};
typedef enum gf1_cli_snapshot_config gf1_cli_snapshot_config;
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot.c b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
index d21377924..cd9ed3f23 100644
--- a/xlators/mgmt/glusterd/src/glusterd-snapshot.c
+++ b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
@@ -395,14 +395,61 @@ out:
}
int
-glusterd_snapshot_config_limit_prevalidate (dict_t *dict, char **op_errstr,
- int config_command)
+snap_max_limits_validate (dict_t *dict, char *key,
+ char **op_errstr)
+{
+ char err_str[PATH_MAX] = "";
+ glusterd_conf_t *conf = NULL;
+ int ret = -1;
+ uint64_t value = 0;
+ uint64_t max_limit = GLUSTERD_SNAPS_MAX_LIMIT;
+ xlator_t *this = NULL;
+
+ this = THIS;
+
+ GF_ASSERT (this);
+ GF_ASSERT (dict);
+ GF_ASSERT (key);
+ GF_ASSERT (op_errstr);
+
+ conf = this->private;
+
+ 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;
+ }
+
+ if ((value < 0) ||
+ (value > max_limit)) {
+ ret = -1;
+ 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:
+ return ret;
+}
+
+int
+glusterd_snapshot_config_prevalidate (dict_t *dict, char **op_errstr)
{
char *volname = NULL;
+ char *key = NULL;
glusterd_volinfo_t *volinfo = NULL;
- uint64_t limit = 0;
xlator_t *this = NULL;
int ret = -1;
+ int config_command = 0;
char err_str[PATH_MAX] = {0,};
glusterd_conf_t *conf = NULL;
@@ -416,70 +463,29 @@ glusterd_snapshot_config_limit_prevalidate (dict_t *dict, char **op_errstr,
GF_ASSERT (conf);
- switch (config_command) {
+ ret = dict_get_int32 (dict, "config-command", &config_command);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "failed to get config-command type");
+ goto out;
+ }
- case GF_SNAP_CONFIG_SYS_MAX:
- ret = dict_get_uint64 (dict, "limit", &limit);
- if (ret) {
- snprintf (err_str, PATH_MAX,"Failed to get the"
- " snapshot limit");
- *op_errstr = gf_strdup (err_str);
- gf_log (this->name, GF_LOG_ERROR, "%s", err_str);
- goto out;
- }
- if (limit < 0 || limit > GLUSTERD_SNAPS_MAX_LIMIT) {
- ret = -1;
- snprintf (err_str, PATH_MAX,"Invalid max snap limit "
- "%"PRIu64 ". Expected range 0 - %"PRIu64,
- limit, conf->snap_max_limit);
- *op_errstr = gf_strdup (err_str);
- gf_log (this->name, GF_LOG_ERROR, "%s", err_str);
- goto out;
- }
- break;
+ ret = dict_get_str (dict, "config-key", &key);
- case GF_SNAP_CONFIG_VOL_MAX:
- // volume wide limit
- 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 = 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;
- }
- ret = dict_get_uint64 (dict, "limit", &limit);
- if (ret) {
- snprintf (err_str, PATH_MAX,"Failed to get 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;
- }
- if (limit < 0 || limit > conf->snap_max_limit) {
- ret = -1;
- snprintf (err_str, PATH_MAX,"Invalid max snap limit "
- "%"PRIu64 " for volume %s. Expected range"
- " 0 - %"PRIu64, limit, volname,
- conf->snap_max_limit);
- *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)))) {
+ /* 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_CG_MAX:
- break;
-
case GF_SNAP_CONFIG_DISPLAY:
ret = dict_get_str (dict, "volname", &volname);
if (ret) {
@@ -489,14 +495,14 @@ glusterd_snapshot_config_limit_prevalidate (dict_t *dict, char **op_errstr,
gf_log (this->name, GF_LOG_ERROR, "%s", err_str);
goto out;
}
- if (!strncmp (volname, "all", 3)) {
+ if (!strncmp (volname, "all", strlen(volname))) {
ret = 0;
goto out;
}
ret = glusterd_volinfo_find (volname, &volinfo);
if (ret) {
- snprintf (err_str, PATH_MAX,"Failed to get the"
- " volinfo for volume %s", volname);
+ snprintf (err_str, PATH_MAX,"Volume %s does not exist.",
+ volname);
*op_errstr = gf_strdup (err_str);
gf_log (this->name, GF_LOG_ERROR, "%s", err_str);
goto out;
@@ -510,39 +516,6 @@ out:
}
int
-glusterd_snapshot_config_prevalidate (dict_t *dict, char **op_errstr)
-{
- int config_command = 0;
- xlator_t *this = NULL;
- int ret = -1;
-
- this = THIS;
- ret = dict_get_int32 (dict, "config-command", &config_command);
- if (ret) {
- gf_log (this->name, GF_LOG_ERROR,
- "failed to get config-command type");
- goto out;
- }
-
- switch (config_command) {
- case GF_SNAP_CONFIG_SYS_MAX:
- case GF_SNAP_CONFIG_VOL_MAX:
- case GF_SNAP_CONFIG_CG_MAX:
- case GF_SNAP_CONFIG_DISPLAY:
- ret = glusterd_snapshot_config_limit_prevalidate (dict,
- op_errstr,
- config_command);
- break;
- default:
- ret = -1;
- gf_log (this->name, GF_LOG_ERROR, "Incorrect config op");
- break;
- }
-out:
- return ret;
-}
-
-int
glusterd_snap_create_pre_val_use_rsp_dict (dict_t *dst, dict_t *src)
{
char *snap_mount = NULL;
@@ -1679,17 +1652,17 @@ glusterd_snapshot_vol_get_snaplist_lk (dict_t *dict, char *keyprefix,
goto out;
}
- if (conf->snap_max_limit < volinfo->snap_max_limit) {
- snap_limit = conf->snap_max_limit;
- gf_log(this->name, GF_LOG_DEBUG, "system snap_limit is "
- "lesser than volume snap_limit, snap_limit value "
- "is set to %ld",snap_limit);
+ if (conf->snap_max_hard_limit < volinfo->snap_max_hard_limit) {
+ snap_limit = conf->snap_max_hard_limit;
+ gf_log(this->name, GF_LOG_DEBUG, "system snap-max-hard-limit is"
+ " lesser than volume snap-max-hard-limit, "
+ "snap-max-hard-limit value is set to %ld", snap_limit);
}
else {
- snap_limit = volinfo->snap_max_limit ;
- gf_log(this->name, GF_LOG_DEBUG, "volume snap_limit is "
- "lesser than system snap_limit, snap_limit value "
- "is set to %ld",snap_limit);
+ snap_limit = volinfo->snap_max_hard_limit ;
+ gf_log(this->name, GF_LOG_DEBUG, "volume snap-max-hard-limit is"
+ " lesser than system snap-max-hard-limit, "
+ "snap-max-hard-limit value is set to %ld",snap_limit);
}
if (snap_limit > volinfo->snap_count)
@@ -4121,152 +4094,233 @@ out:
}
int
-glusterd_snapshot_config_commit (dict_t *dict, char **op_errstr,
- dict_t *rsp_dict)
+snap_max_limits_set_commit (dict_t *dict, char *key, char *volname,
+ char **op_errstr)
{
- char *volname = NULL;
+ char err_str[PATH_MAX] = "";
+ glusterd_conf_t *conf = NULL;
glusterd_volinfo_t *volinfo = NULL;
- uint64_t limit = 0;
- 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;
+ xlator_t *this = NULL;
this = THIS;
GF_ASSERT (this);
GF_ASSERT (dict);
- GF_ASSERT (rsp_dict);
+ GF_ASSERT (key);
+ GF_ASSERT (volname);
GF_ASSERT (op_errstr);
conf = this->private;
GF_ASSERT (conf);
- ret = dict_get_int32 (dict, "config-command", &config_command);
+ ret = dict_get_uint64 (dict, key, &value);
if (ret) {
- gf_log (this->name, GF_LOG_ERROR,
- "failed to get config-command type");
+ snprintf (err_str, PATH_MAX,"Failed to get the"
+ " value for %s", key);
goto out;
}
- switch (config_command) {
+ /* 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;
- case GF_SNAP_CONFIG_SYS_MAX:
- ret = dict_get_uint64 (dict, "limit", &limit);
- if (ret) {
- snprintf (err_str, PATH_MAX,"Failed to get the"
- " snapshot limit");
- *op_errstr = gf_strdup (err_str);
- gf_log (this->name, GF_LOG_ERROR, "%s", err_str);
- goto out;
- }
- conf->snap_max_limit = limit;
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:
- // volume wide limit
- 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);
+ snprintf (err_str, PATH_MAX,"Failed to store %s "
+ "for system", key);
goto out;
}
+ } else {
+ /* 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;
}
- ret = dict_get_uint64 (dict, "limit", &limit);
- if (ret) {
- snprintf (err_str, PATH_MAX,"Failed to get 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;
- }
- volinfo->snap_max_limit = limit;
+
+ if (!strncmp (key, "snap-max-hard-limit", strlen(key)))
+ volinfo->snap_max_hard_limit = value;
+ else
+ volinfo->snap_max_soft_limit = value;
+
ret = glusterd_store_volinfo (volinfo,
- GLUSTERD_VOLINFO_VER_AC_INCREMENT);
+ 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);
+ snprintf (err_str, PATH_MAX,"Failed to store %s "
+ "for volume %s", key, volname);
goto out;
}
- break;
+ }
- case GF_SNAP_CONFIG_CG_MAX:
- break;
- case GF_SNAP_CONFIG_DISPLAY:
- 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", 3)) {
- limit = conf->snap_max_limit;
- } else {
- 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;
- }
- limit = volinfo->snap_max_limit;
- }
+ ret = 0;
+out:
+ if (ret) {
+ *op_errstr = gf_strdup (err_str);
+ gf_log (this->name, GF_LOG_ERROR, "%s", err_str);
+ }
- ret = dict_set_uint64 (rsp_dict, "limit", limit);
+ return ret;
+}
+
+int
+snap_max_limits_display_commit (dict_t *rsp_dict, char *key, 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;
+
+ GF_ASSERT (this);
+ GF_ASSERT (rsp_dict);
+ GF_ASSERT (key);
+ GF_ASSERT (volname);
+ GF_ASSERT (op_errstr);
+
+ conf = this->private;
+
+ GF_ASSERT (conf);
+
+ 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;
+ } else {
+ /* For one volume */
+ ret = glusterd_volinfo_find (volname, &volinfo);
if (ret) {
snprintf (err_str, PATH_MAX,"Failed to get the"
- " set limit for volume %s",
- volname);
+ " volinfo for volume %s", volname);
*op_errstr = gf_strdup (err_str);
gf_log (this->name, GF_LOG_ERROR, "%s", err_str);
goto out;
}
- break;
- default:
- break;
+ if (!strncmp (key, "snap-max-hard-limit", strlen(key)))
+ value = volinfo->snap_max_hard_limit;
+ else
+ value = volinfo->snap_max_soft_limit;
}
- ret = dict_set_str (rsp_dict, "volname", volname);
+ ret = dict_set_uint64 (rsp_dict, key, value);
if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "Failed to set the"
- " volume name");
+ 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);
goto out;
}
- ret = dict_set_int32 (dict, "config-command", config_command);
+ ret = 0;
+out:
+ return ret;
+}
+
+int
+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;
+
+ this = THIS;
+
+ GF_ASSERT (this);
+ GF_ASSERT (dict);
+ GF_ASSERT (rsp_dict);
+ GF_ASSERT (op_errstr);
+
+ conf = this->private;
+
+ GF_ASSERT (conf);
+
+ ret = dict_get_int32 (dict, "config-command", &config_command);
if (ret) {
gf_log (this->name, GF_LOG_ERROR,
- "failed to set config-command type");
+ "failed to get config-command type");
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;
+ }
+
+ 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)))) {
+ /* Commit ops for snap-max-hard-limit and snap-max-soft-limit */
+ ret = snap_max_limits_set_commit (dict, key, volname, op_errstr);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "%s set commit failed.", key);
+ goto out;
+ }
+ }
+ break;
+
+ 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);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "snap-max-hard-limit "
+ "display commit failed.");
+ goto out;
+ }
+
+ 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;
+ }
+ }
+ break;
+ default:
+ break;
+ }
+
out:
gf_log (this->name, GF_LOG_TRACE, "Returning %d", ret);
return ret;
diff --git a/xlators/mgmt/glusterd/src/glusterd-store.c b/xlators/mgmt/glusterd/src/glusterd-store.c
index 88ac2bf6e..f37ad9bec 100644
--- a/xlators/mgmt/glusterd/src/glusterd-store.c
+++ b/xlators/mgmt/glusterd/src/glusterd-store.c
@@ -702,11 +702,24 @@ glusterd_volume_exclude_options_write (int fd, glusterd_volinfo_t *volinfo)
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,
+
+ snprintf (buf, sizeof (buf), "%"PRIu64, volinfo->snap_max_hard_limit);
+ ret = gf_store_save_value (fd, GLUSTERD_STORE_KEY_SNAP_MAX_HARD_LIMIT,
buf);
- if (ret)
+ if (ret) {
+ gf_log (THIS->name, GF_LOG_ERROR,
+ "Unable to write snap-max-hard-limit");
goto out;
+ }
+
+ snprintf (buf, sizeof (buf), "%"PRIu64, volinfo->snap_max_soft_limit);
+ ret = gf_store_save_value (fd, GLUSTERD_STORE_KEY_SNAP_MAX_SOFT_LIMIT,
+ buf);
+ if (ret) {
+ gf_log (THIS->name, GF_LOG_ERROR,
+ "Unable to write snap-max-soft-limit");
+ goto out;
+ }
out:
if (ret)
@@ -2064,14 +2077,24 @@ glusterd_store_global_info (xlator_t *this)
goto out;
}
- snprintf (buf, sizeof (buf), "%"PRIu64, conf->snap_max_limit);
+ snprintf (buf, sizeof (buf), "%"PRIu64, conf->snap_max_hard_limit);
ret = gf_store_save_value (handle->fd,
- GLUSTERD_STORE_KEY_SNAP_MAX_LIMIT, buf);
+ GLUSTERD_STORE_KEY_SNAP_MAX_HARD_LIMIT, buf);
if (ret) {
gf_log (this->name, GF_LOG_ERROR,
- "Storing snap-max-limit failed ret = %d", ret);
+ "Storing snap-max-hard-limit failed ret = %d", ret);
goto out;
}
+
+ snprintf (buf, sizeof (buf), "%"PRIu64, conf->snap_max_soft_limit);
+ ret = gf_store_save_value (handle->fd,
+ GLUSTERD_STORE_KEY_SNAP_MAX_SOFT_LIMIT, buf);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "Storing snap-max-soft-limit failed ret = %d", ret);
+ goto out;
+ }
+
ret = gf_store_rename_tmppath (handle);
out:
if (ret && (handle->fd > 0))
@@ -2144,7 +2167,7 @@ out:
}
int
-glusterd_retrieve_sys_snap_max_limit (xlator_t *this, uint64_t *limit)
+glusterd_retrieve_sys_snap_max_limit (xlator_t *this, uint64_t *limit, char *key)
{
char *limit_str = NULL;
glusterd_conf_t *priv = NULL;
@@ -2154,8 +2177,13 @@ glusterd_retrieve_sys_snap_max_limit (xlator_t *this, uint64_t *limit)
char path[PATH_MAX] = {0,};
gf_store_handle_t *handle = NULL;
+ GF_ASSERT (this);
priv = this->private;
+ GF_ASSERT (priv);
+ GF_ASSERT (limit);
+ GF_ASSERT (key);
+
if (!priv->handle) {
snprintf (path, PATH_MAX, "%s/%s", priv->workdir,
GLUSTERD_INFO_FILE);
@@ -2171,11 +2199,11 @@ glusterd_retrieve_sys_snap_max_limit (xlator_t *this, uint64_t *limit)
}
ret = gf_store_retrieve_value (priv->handle,
- GLUSTERD_STORE_KEY_SNAP_MAX_LIMIT,
+ key,
&limit_str);
if (ret) {
gf_log (this->name, GF_LOG_DEBUG,
- "No previous snap limit present");
+ "No previous %s present", key);
goto out;
}
@@ -2197,12 +2225,33 @@ out:
static int
glusterd_restore_op_version (xlator_t *this)
{
- glusterd_conf_t *conf = NULL;
- int ret = 0;
- int op_version = 0;
+ glusterd_conf_t *conf = NULL;
+ int ret = 0;
+ int op_version = 0;
+ int snap_max_limit = GLUSTERD_SNAPS_MAX_LIMIT;
conf = this->private;
+ ret = glusterd_retrieve_sys_snap_max_limit (this,
+ &conf->snap_max_hard_limit,
+ GLUSTERD_STORE_KEY_SNAP_MAX_HARD_LIMIT);
+ if (ret) {
+ gf_log (this->name, GF_LOG_WARNING,
+ "Unable to retrieve system snap-max-hard-limit, "
+ "setting it to %d", snap_max_limit);
+ conf->snap_max_hard_limit = GLUSTERD_SNAPS_MAX_LIMIT;
+ }
+
+ ret = glusterd_retrieve_sys_snap_max_limit (this,
+ &conf->snap_max_soft_limit,
+ GLUSTERD_STORE_KEY_SNAP_MAX_SOFT_LIMIT);
+ if (ret) {
+ gf_log (this->name, GF_LOG_WARNING,
+ "Unable to retrieve system snap-max-soft-limit, "
+ "setting it to %d", snap_max_limit);
+ conf->snap_max_soft_limit = GLUSTERD_SNAPS_MAX_LIMIT;
+ }
+
ret = glusterd_retrieve_op_version (this, &op_version);
if (!ret) {
if ((op_version < GD_OP_VERSION_MIN) ||
@@ -2241,9 +2290,6 @@ 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;
@@ -2750,9 +2796,12 @@ 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 (!strncmp (key, GLUSTERD_STORE_KEY_SNAP_MAX_HARD_LIMIT,
+ strlen (GLUSTERD_STORE_KEY_SNAP_MAX_HARD_LIMIT))) {
+ volinfo->snap_max_hard_limit = (uint64_t) atoll (value);
+ } else if (!strncmp (key, GLUSTERD_STORE_KEY_SNAP_MAX_SOFT_LIMIT,
+ strlen (GLUSTERD_STORE_KEY_SNAP_MAX_SOFT_LIMIT))) {
+ volinfo->snap_max_soft_limit = (uint64_t) atoll (value);
} else if (!strncmp (key, GLUSTERD_STORE_KEY_PARENT_VOLNAME,
strlen (GLUSTERD_STORE_KEY_PARENT_VOLNAME))) {
strncpy (volinfo->parent_volname, value, sizeof(volinfo->parent_volname) - 1);
diff --git a/xlators/mgmt/glusterd/src/glusterd-store.h b/xlators/mgmt/glusterd/src/glusterd-store.h
index 69ee30dd3..13d408c44 100644
--- a/xlators/mgmt/glusterd/src/glusterd-store.h
+++ b/xlators/mgmt/glusterd/src/glusterd-store.h
@@ -68,7 +68,8 @@ 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_SNAP_MAX_HARD_LIMIT "snap-max-hard-limit"
+#define GLUSTERD_STORE_KEY_SNAP_MAX_SOFT_LIMIT "snap-max-soft-limit"
#define GLUSTERD_STORE_KEY_BRICK_HOSTNAME "hostname"
#define GLUSTERD_STORE_KEY_BRICK_PATH "path"
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
index 7c68947b8..6947facbd 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
@@ -463,10 +463,8 @@ glusterd_volinfo_new (glusterd_volinfo_t **volinfo)
snprintf (new_volinfo->parent_volname, GLUSTERD_MAX_VOLUME_NAME, "N/A");
- if (conf)
- new_volinfo->snap_max_limit = conf->snap_max_limit;
- else
- new_volinfo->snap_max_limit = GLUSTERD_SNAPS_MAX_LIMIT;
+ new_volinfo->snap_max_hard_limit = GLUSTERD_SNAPS_MAX_LIMIT;
+ new_volinfo->snap_max_soft_limit = GLUSTERD_SNAPS_MAX_LIMIT;
new_volinfo->xl = THIS;
@@ -7857,9 +7855,9 @@ out:
int
glusterd_snap_config_use_rsp_dict (dict_t *dst, dict_t *src)
{
- int ret = -1;
- uint64_t limit = 0;
- int config_command = 0;
+ int ret = -1;
+ uint64_t value = 0;
+ int config_command = 0;
if (!dst || !src) {
gf_log ("", GF_LOG_ERROR, "Source or Destination "
@@ -7876,16 +7874,22 @@ glusterd_snap_config_use_rsp_dict (dict_t *dst, dict_t *src)
switch (config_command) {
case GF_SNAP_CONFIG_DISPLAY:
- ret = dict_get_uint64 (src, "limit", &limit);
- if (ret) {
- gf_log ("", GF_LOG_ERROR, "Unable to fetch limit");
- goto out;
+ ret = dict_get_uint64 (src, "snap-max-hard-limit", &value);
+ if (!ret) {
+ ret = dict_set_uint64 (dst, "snap-max-hard-limit", value);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "Unable to set snap_max_hard_limit");
+ goto out;
+ }
}
- ret = dict_set_uint64 (dst, "limit", limit);
- if (ret) {
- gf_log ("", GF_LOG_ERROR, "Unable to set limit");
- goto out;
+ ret = dict_get_uint64 (src, "snap-max-soft-limit", &value);
+ if (!ret) {
+ ret = dict_set_uint64 (dst, "snap-max-soft-limit", value);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "Unable to set snap_max_soft_limit");
+ goto out;
+ }
}
break;
diff --git a/xlators/mgmt/glusterd/src/glusterd.c b/xlators/mgmt/glusterd/src/glusterd.c
index 268acc776..8b97a4e26 100644
--- a/xlators/mgmt/glusterd/src/glusterd.c
+++ b/xlators/mgmt/glusterd/src/glusterd.c
@@ -1322,9 +1322,6 @@ init (xlator_t *this)
conf->gfs_mgmt = &gd_brick_prog;
strncpy (conf->workdir, workdir, PATH_MAX);
- conf->snap_max_limit = GLUSTERD_SNAPS_MAX_LIMIT;
- //TODO: read from saved value and update
-
synclock_init (&conf->big_lock);
pthread_mutex_init (&conf->xprt_lock, NULL);
INIT_LIST_HEAD (&conf->xprt_list);
diff --git a/xlators/mgmt/glusterd/src/glusterd.h b/xlators/mgmt/glusterd/src/glusterd.h
index 648a88452..343e6fe4d 100644
--- a/xlators/mgmt/glusterd/src/glusterd.h
+++ b/xlators/mgmt/glusterd/src/glusterd.h
@@ -158,7 +158,8 @@ typedef struct {
rpcsvc_t *uds_rpc; /* RPCSVC for the unix domain socket */
uint32_t base_port;
struct list_head snap_cg;
- uint64_t snap_max_limit;
+ uint64_t snap_max_hard_limit;
+ uint64_t snap_max_soft_limit;
char *snap_bricks_directory;
} glusterd_conf_t;
@@ -285,7 +286,8 @@ struct glusterd_volinfo_ {
int type;
int brick_count;
uint64_t snap_count;
- uint64_t snap_max_limit;
+ uint64_t snap_max_hard_limit;
+ uint64_t snap_max_soft_limit;
struct list_head vol_list;
struct list_head bricks;
struct list_head snaps;