cli: Changes for GET_NEXT volume info

Signed-off-by: Vijay Bellur <vijay@gluster.com>
Signed-off-by: Vijay Bellur <vijay@dev.gluster.com>

BUG: 1255 ()
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1255
This commit is contained in:
Vijay Bellur 2010-09-02 04:03:12 +00:00 committed by Vijay Bellur
parent 232d32ca93
commit ea86a09143
8 changed files with 121 additions and 14 deletions

View File

@ -69,9 +69,11 @@ int
cli_cmd_volume_info_cbk (struct cli_state *state, struct cli_cmd_word *word,
const char **words, int wordcount)
{
int ret = -1;
rpc_clnt_procedure_t *proc = NULL;
call_frame_t *frame = NULL;
int ret = -1;
rpc_clnt_procedure_t *proc = NULL;
call_frame_t *frame = NULL;
cli_cmd_volume_get_ctx_t ctx = {0,};
cli_local_t *local = NULL;
proc = &cli_rpc_prog->proctable[GF1_CLI_GET_VOLUME];
@ -79,8 +81,23 @@ cli_cmd_volume_info_cbk (struct cli_state *state, struct cli_cmd_word *word,
if (!frame)
goto out;
if ((wordcount == 2) || (wordcount == 3 &&
!strcmp (words[2], "all"))) {
ctx.flags = GF_CLI_GET_NEXT_VOLUME;
proc = &cli_rpc_prog->proctable[GF1_CLI_GET_NEXT_VOLUME];
}
local = cli_local_get ();
if (!local)
goto out;
local->u.get_vol.flags = ctx.flags;
frame->local = local;
if (proc->fn) {
ret = proc->fn (frame, THIS, NULL);
ret = proc->fn (frame, THIS, &ctx);
}
out:
@ -131,7 +148,7 @@ out:
}
}
if (options)
dict_destroy (options);
dict_unref (options);
return ret;
}

View File

@ -33,6 +33,13 @@ struct cli_cmd {
const char *desc;
};
struct cli_cmd_volume_get_ctx_ {
char *volname;
int flags;
};
typedef struct cli_cmd_volume_get_ctx_ cli_cmd_volume_get_ctx_t;
int cli_cmd_volume_register (struct cli_state *state);
int cli_cmd_probe_register (struct cli_state *state);

View File

@ -31,6 +31,7 @@ enum cli_mem_types_ {
cli_mt_char,
cli_mt_call_pool_t,
cli_mt_cli_local_t,
cli_mt_cli_get_vol_ctx_t,
cli_mt_end
};

View File

@ -126,6 +126,11 @@ struct cli_local {
char *volname;
dict_t *dict;
} replace_brick;
struct {
char *volname;
int flags;
} get_vol;
} u;
};

View File

@ -48,6 +48,10 @@ char *cli_volume_status[] = {"Created",
"Stopped"
};
int32_t
gf_cli3_1_get_volume (call_frame_t *frame, xlator_t *this,
void *data);
int
gf_cli3_1_probe_cbk (struct rpc_req *req, struct iovec *iov,
int count, void *myframe)
@ -252,6 +256,8 @@ gf_cli3_1_get_volume_cbk (struct rpc_req *req, struct iovec *iov,
int32_t brick_count = 0;
char *brick = NULL;
int32_t j = 1;
cli_local_t *local = NULL;
if (-1 == req->rpc_status) {
goto out;
@ -300,7 +306,14 @@ gf_cli3_1_get_volume_cbk (struct rpc_req *req, struct iovec *iov,
goto out;
}
cli_out ("Number of Volumes: %d", count);
local = ((call_frame_t *)myframe)->local;
//cli_out ("Number of Volumes: %d", count);
if (!count) {
local->u.get_vol.volname = NULL;
ret = 0;
goto out;
}
while ( i <= count) {
cli_out ("");
@ -324,12 +337,17 @@ gf_cli3_1_get_volume_cbk (struct rpc_req *req, struct iovec *iov,
if (ret)
goto out;
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;
GF_FREE (local->u.get_vol.volname);
local->u.get_vol.volname = gf_strdup (volname);
if (brick_count)
cli_out ("Bricks:");
@ -344,6 +362,8 @@ gf_cli3_1_get_volume_cbk (struct rpc_req *req, struct iovec *iov,
}
i++;
}
} else {
ret = -1;
goto out;
@ -1052,18 +1072,68 @@ out:
}
int32_t
gf_cli3_1_get_volume (call_frame_t *frame, xlator_t *this,
void *data)
gf_cli3_1_get_next_volume (call_frame_t *frame, xlator_t *this,
void *data)
{
gf1_cli_get_vol_req req = {0,};
int ret = 0;
if (!frame || !this) {
int ret = 0;
cli_cmd_volume_get_ctx_t *ctx = NULL;
cli_local_t *local = NULL;
if (!frame || !this || !data) {
ret = -1;
goto out;
}
req.flags = GF_CLI_GET_VOLUME_ALL;
ctx = data;
ret = gf_cli3_1_get_volume (frame, this, data);
local = frame->local;
ctx->volname = local->u.get_vol.volname;
while (ctx->volname) {
ret = gf_cli3_1_get_volume (frame, this, ctx);
if (ret)
goto out;
ctx->volname = local->u.get_vol.volname;
}
out:
return ret;
}
int32_t
gf_cli3_1_get_volume (call_frame_t *frame, xlator_t *this,
void *data)
{
gf1_cli_get_vol_req req = {0,};
int ret = 0;
cli_cmd_volume_get_ctx_t *ctx = NULL;
dict_t *dict = NULL;
if (!frame || !this || !data) {
ret = -1;
goto out;
}
ctx = data;
req.flags = ctx->flags;
dict = dict_new ();
if (!dict)
goto out;
if (ctx->volname) {
ret = dict_set_str (dict, "volname", ctx->volname);
if (ret)
goto out;
}
ret = dict_allocate_and_serialize (dict,
&req.dict.dict_val,
(size_t *)&req.dict.dict_len);
ret = cli_cmd_submit (&req, frame, cli_rpc_prog,
GD_MGMT_CLI_GET_VOLUME, NULL,
@ -1075,6 +1145,7 @@ out:
return ret;
}
int32_t
gf_cli3_1_create_volume (call_frame_t *frame, xlator_t *this,
void *data)
@ -1117,7 +1188,7 @@ gf_cli3_1_create_volume (call_frame_t *frame, xlator_t *this,
local = cli_local_get ();
if (local) {
local->u.create_vol.dict = dict;
local->u.create_vol.dict = dict_ref (dict);
frame->local = local;
}
@ -1691,6 +1762,7 @@ struct rpc_clnt_procedure gluster3_1_cli_actors[GF1_CLI_MAXVALUE] = {
[GF1_CLI_RENAME_VOLUME] = {"RENAME_VOLUME", gf_cli3_1_rename_volume},
[GF1_CLI_DEFRAG_VOLUME] = {"DEFRAG_VOLUME", gf_cli3_1_defrag_volume},
[GF1_CLI_GET_VOLUME] = {"GET_VOLUME", gf_cli3_1_get_volume},
[GF1_CLI_GET_NEXT_VOLUME] = {"GET_NEXT_VOLUME", gf_cli3_1_get_next_volume},
[GF1_CLI_SET_VOLUME] = {"SET_VOLUME", gf_cli3_1_set_volume},
[GF1_CLI_ADD_BRICK] = {"ADD_BRICK", gf_cli3_1_add_brick},
[GF1_CLI_REMOVE_BRICK] = {"REMOVE_BRICK", gf_cli3_1_remove_brick},

View File

@ -114,6 +114,7 @@ enum gf_cli_procnum {
GF1_CLI_LIST_FRIENDS,
GF1_CLI_CREATE_VOLUME,
GF1_CLI_GET_VOLUME,
GF1_CLI_GET_NEXT_VOLUME,
GF1_CLI_DELETE_VOLUME,
GF1_CLI_START_VOLUME,
GF1_CLI_STOP_VOLUME,

View File

@ -58,6 +58,8 @@ typedef enum gf1_cli_friends_list gf1_cli_friends_list;
enum gf1_cli_get_volume {
GF_CLI_GET_VOLUME_ALL = 1,
GF_CLI_GET_VOLUME = 1 + 1,
GF_CLI_GET_NEXT_VOLUME = 1 + 2,
};
typedef enum gf1_cli_get_volume gf1_cli_get_volume;

View File

@ -18,7 +18,9 @@ enum gf1_cli_friends_list {
} ;
enum gf1_cli_get_volume {
GF_CLI_GET_VOLUME_ALL = 1
GF_CLI_GET_VOLUME_ALL = 1,
GF_CLI_GET_VOLUME,
GF_CLI_GET_NEXT_VOLUME
} ;
enum gf1_cli_op_flags {