summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCsaba Henk <csaba@gluster.com>2010-09-17 13:36:12 +0000
committerVijay Bellur <vijay@dev.gluster.com>2010-09-17 23:34:56 -0700
commit1f7610608c4888fecc416a46b52d35c791a5116f (patch)
treea185db8596cd5634c67f24c921ff987c701fa46a
parentdbb2b3764c6f9cfeaeacd868e3167210017ba848 (diff)
glusterd: refactor service termination
Signed-off-by: Csaba Henk <csaba@gluster.com> Signed-off-by: Vijay Bellur <vijay@dev.gluster.com> BUG: 1570 (geosync related changes) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1570
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-op-sm.c37
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.c159
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.h4
3 files changed, 67 insertions, 133 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
index 4d5fb05e162..ce05c92eae2 100644
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
@@ -1876,10 +1876,7 @@ rb_kill_destination_brick (glusterd_volinfo_t *volinfo,
glusterd_brickinfo_t *dst_brickinfo)
{
glusterd_conf_t *priv = NULL;
- int ret = -1;
char pidfile[PATH_MAX] = {0,};
- pid_t pid = -1;
- FILE *file = NULL;
priv = THIS->private;
@@ -1887,39 +1884,7 @@ rb_kill_destination_brick (glusterd_volinfo_t *volinfo,
priv->workdir, volinfo->volname,
RB_DSTBRICK_PIDFILE);
- file = fopen (pidfile, "r+");
- if (!file) {
- gf_log ("", GF_LOG_ERROR, "Unable to open 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;
- }
-
- fclose (file);
- file = NULL;
-
- gf_log ("", GF_LOG_NORMAL, "Stopping glusterfs running in pid: %d",
- pid);
-
- ret = kill (pid, SIGQUIT);
-
- if (ret) {
- gf_log ("", GF_LOG_ERROR, "Unable to kill pid %d", pid);
- goto out;
- }
-
- ret = 0;
-
-out:
- return ret;
+ return glusterd_service_stop ("brick", pidfile, SIGQUIT, _gf_true);
}
static int
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
index ed4d7a32796..30ba5141628 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
@@ -767,6 +767,66 @@ glusterd_volinfo_find (char *volname, glusterd_volinfo_t **volinfo)
}
+int32_t
+glusterd_service_stop(const char *service, char *pidfile, int sig,
+ gf_boolean_t keep_pidfile)
+{
+ int32_t ret = -1;
+ pid_t pid = -1;
+ FILE *file = NULL;
+
+ file = fopen (pidfile, "r+");
+
+ if (!file) {
+ gf_log ("", GF_LOG_ERROR, "Unable to open pidfile: %s",
+ pidfile);
+ if (errno == ENOENT) {
+ gf_log ("",GF_LOG_TRACE, "%s may not be running",
+ service);
+ ret = 0;
+ goto out;
+ }
+ 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;
+ }
+ fclose (file);
+ file = NULL;
+
+ gf_log ("", GF_LOG_NORMAL, "Stopping gluster %s running in pid: %d",
+ service, pid);
+
+ ret = kill (pid, sig);
+
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "Unable to kill pid %d", pid);
+ goto out;
+ }
+
+ if (keep_pidfile)
+ goto out;
+
+ ret = unlink (pidfile);
+
+ if (ret && (ENOENT != errno)) {
+ gf_log ("", GF_LOG_ERROR, "Unable to unlink pidfile: %s",
+ pidfile);
+ goto out;
+ }
+
+ ret = 0;
+out:
+ if (file)
+ fclose (file);
+ return ret;
+}
int32_t
glusterd_volume_start_glusterfs (glusterd_volinfo_t *volinfo,
@@ -841,13 +901,10 @@ glusterd_volume_stop_glusterfs (glusterd_volinfo_t *volinfo,
glusterd_brickinfo_t *brickinfo,
int32_t count)
{
- int32_t ret = -1;
xlator_t *this = NULL;
glusterd_conf_t *priv = NULL;
char pidfile[PATH_MAX] = {0,};
char path[PATH_MAX] = {0,};
- pid_t pid = -1;
- FILE *file = NULL;
GF_ASSERT (volinfo);
GF_ASSERT (brickinfo);
@@ -861,55 +918,7 @@ glusterd_volume_stop_glusterfs (glusterd_volinfo_t *volinfo,
GLUSTERD_GET_BRICK_PIDFILE (pidfile, path, brickinfo->hostname,
brickinfo->path);
- file = fopen (pidfile, "r+");
-
- if (!file) {
- gf_log ("", GF_LOG_ERROR, "Unable to open pidfile: %s",
- pidfile);
- if (errno == ENOENT) {
- gf_log ("",GF_LOG_TRACE, "volume may not be running");
- ret = 0;
- goto out;
- }
- 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;
- }
- fclose (file);
- file = NULL;
-
- gf_log ("", GF_LOG_NORMAL, "Stopping glusterfs running in pid: %d",
- pid);
-
- ret = kill (pid, SIGTERM);
-
- if (ret) {
- gf_log ("", GF_LOG_ERROR, "Unable to kill pid %d", pid);
- goto out;
- }
-
- //pmap_registry_remove (THIS, brickinfo->port, brickinfo->path);
-
- ret = unlink (pidfile);
-
- if (ret && (ENOENT != errno)) {
- gf_log ("", GF_LOG_ERROR, "Unable to unlink pidfile: %s",
- pidfile);
- goto out;
- }
-
- ret = 0;
-out:
- if (file)
- fclose (file);
- return ret;
+ return glusterd_service_stop ("brick", pidfile, SIGTERM, _gf_false);
}
int32_t
@@ -1618,13 +1627,10 @@ out:
int32_t
glusterd_nfs_server_stop ()
{
- int32_t ret = -1;
xlator_t *this = NULL;
glusterd_conf_t *priv = NULL;
char pidfile[PATH_MAX] = {0,};
char path[PATH_MAX] = {0,};
- pid_t pid = -1;
- FILE *file = NULL;
this = THIS;
GF_ASSERT(this);
@@ -1634,48 +1640,7 @@ glusterd_nfs_server_stop ()
GLUSTERD_GET_NFS_DIR(path, priv);
GLUSTERD_GET_NFS_PIDFILE(pidfile);
- file = fopen (pidfile, "r+");
-
- if (!file) {
- gf_log ("", GF_LOG_ERROR, "Unable to open 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;
- }
- fclose (file);
- file = NULL;
-
- gf_log ("", GF_LOG_NORMAL, "Stopping glusterfs running in pid: %d",
- pid);
-
- ret = kill (pid, SIGTERM);
-
- if (ret) {
- gf_log ("", GF_LOG_ERROR, "Unable to kill pid %d", pid);
- goto out;
- }
-
- ret = unlink (pidfile);
-
- if (ret && (ENOENT != errno)) {
- gf_log ("", GF_LOG_ERROR, "Unable to unlink pidfile: %s",
- pidfile);
- goto out;
- }
-
- ret = 0;
-out:
- if (file)
- fclose (file);
- return ret;
+ return glusterd_service_stop ("nfsd", pidfile, SIGTERM, _gf_false);
}
gf_boolean_t
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.h b/xlators/mgmt/glusterd/src/glusterd-utils.h
index 19ca43fa190..a74fa871faf 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.h
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.h
@@ -91,6 +91,10 @@ int32_t
glusterd_volinfo_find (char *volname, glusterd_volinfo_t **volinfo);
int32_t
+glusterd_service_stop(const char *service, char *pidfile, int sig,
+ gf_boolean_t keep_pidfile);
+
+int32_t
glusterd_resolve_brick (glusterd_brickinfo_t *brickinfo);
int32_t