]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
g_lock: Make g_lock_dump return a complete list of locks
authorVolker Lendecke <vl@samba.org>
Thu, 18 May 2017 13:27:46 +0000 (15:27 +0200)
committerVolker Lendecke <vl@samba.org>
Thu, 15 Jun 2017 11:19:14 +0000 (13:19 +0200)
To be honest, it did not really make sense to just pass in
lock holders individually. You could argue that it made sense
with in reality only G_LOCK_WRITE around, but soon we will have
G_LOCK_READ and thus multiple lock holders on a single lock.

Now that we also have userdata, change 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/utils/net_g_lock.c

index f79e0ceef9997f476dc75387d79e3f64447b58f0..e6d4de14cf37c143856fc1e31c3e6542f1b903d8 100644 (file)
@@ -30,6 +30,11 @@ enum g_lock_type {
        G_LOCK_WRITE = 1,
 };
 
+struct g_lock_rec {
+       enum g_lock_type lock_type;
+       struct server_id pid;
+};
+
 struct g_lock_ctx *g_lock_ctx_init(TALLOC_CTX *mem_ctx,
                                   struct messaging_context *msg);
 
@@ -54,9 +59,11 @@ int g_lock_locks(struct g_lock_ctx *ctx,
                 int (*fn)(const char *name, void *private_data),
                 void *private_data);
 NTSTATUS g_lock_dump(struct g_lock_ctx *ctx, const char *name,
-                    int (*fn)(struct server_id pid,
-                              enum g_lock_type lock_type,
-                              void *private_data),
+                    void (*fn)(const struct g_lock_rec *locks,
+                               size_t num_locks,
+                               const uint8_t *data,
+                               size_t datalen,
+                               void *private_data),
                     void *private_data);
 
 #endif
index f6c35bb1bcc9a28259f2093ba1f725aa3ab60955..db2f62ad9d4b99db15a433a9bbe9336b4d009d1a 100644 (file)
@@ -40,11 +40,6 @@ struct g_lock_ctx {
  * structures.
  */
 
-struct g_lock_rec {
-       enum g_lock_type lock_type;
-       struct server_id pid;
-};
-
 #define G_LOCK_REC_LENGTH (SERVER_ID_BUF_LENGTH+1)
 
 static void g_lock_rec_put(uint8_t buf[G_LOCK_REC_LENGTH],
@@ -637,14 +632,18 @@ int g_lock_locks(struct g_lock_ctx *ctx,
 }
 
 NTSTATUS g_lock_dump(struct g_lock_ctx *ctx, const char *name,
-                    int (*fn)(struct server_id pid,
-                              enum g_lock_type lock_type,
-                              void *private_data),
+                    void (*fn)(const struct g_lock_rec *locks,
+                               size_t num_locks,
+                               const uint8_t *data,
+                               size_t datalen,
+                               void *private_data),
                     void *private_data)
 {
        TDB_DATA data;
-       size_t i, num_locks;
+       size_t num_locks;
        struct g_lock_rec *locks = NULL;
+       uint8_t *userdata;
+       size_t userdatalen;
        NTSTATUS status;
 
        status = dbwrap_fetch_bystring(ctx->db, talloc_tos(), name, &data);
@@ -657,22 +656,19 @@ NTSTATUS g_lock_dump(struct g_lock_ctx *ctx, const char *name,
        }
 
        status = g_lock_get_talloc(talloc_tos(), data, &locks, &num_locks,
-                                  NULL, NULL);
-
-       TALLOC_FREE(data.dptr);
+                                  &userdata, &userdatalen);
 
        if (!NT_STATUS_IS_OK(status)) {
                DBG_DEBUG("g_lock_get for %s failed: %s\n", name,
                          nt_errstr(status));
+               TALLOC_FREE(data.dptr);
                return NT_STATUS_INTERNAL_ERROR;
        }
 
-       for (i=0; i<num_locks; i++) {
-               if (fn(locks[i].pid, locks[i].lock_type, private_data) != 0) {
-                       break;
-               }
-       }
+       fn(locks, num_locks, userdata, userdatalen, private_data);
+
        TALLOC_FREE(locks);
+       TALLOC_FREE(data.dptr);
        return NT_STATUS_OK;
 }
 
index d786f5a4ecb3e6ad92c5db9277a834cb24ef2fa1..7543fd8ed01e4080a995d396d3d83892461f484a 100644 (file)
@@ -109,13 +109,20 @@ done:
        return state.result;
 }
 
-static int net_g_lock_dump_fn(struct server_id pid, enum g_lock_type lock_type,
-                             void *private_data)
+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)
 {
-       struct server_id_buf idbuf;
-       d_printf("%s: %s\n", server_id_str_buf(pid, &idbuf),
-                (lock_type & 1) ? "WRITE" : "READ");
-       return 0;
+       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");
+       }
 }
 
 static int net_g_lock_dump(struct net_context *c, int argc, const char **argv)