summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt/glusterd/src/glusterd-proc-mgmt.c
diff options
context:
space:
mode:
authorAtin Mukherjee <amukherj@redhat.com>2015-02-11 17:13:45 +0530
committerKrishnan Parthasarathi <kparthas@redhat.com>2015-02-20 04:04:08 -0800
commit9d842f965655bf70c643b4541844e83bc4e74190 (patch)
tree4d248f27d77993a478267a41e0517228214d7fa0 /xlators/mgmt/glusterd/src/glusterd-proc-mgmt.c
parent571a71f0acd0ec59340b9d0d2519793e33a1dc16 (diff)
glusterd: nfs,shd,quotad,snapd daemons refactoring
This patch ports nfs, shd, quotad & snapd with the approach suggested in http://www.gluster.org/pipermail/gluster-devel/2014-December/043180.html Change-Id: I4ea5b38793f87fc85cc9d2cf873727351dedffd2 BUG: 1191486 Signed-off-by: Atin Mukherjee <amukherj@redhat.com> Signed-off-by: Krishnan Parthasarathi <kparthas@redhat.com> Reviewed-on: http://review.gluster.org/9428 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Anand Nekkunti <anekkunt@redhat.com>
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-proc-mgmt.c')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-proc-mgmt.c134
1 files changed, 134 insertions, 0 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-proc-mgmt.c b/xlators/mgmt/glusterd/src/glusterd-proc-mgmt.c
new file mode 100644
index 00000000000..d6088a398fa
--- /dev/null
+++ b/xlators/mgmt/glusterd/src/glusterd-proc-mgmt.c
@@ -0,0 +1,134 @@
+/*
+ Copyright (c) 2014 Red Hat, Inc. <http://www.redhat.com>
+ This file is part of GlusterFS.
+
+ This file is licensed to you under your choice of the GNU Lesser
+ General Public License, version 3 or any later version (LGPLv3 or
+ later), or the GNU General Public License, version 2 (GPLv2), in all
+ cases as published by the Free Software Foundation.
+*/
+
+#include <stdio.h>
+#include <limits.h>
+#include <signal.h>
+
+#include "common-utils.h"
+#include "xlator.h"
+#include "logging.h"
+#include "glusterd-messages.h"
+#include "glusterd-proc-mgmt.h"
+
+int
+glusterd_proc_init (glusterd_proc_t *proc, char *name, char *pidfile,
+ char *logdir, char *logfile, char *volfile, char *volfileid,
+ char *volfileserver)
+{
+ int ret = -1;
+
+ ret = snprintf (proc->name, sizeof (proc->name), "%s", name);
+ if (ret < 0)
+ goto out;
+
+ ret = snprintf (proc->pidfile, sizeof (proc->pidfile), "%s", pidfile);
+ if (ret < 0)
+ goto out;
+
+ ret = snprintf (proc->logdir, sizeof (proc->logdir), "%s", logdir);
+ if (ret < 0)
+ goto out;
+
+ ret = snprintf (proc->logfile, sizeof (proc->logfile), "%s", logfile);
+ if (ret < 0)
+ goto out;
+
+ ret = snprintf (proc->volfile, sizeof (proc->volfile), "%s", volfile);
+ if (ret < 0)
+ goto out;
+
+ ret = snprintf (proc->volfileid, sizeof (proc->volfileid), "%s",
+ volfileid);
+ if (ret < 0)
+ goto out;
+
+ ret = snprintf (proc->volfileserver, sizeof (proc->volfileserver), "%s",
+ volfileserver);
+ if (ret < 0)
+ goto out;
+
+out:
+ if (ret > 0)
+ ret = 0;
+
+ return ret;
+}
+
+int
+glusterd_proc_stop (glusterd_proc_t *proc, int sig, int flags)
+{
+
+ /* NB: Copy-paste code from glusterd_service_stop, the source may be
+ * removed once all daemon management use proc */
+
+ int32_t ret = -1;
+ pid_t pid = -1;
+ xlator_t *this = NULL;
+
+ this = THIS;
+ GF_ASSERT (this);
+
+ if (!gf_is_service_running (proc->pidfile, &pid)) {
+ ret = 0;
+ gf_log (this->name, GF_LOG_INFO, "%s already stopped",
+ proc->name);
+ goto out;
+ }
+ gf_log (this->name, GF_LOG_DEBUG, "Stopping %s daemon running in pid: "
+ "%d", proc->name, pid);
+
+ ret = kill (pid, sig);
+ if (ret) {
+ switch (errno) {
+ case ESRCH:
+ gf_log (this->name, GF_LOG_DEBUG, "%s is already "
+ "stopped", proc->name);
+ ret = 0;
+ goto out;
+ default:
+ gf_msg (this->name, GF_LOG_ERROR, errno,
+ GD_MSG_SVC_KILL_FAIL, "Unable to kill %s "
+ "service, reason:%s", proc->name,
+ strerror (errno));
+ }
+ }
+ if (flags != PROC_STOP_FORCE)
+ goto out;
+
+ sleep (1);
+ if (gf_is_service_running (proc->pidfile, NULL)) {
+ ret = kill (pid, SIGKILL);
+ if (ret) {
+ gf_msg (this->name, GF_LOG_ERROR, errno,
+ GD_MSG_PID_KILL_FAIL, "Unable to kill pid:%d, "
+ "reason:%s", pid, strerror(errno));
+ goto out;
+ }
+ }
+
+ ret = 0;
+out:
+ return ret;
+}
+
+int
+glusterd_proc_get_pid (glusterd_proc_t *proc)
+{
+ int pid = -1;
+ (void) gf_is_service_running (proc->pidfile, &pid);
+ return pid;
+}
+
+int
+glusterd_proc_is_running (glusterd_proc_t *proc)
+{
+ return gf_is_service_running (proc->pidfile, NULL);
+}