From: Ronnie Sahlberg Date: Sun, 26 Aug 2007 00:57:02 +0000 (+1000) Subject: add a control to pull the server id list off a node X-Git-Tag: tevent-0.9.20~348^2~2435^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=801bdbdc805180155e7cf5b6b268aaeb348d843d;p=thirdparty%2Fsamba.git add a control to pull the server id list off a node (This used to be ctdb commit 38aa759aa88a042c31b401551f6a713fb7bbe84e) --- diff --git a/ctdb/client/ctdb_client.c b/ctdb/client/ctdb_client.c index f0b22dbb066..0aa0e9b97ed 100644 --- a/ctdb/client/ctdb_client.c +++ b/ctdb/client/ctdb_client.c @@ -2385,6 +2385,30 @@ int ctdb_ctrl_check_server_id(struct ctdb_context *ctdb, return 0; } +/* + get the list of server ids that are registered on a node +*/ +int ctdb_ctrl_get_server_id_list(struct ctdb_context *ctdb, + TALLOC_CTX *mem_ctx, + struct timeval timeout, uint32_t destnode, + struct ctdb_server_id_list **svid_list) +{ + int ret; + TDB_DATA outdata; + int32_t res; + + ret = ctdb_control(ctdb, destnode, 0, + CTDB_CONTROL_GET_SERVER_ID_LIST, 0, tdb_null, + mem_ctx, &outdata, &res, &timeout, NULL); + if (ret != 0 || res != 0) { + DEBUG(0,(__location__ " ctdb_control for get_server_id_list failed\n")); + return -1; + } + + *svid_list = (struct ctdb_server_id_list *)talloc_steal(mem_ctx, outdata.dptr); + + return 0; +} /* initialise the ctdb daemon for client applications diff --git a/ctdb/include/ctdb.h b/ctdb/include/ctdb.h index b7c1f71a0b6..e46cc68a794 100644 --- a/ctdb/include/ctdb.h +++ b/ctdb/include/ctdb.h @@ -412,6 +412,13 @@ struct ctdb_server_id { uint32_t vnn; uint32_t server_id; }; + +struct ctdb_server_id_list { + uint32_t num; + struct ctdb_server_id server_ids[1]; +}; + + int ctdb_ctrl_register_server_id(struct ctdb_context *ctdb, struct timeval timeout, struct ctdb_server_id *id); @@ -421,6 +428,10 @@ int ctdb_ctrl_unregister_server_id(struct ctdb_context *ctdb, int ctdb_ctrl_check_server_id(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, struct ctdb_server_id *id, uint32_t *status); +int ctdb_ctrl_get_server_id_list(struct ctdb_context *ctdb, + TALLOC_CTX *mem_ctx, + struct timeval timeout, uint32_t destnode, + struct ctdb_server_id_list **svid_list); int ctdb_socket_connect(struct ctdb_context *ctdb); diff --git a/ctdb/include/ctdb_private.h b/ctdb/include/ctdb_private.h index 9e77e58fd75..516e3111c39 100644 --- a/ctdb/include/ctdb_private.h +++ b/ctdb/include/ctdb_private.h @@ -1133,5 +1133,7 @@ int32_t ctdb_control_check_server_id(struct ctdb_context *ctdb, TDB_DATA indata); int32_t ctdb_control_unregister_server_id(struct ctdb_context *ctdb, TDB_DATA indata); +int32_t ctdb_control_get_server_id_list(struct ctdb_context *ctdb, + TDB_DATA *outdata); #endif diff --git a/ctdb/server/ctdb_control.c b/ctdb/server/ctdb_control.c index 346d0237426..326b8edca66 100644 --- a/ctdb/server/ctdb_control.c +++ b/ctdb/server/ctdb_control.c @@ -308,6 +308,10 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb, CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_server_id)); return ctdb_control_check_server_id(ctdb, indata); + case CTDB_CONTROL_GET_SERVER_ID_LIST: + CHECK_CONTROL_DATA_SIZE(0); + return ctdb_control_get_server_id_list(ctdb, outdata); + default: DEBUG(0,(__location__ " Unknown CTDB control opcode %u\n", opcode)); return -1; diff --git a/ctdb/server/ctdb_serverids.c b/ctdb/server/ctdb_serverids.c index b406a353f13..8c8c9308744 100644 --- a/ctdb/server/ctdb_serverids.c +++ b/ctdb/server/ctdb_serverids.c @@ -72,8 +72,9 @@ int32_t ctdb_control_register_server_id(struct ctdb_context *ctdb, when the structure is free'd it will be automatically removed from the tree */ - server_id = talloc_memdup(client, indata.dptr, indata.dsize); + server_id = talloc_zero(client, struct ctdb_server_id); CTDB_NO_MEMORY(ctdb, server_id); + memcpy(server_id, indata.dptr, sizeof(struct ctdb_server_id)); trbt_insertarray32_callback(ctdb->server_ids, SERVER_ID_KEY_SIZE, get_server_id_key(server_id), @@ -111,3 +112,78 @@ int32_t ctdb_control_unregister_server_id(struct ctdb_context *ctdb, } + + +struct count_server_ids { + int count; + struct ctdb_server_id_list *list; +}; + +static void server_id_count(void *param, void *data) +{ + struct count_server_ids *svid = talloc_get_type(param, + struct count_server_ids); + + if (svid == NULL) { + DEBUG(0, (__location__ " Got null pointer for svid\n")); + return; + } + + svid->count++; +} + +static void server_id_store(void *param, void *data) +{ + struct count_server_ids *svid = talloc_get_type(param, + struct count_server_ids); + struct ctdb_server_id *server_id = talloc_get_type(data, + struct ctdb_server_id); + + if (svid == NULL) { + DEBUG(0, (__location__ " Got null pointer for svid\n")); + return; + } + + if (svid->count >= svid->list->num) { + DEBUG(0, (__location__ " size of server id tree changed during traverse\n")); + return; + } + + memcpy(&svid->list->server_ids[svid->count], server_id, sizeof(struct ctdb_server_id)); + svid->count++; +} + +/* + returns a list of all registered server ids for a node +*/ +int32_t ctdb_control_get_server_id_list(struct ctdb_context *ctdb, TDB_DATA *outdata) +{ + struct count_server_ids *svid; + + + svid = talloc_zero(outdata, struct count_server_ids); + CTDB_NO_MEMORY(ctdb, svid); + + + /* first we must count how many entries we have */ + trbt_traversearray32(ctdb->server_ids, SERVER_ID_KEY_SIZE, + server_id_count, svid); + + + outdata->dsize = offsetof(struct ctdb_server_id_list, + server_ids) + + sizeof(struct ctdb_server_id) * svid->count; + outdata->dptr = talloc_size(outdata, outdata->dsize); + CTDB_NO_MEMORY(ctdb, outdata->dptr); + + + /* now fill the structure in */ + svid->list = (struct ctdb_server_id_list *)(outdata->dptr); + svid->list->num = svid->count; + svid->count=0; + trbt_traversearray32(ctdb->server_ids, SERVER_ID_KEY_SIZE, + server_id_store, svid); + + + return 0; +} diff --git a/ctdb/tools/ctdb.c b/ctdb/tools/ctdb.c index 83b262f520b..3e56a97f6e9 100644 --- a/ctdb/tools/ctdb.c +++ b/ctdb/tools/ctdb.c @@ -453,6 +453,30 @@ static int chksrvid(struct ctdb_context *ctdb, int argc, const char **argv) return 0; } +/* + get a list of all server ids that are registered on a node + */ +static int getsrvids(struct ctdb_context *ctdb, int argc, const char **argv) +{ + int i, ret; + struct ctdb_server_id_list *server_ids; + + ret = ctdb_ctrl_get_server_id_list(ctdb, ctdb, TIMELIMIT(), options.vnn, &server_ids); + if (ret != 0) { + DEBUG(0, ("Unable to get server_id list from node %u\n", options.vnn)); + return ret; + } + + for (i=0; inum; i++) { + printf("Server id %d:%d:%d\n", + server_ids->server_ids[i].vnn, + server_ids->server_ids[i].type, + server_ids->server_ids[i].server_id); + } + + return -1; +} + /* send a tcp tickle ack */ @@ -1048,6 +1072,7 @@ static const struct { { "regsrvid", regsrvid, false, "register a server id", " " }, { "unregsrvid", unregsrvid, false, "unregister a server id", " " }, { "chksrvid", chksrvid, false, "check if a server id exists", " " }, + { "getsrvids", getsrvids, false, "get a list of all server ids"}, }; /*