diff options
author | Krishnan Parthasarathi <kp@gluster.com> | 2012-03-26 16:11:29 +0530 |
---|---|---|
committer | Vijay Bellur <vijay@gluster.com> | 2012-03-31 05:15:08 -0700 |
commit | 66d430da4e3788aeb41eea46455ca25a2d19a626 (patch) | |
tree | b52c1189401cc47c7cfecc7e5225938b926b6a4d /xlators/mgmt/glusterd/src/glusterd-op-sm.c | |
parent | 3f81c44a03e9ab78be2b4a69e3e36d41a4de324a (diff) |
glusterd: Added init scripts like interface for gluster commands
Directories to hold the scripts mentioned above would be created for each
gluster command under glusterd's 'working dir' as follows:
(eg.)
<glusterd-working-dir>/hooks/version/create/pre
<glusterd-working-dir>/hooks/version/create/post
where, version corresponds to the version of hook scripts.
The scripts beginning with 'S' under the above directories would be run before
(pre) and after (post) the volume created. The scripts would receive a command
line argument as below:
--volname=<volname>
This can be optionally used by the script.
Change-Id: Ia81b4ff9dd4477d99dd59b39c805aa645521edb0
BUG: 806996
Signed-off-by: Krishnan Parthasarathi <kp@gluster.com>
Reviewed-on: http://review.gluster.com/3010
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Csaba Henk <csaba@redhat.com>
Reviewed-by: Vijay Bellur <vijay@gluster.com>
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-op-sm.c')
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-op-sm.c | 44 |
1 files changed, 40 insertions, 4 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c index 5788813235b..993ddddb2b4 100644 --- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c +++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c @@ -2127,6 +2127,32 @@ out: } static int +glusterd_op_commit_hook (glusterd_op_t op, dict_t *op_ctx, glusterd_commit_hook_type_t type) +{ + glusterd_conf_t *priv = NULL; + char hookdir[PATH_MAX] = {0, }; + char scriptdir[PATH_MAX] = {0, }; + char type_subdir[256] = {0, }; + char *cmd_subdir = NULL; + + priv = THIS->private; + if (type == GD_COMMIT_HOOK_PRE) + strcpy (type_subdir, "pre"); + else if (type == GD_COMMIT_HOOK_POST) + strcpy (type_subdir, "post"); + + cmd_subdir = glusterd_store_get_hooks_cmd_subdir (op); + if (strlen (cmd_subdir) == 0) + return -1; + + GLUSTERD_GET_HOOKS_DIR (hookdir, GLUSTERD_HOOK_VER, priv); + snprintf (scriptdir, sizeof (scriptdir), "%s/%s/%s", + hookdir, cmd_subdir, type_subdir); + + return glusterd_store_run_hooks (scriptdir, op_ctx); +} + +static int glusterd_op_ac_send_commit_op (glusterd_op_sm_event_t *event, void *ctx) { int ret = 0; @@ -2145,12 +2171,15 @@ glusterd_op_ac_send_commit_op (glusterd_op_sm_event_t *event, void *ctx) priv = this->private; GF_ASSERT (priv); - op = glusterd_op_get_op (); + op = glusterd_op_get_op (); + op_dict = glusterd_op_get_ctx (); + ret = glusterd_op_build_payload (&dict); if (ret) goto out; + glusterd_op_commit_hook (op, op_dict, GD_COMMIT_HOOK_PRE); ret = glusterd_op_commit_perform (op, dict, &op_errstr, NULL); //rsp_dict invalid for source if (ret) { gf_log (THIS->name, GF_LOG_ERROR, "Commit failed"); @@ -2158,6 +2187,8 @@ glusterd_op_ac_send_commit_op (glusterd_op_sm_event_t *event, void *ctx) goto out; } + glusterd_op_commit_hook (op, op_dict, GD_COMMIT_HOOK_POST); + list_for_each_entry (peerinfo, &priv->peers, uuid_list) { GF_ASSERT (peerinfo); @@ -2196,7 +2227,6 @@ out: if (!opinfo.pending_count) { if (op == GD_OP_REPLACE_BRICK) { - op_dict = glusterd_op_get_ctx (); ret = glusterd_op_start_rb_timer (op_dict); } else { @@ -2579,11 +2609,11 @@ static int glusterd_op_ac_commit_op (glusterd_op_sm_event_t *event, void *ctx) { int ret = 0; - glusterd_req_ctx_t *req_ctx = NULL; + glusterd_req_ctx_t *req_ctx = NULL; int32_t status = 0; char *op_errstr = NULL; dict_t *dict = NULL; - dict_t *rsp_dict = NULL; + dict_t *rsp_dict = NULL; GF_ASSERT (ctx); @@ -2595,6 +2625,8 @@ glusterd_op_ac_commit_op (glusterd_op_sm_event_t *event, void *ctx) if (NULL == rsp_dict) return -1; + glusterd_op_commit_hook (req_ctx->op, dict, GD_COMMIT_HOOK_PRE); + if (GD_OP_CLEARLOCKS_VOLUME == req_ctx->op) { /*clear locks should be run only on * originator glusterd*/ @@ -2607,6 +2639,10 @@ glusterd_op_ac_commit_op (glusterd_op_sm_event_t *event, void *ctx) if (status) { gf_log (THIS->name, GF_LOG_ERROR, "Commit failed: %d", status); + } else { + /* On successful commit */ + glusterd_op_commit_hook (req_ctx->op, dict, + GD_COMMIT_HOOK_POST); } ret = glusterd_op_commit_send_resp (req_ctx->req, req_ctx->op, |