1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

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@rustcorp.com.au>


(This used to be ctdb commit 391926a87a7af73840f10bb314c0a2f951a0854c)
This commit is contained in:
Rusty Russell 2009-12-08 00:27:40 +10:30
parent 69c30c6ba0
commit c309d22f9a
4 changed files with 25 additions and 179 deletions

View File

@ -3642,86 +3642,6 @@ int switch_from_server_to_client(struct ctdb_context *ctdb)
return 0;
}
/*
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;
}
/*
get the status of running the monitor eventscripts
*/

View File

@ -603,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,
@ -1507,17 +1503,6 @@ 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);
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_finished(struct ctdb_context *ctdb);
int32_t ctdb_control_get_event_script_status(struct ctdb_context *ctdb, TDB_DATA *outdata);
int ctdb_log_event_script_output(struct ctdb_context *ctdb, char *str, uint16_t len);

View File

@ -432,21 +432,6 @@ 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_GET_EVENT_SCRIPT_STATUS:
CHECK_CONTROL_DATA_SIZE(0);
return ctdb_control_get_event_script_status(ctdb, outdata);

View File

@ -123,10 +123,8 @@ int ctdb_log_event_script_output(struct ctdb_context *ctdb, char *str, uint16_t
return 0;
}
/* called from the event script child process when we are starting a new
* monitor event
*/
int32_t ctdb_control_event_script_init(struct ctdb_context *ctdb)
/* starting a new monitor event */
static int32_t ctdb_control_event_script_init(struct ctdb_context *ctdb)
{
DEBUG(DEBUG_INFO, ("event script init called\n"));
@ -139,12 +137,9 @@ int32_t ctdb_control_event_script_init(struct ctdb_context *ctdb)
}
/* called from the event script child process when we are star running
* an eventscript
*/
int32_t ctdb_control_event_script_start(struct ctdb_context *ctdb, TDB_DATA indata)
/* starting a new child to run a monitor event script */
static int32_t ctdb_control_event_script_start(struct ctdb_context *ctdb, const char *name)
{
const char *name = (const char *)indata.dptr;
struct ctdb_monitor_script_status *script;
DEBUG(DEBUG_INFO, ("event script start called : %s\n", name));
@ -169,12 +164,9 @@ int32_t ctdb_control_event_script_start(struct ctdb_context *ctdb, TDB_DATA inda
return 0;
}
/* called from the event script child process when we have finished running
* an eventscript
*/
int32_t ctdb_control_event_script_stop(struct ctdb_context *ctdb, TDB_DATA indata)
/* finished a child running a monitor event script */
static int32_t ctdb_control_event_script_stop(struct ctdb_context *ctdb, int res)
{
int32_t res = *((int32_t *)indata.dptr);
struct ctdb_monitor_script_status *script;
if (ctdb->current_monitor == NULL) {
@ -231,10 +223,8 @@ static struct ctdb_monitoring_wire *marshall_monitoring_scripts(TALLOC_CTX *mem_
return monitoring_scripts;
}
/* called from the event script child process when we have completed a
* monitor event
*/
int32_t ctdb_control_event_script_finished(struct ctdb_context *ctdb)
/* called when all event script child processes are done */
static int32_t ctdb_control_event_script_finished(struct ctdb_context *ctdb)
{
DEBUG(DEBUG_INFO, ("event script finished called\n"));
@ -432,21 +422,8 @@ static struct ctdb_script_list *ctdb_get_script_list(struct ctdb_context *ctdb,
return head;
}
static int child_setup(struct ctdb_context *ctdb,
bool from_user,
enum ctdb_eventscript_call call)
static int child_setup(struct ctdb_context *ctdb)
{
if (!from_user && call == CTDB_EVENT_MONITOR) {
/* This is running in the forked child process. At this stage
* we want to switch from being a ctdb daemon into being a
* client and connect to the real local daemon.
*/
if (switch_from_server_to_client(ctdb) != 0) {
DEBUG(DEBUG_CRIT, (__location__ "ERROR: failed to switch eventscript child into client mode. shutting down.\n"));
_exit(1);
}
}
if (setpgid(0,0) != 0) {
int ret = -errno;
DEBUG(DEBUG_ERR,("Failed to create process group for event scripts - %s\n",
@ -455,9 +432,6 @@ static int child_setup(struct ctdb_context *ctdb,
}
signal(SIGTERM, sigterm);
child_state.start = timeval_current();
child_state.script_running = "startup";
return 0;
}
@ -532,32 +506,17 @@ static int child_run_script(struct ctdb_context *ctdb,
int ret;
TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
ret = child_setup(ctdb, from_user, call);
child_state.start = timeval_current();
ret = child_setup(ctdb);
if (ret != 0)
goto out;
cmdstr = child_command_string(ctdb, tmp_ctx, from_user,
current->name, call, options);
CTDB_NO_MEMORY(ctdb, cmdstr);
DEBUG(DEBUG_INFO,("Executing event script %s\n",cmdstr));
child_state.start = timeval_current();
child_state.script_running = cmdstr;
if (!from_user && call == CTDB_EVENT_MONITOR) {
if (ctdb_ctrl_event_script_start(ctdb, current->name) != 0) {
ret = -EIO;
goto out;
}
if (current->error) {
if (ctdb_ctrl_event_script_stop(ctdb, -current->error) != 0) {
ret = -EIO;
goto out;
}
}
}
DEBUG(DEBUG_INFO,("Executing event script %s\n",cmdstr));
if (current->error) {
ret = -current->error;
@ -565,17 +524,6 @@ static int child_run_script(struct ctdb_context *ctdb,
}
ret = child_run_one(ctdb, current->name, cmdstr);
if (!from_user && call == CTDB_EVENT_MONITOR) {
if (ctdb_ctrl_event_script_stop(ctdb, ret) != 0) {
ret = -EIO;
goto out;
}
}
child_state.start = timeval_current();
child_state.script_running = "finished";
out:
talloc_free(tmp_ctx);
return ret;
@ -589,6 +537,10 @@ static int fork_child_for_script(struct ctdb_context *ctdb,
{
int r;
if (!state->from_user && state->call == CTDB_EVENT_MONITOR) {
ctdb_control_event_script_start(ctdb, state->script_list->name);
}
r = pipe(state->fd);
if (r != 0) {
DEBUG(DEBUG_ERR, (__location__ " pipe failed for child eventscript process\n"));
@ -644,11 +596,15 @@ static void ctdb_event_script_handler(struct event_context *ev, struct fd_event
state->cb_status = -errno;
} else if (r != sizeof(state->cb_status)) {
state->cb_status = -EIO;
} else {
/* don't stop just because it vanished or was disabled. */
if (state->cb_status == -ENOENT || state->cb_status == -ENOEXEC) {
state->cb_status = 0;
}
}
if (!state->from_user && state->call == CTDB_EVENT_MONITOR) {
ctdb_control_event_script_stop(ctdb, state->cb_status);
}
/* don't stop just because it vanished or was disabled. */
if (state->cb_status == -ENOENT || state->cb_status == -ENOEXEC) {
state->cb_status = 0;
}
state->child = 0;