summaryrefslogtreecommitdiffstats
path: root/xlators
diff options
context:
space:
mode:
authorKrishnan Parthasarathi <kp@gluster.com>2012-05-02 18:38:52 +0530
committerVijay Bellur <vijay@gluster.com>2012-05-03 21:26:07 -0700
commit5f48ad266195ec85171db48cf3dba83f98cbe728 (patch)
treef8a021a1e047272f2f3f546ea6c825771bbce2d5 /xlators
parentd88237faa6982c9f0beca65262a220becaacb096 (diff)
glusterd: Added glusterd command specific optional args for hooks scripts.
start volume: --first=yes if the volume is the first to be started and --first=no otherwise stop volume: --last=yes if the volume is the last to be stopped and --last=no otherwise set volume: -o key=value ... for every key, value supplied in volume set command Change-Id: Ia8530771f8b9d7424fd1c736cb4c3622b5cabec2 BUG: 806996 Signed-off-by: Krishnan Parthasarathi <kp@gluster.com> Reviewed-on: http://review.gluster.com/3260 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Jeff Darcy <jdarcy@redhat.com> Reviewed-by: Vijay Bellur <vijay@gluster.com>
Diffstat (limited to 'xlators')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-hooks.c114
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-hooks.h3
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-op-sm.c2
3 files changed, 116 insertions, 3 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-hooks.c b/xlators/mgmt/glusterd/src/glusterd-hooks.c
index ba73364bd..2afdb1625 100644
--- a/xlators/mgmt/glusterd/src/glusterd-hooks.c
+++ b/xlators/mgmt/glusterd/src/glusterd-hooks.c
@@ -37,6 +37,8 @@
#include "glusterd-store.h"
#include "glusterd-hooks.h"
+#include <fnmatch.h>
+
extern int mkdir_if_missing (char *dir);
#define EMPTY ""
@@ -151,7 +153,110 @@ glusterd_hooks_get_hooks_cmd_subdir (glusterd_op_t op)
}
int
-glusterd_hooks_run_hooks (char *hooks_path, dict_t *op_ctx)
+glusterd_hooks_set_volume_args (dict_t *dict, runner_t *runner)
+{
+ int i = 0;
+ int count = 0;
+ int ret = -1;
+ char query[1024] = {0,};
+ char *key = NULL;
+ char *value = NULL;
+
+ ret = dict_get_int32 (dict, "count", &count);
+ if (ret)
+ goto out;
+
+ /* This will not happen unless op_ctx
+ * is corrupted*/
+ if (!count)
+ goto out;
+
+ runner_add_arg (runner, "-o");
+ for (i = 1; (ret == 0); i++) {
+ snprintf (query, sizeof (query), "key%d", i);
+ ret = dict_get_str (dict, query, &key);
+ if (ret)
+ continue;
+
+ snprintf (query, sizeof (query), "value%d", i);
+ ret = dict_get_str (dict, query, &value);
+ if (ret)
+ continue;
+
+ runner_argprintf (runner, "%s=%s", key, value);
+ }
+
+ ret = 0;
+out:
+ return ret;
+}
+
+static int
+glusterd_hooks_add_op_args (runner_t *runner, glusterd_op_t op,
+ dict_t *op_ctx, glusterd_commit_hook_type_t type)
+{
+ int vol_count = 0;
+ gf_boolean_t truth = _gf_false;
+ glusterd_volinfo_t *voliter = NULL;
+ glusterd_conf_t *priv = NULL;
+ int ret = -1;
+
+ priv = THIS->private;
+ list_for_each_entry (voliter, &priv->volumes,
+ vol_list) {
+ if (glusterd_is_volume_started (voliter))
+ vol_count++;
+ }
+
+ ret = 0;
+ switch (op) {
+ case GD_OP_START_VOLUME:
+ if (type == GD_COMMIT_HOOK_PRE &&
+ vol_count == 0)
+ truth = _gf_true;
+
+ else if (type == GD_COMMIT_HOOK_POST &&
+ vol_count == 1)
+ truth = _gf_true;
+
+ else
+ truth = _gf_false;
+
+ runner_argprintf (runner, "--first=%s",
+ truth? "yes":"no");
+ break;
+
+ case GD_OP_STOP_VOLUME:
+ if (type == GD_COMMIT_HOOK_PRE &&
+ vol_count == 1)
+ truth = _gf_true;
+
+ else if (type == GD_COMMIT_HOOK_POST &&
+ vol_count == 0)
+ truth = _gf_true;
+
+ else
+ truth = _gf_false;
+
+ runner_argprintf (runner, "--last=%s",
+ truth? "yes":"no");
+ break;
+
+ case GD_OP_SET_VOLUME:
+ ret = glusterd_hooks_set_volume_args (op_ctx, runner);
+ break;
+
+ default:
+ break;
+
+ }
+
+ return ret;
+}
+
+int
+glusterd_hooks_run_hooks (char *hooks_path, glusterd_op_t op, dict_t *op_ctx,
+ glusterd_commit_hook_type_t type)
{
xlator_t *this = NULL;
glusterd_conf_t *priv = NULL;
@@ -221,6 +326,13 @@ glusterd_hooks_run_hooks (char *hooks_path, dict_t *op_ctx)
runner_argprintf (&runner, "%s/%s", hooks_path, lines[lineno]);
/*Add future command line arguments to hook scripts below*/
runner_argprintf (&runner, "--volname=%s", volname);
+ ret = glusterd_hooks_add_op_args (&runner, op, op_ctx, type);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR, "Failed to add "
+ "command specific arguments");
+ goto out;
+ }
+
ret = runner_run_reuse (&runner);
if (ret) {
runner_log (&runner, this->name, GF_LOG_ERROR,
diff --git a/xlators/mgmt/glusterd/src/glusterd-hooks.h b/xlators/mgmt/glusterd/src/glusterd-hooks.h
index a57eab0fa..02d9e4331 100644
--- a/xlators/mgmt/glusterd/src/glusterd-hooks.h
+++ b/xlators/mgmt/glusterd/src/glusterd-hooks.h
@@ -45,5 +45,6 @@ char *
glusterd_hooks_get_hooks_cmd_subdir (glusterd_op_t op);
int
-glusterd_hooks_run_hooks (char *hooks_path, dict_t *op_ctx);
+glusterd_hooks_run_hooks (char *hooks_path, glusterd_op_t op, dict_t *op_ctx,
+ glusterd_commit_hook_type_t type);
#endif
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
index 3b6f679ed..07f35642b 100644
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
@@ -2286,7 +2286,7 @@ glusterd_op_commit_hook (glusterd_op_t op, dict_t *op_ctx, glusterd_commit_hook
snprintf (scriptdir, sizeof (scriptdir), "%s/%s/%s",
hookdir, cmd_subdir, type_subdir);
- return glusterd_hooks_run_hooks (scriptdir, op_ctx);
+ return glusterd_hooks_run_hooks (scriptdir, op, op_ctx, type);
}
static int