btrfs: use assertion helpers for extent buffer read lock counters
authorDavid Sterba <dsterba@suse.com>
Fri, 24 Aug 2018 14:15:51 +0000 (16:15 +0200)
committerDavid Sterba <dsterba@suse.com>
Mon, 29 Apr 2019 17:02:21 +0000 (19:02 +0200)
Use the helpers where open coded. On non-debug builds, the warnings will
not trigger and extent_buffer::read_locks become unused and can be
moved to the appropriate section, saving a few bytes.

Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/extent_io.c
fs/btrfs/extent_io.h
fs/btrfs/locking.c

index f010475f74fdfeda95d85cd8df4963ab458ed740..c189b018ed693e25f6e9d54d65d4d58a9ba6d367 100644 (file)
@@ -4678,7 +4678,6 @@ __alloc_extent_buffer(struct btrfs_fs_info *fs_info, u64 start,
        eb->bflags = 0;
        rwlock_init(&eb->lock);
        atomic_set(&eb->write_locks, 0);
        eb->bflags = 0;
        rwlock_init(&eb->lock);
        atomic_set(&eb->write_locks, 0);
-       atomic_set(&eb->read_locks, 0);
        atomic_set(&eb->blocking_readers, 0);
        atomic_set(&eb->blocking_writers, 0);
        eb->lock_nested = 0;
        atomic_set(&eb->blocking_readers, 0);
        atomic_set(&eb->blocking_writers, 0);
        eb->lock_nested = 0;
@@ -4701,6 +4700,7 @@ __alloc_extent_buffer(struct btrfs_fs_info *fs_info, u64 start,
 #ifdef CONFIG_BTRFS_DEBUG
        atomic_set(&eb->spinning_writers, 0);
        atomic_set(&eb->spinning_readers, 0);
 #ifdef CONFIG_BTRFS_DEBUG
        atomic_set(&eb->spinning_writers, 0);
        atomic_set(&eb->spinning_readers, 0);
+       atomic_set(&eb->read_locks, 0);
 #endif
 
        return eb;
 #endif
 
        return eb;
index 89e56df64d6cc7b9c0935865919d54fcbca6018c..41c5d0e9dc7567620ee69d4e9c392d6f9460e8dd 100644 (file)
@@ -162,7 +162,6 @@ struct extent_buffer {
 
        /* count of read lock holders on the extent buffer */
        atomic_t write_locks;
 
        /* count of read lock holders on the extent buffer */
        atomic_t write_locks;
-       atomic_t read_locks;
        atomic_t blocking_writers;
        atomic_t blocking_readers;
        short lock_nested;
        atomic_t blocking_writers;
        atomic_t blocking_readers;
        short lock_nested;
@@ -185,6 +184,7 @@ struct extent_buffer {
 #ifdef CONFIG_BTRFS_DEBUG
        atomic_t spinning_writers;
        atomic_t spinning_readers;
 #ifdef CONFIG_BTRFS_DEBUG
        atomic_t spinning_writers;
        atomic_t spinning_readers;
+       atomic_t read_locks;
        struct list_head leak_list;
 #endif
 };
        struct list_head leak_list;
 #endif
 };
index d3bb19835ab482b34067aed92b34992d19eb4fab..1088cf322fdde2909e7db70d462118990dcce14e 100644 (file)
@@ -164,7 +164,7 @@ again:
                           atomic_read(&eb->blocking_writers) == 0);
                goto again;
        }
                           atomic_read(&eb->blocking_writers) == 0);
                goto again;
        }
-       atomic_inc(&eb->read_locks);
+       btrfs_assert_tree_read_locks_get(eb);
        btrfs_assert_spinning_readers_get(eb);
 }
 
        btrfs_assert_spinning_readers_get(eb);
 }
 
@@ -183,7 +183,7 @@ int btrfs_tree_read_lock_atomic(struct extent_buffer *eb)
                read_unlock(&eb->lock);
                return 0;
        }
                read_unlock(&eb->lock);
                return 0;
        }
-       atomic_inc(&eb->read_locks);
+       btrfs_assert_tree_read_locks_get(eb);
        btrfs_assert_spinning_readers_get(eb);
        return 1;
 }
        btrfs_assert_spinning_readers_get(eb);
        return 1;
 }
@@ -204,7 +204,7 @@ int btrfs_try_tree_read_lock(struct extent_buffer *eb)
                read_unlock(&eb->lock);
                return 0;
        }
                read_unlock(&eb->lock);
                return 0;
        }
-       atomic_inc(&eb->read_locks);
+       btrfs_assert_tree_read_locks_get(eb);
        btrfs_assert_spinning_readers_get(eb);
        return 1;
 }
        btrfs_assert_spinning_readers_get(eb);
        return 1;
 }
@@ -248,7 +248,7 @@ void btrfs_tree_read_unlock(struct extent_buffer *eb)
        }
        btrfs_assert_tree_read_locked(eb);
        btrfs_assert_spinning_readers_put(eb);
        }
        btrfs_assert_tree_read_locked(eb);
        btrfs_assert_spinning_readers_put(eb);
-       atomic_dec(&eb->read_locks);
+       btrfs_assert_tree_read_locks_put(eb);
        read_unlock(&eb->lock);
 }
 
        read_unlock(&eb->lock);
 }
 
@@ -272,7 +272,7 @@ void btrfs_tree_read_unlock_blocking(struct extent_buffer *eb)
        /* atomic_dec_and_test implies a barrier */
        if (atomic_dec_and_test(&eb->blocking_readers))
                cond_wake_up_nomb(&eb->read_lock_wq);
        /* atomic_dec_and_test implies a barrier */
        if (atomic_dec_and_test(&eb->blocking_readers))
                cond_wake_up_nomb(&eb->read_lock_wq);
-       atomic_dec(&eb->read_locks);
+       btrfs_assert_tree_read_locks_put(eb);
 }
 
 /*
 }
 
 /*