blob: da4349649f7f2cd5c7c6d628f40d8bf1a1463b84 [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
17static inline void bio_list_init(struct bio_list *bl)
18{
19 bl->head = bl->tail = NULL;
20}
21
22static inline void bio_list_add(struct bio_list *bl, struct bio *bio)
23{
24 bio->bi_next = NULL;
25
26 if (bl->tail)
27 bl->tail->bi_next = bio;
28 else
29 bl->head = bio;
30
31 bl->tail = bio;
32}
33
34static inline void bio_list_merge(struct bio_list *bl, struct bio_list *bl2)
35{
jblunck@suse.de233886dd2005-11-21 21:32:36 -080036 if (!bl2->head)
37 return;
38
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 if (bl->tail)
40 bl->tail->bi_next = bl2->head;
41 else
42 bl->head = bl2->head;
43
44 bl->tail = bl2->tail;
45}
46
Kiyoshi Ueda2e93ccc2006-12-08 02:41:09 -080047static inline void bio_list_merge_head(struct bio_list *bl,
48 struct bio_list *bl2)
49{
50 if (!bl2->head)
51 return;
52
53 if (bl->head)
54 bl2->tail->bi_next = bl->head;
55 else
56 bl->tail = bl2->tail;
57
58 bl->head = bl2->head;
59}
60
Linus Torvalds1da177e2005-04-16 15:20:36 -070061static inline struct bio *bio_list_pop(struct bio_list *bl)
62{
63 struct bio *bio = bl->head;
64
65 if (bio) {
66 bl->head = bl->head->bi_next;
67 if (!bl->head)
68 bl->tail = NULL;
69
70 bio->bi_next = NULL;
71 }
72
73 return bio;
74}
75
76static inline struct bio *bio_list_get(struct bio_list *bl)
77{
78 struct bio *bio = bl->head;
79
80 bl->head = bl->tail = NULL;
81
82 return bio;
83}
84
85#endif