i2c-algo-bit: Read block data bugfix
[linux-2.6/openmoko-kernel.git] / drivers / md / dm-bio-list.h
blob16ee3b018b3aa83b80beda532ded23b609b731fb
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 struct bio_list {
13 struct bio *head;
14 struct bio *tail;
17 static inline int bio_list_empty(const struct bio_list *bl)
19 return bl->head == NULL;
22 #define BIO_LIST_INIT { .head = NULL, .tail = NULL }
24 #define BIO_LIST(bl) \
25 struct bio_list bl = BIO_LIST_INIT
27 static inline void bio_list_init(struct bio_list *bl)
29 bl->head = bl->tail = NULL;
32 #define bio_list_for_each(bio, bl) \
33 for (bio = (bl)->head; bio; bio = bio->bi_next)
35 static inline unsigned bio_list_size(const struct bio_list *bl)
37 unsigned sz = 0;
38 struct bio *bio;
40 bio_list_for_each(bio, bl)
41 sz++;
43 return sz;
46 static inline void bio_list_add(struct bio_list *bl, struct bio *bio)
48 bio->bi_next = NULL;
50 if (bl->tail)
51 bl->tail->bi_next = bio;
52 else
53 bl->head = bio;
55 bl->tail = bio;
58 static inline void bio_list_merge(struct bio_list *bl, struct bio_list *bl2)
60 if (!bl2->head)
61 return;
63 if (bl->tail)
64 bl->tail->bi_next = bl2->head;
65 else
66 bl->head = bl2->head;
68 bl->tail = bl2->tail;
71 static inline void bio_list_merge_head(struct bio_list *bl,
72 struct bio_list *bl2)
74 if (!bl2->head)
75 return;
77 if (bl->head)
78 bl2->tail->bi_next = bl->head;
79 else
80 bl->tail = bl2->tail;
82 bl->head = bl2->head;
85 static inline struct bio *bio_list_pop(struct bio_list *bl)
87 struct bio *bio = bl->head;
89 if (bio) {
90 bl->head = bl->head->bi_next;
91 if (!bl->head)
92 bl->tail = NULL;
94 bio->bi_next = NULL;
97 return bio;
100 static inline struct bio *bio_list_get(struct bio_list *bl)
102 struct bio *bio = bl->head;
104 bl->head = bl->tail = NULL;
106 return bio;
109 #endif