f338ef
From ec629963d61c3ec084c95366eec5ee3a976b1213 Mon Sep 17 00:00:00 2001
f338ef
From: Mohammed Rafi KC <rkavunga@redhat.com>
f338ef
Date: Thu, 11 Jul 2019 12:57:45 +0530
f338ef
Subject: [PATCH 250/255] Revert "mgmt/shd: Implement multiplexing in self heal
f338ef
 daemon"
f338ef
f338ef
This reverts commit 2cede2b87fb3e3e0673be9cf67e7d6eec3f7879c.
f338ef
f338ef
BUG: 1471742
f338ef
Change-Id: I3830d9189dfdb567a44935aa97dc963f4594dfdb
f338ef
fixes: bz#1471742
f338ef
Signed-off-by: Mohammed Rafi KC <rkavunga@redhat.com>
f338ef
Reviewed-on: https://code.engineering.redhat.com/gerrit/175959
f338ef
Tested-by: RHGS Build Bot <nigelb@redhat.com>
f338ef
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
f338ef
---
f338ef
 glusterfsd/src/glusterfsd-messages.h               |   2 +-
f338ef
 glusterfsd/src/glusterfsd-mgmt.c                   | 238 +------
f338ef
 glusterfsd/src/glusterfsd.c                        |  20 +-
f338ef
 libglusterfs/src/defaults-tmpl.c                   |  19 +-
f338ef
 libglusterfs/src/glusterfs/glusterfs.h             |   7 -
f338ef
 libglusterfs/src/glusterfs/libglusterfs-messages.h |   4 +-
f338ef
 libglusterfs/src/glusterfs/xlator.h                |   3 -
f338ef
 libglusterfs/src/graph.c                           | 451 -------------
f338ef
 libglusterfs/src/graph.y                           |   3 -
f338ef
 libglusterfs/src/libglusterfs.sym                  |   5 -
f338ef
 libglusterfs/src/statedump.c                       |   3 +-
f338ef
 libglusterfs/src/xlator.c                          |  16 -
f338ef
 rpc/rpc-lib/src/protocol-common.h                  |   2 -
f338ef
 tests/basic/glusterd/heald.t                       |  49 +-
f338ef
 .../reset-brick-and-daemons-follow-quorum.t        |   8 +-
f338ef
 tests/volume.rc                                    |   6 +-
f338ef
 xlators/mgmt/glusterd/src/Makefile.am              |   6 +-
f338ef
 xlators/mgmt/glusterd/src/glusterd-brick-ops.c     |   2 +-
f338ef
 xlators/mgmt/glusterd/src/glusterd-conn-mgmt.c     |  42 --
f338ef
 xlators/mgmt/glusterd/src/glusterd-conn-mgmt.h     |   4 +-
f338ef
 xlators/mgmt/glusterd/src/glusterd-gfproxyd-svc.c  |   3 +-
f338ef
 xlators/mgmt/glusterd/src/glusterd-handler.c       |  11 +-
f338ef
 xlators/mgmt/glusterd/src/glusterd-handshake.c     |  21 -
f338ef
 xlators/mgmt/glusterd/src/glusterd-mem-types.h     |   1 -
f338ef
 xlators/mgmt/glusterd/src/glusterd-messages.h      |   4 +-
f338ef
 xlators/mgmt/glusterd/src/glusterd-op-sm.c         |  84 +--
f338ef
 .../mgmt/glusterd/src/glusterd-shd-svc-helper.c    | 140 ----
f338ef
 .../mgmt/glusterd/src/glusterd-shd-svc-helper.h    |  45 --
f338ef
 xlators/mgmt/glusterd/src/glusterd-shd-svc.c       | 540 ++--------------
f338ef
 xlators/mgmt/glusterd/src/glusterd-shd-svc.h       |  17 +-
f338ef
 xlators/mgmt/glusterd/src/glusterd-sm.c            |  12 +-
f338ef
 xlators/mgmt/glusterd/src/glusterd-snapd-svc.c     |   3 +-
f338ef
 xlators/mgmt/glusterd/src/glusterd-statedump.c     |   3 +
f338ef
 xlators/mgmt/glusterd/src/glusterd-svc-helper.c    | 715 +--------------------
f338ef
 xlators/mgmt/glusterd/src/glusterd-svc-helper.h    |  40 +-
f338ef
 xlators/mgmt/glusterd/src/glusterd-svc-mgmt.c      | 246 ++-----
f338ef
 xlators/mgmt/glusterd/src/glusterd-svc-mgmt.h      |  27 -
f338ef
 xlators/mgmt/glusterd/src/glusterd-tier.c          |   3 +-
f338ef
 xlators/mgmt/glusterd/src/glusterd-tierd-svc.c     |   4 +-
f338ef
 xlators/mgmt/glusterd/src/glusterd-utils.c         | 137 +---
f338ef
 xlators/mgmt/glusterd/src/glusterd-utils.h         |   4 -
f338ef
 xlators/mgmt/glusterd/src/glusterd-volgen.c        |  60 +-
f338ef
 xlators/mgmt/glusterd/src/glusterd-volgen.h        |  11 +-
f338ef
 xlators/mgmt/glusterd/src/glusterd-volume-ops.c    |   8 +-
f338ef
 xlators/mgmt/glusterd/src/glusterd.c               |  12 +-
f338ef
 xlators/mgmt/glusterd/src/glusterd.h               |  30 +-
f338ef
 xlators/protocol/client/src/client.c               |  31 +-
f338ef
 47 files changed, 292 insertions(+), 2810 deletions(-)
f338ef
 delete mode 100644 xlators/mgmt/glusterd/src/glusterd-shd-svc-helper.c
f338ef
 delete mode 100644 xlators/mgmt/glusterd/src/glusterd-shd-svc-helper.h
f338ef
f338ef
diff --git a/glusterfsd/src/glusterfsd-messages.h b/glusterfsd/src/glusterfsd-messages.h
f338ef
index 280624c..ce6c8ca 100644
f338ef
--- a/glusterfsd/src/glusterfsd-messages.h
f338ef
+++ b/glusterfsd/src/glusterfsd-messages.h
f338ef
@@ -36,6 +36,6 @@ GLFS_MSGID(GLUSTERFSD, glusterfsd_msg_1, glusterfsd_msg_2, glusterfsd_msg_3,
f338ef
            glusterfsd_msg_31, glusterfsd_msg_32, glusterfsd_msg_33,
f338ef
            glusterfsd_msg_34, glusterfsd_msg_35, glusterfsd_msg_36,
f338ef
            glusterfsd_msg_37, glusterfsd_msg_38, glusterfsd_msg_39,
f338ef
-           glusterfsd_msg_40, glusterfsd_msg_41, glusterfsd_msg_42, glusterfsd_msg_43);
f338ef
+           glusterfsd_msg_40);
f338ef
 
f338ef
 #endif /* !_GLUSTERFSD_MESSAGES_H_ */
f338ef
diff --git a/glusterfsd/src/glusterfsd-mgmt.c b/glusterfsd/src/glusterfsd-mgmt.c
f338ef
index 1d2cd1a..15acc10 100644
f338ef
--- a/glusterfsd/src/glusterfsd-mgmt.c
f338ef
+++ b/glusterfsd/src/glusterfsd-mgmt.c
f338ef
@@ -48,20 +48,7 @@ int
f338ef
 glusterfs_graph_unknown_options(glusterfs_graph_t *graph);
f338ef
 int
f338ef
 emancipate(glusterfs_ctx_t *ctx, int ret);
f338ef
-int
f338ef
-glusterfs_process_svc_attach_volfp(glusterfs_ctx_t *ctx, FILE *fp,
f338ef
-                                   char *volfile_id, char *checksum);
f338ef
-int
f338ef
-glusterfs_mux_volfile_reconfigure(FILE *newvolfile_fp, glusterfs_ctx_t *ctx,
f338ef
-                                  gf_volfile_t *volfile_obj, char *checksum);
f338ef
-int
f338ef
-glusterfs_process_svc_attach_volfp(glusterfs_ctx_t *ctx, FILE *fp,
f338ef
-                                   char *volfile_id, char *checksum);
f338ef
-int
f338ef
-glusterfs_process_svc_detach(glusterfs_ctx_t *ctx, gf_volfile_t *volfile_obj);
f338ef
 
f338ef
-gf_boolean_t
f338ef
-mgmt_is_multiplexed_daemon(char *name);
f338ef
 int
f338ef
 mgmt_cbk_spec(struct rpc_clnt *rpc, void *mydata, void *data)
f338ef
 {
f338ef
@@ -75,96 +62,6 @@ mgmt_cbk_spec(struct rpc_clnt *rpc, void *mydata, void *data)
f338ef
 }
f338ef
 
f338ef
 int
f338ef
-mgmt_process_volfile(const char *volfile, ssize_t size, char *volfile_id)
f338ef
-{
f338ef
-    glusterfs_ctx_t *ctx = NULL;
f338ef
-    int ret = 0;
f338ef
-    FILE *tmpfp = NULL;
f338ef
-    gf_volfile_t *volfile_obj = NULL;
f338ef
-    gf_volfile_t *volfile_tmp = NULL;
f338ef
-    char sha256_hash[SHA256_DIGEST_LENGTH] = {
f338ef
-        0,
f338ef
-    };
f338ef
-    int tmp_fd = -1;
f338ef
-    char template[] = "/tmp/glfs.volfile.XXXXXX";
f338ef
-
f338ef
-    glusterfs_compute_sha256((const unsigned char *)volfile, size, sha256_hash);
f338ef
-    ctx = THIS->ctx;
f338ef
-    LOCK(&ctx->volfile_lock);
f338ef
-    {
f338ef
-        list_for_each_entry(volfile_obj, &ctx->volfile_list, volfile_list)
f338ef
-        {
f338ef
-            if (!strcmp(volfile_id, volfile_obj->vol_id)) {
f338ef
-                if (!memcmp(sha256_hash, volfile_obj->volfile_checksum,
f338ef
-                            sizeof(volfile_obj->volfile_checksum))) {
f338ef
-                    UNLOCK(&ctx->volfile_lock);
f338ef
-                    gf_msg(THIS->name, GF_LOG_INFO, 0, glusterfsd_msg_40,
f338ef
-                           "No change in volfile, continuing");
f338ef
-                    goto out;
f338ef
-                }
f338ef
-                volfile_tmp = volfile_obj;
f338ef
-                break;
f338ef
-            }
f338ef
-        }
f338ef
-
f338ef
-        /* coverity[secure_temp] mkstemp uses 0600 as the mode */
f338ef
-        tmp_fd = mkstemp(template);
f338ef
-        if (-1 == tmp_fd) {
f338ef
-            UNLOCK(&ctx->volfile_lock);
f338ef
-            gf_msg(THIS->name, GF_LOG_ERROR, 0, glusterfsd_msg_39,
f338ef
-                   "Unable to create temporary file: %s", template);
f338ef
-            ret = -1;
f338ef
-            goto out;
f338ef
-        }
f338ef
-
f338ef
-        /* Calling unlink so that when the file is closed or program
f338ef
-         * terminates the temporary file is deleted.
f338ef
-         */
f338ef
-        ret = sys_unlink(template);
f338ef
-        if (ret < 0) {
f338ef
-            gf_msg(THIS->name, GF_LOG_INFO, 0, glusterfsd_msg_39,
f338ef
-                   "Unable to delete temporary file: %s", template);
f338ef
-            ret = 0;
f338ef
-        }
f338ef
-
f338ef
-        tmpfp = fdopen(tmp_fd, "w+b");
f338ef
-        if (!tmpfp) {
f338ef
-            ret = -1;
f338ef
-            goto unlock;
f338ef
-        }
f338ef
-
f338ef
-        fwrite(volfile, size, 1, tmpfp);
f338ef
-        fflush(tmpfp);
f338ef
-        if (ferror(tmpfp)) {
f338ef
-            ret = -1;
f338ef
-            goto unlock;
f338ef
-        }
f338ef
-
f338ef
-        if (!volfile_tmp) {
f338ef
-            /* There is no checksum in the list, which means simple attach
f338ef
-             * the volfile
f338ef
-             */
f338ef
-            ret = glusterfs_process_svc_attach_volfp(ctx, tmpfp, volfile_id,
f338ef
-                                                     sha256_hash);
f338ef
-            goto unlock;
f338ef
-        }
f338ef
-        ret = glusterfs_mux_volfile_reconfigure(tmpfp, ctx, volfile_obj,
f338ef
-                                                sha256_hash);
f338ef
-        if (ret < 0) {
f338ef
-            gf_msg_debug("glusterfsd-mgmt", EINVAL, "Reconfigure failed !!");
f338ef
-        }
f338ef
-    }
f338ef
-unlock:
f338ef
-    UNLOCK(&ctx->volfile_lock);
f338ef
-out:
f338ef
-    if (tmpfp)
f338ef
-        fclose(tmpfp);
f338ef
-    else if (tmp_fd != -1)
f338ef
-        sys_close(tmp_fd);
f338ef
-    return ret;
f338ef
-}
f338ef
-
f338ef
-int
f338ef
 mgmt_cbk_event(struct rpc_clnt *rpc, void *mydata, void *data)
f338ef
 {
f338ef
     return 0;
f338ef
@@ -1069,110 +966,6 @@ glusterfs_handle_attach(rpcsvc_request_t *req)
f338ef
 }
f338ef
 
f338ef
 int
f338ef
-glusterfs_handle_svc_attach(rpcsvc_request_t *req)
f338ef
-{
f338ef
-    int32_t ret = -1;
f338ef
-    gd1_mgmt_brick_op_req xlator_req = {
f338ef
-        0,
f338ef
-    };
f338ef
-    xlator_t *this = NULL;
f338ef
-    glusterfs_ctx_t *ctx = NULL;
f338ef
-
f338ef
-    GF_ASSERT(req);
f338ef
-    this = THIS;
f338ef
-    GF_ASSERT(this);
f338ef
-
f338ef
-    ctx = this->ctx;
f338ef
-    ret = xdr_to_generic(req->msg[0], &xlator_req,
f338ef
-                         (xdrproc_t)xdr_gd1_mgmt_brick_op_req);
f338ef
-
f338ef
-    if (ret < 0) {
f338ef
-        /*failed to decode msg;*/
f338ef
-        req->rpc_err = GARBAGE_ARGS;
f338ef
-        goto out;
f338ef
-    }
f338ef
-    gf_msg(THIS->name, GF_LOG_INFO, 0, glusterfsd_msg_41,
f338ef
-           "received attach "
f338ef
-           "request for volfile-id=%s",
f338ef
-           xlator_req.name);
f338ef
-    ret = 0;
f338ef
-
f338ef
-    if (ctx->active) {
f338ef
-        ret = mgmt_process_volfile(xlator_req.input.input_val,
f338ef
-                                   xlator_req.input.input_len, xlator_req.name);
f338ef
-    } else {
f338ef
-        gf_msg(this->name, GF_LOG_WARNING, EINVAL, glusterfsd_msg_42,
f338ef
-               "got attach for %s but no active graph", xlator_req.name);
f338ef
-    }
f338ef
-out:
f338ef
-    if (xlator_req.input.input_val)
f338ef
-        free(xlator_req.input.input_val);
f338ef
-    if (xlator_req.name)
f338ef
-        free(xlator_req.name);
f338ef
-    glusterfs_translator_info_response_send(req, ret, NULL, NULL);
f338ef
-    return 0;
f338ef
-}
f338ef
-
f338ef
-int
f338ef
-glusterfs_handle_svc_detach(rpcsvc_request_t *req)
f338ef
-{
f338ef
-    gd1_mgmt_brick_op_req xlator_req = {
f338ef
-        0,
f338ef
-    };
f338ef
-    ssize_t ret;
f338ef
-    glusterfs_ctx_t *ctx = NULL;
f338ef
-    gf_volfile_t *volfile_obj = NULL;
f338ef
-    gf_volfile_t *volfile_tmp = NULL;
f338ef
-
f338ef
-    ret = xdr_to_generic(req->msg[0], &xlator_req,
f338ef
-                         (xdrproc_t)xdr_gd1_mgmt_brick_op_req);
f338ef
-    if (ret < 0) {
f338ef
-        req->rpc_err = GARBAGE_ARGS;
f338ef
-        return -1;
f338ef
-    }
f338ef
-    ctx = glusterfsd_ctx;
f338ef
-
f338ef
-    LOCK(&ctx->volfile_lock);
f338ef
-    {
f338ef
-        list_for_each_entry(volfile_obj, &ctx->volfile_list, volfile_list)
f338ef
-        {
f338ef
-            if (!strcmp(xlator_req.name, volfile_obj->vol_id)) {
f338ef
-                volfile_tmp = volfile_obj;
f338ef
-                break;
f338ef
-            }
f338ef
-        }
f338ef
-
f338ef
-        if (!volfile_tmp) {
f338ef
-            UNLOCK(&ctx->volfile_lock);
f338ef
-            gf_msg(THIS->name, GF_LOG_ERROR, 0, glusterfsd_msg_41,
f338ef
-                   "can't detach %s - not found", xlator_req.name);
f338ef
-            /*
f338ef
-             * Used to be -ENOENT.  However, the caller asked us to
f338ef
-             * make sure it's down and if it's already down that's
f338ef
-             * good enough.
f338ef
-             */
f338ef
-            ret = 0;
f338ef
-            goto out;
f338ef
-        }
f338ef
-        ret = glusterfs_process_svc_detach(ctx, volfile_tmp);
f338ef
-        if (ret) {
f338ef
-            UNLOCK(&ctx->volfile_lock);
f338ef
-            gf_msg("glusterfsd-mgmt", GF_LOG_ERROR, EINVAL, glusterfsd_msg_41,
f338ef
-                   "Could not detach "
f338ef
-                   "old graph. Aborting the reconfiguration operation");
f338ef
-            goto out;
f338ef
-        }
f338ef
-    }
f338ef
-    UNLOCK(&ctx->volfile_lock);
f338ef
-out:
f338ef
-    glusterfs_terminate_response_send(req, ret);
f338ef
-    free(xlator_req.name);
f338ef
-    xlator_req.name = NULL;
f338ef
-
f338ef
-    return 0;
f338ef
-}
f338ef
-
f338ef
-int
f338ef
 glusterfs_handle_dump_metrics(rpcsvc_request_t *req)
f338ef
 {
f338ef
     int32_t ret = -1;
f338ef
@@ -2056,13 +1849,6 @@ rpcsvc_actor_t glusterfs_actors[GLUSTERD_BRICK_MAXVALUE] = {
f338ef
 
f338ef
     [GLUSTERD_DUMP_METRICS] = {"DUMP METRICS", GLUSTERD_DUMP_METRICS,
f338ef
                                glusterfs_handle_dump_metrics, NULL, 0, DRC_NA},
f338ef
-
f338ef
-    [GLUSTERD_SVC_ATTACH] = {"ATTACH CLIENT", GLUSTERD_SVC_ATTACH,
f338ef
-                             glusterfs_handle_svc_attach, NULL, 0, DRC_NA},
f338ef
-
f338ef
-    [GLUSTERD_SVC_DETACH] = {"DETACH CLIENT", GLUSTERD_SVC_DETACH,
f338ef
-                             glusterfs_handle_svc_detach, NULL, 0, DRC_NA},
f338ef
-
f338ef
 };
f338ef
 
f338ef
 struct rpcsvc_program glusterfs_mop_prog = {
f338ef
@@ -2210,17 +1996,14 @@ mgmt_getspec_cbk(struct rpc_req *req, struct iovec *iov, int count,
f338ef
     }
f338ef
 
f338ef
 volfile:
f338ef
+    ret = 0;
f338ef
     size = rsp.op_ret;
f338ef
-    volfile_id = frame->local;
f338ef
-    if (mgmt_is_multiplexed_daemon(ctx->cmd_args.process_name)) {
f338ef
-        ret = mgmt_process_volfile((const char *)rsp.spec, size, volfile_id);
f338ef
-        goto post_graph_mgmt;
f338ef
-    }
f338ef
 
f338ef
-    ret = 0;
f338ef
     glusterfs_compute_sha256((const unsigned char *)rsp.spec, size,
f338ef
                              sha256_hash);
f338ef
 
f338ef
+    volfile_id = frame->local;
f338ef
+
f338ef
     LOCK(&ctx->volfile_lock);
f338ef
     {
f338ef
         locked = 1;
f338ef
@@ -2322,7 +2105,6 @@ volfile:
f338ef
             }
f338ef
 
f338ef
             INIT_LIST_HEAD(&volfile_tmp->volfile_list);
f338ef
-            volfile_tmp->graph = ctx->active;
f338ef
             list_add(&volfile_tmp->volfile_list, &ctx->volfile_list);
f338ef
             snprintf(volfile_tmp->vol_id, sizeof(volfile_tmp->vol_id), "%s",
f338ef
                      volfile_id);
f338ef
@@ -2334,7 +2116,6 @@ volfile:
f338ef
 
f338ef
     locked = 0;
f338ef
 
f338ef
-post_graph_mgmt:
f338ef
     if (!is_mgmt_rpc_reconnect) {
f338ef
         need_emancipate = 1;
f338ef
         glusterfs_mgmt_pmap_signin(ctx);
f338ef
@@ -2488,21 +2269,10 @@ glusterfs_volfile_fetch(glusterfs_ctx_t *ctx)
f338ef
 {
f338ef
     xlator_t *server_xl = NULL;
f338ef
     xlator_list_t *trav;
f338ef
-    gf_volfile_t *volfile_obj = NULL;
f338ef
-    int ret = 0;
f338ef
+    int ret;
f338ef
 
f338ef
     LOCK(&ctx->volfile_lock);
f338ef
     {
f338ef
-        if (ctx->active &&
f338ef
-            mgmt_is_multiplexed_daemon(ctx->cmd_args.process_name)) {
f338ef
-            list_for_each_entry(volfile_obj, &ctx->volfile_list, volfile_list)
f338ef
-            {
f338ef
-                ret |= glusterfs_volfile_fetch_one(ctx, volfile_obj->vol_id);
f338ef
-            }
f338ef
-            UNLOCK(&ctx->volfile_lock);
f338ef
-            return ret;
f338ef
-        }
f338ef
-
f338ef
         if (ctx->active) {
f338ef
             server_xl = ctx->active->first;
f338ef
             if (strcmp(server_xl->type, "protocol/server") != 0) {
f338ef
diff --git a/glusterfsd/src/glusterfsd.c b/glusterfsd/src/glusterfsd.c
f338ef
index 2172af4..5b5e996 100644
f338ef
--- a/glusterfsd/src/glusterfsd.c
f338ef
+++ b/glusterfsd/src/glusterfsd.c
f338ef
@@ -2593,6 +2593,24 @@ out:
f338ef
 #endif
f338ef
 
f338ef
 int
f338ef
+glusterfs_graph_fini(glusterfs_graph_t *graph)
f338ef
+{
f338ef
+    xlator_t *trav = NULL;
f338ef
+
f338ef
+    trav = graph->first;
f338ef
+
f338ef
+    while (trav) {
f338ef
+        if (trav->init_succeeded) {
f338ef
+            trav->fini(trav);
f338ef
+            trav->init_succeeded = 0;
f338ef
+        }
f338ef
+        trav = trav->next;
f338ef
+    }
f338ef
+
f338ef
+    return 0;
f338ef
+}
f338ef
+
f338ef
+int
f338ef
 glusterfs_process_volfp(glusterfs_ctx_t *ctx, FILE *fp)
f338ef
 {
f338ef
     glusterfs_graph_t *graph = NULL;
f338ef
@@ -2791,7 +2809,7 @@ main(int argc, char *argv[])
f338ef
 
f338ef
     /* set brick_mux mode only for server process */
f338ef
     if ((ctx->process_mode != GF_SERVER_PROCESS) && cmd->brick_mux) {
f338ef
-        gf_msg("glusterfs", GF_LOG_CRITICAL, 0, glusterfsd_msg_43,
f338ef
+        gf_msg("glusterfs", GF_LOG_CRITICAL, 0, glusterfsd_msg_40,
f338ef
                "command line argument --brick-mux is valid only for brick "
f338ef
                "process");
f338ef
         goto out;
f338ef
diff --git a/libglusterfs/src/defaults-tmpl.c b/libglusterfs/src/defaults-tmpl.c
f338ef
index 82e7f78..5bf64e8 100644
f338ef
--- a/libglusterfs/src/defaults-tmpl.c
f338ef
+++ b/libglusterfs/src/defaults-tmpl.c
f338ef
@@ -127,12 +127,6 @@ default_notify(xlator_t *this, int32_t event, void *data, ...)
f338ef
     GF_UNUSED int ret = 0;
f338ef
     xlator_t *victim = data;
f338ef
 
f338ef
-    glusterfs_graph_t *graph = NULL;
f338ef
-
f338ef
-    GF_VALIDATE_OR_GOTO("notify", this, out);
f338ef
-    graph = this->graph;
f338ef
-    GF_VALIDATE_OR_GOTO(this->name, graph, out);
f338ef
-
f338ef
     switch (event) {
f338ef
         case GF_EVENT_PARENT_UP:
f338ef
         case GF_EVENT_PARENT_DOWN: {
f338ef
@@ -165,17 +159,6 @@ default_notify(xlator_t *this, int32_t event, void *data, ...)
f338ef
                     xlator_notify(parent->xlator, event, this, NULL);
f338ef
                 parent = parent->next;
f338ef
             }
f338ef
-
f338ef
-            if (event == GF_EVENT_CHILD_DOWN &&
f338ef
-                !(this->ctx && this->ctx->master) && (graph->top == this)) {
f338ef
-                /* Make sure this is not a daemon with master xlator */
f338ef
-                pthread_mutex_lock(&graph->mutex);
f338ef
-                {
f338ef
-                    graph->used = 0;
f338ef
-                    pthread_cond_broadcast(&graph->child_down_cond);
f338ef
-                }
f338ef
-                pthread_mutex_unlock(&graph->mutex);
f338ef
-            }
f338ef
         } break;
f338ef
         case GF_EVENT_UPCALL: {
f338ef
             xlator_list_t *parent = this->parents;
f338ef
@@ -222,7 +205,7 @@ default_notify(xlator_t *this, int32_t event, void *data, ...)
f338ef
              * nothing to do with readability.
f338ef
              */
f338ef
     }
f338ef
-out:
f338ef
+
f338ef
     return 0;
f338ef
 }
f338ef
 
f338ef
diff --git a/libglusterfs/src/glusterfs/glusterfs.h b/libglusterfs/src/glusterfs/glusterfs.h
f338ef
index 9ec2365..2cedf1a 100644
f338ef
--- a/libglusterfs/src/glusterfs/glusterfs.h
f338ef
+++ b/libglusterfs/src/glusterfs/glusterfs.h
f338ef
@@ -597,10 +597,6 @@ struct _glusterfs_graph {
f338ef
     int used; /* Should be set when fuse gets
f338ef
                         first CHILD_UP */
f338ef
     uint32_t volfile_checksum;
f338ef
-    void *last_xl; /* Stores the last xl of the graph, as of now only populated
f338ef
-                      in client multiplexed code path */
f338ef
-    pthread_mutex_t mutex;
f338ef
-    pthread_cond_t child_down_cond; /* for broadcasting CHILD_DOWN */
f338ef
 };
f338ef
 typedef struct _glusterfs_graph glusterfs_graph_t;
f338ef
 
f338ef
@@ -743,7 +739,6 @@ typedef struct {
f338ef
     char volfile_checksum[SHA256_DIGEST_LENGTH];
f338ef
     char vol_id[NAME_MAX + 1];
f338ef
     struct list_head volfile_list;
f338ef
-    glusterfs_graph_t *graph;
f338ef
 
f338ef
 } gf_volfile_t;
f338ef
 
f338ef
@@ -827,6 +822,4 @@ gf_free_mig_locks(lock_migration_info_t *locks);
f338ef
 
f338ef
 int
f338ef
 glusterfs_read_secure_access_file(void);
f338ef
-int
f338ef
-glusterfs_graph_fini(glusterfs_graph_t *graph);
f338ef
 #endif /* _GLUSTERFS_H */
f338ef
diff --git a/libglusterfs/src/glusterfs/libglusterfs-messages.h b/libglusterfs/src/glusterfs/libglusterfs-messages.h
f338ef
index ea2aa60..1b72f6d 100644
f338ef
--- a/libglusterfs/src/glusterfs/libglusterfs-messages.h
f338ef
+++ b/libglusterfs/src/glusterfs/libglusterfs-messages.h
f338ef
@@ -109,8 +109,6 @@ GLFS_MSGID(
f338ef
     LG_MSG_PTHREAD_ATTR_INIT_FAILED, LG_MSG_INVALID_INODE_LIST,
f338ef
     LG_MSG_COMPACT_FAILED, LG_MSG_COMPACT_STATUS, LG_MSG_UTIMENSAT_FAILED,
f338ef
     LG_MSG_PTHREAD_NAMING_FAILED, LG_MSG_SYSCALL_RETURNS_WRONG,
f338ef
-    LG_MSG_XXH64_TO_GFID_FAILED, LG_MSG_ASYNC_WARNING, LG_MSG_ASYNC_FAILURE,
f338ef
-    LG_MSG_GRAPH_CLEANUP_FAILED, LG_MSG_GRAPH_SETUP_FAILED,
f338ef
-    LG_MSG_GRAPH_DETACH_STARTED, LG_MSG_GRAPH_ATTACH_FAILED);
f338ef
+    LG_MSG_XXH64_TO_GFID_FAILED);
f338ef
 
f338ef
 #endif /* !_LG_MESSAGES_H_ */
f338ef
diff --git a/libglusterfs/src/glusterfs/xlator.h b/libglusterfs/src/glusterfs/xlator.h
f338ef
index 8998976..b78daad 100644
f338ef
--- a/libglusterfs/src/glusterfs/xlator.h
f338ef
+++ b/libglusterfs/src/glusterfs/xlator.h
f338ef
@@ -1089,7 +1089,4 @@ handle_default_options(xlator_t *xl, dict_t *options);
f338ef
 
f338ef
 void
f338ef
 gluster_graph_take_reference(xlator_t *tree);
f338ef
-
f338ef
-gf_boolean_t
f338ef
-mgmt_is_multiplexed_daemon(char *name);
f338ef
 #endif /* _XLATOR_H */
f338ef
diff --git a/libglusterfs/src/graph.c b/libglusterfs/src/graph.c
f338ef
index a492dd8..bb5e67a 100644
f338ef
--- a/libglusterfs/src/graph.c
f338ef
+++ b/libglusterfs/src/graph.c
f338ef
@@ -114,53 +114,6 @@ out:
f338ef
     return cert_depth;
f338ef
 }
f338ef
 
f338ef
-xlator_t *
f338ef
-glusterfs_get_last_xlator(glusterfs_graph_t *graph)
f338ef
-{
f338ef
-    xlator_t *trav = graph->first;
f338ef
-    if (!trav)
f338ef
-        return NULL;
f338ef
-
f338ef
-    while (trav->next)
f338ef
-        trav = trav->next;
f338ef
-
f338ef
-    return trav;
f338ef
-}
f338ef
-
f338ef
-xlator_t *
f338ef
-glusterfs_mux_xlator_unlink(xlator_t *pxl, xlator_t *cxl)
f338ef
-{
f338ef
-    xlator_list_t *unlink = NULL;
f338ef
-    xlator_list_t *prev = NULL;
f338ef
-    xlator_list_t **tmp = NULL;
f338ef
-    xlator_t *next_child = NULL;
f338ef
-    xlator_t *xl = NULL;
f338ef
-
f338ef
-    for (tmp = &pxl->children; *tmp; tmp = &(*tmp)->next) {
f338ef
-        if ((*tmp)->xlator == cxl) {
f338ef
-            unlink = *tmp;
f338ef
-            *tmp = (*tmp)->next;
f338ef
-            if (*tmp)
f338ef
-                next_child = (*tmp)->xlator;
f338ef
-            break;
f338ef
-        }
f338ef
-        prev = *tmp;
f338ef
-    }
f338ef
-
f338ef
-    if (!prev)
f338ef
-        xl = pxl;
f338ef
-    else if (prev->xlator)
f338ef
-        xl = prev->xlator->graph->last_xl;
f338ef
-
f338ef
-    if (xl)
f338ef
-        xl->next = next_child;
f338ef
-    if (next_child)
f338ef
-        next_child->prev = xl;
f338ef
-
f338ef
-    GF_FREE(unlink);
f338ef
-    return next_child;
f338ef
-}
f338ef
-
f338ef
 int
f338ef
 glusterfs_xlator_link(xlator_t *pxl, xlator_t *cxl)
f338ef
 {
f338ef
@@ -1139,8 +1092,6 @@ glusterfs_graph_destroy_residual(glusterfs_graph_t *graph)
f338ef
     ret = xlator_tree_free_memacct(graph->first);
f338ef
 
f338ef
     list_del_init(&graph->list);
f338ef
-    pthread_mutex_destroy(&graph->mutex);
f338ef
-    pthread_cond_destroy(&graph->child_down_cond);
f338ef
     GF_FREE(graph);
f338ef
 
f338ef
     return ret;
f338ef
@@ -1183,25 +1134,6 @@ out:
f338ef
 }
f338ef
 
f338ef
 int
f338ef
-glusterfs_graph_fini(glusterfs_graph_t *graph)
f338ef
-{
f338ef
-    xlator_t *trav = NULL;
f338ef
-
f338ef
-    trav = graph->first;
f338ef
-
f338ef
-    while (trav) {
f338ef
-        if (trav->init_succeeded) {
f338ef
-            trav->cleanup_starting = 1;
f338ef
-            trav->fini(trav);
f338ef
-            trav->init_succeeded = 0;
f338ef
-        }
f338ef
-        trav = trav->next;
f338ef
-    }
f338ef
-
f338ef
-    return 0;
f338ef
-}
f338ef
-
f338ef
-int
f338ef
 glusterfs_graph_attach(glusterfs_graph_t *orig_graph, char *path,
f338ef
                        glusterfs_graph_t **newgraph)
f338ef
 {
f338ef
@@ -1324,386 +1256,3 @@ glusterfs_graph_attach(glusterfs_graph_t *orig_graph, char *path,
f338ef
 
f338ef
     return 0;
f338ef
 }
f338ef
-int
f338ef
-glusterfs_muxsvc_cleanup_parent(glusterfs_ctx_t *ctx,
f338ef
-                                glusterfs_graph_t *parent_graph)
f338ef
-{
f338ef
-    if (parent_graph) {
f338ef
-        if (parent_graph->first) {
f338ef
-            xlator_destroy(parent_graph->first);
f338ef
-        }
f338ef
-        ctx->active = NULL;
f338ef
-        GF_FREE(parent_graph);
f338ef
-        parent_graph = NULL;
f338ef
-    }
f338ef
-    return 0;
f338ef
-}
f338ef
-
f338ef
-void *
f338ef
-glusterfs_graph_cleanup(void *arg)
f338ef
-{
f338ef
-    glusterfs_graph_t *graph = NULL;
f338ef
-    glusterfs_ctx_t *ctx = THIS->ctx;
f338ef
-    int ret = -1;
f338ef
-    graph = arg;
f338ef
-
f338ef
-    if (!graph)
f338ef
-        return NULL;
f338ef
-
f338ef
-    /* To destroy the graph, fitst sent a GF_EVENT_PARENT_DOWN
f338ef
-     * Then wait for GF_EVENT_CHILD_DOWN to get on the top
f338ef
-     * xl. Once we have GF_EVENT_CHILD_DOWN event, then proceed
f338ef
-     * to fini.
f338ef
-     *
f338ef
-     * During fini call, this will take a last unref on rpc and
f338ef
-     * rpc_transport_object.
f338ef
-     */
f338ef
-    if (graph->first)
f338ef
-        default_notify(graph->first, GF_EVENT_PARENT_DOWN, graph->first);
f338ef
-
f338ef
-    ret = pthread_mutex_lock(&graph->mutex);
f338ef
-    if (ret != 0) {
f338ef
-        gf_msg("glusterfs", GF_LOG_ERROR, EAGAIN, LG_MSG_GRAPH_CLEANUP_FAILED,
f338ef
-               "Failed to aquire a lock");
f338ef
-        goto out;
f338ef
-    }
f338ef
-    /* check and wait for CHILD_DOWN for top xlator*/
f338ef
-    while (graph->used) {
f338ef
-        ret = pthread_cond_wait(&graph->child_down_cond, &graph->mutex);
f338ef
-        if (ret != 0)
f338ef
-            gf_msg("glusterfs", GF_LOG_INFO, 0, LG_MSG_GRAPH_CLEANUP_FAILED,
f338ef
-                   "cond wait failed ");
f338ef
-    }
f338ef
-
f338ef
-    ret = pthread_mutex_unlock(&graph->mutex);
f338ef
-    if (ret != 0) {
f338ef
-        gf_msg("glusterfs", GF_LOG_ERROR, EAGAIN, LG_MSG_GRAPH_CLEANUP_FAILED,
f338ef
-               "Failed to release a lock");
f338ef
-    }
f338ef
-
f338ef
-    /* Though we got a child down on top xlator, we have to wait until
f338ef
-     * all the notifier to exit. Because there should not be any threads
f338ef
-     * that access xl variables.
f338ef
-     */
f338ef
-    pthread_mutex_lock(&ctx->notify_lock);
f338ef
-    {
f338ef
-        while (ctx->notifying)
f338ef
-            pthread_cond_wait(&ctx->notify_cond, &ctx->notify_lock);
f338ef
-    }
f338ef
-    pthread_mutex_unlock(&ctx->notify_lock);
f338ef
-
f338ef
-    glusterfs_graph_fini(graph);
f338ef
-    glusterfs_graph_destroy(graph);
f338ef
-out:
f338ef
-    return NULL;
f338ef
-}
f338ef
-
f338ef
-glusterfs_graph_t *
f338ef
-glusterfs_muxsvc_setup_parent_graph(glusterfs_ctx_t *ctx, char *name,
f338ef
-                                    char *type)
f338ef
-{
f338ef
-    glusterfs_graph_t *parent_graph = NULL;
f338ef
-    xlator_t *ixl = NULL;
f338ef
-    int ret = -1;
f338ef
-    parent_graph = GF_CALLOC(1, sizeof(*parent_graph),
f338ef
-                             gf_common_mt_glusterfs_graph_t);
f338ef
-    if (!parent_graph)
f338ef
-        goto out;
f338ef
-
f338ef
-    INIT_LIST_HEAD(&parent_graph->list);
f338ef
-
f338ef
-    ctx->active = parent_graph;
f338ef
-    ixl = GF_CALLOC(1, sizeof(*ixl), gf_common_mt_xlator_t);
f338ef
-    if (!ixl)
f338ef
-        goto out;
f338ef
-
f338ef
-    ixl->ctx = ctx;
f338ef
-    ixl->graph = parent_graph;
f338ef
-    ixl->options = dict_new();
f338ef
-    if (!ixl->options)
f338ef
-        goto out;
f338ef
-
f338ef
-    ixl->name = gf_strdup(name);
f338ef
-    if (!ixl->name)
f338ef
-        goto out;
f338ef
-
f338ef
-    ixl->is_autoloaded = 1;
f338ef
-
f338ef
-    if (xlator_set_type(ixl, type) == -1) {
f338ef
-        gf_msg("glusterfs", GF_LOG_ERROR, EINVAL, LG_MSG_GRAPH_SETUP_FAILED,
f338ef
-               "%s (%s) set type failed", name, type);
f338ef
-        goto out;
f338ef
-    }
f338ef
-
f338ef
-    glusterfs_graph_set_first(parent_graph, ixl);
f338ef
-    parent_graph->top = ixl;
f338ef
-    ixl = NULL;
f338ef
-
f338ef
-    gettimeofday(&parent_graph->dob, NULL);
f338ef
-    fill_uuid(parent_graph->graph_uuid, 128);
f338ef
-    parent_graph->id = ctx->graph_id++;
f338ef
-    ret = 0;
f338ef
-out:
f338ef
-    if (ixl)
f338ef
-        xlator_destroy(ixl);
f338ef
-
f338ef
-    if (ret) {
f338ef
-        glusterfs_muxsvc_cleanup_parent(ctx, parent_graph);
f338ef
-        parent_graph = NULL;
f338ef
-    }
f338ef
-    return parent_graph;
f338ef
-}
f338ef
-
f338ef
-int
f338ef
-glusterfs_process_svc_detach(glusterfs_ctx_t *ctx, gf_volfile_t *volfile_obj)
f338ef
-{
f338ef
-    xlator_t *last_xl = NULL;
f338ef
-    glusterfs_graph_t *graph = NULL;
f338ef
-    glusterfs_graph_t *parent_graph = NULL;
f338ef
-    pthread_t clean_graph = {
f338ef
-        0,
f338ef
-    };
f338ef
-    int ret = -1;
f338ef
-    xlator_t *xl = NULL;
f338ef
-
f338ef
-    if (!ctx || !ctx->active || !volfile_obj)
f338ef
-        goto out;
f338ef
-    parent_graph = ctx->active;
f338ef
-    graph = volfile_obj->graph;
f338ef
-    if (graph && graph->first)
f338ef
-        xl = graph->first;
f338ef
-
f338ef
-    last_xl = graph->last_xl;
f338ef
-    if (last_xl)
f338ef
-        last_xl->next = NULL;
f338ef
-    if (!xl || xl->cleanup_starting)
f338ef
-        goto out;
f338ef
-
f338ef
-    xl->cleanup_starting = 1;
f338ef
-    gf_msg("mgmt", GF_LOG_INFO, 0, LG_MSG_GRAPH_DETACH_STARTED,
f338ef
-           "detaching child %s", volfile_obj->vol_id);
f338ef
-
f338ef
-    list_del_init(&volfile_obj->volfile_list);
f338ef
-    glusterfs_mux_xlator_unlink(parent_graph->top, xl);
f338ef
-    parent_graph->last_xl = glusterfs_get_last_xlator(parent_graph);
f338ef
-    parent_graph->xl_count -= graph->xl_count;
f338ef
-    parent_graph->leaf_count -= graph->leaf_count;
f338ef
-    default_notify(xl, GF_EVENT_PARENT_DOWN, xl);
f338ef
-    parent_graph->id++;
f338ef
-    ret = 0;
f338ef
-out:
f338ef
-    if (!ret) {
f338ef
-        list_del_init(&volfile_obj->volfile_list);
f338ef
-        if (graph) {
f338ef
-            ret = gf_thread_create_detached(
f338ef
-                &clean_graph, glusterfs_graph_cleanup, graph, "graph_clean");
f338ef
-            if (ret) {
f338ef
-                gf_msg("glusterfs", GF_LOG_ERROR, EINVAL,
f338ef
-                       LG_MSG_GRAPH_CLEANUP_FAILED,
f338ef
-                       "%s failed to create clean "
f338ef
-                       "up thread",
f338ef
-                       volfile_obj->vol_id);
f338ef
-                ret = 0;
f338ef
-            }
f338ef
-        }
f338ef
-        GF_FREE(volfile_obj);
f338ef
-    }
f338ef
-    return ret;
f338ef
-}
f338ef
-
f338ef
-int
f338ef
-glusterfs_process_svc_attach_volfp(glusterfs_ctx_t *ctx, FILE *fp,
f338ef
-                                   char *volfile_id, char *checksum)
f338ef
-{
f338ef
-    glusterfs_graph_t *graph = NULL;
f338ef
-    glusterfs_graph_t *parent_graph = NULL;
f338ef
-    glusterfs_graph_t *clean_graph = NULL;
f338ef
-    int ret = -1;
f338ef
-    xlator_t *xl = NULL;
f338ef
-    xlator_t *last_xl = NULL;
f338ef
-    gf_volfile_t *volfile_obj = NULL;
f338ef
-    pthread_t thread_id = {
f338ef
-        0,
f338ef
-    };
f338ef
-
f338ef
-    if (!ctx)
f338ef
-        goto out;
f338ef
-    parent_graph = ctx->active;
f338ef
-    graph = glusterfs_graph_construct(fp);
f338ef
-    if (!graph) {
f338ef
-        gf_msg("glusterfsd", GF_LOG_ERROR, EINVAL, LG_MSG_GRAPH_ATTACH_FAILED,
f338ef
-               "failed to construct the graph");
f338ef
-        goto out;
f338ef
-    }
f338ef
-    graph->last_xl = glusterfs_get_last_xlator(graph);
f338ef
-
f338ef
-    for (xl = graph->first; xl; xl = xl->next) {
f338ef
-        if (strcmp(xl->type, "mount/fuse") == 0) {
f338ef
-            gf_msg("glusterfsd", GF_LOG_ERROR, EINVAL,
f338ef
-                   LG_MSG_GRAPH_ATTACH_FAILED,
f338ef
-                   "fuse xlator cannot be specified in volume file");
f338ef
-            goto out;
f338ef
-        }
f338ef
-    }
f338ef
-
f338ef
-    graph->leaf_count = glusterfs_count_leaves(glusterfs_root(graph));
f338ef
-    xl = graph->first;
f338ef
-    /* TODO memory leaks everywhere need to free graph in case of error */
f338ef
-    if (glusterfs_graph_prepare(graph, ctx, xl->name)) {
f338ef
-        gf_msg("glusterfsd", GF_LOG_WARNING, EINVAL, LG_MSG_GRAPH_ATTACH_FAILED,
f338ef
-               "failed to prepare graph for xlator %s", xl->name);
f338ef
-        ret = -1;
f338ef
-        goto out;
f338ef
-    } else if (glusterfs_graph_init(graph)) {
f338ef
-        gf_msg("glusterfsd", GF_LOG_WARNING, EINVAL, LG_MSG_GRAPH_ATTACH_FAILED,
f338ef
-               "failed to initialize graph for xlator %s", xl->name);
f338ef
-        ret = -1;
f338ef
-        goto out;
f338ef
-    } else if (glusterfs_graph_parent_up(graph)) {
f338ef
-        gf_msg("glusterfsd", GF_LOG_WARNING, EINVAL, LG_MSG_GRAPH_ATTACH_FAILED,
f338ef
-               "failed to link the graphs for xlator %s ", xl->name);
f338ef
-        ret = -1;
f338ef
-        goto out;
f338ef
-    }
f338ef
-
f338ef
-    if (!parent_graph) {
f338ef
-        parent_graph = glusterfs_muxsvc_setup_parent_graph(ctx, "glustershd",
f338ef
-                                                           "debug/io-stats");
f338ef
-        if (!parent_graph)
f338ef
-            goto out;
f338ef
-        ((xlator_t *)parent_graph->top)->next = xl;
f338ef
-        clean_graph = parent_graph;
f338ef
-    } else {
f338ef
-        last_xl = parent_graph->last_xl;
f338ef
-        if (last_xl)
f338ef
-            last_xl->next = xl;
f338ef
-        xl->prev = last_xl;
f338ef
-    }
f338ef
-    parent_graph->last_xl = graph->last_xl;
f338ef
-
f338ef
-    ret = glusterfs_xlator_link(parent_graph->top, xl);
f338ef
-    if (ret) {
f338ef
-        gf_msg("graph", GF_LOG_ERROR, 0, LG_MSG_EVENT_NOTIFY_FAILED,
f338ef
-               "parent up notification failed");
f338ef
-        goto out;
f338ef
-    }
f338ef
-    parent_graph->xl_count += graph->xl_count;
f338ef
-    parent_graph->leaf_count += graph->leaf_count;
f338ef
-    parent_graph->id++;
f338ef
-
f338ef
-    if (!volfile_obj) {
f338ef
-        volfile_obj = GF_CALLOC(1, sizeof(gf_volfile_t), gf_common_volfile_t);
f338ef
-        if (!volfile_obj) {
f338ef
-            ret = -1;
f338ef
-            goto out;
f338ef
-        }
f338ef
-    }
f338ef
-
f338ef
-    graph->used = 1;
f338ef
-    parent_graph->id++;
f338ef
-    list_add(&graph->list, &ctx->graphs);
f338ef
-    INIT_LIST_HEAD(&volfile_obj->volfile_list);
f338ef
-    volfile_obj->graph = graph;
f338ef
-    snprintf(volfile_obj->vol_id, sizeof(volfile_obj->vol_id), "%s",
f338ef
-             volfile_id);
f338ef
-    memcpy(volfile_obj->volfile_checksum, checksum,
f338ef
-           sizeof(volfile_obj->volfile_checksum));
f338ef
-    list_add_tail(&volfile_obj->volfile_list, &ctx->volfile_list);
f338ef
-
f338ef
-    gf_log_dump_graph(fp, graph);
f338ef
-    graph = NULL;
f338ef
-
f338ef
-    ret = 0;
f338ef
-out:
f338ef
-    if (ret) {
f338ef
-        if (graph) {
f338ef
-            gluster_graph_take_reference(graph->first);
f338ef
-            ret = gf_thread_create_detached(&thread_id, glusterfs_graph_cleanup,
f338ef
-                                            graph, "graph_clean");
f338ef
-            if (ret) {
f338ef
-                gf_msg("glusterfs", GF_LOG_ERROR, EINVAL,
f338ef
-                       LG_MSG_GRAPH_CLEANUP_FAILED,
f338ef
-                       "%s failed to create clean "
f338ef
-                       "up thread",
f338ef
-                       volfile_id);
f338ef
-                ret = 0;
f338ef
-            }
f338ef
-        }
f338ef
-        if (clean_graph)
f338ef
-            glusterfs_muxsvc_cleanup_parent(ctx, clean_graph);
f338ef
-    }
f338ef
-    return ret;
f338ef
-}
f338ef
-
f338ef
-int
f338ef
-glusterfs_mux_volfile_reconfigure(FILE *newvolfile_fp, glusterfs_ctx_t *ctx,
f338ef
-                                  gf_volfile_t *volfile_obj, char *checksum)
f338ef
-{
f338ef
-    glusterfs_graph_t *oldvolfile_graph = NULL;
f338ef
-    glusterfs_graph_t *newvolfile_graph = NULL;
f338ef
-
f338ef
-    int ret = -1;
f338ef
-
f338ef
-    if (!ctx) {
f338ef
-        gf_msg("glusterfsd-mgmt", GF_LOG_ERROR, 0, LG_MSG_CTX_NULL,
f338ef
-               "ctx is NULL");
f338ef
-        goto out;
f338ef
-    }
f338ef
-
f338ef
-    /* Change the message id */
f338ef
-    if (!volfile_obj) {
f338ef
-        gf_msg("glusterfsd-mgmt", GF_LOG_ERROR, 0, LG_MSG_CTX_NULL,
f338ef
-               "failed to get volfile object");
f338ef
-        goto out;
f338ef
-    }
f338ef
-
f338ef
-    oldvolfile_graph = volfile_obj->graph;
f338ef
-    if (!oldvolfile_graph) {
f338ef
-        goto out;
f338ef
-    }
f338ef
-
f338ef
-    newvolfile_graph = glusterfs_graph_construct(newvolfile_fp);
f338ef
-
f338ef
-    if (!newvolfile_graph) {
f338ef
-        goto out;
f338ef
-    }
f338ef
-    newvolfile_graph->last_xl = glusterfs_get_last_xlator(newvolfile_graph);
f338ef
-
f338ef
-    glusterfs_graph_prepare(newvolfile_graph, ctx, newvolfile_graph->first);
f338ef
-
f338ef
-    if (!is_graph_topology_equal(oldvolfile_graph, newvolfile_graph)) {
f338ef
-        ret = glusterfs_process_svc_detach(ctx, volfile_obj);
f338ef
-        if (ret) {
f338ef
-            gf_msg("glusterfsd-mgmt", GF_LOG_ERROR, EINVAL,
f338ef
-                   LG_MSG_GRAPH_CLEANUP_FAILED,
f338ef
-                   "Could not detach "
f338ef
-                   "old graph. Aborting the reconfiguration operation");
f338ef
-            goto out;
f338ef
-        }
f338ef
-        ret = glusterfs_process_svc_attach_volfp(ctx, newvolfile_fp,
f338ef
-                                                 volfile_obj->vol_id, checksum);
f338ef
-        goto out;
f338ef
-    }
f338ef
-
f338ef
-    gf_msg_debug("glusterfsd-mgmt", 0,
f338ef
-                 "Only options have changed in the"
f338ef
-                 " new graph");
f338ef
-
f338ef
-    ret = glusterfs_graph_reconfigure(oldvolfile_graph, newvolfile_graph);
f338ef
-    if (ret) {
f338ef
-        gf_msg_debug("glusterfsd-mgmt", 0,
f338ef
-                     "Could not reconfigure "
f338ef
-                     "new options in old graph");
f338ef
-        goto out;
f338ef
-    }
f338ef
-    memcpy(volfile_obj->volfile_checksum, checksum,
f338ef
-           sizeof(volfile_obj->volfile_checksum));
f338ef
-
f338ef
-    ret = 0;
f338ef
-out:
f338ef
-
f338ef
-    if (newvolfile_graph)
f338ef
-        glusterfs_graph_destroy(newvolfile_graph);
f338ef
-
f338ef
-    return ret;
f338ef
-}
f338ef
diff --git a/libglusterfs/src/graph.y b/libglusterfs/src/graph.y
f338ef
index c60ff38..5b92985 100644
f338ef
--- a/libglusterfs/src/graph.y
f338ef
+++ b/libglusterfs/src/graph.y
f338ef
@@ -542,9 +542,6 @@ glusterfs_graph_new ()
f338ef
 
f338ef
         INIT_LIST_HEAD (&graph->list);
f338ef
 
f338ef
-        pthread_mutex_init(&graph->mutex, NULL);
f338ef
-        pthread_cond_init(&graph->child_down_cond, NULL);
f338ef
-
f338ef
         gettimeofday (&graph->dob, NULL);
f338ef
 
f338ef
         return graph;
f338ef
diff --git a/libglusterfs/src/libglusterfs.sym b/libglusterfs/src/libglusterfs.sym
f338ef
index 05f93b4..4dca7de 100644
f338ef
--- a/libglusterfs/src/libglusterfs.sym
f338ef
+++ b/libglusterfs/src/libglusterfs.sym
f338ef
@@ -1155,8 +1155,3 @@ gf_changelog_register_generic
f338ef
 gf_gfid_generate_from_xxh64
f338ef
 find_xlator_option_in_cmd_args_t
f338ef
 gf_d_type_from_ia_type
f338ef
-glusterfs_graph_fini
f338ef
-glusterfs_process_svc_attach_volfp
f338ef
-glusterfs_mux_volfile_reconfigure
f338ef
-glusterfs_process_svc_detach
f338ef
-mgmt_is_multiplexed_daemon
f338ef
diff --git a/libglusterfs/src/statedump.c b/libglusterfs/src/statedump.c
f338ef
index 0cf80c0..d18b50f 100644
f338ef
--- a/libglusterfs/src/statedump.c
f338ef
+++ b/libglusterfs/src/statedump.c
f338ef
@@ -810,8 +810,7 @@ gf_proc_dump_info(int signum, glusterfs_ctx_t *ctx)
f338ef
     if (!ctx)
f338ef
         goto out;
f338ef
 
f338ef
-    if (!mgmt_is_multiplexed_daemon(ctx->cmd_args.process_name) &&
f338ef
-        (ctx && ctx->active)) {
f338ef
+    if (ctx && ctx->active) {
f338ef
         top = ctx->active->first;
f338ef
         for (trav_p = &top->children; *trav_p; trav_p = &(*trav_p)->next) {
f338ef
             brick_count++;
f338ef
diff --git a/libglusterfs/src/xlator.c b/libglusterfs/src/xlator.c
f338ef
index 022c3ed..6bd4f09 100644
f338ef
--- a/libglusterfs/src/xlator.c
f338ef
+++ b/libglusterfs/src/xlator.c
f338ef
@@ -1470,19 +1470,3 @@ gluster_graph_take_reference(xlator_t *tree)
f338ef
     }
f338ef
     return;
f338ef
 }
f338ef
-
f338ef
-gf_boolean_t
f338ef
-mgmt_is_multiplexed_daemon(char *name)
f338ef
-{
f338ef
-    const char *mux_daemons[] = {"glustershd", NULL};
f338ef
-    int i;
f338ef
-
f338ef
-    if (!name)
f338ef
-        return _gf_false;
f338ef
-
f338ef
-    for (i = 0; mux_daemons[i]; i++) {
f338ef
-        if (!strcmp(name, mux_daemons[i]))
f338ef
-            return _gf_true;
f338ef
-    }
f338ef
-    return _gf_false;
f338ef
-}
f338ef
diff --git a/rpc/rpc-lib/src/protocol-common.h b/rpc/rpc-lib/src/protocol-common.h
f338ef
index 7275d75..779878f 100644
f338ef
--- a/rpc/rpc-lib/src/protocol-common.h
f338ef
+++ b/rpc/rpc-lib/src/protocol-common.h
f338ef
@@ -245,8 +245,6 @@ enum glusterd_brick_procnum {
f338ef
     GLUSTERD_NODE_BITROT,
f338ef
     GLUSTERD_BRICK_ATTACH,
f338ef
     GLUSTERD_DUMP_METRICS,
f338ef
-    GLUSTERD_SVC_ATTACH,
f338ef
-    GLUSTERD_SVC_DETACH,
f338ef
     GLUSTERD_BRICK_MAXVALUE,
f338ef
 };
f338ef
 
f338ef
diff --git a/tests/basic/glusterd/heald.t b/tests/basic/glusterd/heald.t
f338ef
index 7dae3c3..ca112ad 100644
f338ef
--- a/tests/basic/glusterd/heald.t
f338ef
+++ b/tests/basic/glusterd/heald.t
f338ef
@@ -7,16 +7,11 @@
f338ef
 # Covers enable/disable at the moment. Will be enhanced later to include
f338ef
 # the other commands as well.
f338ef
 
f338ef
-function is_pid_running {
f338ef
-    local pid=$1
f338ef
-    num=`ps auxww | grep glustershd | grep $pid | grep -v grep | wc -l`
f338ef
-    echo $num
f338ef
-}
f338ef
-
f338ef
 cleanup;
f338ef
 TEST glusterd
f338ef
 TEST pidof glusterd
f338ef
 
f338ef
+volfile=$(gluster system:: getwd)"/glustershd/glustershd-server.vol"
f338ef
 #Commands should fail when volume doesn't exist
f338ef
 TEST ! $CLI volume heal non-existent-volume enable
f338ef
 TEST ! $CLI volume heal non-existent-volume disable
f338ef
@@ -25,55 +20,51 @@ TEST ! $CLI volume heal non-existent-volume disable
f338ef
 # volumes
f338ef
 TEST $CLI volume create dist $H0:$B0/dist
f338ef
 TEST $CLI volume start dist
f338ef
-TEST "[ -z $(get_shd_process_pid dist)]"
f338ef
+TEST "[ -z $(get_shd_process_pid)]"
f338ef
 TEST ! $CLI volume heal dist enable
f338ef
 TEST ! $CLI volume heal dist disable
f338ef
 
f338ef
 # Commands should work on replicate/disperse volume.
f338ef
 TEST $CLI volume create r2 replica 2 $H0:$B0/r2_0 $H0:$B0/r2_1
f338ef
-TEST "[ -z $(get_shd_process_pid r2)]"
f338ef
+TEST "[ -z $(get_shd_process_pid)]"
f338ef
 TEST $CLI volume start r2
f338ef
-EXPECT_WITHIN $PROCESS_UP_TIMEOUT "[0-9][0-9]*" get_shd_process_pid r2
f338ef
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT "[0-9][0-9]*" get_shd_process_pid
f338ef
 TEST $CLI volume heal r2 enable
f338ef
 EXPECT "enable" volume_option r2 "cluster.self-heal-daemon"
f338ef
-volfiler2=$(gluster system:: getwd)"/vols/r2/r2-shd.vol"
f338ef
-EXPECT "enable" volgen_volume_option $volfiler2 r2-replicate-0 cluster replicate self-heal-daemon
f338ef
-EXPECT_WITHIN $PROCESS_UP_TIMEOUT "[0-9][0-9]*" get_shd_process_pid r2
f338ef
-pid=$( get_shd_process_pid r2 )
f338ef
+EXPECT "enable" volgen_volume_option $volfile r2-replicate-0 cluster replicate self-heal-daemon
f338ef
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT "[0-9][0-9]*" get_shd_process_pid
f338ef
 TEST $CLI volume heal r2 disable
f338ef
 EXPECT "disable" volume_option r2 "cluster.self-heal-daemon"
f338ef
-EXPECT "disable" volgen_volume_option $volfiler2 r2-replicate-0 cluster replicate self-heal-daemon
f338ef
-EXPECT "1" is_pid_running $pid
f338ef
+EXPECT "disable" volgen_volume_option $volfile r2-replicate-0 cluster replicate self-heal-daemon
f338ef
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT "[0-9][0-9]*" get_shd_process_pid
f338ef
 
f338ef
 # Commands should work on disperse volume.
f338ef
 TEST $CLI volume create ec2 disperse 3 redundancy 1 $H0:$B0/ec2_0 $H0:$B0/ec2_1 $H0:$B0/ec2_2
f338ef
 TEST $CLI volume start ec2
f338ef
-EXPECT_WITHIN $PROCESS_UP_TIMEOUT "[0-9][0-9]*" get_shd_process_pid ec2
f338ef
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT "[0-9][0-9]*" get_shd_process_pid
f338ef
 TEST $CLI volume heal ec2 enable
f338ef
 EXPECT "enable" volume_option ec2 "cluster.disperse-self-heal-daemon"
f338ef
-volfileec2=$(gluster system:: getwd)"/vols/ec2/ec2-shd.vol"
f338ef
-EXPECT "enable" volgen_volume_option $volfileec2 ec2-disperse-0 cluster disperse self-heal-daemon
f338ef
-EXPECT_WITHIN $PROCESS_UP_TIMEOUT "[0-9][0-9]*" get_shd_process_pid ec2
f338ef
-pid=$(get_shd_process_pid ec2)
f338ef
+EXPECT "enable" volgen_volume_option $volfile ec2-disperse-0 cluster disperse self-heal-daemon
f338ef
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT "[0-9][0-9]*" get_shd_process_pid
f338ef
 TEST $CLI volume heal ec2 disable
f338ef
 EXPECT "disable" volume_option ec2 "cluster.disperse-self-heal-daemon"
f338ef
-EXPECT "disable" volgen_volume_option $volfileec2 ec2-disperse-0 cluster disperse self-heal-daemon
f338ef
-EXPECT "1" is_pid_running $pid
f338ef
+EXPECT "disable" volgen_volume_option $volfile ec2-disperse-0 cluster disperse self-heal-daemon
f338ef
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT "[0-9][0-9]*" get_shd_process_pid
f338ef
 
f338ef
 #Check that shd graph is rewritten correctly on volume stop/start
f338ef
-EXPECT "Y" volgen_volume_exists $volfileec2 ec2-disperse-0 cluster disperse
f338ef
-
f338ef
-EXPECT "Y" volgen_volume_exists $volfiler2 r2-replicate-0 cluster replicate
f338ef
+EXPECT "Y" volgen_volume_exists $volfile ec2-disperse-0 cluster disperse
f338ef
+EXPECT "Y" volgen_volume_exists $volfile r2-replicate-0 cluster replicate
f338ef
 TEST $CLI volume stop r2
f338ef
-EXPECT "Y" volgen_volume_exists $volfileec2 ec2-disperse-0 cluster disperse
f338ef
+EXPECT "Y" volgen_volume_exists $volfile ec2-disperse-0 cluster disperse
f338ef
+EXPECT "N" volgen_volume_exists $volfile r2-replicate-0 cluster replicate
f338ef
 TEST $CLI volume stop ec2
f338ef
 # When both the volumes are stopped glustershd volfile is not modified just the
f338ef
 # process is stopped
f338ef
-TEST "[ -z $(get_shd_process_pid dist) ]"
f338ef
-TEST "[ -z $(get_shd_process_pid ec2) ]"
f338ef
+TEST "[ -z $(get_shd_process_pid) ]"
f338ef
 
f338ef
 TEST $CLI volume start r2
f338ef
-EXPECT "Y" volgen_volume_exists $volfiler2 r2-replicate-0 cluster replicate
f338ef
+EXPECT "N" volgen_volume_exists $volfile ec2-disperse-0 cluster disperse
f338ef
+EXPECT "Y" volgen_volume_exists $volfile r2-replicate-0 cluster replicate
f338ef
 
f338ef
 TEST $CLI volume set r2 self-heal-daemon on
f338ef
 TEST $CLI volume set r2 cluster.self-heal-daemon off
f338ef
diff --git a/tests/bugs/glusterd/reset-brick-and-daemons-follow-quorum.t b/tests/bugs/glusterd/reset-brick-and-daemons-follow-quorum.t
f338ef
index e6e65c4..cdb1a33 100644
f338ef
--- a/tests/bugs/glusterd/reset-brick-and-daemons-follow-quorum.t
f338ef
+++ b/tests/bugs/glusterd/reset-brick-and-daemons-follow-quorum.t
f338ef
@@ -55,9 +55,9 @@ TEST kill_glusterd 1
f338ef
 #Bring back 1st glusterd
f338ef
 TEST $glusterd_1
f338ef
 
f338ef
-# We need to wait till PROCESS_UP_TIMEOUT and then check shd service started
f338ef
-#on node 2, because once glusterd regains quorum, it will restart all volume
f338ef
-#level daemons
f338ef
-EXPECT_WITHIN $PROCESS_UP_TIMEOUT "Y" shd_up_status_2
f338ef
+# We need to wait till PROCESS_UP_TIMEOUT and then check shd service does not
f338ef
+# come up on node 2
f338ef
+sleep $PROCESS_UP_TIMEOUT
f338ef
+EXPECT "N" shd_up_status_2
f338ef
 
f338ef
 cleanup;
f338ef
diff --git a/tests/volume.rc b/tests/volume.rc
f338ef
index 022d972..76a8fd4 100644
f338ef
--- a/tests/volume.rc
f338ef
+++ b/tests/volume.rc
f338ef
@@ -237,13 +237,11 @@ function ec_child_up_count_shd {
f338ef
 }
f338ef
 
f338ef
 function get_shd_process_pid {
f338ef
-        local vol=$1
f338ef
-        ps auxww | grep "process-name\ glustershd" | awk '{print $2}' | head -1
f338ef
+        ps auxww | grep glusterfs | grep -E "glustershd/glustershd.pid" | awk '{print $2}' | head -1
f338ef
 }
f338ef
 
f338ef
 function generate_shd_statedump {
f338ef
-        local vol=$1
f338ef
-        generate_statedump $(get_shd_process_pid $vol)
f338ef
+        generate_statedump $(get_shd_process_pid)
f338ef
 }
f338ef
 
f338ef
 function generate_nfs_statedump {
f338ef
diff --git a/xlators/mgmt/glusterd/src/Makefile.am b/xlators/mgmt/glusterd/src/Makefile.am
f338ef
index 11ae189..5fe5156 100644
f338ef
--- a/xlators/mgmt/glusterd/src/Makefile.am
f338ef
+++ b/xlators/mgmt/glusterd/src/Makefile.am
f338ef
@@ -18,12 +18,11 @@ glusterd_la_SOURCES = glusterd.c glusterd-handler.c glusterd-sm.c \
f338ef
 	glusterd-locks.c glusterd-snapshot.c glusterd-mgmt-handler.c \
f338ef
 	glusterd-mgmt.c glusterd-peer-utils.c glusterd-statedump.c \
f338ef
 	glusterd-snapshot-utils.c glusterd-conn-mgmt.c \
f338ef
-	glusterd-proc-mgmt.c glusterd-svc-mgmt.c \
f338ef
+	glusterd-proc-mgmt.c glusterd-svc-mgmt.c glusterd-shd-svc.c \
f338ef
 	glusterd-nfs-svc.c glusterd-quotad-svc.c glusterd-svc-helper.c \
f338ef
 	glusterd-conn-helper.c glusterd-snapd-svc.c glusterd-snapd-svc-helper.c \
f338ef
 	glusterd-bitd-svc.c glusterd-scrub-svc.c glusterd-server-quorum.c \
f338ef
 	glusterd-reset-brick.c glusterd-tierd-svc.c glusterd-tierd-svc-helper.c \
f338ef
-        glusterd-shd-svc.c glusterd-shd-svc-helper.c \
f338ef
         glusterd-gfproxyd-svc.c glusterd-gfproxyd-svc-helper.c
f338ef
 
f338ef
 
f338ef
@@ -39,12 +38,11 @@ noinst_HEADERS = glusterd.h glusterd-utils.h glusterd-op-sm.h \
f338ef
 	glusterd-mgmt.h glusterd-messages.h glusterd-peer-utils.h \
f338ef
 	glusterd-statedump.h glusterd-snapshot-utils.h glusterd-geo-rep.h \
f338ef
 	glusterd-conn-mgmt.h glusterd-conn-helper.h glusterd-proc-mgmt.h \
f338ef
-	glusterd-svc-mgmt.h glusterd-nfs-svc.h \
f338ef
+	glusterd-svc-mgmt.h glusterd-shd-svc.h glusterd-nfs-svc.h \
f338ef
 	glusterd-quotad-svc.h glusterd-svc-helper.h glusterd-snapd-svc.h \
f338ef
 	glusterd-snapd-svc-helper.h glusterd-rcu.h glusterd-bitd-svc.h \
f338ef
 	glusterd-scrub-svc.h glusterd-server-quorum.h glusterd-errno.h \
f338ef
 	glusterd-tierd-svc.h glusterd-tierd-svc-helper.h \
f338ef
-        glusterd-shd-svc.h glusterd-shd-svc-helper.h \
f338ef
         glusterd-gfproxyd-svc.h glusterd-gfproxyd-svc-helper.h \
f338ef
 	$(CONTRIBDIR)/userspace-rcu/rculist-extra.h
f338ef
 
f338ef
diff --git a/xlators/mgmt/glusterd/src/glusterd-brick-ops.c b/xlators/mgmt/glusterd/src/glusterd-brick-ops.c
f338ef
index 042a805..ad9a572 100644
f338ef
--- a/xlators/mgmt/glusterd/src/glusterd-brick-ops.c
f338ef
+++ b/xlators/mgmt/glusterd/src/glusterd-brick-ops.c
f338ef
@@ -2863,7 +2863,7 @@ glusterd_op_remove_brick(dict_t *dict, char **op_errstr)
f338ef
     }
f338ef
 
f338ef
     if (start_remove && volinfo->status == GLUSTERD_STATUS_STARTED) {
f338ef
-        ret = glusterd_svcs_reconfigure(volinfo);
f338ef
+        ret = glusterd_svcs_reconfigure();
f338ef
         if (ret) {
f338ef
             gf_msg(this->name, GF_LOG_WARNING, 0, GD_MSG_NFS_RECONF_FAIL,
f338ef
                    "Unable to reconfigure NFS-Server");
f338ef
diff --git a/xlators/mgmt/glusterd/src/glusterd-conn-mgmt.c b/xlators/mgmt/glusterd/src/glusterd-conn-mgmt.c
f338ef
index 16eefa1..c6d7a00 100644
f338ef
--- a/xlators/mgmt/glusterd/src/glusterd-conn-mgmt.c
f338ef
+++ b/xlators/mgmt/glusterd/src/glusterd-conn-mgmt.c
f338ef
@@ -138,45 +138,3 @@ glusterd_conn_build_socket_filepath(char *rundir, uuid_t uuid, char *socketpath,
f338ef
     glusterd_set_socket_filepath(sockfilepath, socketpath, len);
f338ef
     return 0;
f338ef
 }
f338ef
-
f338ef
-int
f338ef
-__glusterd_muxsvc_conn_common_notify(struct rpc_clnt *rpc, void *mydata,
f338ef
-                                     rpc_clnt_event_t event, void *data)
f338ef
-{
f338ef
-    glusterd_conf_t *conf = THIS->private;
f338ef
-    glusterd_svc_proc_t *mux_proc = mydata;
f338ef
-    int ret = -1;
f338ef
-
f338ef
-    /* Silently ignoring this error, exactly like the current
f338ef
-     * implementation */
f338ef
-    if (!mux_proc)
f338ef
-        return 0;
f338ef
-
f338ef
-    if (event == RPC_CLNT_DESTROY) {
f338ef
-        /*RPC_CLNT_DESTROY will only called after mux_proc detached from the
f338ef
-         * list. So it is safe to call without lock. Processing
f338ef
-         * RPC_CLNT_DESTROY under a lock will lead to deadlock.
f338ef
-         */
f338ef
-        if (mux_proc->data) {
f338ef
-            glusterd_volinfo_unref(mux_proc->data);
f338ef
-            mux_proc->data = NULL;
f338ef
-        }
f338ef
-        GF_FREE(mux_proc);
f338ef
-        ret = 0;
f338ef
-    } else {
f338ef
-        pthread_mutex_lock(&conf->attach_lock);
f338ef
-        {
f338ef
-            ret = mux_proc->notify(mux_proc, event);
f338ef
-        }
f338ef
-        pthread_mutex_unlock(&conf->attach_lock);
f338ef
-    }
f338ef
-    return ret;
f338ef
-}
f338ef
-
f338ef
-int
f338ef
-glusterd_muxsvc_conn_common_notify(struct rpc_clnt *rpc, void *mydata,
f338ef
-                                   rpc_clnt_event_t event, void *data)
f338ef
-{
f338ef
-    return glusterd_big_locked_notify(rpc, mydata, event, data,
f338ef
-                                      __glusterd_muxsvc_conn_common_notify);
f338ef
-}
f338ef
diff --git a/xlators/mgmt/glusterd/src/glusterd-conn-mgmt.h b/xlators/mgmt/glusterd/src/glusterd-conn-mgmt.h
f338ef
index d1c4607..602c0ba 100644
f338ef
--- a/xlators/mgmt/glusterd/src/glusterd-conn-mgmt.h
f338ef
+++ b/xlators/mgmt/glusterd/src/glusterd-conn-mgmt.h
f338ef
@@ -43,11 +43,9 @@ glusterd_conn_disconnect(glusterd_conn_t *conn);
f338ef
 int
f338ef
 glusterd_conn_common_notify(struct rpc_clnt *rpc, void *mydata,
f338ef
                             rpc_clnt_event_t event, void *data);
f338ef
-int
f338ef
-glusterd_muxsvc_conn_common_notify(struct rpc_clnt *rpc, void *mydata,
f338ef
-                                   rpc_clnt_event_t event, void *data);
f338ef
 
f338ef
 int32_t
f338ef
 glusterd_conn_build_socket_filepath(char *rundir, uuid_t uuid, char *socketpath,
f338ef
                                     int len);
f338ef
+
f338ef
 #endif
f338ef
diff --git a/xlators/mgmt/glusterd/src/glusterd-gfproxyd-svc.c b/xlators/mgmt/glusterd/src/glusterd-gfproxyd-svc.c
f338ef
index b01fd4d..f9c8617 100644
f338ef
--- a/xlators/mgmt/glusterd/src/glusterd-gfproxyd-svc.c
f338ef
+++ b/xlators/mgmt/glusterd/src/glusterd-gfproxyd-svc.c
f338ef
@@ -370,7 +370,6 @@ int
f338ef
 glusterd_gfproxydsvc_restart()
f338ef
 {
f338ef
     glusterd_volinfo_t *volinfo = NULL;
f338ef
-    glusterd_volinfo_t *tmp = NULL;
f338ef
     int ret = -1;
f338ef
     xlator_t *this = THIS;
f338ef
     glusterd_conf_t *conf = NULL;
f338ef
@@ -381,7 +380,7 @@ glusterd_gfproxydsvc_restart()
f338ef
     conf = this->private;
f338ef
     GF_VALIDATE_OR_GOTO(this->name, conf, out);
f338ef
 
f338ef
-    cds_list_for_each_entry_safe(volinfo, tmp, &conf->volumes, vol_list)
f338ef
+    cds_list_for_each_entry(volinfo, &conf->volumes, vol_list)
f338ef
     {
f338ef
         /* Start per volume gfproxyd svc */
f338ef
         if (volinfo->status == GLUSTERD_STATUS_STARTED) {
f338ef
diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c
f338ef
index ac788a0..cb2666b 100644
f338ef
--- a/xlators/mgmt/glusterd/src/glusterd-handler.c
f338ef
+++ b/xlators/mgmt/glusterd/src/glusterd-handler.c
f338ef
@@ -5940,11 +5940,6 @@ glusterd_get_state(rpcsvc_request_t *req, dict_t *dict)
f338ef
 
f338ef
         GF_FREE(rebal_data);
f338ef
 
f338ef
-        fprintf(fp, "Volume%d.shd_svc.online_status: %s\n", count,
f338ef
-                volinfo->shd.svc.online ? "Online" : "Offline");
f338ef
-        fprintf(fp, "Volume%d.shd_svc.inited: %s\n", count,
f338ef
-                volinfo->shd.svc.inited ? "True" : "False");
f338ef
-
f338ef
         if (volinfo->type == GF_CLUSTER_TYPE_TIER) {
f338ef
             ret = glusterd_volume_get_hot_tier_type_str(volinfo,
f338ef
                                                         &hot_tier_type_str);
f338ef
@@ -6014,6 +6009,12 @@ glusterd_get_state(rpcsvc_request_t *req, dict_t *dict)
f338ef
 
f338ef
     fprintf(fp, "\n[Services]\n");
f338ef
 
f338ef
+    if (priv->shd_svc.inited) {
f338ef
+        fprintf(fp, "svc%d.name: %s\n", ++count, priv->shd_svc.name);
f338ef
+        fprintf(fp, "svc%d.online_status: %s\n\n", count,
f338ef
+                priv->shd_svc.online ? "Online" : "Offline");
f338ef
+    }
f338ef
+
f338ef
     if (priv->nfs_svc.inited) {
f338ef
         fprintf(fp, "svc%d.name: %s\n", ++count, priv->nfs_svc.name);
f338ef
         fprintf(fp, "svc%d.online_status: %s\n\n", count,
f338ef
diff --git a/xlators/mgmt/glusterd/src/glusterd-handshake.c b/xlators/mgmt/glusterd/src/glusterd-handshake.c
f338ef
index 1ba58c3..5599a63 100644
f338ef
--- a/xlators/mgmt/glusterd/src/glusterd-handshake.c
f338ef
+++ b/xlators/mgmt/glusterd/src/glusterd-handshake.c
f338ef
@@ -30,7 +30,6 @@
f338ef
 #include "rpcsvc.h"
f338ef
 #include "rpc-common-xdr.h"
f338ef
 #include "glusterd-gfproxyd-svc-helper.h"
f338ef
-#include "glusterd-shd-svc-helper.h"
f338ef
 
f338ef
 extern struct rpc_clnt_program gd_peer_prog;
f338ef
 extern struct rpc_clnt_program gd_mgmt_prog;
f338ef
@@ -329,26 +328,6 @@ build_volfile_path(char *volume_id, char *path, size_t path_len,
f338ef
         goto out;
f338ef
     }
f338ef
 
f338ef
-    volid_ptr = strstr(volume_id, "shd/");
f338ef
-    if (volid_ptr) {
f338ef
-        volid_ptr = strchr(volid_ptr, '/');
f338ef
-        if (!volid_ptr) {
f338ef
-            ret = -1;
f338ef
-            goto out;
f338ef
-        }
f338ef
-        volid_ptr++;
f338ef
-
f338ef
-        ret = glusterd_volinfo_find(volid_ptr, &volinfo);
f338ef
-        if (ret == -1) {
f338ef
-            gf_log(this->name, GF_LOG_ERROR, "Couldn't find volinfo");
f338ef
-            goto out;
f338ef
-        }
f338ef
-
f338ef
-        glusterd_svc_build_shd_volfile_path(volinfo, path, path_len);
f338ef
-        ret = 0;
f338ef
-        goto out;
f338ef
-    }
f338ef
-
f338ef
     volid_ptr = strstr(volume_id, "/snaps/");
f338ef
     if (volid_ptr) {
f338ef
         ret = get_snap_volname_and_volinfo(volid_ptr, &volname, &volinfo);
f338ef
diff --git a/xlators/mgmt/glusterd/src/glusterd-mem-types.h b/xlators/mgmt/glusterd/src/glusterd-mem-types.h
f338ef
index 17052ce..7a784db 100644
f338ef
--- a/xlators/mgmt/glusterd/src/glusterd-mem-types.h
f338ef
+++ b/xlators/mgmt/glusterd/src/glusterd-mem-types.h
f338ef
@@ -51,7 +51,6 @@ typedef enum gf_gld_mem_types_ {
f338ef
     gf_gld_mt_missed_snapinfo_t,
f338ef
     gf_gld_mt_snap_create_args_t,
f338ef
     gf_gld_mt_glusterd_brick_proc_t,
f338ef
-    gf_gld_mt_glusterd_svc_proc_t,
f338ef
     gf_gld_mt_end,
f338ef
 } gf_gld_mem_types_t;
f338ef
 #endif
f338ef
diff --git a/xlators/mgmt/glusterd/src/glusterd-messages.h b/xlators/mgmt/glusterd/src/glusterd-messages.h
f338ef
index 424e15f..c7b3ca8 100644
f338ef
--- a/xlators/mgmt/glusterd/src/glusterd-messages.h
f338ef
+++ b/xlators/mgmt/glusterd/src/glusterd-messages.h
f338ef
@@ -298,8 +298,6 @@ GLFS_MSGID(
f338ef
     GD_MSG_LOCALTIME_LOGGING_ENABLE, GD_MSG_LOCALTIME_LOGGING_DISABLE,
f338ef
     GD_MSG_PORTS_EXHAUSTED, GD_MSG_CHANGELOG_GET_FAIL,
f338ef
     GD_MSG_MANAGER_FUNCTION_FAILED, GD_MSG_NFS_GANESHA_DISABLED,
f338ef
-    GD_MSG_GANESHA_NOT_RUNNING, GD_MSG_DAEMON_LOG_LEVEL_VOL_OPT_VALIDATE_FAIL,
f338ef
-    GD_MSG_SHD_START_FAIL, GD_MSG_SHD_OBJ_GET_FAIL, GD_MSG_SVC_ATTACH_FAIL,
f338ef
-    GD_MSG_ATTACH_INFO, GD_MSG_DETACH_INFO, GD_MSG_SVC_DETACH_FAIL);
f338ef
+    GD_MSG_GANESHA_NOT_RUNNING, GD_MSG_DAEMON_LOG_LEVEL_VOL_OPT_VALIDATE_FAIL);
f338ef
 
f338ef
 #endif /* !_GLUSTERD_MESSAGES_H_ */
f338ef
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
f338ef
index 9ea695e..0d29de2 100644
f338ef
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c
f338ef
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
f338ef
@@ -44,7 +44,6 @@
f338ef
 #include "glusterd-snapshot-utils.h"
f338ef
 #include "glusterd-svc-mgmt.h"
f338ef
 #include "glusterd-svc-helper.h"
f338ef
-#include "glusterd-shd-svc-helper.h"
f338ef
 #include "glusterd-shd-svc.h"
f338ef
 #include "glusterd-nfs-svc.h"
f338ef
 #include "glusterd-quotad-svc.h"
f338ef
@@ -2225,11 +2224,6 @@ glusterd_options_reset(glusterd_volinfo_t *volinfo, char *key,
f338ef
     if (ret)
f338ef
         goto out;
f338ef
 
f338ef
-    svc = &(volinfo->shd.svc);
f338ef
-    ret = svc->reconfigure(volinfo);
f338ef
-    if (ret)
f338ef
-        goto out;
f338ef
-
f338ef
     ret = glusterd_create_volfiles_and_notify_services(volinfo);
f338ef
     if (ret) {
f338ef
         gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_VOLFILE_CREATE_FAIL,
f338ef
@@ -2244,7 +2238,7 @@ glusterd_options_reset(glusterd_volinfo_t *volinfo, char *key,
f338ef
         goto out;
f338ef
 
f338ef
     if (GLUSTERD_STATUS_STARTED == volinfo->status) {
f338ef
-        ret = glusterd_svcs_reconfigure(volinfo);
f338ef
+        ret = glusterd_svcs_reconfigure();
f338ef
         if (ret)
f338ef
             goto out;
f338ef
     }
f338ef
@@ -2700,11 +2694,6 @@ glusterd_op_set_all_volume_options(xlator_t *this, dict_t *dict,
f338ef
                 if (ret)
f338ef
                     goto out;
f338ef
 
f338ef
-                svc = &(volinfo->shd.svc);
f338ef
-                ret = svc->reconfigure(volinfo);
f338ef
-                if (ret)
f338ef
-                    goto out;
f338ef
-
f338ef
                 ret = glusterd_create_volfiles_and_notify_services(volinfo);
f338ef
                 if (ret) {
f338ef
                     gf_msg(this->name, GF_LOG_ERROR, 0,
f338ef
@@ -2718,7 +2707,7 @@ glusterd_op_set_all_volume_options(xlator_t *this, dict_t *dict,
f338ef
                 }
f338ef
             }
f338ef
             if (svcs_reconfigure) {
f338ef
-                ret = glusterd_svcs_reconfigure(NULL);
f338ef
+                ret = glusterd_svcs_reconfigure();
f338ef
                 if (ret) {
f338ef
                     gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_SVC_RESTART_FAIL,
f338ef
                            "Unable to restart "
f338ef
@@ -3103,11 +3092,6 @@ glusterd_op_set_volume(dict_t *dict, char **errstr)
f338ef
         if (ret)
f338ef
             goto out;
f338ef
 
f338ef
-        svc = &(volinfo->shd.svc);
f338ef
-        ret = svc->reconfigure(volinfo);
f338ef
-        if (ret)
f338ef
-            goto out;
f338ef
-
f338ef
         ret = glusterd_create_volfiles_and_notify_services(volinfo);
f338ef
         if (ret) {
f338ef
             gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_VOLFILE_CREATE_FAIL,
f338ef
@@ -3123,7 +3107,7 @@ glusterd_op_set_volume(dict_t *dict, char **errstr)
f338ef
             goto out;
f338ef
 
f338ef
         if (GLUSTERD_STATUS_STARTED == volinfo->status) {
f338ef
-            ret = glusterd_svcs_reconfigure(volinfo);
f338ef
+            ret = glusterd_svcs_reconfigure();
f338ef
             if (ret) {
f338ef
                 gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_SVC_RESTART_FAIL,
f338ef
                        "Unable to restart services");
f338ef
@@ -3156,11 +3140,6 @@ glusterd_op_set_volume(dict_t *dict, char **errstr)
f338ef
             if (ret)
f338ef
                 goto out;
f338ef
 
f338ef
-            svc = &(volinfo->shd.svc);
f338ef
-            ret = svc->reconfigure(volinfo);
f338ef
-            if (ret)
f338ef
-                goto out;
f338ef
-
f338ef
             ret = glusterd_create_volfiles_and_notify_services(volinfo);
f338ef
             if (ret) {
f338ef
                 gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_VOLFILE_CREATE_FAIL,
f338ef
@@ -3176,7 +3155,7 @@ glusterd_op_set_volume(dict_t *dict, char **errstr)
f338ef
                 goto out;
f338ef
 
f338ef
             if (GLUSTERD_STATUS_STARTED == volinfo->status) {
f338ef
-                ret = glusterd_svcs_reconfigure(volinfo);
f338ef
+                ret = glusterd_svcs_reconfigure();
f338ef
                 if (ret) {
f338ef
                     gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_SVC_RESTART_FAIL,
f338ef
                            "Unable to restart services");
f338ef
@@ -3383,7 +3362,7 @@ glusterd_op_stats_volume(dict_t *dict, char **op_errstr, dict_t *rsp_dict)
f338ef
         goto out;
f338ef
 
f338ef
     if (GLUSTERD_STATUS_STARTED == volinfo->status) {
f338ef
-        ret = glusterd_svcs_reconfigure(volinfo);
f338ef
+        ret = glusterd_svcs_reconfigure();
f338ef
         if (ret)
f338ef
             goto out;
f338ef
     }
f338ef
@@ -3666,6 +3645,14 @@ glusterd_op_status_volume(dict_t *dict, char **op_errstr, dict_t *rsp_dict)
f338ef
         other_count++;
f338ef
         node_count++;
f338ef
 
f338ef
+    } else if ((cmd & GF_CLI_STATUS_SHD) != 0) {
f338ef
+        ret = glusterd_add_node_to_dict(priv->shd_svc.name, rsp_dict, 0,
f338ef
+                                        vol_opts);
f338ef
+        if (ret)
f338ef
+            goto out;
f338ef
+        other_count++;
f338ef
+        node_count++;
f338ef
+
f338ef
     } else if ((cmd & GF_CLI_STATUS_QUOTAD) != 0) {
f338ef
         ret = glusterd_add_node_to_dict(priv->quotad_svc.name, rsp_dict, 0,
f338ef
                                         vol_opts);
f338ef
@@ -3699,12 +3686,6 @@ glusterd_op_status_volume(dict_t *dict, char **op_errstr, dict_t *rsp_dict)
f338ef
             goto out;
f338ef
         other_count++;
f338ef
         node_count++;
f338ef
-    } else if ((cmd & GF_CLI_STATUS_SHD) != 0) {
f338ef
-        ret = glusterd_add_shd_to_dict(volinfo, rsp_dict, other_index);
f338ef
-        if (ret)
f338ef
-            goto out;
f338ef
-        other_count++;
f338ef
-        node_count++;
f338ef
     } else if ((cmd & GF_CLI_STATUS_BRICK) != 0) {
f338ef
         ret = dict_get_strn(dict, "brick", SLEN("brick"), &brick);
f338ef
         if (ret)
f338ef
@@ -3767,19 +3748,6 @@ glusterd_op_status_volume(dict_t *dict, char **op_errstr, dict_t *rsp_dict)
f338ef
                 node_count++;
f338ef
             }
f338ef
 
f338ef
-            if (glusterd_is_shd_compatible_volume(volinfo)) {
f338ef
-                shd_enabled = gd_is_self_heal_enabled(volinfo, vol_opts);
f338ef
-                if (shd_enabled) {
f338ef
-                    ret = glusterd_add_shd_to_dict(volinfo, rsp_dict,
f338ef
-                                                   other_index);
f338ef
-                    if (ret)
f338ef
-                        goto out;
f338ef
-                    other_count++;
f338ef
-                    other_index++;
f338ef
-                    node_count++;
f338ef
-                }
f338ef
-            }
f338ef
-
f338ef
             nfs_disabled = dict_get_str_boolean(vol_opts, NFS_DISABLE_MAP_KEY,
f338ef
                                                 _gf_false);
f338ef
             if (!nfs_disabled) {
f338ef
@@ -3792,6 +3760,18 @@ glusterd_op_status_volume(dict_t *dict, char **op_errstr, dict_t *rsp_dict)
f338ef
                 node_count++;
f338ef
             }
f338ef
 
f338ef
+            if (glusterd_is_shd_compatible_volume(volinfo))
f338ef
+                shd_enabled = gd_is_self_heal_enabled(volinfo, vol_opts);
f338ef
+            if (shd_enabled) {
f338ef
+                ret = glusterd_add_node_to_dict(priv->shd_svc.name, rsp_dict,
f338ef
+                                                other_index, vol_opts);
f338ef
+                if (ret)
f338ef
+                    goto out;
f338ef
+                other_count++;
f338ef
+                node_count++;
f338ef
+                other_index++;
f338ef
+            }
f338ef
+
f338ef
             if (glusterd_is_volume_quota_enabled(volinfo)) {
f338ef
                 ret = glusterd_add_node_to_dict(priv->quotad_svc.name, rsp_dict,
f338ef
                                                 other_index, vol_opts);
f338ef
@@ -6904,18 +6884,16 @@ glusterd_shd_select_brick_xlator(dict_t *dict, gf_xl_afr_op_t heal_op,
f338ef
     int ret = -1;
f338ef
     glusterd_conf_t *priv = NULL;
f338ef
     xlator_t *this = NULL;
f338ef
-    glusterd_svc_t *svc = NULL;
f338ef
 
f338ef
     this = THIS;
f338ef
     GF_ASSERT(this);
f338ef
     priv = this->private;
f338ef
     GF_ASSERT(priv);
f338ef
-    svc = &(volinfo->shd.svc);
f338ef
 
f338ef
     switch (heal_op) {
f338ef
         case GF_SHD_OP_INDEX_SUMMARY:
f338ef
         case GF_SHD_OP_STATISTICS_HEAL_COUNT:
f338ef
-            if (!svc->online) {
f338ef
+            if (!priv->shd_svc.online) {
f338ef
                 if (!rsp_dict) {
f338ef
                     gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_OPCTX_NULL,
f338ef
                            "Received "
f338ef
@@ -6936,7 +6914,7 @@ glusterd_shd_select_brick_xlator(dict_t *dict, gf_xl_afr_op_t heal_op,
f338ef
             break;
f338ef
 
f338ef
         case GF_SHD_OP_STATISTICS_HEAL_COUNT_PER_REPLICA:
f338ef
-            if (!svc->online) {
f338ef
+            if (!priv->shd_svc.online) {
f338ef
                 if (!rsp_dict) {
f338ef
                     gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_OPCTX_NULL,
f338ef
                            "Received "
f338ef
@@ -7071,7 +7049,7 @@ glusterd_bricks_select_heal_volume(dict_t *dict, char **op_errstr,
f338ef
         ret = -1;
f338ef
         goto out;
f338ef
     } else {
f338ef
-        pending_node->node = &(volinfo->shd.svc);
f338ef
+        pending_node->node = &(priv->shd_svc);
f338ef
         pending_node->type = GD_NODE_SHD;
f338ef
         cds_list_add_tail(&pending_node->list, selected);
f338ef
         pending_node = NULL;
f338ef
@@ -7205,7 +7183,6 @@ glusterd_bricks_select_status_volume(dict_t *dict, char **op_errstr,
f338ef
     glusterd_pending_node_t *pending_node = NULL;
f338ef
     xlator_t *this = NULL;
f338ef
     glusterd_conf_t *priv = NULL;
f338ef
-    glusterd_svc_t *svc = NULL;
f338ef
 
f338ef
     GF_ASSERT(dict);
f338ef
 
f338ef
@@ -7301,8 +7278,7 @@ glusterd_bricks_select_status_volume(dict_t *dict, char **op_errstr,
f338ef
 
f338ef
         ret = 0;
f338ef
     } else if ((cmd & GF_CLI_STATUS_SHD) != 0) {
f338ef
-        svc = &(volinfo->shd.svc);
f338ef
-        if (!svc->online) {
f338ef
+        if (!priv->shd_svc.online) {
f338ef
             ret = -1;
f338ef
             gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_SELF_HEALD_DISABLED,
f338ef
                    "Self-heal daemon is not running");
f338ef
@@ -7314,7 +7290,7 @@ glusterd_bricks_select_status_volume(dict_t *dict, char **op_errstr,
f338ef
             ret = -1;
f338ef
             goto out;
f338ef
         }
f338ef
-        pending_node->node = svc;
f338ef
+        pending_node->node = &(priv->shd_svc);
f338ef
         pending_node->type = GD_NODE_SHD;
f338ef
         pending_node->index = 0;
f338ef
         cds_list_add_tail(&pending_node->list, selected);
f338ef
diff --git a/xlators/mgmt/glusterd/src/glusterd-shd-svc-helper.c b/xlators/mgmt/glusterd/src/glusterd-shd-svc-helper.c
f338ef
deleted file mode 100644
f338ef
index 9196758..0000000
f338ef
--- a/xlators/mgmt/glusterd/src/glusterd-shd-svc-helper.c
f338ef
+++ /dev/null
f338ef
@@ -1,140 +0,0 @@
f338ef
-/*
f338ef
-   Copyright (c) 2016 Red Hat, Inc. <http://www.redhat.com>
f338ef
-   This file is part of GlusterFS.
f338ef
-
f338ef
-   This file is licensed to you under your choice of the GNU Lesser
f338ef
-   General Public License, version 3 or any later version (LGPLv3 or
f338ef
-   later), or the GNU General Public License, version 2 (GPLv2), in all
f338ef
-   cases as published by the Free Software Foundation.
f338ef
-*/
f338ef
-
f338ef
-#include "glusterd.h"
f338ef
-#include "glusterd-utils.h"
f338ef
-#include "glusterd-shd-svc-helper.h"
f338ef
-#include "glusterd-messages.h"
f338ef
-#include "glusterd-volgen.h"
f338ef
-
f338ef
-void
f338ef
-glusterd_svc_build_shd_socket_filepath(glusterd_volinfo_t *volinfo, char *path,
f338ef
-                                       int path_len)
f338ef
-{
f338ef
-    char sockfilepath[PATH_MAX] = {
f338ef
-        0,
f338ef
-    };
f338ef
-    char rundir[PATH_MAX] = {
f338ef
-        0,
f338ef
-    };
f338ef
-    int32_t len = 0;
f338ef
-    glusterd_conf_t *priv = THIS->private;
f338ef
-
f338ef
-    if (!priv)
f338ef
-        return;
f338ef
-
f338ef
-    GLUSTERD_GET_SHD_RUNDIR(rundir, volinfo, priv);
f338ef
-    len = snprintf(sockfilepath, sizeof(sockfilepath), "%s/run-%s", rundir,
f338ef
-                   uuid_utoa(MY_UUID));
f338ef
-    if ((len < 0) || (len >= sizeof(sockfilepath))) {
f338ef
-        sockfilepath[0] = 0;
f338ef
-    }
f338ef
-
f338ef
-    glusterd_set_socket_filepath(sockfilepath, path, path_len);
f338ef
-}
f338ef
-
f338ef
-void
f338ef
-glusterd_svc_build_shd_pidfile(glusterd_volinfo_t *volinfo, char *path,
f338ef
-                               int path_len)
f338ef
-{
f338ef
-    char rundir[PATH_MAX] = {
f338ef
-        0,
f338ef
-    };
f338ef
-    glusterd_conf_t *priv = THIS->private;
f338ef
-
f338ef
-    if (!priv)
f338ef
-        return;
f338ef
-
f338ef
-    GLUSTERD_GET_SHD_RUNDIR(rundir, volinfo, priv);
f338ef
-
f338ef
-    snprintf(path, path_len, "%s/%s-shd.pid", rundir, volinfo->volname);
f338ef
-}
f338ef
-
f338ef
-void
f338ef
-glusterd_svc_build_shd_volfile_path(glusterd_volinfo_t *volinfo, char *path,
f338ef
-                                    int path_len)
f338ef
-{
f338ef
-    char workdir[PATH_MAX] = {
f338ef
-        0,
f338ef
-    };
f338ef
-    glusterd_conf_t *priv = THIS->private;
f338ef
-
f338ef
-    if (!priv)
f338ef
-        return;
f338ef
-
f338ef
-    GLUSTERD_GET_VOLUME_DIR(workdir, volinfo, priv);
f338ef
-
f338ef
-    snprintf(path, path_len, "%s/%s-shd.vol", workdir, volinfo->volname);
f338ef
-}
f338ef
-
f338ef
-void
f338ef
-glusterd_svc_build_shd_logdir(char *logdir, char *volname, size_t len)
f338ef
-{
f338ef
-    snprintf(logdir, len, "%s/shd/%s", DEFAULT_LOG_FILE_DIRECTORY, volname);
f338ef
-}
f338ef
-
f338ef
-void
f338ef
-glusterd_svc_build_shd_logfile(char *logfile, char *logdir, size_t len)
f338ef
-{
f338ef
-    snprintf(logfile, len, "%s/shd.log", logdir);
f338ef
-}
f338ef
-
f338ef
-void
f338ef
-glusterd_shd_svcproc_cleanup(glusterd_shdsvc_t *shd)
f338ef
-{
f338ef
-    glusterd_svc_proc_t *svc_proc = NULL;
f338ef
-    glusterd_svc_t *svc = NULL;
f338ef
-    glusterd_conf_t *conf = NULL;
f338ef
-    gf_boolean_t need_unref = _gf_false;
f338ef
-    rpc_clnt_t *rpc = NULL;
f338ef
-
f338ef
-    conf = THIS->private;
f338ef
-    if (!conf)
f338ef
-        return;
f338ef
-
f338ef
-    GF_VALIDATE_OR_GOTO(THIS->name, conf, out);
f338ef
-    GF_VALIDATE_OR_GOTO(THIS->name, shd, out);
f338ef
-
f338ef
-    svc = &shd->svc;
f338ef
-    shd->attached = _gf_false;
f338ef
-
f338ef
-    if (svc->conn.rpc) {
f338ef
-        rpc_clnt_unref(svc->conn.rpc);
f338ef
-        svc->conn.rpc = NULL;
f338ef
-    }
f338ef
-
f338ef
-    pthread_mutex_lock(&conf->attach_lock);
f338ef
-    {
f338ef
-        svc_proc = svc->svc_proc;
f338ef
-        svc->svc_proc = NULL;
f338ef
-        svc->inited = _gf_false;
f338ef
-        cds_list_del_init(&svc->mux_svc);
f338ef
-        glusterd_unlink_file(svc->proc.pidfile);
f338ef
-
f338ef
-        if (svc_proc && cds_list_empty(&svc_proc->svcs)) {
f338ef
-            cds_list_del_init(&svc_proc->svc_proc_list);
f338ef
-            /* We cannot free svc_proc list from here. Because
f338ef
-             * if there are pending events on the rpc, it will
f338ef
-             * try to access the corresponding svc_proc, so unrefing
f338ef
-             * rpc request and then cleaning up the memory is carried
f338ef
-             * from the notify function upon RPC_CLNT_DESTROY destroy.
f338ef
-             */
f338ef
-            need_unref = _gf_true;
f338ef
-            rpc = svc_proc->rpc;
f338ef
-            svc_proc->rpc = NULL;
f338ef
-        }
f338ef
-    }
f338ef
-    pthread_mutex_unlock(&conf->attach_lock);
f338ef
-    /*rpc unref has to be performed outside the lock*/
f338ef
-    if (need_unref && rpc)
f338ef
-        rpc_clnt_unref(rpc);
f338ef
-out:
f338ef
-    return;
f338ef
-}
f338ef
diff --git a/xlators/mgmt/glusterd/src/glusterd-shd-svc-helper.h b/xlators/mgmt/glusterd/src/glusterd-shd-svc-helper.h
f338ef
deleted file mode 100644
f338ef
index c70702c..0000000
f338ef
--- a/xlators/mgmt/glusterd/src/glusterd-shd-svc-helper.h
f338ef
+++ /dev/null
f338ef
@@ -1,45 +0,0 @@
f338ef
-/*
f338ef
-   Copyright (c) 2016 Red Hat, Inc. <http://www.redhat.com>
f338ef
-   This file is part of GlusterFS.
f338ef
-
f338ef
-   This file is licensed to you under your choice of the GNU Lesser
f338ef
-   General Public License, version 3 or any later version (LGPLv3 or
f338ef
-   later), or the GNU General Public License, version 2 (GPLv2), in all
f338ef
-   cases as published by the Free Software Foundation.
f338ef
-*/
f338ef
-
f338ef
-#ifndef _GLUSTERD_SHD_SVC_HELPER_H_
f338ef
-#define _GLUSTERD_SHD_SVC_HELPER_H_
f338ef
-
f338ef
-#include "glusterd.h"
f338ef
-#include "glusterd-svc-mgmt.h"
f338ef
-
f338ef
-void
f338ef
-glusterd_svc_build_shd_socket_filepath(glusterd_volinfo_t *volinfo, char *path,
f338ef
-                                       int path_len);
f338ef
-
f338ef
-void
f338ef
-glusterd_svc_build_shd_pidfile(glusterd_volinfo_t *volinfo, char *path,
f338ef
-                               int path_len);
f338ef
-
f338ef
-void
f338ef
-glusterd_svc_build_shd_volfile_path(glusterd_volinfo_t *volinfo, char *path,
f338ef
-                                    int path_len);
f338ef
-
f338ef
-void
f338ef
-glusterd_svc_build_shd_logdir(char *logdir, char *volname, size_t len);
f338ef
-
f338ef
-void
f338ef
-glusterd_svc_build_shd_logfile(char *logfile, char *logdir, size_t len);
f338ef
-
f338ef
-void
f338ef
-glusterd_shd_svcproc_cleanup(glusterd_shdsvc_t *shd);
f338ef
-
f338ef
-int
f338ef
-glusterd_recover_shd_attach_failure(glusterd_volinfo_t *volinfo,
f338ef
-                                    glusterd_svc_t *svc, int flags);
f338ef
-
f338ef
-int
f338ef
-glusterd_shdsvc_create_volfile(glusterd_volinfo_t *volinfo);
f338ef
-
f338ef
-#endif
f338ef
diff --git a/xlators/mgmt/glusterd/src/glusterd-shd-svc.c b/xlators/mgmt/glusterd/src/glusterd-shd-svc.c
f338ef
index 4789843..f5379b0 100644
f338ef
--- a/xlators/mgmt/glusterd/src/glusterd-shd-svc.c
f338ef
+++ b/xlators/mgmt/glusterd/src/glusterd-shd-svc.c
f338ef
@@ -13,10 +13,9 @@
f338ef
 #include "glusterd.h"
f338ef
 #include "glusterd-utils.h"
f338ef
 #include "glusterd-volgen.h"
f338ef
+#include "glusterd-svc-mgmt.h"
f338ef
 #include "glusterd-shd-svc.h"
f338ef
-#include "glusterd-shd-svc-helper.h"
f338ef
 #include "glusterd-svc-helper.h"
f338ef
-#include "glusterd-store.h"
f338ef
 
f338ef
 #define GD_SHD_PROCESS_NAME "--process-name"
f338ef
 char *shd_svc_name = "glustershd";
f338ef
@@ -24,145 +23,27 @@ char *shd_svc_name = "glustershd";
f338ef
 void
f338ef
 glusterd_shdsvc_build(glusterd_svc_t *svc)
f338ef
 {
f338ef
-    int ret = -1;
f338ef
-    ret = snprintf(svc->name, sizeof(svc->name), "%s", shd_svc_name);
f338ef
-    if (ret < 0)
f338ef
-        return;
f338ef
-
f338ef
-    CDS_INIT_LIST_HEAD(&svc->mux_svc);
f338ef
     svc->manager = glusterd_shdsvc_manager;
f338ef
     svc->start = glusterd_shdsvc_start;
f338ef
-    svc->stop = glusterd_shdsvc_stop;
f338ef
-    svc->reconfigure = glusterd_shdsvc_reconfigure;
f338ef
+    svc->stop = glusterd_svc_stop;
f338ef
 }
f338ef
 
f338ef
 int
f338ef
-glusterd_shdsvc_init(void *data, glusterd_conn_t *mux_conn,
f338ef
-                     glusterd_svc_proc_t *mux_svc)
f338ef
+glusterd_shdsvc_init(glusterd_svc_t *svc)
f338ef
 {
f338ef
-    int ret = -1;
f338ef
-    char rundir[PATH_MAX] = {
f338ef
-        0,
f338ef
-    };
f338ef
-    char sockpath[PATH_MAX] = {
f338ef
-        0,
f338ef
-    };
f338ef
-    char pidfile[PATH_MAX] = {
f338ef
-        0,
f338ef
-    };
f338ef
-    char volfile[PATH_MAX] = {
f338ef
-        0,
f338ef
-    };
f338ef
-    char logdir[PATH_MAX] = {
f338ef
-        0,
f338ef
-    };
f338ef
-    char logfile[PATH_MAX] = {
f338ef
-        0,
f338ef
-    };
f338ef
-    char volfileid[256] = {0};
f338ef
-    glusterd_svc_t *svc = NULL;
f338ef
-    glusterd_volinfo_t *volinfo = NULL;
f338ef
-    glusterd_conf_t *priv = NULL;
f338ef
-    glusterd_muxsvc_conn_notify_t notify = NULL;
f338ef
-    xlator_t *this = NULL;
f338ef
-    char *volfileserver = NULL;
f338ef
-    int32_t len = 0;
f338ef
-
f338ef
-    this = THIS;
f338ef
-    GF_VALIDATE_OR_GOTO(THIS->name, this, out);
f338ef
-
f338ef
-    priv = this->private;
f338ef
-    GF_VALIDATE_OR_GOTO(this->name, priv, out);
f338ef
-
f338ef
-    volinfo = data;
f338ef
-    GF_VALIDATE_OR_GOTO(this->name, data, out);
f338ef
-    GF_VALIDATE_OR_GOTO(this->name, mux_svc, out);
f338ef
-
f338ef
-    svc = &(volinfo->shd.svc);
f338ef
-
f338ef
-    ret = snprintf(svc->name, sizeof(svc->name), "%s", shd_svc_name);
f338ef
-    if (ret < 0)
f338ef
-        goto out;
f338ef
-
f338ef
-    notify = glusterd_muxsvc_common_rpc_notify;
f338ef
-    glusterd_store_perform_node_state_store(volinfo);
f338ef
-
f338ef
-    GLUSTERD_GET_SHD_RUNDIR(rundir, volinfo, priv);
f338ef
-    glusterd_svc_create_rundir(rundir);
f338ef
-
f338ef
-    glusterd_svc_build_shd_logdir(logdir, volinfo->volname, sizeof(logdir));
f338ef
-    glusterd_svc_build_shd_logfile(logfile, logdir, sizeof(logfile));
f338ef
-
f338ef
-    /* Initialize the connection mgmt */
f338ef
-    if (mux_conn && mux_svc->rpc) {
f338ef
-        /* multiplexed svc */
f338ef
-        svc->conn.frame_timeout = mux_conn->frame_timeout;
f338ef
-        /* This will be unrefed from glusterd_shd_svcproc_cleanup*/
f338ef
-        svc->conn.rpc = rpc_clnt_ref(mux_svc->rpc);
f338ef
-        ret = snprintf(svc->conn.sockpath, sizeof(svc->conn.sockpath), "%s",
f338ef
-                       mux_conn->sockpath);
f338ef
-    } else {
f338ef
-        ret = mkdir_p(logdir, 0755, _gf_true);
f338ef
-        if ((ret == -1) && (EEXIST != errno)) {
f338ef
-            gf_msg(this->name, GF_LOG_ERROR, errno, GD_MSG_CREATE_DIR_FAILED,
f338ef
-                   "Unable to create logdir %s", logdir);
f338ef
-            goto out;
f338ef
-        }
f338ef
-
f338ef
-        glusterd_svc_build_shd_socket_filepath(volinfo, sockpath,
f338ef
-                                               sizeof(sockpath));
f338ef
-        ret = glusterd_muxsvc_conn_init(&(svc->conn), mux_svc, sockpath, 600,
f338ef
-                                        notify);
f338ef
-        if (ret)
f338ef
-            goto out;
f338ef
-        /* This will be unrefed when the last svcs is detached from the list */
f338ef
-        if (!mux_svc->rpc)
f338ef
-            mux_svc->rpc = rpc_clnt_ref(svc->conn.rpc);
f338ef
-    }
f338ef
-
f338ef
-    /* Initialize the process mgmt */
f338ef
-    glusterd_svc_build_shd_pidfile(volinfo, pidfile, sizeof(pidfile));
f338ef
-    glusterd_svc_build_shd_volfile_path(volinfo, volfile, PATH_MAX);
f338ef
-    len = snprintf(volfileid, sizeof(volfileid), "shd/%s", volinfo->volname);
f338ef
-    if ((len < 0) || (len >= sizeof(volfileid))) {
f338ef
-        ret = -1;
f338ef
-        goto out;
f338ef
-    }
f338ef
-
f338ef
-    if (dict_get_strn(this->options, "transport.socket.bind-address",
f338ef
-                      SLEN("transport.socket.bind-address"),
f338ef
-                      &volfileserver) != 0) {
f338ef
-        volfileserver = "localhost";
f338ef
-    }
f338ef
-    ret = glusterd_proc_init(&(svc->proc), shd_svc_name, pidfile, logdir,
f338ef
-                             logfile, volfile, volfileid, volfileserver);
f338ef
-    if (ret)
f338ef
-        goto out;
f338ef
-
f338ef
-out:
f338ef
-    gf_msg_debug(this ? this->name : "glusterd", 0, "Returning %d", ret);
f338ef
-    return ret;
f338ef
+    return glusterd_svc_init(svc, shd_svc_name);
f338ef
 }
f338ef
 
f338ef
-int
f338ef
-glusterd_shdsvc_create_volfile(glusterd_volinfo_t *volinfo)
f338ef
+static int
f338ef
+glusterd_shdsvc_create_volfile()
f338ef
 {
f338ef
     char filepath[PATH_MAX] = {
f338ef
         0,
f338ef
     };
f338ef
-
f338ef
     int ret = -1;
f338ef
+    glusterd_conf_t *conf = THIS->private;
f338ef
     dict_t *mod_dict = NULL;
f338ef
 
f338ef
-    glusterd_svc_build_shd_volfile_path(volinfo, filepath, PATH_MAX);
f338ef
-    if (!glusterd_is_shd_compatible_volume(volinfo)) {
f338ef
-        /* If volfile exist, delete it. This case happens when we
f338ef
-         * change from replica/ec to distribute.
f338ef
-         */
f338ef
-        (void)glusterd_unlink_file(filepath);
f338ef
-        ret = 0;
f338ef
-        goto out;
f338ef
-    }
f338ef
     mod_dict = dict_new();
f338ef
     if (!mod_dict)
f338ef
         goto out;
f338ef
@@ -183,7 +64,9 @@ glusterd_shdsvc_create_volfile(glusterd_volinfo_t *volinfo)
f338ef
     if (ret)
f338ef
         goto out;
f338ef
 
f338ef
-    ret = glusterd_shdsvc_generate_volfile(volinfo, filepath, mod_dict);
f338ef
+    glusterd_svc_build_volfile_path(shd_svc_name, conf->workdir, filepath,
f338ef
+                                    sizeof(filepath));
f338ef
+    ret = glusterd_create_global_volfile(build_shd_graph, filepath, mod_dict);
f338ef
     if (ret) {
f338ef
         gf_msg(THIS->name, GF_LOG_ERROR, 0, GD_MSG_VOLFILE_CREATE_FAIL,
f338ef
                "Failed to create volfile");
f338ef
@@ -198,89 +81,26 @@ out:
f338ef
     return ret;
f338ef
 }
f338ef
 
f338ef
-gf_boolean_t
f338ef
-glusterd_svcs_shd_compatible_volumes_stopped(glusterd_svc_t *svc)
f338ef
-{
f338ef
-    glusterd_svc_proc_t *svc_proc = NULL;
f338ef
-    glusterd_shdsvc_t *shd = NULL;
f338ef
-    glusterd_svc_t *temp_svc = NULL;
f338ef
-    glusterd_volinfo_t *volinfo = NULL;
f338ef
-    gf_boolean_t comp = _gf_false;
f338ef
-    glusterd_conf_t *conf = THIS->private;
f338ef
-
f338ef
-    GF_VALIDATE_OR_GOTO("glusterd", conf, out);
f338ef
-    GF_VALIDATE_OR_GOTO("glusterd", svc, out);
f338ef
-    pthread_mutex_lock(&conf->attach_lock);
f338ef
-    {
f338ef
-        svc_proc = svc->svc_proc;
f338ef
-        if (!svc_proc)
f338ef
-            goto unlock;
f338ef
-        cds_list_for_each_entry(temp_svc, &svc_proc->svcs, mux_svc)
f338ef
-        {
f338ef
-            /* Get volinfo->shd from svc object */
f338ef
-            shd = cds_list_entry(svc, glusterd_shdsvc_t, svc);
f338ef
-            if (!shd) {
f338ef
-                gf_msg("glusterd", GF_LOG_ERROR, 0, GD_MSG_SHD_OBJ_GET_FAIL,
f338ef
-                       "Failed to get shd object "
f338ef
-                       "from shd service");
f338ef
-                goto unlock;
f338ef
-            }
f338ef
-
f338ef
-            /* Get volinfo from shd */
f338ef
-            volinfo = cds_list_entry(shd, glusterd_volinfo_t, shd);
f338ef
-            if (!volinfo) {
f338ef
-                gf_msg("glusterd", GF_LOG_ERROR, 0, GD_MSG_VOLINFO_GET_FAIL,
f338ef
-                       "Failed to get volinfo from "
f338ef
-                       "from shd");
f338ef
-                goto unlock;
f338ef
-            }
f338ef
-            if (!glusterd_is_shd_compatible_volume(volinfo))
f338ef
-                continue;
f338ef
-            if (volinfo->status == GLUSTERD_STATUS_STARTED)
f338ef
-                goto unlock;
f338ef
-        }
f338ef
-        comp = _gf_true;
f338ef
-    }
f338ef
-unlock:
f338ef
-    pthread_mutex_unlock(&conf->attach_lock);
f338ef
-out:
f338ef
-    return comp;
f338ef
-}
f338ef
-
f338ef
 int
f338ef
 glusterd_shdsvc_manager(glusterd_svc_t *svc, void *data, int flags)
f338ef
 {
f338ef
-    int ret = -1;
f338ef
+    int ret = 0;
f338ef
     glusterd_volinfo_t *volinfo = NULL;
f338ef
 
f338ef
-    volinfo = data;
f338ef
-    GF_VALIDATE_OR_GOTO("glusterd", svc, out);
f338ef
-    GF_VALIDATE_OR_GOTO("glusterd", volinfo, out);
f338ef
-
f338ef
-    if (volinfo)
f338ef
-        glusterd_volinfo_ref(volinfo);
f338ef
-
f338ef
-    ret = glusterd_shdsvc_create_volfile(volinfo);
f338ef
-    if (ret)
f338ef
-        goto out;
f338ef
-
f338ef
-    if (!glusterd_is_shd_compatible_volume(volinfo)) {
f338ef
-        ret = 0;
f338ef
-        if (svc->inited) {
f338ef
-            /* This means glusterd was running for this volume and now
f338ef
-             * it was converted to a non-shd volume. So just stop the shd
f338ef
-             */
f338ef
-            ret = svc->stop(svc, SIGTERM);
f338ef
+    if (!svc->inited) {
f338ef
+        ret = glusterd_shdsvc_init(svc);
f338ef
+        if (ret) {
f338ef
+            gf_msg(THIS->name, GF_LOG_ERROR, 0, GD_MSG_FAILED_INIT_SHDSVC,
f338ef
+                   "Failed to init shd "
f338ef
+                   "service");
f338ef
+            goto out;
f338ef
+        } else {
f338ef
+            svc->inited = _gf_true;
f338ef
+            gf_msg_debug(THIS->name, 0, "shd service initialized");
f338ef
         }
f338ef
-        goto out;
f338ef
     }
f338ef
 
f338ef
-    ret = glusterd_shd_svc_mux_init(volinfo, svc);
f338ef
-    if (ret) {
f338ef
-        gf_msg(THIS->name, GF_LOG_ERROR, 0, GD_MSG_FAILED_INIT_SHDSVC,
f338ef
-               "Failed to init shd service");
f338ef
-        goto out;
f338ef
-    }
f338ef
+    volinfo = data;
f338ef
 
f338ef
     /* If all the volumes are stopped or all shd compatible volumes
f338ef
      * are stopped then stop the service if:
f338ef
@@ -290,26 +110,31 @@ glusterd_shdsvc_manager(glusterd_svc_t *svc, void *data, int flags)
f338ef
      * - volinfo is NULL or
f338ef
      * - volinfo is present and volume is shd compatible
f338ef
      */
f338ef
-    if (glusterd_svcs_shd_compatible_volumes_stopped(svc)) {
f338ef
-        /* TODO
f338ef
-         * Take a lock and detach all svc's to stop the process
f338ef
-         * also reset the init flag
f338ef
-         */
f338ef
-        ret = svc->stop(svc, SIGTERM);
f338ef
-    } else if (volinfo) {
f338ef
-        ret = svc->stop(svc, SIGTERM);
f338ef
-        if (ret)
f338ef
-            goto out;
f338ef
+    if (glusterd_are_all_volumes_stopped() ||
f338ef
+        glusterd_all_shd_compatible_volumes_stopped()) {
f338ef
+        if (!(volinfo && !glusterd_is_shd_compatible_volume(volinfo))) {
f338ef
+            ret = svc->stop(svc, SIGTERM);
f338ef
+        }
f338ef
+    } else {
f338ef
+        if (!(volinfo && !glusterd_is_shd_compatible_volume(volinfo))) {
f338ef
+            ret = glusterd_shdsvc_create_volfile();
f338ef
+            if (ret)
f338ef
+                goto out;
f338ef
+
f338ef
+            ret = svc->stop(svc, SIGTERM);
f338ef
+            if (ret)
f338ef
+                goto out;
f338ef
 
f338ef
-        if (volinfo->status == GLUSTERD_STATUS_STARTED) {
f338ef
             ret = svc->start(svc, flags);
f338ef
             if (ret)
f338ef
                 goto out;
f338ef
+
f338ef
+            ret = glusterd_conn_connect(&(svc->conn));
f338ef
+            if (ret)
f338ef
+                goto out;
f338ef
         }
f338ef
     }
f338ef
 out:
f338ef
-    if (volinfo)
f338ef
-        glusterd_volinfo_unref(volinfo);
f338ef
     if (ret)
f338ef
         gf_event(EVENT_SVC_MANAGER_FAILED, "svc_name=%s", svc->name);
f338ef
     gf_msg_debug(THIS->name, 0, "Returning %d", ret);
f338ef
@@ -318,7 +143,7 @@ out:
f338ef
 }
f338ef
 
f338ef
 int
f338ef
-glusterd_new_shd_svc_start(glusterd_svc_t *svc, int flags)
f338ef
+glusterd_shdsvc_start(glusterd_svc_t *svc, int flags)
f338ef
 {
f338ef
     int ret = -1;
f338ef
     char glusterd_uuid_option[PATH_MAX] = {0};
f338ef
@@ -363,136 +188,31 @@ glusterd_new_shd_svc_start(glusterd_svc_t *svc, int flags)
f338ef
         goto out;
f338ef
 
f338ef
     ret = glusterd_svc_start(svc, flags, cmdline);
f338ef
-    if (ret)
f338ef
-        goto out;
f338ef
 
f338ef
-    ret = glusterd_conn_connect(&(svc->conn));
f338ef
 out:
f338ef
     if (cmdline)
f338ef
         dict_unref(cmdline);
f338ef
-    return ret;
f338ef
-}
f338ef
 
f338ef
-int
f338ef
-glusterd_recover_shd_attach_failure(glusterd_volinfo_t *volinfo,
f338ef
-                                    glusterd_svc_t *svc, int flags)
f338ef
-{
f338ef
-    int ret = -1;
f338ef
-    glusterd_svc_proc_t *mux_proc = NULL;
f338ef
-    glusterd_conf_t *conf = NULL;
f338ef
-
f338ef
-    conf = THIS->private;
f338ef
-
f338ef
-    if (!conf || !volinfo || !svc)
f338ef
-        return -1;
f338ef
-    glusterd_shd_svcproc_cleanup(&volinfo->shd);
f338ef
-    mux_proc = glusterd_svcprocess_new();
f338ef
-    if (!mux_proc) {
f338ef
-        return -1;
f338ef
-    }
f338ef
-    ret = glusterd_shdsvc_init(volinfo, NULL, mux_proc);
f338ef
-    if (ret)
f338ef
-        return -1;
f338ef
-    pthread_mutex_lock(&conf->attach_lock);
f338ef
-    {
f338ef
-        cds_list_add_tail(&mux_proc->svc_proc_list, &conf->shd_procs);
f338ef
-        svc->svc_proc = mux_proc;
f338ef
-        cds_list_del_init(&svc->mux_svc);
f338ef
-        cds_list_add_tail(&svc->mux_svc, &mux_proc->svcs);
f338ef
-    }
f338ef
-    pthread_mutex_unlock(&conf->attach_lock);
f338ef
-
f338ef
-    ret = glusterd_new_shd_svc_start(svc, flags);
f338ef
-    if (!ret) {
f338ef
-        volinfo->shd.attached = _gf_true;
f338ef
-    }
f338ef
-    return ret;
f338ef
-}
f338ef
-
f338ef
-int
f338ef
-glusterd_shdsvc_start(glusterd_svc_t *svc, int flags)
f338ef
-{
f338ef
-    int ret = -1;
f338ef
-    glusterd_shdsvc_t *shd = NULL;
f338ef
-    glusterd_volinfo_t *volinfo = NULL;
f338ef
-    glusterd_conf_t *conf = NULL;
f338ef
-
f338ef
-    GF_VALIDATE_OR_GOTO("glusterd", svc, out);
f338ef
-    conf = THIS->private;
f338ef
-    GF_VALIDATE_OR_GOTO("glusterd", conf, out);
f338ef
-
f338ef
-    /* Get volinfo->shd from svc object */
f338ef
-    shd = cds_list_entry(svc, glusterd_shdsvc_t, svc);
f338ef
-    if (!shd) {
f338ef
-        gf_msg("glusterd", GF_LOG_ERROR, 0, GD_MSG_SHD_OBJ_GET_FAIL,
f338ef
-               "Failed to get shd object "
f338ef
-               "from shd service");
f338ef
-        return -1;
f338ef
-    }
f338ef
-
f338ef
-    /* Get volinfo from shd */
f338ef
-    volinfo = cds_list_entry(shd, glusterd_volinfo_t, shd);
f338ef
-    if (!volinfo) {
f338ef
-        gf_msg("glusterd", GF_LOG_ERROR, 0, GD_MSG_VOLINFO_GET_FAIL,
f338ef
-               "Failed to get volinfo from "
f338ef
-               "from shd");
f338ef
-        return -1;
f338ef
-    }
f338ef
-
f338ef
-    if (volinfo->status != GLUSTERD_STATUS_STARTED)
f338ef
-        return -1;
f338ef
-
f338ef
-    glusterd_volinfo_ref(volinfo);
f338ef
-    if (!svc->inited) {
f338ef
-        ret = glusterd_shd_svc_mux_init(volinfo, svc);
f338ef
-        if (ret)
f338ef
-            goto out;
f338ef
-    }
f338ef
-
f338ef
-    if (shd->attached) {
f338ef
-        ret = glusterd_attach_svc(svc, volinfo, flags);
f338ef
-        if (ret) {
f338ef
-            gf_msg("glusterd", GF_LOG_ERROR, 0, GD_MSG_VOLINFO_GET_FAIL,
f338ef
-                   "Failed to attach shd svc(volume=%s) to pid=%d. Starting"
f338ef
-                   "a new process",
f338ef
-                   volinfo->volname, glusterd_proc_get_pid(&svc->proc));
f338ef
-            ret = glusterd_recover_shd_attach_failure(volinfo, svc, flags);
f338ef
-        }
f338ef
-        goto out;
f338ef
-    }
f338ef
-    ret = glusterd_new_shd_svc_start(svc, flags);
f338ef
-    if (!ret) {
f338ef
-        shd->attached = _gf_true;
f338ef
-    }
f338ef
-out:
f338ef
-    if (volinfo)
f338ef
-        glusterd_volinfo_unref(volinfo);
f338ef
     gf_msg_debug(THIS->name, 0, "Returning %d", ret);
f338ef
 
f338ef
     return ret;
f338ef
 }
f338ef
 
f338ef
 int
f338ef
-glusterd_shdsvc_reconfigure(glusterd_volinfo_t *volinfo)
f338ef
+glusterd_shdsvc_reconfigure()
f338ef
 {
f338ef
     int ret = -1;
f338ef
     xlator_t *this = NULL;
f338ef
+    glusterd_conf_t *priv = NULL;
f338ef
     gf_boolean_t identical = _gf_false;
f338ef
-    dict_t *mod_dict = NULL;
f338ef
-    glusterd_svc_t *svc = NULL;
f338ef
 
f338ef
     this = THIS;
f338ef
     GF_VALIDATE_OR_GOTO("glusterd", this, out);
f338ef
 
f338ef
-    if (!volinfo) {
f338ef
-        /* reconfigure will be called separately*/
f338ef
-        ret = 0;
f338ef
-        goto out;
f338ef
-    }
f338ef
+    priv = this->private;
f338ef
+    GF_VALIDATE_OR_GOTO(this->name, priv, out);
f338ef
 
f338ef
-    glusterd_volinfo_ref(volinfo);
f338ef
-    svc = &(volinfo->shd.svc);
f338ef
-    if (glusterd_svcs_shd_compatible_volumes_stopped(svc))
f338ef
+    if (glusterd_all_shd_compatible_volumes_stopped())
f338ef
         goto manager;
f338ef
 
f338ef
     /*
f338ef
@@ -500,42 +220,8 @@ glusterd_shdsvc_reconfigure(glusterd_volinfo_t *volinfo)
f338ef
      * and cksum i.e. "character-by-character". If YES, then
f338ef
      * NOTHING has been changed, just return.
f338ef
      */
f338ef
-
f338ef
-    if (!glusterd_is_shd_compatible_volume(volinfo)) {
f338ef
-        if (svc->inited)
f338ef
-            goto manager;
f338ef
-
f338ef
-        /* Nothing to do if not shd compatible */
f338ef
-        ret = 0;
f338ef
-        goto out;
f338ef
-    }
f338ef
-    mod_dict = dict_new();
f338ef
-    if (!mod_dict)
f338ef
-        goto out;
f338ef
-
f338ef
-    ret = dict_set_uint32(mod_dict, "cluster.background-self-heal-count", 0);
f338ef
-    if (ret)
f338ef
-        goto out;
f338ef
-
f338ef
-    ret = dict_set_str(mod_dict, "cluster.data-self-heal", "on");
f338ef
-    if (ret)
f338ef
-        goto out;
f338ef
-
f338ef
-    ret = dict_set_str(mod_dict, "cluster.metadata-self-heal", "on");
f338ef
-    if (ret)
f338ef
-        goto out;
f338ef
-
f338ef
-    ret = dict_set_int32(mod_dict, "graph-check", 1);
f338ef
-    if (ret)
f338ef
-        goto out;
f338ef
-
f338ef
-    ret = dict_set_str(mod_dict, "cluster.entry-self-heal", "on");
f338ef
-    if (ret)
f338ef
-        goto out;
f338ef
-
f338ef
-    ret = glusterd_volume_svc_check_volfile_identical(
f338ef
-        "glustershd", mod_dict, volinfo, glusterd_shdsvc_generate_volfile,
f338ef
-        &identical);
f338ef
+    ret = glusterd_svc_check_volfile_identical(priv->shd_svc.name,
f338ef
+                                               build_shd_graph, &identical);
f338ef
     if (ret)
f338ef
         goto out;
f338ef
 
f338ef
@@ -550,9 +236,8 @@ glusterd_shdsvc_reconfigure(glusterd_volinfo_t *volinfo)
f338ef
      * changed, then inform the xlator to reconfigure the options.
f338ef
      */
f338ef
     identical = _gf_false; /* RESET the FLAG */
f338ef
-    ret = glusterd_volume_svc_check_topology_identical(
f338ef
-        "glustershd", mod_dict, volinfo, glusterd_shdsvc_generate_volfile,
f338ef
-        &identical);
f338ef
+    ret = glusterd_svc_check_topology_identical(priv->shd_svc.name,
f338ef
+                                                build_shd_graph, &identical);
f338ef
     if (ret)
f338ef
         goto out;
f338ef
 
f338ef
@@ -560,7 +245,7 @@ glusterd_shdsvc_reconfigure(glusterd_volinfo_t *volinfo)
f338ef
      * options to shd volfile, so that shd will be reconfigured.
f338ef
      */
f338ef
     if (identical) {
f338ef
-        ret = glusterd_shdsvc_create_volfile(volinfo);
f338ef
+        ret = glusterd_shdsvc_create_volfile();
f338ef
         if (ret == 0) { /* Only if above PASSES */
f338ef
             ret = glusterd_fetchspec_notify(THIS);
f338ef
         }
f338ef
@@ -568,129 +253,12 @@ glusterd_shdsvc_reconfigure(glusterd_volinfo_t *volinfo)
f338ef
     }
f338ef
 manager:
f338ef
     /*
f338ef
-     * shd volfile's topology has been changed. volfile needs
f338ef
-     * to be RECONFIGURED to ACT on the changed volfile.
f338ef
+     * shd volfile's topology has been changed. shd server needs
f338ef
+     * to be RESTARTED to ACT on the changed volfile.
f338ef
      */
f338ef
-    ret = svc->manager(svc, volinfo, PROC_START_NO_WAIT);
f338ef
+    ret = priv->shd_svc.manager(&(priv->shd_svc), NULL, PROC_START_NO_WAIT);
f338ef
 
f338ef
 out:
f338ef
-    if (volinfo)
f338ef
-        glusterd_volinfo_unref(volinfo);
f338ef
-    if (mod_dict)
f338ef
-        dict_unref(mod_dict);
f338ef
     gf_msg_debug(this ? this->name : "glusterd", 0, "Returning %d", ret);
f338ef
     return ret;
f338ef
 }
f338ef
-
f338ef
-int
f338ef
-glusterd_shdsvc_restart()
f338ef
-{
f338ef
-    glusterd_volinfo_t *volinfo = NULL;
f338ef
-    glusterd_volinfo_t *tmp = NULL;
f338ef
-    int ret = -1;
f338ef
-    xlator_t *this = THIS;
f338ef
-    glusterd_conf_t *conf = NULL;
f338ef
-    glusterd_svc_t *svc = NULL;
f338ef
-
f338ef
-    GF_VALIDATE_OR_GOTO("glusterd", this, out);
f338ef
-
f338ef
-    conf = this->private;
f338ef
-    GF_VALIDATE_OR_GOTO(this->name, conf, out);
f338ef
-
f338ef
-    pthread_mutex_lock(&conf->volume_lock);
f338ef
-    cds_list_for_each_entry_safe(volinfo, tmp, &conf->volumes, vol_list)
f338ef
-    {
f338ef
-        glusterd_volinfo_ref(volinfo);
f338ef
-        pthread_mutex_unlock(&conf->volume_lock);
f338ef
-        /* Start per volume shd svc */
f338ef
-        if (volinfo->status == GLUSTERD_STATUS_STARTED) {
f338ef
-            svc = &(volinfo->shd.svc);
f338ef
-            ret = svc->manager(svc, volinfo, PROC_START_NO_WAIT);
f338ef
-            if (ret) {
f338ef
-                gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_SHD_START_FAIL,
f338ef
-                       "Couldn't start shd for "
f338ef
-                       "vol: %s on restart",
f338ef
-                       volinfo->volname);
f338ef
-                gf_event(EVENT_SVC_MANAGER_FAILED, "volume=%s;svc_name=%s",
f338ef
-                         volinfo->volname, svc->name);
f338ef
-                glusterd_volinfo_unref(volinfo);
f338ef
-                goto out;
f338ef
-            }
f338ef
-        }
f338ef
-        glusterd_volinfo_unref(volinfo);
f338ef
-        pthread_mutex_lock(&conf->volume_lock);
f338ef
-    }
f338ef
-    pthread_mutex_unlock(&conf->volume_lock);
f338ef
-out:
f338ef
-    return ret;
f338ef
-}
f338ef
-
f338ef
-int
f338ef
-glusterd_shdsvc_stop(glusterd_svc_t *svc, int sig)
f338ef
-{
f338ef
-    int ret = -1;
f338ef
-    glusterd_svc_proc_t *svc_proc = NULL;
f338ef
-    glusterd_shdsvc_t *shd = NULL;
f338ef
-    glusterd_volinfo_t *volinfo = NULL;
f338ef
-    gf_boolean_t empty = _gf_false;
f338ef
-    glusterd_conf_t *conf = NULL;
f338ef
-    int pid = -1;
f338ef
-
f338ef
-    conf = THIS->private;
f338ef
-    GF_VALIDATE_OR_GOTO("glusterd", svc, out);
f338ef
-    svc_proc = svc->svc_proc;
f338ef
-    GF_VALIDATE_OR_GOTO("glusterd", svc_proc, out);
f338ef
-    GF_VALIDATE_OR_GOTO("glusterd", conf, out);
f338ef
-
f338ef
-    /* Get volinfo->shd from svc object */
f338ef
-    shd = cds_list_entry(svc, glusterd_shdsvc_t, svc);
f338ef
-    if (!shd) {
f338ef
-        gf_msg("glusterd", GF_LOG_ERROR, 0, GD_MSG_SHD_OBJ_GET_FAIL,
f338ef
-               "Failed to get shd object "
f338ef
-               "from shd service");
f338ef
-        return -1;
f338ef
-    }
f338ef
-
f338ef
-    /* Get volinfo from shd */
f338ef
-    volinfo = cds_list_entry(shd, glusterd_volinfo_t, shd);
f338ef
-    if (!volinfo) {
f338ef
-        gf_msg("glusterd", GF_LOG_ERROR, 0, GD_MSG_VOLINFO_GET_FAIL,
f338ef
-               "Failed to get volinfo from "
f338ef
-               "from shd");
f338ef
-        return -1;
f338ef
-    }
f338ef
-
f338ef
-    glusterd_volinfo_ref(volinfo);
f338ef
-    pthread_mutex_lock(&conf->attach_lock);
f338ef
-    {
f338ef
-        gf_is_service_running(svc->proc.pidfile, &pid;;
f338ef
-        cds_list_del_init(&svc->mux_svc);
f338ef
-        empty = cds_list_empty(&svc_proc->svcs);
f338ef
-    }
f338ef
-    pthread_mutex_unlock(&conf->attach_lock);
f338ef
-    if (empty) {
f338ef
-        /* Unref will happen when destroying the connection */
f338ef
-        glusterd_volinfo_ref(volinfo);
f338ef
-        svc_proc->data = volinfo;
f338ef
-        ret = glusterd_svc_stop(svc, sig);
f338ef
-    }
f338ef
-    if (!empty && pid != -1) {
f338ef
-        ret = glusterd_detach_svc(svc, volinfo, sig);
f338ef
-        if (ret)
f338ef
-            gf_msg(THIS->name, GF_LOG_ERROR, 0, GD_MSG_SVC_STOP_FAIL,
f338ef
-                   "shd service is failed to detach volume %s from pid %d",
f338ef
-                   volinfo->volname, glusterd_proc_get_pid(&svc->proc));
f338ef
-        else
f338ef
-            gf_msg(THIS->name, GF_LOG_INFO, 0, GD_MSG_SVC_STOP_SUCCESS,
f338ef
-                   "Shd service is detached for volume %s from pid %d",
f338ef
-                   volinfo->volname, glusterd_proc_get_pid(&svc->proc));
f338ef
-    }
f338ef
-    svc->online = _gf_false;
f338ef
-    (void)glusterd_unlink_file((char *)svc->proc.pidfile);
f338ef
-    glusterd_shd_svcproc_cleanup(shd);
f338ef
-    ret = 0;
f338ef
-    glusterd_volinfo_unref(volinfo);
f338ef
-out:
f338ef
-    gf_msg_debug(THIS->name, 0, "Returning %d", ret);
f338ef
-    return ret;
f338ef
-}
f338ef
diff --git a/xlators/mgmt/glusterd/src/glusterd-shd-svc.h b/xlators/mgmt/glusterd/src/glusterd-shd-svc.h
f338ef
index 55b409f..775a9d4 100644
f338ef
--- a/xlators/mgmt/glusterd/src/glusterd-shd-svc.h
f338ef
+++ b/xlators/mgmt/glusterd/src/glusterd-shd-svc.h
f338ef
@@ -12,20 +12,12 @@
f338ef
 #define _GLUSTERD_SHD_SVC_H_
f338ef
 
f338ef
 #include "glusterd-svc-mgmt.h"
f338ef
-#include "glusterd.h"
f338ef
-
f338ef
-typedef struct glusterd_shdsvc_ glusterd_shdsvc_t;
f338ef
-struct glusterd_shdsvc_ {
f338ef
-    glusterd_svc_t svc;
f338ef
-    gf_boolean_t attached;
f338ef
-};
f338ef
 
f338ef
 void
f338ef
 glusterd_shdsvc_build(glusterd_svc_t *svc);
f338ef
 
f338ef
 int
f338ef
-glusterd_shdsvc_init(void *data, glusterd_conn_t *mux_conn,
f338ef
-                     glusterd_svc_proc_t *svc_proc);
f338ef
+glusterd_shdsvc_init(glusterd_svc_t *svc);
f338ef
 
f338ef
 int
f338ef
 glusterd_shdsvc_manager(glusterd_svc_t *svc, void *data, int flags);
f338ef
@@ -35,11 +27,4 @@ glusterd_shdsvc_start(glusterd_svc_t *svc, int flags);
f338ef
 
f338ef
 int
f338ef
 glusterd_shdsvc_reconfigure();
f338ef
-
f338ef
-int
f338ef
-glusterd_shdsvc_restart();
f338ef
-
f338ef
-int
f338ef
-glusterd_shdsvc_stop(glusterd_svc_t *svc, int sig);
f338ef
-
f338ef
 #endif
f338ef
diff --git a/xlators/mgmt/glusterd/src/glusterd-sm.c b/xlators/mgmt/glusterd/src/glusterd-sm.c
f338ef
index 943b1c6..54a7bd1 100644
f338ef
--- a/xlators/mgmt/glusterd/src/glusterd-sm.c
f338ef
+++ b/xlators/mgmt/glusterd/src/glusterd-sm.c
f338ef
@@ -748,16 +748,6 @@ glusterd_peer_detach_cleanup(glusterd_conf_t *priv)
f338ef
                 }
f338ef
             }
f338ef
 
f338ef
-            if (glusterd_is_shd_compatible_volume(volinfo)) {
f338ef
-                svc = &(volinfo->shd.svc);
f338ef
-                ret = svc->stop(svc, SIGTERM);
f338ef
-                if (ret) {
f338ef
-                    gf_msg(THIS->name, GF_LOG_ERROR, 0, GD_MSG_SVC_STOP_FAIL,
f338ef
-                           "Failed "
f338ef
-                           "to stop shd daemon service");
f338ef
-                }
f338ef
-            }
f338ef
-
f338ef
             if (glusterd_is_gfproxyd_enabled(volinfo)) {
f338ef
                 svc = &(volinfo->gfproxyd.svc);
f338ef
                 ret = svc->stop(svc, SIGTERM);
f338ef
@@ -785,7 +775,7 @@ glusterd_peer_detach_cleanup(glusterd_conf_t *priv)
f338ef
     }
f338ef
 
f338ef
     /*Reconfigure all daemon services upon peer detach*/
f338ef
-    ret = glusterd_svcs_reconfigure(NULL);
f338ef
+    ret = glusterd_svcs_reconfigure();
f338ef
     if (ret) {
f338ef
         gf_msg(THIS->name, GF_LOG_ERROR, 0, GD_MSG_SVC_STOP_FAIL,
f338ef
                "Failed to reconfigure all daemon services.");
f338ef
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapd-svc.c b/xlators/mgmt/glusterd/src/glusterd-snapd-svc.c
f338ef
index 1da4076..56bab07 100644
f338ef
--- a/xlators/mgmt/glusterd/src/glusterd-snapd-svc.c
f338ef
+++ b/xlators/mgmt/glusterd/src/glusterd-snapd-svc.c
f338ef
@@ -366,7 +366,6 @@ int
f338ef
 glusterd_snapdsvc_restart()
f338ef
 {
f338ef
     glusterd_volinfo_t *volinfo = NULL;
f338ef
-    glusterd_volinfo_t *tmp = NULL;
f338ef
     int ret = 0;
f338ef
     xlator_t *this = THIS;
f338ef
     glusterd_conf_t *conf = NULL;
f338ef
@@ -377,7 +376,7 @@ glusterd_snapdsvc_restart()
f338ef
     conf = this->private;
f338ef
     GF_ASSERT(conf);
f338ef
 
f338ef
-    cds_list_for_each_entry_safe(volinfo, tmp, &conf->volumes, vol_list)
f338ef
+    cds_list_for_each_entry(volinfo, &conf->volumes, vol_list)
f338ef
     {
f338ef
         /* Start per volume snapd svc */
f338ef
         if (volinfo->status == GLUSTERD_STATUS_STARTED) {
f338ef
diff --git a/xlators/mgmt/glusterd/src/glusterd-statedump.c b/xlators/mgmt/glusterd/src/glusterd-statedump.c
f338ef
index 69d4cf4..f5ecde7 100644
f338ef
--- a/xlators/mgmt/glusterd/src/glusterd-statedump.c
f338ef
+++ b/xlators/mgmt/glusterd/src/glusterd-statedump.c
f338ef
@@ -202,6 +202,9 @@ glusterd_dump_priv(xlator_t *this)
f338ef
         gf_proc_dump_build_key(key, "glusterd", "ping-timeout");
f338ef
         gf_proc_dump_write(key, "%d", priv->ping_timeout);
f338ef
 
f338ef
+        gf_proc_dump_build_key(key, "glusterd", "shd.online");
f338ef
+        gf_proc_dump_write(key, "%d", priv->shd_svc.online);
f338ef
+
f338ef
         gf_proc_dump_build_key(key, "glusterd", "nfs.online");
f338ef
         gf_proc_dump_write(key, "%d", priv->nfs_svc.online);
f338ef
 
f338ef
diff --git a/xlators/mgmt/glusterd/src/glusterd-svc-helper.c b/xlators/mgmt/glusterd/src/glusterd-svc-helper.c
f338ef
index e42703c..ca19a75 100644
f338ef
--- a/xlators/mgmt/glusterd/src/glusterd-svc-helper.c
f338ef
+++ b/xlators/mgmt/glusterd/src/glusterd-svc-helper.c
f338ef
@@ -7,7 +7,6 @@
f338ef
    later), or the GNU General Public License, version 2 (GPLv2), in all
f338ef
    cases as published by the Free Software Foundation.
f338ef
 */
f338ef
-#include <signal.h>
f338ef
 
f338ef
 #include <glusterfs/globals.h>
f338ef
 #include <glusterfs/run.h>
f338ef
@@ -21,14 +20,12 @@
f338ef
 #include "glusterd-bitd-svc.h"
f338ef
 #include "glusterd-tierd-svc.h"
f338ef
 #include "glusterd-tierd-svc-helper.h"
f338ef
-#include "glusterd-shd-svc-helper.h"
f338ef
 #include "glusterd-scrub-svc.h"
f338ef
 #include "glusterd-svc-helper.h"
f338ef
 #include <glusterfs/syscall.h>
f338ef
-#include "glusterd-snapshot-utils.h"
f338ef
 
f338ef
 int
f338ef
-glusterd_svcs_reconfigure(glusterd_volinfo_t *volinfo)
f338ef
+glusterd_svcs_reconfigure()
f338ef
 {
f338ef
     int ret = 0;
f338ef
     xlator_t *this = THIS;
f338ef
@@ -46,11 +43,9 @@ glusterd_svcs_reconfigure(glusterd_volinfo_t *volinfo)
f338ef
         goto out;
f338ef
 
f338ef
     svc_name = "self-heald";
f338ef
-    if (volinfo) {
f338ef
-        ret = glusterd_shdsvc_reconfigure(volinfo);
f338ef
-        if (ret)
f338ef
-            goto out;
f338ef
-    }
f338ef
+    ret = glusterd_shdsvc_reconfigure();
f338ef
+    if (ret)
f338ef
+        goto out;
f338ef
 
f338ef
     if (conf->op_version == GD_OP_VERSION_MIN)
f338ef
         goto out;
f338ef
@@ -74,7 +69,7 @@ out:
f338ef
 }
f338ef
 
f338ef
 int
f338ef
-glusterd_svcs_stop(glusterd_volinfo_t *volinfo)
f338ef
+glusterd_svcs_stop()
f338ef
 {
f338ef
     int ret = 0;
f338ef
     xlator_t *this = NULL;
f338ef
@@ -90,15 +85,13 @@ glusterd_svcs_stop(glusterd_volinfo_t *volinfo)
f338ef
     if (ret)
f338ef
         goto out;
f338ef
 
f338ef
-    ret = glusterd_svc_stop(&(priv->quotad_svc), SIGTERM);
f338ef
+    ret = glusterd_svc_stop(&(priv->shd_svc), SIGTERM);
f338ef
     if (ret)
f338ef
         goto out;
f338ef
 
f338ef
-    if (volinfo) {
f338ef
-        ret = glusterd_svc_stop(&(volinfo->shd.svc), PROC_START_NO_WAIT);
f338ef
-        if (ret)
f338ef
-            goto out;
f338ef
-    }
f338ef
+    ret = glusterd_svc_stop(&(priv->quotad_svc), SIGTERM);
f338ef
+    if (ret)
f338ef
+        goto out;
f338ef
 
f338ef
     ret = glusterd_svc_stop(&(priv->bitd_svc), SIGTERM);
f338ef
     if (ret)
f338ef
@@ -128,6 +121,12 @@ glusterd_svcs_manager(glusterd_volinfo_t *volinfo)
f338ef
     if (ret)
f338ef
         goto out;
f338ef
 
f338ef
+    ret = conf->shd_svc.manager(&(conf->shd_svc), volinfo, PROC_START_NO_WAIT);
f338ef
+    if (ret == -EINVAL)
f338ef
+        ret = 0;
f338ef
+    if (ret)
f338ef
+        goto out;
f338ef
+
f338ef
     if (conf->op_version == GD_OP_VERSION_MIN)
f338ef
         goto out;
f338ef
 
f338ef
@@ -144,15 +143,6 @@ glusterd_svcs_manager(glusterd_volinfo_t *volinfo)
f338ef
     if (ret)
f338ef
         goto out;
f338ef
 
f338ef
-    if (volinfo) {
f338ef
-        ret = volinfo->shd.svc.manager(&(volinfo->shd.svc), volinfo,
f338ef
-                                       PROC_START_NO_WAIT);
f338ef
-        if (ret == -EINVAL)
f338ef
-            ret = 0;
f338ef
-        if (ret)
f338ef
-            goto out;
f338ef
-    }
f338ef
-
f338ef
     ret = conf->scrub_svc.manager(&(conf->scrub_svc), NULL, PROC_START_NO_WAIT);
f338ef
     if (ret == -EINVAL)
f338ef
         ret = 0;
f338ef
@@ -279,678 +269,3 @@ out:
f338ef
         GF_FREE(tmpvol);
f338ef
     return ret;
f338ef
 }
f338ef
-
f338ef
-int
f338ef
-glusterd_volume_svc_check_volfile_identical(
f338ef
-    char *svc_name, dict_t *mode_dict, glusterd_volinfo_t *volinfo,
f338ef
-    glusterd_vol_graph_builder_t builder, gf_boolean_t *identical)
f338ef
-{
f338ef
-    char orgvol[PATH_MAX] = {
f338ef
-        0,
f338ef
-    };
f338ef
-    char *tmpvol = NULL;
f338ef
-    xlator_t *this = NULL;
f338ef
-    int ret = -1;
f338ef
-    int need_unlink = 0;
f338ef
-    int tmp_fd = -1;
f338ef
-
f338ef
-    this = THIS;
f338ef
-
f338ef
-    GF_VALIDATE_OR_GOTO(this->name, this, out);
f338ef
-    GF_VALIDATE_OR_GOTO(this->name, identical, out);
f338ef
-
f338ef
-    /* This builds volfile for volume level dameons */
f338ef
-    glusterd_volume_svc_build_volfile_path(svc_name, volinfo, orgvol,
f338ef
-                                           sizeof(orgvol));
f338ef
-
f338ef
-    ret = gf_asprintf(&tmpvol, "/tmp/g%s-XXXXXX", svc_name);
f338ef
-    if (ret < 0) {
f338ef
-        goto out;
f338ef
-    }
f338ef
-
f338ef
-    /* coverity[secure_temp] mkstemp uses 0600 as the mode and is safe */
f338ef
-    tmp_fd = mkstemp(tmpvol);
f338ef
-    if (tmp_fd < 0) {
f338ef
-        gf_msg(this->name, GF_LOG_WARNING, errno, GD_MSG_FILE_OP_FAILED,
f338ef
-               "Unable to create temp file"
f338ef
-               " %s:(%s)",
f338ef
-               tmpvol, strerror(errno));
f338ef
-        ret = -1;
f338ef
-        goto out;
f338ef
-    }
f338ef
-
f338ef
-    need_unlink = 1;
f338ef
-
f338ef
-    ret = builder(volinfo, tmpvol, mode_dict);
f338ef
-    if (ret)
f338ef
-        goto out;
f338ef
-
f338ef
-    ret = glusterd_check_files_identical(orgvol, tmpvol, identical);
f338ef
-out:
f338ef
-    if (need_unlink)
f338ef
-        sys_unlink(tmpvol);
f338ef
-
f338ef
-    if (tmpvol != NULL)
f338ef
-        GF_FREE(tmpvol);
f338ef
-
f338ef
-    if (tmp_fd >= 0)
f338ef
-        sys_close(tmp_fd);
f338ef
-
f338ef
-    return ret;
f338ef
-}
f338ef
-
f338ef
-int
f338ef
-glusterd_volume_svc_check_topology_identical(
f338ef
-    char *svc_name, dict_t *mode_dict, glusterd_volinfo_t *volinfo,
f338ef
-    glusterd_vol_graph_builder_t builder, gf_boolean_t *identical)
f338ef
-{
f338ef
-    char orgvol[PATH_MAX] = {
f338ef
-        0,
f338ef
-    };
f338ef
-    char *tmpvol = NULL;
f338ef
-    glusterd_conf_t *conf = NULL;
f338ef
-    xlator_t *this = THIS;
f338ef
-    int ret = -1;
f338ef
-    int tmpclean = 0;
f338ef
-    int tmpfd = -1;
f338ef
-
f338ef
-    if ((!identical) || (!this) || (!this->private))
f338ef
-        goto out;
f338ef
-
f338ef
-    conf = this->private;
f338ef
-    GF_VALIDATE_OR_GOTO(this->name, conf, out);
f338ef
-
f338ef
-    /* This builds volfile for volume level dameons */
f338ef
-    glusterd_volume_svc_build_volfile_path(svc_name, volinfo, orgvol,
f338ef
-                                           sizeof(orgvol));
f338ef
-    /* Create the temporary volfile */
f338ef
-    ret = gf_asprintf(&tmpvol, "/tmp/g%s-XXXXXX", svc_name);
f338ef
-    if (ret < 0) {
f338ef
-        goto out;
f338ef
-    }
f338ef
-
f338ef
-    /* coverity[secure_temp] mkstemp uses 0600 as the mode and is safe */
f338ef
-    tmpfd = mkstemp(tmpvol);
f338ef
-    if (tmpfd < 0) {
f338ef
-        gf_msg(this->name, GF_LOG_WARNING, errno, GD_MSG_FILE_OP_FAILED,
f338ef
-               "Unable to create temp file"
f338ef
-               " %s:(%s)",
f338ef
-               tmpvol, strerror(errno));
f338ef
-        ret = -1;
f338ef
-        goto out;
f338ef
-    }
f338ef
-
f338ef
-    tmpclean = 1; /* SET the flag to unlink() tmpfile */
f338ef
-
f338ef
-    ret = builder(volinfo, tmpvol, mode_dict);
f338ef
-    if (ret)
f338ef
-        goto out;
f338ef
-
f338ef
-    /* Compare the topology of volfiles */
f338ef
-    ret = glusterd_check_topology_identical(orgvol, tmpvol, identical);
f338ef
-out:
f338ef
-    if (tmpfd >= 0)
f338ef
-        sys_close(tmpfd);
f338ef
-    if (tmpclean)
f338ef
-        sys_unlink(tmpvol);
f338ef
-    if (tmpvol != NULL)
f338ef
-        GF_FREE(tmpvol);
f338ef
-    return ret;
f338ef
-}
f338ef
-
f338ef
-void *
f338ef
-__gf_find_compatible_svc(gd_node_type daemon)
f338ef
-{
f338ef
-    glusterd_svc_proc_t *svc_proc = NULL;
f338ef
-    glusterd_svc_proc_t *return_proc = NULL;
f338ef
-    glusterd_svc_t *parent_svc = NULL;
f338ef
-    struct cds_list_head *svc_procs = NULL;
f338ef
-    glusterd_conf_t *conf = NULL;
f338ef
-    int pid = -1;
f338ef
-
f338ef
-    conf = THIS->private;
f338ef
-    GF_VALIDATE_OR_GOTO("glusterd", conf, out);
f338ef
-
f338ef
-    if (daemon == GD_NODE_SHD) {
f338ef
-        svc_procs = &conf->shd_procs;
f338ef
-        if (!svc_procs)
f338ef
-            goto out;
f338ef
-    }
f338ef
-
f338ef
-    cds_list_for_each_entry(svc_proc, svc_procs, svc_proc_list)
f338ef
-    {
f338ef
-        parent_svc = cds_list_entry(svc_proc->svcs.next, glusterd_svc_t,
f338ef
-                                    mux_svc);
f338ef
-        if (!return_proc)
f338ef
-            return_proc = svc_proc;
f338ef
-
f338ef
-        /* If there is an  already running shd daemons, select it. Otehrwise
f338ef
-         * select the first one.
f338ef
-         */
f338ef
-        if (parent_svc && gf_is_service_running(parent_svc->proc.pidfile, &pid))
f338ef
-            return (void *)svc_proc;
f338ef
-        /*
f338ef
-         * Logic to select one process goes here. Currently there is only one
f338ef
-         * shd_proc. So selecting the first one;
f338ef
-         */
f338ef
-    }
f338ef
-out:
f338ef
-    return return_proc;
f338ef
-}
f338ef
-
f338ef
-glusterd_svc_proc_t *
f338ef
-glusterd_svcprocess_new()
f338ef
-{
f338ef
-    glusterd_svc_proc_t *new_svcprocess = NULL;
f338ef
-
f338ef
-    new_svcprocess = GF_CALLOC(1, sizeof(*new_svcprocess),
f338ef
-                               gf_gld_mt_glusterd_svc_proc_t);
f338ef
-
f338ef
-    if (!new_svcprocess)
f338ef
-        return NULL;
f338ef
-
f338ef
-    CDS_INIT_LIST_HEAD(&new_svcprocess->svc_proc_list);
f338ef
-    CDS_INIT_LIST_HEAD(&new_svcprocess->svcs);
f338ef
-    new_svcprocess->notify = glusterd_muxsvc_common_rpc_notify;
f338ef
-    return new_svcprocess;
f338ef
-}
f338ef
-
f338ef
-int
f338ef
-glusterd_shd_svc_mux_init(glusterd_volinfo_t *volinfo, glusterd_svc_t *svc)
f338ef
-{
f338ef
-    int ret = -1;
f338ef
-    glusterd_svc_proc_t *mux_proc = NULL;
f338ef
-    glusterd_conn_t *mux_conn = NULL;
f338ef
-    glusterd_conf_t *conf = NULL;
f338ef
-    glusterd_svc_t *parent_svc = NULL;
f338ef
-    int pid = -1;
f338ef
-
f338ef
-    GF_VALIDATE_OR_GOTO("glusterd", svc, out);
f338ef
-    GF_VALIDATE_OR_GOTO("glusterd", volinfo, out);
f338ef
-    conf = THIS->private;
f338ef
-    GF_VALIDATE_OR_GOTO("glusterd", conf, out);
f338ef
-    GF_VALIDATE_OR_GOTO("glusterd", svc, out);
f338ef
-
f338ef
-    pthread_mutex_lock(&conf->attach_lock);
f338ef
-    {
f338ef
-        if (!svc->inited) {
f338ef
-            if (gf_is_service_running(svc->proc.pidfile, &pid)) {
f338ef
-                /* Just connect is required, but we don't know what happens
f338ef
-                 * during the disconnect. So better to reattach.
f338ef
-                 */
f338ef
-                mux_proc = __gf_find_compatible_svc_from_pid(GD_NODE_SHD, pid);
f338ef
-            }
f338ef
-
f338ef
-            if (!mux_proc) {
f338ef
-                if (pid != -1 && sys_access(svc->proc.pidfile, R_OK) == 0) {
f338ef
-                    /* stale pid file, unlink it. */
f338ef
-                    kill(pid, SIGTERM);
f338ef
-                    sys_unlink(svc->proc.pidfile);
f338ef
-                }
f338ef
-                mux_proc = __gf_find_compatible_svc(GD_NODE_SHD);
f338ef
-            }
f338ef
-            if (mux_proc) {
f338ef
-                /* Take first entry from the process */
f338ef
-                parent_svc = cds_list_entry(mux_proc->svcs.next, glusterd_svc_t,
f338ef
-                                            mux_svc);
f338ef
-                sys_link(parent_svc->proc.pidfile, svc->proc.pidfile);
f338ef
-                mux_conn = &parent_svc->conn;
f338ef
-                if (volinfo)
f338ef
-                    volinfo->shd.attached = _gf_true;
f338ef
-            } else {
f338ef
-                mux_proc = glusterd_svcprocess_new();
f338ef
-                if (!mux_proc) {
f338ef
-                    ret = -1;
f338ef
-                    goto unlock;
f338ef
-                }
f338ef
-                cds_list_add_tail(&mux_proc->svc_proc_list, &conf->shd_procs);
f338ef
-            }
f338ef
-            svc->svc_proc = mux_proc;
f338ef
-            cds_list_del_init(&svc->mux_svc);
f338ef
-            cds_list_add_tail(&svc->mux_svc, &mux_proc->svcs);
f338ef
-            ret = glusterd_shdsvc_init(volinfo, mux_conn, mux_proc);
f338ef
-            if (ret) {
f338ef
-                pthread_mutex_unlock(&conf->attach_lock);
f338ef
-                gf_msg(THIS->name, GF_LOG_ERROR, 0, GD_MSG_FAILED_INIT_SHDSVC,
f338ef
-                       "Failed to init shd "
f338ef
-                       "service");
f338ef
-                goto out;
f338ef
-            }
f338ef
-            gf_msg_debug(THIS->name, 0, "shd service initialized");
f338ef
-            svc->inited = _gf_true;
f338ef
-        }
f338ef
-        ret = 0;
f338ef
-    }
f338ef
-unlock:
f338ef
-    pthread_mutex_unlock(&conf->attach_lock);
f338ef
-out:
f338ef
-    return ret;
f338ef
-}
f338ef
-
f338ef
-void *
f338ef
-__gf_find_compatible_svc_from_pid(gd_node_type daemon, pid_t pid)
f338ef
-{
f338ef
-    glusterd_svc_proc_t *svc_proc = NULL;
f338ef
-    struct cds_list_head *svc_procs = NULL;
f338ef
-    glusterd_svc_t *svc = NULL;
f338ef
-    pid_t mux_pid = -1;
f338ef
-    glusterd_conf_t *conf = NULL;
f338ef
-
f338ef
-    conf = THIS->private;
f338ef
-    if (!conf)
f338ef
-        return NULL;
f338ef
-
f338ef
-    if (daemon == GD_NODE_SHD) {
f338ef
-        svc_procs = &conf->shd_procs;
f338ef
-        if (!svc_proc)
f338ef
-            return NULL;
f338ef
-    } /* Can be moved to switch when mux is implemented for other daemon; */
f338ef
-
f338ef
-    cds_list_for_each_entry(svc_proc, svc_procs, svc_proc_list)
f338ef
-    {
f338ef
-        cds_list_for_each_entry(svc, &svc_proc->svcs, mux_svc)
f338ef
-        {
f338ef
-            if (gf_is_service_running(svc->proc.pidfile, &mux_pid)) {
f338ef
-                if (mux_pid == pid) {
f338ef
-                    /*TODO
f338ef
-                     * inefficient loop, but at the moment, there is only
f338ef
-                     * one shd.
f338ef
-                     */
f338ef
-                    return svc_proc;
f338ef
-                }
f338ef
-            }
f338ef
-        }
f338ef
-    }
f338ef
-    return NULL;
f338ef
-}
f338ef
-
f338ef
-static int32_t
f338ef
-my_callback(struct rpc_req *req, struct iovec *iov, int count, void *v_frame)
f338ef
-{
f338ef
-    call_frame_t *frame = v_frame;
f338ef
-    xlator_t *this = NULL;
f338ef
-    glusterd_conf_t *conf = NULL;
f338ef
-
f338ef
-    GF_VALIDATE_OR_GOTO("glusterd", frame, out);
f338ef
-    this = frame->this;
f338ef
-    GF_VALIDATE_OR_GOTO("glusterd", this, out);
f338ef
-    conf = this->private;
f338ef
-    GF_VALIDATE_OR_GOTO(this->name, conf, out);
f338ef
-
f338ef
-    GF_ATOMIC_DEC(conf->blockers);
f338ef
-
f338ef
-    STACK_DESTROY(frame->root);
f338ef
-out:
f338ef
-    return 0;
f338ef
-}
f338ef
-
f338ef
-static int32_t
f338ef
-glusterd_svc_attach_cbk(struct rpc_req *req, struct iovec *iov, int count,
f338ef
-                        void *v_frame)
f338ef
-{
f338ef
-    call_frame_t *frame = v_frame;
f338ef
-    glusterd_volinfo_t *volinfo = NULL;
f338ef
-    glusterd_shdsvc_t *shd = NULL;
f338ef
-    glusterd_svc_t *svc = frame->cookie;
f338ef
-    glusterd_svc_t *parent_svc = NULL;
f338ef
-    glusterd_svc_proc_t *mux_proc = NULL;
f338ef
-    glusterd_conf_t *conf = NULL;
f338ef
-    int *flag = (int *)frame->local;
f338ef
-    xlator_t *this = THIS;
f338ef
-    int pid = -1;
f338ef
-    int ret = -1;
f338ef
-    gf_getspec_rsp rsp = {
f338ef
-        0,
f338ef
-    };
f338ef
-
f338ef
-    GF_VALIDATE_OR_GOTO("glusterd", this, out);
f338ef
-    conf = this->private;
f338ef
-    GF_VALIDATE_OR_GOTO("glusterd", conf, out);
f338ef
-    GF_VALIDATE_OR_GOTO("glusterd", frame, out);
f338ef
-    GF_VALIDATE_OR_GOTO("glusterd", svc, out);
f338ef
-
f338ef
-    frame->local = NULL;
f338ef
-    frame->cookie = NULL;
f338ef
-
f338ef
-    if (!strcmp(svc->name, "glustershd")) {
f338ef
-        /* Get volinfo->shd from svc object */
f338ef
-        shd = cds_list_entry(svc, glusterd_shdsvc_t, svc);
f338ef
-        if (!shd) {
f338ef
-            gf_msg("glusterd", GF_LOG_ERROR, 0, GD_MSG_SHD_OBJ_GET_FAIL,
f338ef
-                   "Failed to get shd object "
f338ef
-                   "from shd service");
f338ef
-            goto out;
f338ef
-        }
f338ef
-
f338ef
-        /* Get volinfo from shd */
f338ef
-        volinfo = cds_list_entry(shd, glusterd_volinfo_t, shd);
f338ef
-        if (!volinfo) {
f338ef
-            gf_msg("glusterd", GF_LOG_ERROR, 0, GD_MSG_VOLINFO_GET_FAIL,
f338ef
-                   "Failed to get volinfo from "
f338ef
-                   "from shd");
f338ef
-            goto out;
f338ef
-        }
f338ef
-    }
f338ef
-
f338ef
-    if (!iov) {
f338ef
-        gf_msg(frame->this->name, GF_LOG_ERROR, 0, GD_MSG_REQ_DECODE_FAIL,
f338ef
-               "iov is NULL");
f338ef
-        ret = -1;
f338ef
-        goto out;
f338ef
-    }
f338ef
-
f338ef
-    ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_getspec_rsp);
f338ef
-    if (ret < 0) {
f338ef
-        gf_msg(frame->this->name, GF_LOG_ERROR, 0, GD_MSG_REQ_DECODE_FAIL,
f338ef
-               "XDR decoding error");
f338ef
-        ret = -1;
f338ef
-        goto out;
f338ef
-    }
f338ef
-
f338ef
-    if (rsp.op_ret == 0) {
f338ef
-        pthread_mutex_lock(&conf->attach_lock);
f338ef
-        {
f338ef
-            if (!strcmp(svc->name, "glustershd")) {
f338ef
-                mux_proc = svc->svc_proc;
f338ef
-                if (mux_proc &&
f338ef
-                    !gf_is_service_running(svc->proc.pidfile, &pid)) {
f338ef
-                    /*
f338ef
-                     * When svc's are restarting, there is a chance that the
f338ef
-                     * attached svc might not have updated it's pid. Because
f338ef
-                     * it was at connection stage. So in that case, we need
f338ef
-                     * to retry the pid file copy.
f338ef
-                     */
f338ef
-                    parent_svc = cds_list_entry(mux_proc->svcs.next,
f338ef
-                                                glusterd_svc_t, mux_svc);
f338ef
-                    if (parent_svc)
f338ef
-                        sys_link(parent_svc->proc.pidfile, svc->proc.pidfile);
f338ef
-                }
f338ef
-            }
f338ef
-            svc->online = _gf_true;
f338ef
-        }
f338ef
-        pthread_mutex_unlock(&conf->attach_lock);
f338ef
-        gf_msg(this->name, GF_LOG_INFO, 0, GD_MSG_SVC_ATTACH_FAIL,
f338ef
-               "svc %s of volume %s attached successfully to pid %d", svc->name,
f338ef
-               volinfo->volname, glusterd_proc_get_pid(&svc->proc));
f338ef
-    } else {
f338ef
-        gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_SVC_ATTACH_FAIL,
f338ef
-               "svc %s of volume %s failed to "
f338ef
-               "attach to pid %d. Starting a new process",
f338ef
-               svc->name, volinfo->volname, glusterd_proc_get_pid(&svc->proc));
f338ef
-        if (!strcmp(svc->name, "glustershd")) {
f338ef
-            glusterd_recover_shd_attach_failure(volinfo, svc, *flag);
f338ef
-        }
f338ef
-    }
f338ef
-out:
f338ef
-    if (flag) {
f338ef
-        GF_FREE(flag);
f338ef
-    }
f338ef
-    GF_ATOMIC_DEC(conf->blockers);
f338ef
-    STACK_DESTROY(frame->root);
f338ef
-    return 0;
f338ef
-}
f338ef
-
f338ef
-extern size_t
f338ef
-build_volfile_path(char *volume_id, char *path, size_t path_len,
f338ef
-                   char *trusted_str);
f338ef
-
f338ef
-int
f338ef
-__glusterd_send_svc_configure_req(glusterd_svc_t *svc, int flags,
f338ef
-                                  struct rpc_clnt *rpc, char *volfile_id,
f338ef
-                                  int op)
f338ef
-{
f338ef
-    int ret = -1;
f338ef
-    struct iobuf *iobuf = NULL;
f338ef
-    struct iobref *iobref = NULL;
f338ef
-    struct iovec iov = {
f338ef
-        0,
f338ef
-    };
f338ef
-    char path[PATH_MAX] = {
f338ef
-        '\0',
f338ef
-    };
f338ef
-    struct stat stbuf = {
f338ef
-        0,
f338ef
-    };
f338ef
-    int32_t spec_fd = -1;
f338ef
-    size_t file_len = -1;
f338ef
-    char *volfile_content = NULL;
f338ef
-    ssize_t req_size = 0;
f338ef
-    call_frame_t *frame = NULL;
f338ef
-    gd1_mgmt_brick_op_req brick_req;
f338ef
-    void *req = &brick_req;
f338ef
-    void *errlbl = &&err;
f338ef
-    struct rpc_clnt_connection *conn;
f338ef
-    xlator_t *this = THIS;
f338ef
-    glusterd_conf_t *conf = THIS->private;
f338ef
-    extern struct rpc_clnt_program gd_brick_prog;
f338ef
-    fop_cbk_fn_t cbkfn = my_callback;
f338ef
-
f338ef
-    if (!rpc) {
f338ef
-        gf_msg("glusterd", GF_LOG_ERROR, 0, GD_MSG_PARAM_NULL,
f338ef
-               "called with null rpc");
f338ef
-        return -1;
f338ef
-    }
f338ef
-
f338ef
-    conn = &rpc->conn;
f338ef
-    if (!conn->connected || conn->disconnected) {
f338ef
-        gf_msg(this->name, GF_LOG_INFO, 0, GD_MSG_CONNECT_RETURNED,
f338ef
-               "not connected yet");
f338ef
-        return -1;
f338ef
-    }
f338ef
-
f338ef
-    brick_req.op = op;
f338ef
-    brick_req.name = volfile_id;
f338ef
-    brick_req.input.input_val = NULL;
f338ef
-    brick_req.input.input_len = 0;
f338ef
-
f338ef
-    frame = create_frame(this, this->ctx->pool);
f338ef
-    if (!frame) {
f338ef
-        goto *errlbl;
f338ef
-    }
f338ef
-
f338ef
-    if (op == GLUSTERD_SVC_ATTACH) {
f338ef
-        (void)build_volfile_path(volfile_id, path, sizeof(path), NULL);
f338ef
-
f338ef
-        ret = sys_stat(path, &stbuf);
f338ef
-        if (ret < 0) {
f338ef
-            gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_SVC_ATTACH_FAIL,
f338ef
-                   "Unable to stat %s (%s)", path, strerror(errno));
f338ef
-            ret = -EINVAL;
f338ef
-            goto *errlbl;
f338ef
-        }
f338ef
-
f338ef
-        file_len = stbuf.st_size;
f338ef
-        volfile_content = GF_MALLOC(file_len + 1, gf_common_mt_char);
f338ef
-        if (!volfile_content) {
f338ef
-            ret = -ENOMEM;
f338ef
-            goto *errlbl;
f338ef
-        }
f338ef
-        spec_fd = open(path, O_RDONLY);
f338ef
-        if (spec_fd < 0) {
f338ef
-            gf_msg(THIS->name, GF_LOG_WARNING, 0, GD_MSG_SVC_ATTACH_FAIL,
f338ef
-                   "failed to read volfile %s", path);
f338ef
-            ret = -EIO;
f338ef
-            goto *errlbl;
f338ef
-        }
f338ef
-        ret = sys_read(spec_fd, volfile_content, file_len);
f338ef
-        if (ret == file_len) {
f338ef
-            brick_req.input.input_val = volfile_content;
f338ef
-            brick_req.input.input_len = file_len;
f338ef
-        } else {
f338ef
-            gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_SVC_ATTACH_FAIL,
f338ef
-                   "read failed on path %s. File size=%" GF_PRI_SIZET
f338ef
-                   "read size=%d",
f338ef
-                   path, file_len, ret);
f338ef
-            ret = -EIO;
f338ef
-            goto *errlbl;
f338ef
-        }
f338ef
-
f338ef
-        frame->cookie = svc;
f338ef
-        frame->local = GF_CALLOC(1, sizeof(int), gf_gld_mt_int);
f338ef
-        *((int *)frame->local) = flags;
f338ef
-        cbkfn = glusterd_svc_attach_cbk;
f338ef
-    }
f338ef
-
f338ef
-    req_size = xdr_sizeof((xdrproc_t)xdr_gd1_mgmt_brick_op_req, req);
f338ef
-    iobuf = iobuf_get2(rpc->ctx->iobuf_pool, req_size);
f338ef
-    if (!iobuf) {
f338ef
-        goto *errlbl;
f338ef
-    }
f338ef
-    errlbl = &&maybe_free_iobuf;
f338ef
-
f338ef
-    iov.iov_base = iobuf->ptr;
f338ef
-    iov.iov_len = iobuf_pagesize(iobuf);
f338ef
-
f338ef
-    iobref = iobref_new();
f338ef
-    if (!iobref) {
f338ef
-        goto *errlbl;
f338ef
-    }
f338ef
-    errlbl = &&free_iobref;
f338ef
-
f338ef
-    iobref_add(iobref, iobuf);
f338ef
-    /*
f338ef
-     * Drop our reference to the iobuf.  The iobref should already have
f338ef
-     * one after iobref_add, so when we unref that we'll free the iobuf as
f338ef
-     * well.  This allows us to pass just the iobref as frame->local.
f338ef
-     */
f338ef
-    iobuf_unref(iobuf);
f338ef
-    /* Set the pointer to null so we don't free it on a later error. */
f338ef
-    iobuf = NULL;
f338ef
-
f338ef
-    /* Create the xdr payload */
f338ef
-    ret = xdr_serialize_generic(iov, req, (xdrproc_t)xdr_gd1_mgmt_brick_op_req);
f338ef
-    if (ret == -1) {
f338ef
-        goto *errlbl;
f338ef
-    }
f338ef
-    iov.iov_len = ret;
f338ef
-
f338ef
-    /* Send the msg */
f338ef
-    GF_ATOMIC_INC(conf->blockers);
f338ef
-    ret = rpc_clnt_submit(rpc, &gd_brick_prog, op, cbkfn, &iov, 1, NULL, 0,
f338ef
-                          iobref, frame, NULL, 0, NULL, 0, NULL);
f338ef
-    GF_FREE(volfile_content);
f338ef
-    if (spec_fd >= 0)
f338ef
-        sys_close(spec_fd);
f338ef
-    return ret;
f338ef
-
f338ef
-free_iobref:
f338ef
-    iobref_unref(iobref);
f338ef
-maybe_free_iobuf:
f338ef
-    if (iobuf) {
f338ef
-        iobuf_unref(iobuf);
f338ef
-    }
f338ef
-err:
f338ef
-    GF_FREE(volfile_content);
f338ef
-    if (spec_fd >= 0)
f338ef
-        sys_close(spec_fd);
f338ef
-    if (frame)
f338ef
-        STACK_DESTROY(frame->root);
f338ef
-    return -1;
f338ef
-}
f338ef
-
f338ef
-int
f338ef
-glusterd_attach_svc(glusterd_svc_t *svc, glusterd_volinfo_t *volinfo, int flags)
f338ef
-{
f338ef
-    glusterd_conf_t *conf = THIS->private;
f338ef
-    int ret = -1;
f338ef
-    int tries;
f338ef
-    rpc_clnt_t *rpc = NULL;
f338ef
-
f338ef
-    GF_VALIDATE_OR_GOTO("glusterd", conf, out);
f338ef
-    GF_VALIDATE_OR_GOTO("glusterd", svc, out);
f338ef
-    GF_VALIDATE_OR_GOTO("glusterd", volinfo, out);
f338ef
-
f338ef
-    gf_msg("glusterd", GF_LOG_INFO, 0, GD_MSG_ATTACH_INFO,
f338ef
-           "adding svc %s (volume=%s) to existing "
f338ef
-           "process with pid %d",
f338ef
-           svc->name, volinfo->volname, glusterd_proc_get_pid(&svc->proc));
f338ef
-
f338ef
-    rpc = rpc_clnt_ref(svc->conn.rpc);
f338ef
-    for (tries = 15; tries > 0; --tries) {
f338ef
-        if (rpc) {
f338ef
-            pthread_mutex_lock(&conf->attach_lock);
f338ef
-            {
f338ef
-                ret = __glusterd_send_svc_configure_req(
f338ef
-                    svc, flags, rpc, svc->proc.volfileid, GLUSTERD_SVC_ATTACH);
f338ef
-            }
f338ef
-            pthread_mutex_unlock(&conf->attach_lock);
f338ef
-            if (!ret) {
f338ef
-                volinfo->shd.attached = _gf_true;
f338ef
-                goto out;
f338ef
-            }
f338ef
-        }
f338ef
-        /*
f338ef
-         * It might not actually be safe to manipulate the lock
f338ef
-         * like this, but if we don't then the connection can
f338ef
-         * never actually complete and retries are useless.
f338ef
-         * Unfortunately, all of the alternatives (e.g. doing
f338ef
-         * all of this in a separate thread) are much more
f338ef
-         * complicated and risky.
f338ef
-         * TBD: see if there's a better way
f338ef
-         */
f338ef
-        synclock_unlock(&conf->big_lock);
f338ef
-        sleep(1);
f338ef
-        synclock_lock(&conf->big_lock);
f338ef
-    }
f338ef
-    ret = -1;
f338ef
-    gf_msg("glusterd", GF_LOG_WARNING, 0, GD_MSG_SVC_ATTACH_FAIL,
f338ef
-           "attach failed for %s(volume=%s)", svc->name, volinfo->volname);
f338ef
-out:
f338ef
-    if (rpc)
f338ef
-        rpc_clnt_unref(rpc);
f338ef
-    return ret;
f338ef
-}
f338ef
-
f338ef
-int
f338ef
-glusterd_detach_svc(glusterd_svc_t *svc, glusterd_volinfo_t *volinfo, int sig)
f338ef
-{
f338ef
-    glusterd_conf_t *conf = THIS->private;
f338ef
-    int ret = -1;
f338ef
-    int tries;
f338ef
-    rpc_clnt_t *rpc = NULL;
f338ef
-
f338ef
-    GF_VALIDATE_OR_GOTO(THIS->name, conf, out);
f338ef
-    GF_VALIDATE_OR_GOTO(THIS->name, svc, out);
f338ef
-    GF_VALIDATE_OR_GOTO(THIS->name, volinfo, out);
f338ef
-
f338ef
-    gf_msg(THIS->name, GF_LOG_INFO, 0, GD_MSG_DETACH_INFO,
f338ef
-           "removing svc %s (volume=%s) from existing "
f338ef
-           "process with pid %d",
f338ef
-           svc->name, volinfo->volname, glusterd_proc_get_pid(&svc->proc));
f338ef
-
f338ef
-    rpc = rpc_clnt_ref(svc->conn.rpc);
f338ef
-    for (tries = 15; tries > 0; --tries) {
f338ef
-        if (rpc) {
f338ef
-            /*For detach there is no flags, and we are not using sig.*/
f338ef
-            pthread_mutex_lock(&conf->attach_lock);
f338ef
-            {
f338ef
-                ret = __glusterd_send_svc_configure_req(svc, 0, svc->conn.rpc,
f338ef
-                                                        svc->proc.volfileid,
f338ef
-                                                        GLUSTERD_SVC_DETACH);
f338ef
-            }
f338ef
-            pthread_mutex_unlock(&conf->attach_lock);
f338ef
-            if (!ret) {
f338ef
-                goto out;
f338ef
-            }
f338ef
-        }
f338ef
-        /*
f338ef
-         * It might not actually be safe to manipulate the lock
f338ef
-         * like this, but if we don't then the connection can
f338ef
-         * never actually complete and retries are useless.
f338ef
-         * Unfortunately, all of the alternatives (e.g. doing
f338ef
-         * all of this in a separate thread) are much more
f338ef
-         * complicated and risky.
f338ef
-         * TBD: see if there's a better way
f338ef
-         */
f338ef
-        synclock_unlock(&conf->big_lock);
f338ef
-        sleep(1);
f338ef
-        synclock_lock(&conf->big_lock);
f338ef
-    }
f338ef
-    ret = -1;
f338ef
-    gf_msg("glusterd", GF_LOG_WARNING, 0, GD_MSG_SVC_DETACH_FAIL,
f338ef
-           "detach failed for %s(volume=%s)", svc->name, volinfo->volname);
f338ef
-out:
f338ef
-    if (rpc)
f338ef
-        rpc_clnt_unref(rpc);
f338ef
-    return ret;
f338ef
-}
f338ef
diff --git a/xlators/mgmt/glusterd/src/glusterd-svc-helper.h b/xlators/mgmt/glusterd/src/glusterd-svc-helper.h
f338ef
index 5def246..cc98e78 100644
f338ef
--- a/xlators/mgmt/glusterd/src/glusterd-svc-helper.h
f338ef
+++ b/xlators/mgmt/glusterd/src/glusterd-svc-helper.h
f338ef
@@ -16,10 +16,10 @@
f338ef
 #include "glusterd-volgen.h"
f338ef
 
f338ef
 int
f338ef
-glusterd_svcs_reconfigure(glusterd_volinfo_t *volinfo);
f338ef
+glusterd_svcs_reconfigure();
f338ef
 
f338ef
 int
f338ef
-glusterd_svcs_stop(glusterd_volinfo_t *vol);
f338ef
+glusterd_svcs_stop();
f338ef
 
f338ef
 int
f338ef
 glusterd_svcs_manager(glusterd_volinfo_t *volinfo);
f338ef
@@ -41,41 +41,5 @@ int
f338ef
 glusterd_svc_check_tier_topology_identical(char *svc_name,
f338ef
                                            glusterd_volinfo_t *volinfo,
f338ef
                                            gf_boolean_t *identical);
f338ef
-int
f338ef
-glusterd_volume_svc_check_volfile_identical(char *svc_name, dict_t *mode_dict,
f338ef
-                                            glusterd_volinfo_t *volinfo,
f338ef
-                                            glusterd_vol_graph_builder_t,
f338ef
-                                            gf_boolean_t *identical);
f338ef
-int
f338ef
-glusterd_volume_svc_check_topology_identical(char *svc_name, dict_t *mode_dict,
f338ef
-                                             glusterd_volinfo_t *volinfo,
f338ef
-                                             glusterd_vol_graph_builder_t,
f338ef
-                                             gf_boolean_t *identical);
f338ef
-void
f338ef
-glusterd_volume_svc_build_volfile_path(char *server, glusterd_volinfo_t *vol,
f338ef
-                                       char *volfile, size_t len);
f338ef
-void *
f338ef
-__gf_find_compatible_svc(gd_node_type daemon);
f338ef
-
f338ef
-glusterd_svc_proc_t *
f338ef
-glusterd_svcprocess_new();
f338ef
-
f338ef
-int
f338ef
-glusterd_shd_svc_mux_init(glusterd_volinfo_t *volinfo, glusterd_svc_t *svc);
f338ef
-
f338ef
-void *
f338ef
-__gf_find_compatible_svc_from_pid(gd_node_type daemon, pid_t pid);
f338ef
-
f338ef
-int
f338ef
-glusterd_attach_svc(glusterd_svc_t *svc, glusterd_volinfo_t *volinfo,
f338ef
-                    int flags);
f338ef
-
f338ef
-int
f338ef
-glusterd_detach_svc(glusterd_svc_t *svc, glusterd_volinfo_t *volinfo, int sig);
f338ef
-
f338ef
-int
f338ef
-__glusterd_send_svc_configure_req(glusterd_svc_t *svc, int flag,
f338ef
-                                  struct rpc_clnt *rpc, char *volfile_id,
f338ef
-                                  int op);
f338ef
 
f338ef
 #endif
f338ef
diff --git a/xlators/mgmt/glusterd/src/glusterd-svc-mgmt.c b/xlators/mgmt/glusterd/src/glusterd-svc-mgmt.c
f338ef
index f32dafc..4cd4cea 100644
f338ef
--- a/xlators/mgmt/glusterd/src/glusterd-svc-mgmt.c
f338ef
+++ b/xlators/mgmt/glusterd/src/glusterd-svc-mgmt.c
f338ef
@@ -18,7 +18,6 @@
f338ef
 #include "glusterd-conn-mgmt.h"
f338ef
 #include "glusterd-messages.h"
f338ef
 #include <glusterfs/syscall.h>
f338ef
-#include "glusterd-shd-svc-helper.h"
f338ef
 
f338ef
 int
f338ef
 glusterd_svc_create_rundir(char *rundir)
f338ef
@@ -168,75 +167,68 @@ glusterd_svc_start(glusterd_svc_t *svc, int flags, dict_t *cmdline)
f338ef
     GF_ASSERT(this);
f338ef
 
f338ef
     priv = this->private;
f338ef
-    GF_VALIDATE_OR_GOTO("glusterd", priv, out);
f338ef
-    GF_VALIDATE_OR_GOTO("glusterd", svc, out);
f338ef
-
f338ef
-    pthread_mutex_lock(&priv->attach_lock);
f338ef
-    {
f338ef
-        if (glusterd_proc_is_running(&(svc->proc))) {
f338ef
-            ret = 0;
f338ef
-            goto unlock;
f338ef
-        }
f338ef
+    GF_ASSERT(priv);
f338ef
 
f338ef
-        ret = sys_access(svc->proc.volfile, F_OK);
f338ef
-        if (ret) {
f338ef
-            gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_VOLFILE_NOT_FOUND,
f338ef
-                   "Volfile %s is not present", svc->proc.volfile);
f338ef
-            goto unlock;
f338ef
-        }
f338ef
+    if (glusterd_proc_is_running(&(svc->proc))) {
f338ef
+        ret = 0;
f338ef
+        goto out;
f338ef
+    }
f338ef
 
f338ef
-        runinit(&runner);
f338ef
+    ret = sys_access(svc->proc.volfile, F_OK);
f338ef
+    if (ret) {
f338ef
+        gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_VOLFILE_NOT_FOUND,
f338ef
+               "Volfile %s is not present", svc->proc.volfile);
f338ef
+        goto out;
f338ef
+    }
f338ef
 
f338ef
-        if (this->ctx->cmd_args.valgrind) {
f338ef
-            len = snprintf(valgrind_logfile, PATH_MAX, "%s/valgrind-%s.log",
f338ef
-                           svc->proc.logfile, svc->name);
f338ef
-            if ((len < 0) || (len >= PATH_MAX)) {
f338ef
-                ret = -1;
f338ef
-                goto unlock;
f338ef
-            }
f338ef
+    runinit(&runner);
f338ef
 
f338ef
-            runner_add_args(&runner, "valgrind", "--leak-check=full",
f338ef
-                            "--trace-children=yes", "--track-origins=yes",
f338ef
-                            NULL);
f338ef
-            runner_argprintf(&runner, "--log-file=%s", valgrind_logfile);
f338ef
+    if (this->ctx->cmd_args.valgrind) {
f338ef
+        len = snprintf(valgrind_logfile, PATH_MAX, "%s/valgrind-%s.log",
f338ef
+                       svc->proc.logfile, svc->name);
f338ef
+        if ((len < 0) || (len >= PATH_MAX)) {
f338ef
+            ret = -1;
f338ef
+            goto out;
f338ef
         }
f338ef
 
f338ef
-        runner_add_args(&runner, SBIN_DIR "/glusterfs", "-s",
f338ef
-                        svc->proc.volfileserver, "--volfile-id",
f338ef
-                        svc->proc.volfileid, "-p", svc->proc.pidfile, "-l",
f338ef
-                        svc->proc.logfile, "-S", svc->conn.sockpath, NULL);
f338ef
+        runner_add_args(&runner, "valgrind", "--leak-check=full",
f338ef
+                        "--trace-children=yes", "--track-origins=yes", NULL);
f338ef
+        runner_argprintf(&runner, "--log-file=%s", valgrind_logfile);
f338ef
+    }
f338ef
 
f338ef
-        if (dict_get_strn(priv->opts, GLUSTERD_LOCALTIME_LOGGING_KEY,
f338ef
-                          SLEN(GLUSTERD_LOCALTIME_LOGGING_KEY),
f338ef
-                          &localtime_logging) == 0) {
f338ef
-            if (strcmp(localtime_logging, "enable") == 0)
f338ef
-                runner_add_arg(&runner, "--localtime-logging");
f338ef
-        }
f338ef
-        if (dict_get_strn(priv->opts, GLUSTERD_DAEMON_LOG_LEVEL_KEY,
f338ef
-                          SLEN(GLUSTERD_DAEMON_LOG_LEVEL_KEY),
f338ef
-                          &log_level) == 0) {
f338ef
-            snprintf(daemon_log_level, 30, "--log-level=%s", log_level);
f338ef
-            runner_add_arg(&runner, daemon_log_level);
f338ef
-        }
f338ef
+    runner_add_args(&runner, SBIN_DIR "/glusterfs", "-s",
f338ef
+                    svc->proc.volfileserver, "--volfile-id",
f338ef
+                    svc->proc.volfileid, "-p", svc->proc.pidfile, "-l",
f338ef
+                    svc->proc.logfile, "-S", svc->conn.sockpath, NULL);
f338ef
+
f338ef
+    if (dict_get_strn(priv->opts, GLUSTERD_LOCALTIME_LOGGING_KEY,
f338ef
+                      SLEN(GLUSTERD_LOCALTIME_LOGGING_KEY),
f338ef
+                      &localtime_logging) == 0) {
f338ef
+        if (strcmp(localtime_logging, "enable") == 0)
f338ef
+            runner_add_arg(&runner, "--localtime-logging");
f338ef
+    }
f338ef
+    if (dict_get_strn(priv->opts, GLUSTERD_DAEMON_LOG_LEVEL_KEY,
f338ef
+                      SLEN(GLUSTERD_DAEMON_LOG_LEVEL_KEY), &log_level) == 0) {
f338ef
+        snprintf(daemon_log_level, 30, "--log-level=%s", log_level);
f338ef
+        runner_add_arg(&runner, daemon_log_level);
f338ef
+    }
f338ef
 
f338ef
-        if (cmdline)
f338ef
-            dict_foreach(cmdline, svc_add_args, (void *)&runner);
f338ef
+    if (cmdline)
f338ef
+        dict_foreach(cmdline, svc_add_args, (void *)&runner);
f338ef
 
f338ef
-        gf_msg(this->name, GF_LOG_INFO, 0, GD_MSG_SVC_START_SUCCESS,
f338ef
-               "Starting %s service", svc->name);
f338ef
+    gf_msg(this->name, GF_LOG_INFO, 0, GD_MSG_SVC_START_SUCCESS,
f338ef
+           "Starting %s service", svc->name);
f338ef
 
f338ef
-        if (flags == PROC_START_NO_WAIT) {
f338ef
-            ret = runner_run_nowait(&runner);
f338ef
-        } else {
f338ef
-            synclock_unlock(&priv->big_lock);
f338ef
-            {
f338ef
-                ret = runner_run(&runner);
f338ef
-            }
f338ef
-            synclock_lock(&priv->big_lock);
f338ef
+    if (flags == PROC_START_NO_WAIT) {
f338ef
+        ret = runner_run_nowait(&runner);
f338ef
+    } else {
f338ef
+        synclock_unlock(&priv->big_lock);
f338ef
+        {
f338ef
+            ret = runner_run(&runner);
f338ef
         }
f338ef
+        synclock_lock(&priv->big_lock);
f338ef
     }
f338ef
-unlock:
f338ef
-    pthread_mutex_unlock(&priv->attach_lock);
f338ef
+
f338ef
 out:
f338ef
     gf_msg_debug(this->name, 0, "Returning %d", ret);
f338ef
 
f338ef
@@ -289,8 +281,7 @@ glusterd_svc_build_volfile_path(char *server, char *workdir, char *volfile,
f338ef
 
f338ef
     glusterd_svc_build_svcdir(server, workdir, dir, sizeof(dir));
f338ef
 
f338ef
-    if (!strcmp(server, "quotad"))
f338ef
-        /*quotad has different volfile name*/
f338ef
+    if (!strcmp(server, "quotad")) /*quotad has different volfile name*/
f338ef
         snprintf(volfile, len, "%s/%s.vol", dir, server);
f338ef
     else
f338ef
         snprintf(volfile, len, "%s/%s-server.vol", dir, server);
f338ef
@@ -375,138 +366,3 @@ glusterd_svc_common_rpc_notify(glusterd_conn_t *conn, rpc_clnt_event_t event)
f338ef
 
f338ef
     return ret;
f338ef
 }
f338ef
-
f338ef
-void
f338ef
-glusterd_volume_svc_build_volfile_path(char *server, glusterd_volinfo_t *vol,
f338ef
-                                       char *volfile, size_t len)
f338ef
-{
f338ef
-    GF_ASSERT(len == PATH_MAX);
f338ef
-
f338ef
-    if (!strcmp(server, "glustershd")) {
f338ef
-        glusterd_svc_build_shd_volfile_path(vol, volfile, len);
f338ef
-    }
f338ef
-}
f338ef
-
f338ef
-int
f338ef
-glusterd_muxsvc_common_rpc_notify(glusterd_svc_proc_t *mux_proc,
f338ef
-                                  rpc_clnt_event_t event)
f338ef
-{
f338ef
-    int ret = 0;
f338ef
-    glusterd_svc_t *svc = NULL;
f338ef
-    glusterd_svc_t *tmp = NULL;
f338ef
-    xlator_t *this = NULL;
f338ef
-    gf_boolean_t need_logging = _gf_false;
f338ef
-
f338ef
-    this = THIS;
f338ef
-    GF_ASSERT(this);
f338ef
-
f338ef
-    if (!mux_proc) {
f338ef
-        gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_SVC_GET_FAIL,
f338ef
-               "Failed to get the svc proc data");
f338ef
-        return -1;
f338ef
-    }
f338ef
-
f338ef
-    /* Currently this function was used for shd svc, if this function is
f338ef
-     * using for another svc, change ths glustershd reference. We can get
f338ef
-     * the svc name from any of the attached svc's
f338ef
-     */
f338ef
-    switch (event) {
f338ef
-        case RPC_CLNT_CONNECT:
f338ef
-            gf_msg_debug(this->name, 0,
f338ef
-                         "glustershd has connected with glusterd.");
f338ef
-            gf_event(EVENT_SVC_CONNECTED, "svc_name=glustershd");
f338ef
-            cds_list_for_each_entry_safe(svc, tmp, &mux_proc->svcs, mux_svc)
f338ef
-            {
f338ef
-                if (svc->online)
f338ef
-                    continue;
f338ef
-                svc->online = _gf_true;
f338ef
-            }
f338ef
-            break;
f338ef
-
f338ef
-        case RPC_CLNT_DISCONNECT:
f338ef
-            cds_list_for_each_entry_safe(svc, tmp, &mux_proc->svcs, mux_svc)
f338ef
-            {
f338ef
-                if (svc->online) {
f338ef
-                    if (!need_logging)
f338ef
-                        need_logging = _gf_true;
f338ef
-                    svc->online = _gf_false;
f338ef
-                }
f338ef
-            }
f338ef
-            if (need_logging) {
f338ef
-                gf_msg(this->name, GF_LOG_INFO, 0, GD_MSG_NODE_DISCONNECTED,
f338ef
-                       "glustershd has disconnected from glusterd.");
f338ef
-                gf_event(EVENT_SVC_DISCONNECTED, "svc_name=glustershd");
f338ef
-            }
f338ef
-            break;
f338ef
-
f338ef
-        default:
f338ef
-            gf_msg_trace(this->name, 0, "got some other RPC event %d", event);
f338ef
-            break;
f338ef
-    }
f338ef
-
f338ef
-    return ret;
f338ef
-}
f338ef
-
f338ef
-int
f338ef
-glusterd_muxsvc_conn_init(glusterd_conn_t *conn, glusterd_svc_proc_t *mux_proc,
f338ef
-                          char *sockpath, int frame_timeout,
f338ef
-                          glusterd_muxsvc_conn_notify_t notify)
f338ef
-{
f338ef
-    int ret = -1;
f338ef
-    dict_t *options = NULL;
f338ef
-    struct rpc_clnt *rpc = NULL;
f338ef
-    xlator_t *this = THIS;
f338ef
-    glusterd_svc_t *svc = NULL;
f338ef
-
f338ef
-    options = dict_new();
f338ef
-    if (!this || !options)
f338ef
-        goto out;
f338ef
-
f338ef
-    svc = cds_list_entry(conn, glusterd_svc_t, conn);
f338ef
-    if (!svc) {
f338ef
-        gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_SVC_GET_FAIL,
f338ef
-               "Failed to get the service");
f338ef
-        goto out;
f338ef
-    }
f338ef
-
f338ef
-    ret = rpc_transport_unix_options_build(options, sockpath, frame_timeout);
f338ef
-    if (ret)
f338ef
-        goto out;
f338ef
-
f338ef
-    ret = dict_set_int32n(options, "transport.socket.ignore-enoent",
f338ef
-                          SLEN("transport.socket.ignore-enoent"), 1);
f338ef
-    if (ret)
f338ef
-        goto out;
f338ef
-
f338ef
-    /* @options is free'd by rpc_transport when destroyed */
f338ef
-    rpc = rpc_clnt_new(options, this, (char *)svc->name, 16);
f338ef
-    if (!rpc) {
f338ef
-        ret = -1;
f338ef
-        goto out;
f338ef
-    }
f338ef
-
f338ef
-    ret = rpc_clnt_register_notify(rpc, glusterd_muxsvc_conn_common_notify,
f338ef
-                                   mux_proc);
f338ef
-    if (ret)
f338ef
-        goto out;
f338ef
-
f338ef
-    ret = snprintf(conn->sockpath, sizeof(conn->sockpath), "%s", sockpath);
f338ef
-    if (ret < 0)
f338ef
-        goto out;
f338ef
-    else
f338ef
-        ret = 0;
f338ef
-
f338ef
-    conn->frame_timeout = frame_timeout;
f338ef
-    conn->rpc = rpc;
f338ef
-    mux_proc->notify = notify;
f338ef
-out:
f338ef
-    if (options)
f338ef
-        dict_unref(options);
f338ef
-    if (ret) {
f338ef
-        if (rpc) {
f338ef
-            rpc_clnt_unref(rpc);
f338ef
-            rpc = NULL;
f338ef
-        }
f338ef
-    }
f338ef
-    return ret;
f338ef
-}
f338ef
diff --git a/xlators/mgmt/glusterd/src/glusterd-svc-mgmt.h b/xlators/mgmt/glusterd/src/glusterd-svc-mgmt.h
f338ef
index fbc5225..c850bfd 100644
f338ef
--- a/xlators/mgmt/glusterd/src/glusterd-svc-mgmt.h
f338ef
+++ b/xlators/mgmt/glusterd/src/glusterd-svc-mgmt.h
f338ef
@@ -13,12 +13,9 @@
f338ef
 
f338ef
 #include "glusterd-proc-mgmt.h"
f338ef
 #include "glusterd-conn-mgmt.h"
f338ef
-#include "glusterd-rcu.h"
f338ef
 
f338ef
 struct glusterd_svc_;
f338ef
-
f338ef
 typedef struct glusterd_svc_ glusterd_svc_t;
f338ef
-typedef struct glusterd_svc_proc_ glusterd_svc_proc_t;
f338ef
 
f338ef
 typedef void (*glusterd_svc_build_t)(glusterd_svc_t *svc);
f338ef
 
f338ef
@@ -28,17 +25,6 @@ typedef int (*glusterd_svc_start_t)(glusterd_svc_t *svc, int flags);
f338ef
 typedef int (*glusterd_svc_stop_t)(glusterd_svc_t *svc, int sig);
f338ef
 typedef int (*glusterd_svc_reconfigure_t)(void *data);
f338ef
 
f338ef
-typedef int (*glusterd_muxsvc_conn_notify_t)(glusterd_svc_proc_t *mux_proc,
f338ef
-                                             rpc_clnt_event_t event);
f338ef
-
f338ef
-struct glusterd_svc_proc_ {
f338ef
-    struct cds_list_head svc_proc_list;
f338ef
-    struct cds_list_head svcs;
f338ef
-    glusterd_muxsvc_conn_notify_t notify;
f338ef
-    rpc_clnt_t *rpc;
f338ef
-    void *data;
f338ef
-};
f338ef
-
f338ef
 struct glusterd_svc_ {
f338ef
     char name[NAME_MAX];
f338ef
     glusterd_conn_t conn;
f338ef
@@ -49,8 +35,6 @@ struct glusterd_svc_ {
f338ef
     gf_boolean_t online;
f338ef
     gf_boolean_t inited;
f338ef
     glusterd_svc_reconfigure_t reconfigure;
f338ef
-    glusterd_svc_proc_t *svc_proc;
f338ef
-    struct cds_list_head mux_svc;
f338ef
 };
f338ef
 
f338ef
 int
f338ef
@@ -85,15 +69,4 @@ glusterd_svc_reconfigure(int (*create_volfile)());
f338ef
 int
f338ef
 glusterd_svc_common_rpc_notify(glusterd_conn_t *conn, rpc_clnt_event_t event);
f338ef
 
f338ef
-int
f338ef
-glusterd_muxsvc_common_rpc_notify(glusterd_svc_proc_t *conn,
f338ef
-                                  rpc_clnt_event_t event);
f338ef
-
f338ef
-int
f338ef
-glusterd_proc_get_pid(glusterd_proc_t *proc);
f338ef
-
f338ef
-int
f338ef
-glusterd_muxsvc_conn_init(glusterd_conn_t *conn, glusterd_svc_proc_t *mux_proc,
f338ef
-                          char *sockpath, int frame_timeout,
f338ef
-                          glusterd_muxsvc_conn_notify_t notify);
f338ef
 #endif
f338ef
diff --git a/xlators/mgmt/glusterd/src/glusterd-tier.c b/xlators/mgmt/glusterd/src/glusterd-tier.c
f338ef
index 23a9592..4dc0d44 100644
f338ef
--- a/xlators/mgmt/glusterd/src/glusterd-tier.c
f338ef
+++ b/xlators/mgmt/glusterd/src/glusterd-tier.c
f338ef
@@ -27,7 +27,6 @@
f338ef
 #include "glusterd-messages.h"
f338ef
 #include "glusterd-mgmt.h"
f338ef
 #include "glusterd-syncop.h"
f338ef
-#include "glusterd-shd-svc-helper.h"
f338ef
 
f338ef
 #include <sys/wait.h>
f338ef
 #include <dlfcn.h>
f338ef
@@ -616,7 +615,7 @@ glusterd_op_remove_tier_brick(dict_t *dict, char **op_errstr, dict_t *rsp_dict)
f338ef
 
f338ef
     if (cmd == GF_DEFRAG_CMD_DETACH_START &&
f338ef
         volinfo->status == GLUSTERD_STATUS_STARTED) {
f338ef
-        ret = glusterd_svcs_reconfigure(volinfo);
f338ef
+        ret = glusterd_svcs_reconfigure();
f338ef
         if (ret) {
f338ef
             gf_msg(this->name, GF_LOG_WARNING, 0, GD_MSG_NFS_RECONF_FAIL,
f338ef
                    "Unable to reconfigure NFS-Server");
f338ef
diff --git a/xlators/mgmt/glusterd/src/glusterd-tierd-svc.c b/xlators/mgmt/glusterd/src/glusterd-tierd-svc.c
f338ef
index ab463f1..04ceec5 100644
f338ef
--- a/xlators/mgmt/glusterd/src/glusterd-tierd-svc.c
f338ef
+++ b/xlators/mgmt/glusterd/src/glusterd-tierd-svc.c
f338ef
@@ -83,6 +83,7 @@ glusterd_tierdsvc_init(void *data)
f338ef
         goto out;
f338ef
 
f338ef
     notify = glusterd_svc_common_rpc_notify;
f338ef
+    glusterd_store_perform_node_state_store(volinfo);
f338ef
 
f338ef
     volinfo->type = GF_CLUSTER_TYPE_TIER;
f338ef
 
f338ef
@@ -394,7 +395,6 @@ int
f338ef
 glusterd_tierdsvc_restart()
f338ef
 {
f338ef
     glusterd_volinfo_t *volinfo = NULL;
f338ef
-    glusterd_volinfo_t *tmp = NULL;
f338ef
     int ret = 0;
f338ef
     xlator_t *this = THIS;
f338ef
     glusterd_conf_t *conf = NULL;
f338ef
@@ -405,7 +405,7 @@ glusterd_tierdsvc_restart()
f338ef
     conf = this->private;
f338ef
     GF_VALIDATE_OR_GOTO(this->name, conf, out);
f338ef
 
f338ef
-    cds_list_for_each_entry_safe(volinfo, tmp, &conf->volumes, vol_list)
f338ef
+    cds_list_for_each_entry(volinfo, &conf->volumes, vol_list)
f338ef
     {
f338ef
         /* Start per volume tierd svc */
f338ef
         if (volinfo->status == GLUSTERD_STATUS_STARTED &&
f338ef
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
f338ef
index 4525ec7..2aa975b 100644
f338ef
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
f338ef
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
f338ef
@@ -61,7 +61,6 @@
f338ef
 #include "glusterd-server-quorum.h"
f338ef
 #include <glusterfs/quota-common-utils.h>
f338ef
 #include <glusterfs/common-utils.h>
f338ef
-#include "glusterd-shd-svc-helper.h"
f338ef
 
f338ef
 #include "xdr-generic.h"
f338ef
 #include <sys/resource.h>
f338ef
@@ -625,17 +624,13 @@ glusterd_volinfo_t *
f338ef
 glusterd_volinfo_unref(glusterd_volinfo_t *volinfo)
f338ef
 {
f338ef
     int refcnt = -1;
f338ef
-    glusterd_conf_t *conf = THIS->private;
f338ef
 
f338ef
-    pthread_mutex_lock(&conf->volume_lock);
f338ef
+    pthread_mutex_lock(&volinfo->reflock);
f338ef
     {
f338ef
-        pthread_mutex_lock(&volinfo->reflock);
f338ef
-        {
f338ef
-            refcnt = --volinfo->refcnt;
f338ef
-        }
f338ef
-        pthread_mutex_unlock(&volinfo->reflock);
f338ef
+        refcnt = --volinfo->refcnt;
f338ef
     }
f338ef
-    pthread_mutex_unlock(&conf->volume_lock);
f338ef
+    pthread_mutex_unlock(&volinfo->reflock);
f338ef
+
f338ef
     if (!refcnt) {
f338ef
         glusterd_volinfo_delete(volinfo);
f338ef
         return NULL;
f338ef
@@ -707,7 +702,6 @@ glusterd_volinfo_new(glusterd_volinfo_t **volinfo)
f338ef
     glusterd_snapdsvc_build(&new_volinfo->snapd.svc);
f338ef
     glusterd_tierdsvc_build(&new_volinfo->tierd.svc);
f338ef
     glusterd_gfproxydsvc_build(&new_volinfo->gfproxyd.svc);
f338ef
-    glusterd_shdsvc_build(&new_volinfo->shd.svc);
f338ef
 
f338ef
     pthread_mutex_init(&new_volinfo->reflock, NULL);
f338ef
     *volinfo = glusterd_volinfo_ref(new_volinfo);
f338ef
@@ -1073,11 +1067,11 @@ glusterd_volinfo_delete(glusterd_volinfo_t *volinfo)
f338ef
     gf_store_handle_destroy(volinfo->snapd.handle);
f338ef
 
f338ef
     glusterd_auth_cleanup(volinfo);
f338ef
-    glusterd_shd_svcproc_cleanup(&volinfo->shd);
f338ef
 
f338ef
     pthread_mutex_destroy(&volinfo->reflock);
f338ef
     GF_FREE(volinfo);
f338ef
     ret = 0;
f338ef
+
f338ef
 out:
f338ef
     gf_msg_debug(THIS->name, 0, "Returning %d", ret);
f338ef
     return ret;
f338ef
@@ -3929,7 +3923,6 @@ glusterd_spawn_daemons(void *opaque)
f338ef
     ret = glusterd_snapdsvc_restart();
f338ef
     ret = glusterd_tierdsvc_restart();
f338ef
     ret = glusterd_gfproxydsvc_restart();
f338ef
-    ret = glusterd_shdsvc_restart();
f338ef
     return ret;
f338ef
 }
f338ef
 
f338ef
@@ -4880,9 +4873,6 @@ glusterd_delete_stale_volume(glusterd_volinfo_t *stale_volinfo,
f338ef
         svc = &(stale_volinfo->snapd.svc);
f338ef
         (void)svc->manager(svc, stale_volinfo, PROC_START_NO_WAIT);
f338ef
     }
f338ef
-    svc = &(stale_volinfo->shd.svc);
f338ef
-    (void)svc->manager(svc, stale_volinfo, PROC_START_NO_WAIT);
f338ef
-
f338ef
     (void)glusterd_volinfo_remove(stale_volinfo);
f338ef
 
f338ef
     return 0;
f338ef
@@ -4997,15 +4987,6 @@ glusterd_import_friend_volume(dict_t *peer_data, int count)
f338ef
         glusterd_volinfo_unref(old_volinfo);
f338ef
     }
f338ef
 
f338ef
-    ret = glusterd_store_volinfo(new_volinfo, GLUSTERD_VOLINFO_VER_AC_NONE);
f338ef
-    if (ret) {
f338ef
-        gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_VOLINFO_STORE_FAIL,
f338ef
-               "Failed to store "
f338ef
-               "volinfo for volume %s",
f338ef
-               new_volinfo->volname);
f338ef
-        goto out;
f338ef
-    }
f338ef
-
f338ef
     if (glusterd_is_volume_started(new_volinfo)) {
f338ef
         (void)glusterd_start_bricks(new_volinfo);
f338ef
         if (glusterd_is_snapd_enabled(new_volinfo)) {
f338ef
@@ -5014,10 +4995,15 @@ glusterd_import_friend_volume(dict_t *peer_data, int count)
f338ef
                 gf_event(EVENT_SVC_MANAGER_FAILED, "svc_name=%s", svc->name);
f338ef
             }
f338ef
         }
f338ef
-        svc = &(new_volinfo->shd.svc);
f338ef
-        if (svc->manager(svc, new_volinfo, PROC_START_NO_WAIT)) {
f338ef
-            gf_event(EVENT_SVC_MANAGER_FAILED, "svc_name=%s", svc->name);
f338ef
-        }
f338ef
+    }
f338ef
+
f338ef
+    ret = glusterd_store_volinfo(new_volinfo, GLUSTERD_VOLINFO_VER_AC_NONE);
f338ef
+    if (ret) {
f338ef
+        gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_VOLINFO_STORE_FAIL,
f338ef
+               "Failed to store "
f338ef
+               "volinfo for volume %s",
f338ef
+               new_volinfo->volname);
f338ef
+        goto out;
f338ef
     }
f338ef
 
f338ef
     ret = glusterd_create_volfiles_and_notify_services(new_volinfo);
f338ef
@@ -5521,7 +5507,9 @@ glusterd_add_node_to_dict(char *server, dict_t *dict, int count,
f338ef
     glusterd_svc_build_pidfile_path(server, priv->rundir, pidfile,
f338ef
                                     sizeof(pidfile));
f338ef
 
f338ef
-    if (strcmp(server, priv->nfs_svc.name) == 0)
f338ef
+    if (strcmp(server, priv->shd_svc.name) == 0)
f338ef
+        svc = &(priv->shd_svc);
f338ef
+    else if (strcmp(server, priv->nfs_svc.name) == 0)
f338ef
         svc = &(priv->nfs_svc);
f338ef
     else if (strcmp(server, priv->quotad_svc.name) == 0)
f338ef
         svc = &(priv->quotad_svc);
f338ef
@@ -5552,6 +5540,9 @@ glusterd_add_node_to_dict(char *server, dict_t *dict, int count,
f338ef
     if (!strcmp(server, priv->nfs_svc.name))
f338ef
         ret = dict_set_nstrn(dict, key, keylen, "NFS Server",
f338ef
                              SLEN("NFS Server"));
f338ef
+    else if (!strcmp(server, priv->shd_svc.name))
f338ef
+        ret = dict_set_nstrn(dict, key, keylen, "Self-heal Daemon",
f338ef
+                             SLEN("Self-heal Daemon"));
f338ef
     else if (!strcmp(server, priv->quotad_svc.name))
f338ef
         ret = dict_set_nstrn(dict, key, keylen, "Quota Daemon",
f338ef
                              SLEN("Quota Daemon"));
f338ef
@@ -9115,21 +9106,6 @@ glusterd_friend_remove_cleanup_vols(uuid_t uuid)
f338ef
                            "to stop snapd daemon service");
f338ef
                 }
f338ef
             }
f338ef
-
f338ef
-            if (glusterd_is_shd_compatible_volume(volinfo)) {
f338ef
-                /*
f338ef
-                 * Sending stop request for all volumes. So it is fine
f338ef
-                 * to send stop for mux shd
f338ef
-                 */
f338ef
-                svc = &(volinfo->shd.svc);
f338ef
-                ret = svc->stop(svc, SIGTERM);
f338ef
-                if (ret) {
f338ef
-                    gf_msg(THIS->name, GF_LOG_ERROR, 0, GD_MSG_SVC_STOP_FAIL,
f338ef
-                           "Failed "
f338ef
-                           "to stop shd daemon service");
f338ef
-                }
f338ef
-            }
f338ef
-
f338ef
             if (volinfo->type == GF_CLUSTER_TYPE_TIER) {
f338ef
                 svc = &(volinfo->tierd.svc);
f338ef
                 ret = svc->stop(svc, SIGTERM);
f338ef
@@ -9155,7 +9131,7 @@ glusterd_friend_remove_cleanup_vols(uuid_t uuid)
f338ef
     }
f338ef
 
f338ef
     /* Reconfigure all daemon services upon peer detach */
f338ef
-    ret = glusterd_svcs_reconfigure(NULL);
f338ef
+    ret = glusterd_svcs_reconfigure();
f338ef
     if (ret) {
f338ef
         gf_msg(THIS->name, GF_LOG_ERROR, 0, GD_MSG_SVC_STOP_FAIL,
f338ef
                "Failed to reconfigure all daemon services.");
f338ef
@@ -14746,74 +14722,3 @@ glusterd_is_profile_on(glusterd_volinfo_t *volinfo)
f338ef
         return _gf_true;
f338ef
     return _gf_false;
f338ef
 }
f338ef
-
f338ef
-int32_t
f338ef
-glusterd_add_shd_to_dict(glusterd_volinfo_t *volinfo, dict_t *dict,
f338ef
-                         int32_t count)
f338ef
-{
f338ef
-    int ret = -1;
f338ef
-    int32_t pid = -1;
f338ef
-    int32_t brick_online = -1;
f338ef
-    char key[64] = {0};
f338ef
-    int keylen;
f338ef
-    char *pidfile = NULL;
f338ef
-    xlator_t *this = NULL;
f338ef
-    char *uuid_str = NULL;
f338ef
-
f338ef
-    this = THIS;
f338ef
-    GF_VALIDATE_OR_GOTO(THIS->name, this, out);
f338ef
-
f338ef
-    GF_VALIDATE_OR_GOTO(this->name, volinfo, out);
f338ef
-    GF_VALIDATE_OR_GOTO(this->name, dict, out);
f338ef
-
f338ef
-    keylen = snprintf(key, sizeof(key), "brick%d.hostname", count);
f338ef
-    ret = dict_set_nstrn(dict, key, keylen, "Self-heal Daemon",
f338ef
-                         SLEN("Self-heal Daemon"));
f338ef
-    if (ret)
f338ef
-        goto out;
f338ef
-
f338ef
-    keylen = snprintf(key, sizeof(key), "brick%d.path", count);
f338ef
-    uuid_str = gf_strdup(uuid_utoa(MY_UUID));
f338ef
-    if (!uuid_str) {
f338ef
-        ret = -1;
f338ef
-        goto out;
f338ef
-    }
f338ef
-    ret = dict_set_dynstrn(dict, key, keylen, uuid_str);
f338ef
-    if (ret)
f338ef
-        goto out;
f338ef
-    uuid_str = NULL;
f338ef
-
f338ef
-    /* shd doesn't have a port. but the cli needs a port key with
f338ef
-     * a zero value to parse.
f338ef
-     * */
f338ef
-
f338ef
-    keylen = snprintf(key, sizeof(key), "brick%d.port", count);
f338ef
-    ret = dict_set_int32n(dict, key, keylen, 0);
f338ef
-    if (ret)
f338ef
-        goto out;
f338ef
-
f338ef
-    pidfile = volinfo->shd.svc.proc.pidfile;
f338ef
-
f338ef
-    brick_online = gf_is_service_running(pidfile, &pid;;
f338ef
-
f338ef
-    /* If shd is not running, then don't print the pid */
f338ef
-    if (!brick_online)
f338ef
-        pid = -1;
f338ef
-    keylen = snprintf(key, sizeof(key), "brick%d.pid", count);
f338ef
-    ret = dict_set_int32n(dict, key, keylen, pid);
f338ef
-    if (ret)
f338ef
-        goto out;
f338ef
-
f338ef
-    keylen = snprintf(key, sizeof(key), "brick%d.status", count);
f338ef
-    ret = dict_set_int32n(dict, key, keylen, brick_online);
f338ef
-
f338ef
-out:
f338ef
-    if (uuid_str)
f338ef
-        GF_FREE(uuid_str);
f338ef
-    if (ret)
f338ef
-        gf_msg(this ? this->name : "glusterd", GF_LOG_ERROR, 0,
f338ef
-               GD_MSG_DICT_SET_FAILED,
f338ef
-               "Returning %d. adding values to dict failed", ret);
f338ef
-
f338ef
-    return ret;
f338ef
-}
f338ef
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.h b/xlators/mgmt/glusterd/src/glusterd-utils.h
f338ef
index 5c6a453..ead16b2 100644
f338ef
--- a/xlators/mgmt/glusterd/src/glusterd-utils.h
f338ef
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.h
f338ef
@@ -881,8 +881,4 @@ glusterd_is_profile_on(glusterd_volinfo_t *volinfo);
f338ef
 
f338ef
 char *
f338ef
 search_brick_path_from_proc(pid_t brick_pid, char *brickpath);
f338ef
-
f338ef
-int32_t
f338ef
-glusterd_add_shd_to_dict(glusterd_volinfo_t *volinfo, dict_t *dict,
f338ef
-                         int32_t count);
f338ef
 #endif
f338ef
diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c
f338ef
index 8b58d40..5e0214e 100644
f338ef
--- a/xlators/mgmt/glusterd/src/glusterd-volgen.c
f338ef
+++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c
f338ef
@@ -36,7 +36,6 @@
f338ef
 #include "glusterd-svc-mgmt.h"
f338ef
 #include "glusterd-svc-helper.h"
f338ef
 #include "glusterd-snapd-svc-helper.h"
f338ef
-#include "glusterd-shd-svc-helper.h"
f338ef
 #include "glusterd-gfproxyd-svc-helper.h"
f338ef
 
f338ef
 struct gd_validate_reconf_opts {
f338ef
@@ -4865,7 +4864,7 @@ volgen_get_shd_key(int type)
f338ef
 static int
f338ef
 volgen_set_shd_key_enable(dict_t *set_dict, const int type)
f338ef
 {
f338ef
-    int ret = 0;
f338ef
+    int ret = -1;
f338ef
 
f338ef
     switch (type) {
f338ef
         case GF_CLUSTER_TYPE_REPLICATE:
f338ef
@@ -5156,15 +5155,24 @@ out:
f338ef
 static int
f338ef
 build_shd_volume_graph(xlator_t *this, volgen_graph_t *graph,
f338ef
                        glusterd_volinfo_t *volinfo, dict_t *mod_dict,
f338ef
-                       dict_t *set_dict, gf_boolean_t graph_check)
f338ef
+                       dict_t *set_dict, gf_boolean_t graph_check,
f338ef
+                       gf_boolean_t *valid_config)
f338ef
 {
f338ef
     volgen_graph_t cgraph = {0};
f338ef
     int ret = 0;
f338ef
     int clusters = -1;
f338ef
 
f338ef
+    if (!graph_check && (volinfo->status != GLUSTERD_STATUS_STARTED))
f338ef
+        goto out;
f338ef
+
f338ef
     if (!glusterd_is_shd_compatible_volume(volinfo))
f338ef
         goto out;
f338ef
 
f338ef
+    /* Shd graph is valid only when there is at least one
f338ef
+     * replica/disperse volume is present
f338ef
+     */
f338ef
+    *valid_config = _gf_true;
f338ef
+
f338ef
     ret = prepare_shd_volume_options(volinfo, mod_dict, set_dict);
f338ef
     if (ret)
f338ef
         goto out;
f338ef
@@ -5194,16 +5202,19 @@ out:
f338ef
 }
f338ef
 
f338ef
 int
f338ef
-build_shd_graph(glusterd_volinfo_t *volinfo, volgen_graph_t *graph,
f338ef
-                dict_t *mod_dict)
f338ef
+build_shd_graph(volgen_graph_t *graph, dict_t *mod_dict)
f338ef
 {
f338ef
+    glusterd_volinfo_t *voliter = NULL;
f338ef
     xlator_t *this = NULL;
f338ef
+    glusterd_conf_t *priv = NULL;
f338ef
     dict_t *set_dict = NULL;
f338ef
     int ret = 0;
f338ef
+    gf_boolean_t valid_config = _gf_false;
f338ef
     xlator_t *iostxl = NULL;
f338ef
     gf_boolean_t graph_check = _gf_false;
f338ef
 
f338ef
     this = THIS;
f338ef
+    priv = this->private;
f338ef
 
f338ef
     set_dict = dict_new();
f338ef
     if (!set_dict) {
f338ef
@@ -5213,18 +5224,26 @@ build_shd_graph(glusterd_volinfo_t *volinfo, volgen_graph_t *graph,
f338ef
 
f338ef
     if (mod_dict)
f338ef
         graph_check = dict_get_str_boolean(mod_dict, "graph-check", 0);
f338ef
-    iostxl = volgen_graph_add_as(graph, "debug/io-stats", volinfo->volname);
f338ef
+    iostxl = volgen_graph_add_as(graph, "debug/io-stats", "glustershd");
f338ef
     if (!iostxl) {
f338ef
         ret = -1;
f338ef
         goto out;
f338ef
     }
f338ef
 
f338ef
-    ret = build_shd_volume_graph(this, graph, volinfo, mod_dict, set_dict,
f338ef
-                                 graph_check);
f338ef
+    cds_list_for_each_entry(voliter, &priv->volumes, vol_list)
f338ef
+    {
f338ef
+        ret = build_shd_volume_graph(this, graph, voliter, mod_dict, set_dict,
f338ef
+                                     graph_check, &valid_config);
f338ef
+        ret = dict_reset(set_dict);
f338ef
+        if (ret)
f338ef
+            goto out;
f338ef
+    }
f338ef
 
f338ef
 out:
f338ef
     if (set_dict)
f338ef
         dict_unref(set_dict);
f338ef
+    if (!valid_config)
f338ef
+        ret = -EINVAL;
f338ef
     return ret;
f338ef
 }
f338ef
 
f338ef
@@ -6541,10 +6560,6 @@ glusterd_create_volfiles(glusterd_volinfo_t *volinfo)
f338ef
     if (ret)
f338ef
         gf_log(this->name, GF_LOG_ERROR, "Could not generate gfproxy volfiles");
f338ef
 
f338ef
-    ret = glusterd_shdsvc_create_volfile(volinfo);
f338ef
-    if (ret)
f338ef
-        gf_log(this->name, GF_LOG_ERROR, "Could not generate shd volfiles");
f338ef
-
f338ef
     dict_del_sizen(volinfo->dict, "skip-CLIOT");
f338ef
 
f338ef
 out:
f338ef
@@ -6625,7 +6640,7 @@ validate_shdopts(glusterd_volinfo_t *volinfo, dict_t *val_dict,
f338ef
     ret = dict_set_int32_sizen(val_dict, "graph-check", 1);
f338ef
     if (ret)
f338ef
         goto out;
f338ef
-    ret = build_shd_graph(volinfo, &graph, val_dict);
f338ef
+    ret = build_shd_graph(&graph, val_dict);
f338ef
     if (!ret)
f338ef
         ret = graph_reconf_validateopt(&graph.graph, op_errstr);
f338ef
 
f338ef
@@ -7002,22 +7017,3 @@ gd_is_boolean_option(char *key)
f338ef
 
f338ef
     return _gf_false;
f338ef
 }
f338ef
-
f338ef
-int
f338ef
-glusterd_shdsvc_generate_volfile(glusterd_volinfo_t *volinfo, char *filename,
f338ef
-                                 dict_t *mode_dict)
f338ef
-{
f338ef
-    int ret = -1;
f338ef
-    volgen_graph_t graph = {
f338ef
-        0,
f338ef
-    };
f338ef
-
f338ef
-    graph.type = GF_SHD;
f338ef
-    ret = build_shd_graph(volinfo, &graph, mode_dict);
f338ef
-    if (!ret)
f338ef
-        ret = volgen_write_volfile(&graph, filename);
f338ef
-
f338ef
-    volgen_graph_free(&graph);
f338ef
-
f338ef
-    return ret;
f338ef
-}
f338ef
diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.h b/xlators/mgmt/glusterd/src/glusterd-volgen.h
f338ef
index 897d8fa..f9fc068 100644
f338ef
--- a/xlators/mgmt/glusterd/src/glusterd-volgen.h
f338ef
+++ b/xlators/mgmt/glusterd/src/glusterd-volgen.h
f338ef
@@ -66,7 +66,6 @@ typedef enum {
f338ef
     GF_REBALANCED = 1,
f338ef
     GF_QUOTAD,
f338ef
     GF_SNAPD,
f338ef
-    GF_SHD,
f338ef
 } glusterd_graph_type_t;
f338ef
 
f338ef
 struct volgen_graph {
f338ef
@@ -78,8 +77,6 @@ typedef struct volgen_graph volgen_graph_t;
f338ef
 
f338ef
 typedef int (*glusterd_graph_builder_t)(volgen_graph_t *graph,
f338ef
                                         dict_t *mod_dict);
f338ef
-typedef int (*glusterd_vol_graph_builder_t)(glusterd_volinfo_t *,
f338ef
-                                            char *filename, dict_t *mod_dict);
f338ef
 
f338ef
 #define COMPLETE_OPTION(key, completion, ret)                                  \
f338ef
     do {                                                                       \
f338ef
@@ -204,8 +201,7 @@ void
f338ef
 glusterd_get_shd_filepath(char *filename);
f338ef
 
f338ef
 int
f338ef
-build_shd_graph(glusterd_volinfo_t *volinfo, volgen_graph_t *graph,
f338ef
-                dict_t *mod_dict);
f338ef
+build_shd_graph(volgen_graph_t *graph, dict_t *mod_dict);
f338ef
 
f338ef
 int
f338ef
 build_nfs_graph(volgen_graph_t *graph, dict_t *mod_dict);
f338ef
@@ -317,9 +313,4 @@ glusterd_generate_gfproxyd_volfile(glusterd_volinfo_t *volinfo);
f338ef
 
f338ef
 int
f338ef
 glusterd_build_gfproxyd_volfile(glusterd_volinfo_t *volinfo, char *filename);
f338ef
-
f338ef
-int
f338ef
-glusterd_shdsvc_generate_volfile(glusterd_volinfo_t *volinfo, char *filename,
f338ef
-                                 dict_t *mode_dict);
f338ef
-
f338ef
 #endif
f338ef
diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-ops.c b/xlators/mgmt/glusterd/src/glusterd-volume-ops.c
f338ef
index 4c3ad50..1ea8ba6 100644
f338ef
--- a/xlators/mgmt/glusterd/src/glusterd-volume-ops.c
f338ef
+++ b/xlators/mgmt/glusterd/src/glusterd-volume-ops.c
f338ef
@@ -1940,7 +1940,7 @@ static int
f338ef
 glusterd_handle_heal_cmd(xlator_t *this, glusterd_volinfo_t *volinfo,
f338ef
                          dict_t *dict, char **op_errstr)
f338ef
 {
f338ef
-    glusterd_svc_t *svc = NULL;
f338ef
+    glusterd_conf_t *priv = NULL;
f338ef
     gf_xl_afr_op_t heal_op = GF_SHD_OP_INVALID;
f338ef
     int ret = 0;
f338ef
     char msg[2408] = {
f338ef
@@ -1950,6 +1950,7 @@ glusterd_handle_heal_cmd(xlator_t *this, glusterd_volinfo_t *volinfo,
f338ef
         "Self-heal daemon is not running. "
f338ef
         "Check self-heal daemon log file.";
f338ef
 
f338ef
+    priv = this->private;
f338ef
     ret = dict_get_int32n(dict, "heal-op", SLEN("heal-op"),
f338ef
                           (int32_t *)&heal_op);
f338ef
     if (ret) {
f338ef
@@ -1958,7 +1959,6 @@ glusterd_handle_heal_cmd(xlator_t *this, glusterd_volinfo_t *volinfo,
f338ef
         goto out;
f338ef
     }
f338ef
 
f338ef
-    svc = &(volinfo->shd.svc);
f338ef
     switch (heal_op) {
f338ef
         case GF_SHD_OP_INVALID:
f338ef
         case GF_SHD_OP_HEAL_ENABLE: /* This op should be handled in volume-set*/
f338ef
@@ -1988,7 +1988,7 @@ glusterd_handle_heal_cmd(xlator_t *this, glusterd_volinfo_t *volinfo,
f338ef
                 goto out;
f338ef
             }
f338ef
 
f338ef
-            if (!svc->online) {
f338ef
+            if (!priv->shd_svc.online) {
f338ef
                 ret = -1;
f338ef
                 *op_errstr = gf_strdup(offline_msg);
f338ef
                 goto out;
f338ef
@@ -2009,7 +2009,7 @@ glusterd_handle_heal_cmd(xlator_t *this, glusterd_volinfo_t *volinfo,
f338ef
                 goto out;
f338ef
             }
f338ef
 
f338ef
-            if (!svc->online) {
f338ef
+            if (!priv->shd_svc.online) {
f338ef
                 ret = -1;
f338ef
                 *op_errstr = gf_strdup(offline_msg);
f338ef
                 goto out;
f338ef
diff --git a/xlators/mgmt/glusterd/src/glusterd.c b/xlators/mgmt/glusterd/src/glusterd.c
f338ef
index c0973cb..d360312 100644
f338ef
--- a/xlators/mgmt/glusterd/src/glusterd.c
f338ef
+++ b/xlators/mgmt/glusterd/src/glusterd.c
f338ef
@@ -1537,6 +1537,14 @@ init(xlator_t *this)
f338ef
         exit(1);
f338ef
     }
f338ef
 
f338ef
+    ret = glusterd_init_var_run_dirs(this, rundir, GLUSTERD_GLUSTERSHD_RUN_DIR);
f338ef
+    if (ret) {
f338ef
+        gf_msg(this->name, GF_LOG_CRITICAL, 0, GD_MSG_CREATE_DIR_FAILED,
f338ef
+               "Unable to create "
f338ef
+               "glustershd running directory");
f338ef
+        exit(1);
f338ef
+    }
f338ef
+
f338ef
     ret = glusterd_init_var_run_dirs(this, rundir, GLUSTERD_NFS_RUN_DIR);
f338ef
     if (ret) {
f338ef
         gf_msg(this->name, GF_LOG_CRITICAL, 0, GD_MSG_CREATE_DIR_FAILED,
f338ef
@@ -1811,9 +1819,6 @@ init(xlator_t *this)
f338ef
     CDS_INIT_LIST_HEAD(&conf->snapshots);
f338ef
     CDS_INIT_LIST_HEAD(&conf->missed_snaps_list);
f338ef
     CDS_INIT_LIST_HEAD(&conf->brick_procs);
f338ef
-    CDS_INIT_LIST_HEAD(&conf->shd_procs);
f338ef
-    pthread_mutex_init(&conf->attach_lock, NULL);
f338ef
-    pthread_mutex_init(&conf->volume_lock, NULL);
f338ef
 
f338ef
     pthread_mutex_init(&conf->mutex, NULL);
f338ef
     conf->rpc = rpc;
f338ef
@@ -1894,6 +1899,7 @@ init(xlator_t *this)
f338ef
     glusterd_mgmt_v3_lock_timer_init();
f338ef
     glusterd_txn_opinfo_dict_init();
f338ef
 
f338ef
+    glusterd_shdsvc_build(&conf->shd_svc);
f338ef
     glusterd_nfssvc_build(&conf->nfs_svc);
f338ef
     glusterd_quotadsvc_build(&conf->quotad_svc);
f338ef
     glusterd_bitdsvc_build(&conf->bitd_svc);
f338ef
diff --git a/xlators/mgmt/glusterd/src/glusterd.h b/xlators/mgmt/glusterd/src/glusterd.h
f338ef
index 0fbc9dd..2be005c 100644
f338ef
--- a/xlators/mgmt/glusterd/src/glusterd.h
f338ef
+++ b/xlators/mgmt/glusterd/src/glusterd.h
f338ef
@@ -28,7 +28,6 @@
f338ef
 #include "glusterd-sm.h"
f338ef
 #include "glusterd-snapd-svc.h"
f338ef
 #include "glusterd-tierd-svc.h"
f338ef
-#include "glusterd-shd-svc.h"
f338ef
 #include "glusterd-bitd-svc.h"
f338ef
 #include "glusterd1-xdr.h"
f338ef
 #include "protocol-common.h"
f338ef
@@ -173,6 +172,7 @@ typedef struct {
f338ef
     char workdir[VALID_GLUSTERD_PATHMAX];
f338ef
     char rundir[VALID_GLUSTERD_PATHMAX];
f338ef
     rpcsvc_t *rpc;
f338ef
+    glusterd_svc_t shd_svc;
f338ef
     glusterd_svc_t nfs_svc;
f338ef
     glusterd_svc_t bitd_svc;
f338ef
     glusterd_svc_t scrub_svc;
f338ef
@@ -181,7 +181,6 @@ typedef struct {
f338ef
     struct cds_list_head volumes;
f338ef
     struct cds_list_head snapshots;   /*List of snap volumes */
f338ef
     struct cds_list_head brick_procs; /* List of brick processes */
f338ef
-    struct cds_list_head shd_procs;   /* List of shd processes */
f338ef
     pthread_mutex_t xprt_lock;
f338ef
     struct list_head xprt_list;
f338ef
     pthread_mutex_t import_volumes;
f338ef
@@ -222,11 +221,6 @@ typedef struct {
f338ef
     gf_atomic_t blockers;
f338ef
     uint32_t mgmt_v3_lock_timeout;
f338ef
     gf_boolean_t restart_bricks;
f338ef
-    pthread_mutex_t attach_lock; /* Lock can be per process or a common one */
f338ef
-    pthread_mutex_t volume_lock; /* We release the big_lock from lot of places
f338ef
-                                    which might lead the modification of volinfo
f338ef
-                                    list.
f338ef
-                                 */
f338ef
     gf_atomic_t thread_count;
f338ef
 } glusterd_conf_t;
f338ef
 
f338ef
@@ -519,7 +513,6 @@ struct glusterd_volinfo_ {
f338ef
 
f338ef
     glusterd_snapdsvc_t snapd;
f338ef
     glusterd_tierdsvc_t tierd;
f338ef
-    glusterd_shdsvc_t shd;
f338ef
     glusterd_gfproxydsvc_t gfproxyd;
f338ef
     int32_t quota_xattr_version;
f338ef
     gf_boolean_t stage_deleted;         /* volume has passed staging
f338ef
@@ -646,6 +639,7 @@ typedef enum {
f338ef
 #define GLUSTERD_DEFAULT_SNAPS_BRICK_DIR "/gluster/snaps"
f338ef
 #define GLUSTERD_BITD_RUN_DIR "/bitd"
f338ef
 #define GLUSTERD_SCRUB_RUN_DIR "/scrub"
f338ef
+#define GLUSTERD_GLUSTERSHD_RUN_DIR "/glustershd"
f338ef
 #define GLUSTERD_NFS_RUN_DIR "/nfs"
f338ef
 #define GLUSTERD_QUOTAD_RUN_DIR "/quotad"
f338ef
 #define GLUSTER_SHARED_STORAGE_BRICK_DIR GLUSTERD_DEFAULT_WORKDIR "/ss_brick"
f338ef
@@ -701,26 +695,6 @@ typedef ssize_t (*gd_serialize_t)(struct iovec outmsg, void *args);
f338ef
         }                                                                      \
f338ef
     } while (0)
f338ef
 
f338ef
-#define GLUSTERD_GET_SHD_RUNDIR(path, volinfo, priv)                           \
f338ef
-    do {                                                                       \
f338ef
-        int32_t _shd_dir_len;                                                  \
f338ef
-        _shd_dir_len = snprintf(path, PATH_MAX, "%s/shd/%s", priv->rundir,     \
f338ef
-                                volinfo->volname);                             \
f338ef
-        if ((_shd_dir_len < 0) || (_shd_dir_len >= PATH_MAX)) {                \
f338ef
-            path[0] = 0;                                                       \
f338ef
-        }                                                                      \
f338ef
-    } while (0)
f338ef
-
f338ef
-#define GLUSTERD_GET_SHD_PID_FILE(path, volinfo, priv)                         \
f338ef
-    do {                                                                       \
f338ef
-        int32_t _shd_pid_len;                                                  \
f338ef
-        _shd_pid_len = snprintf(path, PATH_MAX, "%s/shd/%s-shd.pid",           \
f338ef
-                                priv->rundir, volinfo->volname);               \
f338ef
-        if ((_shd_pid_len < 0) || (_shd_pid_len >= PATH_MAX)) {                \
f338ef
-            path[0] = 0;                                                       \
f338ef
-        }                                                                      \
f338ef
-    } while (0)
f338ef
-
f338ef
 #define GLUSTERD_GET_VOLUME_PID_DIR(path, volinfo, priv)                       \
f338ef
     do {                                                                       \
f338ef
         int32_t _vol_pid_len;                                                  \
f338ef
diff --git a/xlators/protocol/client/src/client.c b/xlators/protocol/client/src/client.c
f338ef
index 532ef35..e156d4d 100644
f338ef
--- a/xlators/protocol/client/src/client.c
f338ef
+++ b/xlators/protocol/client/src/client.c
f338ef
@@ -46,6 +46,7 @@ client_fini_complete(xlator_t *this)
f338ef
     GF_VALIDATE_OR_GOTO(this->name, this->private, out);
f338ef
 
f338ef
     clnt_conf_t *conf = this->private;
f338ef
+
f338ef
     if (!conf->destroy)
f338ef
         return 0;
f338ef
 
f338ef
@@ -68,11 +69,6 @@ client_notify_dispatch_uniq(xlator_t *this, int32_t event, void *data, ...)
f338ef
         return 0;
f338ef
 
f338ef
     return client_notify_dispatch(this, event, data);
f338ef
-
f338ef
-    /* Please avoid any code that access xlator object here
f338ef
-     * Because for a child down event, once we do the signal
f338ef
-     * we will start cleanup.
f338ef
-     */
f338ef
 }
f338ef
 
f338ef
 int
f338ef
@@ -109,11 +105,6 @@ client_notify_dispatch(xlator_t *this, int32_t event, void *data, ...)
f338ef
     }
f338ef
     pthread_mutex_unlock(&ctx->notify_lock);
f338ef
 
f338ef
-    /* Please avoid any code that access xlator object here
f338ef
-     * Because for a child down event, once we do the signal
f338ef
-     * we will start cleanup.
f338ef
-     */
f338ef
-
f338ef
     return ret;
f338ef
 }
f338ef
 
f338ef
@@ -2287,7 +2278,6 @@ client_rpc_notify(struct rpc_clnt *rpc, void *mydata, rpc_clnt_event_t event,
f338ef
 {
f338ef
     xlator_t *this = NULL;
f338ef
     clnt_conf_t *conf = NULL;
f338ef
-    gf_boolean_t is_parent_down = _gf_false;
f338ef
     int ret = 0;
f338ef
 
f338ef
     this = mydata;
f338ef
@@ -2351,19 +2341,6 @@ client_rpc_notify(struct rpc_clnt *rpc, void *mydata, rpc_clnt_event_t event,
f338ef
                     if (conf->portmap_err_logged)
f338ef
                         conf->disconnect_err_logged = 1;
f338ef
                 }
f338ef
-                /*
f338ef
-                 * Once we complete the child down notification,
f338ef
-                 * There is a chance that the graph might get freed,
f338ef
-                 * So it is not safe to access any xlator contens
f338ef
-                 * So here we are checking whether the parent is down
f338ef
-                 * or not.
f338ef
-                 */
f338ef
-                pthread_mutex_lock(&conf->lock);
f338ef
-                {
f338ef
-                    is_parent_down = conf->parent_down;
f338ef
-                }
f338ef
-                pthread_mutex_unlock(&conf->lock);
f338ef
-
f338ef
                 /* If the CHILD_DOWN event goes to parent xlator
f338ef
                    multiple times, the logic of parent xlator notify
f338ef
                    may get screwed up.. (eg. CHILD_MODIFIED event in
f338ef
@@ -2371,12 +2348,6 @@ client_rpc_notify(struct rpc_clnt *rpc, void *mydata, rpc_clnt_event_t event,
f338ef
                    to parent are genuine */
f338ef
                 ret = client_notify_dispatch_uniq(this, GF_EVENT_CHILD_DOWN,
f338ef
                                                   NULL);
f338ef
-                if (is_parent_down) {
f338ef
-                    /* If parent is down, then there should not be any
f338ef
-                     * operation after a child down.
f338ef
-                     */
f338ef
-                    goto out;
f338ef
-                }
f338ef
                 if (ret)
f338ef
                     gf_msg(this->name, GF_LOG_INFO, 0,
f338ef
                            PC_MSG_CHILD_DOWN_NOTIFY_FAILED,
f338ef
-- 
f338ef
1.8.3.1
f338ef