mirror of
https://github.com/samba-team/samba.git
synced 2025-02-23 09:57:40 +03:00
g_lock: Change prototype of g_lock_dump
Soon the g_lock database format will change. There will be one exclusive entry and an array of shared entries. In that format, there's no need to attach a lock_type to each entry in the g_lock database. Reflect this change in the g_lock_dump API Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
This commit is contained in:
parent
06b0bcdf8d
commit
c9b34cd205
@ -55,8 +55,9 @@ int g_lock_locks(struct g_lock_ctx *ctx,
|
||||
int (*fn)(TDB_DATA key, void *private_data),
|
||||
void *private_data);
|
||||
NTSTATUS g_lock_dump(struct g_lock_ctx *ctx, TDB_DATA key,
|
||||
void (*fn)(const struct g_lock_rec *locks,
|
||||
size_t num_locks,
|
||||
void (*fn)(struct server_id exclusive,
|
||||
size_t num_shared,
|
||||
struct server_id *shared,
|
||||
const uint8_t *data,
|
||||
size_t datalen,
|
||||
void *private_data),
|
||||
|
@ -681,8 +681,9 @@ int g_lock_locks(struct g_lock_ctx *ctx,
|
||||
struct g_lock_dump_state {
|
||||
TALLOC_CTX *mem_ctx;
|
||||
TDB_DATA key;
|
||||
void (*fn)(const struct g_lock_rec *locks,
|
||||
size_t num_locks,
|
||||
void (*fn)(struct server_id exclusive,
|
||||
size_t num_shared,
|
||||
struct server_id *shared,
|
||||
const uint8_t *data,
|
||||
size_t datalen,
|
||||
void *private_data);
|
||||
@ -694,8 +695,10 @@ static void g_lock_dump_fn(TDB_DATA key, TDB_DATA data,
|
||||
void *private_data)
|
||||
{
|
||||
struct g_lock_dump_state *state = private_data;
|
||||
struct g_lock_rec *recs;
|
||||
struct g_lock_rec *recs = NULL;
|
||||
struct g_lock lck;
|
||||
struct server_id exclusive = { .pid = 0 };
|
||||
struct server_id *shared = NULL;
|
||||
size_t i;
|
||||
bool ok;
|
||||
|
||||
@ -713,24 +716,52 @@ static void g_lock_dump_fn(TDB_DATA key, TDB_DATA data,
|
||||
if (recs == NULL) {
|
||||
DBG_DEBUG("talloc failed\n");
|
||||
state->status = NT_STATUS_NO_MEMORY;
|
||||
return;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
for (i=0; i<lck.num_recs; i++) {
|
||||
g_lock_get_rec(&lck, i, &recs[i]);
|
||||
}
|
||||
|
||||
state->fn(recs, lck.num_recs, lck.data, lck.datalen,
|
||||
if ((lck.num_recs == 1) && (recs[0].lock_type == G_LOCK_WRITE)) {
|
||||
exclusive = recs[0].pid;
|
||||
lck.num_recs = 0;
|
||||
} else {
|
||||
shared = talloc_array(recs, struct server_id, lck.num_recs);
|
||||
if (shared == NULL) {
|
||||
DBG_DEBUG("talloc_array failed\n");
|
||||
state->status = NT_STATUS_NO_MEMORY;
|
||||
goto fail;
|
||||
}
|
||||
for (i=0; i<lck.num_recs; i++) {
|
||||
if (recs[i].lock_type != G_LOCK_READ) {
|
||||
DBG_WARNING("locks[%zu] has wrong type %d\n",
|
||||
i,
|
||||
(int)recs[i].lock_type);
|
||||
state->status =
|
||||
NT_STATUS_INTERNAL_DB_CORRUPTION;
|
||||
goto fail;
|
||||
}
|
||||
shared[i] = recs[i].pid;
|
||||
}
|
||||
}
|
||||
|
||||
state->fn(exclusive,
|
||||
lck.num_recs,
|
||||
shared,
|
||||
lck.data,
|
||||
lck.datalen,
|
||||
state->private_data);
|
||||
|
||||
TALLOC_FREE(recs);
|
||||
|
||||
state->status = NT_STATUS_OK;
|
||||
fail:
|
||||
TALLOC_FREE(recs);
|
||||
}
|
||||
|
||||
NTSTATUS g_lock_dump(struct g_lock_ctx *ctx, TDB_DATA key,
|
||||
void (*fn)(const struct g_lock_rec *locks,
|
||||
size_t num_locks,
|
||||
void (*fn)(struct server_id exclusive,
|
||||
size_t num_shared,
|
||||
struct server_id *shared,
|
||||
const uint8_t *data,
|
||||
size_t datalen,
|
||||
void *private_data),
|
||||
|
@ -1417,8 +1417,9 @@ struct smbd_claim_version_state {
|
||||
char *version;
|
||||
};
|
||||
|
||||
static void smbd_claim_version_parser(const struct g_lock_rec *locks,
|
||||
size_t num_locks,
|
||||
static void smbd_claim_version_parser(struct server_id exclusive,
|
||||
size_t num_shared,
|
||||
struct server_id *shared,
|
||||
const uint8_t *data,
|
||||
size_t datalen,
|
||||
void *private_data)
|
||||
|
@ -111,8 +111,9 @@ struct lock2_parser_state {
|
||||
bool ok;
|
||||
};
|
||||
|
||||
static void lock2_parser(const struct g_lock_rec *locks,
|
||||
size_t num_locks,
|
||||
static void lock2_parser(struct server_id exclusive,
|
||||
size_t num_shared,
|
||||
struct server_id *shared,
|
||||
const uint8_t *data,
|
||||
size_t datalen,
|
||||
void *private_data)
|
||||
@ -211,13 +212,16 @@ struct lock3_parser_state {
|
||||
bool ok;
|
||||
};
|
||||
|
||||
static void lock3_parser(const struct g_lock_rec *locks,
|
||||
size_t num_locks,
|
||||
static void lock3_parser(struct server_id exclusive,
|
||||
size_t num_shared,
|
||||
struct server_id *shared,
|
||||
const uint8_t *data,
|
||||
size_t datalen,
|
||||
void *private_data)
|
||||
{
|
||||
struct lock3_parser_state *state = private_data;
|
||||
size_t num_locks = num_shared + ((exclusive.pid != 0) ? 1 : 0);
|
||||
struct server_id *pid;
|
||||
|
||||
if (datalen != 0) {
|
||||
fprintf(stderr, "datalen=%zu\n", datalen);
|
||||
@ -227,15 +231,25 @@ static void lock3_parser(const struct g_lock_rec *locks,
|
||||
fprintf(stderr, "num_locks=%zu\n", num_locks);
|
||||
return;
|
||||
}
|
||||
if (locks[0].lock_type != state->lock_type) {
|
||||
fprintf(stderr, "found type %d, expected %d\n",
|
||||
(int)locks[0].lock_type, (int)state->lock_type);
|
||||
return;
|
||||
|
||||
if (state->lock_type == G_LOCK_WRITE) {
|
||||
if (exclusive.pid == 0) {
|
||||
fprintf(stderr, "Found READ, expected WRITE\n");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (exclusive.pid != 0) {
|
||||
fprintf(stderr, "Found WRITE, expected READ\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!server_id_equal(&locks[0].pid, &state->self)) {
|
||||
|
||||
pid = (exclusive.pid != 0) ? &exclusive : &shared[0];
|
||||
|
||||
if (!server_id_equal(pid, &state->self)) {
|
||||
struct server_id_buf tmp1, tmp2;
|
||||
fprintf(stderr, "found pid %s, expected %s\n",
|
||||
server_id_str_buf(locks[0].pid, &tmp1),
|
||||
server_id_str_buf(*pid, &tmp1),
|
||||
server_id_str_buf(state->self, &tmp2));
|
||||
return;
|
||||
}
|
||||
@ -408,30 +422,31 @@ struct lock4_check_state {
|
||||
bool ok;
|
||||
};
|
||||
|
||||
static void lock4_check(const struct g_lock_rec *locks,
|
||||
size_t num_locks,
|
||||
static void lock4_check(struct server_id exclusive,
|
||||
size_t num_shared,
|
||||
struct server_id *shared,
|
||||
const uint8_t *data,
|
||||
size_t datalen,
|
||||
void *private_data)
|
||||
{
|
||||
struct lock4_check_state *state = private_data;
|
||||
size_t num_locks = num_shared + ((exclusive.pid != 0) ? 1 : 0);
|
||||
|
||||
if (num_locks != 1) {
|
||||
fprintf(stderr, "num_locks=%zu\n", num_locks);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!server_id_equal(&state->me, &locks[0].pid)) {
|
||||
struct server_id_buf buf1, buf2;
|
||||
fprintf(stderr, "me=%s, locker=%s\n",
|
||||
server_id_str_buf(state->me, &buf1),
|
||||
server_id_str_buf(locks[0].pid, &buf2));
|
||||
if (exclusive.pid == 0) {
|
||||
fprintf(stderr, "Wrong lock type, not WRITE\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (locks[0].lock_type != G_LOCK_WRITE) {
|
||||
fprintf(stderr, "wrong lock type: %d\n",
|
||||
(int)locks[0].lock_type);
|
||||
if (!server_id_equal(&state->me, &exclusive)) {
|
||||
struct server_id_buf buf1, buf2;
|
||||
fprintf(stderr, "me=%s, locker=%s\n",
|
||||
server_id_str_buf(state->me, &buf1),
|
||||
server_id_str_buf(exclusive, &buf2));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -565,14 +580,15 @@ struct lock5_parser_state {
|
||||
size_t num_locks;
|
||||
};
|
||||
|
||||
static void lock5_parser(const struct g_lock_rec *locks,
|
||||
size_t num_locks,
|
||||
static void lock5_parser(struct server_id exclusive,
|
||||
size_t num_shared,
|
||||
struct server_id *shared,
|
||||
const uint8_t *data,
|
||||
size_t datalen,
|
||||
void *private_data)
|
||||
{
|
||||
struct lock5_parser_state *state = private_data;
|
||||
state->num_locks = num_locks;
|
||||
state->num_locks = num_shared + ((exclusive.pid != 0) ? 1 : 0);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -711,14 +727,15 @@ struct lock6_parser_state {
|
||||
size_t num_locks;
|
||||
};
|
||||
|
||||
static void lock6_parser(const struct g_lock_rec *locks,
|
||||
size_t num_locks,
|
||||
static void lock6_parser(struct server_id exclusive,
|
||||
size_t num_shared,
|
||||
struct server_id *shared,
|
||||
const uint8_t *data,
|
||||
size_t datalen,
|
||||
void *private_data)
|
||||
{
|
||||
struct lock6_parser_state *state = private_data;
|
||||
state->num_locks = num_locks;
|
||||
state->num_locks = num_shared + ((exclusive.pid != 0) ? 1 : 0);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -111,19 +111,24 @@ done:
|
||||
return result;
|
||||
}
|
||||
|
||||
static void net_g_lock_dump_fn(const struct g_lock_rec *locks,
|
||||
size_t num_locks,
|
||||
const uint8_t *data,
|
||||
size_t datalen,
|
||||
void *private_data)
|
||||
static void net_g_lock_dump_fn(struct server_id exclusive,
|
||||
size_t num_shared,
|
||||
struct server_id *shared,
|
||||
const uint8_t *data,
|
||||
size_t datalen,
|
||||
void *private_data)
|
||||
{
|
||||
size_t i;
|
||||
struct server_id_buf idbuf;
|
||||
|
||||
for (i=0; i<num_locks; i++) {
|
||||
const struct g_lock_rec *l = &locks[i];
|
||||
struct server_id_buf idbuf;
|
||||
d_printf("%s: %s\n", server_id_str_buf(l->pid, &idbuf),
|
||||
(l->lock_type & 1) ? "WRITE" : "READ");
|
||||
if (exclusive.pid != 0) {
|
||||
d_printf("%s: WRITE\n",
|
||||
server_id_str_buf(exclusive, &idbuf));
|
||||
} else {
|
||||
size_t i;
|
||||
for (i=0; i<num_shared; i++) {
|
||||
d_printf("%s: READ\n",
|
||||
server_id_str_buf(shared[i], &idbuf));
|
||||
}
|
||||
}
|
||||
dump_data_file(data, datalen, true, stdout);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user