From a60fc2ddc03134fb23c5ed5c0bcb195e1649416b Mon Sep 17 00:00:00 2001 From: Sanju Rakonde Date: Wed, 21 Feb 2018 12:46:25 +0530 Subject: glusterd: handling brick termination in brick-mux Problem: There's a race between the last glusterfs_handle_terminate() response sent to glusterd and the kill that happens immediately if the terminated brick is the last brick. Solution: When it is a last brick for the brick process, instead of glusterfsd killing itself, glusterd will kill the process in case of brick multiplexing. And also changing gf_attach utility accordingly. Change-Id: I386c19ca592536daa71294a13d9fc89a26d7e8c0 fixes: bz#1545048 BUG: 1545048 Signed-off-by: Sanju Rakonde --- glusterfsd/src/gf_attach.c | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) (limited to 'glusterfsd/src/gf_attach.c') diff --git a/glusterfsd/src/gf_attach.c b/glusterfsd/src/gf_attach.c index 3f248292ddf..0eb4868263b 100644 --- a/glusterfsd/src/gf_attach.c +++ b/glusterfsd/src/gf_attach.c @@ -11,6 +11,9 @@ #include #include #include +#include +#include +#include //#include "config.h" #include "glusterfs.h" @@ -23,6 +26,7 @@ int done = 0; int rpc_status; +glfs_t *fs; struct rpc_clnt_procedure gf_attach_actors[GLUSTERD_BRICK_MAXVALUE] = { [GLUSTERD_BRICK_NULL] = {"NULL", NULL }, @@ -71,11 +75,43 @@ my_notify (struct rpc_clnt *rpc, void *mydata, } int32_t -my_callback (struct rpc_req *req, struct iovec *iov, int count, void *frame) +my_callback (struct rpc_req *req, struct iovec *iov, int count, void *v_frame) { + gd1_mgmt_brick_op_rsp rsp; + dict_t *dict = NULL; + pid_t pid = -1; + int ret = -1; + xlator_t *this = NULL; + + this = fs->ctx->master; + memset (&rsp, 0, sizeof (rsp)); + + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gd1_mgmt_brick_op_rsp); + + if (ret < 0) { + fprintf (stderr, "xdr decoding failed\n"); + goto out; + } + GF_PROTOCOL_DICT_UNSERIALIZE (this, dict, + (rsp.output.output_val), + (rsp.output.output_len), + ret, rsp.op_errno, out); + if (dict) { + if (dict_get_int32 (dict, "last_brick_terminated", &pid) == 0) { + int status = 0; + + gf_log ("gf_attach", GF_LOG_INFO, "Killing %d", pid); + kill (pid, SIGTERM); + waitpid (pid, &status, 0); + } + dict_unref (dict); + } + rpc_status = req->rpc_status; done = 1; - return 0; + ret = 0; +out: + return ret; } /* copied from gd_syncop_submit_request */ @@ -170,7 +206,6 @@ usage (char *prog) int main (int argc, char *argv[]) { - glfs_t *fs; struct rpc_clnt *rpc; dict_t *options; int ret; -- cgit