summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt/glusterd/src/glusterd-volume-set.c
diff options
context:
space:
mode:
authorAvra Sengupta <asengupt@redhat.com>2013-02-19 16:27:54 +0530
committerAnand Avati <avati@redhat.com>2013-02-28 11:31:28 -0800
commit549231dda9769f23eebf039bc0f7c34a4c086270 (patch)
treecb349d444a57502f9dbbb073a85e0f307ce6b284 /xlators/mgmt/glusterd/src/glusterd-volume-set.c
parent6788badddafd6c749136a6d1cbac030f031ada52 (diff)
glusterd: Added the validation function for subvols-per-directory
Change-Id: Ie2259023b9001311a2032792639c3093054f6750 BUG: 896431 Signed-off-by: Avra Sengupta <asengupt@redhat.com> Reviewed-on: http://review.gluster.org/4552 Reviewed-by: Jeff Darcy <jdarcy@redhat.com> Tested-by: Gluster Build System <jenkins@build.gluster.com>
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-volume-set.c')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-volume-set.c73
1 files changed, 55 insertions, 18 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-set.c b/xlators/mgmt/glusterd/src/glusterd-volume-set.c
index a5efb55f8a1..49d2158ffdf 100644
--- a/xlators/mgmt/glusterd/src/glusterd-volume-set.c
+++ b/xlators/mgmt/glusterd/src/glusterd-volume-set.c
@@ -19,7 +19,6 @@
static int
check_dict_key_value (dict_t *dict, char *key, char *value)
{
- char errstr[2048] = "";
glusterd_conf_t *priv = NULL;
int ret = 0;
xlator_t *this = NULL;
@@ -30,25 +29,19 @@ check_dict_key_value (dict_t *dict, char *key, char *value)
GF_ASSERT (priv);
if (!dict) {
- snprintf (errstr, 2048, "Received Empty Dict.");
- gf_log (this->name, GF_LOG_ERROR,
- "%s.", errstr);
+ gf_log (this->name, GF_LOG_ERROR, "Received Empty Dict.");
ret = -1;
goto out;
}
if (!key) {
- snprintf (errstr, 2048, "Received Empty Key.");
- gf_log (this->name, GF_LOG_ERROR,
- "%s.", errstr);
+ gf_log (this->name, GF_LOG_ERROR, "Received Empty Key.");
ret = -1;
goto out;
}
if (!value) {
- snprintf (errstr, 2048, "Received Empty Value.");
- gf_log (this->name, GF_LOG_ERROR,
- "%s.", errstr);
+ gf_log (this->name, GF_LOG_ERROR, "Received Empty Value.");
ret = -1;
goto out;
}
@@ -62,7 +55,6 @@ out:
static int
get_volname_volinfo (dict_t *dict, char **volname, glusterd_volinfo_t **volinfo)
{
- char errstr[2048] = "";
glusterd_conf_t *priv = NULL;
int ret = 0;
xlator_t *this = NULL;
@@ -74,17 +66,13 @@ get_volname_volinfo (dict_t *dict, char **volname, glusterd_volinfo_t **volinfo)
ret = dict_get_str (dict, "volname", volname);
if (ret) {
- snprintf (errstr, 2048, "Unable to get volume name");
- gf_log (this->name, GF_LOG_ERROR,
- "%s.", errstr);
+ gf_log (this->name, GF_LOG_ERROR, "Unable to get volume name");
goto out;
}
ret = glusterd_volinfo_find (*volname, volinfo);
if (ret) {
- snprintf (errstr, 2048, "Unable to allocate memory");
- gf_log (this->name, GF_LOG_ERROR,
- "%s.", errstr);
+ gf_log (this->name, GF_LOG_ERROR, "Unable to allocate memory");
goto out;
}
@@ -246,6 +234,54 @@ out:
return ret;
}
+static int
+validate_subvols_per_directory (dict_t *dict, char *key, char *value,
+ char **op_errstr)
+{
+ char errstr[2048] = "";
+ char *volname = NULL;
+ glusterd_conf_t *priv = NULL;
+ glusterd_volinfo_t *volinfo = NULL;
+ int ret = 0;
+ int subvols = 0;
+ xlator_t *this = NULL;
+
+ this = THIS;
+ GF_ASSERT (this);
+ priv = this->private;
+ GF_ASSERT (priv);
+
+ ret = check_dict_key_value (dict, key, value);
+ if (ret)
+ goto out;
+
+ ret = get_volname_volinfo (dict, &volname, &volinfo);
+ if (ret)
+ goto out;
+
+ subvols = atoi(value);
+
+ /* Checking if the subvols-per-directory exceed the total
+ number of subvolumes. */
+ if (subvols > volinfo->subvol_count) {
+ snprintf (errstr, sizeof(errstr),
+ "subvols-per-directory(%d) is greater "
+ "than the number of subvolumes(%d).",
+ subvols, volinfo->subvol_count);
+ gf_log (this->name, GF_LOG_ERROR,
+ "%s.", errstr);
+ *op_errstr = gf_strdup (errstr);
+ ret = -1;
+ goto out;
+ }
+
+out:
+ gf_log (this->name, GF_LOG_DEBUG, "Returning %d", ret);
+
+ return ret;
+}
+
+
/* dispatch table for VOLUME SET
* -----------------------------
*
@@ -330,7 +366,8 @@ struct volopt_map_entry glusterd_volopt_map[] = {
{ .key = "cluster.subvols-per-directory",
.voltype = "cluster/distribute",
.option = "directory-layout-spread",
- .op_version = 2
+ .op_version = 2,
+ .validate_fn = validate_subvols_per_directory
},
{ .key = "cluster.readdir-optimize",
.voltype = "cluster/distribute",