1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-11 05:18:09 +03:00

lib: Move ctdbd_init_connection out of ctdbd_traverse()

2 effects: This removes the [un]become_root calls from ctdbd_conn,
and it makes it possible to re-use the traversal connections, should
the setup/teardown become a problem in the future.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
This commit is contained in:
Volker Lendecke 2016-04-05 17:30:11 +02:00 committed by Ralph Boehme
parent 966cef0d41
commit ff72a8ae82
2 changed files with 36 additions and 24 deletions

View File

@ -1014,32 +1014,21 @@ int ctdbd_parse(struct ctdbd_connection *conn, uint32_t db_id,
}
/*
Traverse a ctdb database. This uses a kind-of hackish way to open a second
connection to ctdbd to avoid the hairy recursive and async problems with
everything in-line.
Traverse a ctdb database. "conn" must be an otherwise unused
ctdb_connection where no other messages but the traverse ones are
expected.
*/
int ctdbd_traverse(struct ctdbd_connection *master, uint32_t db_id,
int ctdbd_traverse(struct ctdbd_connection *conn, uint32_t db_id,
void (*fn)(TDB_DATA key, TDB_DATA data,
void *private_data),
void *private_data)
{
struct ctdbd_connection *conn;
int ret;
TDB_DATA key, data;
struct ctdb_traverse_start t;
int cstatus;
become_root();
ret = ctdbd_init_connection(NULL, master->sockname, master->timeout,
&conn);
unbecome_root();
if (ret != 0) {
DEBUG(0, ("ctdbd_init_connection failed: %s\n",
strerror(ret)));
return ret;
}
t.db_id = db_id;
t.srvid = conn->rand_srvid;
t.reqid = ctdbd_next_reqid(conn);
@ -1061,7 +1050,6 @@ int ctdbd_traverse(struct ctdbd_connection *master, uint32_t db_id,
*/
ret = EIO;
}
TALLOC_FREE(conn);
return ret;
}
@ -1080,7 +1068,6 @@ int ctdbd_traverse(struct ctdbd_connection *master, uint32_t db_id,
if (hdr->operation != CTDB_REQ_MESSAGE) {
DEBUG(0, ("Got operation %u, expected a message\n",
(unsigned)hdr->operation));
TALLOC_FREE(conn);
return EIO;
}
@ -1089,7 +1076,6 @@ int ctdbd_traverse(struct ctdbd_connection *master, uint32_t db_id,
if (m->datalen < sizeof(uint32_t) || m->datalen != d->length) {
DEBUG(0, ("Got invalid traverse data of length %d\n",
(int)m->datalen));
TALLOC_FREE(conn);
return EIO;
}
@ -1100,14 +1086,12 @@ int ctdbd_traverse(struct ctdbd_connection *master, uint32_t db_id,
if (key.dsize == 0 && data.dsize == 0) {
/* end of traverse */
TALLOC_FREE(conn);
return 0;
}
if (data.dsize < sizeof(struct ctdb_ltdb_header)) {
DEBUG(0, ("Got invalid ltdb header length %d\n",
(int)data.dsize));
TALLOC_FREE(conn);
return EIO;
}
data.dsize -= sizeof(struct ctdb_ltdb_header);

View File

@ -1358,6 +1358,36 @@ static int traverse_persistent_callback_dbwrap(struct db_record *rec, void* data
return traverse_persistent_callback(NULL, rec->key, rec->value, data);
}
static int db_ctdbd_traverse(uint32_t db_id,
void (*fn)(TDB_DATA key, TDB_DATA data,
void *private_data),
void *private_data)
{
struct ctdbd_connection *conn;
int ret;
become_root();
ret = ctdbd_init_connection(talloc_tos(), lp_ctdbd_socket(),
lp_ctdb_timeout(), &conn);
unbecome_root();
if (ret != 0) {
DBG_WARNING("ctdbd_init_connection failed: %s\n",
strerror(ret));
return ret;
}
ret = ctdbd_traverse(conn, db_id, fn, private_data);
TALLOC_FREE(conn);
if (ret != 0) {
DBG_WARNING("ctdbd_traverse failed: %s\n",
strerror(ret));
return ret;
}
return 0;
}
static int db_ctdb_traverse(struct db_context *db,
int (*fn)(struct db_record *rec,
@ -1422,8 +1452,7 @@ static int db_ctdb_traverse(struct db_context *db,
return ret;
}
ret = ctdbd_traverse(messaging_ctdbd_connection(), ctx->db_id,
traverse_callback, &state);
ret = db_ctdbd_traverse(ctx->db_id, traverse_callback, &state);
if (ret != 0) {
return -1;
}
@ -1512,8 +1541,7 @@ static int db_ctdb_traverse_read(struct db_context *db,
return tdb_traverse_read(ctx->wtdb->tdb, traverse_persistent_callback_read, &state);
}
ret = ctdbd_traverse(messaging_ctdbd_connection(), ctx->db_id,
traverse_read_callback, &state);
ret = db_ctdbd_traverse(ctx->db_id, traverse_read_callback, &state);
if (ret != 0) {
return -1;
}