3604df
From 989ec0fb1bff496d35079cc97ad87cbc3495e79b Mon Sep 17 00:00:00 2001
3604df
From: Avra Sengupta <asengupt@redhat.com>
3604df
Date: Tue, 25 Oct 2016 12:44:29 +0530
3604df
Subject: [PATCH 149/157] glusterd/shared storage: Check for hook-script at staging
3604df
3604df
Check if S32gluster_enable_shared_storage.sh is present
3604df
at /var/lib/glusterd/hooks/1/set/post/ at staging
3604df
before proceeding with the command. Fail the command
3604df
with the appropriate error message in case it is not
3604df
present.
3604df
3604df
> Reviewed-on: http://review.gluster.org/15718
3604df
> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
3604df
> Smoke: Gluster Build System <jenkins@build.gluster.org>
3604df
> CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
3604df
> Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
3604df
3604df
(cherry picked from commit 29587a91716e1e55bd172d63340c40249fb343c9)
3604df
3604df
Change-Id: I84e3912f1cdffb927f8a40d74d52be43ee69388b
3604df
BUG: 1389168
3604df
Signed-off-by: Avra Sengupta <asengupt@redhat.com>
3604df
Reviewed-on: http://review.gluster.org/15741
3604df
Smoke: Gluster Build System <jenkins@build.gluster.org>
3604df
NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
3604df
CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
3604df
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
3604df
Reviewed-on: https://code.engineering.redhat.com/gerrit/89246
3604df
---
3604df
 xlators/mgmt/glusterd/src/glusterd-op-sm.c |   29 ++++++++++++++++++++++-----
3604df
 xlators/mgmt/glusterd/src/glusterd.h       |    2 +
3604df
 2 files changed, 25 insertions(+), 6 deletions(-)
3604df
3604df
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
3604df
index 2b6814b..0528fbd 100644
3604df
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c
3604df
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
3604df
@@ -773,12 +773,14 @@ out:
3604df
 static int
3604df
 glusterd_validate_shared_storage (char *key, char *value, char *errstr)
3604df
 {
3604df
-        int32_t            ret      = -1;
3604df
-        int32_t            exists   = -1;
3604df
-        int32_t            count    = -1;
3604df
-        char              *op       = NULL;
3604df
-        xlator_t          *this     = NULL;
3604df
-        glusterd_conf_t   *conf     = NULL;
3604df
+        int32_t            ret                      = -1;
3604df
+        int32_t            exists                   = -1;
3604df
+        int32_t            count                    = -1;
3604df
+        char              *op                       = NULL;
3604df
+        char               hook_script[PATH_MAX]    = "";
3604df
+        xlator_t          *this                     = NULL;
3604df
+        glusterd_conf_t   *conf                     = NULL;
3604df
+        struct stat        stbuf                    = {0,};
3604df
 
3604df
         this = THIS;
3604df
         GF_VALIDATE_OR_GOTO ("glusterd", this, out);
3604df
@@ -807,6 +809,21 @@ glusterd_validate_shared_storage (char *key, char *value, char *errstr)
3604df
                 goto out;
3604df
         }
3604df
 
3604df
+        snprintf (hook_script, sizeof(hook_script),
3604df
+                  "%s"GLUSTERD_SHRD_STRG_HOOK_SCRIPT, conf->workdir);
3604df
+
3604df
+        ret = sys_lstat (hook_script, &stbuf);
3604df
+        if (ret) {
3604df
+                snprintf (errstr, PATH_MAX,
3604df
+                          "The hook-script (%s) required "
3604df
+                          "for this operation is not present. "
3604df
+                          "Please install the hook-script "
3604df
+                          "and retry", hook_script);
3604df
+                gf_msg (this->name, GF_LOG_ERROR, ENOENT,
3604df
+                        GD_MSG_FILE_OP_FAILED, "%s", errstr);
3604df
+                goto out;
3604df
+        }
3604df
+
3604df
         if (!strncmp (value, "disable", strlen ("disable"))) {
3604df
                 ret = dict_get_str (conf->opts, GLUSTERD_SHARED_STORAGE_KEY,
3604df
                                                                            &op);
3604df
diff --git a/xlators/mgmt/glusterd/src/glusterd.h b/xlators/mgmt/glusterd/src/glusterd.h
3604df
index d981fa5..8695ab9 100644
3604df
--- a/xlators/mgmt/glusterd/src/glusterd.h
3604df
+++ b/xlators/mgmt/glusterd/src/glusterd.h
3604df
@@ -47,6 +47,8 @@
3604df
 #define GEO_CONF_MAX_OPT_VALS           6
3604df
 #define GLUSTERD_CREATE_HOOK_SCRIPT     "/hooks/1/gsync-create/post/" \
3604df
                                         "S56glusterd-geo-rep-create-post.sh"
3604df
+#define GLUSTERD_SHRD_STRG_HOOK_SCRIPT  "/hooks/1/set/post/" \
3604df
+                                        "S32gluster_enable_shared_storage.sh"
3604df
 #define GLUSTER_SHARED_STORAGE          "gluster_shared_storage"
3604df
 #define GLUSTERD_SHARED_STORAGE_KEY     "cluster.enable-shared-storage"
3604df
 
3604df
-- 
3604df
1.7.1
3604df