diff options
| author | Csaba Henk <csaba@gluster.com> | 2010-09-15 08:11:19 +0000 | 
|---|---|---|
| committer | Vijay Bellur <vijay@dev.gluster.com> | 2010-09-16 23:07:48 -0700 | 
| commit | e690af8375f55bf8d8e56a0334cc9bd88867326e (patch) | |
| tree | 31aa2110700f89c4620aee00b746317b3f26316b | |
| parent | 202761d052d2faa2c92b23c5afc32c27853b11ad (diff) | |
cli: added system:: getspec
Signed-off-by: Csaba Henk <csaba@gluster.com>
Signed-off-by: Vijay Bellur <vijay@dev.gluster.com>
BUG: 1570 (geosync related changes)
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1570
| -rw-r--r-- | cli/src/cli-cmd-system.c | 49 | ||||
| -rw-r--r-- | cli/src/cli3_1-cops.c | 77 | ||||
| -rw-r--r-- | rpc/rpc-lib/src/protocol-common.h | 1 | 
3 files changed, 127 insertions, 0 deletions
diff --git a/cli/src/cli-cmd-system.c b/cli/src/cli-cmd-system.c index ec53b9848fb..86e2c167b57 100644 --- a/cli/src/cli-cmd-system.c +++ b/cli/src/cli-cmd-system.c @@ -33,6 +33,8 @@  #include "cli-mem-types.h"  #include "protocol-common.h" +#define GETSPEC_SYNTAX "system:: getspec <VOLID>" +  extern struct rpc_clnt *global_rpc;  extern rpc_clnt_prog_t *cli_rpc_prog; @@ -40,7 +42,54 @@ extern rpc_clnt_prog_t *cli_rpc_prog;  int cli_cmd_system_help_cbk (struct cli_state *state, struct cli_cmd_word *in_word,                               const char **words, int wordcount); +int +cli_cmd_getspec_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; +        dict_t                  *dict = NULL; + +        frame = create_frame (THIS, THIS->ctx->pool); +        if (!frame) +                goto out; + +        dict = dict_new (); +        if (!dict) +                goto out; + +        if (wordcount != 3) { +                cli_out ("Usage: " GETSPEC_SYNTAX); +                goto out; +        } + +        ret = dict_set_str (dict, "volid", (char *)words[2]); +        if (ret) +                goto out; + +        proc = &cli_rpc_prog->proctable[GF1_CLI_GETSPEC]; +        if (proc->fn) { +                ret = proc->fn (frame, THIS, dict); +        } + +out: +        if (!proc && ret) { +                if (dict) +                        dict_destroy (dict); +                if (wordcount > 1) +                        cli_out ("Fetching spec for volume %s failed", +                                 (char *)words[2]); +        } + +        return ret; +} +  struct cli_cmd cli_system_cmds[] = { +        { GETSPEC_SYNTAX, +          cli_cmd_getspec_cbk, +          "fetch spec for volume <VOLID>"}, +          { "system:: help",             cli_cmd_system_help_cbk,             "display help for system commands"}, diff --git a/cli/src/cli3_1-cops.c b/cli/src/cli3_1-cops.c index a3c0a2518cd..a63c2e17a3a 100644 --- a/cli/src/cli3_1-cops.c +++ b/cli/src/cli3_1-cops.c @@ -34,6 +34,8 @@  #include "cli-mem-types.h"  #include "compat.h" +#include "glusterfs3.h" +  extern rpc_clnt_prog_t *cli_rpc_prog;  extern int      cli_op_ret; @@ -52,6 +54,14 @@ int32_t  gf_cli3_1_get_volume (call_frame_t *frame, xlator_t *this,                        void *data); + +rpc_clnt_prog_t cli_handshake_prog = { +        .progname  = "cli handshake", +        .prognum   = GLUSTER_HNDSK_PROGRAM, +        .progver   = GLUSTER_HNDSK_VERSION, +}; + +  int  gf_cli3_1_probe_cbk (struct rpc_req *req, struct iovec *iov,                          int count, void *myframe) @@ -1015,6 +1025,42 @@ out:          return ret;  } +int +gf_cli3_1_getspec_cbk (struct rpc_req *req, struct iovec *iov, +                       int count, void *myframe) +{ +        gf_getspec_rsp          rsp   = {0,}; +        int                     ret   = 0; +        char                   *spec  = NULL; + +        if (-1 == req->rpc_status) { +                goto out; +        } + +        ret = xdr_to_getspec_rsp (*iov, &rsp); +        if (ret < 0 || rsp.op_ret == -1) { +                gf_log ("", GF_LOG_ERROR, "error"); +                goto out; +        } + +        gf_log ("cli", GF_LOG_NORMAL, "Received resp to getspec"); + +        spec = GF_MALLOC (rsp.op_ret + 1, cli_mt_char); +        if (!spec) { +                gf_log("", GF_LOG_ERROR, "out of memory"); +                goto out; +        } +        memcpy (spec, rsp.spec, rsp.op_ret); +        spec[rsp.op_ret] = '\0'; +        cli_out ("%s", spec); +        GF_FREE (spec); + +        ret = rsp.op_ret; + +out: +        cli_cmd_broadcast_response (ret); +        return ret; +}  int32_t @@ -1797,6 +1843,36 @@ out:          return ret;  } +int32_t +gf_cli3_1_getspec (call_frame_t *frame, xlator_t *this, +                         void *data) +{ +        gf_getspec_req          req = {0,}; +        int                     ret = 0; +        dict_t                  *dict = NULL; + +        if (!frame || !this ||  !data) { +                ret = -1; +                goto out; +        } + +        dict = data; + +        ret = dict_get_str (dict, "volid", &req.key); +        if (ret) +                goto out; + +        ret = cli_cmd_submit (&req, frame, &cli_handshake_prog, +                              GF_HNDSK_GETSPEC, NULL, +                              xdr_from_getspec_req, +                              this, gf_cli3_1_getspec_cbk); + +out: +        gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret); + +        return ret; +} +  struct rpc_clnt_procedure gluster3_1_cli_actors[GF1_CLI_MAXVALUE] = {          [GF1_CLI_NULL]        = {"NULL", NULL }, @@ -1818,6 +1894,7 @@ struct rpc_clnt_procedure gluster3_1_cli_actors[GF1_CLI_MAXVALUE] = {          [GF1_CLI_LOG_FILENAME] = {"LOG FILENAME", gf_cli3_1_log_filename},          [GF1_CLI_LOG_LOCATE] = {"LOG LOCATE", gf_cli3_1_log_locate},          [GF1_CLI_LOG_ROTATE] = {"LOG ROTATE", gf_cli3_1_log_rotate}, +        [GF1_CLI_GETSPEC] = {"GETSPEC", gf_cli3_1_getspec},  };  struct rpc_clnt_program cli3_1_prog = { diff --git a/rpc/rpc-lib/src/protocol-common.h b/rpc/rpc-lib/src/protocol-common.h index c18f468c20b..4bb32a5908a 100644 --- a/rpc/rpc-lib/src/protocol-common.h +++ b/rpc/rpc-lib/src/protocol-common.h @@ -127,6 +127,7 @@ enum gf_cli_procnum {          GF1_CLI_LOG_FILENAME,          GF1_CLI_LOG_LOCATE,          GF1_CLI_LOG_ROTATE, +        GF1_CLI_GETSPEC,          GF1_CLI_MAXVALUE,  };  | 
