diff options
author | Krutika Dhananjay <kdhananj@redhat.com> | 2013-08-11 15:51:15 +0530 |
---|---|---|
committer | Krutika Dhananjay <kdhananj@redhat.com> | 2013-08-12 16:28:28 +0530 |
commit | 8a681105436f953062d69d2c1dcf559d9dcd7984 (patch) | |
tree | 4eabe24f306787c0e330701b91664dffdc7110ab | |
parent | 0c4f174ab2ab5450a32ef09c791f131931cbb8a4 (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>
-rw-r--r-- | cli/src/cli-cmd-volume.c | 100 | ||||
-rw-r--r-- | cli/src/cli-rpc-ops.c | 66 | ||||
-rw-r--r-- | cli/src/cli.h | 7 |
3 files changed, 105 insertions, 68 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); diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c index 514c3cbc..f2749b48 100644 --- a/cli/src/cli-rpc-ops.c +++ b/cli/src/cli-rpc-ops.c @@ -2454,60 +2454,6 @@ out: return ret; } -static int -gf_cli_create_auxiliary_mount (char *volname) -{ - int ret = -1; - char mountdir[PATH_MAX] = {0,}; - - snprintf (mountdir, sizeof (mountdir)-1, "/tmp/%s", volname); - ret = mkdir (mountdir, 0777); - if (ret && errno != EEXIST) - goto out; - - ret = runcmd (SBIN_DIR"/glusterfs", "-s", - "localhost", "--volfile-id", volname, "-l", - DEFAULT_LOG_FILE_DIRECTORY"/quota-enable.log", - mountdir, "--client-pid", "-42", NULL); - if (ret) { - gf_log ("cli", GF_LOG_WARNING, "failed to mount glusterfs " - "client"); - ret = -1; - goto out; - } - ret = 0; - -out: - return ret; -} - -static int -gf_cli_remove_auxiliary_mount (char *volname) -{ - int ret = -1; - runner_t runner = {0,}; - char mountdir [PATH_MAX] = {0,}; - - snprintf (mountdir, sizeof (mountdir)-1, "/tmp/%s", volname); - - runinit (&runner); - runner_add_args (&runner, "umount", - -#if GF_LINUX_HOST_OS - "-l", -#endif - mountdir, NULL); - ret = runner_run_reuse (&runner); - if (ret) - gf_log ("cli", GF_LOG_WARNING, "umount on %s failed, " - "reason : %s", mountdir, strerror (errno)); - runner_end (&runner); - - rmdir (mountdir); - return ret; - -} - void gf_cli_quota_list (char *volname, dict_t *dict, int count, char *op_errstr, char *default_sl) @@ -2595,17 +2541,7 @@ gf_cli_quota_cbk (struct rpc_req *req, struct iovec *iov, if (ret) gf_log (frame->this->name, GF_LOG_TRACE, "failed to get count"); - if (type == GF_QUOTA_OPTION_TYPE_ENABLE) { - ret = gf_cli_create_auxiliary_mount (volname); - if (ret) - goto out; - - } else if (type == GF_QUOTA_OPTION_TYPE_DISABLE) { - ret = gf_cli_remove_auxiliary_mount (volname); - if (ret) - goto out; - - } else if (type == GF_QUOTA_OPTION_TYPE_LIST) { + if (type == GF_QUOTA_OPTION_TYPE_LIST) { if (global_state->mode & GLUSTER_MODE_XML) { ret = cli_xml_output_vol_quota_limit_list (volname, limit_list, rsp.op_ret, diff --git a/cli/src/cli.h b/cli/src/cli.h index 259f3bd3..83651dba 100644 --- a/cli/src/cli.h +++ b/cli/src/cli.h @@ -59,6 +59,13 @@ enum argp_option_keys { #define GLUSTER_MODE_SCRIPT (1 << 0) #define GLUSTER_MODE_ERR_FATAL (1 << 1) #define GLUSTER_MODE_XML (1 << 2) + + +#define GLUSTERFS_GET_AUX_MOUNT_PIDFILE(pidfile,volname) { \ + snprintf (pidfile, PATH_MAX-1, \ + DEFAULT_VAR_RUN_DIRECTORY"/%s.pid", volname); \ + } + struct cli_state; struct cli_cmd_word; struct cli_cmd_tree; |