mirror of
https://github.com/samba-team/samba.git
synced 2025-01-10 01:18:15 +03:00
factor out the packet allocation code
(This used to be ctdb commit 4cbaf22cc4bede8c95dd9b87e21bbe886307e23b)
This commit is contained in:
parent
a8de91b83f
commit
353a82f87c
@ -142,17 +142,11 @@ static void ctdb_send_error(struct ctdb_context *ctdb,
|
||||
|
||||
msglen = strlen(msg)+1;
|
||||
len = offsetof(struct ctdb_reply_error, msg);
|
||||
r = ctdb->methods->allocate_pkt(msg, len + msglen);
|
||||
r = ctdb_transport_allocate(ctdb, msg, CTDB_REPLY_ERROR, len + msglen,
|
||||
struct ctdb_reply_error);
|
||||
CTDB_NO_MEMORY_FATAL(ctdb, r);
|
||||
talloc_set_name_const(r, "send_error packet");
|
||||
|
||||
r->hdr.length = len + msglen;
|
||||
r->hdr.ctdb_magic = CTDB_MAGIC;
|
||||
r->hdr.ctdb_version = CTDB_VERSION;
|
||||
r->hdr.generation= ctdb->vnn_map->generation;
|
||||
r->hdr.operation = CTDB_REPLY_ERROR;
|
||||
r->hdr.destnode = hdr->srcnode;
|
||||
r->hdr.srcnode = ctdb->vnn;
|
||||
r->hdr.reqid = hdr->reqid;
|
||||
r->status = status;
|
||||
r->msglen = msglen;
|
||||
@ -173,16 +167,11 @@ static void ctdb_call_send_redirect(struct ctdb_context *ctdb,
|
||||
{
|
||||
struct ctdb_reply_redirect *r;
|
||||
|
||||
r = ctdb->methods->allocate_pkt(ctdb, sizeof(*r));
|
||||
r = ctdb_transport_allocate(ctdb, ctdb, CTDB_REPLY_REDIRECT, sizeof(*r),
|
||||
struct ctdb_reply_redirect);
|
||||
CTDB_NO_MEMORY_FATAL(ctdb, r);
|
||||
talloc_set_name_const(r, "send_redirect packet");
|
||||
r->hdr.length = sizeof(*r);
|
||||
r->hdr.ctdb_magic = CTDB_MAGIC;
|
||||
r->hdr.ctdb_version = CTDB_VERSION;
|
||||
r->hdr.generation= ctdb->vnn_map->generation;
|
||||
r->hdr.operation = CTDB_REPLY_REDIRECT;
|
||||
|
||||
r->hdr.destnode = c->hdr.srcnode;
|
||||
r->hdr.srcnode = ctdb->vnn;
|
||||
r->hdr.reqid = c->hdr.reqid;
|
||||
r->dmaster = header->dmaster;
|
||||
|
||||
@ -227,17 +216,11 @@ static void ctdb_send_dmaster_reply(struct ctdb_db_context *ctdb_db,
|
||||
|
||||
/* send the CTDB_REPLY_DMASTER */
|
||||
len = offsetof(struct ctdb_reply_dmaster, data) + data.dsize;
|
||||
r = ctdb->methods->allocate_pkt(tmp_ctx, len);
|
||||
r = ctdb_transport_allocate(ctdb, tmp_ctx, CTDB_REPLY_DMASTER, len,
|
||||
struct ctdb_reply_dmaster);
|
||||
CTDB_NO_MEMORY_FATAL(ctdb, r);
|
||||
|
||||
talloc_set_name_const(r, "reply_dmaster packet");
|
||||
r->hdr.length = len;
|
||||
r->hdr.ctdb_magic = CTDB_MAGIC;
|
||||
r->hdr.ctdb_version = CTDB_VERSION;
|
||||
r->hdr.generation= ctdb->vnn_map->generation;
|
||||
r->hdr.operation = CTDB_REPLY_DMASTER;
|
||||
r->hdr.destnode = new_dmaster;
|
||||
r->hdr.srcnode = ctdb->vnn;
|
||||
r->hdr.reqid = reqid;
|
||||
r->datalen = data.dsize;
|
||||
memcpy(&r->data[0], data.dptr, data.dsize);
|
||||
@ -271,16 +254,10 @@ static void ctdb_call_send_dmaster(struct ctdb_db_context *ctdb_db,
|
||||
}
|
||||
|
||||
len = offsetof(struct ctdb_req_dmaster, data) + key->dsize + data->dsize;
|
||||
r = ctdb->methods->allocate_pkt(ctdb, len);
|
||||
r = ctdb_transport_allocate(ctdb, ctdb, CTDB_REQ_DMASTER, len,
|
||||
struct ctdb_req_dmaster);
|
||||
CTDB_NO_MEMORY_FATAL(ctdb, r);
|
||||
talloc_set_name_const(r, "send_dmaster packet");
|
||||
r->hdr.length = len;
|
||||
r->hdr.ctdb_magic = CTDB_MAGIC;
|
||||
r->hdr.ctdb_version = CTDB_VERSION;
|
||||
r->hdr.generation= ctdb->vnn_map->generation;
|
||||
r->hdr.operation = CTDB_REQ_DMASTER;
|
||||
r->hdr.destnode = lmaster;
|
||||
r->hdr.srcnode = ctdb->vnn;
|
||||
r->hdr.reqid = c->hdr.reqid;
|
||||
r->db_id = c->db_id;
|
||||
r->dmaster = c->hdr.srcnode;
|
||||
@ -488,14 +465,9 @@ void ctdb_request_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr)
|
||||
ctdb_ltdb_unlock(ctdb_db, call.key);
|
||||
|
||||
len = offsetof(struct ctdb_reply_call, data) + call.reply_data.dsize;
|
||||
r = ctdb->methods->allocate_pkt(ctdb, len);
|
||||
r = ctdb_transport_allocate(ctdb, ctdb, CTDB_REPLY_CALL, len,
|
||||
struct ctdb_reply_call);
|
||||
CTDB_NO_MEMORY_FATAL(ctdb, r);
|
||||
talloc_set_name_const(r, "reply_call packet");
|
||||
r->hdr.length = len;
|
||||
r->hdr.ctdb_magic = CTDB_MAGIC;
|
||||
r->hdr.ctdb_version = CTDB_VERSION;
|
||||
r->hdr.generation= ctdb->vnn_map->generation;
|
||||
r->hdr.operation = CTDB_REPLY_CALL;
|
||||
r->hdr.destnode = hdr->srcnode;
|
||||
r->hdr.srcnode = hdr->destnode;
|
||||
r->hdr.reqid = hdr->reqid;
|
||||
@ -753,15 +725,9 @@ struct ctdb_call_state *ctdb_daemon_call_send_remote(struct ctdb_db_context *ctd
|
||||
talloc_set_destructor(state, ctdb_call_destructor);
|
||||
|
||||
len = offsetof(struct ctdb_req_call, data) + call->key.dsize + call->call_data.dsize;
|
||||
state->c = ctdb->methods->allocate_pkt(state, len);
|
||||
state->c = ctdb_transport_allocate(ctdb, state, CTDB_REQ_CALL, len,
|
||||
struct ctdb_req_call);
|
||||
CTDB_NO_MEMORY_NULL(ctdb, state->c);
|
||||
talloc_set_name_const(state->c, "req_call packet");
|
||||
|
||||
state->c->hdr.length = len;
|
||||
state->c->hdr.ctdb_magic = CTDB_MAGIC;
|
||||
state->c->hdr.ctdb_version = CTDB_VERSION;
|
||||
state->c->hdr.generation= ctdb_db->ctdb->vnn_map->generation;
|
||||
state->c->hdr.operation = CTDB_REQ_CALL;
|
||||
state->c->hdr.destnode = header->dmaster;
|
||||
/*
|
||||
always sending the remote call straight to the lmaster
|
||||
@ -771,7 +737,6 @@ struct ctdb_call_state *ctdb_daemon_call_send_remote(struct ctdb_db_context *ctd
|
||||
*/
|
||||
|
||||
|
||||
state->c->hdr.srcnode = ctdb->vnn;
|
||||
/* this limits us to 16k outstanding messages - not unreasonable */
|
||||
state->c->hdr.reqid = state->reqid;
|
||||
state->c->flags = call->flags;
|
||||
|
@ -322,18 +322,12 @@ struct ctdb_client_call_state *ctdb_call_send(struct ctdb_db_context *ctdb_db,
|
||||
}
|
||||
|
||||
len = offsetof(struct ctdb_req_call, data) + call->key.dsize + call->call_data.dsize;
|
||||
c = ctdbd_allocate_pkt(state, len);
|
||||
c = ctdbd_allocate_pkt(ctdb, state, CTDB_REQ_CALL, len, struct ctdb_req_call);
|
||||
if (c == NULL) {
|
||||
DEBUG(0, (__location__ " failed to allocate packet\n"));
|
||||
return NULL;
|
||||
}
|
||||
talloc_set_name_const(c, "ctdb client req_call packet");
|
||||
memset(c, 0, offsetof(struct ctdb_req_call, data));
|
||||
|
||||
c->hdr.length = len;
|
||||
c->hdr.ctdb_magic = CTDB_MAGIC;
|
||||
c->hdr.ctdb_version = CTDB_VERSION;
|
||||
c->hdr.operation = CTDB_REQ_CALL;
|
||||
/* this limits us to 16k outstanding messages - not unreasonable */
|
||||
c->hdr.reqid = ctdb_reqid_new(ctdb, state);
|
||||
c->flags = call->flags;
|
||||
@ -389,11 +383,9 @@ int ctdb_set_message_handler(struct ctdb_context *ctdb, uint64_t srvid,
|
||||
ctdb_socket_connect(ctdb);
|
||||
}
|
||||
|
||||
c = ctdbd_allocate_pkt(ctdb, sizeof(*c));
|
||||
c->hdr.length = sizeof(*c);
|
||||
c->hdr.ctdb_magic = CTDB_MAGIC;
|
||||
c->hdr.ctdb_version = CTDB_VERSION;
|
||||
c->hdr.operation = CTDB_REQ_REGISTER;
|
||||
c = ctdbd_allocate_pkt(ctdb, ctdb, CTDB_REQ_REGISTER, sizeof(*c),
|
||||
struct ctdb_req_register);
|
||||
CTDB_NO_MEMORY(ctdb, c);
|
||||
c->srvid = srvid;
|
||||
|
||||
res = ctdb_client_queue_pkt(ctdb, &c->hdr);
|
||||
@ -417,17 +409,12 @@ int ctdb_send_message(struct ctdb_context *ctdb, uint32_t vnn,
|
||||
int len, res;
|
||||
|
||||
len = offsetof(struct ctdb_req_message, data) + data.dsize;
|
||||
r = ctdbd_allocate_pkt(ctdb, len);
|
||||
r = ctdbd_allocate_pkt(ctdb, ctdb, CTDB_REQ_MESSAGE,
|
||||
len, struct ctdb_req_message);
|
||||
CTDB_NO_MEMORY(ctdb, r);
|
||||
talloc_set_name_const(r, "req_message packet");
|
||||
|
||||
r->hdr.length = len;
|
||||
r->hdr.ctdb_magic = CTDB_MAGIC;
|
||||
r->hdr.ctdb_version = CTDB_VERSION;
|
||||
r->hdr.operation = CTDB_REQ_MESSAGE;
|
||||
r->hdr.destnode = vnn;
|
||||
r->hdr.srcnode = ctdb->vnn;
|
||||
r->hdr.reqid = 0;
|
||||
r->srvid = srvid;
|
||||
r->datalen = data.dsize;
|
||||
memcpy(&r->data[0], data.dptr, data.dsize);
|
||||
@ -449,12 +436,9 @@ void ctdb_connect_wait(struct ctdb_context *ctdb)
|
||||
struct ctdb_req_connect_wait *r;
|
||||
int res;
|
||||
|
||||
r = ctdbd_allocate_pkt(ctdb, sizeof(*r));
|
||||
r->hdr.length = sizeof(*r);
|
||||
r->hdr.ctdb_magic = CTDB_MAGIC;
|
||||
r->hdr.ctdb_version = CTDB_VERSION;
|
||||
r->hdr.operation = CTDB_REQ_CONNECT_WAIT;
|
||||
r->hdr.generation= ctdb->vnn_map->generation;
|
||||
r = ctdbd_allocate_pkt(ctdb, ctdb, CTDB_REQ_CONNECT_WAIT, sizeof(*r),
|
||||
struct ctdb_req_connect_wait);
|
||||
CTDB_NO_MEMORY_VOID(ctdb, r);
|
||||
|
||||
DEBUG(3,("ctdb_connect_wait: sending to ctdbd\n"));
|
||||
|
||||
@ -604,13 +588,9 @@ void ctdb_shutdown(struct ctdb_context *ctdb)
|
||||
ctdb_socket_connect(ctdb);
|
||||
}
|
||||
|
||||
r = ctdbd_allocate_pkt(ctdb, sizeof(*r));
|
||||
ZERO_STRUCT(*r);
|
||||
r->hdr.length = sizeof(*r);
|
||||
r->hdr.ctdb_magic = CTDB_MAGIC;
|
||||
r->hdr.ctdb_version = CTDB_VERSION;
|
||||
r->hdr.operation = CTDB_REQ_SHUTDOWN;
|
||||
r->hdr.reqid = 0;
|
||||
r = ctdbd_allocate_pkt(ctdb, ctdb, CTDB_REQ_SHUTDOWN, sizeof(*r),
|
||||
struct ctdb_req_shutdown);
|
||||
CTDB_NO_MEMORY_VOID(ctdb, r);
|
||||
|
||||
ctdb_client_queue_pkt(ctdb, &(r->hdr));
|
||||
|
||||
@ -688,13 +668,10 @@ int ctdb_control(struct ctdb_context *ctdb, uint32_t destnode, uint64_t srvid,
|
||||
state->state = CTDB_CALL_WAIT;
|
||||
|
||||
len = offsetof(struct ctdb_req_control, data) + data.dsize;
|
||||
c = ctdbd_allocate_pkt(state, len);
|
||||
c = ctdbd_allocate_pkt(ctdb, state, CTDB_REQ_CONTROL,
|
||||
len, struct ctdb_req_control);
|
||||
CTDB_NO_MEMORY(ctdb, c);
|
||||
|
||||
memset(c, 0, len);
|
||||
c->hdr.length = len;
|
||||
c->hdr.ctdb_magic = CTDB_MAGIC;
|
||||
c->hdr.ctdb_version = CTDB_VERSION;
|
||||
c->hdr.operation = CTDB_REQ_CONTROL;
|
||||
c->hdr.reqid = state->reqid;
|
||||
c->hdr.destnode = destnode;
|
||||
c->hdr.srcnode = ctdb->vnn;
|
||||
|
@ -165,17 +165,10 @@ void ctdb_request_control(struct ctdb_context *ctdb, struct ctdb_req_header *hdr
|
||||
status = ctdb_control_dispatch(ctdb, c->opcode, data, outdata);
|
||||
|
||||
len = offsetof(struct ctdb_reply_control, data) + outdata->dsize;
|
||||
r = ctdb->methods->allocate_pkt(ctdb, len);
|
||||
r = ctdb_transport_allocate(ctdb, ctdb, CTDB_REPLY_CONTROL, len, struct ctdb_reply_control);
|
||||
CTDB_NO_MEMORY_VOID(ctdb, r);
|
||||
talloc_set_name_const(r, "ctdb_reply_control packet");
|
||||
|
||||
r->hdr.length = len;
|
||||
r->hdr.ctdb_magic = CTDB_MAGIC;
|
||||
r->hdr.ctdb_version = CTDB_VERSION;
|
||||
r->hdr.generation = ctdb->vnn_map->generation;
|
||||
r->hdr.operation = CTDB_REPLY_CONTROL;
|
||||
r->hdr.destnode = hdr->srcnode;
|
||||
r->hdr.srcnode = ctdb->vnn;
|
||||
r->hdr.reqid = hdr->reqid;
|
||||
r->status = status;
|
||||
r->datalen = outdata->dsize;
|
||||
@ -244,17 +237,12 @@ int ctdb_daemon_send_control(struct ctdb_context *ctdb, uint32_t destnode,
|
||||
talloc_set_destructor(state, ctdb_control_destructor);
|
||||
|
||||
len = offsetof(struct ctdb_req_control, data) + data.dsize;
|
||||
c = ctdb->methods->allocate_pkt(state, len);
|
||||
c = ctdb_transport_allocate(ctdb, state, CTDB_REQ_CONTROL, len,
|
||||
struct ctdb_req_control);
|
||||
CTDB_NO_MEMORY(ctdb, c);
|
||||
talloc_set_name_const(c, "ctdb_req_control packet");
|
||||
|
||||
c->hdr.length = len;
|
||||
c->hdr.ctdb_magic = CTDB_MAGIC;
|
||||
c->hdr.ctdb_version = CTDB_VERSION;
|
||||
c->hdr.generation= ctdb->vnn_map->generation;
|
||||
c->hdr.operation = CTDB_REQ_CONTROL;
|
||||
c->hdr.destnode = destnode;
|
||||
c->hdr.srcnode = ctdb->vnn;
|
||||
c->hdr.reqid = state->reqid;
|
||||
c->opcode = opcode;
|
||||
c->srvid = srvid;
|
||||
|
@ -114,17 +114,12 @@ static void daemon_message_handler(struct ctdb_context *ctdb, uint64_t srvid,
|
||||
|
||||
/* construct a message to send to the client containing the data */
|
||||
len = offsetof(struct ctdb_req_message, data) + data.dsize;
|
||||
r = ctdbd_allocate_pkt(ctdb, len);
|
||||
r = ctdbd_allocate_pkt(ctdb, ctdb, CTDB_REQ_MESSAGE,
|
||||
len, struct ctdb_req_message);
|
||||
CTDB_NO_MEMORY_VOID(ctdb, r);
|
||||
|
||||
talloc_set_name_const(r, "req_message packet");
|
||||
|
||||
memset(r, 0, offsetof(struct ctdb_req_message, data));
|
||||
|
||||
r->hdr.length = len;
|
||||
r->hdr.ctdb_magic = CTDB_MAGIC;
|
||||
r->hdr.ctdb_version = CTDB_VERSION;
|
||||
r->hdr.generation= ctdb->vnn_map->generation;
|
||||
r->hdr.operation = CTDB_REQ_MESSAGE;
|
||||
r->srvid = srvid;
|
||||
r->datalen = data.dsize;
|
||||
memcpy(&r->data[0], data.dptr, data.dsize);
|
||||
@ -181,19 +176,11 @@ static void daemon_request_shutdown(struct ctdb_client *client,
|
||||
}
|
||||
|
||||
len = sizeof(struct ctdb_req_finished);
|
||||
rf = ctdb->methods->allocate_pkt(ctdb, len);
|
||||
rf = ctdb_transport_allocate(ctdb, ctdb, CTDB_REQ_FINISHED, len,
|
||||
struct ctdb_req_finished);
|
||||
CTDB_NO_MEMORY_FATAL(ctdb, rf);
|
||||
talloc_set_name_const(rf, "ctdb_req_finished packet");
|
||||
|
||||
ZERO_STRUCT(*rf);
|
||||
rf->hdr.length = len;
|
||||
rf->hdr.ctdb_magic = CTDB_MAGIC;
|
||||
rf->hdr.ctdb_version = CTDB_VERSION;
|
||||
rf->hdr.generation= ctdb->vnn_map->generation;
|
||||
rf->hdr.operation = CTDB_REQ_FINISHED;
|
||||
rf->hdr.destnode = node;
|
||||
rf->hdr.srcnode = ctdb->vnn;
|
||||
rf->hdr.reqid = 0;
|
||||
|
||||
ctdb_queue_packet(ctdb, &(rf->hdr));
|
||||
|
||||
@ -225,12 +212,9 @@ static void daemon_request_connect_wait(struct ctdb_client *client,
|
||||
ctdb_daemon_connect_wait(client->ctdb);
|
||||
|
||||
/* now send the reply */
|
||||
r = ctdbd_allocate_pkt(client, sizeof(*r));
|
||||
r->hdr.length = sizeof(*r);
|
||||
r->hdr.ctdb_magic = CTDB_MAGIC;
|
||||
r->hdr.ctdb_version = CTDB_VERSION;
|
||||
r->hdr.generation= client->ctdb->vnn_map->generation;
|
||||
r->hdr.operation = CTDB_REPLY_CONNECT_WAIT;
|
||||
r = ctdbd_allocate_pkt(client->ctdb, client, CTDB_REPLY_CONNECT_WAIT, sizeof(*r),
|
||||
struct ctdb_reply_connect_wait);
|
||||
CTDB_NO_MEMORY_VOID(client->ctdb, r);
|
||||
r->vnn = ctdb_get_vnn(client->ctdb);
|
||||
r->num_connected = client->ctdb->num_connected;
|
||||
|
||||
@ -313,19 +297,14 @@ static void daemon_call_from_client_callback(struct ctdb_call_state *state)
|
||||
}
|
||||
|
||||
length = offsetof(struct ctdb_reply_call, data) + dstate->call->reply_data.dsize;
|
||||
r = ctdbd_allocate_pkt(dstate, length);
|
||||
r = ctdbd_allocate_pkt(client->ctdb, dstate, CTDB_REPLY_CALL,
|
||||
length, struct ctdb_reply_call);
|
||||
if (r == NULL) {
|
||||
DEBUG(0, (__location__ " Failed to allocate reply_call in ctdb daemon\n"));
|
||||
client->ctdb->status.pending_calls--;
|
||||
ctdb_latency(&client->ctdb->status.max_call_latency, dstate->start_time);
|
||||
return;
|
||||
}
|
||||
memset(r, 0, offsetof(struct ctdb_reply_call, data));
|
||||
r->hdr.length = length;
|
||||
r->hdr.ctdb_magic = CTDB_MAGIC;
|
||||
r->hdr.ctdb_version = CTDB_VERSION;
|
||||
r->hdr.generation = client->ctdb->vnn_map->generation;
|
||||
r->hdr.operation = CTDB_REPLY_CALL;
|
||||
r->hdr.reqid = dstate->reqid;
|
||||
r->datalen = dstate->call->reply_data.dsize;
|
||||
memcpy(&r->data[0], dstate->call->reply_data.dptr, r->datalen);
|
||||
@ -694,12 +673,61 @@ int ctdb_start(struct ctdb_context *ctdb)
|
||||
/*
|
||||
allocate a packet for use in client<->daemon communication
|
||||
*/
|
||||
void *ctdbd_allocate_pkt(TALLOC_CTX *mem_ctx, size_t len)
|
||||
struct ctdb_req_header *_ctdbd_allocate_pkt(struct ctdb_context *ctdb,
|
||||
TALLOC_CTX *mem_ctx,
|
||||
enum ctdb_operation operation,
|
||||
size_t length, size_t slength,
|
||||
const char *type)
|
||||
{
|
||||
int size;
|
||||
struct ctdb_req_header *hdr;
|
||||
size = ((length+1)+(CTDB_DS_ALIGNMENT-1)) & ~(CTDB_DS_ALIGNMENT-1);
|
||||
hdr = (struct ctdb_req_header *)talloc_size(mem_ctx, size);
|
||||
if (hdr == NULL) {
|
||||
DEBUG(0,("Unable to allocate packet for operation %u of length %u\n",
|
||||
operation, length));
|
||||
return NULL;
|
||||
}
|
||||
talloc_set_name_const(hdr, type);
|
||||
memset(hdr, 0, slength);
|
||||
hdr->operation = operation;
|
||||
hdr->length = length;
|
||||
hdr->ctdb_magic = CTDB_MAGIC;
|
||||
hdr->ctdb_version = CTDB_VERSION;
|
||||
hdr->generation = ctdb->vnn_map->generation;
|
||||
|
||||
size = (len+(CTDB_DS_ALIGNMENT-1)) & ~(CTDB_DS_ALIGNMENT-1);
|
||||
return talloc_size(mem_ctx, size);
|
||||
return hdr;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
allocate a packet for use in daemon<->daemon communication
|
||||
*/
|
||||
struct ctdb_req_header *_ctdb_transport_allocate(struct ctdb_context *ctdb,
|
||||
TALLOC_CTX *mem_ctx,
|
||||
enum ctdb_operation operation,
|
||||
size_t length, size_t slength,
|
||||
const char *type)
|
||||
{
|
||||
int size;
|
||||
struct ctdb_req_header *hdr;
|
||||
size = ((length+1)+(CTDB_DS_ALIGNMENT-1)) & ~(CTDB_DS_ALIGNMENT-1);
|
||||
hdr = (struct ctdb_req_header *)ctdb->methods->allocate_pkt(mem_ctx, size);
|
||||
if (hdr == NULL) {
|
||||
DEBUG(0,("Unable to allocate transport packet for operation %u of length %u\n",
|
||||
operation, length));
|
||||
return NULL;
|
||||
}
|
||||
talloc_set_name_const(hdr, type);
|
||||
memset(hdr, 0, slength);
|
||||
hdr->operation = operation;
|
||||
hdr->length = length;
|
||||
hdr->ctdb_magic = CTDB_MAGIC;
|
||||
hdr->ctdb_version = CTDB_VERSION;
|
||||
hdr->generation = ctdb->vnn_map->generation;
|
||||
hdr->srcnode = ctdb->vnn;
|
||||
|
||||
return hdr;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -732,16 +760,10 @@ static void daemon_control_callback(struct ctdb_context *ctdb,
|
||||
|
||||
/* construct a message to send to the client containing the data */
|
||||
len = offsetof(struct ctdb_reply_control, data) + data.dsize;
|
||||
r = ctdbd_allocate_pkt(client, len);
|
||||
talloc_set_name_const(r, "reply_control packet");
|
||||
r = ctdbd_allocate_pkt(ctdb, client, CTDB_REPLY_CONTROL, len,
|
||||
struct ctdb_reply_control);
|
||||
CTDB_NO_MEMORY_VOID(ctdb, r);
|
||||
|
||||
memset(r, 0, offsetof(struct ctdb_reply_control, data));
|
||||
|
||||
r->hdr.length = len;
|
||||
r->hdr.ctdb_magic = CTDB_MAGIC;
|
||||
r->hdr.ctdb_version = CTDB_VERSION;
|
||||
r->hdr.generation= ctdb->vnn_map->generation;
|
||||
r->hdr.operation = CTDB_REPLY_CONTROL;
|
||||
r->hdr.reqid = state->reqid;
|
||||
r->status = status;
|
||||
r->datalen = data.dsize;
|
||||
|
@ -120,18 +120,11 @@ int ctdb_daemon_send_message(struct ctdb_context *ctdb, uint32_t vnn,
|
||||
}
|
||||
|
||||
len = offsetof(struct ctdb_req_message, data) + data.dsize;
|
||||
r = ctdb->methods->allocate_pkt(ctdb, len);
|
||||
r = ctdb_transport_allocate(ctdb, ctdb, CTDB_REQ_MESSAGE, len,
|
||||
struct ctdb_req_message);
|
||||
CTDB_NO_MEMORY(ctdb, r);
|
||||
talloc_set_name_const(r, "req_message packet");
|
||||
|
||||
r->hdr.length = len;
|
||||
r->hdr.ctdb_magic = CTDB_MAGIC;
|
||||
r->hdr.ctdb_version = CTDB_VERSION;
|
||||
r->hdr.generation= ctdb->vnn_map->generation;
|
||||
r->hdr.operation = CTDB_REQ_MESSAGE;
|
||||
r->hdr.destnode = vnn;
|
||||
r->hdr.srcnode = ctdb->vnn;
|
||||
r->hdr.reqid = 0;
|
||||
r->srvid = srvid;
|
||||
r->datalen = data.dsize;
|
||||
memcpy(&r->data[0], data.dptr, data.dsize);
|
||||
|
@ -160,3 +160,4 @@ void ctdb_reqid_remove(struct ctdb_context *ctdb, uint32_t reqid)
|
||||
DEBUG(0, ("Removing idr that does not exist\n"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -488,7 +488,21 @@ struct ctdb_queue *ctdb_queue_setup(struct ctdb_context *ctdb,
|
||||
/*
|
||||
allocate a packet for use in client<->daemon communication
|
||||
*/
|
||||
void *ctdbd_allocate_pkt(TALLOC_CTX *mem_ctx, size_t len);
|
||||
struct ctdb_req_header *_ctdbd_allocate_pkt(struct ctdb_context *ctdb,
|
||||
TALLOC_CTX *mem_ctx,
|
||||
enum ctdb_operation operation,
|
||||
size_t length, size_t slength,
|
||||
const char *type);
|
||||
#define ctdbd_allocate_pkt(ctdb, mem_ctx, operation, length, type) \
|
||||
(type *)_ctdbd_allocate_pkt(ctdb, mem_ctx, operation, length, sizeof(type), #type)
|
||||
|
||||
struct ctdb_req_header *_ctdb_transport_allocate(struct ctdb_context *ctdb,
|
||||
TALLOC_CTX *mem_ctx,
|
||||
enum ctdb_operation operation,
|
||||
size_t length, size_t slength,
|
||||
const char *type);
|
||||
#define ctdb_transport_allocate(ctdb, mem_ctx, operation, length, type) \
|
||||
(type *)_ctdb_transport_allocate(ctdb, mem_ctx, operation, length, sizeof(type), #type)
|
||||
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user