summaryrefslogtreecommitdiffstats
path: root/cli/src/cli-cmd-volume.c
diff options
context:
space:
mode:
authorKrutika Dhananjay <kdhananj@redhat.com>2013-08-11 15:51:15 +0530
committerKrutika Dhananjay <kdhananj@redhat.com>2013-08-12 16:28:28 +0530
commit8a681105436f953062d69d2c1dcf559d9dcd7984 (patch)
tree4eabe24f306787c0e330701b91664dffdc7110ab /cli/src/cli-cmd-volume.c
parent0c4f174ab2ab5450a32ef09c791f131931cbb8a4 (diff)
cli: Perform mount from CLI on demand
The CLI now performs a mount everytime any one of the following quota commands are issued: a. enable b. limit-usage c. list d. remove The pidfile of the auxiliary mount process will be placed under DEFAULT_VAR_RUN_DIRECTORY and will be named <volname>.pid Change-Id: I09709ea5c0c59871c33544dee7e691f6cd0ecef3 Signed-off-by: Krutika Dhananjay <kdhananj@redhat.com>
Diffstat (limited to 'cli/src/cli-cmd-volume.c')
-rw-r--r--cli/src/cli-cmd-volume.c100
1 files changed, 97 insertions, 3 deletions
diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c
index 2fd74554..0657eee4 100644
--- a/cli/src/cli-cmd-volume.c
+++ b/cli/src/cli-cmd-volume.c
@@ -1007,6 +1007,82 @@ out:
return ret;
}
+static int
+gf_cli_create_auxiliary_mount (char *volname)
+{
+ int ret = -1;
+ char mountdir[PATH_MAX] = {0,};
+ char pidfile_path[PATH_MAX] = {0,};
+ char logfile[PATH_MAX] = {0,};
+
+ GLUSTERFS_GET_AUX_MOUNT_PIDFILE (pidfile_path, volname);
+
+ if (gf_is_service_running (pidfile_path, NULL)) {
+ gf_log ("cli", GF_LOG_DEBUG, "Aux mount of volume %s is running"
+ " already", volname);
+ ret = 0;
+ goto out;
+ }
+
+ snprintf (mountdir, sizeof (mountdir)-1, "/tmp/%s", volname);
+ ret = mkdir (mountdir, 0777);
+ if (ret && errno != EEXIST) {
+ gf_log ("cli", GF_LOG_ERROR, "Failed to create auxiliary mount "
+ "directory %s. Reason : %s", mountdir,
+ strerror (errno));
+ goto out;
+ }
+
+ snprintf (logfile, PATH_MAX-1, "%s/quota-mount-%s.log",
+ DEFAULT_LOG_FILE_DIRECTORY, volname);
+
+ ret = runcmd (SBIN_DIR"/glusterfs",
+ "-s", "localhost",
+ "--volfile-id", volname,
+ "-l", logfile,
+ "-p", pidfile_path,
+ mountdir,
+ "--client-pid", "-42", NULL);
+
+ if (ret) {
+ gf_log ("cli", GF_LOG_WARNING, "failed to mount glusterfs "
+ "client. Please check the log file %s for more details",
+ logfile);
+ ret = -1;
+ goto out;
+ }
+
+ ret = 0;
+
+out:
+ return ret;
+}
+
+static int
+cli_stage_quota_op (char *volname, int op_code)
+{
+ int ret = -1;
+
+ switch (op_code) {
+ case GF_QUOTA_OPTION_TYPE_ENABLE:
+ case GF_QUOTA_OPTION_TYPE_LIMIT_USAGE:
+ case GF_QUOTA_OPTION_TYPE_REMOVE:
+ case GF_QUOTA_OPTION_TYPE_LIST:
+ ret = gf_cli_create_auxiliary_mount (volname);
+ if (ret)
+ goto out;
+ ret = 0;
+ break;
+
+ default:
+ ret = 0;
+ break;
+ }
+
+out:
+ return ret;
+}
+
int
cli_cmd_quota_cbk (struct cli_state *state, struct cli_cmd_word *word,
const char **words, int wordcount)
@@ -1021,6 +1097,7 @@ cli_cmd_quota_cbk (struct cli_state *state, struct cli_cmd_word *word,
gf_answer_t answer = GF_ANSWER_NO;
cli_local_t *local = NULL;
int sent = 0;
+ char *volname = NULL;
const char *question = "Disabling quota will delete all the quota "
"configuration. Do you want to continue?";
@@ -1042,13 +1119,29 @@ cli_cmd_quota_cbk (struct cli_state *state, struct cli_cmd_word *word,
cli_usage_out (word->pattern);
parse_err = 1;
goto out;
- } else if (dict_get_int32 (options, "type", &type) == 0 &&
- type == GF_QUOTA_OPTION_TYPE_DISABLE) {
+ }
+
+ ret = dict_get_int32 (options, "type", &type);
+ if (ret) {
+ gf_log ("cli", GF_LOG_ERROR, "Failed to get opcode");
+ goto out;
+ }
+ if (type == GF_QUOTA_OPTION_TYPE_DISABLE) {
answer = cli_cmd_get_confirmation (state, question);
if (answer == GF_ANSWER_NO)
goto out;
}
+ ret = dict_get_str (options, "volname", &volname);
+ if (ret) {
+ gf_log ("cli", GF_LOG_ERROR, "Failed to get volume name");
+ goto out;
+ }
+
+ ret = cli_stage_quota_op (volname, type);
+ if (ret)
+ goto out;
+
CLI_LOCAL_INIT (local, words, frame, options);
if (proc->fn)
@@ -1058,7 +1151,8 @@ out:
if (ret) {
cli_cmd_sent_status_get (&sent);
if (sent == 0 && parse_err == 0)
- cli_out ("Quota command failed");
+ cli_out ("Quota command failed. Please check the cli "
+ "logs for more details");
}
CLI_STACK_DESTROY (frame);