diff options
author | Volker Lendecke <vl@samba.org> | 2010-03-01 14:28:22 +0100 |
---|---|---|
committer | Volker Lendecke <vl@samba.org> | 2010-03-01 14:51:34 +0100 |
commit | 8bebb380e8b581b41f3057c128d73094c1bde332 (patch) | |
tree | 3470aabb76b4800f32ef85a13f6f53936a9e261e /source3/lib | |
parent | 3deba6349ca751d669e2af817ec7e2c7eb6195b3 (diff) | |
download | samba-8bebb380e8b581b41f3057c128d73094c1bde332.tar.gz samba-8bebb380e8b581b41f3057c128d73094c1bde332.tar.bz2 samba-8bebb380e8b581b41f3057c128d73094c1bde332.zip |
s3: Add connections_forall_read()
In a cluster, this makes a large difference: For r/w traverse, we have to do a
fetch_locked on every record which for most users of connections_forall is just
overkill.
Diffstat (limited to 'source3/lib')
-rw-r--r-- | source3/lib/conn_tdb.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/source3/lib/conn_tdb.c b/source3/lib/conn_tdb.c index e95ada4c6a..0770f66828 100644 --- a/source3/lib/conn_tdb.c +++ b/source3/lib/conn_tdb.c @@ -121,6 +121,48 @@ int connections_forall(int (*fn)(struct db_record *rec, return ctx->traverse(ctx, conn_traverse_fn, (void *)&state); } +struct conn_traverse_read_state { + int (*fn)(const struct connections_key *key, + const struct connections_data *data, + void *private_data); + void *private_data; +}; + +static int connections_forall_read_fn(struct db_record *rec, + void *private_data) +{ + struct conn_traverse_read_state *state = + (struct conn_traverse_read_state *)private_data; + + if ((rec->key.dsize != sizeof(struct connections_key)) + || (rec->value.dsize != sizeof(struct connections_data))) { + return 0; + } + return state->fn((const struct connections_key *)rec->key.dptr, + (const struct connections_data *)rec->value.dptr, + state->private_data); +} + +int connections_forall_read(int (*fn)(const struct connections_key *key, + const struct connections_data *data, + void *private_data), + void *private_data) +{ + struct db_context *ctx; + struct conn_traverse_read_state state; + + ctx = connections_db_ctx(false); + if (ctx == NULL) { + return -1; + } + + state.fn = fn; + state.private_data = private_data; + + return ctx->traverse_read(ctx, connections_forall_read_fn, + (void *)&state); +} + bool connections_init(bool rw) { return (connections_db_ctx(rw) != NULL); |