mirror of
https://github.com/samba-team/samba.git
synced 2025-02-02 09:47:23 +03:00
got rid of the getdbpath call
(This used to be ctdb commit 736ce5c00a1d1b47abb44c4b262b14bfba5202b1)
This commit is contained in:
parent
afa0876335
commit
f0a582e454
@ -91,7 +91,6 @@ static void ctdb_client_reply_call(struct ctdb_context *ctdb, struct ctdb_req_he
|
||||
state->state = CTDB_CALL_DONE;
|
||||
}
|
||||
|
||||
static void ctdb_reply_getdbpath(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
|
||||
static void ctdb_client_reply_control(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
|
||||
|
||||
/*
|
||||
@ -148,10 +147,6 @@ static void ctdb_client_read_cb(uint8_t *data, size_t cnt, void *args)
|
||||
ctdb_reply_connect_wait(ctdb, hdr);
|
||||
break;
|
||||
|
||||
case CTDB_REPLY_GETDBPATH:
|
||||
ctdb_reply_getdbpath(ctdb, hdr);
|
||||
break;
|
||||
|
||||
case CTDB_REPLY_CONTROL:
|
||||
ctdb_client_reply_control(ctdb, hdr);
|
||||
break;
|
||||
@ -626,83 +621,6 @@ void ctdb_shutdown(struct ctdb_context *ctdb)
|
||||
}
|
||||
|
||||
|
||||
enum ctdb_getdbpath_states {CTDB_GETDBPATH_WAIT, CTDB_GETDBPATH_DONE};
|
||||
|
||||
struct ctdb_getdbpath_state {
|
||||
uint32_t reqid;
|
||||
TDB_DATA path;
|
||||
enum ctdb_getdbpath_states state;
|
||||
};
|
||||
|
||||
/*
|
||||
handle a ctdb_reply_getdbpath reply
|
||||
*/
|
||||
static void ctdb_reply_getdbpath(struct ctdb_context *ctdb, struct ctdb_req_header *hdr)
|
||||
{
|
||||
struct ctdb_reply_getdbpath *r = (struct ctdb_reply_getdbpath *)hdr;
|
||||
struct ctdb_getdbpath_state *state;
|
||||
|
||||
state = ctdb_reqid_find(ctdb, hdr->reqid, struct ctdb_getdbpath_state);
|
||||
if (state == NULL) {
|
||||
DEBUG(0,(__location__ " reqid %d not found\n", hdr->reqid));
|
||||
return;
|
||||
}
|
||||
|
||||
if (hdr->reqid != state->reqid) {
|
||||
/* we found a record but it was the wrong one */
|
||||
DEBUG(0, ("Dropped orphaned reply with reqid:%d\n",hdr->reqid));
|
||||
return;
|
||||
}
|
||||
|
||||
state->path.dsize = r->datalen;
|
||||
state->path.dptr = talloc_memdup(state, &r->data[0], r->datalen);
|
||||
|
||||
state->state = CTDB_GETDBPATH_DONE;
|
||||
}
|
||||
|
||||
int ctdb_getdbpath(struct ctdb_db_context *ctdb_db, TDB_DATA *path)
|
||||
{
|
||||
struct ctdb_req_getdbpath r;
|
||||
int ret;
|
||||
struct ctdb_getdbpath_state *state;
|
||||
|
||||
/* if the domain socket is not yet open, open it */
|
||||
if (ctdb_db->ctdb->daemon.sd==-1) {
|
||||
ctdb_socket_connect(ctdb_db->ctdb);
|
||||
}
|
||||
|
||||
state = talloc(ctdb_db, struct ctdb_getdbpath_state);
|
||||
/* CTDB_NO_MEMORY(ctdb_db, state);*/
|
||||
|
||||
state->reqid = ctdb_reqid_new(ctdb_db->ctdb, state);
|
||||
state->state = CTDB_GETDBPATH_WAIT;
|
||||
|
||||
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_GETDBPATH;
|
||||
r.hdr.reqid = state->reqid;
|
||||
r.db_id = ctdb_db->db_id;
|
||||
|
||||
ret = ctdb_client_queue_pkt(ctdb_db->ctdb, &r.hdr);
|
||||
if (ret != 0) {
|
||||
talloc_free(state);
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (state->state == CTDB_GETDBPATH_WAIT) {
|
||||
event_loop_once(ctdb_db->ctdb->ev);
|
||||
}
|
||||
|
||||
path->dsize = state->path.dsize;
|
||||
path->dptr = talloc_steal(path, state->path.dptr);
|
||||
talloc_free(state);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
struct ctdb_client_control_state {
|
||||
uint32_t reqid;
|
||||
int32_t status;
|
||||
@ -910,3 +828,34 @@ int ctdb_get_config(struct ctdb_context *ctdb)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
find the real path to a ltdb
|
||||
*/
|
||||
int ctdb_getdbpath(struct ctdb_db_context *ctdb_db, TALLOC_CTX *mem_ctx,
|
||||
const char **path)
|
||||
{
|
||||
int ret;
|
||||
int32_t res;
|
||||
TDB_DATA data;
|
||||
|
||||
data.dptr = (uint8_t *)&ctdb_db->db_id;
|
||||
data.dsize = sizeof(ctdb_db->db_id);
|
||||
|
||||
ret = ctdb_control(ctdb_db->ctdb, CTDB_CURRENT_NODE, 0,
|
||||
CTDB_CONTROL_GETDBPATH, data,
|
||||
ctdb_db, &data, &res);
|
||||
if (ret != 0 || res != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
(*path) = talloc_strndup(mem_ctx, (const char *)data.dptr, data.dsize);
|
||||
if ((*path) == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
talloc_free(data.dptr);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
@ -66,6 +66,22 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
|
||||
case CTDB_CONTROL_PING:
|
||||
return 0;
|
||||
|
||||
case CTDB_CONTROL_GETDBPATH: {
|
||||
uint32_t db_id;
|
||||
struct ctdb_db_context *ctdb_db;
|
||||
|
||||
if (indata.dsize != sizeof(uint32_t)) {
|
||||
DEBUG(0,(__location__ " Invalid data in CTDB_CONTROL_GETDBPATH\n"));
|
||||
return -1;
|
||||
}
|
||||
db_id = *(uint32_t *)indata.dptr;
|
||||
ctdb_db = find_ctdb_db(ctdb, db_id);
|
||||
if (ctdb_db == NULL) return -1;
|
||||
outdata->dptr = discard_const(ctdb_db->db_path);
|
||||
outdata->dsize = strlen(ctdb_db->db_path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
default:
|
||||
DEBUG(0,(__location__ " Unknown CTDB control opcode %u\n", opcode));
|
||||
return -1;
|
||||
|
@ -240,51 +240,6 @@ static void daemon_request_connect_wait(struct ctdb_client *client,
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
called when the daemon gets a getdbpath request from a client
|
||||
*/
|
||||
static void daemon_request_getdbpath(struct ctdb_client *client,
|
||||
struct ctdb_req_getdbpath *c)
|
||||
{
|
||||
struct ctdb_reply_getdbpath *r;
|
||||
struct ctdb_db_context *ctdb_db;
|
||||
char *path;
|
||||
int res, len;
|
||||
|
||||
ctdb_db = find_ctdb_db(client->ctdb, c->db_id);
|
||||
if (!ctdb_db) {
|
||||
DEBUG(0, (__location__ " Unknown database in request. db_id==0x%08x",
|
||||
c->db_id));
|
||||
ctdb_db->ctdb->status.pending_calls--;
|
||||
return;
|
||||
}
|
||||
|
||||
path = talloc_asprintf(c, "%s/%s", ctdb_db->ctdb->db_directory, ctdb_db->db_name);
|
||||
|
||||
/* now send the reply */
|
||||
len = offsetof(struct ctdb_reply_getdbpath, data) + strlen(path);
|
||||
r = ctdbd_allocate_pkt(ctdb_db->ctdb, len);
|
||||
|
||||
talloc_set_name_const(r, "reply_getdbpath packet");
|
||||
|
||||
memset(r, 0, offsetof(struct ctdb_reply_getdbpath, data));
|
||||
|
||||
r->hdr.length = len;
|
||||
r->hdr.ctdb_magic = CTDB_MAGIC;
|
||||
r->hdr.ctdb_version = CTDB_VERSION;
|
||||
r->hdr.operation = CTDB_REPLY_GETDBPATH;
|
||||
r->hdr.reqid = c->hdr.reqid;
|
||||
r->datalen = strlen(path);
|
||||
memcpy(&r->data[0], path, r->datalen);
|
||||
|
||||
res = daemon_queue_send(client, &(r->hdr));
|
||||
if (res != 0) {
|
||||
DEBUG(0,(__location__ " Failed to queue a getdbpath response\n"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
destroy a ctdb_client
|
||||
*/
|
||||
@ -530,10 +485,6 @@ static void daemon_incoming_packet(void *p, uint8_t *data, uint32_t nread)
|
||||
daemon_request_shutdown(client, (struct ctdb_req_shutdown *)hdr);
|
||||
break;
|
||||
|
||||
case CTDB_REQ_GETDBPATH:
|
||||
daemon_request_getdbpath(client, (struct ctdb_req_getdbpath *)hdr);
|
||||
break;
|
||||
|
||||
case CTDB_REQ_CONTROL:
|
||||
ctdb->status.client.req_control++;
|
||||
daemon_request_control_from_client(client, (struct ctdb_req_control *)hdr);
|
||||
@ -775,11 +726,11 @@ static void daemon_control_callback(struct ctdb_context *ctdb,
|
||||
size_t len;
|
||||
|
||||
/* construct a message to send to the client containing the data */
|
||||
len = offsetof(struct ctdb_req_control, data) + data.dsize;
|
||||
len = offsetof(struct ctdb_reply_control, data) + data.dsize;
|
||||
r = ctdbd_allocate_pkt(client, len);
|
||||
talloc_set_name_const(r, "reply_control packet");
|
||||
|
||||
memset(r, 0, offsetof(struct ctdb_req_message, data));
|
||||
memset(r, 0, offsetof(struct ctdb_reply_control, data));
|
||||
|
||||
r->hdr.length = len;
|
||||
r->hdr.ctdb_magic = CTDB_MAGIC;
|
||||
|
@ -90,12 +90,13 @@ struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb, const char *name,
|
||||
|
||||
/* add the node id to the database name, so when we run on loopback
|
||||
we don't conflict in the local filesystem */
|
||||
name = talloc_asprintf(ctdb_db, "%s/%s", ctdb->db_directory, name);
|
||||
ctdb_db->db_path = talloc_asprintf(ctdb_db, "%s/%s", ctdb->db_directory, name);
|
||||
|
||||
/* when we have a separate daemon this will need to be a real
|
||||
file, not a TDB_INTERNAL, so the parent can access it to
|
||||
for ltdb bypass */
|
||||
ctdb_db->ltdb = tdb_wrap_open(ctdb, name, 0, TDB_CLEAR_IF_FIRST, open_flags, mode);
|
||||
ctdb_db->ltdb = tdb_wrap_open(ctdb, ctdb_db->db_path, 0,
|
||||
TDB_CLEAR_IF_FIRST, open_flags, mode);
|
||||
if (ctdb_db->ltdb == NULL) {
|
||||
ctdb_set_error(ctdb, "Failed to open tdb %s\n", name);
|
||||
talloc_free(ctdb_db);
|
||||
|
@ -215,7 +215,7 @@ struct ctdb_context *ctdb_cmdline_client(struct event_context *ev);
|
||||
struct ctdb_status;
|
||||
int ctdb_status(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_status *status);
|
||||
|
||||
int ctdb_getdbpath(struct ctdb_db_context *ctdb_db, TDB_DATA *path);
|
||||
int ctdb_getdbpath(struct ctdb_db_context *ctdb_db, TALLOC_CTX *mem_ctx, const char **path);
|
||||
|
||||
int ctdb_process_exists(struct ctdb_context *ctdb, uint32_t destnode, pid_t pid);
|
||||
|
||||
|
@ -188,6 +188,7 @@ struct ctdb_db_context {
|
||||
struct ctdb_context *ctdb;
|
||||
uint32_t db_id;
|
||||
const char *db_name;
|
||||
const char *db_path;
|
||||
struct tdb_wrap *ltdb;
|
||||
struct ctdb_registered_call *calls; /* list of registered calls */
|
||||
};
|
||||
@ -232,7 +233,8 @@ struct ctdb_ltdb_header {
|
||||
enum ctdb_controls {CTDB_CONTROL_PROCESS_EXISTS,
|
||||
CTDB_CONTROL_STATUS,
|
||||
CTDB_CONTROL_CONFIG,
|
||||
CTDB_CONTROL_PING};
|
||||
CTDB_CONTROL_PING,
|
||||
CTDB_CONTROL_GETDBPATH};
|
||||
|
||||
enum call_state {CTDB_CALL_WAIT, CTDB_CALL_DONE, CTDB_CALL_ERROR};
|
||||
|
||||
@ -283,9 +285,7 @@ enum ctdb_operation {
|
||||
CTDB_REQ_REGISTER = 1000,
|
||||
CTDB_REQ_CONNECT_WAIT = 1001,
|
||||
CTDB_REPLY_CONNECT_WAIT = 1002,
|
||||
CTDB_REQ_SHUTDOWN = 1003,
|
||||
CTDB_REQ_GETDBPATH = 1004,
|
||||
CTDB_REPLY_GETDBPATH = 1005
|
||||
CTDB_REQ_SHUTDOWN = 1003
|
||||
};
|
||||
|
||||
#define CTDB_MAGIC 0x43544442 /* CTDB */
|
||||
|
@ -91,7 +91,7 @@ int main(int argc, const char *argv[])
|
||||
poptContext pc;
|
||||
struct event_context *ev;
|
||||
struct ctdb_call call;
|
||||
TDB_DATA *path;
|
||||
const char *path;
|
||||
|
||||
pc = poptGetContext(argv[0], argc, argv, popt_options, POPT_CONTEXT_KEEP_FIRST);
|
||||
|
||||
@ -137,9 +137,8 @@ int main(int argc, const char *argv[])
|
||||
ctdb_connect_wait(ctdb);
|
||||
|
||||
/* find the full path to the database file */
|
||||
path = talloc_zero(ctdb_db, TDB_DATA);
|
||||
ctdb_getdbpath(ctdb_db, path);
|
||||
printf("path to database:[%s]\n",path->dptr);
|
||||
ctdb_getdbpath(ctdb_db, ctdb_db, &path);
|
||||
printf("path to database:[%s]\n",path);
|
||||
|
||||
ZERO_STRUCT(call);
|
||||
call.key.dptr = discard_const("test");
|
||||
|
Loading…
x
Reference in New Issue
Block a user