From 5619b2dc4189e9de4a2327dc63ccb647f863f2b1 Mon Sep 17 00:00:00 2001 From: Kaushal M Date: Wed, 21 Sep 2011 12:06:14 +0530 Subject: glusterd: fix 'volume status' showing incorrect online status glusterd now checks if a brick process is running to set online status, instead of using brickinfo->signed_in. The earlier method used to show incorrect online status as brickinfo->signed_in was not updated when brick process was killed with SIGKILL Change-Id: Id5589ea8abbcffebe5c794e5a4adf4f0e6e489f0 BUG: 3573 Reviewed-on: http://review.gluster.com/476 Tested-by: Gluster Build System Reviewed-by: Amar Tumballi Reviewed-by: Vijay Bellur --- xlators/mgmt/glusterd/src/glusterd-utils.c | 53 +++++++++++++++++++----------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c index 89a29abea78..e6c23e8337e 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.c +++ b/xlators/mgmt/glusterd/src/glusterd-utils.c @@ -2897,7 +2897,9 @@ glusterd_add_brick_to_dict (glusterd_volinfo_t *volinfo, char pidfile[PATH_MAX] = {0}; char path[PATH_MAX] = {0}; FILE *file = NULL; + int fd = -1; int32_t pid = -1; + int32_t brick_online = -1; xlator_t *this = NULL; glusterd_conf_t *priv = NULL; @@ -2929,43 +2931,54 @@ glusterd_add_brick_to_dict (glusterd_volinfo_t *volinfo, goto out; - memset (key, 0, sizeof (key)); - snprintf (key, sizeof (key), "%s.status", base_key); - ret = dict_set_int32 (dict, key, brickinfo->signed_in); - if (ret) - goto out; - - if (!brickinfo->signed_in) - goto out; - - GLUSTERD_GET_VOLUME_DIR (path, volinfo, priv); GLUSTERD_GET_BRICK_PIDFILE (pidfile, path, brickinfo->hostname, brickinfo->path); - file = fopen (pidfile, "r+"); + file = fopen (pidfile, "r"); if (!file) { gf_log ("", GF_LOG_ERROR, "Unable to open pidfile: %s", pidfile); - ret = -1; - goto out; - } + /* pidfile doesn't exist means brick is down*/ + pid = 0; + brick_online = 0; + goto cont; + } else { + ret = fscanf (file, "%d", &pid); + if (ret <= 0) { + gf_log ("", GF_LOG_ERROR, "Unable to read pidfile: %s", + pidfile); + ret = -1; + goto out; + } - ret = fscanf (file, "%d", &pid); - if (ret <= 0) { - gf_log ("", GF_LOG_ERROR, "Unable to read pidfile: %s", - pidfile); - ret = -1; - goto out; + /* check if process is crashed*/ + fd = fileno (file); + if ((fd != -1) && (lockf (fd, F_TEST, 0))) + brick_online = 1; + else { + pid = 0; + brick_online = 0; + } } +cont: memset (key, 0, sizeof (key)); snprintf (key, sizeof (key), "%s.pid", base_key); ret = dict_set_int32 (dict, key, pid); if (ret) goto out; + memset (key, 0, sizeof (key)); + snprintf (key, sizeof (key), "%s.status", base_key); + ret = dict_set_int32 (dict, key, brick_online); + if (ret) + goto out; + out: + if (file) + fclose (file); + if (ret) gf_log ("", GF_LOG_DEBUG, "Returning %d", ret); -- cgit