mirror of
https://github.com/samba-team/samba.git
synced 2025-01-11 05:18:09 +03:00
add a control to pull the server id list off a node
(This used to be ctdb commit 38aa759aa88a042c31b401551f6a713fb7bbe84e)
This commit is contained in:
parent
6681da31df
commit
801bdbdc80
@ -2385,6 +2385,30 @@ int ctdb_ctrl_check_server_id(struct ctdb_context *ctdb,
|
|||||||
return 0;
|
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
|
initialise the ctdb daemon for client applications
|
||||||
|
@ -412,6 +412,13 @@ struct ctdb_server_id {
|
|||||||
uint32_t vnn;
|
uint32_t vnn;
|
||||||
uint32_t server_id;
|
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,
|
int ctdb_ctrl_register_server_id(struct ctdb_context *ctdb,
|
||||||
struct timeval timeout,
|
struct timeval timeout,
|
||||||
struct ctdb_server_id *id);
|
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,
|
int ctdb_ctrl_check_server_id(struct ctdb_context *ctdb,
|
||||||
struct timeval timeout, uint32_t destnode,
|
struct timeval timeout, uint32_t destnode,
|
||||||
struct ctdb_server_id *id, uint32_t *status);
|
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);
|
int ctdb_socket_connect(struct ctdb_context *ctdb);
|
||||||
|
|
||||||
|
@ -1133,5 +1133,7 @@ int32_t ctdb_control_check_server_id(struct ctdb_context *ctdb,
|
|||||||
TDB_DATA indata);
|
TDB_DATA indata);
|
||||||
int32_t ctdb_control_unregister_server_id(struct ctdb_context *ctdb,
|
int32_t ctdb_control_unregister_server_id(struct ctdb_context *ctdb,
|
||||||
TDB_DATA indata);
|
TDB_DATA indata);
|
||||||
|
int32_t ctdb_control_get_server_id_list(struct ctdb_context *ctdb,
|
||||||
|
TDB_DATA *outdata);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -308,6 +308,10 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
|
|||||||
CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_server_id));
|
CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_server_id));
|
||||||
return ctdb_control_check_server_id(ctdb, indata);
|
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:
|
default:
|
||||||
DEBUG(0,(__location__ " Unknown CTDB control opcode %u\n", opcode));
|
DEBUG(0,(__location__ " Unknown CTDB control opcode %u\n", opcode));
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -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
|
when the structure is free'd it will be automatically
|
||||||
removed from the tree
|
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);
|
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,
|
trbt_insertarray32_callback(ctdb->server_ids, SERVER_ID_KEY_SIZE,
|
||||||
get_server_id_key(server_id),
|
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;
|
||||||
|
}
|
||||||
|
@ -453,6 +453,30 @@ static int chksrvid(struct ctdb_context *ctdb, int argc, const char **argv)
|
|||||||
return 0;
|
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; i<server_ids->num; 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
|
send a tcp tickle ack
|
||||||
*/
|
*/
|
||||||
@ -1048,6 +1072,7 @@ static const struct {
|
|||||||
{ "regsrvid", regsrvid, false, "register a server id", "<vnn> <type> <id>" },
|
{ "regsrvid", regsrvid, false, "register a server id", "<vnn> <type> <id>" },
|
||||||
{ "unregsrvid", unregsrvid, false, "unregister a server id", "<vnn> <type> <id>" },
|
{ "unregsrvid", unregsrvid, false, "unregister a server id", "<vnn> <type> <id>" },
|
||||||
{ "chksrvid", chksrvid, false, "check if a server id exists", "<vnn> <type> <id>" },
|
{ "chksrvid", chksrvid, false, "check if a server id exists", "<vnn> <type> <id>" },
|
||||||
|
{ "getsrvids", getsrvids, false, "get a list of all server ids"},
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user