diff options
| author | Vijay Bellur <vijay@gluster.com> | 2010-07-12 08:19:44 +0000 | 
|---|---|---|
| committer | Anand V. Avati <avati@dev.gluster.com> | 2010-07-12 06:59:29 -0700 | 
| commit | 6ef7f0e25fb7c76231b4d4ae05cbc45330de300d (patch) | |
| tree | 6e5b8537dfbee8b7d8e51cdbb62af1d9d0f31a35 | |
| parent | 9bee476eabb5034a27e994008a12ef684755d76c (diff) | |
Changes in CLI and glusterd
Signed-off-by: Vijay Bellur <vijay@gluster.com>
Signed-off-by: Anand V. Avati <avati@dev.gluster.com>
BUG: 971 (dynamic volume management)
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=971
24 files changed, 1731 insertions, 507 deletions
diff --git a/cli/src/Makefile.am b/cli/src/Makefile.am index 8e173260325..ee6a675edba 100644 --- a/cli/src/Makefile.am +++ b/cli/src/Makefile.am @@ -1,7 +1,8 @@  sbin_PROGRAMS = gluster  gluster_SOURCES = cli.c registry.c input.c cli-cmd.c cli-rl.c \ -	 cli-cmd-volume.c cli-cmd-probe.c cli3_1-cops.c cli-cmd-parser.c +	 cli-cmd-volume.c cli-cmd-probe.c cli3_1-cops.c cli-cmd-parser.c\ +	 cli-cmd-misc.c  gluster_LDADD = $(top_builddir)/libglusterfs/src/libglusterfs.la $(GF_LDADD)\  		$(RLLIBS) $(top_builddir)/xlators/protocol/lib/src/libgfproto1.la\ diff --git a/cli/src/cli-cmd-misc.c b/cli/src/cli-cmd-misc.c new file mode 100644 index 00000000000..9e78ca607e1 --- /dev/null +++ b/cli/src/cli-cmd-misc.c @@ -0,0 +1,69 @@ +/* +  Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com> +  This file is part of GlusterFS. + +  GlusterFS is free software; you can redistribute it and/or modify +  it under the terms of the GNU General Public License as published +  by the Free Software Foundation; either version 3 of the License, +  or (at your option) any later version. + +  GlusterFS is distributed in the hope that it will be useful, but +  WITHOUT ANY WARRANTY; without even the implied warranty of +  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU +  General Public License for more details. + +  You should have received a copy of the GNU General Public License +  along with this program.  If not, see +  <http://www.gnu.org/licenses/>. +*/ + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <stdint.h> +#include <pthread.h> + +#ifndef _CONFIG_H +#define _CONFIG_H +#include "config.h" +#endif + +#include "cli.h" +#include "cli-cmd.h" +#include "cli-mem-types.h" +#include "protocol-common.h" + +extern struct rpc_clnt *global_rpc; + +extern rpc_clnt_prog_t *cli_rpc_prog; + +int +cli_cmd_quit_cbk (struct cli_state *state, struct cli_cmd_word *word, +                   const char **words, int wordcount) +{ +        exit (0); +} + +struct cli_cmd cli_misc_cmds[] = { +        { "quit", +          cli_cmd_quit_cbk }, + + +        { NULL, NULL } +}; + + +int +cli_cmd_misc_register (struct cli_state *state) +{ +        int  ret = 0; +        struct cli_cmd *cmd = NULL; + +        for (cmd = cli_misc_cmds; cmd->pattern; cmd++) { +                ret = cli_cmd_register (&state->tree, cmd->pattern, cmd->cbk); +                if (ret) +                        goto out; +        } +out: +        return ret; +} diff --git a/cli/src/cli-cmd-probe.c b/cli/src/cli-cmd-probe.c index dccdaedbef9..a9f15a423bf 100644 --- a/cli/src/cli-cmd-probe.c +++ b/cli/src/cli-cmd-probe.c @@ -37,6 +37,24 @@ extern struct rpc_clnt *global_rpc;  extern rpc_clnt_prog_t *cli_rpc_prog; +void +cli_cmd_probe_usage () +{ +        cli_out ("Usage: probe <hostname>\n"); +} + +void +cli_cmd_deprobe_usage () +{ +        cli_out ("Usage: detach <hostname>\n"); +} + +void +cli_cmd_peer_status_usage () +{ +        cli_out ("Usage: peer status <hostname>\n"); +} +  int  cli_cmd_probe_cbk (struct cli_state *state, struct cli_cmd_word *word,                     const char **words, int wordcount) @@ -45,7 +63,11 @@ cli_cmd_probe_cbk (struct cli_state *state, struct cli_cmd_word *word,          rpc_clnt_procedure_t    *proc = NULL;          call_frame_t            *frame = NULL; -        //cli_out ("probe not implemented\n"); +        if (wordcount != 2) { +                cli_cmd_probe_usage (); +                goto out; +        } +          proc = &cli_rpc_prog->proctable[GF1_CLI_PROBE];          frame = create_frame (THIS, THIS->ctx->pool); @@ -53,21 +75,83 @@ cli_cmd_probe_cbk (struct cli_state *state, struct cli_cmd_word *word,                  goto out;          if (proc->fn) { -                ret = proc->fn (frame, THIS, "localhost"); -        }  +                ret = proc->fn (frame, THIS, (char *)words[1] ); +        } + +out: +        if (ret) +                cli_out ("Probe failed\n"); +        return ret; +} + + +int +cli_cmd_deprobe_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; + +        if (wordcount != 2) { +                cli_cmd_deprobe_usage (); +                goto out; +        } + +        proc = &cli_rpc_prog->proctable[GF1_CLI_DEPROBE]; + +        frame = create_frame (THIS, THIS->ctx->pool); +        if (!frame) +                goto out; + +        if (proc->fn) { +                ret = proc->fn (frame, THIS, (char *)words[1] ); +        }  out:          if (ret) -                cli_out ("Probe failed!"); +                cli_out ("Detach failed\n");          return ret;  } +int +cli_cmd_peer_status_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; + +        if (wordcount != 2) { +                cli_cmd_peer_status_usage (); +                goto out; +        } + +        proc = &cli_rpc_prog->proctable[GF1_CLI_LIST_FRIENDS]; + +        frame = create_frame (THIS, THIS->ctx->pool); +        if (!frame) +                goto out; + +        if (proc->fn) { +                ret = proc->fn (frame, THIS, (char *)words[1] ); +        } +out: +        if (ret) +                cli_out ("Command Execution failed\n"); +        return ret; +}  struct cli_cmd cli_probe_cmds[] = { -        { "probe <VOLNAME>", +        { "probe <HOSTNAME>",            cli_cmd_probe_cbk }, +        { "detach <HOSTNAME>", +          cli_cmd_deprobe_cbk }, + +        { "peer status", +          cli_cmd_peer_status_cbk},          { NULL, NULL }  }; diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c index 227438db479..dd15a78379c 100644 --- a/cli/src/cli-cmd-volume.c +++ b/cli/src/cli-cmd-volume.c @@ -52,7 +52,7 @@ cli_cmd_volume_info_cbk (struct cli_state *state, struct cli_cmd_word *word,          if (proc->fn) {                  ret = proc->fn (frame, THIS, "localhost"); -        }  +        }  out:          if (ret) @@ -116,7 +116,7 @@ cli_cmd_volume_delete_cbk (struct cli_state *state, struct cli_cmd_word *word,          if (proc->fn) {                  ret = proc->fn (frame, THIS, volname); -        }  +        }  out:          if (ret) @@ -147,7 +147,7 @@ cli_cmd_volume_start_cbk (struct cli_state *state, struct cli_cmd_word *word,          if (proc->fn) {                  ret = proc->fn (frame, THIS, volname); -        }  +        }  out:          if (ret) @@ -178,7 +178,7 @@ cli_cmd_volume_stop_cbk (struct cli_state *state, struct cli_cmd_word *word,          if (proc->fn) {                  ret = proc->fn (frame, THIS, volname); -        }  +        }  out:          if (ret) @@ -224,12 +224,12 @@ cli_cmd_volume_rename_cbk (struct cli_state *state, struct cli_cmd_word *word,          if (proc->fn) {                  ret = proc->fn (frame, THIS, dict); -        }  +        }  out:          if (ret) {                  char *volname = (char *) words[2]; -                if (dict)  +                if (dict)                          dict_destroy (dict);                  cli_out ("Renaming Volume %s failed", volname );          } @@ -259,7 +259,7 @@ cli_cmd_volume_defrag_cbk (struct cli_state *state, struct cli_cmd_word *word,          if (proc->fn) {                  ret = proc->fn (frame, THIS, volname); -        }  +        }  out:          if (ret) @@ -290,7 +290,7 @@ cli_cmd_volume_set_cbk (struct cli_state *state, struct cli_cmd_word *word,          GF_ASSERT (words[3]); -        ret = cli_cmd_volume_set_parse (words, wordcount, &dict);  +        ret = cli_cmd_volume_set_parse (words, wordcount, &dict);          if (ret)                  goto out; @@ -298,7 +298,7 @@ cli_cmd_volume_set_cbk (struct cli_state *state, struct cli_cmd_word *word,          //TODO: Build validation here          if (proc->fn) {                  ret = proc->fn (frame, THIS, dict); -        }  +        }  out:          if (ret) { @@ -334,7 +334,7 @@ cli_cmd_volume_add_brick_cbk (struct cli_state *state,          if (proc->fn) {                  ret = proc->fn (frame, THIS, options); -        }  +        }  out:          if (ret) { @@ -368,7 +368,7 @@ cli_cmd_volume_remove_brick_cbk (struct cli_state *state,          if (proc->fn) {                  ret = proc->fn (frame, THIS, options); -        }  +        }  out:          if (ret) { @@ -406,7 +406,7 @@ cli_cmd_volume_replace_brick_cbk (struct cli_state *state,          if (proc->fn) {                  ret = proc->fn (frame, THIS, options); -        }  +        }  out:          if (ret) { diff --git a/cli/src/cli-cmd.c b/cli/src/cli-cmd.c index a91dd77e23d..d19703abb45 100644 --- a/cli/src/cli-cmd.c +++ b/cli/src/cli-cmd.c @@ -158,6 +158,10 @@ cli_cmds_register (struct cli_state *state)          if (ret)                  goto out; +        ret = cli_cmd_misc_register (state); +        if (ret) +                goto out; +  out:          return ret;  } diff --git a/cli/src/cli-cmd.h b/cli/src/cli-cmd.h index d1da3e2acd2..4a838151049 100644 --- a/cli/src/cli-cmd.h +++ b/cli/src/cli-cmd.h @@ -36,6 +36,8 @@ int cli_cmd_volume_register (struct cli_state *state);  int cli_cmd_probe_register (struct cli_state *state); +int cli_cmd_misc_register (struct cli_state *state); +  struct cli_cmd_word *cli_cmd_nextword (struct cli_cmd_word *word,                                         const char *text);  void cli_cmd_tokens_destroy (char **tokens); diff --git a/cli/src/cli.c b/cli/src/cli.c index f899fbb72b8..96261de63ca 100644 --- a/cli/src/cli.c +++ b/cli/src/cli.c @@ -249,9 +249,9 @@ logging_init (glusterfs_ctx_t *ctx)  }  int -cli_submit_request (void *req, call_frame_t *frame,  -                    rpc_clnt_prog_t *prog,  -                    int procnum, struct iobref *iobref,  +cli_submit_request (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)  { @@ -295,8 +295,8 @@ cli_submit_request (void *req, call_frame_t *frame,          }          /* Send the msg */ -        ret = rpc_clnt_submit (global_rpc, prog, procnum, cbkfn,  -                               &iov, count,  +        ret = rpc_clnt_submit (global_rpc, prog, procnum, cbkfn, +                               &iov, count,                                 NULL, 0, iobref, frame);          if (ret == 0) { @@ -395,7 +395,7 @@ cli_rpc_init (struct cli_state *state)          options = dict_new ();          if (!options)                  goto out; -         +          ret = dict_set_str (options, "remote-host", "localhost");          if (ret)                  goto out; diff --git a/cli/src/cli3_1-cops.c b/cli/src/cli3_1-cops.c index a3d5ddd8950..4016fee80cb 100644 --- a/cli/src/cli3_1-cops.c +++ b/cli/src/cli3_1-cops.c @@ -34,7 +34,7 @@  extern rpc_clnt_prog_t *cli_rpc_prog;  int -gf_cli3_1_probe_cbk (struct rpc_req *req, struct iovec *iov,  +gf_cli3_1_probe_cbk (struct rpc_req *req, struct iovec *iov,                          int count, void *myframe)  {          gf1_cli_probe_rsp    rsp   = {0,}; @@ -44,7 +44,7 @@ gf_cli3_1_probe_cbk (struct rpc_req *req, struct iovec *iov,                  goto out;          } -        ret = gf_xdr_to_cli_probe_req (*iov, &rsp); +        ret = gf_xdr_to_cli_probe_rsp (*iov, &rsp);          if (ret < 0) {                  gf_log ("", GF_LOG_ERROR, "error");                  //rsp.op_ret   = -1; @@ -64,7 +64,137 @@ out:  }  int -gf_cli3_1_create_volume_cbk (struct rpc_req *req, struct iovec *iov,  +gf_cli3_1_deprobe_cbk (struct rpc_req *req, struct iovec *iov, +                       int count, void *myframe) +{ +        gf1_cli_deprobe_rsp    rsp   = {0,}; +        int                   ret   = 0; + +        if (-1 == req->rpc_status) { +                goto out; +        } + +        ret = gf_xdr_to_cli_deprobe_req (*iov, &rsp); +        if (ret < 0) { +                gf_log ("", GF_LOG_ERROR, "error"); +                //rsp.op_ret   = -1; +                //rsp.op_errno = EINVAL; +                goto out; +        } + +        gf_log ("cli", GF_LOG_NORMAL, "Received resp to deprobe"); +        cli_out ("Detach %s", (rsp.op_ret) ? "Unsuccessful": "Successful"); + +        cli_cmd_broadcast_response (); + +        ret = 0; + +out: +        return ret; +} + +int +gf_cli3_1_list_friends_cbk (struct rpc_req *req, struct iovec *iov, +                             int count, void *myframe) +{ +        gf1_cli_peer_list_rsp      rsp   = {0,}; +        int                        ret   = 0; +        dict_t                     *dict = NULL; +        char                       *uuid_buf = NULL; +        char                       *hostname_buf = NULL; +        int32_t                    i = 1; +        char                       key[256] = {0,}; +        int32_t                    state = 0; + +        if (-1 == req->rpc_status) { +                goto out; +        } + +        ret = gf_xdr_to_cli_peer_list_rsp (*iov, &rsp); +        if (ret < 0) { +                gf_log ("", GF_LOG_ERROR, "error"); +                //rsp.op_ret   = -1; +                //rsp.op_errno = EINVAL; +                goto out; +        } + + +        gf_log ("cli", GF_LOG_NORMAL, "Received resp to list: %d", +                rsp.op_ret); + +        if (!rsp.op_ret) { + +                if (!rsp.friends.friends_len) { +                        cli_out ("No peers present"); +                        goto out; +                } + +                dict = dict_new (); + +                if (!dict) { +                        ret = -1; +                        goto out; +                } + +                ret = dict_unserialize (rsp.friends.friends_val, +                                        rsp.friends.friends_len, +                                        &dict); + +                if (ret) { +                        gf_log ("", GF_LOG_ERROR, +                                        "Unable to allocate memory"); +                        goto out; +                } + +                ret = dict_get_int32 (dict, "count", &count); + +                if (ret) { +                        goto out; +                } + +                cli_out ("Number of Peers: %d", count); + +                while ( i <= count) { +                        snprintf (key, 256, "friend%d.uuid", i); +                        ret = dict_get_str (dict, key, &uuid_buf); +                        if (ret) +                                goto out; + +                        snprintf (key, 256, "friend%d.hostname", i); +                        ret = dict_get_str (dict, key, &hostname_buf); +                        if (ret) +                                goto out; + +                        snprintf (key, 256, "friend%d.state", i); +                        ret = dict_get_int32 (dict, key, &state); +                        if (ret) +                                goto out; + +                        cli_out ("hostname:%s, uuid:%s, state:%d\n", +                                  hostname_buf, uuid_buf, state); +                        i++; +                } +        } else { +                ret = -1; +                goto out; +        } + + +        ret = 0; + +out: +        if (ret) +                cli_out ("Command Execution Failed\n"); + +        if (dict) +                dict_destroy (dict); + +        return ret; +} + + +int +gf_cli3_1_create_volume_cbk (struct rpc_req *req, struct iovec *iov,                               int count, void *myframe)  {          gf1_cli_create_vol_rsp  rsp   = {0,}; @@ -74,7 +204,7 @@ gf_cli3_1_create_volume_cbk (struct rpc_req *req, struct iovec *iov,                  goto out;          } -        ret = gf_xdr_to_cli_create_vol_req (*iov, &rsp); +        ret = gf_xdr_to_cli_create_vol_rsp (*iov, &rsp);          if (ret < 0) {                  gf_log ("", GF_LOG_ERROR, "error");                  goto out; @@ -82,7 +212,7 @@ gf_cli3_1_create_volume_cbk (struct rpc_req *req, struct iovec *iov,          gf_log ("cli", GF_LOG_NORMAL, "Received resp to create volume"); -        cli_out ("Create Volume %s", (rsp.op_ret) ? "Unsuccessful":  +        cli_out ("Create Volume %s", (rsp.op_ret) ? "Unsuccessful":                                          "Successful");          ret = 0; @@ -92,7 +222,7 @@ out:  }  int -gf_cli3_1_delete_volume_cbk (struct rpc_req *req, struct iovec *iov,  +gf_cli3_1_delete_volume_cbk (struct rpc_req *req, struct iovec *iov,                               int count, void *myframe)  {          gf1_cli_delete_vol_rsp  rsp   = {0,}; @@ -102,7 +232,7 @@ gf_cli3_1_delete_volume_cbk (struct rpc_req *req, struct iovec *iov,                  goto out;          } -        ret = gf_xdr_to_cli_delete_vol_req (*iov, &rsp); +        ret = gf_xdr_to_cli_delete_vol_rsp (*iov, &rsp);          if (ret < 0) {                  gf_log ("", GF_LOG_ERROR, "error");                  goto out; @@ -110,7 +240,7 @@ gf_cli3_1_delete_volume_cbk (struct rpc_req *req, struct iovec *iov,          gf_log ("cli", GF_LOG_NORMAL, "Received resp to delete volume"); -        cli_out ("Delete Volume %s", (rsp.op_ret) ? "Unsuccessful":  +        cli_out ("Delete Volume %s", (rsp.op_ret) ? "Unsuccessful":                                          "Successful");          ret = 0; @@ -120,7 +250,7 @@ out:  }  int -gf_cli3_1_start_volume_cbk (struct rpc_req *req, struct iovec *iov,  +gf_cli3_1_start_volume_cbk (struct rpc_req *req, struct iovec *iov,                               int count, void *myframe)  {          gf1_cli_start_vol_rsp  rsp   = {0,}; @@ -130,7 +260,7 @@ gf_cli3_1_start_volume_cbk (struct rpc_req *req, struct iovec *iov,                  goto out;          } -        ret = gf_xdr_to_cli_start_vol_req (*iov, &rsp); +        ret = gf_xdr_to_cli_start_vol_rsp (*iov, &rsp);          if (ret < 0) {                  gf_log ("", GF_LOG_ERROR, "error");                  goto out; @@ -138,7 +268,7 @@ gf_cli3_1_start_volume_cbk (struct rpc_req *req, struct iovec *iov,          gf_log ("cli", GF_LOG_NORMAL, "Received resp to start volume"); -        cli_out ("Start Volume %s", (rsp.op_ret) ? "Unsuccessful":  +        cli_out ("Start Volume %s", (rsp.op_ret) ? "Unsuccessful":                                          "Successful");          ret = 0; @@ -148,7 +278,7 @@ out:  }  int -gf_cli3_1_stop_volume_cbk (struct rpc_req *req, struct iovec *iov,  +gf_cli3_1_stop_volume_cbk (struct rpc_req *req, struct iovec *iov,                               int count, void *myframe)  {          gf1_cli_stop_vol_rsp  rsp   = {0,}; @@ -158,7 +288,7 @@ gf_cli3_1_stop_volume_cbk (struct rpc_req *req, struct iovec *iov,                  goto out;          } -        ret = gf_xdr_to_cli_stop_vol_req (*iov, &rsp); +        ret = gf_xdr_to_cli_stop_vol_rsp (*iov, &rsp);          if (ret < 0) {                  gf_log ("", GF_LOG_ERROR, "error");                  goto out; @@ -166,7 +296,7 @@ gf_cli3_1_stop_volume_cbk (struct rpc_req *req, struct iovec *iov,          gf_log ("cli", GF_LOG_NORMAL, "Received resp to stop volume"); -        cli_out ("Delete Volume %s", (rsp.op_ret) ? "Unsuccessful":  +        cli_out ("Delete Volume %s", (rsp.op_ret) ? "Unsuccessful":                                          "Successful");          ret = 0; @@ -176,7 +306,7 @@ out:  }  int -gf_cli3_1_defrag_volume_cbk (struct rpc_req *req, struct iovec *iov,  +gf_cli3_1_defrag_volume_cbk (struct rpc_req *req, struct iovec *iov,                               int count, void *myframe)  {          gf1_cli_defrag_vol_rsp  rsp   = {0,}; @@ -186,7 +316,7 @@ gf_cli3_1_defrag_volume_cbk (struct rpc_req *req, struct iovec *iov,                  goto out;          } -        ret = gf_xdr_to_cli_defrag_vol_req (*iov, &rsp); +        ret = gf_xdr_to_cli_defrag_vol_rsp (*iov, &rsp);          if (ret < 0) {                  gf_log ("", GF_LOG_ERROR, "error");                  goto out; @@ -194,7 +324,7 @@ gf_cli3_1_defrag_volume_cbk (struct rpc_req *req, struct iovec *iov,          gf_log ("cli", GF_LOG_NORMAL, "Received resp to probe"); -        cli_out ("Defrag Volume %s", (rsp.op_ret) ? "Unsuccessful":  +        cli_out ("Defrag Volume %s", (rsp.op_ret) ? "Unsuccessful":                                          "Successful");          ret = 0; @@ -204,7 +334,7 @@ out:  }  int -gf_cli3_1_rename_volume_cbk (struct rpc_req *req, struct iovec *iov,  +gf_cli3_1_rename_volume_cbk (struct rpc_req *req, struct iovec *iov,                               int count, void *myframe)  {          gf1_cli_rename_vol_rsp  rsp   = {0,}; @@ -214,7 +344,7 @@ gf_cli3_1_rename_volume_cbk (struct rpc_req *req, struct iovec *iov,                  goto out;          } -        ret = gf_xdr_to_cli_rename_vol_req (*iov, &rsp); +        ret = gf_xdr_to_cli_rename_vol_rsp (*iov, &rsp);          if (ret < 0) {                  gf_log ("", GF_LOG_ERROR, "error");                  goto out; @@ -222,7 +352,7 @@ gf_cli3_1_rename_volume_cbk (struct rpc_req *req, struct iovec *iov,          gf_log ("cli", GF_LOG_NORMAL, "Received resp to probe"); -        cli_out ("Rename Volume %s", (rsp.op_ret) ? "Unsuccessful":  +        cli_out ("Rename Volume %s", (rsp.op_ret) ? "Unsuccessful":                                          "Successful");          ret = 0; @@ -232,7 +362,7 @@ out:  }  int -gf_cli3_1_set_volume_cbk (struct rpc_req *req, struct iovec *iov,  +gf_cli3_1_set_volume_cbk (struct rpc_req *req, struct iovec *iov,                               int count, void *myframe)  {          gf1_cli_set_vol_rsp  rsp   = {0,}; @@ -242,7 +372,7 @@ gf_cli3_1_set_volume_cbk (struct rpc_req *req, struct iovec *iov,                  goto out;          } -        ret = gf_xdr_to_cli_set_vol_req (*iov, &rsp); +        ret = gf_xdr_to_cli_set_vol_rsp (*iov, &rsp);          if (ret < 0) {                  gf_log ("", GF_LOG_ERROR, "error");                  goto out; @@ -250,7 +380,7 @@ gf_cli3_1_set_volume_cbk (struct rpc_req *req, struct iovec *iov,          gf_log ("cli", GF_LOG_NORMAL, "Received resp to set"); -        cli_out ("Set Volume %s", (rsp.op_ret) ? "Unsuccessful":  +        cli_out ("Set Volume %s", (rsp.op_ret) ? "Unsuccessful":                                          "Successful");          ret = 0; @@ -260,7 +390,7 @@ out:  }  int -gf_cli3_1_add_brick_cbk (struct rpc_req *req, struct iovec *iov,  +gf_cli3_1_add_brick_cbk (struct rpc_req *req, struct iovec *iov,                               int count, void *myframe)  {          gf1_cli_add_brick_rsp       rsp   = {0,}; @@ -270,7 +400,7 @@ gf_cli3_1_add_brick_cbk (struct rpc_req *req, struct iovec *iov,                  goto out;          } -        ret = gf_xdr_to_cli_add_brick_req (*iov, &rsp); +        ret = gf_xdr_to_cli_add_brick_rsp (*iov, &rsp);          if (ret < 0) {                  gf_log ("", GF_LOG_ERROR, "error");                  goto out; @@ -278,7 +408,7 @@ gf_cli3_1_add_brick_cbk (struct rpc_req *req, struct iovec *iov,          gf_log ("cli", GF_LOG_NORMAL, "Received resp to add brick"); -        cli_out ("Add Brick %s", (rsp.op_ret) ? "Unsuccessful":  +        cli_out ("Add Brick %s", (rsp.op_ret) ? "Unsuccessful":                                          "Successful");          ret = 0; @@ -289,7 +419,7 @@ out:  int -gf_cli3_1_remove_brick_cbk (struct rpc_req *req, struct iovec *iov,  +gf_cli3_1_remove_brick_cbk (struct rpc_req *req, struct iovec *iov,                               int count, void *myframe)  {          gf1_cli_remove_brick_rsp        rsp   = {0,}; @@ -299,14 +429,14 @@ gf_cli3_1_remove_brick_cbk (struct rpc_req *req, struct iovec *iov,                  goto out;          } -        ret = gf_xdr_to_cli_remove_brick_req (*iov, &rsp); +        ret = gf_xdr_to_cli_remove_brick_rsp (*iov, &rsp);          if (ret < 0) {                  gf_log ("", GF_LOG_ERROR, "error");                  goto out;          }          gf_log ("cli", GF_LOG_NORMAL, "Received resp to remove brick"); -        cli_out ("Remove Brick %s", (rsp.op_ret) ? "Unsuccessful":  +        cli_out ("Remove Brick %s", (rsp.op_ret) ? "Unsuccessful":                                          "Successful");          ret = 0; @@ -317,7 +447,7 @@ out:  int -gf_cli3_1_replace_brick_cbk (struct rpc_req *req, struct iovec *iov,  +gf_cli3_1_replace_brick_cbk (struct rpc_req *req, struct iovec *iov,                               int count, void *myframe)  {          gf1_cli_replace_brick_rsp       rsp   = {0,}; @@ -327,7 +457,7 @@ gf_cli3_1_replace_brick_cbk (struct rpc_req *req, struct iovec *iov,                  goto out;          } -        ret = gf_xdr_to_cli_replace_brick_req (*iov, &rsp); +        ret = gf_xdr_to_cli_replace_brick_rsp (*iov, &rsp);          if (ret < 0) {                  gf_log ("", GF_LOG_ERROR, "error");                  goto out; @@ -335,7 +465,7 @@ gf_cli3_1_replace_brick_cbk (struct rpc_req *req, struct iovec *iov,          gf_log ("cli", GF_LOG_NORMAL, "Received resp to replace brick"); -        cli_out ("Replace Brick %s", (rsp.op_ret) ? "Unsuccessful":  +        cli_out ("Replace Brick %s", (rsp.op_ret) ? "Unsuccessful":                                          "Successful");          ret = 0; @@ -345,7 +475,7 @@ out:  }  int32_t -gf_cli3_1_probe (call_frame_t *frame, xlator_t *this,  +gf_cli3_1_probe (call_frame_t *frame, xlator_t *this,                   void *data)  {          gf1_cli_probe_req      req = {0,}; @@ -374,7 +504,65 @@ out:  }  int32_t -gf_cli3_1_create_volume (call_frame_t *frame, xlator_t *this,  +gf_cli3_1_deprobe (call_frame_t *frame, xlator_t *this, +                   void *data) +{ +        gf1_cli_deprobe_req      req = {0,}; +        int                      ret = 0; +        char                     *hostname = NULL; + +        if (!frame || !this ||  !data) { +                ret = -1; +                goto out; +        } + +        hostname = data; + +        req.hostname = hostname; + +        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); + +        if (!ret) { +                //ret = cli_cmd_await_response (); +        } +out: +        gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret); +        return ret; +} + +int32_t +gf_cli3_1_list_friends (call_frame_t *frame, xlator_t *this, +                        void *data) +{ +        gf1_cli_peer_list_req   req = {0,}; +        int                     ret = 0; + +        if (!frame || !this) { +                ret = -1; +                goto out; +        } + +        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); + +        if (!ret) { +                //ret = cli_cmd_await_response (); +        } +out: +        gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret); +        return ret; +} + + +int32_t +gf_cli3_1_create_volume (call_frame_t *frame, xlator_t *this,                           void *data)  {          gf1_cli_create_vol_req  req = {0,}; @@ -433,7 +621,7 @@ out:  }  int32_t -gf_cli3_1_delete_volume (call_frame_t *frame, xlator_t *this,  +gf_cli3_1_delete_volume (call_frame_t *frame, xlator_t *this,                           void *data)  {          gf1_cli_delete_vol_req  req = {0,}; @@ -447,7 +635,7 @@ 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,  +                                   GD_MGMT_CLI_DELETE_VOLUME, NULL,                                     gf_xdr_from_cli_delete_vol_req,                                     this, gf_cli3_1_delete_volume_cbk); @@ -458,7 +646,7 @@ out:  }  int32_t -gf_cli3_1_start_volume (call_frame_t *frame, xlator_t *this,  +gf_cli3_1_start_volume (call_frame_t *frame, xlator_t *this,                           void *data)  {          gf1_cli_start_vol_req   req = {0,}; @@ -472,7 +660,7 @@ 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,  +                                   GD_MGMT_CLI_START_VOLUME, NULL,                                     gf_xdr_from_cli_start_vol_req,                                     this, gf_cli3_1_start_volume_cbk); @@ -483,7 +671,7 @@ out:  }  int32_t -gf_cli3_1_stop_volume (call_frame_t *frame, xlator_t *this,  +gf_cli3_1_stop_volume (call_frame_t *frame, xlator_t *this,                           void *data)  {          gf1_cli_stop_vol_req   req = {0,}; @@ -497,7 +685,7 @@ gf_cli3_1_stop_volume (call_frame_t *frame, xlator_t *this,          req.volname = data;          ret = cli_submit_request (&req, frame, cli_rpc_prog, -                                   GD_MGMT_CLI_STOP_VOLUME, NULL,  +                                   GD_MGMT_CLI_STOP_VOLUME, NULL,                                     gf_xdr_from_cli_stop_vol_req,                                     this, gf_cli3_1_stop_volume_cbk); @@ -508,7 +696,7 @@ out:  }  int32_t -gf_cli3_1_defrag_volume (call_frame_t *frame, xlator_t *this,  +gf_cli3_1_defrag_volume (call_frame_t *frame, xlator_t *this,                           void *data)  {          gf1_cli_defrag_vol_req   req = {0,}; @@ -522,7 +710,7 @@ 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,  +                                   GD_MGMT_CLI_DEFRAG_VOLUME, NULL,                                     gf_xdr_from_cli_defrag_vol_req,                                     this, gf_cli3_1_defrag_volume_cbk); @@ -533,7 +721,7 @@ out:  }  int32_t -gf_cli3_1_rename_volume (call_frame_t *frame, xlator_t *this,  +gf_cli3_1_rename_volume (call_frame_t *frame, xlator_t *this,                           void *data)  {          gf1_cli_rename_vol_req  req = {0,}; @@ -547,18 +735,18 @@ gf_cli3_1_rename_volume (call_frame_t *frame, xlator_t *this,          dict = data; -        ret = dict_get_str (dict, "old-volname", &req.old_volname);   +        ret = dict_get_str (dict, "old-volname", &req.old_volname);          if (ret)                  goto out;          ret = dict_get_str (dict, "new-volname", &req.new_volname); -         +          if (ret)                  goto out;          ret = cli_submit_request (&req, frame, cli_rpc_prog, -                                   GD_MGMT_CLI_RENAME_VOLUME, NULL,  +                                   GD_MGMT_CLI_RENAME_VOLUME, NULL,                                     gf_xdr_from_cli_rename_vol_req,                                     this, gf_cli3_1_rename_volume_cbk); @@ -569,7 +757,7 @@ out:  }  int32_t -gf_cli3_1_set_volume (call_frame_t *frame, xlator_t *this,  +gf_cli3_1_set_volume (call_frame_t *frame, xlator_t *this,                           void *data)  {          gf1_cli_set_vol_req     req = {0,}; @@ -583,7 +771,7 @@ gf_cli3_1_set_volume (call_frame_t *frame, xlator_t *this,          dict = data; -        ret = dict_get_str (dict, "volname", &req.volname);   +        ret = dict_get_str (dict, "volname", &req.volname);          if (ret)                  goto out; @@ -599,7 +787,7 @@ 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,  +                                   GD_MGMT_CLI_SET_VOLUME, NULL,                                     gf_xdr_from_cli_set_vol_req,                                     this, gf_cli3_1_set_volume_cbk); @@ -610,7 +798,7 @@ out:  }  int32_t -gf_cli3_1_add_brick (call_frame_t *frame, xlator_t *this,  +gf_cli3_1_add_brick (call_frame_t *frame, xlator_t *this,                           void *data)  {          gf1_cli_add_brick_req  req = {0,}; @@ -624,7 +812,7 @@ gf_cli3_1_add_brick (call_frame_t *frame, xlator_t *this,          dict = data; -        ret = dict_get_str (dict, "volname", &req.volname);   +        ret = dict_get_str (dict, "volname", &req.volname);          if (ret)                  goto out; @@ -635,7 +823,7 @@ gf_cli3_1_add_brick (call_frame_t *frame, xlator_t *this,                  goto out;          ret = dict_get_int32 (dict, "count", &req.count); -         +          if (ret)                  goto out; @@ -649,7 +837,7 @@ gf_cli3_1_add_brick (call_frame_t *frame, xlator_t *this,          }          ret = cli_submit_request (&req, frame, cli_rpc_prog, -                                   GD_MGMT_CLI_ADD_BRICK, NULL,  +                                   GD_MGMT_CLI_ADD_BRICK, NULL,                                     gf_xdr_from_cli_add_brick_req,                                     this, gf_cli3_1_add_brick_cbk); @@ -664,7 +852,7 @@ out:  }  int32_t -gf_cli3_1_remove_brick (call_frame_t *frame, xlator_t *this,  +gf_cli3_1_remove_brick (call_frame_t *frame, xlator_t *this,                           void *data)  {          gf1_cli_remove_brick_req  req = {0,}; @@ -678,7 +866,7 @@ gf_cli3_1_remove_brick (call_frame_t *frame, xlator_t *this,          dict = data; -        ret = dict_get_str (dict, "volname", &req.volname);   +        ret = dict_get_str (dict, "volname", &req.volname);          if (ret)                  goto out; @@ -689,7 +877,7 @@ gf_cli3_1_remove_brick (call_frame_t *frame, xlator_t *this,                  goto out;          ret = dict_get_int32 (dict, "count", &req.count); -         +          if (ret)                  goto out; @@ -703,7 +891,7 @@ gf_cli3_1_remove_brick (call_frame_t *frame, xlator_t *this,          }          ret = cli_submit_request (&req, frame, cli_rpc_prog, -                                   GD_MGMT_CLI_REMOVE_BRICK, NULL,  +                                   GD_MGMT_CLI_REMOVE_BRICK, NULL,                                     gf_xdr_from_cli_remove_brick_req,                                     this, gf_cli3_1_remove_brick_cbk); @@ -718,7 +906,7 @@ out:  }  int32_t -gf_cli3_1_replace_brick (call_frame_t *frame, xlator_t *this,  +gf_cli3_1_replace_brick (call_frame_t *frame, xlator_t *this,                           void *data)  {          gf1_cli_replace_brick_req  req = {0,}; @@ -734,7 +922,7 @@ gf_cli3_1_replace_brick (call_frame_t *frame, xlator_t *this,          dict = data; -        ret = dict_get_str (dict, "volname", &req.volname);   +        ret = dict_get_str (dict, "volname", &req.volname);          if (ret)                  goto out; @@ -763,7 +951,7 @@ gf_cli3_1_replace_brick (call_frame_t *frame, xlator_t *this,          }          ret = cli_submit_request (&req, frame, cli_rpc_prog, -                                   GD_MGMT_CLI_REPLACE_BRICK, NULL,  +                                   GD_MGMT_CLI_REPLACE_BRICK, NULL,                                     gf_xdr_from_cli_replace_brick_req,                                     this, gf_cli3_1_replace_brick_cbk); @@ -784,6 +972,8 @@ out:  struct rpc_clnt_procedure gluster3_1_cli_actors[GF1_CLI_MAXVALUE] = {          [GF1_CLI_NULL]        = {"NULL", NULL },          [GF1_CLI_PROBE]  = { "PROBE_QUERY",  gf_cli3_1_probe}, +        [GF1_CLI_DEPROBE]  = { "DEPROBE_QUERY",  gf_cli3_1_deprobe}, +        [GF1_CLI_LIST_FRIENDS]  = { "DEPROBE_QUERY",  gf_cli3_1_list_friends},          [GF1_CLI_CREATE_VOLUME] = {"CREATE_VOLUME", gf_cli3_1_create_volume},          [GF1_CLI_DELETE_VOLUME] = {"DELETE_VOLUME", gf_cli3_1_delete_volume},          [GF1_CLI_START_VOLUME] = {"START_VOLUME", gf_cli3_1_start_volume}, diff --git a/xlators/mgmt/glusterd/src/glusterd-ha.c b/xlators/mgmt/glusterd/src/glusterd-ha.c index 1c049e5f720..26de16b3a7a 100644 --- a/xlators/mgmt/glusterd/src/glusterd-ha.c +++ b/xlators/mgmt/glusterd/src/glusterd-ha.c @@ -59,7 +59,7 @@ glusterd_ha_create_volume (glusterd_volinfo_t *volinfo)          int     fd = -1;          GF_ASSERT (volinfo); -        snprintf (pathname, 1024, "%s/vols/%s", GLUSTERD_DEFAULT_WORKDIR,  +        snprintf (pathname, 1024, "%s/vols/%s", GLUSTERD_DEFAULT_WORKDIR,                    volinfo->volname);          ret = mkdir (pathname, 0x777); @@ -72,7 +72,7 @@ glusterd_ha_create_volume (glusterd_volinfo_t *volinfo)          snprintf (filepath, 1024, "%s/info", pathname); -        fd = open (filepath, O_RDWR | O_CREAT | O_APPEND, 0644);  +        fd = open (filepath, O_RDWR | O_CREAT | O_APPEND, 0644);          if (-1 == fd) {                  gf_log ("", GF_LOG_ERROR, "open() failed on path %s," @@ -99,7 +99,7 @@ out:          return ret;  } -         +  int32_t  glusterd_ha_delete_volume (glusterd_volinfo_t *volinfo)  { @@ -108,7 +108,7 @@ glusterd_ha_delete_volume (glusterd_volinfo_t *volinfo)          char    filepath[PATH_MAX] = {0,};          GF_ASSERT (volinfo); -        snprintf (pathname, 1024, "%s/vols/%s", GLUSTERD_DEFAULT_WORKDIR,  +        snprintf (pathname, 1024, "%s/vols/%s", GLUSTERD_DEFAULT_WORKDIR,                    volinfo->volname);          snprintf (filepath, 1024, "%s/info", pathname); diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c index 00067a566d4..f769693adb5 100644 --- a/xlators/mgmt/glusterd/src/glusterd-handler.c +++ b/xlators/mgmt/glusterd/src/glusterd-handler.c @@ -44,6 +44,7 @@  #include "gd-xdr.h"  #include "cli-xdr.h"  #include "rpc-clnt.h" +#include "gluster1.h"  #include <sys/resource.h>  #include <inttypes.h> @@ -61,7 +62,7 @@  static int -glusterd_friend_find_by_hostname (const char *hoststr,  +glusterd_friend_find_by_hostname (const char *hoststr,                                    glusterd_peerinfo_t  **peerinfo)  {          int                     ret = -1; @@ -79,7 +80,7 @@ glusterd_friend_find_by_hostname (const char *hoststr,          list_for_each_entry (entry, &priv->peers, uuid_list) {                  if (entry->hostname && (!strncmp (entry->hostname, hoststr,                                          sizeof (entry->hostname)))) { -                         +                          gf_log ("glusterd", GF_LOG_NORMAL,                                   "Friend %s found.. state: %d", hoststr,                                    entry->state.state); @@ -92,7 +93,7 @@ glusterd_friend_find_by_hostname (const char *hoststr,  }  static int -glusterd_friend_find_by_uuid (uuid_t uuid,  +glusterd_friend_find_by_uuid (uuid_t uuid,                                glusterd_peerinfo_t  **peerinfo)  {          int                     ret = -1; @@ -108,7 +109,7 @@ glusterd_friend_find_by_uuid (uuid_t uuid,          list_for_each_entry (entry, &priv->peers, uuid_list) {                  if (!uuid_compare (entry->uuid, uuid)) { -                         +                          gf_log ("glusterd", GF_LOG_NORMAL,                                   "Friend found.. state: %d",                                    entry->state.state); @@ -132,12 +133,12 @@ glusterd_handle_friend_req (rpcsvc_request_t *req, uuid_t  uuid, char *hostname)          ret = glusterd_friend_find (uuid, hostname, &peerinfo);          if (ret) { -                gf_log ("glusterd", GF_LOG_NORMAL,  +                gf_log ("glusterd", GF_LOG_NORMAL,                           "Unable to find peer");          } -        ret = glusterd_friend_sm_new_event  +        ret = glusterd_friend_sm_new_event                          (GD_FRIEND_EVENT_RCVD_FRIEND_REQ, &event);          if (ret) { @@ -169,7 +170,7 @@ glusterd_handle_friend_req (rpcsvc_request_t *req, uuid_t  uuid, char *hostname)                          "ret = %d", event->event, ret);                  goto out;          } -        +          ret = 0;  out: @@ -184,11 +185,101 @@ out:  } +static int +glusterd_handle_unfriend_req (rpcsvc_request_t *req, uuid_t  uuid, char *hostname) +{ +        int                             ret = -1; +        glusterd_peerinfo_t             *peerinfo = NULL; +        glusterd_friend_sm_event_t      *event = NULL; +        glusterd_friend_req_ctx_t       *ctx = NULL; + +        ret = glusterd_friend_find (uuid, hostname, &peerinfo); + +        if (ret) { +                gf_log ("glusterd", GF_LOG_NORMAL, +                         "Unable to find peer"); +        } + +        ret = glusterd_friend_sm_new_event +                        (GD_FRIEND_EVENT_REMOVE_FRIEND, &event); +        if (ret) { +                gf_log ("", GF_LOG_ERROR, "event generation failed: %d", ret); +                return ret; +        } + +        event->peerinfo = peerinfo; + +        ctx = GF_CALLOC (1, sizeof (*ctx), gf_gld_mt_friend_req_ctx_t); + +        if (!ctx) { +                gf_log ("", GF_LOG_ERROR, "Unable to allocate memory"); +                ret = -1; +                goto out; +        } + +        uuid_copy (ctx->uuid, uuid); +        if (hostname) +                ctx->hostname = gf_strdup (hostname); +        ctx->req = req; + +        event->ctx = ctx; + +        ret = glusterd_friend_sm_inject_event (event); + +        if (ret) { +                gf_log ("glusterd", GF_LOG_ERROR, "Unable to inject event %d, " +                        "ret = %d", event->event, ret); +                goto out; +        } + +        ret = 0; + +out: +        if (0 != ret) { +                if (ctx && ctx->hostname) +                        GF_FREE (ctx->hostname); +                if (ctx) +                        GF_FREE (ctx); +        } + +        return ret; +} + +static int +glusterd_add_peer_detail_to_dict (glusterd_peerinfo_t   *peerinfo, +                                  dict_t  *friends, int   count) +{ + +        int             ret = -1; +        char            key[256] = {0, }; + +        GF_ASSERT (peerinfo); +        GF_ASSERT (friends); + +        snprintf (key, 256, "friend%d.uuid", count); +        uuid_unparse (peerinfo->uuid, peerinfo->uuid_str); +        ret = dict_set_str (friends, key, peerinfo->uuid_str); +        if (ret) +                goto out; + +        snprintf (key, 256, "friend%d.hostname", count); +        ret = dict_set_str (friends, key, peerinfo->hostname); +        if (ret) +                goto out; + +        snprintf (key, 256, "friend%d.state", count); +        ret = dict_set_int32 (friends, key, (int32_t)peerinfo->state.state); +        if (ret) +                goto out; + +out: +        return ret; +}  int -glusterd_friend_find (uuid_t uuid, char *hostname,  +glusterd_friend_find (uuid_t uuid, char *hostname,                        glusterd_peerinfo_t **peerinfo)  {          int     ret = -1; @@ -197,7 +288,7 @@ glusterd_friend_find (uuid_t uuid, char *hostname,                  ret = glusterd_friend_find_by_uuid (uuid, peerinfo);                  if (ret) { -                        gf_log ("glusterd", GF_LOG_NORMAL,  +                        gf_log ("glusterd", GF_LOG_NORMAL,                                   "Unable to find peer by uuid");                  } else {                          goto out; @@ -238,7 +329,7 @@ glusterd_handle_cluster_lock (rpcsvc_request_t *req)          }          uuid_unparse (lock_req.uuid, str); -        gf_log ("glusterd", GF_LOG_NORMAL,  +        gf_log ("glusterd", GF_LOG_NORMAL,                  "Received LOCK from uuid: %s", str);          ret = glusterd_op_sm_new_event (GD_OP_EVENT_LOCK, &event); @@ -247,7 +338,7 @@ glusterd_handle_cluster_lock (rpcsvc_request_t *req)                  //respond back here                  return ret;          } -                 +          ctx = GF_CALLOC (1, sizeof (*ctx), gf_gld_mt_op_stage_ctx_t);          if (!ctx) { @@ -274,11 +365,11 @@ glusterd_handle_stage_op (rpcsvc_request_t *req)          char                            str[50];          gd1_mgmt_stage_op_req           *stage_req = NULL;          glusterd_op_sm_event_t          *event = NULL; -        glusterd_op_stage_ctx_t         *ctx = NULL;  +        glusterd_op_stage_ctx_t         *ctx = NULL;          GF_ASSERT (req); -        stage_req = GF_CALLOC (1, sizeof (*stage_req),  +        stage_req = GF_CALLOC (1, sizeof (*stage_req),                                 gf_gld_mt_mop_stage_req_t);          GF_ASSERT (stage_req); @@ -290,7 +381,7 @@ glusterd_handle_stage_op (rpcsvc_request_t *req)          }          uuid_unparse (stage_req->uuid, str); -        gf_log ("glusterd", GF_LOG_NORMAL,  +        gf_log ("glusterd", GF_LOG_NORMAL,                  "Received stage op from uuid: %s", str);          ret = glusterd_op_sm_new_event (GD_OP_EVENT_STAGE_OP, &event); @@ -299,7 +390,7 @@ glusterd_handle_stage_op (rpcsvc_request_t *req)                  //respond back here                  return ret;          } -                 +          ctx = GF_CALLOC (1, sizeof (*ctx), gf_gld_mt_op_stage_ctx_t);          if (!ctx) { @@ -314,7 +405,7 @@ glusterd_handle_stage_op (rpcsvc_request_t *req)          ret = glusterd_op_sm_inject_event (event); -out:         +out:          return ret;  } @@ -325,7 +416,7 @@ glusterd_handle_commit_op (rpcsvc_request_t *req)          char                            str[50];          glusterd_op_sm_event_t          *event = NULL;          gd1_mgmt_commit_op_req          commit_req = {{0},}; -        glusterd_op_commit_ctx_t        *ctx = NULL;  +        glusterd_op_commit_ctx_t        *ctx = NULL;          GF_ASSERT (req); @@ -337,7 +428,7 @@ glusterd_handle_commit_op (rpcsvc_request_t *req)          uuid_unparse (commit_req.uuid, str); -        gf_log ("glusterd", GF_LOG_NORMAL,  +        gf_log ("glusterd", GF_LOG_NORMAL,                  "Received commit op from uuid: %s", str);          ret = glusterd_op_sm_new_event (GD_OP_EVENT_COMMIT_OP, &event); @@ -346,7 +437,7 @@ glusterd_handle_commit_op (rpcsvc_request_t *req)                  //respond back here                  return ret;          } -                 +          ctx = GF_CALLOC (1, sizeof (*ctx), gf_gld_mt_op_commit_ctx_t);          if (!ctx) { @@ -389,6 +480,67 @@ out:  }  int +glusterd_handle_cli_deprobe (rpcsvc_request_t *req) +{ +        int32_t                         ret = -1; +        gf1_cli_probe_req               cli_req = {0,}; + +        GF_ASSERT (req); + +        if (!gf_xdr_to_cli_probe_req (req->msg[0], &cli_req)) { +                //failed to decode msg; +                req->rpc_err = GARBAGE_ARGS; +                goto out; +        } + +        gf_log ("glusterd", GF_LOG_NORMAL, "Received CLI deprobe req"); + + +        ret = glusterd_deprobe_begin (req, cli_req.hostname); + +out: +        return ret; +} + +int +glusterd_handle_cli_list_friends (rpcsvc_request_t *req) +{ +        int32_t                         ret = -1; +        gf1_cli_peer_list_req           cli_req = {0,}; +        dict_t                          *dict = NULL; + +        GF_ASSERT (req); + +        if (!gf_xdr_to_cli_peer_list_req (req->msg[0], &cli_req)) { +                //failed to decode msg; +                req->rpc_err = GARBAGE_ARGS; +                goto out; +        } + +        gf_log ("glusterd", GF_LOG_NORMAL, "Received cli list req"); + +        if (cli_req.dict.dict_len) { +                /* Unserialize the dictionary */ +                dict  = dict_new (); + +                ret = dict_unserialize (cli_req.dict.dict_val, +                                        cli_req.dict.dict_len, +                                        &dict); +                if (ret < 0) { +                        gf_log ("glusterd", GF_LOG_ERROR, +                                "failed to " +                                "unserialize req-buffer to dictionary"); +                        goto out; +                } +        } + +        ret = glusterd_list_friends (req, dict, cli_req.flags); + +out: +        return ret; +} + +int  glusterd_handle_create_volume (rpcsvc_request_t *req)  {          int32_t                         ret = -1; @@ -409,7 +561,7 @@ glusterd_handle_create_volume (rpcsvc_request_t *req)                  /* Unserialize the dictionary */                  dict  = dict_new (); -                ret = dict_unserialize (cli_req.bricks.bricks_val,  +                ret = dict_unserialize (cli_req.bricks.bricks_val,                                          cli_req.bricks.bricks_len,                                          &dict);                  if (ret < 0) { @@ -437,10 +589,10 @@ glusterd_op_lock_send_resp (rpcsvc_request_t *req, int32_t status)          glusterd_get_uuid (&rsp.uuid);          rsp.op_ret = status; -        ret = glusterd_submit_reply (req, &rsp, NULL, 0, NULL,  +        ret = glusterd_submit_reply (req, &rsp, NULL, 0, NULL,                                       gd_xdr_serialize_mgmt_cluster_lock_rsp); -        gf_log ("glusterd", GF_LOG_NORMAL,  +        gf_log ("glusterd", GF_LOG_NORMAL,                  "Responded, ret: %d", ret);          return 0; @@ -457,10 +609,10 @@ glusterd_op_unlock_send_resp (rpcsvc_request_t *req, int32_t status)          rsp.op_ret = status;          glusterd_get_uuid (&rsp.uuid); -        ret = glusterd_submit_reply (req, &rsp, NULL, 0, NULL,  +        ret = glusterd_submit_reply (req, &rsp, NULL, 0, NULL,                                       gd_xdr_serialize_mgmt_cluster_unlock_rsp); -        gf_log ("glusterd", GF_LOG_NORMAL,  +        gf_log ("glusterd", GF_LOG_NORMAL,                  "Responded to unlock, ret: %d", ret);          return ret; @@ -485,7 +637,7 @@ glusterd_handle_cluster_unlock (rpcsvc_request_t *req)          uuid_unparse (unlock_req.uuid, str); -        gf_log ("glusterd", GF_LOG_NORMAL,  +        gf_log ("glusterd", GF_LOG_NORMAL,                  "Received UNLOCK from uuid: %s", str);          ret = glusterd_op_sm_new_event (GD_OP_EVENT_UNLOCK, &event); @@ -494,7 +646,7 @@ glusterd_handle_cluster_unlock (rpcsvc_request_t *req)                  //respond back here                  return ret;          } -                 +          ctx = GF_CALLOC (1, sizeof (*ctx), gf_gld_mt_op_lock_ctx_t);          if (!ctx) { @@ -512,7 +664,7 @@ out:  }  int -glusterd_op_stage_send_resp (rpcsvc_request_t   *req,  +glusterd_op_stage_send_resp (rpcsvc_request_t   *req,                               int32_t op, int32_t status)  { @@ -524,17 +676,17 @@ glusterd_op_stage_send_resp (rpcsvc_request_t   *req,          glusterd_get_uuid (&rsp.uuid);          rsp.op = op; -        ret = glusterd_submit_reply (req, &rsp, NULL, 0, NULL,  +        ret = glusterd_submit_reply (req, &rsp, NULL, 0, NULL,                                       gd_xdr_serialize_mgmt_stage_op_rsp); -        gf_log ("glusterd", GF_LOG_NORMAL,  +        gf_log ("glusterd", GF_LOG_NORMAL,                  "Responded to stage, ret: %d", ret);          return ret;  }  int -glusterd_op_commit_send_resp (rpcsvc_request_t *req,  +glusterd_op_commit_send_resp (rpcsvc_request_t *req,                                 int32_t op, int32_t status)  {          gd1_mgmt_commit_op_rsp          rsp = {{0}, }; @@ -545,10 +697,10 @@ glusterd_op_commit_send_resp (rpcsvc_request_t *req,          glusterd_get_uuid (&rsp.uuid);          rsp.op = op; -        ret = glusterd_submit_reply (req, &rsp, NULL, 0, NULL,  +        ret = glusterd_submit_reply (req, &rsp, NULL, 0, NULL,                                       gd_xdr_serialize_mgmt_commit_op_rsp); -        gf_log ("glusterd", GF_LOG_NORMAL,  +        gf_log ("glusterd", GF_LOG_NORMAL,                  "Responded to commit, ret: %d", ret);          return ret; @@ -569,10 +721,10 @@ glusterd_handle_incoming_friend_req (rpcsvc_request_t *req)          }          uuid_unparse (friend_req.uuid, str); -        gf_log ("glusterd", GF_LOG_NORMAL,  +        gf_log ("glusterd", GF_LOG_NORMAL,                  "Received probe from uuid: %s", str); -        ret = glusterd_handle_friend_req (req, friend_req.uuid,  +        ret = glusterd_handle_friend_req (req, friend_req.uuid,                                            friend_req.hostname);  out: @@ -581,6 +733,32 @@ out:  }  int +glusterd_handle_incoming_unfriend_req (rpcsvc_request_t *req) +{ +        int32_t                 ret = -1; +        gd1_mgmt_friend_req     friend_req = {{0},}; +        char                    str[50]; + +        GF_ASSERT (req); +        if (!gd_xdr_to_mgmt_friend_req (req->msg[0], &friend_req)) { +                //failed to decode msg; +                req->rpc_err = GARBAGE_ARGS; +                goto out; +        } +        uuid_unparse (friend_req.uuid, str); + +        gf_log ("glusterd", GF_LOG_NORMAL, +                "Received unfriend from uuid: %s", str); + +        ret = glusterd_handle_unfriend_req (req, friend_req.uuid, +                                            friend_req.hostname); + +out: + +        return ret; +} + +int  glusterd_handle_probe_query (rpcsvc_request_t *req)  {          int32_t             ret = -1; @@ -604,7 +782,7 @@ glusterd_handle_probe_query (rpcsvc_request_t *req)          uuid_unparse (probe_req.uuid, str); -        gf_log ("glusterd", GF_LOG_NORMAL,  +        gf_log ("glusterd", GF_LOG_NORMAL,                  "Received probe from uuid: %s", str); @@ -615,10 +793,10 @@ glusterd_handle_probe_query (rpcsvc_request_t *req)          uuid_copy (rsp.uuid, conf->uuid);          rsp.hostname = gf_strdup (probe_req.hostname); -        ret = glusterd_submit_reply (req, &rsp, NULL, 0, NULL,  +        ret = glusterd_submit_reply (req, &rsp, NULL, 0, NULL,                                       gd_xdr_serialize_mgmt_probe_rsp); -        gf_log ("glusterd", GF_LOG_NORMAL,  +        gf_log ("glusterd", GF_LOG_NORMAL,                  "Responded to %s, ret: %d", probe_req.hostname, ret);  out: @@ -644,8 +822,8 @@ glusterd_handle_friend_req_resp (call_frame_t *frame,          op_ret = rsp_hdr->rsp.op_ret; -        gf_log ("glusterd", GF_LOG_NORMAL,  -                "Received %s from uuid: %s, host: %s",  +        gf_log ("glusterd", GF_LOG_NORMAL, +                "Received %s from uuid: %s, host: %s",                  (op_ret)?"RJT":"ACC", str, rsp->hostname);          ret = glusterd_friend_find (rsp->uuid, rsp->hostname, &peerinfo); @@ -654,7 +832,7 @@ glusterd_handle_friend_req_resp (call_frame_t *frame,                  GF_ASSERT (0);          } -        if (op_ret)  +        if (op_ret)                  event_type = GD_FRIEND_EVENT_RCVD_ACC;          else                  event_type = GD_FRIEND_EVENT_RCVD_RJT; @@ -676,7 +854,7 @@ glusterd_handle_friend_req_resp (call_frame_t *frame,  }*/  /*int -glusterd_handle_probe_resp (call_frame_t *frame, gf_hdr_common_t *rsp_hdr,  +glusterd_handle_probe_resp (call_frame_t *frame, gf_hdr_common_t *rsp_hdr,                              size_t hdrlen)  {          gf_mop_probe_rsp_t      *rsp = NULL; @@ -691,8 +869,8 @@ glusterd_handle_probe_resp (call_frame_t *frame, gf_hdr_common_t *rsp_hdr,          rsp   = gf_param (rsp_hdr);          uuid_unparse (rsp->uuid, str); -        gf_log ("glusterd", GF_LOG_NORMAL,  -                "Received probe resp from uuid: %s, host: %s",  +        gf_log ("glusterd", GF_LOG_NORMAL, +                "Received probe resp from uuid: %s, host: %s",                  str, rsp->hostname);          ret = glusterd_friend_find (rsp->uuid, rsp->hostname, &peerinfo); @@ -714,7 +892,7 @@ glusterd_handle_probe_resp (call_frame_t *frame, gf_hdr_common_t *rsp_hdr,          GF_ASSERT (peerinfo->hostname);          uuid_copy (peerinfo->uuid, rsp->uuid); -        ret = glusterd_friend_sm_new_event  +        ret = glusterd_friend_sm_new_event                          (GD_FRIEND_EVENT_INIT_FRIEND_REQ, &event);          if (ret) { @@ -870,11 +1048,11 @@ glusterd_xfer_cluster_lock_req (xlator_t *this, int32_t *lock_count)          list_for_each_entry (peerinfo, &priv->peers, uuid_list) {                  GF_ASSERT (peerinfo); -                if (peerinfo->state.state != GD_FRIEND_STATE_BEFRIENDED)  +                if (peerinfo->state.state != GD_FRIEND_STATE_BEFRIENDED)                          continue; -         -                ret = glusterd_submit_request (peerinfo, &req, dummy_frame,  + +                ret = glusterd_submit_request (peerinfo, &req, dummy_frame,                                                 prog, GD_MGMT_PROBE_QUERY,                                                 NULL, gd_xdr_from_mgmt_probe_req,                                                 this); @@ -926,13 +1104,13 @@ glusterd_xfer_cluster_unlock_req (xlator_t *this, int32_t *pending_count)          list_for_each_entry (peerinfo, &priv->peers, uuid_list) {                  GF_ASSERT (peerinfo); -                if (peerinfo->state.state != GD_FRIEND_STATE_BEFRIENDED)  +                if (peerinfo->state.state != GD_FRIEND_STATE_BEFRIENDED)                          continue; -         +                  ret = glusterd_xfer (dummy_frame, this,                                       peerinfo->trans, -                                     GF_OP_TYPE_MOP_REQUEST,  +                                     GF_OP_TYPE_MOP_REQUEST,                                       GF_MOP_CLUSTER_UNLOCK,                                       hdr, hdrlen, NULL, 0, NULL);                  if (!ret) @@ -953,7 +1131,7 @@ unwind:  int  glusterd_friend_add (const char *hoststr, -                     glusterd_peer_state_t state, +                     glusterd_friend_sm_state_t state,                       uuid_t *uuid,                       struct rpc_clnt    *rpc,                       glusterd_peerinfo_t **friend) @@ -987,7 +1165,7 @@ glusterd_friend_add (const char *hoststr,          if (uuid) {                  uuid_copy (peerinfo->uuid, *uuid); -        }  +        }          if (hoststr) { @@ -1006,8 +1184,8 @@ glusterd_friend_add (const char *hoststr,                  gf_log ("glusterd", GF_LOG_NORMAL, "remote-port: %d", port_num); -                //ret = dict_set_int32 (options, "remote-port", GLUSTERD_DEFAULT_PORT);  -                ret = dict_set_int32 (options, "remote-port", port_num);  +                //ret = dict_set_int32 (options, "remote-port", GLUSTERD_DEFAULT_PORT); +                ret = dict_set_int32 (options, "remote-port", port_num);                  if (ret)                          goto out; @@ -1018,12 +1196,12 @@ glusterd_friend_add (const char *hoststr,                  rpc = rpc_clnt_init (&rpc_cfg, options, THIS->ctx, THIS->name);                  if (!rpc) { -                        gf_log ("glusterd", GF_LOG_ERROR,  +                        gf_log ("glusterd", GF_LOG_ERROR,                                  "rpc init failed for peer: %s!", hoststr);                          ret = -1;                          goto out;                  } -         +                  ret = rpc_clnt_register_notify (rpc, glusterd_rpc_notify,                                                  peerinfo); @@ -1050,11 +1228,11 @@ glusterd_friend_probe (const char *hoststr)          if (ret) {                  //We should not reach this state ideally                  GF_ASSERT (0); -                goto out;  +                goto out;          } -         +          ret = glusterd_xfer_probe_msg (peerinfo, THIS); -         +  out:          return ret;  }*/ @@ -1075,13 +1253,14 @@ glusterd_probe_begin (rpcsvc_request_t *req, const char *hoststr)          if (ret) {                  gf_log ("glusterd", GF_LOG_NORMAL, "Unable to find peerinfo"                                  " for host: %s", hoststr); -                ret = glusterd_friend_add ((char *)hoststr, GD_PEER_STATE_NONE,  +                ret = glusterd_friend_add ((char *)hoststr, +                                           GD_FRIEND_STATE_DEFAULT,                                             NULL, NULL, &peerinfo);          } -        ret = glusterd_friend_sm_new_event  +        ret = glusterd_friend_sm_new_event                          (GD_FRIEND_EVENT_PROBE, &event); -         +          if (ret) {                  gf_log ("glusterd", GF_LOG_ERROR, "Unable to get new event");                  return ret; @@ -1110,6 +1289,62 @@ glusterd_probe_begin (rpcsvc_request_t *req, const char *hoststr)          return ret;  } +int +glusterd_deprobe_begin (rpcsvc_request_t *req, const char *hoststr) +{ +        int                             ret = -1; +        glusterd_peerinfo_t             *peerinfo = NULL; +        glusterd_friend_sm_event_t      *event = NULL; +        glusterd_probe_ctx_t            *ctx = NULL; + +        GF_ASSERT (hoststr); +        GF_ASSERT (req); + +        ret = glusterd_friend_find (NULL, (char *)hoststr, &peerinfo); + +        if (ret) { +                gf_log ("glusterd", GF_LOG_NORMAL, "Unable to find peerinfo" +                                " for host: %s", hoststr); +                goto out; +        } + +        if (!peerinfo->rpc) { +                //handle this case +                goto out; +        } + +        ret = glusterd_friend_sm_new_event +                        (GD_FRIEND_EVENT_INIT_REMOVE_FRIEND, &event); + +        if (ret) { +                gf_log ("glusterd", GF_LOG_ERROR, "Unable to get new event"); +                return ret; +        } + +        ctx = GF_CALLOC (1, sizeof(*ctx), gf_gld_mt_probe_ctx_t); + +        if (!ctx) { +                return ret; +        } + +        ctx->hostname = gf_strdup (hoststr); +        ctx->req = req; + +        event->peerinfo = peerinfo; +        event->ctx = ctx; + +        ret = glusterd_friend_sm_inject_event (event); + +        if (ret) { +                gf_log ("glusterd", GF_LOG_ERROR, "Unable to inject event %d, " +                        "ret = %d", event->event, ret); +                return ret; +        } + +out: +        return ret; +} +  /*int  glusterd_interpret (xlator_t *this, transport_t *trans,                      char *hdr_p, size_t hdrlen, struct iobuf *iobuf) @@ -1174,6 +1409,33 @@ glusterd_interpret (xlator_t *this, transport_t *trans,  */  int +glusterd_xfer_friend_remove_resp (rpcsvc_request_t *req, char *hostname) +{ +        gd1_mgmt_friend_rsp  rsp = {{0}, }; +        int32_t              ret = -1; +        xlator_t             *this = NULL; +        glusterd_conf_t      *conf = NULL; + +        GF_ASSERT (hostname); + +        rsp.op_ret = 0; +        this = THIS; +        GF_ASSERT (this); + +        conf = this->private; + +        uuid_copy (rsp.uuid, conf->uuid); +        rsp.hostname = hostname; + +        ret = glusterd_submit_reply (req, &rsp, NULL, 0, NULL, +                                     gd_xdr_serialize_mgmt_friend_rsp); + +        gf_log ("glusterd", GF_LOG_NORMAL, +                "Responded to %s, ret: %d", hostname, ret); +        return ret; +} + +int  glusterd_xfer_friend_add_resp (rpcsvc_request_t *req, char *hostname)  {          gd1_mgmt_friend_rsp  rsp = {{0}, }; @@ -1193,10 +1455,10 @@ glusterd_xfer_friend_add_resp (rpcsvc_request_t *req, char *hostname)          rsp.hostname = gf_strdup (hostname); -        ret = glusterd_submit_reply (req, &rsp, NULL, 0, NULL,  +        ret = glusterd_submit_reply (req, &rsp, NULL, 0, NULL,                                       gd_xdr_serialize_mgmt_friend_rsp); -        gf_log ("glusterd", GF_LOG_NORMAL,  +        gf_log ("glusterd", GF_LOG_NORMAL,                  "Responded to %s, ret: %d", hostname, ret);          return ret;  } @@ -1214,7 +1476,7 @@ glusterd_xfer_cli_probe_resp (rpcsvc_request_t *req, int32_t op_ret,          rsp.op_errno = op_errno;          rsp.hostname = hostname; -        ret = glusterd_submit_reply (req, &rsp, NULL, 0, NULL,  +        ret = glusterd_submit_reply (req, &rsp, NULL, 0, NULL,                                       gf_xdr_serialize_cli_probe_rsp);          gf_log ("glusterd", GF_LOG_NORMAL, "Responded to CLI, ret: %d",ret); @@ -1305,7 +1567,7 @@ glusterd_create_volume (rpcsvc_request_t *req, dict_t *dict)                  snprintf (cmd_str, 8192,                            "glusterfs-volgen -n %s -c /etc/glusterd -r 1 %s",                            volname, bricks); -                system (cmd_str); +                ret = system (cmd_str);                  break;          }          case GF_CLUSTER_TYPE_STRIPE: @@ -1316,7 +1578,7 @@ glusterd_create_volume (rpcsvc_request_t *req, dict_t *dict)                  snprintf (cmd_str, 8192,                            "glusterfs-volgen -n %s -c /etc/glusterd -r 0 %s",                            volname, bricks); -                system (cmd_str); +                ret = system (cmd_str);                  break;          }          case GF_CLUSTER_TYPE_NONE: @@ -1324,7 +1586,7 @@ glusterd_create_volume (rpcsvc_request_t *req, dict_t *dict)                  snprintf (cmd_str, 8192,                            "glusterfs-volgen -n %s -c /etc/glusterd %s",                            volname, bricks); -                system (cmd_str); +                ret = system (cmd_str);                  break;          }          } @@ -1336,6 +1598,68 @@ out:  } +int32_t +glusterd_list_friends (rpcsvc_request_t *req, dict_t *dict, int32_t flags) +{ +        int32_t                 ret = -1; +        glusterd_conf_t         *priv = NULL; +        glusterd_peerinfo_t     *entry = NULL; +        int32_t                 count = 0; +        dict_t                  *friends = NULL; +        gf1_cli_peer_list_rsp   rsp = {0,}; + +        priv = THIS->private; +        GF_ASSERT (priv); + +        if (!list_empty (&priv->peers)) { +                friends = dict_new (); +                if (!friends) { +                        gf_log ("", GF_LOG_WARNING, "Out of Memory"); +                        goto out; +                } +        } else { +                ret = 0; +                goto out; +        } + +        if (flags == GF_CLI_LIST_ALL) { +                        list_for_each_entry (entry, &priv->peers, uuid_list) { +                                count++; +                                ret = glusterd_add_peer_detail_to_dict (entry, +                                                                friends, count); +                                if (ret) +                                        goto out; + +                        } + +                        ret = dict_set_int32 (friends, "count", count); + +                        if (ret) +                                goto out; +        } + +        ret = dict_allocate_and_serialize (friends, &rsp.friends.friends_val, +                                           (size_t *)&rsp.friends.friends_len); + +        if (ret) +                goto out; + +        ret = 0; +out: + +        if (ret) { +                if (friends) +                        dict_destroy (friends); +        } + +        rsp.op_ret = ret; + +        ret = glusterd_submit_reply (req, &rsp, NULL, 0, NULL, +                                     gf_xdr_serialize_cli_peer_list_rsp); + +        return ret; +} +  int  glusterd_rpc_notify (struct rpc_clnt *rpc, void *mydata, rpc_clnt_event_t event,                       void *data) @@ -1364,7 +1688,7 @@ glusterd_rpc_notify (struct rpc_clnt *rpc, void *mydata, rpc_clnt_event_t event,                  } else {                          //conf->rpc->connected = 1;                          ret = default_notify (this, GF_EVENT_CHILD_UP, NULL); -                }  +                }                  break;          } diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c index 41203606c63..c6aaf712721 100644 --- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c +++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c @@ -77,20 +77,20 @@ glusterd_op_get_len (glusterd_op_t op)          return 0;  } -int  +int  glusterd_op_build_payload (glusterd_op_t op, gd1_mgmt_stage_op_req **req)  {          int                     len = 0;          int                     ret = -1;          gd1_mgmt_stage_op_req   *stage_req = NULL; -         +          GF_ASSERT (op < GD_OP_MAX);          GF_ASSERT (op > GD_OP_NONE);          GF_ASSERT (req);          len = glusterd_op_get_len (op); -        stage_req = GF_CALLOC (1, sizeof (*stage_req),  +        stage_req = GF_CALLOC (1, sizeof (*stage_req),                                 gf_gld_mt_mop_stage_req_t);          if (!stage_req) { @@ -98,7 +98,7 @@ glusterd_op_build_payload (glusterd_op_t op, gd1_mgmt_stage_op_req **req)                  goto out;          } -        stage_req->buf.buf_val = GF_CALLOC (1, len,  +        stage_req->buf.buf_val = GF_CALLOC (1, len,                                              gf_gld_mt_mop_stage_req_t);          if (!stage_req->buf.buf_val) { @@ -116,7 +116,7 @@ glusterd_op_build_payload (glusterd_op_t op, gd1_mgmt_stage_op_req **req)                                  dict_t  *dict = NULL;                                  dict = glusterd_op_get_ctx (op);                                  GF_ASSERT (dict); -                                ret = dict_serialize (dict,  +                                ret = dict_serialize (dict,                                                        stage_req->buf.buf_val);                                  if (ret) {                                          goto out; @@ -166,13 +166,13 @@ glusterd_xfer_stage_req (xlator_t *this, int32_t *lock_count)                  //No pending ops, inject stage_acc                  glusterd_op_sm_event_t  *event = NULL; -         -                ret = glusterd_op_sm_new_event (GD_OP_EVENT_STAGE_ACC,  + +                ret = glusterd_op_sm_new_event (GD_OP_EVENT_STAGE_ACC,                                                  &event);                  if (ret)                          goto out; -         +                  ret = glusterd_op_sm_inject_event (event);                  return ret; @@ -192,12 +192,12 @@ glusterd_xfer_stage_req (xlator_t *this, int32_t *lock_count)          list_for_each_entry (peerinfo, &opinfo.op_peers, op_peers_list) {                  GF_ASSERT (peerinfo); -                GF_ASSERT (peerinfo->state.state == GD_FRIEND_STATE_BEFRIENDED);  +                GF_ASSERT (peerinfo->state.state == GD_FRIEND_STATE_BEFRIENDED); + -                          ret = glusterd_xfer (dummy_frame, this,                                       peerinfo->trans, -                                     GF_OP_TYPE_MOP_REQUEST,  +                                     GF_OP_TYPE_MOP_REQUEST,                                       GF_MOP_STAGE_OP,                                       hdr, hdrlen, NULL, 0, NULL);                  if (!ret) @@ -206,7 +206,7 @@ glusterd_xfer_stage_req (xlator_t *this, int32_t *lock_count)          gf_log ("glusterd", GF_LOG_NORMAL, "Sent op req to %d peers",                                              pending_lock); -        if (i < GD_OP_MAX)  +        if (i < GD_OP_MAX)                  opinfo.pending_op[i] = 0;          *lock_count = pending_lock; @@ -247,13 +247,13 @@ glusterd_xfer_commit_req (xlator_t *this, int32_t *lock_count)                  //No pending ops, inject stage_acc                  glusterd_op_sm_event_t  *event = NULL; -         -                ret = glusterd_op_sm_new_event (GD_OP_EVENT_COMMIT_ACC,  + +                ret = glusterd_op_sm_new_event (GD_OP_EVENT_COMMIT_ACC,                                                  &event);                  if (ret)                          goto out; -         +                  ret = glusterd_op_sm_inject_event (event);                  return ret; @@ -273,12 +273,12 @@ glusterd_xfer_commit_req (xlator_t *this, int32_t *lock_count)          list_for_each_entry (peerinfo, &opinfo.op_peers, op_peers_list) {                  GF_ASSERT (peerinfo); -                GF_ASSERT (peerinfo->state.state == GD_FRIEND_STATE_BEFRIENDED);  +                GF_ASSERT (peerinfo->state.state == GD_FRIEND_STATE_BEFRIENDED); + -                          ret = glusterd_xfer (dummy_frame, this,                                       peerinfo->trans, -                                     GF_OP_TYPE_MOP_REQUEST,  +                                     GF_OP_TYPE_MOP_REQUEST,                                       GF_MOP_STAGE_OP,                                       hdr, hdrlen, NULL, 0, NULL);                  if (!ret) @@ -287,7 +287,7 @@ glusterd_xfer_commit_req (xlator_t *this, int32_t *lock_count)          gf_log ("glusterd", GF_LOG_NORMAL, "Sent op req to %d peers",                                              pending_lock); -        if (i < GD_OP_MAX)  +        if (i < GD_OP_MAX)                  opinfo.pending_op[i] = 0;          *lock_count = pending_lock; @@ -323,10 +323,10 @@ glusterd_op_stage_create_volume (gd1_mgmt_stage_op_req *req)                  goto out;          } -        exists = glusterd_check_volume_exists (volname);  +        exists = glusterd_check_volume_exists (volname);          if (exists) { -                gf_log ("", GF_LOG_ERROR, "Volume with name: %s exists",  +                gf_log ("", GF_LOG_ERROR, "Volume with name: %s exists",                          volname);                  ret = -1;          } else { @@ -394,7 +394,7 @@ glusterd_op_create_volume (gd1_mgmt_stage_op_req *req)                  goto out;          } -        ret = dict_get_int32 (dict, "count", &volinfo->brick_count);  +        ret = dict_get_int32 (dict, "count", &volinfo->brick_count);          if (ret) {                  gf_log ("", GF_LOG_ERROR, "Unable to get count"); @@ -756,8 +756,8 @@ glusterd_op_ac_commit_op (glusterd_op_sm_event_t *event, void *ctx)  static int -glusterd_op_sm_transition_state (glusterd_op_info_t *opinfo,  -                                 glusterd_op_sm_t *state,  +glusterd_op_sm_transition_state (glusterd_op_info_t *opinfo, +                                 glusterd_op_sm_t *state,                                   glusterd_op_sm_event_type_t event_type)  { @@ -766,7 +766,7 @@ glusterd_op_sm_transition_state (glusterd_op_info_t *opinfo,          gf_log ("", GF_LOG_NORMAL, "Transitioning from %d to %d",                       opinfo->state.state, state[event_type].next_state); -        opinfo->state.state =  +        opinfo->state.state =                  state[event_type].next_state;          return 0;  } @@ -777,10 +777,10 @@ glusterd_op_sm_t glusterd_op_state_default [] = {          {GD_OP_STATE_DEFAULT, glusterd_op_ac_none}, //EVENT_NONE          {GD_OP_STATE_LOCK_SENT, glusterd_op_ac_send_lock},//EVENT_START_LOCK          {GD_OP_STATE_LOCKED, glusterd_op_ac_lock}, //EVENT_LOCK -        {GD_OP_STATE_DEFAULT, glusterd_op_ac_none}, //EVENT_RCVD_ACC  -        {GD_OP_STATE_DEFAULT, glusterd_op_ac_none}, //EVENT_ALL_ACC  -        {GD_OP_STATE_DEFAULT, glusterd_op_ac_none}, //EVENT_STAGE_ACC  -        {GD_OP_STATE_DEFAULT, glusterd_op_ac_none}, //EVENT_COMMIT_ACC  +        {GD_OP_STATE_DEFAULT, glusterd_op_ac_none}, //EVENT_RCVD_ACC +        {GD_OP_STATE_DEFAULT, glusterd_op_ac_none}, //EVENT_ALL_ACC +        {GD_OP_STATE_DEFAULT, glusterd_op_ac_none}, //EVENT_STAGE_ACC +        {GD_OP_STATE_DEFAULT, glusterd_op_ac_none}, //EVENT_COMMIT_ACC          {GD_OP_STATE_DEFAULT, glusterd_op_ac_none}, //EVENT_RCVD_RJT          {GD_OP_STATE_DEFAULT, glusterd_op_ac_none}, //EVENT_STAGE_OP          {GD_OP_STATE_DEFAULT, glusterd_op_ac_none}, //EVENT_COMMIT_OP @@ -792,10 +792,10 @@ glusterd_op_sm_t glusterd_op_state_lock_sent [] = {          {GD_OP_STATE_LOCK_SENT, glusterd_op_ac_none}, //EVENT_NONE          {GD_OP_STATE_LOCK_SENT, glusterd_op_ac_none},//EVENT_START_LOCK          {GD_OP_STATE_LOCK_SENT, glusterd_op_ac_none}, //EVENT_LOCK -        {GD_OP_STATE_LOCK_SENT, glusterd_op_ac_rcvd_lock_acc}, //EVENT_RCVD_ACC  -        {GD_OP_STATE_STAGE_OP_SENT, glusterd_op_ac_send_stage_op}, //EVENT_ALL_ACC  -        {GD_OP_STATE_LOCK_SENT, glusterd_op_ac_none}, //EVENT_STAGE_ACC  -        {GD_OP_STATE_LOCK_SENT, glusterd_op_ac_none}, //EVENT_COMMIT_ACC  +        {GD_OP_STATE_LOCK_SENT, glusterd_op_ac_rcvd_lock_acc}, //EVENT_RCVD_ACC +        {GD_OP_STATE_STAGE_OP_SENT, glusterd_op_ac_send_stage_op}, //EVENT_ALL_ACC +        {GD_OP_STATE_LOCK_SENT, glusterd_op_ac_none}, //EVENT_STAGE_ACC +        {GD_OP_STATE_LOCK_SENT, glusterd_op_ac_none}, //EVENT_COMMIT_ACC          {GD_OP_STATE_UNLOCK_SENT, glusterd_op_ac_send_unlock}, //EVENT_RCVD_RJT          {GD_OP_STATE_LOCK_SENT, glusterd_op_ac_none}, //EVENT_STAGE_OP          {GD_OP_STATE_LOCK_SENT, glusterd_op_ac_none}, //EVENT_COMMIT_OP @@ -807,10 +807,10 @@ glusterd_op_sm_t glusterd_op_state_locked [] = {          {GD_OP_STATE_LOCKED, glusterd_op_ac_none}, //EVENT_NONE          {GD_OP_STATE_LOCKED, glusterd_op_ac_none},//EVENT_START_LOCK          {GD_OP_STATE_LOCKED, glusterd_op_ac_none}, //EVENT_LOCK -        {GD_OP_STATE_LOCKED, glusterd_op_ac_none}, //EVENT_RCVD_ACC  -        {GD_OP_STATE_LOCKED, glusterd_op_ac_none}, //EVENT_ALL_ACC  -        {GD_OP_STATE_LOCKED, glusterd_op_ac_none}, //EVENT_STAGE_ACC  -        {GD_OP_STATE_LOCKED, glusterd_op_ac_none}, //EVENT_COMMIT_ACC  +        {GD_OP_STATE_LOCKED, glusterd_op_ac_none}, //EVENT_RCVD_ACC +        {GD_OP_STATE_LOCKED, glusterd_op_ac_none}, //EVENT_ALL_ACC +        {GD_OP_STATE_LOCKED, glusterd_op_ac_none}, //EVENT_STAGE_ACC +        {GD_OP_STATE_LOCKED, glusterd_op_ac_none}, //EVENT_COMMIT_ACC          {GD_OP_STATE_LOCKED, glusterd_op_ac_none}, //EVENT_RCVD_RJT          {GD_OP_STATE_STAGED, glusterd_op_ac_stage_op}, //EVENT_STAGE_OP          {GD_OP_STATE_LOCKED, glusterd_op_ac_none}, //EVENT_COMMIT_OP @@ -822,10 +822,10 @@ glusterd_op_sm_t glusterd_op_state_stage_op_sent [] = {          {GD_OP_STATE_STAGE_OP_SENT, glusterd_op_ac_none}, //EVENT_NONE          {GD_OP_STATE_STAGE_OP_SENT, glusterd_op_ac_none},//EVENT_START_LOCK          {GD_OP_STATE_STAGE_OP_SENT, glusterd_op_ac_none}, //EVENT_LOCK -        {GD_OP_STATE_STAGE_OP_SENT, glusterd_op_ac_rcvd_stage_op_acc}, //EVENT_RCVD_ACC  -        {GD_OP_STATE_STAGE_OP_SENT, glusterd_op_ac_send_stage_op}, //EVENT_ALL_ACC  -        {GD_OP_STATE_COMMIT_OP_SENT, glusterd_op_ac_send_commit_op}, //EVENT_STAGE_ACC  -        {GD_OP_STATE_STAGE_OP_SENT, glusterd_op_ac_none}, //EVENT_COMMIT_ACC  +        {GD_OP_STATE_STAGE_OP_SENT, glusterd_op_ac_rcvd_stage_op_acc}, //EVENT_RCVD_ACC +        {GD_OP_STATE_STAGE_OP_SENT, glusterd_op_ac_send_stage_op}, //EVENT_ALL_ACC +        {GD_OP_STATE_COMMIT_OP_SENT, glusterd_op_ac_send_commit_op}, //EVENT_STAGE_ACC +        {GD_OP_STATE_STAGE_OP_SENT, glusterd_op_ac_none}, //EVENT_COMMIT_ACC          {GD_OP_STATE_UNLOCK_SENT,   glusterd_op_ac_send_unlock}, //EVENT_RCVD_RJT          {GD_OP_STATE_STAGE_OP_SENT, glusterd_op_ac_none}, //EVENT_STAGE_OP          {GD_OP_STATE_STAGE_OP_SENT, glusterd_op_ac_none}, //EVENT_COMMIT_OP @@ -837,10 +837,10 @@ glusterd_op_sm_t glusterd_op_state_staged [] = {          {GD_OP_STATE_STAGED, glusterd_op_ac_none}, //EVENT_NONE          {GD_OP_STATE_STAGED, glusterd_op_ac_none},//EVENT_START_LOCK          {GD_OP_STATE_STAGED, glusterd_op_ac_none}, //EVENT_LOCK -        {GD_OP_STATE_STAGED, glusterd_op_ac_none}, //EVENT_RCVD_ACC  -        {GD_OP_STATE_STAGED, glusterd_op_ac_none}, //EVENT_ALL_ACC  -        {GD_OP_STATE_STAGED, glusterd_op_ac_none}, //EVENT_STAGE_ACC  -        {GD_OP_STATE_STAGED, glusterd_op_ac_none}, //EVENT_COMMIT_ACC  +        {GD_OP_STATE_STAGED, glusterd_op_ac_none}, //EVENT_RCVD_ACC +        {GD_OP_STATE_STAGED, glusterd_op_ac_none}, //EVENT_ALL_ACC +        {GD_OP_STATE_STAGED, glusterd_op_ac_none}, //EVENT_STAGE_ACC +        {GD_OP_STATE_STAGED, glusterd_op_ac_none}, //EVENT_COMMIT_ACC          {GD_OP_STATE_STAGED, glusterd_op_ac_none}, //EVENT_RCVD_RJT          {GD_OP_STATE_STAGED, glusterd_op_ac_none}, //EVENT_STAGE_OP          {GD_OP_STATE_COMMITED, glusterd_op_ac_commit_op}, //EVENT_COMMIT_OP @@ -852,10 +852,10 @@ glusterd_op_sm_t glusterd_op_state_commit_op_sent [] = {          {GD_OP_STATE_COMMIT_OP_SENT, glusterd_op_ac_none}, //EVENT_NONE          {GD_OP_STATE_COMMIT_OP_SENT, glusterd_op_ac_none},//EVENT_START_LOCK          {GD_OP_STATE_COMMIT_OP_SENT, glusterd_op_ac_none}, //EVENT_LOCK -        {GD_OP_STATE_COMMIT_OP_SENT, glusterd_op_ac_rcvd_commit_op_acc}, //EVENT_RCVD_ACC  -        {GD_OP_STATE_UNLOCK_SENT,    glusterd_op_ac_commit_op}, //EVENT_ALL_ACC  -        {GD_OP_STATE_COMMIT_OP_SENT, glusterd_op_ac_none}, //EVENT_STAGE_ACC  -        {GD_OP_STATE_UNLOCK_SENT,    glusterd_op_ac_send_unlock}, //EVENT_COMMIT_ACC  +        {GD_OP_STATE_COMMIT_OP_SENT, glusterd_op_ac_rcvd_commit_op_acc}, //EVENT_RCVD_ACC +        {GD_OP_STATE_UNLOCK_SENT,    glusterd_op_ac_commit_op}, //EVENT_ALL_ACC +        {GD_OP_STATE_COMMIT_OP_SENT, glusterd_op_ac_none}, //EVENT_STAGE_ACC +        {GD_OP_STATE_UNLOCK_SENT,    glusterd_op_ac_send_unlock}, //EVENT_COMMIT_ACC          {GD_OP_STATE_COMMIT_OP_SENT, glusterd_op_ac_commit_error}, //EVENT_RCVD_RJT          {GD_OP_STATE_COMMIT_OP_SENT, glusterd_op_ac_none}, //EVENT_STAGE_OP          {GD_OP_STATE_COMMIT_OP_SENT, glusterd_op_ac_none}, //EVENT_COMMIT_OP @@ -867,10 +867,10 @@ glusterd_op_sm_t glusterd_op_state_commited [] = {          {GD_OP_STATE_COMMITED, glusterd_op_ac_none}, //EVENT_NONE          {GD_OP_STATE_COMMITED, glusterd_op_ac_none},//EVENT_START_LOCK          {GD_OP_STATE_COMMITED, glusterd_op_ac_none}, //EVENT_LOCK -        {GD_OP_STATE_COMMITED, glusterd_op_ac_none}, //EVENT_RCVD_ACC  -        {GD_OP_STATE_COMMITED, glusterd_op_ac_none}, //EVENT_ALL_ACC  -        {GD_OP_STATE_COMMITED, glusterd_op_ac_none}, //EVENT_STAGE_ACC  -        {GD_OP_STATE_COMMITED, glusterd_op_ac_none}, //EVENT_COMMIT_ACC  +        {GD_OP_STATE_COMMITED, glusterd_op_ac_none}, //EVENT_RCVD_ACC +        {GD_OP_STATE_COMMITED, glusterd_op_ac_none}, //EVENT_ALL_ACC +        {GD_OP_STATE_COMMITED, glusterd_op_ac_none}, //EVENT_STAGE_ACC +        {GD_OP_STATE_COMMITED, glusterd_op_ac_none}, //EVENT_COMMIT_ACC          {GD_OP_STATE_COMMITED, glusterd_op_ac_none}, //EVENT_RCVD_RJT          {GD_OP_STATE_COMMITED, glusterd_op_ac_none}, //EVENT_STAGE_OP          {GD_OP_STATE_COMMITED, glusterd_op_ac_none}, //EVENT_COMMIT_OP @@ -882,10 +882,10 @@ glusterd_op_sm_t glusterd_op_state_unlock_sent [] = {          {GD_OP_STATE_UNLOCK_SENT, glusterd_op_ac_none}, //EVENT_NONE          {GD_OP_STATE_UNLOCK_SENT, glusterd_op_ac_none},//EVENT_START_LOCK          {GD_OP_STATE_UNLOCK_SENT, glusterd_op_ac_none}, //EVENT_LOCK -        {GD_OP_STATE_UNLOCK_SENT, glusterd_op_ac_rcvd_unlock_acc}, //EVENT_RCVD_ACC  -        {GD_OP_STATE_DEFAULT, glusterd_op_ac_none}, //EVENT_ALL_ACC  -        {GD_OP_STATE_UNLOCK_SENT, glusterd_op_ac_none}, //EVENT_STAGE_ACC  -        {GD_OP_STATE_UNLOCK_SENT, glusterd_op_ac_none}, //EVENT_COMMIT_ACC  +        {GD_OP_STATE_UNLOCK_SENT, glusterd_op_ac_rcvd_unlock_acc}, //EVENT_RCVD_ACC +        {GD_OP_STATE_DEFAULT, glusterd_op_ac_none}, //EVENT_ALL_ACC +        {GD_OP_STATE_UNLOCK_SENT, glusterd_op_ac_none}, //EVENT_STAGE_ACC +        {GD_OP_STATE_UNLOCK_SENT, glusterd_op_ac_none}, //EVENT_COMMIT_ACC          {GD_OP_STATE_UNLOCK_SENT, glusterd_op_ac_none}, //EVENT_RCVD_RJT          {GD_OP_STATE_UNLOCK_SENT, glusterd_op_ac_none}, //EVENT_STAGE_OP          {GD_OP_STATE_UNLOCK_SENT, glusterd_op_ac_none}, //EVENT_COMMIT_OP @@ -915,7 +915,7 @@ glusterd_op_sm_new_event (glusterd_op_sm_event_type_t event_type,          GF_ASSERT (GD_OP_EVENT_NONE <= event_type &&                          GD_OP_EVENT_MAX > event_type); -        event = GF_CALLOC (1, sizeof (*event), gf_gld_mt_op_sm_event_t);  +        event = GF_CALLOC (1, sizeof (*event), gf_gld_mt_op_sm_event_t);          if (!event)                  return -1; @@ -949,11 +949,11 @@ glusterd_op_sm ()          glusterd_op_sm_t                *state = NULL;          glusterd_op_sm_event_type_t     event_type = 0; -         +          while (!list_empty (&gd_op_sm_queue)) { -	 +                  list_for_each_entry_safe (event, tmp, &gd_op_sm_queue, list) { -		 +                          list_del_init (&event->list);                          event_type = event->event; @@ -963,22 +963,22 @@ glusterd_op_sm ()                          handler = state[event_type].handler;                          GF_ASSERT (handler); -                 +                          ret = handler (event, event->ctx);                          if (ret) { -                                gf_log ("glusterd", GF_LOG_ERROR,  +                                gf_log ("glusterd", GF_LOG_ERROR,                                          "handler returned: %d", ret);                                  return ret;                          } -                        ret = glusterd_op_sm_transition_state (&opinfo, state,  +                        ret = glusterd_op_sm_transition_state (&opinfo, state,                                                                  event_type);                          if (ret) { -                                gf_log ("glusterd", GF_LOG_ERROR,  +                                gf_log ("glusterd", GF_LOG_ERROR,                                          "Unable to transition" -                                        "state from %d to %d",  +                                        "state from %d to %d",                                           opinfo.state.state,                                           state[event_type].next_state);                                  return ret; @@ -987,7 +987,7 @@ glusterd_op_sm ()                          GF_FREE (event);                  }          } -         +          ret = 0; @@ -997,7 +997,7 @@ glusterd_op_sm ()  int32_t  glusterd_op_set_op (glusterd_op_t op)  { -  +          GF_ASSERT (op < GD_OP_MAX);          GF_ASSERT (op > GD_OP_NONE); @@ -1012,7 +1012,7 @@ glusterd_op_set_op (glusterd_op_t op)  int32_t  glusterd_op_set_ctx (glusterd_op_t op, void *ctx)  { -  +          GF_ASSERT (op < GD_OP_MAX);          GF_ASSERT (op > GD_OP_NONE); diff --git a/xlators/mgmt/glusterd/src/glusterd-sm.c b/xlators/mgmt/glusterd/src/glusterd-sm.c index 53a0f5af8f8..b55fdd5678a 100644 --- a/xlators/mgmt/glusterd/src/glusterd-sm.c +++ b/xlators/mgmt/glusterd/src/glusterd-sm.c @@ -42,6 +42,7 @@  #include "compat-errno.h"  #include "statedump.h"  #include "glusterd-sm.h" +#include "glusterd-utils.h"  static struct list_head gd_friend_sm_queue; @@ -56,6 +57,16 @@ glusterd_ac_none (glusterd_friend_sm_event_t *event, void *ctx)  }  static int +glusterd_ac_error (glusterd_friend_sm_event_t *event, void *ctx) +{ +        int ret = 0; + +        gf_log ("", GF_LOG_ERROR, "Received event %d ", event->event); + +        return ret; +} + +static int  glusterd_ac_friend_add (glusterd_friend_sm_event_t *event, void *ctx)  {          int                     ret = 0; @@ -143,12 +154,95 @@ glusterd_ac_friend_probe (glusterd_friend_sm_event_t *event, void *ctx)          }  */ -out:         +out:          gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret);          return ret;  } +static int +glusterd_ac_send_friend_remove_req (glusterd_friend_sm_event_t *event, void *ctx) +{ +        int                     ret = 0; +        glusterd_peerinfo_t     *peerinfo = NULL; +        rpc_clnt_procedure_t    *proc = NULL; +        call_frame_t            *frame = NULL; +        glusterd_conf_t         *conf = NULL; +        xlator_t                *this = NULL; + + +        GF_ASSERT (event); +        peerinfo = event->peerinfo; + +        this = THIS; +        conf = this->private; + +        GF_ASSERT (conf); +        GF_ASSERT (conf->mgmt); + +        proc = &conf->mgmt->proctable[GD_MGMT_FRIEND_REMOVE]; +        if (proc->fn) { +                frame = create_frame (this, this->ctx->pool); +                if (!frame) { +                        goto out; +                } +                frame->local = ctx; +                ret = proc->fn (frame, this, event); +        } + +/*        ret = glusterd_xfer_friend_req_msg (peerinfo, THIS); + +        if (ret) { +                gf_log ("", GF_LOG_ERROR, "Unable to probe: %s", hostname); +        } +*/ + +out: +        gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret); + +        return ret; +} + +static int +glusterd_ac_handle_friend_remove_req (glusterd_friend_sm_event_t *event, +                                      void *ctx) +{ +        int                             ret = 0; +        glusterd_peerinfo_t             *peerinfo = NULL; +        glusterd_friend_req_ctx_t       *ev_ctx = NULL; + +        GF_ASSERT (ctx); +        ev_ctx = ctx; +        peerinfo = event->peerinfo; +        GF_ASSERT (peerinfo); + +        uuid_clear (peerinfo->uuid); + +        ret = glusterd_xfer_friend_remove_resp (ev_ctx->req, ev_ctx->hostname); + +        rpc_clnt_destroy (peerinfo->rpc); +        peerinfo->rpc = NULL; + +        gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret); + +        return ret; +} + +static int +glusterd_ac_friend_remove (glusterd_friend_sm_event_t *event, void *ctx) +{ +        int                     ret = -1; + +        ret = glusterd_friend_cleanup (event->peerinfo); + +        if (ret) { +                gf_log ("", GF_LOG_ERROR, "Cleanup returned: %d", ret); +        } + + +        return 0; +} +  /*static int  glusterd_ac_none (void *ctx)  { @@ -166,6 +260,9 @@ glusterd_ac_handle_friend_add_req (glusterd_friend_sm_event_t *event, void *ctx)          uuid_t                          uuid;          glusterd_peerinfo_t             *peerinfo = NULL;          glusterd_friend_req_ctx_t       *ev_ctx = NULL; +        glusterd_friend_sm_event_t      *new_event = NULL; +        glusterd_friend_sm_event_type_t event_type = GD_FRIEND_EVENT_NONE; +        int                             status = 0;          GF_ASSERT (ctx);          ev_ctx = ctx; @@ -174,6 +271,22 @@ glusterd_ac_handle_friend_add_req (glusterd_friend_sm_event_t *event, void *ctx)          GF_ASSERT (peerinfo);          uuid_copy (peerinfo->uuid, ev_ctx->uuid); +        //Build comparison logic here. + +        if (!status) +                event_type = GD_FRIEND_EVENT_LOCAL_ACC; +        else +                event_type = GD_FRIEND_EVENT_LOCAL_RJT; + +        ret = glusterd_friend_sm_new_event (event_type, &new_event); + +        if (ret) { +                gf_log ("", GF_LOG_ERROR, "Out of Memory"); +        } + +        new_event->peerinfo = peerinfo; +        glusterd_friend_sm_inject_event (new_event); +          ret = glusterd_xfer_friend_add_resp (ev_ctx->req, ev_ctx->hostname);          gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret); @@ -182,8 +295,8 @@ glusterd_ac_handle_friend_add_req (glusterd_friend_sm_event_t *event, void *ctx)  }  static int -glusterd_friend_sm_transition_state (glusterd_peerinfo_t *peerinfo,  -                                     glusterd_sm_t *state,  +glusterd_friend_sm_transition_state (glusterd_peerinfo_t *peerinfo, +                                     glusterd_sm_t *state,                                       glusterd_friend_sm_event_type_t event_type)  { @@ -203,9 +316,12 @@ glusterd_sm_t glusterd_state_default [] = {          {GD_FRIEND_STATE_DEFAULT, glusterd_ac_none},          {GD_FRIEND_STATE_DEFAULT, glusterd_ac_friend_probe},//EV_PROBE          {GD_FRIEND_STATE_REQ_SENT, glusterd_ac_friend_add}, //EV_INIT_FRIEND_REQ -        {GD_FRIEND_STATE_DEFAULT, glusterd_ac_none}, //EVENT_RCVD_ACC  +        {GD_FRIEND_STATE_DEFAULT, glusterd_ac_none}, //EVENT_RCVD_ACC +        {GD_FRIEND_STATE_DEFAULT, glusterd_ac_none}, //EVENT_RCVD_LOCAL_ACC          {GD_FRIEND_STATE_DEFAULT, glusterd_ac_none}, //EVENT_RCVD_RJT +        {GD_FRIEND_STATE_DEFAULT, glusterd_ac_none}, //EVENT_RCVD_LOCAL_RJT          {GD_FRIEND_STATE_REQ_RCVD, glusterd_ac_handle_friend_add_req}, //EVENT_RCV_FRIEND_REQ +        {GD_FRIEND_STATE_DEFAULT, glusterd_ac_error}, //EV_INIT_REMOVE_FRIEND          {GD_FRIEND_STATE_DEFAULT, glusterd_ac_none}, //EVENT_REMOVE_FRIEND          {GD_FRIEND_STATE_DEFAULT, glusterd_ac_none}, //EVENT_MAX  }; @@ -215,9 +331,12 @@ glusterd_sm_t  glusterd_state_req_sent [] = {          {GD_FRIEND_STATE_REQ_SENT, glusterd_ac_none}, //EVENT_NONE,          {GD_FRIEND_STATE_REQ_SENT, glusterd_ac_none}, //EVENT_PROBE,          {GD_FRIEND_STATE_REQ_SENT, glusterd_ac_none}, //EVENT_INIT_FRIEND_REQ, -        {GD_FRIEND_STATE_BEFRIENDED, glusterd_ac_none}, //EVENT_RCVD_ACC +        {GD_FRIEND_STATE_REQ_ACCEPTED, glusterd_ac_none}, //EVENT_RCVD_ACC +        {GD_FRIEND_STATE_REQ_SENT, glusterd_ac_none}, //EVENT_RCVD_LOCAL_ACC          {GD_FRIEND_STATE_REJECTED, glusterd_ac_none}, //EVENT_RCVD_RJT +        {GD_FRIEND_STATE_REQ_SENT, glusterd_ac_none}, //EVENT_RCVD_LOCAL_RJT          {GD_FRIEND_STATE_REQ_SENT_RCVD, glusterd_ac_handle_friend_add_req}, //EVENT_RCV_FRIEND_REQ +        {GD_FRIEND_STATE_DEFAULT, glusterd_ac_friend_remove}, //EVENT_INIT_REMOVE_FRIEND,          {GD_FRIEND_STATE_DEFAULT, glusterd_ac_none}, //EVENT_REMOVE_FRIEND          {GD_FRIEND_STATE_REQ_SENT, glusterd_ac_none},//EVENT_MAX  }; @@ -227,8 +346,11 @@ glusterd_sm_t  glusterd_state_req_rcvd [] = {          {GD_FRIEND_STATE_REQ_RCVD, glusterd_ac_friend_probe}, //EVENT_PROBE,          {GD_FRIEND_STATE_REQ_SENT_RCVD, glusterd_ac_friend_add}, //EVENT_INIT_FRIEND_REQ,          {GD_FRIEND_STATE_REQ_RCVD, glusterd_ac_none}, //EVENT_RCVD_ACC +        {GD_FRIEND_STATE_REQ_RCVD, glusterd_ac_none}, //EVENT_RCVD_LOCAL_ACC          {GD_FRIEND_STATE_REQ_RCVD, glusterd_ac_none}, //EVENT_RCVD_RJT +        {GD_FRIEND_STATE_REQ_RCVD, glusterd_ac_none}, //EVENT_RCVD_LOCAL_RJT          {GD_FRIEND_STATE_REQ_RCVD, glusterd_ac_none}, //EVENT_RCV_FRIEND_REQ +        {GD_FRIEND_STATE_REQ_RCVD, glusterd_ac_error}, //EVENT_INIT_REMOVE_FRIEND,          {GD_FRIEND_STATE_DEFAULT, glusterd_ac_none}, //EVENT_REMOVE_FRIEND          {GD_FRIEND_STATE_REQ_RCVD, glusterd_ac_none},//EVENT_MAX  }; @@ -238,9 +360,12 @@ glusterd_sm_t  glusterd_state_befriended [] = {          {GD_FRIEND_STATE_BEFRIENDED, glusterd_ac_none}, //EVENT_PROBE,          {GD_FRIEND_STATE_BEFRIENDED, glusterd_ac_none}, //EVENT_INIT_FRIEND_REQ,          {GD_FRIEND_STATE_BEFRIENDED, glusterd_ac_none}, //EVENT_RCVD_ACC +        {GD_FRIEND_STATE_BEFRIENDED, glusterd_ac_none}, //EVENT_RCVD_LOCAL_ACC          {GD_FRIEND_STATE_BEFRIENDED, glusterd_ac_none}, //EVENT_RCVD_RJT +        {GD_FRIEND_STATE_BEFRIENDED, glusterd_ac_none}, //EVENT_RCVD_LOCAL_RJT          {GD_FRIEND_STATE_BEFRIENDED, glusterd_ac_none}, //EVENT_RCV_FRIEND_REQ -        {GD_FRIEND_STATE_DEFAULT, glusterd_ac_none}, //EVENT_REMOVE_FRIEND +        {GD_FRIEND_STATE_UNFRIEND_SENT, glusterd_ac_send_friend_remove_req}, //EVENT_INIT_REMOVE_FRIEND, +        {GD_FRIEND_STATE_DEFAULT, glusterd_ac_handle_friend_remove_req}, //EVENT_REMOVE_FRIEND          {GD_FRIEND_STATE_BEFRIENDED, glusterd_ac_none},//EVENT_MAX  }; @@ -249,8 +374,11 @@ glusterd_sm_t  glusterd_state_req_sent_rcvd [] = {          {GD_FRIEND_STATE_REQ_SENT_RCVD, glusterd_ac_none}, //EVENT_PROBE,          {GD_FRIEND_STATE_REQ_SENT_RCVD, glusterd_ac_none}, //EVENT_INIT_FRIEND_REQ,          {GD_FRIEND_STATE_BEFRIENDED, glusterd_ac_none}, //EVENT_RCVD_ACC +        {GD_FRIEND_STATE_REQ_SENT_RCVD, glusterd_ac_none}, //EVENT_RCVD_LOCAL_ACC          {GD_FRIEND_STATE_REJECTED, glusterd_ac_none}, //EVENT_RCVD_RJT +        {GD_FRIEND_STATE_REQ_SENT_RCVD, glusterd_ac_none}, //EVENT_RCVD_LOCAL_RJT          {GD_FRIEND_STATE_REQ_SENT_RCVD, glusterd_ac_none}, //EVENT_RCV_FRIEND_REQ +        {GD_FRIEND_STATE_UNFRIEND_SENT, glusterd_ac_send_friend_remove_req}, //EVENT_INIT_REMOVE_FRIEND,          {GD_FRIEND_STATE_DEFAULT, glusterd_ac_none}, //EVENT_REMOVE_FRIEND          {GD_FRIEND_STATE_REQ_SENT_RCVD, glusterd_ac_none},//EVENT_MAX  }; @@ -260,12 +388,43 @@ glusterd_sm_t  glusterd_state_rejected [] = {          {GD_FRIEND_STATE_REJECTED, glusterd_ac_friend_probe}, //EVENT_PROBE,          {GD_FRIEND_STATE_REQ_SENT, glusterd_ac_friend_add}, //EVENT_INIT_FRIEND_REQ,          {GD_FRIEND_STATE_REJECTED, glusterd_ac_none}, //EVENT_RCVD_ACC +        {GD_FRIEND_STATE_REJECTED, glusterd_ac_none}, //EVENT_RCVD_LOCAL_ACC          {GD_FRIEND_STATE_REJECTED, glusterd_ac_none}, //EVENT_RCVD_RJT +        {GD_FRIEND_STATE_REJECTED, glusterd_ac_none}, //EVENT_RCVD_LOCAL_RJT          {GD_FRIEND_STATE_REQ_RCVD, glusterd_ac_handle_friend_add_req}, //EVENT_RCV_FRIEND_REQ +        {GD_FRIEND_STATE_DEFAULT, glusterd_ac_friend_remove}, //EVENT_INIT_REMOVE_FRIEND          {GD_FRIEND_STATE_DEFAULT, glusterd_ac_none}, //EVENT_REMOVE_FRIEND          {GD_FRIEND_STATE_REQ_RCVD, glusterd_ac_none},//EVENT_MAX  }; +glusterd_sm_t  glusterd_state_req_accepted [] = { +        {GD_FRIEND_STATE_REQ_ACCEPTED, glusterd_ac_none}, //EVENT_NONE, +        {GD_FRIEND_STATE_REQ_ACCEPTED, glusterd_ac_none}, //EVENT_PROBE, +        {GD_FRIEND_STATE_REQ_ACCEPTED, glusterd_ac_none}, //EVENT_INIT_FRIEND_REQ, +        {GD_FRIEND_STATE_BEFRIENDED, glusterd_ac_none}, //EVENT_RCVD_ACC +        {GD_FRIEND_STATE_BEFRIENDED, glusterd_ac_none}, //EVENT_RCVD_LOCAL_ACC +        {GD_FRIEND_STATE_REJECTED, glusterd_ac_none}, //EVENT_RCVD_RJT +        {GD_FRIEND_STATE_REJECTED, glusterd_ac_none}, //EVENT_RCVD_LOCAL_RJT +        {GD_FRIEND_STATE_REQ_ACCEPTED, glusterd_ac_handle_friend_add_req}, //EVENT_RCV_FRIEND_REQ +        {GD_FRIEND_STATE_DEFAULT, glusterd_ac_friend_remove}, //EVENT_INIT_REMOVE_FRIEND +        {GD_FRIEND_STATE_DEFAULT, glusterd_ac_none}, //EVENT_REMOVE_FRIEND +        {GD_FRIEND_STATE_REQ_SENT, glusterd_ac_none},//EVENT_MAX +}; + +glusterd_sm_t  glusterd_state_unfriend_sent [] = { +        {GD_FRIEND_STATE_REQ_ACCEPTED, glusterd_ac_none}, //EVENT_NONE, +        {GD_FRIEND_STATE_UNFRIEND_SENT, glusterd_ac_error}, //EVENT_PROBE, +        {GD_FRIEND_STATE_UNFRIEND_SENT, glusterd_ac_none}, //EVENT_INIT_FRIEND_REQ, +        {GD_FRIEND_STATE_UNFRIEND_SENT, glusterd_ac_none}, //EVENT_RCVD_ACC +        {GD_FRIEND_STATE_UNFRIEND_SENT, glusterd_ac_none}, //EVENT_RCVD_LOCAL_ACC +        {GD_FRIEND_STATE_UNFRIEND_SENT, glusterd_ac_error}, //EVENT_RCVD_RJT +        {GD_FRIEND_STATE_UNFRIEND_SENT, glusterd_ac_error}, //EVENT_RCVD_LOCAL_RJT +        {GD_FRIEND_STATE_UNFRIEND_SENT, glusterd_ac_error}, //EVENT_RCV_FRIEND_REQ +        {GD_FRIEND_STATE_UNFRIEND_SENT, glusterd_ac_none}, //EVENT_INIT_REMOVE_FRIEND +        {GD_FRIEND_STATE_DEFAULT, glusterd_ac_friend_remove}, //EVENT_REMOVE_FRIEND +        {GD_FRIEND_STATE_UNFRIEND_SENT, glusterd_ac_none},//EVENT_MAX +}; +  glusterd_sm_t *glusterd_friend_state_table [] = {          glusterd_state_default,          glusterd_state_req_sent, @@ -273,6 +432,8 @@ glusterd_sm_t *glusterd_friend_state_table [] = {          glusterd_state_befriended,          glusterd_state_req_sent_rcvd,          glusterd_state_rejected, +        glusterd_state_req_accepted, +        glusterd_state_unfriend_sent,  };  int @@ -285,7 +446,7 @@ glusterd_friend_sm_new_event (glusterd_friend_sm_event_type_t event_type,          GF_ASSERT (GD_FRIEND_EVENT_NONE <= event_type &&                          GD_FRIEND_EVENT_MAX > event_type); -        event = GF_CALLOC (1, sizeof (*event), gf_gld_mt_friend_sm_event_t);  +        event = GF_CALLOC (1, sizeof (*event), gf_gld_mt_friend_sm_event_t);          if (!event)                  return -1; @@ -321,21 +482,22 @@ glusterd_friend_sm ()          glusterd_friend_sm_event_type_t event_type = 0;  	list_for_each_entry_safe (event, tmp, &gd_friend_sm_queue, list) { -		 +                  list_del_init (&event->list);                  peerinfo = event->peerinfo;                  event_type = event->event; -                if (!peerinfo &&  +                if (!peerinfo &&                     (GD_FRIEND_EVENT_PROBE == event_type ||                      GD_FRIEND_EVENT_RCVD_FRIEND_REQ == event_type)) { -                        ret = glusterd_friend_add (NULL, GD_PEER_STATE_NONE, NULL, NULL, -                                                   &peerinfo); +                        ret = glusterd_friend_add (NULL, +                                                  GD_FRIEND_STATE_DEFAULT, +                                                  NULL, NULL, &peerinfo);                          if (ret) {                                  gf_log ("glusterd", GF_LOG_ERROR, "Unable to add peer, "                                          "ret = %d", ret); -                                continue;  +                                continue;                          }                          GF_ASSERT (peerinfo);                          event->peerinfo = peerinfo; @@ -348,7 +510,7 @@ glusterd_friend_sm ()                  handler = state[event_type].handler;                  GF_ASSERT (handler); -         +                  ret = handler (event, event->ctx);                  if (ret) { @@ -368,7 +530,7 @@ glusterd_friend_sm ()                  GF_FREE (event);          } -         +          ret = 0; diff --git a/xlators/mgmt/glusterd/src/glusterd-sm.h b/xlators/mgmt/glusterd/src/glusterd-sm.h index 087a4c301bc..6f03a8497ef 100644 --- a/xlators/mgmt/glusterd/src/glusterd-sm.h +++ b/xlators/mgmt/glusterd/src/glusterd-sm.h @@ -28,6 +28,7 @@  #include <pthread.h>  #include <uuid/uuid.h> +#include "rpc-clnt.h"  #include "glusterfs.h"  #include "xlator.h"  #include "logging.h" @@ -35,27 +36,52 @@  #include "authenticate.h"  #include "fd.h"  #include "byte-order.h" -#include "glusterd.h" +//#include "glusterd.h"  #include "rpcsvc.h" -  typedef enum glusterd_friend_sm_state_ {          GD_FRIEND_STATE_DEFAULT = 0,          GD_FRIEND_STATE_REQ_SENT,          GD_FRIEND_STATE_REQ_RCVD,          GD_FRIEND_STATE_BEFRIENDED, +        GD_FRIEND_STATE_REQ_ACCEPTED,          GD_FRIEND_STATE_REQ_SENT_RCVD,          GD_FRIEND_STATE_REJECTED, +        GD_FRIEND_STATE_UNFRIEND_SENT,          GD_FRIEND_STATE_MAX  } glusterd_friend_sm_state_t; +typedef struct glusterd_peer_state_info_ { +        glusterd_friend_sm_state_t   state; +        struct timeval          transition_time; +}glusterd_peer_state_info_t; + + +struct glusterd_peerinfo_ { +        uuid_t                          uuid; +        char                            uuid_str[50]; +        glusterd_peer_state_info_t      state; +        char                            *hostname; +        int                             port; +        struct list_head                uuid_list; +        struct list_head                op_peers_list; +        struct rpc_clnt                 *rpc; +}; + +typedef struct glusterd_peerinfo_ glusterd_peerinfo_t; + + +  typedef enum glusterd_friend_sm_event_type_ {          GD_FRIEND_EVENT_NONE = 0,          GD_FRIEND_EVENT_PROBE,          GD_FRIEND_EVENT_INIT_FRIEND_REQ,          GD_FRIEND_EVENT_RCVD_ACC, +        GD_FRIEND_EVENT_LOCAL_ACC,          GD_FRIEND_EVENT_RCVD_RJT, +        GD_FRIEND_EVENT_LOCAL_RJT,          GD_FRIEND_EVENT_RCVD_FRIEND_REQ, +        GD_FRIEND_EVENT_INIT_REMOVE_FRIEND,          GD_FRIEND_EVENT_REMOVE_FRIEND,          GD_FRIEND_EVENT_MAX  } glusterd_friend_sm_event_type_t; diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c index 0e3168036cb..feb4919ee19 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.c +++ b/xlators/mgmt/glusterd/src/glusterd-utils.c @@ -106,7 +106,7 @@ out:  int32_t  glusterd_unlock (uuid_t uuid) -{         +{          uuid_t  owner;          char    new_owner_str[50];          char    owner_str[50]; @@ -162,8 +162,8 @@ glusterd_get_uuid (uuid_t *uuid)  int  glusterd_submit_request (glusterd_peerinfo_t *peerinfo, void *req, -                         call_frame_t *frame, rpc_clnt_prog_t *prog,  -                         int procnum, struct iobref *iobref,  +                         call_frame_t *frame, rpc_clnt_prog_t *prog, +                         int procnum, struct iobref *iobref,                           gd_serialize_t sfunc, xlator_t *this,                           fop_cbk_fn_t cbkfn)  { @@ -205,8 +205,8 @@ glusterd_submit_request (glusterd_peerinfo_t *peerinfo, void *req,                  count = 1;          }          /* Send the msg */ -        ret = rpc_clnt_submit (peerinfo->rpc, prog, procnum, cbkfn,  -                               &iov, count,  +        ret = rpc_clnt_submit (peerinfo->rpc, prog, procnum, cbkfn, +                               &iov, count,                                 NULL, 0, iobref, frame);          if (ret == 0) { @@ -235,7 +235,7 @@ out:  struct iobuf * -glusterd_serialize_reply (rpcsvc_request_t *req, void *arg,  +glusterd_serialize_reply (rpcsvc_request_t *req, void *arg,                            gd_serialize_t sfunc, struct iovec *outmsg)  {          struct iobuf            *iob = NULL; @@ -337,7 +337,7 @@ glusterd_check_volume_exists (char *volname)          struct stat stbuf = {0,};          int32_t ret = -1; -        snprintf (pathname, 1024, "%s/vols/%s", GLUSTERD_DEFAULT_WORKDIR,  +        snprintf (pathname, 1024, "%s/vols/%s", GLUSTERD_DEFAULT_WORKDIR,                    volname);          ret = stat (pathname, &stbuf); @@ -371,7 +371,7 @@ glusterd_volinfo_new (glusterd_volinfo_t **volinfo)          *volinfo = new_volinfo;          ret = 0; -         +  out:          gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);          return ret; @@ -434,3 +434,17 @@ out:          gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);          return ret;  } + + +int32_t +glusterd_friend_cleanup (glusterd_peerinfo_t *peerinfo) +{ +        GF_ASSERT (peerinfo); +        if (peerinfo->rpc) { +                rpc_clnt_destroy (peerinfo->rpc); +                peerinfo->rpc = NULL; +        } +        GF_FREE (peerinfo->hostname); + +        return 0; +} diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.h b/xlators/mgmt/glusterd/src/glusterd-utils.h index 01c485b081b..8007fa72da9 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.h +++ b/xlators/mgmt/glusterd/src/glusterd-utils.h @@ -61,8 +61,8 @@ glusterd_submit_reply (rpcsvc_request_t *req, void *arg,  int  glusterd_submit_request (glusterd_peerinfo_t *peerinfo, void *req, -                         call_frame_t *frame, struct rpc_clnt_program *prog,  -                         int procnum, struct iobref *iobref,  +                         call_frame_t *frame, struct rpc_clnt_program *prog, +                         int procnum, struct iobref *iobref,                           gd_serialize_t sfunc, xlator_t *this,                           fop_cbk_fn_t cbkfn); @@ -77,4 +77,7 @@ glusterd_brickinfo_new (glusterd_brickinfo_t **brickinfo);  int32_t  glusterd_brickinfo_from_brick (char *brick, glusterd_brickinfo_t **brickinfo); + +int32_t +glusterd_friend_cleanup (glusterd_peerinfo_t *peerinfo);  #endif diff --git a/xlators/mgmt/glusterd/src/glusterd.c b/xlators/mgmt/glusterd/src/glusterd.c index 9c688c136b9..7ce466a6454 100644 --- a/xlators/mgmt/glusterd/src/glusterd.c +++ b/xlators/mgmt/glusterd/src/glusterd.c @@ -33,7 +33,6 @@  #include "rpcsvc.h"  #include "fnmatch.h"  #include "xlator.h" -//#include "protocol.h"  #include "call-stub.h"  #include "defaults.h"  #include "list.h" @@ -41,7 +40,6 @@  #include "compat.h"  #include "compat-errno.h"  #include "statedump.h" -//#include "md5.h"  #include "glusterd-sm.h"  #include "glusterd-op-sm.h" @@ -94,46 +92,6 @@ glusterd_uuid_init ()  } -/* xxx_MOPS */ - -#if 0 - -#endif - - - - - - - - - - -/* - * glusterd_nop_cbk - nop callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: return value - * @op_errno: errno - * - * not for external reference - */ -/*int -glusterd_nop_cbk (call_frame_t *frame, void *cookie, xlator_t *this, -                  int32_t op_ret, int32_t op_errno) -{ -        glusterd_state_t *state = NULL; - -        state = GLUSTERD_CALL_STATE(frame); - -        if (state) -                free_state (state); -        STACK_DESTROY (frame->root); -        return 0; -} -*/ -  int  glusterd_priv (xlator_t *this) @@ -152,7 +110,7 @@ mem_acct_init (xlator_t *this)                  return ret;          ret = xlator_mem_acct_init (this, gf_gld_mt_end + 1); -         +          if (ret != 0) {                  gf_log (this->name, GF_LOG_ERROR, "Memory accounting init"                          " failed"); @@ -181,23 +139,12 @@ glusterd_rpcsvc_notify (rpcsvc_t *rpc, void *xl, rpcsvc_event_t event,          switch (event) {          case RPCSVC_EVENT_ACCEPT:          { -                /* Have a structure per new connection */ -                /* TODO: Should we create anything here at all ? * / -                conn = create_server_conn_state (this, xprt); -                if (!conn) -                        goto out; - -                xprt->protocol_private = conn; -                */                  xprt->mydata = this;                  break;          }          case RPCSVC_EVENT_DISCONNECT: -               /* conn = get_server_conn_state (this, xprt); -                if (conn) -                        destroy_server_conn_state (conn); -                */                  break; +          default:                  break;          } @@ -263,7 +210,7 @@ init (xlator_t *this)          gf_log (this->name, GF_LOG_NORMAL, "Using %s as working directory",                  dirname); -         +          rpc = rpcsvc_init (this->ctx, this->options);          if (rpc == NULL) {                  gf_log (this->name, GF_LOG_ERROR, @@ -313,7 +260,7 @@ init (xlator_t *this)          ret = glusterd_uuid_init (); -        if (ret < 0)  +        if (ret < 0)                  goto out;          glusterd_friend_sm_init (); @@ -328,34 +275,10 @@ out: -/*int -glusterd_pollin (xlator_t *this, transport_t *trans) -{ -        char                *hdr = NULL; -        size_t               hdrlen = 0; -        int                  ret = -1; -        struct iobuf        *iobuf = NULL; - - -        ret = transport_receive (trans, &hdr, &hdrlen, &iobuf); - -        if (ret == 0) -                ret = glusterd_interpret (this, trans, hdr, -                                          hdrlen, iobuf); - -        ret = glusterd_friend_sm (); - -        glusterd_op_sm (); - -        GF_FREE (hdr); - -        return ret; -} -*/  /* - * fini - finish function for server protocol, called before - *        unloading server protocol. + * fini - finish function for glusterd, called before + *        unloading gluster.   *   * @this:   * @@ -373,7 +296,7 @@ out:  }  /* - * server_protocol_notify - notify function for server protocol + * notify - notify function for glusterd   * @this:   * @trans:   * @event: @@ -393,12 +316,12 @@ notify (xlator_t *this, int32_t event, void *data, ...)          }  */          switch (event) { -         +                  case GF_EVENT_POLLIN:            //              ret = glusterd_pollin (this, trans);                          break; -         +                  case GF_EVENT_POLLERR:                          break; @@ -408,49 +331,10 @@ notify (xlator_t *this, int32_t event, void *data, ...)                  default:                          default_notify (this, event, data);                          break; -         -        } - -        return ret; -} - - -void -glusterd_init (int signum) -{ -        int ret = -1; - -        glusterfs_this_set ((xlator_t *)CTX->active); -        ret = glusterd_probe_begin (NULL, "localhost"); - -        if (!ret) { -                ret = glusterd_friend_sm (); - -                glusterd_op_sm (); -        } - -        gf_log ("glusterd", GF_LOG_WARNING, "ret = %d", ret); - -        //return 0; -} - -void -glusterd_op_init (int signum)  -{ -        int     ret = -1; - -        glusterfs_this_set ((xlator_t *)CTX->active); - -        //ret = glusterd_create_volume ("vol1"); - -/*        if (!ret) { -                glusterd_friend_sm (); -                glusterd_op_sm ();          } -*/ -        gf_log ("glusterd", GF_LOG_WARNING, "ret = %d", ret); +        return ret;  } diff --git a/xlators/mgmt/glusterd/src/glusterd.h b/xlators/mgmt/glusterd/src/glusterd.h index b3d53244eff..48fe0fc663b 100644 --- a/xlators/mgmt/glusterd/src/glusterd.h +++ b/xlators/mgmt/glusterd/src/glusterd.h @@ -36,38 +36,14 @@  #include "authenticate.h"  #include "fd.h"  #include "byte-order.h" -//#include "protocol.h"  #include "glusterd-mem-types.h"  #include "rpcsvc.h" +#include "glusterd-sm.h"  #include "glusterd1.h" - - -/*struct _glusterd_connection { -	struct list_head    list; -	char               *id; -	int                 ref; -        int                 active_transports; -	pthread_mutex_t     lock; -	char                disconnected; -	xlator_t           *bound_xl; -}; - -typedef struct _glusterd_connection glusterd_connection_t; -*/ - - -typedef enum glusterd_peer_state_ { -        GD_PEER_STATE_NONE = 0, -        GD_PEER_STATE_INBOUND, -        GD_PEER_STATE_OUTBOUND, -        GD_PEER_STATE_FRIEND -} glusterd_peer_state_t; - - -typedef struct glusterd_peer_state_info_ { -        glusterd_peer_state_t   state; +/*typedef struct glusterd_peer_state_info_ { +        glusterd_friend_sm_state_t   state;          struct timeval          transition_time;  }glusterd_peer_state_info_t; @@ -79,11 +55,11 @@ struct glusterd_peerinfo_ {          int                             port;          struct list_head                uuid_list;          struct list_head                op_peers_list; - //       struct list_head                pending_uuid;          struct rpc_clnt                 *rpc;  };  typedef struct glusterd_peerinfo_ glusterd_peerinfo_t; +*/  typedef struct {          struct _volfile_ctx *volfile; @@ -142,12 +118,12 @@ int  glusterd_xfer_friend_add_resp (rpcsvc_request_t *req, char *hostname);  int -glusterd_friend_find (uuid_t uuid, char *hostname,  +glusterd_friend_find (uuid_t uuid, char *hostname,                        glusterd_peerinfo_t **peerinfo);  int  glusterd_friend_add (const char *hoststr, -                     glusterd_peer_state_t state, +                     glusterd_friend_sm_state_t state,                       uuid_t *uuid, struct rpc_clnt    *rpc,                       glusterd_peerinfo_t **friend);  /* @@ -169,18 +145,18 @@ int  glusterd_op_unlock_send_resp (rpcsvc_request_t *req, int32_t status);  int -glusterd_op_stage_send_resp (rpcsvc_request_t *req,  +glusterd_op_stage_send_resp (rpcsvc_request_t *req,                               int32_t op, int32_t status);  int -glusterd_op_commmit_send_resp (rpcsvc_request_t *req,  +glusterd_op_commmit_send_resp (rpcsvc_request_t *req,                                 int32_t op, int32_t status);  int32_t  glusterd_create_volume (rpcsvc_request_t *req, dict_t *dict);  int -glusterd_rpc_notify (struct rpc_clnt *rpc, void *mydata,  +glusterd_rpc_notify (struct rpc_clnt *rpc, void *mydata,                       rpc_clnt_event_t event,                       void *data);  int @@ -211,8 +187,25 @@ int  glusterd_xfer_cli_probe_resp (rpcsvc_request_t *req, int32_t op_ret,                                int32_t op_errno, char *hostname); -  int -glusterd_op_commit_send_resp (rpcsvc_request_t *req,  +glusterd_op_commit_send_resp (rpcsvc_request_t *req,                                 int32_t op, int32_t status); + +int +glusterd_xfer_friend_remove_resp (rpcsvc_request_t *req, char *hostname); + +int +glusterd_deprobe_begin (rpcsvc_request_t *req, const char *hoststr); + +int +glusterd_handle_cli_deprobe (rpcsvc_request_t *req); + +int +glusterd_handle_incoming_unfriend_req (rpcsvc_request_t *req); + +int32_t +glusterd_list_friends (rpcsvc_request_t *req, dict_t *dict, int32_t flags); + +int +glusterd_handle_cli_list_friends (rpcsvc_request_t *req);  #endif diff --git a/xlators/mgmt/glusterd/src/glusterd3_1-mops.c b/xlators/mgmt/glusterd/src/glusterd3_1-mops.c index d377f09ac80..1bd33ad1e54 100644 --- a/xlators/mgmt/glusterd/src/glusterd3_1-mops.c +++ b/xlators/mgmt/glusterd/src/glusterd3_1-mops.c @@ -43,26 +43,18 @@ extern glusterd_op_info_t    opinfo;  int  glusterd_null (rpcsvc_request_t *req)  { -/*        gf_common_rsp rsp = {0,}; -        rsp.gfs_id = req->gfs_id; -         //Accepted  -        rsp.op_ret = 0; - -        server_submit_reply (NULL, req, &rsp, NULL, 0, NULL, -                             (gfs_serialize_t)xdr_serialize_common_rsp); -*/          return 0;  }  int -glusterd3_1_probe_cbk (struct rpc_req *req, struct iovec *iov,  +glusterd3_1_probe_cbk (struct rpc_req *req, struct iovec *iov,                          int count, void *myframe)  {          gd1_mgmt_probe_rsp    rsp   = {{0},};          glusterd_conf_t       *conf = NULL;          int                   ret   = 0; -        char                  str[50]; +        char                  str[50] = {0,};          glusterd_peerinfo_t           *peerinfo = NULL;          glusterd_peerinfo_t           *dup_peerinfo = NULL;          glusterd_friend_sm_event_t    *event = NULL; @@ -82,8 +74,8 @@ glusterd3_1_probe_cbk (struct rpc_req *req, struct iovec *iov,          }          uuid_unparse (rsp.uuid, str); -        gf_log ("glusterd", GF_LOG_NORMAL,  -                "Received probe resp from uuid: %s, host: %s",  +        gf_log ("glusterd", GF_LOG_NORMAL, +                "Received probe resp from uuid: %s, host: %s",                  str, rsp.hostname);          ret = glusterd_friend_find (rsp.uuid, rsp.hostname, &peerinfo); @@ -105,7 +97,7 @@ glusterd3_1_probe_cbk (struct rpc_req *req, struct iovec *iov,          GF_ASSERT (peerinfo->hostname);          uuid_copy (peerinfo->uuid, rsp.uuid); -        ret = glusterd_friend_sm_new_event  +        ret = glusterd_friend_sm_new_event                          (GD_FRIEND_EVENT_INIT_FRIEND_REQ, &event);          if (ret) { @@ -133,7 +125,7 @@ out:  }  int -glusterd3_1_friend_add_cbk (struct rpc_req * req, struct iovec *iov,  +glusterd3_1_friend_add_cbk (struct rpc_req * req, struct iovec *iov,                              int count, void *myframe)  {          gd1_mgmt_friend_rsp           rsp   = {{0},}; @@ -166,8 +158,8 @@ glusterd3_1_friend_add_cbk (struct rpc_req * req, struct iovec *iov,          op_ret = rsp.op_ret;          op_errno = rsp.op_errno; -        gf_log ("glusterd", GF_LOG_NORMAL,  -                "Received %s from uuid: %s, host: %s",  +        gf_log ("glusterd", GF_LOG_NORMAL, +                "Received %s from uuid: %s, host: %s",                  (op_ret)?"RJT":"ACC", str, rsp.hostname);          ret = glusterd_friend_find (rsp.uuid, rsp.hostname, &peerinfo); @@ -176,7 +168,7 @@ glusterd3_1_friend_add_cbk (struct rpc_req * req, struct iovec *iov,                  GF_ASSERT (0);          } -        if (op_ret)  +        if (op_ret)                  event_type = GD_FRIEND_EVENT_RCVD_RJT;          else                  event_type = GD_FRIEND_EVENT_RCVD_ACC; @@ -199,7 +191,7 @@ glusterd3_1_friend_add_cbk (struct rpc_req * req, struct iovec *iov,          GF_ASSERT (ctx); -        ret = glusterd_xfer_cli_probe_resp (ctx->req, op_ret, op_errno,  +        ret = glusterd_xfer_cli_probe_resp (ctx->req, op_ret, op_errno,                                              ctx->hostname);          if (!ret) {                  glusterd_friend_sm (); @@ -210,8 +202,93 @@ out:          return ret;  } +int +glusterd3_1_friend_remove_cbk (struct rpc_req * req, struct iovec *iov, +                               int count, void *myframe) +{ +        gd1_mgmt_friend_rsp             rsp   = {{0},}; +        glusterd_conf_t                 *conf = NULL; +        int                             ret   = -1; +        glusterd_friend_sm_event_t      *event = NULL; +        glusterd_friend_sm_event_type_t event_type = GD_FRIEND_EVENT_NONE; +        glusterd_peerinfo_t             *peerinfo = NULL; +        char                            str[50] = {0,}; +        int32_t                         op_ret = -1; +        int32_t                         op_errno = -1; +        glusterd_probe_ctx_t            *ctx = NULL; + +        conf  = THIS->private; +        GF_ASSERT (conf); + +        ctx = ((call_frame_t *)myframe)->local; +        GF_ASSERT (ctx); + +        if (-1 == req->rpc_status) { +                rsp.op_ret   = -1; +                rsp.op_errno = EINVAL; +                goto respond; +        } + +        ret = gd_xdr_to_mgmt_friend_req (*iov, &rsp); +        if (ret < 0) { +                gf_log ("", GF_LOG_ERROR, "error"); +                rsp.op_ret   = -1; +                rsp.op_errno = EINVAL; +                goto respond; +        } +        uuid_unparse (rsp.uuid, str); + +        op_ret = rsp.op_ret; +        op_errno = rsp.op_errno; + +        gf_log ("glusterd", GF_LOG_NORMAL, +                "Received %s from uuid: %s, host: %s", +                (op_ret)?"RJT":"ACC", str, rsp.hostname); + +        if (op_ret) +                goto respond; + +        ret = glusterd_friend_find (rsp.uuid, rsp.hostname, &peerinfo); + +        if (ret) { +                GF_ASSERT (0); +                goto respond; +        } + +        event_type = GD_FRIEND_EVENT_REMOVE_FRIEND; + +        ret = glusterd_friend_sm_new_event (event_type, &event); + +        if (ret) { +                gf_log ("glusterd", GF_LOG_ERROR, +                         "Unable to get event"); +                goto respond; +        } +        event->peerinfo = peerinfo; + +        ret = glusterd_friend_sm_inject_event (event); + +        if (ret) +                goto respond; + +        glusterd_friend_sm (); +        glusterd_op_sm (); + +        return ret; + +respond: +        ret = glusterd_xfer_cli_probe_resp (ctx->req, op_ret, op_errno, +                                            ctx->hostname); +        if (!ret) { +                glusterd_friend_sm (); +                glusterd_op_sm (); +        } + +        return ret; +} +  int32_t -glusterd3_1_cluster_lock_cbk (struct rpc_req *req, struct iovec *iov,  +glusterd3_1_cluster_lock_cbk (struct rpc_req *req, struct iovec *iov,                                int count, void *myframe)  {          gd1_mgmt_cluster_lock_rsp     rsp   = {{0},}; @@ -240,8 +317,8 @@ glusterd3_1_cluster_lock_cbk (struct rpc_req *req, struct iovec *iov,          op_ret = rsp.op_ret; -        gf_log ("glusterd", GF_LOG_NORMAL,  -                "Received %s from uuid: %s",  +        gf_log ("glusterd", GF_LOG_NORMAL, +                "Received %s from uuid: %s",                  (op_ret)?"RJT":"ACC", str);          ret = glusterd_friend_find (rsp.uuid, NULL, &peerinfo); @@ -250,7 +327,7 @@ glusterd3_1_cluster_lock_cbk (struct rpc_req *req, struct iovec *iov,                  GF_ASSERT (0);          } -        if (op_ret)  +        if (op_ret)                  event_type = GD_OP_EVENT_RCVD_RJT;          else                  event_type = GD_OP_EVENT_RCVD_ACC; @@ -278,7 +355,7 @@ out:  }  int32_t -glusterd3_1_cluster_unlock_cbk (struct rpc_req *req, struct iovec *iov,  +glusterd3_1_cluster_unlock_cbk (struct rpc_req *req, struct iovec *iov,                                   int count, void *myframe)  {          gd1_mgmt_cluster_lock_rsp     rsp   = {{0},}; @@ -308,8 +385,8 @@ glusterd3_1_cluster_unlock_cbk (struct rpc_req *req, struct iovec *iov,          op_ret = rsp.op_ret; -        gf_log ("glusterd", GF_LOG_NORMAL,  -                "Received %s from uuid: %s",  +        gf_log ("glusterd", GF_LOG_NORMAL, +                "Received %s from uuid: %s",                  (op_ret)?"RJT":"ACC", str);          ret = glusterd_friend_find (rsp.uuid, NULL, &peerinfo); @@ -318,7 +395,7 @@ glusterd3_1_cluster_unlock_cbk (struct rpc_req *req, struct iovec *iov,                  GF_ASSERT (0);          } -        if (op_ret)  +        if (op_ret)                  event_type = GD_OP_EVENT_RCVD_RJT;          else                  event_type = GD_OP_EVENT_RCVD_ACC; @@ -346,7 +423,7 @@ out:  }  int32_t -glusterd3_1_stage_op_cbk (struct rpc_req *req, struct iovec *iov,  +glusterd3_1_stage_op_cbk (struct rpc_req *req, struct iovec *iov,                            int count, void *myframe)  {          gd1_mgmt_stage_op_rsp         rsp   = {{0},}; @@ -376,8 +453,8 @@ glusterd3_1_stage_op_cbk (struct rpc_req *req, struct iovec *iov,          op_ret = rsp.op_ret; -        gf_log ("glusterd", GF_LOG_NORMAL,  -                "Received %s from uuid: %s",  +        gf_log ("glusterd", GF_LOG_NORMAL, +                "Received %s from uuid: %s",                  (op_ret)?"RJT":"ACC", str);          ret = glusterd_friend_find (rsp.uuid, NULL, &peerinfo); @@ -386,7 +463,7 @@ glusterd3_1_stage_op_cbk (struct rpc_req *req, struct iovec *iov,                  GF_ASSERT (0);          } -        if (op_ret)  +        if (op_ret)                  event_type = GD_OP_EVENT_RCVD_RJT;          else                  event_type = GD_OP_EVENT_RCVD_ACC; @@ -414,7 +491,7 @@ out:  }  int32_t -glusterd3_1_commit_op_cbk (struct rpc_req *req, struct iovec *iov,  +glusterd3_1_commit_op_cbk (struct rpc_req *req, struct iovec *iov,                            int count, void *myframe)  {          gd1_mgmt_commit_op_rsp         rsp   = {{0},}; @@ -444,8 +521,8 @@ glusterd3_1_commit_op_cbk (struct rpc_req *req, struct iovec *iov,          op_ret = rsp.op_ret; -        gf_log ("glusterd", GF_LOG_NORMAL,  -                "Received %s from uuid: %s",  +        gf_log ("glusterd", GF_LOG_NORMAL, +                "Received %s from uuid: %s",                  (op_ret)?"RJT":"ACC", str);          ret = glusterd_friend_find (rsp.uuid, NULL, &peerinfo); @@ -454,7 +531,7 @@ glusterd3_1_commit_op_cbk (struct rpc_req *req, struct iovec *iov,                  GF_ASSERT (0);          } -        if (op_ret)  +        if (op_ret)                  event_type = GD_OP_EVENT_RCVD_RJT;          else                  event_type = GD_OP_EVENT_RCVD_ACC; @@ -484,7 +561,7 @@ out:  int32_t -glusterd3_1_probe (call_frame_t *frame, xlator_t *this,  +glusterd3_1_probe (call_frame_t *frame, xlator_t *this,                     void *data)  {          gd1_mgmt_probe_req      req = {{0},}; @@ -508,7 +585,7 @@ glusterd3_1_probe (call_frame_t *frame, xlator_t *this,          if (ret) {                  //We should not reach this state ideally                  GF_ASSERT (0); -                goto out;  +                goto out;          }          uuid_copy (req.uuid, priv->uuid); @@ -526,7 +603,7 @@ out:  int32_t -glusterd3_1_friend_add (call_frame_t *frame, xlator_t *this,  +glusterd3_1_friend_add (call_frame_t *frame, xlator_t *this,                          void *data)  {          gd1_mgmt_friend_req     req = {{0},}; @@ -546,7 +623,7 @@ glusterd3_1_friend_add (call_frame_t *frame, xlator_t *this,          priv = this->private;          GF_ASSERT (priv); -         +          ctx = event->ctx;          peerinfo = event->peerinfo; @@ -565,7 +642,47 @@ out:  }  int32_t -glusterd3_1_cluster_lock (call_frame_t *frame, xlator_t *this,  +glusterd3_1_friend_remove (call_frame_t *frame, xlator_t *this, +                           void *data) +{ +        gd1_mgmt_friend_req             req = {{0},}; +        int                             ret = 0; +        glusterd_peerinfo_t             *peerinfo = NULL; +        glusterd_conf_t                 *priv = NULL; +        glusterd_friend_sm_event_t      *event = NULL; +        glusterd_friend_req_ctx_t       *ctx = NULL; + + +        if (!frame || !this || !data) { +                ret = -1; +                goto out; +        } + +        event = data; +        priv = this->private; + +        GF_ASSERT (priv); + +        ctx = event->ctx; + +        peerinfo = event->peerinfo; + +        uuid_copy (req.uuid, priv->uuid); +        req.hostname = peerinfo->hostname; + +        ret = glusterd_submit_request (peerinfo, &req, frame, priv->mgmt, +                                       GD_MGMT_FRIEND_REMOVE, +                                       NULL, gd_xdr_from_mgmt_friend_req, +                                       this, glusterd3_1_friend_remove_cbk); + +out: +        gf_log ("glusterd", GF_LOG_DEBUG, "Returning %d", ret); +        return ret; +} + + +int32_t +glusterd3_1_cluster_lock (call_frame_t *frame, xlator_t *this,                             void *data)  {          gd1_mgmt_cluster_lock_req       req = {{0},}; @@ -587,7 +704,7 @@ glusterd3_1_cluster_lock (call_frame_t *frame, xlator_t *this,          list_for_each_entry (peerinfo, &priv->peers, uuid_list) {                  GF_ASSERT (peerinfo); -                if (peerinfo->state.state != GD_FRIEND_STATE_BEFRIENDED)  +                if (peerinfo->state.state != GD_FRIEND_STATE_BEFRIENDED)                          continue;                  dummy_frame = create_frame (this, this->ctx->pool); @@ -595,9 +712,9 @@ glusterd3_1_cluster_lock (call_frame_t *frame, xlator_t *this,                  if (!dummy_frame)                          continue; -                ret = glusterd_submit_request (peerinfo, &req, dummy_frame,  +                ret = glusterd_submit_request (peerinfo, &req, dummy_frame,                                          priv->mgmt, GD_MGMT_CLUSTER_LOCK, -                                        NULL,  +                                        NULL,                                          gd_xdr_from_mgmt_cluster_lock_req,                                          this, glusterd3_1_cluster_lock_cbk);                  if (!ret) @@ -615,7 +732,7 @@ out:  }  int32_t -glusterd3_1_cluster_unlock (call_frame_t *frame, xlator_t *this,  +glusterd3_1_cluster_unlock (call_frame_t *frame, xlator_t *this,                              void *data)  {          gd1_mgmt_cluster_lock_req       req = {{0},}; @@ -638,7 +755,7 @@ glusterd3_1_cluster_unlock (call_frame_t *frame, xlator_t *this,          list_for_each_entry (peerinfo, &priv->peers, uuid_list) {                  GF_ASSERT (peerinfo); -                if (peerinfo->state.state != GD_FRIEND_STATE_BEFRIENDED)  +                if (peerinfo->state.state != GD_FRIEND_STATE_BEFRIENDED)                          continue;                  dummy_frame = create_frame (this, this->ctx->pool); @@ -646,9 +763,9 @@ glusterd3_1_cluster_unlock (call_frame_t *frame, xlator_t *this,                  if (!dummy_frame)                          continue; -                ret = glusterd_submit_request (peerinfo, &req, dummy_frame,  +                ret = glusterd_submit_request (peerinfo, &req, dummy_frame,                                          priv->mgmt, GD_MGMT_CLUSTER_UNLOCK, -                                        NULL,  +                                        NULL,                                          gd_xdr_from_mgmt_cluster_unlock_req,                                          this, glusterd3_1_cluster_unlock_cbk);                  if (!ret) @@ -667,7 +784,7 @@ out:  }  int32_t -glusterd3_1_stage_op (call_frame_t *frame, xlator_t *this,  +glusterd3_1_stage_op (call_frame_t *frame, xlator_t *this,                        void *data)  {          gd1_mgmt_stage_op_req           *req = NULL; @@ -697,13 +814,13 @@ glusterd3_1_stage_op (call_frame_t *frame, xlator_t *this,                  //No pending ops, inject stage_acc                  glusterd_op_sm_event_t  *event = NULL; -         -                ret = glusterd_op_sm_new_event (GD_OP_EVENT_STAGE_ACC,  + +                ret = glusterd_op_sm_new_event (GD_OP_EVENT_STAGE_ACC,                                                  &event);                  if (ret)                          goto out; -         +                  ret = glusterd_op_sm_inject_event (event);                  return ret; @@ -718,7 +835,7 @@ glusterd3_1_stage_op (call_frame_t *frame, xlator_t *this,          list_for_each_entry (peerinfo, &priv->peers, uuid_list) {                  GF_ASSERT (peerinfo); -                if (peerinfo->state.state != GD_FRIEND_STATE_BEFRIENDED)  +                if (peerinfo->state.state != GD_FRIEND_STATE_BEFRIENDED)                          continue;                  dummy_frame = create_frame (this, this->ctx->pool); @@ -726,14 +843,14 @@ glusterd3_1_stage_op (call_frame_t *frame, xlator_t *this,                  if (!dummy_frame)                          continue; -                ret = glusterd_submit_request (peerinfo, req, dummy_frame,  +                ret = glusterd_submit_request (peerinfo, req, dummy_frame,                                                  priv->mgmt, GD_MGMT_STAGE_OP, -                                                NULL,  +                                                NULL,                                                  gd_xdr_from_mgmt_stage_op_req,                                                  this, glusterd3_1_stage_op_cbk);                  if (!ret)                          pending_peer++; -                //TODO: Instead of keeping count, maintain a list of pending  +                //TODO: Instead of keeping count, maintain a list of pending                  //UUIDs.          } @@ -747,7 +864,7 @@ out:  }  int32_t -glusterd3_1_commit_op (call_frame_t *frame, xlator_t *this,  +glusterd3_1_commit_op (call_frame_t *frame, xlator_t *this,                        void *data)  {          gd1_mgmt_commit_op_req          *req = NULL; @@ -777,13 +894,13 @@ glusterd3_1_commit_op (call_frame_t *frame, xlator_t *this,                  //No pending ops, inject stage_acc                  glusterd_op_sm_event_t  *event = NULL; -         -                ret = glusterd_op_sm_new_event (GD_OP_EVENT_COMMIT_ACC,  + +                ret = glusterd_op_sm_new_event (GD_OP_EVENT_COMMIT_ACC,                                                  &event);                  if (ret)                          goto out; -         +                  ret = glusterd_op_sm_inject_event (event);                  return ret; @@ -798,7 +915,7 @@ glusterd3_1_commit_op (call_frame_t *frame, xlator_t *this,          list_for_each_entry (peerinfo, &priv->peers, uuid_list) {                  GF_ASSERT (peerinfo); -                if (peerinfo->state.state != GD_FRIEND_STATE_BEFRIENDED)  +                if (peerinfo->state.state != GD_FRIEND_STATE_BEFRIENDED)                          continue;                  dummy_frame = create_frame (this, this->ctx->pool); @@ -806,14 +923,14 @@ glusterd3_1_commit_op (call_frame_t *frame, xlator_t *this,                  if (!dummy_frame)                          continue; -                ret = glusterd_submit_request (peerinfo, req, dummy_frame,  +                ret = glusterd_submit_request (peerinfo, req, dummy_frame,                                                  priv->mgmt, GD_MGMT_COMMIT_OP, -                                                NULL,  +                                                NULL,                                                  gd_xdr_from_mgmt_commit_op_req,                                                  this, glusterd3_1_commit_op_cbk);                  if (!ret)                          pending_peer++; -                //TODO: Instead of keeping count, maintain a list of pending  +                //TODO: Instead of keeping count, maintain a list of pending                  //UUIDs.          } @@ -869,6 +986,18 @@ glusterd_handle_rpc_msg (rpcsvc_request_t *req)                          ret = glusterd_handle_create_volume (req);                          break; +                case GD_MGMT_CLI_DEPROBE: +                        ret = glusterd_handle_cli_deprobe (req); +                        break; + +                case GD_MGMT_FRIEND_REMOVE: +                        ret = glusterd_handle_incoming_unfriend_req (req); +                        break; + +                case GD_MGMT_CLI_LIST_FRIENDS: +                        ret = glusterd_handle_cli_list_friends (req); +                        break; +                  default:                          GF_ASSERT (0);          } @@ -884,20 +1013,23 @@ glusterd_handle_rpc_msg (rpcsvc_request_t *req)  rpcsvc_actor_t glusterd1_mgmt_actors[] = {          [GD_MGMT_NULL]        = { "NULL",       GD_MGMT_NULL, glusterd_null, NULL, NULL}, -        [GD_MGMT_PROBE_QUERY] = { "PROBE_QUERY", GD_MGMT_PROBE_QUERY, glusterd_handle_rpc_msg, NULL, NULL},  -        [GD_MGMT_FRIEND_ADD] = { "FRIEND_ADD", GD_MGMT_FRIEND_ADD, glusterd_handle_rpc_msg, NULL, NULL},  +        [GD_MGMT_PROBE_QUERY] = { "PROBE_QUERY", GD_MGMT_PROBE_QUERY, glusterd_handle_rpc_msg, NULL, NULL}, +        [GD_MGMT_FRIEND_ADD] = { "FRIEND_ADD", GD_MGMT_FRIEND_ADD, glusterd_handle_rpc_msg, NULL, NULL}, +        [GD_MGMT_FRIEND_REMOVE] = { "FRIEND_REMOVE", GD_MGMT_FRIEND_REMOVE, glusterd_handle_rpc_msg, NULL, NULL},          [GD_MGMT_CLUSTER_LOCK] = { "CLUSTER_LOCK", GD_MGMT_CLUSTER_LOCK, glusterd_handle_rpc_msg, NULL, NULL},          [GD_MGMT_CLUSTER_UNLOCK] = { "CLUSTER_UNLOCK", GD_MGMT_CLUSTER_UNLOCK, glusterd_handle_rpc_msg, NULL, NULL},          [GD_MGMT_STAGE_OP] = { "STAGE_OP", GD_MGMT_STAGE_OP, glusterd_handle_rpc_msg, NULL, NULL},          [GD_MGMT_COMMIT_OP] = { "COMMIT_OP", GD_MGMT_COMMIT_OP, glusterd_handle_rpc_msg, NULL, NULL},          [GD_MGMT_CLI_PROBE] = { "CLI_PROBE", GD_MGMT_CLI_PROBE, glusterd_handle_rpc_msg, NULL, NULL},          [GD_MGMT_CLI_CREATE_VOLUME] = { "CLI_CREATE_VOLUME", GD_MGMT_CLI_CREATE_VOLUME, glusterd_handle_rpc_msg, NULL, NULL}, +        [GD_MGMT_CLI_DEPROBE] = { "FRIEND_REMOVE", GD_MGMT_CLI_DEPROBE, glusterd_handle_rpc_msg, NULL, NULL}, +        [GD_MGMT_CLI_LIST_FRIENDS] = { "LIST_FRIENDS", GD_MGMT_CLI_LIST_FRIENDS, glusterd_handle_rpc_msg, NULL, NULL},  };  /*rpcsvc_actor_t glusterd1_mgmt_actors[] = {          [GD_MGMT_NULL]        = { "NULL",       GD_MGMT_NULL, glusterd_null, NULL, NULL}, -        [GD_MGMT_PROBE_QUERY] = { "PROBE_QUERY", GD_MGMT_PROBE_QUERY, glusterd_handle_probe_query, NULL, NULL},  -        [GD_MGMT_FRIEND_ADD] = { "FRIEND_ADD", GD_MGMT_FRIEND_ADD, glusterd_handle_incoming_friend_req, NULL, NULL},  +        [GD_MGMT_PROBE_QUERY] = { "PROBE_QUERY", GD_MGMT_PROBE_QUERY, glusterd_handle_probe_query, NULL, NULL}, +        [GD_MGMT_FRIEND_ADD] = { "FRIEND_ADD", GD_MGMT_FRIEND_ADD, glusterd_handle_incoming_friend_req, NULL, NULL},          [GD_MGMT_CLUSTER_LOCK] = { "CLUSTER_LOCK", GD_MGMT_CLUSTER_LOCK, glusterd_handle_cluster_lock, NULL, NULL},          [GD_MGMT_CLUSTER_UNLOCK] = { "CLUSTER_UNLOCK", GD_MGMT_CLUSTER_UNLOCK, glusterd_handle_cluster_unlock, NULL, NULL},          [GD_MGMT_STAGE_OP] = { "STAGE_OP", GD_MGMT_STAGE_OP, glusterd_handle_stage_op, NULL, NULL}, @@ -924,6 +1056,7 @@ struct rpc_clnt_procedure glusterd3_1_clnt_mgmt_actors[GD_MGMT_MAXVALUE] = {          [GD_MGMT_CLUSTER_UNLOCK] = {"CLUSTER_UNLOCK", glusterd3_1_cluster_unlock},          [GD_MGMT_STAGE_OP] = {"STAGE_OP", glusterd3_1_stage_op},          [GD_MGMT_COMMIT_OP] = {"COMMIT_OP", glusterd3_1_commit_op}, +        [GD_MGMT_FRIEND_REMOVE]  = { "FRIEND_REMOVE",  glusterd3_1_friend_remove},  //        [GF_FOP_GETSPEC]     = { "GETSPEC",   client_getspec, client_getspec_cbk },  }; diff --git a/xlators/protocol/lib/src/cli-xdr.c b/xlators/protocol/lib/src/cli-xdr.c index c6a351b124f..ba9565261c1 100644 --- a/xlators/protocol/lib/src/cli-xdr.c +++ b/xlators/protocol/lib/src/cli-xdr.c @@ -36,6 +36,12 @@ gf_xdr_to_cli_probe_req (struct iovec inmsg, void *args)                                 (xdrproc_t)xdr_gf1_cli_probe_req);  } +ssize_t +gf_xdr_to_cli_probe_rsp (struct iovec inmsg, void *args) +{ +        return xdr_to_generic (inmsg, (void *)args, +                               (xdrproc_t)xdr_gf1_cli_probe_rsp); +}  ssize_t  gf_xdr_from_cli_probe_req (struct iovec outmsg, void *req) @@ -44,8 +50,64 @@ gf_xdr_from_cli_probe_req (struct iovec outmsg, void *req)                                        (xdrproc_t)xdr_gf1_cli_probe_req);  } +ssize_t +gf_xdr_serialize_cli_deprobe_rsp (struct iovec outmsg, void *rsp) +{ +        return xdr_serialize_generic (outmsg, (void *)rsp, +                                      (xdrproc_t)xdr_gf1_cli_deprobe_rsp); + +} + +ssize_t +gf_xdr_to_cli_deprobe_req (struct iovec inmsg, void *args) +{ +        return xdr_to_generic (inmsg, (void *)args, +                               (xdrproc_t)xdr_gf1_cli_deprobe_req); +} + +ssize_t +gf_xdr_to_cli_deprobe_rsp (struct iovec inmsg, void *args) +{ +        return xdr_to_generic (inmsg, (void *)args, +                               (xdrproc_t)xdr_gf1_cli_deprobe_rsp); +} + +ssize_t +gf_xdr_from_cli_deprobe_req (struct iovec outmsg, void *req) +{ +        return xdr_serialize_generic (outmsg, (void *)req, +                                      (xdrproc_t)xdr_gf1_cli_deprobe_req); +} + +ssize_t +gf_xdr_serialize_cli_peer_list_rsp (struct iovec outmsg, void *rsp) +{ +        return xdr_serialize_generic (outmsg, (void *)rsp, +                                      (xdrproc_t)xdr_gf1_cli_peer_list_rsp); + +} + +ssize_t +gf_xdr_to_cli_peer_list_req (struct iovec inmsg, void *args) +{ +        return xdr_to_generic (inmsg, (void *)args, +                               (xdrproc_t)xdr_gf1_cli_peer_list_req); +} + +ssize_t +gf_xdr_to_cli_peer_list_rsp (struct iovec inmsg, void *args) +{ +        return xdr_to_generic (inmsg, (void *)args, +                               (xdrproc_t)xdr_gf1_cli_peer_list_rsp); +}  ssize_t +gf_xdr_from_cli_peer_list_req (struct iovec outmsg, void *req) +{ +        return xdr_serialize_generic (outmsg, (void *)req, +                                      (xdrproc_t)xdr_gf1_cli_peer_list_req); +} +ssize_t  gf_xdr_serialize_cli_create_vol_rsp (struct iovec outmsg, void *rsp)  {          return xdr_serialize_generic (outmsg, (void *)rsp, @@ -60,6 +122,12 @@ gf_xdr_to_cli_create_vol_req (struct iovec inmsg, void *args)                                 (xdrproc_t)xdr_gf1_cli_create_vol_req);  } +ssize_t +gf_xdr_to_cli_create_vol_rsp (struct iovec inmsg, void *args) +{ +        return xdr_to_generic (inmsg, (void *)args, +                               (xdrproc_t)xdr_gf1_cli_create_vol_rsp); +}  ssize_t  gf_xdr_from_cli_create_vol_req (struct iovec outmsg, void *req) @@ -86,6 +154,13 @@ gf_xdr_to_cli_delete_vol_req (struct iovec inmsg, void *args)  ssize_t +gf_xdr_to_cli_delete_vol_rsp (struct iovec inmsg, void *args) +{ +        return xdr_to_generic (inmsg, (void *)args, +                               (xdrproc_t)xdr_gf1_cli_delete_vol_rsp); +} + +ssize_t  gf_xdr_from_cli_delete_vol_req (struct iovec outmsg, void *req)  {          return xdr_serialize_generic (outmsg, (void *)req, @@ -107,6 +182,12 @@ gf_xdr_to_cli_start_vol_req (struct iovec inmsg, void *args)                                 (xdrproc_t)xdr_gf1_cli_start_vol_req);  } +ssize_t +gf_xdr_to_cli_start_vol_rsp (struct iovec inmsg, void *args) +{ +        return xdr_to_generic (inmsg, (void *)args, +                               (xdrproc_t)xdr_gf1_cli_start_vol_rsp); +}  ssize_t  gf_xdr_from_cli_start_vol_req (struct iovec outmsg, void *req) @@ -131,6 +212,12 @@ gf_xdr_to_cli_stop_vol_req (struct iovec inmsg, void *args)                                 (xdrproc_t)xdr_gf1_cli_stop_vol_req);  } +ssize_t +gf_xdr_to_cli_stop_vol_rsp (struct iovec inmsg, void *args) +{ +        return xdr_to_generic (inmsg, (void *)args, +                               (xdrproc_t)xdr_gf1_cli_stop_vol_rsp); +}  ssize_t  gf_xdr_from_cli_stop_vol_req (struct iovec outmsg, void *req) @@ -155,6 +242,12 @@ gf_xdr_to_cli_rename_vol_req (struct iovec inmsg, void *args)                                 (xdrproc_t)xdr_gf1_cli_rename_vol_req);  } +ssize_t +gf_xdr_to_cli_rename_vol_rsp (struct iovec inmsg, void *args) +{ +        return xdr_to_generic (inmsg, (void *)args, +                               (xdrproc_t)xdr_gf1_cli_rename_vol_rsp); +}  ssize_t  gf_xdr_from_cli_rename_vol_req (struct iovec outmsg, void *req) @@ -173,13 +266,19 @@ gf_xdr_serialize_cli_defrag_vol_rsp (struct iovec outmsg, void *rsp)  }  ssize_t +gf_xdr_to_cli_defrag_vol_rsp (struct iovec inmsg, void *args) +{ +        return xdr_to_generic (inmsg, (void *)args, +                               (xdrproc_t)xdr_gf1_cli_defrag_vol_rsp); +} + +ssize_t  gf_xdr_to_cli_defrag_vol_req (struct iovec inmsg, void *args)  {          return xdr_to_generic (inmsg, (void *)args,                                 (xdrproc_t)xdr_gf1_cli_defrag_vol_req);  } -  ssize_t  gf_xdr_from_cli_defrag_vol_req (struct iovec outmsg, void *req)  { @@ -204,6 +303,12 @@ gf_xdr_to_cli_add_brick_req (struct iovec inmsg, void *args)                                 (xdrproc_t)xdr_gf1_cli_add_brick_req);  } +ssize_t +gf_xdr_to_cli_add_brick_rsp (struct iovec inmsg, void *args) +{ +        return xdr_to_generic (inmsg, (void *)args, +                               (xdrproc_t)xdr_gf1_cli_add_brick_rsp); +}  ssize_t  gf_xdr_from_cli_add_brick_req (struct iovec outmsg, void *req) @@ -230,6 +335,13 @@ gf_xdr_to_cli_remove_brick_req (struct iovec inmsg, void *args)  ssize_t +gf_xdr_to_cli_remove_brick_rsp (struct iovec inmsg, void *args) +{ +        return xdr_to_generic (inmsg, (void *)args, +                               (xdrproc_t)xdr_gf1_cli_remove_brick_rsp); +} + +ssize_t  gf_xdr_from_cli_remove_brick_req (struct iovec outmsg, void *req)  {          return xdr_serialize_generic (outmsg, (void *)req, @@ -252,6 +364,12 @@ gf_xdr_to_cli_replace_brick_req (struct iovec inmsg, void *args)                                 (xdrproc_t)xdr_gf1_cli_replace_brick_req);  } +ssize_t +gf_xdr_to_cli_replace_brick_rsp (struct iovec inmsg, void *args) +{ +        return xdr_to_generic (inmsg, (void *)args, +                               (xdrproc_t)xdr_gf1_cli_replace_brick_rsp); +}  ssize_t  gf_xdr_from_cli_replace_brick_req (struct iovec outmsg, void *req) @@ -275,6 +393,12 @@ gf_xdr_to_cli_set_vol_req (struct iovec inmsg, void *args)                                 (xdrproc_t)xdr_gf1_cli_set_vol_req);  } +ssize_t +gf_xdr_to_cli_set_vol_rsp (struct iovec inmsg, void *args) +{ +        return xdr_to_generic (inmsg, (void *)args, +                               (xdrproc_t)xdr_gf1_cli_set_vol_rsp); +}  ssize_t  gf_xdr_from_cli_set_vol_req (struct iovec outmsg, void *req) diff --git a/xlators/protocol/lib/src/cli-xdr.h b/xlators/protocol/lib/src/cli-xdr.h index 9705071bad4..2ec4f95241e 100644 --- a/xlators/protocol/lib/src/cli-xdr.h +++ b/xlators/protocol/lib/src/cli-xdr.h @@ -33,86 +33,140 @@ ssize_t  gf_xdr_to_cli_probe_req (struct iovec inmsg, void *args);  ssize_t +gf_xdr_to_cli_probe_rsp (struct iovec inmsg, void *args); + +ssize_t  gf_xdr_from_cli_probe_req (struct iovec outmsg, void *req);  ssize_t +gf_xdr_serialize_cli_deprobe_rsp (struct iovec outmsg, void *rsp); + +ssize_t +gf_xdr_to_cli_deprobe_req (struct iovec inmsg, void *args); + +ssize_t +gf_xdr_to_cli_deprobe_rsp (struct iovec inmsg, void *args); + +ssize_t +gf_xdr_from_cli_deprobe_req (struct iovec outmsg, void *req); + +ssize_t +gf_xdr_serialize_cli_peer_list_rsp (struct iovec outmsg, void *rsp); + +ssize_t +gf_xdr_to_cli_peer_list_req (struct iovec inmsg, void *args); + +ssize_t +gf_xdr_to_cli_peer_list_rsp (struct iovec inmsg, void *args); + +ssize_t +gf_xdr_from_cli_peer_list_req (struct iovec outmsg, void *req); + +ssize_t  gf_xdr_serialize_cli_create_vol_rsp (struct iovec outmsg, void *rsp); -   +  ssize_t  gf_xdr_to_cli_create_vol_req (struct iovec inmsg, void *args); -   + +ssize_t +gf_xdr_to_cli_create_vol_rsp (struct iovec inmsg, void *args); +  ssize_t  gf_xdr_from_cli_create_vol_req (struct iovec outmsg, void *req); -   +  ssize_t  gf_xdr_serialize_cli_delete_vol_rsp (struct iovec outmsg, void *rsp); -   +  ssize_t  gf_xdr_to_cli_delete_vol_req (struct iovec inmsg, void *args); -   + +ssize_t +gf_xdr_to_cli_delete_vol_rsp (struct iovec inmsg, void *args); +  ssize_t  gf_xdr_from_cli_delete_vol_req (struct iovec outmsg, void *req); -   +  ssize_t  gf_xdr_serialize_cli_start_vol_rsp (struct iovec outmsg, void *rsp); -   +  ssize_t  gf_xdr_to_cli_start_vol_req (struct iovec inmsg, void *args); -   + +ssize_t +gf_xdr_to_cli_start_vol_rsp (struct iovec inmsg, void *args); +  ssize_t  gf_xdr_from_cli_start_vol_req (struct iovec outmsg, void *req); -   +  ssize_t  gf_xdr_serialize_cli_stop_vol_rsp (struct iovec outmsg, void *rsp); -   +  ssize_t  gf_xdr_to_cli_stop_vol_req (struct iovec inmsg, void *args); -   + +ssize_t +gf_xdr_to_cli_stop_vol_rsp (struct iovec inmsg, void *args); +  ssize_t  gf_xdr_from_cli_stop_vol_req (struct iovec outmsg, void *req); -   +  ssize_t  gf_xdr_serialize_cli_rename_vol_rsp (struct iovec outmsg, void *rsp); -   +  ssize_t  gf_xdr_to_cli_rename_vol_req (struct iovec inmsg, void *args); -   + +ssize_t +gf_xdr_to_cli_rename_vol_rsp (struct iovec inmsg, void *args); +  ssize_t  gf_xdr_from_cli_rename_vol_req (struct iovec outmsg, void *req); -   +  ssize_t  gf_xdr_serialize_cli_defrag_vol_rsp (struct iovec outmsg, void *rsp); -   +  ssize_t  gf_xdr_to_cli_defrag_vol_req (struct iovec inmsg, void *args); -   +  ssize_t  gf_xdr_from_cli_defrag_vol_req (struct iovec outmsg, void *req); -   + +ssize_t +gf_xdr_to_cli_defrag_vol_rsp (struct iovec inmsg, void *args); +  ssize_t  gf_xdr_serialize_cli_add_brick_rsp (struct iovec outmsg, void *rsp); -   +  ssize_t  gf_xdr_to_cli_add_brick_req (struct iovec inmsg, void *args); -   + +ssize_t +gf_xdr_to_cli_add_brick_rsp (struct iovec inmsg, void *args); +  ssize_t  gf_xdr_from_cli_add_brick_req (struct iovec outmsg, void *req); -   +  ssize_t  gf_xdr_serialize_cli_remove_brick_rsp (struct iovec outmsg, void *rsp); -   +  ssize_t  gf_xdr_to_cli_remove_brick_req (struct iovec inmsg, void *args); -   + +ssize_t +gf_xdr_to_cli_remove_brick_rsp (struct iovec inmsg, void *args); +  ssize_t  gf_xdr_from_cli_remove_brick_req (struct iovec outmsg, void *req); -   +  ssize_t  gf_xdr_serialize_cli_replace_brick_rsp (struct iovec outmsg, void *rsp); -   +  ssize_t  gf_xdr_to_cli_replace_brick_req (struct iovec inmsg, void *args); -   + +ssize_t +gf_xdr_to_cli_replace_brick_rsp (struct iovec inmsg, void *args); +  ssize_t  gf_xdr_from_cli_replace_brick_req (struct iovec outmsg, void *req); @@ -122,6 +176,8 @@ gf_xdr_serialize_cli_set_vol_rsp (struct iovec outmsg, void *rsp);  ssize_t  gf_xdr_to_cli_set_vol_req (struct iovec inmsg, void *args); +ssize_t +gf_xdr_to_cli_set_vol_rsp (struct iovec inmsg, void *args);  ssize_t  gf_xdr_from_cli_set_vol_req (struct iovec outmsg, void *req); diff --git a/xlators/protocol/lib/src/gluster1.h b/xlators/protocol/lib/src/gluster1.h index 359fdcf42ba..81948b34aac 100644 --- a/xlators/protocol/lib/src/gluster1.h +++ b/xlators/protocol/lib/src/gluster1.h @@ -31,6 +31,11 @@ enum gf1_cli_replace_op {  };  typedef enum gf1_cli_replace_op gf1_cli_replace_op; +enum gf1_cli_enum_friends_list { +	GF_CLI_LIST_ALL = 1, +}; +typedef enum gf1_cli_enum_friends_list gf1_cli_enum_friends_list; +  struct gf1_cli_probe_req {  	char *hostname;  }; @@ -43,6 +48,37 @@ struct gf1_cli_probe_rsp {  };  typedef struct gf1_cli_probe_rsp gf1_cli_probe_rsp; +struct gf1_cli_deprobe_req { +	char *hostname; +}; +typedef struct gf1_cli_deprobe_req gf1_cli_deprobe_req; + +struct gf1_cli_deprobe_rsp { +	int op_ret; +	int op_errno; +	char *hostname; +}; +typedef struct gf1_cli_deprobe_rsp gf1_cli_deprobe_rsp; + +struct gf1_cli_peer_list_req { +	int flags; +	struct { +		u_int dict_len; +		char *dict_val; +	} dict; +}; +typedef struct gf1_cli_peer_list_req gf1_cli_peer_list_req; + +struct gf1_cli_peer_list_rsp { +	int op_ret; +	int op_errno; +	struct { +		u_int friends_len; +		char *friends_val; +	} friends; +}; +typedef struct gf1_cli_peer_list_rsp gf1_cli_peer_list_rsp; +  struct gf1_cli_create_vol_req {  	char *volname;  	gf1_cluster_type type; @@ -200,8 +236,13 @@ typedef struct gf1_cli_set_vol_rsp gf1_cli_set_vol_rsp;  #if defined(__STDC__) || defined(__cplusplus)  extern  bool_t xdr_gf1_cluster_type (XDR *, gf1_cluster_type*);  extern  bool_t xdr_gf1_cli_replace_op (XDR *, gf1_cli_replace_op*); +extern  bool_t xdr_gf1_cli_enum_friends_list (XDR *, gf1_cli_enum_friends_list*);  extern  bool_t xdr_gf1_cli_probe_req (XDR *, gf1_cli_probe_req*);  extern  bool_t xdr_gf1_cli_probe_rsp (XDR *, gf1_cli_probe_rsp*); +extern  bool_t xdr_gf1_cli_deprobe_req (XDR *, gf1_cli_deprobe_req*); +extern  bool_t xdr_gf1_cli_deprobe_rsp (XDR *, gf1_cli_deprobe_rsp*); +extern  bool_t xdr_gf1_cli_peer_list_req (XDR *, gf1_cli_peer_list_req*); +extern  bool_t xdr_gf1_cli_peer_list_rsp (XDR *, gf1_cli_peer_list_rsp*);  extern  bool_t xdr_gf1_cli_create_vol_req (XDR *, gf1_cli_create_vol_req*);  extern  bool_t xdr_gf1_cli_create_vol_rsp (XDR *, gf1_cli_create_vol_rsp*);  extern  bool_t xdr_gf1_cli_delete_vol_req (XDR *, gf1_cli_delete_vol_req*); @@ -226,8 +267,13 @@ extern  bool_t xdr_gf1_cli_set_vol_rsp (XDR *, gf1_cli_set_vol_rsp*);  #else /* K&R C */  extern bool_t xdr_gf1_cluster_type ();  extern bool_t xdr_gf1_cli_replace_op (); +extern bool_t xdr_gf1_cli_enum_friends_list ();  extern bool_t xdr_gf1_cli_probe_req ();  extern bool_t xdr_gf1_cli_probe_rsp (); +extern bool_t xdr_gf1_cli_deprobe_req (); +extern bool_t xdr_gf1_cli_deprobe_rsp (); +extern bool_t xdr_gf1_cli_peer_list_req (); +extern bool_t xdr_gf1_cli_peer_list_rsp ();  extern bool_t xdr_gf1_cli_create_vol_req ();  extern bool_t xdr_gf1_cli_create_vol_rsp ();  extern bool_t xdr_gf1_cli_delete_vol_req (); diff --git a/xlators/protocol/lib/src/gluster1.x b/xlators/protocol/lib/src/gluster1.x index 1fe7ef14f6b..a8af1b7d658 100644 --- a/xlators/protocol/lib/src/gluster1.x +++ b/xlators/protocol/lib/src/gluster1.x @@ -13,6 +13,10 @@          GF_REPLACE_OP_STATUS  } ; +enum gf1_cli_enum_friends_list { +        GF_CLI_LIST_ALL = 1 +} ; +   struct gf1_cli_probe_req {          string  hostname<>;  }  ; @@ -23,6 +27,27 @@          string  hostname<>;  }  ; + struct gf1_cli_deprobe_req { +        string  hostname<>; +}  ; + + struct gf1_cli_deprobe_rsp { +        int     op_ret; +        int     op_errno; +        string  hostname<>; +}  ; + +struct gf1_cli_peer_list_req { +        int     flags; +        opaque  dict<>; +}  ; + +struct gf1_cli_peer_list_rsp { +        int     op_ret; +        int     op_errno; +        opaque  friends<>; +} ; +   struct gf1_cli_create_vol_req {          string  volname<>;          gf1_cluster_type type; @@ -39,7 +64,7 @@   struct gf1_cli_delete_vol_req {          string volname<>;  }  ; -         +   struct gf1_cli_delete_vol_rsp {          int     op_ret;          int     op_errno; diff --git a/xlators/protocol/lib/src/gluster1_xdr.c b/xlators/protocol/lib/src/gluster1_xdr.c index 2cd83315ac8..9a44b9989ae 100644 --- a/xlators/protocol/lib/src/gluster1_xdr.c +++ b/xlators/protocol/lib/src/gluster1_xdr.c @@ -8,6 +8,7 @@  bool_t  xdr_gf1_cluster_type (XDR *xdrs, gf1_cluster_type *objp)  { +  	 if (!xdr_enum (xdrs, (enum_t *) objp))  		 return FALSE;  	return TRUE; @@ -16,6 +17,16 @@ xdr_gf1_cluster_type (XDR *xdrs, gf1_cluster_type *objp)  bool_t  xdr_gf1_cli_replace_op (XDR *xdrs, gf1_cli_replace_op *objp)  { + +	 if (!xdr_enum (xdrs, (enum_t *) objp)) +		 return FALSE; +	return TRUE; +} + +bool_t +xdr_gf1_cli_enum_friends_list (XDR *xdrs, gf1_cli_enum_friends_list *objp) +{ +  	 if (!xdr_enum (xdrs, (enum_t *) objp))  		 return FALSE;  	return TRUE; @@ -24,6 +35,7 @@ xdr_gf1_cli_replace_op (XDR *xdrs, gf1_cli_replace_op *objp)  bool_t  xdr_gf1_cli_probe_req (XDR *xdrs, gf1_cli_probe_req *objp)  { +  	 if (!xdr_string (xdrs, &objp->hostname, ~0))  		 return FALSE;  	return TRUE; @@ -32,6 +44,29 @@ xdr_gf1_cli_probe_req (XDR *xdrs, gf1_cli_probe_req *objp)  bool_t  xdr_gf1_cli_probe_rsp (XDR *xdrs, gf1_cli_probe_rsp *objp)  { + +	 if (!xdr_int (xdrs, &objp->op_ret)) +		 return FALSE; +	 if (!xdr_int (xdrs, &objp->op_errno)) +		 return FALSE; +	 if (!xdr_string (xdrs, &objp->hostname, ~0)) +		 return FALSE; +	return TRUE; +} + +bool_t +xdr_gf1_cli_deprobe_req (XDR *xdrs, gf1_cli_deprobe_req *objp) +{ + +	 if (!xdr_string (xdrs, &objp->hostname, ~0)) +		 return FALSE; +	return TRUE; +} + +bool_t +xdr_gf1_cli_deprobe_rsp (XDR *xdrs, gf1_cli_deprobe_rsp *objp) +{ +  	 if (!xdr_int (xdrs, &objp->op_ret))  		 return FALSE;  	 if (!xdr_int (xdrs, &objp->op_errno)) @@ -42,8 +77,33 @@ xdr_gf1_cli_probe_rsp (XDR *xdrs, gf1_cli_probe_rsp *objp)  }  bool_t +xdr_gf1_cli_peer_list_req (XDR *xdrs, gf1_cli_peer_list_req *objp) +{ + +	 if (!xdr_int (xdrs, &objp->flags)) +		 return FALSE; +	 if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) +		 return FALSE; +	return TRUE; +} + +bool_t +xdr_gf1_cli_peer_list_rsp (XDR *xdrs, gf1_cli_peer_list_rsp *objp) +{ + +	 if (!xdr_int (xdrs, &objp->op_ret)) +		 return FALSE; +	 if (!xdr_int (xdrs, &objp->op_errno)) +		 return FALSE; +	 if (!xdr_bytes (xdrs, (char **)&objp->friends.friends_val, (u_int *) &objp->friends.friends_len, ~0)) +		 return FALSE; +	return TRUE; +} + +bool_t  xdr_gf1_cli_create_vol_req (XDR *xdrs, gf1_cli_create_vol_req *objp)  { +  	 if (!xdr_string (xdrs, &objp->volname, ~0))  		 return FALSE;  	 if (!xdr_gf1_cluster_type (xdrs, &objp->type)) @@ -58,6 +118,7 @@ xdr_gf1_cli_create_vol_req (XDR *xdrs, gf1_cli_create_vol_req *objp)  bool_t  xdr_gf1_cli_create_vol_rsp (XDR *xdrs, gf1_cli_create_vol_rsp *objp)  { +  	 if (!xdr_int (xdrs, &objp->op_ret))  		 return FALSE;  	 if (!xdr_int (xdrs, &objp->op_errno)) @@ -70,6 +131,7 @@ xdr_gf1_cli_create_vol_rsp (XDR *xdrs, gf1_cli_create_vol_rsp *objp)  bool_t  xdr_gf1_cli_delete_vol_req (XDR *xdrs, gf1_cli_delete_vol_req *objp)  { +  	 if (!xdr_string (xdrs, &objp->volname, ~0))  		 return FALSE;  	return TRUE; @@ -78,6 +140,7 @@ xdr_gf1_cli_delete_vol_req (XDR *xdrs, gf1_cli_delete_vol_req *objp)  bool_t  xdr_gf1_cli_delete_vol_rsp (XDR *xdrs, gf1_cli_delete_vol_rsp *objp)  { +  	 if (!xdr_int (xdrs, &objp->op_ret))  		 return FALSE;  	 if (!xdr_int (xdrs, &objp->op_errno)) @@ -90,6 +153,7 @@ xdr_gf1_cli_delete_vol_rsp (XDR *xdrs, gf1_cli_delete_vol_rsp *objp)  bool_t  xdr_gf1_cli_start_vol_req (XDR *xdrs, gf1_cli_start_vol_req *objp)  { +  	 if (!xdr_string (xdrs, &objp->volname, ~0))  		 return FALSE;  	return TRUE; @@ -98,6 +162,7 @@ xdr_gf1_cli_start_vol_req (XDR *xdrs, gf1_cli_start_vol_req *objp)  bool_t  xdr_gf1_cli_start_vol_rsp (XDR *xdrs, gf1_cli_start_vol_rsp *objp)  { +  	 if (!xdr_int (xdrs, &objp->op_ret))  		 return FALSE;  	 if (!xdr_int (xdrs, &objp->op_errno)) @@ -110,6 +175,7 @@ xdr_gf1_cli_start_vol_rsp (XDR *xdrs, gf1_cli_start_vol_rsp *objp)  bool_t  xdr_gf1_cli_stop_vol_req (XDR *xdrs, gf1_cli_stop_vol_req *objp)  { +  	 if (!xdr_string (xdrs, &objp->volname, ~0))  		 return FALSE;  	return TRUE; @@ -118,6 +184,7 @@ xdr_gf1_cli_stop_vol_req (XDR *xdrs, gf1_cli_stop_vol_req *objp)  bool_t  xdr_gf1_cli_stop_vol_rsp (XDR *xdrs, gf1_cli_stop_vol_rsp *objp)  { +  	 if (!xdr_int (xdrs, &objp->op_ret))  		 return FALSE;  	 if (!xdr_int (xdrs, &objp->op_errno)) @@ -130,6 +197,7 @@ xdr_gf1_cli_stop_vol_rsp (XDR *xdrs, gf1_cli_stop_vol_rsp *objp)  bool_t  xdr_gf1_cli_rename_vol_req (XDR *xdrs, gf1_cli_rename_vol_req *objp)  { +  	 if (!xdr_string (xdrs, &objp->old_volname, ~0))  		 return FALSE;  	 if (!xdr_string (xdrs, &objp->new_volname, ~0)) @@ -140,6 +208,7 @@ xdr_gf1_cli_rename_vol_req (XDR *xdrs, gf1_cli_rename_vol_req *objp)  bool_t  xdr_gf1_cli_rename_vol_rsp (XDR *xdrs, gf1_cli_rename_vol_rsp *objp)  { +  	 if (!xdr_int (xdrs, &objp->op_ret))  		 return FALSE;  	 if (!xdr_int (xdrs, &objp->op_errno)) @@ -152,6 +221,7 @@ xdr_gf1_cli_rename_vol_rsp (XDR *xdrs, gf1_cli_rename_vol_rsp *objp)  bool_t  xdr_gf1_cli_defrag_vol_req (XDR *xdrs, gf1_cli_defrag_vol_req *objp)  { +  	 if (!xdr_string (xdrs, &objp->volname, ~0))  		 return FALSE;  	return TRUE; @@ -160,6 +230,7 @@ xdr_gf1_cli_defrag_vol_req (XDR *xdrs, gf1_cli_defrag_vol_req *objp)  bool_t  xdr_gf1_cli_defrag_vol_rsp (XDR *xdrs, gf1_cli_defrag_vol_rsp *objp)  { +  	 if (!xdr_int (xdrs, &objp->op_ret))  		 return FALSE;  	 if (!xdr_int (xdrs, &objp->op_errno)) @@ -172,6 +243,7 @@ xdr_gf1_cli_defrag_vol_rsp (XDR *xdrs, gf1_cli_defrag_vol_rsp *objp)  bool_t  xdr_gf1_cli_add_brick_req (XDR *xdrs, gf1_cli_add_brick_req *objp)  { +  	 if (!xdr_string (xdrs, &objp->volname, ~0))  		 return FALSE;  	 if (!xdr_gf1_cluster_type (xdrs, &objp->type)) @@ -186,6 +258,7 @@ xdr_gf1_cli_add_brick_req (XDR *xdrs, gf1_cli_add_brick_req *objp)  bool_t  xdr_gf1_cli_add_brick_rsp (XDR *xdrs, gf1_cli_add_brick_rsp *objp)  { +  	 if (!xdr_int (xdrs, &objp->op_ret))  		 return FALSE;  	 if (!xdr_int (xdrs, &objp->op_errno)) @@ -198,6 +271,7 @@ xdr_gf1_cli_add_brick_rsp (XDR *xdrs, gf1_cli_add_brick_rsp *objp)  bool_t  xdr_gf1_cli_remove_brick_req (XDR *xdrs, gf1_cli_remove_brick_req *objp)  { +  	 if (!xdr_string (xdrs, &objp->volname, ~0))  		 return FALSE;  	 if (!xdr_gf1_cluster_type (xdrs, &objp->type)) @@ -212,6 +286,7 @@ xdr_gf1_cli_remove_brick_req (XDR *xdrs, gf1_cli_remove_brick_req *objp)  bool_t  xdr_gf1_cli_remove_brick_rsp (XDR *xdrs, gf1_cli_remove_brick_rsp *objp)  { +  	 if (!xdr_int (xdrs, &objp->op_ret))  		 return FALSE;  	 if (!xdr_int (xdrs, &objp->op_errno)) @@ -224,6 +299,7 @@ xdr_gf1_cli_remove_brick_rsp (XDR *xdrs, gf1_cli_remove_brick_rsp *objp)  bool_t  xdr_gf1_cli_replace_brick_req (XDR *xdrs, gf1_cli_replace_brick_req *objp)  { +  	 if (!xdr_string (xdrs, &objp->volname, ~0))  		 return FALSE;  	 if (!xdr_gf1_cli_replace_op (xdrs, &objp->op)) @@ -238,6 +314,7 @@ xdr_gf1_cli_replace_brick_req (XDR *xdrs, gf1_cli_replace_brick_req *objp)  bool_t  xdr_gf1_cli_replace_brick_rsp (XDR *xdrs, gf1_cli_replace_brick_rsp *objp)  { +  	 if (!xdr_int (xdrs, &objp->op_ret))  		 return FALSE;  	 if (!xdr_int (xdrs, &objp->op_errno)) @@ -250,6 +327,7 @@ xdr_gf1_cli_replace_brick_rsp (XDR *xdrs, gf1_cli_replace_brick_rsp *objp)  bool_t  xdr_gf1_cli_set_vol_req (XDR *xdrs, gf1_cli_set_vol_req *objp)  { +  	 if (!xdr_string (xdrs, &objp->volname, ~0))  		 return FALSE;  	 if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) @@ -260,6 +338,7 @@ xdr_gf1_cli_set_vol_req (XDR *xdrs, gf1_cli_set_vol_req *objp)  bool_t  xdr_gf1_cli_set_vol_rsp (XDR *xdrs, gf1_cli_set_vol_rsp *objp)  { +  	 if (!xdr_int (xdrs, &objp->op_ret))  		 return FALSE;  	 if (!xdr_int (xdrs, &objp->op_errno)) diff --git a/xlators/protocol/lib/src/protocol-common.h b/xlators/protocol/lib/src/protocol-common.h index 0cb62426c66..c4fc12a7042 100644 --- a/xlators/protocol/lib/src/protocol-common.h +++ b/xlators/protocol/lib/src/protocol-common.h @@ -83,7 +83,10 @@ enum gf_mgmt_procnum {          GD_MGMT_CLUSTER_UNLOCK,          GD_MGMT_STAGE_OP,          GD_MGMT_COMMIT_OP, +        GD_MGMT_FRIEND_REMOVE,          GD_MGMT_CLI_PROBE, +        GD_MGMT_CLI_DEPROBE, +        GD_MGMT_CLI_LIST_FRIENDS,          GD_MGMT_CLI_CREATE_VOLUME,          GD_MGMT_CLI_GET_VOLUME,          GD_MGMT_CLI_DELETE_VOLUME, @@ -101,6 +104,8 @@ enum gf_mgmt_procnum {  enum gf_cli_procnum {          GF1_CLI_NULL = GD_MGMT_MAXVALUE+1,    /* 0 */          GF1_CLI_PROBE, +        GF1_CLI_DEPROBE, +        GF1_CLI_LIST_FRIENDS,          GF1_CLI_CREATE_VOLUME,          GF1_CLI_GET_VOLUME,          GF1_CLI_DELETE_VOLUME,  | 
