return result;
}
-struct ctdb_vnn_list {
- uint32_t vnn;
- uint32_t reqid;
- unsigned num_srvids;
- unsigned num_filled;
- uint64_t *srvids;
- unsigned *pid_indexes;
-};
-
-/*
- * Get a list of all vnns mentioned in a list of
- * server_ids. vnn_indexes tells where in the vnns array we have to
- * place the pids.
- */
-static bool ctdb_collect_vnns(TALLOC_CTX *mem_ctx,
- const struct server_id *pids, unsigned num_pids,
- struct ctdb_vnn_list **pvnns,
- unsigned *pnum_vnns)
-{
- struct ctdb_vnn_list *vnns = NULL;
- unsigned *vnn_indexes = NULL;
- unsigned i, num_vnns = 0;
-
- vnn_indexes = talloc_array(mem_ctx, unsigned, num_pids);
- if (vnn_indexes == NULL) {
- DEBUG(1, ("talloc_array failed\n"));
- goto fail;
- }
-
- for (i=0; i<num_pids; i++) {
- unsigned j;
- uint32_t vnn = pids[i].vnn;
-
- for (j=0; j<num_vnns; j++) {
- if (vnn == vnns[j].vnn) {
- break;
- }
- }
- vnn_indexes[i] = j;
-
- if (j < num_vnns) {
- /*
- * Already in the array
- */
- vnns[j].num_srvids += 1;
- continue;
- }
- vnns = talloc_realloc(mem_ctx, vnns, struct ctdb_vnn_list,
- num_vnns+1);
- if (vnns == NULL) {
- DEBUG(1, ("talloc_realloc failed\n"));
- goto fail;
- }
- vnns[num_vnns].vnn = vnn;
- vnns[num_vnns].num_srvids = 1;
- vnns[num_vnns].num_filled = 0;
- num_vnns += 1;
- }
- for (i=0; i<num_vnns; i++) {
- struct ctdb_vnn_list *vnn = &vnns[i];
-
- vnn->srvids = talloc_array(vnns, uint64_t, vnn->num_srvids);
- if (vnn->srvids == NULL) {
- DEBUG(1, ("talloc_array failed\n"));
- goto fail;
- }
- vnn->pid_indexes = talloc_array(vnns, unsigned,
- vnn->num_srvids);
- if (vnn->pid_indexes == NULL) {
- DEBUG(1, ("talloc_array failed\n"));
- goto fail;
- }
- }
- for (i=0; i<num_pids; i++) {
- struct ctdb_vnn_list *vnn = &vnns[vnn_indexes[i]];
- vnn->srvids[vnn->num_filled] = pids[i].unique_id;
- vnn->pid_indexes[vnn->num_filled] = i;
- vnn->num_filled += 1;
- }
-
- TALLOC_FREE(vnn_indexes);
- *pvnns = vnns;
- *pnum_vnns = num_vnns;
- return true;
-fail:
- TALLOC_FREE(vnns);
- TALLOC_FREE(vnn_indexes);
- return false;
-}
-
-bool ctdb_serverids_exist_supported(struct ctdbd_connection *conn)
-{
- return true;
-}
-
-bool ctdb_serverids_exist(struct ctdbd_connection *conn,
- const struct server_id *pids, unsigned num_pids,
- bool *results)
-{
- unsigned i, num_received;
- struct ctdb_vnn_list *vnns = NULL;
- unsigned num_vnns;
-
- if (!ctdb_collect_vnns(talloc_tos(), pids, num_pids,
- &vnns, &num_vnns)) {
- DEBUG(1, ("ctdb_collect_vnns failed\n"));
- goto fail;
- }
-
- for (i=0; i<num_vnns; i++) {
- struct ctdb_vnn_list *vnn = &vnns[i];
- struct ctdb_req_control req;
- struct iovec iov[2];
- ssize_t nwritten;
-
- vnn->reqid = ctdbd_next_reqid(conn);
-
- ZERO_STRUCT(req);
-
- DEBUG(10, ("Requesting VNN %d, reqid=%d, num_srvids=%u\n",
- (int)vnn->vnn, (int)vnn->reqid, vnn->num_srvids));
-
- req.hdr.length = offsetof(struct ctdb_req_control, data);
- req.hdr.ctdb_magic = CTDB_MAGIC;
- req.hdr.ctdb_version = CTDB_PROTOCOL;
- req.hdr.operation = CTDB_REQ_CONTROL;
- req.hdr.reqid = vnn->reqid;
- req.hdr.destnode = vnn->vnn;
- req.opcode = CTDB_CONTROL_CHECK_SRVIDS;
- req.srvid = 0;
- req.datalen = sizeof(uint64_t) * vnn->num_srvids;
- req.hdr.length += req.datalen;
- req.flags = 0;
-
- DEBUG(10, ("ctdbd_control: Sending ctdb packet\n"));
- ctdb_packet_dump(&req.hdr);
-
- iov[0].iov_base = &req;
- iov[0].iov_len = offsetof(struct ctdb_req_control, data);
- iov[1].iov_base = vnn->srvids;
- iov[1].iov_len = req.datalen;
-
- nwritten = write_data_iov(conn->fd, iov, ARRAY_SIZE(iov));
- if (nwritten == -1) {
- DEBUG(10, ("write_data_iov failed: %s\n",
- strerror(errno)));
- goto fail;
- }
- }
-
- num_received = 0;
-
- while (num_received < num_vnns) {
- struct ctdb_req_header *hdr;
- struct ctdb_reply_control *reply;
- struct ctdb_vnn_list *vnn;
- uint32_t reqid;
- uint8_t *reply_data;
- int ret;
-
- ret = ctdb_read_req(conn, 0, talloc_tos(), &hdr);
- if (ret != 0) {
- DEBUG(10, ("ctdb_read_req failed: %s\n",
- strerror(ret)));
- goto fail;
- }
-
- if (hdr->operation != CTDB_REPLY_CONTROL) {
- DEBUG(1, ("Received invalid reply %u\n",
- (unsigned)hdr->operation));
- goto fail;
- }
- reply = (struct ctdb_reply_control *)hdr;
-
- reqid = reply->hdr.reqid;
-
- DEBUG(10, ("Received reqid %d\n", (int)reqid));
-
- for (i=0; i<num_vnns; i++) {
- if (reqid == vnns[i].reqid) {
- break;
- }
- }
- if (i == num_vnns) {
- DEBUG(1, ("Received unknown reqid number %u\n",
- (unsigned)reqid));
- goto fail;
- }
-
- DEBUG(10, ("Found index %u\n", i));
-
- vnn = &vnns[i];
-
- DEBUG(10, ("Received vnn %u, vnn->num_srvids %u, datalen %u\n",
- (unsigned)vnn->vnn, vnn->num_srvids,
- (unsigned)reply->datalen));
-
- if (reply->datalen >= ((vnn->num_srvids+7)/8)) {
- /*
- * Got a real reply
- */
- reply_data = reply->data;
- } else {
- /*
- * Got an error reply
- */
- DEBUG(5, ("Received short reply len %d, status %u, "
- "errorlen %u\n",
- (unsigned)reply->datalen,
- (unsigned)reply->status,
- (unsigned)reply->errorlen));
- dump_data(5, reply->data, reply->errorlen);
-
- /*
- * This will trigger everything set to false
- */
- reply_data = NULL;
- }
-
- for (i=0; i<vnn->num_srvids; i++) {
- int idx = vnn->pid_indexes[i];
-
- if (pids[i].unique_id ==
- SERVERID_UNIQUE_ID_NOT_TO_VERIFY) {
- results[idx] = true;
- continue;
- }
- results[idx] =
- (reply_data != NULL) &&
- ((reply_data[i/8] & (1<<(i%8))) != 0);
- }
-
- TALLOC_FREE(reply);
- num_received += 1;
- }
-
- TALLOC_FREE(vnns);
- return true;
-fail:
- cluster_fatal("serverids_exist failed");
- return false;
-}
-
/*
* Get a db path
*/