Esempio n. 1
0
/*
  this is called when the ctdb daemon received a ctdb request message
  from a local client over the unix domain socket
 */
static void daemon_request_message_from_client(struct ctdb_client *client, 
					       struct ctdb_req_message *c)
{
	TDB_DATA data;
	int res;

	if (c->hdr.destnode == CTDB_CURRENT_NODE) {
		c->hdr.destnode = ctdb_get_pnn(client->ctdb);
	}

	/* maybe the message is for another client on this node */
	if (ctdb_get_pnn(client->ctdb)==c->hdr.destnode) {
		ctdb_request_message(client->ctdb, (struct ctdb_req_header *)c);
		return;
	}

	/* its for a remote node */
	data.dptr = &c->data[0];
	data.dsize = c->datalen;
	res = ctdb_daemon_send_message(client->ctdb, c->hdr.destnode,
				       c->srvid, data);
	if (res != 0) {
		DEBUG(DEBUG_ERR,(__location__ " Failed to send message to remote node %u\n",
			 c->hdr.destnode));
	}
}
Esempio n. 2
0
/*
  called when we need to process a packet. This can be a requeued packet
  after a lockwait, or a real packet from another node
*/
void ctdb_input_pkt(struct ctdb_context *ctdb, struct ctdb_req_header *hdr)
{
    TALLOC_CTX *tmp_ctx;

    /* place the packet as a child of the tmp_ctx. We then use
       talloc_free() below to free it. If any of the calls want
       to keep it, then they will steal it somewhere else, and the
       talloc_free() will only free the tmp_ctx */
    tmp_ctx = talloc_new(ctdb);
    talloc_steal(tmp_ctx, hdr);

    DEBUG(DEBUG_DEBUG,(__location__ " ctdb request %u of type %u length %u from "
                       "node %u to %u\n", hdr->reqid, hdr->operation, hdr->length,
                       hdr->srcnode, hdr->destnode));

    switch (hdr->operation) {
    case CTDB_REQ_CALL:
    case CTDB_REPLY_CALL:
    case CTDB_REQ_DMASTER:
    case CTDB_REPLY_DMASTER:
        /* we don't allow these calls when banned */
        if (ctdb->nodes[ctdb->pnn]->flags & NODE_FLAGS_BANNED) {
            DEBUG(DEBUG_DEBUG,(__location__ " ctdb operation %u"
                               " request %u"
                               " length %u from node %u to %u while node"
                               " is banned\n",
                               hdr->operation, hdr->reqid,
                               hdr->length,
                               hdr->srcnode, hdr->destnode));
            goto done;
        }

        /* for ctdb_call inter-node operations verify that the
           remote node that sent us the call is running in the
           same generation instance as this node
        */
        if (ctdb->vnn_map->generation != hdr->generation) {
            DEBUG(DEBUG_DEBUG,(__location__ " ctdb operation %u"
                               " request %u"
                               " length %u from node %u to %u had an"
                               " invalid generation id:%u while our"
                               " generation id is:%u\n",
                               hdr->operation, hdr->reqid,
                               hdr->length,
                               hdr->srcnode, hdr->destnode,
                               hdr->generation, ctdb->vnn_map->generation));
            goto done;
        }
    }

    switch (hdr->operation) {
    case CTDB_REQ_CALL:
        CTDB_INCREMENT_STAT(ctdb, node.req_call);
        ctdb_request_call(ctdb, hdr);
        break;

    case CTDB_REPLY_CALL:
        CTDB_INCREMENT_STAT(ctdb, node.reply_call);
        ctdb_reply_call(ctdb, hdr);
        break;

    case CTDB_REPLY_ERROR:
        CTDB_INCREMENT_STAT(ctdb, node.reply_error);
        ctdb_reply_error(ctdb, hdr);
        break;

    case CTDB_REQ_DMASTER:
        CTDB_INCREMENT_STAT(ctdb, node.req_dmaster);
        ctdb_request_dmaster(ctdb, hdr);
        break;

    case CTDB_REPLY_DMASTER:
        CTDB_INCREMENT_STAT(ctdb, node.reply_dmaster);
        ctdb_reply_dmaster(ctdb, hdr);
        break;

    case CTDB_REQ_MESSAGE:
        CTDB_INCREMENT_STAT(ctdb, node.req_message);
        ctdb_request_message(ctdb, hdr);
        break;

    case CTDB_REQ_CONTROL:
        CTDB_INCREMENT_STAT(ctdb, node.req_control);
        ctdb_request_control(ctdb, hdr);
        break;

    case CTDB_REPLY_CONTROL:
        CTDB_INCREMENT_STAT(ctdb, node.reply_control);
        ctdb_reply_control(ctdb, hdr);
        break;

    case CTDB_REQ_KEEPALIVE:
        CTDB_INCREMENT_STAT(ctdb, keepalive_packets_recv);
        break;

    default:
        DEBUG(DEBUG_CRIT,("%s: Packet with unknown operation %u\n",
                          __location__, hdr->operation));
        break;
    }

done:
    talloc_free(tmp_ctx);
}