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

s3/g_lock: add g_lock_locks() and g_lock_locks_read() varients

Gives callers the option to modify data if needed. All existing
callers use g_lock_locks_read(), so no change in behaviour.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15608

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
This commit is contained in:
Ralph Boehme 2024-10-12 16:36:21 +02:00
parent 5305e36194
commit 9b4ff5ff28
4 changed files with 30 additions and 4 deletions

View File

@ -92,6 +92,9 @@ NTSTATUS g_lock_writev_data(
NTSTATUS g_lock_write_data(struct g_lock_ctx *ctx, TDB_DATA key,
const uint8_t *buf, size_t buflen);
int g_lock_locks_read(struct g_lock_ctx *ctx,
int (*fn)(TDB_DATA key, void *private_data),
void *private_data);
int g_lock_locks(struct g_lock_ctx *ctx,
int (*fn)(TDB_DATA key, void *private_data),
void *private_data);

View File

@ -1558,6 +1558,29 @@ static int g_lock_locks_fn(struct db_record *rec, void *priv)
return state->fn(key, state->private_data);
}
int g_lock_locks_read(struct g_lock_ctx *ctx,
int (*fn)(TDB_DATA key, void *private_data),
void *private_data)
{
struct g_lock_locks_state state;
NTSTATUS status;
int count;
SMB_ASSERT(!ctx->busy);
state.fn = fn;
state.private_data = private_data;
status = dbwrap_traverse_read(ctx->db,
g_lock_locks_fn,
&state,
&count);
if (!NT_STATUS_IS_OK(status)) {
return -1;
}
return count;
}
int g_lock_locks(struct g_lock_ctx *ctx,
int (*fn)(TDB_DATA key, void *private_data),
void *private_data)
@ -1571,7 +1594,7 @@ int g_lock_locks(struct g_lock_ctx *ctx,
state.fn = fn;
state.private_data = private_data;
status = dbwrap_traverse_read(ctx->db, g_lock_locks_fn, &state, &count);
status = dbwrap_traverse(ctx->db, g_lock_locks_fn, &state, &count);
if (!NT_STATUS_IS_OK(status)) {
return -1;
}

View File

@ -1821,7 +1821,7 @@ int share_mode_forall(int (*fn)(struct file_id fid,
return 0;
}
ret = g_lock_locks(
ret = g_lock_locks_read(
lock_ctx, share_mode_forall_fn, &state);
if (ret < 0) {
DBG_ERR("g_lock_locks failed\n");

View File

@ -191,7 +191,7 @@ static int net_g_lock_dumpall(
goto done;
}
ret = g_lock_locks(g_ctx, net_g_lock_dumpall_fn, g_ctx);
ret = g_lock_locks_read(g_ctx, net_g_lock_dumpall_fn, g_ctx);
done:
TALLOC_FREE(g_ctx);
TALLOC_FREE(msg);
@ -221,7 +221,7 @@ static int net_g_lock_locks(struct net_context *c, int argc, const char **argv)
goto done;
}
ret = g_lock_locks(g_ctx, net_g_lock_locks_fn, NULL);
ret = g_lock_locks_read(g_ctx, net_g_lock_locks_fn, NULL);
done:
TALLOC_FREE(g_ctx);
TALLOC_FREE(msg);