Rev 33: added error reply packets in http://samba.org/~tridge/ctdb
tridge at samba.org
tridge at samba.org
Mon Dec 18 03:27:20 GMT 2006
------------------------------------------------------------
revno: 33
revision-id: tridge at samba.org-20061218032720-i855uc7pif1s4tbq
parent: tridge at samba.org-20061218030549-g48z07waip15qba4
committer: Andrew Tridgell <tridge at samba.org>
branch nick: tridge
timestamp: Mon 2006-12-18 14:27:20 +1100
message:
added error reply packets
modified:
common/ctdb.c ctdb.c-20061127094323-t50f58d65iaao5of-2
common/ctdb_call.c ctdb_call.c-20061128065342-to93h6eejj5kon81-1
include/ctdb_private.h ctdb_private.h-20061117234101-o3qt14umlg9en8z0-13
=== modified file 'common/ctdb.c'
--- a/common/ctdb.c 2006-12-01 04:45:24 +0000
+++ b/common/ctdb.c 2006-12-18 03:27:20 +0000
@@ -177,6 +177,10 @@
ctdb_reply_call(ctdb, hdr);
break;
+ case CTDB_REPLY_ERROR:
+ ctdb_reply_error(ctdb, hdr);
+ break;
+
default:
printf("Packet with unknown operation %d\n", hdr->operation);
talloc_free(hdr);
=== modified file 'common/ctdb_call.c'
--- a/common/ctdb_call.c 2006-12-18 03:05:49 +0000
+++ b/common/ctdb_call.c 2006-12-18 03:27:20 +0000
@@ -85,9 +85,42 @@
send an error reply
*/
static void ctdb_send_error(struct ctdb_context *ctdb,
- struct ctdb_req_header *hdr, int ecode)
+ struct ctdb_req_header *hdr, uint32_t status,
+ const char *fmt, ...)
{
- printf("ctdb_send_error not implemented\n");
+ va_list ap;
+ struct ctdb_reply_error *r;
+ char *msg;
+ int len;
+ struct ctdb_node *node;
+
+ va_start(ap, fmt);
+ msg = talloc_vasprintf(ctdb, fmt, ap);
+ if (msg == NULL) {
+ /* can't send an error message, need to rely on call
+ timeouts instead */
+ return;
+ }
+ va_end(ap);
+
+ len = strlen(msg)+1;
+ r = talloc_size(ctdb, sizeof(*r) + len);
+ r->hdr.length = sizeof(*r) + len;
+ 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 = len;
+ memcpy(&r->msg[0], msg, len);
+
+ talloc_free(msg);
+
+ node = ctdb->nodes[hdr->srcnode];
+
+ ctdb->methods->queue_pkt(node, (uint8_t *)r, r->hdr.length);
+
+ talloc_free(r);
}
/*
@@ -122,7 +155,7 @@
if the call will be answered locally */
ret = ctdb_ltdb_fetch(ctdb, key, &header, &data);
if (ret != 0) {
- ctdb_send_error(ctdb, hdr, ret);
+ ctdb_send_error(ctdb, hdr, ret, "ltdb fetch failed in ctdb_request_call");
return;
}
@@ -164,6 +197,7 @@
enum call_state state;
struct ctdb_req_call *c;
struct ctdb_node *node;
+ const char *errmsg;
TDB_DATA reply_data;
};
@@ -189,6 +223,23 @@
state->state = CTDB_CALL_DONE;
}
+
+/*
+ called when a CTDB_REPLY_ERROR packet comes in
+*/
+void ctdb_reply_error(struct ctdb_context *ctdb, struct ctdb_req_header *hdr)
+{
+ struct ctdb_reply_error *c = (struct ctdb_reply_error *)hdr;
+ struct ctdb_call_state *state;
+
+ state = idr_find(ctdb->idr, hdr->reqid);
+
+ talloc_steal(state, c);
+
+ state->state = CTDB_CALL_ERROR;
+ state->errmsg = (char *)c->msg;
+}
+
/*
destroy a ctdb_call
*/
@@ -306,6 +357,7 @@
event_loop_once(state->node->ctdb->ev);
}
if (state->state != CTDB_CALL_DONE) {
+ ctdb_set_error(state->node->ctdb, "%s", state->errmsg);
talloc_free(state);
return -1;
}
=== modified file 'include/ctdb_private.h'
--- a/include/ctdb_private.h 2006-12-18 03:05:49 +0000
+++ b/include/ctdb_private.h 2006-12-18 03:27:20 +0000
@@ -116,11 +116,12 @@
operation IDs
*/
enum ctdb_operation {
- CTDB_REQ_CALL = 0,
- CTDB_REPLY_CALL = 1,
+ CTDB_REQ_CALL = 0,
+ CTDB_REPLY_CALL = 1,
CTDB_REPLY_REDIRECT = 2,
- CTDB_REQ_DMASTER = 3,
- CTDB_REPLY_DMASTER = 4,
+ CTDB_REQ_DMASTER = 3,
+ CTDB_REPLY_DMASTER = 4,
+ CTDB_REPLY_ERROR = 5
};
/*
@@ -148,6 +149,13 @@
uint8_t data[0];
};
+struct ctdb_reply_error {
+ struct ctdb_req_header hdr;
+ uint32_t status;
+ uint32_t msglen;
+ uint8_t msg[0];
+};
+
/* internal prototypes */
void ctdb_set_error(struct ctdb_context *ctdb, const char *fmt, ...);
bool ctdb_same_address(struct ctdb_address *a1, struct ctdb_address *a2);
@@ -157,6 +165,7 @@
uint32_t ctdb_hash(TDB_DATA *key);
void ctdb_request_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
void ctdb_reply_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
+void ctdb_reply_error(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
int ctdb_ltdb_fetch(struct ctdb_context *ctdb,
TDB_DATA key, struct ctdb_ltdb_header *header, TDB_DATA *data);
More information about the samba-cvs
mailing list