diff options
author | Kaushal M <kaushal@gluster.com> | 2011-09-21 12:06:14 +0530 |
---|---|---|
committer | Vijay Bellur <vijay@gluster.com> | 2011-09-22 04:24:38 -0700 |
commit | 5619b2dc4189e9de4a2327dc63ccb647f863f2b1 (patch) | |
tree | 1436d4f11e3d344bd5af5e985237b8901e462671 /xlators/mgmt/glusterd/src | |
parent | aa7815c29a849346a75389f6ad15d8190f5a6710 (diff) |
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 <jenkins@build.gluster.com>
Reviewed-by: Amar Tumballi <amar@gluster.com>
Reviewed-by: Vijay Bellur <vijay@gluster.com>
Diffstat (limited to 'xlators/mgmt/glusterd/src')
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-utils.c | 53 |
1 files changed, 33 insertions, 20 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c index 89a29abea..e6c23e833 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); |