cb8e9e
From cae9e746422dc54126eca96c4bacf11f24921cf2 Mon Sep 17 00:00:00 2001
cb8e9e
From: Atin Mukherjee <amukherj@redhat.com>
cb8e9e
Date: Wed, 1 Jul 2015 14:47:48 +0530
cb8e9e
Subject: [PATCH 267/275] glusterd: initialize the daemon services on demand
cb8e9e
cb8e9e
backport of http://review.gluster.org/#/c/11488/
cb8e9e
cb8e9e
As of now all the daemon services are initialized at glusterD init path. Since
cb8e9e
socket file path of per node daemon demands the uuid of the node, MY_UUID macro
cb8e9e
is invoked as part of the initialization.
cb8e9e
cb8e9e
The above flow breaks the usecases where a gluster image is built following a
cb8e9e
template could be Dockerfile, Vagrantfile or any kind of virtualization
cb8e9e
environment. This means bringing instances of this image would have same UUIDs
cb8e9e
for the node resulting in peer probe failure.
cb8e9e
cb8e9e
Solution is to lazily initialize the services on demand.
cb8e9e
cb8e9e
Change-Id: If7caa533026c83e98c7c7678bded67085d0bbc1e
cb8e9e
BUG: 1245536
cb8e9e
Signed-off-by: Atin Mukherjee <amukherj@redhat.com>
cb8e9e
Reviewed-on: http://review.gluster.org/11488
cb8e9e
Tested-by: Gluster Build System <jenkins@build.gluster.com>
cb8e9e
Tested-by: NetBSD Build System <jenkins@build.gluster.org>
cb8e9e
Reviewed-by: Gaurav Kumar Garg <ggarg@redhat.com>
cb8e9e
Reviewed-by: Kaushal M <kaushal@redhat.com>
cb8e9e
Reviewed-on: https://code.engineering.redhat.com/gerrit/55044
cb8e9e
Reviewed-by: Krishnan Parthasarathi <kparthas@redhat.com>
cb8e9e
Tested-by: Krishnan Parthasarathi <kparthas@redhat.com>
cb8e9e
---
cb8e9e
 doc/developer-guide/daemon-management-framework.md |    9 ++-
cb8e9e
 ...-1238135-lazy-daemon-initialization-on-demand.t |   16 +++++
cb8e9e
 xlators/mgmt/glusterd/src/glusterd-bitd-svc.c      |   27 +++++++-
cb8e9e
 xlators/mgmt/glusterd/src/glusterd-bitd-svc.h      |    3 +
cb8e9e
 xlators/mgmt/glusterd/src/glusterd-ganesha.c       |   19 ++++--
cb8e9e
 xlators/mgmt/glusterd/src/glusterd-nfs-svc.c       |   26 +++++++-
cb8e9e
 xlators/mgmt/glusterd/src/glusterd-nfs-svc.h       |    3 +
cb8e9e
 xlators/mgmt/glusterd/src/glusterd-quotad-svc.c    |   27 +++++++-
cb8e9e
 xlators/mgmt/glusterd/src/glusterd-quotad-svc.h    |    3 +
cb8e9e
 xlators/mgmt/glusterd/src/glusterd-scrub-svc.c     |   27 +++++++-
cb8e9e
 xlators/mgmt/glusterd/src/glusterd-scrub-svc.h     |    3 +
cb8e9e
 xlators/mgmt/glusterd/src/glusterd-shd-svc.c       |   26 +++++++-
cb8e9e
 xlators/mgmt/glusterd/src/glusterd-shd-svc.h       |    3 +
cb8e9e
 xlators/mgmt/glusterd/src/glusterd-snapd-svc.c     |   26 +++++++-
cb8e9e
 xlators/mgmt/glusterd/src/glusterd-snapd-svc.h     |    3 +
cb8e9e
 xlators/mgmt/glusterd/src/glusterd-snapshot.c      |   10 ---
cb8e9e
 xlators/mgmt/glusterd/src/glusterd-store.c         |    9 ---
cb8e9e
 xlators/mgmt/glusterd/src/glusterd-svc-mgmt.c      |   15 +----
cb8e9e
 xlators/mgmt/glusterd/src/glusterd-svc-mgmt.h      |    9 ++-
cb8e9e
 xlators/mgmt/glusterd/src/glusterd-utils.c         |   25 ++------
cb8e9e
 xlators/mgmt/glusterd/src/glusterd-volume-ops.c    |    6 --
cb8e9e
 xlators/mgmt/glusterd/src/glusterd.c               |   67 ++++----------------
cb8e9e
 22 files changed, 212 insertions(+), 150 deletions(-)
cb8e9e
 create mode 100644 tests/bugs/glusterd/bug-1238135-lazy-daemon-initialization-on-demand.t
cb8e9e
cb8e9e
diff --git a/tests/bugs/glusterd/bug-1238135-lazy-daemon-initialization-on-demand.t b/tests/bugs/glusterd/bug-1238135-lazy-daemon-initialization-on-demand.t
cb8e9e
new file mode 100644
cb8e9e
index 0000000..54c3187
cb8e9e
--- /dev/null
cb8e9e
+++ b/tests/bugs/glusterd/bug-1238135-lazy-daemon-initialization-on-demand.t
cb8e9e
@@ -0,0 +1,16 @@
cb8e9e
+#!/bin/bash
cb8e9e
+
cb8e9e
+. $(dirname $0)/../../include.rc
cb8e9e
+
cb8e9e
+cleanup;
cb8e9e
+
cb8e9e
+TEST glusterd;
cb8e9e
+TEST pidof glusterd;
cb8e9e
+
cb8e9e
+GDWD=$($CLI system getwd)
cb8e9e
+
cb8e9e
+# glusterd.info file will be created on either first peer probe or volume
cb8e9e
+# creation, hence we expect file to be not present in this case
cb8e9e
+TEST ! -e $GDWD/glusterd.info
cb8e9e
+
cb8e9e
+cleanup;
cb8e9e
diff --git a/xlators/mgmt/glusterd/src/glusterd-bitd-svc.c b/xlators/mgmt/glusterd/src/glusterd-bitd-svc.c
cb8e9e
index 1b71b6c..6b606f8 100644
cb8e9e
--- a/xlators/mgmt/glusterd/src/glusterd-bitd-svc.c
cb8e9e
+++ b/xlators/mgmt/glusterd/src/glusterd-bitd-svc.c
cb8e9e
@@ -15,13 +15,18 @@
cb8e9e
 #include "glusterd-volgen.h"
cb8e9e
 #include "glusterd-bitd-svc.h"
cb8e9e
 
cb8e9e
+void
cb8e9e
+glusterd_bitdsvc_build (glusterd_svc_t *svc)
cb8e9e
+{
cb8e9e
+        svc->manager = glusterd_bitdsvc_manager;
cb8e9e
+        svc->start = glusterd_bitdsvc_start;
cb8e9e
+        svc->stop = glusterd_bitdsvc_stop;
cb8e9e
+}
cb8e9e
+
cb8e9e
 int
cb8e9e
 glusterd_bitdsvc_init (glusterd_svc_t *svc)
cb8e9e
 {
cb8e9e
-        return glusterd_svc_init (svc, bitd_svc_name,
cb8e9e
-                                  glusterd_bitdsvc_manager,
cb8e9e
-                                  glusterd_bitdsvc_start,
cb8e9e
-                                  glusterd_bitdsvc_stop);
cb8e9e
+        return glusterd_svc_init (svc, bitd_svc_name);
cb8e9e
 }
cb8e9e
 
cb8e9e
 static int
cb8e9e
@@ -65,6 +70,20 @@ glusterd_bitdsvc_manager (glusterd_svc_t *svc, void *data, int flags)
cb8e9e
         this = THIS;
cb8e9e
         GF_ASSERT (this);
cb8e9e
 
cb8e9e
+        if (!svc->inited) {
cb8e9e
+                ret = glusterd_bitdsvc_init (svc);
cb8e9e
+                if (ret) {
cb8e9e
+                        gf_msg (this->name, GF_LOG_ERROR, 0,
cb8e9e
+                                GD_MSG_BITD_INIT_FAIL, "Failed to init "
cb8e9e
+                                "bitd service");
cb8e9e
+                        goto out;
cb8e9e
+                } else {
cb8e9e
+                        svc->inited = _gf_true;
cb8e9e
+                        gf_msg_debug (this->name, 0, "BitD service "
cb8e9e
+                                      "initialized");
cb8e9e
+                }
cb8e9e
+        }
cb8e9e
+
cb8e9e
         if (glusterd_should_i_stop_bitd ()) {
cb8e9e
                 ret = svc->stop (svc, SIGTERM);
cb8e9e
         } else {
cb8e9e
diff --git a/xlators/mgmt/glusterd/src/glusterd-bitd-svc.h b/xlators/mgmt/glusterd/src/glusterd-bitd-svc.h
cb8e9e
index e6f5d51..103d404 100644
cb8e9e
--- a/xlators/mgmt/glusterd/src/glusterd-bitd-svc.h
cb8e9e
+++ b/xlators/mgmt/glusterd/src/glusterd-bitd-svc.h
cb8e9e
@@ -20,6 +20,9 @@
cb8e9e
 
cb8e9e
 #define bitd_svc_name "bitd"
cb8e9e
 
cb8e9e
+void
cb8e9e
+glusterd_bitdsvc_build (glusterd_svc_t *svc);
cb8e9e
+
cb8e9e
 int
cb8e9e
 glusterd_bitdsvc_init (glusterd_svc_t *svc);
cb8e9e
 
cb8e9e
diff --git a/xlators/mgmt/glusterd/src/glusterd-ganesha.c b/xlators/mgmt/glusterd/src/glusterd-ganesha.c
cb8e9e
index 4d2efb9..8cd2aa6 100644
cb8e9e
--- a/xlators/mgmt/glusterd/src/glusterd-ganesha.c
cb8e9e
+++ b/xlators/mgmt/glusterd/src/glusterd-ganesha.c
cb8e9e
@@ -671,14 +671,19 @@ start_ganesha (char **op_errstr)
cb8e9e
                 }
cb8e9e
         }
cb8e9e
 
cb8e9e
-        ret = priv->nfs_svc.stop (&(priv->nfs_svc), SIGKILL);
cb8e9e
-        if (ret) {
cb8e9e
-                ret = -1;
cb8e9e
-                gf_asprintf (op_errstr, "Gluster-NFS service could"
cb8e9e
-                             "not be stopped, exiting.");
cb8e9e
-                goto out;
cb8e9e
+        /* If the nfs svc is not initialized it means that the service is not
cb8e9e
+         * running, hence we can skip the process of stopping gluster-nfs
cb8e9e
+         * service
cb8e9e
+         */
cb8e9e
+        if (priv->nfs_svc.inited) {
cb8e9e
+                ret = priv->nfs_svc.stop (&(priv->nfs_svc), SIGKILL);
cb8e9e
+                if (ret) {
cb8e9e
+                        ret = -1;
cb8e9e
+                        gf_asprintf (op_errstr, "Gluster-NFS service could"
cb8e9e
+                                     "not be stopped, exiting.");
cb8e9e
+                        goto out;
cb8e9e
+                }
cb8e9e
         }
cb8e9e
-
cb8e9e
         if (check_host_list()) {
cb8e9e
                 ret = manage_service ("start");
cb8e9e
                 if (ret)
cb8e9e
diff --git a/xlators/mgmt/glusterd/src/glusterd-nfs-svc.c b/xlators/mgmt/glusterd/src/glusterd-nfs-svc.c
cb8e9e
index 0c4d3c1..b1d9814 100644
cb8e9e
--- a/xlators/mgmt/glusterd/src/glusterd-nfs-svc.c
cb8e9e
+++ b/xlators/mgmt/glusterd/src/glusterd-nfs-svc.c
cb8e9e
@@ -18,6 +18,14 @@
cb8e9e
 
cb8e9e
 char *nfs_svc_name = "nfs";
cb8e9e
 
cb8e9e
+void
cb8e9e
+glusterd_nfssvc_build (glusterd_svc_t *svc)
cb8e9e
+{
cb8e9e
+        svc->manager = glusterd_nfssvc_manager;
cb8e9e
+        svc->start = glusterd_nfssvc_start;
cb8e9e
+        svc->stop = glusterd_nfssvc_stop;
cb8e9e
+}
cb8e9e
+
cb8e9e
 static gf_boolean_t
cb8e9e
 glusterd_nfssvc_need_start ()
cb8e9e
 {
cb8e9e
@@ -43,10 +51,7 @@ glusterd_nfssvc_need_start ()
cb8e9e
 int
cb8e9e
 glusterd_nfssvc_init (glusterd_svc_t *svc)
cb8e9e
 {
cb8e9e
-        return glusterd_svc_init (svc, nfs_svc_name,
cb8e9e
-                                  glusterd_nfssvc_manager,
cb8e9e
-                                  glusterd_nfssvc_start,
cb8e9e
-                                  glusterd_nfssvc_stop);
cb8e9e
+        return glusterd_svc_init (svc, nfs_svc_name);
cb8e9e
 }
cb8e9e
 
cb8e9e
 static int
cb8e9e
@@ -167,6 +172,19 @@ glusterd_nfssvc_manager (glusterd_svc_t *svc, void *data, int flags)
cb8e9e
 {
cb8e9e
         int                 ret     = -1;
cb8e9e
 
cb8e9e
+        if (!svc->inited) {
cb8e9e
+                ret = glusterd_nfssvc_init (svc);
cb8e9e
+                if (ret) {
cb8e9e
+                        gf_msg (THIS->name, GF_LOG_ERROR, 0,
cb8e9e
+                                GD_MSG_FAILED_INIT_NFSSVC, "Failed to init nfs "
cb8e9e
+                                "service");
cb8e9e
+                        goto out;
cb8e9e
+                } else {
cb8e9e
+                        svc->inited = _gf_true;
cb8e9e
+                        gf_msg_debug (THIS->name, 0, "nfs service initialized");
cb8e9e
+                }
cb8e9e
+        }
cb8e9e
+
cb8e9e
         ret = svc->stop (svc, SIGKILL);
cb8e9e
         if (ret)
cb8e9e
                 goto out;
cb8e9e
diff --git a/xlators/mgmt/glusterd/src/glusterd-nfs-svc.h b/xlators/mgmt/glusterd/src/glusterd-nfs-svc.h
cb8e9e
index 210336c..c1c0330 100644
cb8e9e
--- a/xlators/mgmt/glusterd/src/glusterd-nfs-svc.h
cb8e9e
+++ b/xlators/mgmt/glusterd/src/glusterd-nfs-svc.h
cb8e9e
@@ -18,6 +18,9 @@
cb8e9e
 
cb8e9e
 #include "glusterd-svc-mgmt.h"
cb8e9e
 
cb8e9e
+void
cb8e9e
+glusterd_nfssvc_build (glusterd_svc_t *svc);
cb8e9e
+
cb8e9e
 int
cb8e9e
 glusterd_nfssvc_init (glusterd_svc_t *svc);
cb8e9e
 
cb8e9e
diff --git a/xlators/mgmt/glusterd/src/glusterd-quotad-svc.c b/xlators/mgmt/glusterd/src/glusterd-quotad-svc.c
cb8e9e
index 37824f6..59a7671 100644
cb8e9e
--- a/xlators/mgmt/glusterd/src/glusterd-quotad-svc.c
cb8e9e
+++ b/xlators/mgmt/glusterd/src/glusterd-quotad-svc.c
cb8e9e
@@ -18,16 +18,21 @@
cb8e9e
 
cb8e9e
 char *quotad_svc_name = "quotad";
cb8e9e
 
cb8e9e
+void
cb8e9e
+glusterd_quotadsvc_build (glusterd_svc_t *svc)
cb8e9e
+{
cb8e9e
+        svc->manager = glusterd_quotadsvc_manager;
cb8e9e
+        svc->start = glusterd_quotadsvc_start;
cb8e9e
+        svc->stop = glusterd_svc_stop;
cb8e9e
+}
cb8e9e
+
cb8e9e
 int glusterd_quotadsvc_init (glusterd_svc_t *svc)
cb8e9e
 {
cb8e9e
         int              ret                = -1;
cb8e9e
         char             volfile[PATH_MAX]  = {0,};
cb8e9e
         glusterd_conf_t *conf               = THIS->private;
cb8e9e
 
cb8e9e
-        ret = glusterd_svc_init (svc, quotad_svc_name,
cb8e9e
-                                 glusterd_quotadsvc_manager,
cb8e9e
-                                 glusterd_quotadsvc_start,
cb8e9e
-                                 glusterd_svc_stop);
cb8e9e
+        ret = glusterd_svc_init (svc, quotad_svc_name);
cb8e9e
         if (ret)
cb8e9e
                 goto out;
cb8e9e
 
cb8e9e
@@ -60,6 +65,20 @@ glusterd_quotadsvc_manager (glusterd_svc_t *svc, void *data, int flags)
cb8e9e
         int                 ret     = 0;
cb8e9e
         glusterd_volinfo_t *volinfo = NULL;
cb8e9e
 
cb8e9e
+        if (!svc->inited) {
cb8e9e
+                ret = glusterd_quotadsvc_init (svc);
cb8e9e
+                if (ret) {
cb8e9e
+                        gf_msg (THIS->name, GF_LOG_ERROR, 0,
cb8e9e
+                                GD_MSG_FAILED_INIT_QUOTASVC, "Failed to init "
cb8e9e
+                                "quotad service");
cb8e9e
+                        goto out;
cb8e9e
+                } else {
cb8e9e
+                        svc->inited = _gf_true;
cb8e9e
+                        gf_msg_debug (THIS->name, 0, "quotad service "
cb8e9e
+                                      "initialized");
cb8e9e
+                }
cb8e9e
+        }
cb8e9e
+
cb8e9e
         volinfo = data;
cb8e9e
 
cb8e9e
         /* If all the volumes are stopped or all shd compatible volumes
cb8e9e
diff --git a/xlators/mgmt/glusterd/src/glusterd-quotad-svc.h b/xlators/mgmt/glusterd/src/glusterd-quotad-svc.h
cb8e9e
index 945d47e..c275aa4 100644
cb8e9e
--- a/xlators/mgmt/glusterd/src/glusterd-quotad-svc.h
cb8e9e
+++ b/xlators/mgmt/glusterd/src/glusterd-quotad-svc.h
cb8e9e
@@ -18,6 +18,9 @@
cb8e9e
 
cb8e9e
 #include "glusterd-svc-mgmt.h"
cb8e9e
 
cb8e9e
+void
cb8e9e
+glusterd_quotadsvc_build (glusterd_svc_t *svc);
cb8e9e
+
cb8e9e
 int
cb8e9e
 glusterd_quotadsvc_init (glusterd_svc_t *svc);
cb8e9e
 
cb8e9e
diff --git a/xlators/mgmt/glusterd/src/glusterd-scrub-svc.c b/xlators/mgmt/glusterd/src/glusterd-scrub-svc.c
cb8e9e
index 36863e2..b5c9785 100644
cb8e9e
--- a/xlators/mgmt/glusterd/src/glusterd-scrub-svc.c
cb8e9e
+++ b/xlators/mgmt/glusterd/src/glusterd-scrub-svc.c
cb8e9e
@@ -17,13 +17,18 @@
cb8e9e
 
cb8e9e
 char *scrub_svc_name = "scrub";
cb8e9e
 
cb8e9e
+void
cb8e9e
+glusterd_scrubsvc_build (glusterd_svc_t *svc)
cb8e9e
+{
cb8e9e
+        svc->manager = glusterd_scrubsvc_manager;
cb8e9e
+        svc->start = glusterd_scrubsvc_start;
cb8e9e
+        svc->stop = glusterd_scrubsvc_stop;
cb8e9e
+}
cb8e9e
+
cb8e9e
 int
cb8e9e
 glusterd_scrubsvc_init (glusterd_svc_t *svc)
cb8e9e
 {
cb8e9e
-        return glusterd_svc_init (svc, scrub_svc_name,
cb8e9e
-                                  glusterd_scrubsvc_manager,
cb8e9e
-                                  glusterd_scrubsvc_start,
cb8e9e
-                                  glusterd_scrubsvc_stop);
cb8e9e
+        return glusterd_svc_init (svc, scrub_svc_name);
cb8e9e
 }
cb8e9e
 
cb8e9e
 static int
cb8e9e
@@ -60,6 +65,20 @@ glusterd_scrubsvc_manager (glusterd_svc_t *svc, void *data, int flags)
cb8e9e
 {
cb8e9e
         int          ret    = -EINVAL;
cb8e9e
 
cb8e9e
+        if (!svc->inited) {
cb8e9e
+                ret = glusterd_scrubsvc_init (svc);
cb8e9e
+                if (ret) {
cb8e9e
+                        gf_msg (THIS->name, GF_LOG_ERROR, 0,
cb8e9e
+                                GD_MSG_SCRUB_INIT_FAIL, "Failed to init "
cb8e9e
+                                "scrub service");
cb8e9e
+                        goto out;
cb8e9e
+                } else {
cb8e9e
+                        svc->inited = _gf_true;
cb8e9e
+                        gf_msg_debug (THIS->name, 0, "scrub service "
cb8e9e
+                                      "initialized");
cb8e9e
+                }
cb8e9e
+        }
cb8e9e
+
cb8e9e
         if (glusterd_should_i_stop_bitd ()) {
cb8e9e
                 ret = svc->stop (svc, SIGTERM);
cb8e9e
         } else {
cb8e9e
diff --git a/xlators/mgmt/glusterd/src/glusterd-scrub-svc.h b/xlators/mgmt/glusterd/src/glusterd-scrub-svc.h
cb8e9e
index e2e3b0d..aeea00d 100644
cb8e9e
--- a/xlators/mgmt/glusterd/src/glusterd-scrub-svc.h
cb8e9e
+++ b/xlators/mgmt/glusterd/src/glusterd-scrub-svc.h
cb8e9e
@@ -25,6 +25,9 @@ struct glusterd_scrubsvc_{
cb8e9e
         gf_store_handle_t   *handle;
cb8e9e
 };
cb8e9e
 
cb8e9e
+void
cb8e9e
+glusterd_scrubsvc_build (glusterd_svc_t *svc);
cb8e9e
+
cb8e9e
 int
cb8e9e
 glusterd_scrubsvc_init (glusterd_svc_t *svc);
cb8e9e
 
cb8e9e
diff --git a/xlators/mgmt/glusterd/src/glusterd-shd-svc.c b/xlators/mgmt/glusterd/src/glusterd-shd-svc.c
cb8e9e
index 49454cc..f9f4189 100644
cb8e9e
--- a/xlators/mgmt/glusterd/src/glusterd-shd-svc.c
cb8e9e
+++ b/xlators/mgmt/glusterd/src/glusterd-shd-svc.c
cb8e9e
@@ -18,13 +18,18 @@
cb8e9e
 
cb8e9e
 char *shd_svc_name = "glustershd";
cb8e9e
 
cb8e9e
+void
cb8e9e
+glusterd_shdsvc_build (glusterd_svc_t *svc)
cb8e9e
+{
cb8e9e
+        svc->manager = glusterd_shdsvc_manager;
cb8e9e
+        svc->start = glusterd_shdsvc_start;
cb8e9e
+        svc->stop = glusterd_svc_stop;
cb8e9e
+}
cb8e9e
+
cb8e9e
 int
cb8e9e
 glusterd_shdsvc_init (glusterd_svc_t *svc)
cb8e9e
 {
cb8e9e
-        return glusterd_svc_init (svc, shd_svc_name,
cb8e9e
-                                  glusterd_shdsvc_manager,
cb8e9e
-                                  glusterd_shdsvc_start,
cb8e9e
-                                  glusterd_svc_stop);
cb8e9e
+        return glusterd_svc_init (svc, shd_svc_name);
cb8e9e
 }
cb8e9e
 
cb8e9e
 static int
cb8e9e
@@ -80,6 +85,19 @@ glusterd_shdsvc_manager (glusterd_svc_t *svc, void *data, int flags)
cb8e9e
         int                 ret     = 0;
cb8e9e
         glusterd_volinfo_t *volinfo = NULL;
cb8e9e
 
cb8e9e
+        if (!svc->inited) {
cb8e9e
+                ret = glusterd_shdsvc_init (svc);
cb8e9e
+                if (ret) {
cb8e9e
+                        gf_msg (THIS->name, GF_LOG_ERROR, 0,
cb8e9e
+                                GD_MSG_FAILED_INIT_SHDSVC, "Failed to init shd "
cb8e9e
+                                "service");
cb8e9e
+                        goto out;
cb8e9e
+                } else {
cb8e9e
+                        svc->inited = _gf_true;
cb8e9e
+                        gf_msg_debug (THIS->name, 0, "shd service initialized");
cb8e9e
+                }
cb8e9e
+        }
cb8e9e
+
cb8e9e
         volinfo = data;
cb8e9e
 
cb8e9e
         /* If all the volumes are stopped or all shd compatible volumes
cb8e9e
diff --git a/xlators/mgmt/glusterd/src/glusterd-shd-svc.h b/xlators/mgmt/glusterd/src/glusterd-shd-svc.h
cb8e9e
index 469ed5d..7dbb247 100644
cb8e9e
--- a/xlators/mgmt/glusterd/src/glusterd-shd-svc.h
cb8e9e
+++ b/xlators/mgmt/glusterd/src/glusterd-shd-svc.h
cb8e9e
@@ -18,6 +18,9 @@
cb8e9e
 
cb8e9e
 #include "glusterd-svc-mgmt.h"
cb8e9e
 
cb8e9e
+void
cb8e9e
+glusterd_shdsvc_build (glusterd_svc_t *svc);
cb8e9e
+
cb8e9e
 int
cb8e9e
 glusterd_shdsvc_init (glusterd_svc_t *svc);
cb8e9e
 
cb8e9e
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapd-svc.c b/xlators/mgmt/glusterd/src/glusterd-snapd-svc.c
cb8e9e
index 757c7f6..2ec7200 100644
cb8e9e
--- a/xlators/mgmt/glusterd/src/glusterd-snapd-svc.c
cb8e9e
+++ b/xlators/mgmt/glusterd/src/glusterd-snapd-svc.c
cb8e9e
@@ -36,6 +36,13 @@ glusterd_svc_build_snapd_logfile (char *logfile, char *logdir, size_t len)
cb8e9e
         snprintf (logfile, len, "%s/snapd.log", logdir);
cb8e9e
 }
cb8e9e
 
cb8e9e
+void
cb8e9e
+glusterd_snapdsvc_build (glusterd_svc_t *svc)
cb8e9e
+{
cb8e9e
+        svc->manager = glusterd_snapdsvc_manager;
cb8e9e
+        svc->start = glusterd_snapdsvc_start;
cb8e9e
+        svc->stop = glusterd_svc_stop;
cb8e9e
+}
cb8e9e
 
cb8e9e
 int
cb8e9e
 glusterd_snapdsvc_init (void *data)
cb8e9e
@@ -69,10 +76,6 @@ glusterd_snapdsvc_init (void *data)
cb8e9e
         if (ret < 0)
cb8e9e
                 goto out;
cb8e9e
 
cb8e9e
-        svc->manager = glusterd_snapdsvc_manager;
cb8e9e
-        svc->start = glusterd_snapdsvc_start;
cb8e9e
-        svc->stop = glusterd_svc_stop;
cb8e9e
-
cb8e9e
         notify = glusterd_snapdsvc_rpc_notify;
cb8e9e
 
cb8e9e
         glusterd_svc_build_snapd_rundir (volinfo, rundir, sizeof (rundir));
cb8e9e
@@ -123,6 +126,21 @@ glusterd_snapdsvc_manager (glusterd_svc_t *svc, void *data, int flags)
cb8e9e
 
cb8e9e
         volinfo = data;
cb8e9e
 
cb8e9e
+        if (!svc->inited) {
cb8e9e
+                ret = glusterd_snapdsvc_init (volinfo);
cb8e9e
+                if (ret) {
cb8e9e
+                        gf_msg (THIS->name, GF_LOG_ERROR, 0,
cb8e9e
+                                GD_MSG_SNAPD_INIT_FAIL, "Failed to initialize "
cb8e9e
+                                "snapd service for volume %s",
cb8e9e
+                                volinfo->volname);
cb8e9e
+                        goto out;
cb8e9e
+                } else {
cb8e9e
+                        svc->inited = _gf_true;
cb8e9e
+                        gf_msg_debug (THIS->name, 0, "snapd service "
cb8e9e
+                                      "initialized");
cb8e9e
+                }
cb8e9e
+        }
cb8e9e
+
cb8e9e
         ret = glusterd_is_snapd_enabled (volinfo);
cb8e9e
         if (ret == -1) {
cb8e9e
                 gf_msg (this->name, GF_LOG_ERROR, 0,
cb8e9e
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapd-svc.h b/xlators/mgmt/glusterd/src/glusterd-snapd-svc.h
cb8e9e
index bc5d39f..fae31e8 100644
cb8e9e
--- a/xlators/mgmt/glusterd/src/glusterd-snapd-svc.h
cb8e9e
+++ b/xlators/mgmt/glusterd/src/glusterd-snapd-svc.h
cb8e9e
@@ -26,6 +26,9 @@ struct glusterd_snapdsvc_{
cb8e9e
         gf_store_handle_t *handle;
cb8e9e
 };
cb8e9e
 
cb8e9e
+void
cb8e9e
+glusterd_snapdsvc_build (glusterd_svc_t *svc);
cb8e9e
+
cb8e9e
 int
cb8e9e
 glusterd_snapdsvc_init (void *data);
cb8e9e
 
cb8e9e
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot.c b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
cb8e9e
index 839b274..34cafd8 100644
cb8e9e
--- a/xlators/mgmt/glusterd/src/glusterd-snapshot.c
cb8e9e
+++ b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
cb8e9e
@@ -6492,7 +6492,6 @@ glusterd_snapshot_clone_commit (dict_t *dict, char **op_errstr,
cb8e9e
                        snap->snapname);
cb8e9e
                goto out;
cb8e9e
        }
cb8e9e
-       ret = glusterd_snapdsvc_init (snap_vol);
cb8e9e
 
cb8e9e
        glusterd_list_add_order (&snap_vol->vol_list, &priv->volumes,
cb8e9e
                        glusterd_compare_volume_name);
cb8e9e
@@ -9525,15 +9524,6 @@ gd_restore_snap_volume (dict_t *dict, dict_t *rsp_dict,
cb8e9e
                 goto out;
cb8e9e
         }
cb8e9e
 
cb8e9e
-        /* Initialize the snapd service */
cb8e9e
-        ret = glusterd_snapdsvc_init (new_volinfo);
cb8e9e
-        if (ret) {
cb8e9e
-                gf_msg (this->name, GF_LOG_ERROR, 0,
cb8e9e
-                        GD_MSG_SNAPD_INIT_FAIL, "Failed to initialize snapd "
cb8e9e
-                        "service for volume %s", orig_vol->volname);
cb8e9e
-                goto out;
cb8e9e
-        }
cb8e9e
-
cb8e9e
         ret = 0;
cb8e9e
 out:
cb8e9e
         if (ret) {
cb8e9e
diff --git a/xlators/mgmt/glusterd/src/glusterd-store.c b/xlators/mgmt/glusterd/src/glusterd-store.c
cb8e9e
index db7d1d4..7a605dd 100644
cb8e9e
--- a/xlators/mgmt/glusterd/src/glusterd-store.c
cb8e9e
+++ b/xlators/mgmt/glusterd/src/glusterd-store.c
cb8e9e
@@ -2816,15 +2816,6 @@ glusterd_store_retrieve_volume (char *volname, glusterd_snap_t *snap)
cb8e9e
         if (snap)
cb8e9e
                 volinfo->is_snap_volume = _gf_true;
cb8e9e
 
cb8e9e
-        /* Initialize the snapd service */
cb8e9e
-        ret = glusterd_snapdsvc_init (volinfo);
cb8e9e
-        if (ret) {
cb8e9e
-                gf_msg (this->name, GF_LOG_ERROR, 0,
cb8e9e
-                        GD_MSG_SNAPD_INIT_FAIL, "Failed to initialize snapd "
cb8e9e
-                        "service for volume %s", volinfo->volname);
cb8e9e
-                goto out;
cb8e9e
-        }
cb8e9e
-
cb8e9e
         ret = glusterd_store_update_volinfo (volinfo);
cb8e9e
         if (ret) {
cb8e9e
                 gf_msg (this->name, GF_LOG_ERROR, 0,
cb8e9e
diff --git a/xlators/mgmt/glusterd/src/glusterd-svc-mgmt.c b/xlators/mgmt/glusterd/src/glusterd-svc-mgmt.c
cb8e9e
index 04096a4..130bc56 100644
cb8e9e
--- a/xlators/mgmt/glusterd/src/glusterd-svc-mgmt.c
cb8e9e
+++ b/xlators/mgmt/glusterd/src/glusterd-svc-mgmt.c
cb8e9e
@@ -49,9 +49,6 @@ static int
cb8e9e
 glusterd_svc_init_common (glusterd_svc_t *svc,
cb8e9e
                           char *svc_name, char *workdir,
cb8e9e
                           char *rundir, char *logdir,
cb8e9e
-                          glusterd_svc_manager_t manager,
cb8e9e
-                          glusterd_svc_start_t start,
cb8e9e
-                          glusterd_svc_stop_t stop,
cb8e9e
                           glusterd_conn_notify_t notify)
cb8e9e
 {
cb8e9e
         int                     ret                        = -1;
cb8e9e
@@ -74,10 +71,6 @@ glusterd_svc_init_common (glusterd_svc_t *svc,
cb8e9e
         if (ret < 0)
cb8e9e
                 goto out;
cb8e9e
 
cb8e9e
-        svc->manager = manager;
cb8e9e
-        svc->start = start;
cb8e9e
-        svc->stop = stop;
cb8e9e
-
cb8e9e
         if (!notify)
cb8e9e
                 notify = glusterd_svc_common_rpc_notify;
cb8e9e
 
cb8e9e
@@ -126,10 +119,7 @@ svc_add_args (dict_t *cmdline, char *arg, data_t *value, void *data)
cb8e9e
         return 0;
cb8e9e
 }
cb8e9e
 
cb8e9e
-int glusterd_svc_init (glusterd_svc_t *svc, char *svc_name,
cb8e9e
-                       glusterd_svc_manager_t manager,
cb8e9e
-                       glusterd_svc_start_t start,
cb8e9e
-                       glusterd_svc_stop_t stop)
cb8e9e
+int glusterd_svc_init (glusterd_svc_t *svc, char *svc_name)
cb8e9e
 {
cb8e9e
         int              ret               = -1;
cb8e9e
         char             rundir[PATH_MAX]  = {0,};
cb8e9e
@@ -145,8 +135,7 @@ int glusterd_svc_init (glusterd_svc_t *svc, char *svc_name,
cb8e9e
         glusterd_svc_build_rundir (svc_name, priv->workdir, rundir,
cb8e9e
                                    sizeof (rundir));
cb8e9e
         ret = glusterd_svc_init_common (svc, svc_name, priv->workdir, rundir,
cb8e9e
-                                        DEFAULT_LOG_FILE_DIRECTORY, manager,
cb8e9e
-                                        start, stop, NULL);
cb8e9e
+                                        DEFAULT_LOG_FILE_DIRECTORY, NULL);
cb8e9e
 
cb8e9e
         return ret;
cb8e9e
 }
cb8e9e
diff --git a/xlators/mgmt/glusterd/src/glusterd-svc-mgmt.h b/xlators/mgmt/glusterd/src/glusterd-svc-mgmt.h
cb8e9e
index bb4f6f1..22028d3 100644
cb8e9e
--- a/xlators/mgmt/glusterd/src/glusterd-svc-mgmt.h
cb8e9e
+++ b/xlators/mgmt/glusterd/src/glusterd-svc-mgmt.h
cb8e9e
@@ -22,6 +22,8 @@
cb8e9e
 struct glusterd_svc_;
cb8e9e
 typedef struct glusterd_svc_ glusterd_svc_t;
cb8e9e
 
cb8e9e
+typedef void (*glusterd_svc_build_t) (glusterd_svc_t *svc);
cb8e9e
+
cb8e9e
 typedef int (*glusterd_svc_manager_t) (glusterd_svc_t *svc,
cb8e9e
                                        void *data, int flags);
cb8e9e
 typedef int (*glusterd_svc_start_t) (glusterd_svc_t *svc, int flags);
cb8e9e
@@ -31,20 +33,19 @@ struct glusterd_svc_ {
cb8e9e
         char                      name[PATH_MAX];
cb8e9e
         glusterd_conn_t           conn;
cb8e9e
         glusterd_proc_t           proc;
cb8e9e
+        glusterd_svc_build_t      build;
cb8e9e
         glusterd_svc_manager_t    manager;
cb8e9e
         glusterd_svc_start_t      start;
cb8e9e
         glusterd_svc_stop_t       stop;
cb8e9e
         gf_boolean_t              online;
cb8e9e
+        gf_boolean_t              inited;
cb8e9e
 };
cb8e9e
 
cb8e9e
 int
cb8e9e
 glusterd_svc_create_rundir (char *rundir);
cb8e9e
 
cb8e9e
 int
cb8e9e
-glusterd_svc_init (glusterd_svc_t *svc, char *svc_name,
cb8e9e
-                   glusterd_svc_manager_t manager,
cb8e9e
-                   glusterd_svc_start_t start,
cb8e9e
-                   glusterd_svc_stop_t stop);
cb8e9e
+glusterd_svc_init (glusterd_svc_t *svc, char *svc_name);
cb8e9e
 
cb8e9e
 int
cb8e9e
 glusterd_svc_start (glusterd_svc_t *svc, int flags, dict_t *cmdline);
cb8e9e
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
cb8e9e
index 1af9902..0101ec5 100644
cb8e9e
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
cb8e9e
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
cb8e9e
@@ -500,6 +500,9 @@ glusterd_volinfo_new (glusterd_volinfo_t **volinfo)
cb8e9e
 
cb8e9e
         new_volinfo->xl = THIS;
cb8e9e
 
cb8e9e
+        new_volinfo->snapd.svc.build = glusterd_snapdsvc_build;
cb8e9e
+        new_volinfo->snapd.svc.build (&(new_volinfo->snapd.svc));
cb8e9e
+
cb8e9e
         pthread_mutex_init (&new_volinfo->reflock, NULL);
cb8e9e
         *volinfo = glusterd_volinfo_ref (new_volinfo);
cb8e9e
 
cb8e9e
@@ -3776,35 +3779,17 @@ glusterd_import_friend_volume (dict_t *peer_data, size_t count)
cb8e9e
 
cb8e9e
         ret = glusterd_volinfo_find (new_volinfo->volname, &old_volinfo);
cb8e9e
         if (0 == ret) {
cb8e9e
-                /* snapdsvc initialization of old_volinfo is also required here
cb8e9e
-                 * as glusterd_delete_stale_volume () invokes snapdsvc manager
cb8e9e
-                 */
cb8e9e
-                ret = glusterd_snapdsvc_init (old_volinfo);
cb8e9e
-                if (ret) {
cb8e9e
-                        gf_msg (this->name, GF_LOG_ERROR, 0,
cb8e9e
-                                GD_MSG_SNAPD_INIT_FAIL, "Failed to initialize"
cb8e9e
-                                " snapdsvc for old volume %s",
cb8e9e
-                                old_volinfo->volname);
cb8e9e
-                        goto out;
cb8e9e
-                }
cb8e9e
                 (void) gd_check_and_update_rebalance_info (old_volinfo,
cb8e9e
                                                            new_volinfo);
cb8e9e
                 (void) glusterd_delete_stale_volume (old_volinfo, new_volinfo);
cb8e9e
         }
cb8e9e
 
cb8e9e
-        ret = glusterd_snapdsvc_init (new_volinfo);
cb8e9e
-        if (ret) {
cb8e9e
-                gf_msg (this->name, GF_LOG_ERROR, 0,
cb8e9e
-                        GD_MSG_SNAPD_INIT_FAIL, "Failed to initialize "
cb8e9e
-                        "snapdsvc for volume %s", new_volinfo->volname);
cb8e9e
-                goto out;
cb8e9e
-        }
cb8e9e
-
cb8e9e
         if (glusterd_is_volume_started (new_volinfo)) {
cb8e9e
                 (void) glusterd_start_bricks (new_volinfo);
cb8e9e
                 if (glusterd_is_snapd_enabled (new_volinfo)) {
cb8e9e
                         svc = &(new_volinfo->snapd.svc);
cb8e9e
-                        (void) svc->start (svc, PROC_START_NO_WAIT);
cb8e9e
+                        (void) svc->manager (svc, new_volinfo,
cb8e9e
+                                             PROC_START_NO_WAIT);
cb8e9e
                 }
cb8e9e
         }
cb8e9e
 
cb8e9e
diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-ops.c b/xlators/mgmt/glusterd/src/glusterd-volume-ops.c
cb8e9e
index 2ad1614..b52f832 100644
cb8e9e
--- a/xlators/mgmt/glusterd/src/glusterd-volume-ops.c
cb8e9e
+++ b/xlators/mgmt/glusterd/src/glusterd-volume-ops.c
cb8e9e
@@ -2302,12 +2302,6 @@ glusterd_op_create_volume (dict_t *dict, char **op_errstr)
cb8e9e
                 goto out;
cb8e9e
         }
cb8e9e
 
cb8e9e
-        ret = glusterd_snapdsvc_init (volinfo);
cb8e9e
-        if (ret) {
cb8e9e
-                *op_errstr = gf_strdup ("Failed to initialize snapd service");
cb8e9e
-                goto out;
cb8e9e
-        }
cb8e9e
-
cb8e9e
         ret = glusterd_create_volfiles_and_notify_services (volinfo);
cb8e9e
         if (ret) {
cb8e9e
                 *op_errstr = gf_strdup ("Failed to create volume files");
cb8e9e
diff --git a/xlators/mgmt/glusterd/src/glusterd.c b/xlators/mgmt/glusterd/src/glusterd.c
cb8e9e
index 1286488..2c75545 100644
cb8e9e
--- a/xlators/mgmt/glusterd/src/glusterd.c
cb8e9e
+++ b/xlators/mgmt/glusterd/src/glusterd.c
cb8e9e
@@ -1274,10 +1274,9 @@ out:
cb8e9e
         return ret;
cb8e9e
 }
cb8e9e
 
cb8e9e
-static int
cb8e9e
-glusterd_svc_init_all ()
cb8e9e
+static void
cb8e9e
+glusterd_svcs_build ()
cb8e9e
 {
cb8e9e
-        int                 ret     = -1;
cb8e9e
         xlator_t           *this    = NULL;
cb8e9e
         glusterd_conf_t    *priv    = NULL;
cb8e9e
 
cb8e9e
@@ -1287,59 +1286,22 @@ glusterd_svc_init_all ()
cb8e9e
         priv = this->private;
cb8e9e
         GF_ASSERT (priv);
cb8e9e
 
cb8e9e
-        /* Init SHD svc */
cb8e9e
-        ret = glusterd_shdsvc_init (&(priv->shd_svc));
cb8e9e
-        if (ret) {
cb8e9e
-                gf_msg (THIS->name, GF_LOG_ERROR, 0,
cb8e9e
-                        GD_MSG_FAILED_INIT_SHDSVC,
cb8e9e
-                        "Failed to init shd service");
cb8e9e
-                goto out;
cb8e9e
-        }
cb8e9e
-        gf_msg_debug (THIS->name, 0, "shd service initialized");
cb8e9e
+        priv->shd_svc.build = glusterd_shdsvc_build;
cb8e9e
+        priv->shd_svc.build (&(priv->shd_svc));
cb8e9e
 
cb8e9e
-        /* Init NFS svc */
cb8e9e
-        ret = glusterd_nfssvc_init (&(priv->nfs_svc));
cb8e9e
-        if (ret) {
cb8e9e
-                gf_msg (THIS->name, GF_LOG_ERROR, 0,
cb8e9e
-                        GD_MSG_FAILED_INIT_NFSSVC,
cb8e9e
-                        "Failed to init nfs service");
cb8e9e
-                goto out;
cb8e9e
-        }
cb8e9e
-        gf_msg_debug (THIS->name, 0, "nfs service initialized");
cb8e9e
+        priv->nfs_svc.build = glusterd_nfssvc_build;
cb8e9e
+        priv->nfs_svc.build (&(priv->nfs_svc));
cb8e9e
 
cb8e9e
-        /* Init QuotaD svc */
cb8e9e
-        ret = glusterd_quotadsvc_init (&(priv->quotad_svc));
cb8e9e
-        if (ret) {
cb8e9e
-                gf_msg (THIS->name, GF_LOG_ERROR, 0,
cb8e9e
-                        GD_MSG_FAILED_INIT_QUOTASVC, "Failed to init quotad "
cb8e9e
-                        "service");
cb8e9e
-                goto out;
cb8e9e
-        }
cb8e9e
-        gf_msg_debug (THIS->name, 0, "quotad service initialized");
cb8e9e
+        priv->quotad_svc.build = glusterd_quotadsvc_build;
cb8e9e
+        priv->quotad_svc.build (&(priv->quotad_svc));
cb8e9e
 
cb8e9e
-        /* Init BitD svc */
cb8e9e
-        ret = glusterd_bitdsvc_init (&(priv->bitd_svc));
cb8e9e
-        if (ret) {
cb8e9e
-                gf_msg (THIS->name, GF_LOG_ERROR, 0,
cb8e9e
-                        GD_MSG_BITD_INIT_FAIL, "Failed to initialized BitD "
cb8e9e
-                        "service");
cb8e9e
-                goto out;
cb8e9e
-        }
cb8e9e
-        gf_msg_debug (THIS->name, 0, "BitD service initialized");
cb8e9e
+        priv->bitd_svc.build = glusterd_bitdsvc_build;
cb8e9e
+        priv->bitd_svc.build (&(priv->bitd_svc));
cb8e9e
 
cb8e9e
-        ret = glusterd_scrubsvc_init (&(priv->scrub_svc));
cb8e9e
-        if (ret) {
cb8e9e
-                gf_msg (THIS->name, GF_LOG_ERROR, 0,
cb8e9e
-                        GD_MSG_SCRUB_INIT_FAIL, "Failed to initialized scrub "
cb8e9e
-                        "service");
cb8e9e
-                goto out;
cb8e9e
-        }
cb8e9e
-        gf_msg_debug (THIS->name, 0, "scrub service initialized");
cb8e9e
+        priv->scrub_svc.build = glusterd_scrubsvc_build;
cb8e9e
+        priv->scrub_svc.build (&(priv->scrub_svc));
cb8e9e
 
cb8e9e
-out:
cb8e9e
-        return ret;
cb8e9e
 }
cb8e9e
-
cb8e9e
 /*
cb8e9e
  * init - called during glusterd initialization
cb8e9e
  *
cb8e9e
@@ -1740,6 +1702,7 @@ init (xlator_t *this)
cb8e9e
         this->private = conf;
cb8e9e
         glusterd_mgmt_v3_lock_init ();
cb8e9e
         glusterd_txn_opinfo_dict_init ();
cb8e9e
+        glusterd_svcs_build ();
cb8e9e
 
cb8e9e
         /* Make install copies few of the hook-scripts by creating hooks
cb8e9e
          * directory. Hence purposefully not doing the check for the presence of
cb8e9e
@@ -1789,10 +1752,6 @@ init (xlator_t *this)
cb8e9e
                 goto out;
cb8e9e
         }
cb8e9e
 
cb8e9e
-        ret = glusterd_svc_init_all ();
cb8e9e
-        if (ret)
cb8e9e
-                goto out;
cb8e9e
-
cb8e9e
         ret = glusterd_restore ();
cb8e9e
         if (ret < 0)
cb8e9e
                 goto out;
cb8e9e
-- 
cb8e9e
1.7.1
cb8e9e