ACPI: thinkpad-acpi: keep track of module state
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / md / dm-bio-list.h
blob3f7b827649e3d5ceeb93c1e4d51a5290b4dce933
1 /*
2 * Copyright (C) 2004 Red Hat UK Ltd.
4 * This file is released under the GPL.
5 */
7 #ifndef DM_BIO_LIST_H
8 #define DM_BIO_LIST_H
10 #include <linux/bio.h>
12 #ifdef CONFIG_BLOCK
14 struct bio_list {
15 struct bio *head;
16 struct bio *tail;
19 static inline int bio_list_empty(const struct bio_list *bl)
21 return bl->head == NULL;
24 #define BIO_LIST_INIT { .head = NULL, .tail = NULL }
26 #define BIO_LIST(bl) \
27 struct bio_list bl = BIO_LIST_INIT
29 static inline void bio_list_init(struct bio_list *bl)
31 bl->head = bl->tail = NULL;
34 #define bio_list_for_each(bio, bl) \
35 for (bio = (bl)->head; bio; bio = bio->bi_next)
37 static inline unsigned bio_list_size(const struct bio_list *bl)
39 unsigned sz = 0;
40 struct bio *bio;
42 bio_list_for_each(bio, bl)
43 sz++;
45 return sz;
48 static inline void bio_list_add(struct bio_list *bl, struct bio *bio)
50 bio->bi_next = NULL;
52 if (bl->tail)
53 bl->tail->bi_next = bio;
54 else
55 bl->head = bio;
57 bl->tail = bio;
60 static inline void bio_list_merge(struct bio_list *bl, struct bio_list *bl2)
62 if (!bl2->head)
63 return;
65 if (bl->tail)
66 bl->tail->bi_next = bl2->head;
67 else
68 bl->head = bl2->head;
70 bl->tail = bl2->tail;
73 static inline void bio_list_merge_head(struct bio_list *bl,
74 struct bio_list *bl2)
76 if (!bl2->head)
77 return;
79 if (bl->head)
80 bl2->tail->bi_next = bl->head;
81 else
82 bl->tail = bl2->tail;
84 bl->head = bl2->head;
87 static inline struct bio *bio_list_pop(struct bio_list *bl)
89 struct bio *bio = bl->head;
91 if (bio) {
92 bl->head = bl->head->bi_next;
93 if (!bl->head)
94 bl->tail = NULL;
96 bio->bi_next = NULL;
99 return bio;
102 static inline struct bio *bio_list_get(struct bio_list *bl)
104 struct bio *bio = bl->head;
106 bl->head = bl->tail = NULL;
108 return bio;
111 #endif /* CONFIG_BLOCK */
112 #endif