dm: bio list add bio_list_add_head
[linux-2.6/verdex.git] / drivers / md / dm-bio-list.h
blob345098b4ca77ac77400c00e7598f2398bec04a06
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 static inline void bio_list_init(struct bio_list *bl)
26 bl->head = bl->tail = NULL;
29 #define bio_list_for_each(bio, bl) \
30 for (bio = (bl)->head; bio; bio = bio->bi_next)
32 static inline unsigned bio_list_size(const struct bio_list *bl)
34 unsigned sz = 0;
35 struct bio *bio;
37 bio_list_for_each(bio, bl)
38 sz++;
40 return sz;
43 static inline void bio_list_add(struct bio_list *bl, struct bio *bio)
45 bio->bi_next = NULL;
47 if (bl->tail)
48 bl->tail->bi_next = bio;
49 else
50 bl->head = bio;
52 bl->tail = bio;
55 static inline void bio_list_add_head(struct bio_list *bl, struct bio *bio)
57 bio->bi_next = bl->head;
59 bl->head = bio;
61 if (!bl->tail)
62 bl->tail = bio;
65 static inline void bio_list_merge(struct bio_list *bl, struct bio_list *bl2)
67 if (!bl2->head)
68 return;
70 if (bl->tail)
71 bl->tail->bi_next = bl2->head;
72 else
73 bl->head = bl2->head;
75 bl->tail = bl2->tail;
78 static inline void bio_list_merge_head(struct bio_list *bl,
79 struct bio_list *bl2)
81 if (!bl2->head)
82 return;
84 if (bl->head)
85 bl2->tail->bi_next = bl->head;
86 else
87 bl->tail = bl2->tail;
89 bl->head = bl2->head;
92 static inline struct bio *bio_list_pop(struct bio_list *bl)
94 struct bio *bio = bl->head;
96 if (bio) {
97 bl->head = bl->head->bi_next;
98 if (!bl->head)
99 bl->tail = NULL;
101 bio->bi_next = NULL;
104 return bio;
107 static inline struct bio *bio_list_get(struct bio_list *bl)
109 struct bio *bio = bl->head;
111 bl->head = bl->tail = NULL;
113 return bio;
116 #endif /* CONFIG_BLOCK */
117 #endif