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

lib: Make g_lock_lock use TDB_DATA

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
This commit is contained in:
Volker Lendecke 2017-12-03 20:47:02 +01:00 committed by Ralph Boehme
parent 3bc87a20e9
commit bdeb7e7d81
6 changed files with 34 additions and 26 deletions

View File

@ -44,7 +44,7 @@ struct tevent_req *g_lock_lock_send(TALLOC_CTX *mem_ctx,
TDB_DATA key,
enum g_lock_type type);
NTSTATUS g_lock_lock_recv(struct tevent_req *req);
NTSTATUS g_lock_lock(struct g_lock_ctx *ctx, const char *name,
NTSTATUS g_lock_lock(struct g_lock_ctx *ctx, TDB_DATA key,
enum g_lock_type lock_type, struct timeval timeout);
NTSTATUS g_lock_unlock(struct g_lock_ctx *ctx, const char *name);

View File

@ -380,8 +380,8 @@ static int db_ctdb_transaction_start(struct db_context *db)
/*
* Wait a day, i.e. forever...
*/
status = g_lock_lock(ctx->lock_ctx, h->lock_name, G_LOCK_WRITE,
timeval_set(86400, 0));
status = g_lock_lock(ctx->lock_ctx, string_term_tdb_data(h->lock_name),
G_LOCK_WRITE, timeval_set(86400, 0));
if (!NT_STATUS_IS_OK(status)) {
DEBUG(0, ("g_lock_lock failed: %s\n", nt_errstr(status)));
TALLOC_FREE(h);

View File

@ -452,7 +452,7 @@ NTSTATUS g_lock_lock_recv(struct tevent_req *req)
return tevent_req_simple_recv_ntstatus(req);
}
NTSTATUS g_lock_lock(struct g_lock_ctx *ctx, const char *name,
NTSTATUS g_lock_lock(struct g_lock_ctx *ctx, TDB_DATA key,
enum g_lock_type type, struct timeval timeout)
{
TALLOC_CTX *frame = talloc_stackframe();
@ -465,8 +465,7 @@ NTSTATUS g_lock_lock(struct g_lock_ctx *ctx, const char *name,
if (ev == NULL) {
goto fail;
}
req = g_lock_lock_send(frame, ev, ctx, string_term_tdb_data(name),
type);
req = g_lock_lock_send(frame, ev, ctx, key, type);
if (req == NULL) {
goto fail;
}
@ -783,7 +782,8 @@ NTSTATUS g_lock_do(const char *name, enum g_lock_type lock_type,
goto done;
}
status = g_lock_lock(g_ctx, name, lock_type, timeout);
status = g_lock_lock(g_ctx, string_term_tdb_data(name), lock_type,
timeout);
if (!NT_STATUS_IS_OK(status)) {
goto done;
}

View File

@ -30,6 +30,7 @@
#include "libsmb/libsmb.h"
#include "source3/include/messages.h"
#include "source3/include/g_lock.h"
#include "lib/util/util_tdb.h"
/*********************************************************
Change the domain password on the PDC.
@ -191,7 +192,7 @@ NTSTATUS trust_pw_change(struct netlogon_creds_cli_context *context,
g_timeout = timeval_current_ofs(10, 0);
status = g_lock_lock(state->g_ctx,
state->g_lock_key,
string_term_tdb_data(state->g_lock_key),
G_LOCK_WRITE, g_timeout);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(1, ("could not get g_lock on [%s]!\n",

View File

@ -1480,7 +1480,7 @@ static NTSTATUS smbd_claim_version(struct messaging_context *msg,
return NT_STATUS_UNSUCCESSFUL;
}
status = g_lock_lock(ctx, name, G_LOCK_READ,
status = g_lock_lock(ctx, string_term_tdb_data(name), G_LOCK_READ,
(struct timeval) { .tv_sec = 60 });
if (!NT_STATUS_IS_OK(status)) {
DBG_WARNING("g_lock_lock(G_LOCK_READ) failed: %s\n",
@ -1509,7 +1509,7 @@ static NTSTATUS smbd_claim_version(struct messaging_context *msg,
return NT_STATUS_OK;
}
status = g_lock_lock(ctx, name, G_LOCK_WRITE,
status = g_lock_lock(ctx, string_term_tdb_data(name), G_LOCK_WRITE,
(struct timeval) { .tv_sec = 60 });
if (!NT_STATUS_IS_OK(status)) {
DBG_WARNING("g_lock_lock(G_LOCK_WRITE) failed: %s\n",
@ -1529,7 +1529,7 @@ static NTSTATUS smbd_claim_version(struct messaging_context *msg,
return status;
}
status = g_lock_lock(ctx, name, G_LOCK_READ,
status = g_lock_lock(ctx, string_term_tdb_data(name), G_LOCK_READ,
(struct timeval) { .tv_sec = 60 });
if (!NT_STATUS_IS_OK(status)) {
DBG_WARNING("g_lock_lock(G_LOCK_READ) failed: %s\n",

View File

@ -68,7 +68,7 @@ bool run_g_lock1(int dummy)
goto fail;
}
status = g_lock_lock(ctx, lockname, G_LOCK_READ,
status = g_lock_lock(ctx, string_term_tdb_data(lockname), G_LOCK_READ,
(struct timeval) { .tv_sec = 1 });
if (!NT_STATUS_IS_OK(status)) {
fprintf(stderr, "g_lock_lock failed: %s\n",
@ -76,7 +76,7 @@ bool run_g_lock1(int dummy)
goto fail;
}
status = g_lock_lock(ctx, lockname, G_LOCK_READ,
status = g_lock_lock(ctx, string_term_tdb_data(lockname), G_LOCK_READ,
(struct timeval) { .tv_sec = 1 });
if (!NT_STATUS_EQUAL(status, NT_STATUS_WAS_LOCKED)) {
fprintf(stderr, "Double lock got %s\n",
@ -155,7 +155,7 @@ bool run_g_lock2(int dummy)
goto fail;
}
status = g_lock_lock(ctx, lockname, G_LOCK_WRITE,
status = g_lock_lock(ctx, string_term_tdb_data(lockname), G_LOCK_WRITE,
(struct timeval) { .tv_sec = 1 });
if (!NT_STATUS_IS_OK(status)) {
fprintf(stderr, "g_lock_lock returned %s\n",
@ -262,7 +262,7 @@ bool run_g_lock3(int dummy)
state.self = messaging_server_id(msg);
status = g_lock_lock(ctx, lockname, G_LOCK_READ,
status = g_lock_lock(ctx, string_term_tdb_data(lockname), G_LOCK_READ,
(struct timeval) { .tv_sec = 1 });
if (!NT_STATUS_IS_OK(status)) {
fprintf(stderr, "g_lock_lock returned %s\n",
@ -270,7 +270,7 @@ bool run_g_lock3(int dummy)
goto fail;
}
status = g_lock_lock(ctx, lockname, G_LOCK_READ,
status = g_lock_lock(ctx, string_term_tdb_data(lockname), G_LOCK_READ,
(struct timeval) { .tv_sec = 1 });
if (!NT_STATUS_EQUAL(status, NT_STATUS_WAS_LOCKED)) {
fprintf(stderr, "g_lock_lock returned %s, expected %s\n",
@ -291,7 +291,7 @@ bool run_g_lock3(int dummy)
goto fail;
}
status = g_lock_lock(ctx, lockname, G_LOCK_WRITE,
status = g_lock_lock(ctx, string_term_tdb_data(lockname), G_LOCK_WRITE,
(struct timeval) { .tv_sec = 1 });
if (!NT_STATUS_IS_OK(status)) {
fprintf(stderr, "g_lock_lock returned %s\n",
@ -336,7 +336,7 @@ static bool lock4_child(const char *lockname,
return false;
}
status = g_lock_lock(ctx, lockname, G_LOCK_WRITE,
status = g_lock_lock(ctx, string_term_tdb_data(lockname), G_LOCK_WRITE,
(struct timeval) { .tv_sec = 1 });
if (!NT_STATUS_IS_OK(status)) {
fprintf(stderr, "child: g_lock_lock returned %s\n",
@ -489,7 +489,7 @@ bool run_g_lock4(int dummy)
return false;
}
status = g_lock_lock(ctx, lockname, G_LOCK_WRITE,
status = g_lock_lock(ctx, string_term_tdb_data(lockname), G_LOCK_WRITE,
(struct timeval) { .tv_usec = 1 });
if (!NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) {
fprintf(stderr, "g_lock_lock returned %s\n",
@ -497,7 +497,7 @@ bool run_g_lock4(int dummy)
goto fail;
}
status = g_lock_lock(ctx, lockname, G_LOCK_READ,
status = g_lock_lock(ctx, string_term_tdb_data(lockname), G_LOCK_READ,
(struct timeval) { .tv_usec = 1 });
if (!NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) {
fprintf(stderr, "g_lock_lock returned %s\n",
@ -623,7 +623,9 @@ bool run_g_lock5(int dummy)
fprintf(stderr, "get_g_lock_ctx failed");
exit(1);
}
status = g_lock_lock(ctx, lockname, G_LOCK_READ,
status = g_lock_lock(ctx,
string_term_tdb_data(lockname),
G_LOCK_READ,
(struct timeval) { .tv_sec = 1 });
if (!NT_STATUS_IS_OK(status)) {
fprintf(stderr,
@ -678,7 +680,8 @@ bool run_g_lock5(int dummy)
return false;
}
status = g_lock_lock(ctx, lockname, G_LOCK_READ,
status = g_lock_lock(ctx, string_term_tdb_data(lockname),
G_LOCK_READ,
(struct timeval) { .tv_sec = 1 });
if (!NT_STATUS_IS_OK(status)) {
fprintf(stderr, "g_lock_lock failed %s\n",
@ -769,7 +772,9 @@ bool run_g_lock6(int dummy)
fprintf(stderr, "get_g_lock_ctx failed");
exit(1);
}
status = g_lock_lock(ctx, lockname, G_LOCK_READ,
status = g_lock_lock(ctx,
string_term_tdb_data(lockname),
G_LOCK_READ,
(struct timeval) { .tv_sec = 1 });
if (!NT_STATUS_IS_OK(status)) {
fprintf(stderr,
@ -825,7 +830,8 @@ bool run_g_lock6(int dummy)
return false;
}
status = g_lock_lock(ctx, lockname, G_LOCK_WRITE,
status = g_lock_lock(ctx, string_term_tdb_data(lockname),
G_LOCK_WRITE,
(struct timeval) { .tv_sec = 1 });
if (!NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) {
fprintf(stderr, "g_lock_lock should have failed with %s - %s\n",
@ -893,7 +899,7 @@ bool run_g_lock_ping_pong(int dummy)
snprintf(name, sizeof(name), "ping_pong_%d", i);
status = g_lock_lock(ctx, name, G_LOCK_WRITE,
status = g_lock_lock(ctx, string_term_tdb_data(name), G_LOCK_WRITE,
(struct timeval) { .tv_sec = 60 });
if (!NT_STATUS_IS_OK(status)) {
fprintf(stderr, "g_lock_lock failed: %s\n",
@ -905,7 +911,8 @@ bool run_g_lock_ping_pong(int dummy)
name[10] = '0' + ((i+1) % torture_nprocs);
status = g_lock_lock(ctx, name, G_LOCK_WRITE,
status = g_lock_lock(ctx, string_term_tdb_data(name),
G_LOCK_WRITE,
(struct timeval) { .tv_sec = 60 });
if (!NT_STATUS_IS_OK(status)) {
fprintf(stderr, "g_lock_lock failed: %s\n",