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
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);
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);
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
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;
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),
}
+
+
+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;
+}
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
*/
{ "regsrvid", regsrvid, false, "register 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>" },
+ { "getsrvids", getsrvids, false, "get a list of all server ids"},
};
/*