diff options
author | Ronnie Sahlberg <ronniesahlberg@gmail.com> | 2011-11-30 10:00:07 +1100 |
---|---|---|
committer | Ronnie Sahlberg <ronniesahlberg@gmail.com> | 2011-11-30 10:00:07 +1100 |
commit | 11f3c947e6189994bd43a9fcd1301a1dc6251c78 (patch) | |
tree | f0f430e05b1cfa7295d36a5a3cdabaa8bbb429f2 | |
parent | 5a1e8df45187bcc4cf64b9135e174cc858a88c0a (diff) | |
download | samba-11f3c947e6189994bd43a9fcd1301a1dc6251c78.tar.gz samba-11f3c947e6189994bd43a9fcd1301a1dc6251c78.tar.xz samba-11f3c947e6189994bd43a9fcd1301a1dc6251c78.zip |
LibCTDB: add support for the check-srvids control
(This used to be ctdb commit c32604fd0016de0df14845a2f222edaa3c52a4fa)
-rw-r--r-- | ctdb/include/ctdb.h | 69 | ||||
-rw-r--r-- | ctdb/libctdb/control.c | 44 | ||||
-rw-r--r-- | ctdb/libctdb/sync.c | 18 |
3 files changed, 131 insertions, 0 deletions
diff --git a/ctdb/include/ctdb.h b/ctdb/include/ctdb.h index 43ab192c0f..aeab615b44 100644 --- a/ctdb/include/ctdb.h +++ b/ctdb/include/ctdb.h @@ -510,6 +510,48 @@ bool ctdb_getpnn_recv(struct ctdb_connection *ctdb, /** + * ctdb_check_message_handlers_send - check a list of message_handlers + * if they are registered + * message_handlers are registered on the daemon using the + * ctdb_set_message_handler_send() call + * + * @ctdb: the ctdb_connection from ctdb_connect. + * @destnode: the destination node (see below) + * @num: number of srvids to check + * @mhs: @num message_handlers values to check + * @callback: the callback when ctdb replies to our message (typesafe) + * @cbdata: the argument to callback() + * + * There are several special values for destnode, detailed in + * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the + * local ctdbd. + */ +struct ctdb_request * +ctdb_check_message_handlers_send(struct ctdb_connection *ctdb, + uint32_t destnode, + uint32_t num, + uint64_t *mhs, + ctdb_callback_t callback, + void *cbdata); +/** + * ctdb_check_message_handlers_recv - read a ctdb_check_message_handlers + * reply from ctdbd + * @ctdb: the ctdb_connection from ctdb_connect. + * @req: the completed request. + * @num: number of message_handlers to check + * @result: an array of @num uint8_t fields containing the result of the check + * 0: message_handler does not exist + * 1: message_handler exists + * + * This returns false if something went wrong, or otherwise fills in result. + */ +bool +ctdb_check_message_handlers_recv(struct ctdb_connection *ctdb, + struct ctdb_request *req, uint32_t num, + uint8_t *result); + + +/** * ctdb_getdbseqnum_send - read the sequence number off a db * @ctdb: the ctdb_connection from ctdb_connect. * @destnode: the destination node (see below) @@ -767,6 +809,27 @@ bool ctdb_getpnn(struct ctdb_connection *ctdb, uint32_t *pnn); /** + * ctdb_check_message_handlers - check a list of message_handlers (synchronous) + * @ctdb: the ctdb_connection from ctdb_connect. + * @destnode: the destination node (see below) + * @num: number of srvids to check + * @mhs: @num message_handlers to check + * @result: an array of @num uint8_t fields containing the result of the check + * 0: message_handler does not exist + * 1: message_handler exists + * + * There are several special values for destnode, detailed in + * ctdb_protocol.h, particularly CTDB_CURRENT_NODE which means the + * local ctdbd. + */ +bool +ctdb_check_message_handlers(struct ctdb_connection *ctdb, + uint32_t destnode, + uint32_t num, + uint64_t *mhs, + uint8_t *result); + +/** * ctdb_getdbseqnum - read the seqnum of a database * @ctdb: the ctdb_connection from ctdb_connect. * @destnode: the destination node (see below) @@ -922,6 +985,12 @@ void ctdb_free_publicips(struct ctdb_all_public_ips *ips); ctdb_getpnn_send((ctdb), (destnode), \ ctdb_sendcb((cb), (cbdata)), (cbdata)) +#define ctdb_check_message_handlers_send(ctdb, destnode, num, mhs, \ + cb, cbdata) \ + ctdb_check_message_handlers_send((ctdb), (destnode), (num), \ + (mhs), \ + ctdb_sendcb((cb), (cbdata)), (cbdata)) + #define ctdb_getrecmaster_send(ctdb, destnode, cb, cbdata) \ ctdb_getrecmaster_send((ctdb), (destnode), \ ctdb_sendcb((cb), (cbdata)), (cbdata)) diff --git a/ctdb/libctdb/control.c b/ctdb/libctdb/control.c index 70c8e51950..419238101c 100644 --- a/ctdb/libctdb/control.c +++ b/ctdb/libctdb/control.c @@ -25,6 +25,7 @@ #undef ctdb_getrecmaster_send #undef ctdb_getrecmode_send #undef ctdb_getpnn_send +#undef ctdb_check_message_handlers_send #undef ctdb_getnodemap_send #undef ctdb_getpublicips_send #undef ctdb_getdbseqnum_send @@ -240,3 +241,46 @@ struct ctdb_request *ctdb_getdbseqnum_send(struct ctdb_connection *ctdb, destnode, &indata, sizeof(uint64_t), callback, private_data); } + +bool ctdb_check_message_handlers_recv(struct ctdb_connection *ctdb, + struct ctdb_request *req, + uint32_t num, uint8_t *result) +{ + struct ctdb_reply_control *reply; + int i, count; + + reply = unpack_reply_control(req, CTDB_CONTROL_CHECK_SRVIDS); + if (!reply) { + return false; + } + if (reply->status == -1) { + DEBUG(ctdb, LOG_ERR, "ctdb_check_message_handlers_recv: status -1"); + return false; + } + + count = (num + 7) / 8; + if (count != reply->datalen) { + DEBUG(ctdb, LOG_ERR, "ctdb_check_message_handlers_recv: wrong amount of data returned, expected %d bytes for %d srvids but received %d bytes", count, num, reply->datalen); + return false; + } + + for (i = 0; i < num; i++) { + result[i] = !!(reply->data[i / 8] & (1 << (i % 8))); + } + + return true; +} + +struct ctdb_request * +ctdb_check_message_handlers_send(struct ctdb_connection *ctdb, + uint32_t destnode, + uint32_t num, + uint64_t *mhs, + ctdb_callback_t callback, + void *private_data) +{ + return new_ctdb_control_request(ctdb, CTDB_CONTROL_CHECK_SRVIDS, + destnode, + mhs, num * sizeof(uint64_t) , + callback, private_data); +} diff --git a/ctdb/libctdb/sync.c b/ctdb/libctdb/sync.c index 7c9949464b..6696283f04 100644 --- a/ctdb/libctdb/sync.c +++ b/ctdb/libctdb/sync.c @@ -136,6 +136,24 @@ bool ctdb_getpnn(struct ctdb_connection *ctdb, return ret; } +bool ctdb_check_message_handlers(struct ctdb_connection *ctdb, + uint32_t destnode, uint32_t num, + uint64_t *mhs, uint8_t *result) +{ + struct ctdb_request *req; + bool done = false; + bool ret = false; + + req = synchronous(ctdb, + ctdb_check_message_handlers_send(ctdb, destnode, num, mhs, set, &done), + &done); + if (req != NULL) { + ret = ctdb_check_message_handlers_recv(ctdb, req, num, result); + ctdb_request_free(req); + } + return ret; +} + bool ctdb_getnodemap(struct ctdb_connection *ctdb, uint32_t destnode, struct ctdb_node_map **nodemap) { |