eventscript: expost call names and enum
authorRusty Russell <rusty@rustcorp.com.au>
Mon, 7 Dec 2009 15:17:13 +0000 (01:47 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Mon, 7 Dec 2009 15:17:13 +0000 (01:47 +1030)
We're going to need this so ctdb can query non-monitor status.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
common/ctdb_util.c
include/ctdb.h
include/ctdb_private.h
server/eventscript.c

index 3af1346528b3f607fb73671c882d0f4dd590f792..787d8d71748f17b8c046f41253e4403fdd4d6b29 100644 (file)
@@ -662,3 +662,15 @@ int32_t get_debug_by_desc(const char *desc)
        return DEBUG_ERR;
 }
 
+const char *ctdb_eventscript_call_names[] = {
+       "startup",
+       "startrecovery",
+       "recovered",
+       "takeip",
+       "releaseip",
+       "stopped",
+       "monitor",
+       "status",
+       "shutdown",
+       "reload"
+};
index 6721841aaffcff05c1abe9e70e1af0f641eab7a1..a17abca4fe82a786e888d53b47e3f2febc77c9cf 100644 (file)
@@ -667,6 +667,24 @@ struct ctdb_scripts_wire {
        struct ctdb_script_wire scripts[1];
 };
 
+/* different calls to event scripts. */
+enum ctdb_eventscript_call {
+       CTDB_EVENT_STARTUP,             /* CTDB starting up: no args. */
+       CTDB_EVENT_START_RECOVERY,      /* CTDB recovery starting: no args. */
+       CTDB_EVENT_RECOVERED,           /* CTDB recovery finished: no args. */
+       CTDB_EVENT_TAKE_IP,             /* IP taken: interface, IP address, netmask bits. */
+       CTDB_EVENT_RELEASE_IP,          /* IP released: interface, IP address, netmask bits. */
+       CTDB_EVENT_STOPPED,             /* This node is stopped: no args. */
+       CTDB_EVENT_MONITOR,             /* Please check if service is healthy: no args. */
+       CTDB_EVENT_STATUS,              /* Report service status: no args. */
+       CTDB_EVENT_SHUTDOWN,            /* CTDB shutting down: no args. */
+       CTDB_EVENT_RELOAD,              /* magic */
+       CTDB_EVENT_MAX
+};
+
+/* Mapping from enum to names. */
+extern const char *ctdb_eventscript_call_names[];
+
 int ctdb_ctrl_getscriptstatus(struct ctdb_context *ctdb, 
                    struct timeval timeout, uint32_t destnode, 
                    TALLOC_CTX *mem_ctx, struct ctdb_scripts_wire **script_status);
index e226166eee8dc91c728d8f91b83fd1680f43e02d..f6ea265442acc238296ad939b70c5830104e99bd 100644 (file)
@@ -374,21 +374,6 @@ struct ctdb_write_record {
        unsigned char blob[1];
 };
 
-/* different calls to event scripts. */
-enum ctdb_eventscript_call {
-       CTDB_EVENT_STARTUP,             /* CTDB starting up: no args. */
-       CTDB_EVENT_START_RECOVERY,      /* CTDB recovery starting: no args. */
-       CTDB_EVENT_RECOVERED,           /* CTDB recovery finished: no args. */
-       CTDB_EVENT_TAKE_IP,             /* IP taken: interface, IP address, netmask bits. */
-       CTDB_EVENT_RELEASE_IP,          /* IP released: interface, IP address, netmask bits. */
-       CTDB_EVENT_STOPPED,             /* This node is stopped: no args. */
-       CTDB_EVENT_MONITOR,             /* Please check if service is healthy: no args. */
-       CTDB_EVENT_STATUS,              /* Report service status: no args. */
-       CTDB_EVENT_SHUTDOWN,            /* CTDB shutting down: no args. */
-       CTDB_EVENT_RELOAD,              /* magic */
-       CTDB_EVENT_MAX
-};
-
 enum ctdb_freeze_mode {CTDB_FREEZE_NONE, CTDB_FREEZE_PENDING, CTDB_FREEZE_FROZEN};
 
 #define CTDB_MONITORING_ACTIVE         0
index 3e857f7ee6bb77d190156d03fe58a8a3fc434b12..f4e3f54661def1599c1a16b4ae9f744d9c319f95 100644 (file)
@@ -32,19 +32,6 @@ static struct {
        const char *script_running;
 } child_state;
 
-static const char *call_names[] = {
-       "startup",
-       "startrecovery",
-       "recovered",
-       "takeip",
-       "releaseip",
-       "stopped",
-       "monitor",
-       "status",
-       "shutdown",
-       "reload"
-};
-
 static void ctdb_event_script_timeout(struct event_context *ev, struct timed_event *te, struct timeval t, void *p);
 
 /*
@@ -311,7 +298,9 @@ static char *child_command_string(struct ctdb_context *ctdb,
                return talloc_asprintf(ctx, "%s%s/%s %s %s",
                                       str,
                                       ctdb->event_script_dir,
-                                      scriptname, call_names[call], options);
+                                      scriptname,
+                                      ctdb_eventscript_call_names[call],
+                                      options);
        }
 }
 
@@ -463,7 +452,7 @@ static void ctdb_event_script_handler(struct event_context *ev, struct fd_event
        /* Aborted or finished all scripts?  We're done. */
        if (state->cb_status != 0 || state->current+1 == state->scripts->num_scripts) {
                DEBUG(DEBUG_INFO,(__location__ " Eventscript %s %s finished with state %d\n",
-                                 call_names[state->call], state->options, state->cb_status));
+                                 ctdb_eventscript_call_names[state->call], state->options, state->cb_status));
 
                ctdb->event_script_timeouts = 0;
                talloc_free(state);
@@ -490,7 +479,7 @@ static void ctdb_event_script_timeout(struct event_context *ev, struct timed_eve
        struct ctdb_context *ctdb = state->ctdb;
 
        DEBUG(DEBUG_ERR,("Event script timed out : %s %s count : %u  pid : %d\n",
-                        call_names[state->call], state->options, ctdb->event_script_timeouts, state->child));
+                        ctdb_eventscript_call_names[state->call], state->options, ctdb->event_script_timeouts, state->child));
 
        state->cb_status = -ETIME;
 
@@ -607,7 +596,7 @@ static int ctdb_event_script_callback_v(struct ctdb_context *ctdb,
        }
        if (!check_options(state->call, state->options)) {
                DEBUG(DEBUG_ERR, ("Bad eventscript options '%s' for %s\n",
-                                 call_names[state->call], state->options));
+                                 ctdb_eventscript_call_names[state->call], state->options));
                talloc_free(state);
                return -1;
        }
@@ -623,7 +612,7 @@ static int ctdb_event_script_callback_v(struct ctdb_context *ctdb,
                }
                if (i == ARRAY_SIZE(allowed_calls)) {
                        DEBUG(DEBUG_ERR,("Refusing to run event scripts call '%s' while in recovery\n",
-                                call_names[call]));
+                                ctdb_eventscript_call_names[call]));
                        talloc_free(state);
                        return -1;
                }
@@ -638,7 +627,8 @@ static int ctdb_event_script_callback_v(struct ctdb_context *ctdb,
        }
 
        DEBUG(DEBUG_INFO,(__location__ " Starting eventscript %s %s\n",
-                         call_names[state->call], state->options));
+                         ctdb_eventscript_call_names[state->call],
+                         state->options));
 
        /* This is not a child of state, since we save it in destructor. */
        state->scripts = ctdb_get_script_list(ctdb, ctdb);
@@ -667,7 +657,8 @@ static int ctdb_event_script_callback_v(struct ctdb_context *ctdb,
                event_add_timed(ctdb->ev, state, timeval_current_ofs(state->timeout.tv_sec, state->timeout.tv_usec), ctdb_event_script_timeout, state);
        } else {
                DEBUG(DEBUG_ERR, (__location__ " eventscript %s %s called with no timeout\n",
-                                 call_names[state->call], state->options));
+                                 ctdb_eventscript_call_names[state->call],
+                                 state->options));
        }
 
        return 0;
@@ -739,7 +730,7 @@ int ctdb_event_script_args(struct ctdb_context *ctdb, enum ctdb_eventscript_call
        if (status.status == -ETIME) {
                DEBUG(DEBUG_ERR, (__location__ " eventscript for '%s' timedout."
                                  " Immediately banning ourself for %d seconds\n",
-                                 call_names[call],
+                                 ctdb_eventscript_call_names[call],
                                  ctdb->tunable.recovery_ban_period));
                ctdb_ban_self(ctdb);
        }
@@ -788,9 +779,9 @@ static const char *get_call(const char *p, enum ctdb_eventscript_call *call)
        p += strspn(p, " \t");
 
        /* See if we match any. */
-       for (*call = 0; *call < ARRAY_SIZE(call_names); (*call)++) {
-               len = strlen(call_names[*call]);
-               if (strncmp(p, call_names[*call], len) == 0) {
+       for (*call = 0; *call < CTDB_EVENT_MAX; (*call)++) {
+               len = strlen(ctdb_eventscript_call_names[*call]);
+               if (strncmp(p, ctdb_eventscript_call_names[*call], len) == 0) {
                        /* If end of string or whitespace, we're done. */
                        if (strcspn(p + len, " \t") == 0) {
                                return p + len;