From: Ronnie Sahlberg Date: Sun, 29 Apr 2007 13:49:27 +0000 (+1000) Subject: merge from tridge X-Git-Tag: tevent-0.9.20~348^2~2800^2~7 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f67a79ad8ef6ce21aaefa75ecf04d447c92d11bc;p=thirdparty%2Fsamba.git merge from tridge (This used to be ctdb commit a84e9b47a87fc7d4756b4a179aa2ea0bc7c54c78) --- f67a79ad8ef6ce21aaefa75ecf04d447c92d11bc diff --cc ctdb/Makefile.in index a80908c638c,81cf72516d8..ff53535c904 --- a/ctdb/Makefile.in +++ b/ctdb/Makefile.in @@@ -108,15 -108,15 +108,21 @@@ distclean: clea install: all mkdir -p $(bindir) mkdir -p $(includedir) - cp $(BINS) $(bindir) - cp $(srcdir)/include/ctdb.h $(includedir) + rsync $(BINS) $(bindir) + rsync $(srcdir)/include/ctdb.h $(includedir) + + test: + tests/run_tests.sh + + valgrindtest: + VALGRIND="valgrind -q --trace-children=yes" tests/run_tests.sh +test: + tests/run_tests.sh + +valgrindtest: + VALGRIND="valgrind -q --trace-children=yes" tests/run_tests.sh + realdistclean: distclean rm -f configure config.h.in diff --cc ctdb/common/ctdb_client.c index d7dc7be54d7,075f8553ae4..d11bab6fc40 --- a/ctdb/common/ctdb_client.c +++ b/ctdb/common/ctdb_client.c @@@ -943,147 -892,8 +939,147 @@@ int ctdb_setvnnmap(struct ctdb_context return 0; } +/* + get all keys for a specific database + */ +int ctdb_getkeys(struct ctdb_context *ctdb, uint32_t destnode, uint32_t dbid, TALLOC_CTX *mem_ctx, struct ctdb_key_list *keys) +{ + int i, ret; + TDB_DATA indata, outdata; + int32_t res; + unsigned char *ptr; + + indata.dsize = sizeof(uint32_t); + indata.dptr = (unsigned char *)&dbid; + + ret = ctdb_control(ctdb, destnode, 0, + CTDB_CONTROL_GET_KEYS, indata, + mem_ctx, &outdata, &res); + if (ret != 0 || res != 0) { + DEBUG(0,(__location__ " ctdb_control for getkeys failed\n")); + return -1; + } + + + keys->num= *((uint32_t *)(&outdata.dptr[0])); + keys->keys=talloc_array(mem_ctx, TDB_DATA, keys->num); + keys->headers=talloc_array(mem_ctx, struct ctdb_ltdb_header, keys->num); + keys->lmasters=talloc_array(mem_ctx, uint32_t, keys->num); + keys->data=talloc_array(mem_ctx, TDB_DATA, keys->num); + + /* loop over all key/data pairs */ + ptr=&outdata.dptr[4]; + for(i=0;inum;i++){ + uint32_t len; + TDB_DATA *key, *data; + + keys->lmasters[i]= *((uint32_t *)ptr); + ptr+=4; + + key=&keys->keys[i]; + key->dsize= *((uint32_t *)ptr); + ptr+=4; + key->dptr=talloc_size(mem_ctx, key->dsize); + memcpy(key->dptr, ptr, key->dsize); + len = (key->dsize+CTDB_DS_ALIGNMENT-1)& ~(CTDB_DS_ALIGNMENT-1); + ptr+=len; + + memcpy(&keys->headers[i], ptr, sizeof(struct ctdb_ltdb_header)); + len = (sizeof(struct ctdb_ltdb_header)+CTDB_DS_ALIGNMENT-1)& ~(CTDB_DS_ALIGNMENT-1); + ptr+=len; + + data=&keys->data[i]; + data->dsize= *((uint32_t *)ptr); + ptr+=4; + data->dptr=talloc_size(mem_ctx, data->dsize); + memcpy(data->dptr, ptr, data->dsize); + len = (data->dsize+CTDB_DS_ALIGNMENT-1)& ~(CTDB_DS_ALIGNMENT-1); + ptr+=len; + + } + + return 0; +} + +/* + change dmaster for all keys in the database to the new value + */ +int ctdb_setdmaster(struct ctdb_context *ctdb, uint32_t destnode, TALLOC_CTX *mem_ctx, uint32_t dbid, uint32_t dmaster) +{ + int ret; + TDB_DATA indata, outdata; + int32_t res; + + indata.dsize = 2*sizeof(uint32_t); + indata.dptr = (unsigned char *)talloc_array(mem_ctx, uint32_t, 2); + + ((uint32_t *)(&indata.dptr[0]))[0] = dbid; + ((uint32_t *)(&indata.dptr[0]))[1] = dmaster; + + ret = ctdb_control(ctdb, destnode, 0, + CTDB_CONTROL_SET_DMASTER, indata, + mem_ctx, &outdata, &res); + if (ret != 0 || res != 0) { + DEBUG(0,(__location__ " ctdb_control for setdmaster failed\n")); + return -1; + } + + return 0; +} + +/* + delete all records from a tdb + */ +int ctdb_cleardb(struct ctdb_context *ctdb, uint32_t destnode, TALLOC_CTX *mem_ctx, uint32_t dbid) +{ + int ret; + TDB_DATA indata, outdata; + int32_t res; + + indata.dsize = sizeof(uint32_t); + indata.dptr = (unsigned char *)talloc_array(mem_ctx, uint32_t, 1); + + ((uint32_t *)(&indata.dptr[0]))[0] = dbid; + + ret = ctdb_control(ctdb, destnode, 0, + CTDB_CONTROL_CLEAR_DB, indata, + mem_ctx, &outdata, &res); + if (ret != 0 || res != 0) { + DEBUG(0,(__location__ " ctdb_control for cleardb failed\n")); + return -1; + } + + return 0; +} + +/* + pull a db from a remote node + */ +int ctdb_pulldb(struct ctdb_context *ctdb, uint32_t destnode, TALLOC_CTX *mem_ctx, uint32_t dbid, uint32_t from_vnn) +{ + int ret; + TDB_DATA indata, outdata; + int32_t res; + + indata.dsize = 2*sizeof(uint32_t); + indata.dptr = (unsigned char *)talloc_array(mem_ctx, uint32_t, 2); + + ((uint32_t *)(&indata.dptr[0]))[0] = dbid; + ((uint32_t *)(&indata.dptr[0]))[1] = from_vnn; + + ret = ctdb_control(ctdb, destnode, 0, + CTDB_CONTROL_PULL_DB, indata, + mem_ctx, &outdata, &res); + if (ret != 0 || res != 0) { + DEBUG(0,(__location__ " ctdb_control for pulldb failed\n")); + return -1; + } + + return 0; +} + /* - ping a node + ping a node, return number of clients connected */ int ctdb_ping(struct ctdb_context *ctdb, uint32_t destnode) { diff --cc ctdb/include/ctdb.h index aa2f31fa34c,d9e53d30a94..1e382b4b8c1 --- a/ctdb/include/ctdb.h +++ b/ctdb/include/ctdb.h @@@ -239,17 -239,9 +239,18 @@@ struct ctdb_node_map uint32_t num; struct ctdb_node_and_flags *nodes; }; - int ctdb_getnodemap(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_node_map *nodemap); + int ctdb_getnodemap(struct ctdb_context *ctdb, uint32_t destnode, + TALLOC_CTX *mem_ctx, struct ctdb_node_map *nodemap); +struct ctdb_key_list { + uint32_t num; + TDB_DATA *keys; + struct ctdb_ltdb_header *headers; + uint32_t *lmasters; + TDB_DATA *data; +}; +int ctdb_getkeys(struct ctdb_context *ctdb, uint32_t destnode, uint32_t dbid, TALLOC_CTX *mem_ctx, struct ctdb_key_list *keys); + int ctdb_getdbpath(struct ctdb_context *ctdb, uint32_t dbid, TALLOC_CTX *mem_ctx, const char **path); int ctdb_process_exists(struct ctdb_context *ctdb, uint32_t destnode, pid_t pid); @@@ -261,31 -253,9 +262,36 @@@ int ctdb_get_config(struct ctdb_contex int ctdb_get_debuglevel(struct ctdb_context *ctdb, uint32_t destnode, uint32_t *level); int ctdb_set_debuglevel(struct ctdb_context *ctdb, uint32_t destnode, uint32_t level); +/* + change dmaster for all keys in the database to the new value + */ +int ctdb_setdmaster(struct ctdb_context *ctdb, uint32_t destnode, TALLOC_CTX *mem_ctx, uint32_t dbid, uint32_t dmaster); + +/* + delete all records from a tdb + */ +int ctdb_cleardb(struct ctdb_context *ctdb, uint32_t destnode, TALLOC_CTX *mem_ctx, uint32_t dbid); + +/* + pull a db from a remote node + */ +int ctdb_pulldb(struct ctdb_context *ctdb, uint32_t destnode, TALLOC_CTX *mem_ctx, uint32_t dbid, uint32_t from_vnn); + + +#define CTDB_RECOVERY_NORMAL 0 +#define CTDB_RECOVERY_ACTIVE 1 +/* + get the recovery mode of a remote node + */ +int ctdb_getrecmode(struct ctdb_context *ctdb, uint32_t destnode, uint32_t *recmode); +/* + set the recovery mode of a remote node + */ +int ctdb_setrecmode(struct ctdb_context *ctdb, uint32_t destnode, uint32_t recmode); + + uint32_t *ctdb_get_connected_nodes(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, + uint32_t *num_nodes); + + int ctdb_status_reset(struct ctdb_context *ctdb, uint32_t destnode); + #endif diff --cc ctdb/include/ctdb_private.h index 73de824f33c,f9b869c4b20..e3b33ff6bfd --- a/ctdb/include/ctdb_private.h +++ b/ctdb/include/ctdb_private.h @@@ -256,12 -252,7 +253,13 @@@ enum ctdb_controls {CTDB_CONTROL_PROCES CTDB_CONTROL_SET_DEBUG, CTDB_CONTROL_GET_DBMAP, CTDB_CONTROL_GET_NODEMAP, + CTDB_CONTROL_GET_KEYS, + CTDB_CONTROL_SET_DMASTER, + CTDB_CONTROL_CLEAR_DB, + CTDB_CONTROL_PULL_DB, + CTDB_CONTROL_GET_RECMODE, - CTDB_CONTROL_SET_RECMODE}; ++ CTDB_CONTROL_SET_RECMODE, + CTDB_CONTROL_STATUS_RESET}; enum call_state {CTDB_CALL_WAIT, CTDB_CALL_DONE, CTDB_CALL_ERROR};