]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
btrfs: change return type of btrfs_delayed_ref_lock() to boolean
authorFilipe Manana <fdmanana@suse.com>
Mon, 21 Oct 2024 11:32:55 +0000 (12:32 +0100)
committerDavid Sterba <dsterba@suse.com>
Mon, 11 Nov 2024 13:34:20 +0000 (14:34 +0100)
The function only returns 0, meaning it was able to lock the delayed ref
head, or -EAGAIN in case it wasn't able to lock it. So simplify this and
use a boolean return type instead, returning true if it was able to lock
and false otherwise.

Reviewed-by: Boris Burkov <boris@bur.io>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/delayed-ref.c
fs/btrfs/delayed-ref.h
fs/btrfs/extent-tree.c

index f7c7d1249f04f8fcf741cae2c62d3558e261f017..8392cb366700e0ca42b3fb3ca75ace3233d6657b 100644 (file)
@@ -431,12 +431,12 @@ static struct btrfs_delayed_ref_head *find_ref_head(
        return NULL;
 }
 
-int btrfs_delayed_ref_lock(struct btrfs_delayed_ref_root *delayed_refs,
-                          struct btrfs_delayed_ref_head *head)
+bool btrfs_delayed_ref_lock(struct btrfs_delayed_ref_root *delayed_refs,
+                           struct btrfs_delayed_ref_head *head)
 {
        lockdep_assert_held(&delayed_refs->lock);
        if (mutex_trylock(&head->mutex))
-               return 0;
+               return true;
 
        refcount_inc(&head->refs);
        spin_unlock(&delayed_refs->lock);
@@ -446,10 +446,10 @@ int btrfs_delayed_ref_lock(struct btrfs_delayed_ref_root *delayed_refs,
        if (RB_EMPTY_NODE(&head->href_node)) {
                mutex_unlock(&head->mutex);
                btrfs_put_delayed_ref_head(head);
-               return -EAGAIN;
+               return false;
        }
        btrfs_put_delayed_ref_head(head);
-       return 0;
+       return true;
 }
 
 static inline void drop_delayed_ref(struct btrfs_fs_info *fs_info,
@@ -1250,7 +1250,7 @@ void btrfs_destroy_delayed_refs(struct btrfs_transaction *trans)
                if (!head)
                        break;
 
-               if (btrfs_delayed_ref_lock(delayed_refs, head))
+               if (!btrfs_delayed_ref_lock(delayed_refs, head))
                        continue;
 
                spin_lock(&head->lock);
index a97c9df19ea0715fc6122348fbd0b6a57e48c2d3..04730c6502126b533ac896c973bab5cbd2cbce46 100644 (file)
@@ -369,8 +369,8 @@ void btrfs_merge_delayed_refs(struct btrfs_fs_info *fs_info,
 struct btrfs_delayed_ref_head *
 btrfs_find_delayed_ref_head(struct btrfs_delayed_ref_root *delayed_refs,
                            u64 bytenr);
-int btrfs_delayed_ref_lock(struct btrfs_delayed_ref_root *delayed_refs,
-                          struct btrfs_delayed_ref_head *head);
+bool btrfs_delayed_ref_lock(struct btrfs_delayed_ref_root *delayed_refs,
+                           struct btrfs_delayed_ref_head *head);
 static inline void btrfs_delayed_ref_unlock(struct btrfs_delayed_ref_head *head)
 {
        mutex_unlock(&head->mutex);
index adff2b6fb629409e98cd3e9252479d444d4f6174..b9f455ae8788a4042c26c7fd517bbbe469125e06 100644 (file)
@@ -1959,7 +1959,7 @@ static struct btrfs_delayed_ref_head *btrfs_obtain_ref_head(
        struct btrfs_delayed_ref_root *delayed_refs =
                &trans->transaction->delayed_refs;
        struct btrfs_delayed_ref_head *head = NULL;
-       int ret;
+       bool locked;
 
        spin_lock(&delayed_refs->lock);
        head = btrfs_select_ref_head(delayed_refs);
@@ -1972,7 +1972,7 @@ static struct btrfs_delayed_ref_head *btrfs_obtain_ref_head(
         * Grab the lock that says we are going to process all the refs for
         * this head
         */
-       ret = btrfs_delayed_ref_lock(delayed_refs, head);
+       locked = btrfs_delayed_ref_lock(delayed_refs, head);
        spin_unlock(&delayed_refs->lock);
 
        /*
@@ -1980,7 +1980,7 @@ static struct btrfs_delayed_ref_head *btrfs_obtain_ref_head(
         * that might have given someone else time to free the head.  If that's
         * true, it has been removed from our list and we can move on.
         */
-       if (ret == -EAGAIN)
+       if (!locked)
                head = ERR_PTR(-EAGAIN);
 
        return head;