diff options
| -rw-r--r-- | cli/src/cli-cmd-volume.c | 62 | ||||
| -rw-r--r-- | events/eventskeygen.py | 2 | ||||
| -rw-r--r-- | events/src/eventtypes.py | 2 | ||||
| -rw-r--r-- | events/src/handlers.py | 19 | ||||
| -rw-r--r-- | libglusterfs/src/eventtypes.h | 2 | 
5 files changed, 87 insertions, 0 deletions
diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c index 6d44095d757..af815da51ef 100644 --- a/cli/src/cli-cmd-volume.c +++ b/cli/src/cli-cmd-volume.c @@ -665,6 +665,10 @@ cli_cmd_volume_reset_cbk (struct cli_state *state, struct cli_cmd_word *word,          call_frame_t            *frame = NULL;          dict_t                  *options = NULL;          cli_local_t             *local = NULL; +#if (USE_EVENTS) +        int                      ret1    = -1; +        char                    *tmp_opt = NULL; +#endif          proc = &cli_rpc_prog->proctable[GLUSTER_CLI_RESET_VOLUME]; @@ -692,6 +696,18 @@ out:                          cli_out ("Volume reset failed");          } +#if (USE_EVENTS) +        if (ret == 0) { +                ret1 = dict_get_str (options, "key", &tmp_opt); +                if (ret1) +                        tmp_opt = ""; + +                gf_event (EVENT_VOLUME_RESET, "name=%s;option=%s", +                          (char *)words[2], +                          tmp_opt); +        } +#endif +          CLI_STACK_DESTROY (frame);          return ret; @@ -758,6 +774,15 @@ cli_cmd_volume_set_cbk (struct cli_state *state, struct cli_cmd_word *word,          cli_local_t             *local = NULL;          char                    *op_errstr = NULL; +#if (USE_EVENTS) +        int                      ret1          = -1; +        int                      i             = 1; +        char                     dict_key[50]  = {0,}; +        char                    *tmp_opt       = NULL; +        char                    *opts_str      = NULL; +        int                      num_options   = 0; +#endif +          proc = &cli_rpc_prog->proctable[GLUSTER_CLI_SET_VOLUME];          frame = create_frame (THIS, THIS->ctx->pool); @@ -790,6 +815,43 @@ out:                          cli_out ("Volume set failed");          } +#if (USE_EVENTS) +        if (ret == 0) { +                ret1 = dict_get_int32 (options, "count", &num_options); +                if (ret1) +                        num_options = 0; +                else +                        num_options = num_options/2; + +                /* Initialize opts_str */ +                opts_str = gf_strdup (""); + +                /* Prepare String in format options=KEY1,VALUE1,KEY2,VALUE2 */ +                for (i = 1; i <= num_options; i++) { +                        sprintf (dict_key, "key%d", i); +                        ret1 = dict_get_str (options, dict_key, &tmp_opt); +                        if (ret1) +                                tmp_opt = ""; + +                        gf_asprintf (&opts_str, "%s,%s", opts_str, tmp_opt); + +                        sprintf (dict_key, "value%d", i); +                        ret1 = dict_get_str (options, dict_key, &tmp_opt); +                        if (ret1) +                                tmp_opt = ""; + +                        gf_asprintf (&opts_str, "%s,%s", opts_str, tmp_opt); +                } + +                gf_event (EVENT_VOLUME_SET, "name=%s;options=%s", +                          (char *)words[2], +                          opts_str); + +                /* Allocated by gf_strdup and gf_asprintf */ +                GF_FREE (opts_str); +        } +#endif +          CLI_STACK_DESTROY (frame);          return ret; diff --git a/events/eventskeygen.py b/events/eventskeygen.py index 656a7dce9f1..f9bdb9fed52 100644 --- a/events/eventskeygen.py +++ b/events/eventskeygen.py @@ -25,6 +25,8 @@ keys = (      "EVENT_VOLUME_START",      "EVENT_VOLUME_STOP",      "EVENT_VOLUME_DELETE", +    "EVENT_VOLUME_SET", +    "EVENT_VOLUME_RESET",  )  LAST_EVENT = "EVENT_LAST" diff --git a/events/src/eventtypes.py b/events/src/eventtypes.py index 4812e659de3..b09e5bcff9a 100644 --- a/events/src/eventtypes.py +++ b/events/src/eventtypes.py @@ -6,4 +6,6 @@ all_events = [      "EVENT_VOLUME_START",      "EVENT_VOLUME_STOP",      "EVENT_VOLUME_DELETE", +    "EVENT_VOLUME_SET", +    "EVENT_VOLUME_RESET",  ] diff --git a/events/src/handlers.py b/events/src/handlers.py index 9b756a91d51..21d3e83de54 100644 --- a/events/src/handlers.py +++ b/events/src/handlers.py @@ -19,3 +19,22 @@ def generic_handler(ts, key, data):      Ex: handle_event_volume_create(ts, key, data)      """      utils.publish(ts, key, data) + + +def handle_event_volume_set(ts, key, data): +    """ +    Recieved data will have all the options as one string, split into +    list of options. "key1,value1,key2,value2" into +    [[key1, value1], [key2, value2]] +    """ +    opts = data.get("options", "").strip(",").split(",") +    data["options"] = [] +    for i, opt in enumerate(opts): +        if i % 2 == 0: +            # Add new array with key +            data["options"].append([opt]) +        else: +            # Add to the last added array +            data["options"][-1].append(opt) + +    utils.publish(ts, key, data) diff --git a/libglusterfs/src/eventtypes.h b/libglusterfs/src/eventtypes.h index 874f8ccf114..20c4b02ebab 100644 --- a/libglusterfs/src/eventtypes.h +++ b/libglusterfs/src/eventtypes.h @@ -16,6 +16,8 @@ typedef enum {      EVENT_VOLUME_START,      EVENT_VOLUME_STOP,      EVENT_VOLUME_DELETE, +    EVENT_VOLUME_SET, +    EVENT_VOLUME_RESET,      EVENT_LAST  } eventtypes_t;  | 
