s3:locking: move from uint8_t share_mode_lock_key_data[] to struct file_id
authorStefan Metzmacher <metze@samba.org>
Fri, 26 Aug 2022 07:42:45 +0000 (09:42 +0200)
committerJeremy Allison <jra@samba.org>
Tue, 20 Sep 2022 00:34:35 +0000 (00:34 +0000)
This will allow us to have better debug messages and will also make
further changes easier.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/locking/share_mode_lock.c

index 9d88f7766b2b7db1a57b1c42eb065ca4e10323f6..6354ae00ed83bcab620451066188cf462270be21 100644 (file)
@@ -725,10 +725,10 @@ fail:
 /*
  * Key that's locked with g_lock
  */
-static uint8_t share_mode_lock_key_data[sizeof(struct file_id)];
+static struct file_id share_mode_lock_key_id = {};
 static TDB_DATA share_mode_lock_key = {
-       .dptr = share_mode_lock_key_data,
-       .dsize = sizeof(share_mode_lock_key_data),
+       .dptr = (uint8_t *)&share_mode_lock_key_id,
+       .dsize = sizeof(share_mode_lock_key_id),
 };
 static size_t share_mode_lock_key_refcount = 0;
 
@@ -878,7 +878,6 @@ struct share_mode_lock *get_share_mode_lock(
        TDB_DATA key = locking_key(&id);
        struct share_mode_lock *lck = NULL;
        NTSTATUS status;
-       int cmp;
 
        lck = talloc(mem_ctx, struct share_mode_lock);
        if (lck == NULL) {
@@ -914,12 +913,17 @@ struct share_mode_lock *get_share_mode_lock(
                                  nt_errstr(status));
                        goto fail;
                }
-               memcpy(share_mode_lock_key_data, key.dptr, key.dsize);
+               share_mode_lock_key_id = id;
        }
 
-       cmp = tdb_data_cmp(share_mode_lock_key, key);
-       if (cmp != 0) {
-               DBG_WARNING("Can not lock two share modes simultaneously\n");
+       if (!file_id_equal(&share_mode_lock_key_id, &id)) {
+               struct file_id_buf existing;
+               struct file_id_buf requested;
+
+               DBG_ERR("Can not lock two share modes "
+                       "simultaneously: existing %s requested %s\n",
+                       file_id_str_buf(share_mode_lock_key_id, &existing),
+                       file_id_str_buf(id, &requested));
                smb_panic(__location__);
                goto fail;
        }