blob: 16ee3b018b3aa83b80beda532ded23b609b731fb [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (C) 2004 Red Hat UK Ltd.
3 *
4 * This file is released under the GPL.
5 */
6
7#ifndef DM_BIO_LIST_H
8#define DM_BIO_LIST_H
9
10#include <linux/bio.h>
11
12struct bio_list {
13 struct bio *head;
14 struct bio *tail;
15};
16
Heinz Mauelshagen0ba69932007-05-09 02:33:05 -070017static inline int bio_list_empty(const struct bio_list *bl)
18{
19 return bl->head == NULL;
20}
21
22#define BIO_LIST_INIT { .head = NULL, .tail = NULL }
23
24#define BIO_LIST(bl) \
25 struct bio_list bl = BIO_LIST_INIT
26
Linus Torvalds1da177e2005-04-16 15:20:36 -070027static inline void bio_list_init(struct bio_list *bl)
28{
29 bl->head = bl->tail = NULL;
30}
31
Heinz Mauelshagen0ba69932007-05-09 02:33:05 -070032#define bio_list_for_each(bio, bl) \
Alasdair G Kergon79e15ae2007-07-12 17:26:19 +010033 for (bio = (bl)->head; bio; bio = bio->bi_next)
Heinz Mauelshagen0ba69932007-05-09 02:33:05 -070034
35static inline unsigned bio_list_size(const struct bio_list *bl)
36{
37 unsigned sz = 0;
38 struct bio *bio;
39
40 bio_list_for_each(bio, bl)
41 sz++;
42
43 return sz;
44}
45
Linus Torvalds1da177e2005-04-16 15:20:36 -070046static inline void bio_list_add(struct bio_list *bl, struct bio *bio)
47{
48 bio->bi_next = NULL;
49
50 if (bl->tail)
51 bl->tail->bi_next = bio;
52 else
53 bl->head = bio;
54
55 bl->tail = bio;
56}
57
58static inline void bio_list_merge(struct bio_list *bl, struct bio_list *bl2)
59{
jblunck@suse.de233886dd2005-11-21 21:32:36 -080060 if (!bl2->head)
61 return;
62
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 if (bl->tail)
64 bl->tail->bi_next = bl2->head;
65 else
66 bl->head = bl2->head;
67
68 bl->tail = bl2->tail;
69}
70
Kiyoshi Ueda2e93ccc2006-12-08 02:41:09 -080071static inline void bio_list_merge_head(struct bio_list *bl,
72 struct bio_list *bl2)
73{
74 if (!bl2->head)
75 return;
76
77 if (bl->head)
78 bl2->tail->bi_next = bl->head;
79 else
80 bl->tail = bl2->tail;
81
82 bl->head = bl2->head;
83}
84
Linus Torvalds1da177e2005-04-16 15:20:36 -070085static inline struct bio *bio_list_pop(struct bio_list *bl)
86{
87 struct bio *bio = bl->head;
88
89 if (bio) {
90 bl->head = bl->head->bi_next;
91 if (!bl->head)
92 bl->tail = NULL;
93
94 bio->bi_next = NULL;
95 }
96
97 return bio;
98}
99
100static inline struct bio *bio_list_get(struct bio_list *bl)
101{
102 struct bio *bio = bl->head;
103
104 bl->head = bl->tail = NULL;
105
106 return bio;
107}
108
109#endif