s3:locking: remove static_share_mode_data_refcount
authorStefan Metzmacher <metze@samba.org>
Fri, 26 Aug 2022 07:50:00 +0000 (09:50 +0200)
committerJeremy Allison <jra@samba.org>
Tue, 20 Sep 2022 00:34:35 +0000 (00:34 +0000)
The effective value of share_mode_lock_key_refcount
is 'share_mode_lock_key_refcount + static_share_mode_data_refcount',
which is quite confusing.

This complexity is not needed and we can just use
share_mode_lock_key_refcount.

This will also simplify further changes.

Review with: git show -U15 -w

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 6354ae00ed83bcab620451066188cf462270be21..3068ef0456387c367edc69266445603d92ae89f3 100644 (file)
@@ -738,7 +738,6 @@ static size_t share_mode_lock_key_refcount = 0;
  * share_mode_lock structures, explicitly refcounted.
  */
 static struct share_mode_data *static_share_mode_data = NULL;
-static size_t static_share_mode_data_refcount = 0;
 
 /*******************************************************************
  Either fetch a share mode from the database, or allocate a fresh
@@ -886,22 +885,6 @@ struct share_mode_lock *get_share_mode_lock(
        }
        lck->id = id;
 
-       if (static_share_mode_data != NULL) {
-               if (!file_id_equal(&static_share_mode_data->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(static_share_mode_data->id, &existing),
-                               file_id_str_buf(id, &requested));
-
-                       smb_panic(__location__);
-                       goto fail;
-               }
-               goto done;
-       }
-
        if (share_mode_lock_key_refcount == 0) {
                status = g_lock_lock(
                        lock_ctx,
@@ -931,7 +914,9 @@ struct share_mode_lock *get_share_mode_lock(
        SMB_ASSERT(share_mode_lock_key_refcount < SIZE_MAX);
        share_mode_lock_key_refcount += 1;
 
-       SMB_ASSERT(static_share_mode_data_refcount == 0);
+       if (static_share_mode_data != NULL) {
+               goto done;
+       }
 
        status = get_static_share_mode_data(
                id,
@@ -945,7 +930,6 @@ struct share_mode_lock *get_share_mode_lock(
                goto fail;
        }
 done:
-       static_share_mode_data_refcount += 1;
        lck->cached_data = static_share_mode_data;
 
        talloc_set_destructor(lck, share_mode_lock_destructor);
@@ -953,9 +937,9 @@ done:
        if (CHECK_DEBUGLVL(DBGLVL_DEBUG)) {
                struct file_id_buf returned;
 
-               DBG_DEBUG("Returning %s (data_refcount=%zu key_refcount=%zu)\n",
+               DBG_DEBUG("Returning %s (data_cached=%u key_refcount=%zu)\n",
                          file_id_str_buf(id, &returned),
-                         static_share_mode_data_refcount,
+                         static_share_mode_data != NULL,
                          share_mode_lock_key_refcount);
        }
 
@@ -976,10 +960,10 @@ static int share_mode_lock_destructor(struct share_mode_lock *lck)
 {
        NTSTATUS status;
 
-       SMB_ASSERT(static_share_mode_data_refcount > 0);
-       static_share_mode_data_refcount -= 1;
+       SMB_ASSERT(share_mode_lock_key_refcount > 0);
+       share_mode_lock_key_refcount -= 1;
 
-       if (static_share_mode_data_refcount > 0) {
+       if (share_mode_lock_key_refcount > 0) {
                return 0;
        }
 
@@ -990,16 +974,11 @@ static int share_mode_lock_destructor(struct share_mode_lock *lck)
                smb_panic("Could not store share mode data\n");
        }
 
-       SMB_ASSERT(share_mode_lock_key_refcount > 0);
-       share_mode_lock_key_refcount -= 1;
-
-       if (share_mode_lock_key_refcount == 0) {
-               status = g_lock_unlock(lock_ctx, share_mode_lock_key);
-               if (!NT_STATUS_IS_OK(status)) {
-                       DBG_ERR("g_lock_unlock failed: %s\n",
-                               nt_errstr(status));
-                       smb_panic("Could not unlock share mode\n");
-               }
+       status = g_lock_unlock(lock_ctx, share_mode_lock_key);
+       if (!NT_STATUS_IS_OK(status)) {
+               DBG_ERR("g_lock_unlock failed: %s\n",
+                       nt_errstr(status));
+               smb_panic("Could not unlock share mode\n");
        }
 
        if (!static_share_mode_data->not_stored) {