mirror of
https://github.com/samba-team/samba.git
synced 2025-02-26 21:57:41 +03:00
added error messages in ctdb_control replies
(This used to be ctdb commit bd848f5b760e6b2a73ebfc67fd8adb3c31479fb5)
This commit is contained in:
parent
58dc8d4e19
commit
81826da2df
@ -380,7 +380,7 @@ int ctdb_set_message_handler(struct ctdb_context *ctdb, uint64_t srvid,
|
||||
int32_t status;
|
||||
|
||||
res = ctdb_control(ctdb, CTDB_CURRENT_NODE, srvid, CTDB_CONTROL_REGISTER_SRVID, 0,
|
||||
tdb_null, NULL, NULL, &status, NULL);
|
||||
tdb_null, NULL, NULL, &status, NULL, NULL);
|
||||
if (res != 0 || status != 0) {
|
||||
DEBUG(0,("Failed to register srvid %llu\n", (unsigned long long)srvid));
|
||||
return -1;
|
||||
@ -399,7 +399,7 @@ int ctdb_remove_message_handler(struct ctdb_context *ctdb, uint64_t srvid, void
|
||||
int32_t status;
|
||||
|
||||
res = ctdb_control(ctdb, CTDB_CURRENT_NODE, srvid, CTDB_CONTROL_DEREGISTER_SRVID, 0,
|
||||
tdb_null, NULL, NULL, &status, NULL);
|
||||
tdb_null, NULL, NULL, &status, NULL, NULL);
|
||||
if (res != 0 || status != 0) {
|
||||
DEBUG(0,("Failed to deregister srvid %llu\n", (unsigned long long)srvid));
|
||||
return -1;
|
||||
@ -620,6 +620,7 @@ struct ctdb_client_control_state {
|
||||
int32_t status;
|
||||
TDB_DATA outdata;
|
||||
enum call_state state;
|
||||
char *errormsg;
|
||||
};
|
||||
|
||||
/*
|
||||
@ -649,6 +650,11 @@ static void ctdb_client_reply_control(struct ctdb_context *ctdb,
|
||||
state->outdata.dptr = c->data;
|
||||
state->outdata.dsize = c->datalen;
|
||||
state->status = c->status;
|
||||
if (c->errorlen) {
|
||||
state->errormsg = talloc_strndup(state,
|
||||
(char *)&c->data[c->datalen],
|
||||
c->errorlen);
|
||||
}
|
||||
|
||||
talloc_steal(state, c);
|
||||
|
||||
@ -682,7 +688,8 @@ static int ctdb_control_destructor(struct ctdb_client_control_state *state)
|
||||
int ctdb_control(struct ctdb_context *ctdb, uint32_t destnode, uint64_t srvid,
|
||||
uint32_t opcode, uint32_t flags, TDB_DATA data,
|
||||
TALLOC_CTX *mem_ctx, TDB_DATA *outdata, int32_t *status,
|
||||
struct timeval *timeout)
|
||||
struct timeval *timeout,
|
||||
char **errormsg)
|
||||
{
|
||||
struct ctdb_client_control_state *state;
|
||||
struct ctdb_req_control *c;
|
||||
@ -690,6 +697,10 @@ int ctdb_control(struct ctdb_context *ctdb, uint32_t destnode, uint64_t srvid,
|
||||
int ret;
|
||||
uint32_t timed_out;
|
||||
|
||||
if (errormsg) {
|
||||
*errormsg = NULL;
|
||||
}
|
||||
|
||||
/* if the domain socket is not yet open, open it */
|
||||
if (ctdb->daemon.sd==-1) {
|
||||
ctdb_socket_connect(ctdb);
|
||||
@ -701,6 +712,7 @@ int ctdb_control(struct ctdb_context *ctdb, uint32_t destnode, uint64_t srvid,
|
||||
state->ctdb = ctdb;
|
||||
state->reqid = ctdb_reqid_new(ctdb, state);
|
||||
state->state = CTDB_CALL_WAIT;
|
||||
state->errormsg = NULL;
|
||||
|
||||
talloc_set_destructor(state, ctdb_control_destructor);
|
||||
|
||||
@ -753,6 +765,14 @@ int ctdb_control(struct ctdb_context *ctdb, uint32_t destnode, uint64_t srvid,
|
||||
|
||||
*status = state->status;
|
||||
|
||||
if (!errormsg && state->errormsg) {
|
||||
DEBUG(0,("ctdb_control error: '%s'\n", state->errormsg));
|
||||
}
|
||||
|
||||
if (errormsg && state->errormsg) {
|
||||
(*errormsg) = talloc_move(mem_ctx, &state->errormsg);
|
||||
}
|
||||
|
||||
talloc_free(state);
|
||||
|
||||
return 0;
|
||||
@ -774,7 +794,7 @@ int ctdb_ctrl_process_exists(struct ctdb_context *ctdb, uint32_t destnode, pid_t
|
||||
|
||||
ret = ctdb_control(ctdb, destnode, 0,
|
||||
CTDB_CONTROL_PROCESS_EXISTS, 0, data,
|
||||
NULL, NULL, &status, NULL);
|
||||
NULL, NULL, &status, NULL, NULL);
|
||||
if (ret != 0) {
|
||||
DEBUG(0,(__location__ " ctdb_control for process_exists failed\n"));
|
||||
return -1;
|
||||
@ -795,7 +815,7 @@ int ctdb_ctrl_status(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_s
|
||||
ZERO_STRUCT(data);
|
||||
ret = ctdb_control(ctdb, destnode, 0,
|
||||
CTDB_CONTROL_STATUS, 0, data,
|
||||
ctdb, &data, &res, NULL);
|
||||
ctdb, &data, &res, NULL, NULL);
|
||||
if (ret != 0 || res != 0) {
|
||||
DEBUG(0,(__location__ " ctdb_control for status failed\n"));
|
||||
return -1;
|
||||
@ -826,7 +846,7 @@ int ctdb_ctrl_getvnnmap(struct ctdb_context *ctdb, struct timeval timeout, uint3
|
||||
ZERO_STRUCT(data);
|
||||
ret = ctdb_control(ctdb, destnode, 0,
|
||||
CTDB_CONTROL_GETVNNMAP, 0, data,
|
||||
mem_ctx, &outdata, &res, &timeout);
|
||||
mem_ctx, &outdata, &res, &timeout, NULL);
|
||||
if (ret != 0 || res != 0) {
|
||||
DEBUG(0,(__location__ " ctdb_control for getvnnmap failed\n"));
|
||||
return -1;
|
||||
@ -863,7 +883,7 @@ int ctdb_ctrl_getrecmode(struct ctdb_context *ctdb, struct timeval timeout, uint
|
||||
ZERO_STRUCT(data);
|
||||
ret = ctdb_control(ctdb, destnode, 0,
|
||||
CTDB_CONTROL_GET_RECMODE, 0, data,
|
||||
ctdb, &outdata, &res, &timeout);
|
||||
ctdb, &outdata, &res, &timeout, NULL);
|
||||
if (ret != 0) {
|
||||
DEBUG(0,(__location__ " ctdb_control for getrecmode failed\n"));
|
||||
return -1;
|
||||
@ -888,7 +908,7 @@ int ctdb_ctrl_setrecmode(struct ctdb_context *ctdb, struct timeval timeout, uint
|
||||
|
||||
ret = ctdb_control(ctdb, destnode, 0,
|
||||
CTDB_CONTROL_SET_RECMODE, 0, data,
|
||||
ctdb, &outdata, &res, &timeout);
|
||||
ctdb, &outdata, &res, &timeout, NULL);
|
||||
if (ret != 0 || res != 0) {
|
||||
DEBUG(0,(__location__ " ctdb_control for setrecmode failed\n"));
|
||||
return -1;
|
||||
@ -909,7 +929,7 @@ int ctdb_ctrl_getrecmaster(struct ctdb_context *ctdb, struct timeval timeout, ui
|
||||
ZERO_STRUCT(data);
|
||||
ret = ctdb_control(ctdb, destnode, 0,
|
||||
CTDB_CONTROL_GET_RECMASTER, 0, data,
|
||||
ctdb, &outdata, &res, &timeout);
|
||||
ctdb, &outdata, &res, &timeout, NULL);
|
||||
if (ret != 0) {
|
||||
DEBUG(0,(__location__ " ctdb_control for getrecmaster failed\n"));
|
||||
return -1;
|
||||
@ -935,7 +955,7 @@ int ctdb_ctrl_setrecmaster(struct ctdb_context *ctdb, struct timeval timeout, ui
|
||||
|
||||
ret = ctdb_control(ctdb, destnode, 0,
|
||||
CTDB_CONTROL_SET_RECMASTER, 0, data,
|
||||
ctdb, &outdata, &res, &timeout);
|
||||
ctdb, &outdata, &res, &timeout, NULL);
|
||||
if (ret != 0 || res != 0) {
|
||||
DEBUG(0,(__location__ " ctdb_control for setrecmaster failed\n"));
|
||||
return -1;
|
||||
@ -957,7 +977,7 @@ int ctdb_ctrl_getdbmap(struct ctdb_context *ctdb, struct timeval timeout, uint32
|
||||
ZERO_STRUCT(data);
|
||||
ret = ctdb_control(ctdb, destnode, 0,
|
||||
CTDB_CONTROL_GET_DBMAP, 0, data,
|
||||
mem_ctx, &outdata, &res, &timeout);
|
||||
mem_ctx, &outdata, &res, &timeout, NULL);
|
||||
if (ret != 0 || res != 0) {
|
||||
DEBUG(0,(__location__ " ctdb_control for getdbmap failed\n"));
|
||||
return -1;
|
||||
@ -983,7 +1003,7 @@ int ctdb_ctrl_getnodemap(struct ctdb_context *ctdb,
|
||||
ZERO_STRUCT(data);
|
||||
ret = ctdb_control(ctdb, destnode, 0,
|
||||
CTDB_CONTROL_GET_NODEMAP, 0, data,
|
||||
mem_ctx, &outdata, &res, &timeout);
|
||||
mem_ctx, &outdata, &res, &timeout, NULL);
|
||||
if (ret != 0 || res != 0) {
|
||||
DEBUG(0,(__location__ " ctdb_control for getnodes failed\n"));
|
||||
return -1;
|
||||
@ -1018,7 +1038,7 @@ int ctdb_ctrl_setvnnmap(struct ctdb_context *ctdb, struct timeval timeout, uint3
|
||||
|
||||
ret = ctdb_control(ctdb, destnode, 0,
|
||||
CTDB_CONTROL_SETVNNMAP, 0, data,
|
||||
mem_ctx, &outdata, &res, &timeout);
|
||||
mem_ctx, &outdata, &res, &timeout, NULL);
|
||||
if (ret != 0 || res != 0) {
|
||||
DEBUG(0,(__location__ " ctdb_control for setvnnmap failed\n"));
|
||||
return -1;
|
||||
@ -1049,7 +1069,7 @@ int ctdb_ctrl_pulldb(struct ctdb_context *ctdb, uint32_t destnode, uint32_t dbid
|
||||
|
||||
ret = ctdb_control(ctdb, destnode, 0,
|
||||
CTDB_CONTROL_PULL_DB, 0, indata,
|
||||
mem_ctx, &outdata, &res, NULL);
|
||||
mem_ctx, &outdata, &res, NULL, NULL);
|
||||
if (ret != 0 || res != 0) {
|
||||
DEBUG(0,(__location__ " ctdb_control for pulldb failed\n"));
|
||||
return -1;
|
||||
@ -1105,7 +1125,7 @@ int ctdb_ctrl_copydb(struct ctdb_context *ctdb, struct timeval timeout, uint32_t
|
||||
|
||||
ret = ctdb_control(ctdb, sourcenode, 0,
|
||||
CTDB_CONTROL_PULL_DB, 0, indata,
|
||||
mem_ctx, &outdata, &res, &timeout);
|
||||
mem_ctx, &outdata, &res, &timeout, NULL);
|
||||
if (ret != 0 || res != 0) {
|
||||
DEBUG(0,(__location__ " ctdb_control for pulldb failed\n"));
|
||||
return -1;
|
||||
@ -1113,7 +1133,7 @@ int ctdb_ctrl_copydb(struct ctdb_context *ctdb, struct timeval timeout, uint32_t
|
||||
|
||||
ret = ctdb_control(ctdb, destnode, 0,
|
||||
CTDB_CONTROL_PUSH_DB, 0, outdata,
|
||||
mem_ctx, NULL, &res, &timeout);
|
||||
mem_ctx, NULL, &res, &timeout, NULL);
|
||||
if (ret != 0 || res != 0) {
|
||||
DEBUG(0,(__location__ " ctdb_control for pushdb failed\n"));
|
||||
return -1;
|
||||
@ -1139,7 +1159,7 @@ int ctdb_ctrl_setdmaster(struct ctdb_context *ctdb, struct timeval timeout, uint
|
||||
|
||||
ret = ctdb_control(ctdb, destnode, 0,
|
||||
CTDB_CONTROL_SET_DMASTER, 0, indata,
|
||||
mem_ctx, &outdata, &res, &timeout);
|
||||
mem_ctx, &outdata, &res, &timeout, NULL);
|
||||
if (ret != 0 || res != 0) {
|
||||
DEBUG(0,(__location__ " ctdb_control for setdmaster failed\n"));
|
||||
return -1;
|
||||
@ -1164,7 +1184,7 @@ int ctdb_ctrl_cleardb(struct ctdb_context *ctdb, uint32_t destnode, TALLOC_CTX *
|
||||
|
||||
ret = ctdb_control(ctdb, destnode, 0,
|
||||
CTDB_CONTROL_CLEAR_DB, 0, indata,
|
||||
mem_ctx, &outdata, &res, NULL);
|
||||
mem_ctx, &outdata, &res, NULL, NULL);
|
||||
if (ret != 0 || res != 0) {
|
||||
DEBUG(0,(__location__ " ctdb_control for cleardb failed\n"));
|
||||
return -1;
|
||||
@ -1184,7 +1204,7 @@ int ctdb_ctrl_ping(struct ctdb_context *ctdb, uint32_t destnode)
|
||||
|
||||
ZERO_STRUCT(data);
|
||||
ret = ctdb_control(ctdb, destnode, 0, CTDB_CONTROL_PING, 0,
|
||||
data, NULL, NULL, &res, NULL);
|
||||
data, NULL, NULL, &res, NULL, NULL);
|
||||
if (ret != 0) {
|
||||
return -1;
|
||||
}
|
||||
@ -1203,7 +1223,7 @@ int ctdb_ctrl_get_config(struct ctdb_context *ctdb)
|
||||
|
||||
ZERO_STRUCT(data);
|
||||
ret = ctdb_control(ctdb, CTDB_CURRENT_NODE, 0, CTDB_CONTROL_CONFIG, 0,
|
||||
data, ctdb, &data, &res, NULL);
|
||||
data, ctdb, &data, &res, NULL, NULL);
|
||||
if (ret != 0 || res != 0) {
|
||||
return -1;
|
||||
}
|
||||
@ -1238,7 +1258,7 @@ int ctdb_ctrl_getdbpath(struct ctdb_context *ctdb, struct timeval timeout, uint3
|
||||
|
||||
ret = ctdb_control(ctdb, destnode, 0,
|
||||
CTDB_CONTROL_GETDBPATH, 0, data,
|
||||
mem_ctx, &data, &res, &timeout);
|
||||
mem_ctx, &data, &res, &timeout, NULL);
|
||||
if (ret != 0 || res != 0) {
|
||||
return -1;
|
||||
}
|
||||
@ -1268,7 +1288,7 @@ int ctdb_ctrl_getdbname(struct ctdb_context *ctdb, struct timeval timeout, uint3
|
||||
|
||||
ret = ctdb_control(ctdb, destnode, 0,
|
||||
CTDB_CONTROL_GET_DBNAME, 0, data,
|
||||
mem_ctx, &data, &res, &timeout);
|
||||
mem_ctx, &data, &res, &timeout, NULL);
|
||||
if (ret != 0 || res != 0) {
|
||||
return -1;
|
||||
}
|
||||
@ -1297,7 +1317,7 @@ int ctdb_ctrl_createdb(struct ctdb_context *ctdb, struct timeval timeout, uint32
|
||||
|
||||
ret = ctdb_control(ctdb, destnode, 0,
|
||||
CTDB_CONTROL_DB_ATTACH, 0, data,
|
||||
mem_ctx, &data, &res, &timeout);
|
||||
mem_ctx, &data, &res, &timeout, NULL);
|
||||
|
||||
if (ret != 0 || res != 0) {
|
||||
return -1;
|
||||
@ -1317,7 +1337,7 @@ int ctdb_ctrl_get_debuglevel(struct ctdb_context *ctdb, uint32_t destnode, uint3
|
||||
|
||||
ZERO_STRUCT(data);
|
||||
ret = ctdb_control(ctdb, destnode, 0, CTDB_CONTROL_GET_DEBUG, 0, data,
|
||||
ctdb, &data, &res, NULL);
|
||||
ctdb, &data, &res, NULL, NULL);
|
||||
if (ret != 0 || res != 0) {
|
||||
return -1;
|
||||
}
|
||||
@ -1344,7 +1364,7 @@ int ctdb_ctrl_set_debuglevel(struct ctdb_context *ctdb, uint32_t destnode, uint3
|
||||
data.dsize = sizeof(level);
|
||||
|
||||
ret = ctdb_control(ctdb, destnode, 0, CTDB_CONTROL_SET_DEBUG, 0, data,
|
||||
NULL, NULL, &res, NULL);
|
||||
NULL, NULL, &res, NULL, NULL);
|
||||
if (ret != 0 || res != 0) {
|
||||
return -1;
|
||||
}
|
||||
@ -1399,7 +1419,7 @@ int ctdb_status_reset(struct ctdb_context *ctdb, uint32_t destnode)
|
||||
ZERO_STRUCT(data);
|
||||
ret = ctdb_control(ctdb, destnode, 0,
|
||||
CTDB_CONTROL_STATUS_RESET, 0, data,
|
||||
NULL, NULL, &res, NULL);
|
||||
NULL, NULL, &res, NULL, NULL);
|
||||
if (ret != 0 || res != 0) {
|
||||
DEBUG(0,(__location__ " ctdb_control for reset status failed\n"));
|
||||
return -1;
|
||||
@ -1430,7 +1450,7 @@ struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb, const char *name)
|
||||
|
||||
/* tell ctdb daemon to attach */
|
||||
ret = ctdb_control(ctdb, CTDB_CURRENT_NODE, 0, CTDB_CONTROL_DB_ATTACH,
|
||||
0, data, ctdb_db, &data, &res, NULL);
|
||||
0, data, ctdb_db, &data, &res, NULL, NULL);
|
||||
if (ret != 0 || res != 0 || data.dsize != sizeof(uint32_t)) {
|
||||
DEBUG(0,("Failed to attach to database '%s'\n", name));
|
||||
talloc_free(ctdb_db);
|
||||
@ -1478,7 +1498,7 @@ int ctdb_set_call(struct ctdb_db_context *ctdb_db, ctdb_fn_t fn, uint32_t id)
|
||||
data.dsize = sizeof(c);
|
||||
|
||||
ret = ctdb_control(ctdb_db->ctdb, CTDB_CURRENT_NODE, 0, CTDB_CONTROL_SET_CALL, 0,
|
||||
data, NULL, NULL, &status, NULL);
|
||||
data, NULL, NULL, &status, NULL, NULL);
|
||||
if (ret != 0 || status != 0) {
|
||||
DEBUG(0,("ctdb_set_call failed for call %u\n", id));
|
||||
return -1;
|
||||
@ -1568,7 +1588,7 @@ int ctdb_traverse(struct ctdb_db_context *ctdb_db, ctdb_traverse_func fn, void *
|
||||
data.dsize = sizeof(t);
|
||||
|
||||
ret = ctdb_control(ctdb_db->ctdb, CTDB_CURRENT_NODE, 0, CTDB_CONTROL_TRAVERSE_START, 0,
|
||||
data, NULL, NULL, &status, NULL);
|
||||
data, NULL, NULL, &status, NULL, NULL);
|
||||
if (ret != 0 || status != 0) {
|
||||
DEBUG(0,("ctdb_traverse_all failed\n"));
|
||||
ctdb_remove_message_handler(ctdb_db->ctdb, srvid, &state);
|
||||
@ -1629,7 +1649,7 @@ int ctdb_ctrl_getpid(struct ctdb_context *ctdb, struct timeval timeout, uint32_t
|
||||
ZERO_STRUCT(data);
|
||||
ret = ctdb_control(ctdb, destnode, 0,
|
||||
CTDB_CONTROL_GET_PID, 0, data,
|
||||
ctdb, &outdata, &res, &timeout);
|
||||
ctdb, &outdata, &res, &timeout, NULL);
|
||||
if (ret != 0) {
|
||||
DEBUG(0,(__location__ " ctdb_control for getpid failed\n"));
|
||||
return -1;
|
||||
@ -1651,7 +1671,7 @@ int ctdb_ctrl_freeze(struct ctdb_context *ctdb, struct timeval timeout, uint32_t
|
||||
|
||||
ret = ctdb_control(ctdb, destnode, 0,
|
||||
CTDB_CONTROL_FREEZE, 0, tdb_null,
|
||||
NULL, NULL, &res, &timeout);
|
||||
NULL, NULL, &res, &timeout, NULL);
|
||||
if (ret != 0 || res != 0) {
|
||||
DEBUG(0,(__location__ " ctdb_control freeze failed\n"));
|
||||
return -1;
|
||||
@ -1670,7 +1690,7 @@ int ctdb_ctrl_thaw(struct ctdb_context *ctdb, struct timeval timeout, uint32_t d
|
||||
|
||||
ret = ctdb_control(ctdb, destnode, 0,
|
||||
CTDB_CONTROL_THAW, 0, tdb_null,
|
||||
NULL, NULL, &res, &timeout);
|
||||
NULL, NULL, &res, &timeout, NULL);
|
||||
if (ret != 0 || res != 0) {
|
||||
DEBUG(0,(__location__ " ctdb_control thaw failed\n"));
|
||||
return -1;
|
||||
|
@ -41,6 +41,7 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
|
||||
struct ctdb_req_control *c,
|
||||
TDB_DATA indata,
|
||||
TDB_DATA *outdata, uint32_t srcnode,
|
||||
const char **errormsg,
|
||||
bool *async_reply)
|
||||
{
|
||||
uint32_t opcode = c->opcode;
|
||||
@ -232,7 +233,7 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
|
||||
|
||||
case CTDB_CONTROL_SET_RECMODE:
|
||||
CHECK_CONTROL_DATA_SIZE(sizeof(uint32_t));
|
||||
return ctdb_control_set_recmode(ctdb, indata);
|
||||
return ctdb_control_set_recmode(ctdb, indata, errormsg);
|
||||
|
||||
default:
|
||||
DEBUG(0,(__location__ " Unknown CTDB control opcode %u\n", opcode));
|
||||
@ -245,17 +246,20 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
|
||||
send a reply for a ctdb control
|
||||
*/
|
||||
void ctdb_request_control_reply(struct ctdb_context *ctdb, struct ctdb_req_control *c,
|
||||
TDB_DATA *outdata, int32_t status)
|
||||
TDB_DATA *outdata, int32_t status, const char *errormsg)
|
||||
{
|
||||
struct ctdb_reply_control *r;
|
||||
size_t len;
|
||||
|
||||
|
||||
/* some controls send no reply */
|
||||
if (c->flags & CTDB_CTRL_FLAG_NOREPLY) {
|
||||
return;
|
||||
}
|
||||
|
||||
len = offsetof(struct ctdb_reply_control, data) + (outdata?outdata->dsize:0);
|
||||
if (errormsg) {
|
||||
len += strlen(errormsg);
|
||||
}
|
||||
r = ctdb_transport_allocate(ctdb, ctdb, CTDB_REPLY_CONTROL, len, struct ctdb_reply_control);
|
||||
CTDB_NO_MEMORY_VOID(ctdb, r);
|
||||
|
||||
@ -266,6 +270,10 @@ void ctdb_request_control_reply(struct ctdb_context *ctdb, struct ctdb_req_contr
|
||||
if (outdata && outdata->dsize) {
|
||||
memcpy(&r->data[0], outdata->dptr, outdata->dsize);
|
||||
}
|
||||
if (errormsg) {
|
||||
r->errorlen = strlen(errormsg);
|
||||
memcpy(&r->data[r->datalen], errormsg, r->errorlen);
|
||||
}
|
||||
|
||||
ctdb_queue_packet(ctdb, &r->hdr);
|
||||
|
||||
@ -281,16 +289,18 @@ void ctdb_request_control(struct ctdb_context *ctdb, struct ctdb_req_header *hdr
|
||||
TDB_DATA data, *outdata;
|
||||
int32_t status;
|
||||
bool async_reply = False;
|
||||
const char *errormsg = NULL;
|
||||
|
||||
data.dptr = &c->data[0];
|
||||
data.dsize = c->datalen;
|
||||
|
||||
outdata = talloc_zero(c, TDB_DATA);
|
||||
|
||||
status = ctdb_control_dispatch(ctdb, c, data, outdata, hdr->srcnode, &async_reply);
|
||||
status = ctdb_control_dispatch(ctdb, c, data, outdata, hdr->srcnode,
|
||||
&errormsg, &async_reply);
|
||||
|
||||
if (!async_reply) {
|
||||
ctdb_request_control_reply(ctdb, c, outdata, status);
|
||||
ctdb_request_control_reply(ctdb, c, outdata, status, errormsg);
|
||||
}
|
||||
}
|
||||
|
||||
@ -302,6 +312,7 @@ void ctdb_reply_control(struct ctdb_context *ctdb, struct ctdb_req_header *hdr)
|
||||
struct ctdb_reply_control *c = (struct ctdb_reply_control *)hdr;
|
||||
TDB_DATA data;
|
||||
struct ctdb_control_state *state;
|
||||
const char *errormsg = NULL;
|
||||
|
||||
state = ctdb_reqid_find(ctdb, hdr->reqid, struct ctdb_control_state);
|
||||
if (state == NULL) {
|
||||
@ -318,12 +329,16 @@ void ctdb_reply_control(struct ctdb_context *ctdb, struct ctdb_req_header *hdr)
|
||||
|
||||
data.dptr = &c->data[0];
|
||||
data.dsize = c->datalen;
|
||||
if (c->errorlen) {
|
||||
errormsg = talloc_strndup(state,
|
||||
(char *)&c->data[c->datalen], c->errorlen);
|
||||
}
|
||||
|
||||
/* make state a child of the packet, so it goes away when the packet
|
||||
is freed. */
|
||||
talloc_steal(hdr, state);
|
||||
|
||||
state->callback(ctdb, c->status, data, state->private_data);
|
||||
state->callback(ctdb, c->status, data, errormsg, state->private_data);
|
||||
}
|
||||
|
||||
static int ctdb_control_destructor(struct ctdb_control_state *state)
|
||||
@ -345,7 +360,8 @@ static void ctdb_control_timeout(struct event_context *ev, struct timed_event *t
|
||||
|
||||
talloc_steal(tmp_ctx, state);
|
||||
|
||||
state->callback(state->ctdb, -1, tdb_null, state->private_data);
|
||||
state->callback(state->ctdb, -1, tdb_null, "ctdb_control timed out",
|
||||
state->private_data);
|
||||
talloc_free(tmp_ctx);
|
||||
}
|
||||
|
||||
|
@ -825,6 +825,7 @@ struct daemon_control_state {
|
||||
*/
|
||||
static void daemon_control_callback(struct ctdb_context *ctdb,
|
||||
uint32_t status, TDB_DATA data,
|
||||
const char *errormsg,
|
||||
void *private_data)
|
||||
{
|
||||
struct daemon_control_state *state = talloc_get_type(private_data,
|
||||
@ -835,6 +836,9 @@ 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;
|
||||
if (errormsg) {
|
||||
len += strlen(errormsg);
|
||||
}
|
||||
r = ctdbd_allocate_pkt(ctdb, state, CTDB_REPLY_CONTROL, len,
|
||||
struct ctdb_reply_control);
|
||||
CTDB_NO_MEMORY_VOID(ctdb, r);
|
||||
@ -842,7 +846,12 @@ static void daemon_control_callback(struct ctdb_context *ctdb,
|
||||
r->hdr.reqid = state->reqid;
|
||||
r->status = status;
|
||||
r->datalen = data.dsize;
|
||||
r->errorlen = 0;
|
||||
memcpy(&r->data[0], data.dptr, data.dsize);
|
||||
if (errormsg) {
|
||||
r->errorlen = strlen(errormsg);
|
||||
memcpy(&r->data[r->datalen], errormsg, r->errorlen);
|
||||
}
|
||||
|
||||
daemon_queue_send(client, &r->hdr);
|
||||
|
||||
|
@ -177,7 +177,7 @@ static struct ctdb_freeze_handle *ctdb_freeze_lock(struct ctdb_context *ctdb)
|
||||
static int ctdb_freeze_waiter_destructor(struct ctdb_freeze_waiter *w)
|
||||
{
|
||||
DLIST_REMOVE(w->ctdb->freeze_handle->waiters, w);
|
||||
ctdb_request_control_reply(w->ctdb, w->c, NULL, w->status);
|
||||
ctdb_request_control_reply(w->ctdb, w->c, NULL, w->status, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -431,12 +431,14 @@ int32_t ctdb_control_clear_db(struct ctdb_context *ctdb, TDB_DATA indata)
|
||||
/*
|
||||
set the recovery mode
|
||||
*/
|
||||
int32_t ctdb_control_set_recmode(struct ctdb_context *ctdb, TDB_DATA indata)
|
||||
int32_t ctdb_control_set_recmode(struct ctdb_context *ctdb, TDB_DATA indata,
|
||||
const char **errormsg)
|
||||
{
|
||||
uint32_t recmode = *(uint32_t *)indata.dptr;
|
||||
if (ctdb->freeze_mode != CTDB_FREEZE_FROZEN) {
|
||||
DEBUG(0,("Attempt to change recovery mode to %u when not frozen\n",
|
||||
recmode));
|
||||
(*errormsg) = "Cannot change recovery mode while not frozen";
|
||||
return -1;
|
||||
}
|
||||
ctdb->recovery_mode = recmode;
|
||||
|
@ -75,6 +75,7 @@ typedef void (*ctdb_queue_cb_fn_t)(uint8_t *data, size_t length,
|
||||
/* used for callbacks in ctdb_control requests */
|
||||
typedef void (*ctdb_control_callback_fn_t)(struct ctdb_context *,
|
||||
uint32_t status, TDB_DATA data,
|
||||
const char *errormsg,
|
||||
void *private_data);
|
||||
|
||||
/*
|
||||
@ -526,6 +527,7 @@ struct ctdb_reply_control {
|
||||
struct ctdb_req_header hdr;
|
||||
int32_t status;
|
||||
uint32_t datalen;
|
||||
uint32_t errorlen;
|
||||
uint8_t data[1];
|
||||
};
|
||||
|
||||
@ -710,7 +712,7 @@ int ctdb_daemon_set_call(struct ctdb_context *ctdb, uint32_t db_id,
|
||||
int ctdb_control(struct ctdb_context *ctdb, uint32_t destnode, uint64_t srvid,
|
||||
uint32_t opcode, uint32_t flags, TDB_DATA data,
|
||||
TALLOC_CTX *mem_ctx, TDB_DATA *outdata, int32_t *status,
|
||||
struct timeval *timeout);
|
||||
struct timeval *timeout, char **errormsg);
|
||||
|
||||
|
||||
|
||||
@ -789,9 +791,9 @@ int32_t ctdb_control_push_db(struct ctdb_context *ctdb, TDB_DATA indata);
|
||||
int32_t ctdb_control_set_dmaster(struct ctdb_context *ctdb, TDB_DATA indata);
|
||||
int32_t ctdb_control_clear_db(struct ctdb_context *ctdb, TDB_DATA indata);
|
||||
|
||||
int32_t ctdb_control_set_recmode(struct ctdb_context *ctdb, TDB_DATA data);
|
||||
int32_t ctdb_control_set_recmode(struct ctdb_context *ctdb, TDB_DATA data, const char **);
|
||||
void ctdb_request_control_reply(struct ctdb_context *ctdb, struct ctdb_req_control *c,
|
||||
TDB_DATA *outdata, int32_t status);
|
||||
TDB_DATA *outdata, int32_t status, const char *errormsg);
|
||||
|
||||
int32_t ctdb_control_freeze(struct ctdb_context *ctdb, struct ctdb_req_control *c, bool *async_reply);
|
||||
int32_t ctdb_control_thaw(struct ctdb_context *ctdb);
|
||||
|
@ -96,7 +96,7 @@ static void show_status(struct ctdb_status *s)
|
||||
TALLOC_CTX *tmp_ctx = talloc_new(NULL);
|
||||
int i;
|
||||
const char *prefix=NULL;
|
||||
size_t preflen=0;
|
||||
int preflen=0;
|
||||
const struct {
|
||||
const char *name;
|
||||
uint32_t offset;
|
||||
@ -488,7 +488,9 @@ static int control_catdb(struct ctdb_context *ctdb, int argc, const char **argv)
|
||||
keystr = hex_encode(ctdb, keys.keys[i].dptr, keys.keys[i].dsize);
|
||||
datastr = hex_encode(ctdb, keys.data[i].dptr, keys.data[i].dsize);
|
||||
|
||||
printf("rsn:%llu lmaster:%d dmaster:%d key:%s data:%s\n", keys.headers[i].rsn, keys.lmasters[i], keys.headers[i].dmaster, keystr, datastr);
|
||||
printf("rsn:%llu lmaster:%d dmaster:%d key:%s data:%s\n",
|
||||
(unsigned long long)keys.headers[i].rsn, keys.lmasters[i],
|
||||
keys.headers[i].dmaster, keystr, datastr);
|
||||
ret++;
|
||||
}
|
||||
}
|
||||
@ -702,7 +704,7 @@ static int control_createdb(struct ctdb_context *ctdb, int argc, const char **ar
|
||||
timeout = timeval_current_ofs(timelimit, 0);
|
||||
ret = ctdb_control(ctdb, vnn, 0, CTDB_CONTROL_DB_ATTACH,
|
||||
0, data, ctdb, &data, &res,
|
||||
&timeout);
|
||||
&timeout, NULL);
|
||||
if (ret != 0 || res != 0 || data.dsize != sizeof(uint32_t)) {
|
||||
DEBUG(0,("Failed to attach to database '%s'\n", dbname));
|
||||
return -1;
|
||||
@ -921,7 +923,7 @@ static int control_dumpmemory(struct ctdb_context *ctdb, int argc, const char **
|
||||
}
|
||||
|
||||
ctdb_control(ctdb, vnn, 0, CTDB_CONTROL_DUMP_MEMORY,
|
||||
CTDB_CTRL_FLAG_NOREPLY, tdb_null, NULL, NULL, NULL, NULL);
|
||||
CTDB_CTRL_FLAG_NOREPLY, tdb_null, NULL, NULL, NULL, NULL, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user