From 953bdf315ffcca73e4aad3eafb5f25a0457947ca Mon Sep 17 00:00:00 2001
From: Atin Mukherjee <amukherj@redhat.com>
Date: Wed, 3 May 2017 12:17:30 +0530
Subject: [PATCH 421/426] glusterd: cleanup pidfile on pmap signout
This patch ensures
1. brick pidfile is cleaned up on pmap signout
2. pmap signout evemt is sent for all the bricks when a brick process
shuts down.
>Reviewed-on: https://review.gluster.org/17168
>Smoke: Gluster Build System <jenkins@build.gluster.org>
>NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
>CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
>Reviewed-by: Jeff Darcy <jeff@pl.atyp.us>
Change-Id: I7606a60775b484651d4b9743b6037b40323931a2
BUG: 1443972
Signed-off-by: Atin Mukherjee <amukherj@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/105595
Reviewed-by: Prashanth Pai <ppai@redhat.com>
---
glusterfsd/src/glusterfsd.c | 18 ++++++++-
xlators/mgmt/glusterd/src/glusterd-pmap.c | 31 ++++++++++++---
xlators/mgmt/glusterd/src/glusterd-utils.c | 62 ++++++++++++++++++++++++++++++
xlators/mgmt/glusterd/src/glusterd-utils.h | 4 ++
4 files changed, 109 insertions(+), 6 deletions(-)
diff --git a/glusterfsd/src/glusterfsd.c b/glusterfsd/src/glusterfsd.c
index cbc1b93..7957f38 100644
--- a/glusterfsd/src/glusterfsd.c
+++ b/glusterfsd/src/glusterfsd.c
@@ -1262,6 +1262,9 @@ cleanup_and_exit (int signum)
{
glusterfs_ctx_t *ctx = NULL;
xlator_t *trav = NULL;
+ xlator_t *top;
+ xlator_t *victim;
+ xlator_list_t **trav_p;
ctx = glusterfsd_ctx;
@@ -1291,7 +1294,20 @@ cleanup_and_exit (int signum)
return;
ctx->cleanup_started = 1;
- glusterfs_mgmt_pmap_signout (ctx, NULL);
+
+ /* signout should be sent to all the bricks in case brick mux is enabled
+ * and multiple brick instances are attached to this process
+ */
+ if (ctx->active) {
+ top = ctx->active->first;
+ for (trav_p = &top->children; *trav_p;
+ trav_p = &(*trav_p)->next) {
+ victim = (*trav_p)->xlator;
+ glusterfs_mgmt_pmap_signout (ctx, victim->name);
+ }
+ } else {
+ glusterfs_mgmt_pmap_signout (ctx, NULL);
+ }
/* below part is a racy code where the rpcsvc object is freed.
* But in another thread (epoll thread), upon poll error in the
diff --git a/xlators/mgmt/glusterd/src/glusterd-pmap.c b/xlators/mgmt/glusterd/src/glusterd-pmap.c
index d87c31e..d67117f 100644
--- a/xlators/mgmt/glusterd/src/glusterd-pmap.c
+++ b/xlators/mgmt/glusterd/src/glusterd-pmap.c
@@ -551,11 +551,20 @@ gluster_pmap_signin (rpcsvc_request_t *req)
int
__gluster_pmap_signout (rpcsvc_request_t *req)
{
- pmap_signout_req args = {0,};
- pmap_signout_rsp rsp = {0,};
- int ret = -1;
- char brick_path[PATH_MAX] = {0,};
- glusterd_brickinfo_t *brickinfo = NULL;
+ pmap_signout_req args = {0,};
+ pmap_signout_rsp rsp = {0,};
+ int ret = -1;
+ xlator_t *this = NULL;
+ glusterd_conf_t *conf = NULL;
+ glusterd_volinfo_t *volinfo = NULL;
+ glusterd_brickinfo_t *brickinfo = NULL;
+ char pidfile[PATH_MAX] = {0};
+ char brick_path[PATH_MAX] = {0,};
+
+ this = THIS;
+ GF_VALIDATE_OR_GOTO ("glusterd", this, fail);
+ conf = this->private;
+ GF_VALIDATE_OR_GOTO (this->name, conf, fail);
ret = xdr_to_generic (req->msg[0], &args,
(xdrproc_t)xdr_pmap_signout_req);
@@ -574,6 +583,18 @@ __gluster_pmap_signout (rpcsvc_request_t *req)
brick_path, GF_PMAP_PORT_BRICKSERVER,
req->trans);
}
+ /* Clean up the pidfile for this brick given glusterfsd doesn't clean it
+ * any more. This is required to ensure we don't end up with having
+ * stale pid files in case a brick is killed from the backend
+ */
+ ret = glusterd_get_volinfo_from_brick (args.brick, &volinfo);
+ if (!ret) {
+ if (volinfo && brickinfo) {
+ GLUSTERD_GET_BRICK_PIDFILE (pidfile, volinfo, brickinfo,
+ conf);
+ sys_unlink (pidfile);
+ }
+ }
fail:
glusterd_submit_reply (req, &rsp, NULL, 0, NULL,
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
index 9eb6502..36eb1d1 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
@@ -5742,6 +5742,7 @@ glusterd_get_brickinfo (xlator_t *this, const char *brickname, int port,
glusterd_conf_t *priv = NULL;
glusterd_volinfo_t *volinfo = NULL;
glusterd_brickinfo_t *tmpbrkinfo = NULL;
+ glusterd_snap_t *snap = NULL;
int ret = -1;
GF_ASSERT (brickname);
@@ -5760,6 +5761,21 @@ glusterd_get_brickinfo (xlator_t *this, const char *brickname, int port,
}
}
}
+ /* In case normal volume is not found, check for snapshot volumes */
+ cds_list_for_each_entry (snap, &priv->snapshots, snap_list) {
+ cds_list_for_each_entry (volinfo, &snap->volumes, vol_list) {
+ cds_list_for_each_entry (tmpbrkinfo, &volinfo->bricks,
+ brick_list) {
+ if (gf_uuid_compare (tmpbrkinfo->uuid, MY_UUID))
+ continue;
+ if (!strcmp(tmpbrkinfo->path, brickname)) {
+ *brickinfo = tmpbrkinfo;
+ return 0;
+ }
+ }
+ }
+ }
+
return ret;
}
@@ -12757,6 +12773,52 @@ out:
return ret;
}
+int
+glusterd_get_volinfo_from_brick (char *brick, glusterd_volinfo_t **volinfo)
+{
+ int ret = -1;
+ xlator_t *this = NULL;
+ glusterd_conf_t *conf = NULL;
+ glusterd_volinfo_t *voliter = NULL;
+ glusterd_brickinfo_t *brickiter = NULL;
+ glusterd_snap_t *snap = NULL;
+
+ this = THIS;
+ GF_VALIDATE_OR_GOTO ("glusterd", this, out);
+ conf = this->private;
+ GF_VALIDATE_OR_GOTO (this->name, conf, out);
+
+ /* First check for normal volumes */
+ cds_list_for_each_entry (voliter, &conf->volumes, vol_list) {
+ cds_list_for_each_entry (brickiter, &voliter->bricks,
+ brick_list) {
+ if (gf_uuid_compare (brickiter->uuid, MY_UUID))
+ continue;
+ if (!strcmp(brickiter->path, brick)) {
+ *volinfo = voliter;
+ return 0;
+ }
+ }
+ }
+ /* In case normal volume is not found, check for snapshot volumes */
+ cds_list_for_each_entry (snap, &conf->snapshots, snap_list) {
+ cds_list_for_each_entry (voliter, &snap->volumes, vol_list) {
+ cds_list_for_each_entry (brickiter, &voliter->bricks,
+ brick_list) {
+ if (gf_uuid_compare (brickiter->uuid, MY_UUID))
+ continue;
+ if (!strcmp(brickiter->path, brick)) {
+ *volinfo = voliter;
+ return 0;
+ }
+ }
+ }
+ }
+
+out:
+ return ret;
+}
+
glusterd_op_t
gd_cli_to_gd_op (char *cli_op)
{
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.h b/xlators/mgmt/glusterd/src/glusterd-utils.h
index d3ff44f..aab6a29 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.h
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.h
@@ -820,4 +820,8 @@ glusterd_brick_op_prerequisites (dict_t *dict,
char **src_brick, glusterd_brickinfo_t
**src_brickinfo, char *pidfile,
char **op_errstr, dict_t *rsp_dict);
+
+int
+glusterd_get_volinfo_from_brick (char *brick, glusterd_volinfo_t **volinfo);
+
#endif
--
1.8.3.1