bcachefs: list_pop_entry()
authorKent Overstreet <kent.overstreet@linux.dev>
Sat, 30 Nov 2024 00:13:54 +0000 (19:13 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sat, 21 Dec 2024 06:36:21 +0000 (01:36 -0500)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/ec.c
fs/bcachefs/io_write.c
fs/bcachefs/util.h

index eaca4c39d703d46fd8808e36baeddc1d909ce55d..df9c0e4533919af20a41f9b48ca6b172c35e6728 100644 (file)
@@ -2456,11 +2456,9 @@ void bch2_fs_ec_exit(struct bch_fs *c)
 
        while (1) {
                mutex_lock(&c->ec_stripe_head_lock);
-               h = list_first_entry_or_null(&c->ec_stripe_head_list,
-                                            struct ec_stripe_head, list);
-               if (h)
-                       list_del(&h->list);
+               h = list_pop_entry(&c->ec_stripe_head_list, struct ec_stripe_head, list);
                mutex_unlock(&c->ec_stripe_head_lock);
+
                if (!h)
                        break;
 
index bae045e76055740f1345614ef1f52ee52964d8df..3e71860f66b9e877b825e61daad8af97797e81df 100644 (file)
@@ -637,9 +637,7 @@ void bch2_write_point_do_index_updates(struct work_struct *work)
 
        while (1) {
                spin_lock_irq(&wp->writes_lock);
-               op = list_first_entry_or_null(&wp->writes, struct bch_write_op, wp_list);
-               if (op)
-                       list_del(&op->wp_list);
+               op = list_pop_entry(&wp->writes, struct bch_write_op, wp_list);
                wp_update_state(wp, op != NULL);
                spin_unlock_irq(&wp->writes_lock);
 
index fb02c1c360044352205572a4970c237239d9848b..5e4820c8fa44b8852ddfbf2cb6e0d869d017cb36 100644 (file)
@@ -317,6 +317,19 @@ do {                                                                       \
        _ptr ? container_of(_ptr, type, member) : NULL;                 \
 })
 
+static inline struct list_head *list_pop(struct list_head *head)
+{
+       if (list_empty(head))
+               return NULL;
+
+       struct list_head *ret = head->next;
+       list_del_init(ret);
+       return ret;
+}
+
+#define list_pop_entry(head, type, member)             \
+       container_of_or_null(list_pop(head), type, member)
+
 /* Does linear interpolation between powers of two */
 static inline unsigned fract_exp_two(unsigned x, unsigned fract_bits)
 {