]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
g_lock: Change prototype of g_lock_dump
authorVolker Lendecke <vl@samba.org>
Fri, 25 Oct 2019 11:35:39 +0000 (13:35 +0200)
committerJeremy Allison <jra@samba.org>
Fri, 22 Nov 2019 23:57:47 +0000 (23:57 +0000)
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>
source3/include/g_lock.h
source3/lib/g_lock.c
source3/smbd/server.c
source3/torture/test_g_lock.c
source3/utils/net_g_lock.c

index 782a2e9d160e522b2a8030029695a416b1436b29..7fb424c13fc1c9d670aa0c223fa64bda849c9c30 100644 (file)
@@ -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),
index 3c76b34baa7cf90e6b26dd88a1490e4dda26a256..bfa659cde719ee739bf6ad7f191c28201144b46b 100644 (file)
@@ -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,
-                 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; 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;
+               }
+       }
 
-       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),
index 0cff4fcb39d437ddb5da80376e9533e7b4c05278..20f34bc401bb8af171eefc5101676afbaada0cc9 100644 (file)
@@ -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)
index 615f7fcfbe8dd930e2faaa042e90274d0ed6f3a5..263192baaddebb6d54ef6df420561d89df5c6879 100644 (file)
@@ -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);
 }
 
 /*
index 8dd58b2c1bad1bd537954bb0fe1b149a40b49bd3..3652fc7b13f4f1238a85134e7f1883da60cbe9d6 100644 (file)
@@ -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; 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");
+       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<num_shared; i++) {
+                       d_printf("%s: READ\n",
+                                server_id_str_buf(shared[i], &idbuf));
+               }
        }
        dump_data_file(data, datalen, true, stdout);
 }