summaryrefslogtreecommitdiffstats
path: root/cli
diff options
context:
space:
mode:
authorVijay Bellur <vijay@gluster.com>2010-07-27 14:49:07 +0000
committerAnand V. Avati <avati@dev.gluster.com>2010-07-27 19:39:40 -0700
commit9460675a921d504a31088b0e0f42143cc7f2a56f (patch)
tree30e00eeb0f42da671d778df73a014483ae931ea7 /cli
parent26cc6b015bb29f942194d1ca2a3dd21d5483d829 (diff)
DVM: Changes in CLI output
Signed-off-by: Vijay Bellur <vijay@gluster.com> Signed-off-by: Anand V. Avati <avati@dev.gluster.com> BUG: 1220 () URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1220
Diffstat (limited to 'cli')
-rw-r--r--cli/src/cli-cmd.c65
-rw-r--r--cli/src/cli-cmd.h13
-rw-r--r--cli/src/cli.c5
-rw-r--r--cli/src/cli3_1-cops.c182
4 files changed, 162 insertions, 103 deletions
diff --git a/cli/src/cli-cmd.c b/cli/src/cli-cmd.c
index c88d3fe8505..ee30ea996e6 100644
--- a/cli/src/cli-cmd.c
+++ b/cli/src/cli-cmd.c
@@ -175,23 +175,41 @@ out:
}
int
-cli_cmd_await_response ()
+cli_cmd_cond_init ()
{
+
pthread_mutex_init (&cond_mutex, NULL);
pthread_cond_init (&cond, NULL);
- cmd_done = 0;
+ pthread_mutex_init (&conn_mutex, NULL);
+ pthread_cond_init (&conn, NULL);
+
+ return 0;
+}
+
+int
+cli_cmd_lock ()
+{
pthread_mutex_lock (&cond_mutex);
- {
- cli_op_ret = 0;
- while (!cmd_done) {
- pthread_cond_wait (&cond, &cond_mutex);
- }
- }
+ return 0;
+}
+
+int
+cli_cmd_unlock ()
+{
pthread_mutex_unlock (&cond_mutex);
+ return 0;
+}
+
+int
+cli_cmd_await_response ()
+{
- pthread_mutex_destroy (&cond_mutex);
- pthread_cond_destroy (&cond);
+ cmd_done = 0;
+ while (!cmd_done)
+ pthread_cond_wait (&cond, &cond_mutex);
+
+ cli_cmd_unlock ();
return cli_op_ret;
}
@@ -214,8 +232,6 @@ cli_cmd_broadcast_response (int32_t status)
int32_t
cli_cmd_await_connected ()
{
- pthread_mutex_init (&conn_mutex, NULL);
- pthread_cond_init (&conn, NULL);
pthread_mutex_lock (&conn_mutex);
{
@@ -225,8 +241,6 @@ cli_cmd_await_connected ()
}
pthread_mutex_unlock (&conn_mutex);
- pthread_mutex_destroy (&conn_mutex);
- pthread_cond_destroy (&conn);
return 0;
}
@@ -245,3 +259,26 @@ cli_cmd_broadcast_connected ()
return 0;
}
+
+int
+cli_cmd_submit (void *req, call_frame_t *frame,
+ rpc_clnt_prog_t *prog,
+ int procnum, struct iobref *iobref,
+ cli_serialize_t sfunc, xlator_t *this,
+ fop_cbk_fn_t cbkfn)
+{
+ int ret = -1;
+
+ cli_cmd_lock ();
+ ret = cli_submit_request (req, frame, prog,
+ procnum, NULL, sfunc,
+ this, cbkfn);
+
+ if (!ret)
+ ret = cli_cmd_await_response ();
+ else
+ cli_cmd_unlock ();
+
+ gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret);
+ return ret;
+}
diff --git a/cli/src/cli-cmd.h b/cli/src/cli-cmd.h
index b08f5b3d5f2..87a9d3d892e 100644
--- a/cli/src/cli-cmd.h
+++ b/cli/src/cli-cmd.h
@@ -45,4 +45,17 @@ void cli_cmd_tokens_destroy (char **tokens);
int cli_cmd_await_response ();
int cli_cmd_broadcast_response (int32_t status);
+
+int cli_cmd_cond_init ();
+
+int cli_cmd_lock ();
+
+int cli_cmd_unlock ();
+
+int
+cli_cmd_submit (void *req, call_frame_t *frame,
+ rpc_clnt_prog_t *prog,
+ int procnum, struct iobref *iobref,
+ cli_serialize_t sfunc, xlator_t *this,
+ fop_cbk_fn_t cbkfn);
#endif /* __CLI_CMD_H__ */
diff --git a/cli/src/cli.c b/cli/src/cli.c
index 5f734d8e8f2..59782b42db2 100644
--- a/cli/src/cli.c
+++ b/cli/src/cli.c
@@ -218,7 +218,7 @@ glusterfs_ctx_defaults_init (glusterfs_ctx_t *ctx)
/* parsing command line arguments */
cmd_args->log_file = "/dev/stderr";
- cmd_args->log_level = GF_LOG_NORMAL;
+ cmd_args->log_level = GF_LOG_NONE;
INIT_LIST_HEAD (&cmd_args->xlator_options);
@@ -524,6 +524,9 @@ main (int argc, char *argv[])
if (ret)
goto out;
+ ret = cli_cmd_cond_init ();
+ if (ret)
+ goto out;
ret = event_dispatch (ctx->event_pool);
diff --git a/cli/src/cli3_1-cops.c b/cli/src/cli3_1-cops.c
index 8e6c76ae688..4275adec88e 100644
--- a/cli/src/cli3_1-cops.c
+++ b/cli/src/cli3_1-cops.c
@@ -35,6 +35,17 @@
extern rpc_clnt_prog_t *cli_rpc_prog;
extern int cli_op_ret;
+char *cli_volume_type[] = {"None",
+ "Stripe",
+ "Replicate"
+};
+
+
+char *cli_volume_status[] = {"Created",
+ "Started",
+ "Stopped"
+};
+
int
gf_cli3_1_probe_cbk (struct rpc_req *req, struct iovec *iov,
int count, void *myframe)
@@ -215,6 +226,8 @@ gf_cli3_1_get_volume_cbk (struct rpc_req *req, struct iovec *iov,
int32_t status = 0;
int32_t type = 0;
int32_t brick_count = 0;
+ char *brick = NULL;
+ int32_t j = 1;
if (-1 == req->rpc_status) {
goto out;
@@ -266,6 +279,7 @@ gf_cli3_1_get_volume_cbk (struct rpc_req *req, struct iovec *iov,
cli_out ("Number of Volumes: %d", count);
while ( i <= count) {
+ cli_out ("");
snprintf (key, 256, "volume%d.name", i);
ret = dict_get_str (dict, key, &volname);
if (ret)
@@ -286,9 +300,24 @@ gf_cli3_1_get_volume_cbk (struct rpc_req *req, struct iovec *iov,
if (ret)
goto out;
- cli_out ("Volume Name:%s, type:%d, status:%d,"
- "brick_count: %d",
- volname, type, status, brick_count);
+ cli_out ("Volume Name: %s", volname);
+ cli_out ("Type: %s", cli_volume_type[type]);
+ cli_out ("Status: %s", cli_volume_status[status], brick_count);
+ cli_out ("Number of Bricks: %d", brick_count);
+ j = 1;
+
+ if (brick_count)
+ cli_out ("Bricks:");
+
+ while ( j <= brick_count) {
+ snprintf (key, 1024, "volume%d.brick%d",
+ i, j);
+ ret = dict_get_str (dict, key, &brick);
+ if (ret)
+ goto out;
+ cli_out ("Brick%d: %s", j, brick);
+ j++;
+ }
i++;
}
} else {
@@ -307,8 +336,10 @@ out:
if (dict)
dict_destroy (dict);
+ gf_log ("", GF_LOG_NORMAL, "Returning: %d", ret);
return ret;
}
+
int
gf_cli3_1_create_volume_cbk (struct rpc_req *req, struct iovec *iov,
int count, void *myframe)
@@ -527,6 +558,7 @@ gf_cli3_1_rename_volume_cbk (struct rpc_req *req, struct iovec *iov,
ret = rsp.op_ret;
out:
+ cli_cmd_broadcast_response (ret);
return ret;
}
@@ -555,6 +587,7 @@ gf_cli3_1_set_volume_cbk (struct rpc_req *req, struct iovec *iov,
ret = rsp.op_ret;
out:
+ cli_cmd_broadcast_response (ret);
return ret;
}
@@ -612,6 +645,7 @@ gf_cli3_1_remove_brick_cbk (struct rpc_req *req, struct iovec *iov,
ret = rsp.op_ret;
out:
+ cli_cmd_broadcast_response (ret);
return ret;
}
@@ -641,6 +675,7 @@ gf_cli3_1_replace_brick_cbk (struct rpc_req *req, struct iovec *iov,
ret = rsp.op_ret;
out:
+ cli_cmd_broadcast_response (ret);
return ret;
}
@@ -671,13 +706,10 @@ gf_cli3_1_probe (call_frame_t *frame, xlator_t *this,
req.hostname = hostname;
req.port = port;
- ret = cli_submit_request (&req, frame, cli_rpc_prog,
- GD_MGMT_CLI_PROBE, NULL, gf_xdr_from_cli_probe_req,
- this, gf_cli3_1_probe_cbk);
+ ret = cli_cmd_submit (&req, frame, cli_rpc_prog,
+ GD_MGMT_CLI_PROBE, NULL, gf_xdr_from_cli_probe_req,
+ this, gf_cli3_1_probe_cbk);
- if (!ret) {
- ret = cli_cmd_await_response ();
- }
out:
gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret);
return ret;
@@ -710,14 +742,11 @@ gf_cli3_1_deprobe (call_frame_t *frame, xlator_t *this,
req.hostname = hostname;
req.port = port;
- ret = cli_submit_request (&req, frame, cli_rpc_prog,
- GD_MGMT_CLI_DEPROBE, NULL,
- gf_xdr_from_cli_deprobe_req,
- this, gf_cli3_1_deprobe_cbk);
+ ret = cli_cmd_submit (&req, frame, cli_rpc_prog,
+ GD_MGMT_CLI_DEPROBE, NULL,
+ gf_xdr_from_cli_deprobe_req,
+ this, gf_cli3_1_deprobe_cbk);
- if (!ret) {
- ret = cli_cmd_await_response ();
- }
out:
gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret);
return ret;
@@ -737,14 +766,11 @@ gf_cli3_1_list_friends (call_frame_t *frame, xlator_t *this,
req.flags = GF_CLI_LIST_ALL;
- ret = cli_submit_request (&req, frame, cli_rpc_prog,
- GD_MGMT_CLI_LIST_FRIENDS, NULL,
- gf_xdr_from_cli_peer_list_req,
- this, gf_cli3_1_list_friends_cbk);
+ ret = cli_cmd_submit (&req, frame, cli_rpc_prog,
+ GD_MGMT_CLI_LIST_FRIENDS, NULL,
+ gf_xdr_from_cli_peer_list_req,
+ this, gf_cli3_1_list_friends_cbk);
- if (!ret) {
- ret = cli_cmd_await_response ();
- }
out:
gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret);
return ret;
@@ -764,14 +790,11 @@ gf_cli3_1_get_volume (call_frame_t *frame, xlator_t *this,
req.flags = GF_CLI_GET_VOLUME_ALL;
- ret = cli_submit_request (&req, frame, cli_rpc_prog,
- GD_MGMT_CLI_GET_VOLUME, NULL,
- gf_xdr_from_cli_get_vol_req,
- this, gf_cli3_1_get_volume_cbk);
+ ret = cli_cmd_submit (&req, frame, cli_rpc_prog,
+ GD_MGMT_CLI_GET_VOLUME, NULL,
+ gf_xdr_from_cli_get_vol_req,
+ this, gf_cli3_1_get_volume_cbk);
- if (!ret) {
- ret = cli_cmd_await_response ();
- }
out:
gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret);
return ret;
@@ -823,14 +846,11 @@ gf_cli3_1_create_volume (call_frame_t *frame, xlator_t *this,
frame->local = local;
}
- ret = cli_submit_request (&req, frame, cli_rpc_prog,
- GD_MGMT_CLI_CREATE_VOLUME, NULL,
- gf_xdr_from_cli_create_vol_req,
- this, gf_cli3_1_create_volume_cbk);
+ ret = cli_cmd_submit (&req, frame, cli_rpc_prog,
+ GD_MGMT_CLI_CREATE_VOLUME, NULL,
+ gf_xdr_from_cli_create_vol_req,
+ this, gf_cli3_1_create_volume_cbk);
- if (!ret) {
- ret = cli_cmd_await_response ();
- }
out:
@@ -865,13 +885,10 @@ gf_cli3_1_delete_volume (call_frame_t *frame, xlator_t *this,
req.volname = data;
- ret = cli_submit_request (&req, frame, cli_rpc_prog,
- GD_MGMT_CLI_DELETE_VOLUME, NULL,
- gf_xdr_from_cli_delete_vol_req,
- this, gf_cli3_1_delete_volume_cbk);
- if (!ret) {
- ret = cli_cmd_await_response ();
- }
+ ret = cli_cmd_submit (&req, frame, cli_rpc_prog,
+ GD_MGMT_CLI_DELETE_VOLUME, NULL,
+ gf_xdr_from_cli_delete_vol_req,
+ this, gf_cli3_1_delete_volume_cbk);
out:
gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret);
@@ -901,14 +918,11 @@ gf_cli3_1_start_volume (call_frame_t *frame, xlator_t *this,
req.volname = data;
- ret = cli_submit_request (&req, frame, cli_rpc_prog,
- GD_MGMT_CLI_START_VOLUME, NULL,
- gf_xdr_from_cli_start_vol_req,
- this, gf_cli3_1_start_volume_cbk);
+ ret = cli_cmd_submit (&req, frame, cli_rpc_prog,
+ GD_MGMT_CLI_START_VOLUME, NULL,
+ gf_xdr_from_cli_start_vol_req,
+ this, gf_cli3_1_start_volume_cbk);
- if (!ret) {
- ret = cli_cmd_await_response ();
- }
out:
gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret);
@@ -937,14 +951,11 @@ gf_cli3_1_stop_volume (call_frame_t *frame, xlator_t *this,
frame->local = local;
}
- ret = cli_submit_request (&req, frame, cli_rpc_prog,
- GD_MGMT_CLI_STOP_VOLUME, NULL,
- gf_xdr_from_cli_stop_vol_req,
- this, gf_cli3_1_stop_volume_cbk);
+ ret = cli_cmd_submit (&req, frame, cli_rpc_prog,
+ GD_MGMT_CLI_STOP_VOLUME, NULL,
+ gf_xdr_from_cli_stop_vol_req,
+ this, gf_cli3_1_stop_volume_cbk);
- if (!ret) {
- ret = cli_cmd_await_response ();
- }
out:
gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret);
@@ -973,14 +984,11 @@ gf_cli3_1_defrag_volume (call_frame_t *frame, xlator_t *this,
req.volname = data;
- ret = cli_submit_request (&req, frame, cli_rpc_prog,
- GD_MGMT_CLI_DEFRAG_VOLUME, NULL,
- gf_xdr_from_cli_defrag_vol_req,
- this, gf_cli3_1_defrag_volume_cbk);
+ ret = cli_cmd_submit (&req, frame, cli_rpc_prog,
+ GD_MGMT_CLI_DEFRAG_VOLUME, NULL,
+ gf_xdr_from_cli_defrag_vol_req,
+ this, gf_cli3_1_defrag_volume_cbk);
- if (!ret) {
- ret = cli_cmd_await_response ();
- }
out:
gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret);
@@ -1012,10 +1020,10 @@ gf_cli3_1_rename_volume (call_frame_t *frame, xlator_t *this,
if (ret)
goto out;
- ret = cli_submit_request (&req, frame, cli_rpc_prog,
- GD_MGMT_CLI_RENAME_VOLUME, NULL,
- gf_xdr_from_cli_rename_vol_req,
- this, gf_cli3_1_rename_volume_cbk);
+ ret = cli_cmd_submit (&req, frame, cli_rpc_prog,
+ GD_MGMT_CLI_RENAME_VOLUME, NULL,
+ gf_xdr_from_cli_rename_vol_req,
+ this, gf_cli3_1_rename_volume_cbk);
out:
gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret);
@@ -1053,10 +1061,10 @@ gf_cli3_1_set_volume (call_frame_t *frame, xlator_t *this,
}
- ret = cli_submit_request (&req, frame, cli_rpc_prog,
- GD_MGMT_CLI_SET_VOLUME, NULL,
- gf_xdr_from_cli_set_vol_req,
- this, gf_cli3_1_set_volume_cbk);
+ ret = cli_cmd_submit (&req, frame, cli_rpc_prog,
+ GD_MGMT_CLI_SET_VOLUME, NULL,
+ gf_xdr_from_cli_set_vol_req,
+ this, gf_cli3_1_set_volume_cbk);
out:
gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret);
@@ -1098,14 +1106,11 @@ gf_cli3_1_add_brick (call_frame_t *frame, xlator_t *this,
goto out;
}
- ret = cli_submit_request (&req, frame, cli_rpc_prog,
- GD_MGMT_CLI_ADD_BRICK, NULL,
- gf_xdr_from_cli_add_brick_req,
- this, gf_cli3_1_add_brick_cbk);
+ ret = cli_cmd_submit (&req, frame, cli_rpc_prog,
+ GD_MGMT_CLI_ADD_BRICK, NULL,
+ gf_xdr_from_cli_add_brick_req,
+ this, gf_cli3_1_add_brick_cbk);
- if (!ret) {
- ret = cli_cmd_await_response ();
- }
out:
gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret);
@@ -1155,10 +1160,11 @@ gf_cli3_1_remove_brick (call_frame_t *frame, xlator_t *this,
goto out;
}
- ret = cli_submit_request (&req, frame, cli_rpc_prog,
- GD_MGMT_CLI_REMOVE_BRICK, NULL,
- gf_xdr_from_cli_remove_brick_req,
- this, gf_cli3_1_remove_brick_cbk);
+ ret = cli_cmd_submit (&req, frame, cli_rpc_prog,
+ GD_MGMT_CLI_REMOVE_BRICK, NULL,
+ gf_xdr_from_cli_remove_brick_req,
+ this, gf_cli3_1_remove_brick_cbk);
+
out:
gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret);
@@ -1198,10 +1204,10 @@ gf_cli3_1_replace_brick (call_frame_t *frame, xlator_t *this,
if (GF_REPLACE_OP_START == req.op) {
}
- ret = cli_submit_request (&req, frame, cli_rpc_prog,
- GD_MGMT_CLI_REPLACE_BRICK, NULL,
- gf_xdr_from_cli_replace_brick_req,
- this, gf_cli3_1_replace_brick_cbk);
+ ret = cli_cmd_submit (&req, frame, cli_rpc_prog,
+ GD_MGMT_CLI_REPLACE_BRICK, NULL,
+ gf_xdr_from_cli_replace_brick_req,
+ this, gf_cli3_1_replace_brick_cbk);
out:
gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret);