From: Volker Lendecke Date: Fri, 25 Oct 2019 11:35:39 +0000 (+0200) Subject: g_lock: Change prototype of g_lock_dump X-Git-Tag: ldb-2.1.0~619 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c9b34cd2057c05e9965464ca5e9e28b423cb418b;p=thirdparty%2Fsamba.git 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 Reviewed-by: Jeremy Allison --- diff --git a/source3/include/g_lock.h b/source3/include/g_lock.h index 782a2e9d160..7fb424c13fc 100644 --- a/source3/include/g_lock.h +++ b/source3/include/g_lock.h @@ -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), diff --git a/source3/lib/g_lock.c b/source3/lib/g_lock.c index 3c76b34baa7..bfa659cde71 100644 --- a/source3/lib/g_lock.c +++ b/source3/lib/g_lock.c @@ -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; ifn(recs, lck.num_recs, lck.data, lck.datalen, - state->private_data); + 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; istatus = + NT_STATUS_INTERNAL_DB_CORRUPTION; + goto fail; + } + shared[i] = recs[i].pid; + } + } - TALLOC_FREE(recs); + state->fn(exclusive, + lck.num_recs, + shared, + lck.data, + lck.datalen, + state->private_data); 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), diff --git a/source3/smbd/server.c b/source3/smbd/server.c index 0cff4fcb39d..20f34bc401b 100644 --- a/source3/smbd/server.c +++ b/source3/smbd/server.c @@ -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) diff --git a/source3/torture/test_g_lock.c b/source3/torture/test_g_lock.c index 615f7fcfbe8..263192baadd 100644 --- a/source3/torture/test_g_lock.c +++ b/source3/torture/test_g_lock.c @@ -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); } /* diff --git a/source3/utils/net_g_lock.c b/source3/utils/net_g_lock.c index 8dd58b2c1ba..3652fc7b13f 100644 --- a/source3/utils/net_g_lock.c +++ b/source3/utils/net_g_lock.c @@ -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; - - for (i=0; ipid, &idbuf), - (l->lock_type & 1) ? "WRITE" : "READ"); + struct server_id_buf idbuf; + + if (exclusive.pid != 0) { + d_printf("%s: WRITE\n", + server_id_str_buf(exclusive, &idbuf)); + } else { + size_t i; + for (i=0; i