[SCM] CTDB repository - branch master updated - ctdb-1.0.108-41-g6e8b279
Ronnie Sahlberg
sahlberg at samba.org
Tue Dec 8 20:31:07 MST 2009
The branch, master has been updated
via 6e8b279ed307eccac08386e98510361ba3ab3d36 (commit)
via 9b90d671581e390e2892d3a68f3ca98d58bef4df (commit)
via 53bc5ca23ca55a3ac63a440051f16716944a2a51 (commit)
via 93153bca68926401dc9ae7fd77ed3f17be923344 (commit)
via 47ffe75848f216568ce3db0a60ca88cfe3d6903a (commit)
via c1ba1392fe52762960e896ace0aca0ee4faa94d5 (commit)
via c73ea56275d4be76f7ed983d7565b20237dbdce3 (commit)
via 4cf1b7c32bcf7e4b65aec1fa7ee1a4b162cac889 (commit)
via fd2f04554e604bc421806be96b987e601473a9b8 (commit)
via f5cb41ecf3fa986b8af243e8546eb3b985cd902a (commit)
via e9661b383e0c50b9e3d114b7434dfe601aff5744 (commit)
via 76e8bdc11b953398ce8850de57aa51f30cb46bff (commit)
via c476c81f3e3d8fc62f2e53d82fce5774044ee9ce (commit)
via b2a300768536d10bd867a987ad4cf1c5268c44bc (commit)
via 32cfdc3aec34272612f43a3588e4cabed9c85b68 (commit)
via 497766cf186442de00fb324343150442457be858 (commit)
via 391926a87a7af73840f10bb314c0a2f951a0854c (commit)
via 814704a3286756d40c2a6c508c1c0b77fa711891 (commit)
via 0fafdcb8d3532a05846abaa5805b2e2f3cee8f47 (commit)
via 020fd21e0905e7f11400f6537988645987f2bb32 (commit)
via 9a2b4f6b17e54685f878d75bad27aa5090b4571f (commit)
via 0d925e6f2767691fa561f15bbb857a2aec531143 (commit)
via bfee777faff75e9bed4aedc1558957483616a6d3 (commit)
via 816b9177f51ae5b21b92ff4a404f548fe9723c96 (commit)
via e6488c0e05bab5c4c2c0a6370930b0b27e5ed56e (commit)
via 9ecee127e19a9e7cae114a66f3514ee7a75276c5 (commit)
via a305cb7743c24386e464f6b2efab7e2108bb1e7e (commit)
via 024386931bda9757079f206238ae09bae4de6ea2 (commit)
via 1269458547795c90d544371332ba1de68df29548 (commit)
via ec36ced9446da7e3bf866466d265ee8e18f606c1 (commit)
via 5d894e1ae5228df6bbe4fc305ccba19803fa3798 (commit)
via eadf5e44ef97d7703a7d3bce0e7ea0f21cb11f14 (commit)
via 0a53d6b5ac81daf0efa32f35e7758ede2a5bdb63 (commit)
via 8ddb97040842375daf378cbb5816d0c2b031fa65 (commit)
via 76a0ca77feba14e1e1162c195ffbdf516e62aa4d (commit)
via 0eb1d0aa14e68b598d9e281c8a02b8f94a042fd9 (commit)
via 6be931266a4e41fd0253f760936ad9707dd97c47 (commit)
via 17fa252d0d6981fbae8083a818f26d5ce9c5102e (commit)
from 8cc6c5de3d7abb0b72eaa6e769e70963b02d84cb (commit)
http://gitweb.samba.org/?p=sahlberg/ctdb.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 6e8b279ed307eccac08386e98510361ba3ab3d36
Merge: 8cc6c5de3d7abb0b72eaa6e769e70963b02d84cb 9b90d671581e390e2892d3a68f3ca98d58bef4df
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date: Wed Dec 9 14:26:42 2009 +1100
Merge commit 'rusty/script-report'
commit 9b90d671581e390e2892d3a68f3ca98d58bef4df
Author: Rusty Russell <rusty at rustcorp.com.au>
Date: Tue Dec 8 01:50:55 2009 +1030
ctdb: scriptstatus can now query non-monitor events
We also no longer return an error before scripts have been run; a special
zero-length data means we have never run the scripts.
"ctdb scriptstatus all" returns all event script results.
Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
commit 53bc5ca23ca55a3ac63a440051f16716944a2a51
Author: Rusty Russell <rusty at rustcorp.com.au>
Date: Tue Dec 8 01:47:13 2009 +1030
eventscript: expost call names and enum
We're going to need this so ctdb can query non-monitor status.
Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
commit 93153bca68926401dc9ae7fd77ed3f17be923344
Author: Rusty Russell <rusty at rustcorp.com.au>
Date: Tue Dec 8 01:32:36 2009 +1030
eventscript: lock logging on timeout.
Ronnie suggested this; seems like a very good idea.
Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
commit 47ffe75848f216568ce3db0a60ca88cfe3d6903a
Author: Rusty Russell <rusty at rustcorp.com.au>
Date: Tue Dec 8 01:31:53 2009 +1030
ctdb: support --machinereadable (-Y) for scriptstatus
Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
commit c1ba1392fe52762960e896ace0aca0ee4faa94d5
Author: Rusty Russell <rusty at rustcorp.com.au>
Date: Tue Dec 8 12:29:10 2009 +1030
eventscript: get rid of ctdb_control_event_script_finished altogether
We always have to call it before freeing the state; we should just do
this work in the destructor itself.
Unfortunately, the script state would already be freed by the time
the state destructor is called, so we make the script state a child of
ctdb, and talloc_free() it manually on the one path which doesn't use
the destructor.
Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
commit c73ea56275d4be76f7ed983d7565b20237dbdce3
Author: Rusty Russell <rusty at rustcorp.com.au>
Date: Tue Dec 8 12:27:48 2009 +1030
eventscript: save state for all script invocations
Rather than only tranferring to last_status for monitor events, do
it for every event (ctdb->last_status is now an array).
Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
commit 4cf1b7c32bcf7e4b65aec1fa7ee1a4b162cac889
Author: Rusty Russell <rusty at rustcorp.com.au>
Date: Tue Dec 8 12:24:56 2009 +1030
eventscript: cleanup finished to take state arg
We only need ctdb->current_monitor so we can kill it when we want to run
something else; we don't need to use it here as we always know what script
we are running.
Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
commit fd2f04554e604bc421806be96b987e601473a9b8
Author: Rusty Russell <rusty at rustcorp.com.au>
Date: Tue Dec 8 12:48:17 2009 +1030
eventscript: use wire format internally for script status.
The only difference between the exposed an internal structure now is
that the name and output fields were pointers. Switch to using
ctdb_scripts_wire/ctdb_script_wire internally as well so marshalling
is a noop.
We now reject scripts which are too long and truncate logging to the
511 characters we have space for (the entire output will be in the
normal ctdbd log).
Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
commit f5cb41ecf3fa986b8af243e8546eb3b985cd902a
Author: Rusty Russell <rusty at rustcorp.com.au>
Date: Tue Dec 8 00:51:24 2009 +1030
eventscript: rename ctdb_monitoring_wire to ctdb_scripts_wire
We're going to allow fetching status of all script runs, so this
name is no longer appropriate.
Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
commit e9661b383e0c50b9e3d114b7434dfe601aff5744
Author: Rusty Russell <rusty at rustcorp.com.au>
Date: Tue Dec 8 12:47:24 2009 +1030
eventscript: get_current_script() helper
This neatens the code slightly. We also use the name 'current' in
ctdb_event_script_handler() for uniformity.
Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
commit 76e8bdc11b953398ce8850de57aa51f30cb46bff
Author: Rusty Russell <rusty at rustcorp.com.au>
Date: Tue Dec 8 12:47:05 2009 +1030
eventscript: use an array rather than a linked list of scripts
This brings us closer to the wire format, by using a simple array
and a 'current' iterator.
The downside is that a 'struct ctdb_script' is no longer a talloc
object: the state must be passed to our log fn, and the current
script extracted with &state->scripts->scripts[state->current].
The wackiness of marshalling is simplified, and as a bonus, we can
distinguish between an empty event directory
(state->scripts->num_scripts == 0) and and error (state->scripts ==
NULL).
Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
commit c476c81f3e3d8fc62f2e53d82fce5774044ee9ce
Author: Rusty Russell <rusty at rustcorp.com.au>
Date: Tue Dec 8 12:46:18 2009 +1030
eventscript: record script status for all events
This unifies almost everything: the state->current pointer points to
the struct ctdb_script where we record start, finish, status and
output.
We still only marshall up the monitor events; the rest disappear when
the state structure is freed.
Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
commit b2a300768536d10bd867a987ad4cf1c5268c44bc
Author: Rusty Russell <rusty at rustcorp.com.au>
Date: Tue Dec 8 12:45:17 2009 +1030
eventscript: use scripts array directly, rather than separate list
We rename ctdb_monitor_script_status to ctdb_script, and instead of
allocating them as the scripts are executed, we allocate them up front
and keep a "current" interator.
This slightly simplifies the code, though it means we only marshall up
to the last successfully run script.
Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
commit 32cfdc3aec34272612f43a3588e4cabed9c85b68
Author: Rusty Russell <rusty at rustcorp.com.au>
Date: Tue Dec 8 12:44:30 2009 +1030
eventscript: ctdb_fork_with_logging()
A new helper functions which sets up an event attached to the child's
stdout/stderr which gets routed to the logging callback after being
placed in the normal logs.
This is a generalization of the previous code which was hardcoded to
call ctdb_log_event_script_output.
The only subtlety is that we hang the child fds off the output buffer;
the destructor for that will flush, which means it has to be destroyed
before the output buffer is.
Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
commit 497766cf186442de00fb324343150442457be858
Author: Rusty Russell <rusty at rustcorp.com.au>
Date: Tue Dec 8 00:31:29 2009 +1030
eventscript: pass struct ctdb_log_state directly to ctdb_log_handler().
The current logging logic assumes that any stdout/stderr belongs to
the currently running monitor script output. This isn't quite right
anyway, and we'd like to capture stderr output of other script
invocations.
So we move towards multiple struct ctdb_log_state by handing it
directly to ctdb_log_handler to use, rather than having it assume
ctdb->log. We need a ctdb pointer inside the log struct now though.
Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
commit 391926a87a7af73840f10bb314c0a2f951a0854c
Author: Rusty Russell <rusty at rustcorp.com.au>
Date: Tue Dec 8 00:27:40 2009 +1030
eventscript: remove unused ctbd_ctrl_event_script*
The child no longer uses ctdb_ctrl_event_script_init or
ctdb_ctrl_event_script_finished, and the others are redundant: it
doesn't need to tell us it's starting a script when it only runs one.
We move start and stop calls to the parent, and eliminate the RPC
infrastructure altogether.
Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
commit 814704a3286756d40c2a6c508c1c0b77fa711891
Author: Rusty Russell <rusty at rustcorp.com.au>
Date: Tue Dec 8 00:22:55 2009 +1030
eventscript: refactor forking code into fork_child_for_script()
We do the same thing in two places: fire off a child from the initial
ctdb_event_script_callback_v() and also from the ctdb_event_script_handler()
when it's done.
Unify this logic into fork_child_for_script().
Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
commit 0fafdcb8d3532a05846abaa5805b2e2f3cee8f47
Author: Rusty Russell <rusty at rustcorp.com.au>
Date: Tue Dec 8 00:21:25 2009 +1030
eventscript: fork() a child for each script.
We rename child_run_scripts() to child_run_script(), because it now
runs a single script rather than walking the list. When it's
finished, we fork the next child from the ctdb_event_script_handler()
callback.
ctdb_control_event_script_init() and ctdb_control_event_script_finished()
are now called directly by the parent process; the child still calls
ctdb_ctrl_event_script_start() and ctdb_ctrl_event_script_stop() before
and after the script.
Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
commit 020fd21e0905e7f11400f6537988645987f2bb32
Author: Rusty Russell <rusty at rustcorp.com.au>
Date: Tue Dec 8 00:15:18 2009 +1030
eventscript: store from_user and script_list inside state structure
This means all the state about running the scripts is in that structure,
which helps in the next patch.
Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
commit 9a2b4f6b17e54685f878d75bad27aa5090b4571f
Author: Rusty Russell <rusty at rustcorp.com.au>
Date: Tue Dec 8 00:14:01 2009 +1030
eventscript: use direct script state pointer for current monitor
We put a "scripts" member in ctdb_event_script_state, rather than using
a special struct for monitor events. This will fit better as we further
unify the different events, and holds the reports from the child process
running each monitor script.
Rather than making the monitor state a child of current_monitor_status_ctx,
we just point current_monitor directly at it. This means we need to reset
that pointer in the destructor for ctdb_event_script_state.
Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
commit 0d925e6f2767691fa561f15bbb857a2aec531143
Author: Rusty Russell <rusty at rustcorp.com.au>
Date: Tue Dec 8 00:09:20 2009 +1030
eventscript: make current_monitor_status_ctx serve as monitor_event_script_ctx
We have monitor_event_script_ctx and other_event_script_ctx, and
current_monitor_status_ctx in struct ctdb_context. This seems more
complex than it needs to be.
We use a single "event_script_ctx" as parent for all event script
state structures. Then we explicitly reparent monitor events under
current_monitor_status_ctx: this is freed every script invocation to
kill off any running scripts anyway.
Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
commit bfee777faff75e9bed4aedc1558957483616a6d3
Author: Rusty Russell <rusty at rustcorp.com.au>
Date: Mon Dec 7 23:55:03 2009 +1030
eventscript: split ctdb_run_event_script into multiple parts
Simple refactoring in preparation for switching to one-child-per-script.
We also call the functions run by the child process "child_".
Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
commit 816b9177f51ae5b21b92ff4a404f548fe9723c96
Author: Rusty Russell <rusty at rustcorp.com.au>
Date: Mon Dec 7 23:53:35 2009 +1030
eventscript: hoist work out of child process, into parent
This is the start of a move towards finer-grained reporting, with one
child per script. Simple code motion to do sanity check and get the
list of scripts before fork().
Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
commit e6488c0e05bab5c4c2c0a6370930b0b27e5ed56e
Author: Rusty Russell <rusty at rustcorp.com.au>
Date: Mon Dec 7 23:52:01 2009 +1030
eventscript: don't make ourselves healthy if we're under ban_count
If we've timed out, but we've not timed out more than
ctdb->tunable.script_ban_count, we pretend we haven't.
There's a logic bug in the way this is done: if we were unhealthy before,
this would set us to "healthy" again (status == 0). I don't think this
would happen in real life, but it's a little surprising.
Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
commit 9ecee127e19a9e7cae114a66f3514ee7a75276c5
Author: Rusty Russell <rusty at rustcorp.com.au>
Date: Mon Dec 7 23:48:57 2009 +1030
eventscript: handle banning within the callbacks
Currently the timeout handler in eventscript.c does the banning if a
timeout happens. However, because monitor events are different, it has
to special case them.
As we call the callback anyway in this case, we should make that handle
-ETIME as it sees fit: for everyone but the monitor event, we simply ban
ourselves. The more complicated monitor event banning logic is now in
ctdb_monitor.c where it belongs.
Note: I wrapped the other bans in "if (status == -ETIME)", though they
should probably ban themselves on any error. This change should be a
noop.
Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
commit a305cb7743c24386e464f6b2efab7e2108bb1e7e
Author: Rusty Russell <rusty at rustcorp.com.au>
Date: Mon Dec 7 23:18:40 2009 +1030
eventscript: expost ctdb_ban_self()
eventscript.c uses this now, but our next patch makes others use it.
Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
commit 024386931bda9757079f206238ae09bae4de6ea2
Author: Rusty Russell <rusty at rustcorp.com.au>
Date: Mon Dec 7 23:17:23 2009 +1030
eventscript: handle v. unlikely timeout race
If we time out just as the child exits, we currently will report an
uninitialized cb_status field. Set it to -ETIME as expected.
Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
commit 1269458547795c90d544371332ba1de68df29548
Author: Rusty Russell <rusty at rustcorp.com.au>
Date: Mon Dec 7 23:15:56 2009 +1030
eventscript: replace other -1 returns with -errno
This completes our "problem with script" reporting; we never set cb_status
to -1 on error. Real errnos are used where the failure is a system call
(eg. read, setpgid), otherwise -EIO is used if we couldn't communicate with
the parent.
The latter case is a bit useless, since the parent probably won't see
the error anyway, but it's neater.
Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
commit ec36ced9446da7e3bf866466d265ee8e18f606c1
Author: Rusty Russell <rusty at rustcorp.com.au>
Date: Mon Dec 7 23:13:12 2009 +1030
eventscript: simplify ctdb_run_event_script loop
If we break, we avoid cut & paste code inside the loop. Need to initialize
ret to 0 for the "no scripts" case.
Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
commit 5d894e1ae5228df6bbe4fc305ccba19803fa3798
Author: Rusty Russell <rusty at rustcorp.com.au>
Date: Mon Dec 7 23:12:19 2009 +1030
eventscript: handle and report generic stat/execution errors
Rather than ignoring deleted event scripts (or pretending that they were "OK"),
and discarding other stat errors, we save the errno and turn it into a negative
status.
This gives us a bit more information if we can't execute a script (eg.
too many symlinks or other weird errors).
Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
commit eadf5e44ef97d7703a7d3bce0e7ea0f21cb11f14
Author: Rusty Russell <rusty at rustcorp.com.au>
Date: Mon Dec 7 23:11:47 2009 +1030
eventscript: use -ENOEXEC for disabled status value
This unifies code paths and simplifies things: we just hand -ENOEXEC to
ctdb_ctrl_event_script_stop().
Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
commit 0a53d6b5ac81daf0efa32f35e7758ede2a5bdb63
Author: Rusty Russell <rusty at rustcorp.com.au>
Date: Mon Dec 7 23:09:02 2009 +1030
eventscript: enhance script delete race check
We currently assume 127 == script removed. The script can also return 127;
best to re-check the execution status in this case (and for 126, which will
happen if the script is non-executable).
If the script is no longer executable/not present, we ignore it.
Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
commit 8ddb97040842375daf378cbb5816d0c2b031fa65
Author: Rusty Russell <rusty at rustcorp.com.au>
Date: Mon Dec 7 23:09:39 2009 +1030
eventscript: check_executable() to centralize stat/perm checks
This is used later in the "script vanished" check.
Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
commit 76a0ca77feba14e1e1162c195ffbdf516e62aa4d
Author: Rusty Russell <rusty at rustcorp.com.au>
Date: Mon Dec 7 23:05:58 2009 +1030
talloc: save errno over talloc_free
As we start to use errno more, it's a huge pain if talloc_free() can blatt
it (esp. destructors).
Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
commit 0eb1d0aa14e68b598d9e281c8a02b8f94a042fd9
Author: Rusty Russell <rusty at rustcorp.com.au>
Date: Mon Dec 7 23:09:42 2009 +1030
eventscript: use -ETIME for timeout status value
This starts the move toward more expressive encoding of return values:
positive values mean the script ran, negative means we had a problem with
the script (and the value is the errno).
This does timeout, but changes the ctdb tool to recognize it.
Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
commit 6be931266a4e41fd0253f760936ad9707dd97c47
Author: Rusty Russell <rusty at rustcorp.com.au>
Date: Mon Dec 7 23:09:40 2009 +1030
eventscript: marshall onto last_status immediately
This simplifies the code a little: last_status is now read to go
(it's only used by the scriptstatus command at the moment).
Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
commit 17fa252d0d6981fbae8083a818f26d5ce9c5102e
Author: Rusty Russell <rusty at rustcorp.com.au>
Date: Wed Dec 2 16:15:57 2009 +1030
eventscript: reduce code duplication for ending a script, and fix bug
Commit 50c2caed57c0 removed a gratuitous talloc_steal from the code in
ctdb_control_event_script_finished(), but not ctdb_event_script_timeout().
Easiest to call ctdb_control_event_script_finished() at the bottom of the
timeout routine.
Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
-----------------------------------------------------------------------
Summary of changes:
client/ctdb_client.c | 126 +------
common/ctdb_util.c | 12 +
include/ctdb.h | 29 ++-
include/ctdb_private.h | 48 +--
lib/talloc/talloc.c | 7 +-
server/ctdb_banning.c | 15 +
server/ctdb_control.c | 22 +--
server/ctdb_logging.c | 134 ++++++--
server/ctdb_monitor.c | 12 +
server/ctdb_recover.c | 6 +
server/ctdb_takeover.c | 7 +
server/eventscript.c | 859 ++++++++++++++++++------------------------------
tools/ctdb.c | 133 +++++++--
13 files changed, 645 insertions(+), 765 deletions(-)
Changeset truncated at 500 lines:
diff --git a/client/ctdb_client.c b/client/ctdb_client.c
index 82f156d..aa462fb 100644
--- a/client/ctdb_client.c
+++ b/client/ctdb_client.c
@@ -3643,129 +3643,35 @@ int switch_from_server_to_client(struct ctdb_context *ctdb)
}
/*
- tell the main daemon we are starting a new monitor event script
- */
-int ctdb_ctrl_event_script_init(struct ctdb_context *ctdb)
-{
- int ret;
- int32_t res;
-
- ret = ctdb_control(ctdb, CTDB_CURRENT_NODE, 0, CTDB_CONTROL_EVENT_SCRIPT_INIT, 0, tdb_null,
- ctdb, NULL, &res, NULL, NULL);
- if (ret != 0 || res != 0) {
- DEBUG(DEBUG_ERR,("Failed to send event_script_init\n"));
- return -1;
- }
-
- return 0;
-}
-
-/*
- tell the main daemon we are starting a new monitor event script
- */
-int ctdb_ctrl_event_script_finished(struct ctdb_context *ctdb)
-{
- int ret;
- int32_t res;
-
- ret = ctdb_control(ctdb, CTDB_CURRENT_NODE, 0, CTDB_CONTROL_EVENT_SCRIPT_FINISHED, 0, tdb_null,
- ctdb, NULL, &res, NULL, NULL);
- if (ret != 0 || res != 0) {
- DEBUG(DEBUG_ERR,("Failed to send event_script_init\n"));
- return -1;
- }
-
- return 0;
-}
-
-/*
- tell the main daemon we are starting to run an eventscript
- */
-int ctdb_ctrl_event_script_start(struct ctdb_context *ctdb, const char *name)
-{
- int ret;
- int32_t res;
- TDB_DATA data;
-
- data.dptr = discard_const(name);
- data.dsize = strlen(name)+1;
-
- ret = ctdb_control(ctdb, CTDB_CURRENT_NODE, 0, CTDB_CONTROL_EVENT_SCRIPT_START, 0, data,
- ctdb, NULL, &res, NULL, NULL);
- if (ret != 0 || res != 0) {
- DEBUG(DEBUG_ERR,("Failed to send event_script_start\n"));
- return -1;
- }
-
- return 0;
-}
-
-/*
- tell the main daemon the status of the script we ran
- */
-int ctdb_ctrl_event_script_stop(struct ctdb_context *ctdb, int32_t result)
-{
- int ret;
- int32_t res;
- TDB_DATA data;
-
- data.dptr = (uint8_t *)&result;
- data.dsize = sizeof(result);
-
- ret = ctdb_control(ctdb, CTDB_CURRENT_NODE, 0, CTDB_CONTROL_EVENT_SCRIPT_STOP, 0, data,
- ctdb, NULL, &res, NULL, NULL);
- if (ret != 0 || res != 0) {
- DEBUG(DEBUG_ERR,("Failed to send event_script_stop\n"));
- return -1;
- }
-
- return 0;
-}
-
-/*
- tell the main daemon a script was disabled
- */
-int ctdb_ctrl_event_script_disabled(struct ctdb_context *ctdb, const char *name)
-{
- int ret;
- int32_t res;
- TDB_DATA data;
-
- data.dptr = discard_const(name);
- data.dsize = strlen(name)+1;
-
- ret = ctdb_control(ctdb, CTDB_CURRENT_NODE, 0, CTDB_CONTROL_EVENT_SCRIPT_DISABLED, 0, data,
- ctdb, NULL, &res, NULL, NULL);
- if (ret != 0 || res != 0) {
- DEBUG(DEBUG_ERR,("Failed to send event_script_disabeld\n"));
- return -1;
- }
-
- return 0;
-}
-
-/*
- get the status of running the monitor eventscripts
+ get the status of running the monitor eventscripts: NULL means never run.
*/
int ctdb_ctrl_getscriptstatus(struct ctdb_context *ctdb,
struct timeval timeout, uint32_t destnode,
- TALLOC_CTX *mem_ctx,
- struct ctdb_monitoring_wire **script_status)
+ TALLOC_CTX *mem_ctx, enum ctdb_eventscript_call type,
+ struct ctdb_scripts_wire **script_status)
{
int ret;
- TDB_DATA outdata;
+ TDB_DATA outdata, indata;
int32_t res;
+ uint32_t uinttype = type;
+
+ indata.dptr = (uint8_t *)&uinttype;
+ indata.dsize = sizeof(uinttype);
ret = ctdb_control(ctdb, destnode, 0,
- CTDB_CONTROL_GET_EVENT_SCRIPT_STATUS, 0, tdb_null,
+ CTDB_CONTROL_GET_EVENT_SCRIPT_STATUS, 0, indata,
mem_ctx, &outdata, &res, &timeout, NULL);
- if (ret != 0 || res != 0 || outdata.dsize == 0) {
+ if (ret != 0 || res != 0) {
DEBUG(DEBUG_ERR,(__location__ " ctdb_control for getscriptstatus failed ret:%d res:%d\n", ret, res));
return -1;
}
- *script_status = (struct ctdb_monitoring_wire *)talloc_memdup(mem_ctx, outdata.dptr, outdata.dsize);
- talloc_free(outdata.dptr);
+ if (outdata.dsize == 0) {
+ *script_status = NULL;
+ } else {
+ *script_status = (struct ctdb_scripts_wire *)talloc_memdup(mem_ctx, outdata.dptr, outdata.dsize);
+ talloc_free(outdata.dptr);
+ }
return 0;
}
diff --git a/common/ctdb_util.c b/common/ctdb_util.c
index 3af1346..787d8d7 100644
--- a/common/ctdb_util.c
+++ b/common/ctdb_util.c
@@ -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"
+};
diff --git a/include/ctdb.h b/include/ctdb.h
index 1d5d0d8..0270925 100644
--- a/include/ctdb.h
+++ b/include/ctdb.h
@@ -654,24 +654,41 @@ int switch_from_server_to_client(struct ctdb_context *ctdb);
#define MAX_SCRIPT_NAME 31
#define MAX_SCRIPT_OUTPUT 511
-struct ctdb_monitoring_script_wire {
+struct ctdb_script_wire {
char name[MAX_SCRIPT_NAME+1];
struct timeval start;
struct timeval finished;
- int32_t disabled;
int32_t status;
- int32_t timedout;
char output[MAX_SCRIPT_OUTPUT+1];
};
-struct ctdb_monitoring_wire {
+struct ctdb_scripts_wire {
uint32_t num_scripts;
- struct ctdb_monitoring_script_wire scripts[1];
+ 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_monitoring_wire **script_status);
+ TALLOC_CTX *mem_ctx, enum ctdb_eventscript_call type,
+ struct ctdb_scripts_wire **script_status);
struct debug_levels {
diff --git a/include/ctdb_private.h b/include/ctdb_private.h
index c074afa..142bbd5 100644
--- a/include/ctdb_private.h
+++ b/include/ctdb_private.h
@@ -452,11 +452,10 @@ struct ctdb_context {
uint32_t *recd_ping_count;
TALLOC_CTX *release_ips_ctx; /* a context used to automatically drop all IPs if we fail to recover the node */
- TALLOC_CTX *monitor_event_script_ctx;
- TALLOC_CTX *other_event_script_ctx;
+ TALLOC_CTX *event_script_ctx;
- struct ctdb_monitor_script_status_ctx *current_monitor_status_ctx;
- struct ctdb_monitor_script_status_ctx *last_monitor_status_ctx;
+ struct ctdb_event_script_state *current_monitor;
+ struct ctdb_scripts_wire *last_status[CTDB_EVENT_MAX];
TALLOC_CTX *banning_ctx;
@@ -604,10 +603,6 @@ enum ctdb_controls {CTDB_CONTROL_PROCESS_EXISTS = 0,
CTDB_CONTROL_TAKEOVER_IP = 89,
CTDB_CONTROL_GET_PUBLIC_IPS = 90,
CTDB_CONTROL_GET_NODEMAP = 91,
- CTDB_CONTROL_EVENT_SCRIPT_INIT = 92,
- CTDB_CONTROL_EVENT_SCRIPT_START = 93,
- CTDB_CONTROL_EVENT_SCRIPT_STOP = 94,
- CTDB_CONTROL_EVENT_SCRIPT_FINISHED = 95,
CTDB_CONTROL_GET_EVENT_SCRIPT_STATUS = 96,
CTDB_CONTROL_TRAVERSE_KILL = 97,
CTDB_CONTROL_RECD_RECLOCK_LATENCY = 98,
@@ -618,7 +613,6 @@ enum ctdb_controls {CTDB_CONTROL_PROCESS_EXISTS = 0,
CTDB_CONTROL_SET_NATGWSTATE = 103,
CTDB_CONTROL_SET_LMASTERROLE = 104,
CTDB_CONTROL_SET_RECMASTERROLE = 105,
- CTDB_CONTROL_EVENT_SCRIPT_DISABLED = 106,
CTDB_CONTROL_ENABLE_SCRIPT = 107,
CTDB_CONTROL_DISABLE_SCRIPT = 108,
CTDB_CONTROL_SET_BAN_STATE = 109,
@@ -864,20 +858,6 @@ enum ctdb_trans2_commit_error {
CTDB_TRANS2_COMMIT_SOMEFAIL=3 /* some nodes failed the commit, some allowed it */
};
-/* 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 */
-};
-
/* internal prototypes */
void ctdb_set_error(struct ctdb_context *ctdb, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
void ctdb_fatal(struct ctdb_context *ctdb, const char *msg);
@@ -1509,20 +1489,9 @@ int32_t ctdb_control_set_recmaster(struct ctdb_context *ctdb, uint32_t opcode, T
extern int script_log_level;
-int ctdb_ctrl_event_script_init(struct ctdb_context *ctdb);
-int ctdb_ctrl_event_script_start(struct ctdb_context *ctdb, const char *name);
-int ctdb_ctrl_event_script_stop(struct ctdb_context *ctdb, int32_t res);
-int ctdb_ctrl_event_script_finished(struct ctdb_context *ctdb);
-int ctdb_ctrl_event_script_disabled(struct ctdb_context *ctdb, const char *name);
-
-int32_t ctdb_control_event_script_init(struct ctdb_context *ctdb);
-int32_t ctdb_control_event_script_start(struct ctdb_context *ctdb, TDB_DATA indata);
-int32_t ctdb_control_event_script_stop(struct ctdb_context *ctdb, TDB_DATA indata);
-int32_t ctdb_control_event_script_disabled(struct ctdb_context *ctdb, TDB_DATA indata);
-int32_t ctdb_control_event_script_finished(struct ctdb_context *ctdb);
-
-
-int32_t ctdb_control_get_event_script_status(struct ctdb_context *ctdb, TDB_DATA *outdata);
+int32_t ctdb_control_get_event_script_status(struct ctdb_context *ctdb,
+ uint32_t call_type,
+ TDB_DATA *outdata);
int ctdb_log_event_script_output(struct ctdb_context *ctdb, char *str, uint16_t len);
int ctdb_ctrl_report_recd_lock_latency(struct ctdb_context *ctdb, struct timeval timeout, double latency);
@@ -1538,6 +1507,7 @@ int32_t ctdb_control_disable_script(struct ctdb_context *ctdb, TDB_DATA indata);
int32_t ctdb_control_set_ban_state(struct ctdb_context *ctdb, TDB_DATA indata);
int32_t ctdb_control_get_ban_state(struct ctdb_context *ctdb, TDB_DATA *outdata);
int32_t ctdb_control_set_db_priority(struct ctdb_context *ctdb, TDB_DATA indata);
+void ctdb_ban_self(struct ctdb_context *ctdb);
int32_t ctdb_control_register_notify(struct ctdb_context *ctdb, uint32_t client_id, TDB_DATA indata);
@@ -1554,6 +1524,10 @@ struct ctdb_get_log_addr {
int32_t ctdb_control_get_log(struct ctdb_context *ctdb, TDB_DATA addr);
int32_t ctdb_control_clear_log(struct ctdb_context *ctdb);
+struct ctdb_log_state *ctdb_fork_with_logging(TALLOC_CTX *mem_ctx,
+ struct ctdb_context *ctdb,
+ void (*logfn)(const char *, uint16_t, void *),
+ void *logfn_private, pid_t *pid);
int32_t ctdb_control_process_exists(struct ctdb_context *ctdb, pid_t pid);
struct ctdb_client *ctdb_find_client_by_pid(struct ctdb_context *ctdb, pid_t pid);
diff --git a/lib/talloc/talloc.c b/lib/talloc/talloc.c
index b805c97..8e11a11 100644
--- a/lib/talloc/talloc.c
+++ b/lib/talloc/talloc.c
@@ -746,7 +746,12 @@ void *talloc_named_const(const void *context, size_t size, const char *name)
*/
int talloc_free(void *ptr)
{
- return _talloc_free(ptr);
+ int ret, saved_errno;
+
+ saved_errno = errno;
+ ret = _talloc_free(ptr);
+ errno = saved_errno;
+ return ret;
}
diff --git a/server/ctdb_banning.c b/server/ctdb_banning.c
index 5dfcef1..a46f60b 100644
--- a/server/ctdb_banning.c
+++ b/server/ctdb_banning.c
@@ -119,3 +119,18 @@ int32_t ctdb_control_get_ban_state(struct ctdb_context *ctdb, TDB_DATA *outdata)
return 0;
}
+
+/* Routine to ban ourselves for a while when trouble strikes. */
+void ctdb_ban_self(struct ctdb_context *ctdb)
+{
+ TDB_DATA data;
+ struct ctdb_ban_time bantime;
+
+ bantime.pnn = ctdb->pnn;
+ bantime.time = ctdb->tunable.recovery_ban_period;
+
+ data.dsize = sizeof(bantime);
+ data.dptr = (uint8_t *)&bantime;
+
+ ctdb_control_set_ban_state(ctdb, data);
+}
diff --git a/server/ctdb_control.c b/server/ctdb_control.c
index 73853e3..fcffca3 100644
--- a/server/ctdb_control.c
+++ b/server/ctdb_control.c
@@ -432,27 +432,9 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
CHECK_CONTROL_DATA_SIZE(0);
return ctdb_control_recd_ping(ctdb);
- case CTDB_CONTROL_EVENT_SCRIPT_INIT:
- CHECK_CONTROL_DATA_SIZE(0);
- return ctdb_control_event_script_init(ctdb);
-
- case CTDB_CONTROL_EVENT_SCRIPT_START:
- return ctdb_control_event_script_start(ctdb, indata);
-
- case CTDB_CONTROL_EVENT_SCRIPT_STOP:
- CHECK_CONTROL_DATA_SIZE(sizeof(int32_t));
- return ctdb_control_event_script_stop(ctdb, indata);
-
- case CTDB_CONTROL_EVENT_SCRIPT_FINISHED:
- CHECK_CONTROL_DATA_SIZE(0);
- return ctdb_control_event_script_finished(ctdb);
-
- case CTDB_CONTROL_EVENT_SCRIPT_DISABLED:
- return ctdb_control_event_script_disabled(ctdb, indata);
-
case CTDB_CONTROL_GET_EVENT_SCRIPT_STATUS:
- CHECK_CONTROL_DATA_SIZE(0);
- return ctdb_control_get_event_script_status(ctdb, outdata);
+ CHECK_CONTROL_DATA_SIZE(sizeof(uint32_t));
+ return ctdb_control_get_event_script_status(ctdb, *(uint32_t *)indata.dptr, outdata);
case CTDB_CONTROL_RECD_RECLOCK_LATENCY:
CHECK_CONTROL_DATA_SIZE(sizeof(double));
diff --git a/server/ctdb_logging.c b/server/ctdb_logging.c
index 5bb39e3..7dadbfd 100644
--- a/server/ctdb_logging.c
+++ b/server/ctdb_logging.c
@@ -154,10 +154,13 @@ int start_syslog_daemon(struct ctdb_context *ctdb)
}
struct ctdb_log_state {
+ struct ctdb_context *ctdb;
int fd, pfd;
char buf[1024];
uint16_t buf_used;
bool use_syslog;
+ void (*logfn)(const char *, uint16_t, void *);
+ void *logfn_private;
};
/* we need this global to keep the DEBUG() syntax */
@@ -317,6 +320,7 @@ int ctdb_set_logfile(struct ctdb_context *ctdb, const char *logfile, bool use_sy
abort();
}
+ ctdb->log->ctdb = ctdb;
log_state = ctdb->log;
if (use_syslog) {
@@ -347,7 +351,17 @@ int ctdb_set_logfile(struct ctdb_context *ctdb, const char *logfile, bool use_sy
return 0;
}
-
+/* Note that do_debug always uses the global log state. */
+static void write_to_log(struct ctdb_log_state *log,
+ const char *buf, unsigned int len)
+{
+ if (script_log_level <= LogLevel) {
+ do_debug("%*.*s\n", len, len, buf);
+ /* log it in the eventsystem as well */
+ if (log->logfn)
+ log->logfn(log->buf, len, log->logfn_private);
+ }
+}
/*
called when log data comes in from a child process
@@ -355,7 +369,7 @@ int ctdb_set_logfile(struct ctdb_context *ctdb, const char *logfile, bool use_sy
static void ctdb_log_handler(struct event_context *ev, struct fd_event *fde,
uint16_t flags, void *private)
{
- struct ctdb_context *ctdb = talloc_get_type(private, struct ctdb_context);
+ struct ctdb_log_state *log = talloc_get_type(private, struct ctdb_log_state);
char *p;
int n;
@@ -363,45 +377,115 @@ static void ctdb_log_handler(struct event_context *ev, struct fd_event *fde,
return;
}
- n = read(ctdb->log->pfd, &ctdb->log->buf[ctdb->log->buf_used],
- sizeof(ctdb->log->buf) - ctdb->log->buf_used);
+ n = read(log->pfd, &log->buf[log->buf_used],
+ sizeof(log->buf) - log->buf_used);
if (n > 0) {
- ctdb->log->buf_used += n;
+ log->buf_used += n;
}
this_log_level = script_log_level;
- while (ctdb->log->buf_used > 0 &&
- (p = memchr(ctdb->log->buf, '\n', ctdb->log->buf_used)) != NULL) {
- int n1 = (p - ctdb->log->buf)+1;
+ while (log->buf_used > 0 &&
+ (p = memchr(log->buf, '\n', log->buf_used)) != NULL) {
+ int n1 = (p - log->buf)+1;
int n2 = n1 - 1;
/* swallow \r from child processes */
- if (n2 > 0 && ctdb->log->buf[n2-1] == '\r') {
+ if (n2 > 0 && log->buf[n2-1] == '\r') {
n2--;
}
- if (script_log_level <= LogLevel) {
- do_debug("%*.*s\n", n2, n2, ctdb->log->buf);
- /* log it in the eventsystem as well */
- ctdb_log_event_script_output(ctdb, ctdb->log->buf, n2);
- }
- memmove(ctdb->log->buf, p+1, sizeof(ctdb->log->buf) - n1);
- ctdb->log->buf_used -= n1;
+ write_to_log(log, log->buf, n2);
+ memmove(log->buf, p+1, sizeof(log->buf) - n1);
+ log->buf_used -= n1;
}
/* the buffer could have completely filled - unfortunately we have
no choice but to dump it out straight away */
- if (ctdb->log->buf_used == sizeof(ctdb->log->buf)) {
- if (script_log_level <= LogLevel) {
- do_debug("%*.*s\n",
- (int)ctdb->log->buf_used, (int)ctdb->log->buf_used, ctdb->log->buf);
- /* log it in the eventsystem as well */
- ctdb_log_event_script_output(ctdb, ctdb->log->buf, ctdb->log->buf_used);
--
CTDB repository
More information about the samba-cvs
mailing list