}
+/* time out handler for ctdb_control */
+static void timeout_func(struct event_context *ev, struct timed_event *te,
+ struct timeval t, void *private_data)
+{
+ uint32_t *timed_out = (uint32_t *)private_data;
+
+ *timed_out = 1;
+}
+
/*
send a ctdb control message
+ timeout specifies how long we should wait for a reply.
+ if timeout is NULL we wait indefinitely
*/
int ctdb_control(struct ctdb_context *ctdb, uint32_t destnode, uint64_t srvid,
uint32_t opcode, uint32_t flags, TDB_DATA data,
- TALLOC_CTX *mem_ctx, TDB_DATA *outdata, int32_t *status)
+ TALLOC_CTX *mem_ctx, TDB_DATA *outdata, int32_t *status,
+ struct timeval *timeout)
{
struct ctdb_client_control_state *state;
struct ctdb_req_control *c;
size_t len;
int ret;
+ uint32_t timed_out;
/* if the domain socket is not yet open, open it */
if (ctdb->daemon.sd==-1) {
}
/* semi-async operation */
- while (state->state == CTDB_CALL_WAIT) {
+ timed_out = 0;
+ if (timeout) {
+ event_add_timed(ctdb->ev, mem_ctx, timeval_current_ofs(1, 0), timeout_func, &timed_out);
+ }
+ while ((state->state == CTDB_CALL_WAIT)
+ && (timed_out == 0) ){
event_loop_once(ctdb->ev);
}
-
+ if (timed_out) {
+ talloc_free(state);
+ return -1;
+ }
+
if (outdata) {
*outdata = state->outdata;
outdata->dptr = talloc_memdup(mem_ctx, outdata->dptr, outdata->dsize);
ret = ctdb_control(ctdb, destnode, 0,
CTDB_CONTROL_PROCESS_EXISTS, 0, data,
- NULL, NULL, &status);
+ NULL, NULL, &status, NULL);
if (ret != 0) {
DEBUG(0,(__location__ " ctdb_control for process_exists failed\n"));
return -1;
ZERO_STRUCT(data);
ret = ctdb_control(ctdb, destnode, 0,
CTDB_CONTROL_STATUS, 0, data,
- ctdb, &data, &res);
+ ctdb, &data, &res, NULL);
if (ret != 0 || res != 0) {
DEBUG(0,(__location__ " ctdb_control for status failed\n"));
return -1;
ZERO_STRUCT(data);
ret = ctdb_control(ctdb, destnode, 0,
CTDB_CONTROL_GETVNNMAP, 0, data,
- ctdb, &outdata, &res);
+ ctdb, &outdata, &res, NULL);
if (ret != 0 || res != 0) {
DEBUG(0,(__location__ " ctdb_control for getvnnmap failed\n"));
return -1;
ZERO_STRUCT(data);
ret = ctdb_control(ctdb, destnode, 0,
CTDB_CONTROL_GET_RECMODE, 0, data,
- ctdb, &outdata, &res);
+ ctdb, &outdata, &res, NULL);
if (ret != 0 || res != 0) {
DEBUG(0,(__location__ " ctdb_control for getrecmode failed\n"));
return -1;
ret = ctdb_control(ctdb, destnode, 0,
CTDB_CONTROL_SET_RECMODE, 0, data,
- ctdb, &outdata, &res);
+ ctdb, &outdata, &res, NULL);
if (ret != 0 || res != 0) {
DEBUG(0,(__location__ " ctdb_control for getrecmode failed\n"));
return -1;
ZERO_STRUCT(data);
ret = ctdb_control(ctdb, destnode, 0,
CTDB_CONTROL_GET_DBMAP, 0, data,
- ctdb, &outdata, &res);
+ ctdb, &outdata, &res, NULL);
if (ret != 0 || res != 0) {
DEBUG(0,(__location__ " ctdb_control for getdbmap failed\n"));
return -1;
ZERO_STRUCT(data);
ret = ctdb_control(ctdb, destnode, 0,
CTDB_CONTROL_GET_NODEMAP, 0, data,
- ctdb, &outdata, &res);
+ ctdb, &outdata, &res, NULL);
if (ret != 0 || res != 0) {
DEBUG(0,(__location__ " ctdb_control for getnodes failed\n"));
return -1;
ret = ctdb_control(ctdb, destnode, 0,
CTDB_CONTROL_SETVNNMAP, 0, data,
- ctdb, &outdata, &res);
+ ctdb, &outdata, &res, NULL);
if (ret != 0 || res != 0) {
DEBUG(0,(__location__ " ctdb_control for setvnnmap failed\n"));
return -1;
ret = ctdb_control(ctdb, destnode, 0,
CTDB_CONTROL_PULL_DB, 0, indata,
- mem_ctx, &outdata, &res);
+ mem_ctx, &outdata, &res, NULL);
if (ret != 0 || res != 0) {
DEBUG(0,(__location__ " ctdb_control for pulldb failed\n"));
return -1;
ret = ctdb_control(ctdb, sourcenode, 0,
CTDB_CONTROL_PULL_DB, 0, indata,
- mem_ctx, &outdata, &res);
+ mem_ctx, &outdata, &res, NULL);
if (ret != 0 || res != 0) {
DEBUG(0,(__location__ " ctdb_control for pulldb failed\n"));
return -1;
ret = ctdb_control(ctdb, destnode, 0,
CTDB_CONTROL_PUSH_DB, 0, outdata,
- mem_ctx, NULL, &res);
+ mem_ctx, NULL, &res, NULL);
if (ret != 0 || res != 0) {
DEBUG(0,(__location__ " ctdb_control for pushdb failed\n"));
return -1;
ret = ctdb_control(ctdb, destnode, 0,
CTDB_CONTROL_SET_DMASTER, 0, indata,
- mem_ctx, &outdata, &res);
+ mem_ctx, &outdata, &res, NULL);
if (ret != 0 || res != 0) {
DEBUG(0,(__location__ " ctdb_control for setdmaster failed\n"));
return -1;
ret = ctdb_control(ctdb, destnode, 0,
CTDB_CONTROL_CLEAR_DB, 0, indata,
- mem_ctx, &outdata, &res);
+ mem_ctx, &outdata, &res, NULL);
if (ret != 0 || res != 0) {
DEBUG(0,(__location__ " ctdb_control for cleardb failed\n"));
return -1;
ret = ctdb_control(ctdb, destnode, 0,
CTDB_CONTROL_WRITE_RECORD, 0, indata,
- mem_ctx, &outdata, &res);
+ mem_ctx, &outdata, &res, NULL);
if (ret != 0 || res != 0) {
DEBUG(0,(__location__ " ctdb_control for write record failed\n"));
return -1;
ZERO_STRUCT(data);
ret = ctdb_control(ctdb, destnode, 0, CTDB_CONTROL_PING, 0,
- data, NULL, NULL, &res);
+ data, NULL, NULL, &res, NULL);
if (ret != 0) {
return -1;
}
ZERO_STRUCT(data);
ret = ctdb_control(ctdb, CTDB_CURRENT_NODE, 0, CTDB_CONTROL_CONFIG, 0,
- data, ctdb, &data, &res);
+ data, ctdb, &data, &res, NULL);
if (ret != 0 || res != 0) {
return -1;
}
ret = ctdb_control(ctdb, CTDB_CURRENT_NODE, 0,
CTDB_CONTROL_GETDBPATH, 0, data,
- mem_ctx, &data, &res);
+ mem_ctx, &data, &res, NULL);
if (ret != 0 || res != 0) {
return -1;
}
ZERO_STRUCT(data);
ret = ctdb_control(ctdb, destnode, 0, CTDB_CONTROL_GET_DEBUG, 0, data,
- ctdb, &data, &res);
+ ctdb, &data, &res, NULL);
if (ret != 0 || res != 0) {
return -1;
}
data.dsize = sizeof(level);
ret = ctdb_control(ctdb, destnode, 0, CTDB_CONTROL_SET_DEBUG, 0, data,
- NULL, NULL, &res);
+ NULL, NULL, &res, NULL);
if (ret != 0 || res != 0) {
return -1;
}
ZERO_STRUCT(data);
ret = ctdb_control(ctdb, destnode, 0,
CTDB_CONTROL_STATUS_RESET, 0, data,
- NULL, NULL, &res);
+ NULL, NULL, &res, NULL);
if (ret != 0 || res != 0) {
DEBUG(0,(__location__ " ctdb_control for reset status failed\n"));
return -1;
/* tell ctdb daemon to attach */
ret = ctdb_control(ctdb, CTDB_CURRENT_NODE, 0, CTDB_CONTROL_DB_ATTACH,
- 0, data, ctdb_db, &data, &res);
+ 0, data, ctdb_db, &data, &res, NULL);
if (ret != 0 || res != 0 || data.dsize != sizeof(uint32_t)) {
DEBUG(0,("Failed to attach to database '%s'\n", name));
talloc_free(ctdb_db);
data.dsize = sizeof(c);
ret = ctdb_control(ctdb_db->ctdb, CTDB_CURRENT_NODE, 0, CTDB_CONTROL_SET_CALL, 0,
- data, NULL, NULL, &status);
+ data, NULL, NULL, &status, NULL);
if (ret != 0 || status != 0) {
DEBUG(0,("ctdb_set_call failed for call %u\n", id));
return -1;
data.dsize = sizeof(t);
ret = ctdb_control(ctdb_db->ctdb, CTDB_CURRENT_NODE, 0, CTDB_CONTROL_TRAVERSE_START, 0,
- data, NULL, NULL, &status);
+ data, NULL, NULL, &status, NULL);
if (ret != 0 || status != 0) {
DEBUG(0,("ctdb_traverse_all failed\n"));
return -1;
--- /dev/null
+/*
+ ctdb recovery daemon
+
+ Copyright (C) Ronnie Sahlberg 2007
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#include "includes.h"
+#include "lib/events/events.h"
+#include "system/filesys.h"
+#include "popt.h"
+#include "cmdline.h"
+#include "../include/ctdb.h"
+#include "../include/ctdb_private.h"
+
+static int timeout = 0;
+
+/*
+ show usage message
+ */
+static void usage(void)
+{
+ printf(
+ "Usage: recoverd\n"
+ );
+ exit(1);
+}
+
+void timeout_func(struct event_context *ev, struct timed_event *te,
+ struct timeval t, void *private_data)
+{
+ timeout = 1;
+}
+
+
+void recoverd(struct ctdb_context *ctdb, struct event_context *ev)
+{
+ uint32_t vnn;
+ TALLOC_CTX *mem_ctx=NULL;
+
+again:
+ if (mem_ctx) {
+ talloc_free(mem_ctx);
+ mem_ctx = NULL;
+ }
+ mem_ctx = talloc_new(ctdb);
+ if (!mem_ctx) {
+ DEBUG(0,("Failed to create temporary context\n"));
+ exit(-1);
+ }
+
+
+ /* we only check for recovery once every second */
+ timeout = 0;
+ event_add_timed(ctdb->ev, mem_ctx, timeval_current_ofs(1, 0), timeout_func, ctdb);
+ while (!timeout) {
+ event_loop_once(ev);
+ }
+
+
+ /* get our vnn number */
+ vnn = ctdb_get_vnn(ctdb);
+printf("our node number is :%d\n",vnn);
+
+ /* get number of nodes */
+
+}
+
+/*
+ main program
+*/
+int main(int argc, const char *argv[])
+{
+ struct ctdb_context *ctdb;
+ struct poptOption popt_options[] = {
+ POPT_AUTOHELP
+ POPT_CTDB_CMDLINE
+ POPT_TABLEEND
+ };
+ int opt;
+ const char **extra_argv;
+ int extra_argc = 0;
+ int ret;
+ poptContext pc;
+ struct event_context *ev;
+
+ pc = poptGetContext(argv[0], argc, argv, popt_options, POPT_CONTEXT_KEEP_FIRST);
+
+ while ((opt = poptGetNextOpt(pc)) != -1) {
+ switch (opt) {
+ default:
+ fprintf(stderr, "Invalid option %s: %s\n",
+ poptBadOption(pc, 0), poptStrerror(opt));
+ exit(1);
+ }
+ }
+
+ /* setup the remaining options for the main program to use */
+ extra_argv = poptGetArgs(pc);
+ if (extra_argv) {
+ extra_argv++;
+ while (extra_argv[extra_argc]) extra_argc++;
+ }
+
+#if 0
+ if (extra_argc < 1) {
+ usage();
+ }
+#endif
+
+ ev = event_context_init(NULL);
+
+ /* initialise ctdb */
+ ctdb = ctdb_cmdline_client(ev);
+ if (ctdb == NULL) {
+ printf("Failed to init ctdb\n");
+ exit(1);
+ }
+
+
+ recoverd(ctdb, ev);
+
+ return ret;
+}