diff options
author | Krishnan Parthasarathi <kparthas@redhat.com> | 2012-08-20 21:34:26 +0530 |
---|---|---|
committer | Anand Avati <avati@redhat.com> | 2012-09-12 12:25:06 -0700 |
commit | 35d178dbd4ddb8c407e911823c850642563baa9f (patch) | |
tree | 07be45c363cfd6dcd3ece83e87e522b61c9ce529 | |
parent | a032de191ec32be363d1feedfbd839f6dbde2579 (diff) |
cli: Added special key "group" for bulk volume set.
gluster volume set VOLNAME group group_name
- where group_name is a file under /var/lib/glusterd/groups containing one
key, value pair per line as below,
key1=value1
key2=value2
[...]
- the command sets key1 to value1 and so on.
Change-Id: Ic4c8dedb98d013b29a74e57f8ee7c1d3573137d2
BUG: 851237
Signed-off-by: Krishnan Parthasarathi <kparthas@redhat.com>
Reviewed-on: http://review.gluster.org/3831
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Amar Tumballi <amarts@redhat.com>
Reviewed-by: Anand Avati <avati@redhat.com>
-rw-r--r-- | cli/src/cli-cmd-parser.c | 113 | ||||
-rw-r--r-- | glusterfs.spec.in | 2 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd.c | 66 |
3 files changed, 148 insertions, 33 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index d4c2451c899..369ad371db4 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -643,6 +643,90 @@ out: return ret; } +static inline gf_boolean_t +cli_is_key_spl (char *key) +{ + return (strcmp (key, "group") == 0); +} + +#define GLUSTERD_DEFAULT_WORKDIR "/var/lib/glusterd" +static int +cli_add_key_group (dict_t *dict, char *key, char *value) +{ + int ret = -1; + int opt_count = 0; + char iter_key[1024] = {0,}; + char iter_val[1024] = {0,}; + char *saveptr = NULL; + char *tok_key = NULL; + char *tok_val = NULL; + char *dkey = NULL; + char *dval = NULL; + char *tagpath = NULL; + char *buf = NULL; + char line[PATH_MAX + 256] = {0,}; + FILE *fp = NULL; + + ret = gf_asprintf (&tagpath, "%s/groups/%s", + GLUSTERD_DEFAULT_WORKDIR, value); + if (ret == -1) { + tagpath = NULL; + goto out; + } + + fp = fopen (tagpath, "r"); + if (!fp) { + ret = -1; + goto out; + } + + opt_count = 0; + buf = line; + while (fscanf (fp, "%s", buf) != EOF) { + + opt_count++; + tok_key = strtok_r (line, "=", &saveptr); + tok_val = strtok_r (NULL, "=", &saveptr); + if (!tok_key || !tok_val) { + ret = -1; + goto out; + } + + snprintf (iter_key, sizeof (iter_key), "key%d", opt_count); + dkey = gf_strdup (tok_key); + ret = dict_set_dynstr (dict, iter_key, dkey); + if (ret) + goto out; + + snprintf (iter_val, sizeof (iter_val), "value%d", opt_count); + dval = gf_strdup (tok_val); + ret = dict_set_dynstr (dict, iter_val, dval); + if (ret) + goto out; + + } + + if (!opt_count) { + ret = -1; + goto out; + } + ret = dict_set_int32 (dict, "count", opt_count); +out: + + GF_FREE (tagpath); + + if (ret) { + GF_FREE (dkey); + GF_FREE (dval); + } + + if (fp) + fclose (fp); + + return ret; +} +#undef GLUSTERD_DEFAULT_WORKDIR + int32_t cli_cmd_volume_set_parse (const char **words, int wordcount, dict_t **options) { @@ -680,9 +764,27 @@ cli_cmd_volume_set_parse (const char **words, int wordcount, dict_t **options) ret = dict_set_str (dict, volname, volname); if (ret) goto out; + } else if (wordcount < 5) { ret = -1; goto out; + + } else if (wordcount == 5 && cli_is_key_spl ((char *)words[3])) { + key = (char *) words[3]; + value = (char *) words[4]; + if ( !key || !value) { + ret = -1; + goto out; + } + + ret = gf_strip_whitespace (value, strlen (value)); + if (ret == -1) + goto out; + + ret = cli_add_key_group (dict, key, value); + if (ret == 0) + *options = dict; + goto out; } for (i = 3; i < wordcount; i+=2) { @@ -701,6 +803,11 @@ cli_cmd_volume_set_parse (const char **words, int wordcount, dict_t **options) if (ret == -1) goto out; + if (cli_is_key_spl (key)) { + ret = -1; + goto out; + } + sprintf (str, "key%d", count); ret = dict_set_str (dict, str, key); if (ret) @@ -721,10 +828,8 @@ cli_cmd_volume_set_parse (const char **words, int wordcount, dict_t **options) *options = dict; out: - if (ret) { - if (dict) - dict_destroy (dict); - } + if (ret) + dict_destroy (dict); return ret; } diff --git a/glusterfs.spec.in b/glusterfs.spec.in index 49bf19c7745..05eec2cc1f8 100644 --- a/glusterfs.spec.in +++ b/glusterfs.spec.in @@ -244,6 +244,7 @@ touch %{buildroot}%{_sharedstatedir}/glusterd/glusterd.info %{__mkdir_p} %{buildroot}%{_sharedstatedir}/glusterd/nfs %{__mkdir_p} %{buildroot}%{_sharedstatedir}/glusterd/peers %{__mkdir_p} %{buildroot}%{_sharedstatedir}/glusterd/vols +%{__mkdir_p} %{buildroot}%{_sharedstatedir}/glusterd/groups %if 0%{?_can_georeplicate} %if 0%{!?_without_georeplication:1} %{__mkdir_p} %{buildroot}%{_sharedstatedir}/glusterd/geo-replication @@ -417,6 +418,7 @@ fi %ghost %dir %attr(0755,-,-) %{_sharedstatedir}/glusterd/vols %ghost %dir %attr(0755,-,-) %{_sharedstatedir}/glusterd/nfs %ghost %dir %attr(0755,-,-) %{_sharedstatedir}/glusterd/peers +%ghost %dir %attr(0755,-,-) %{_sharedstatedir}/glusterd/groups %files devel %defattr(-,root,root,-) diff --git a/xlators/mgmt/glusterd/src/glusterd.c b/xlators/mgmt/glusterd/src/glusterd.c index c7b3b769dcf..a600c379495 100644 --- a/xlators/mgmt/glusterd/src/glusterd.c +++ b/xlators/mgmt/glusterd/src/glusterd.c @@ -747,10 +747,10 @@ init (xlator_t *this) glusterd_conf_t *conf = NULL; data_t *dir_data = NULL; struct stat buf = {0,}; - char voldir [PATH_MAX] = {0,}; - char dirname [PATH_MAX]; - char cmd_log_filename [PATH_MAX] = {0,}; + char storedir [PATH_MAX] = {0,}; + char workdir [PATH_MAX] = {0,}; char hooks_dir [PATH_MAX] = {0,}; + char cmd_log_filename [PATH_MAX] = {0,}; int first_time = 0; char *mountbroker_root = NULL; @@ -761,34 +761,34 @@ init (xlator_t *this) if (!dir_data) { //Use default working dir - strncpy (dirname, GLUSTERD_DEFAULT_WORKDIR, PATH_MAX); + strncpy (workdir, GLUSTERD_DEFAULT_WORKDIR, PATH_MAX); } else { - strncpy (dirname, dir_data->data, PATH_MAX); + strncpy (workdir, dir_data->data, PATH_MAX); } - ret = stat (dirname, &buf); + ret = stat (workdir, &buf); if ((ret != 0) && (ENOENT != errno)) { gf_log (this->name, GF_LOG_ERROR, "stat fails on %s, exiting. (errno = %d)", - dirname, errno); + workdir, errno); exit (1); } if ((!ret) && (!S_ISDIR(buf.st_mode))) { gf_log (this->name, GF_LOG_CRITICAL, "Provided working area %s is not a directory," - "exiting", dirname); + "exiting", workdir); exit (1); } if ((-1 == ret) && (ENOENT == errno)) { - ret = mkdir (dirname, 0777); + ret = mkdir (workdir, 0777); if (-1 == ret) { gf_log (this->name, GF_LOG_CRITICAL, "Unable to create directory %s" - " ,errno = %d", dirname, errno); + " ,errno = %d", workdir, errno); exit (1); } @@ -796,7 +796,7 @@ init (xlator_t *this) } gf_log (this->name, GF_LOG_INFO, "Using %s as working directory", - dirname); + workdir); snprintf (cmd_log_filename, PATH_MAX,"%s/.cmd_log_history", DEFAULT_LOG_FILE_DIRECTORY); @@ -808,52 +808,61 @@ init (xlator_t *this) exit (1); } - snprintf (voldir, PATH_MAX, "%s/vols", dirname); + snprintf (storedir, PATH_MAX, "%s/vols", workdir); - ret = mkdir (voldir, 0777); + ret = mkdir (storedir, 0777); if ((-1 == ret) && (errno != EEXIST)) { gf_log (this->name, GF_LOG_CRITICAL, "Unable to create volume directory %s" - " ,errno = %d", voldir, errno); + " ,errno = %d", storedir, errno); exit (1); } - snprintf (voldir, PATH_MAX, "%s/peers", dirname); + snprintf (storedir, PATH_MAX, "%s/peers", workdir); - ret = mkdir (voldir, 0777); + ret = mkdir (storedir, 0777); if ((-1 == ret) && (errno != EEXIST)) { gf_log (this->name, GF_LOG_CRITICAL, "Unable to create peers directory %s" - " ,errno = %d", voldir, errno); + " ,errno = %d", storedir, errno); exit (1); } - snprintf (voldir, PATH_MAX, "%s/bricks", DEFAULT_LOG_FILE_DIRECTORY); - ret = mkdir (voldir, 0777); + snprintf (storedir, PATH_MAX, "%s/bricks", DEFAULT_LOG_FILE_DIRECTORY); + ret = mkdir (storedir, 0777); if ((-1 == ret) && (errno != EEXIST)) { gf_log (this->name, GF_LOG_CRITICAL, "Unable to create logs directory %s" - " ,errno = %d", voldir, errno); + " ,errno = %d", storedir, errno); exit (1); } - snprintf (voldir, PATH_MAX, "%s/nfs", dirname); - ret = mkdir (voldir, 0777); + snprintf (storedir, PATH_MAX, "%s/nfs", workdir); + ret = mkdir (storedir, 0777); if ((-1 == ret) && (errno != EEXIST)) { gf_log (this->name, GF_LOG_CRITICAL, "Unable to create nfs directory %s" - " ,errno = %d", voldir, errno); + " ,errno = %d", storedir, errno); + exit (1); + } + + snprintf (storedir, PATH_MAX, "%s/glustershd", workdir); + ret = mkdir (storedir, 0777); + if ((-1 == ret) && (errno != EEXIST)) { + gf_log (this->name, GF_LOG_CRITICAL, + "Unable to create glustershd directory %s" + " ,errno = %d", storedir, errno); exit (1); } - snprintf (voldir, PATH_MAX, "%s/glustershd", dirname); - ret = mkdir (voldir, 0777); + snprintf (storedir, PATH_MAX, "%s/groups", workdir); + ret = mkdir (storedir, 0777); if ((-1 == ret) && (errno != EEXIST)) { gf_log (this->name, GF_LOG_CRITICAL, "Unable to create glustershd directory %s" - " ,errno = %d", voldir, errno); + " ,errno = %d", storedir, errno); exit (1); } @@ -936,7 +945,7 @@ init (xlator_t *this) pthread_mutex_init (&conf->mutex, NULL); conf->rpc = rpc; conf->gfs_mgmt = &gd_brick_prog; - strncpy (conf->workdir, dirname, PATH_MAX); + strncpy (conf->workdir, workdir, PATH_MAX); INIT_LIST_HEAD (&conf->xprt_list); @@ -968,11 +977,10 @@ init (xlator_t *this) this->private = conf; (void) glusterd_nodesvc_set_running ("glustershd", _gf_false); - /* this->ctx->top = this;*/ GLUSTERD_GET_HOOKS_DIR (hooks_dir, GLUSTERD_HOOK_VER, conf); if (stat (hooks_dir, &buf)) { - ret = glusterd_hooks_create_hooks_directory (dirname); + ret = glusterd_hooks_create_hooks_directory (conf->workdir); if (-1 == ret) { gf_log (this->name, GF_LOG_CRITICAL, "Unable to create hooks directory "); |