Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 12 | struct bio_list { |
| 13 | struct bio *head; |
| 14 | struct bio *tail; |
| 15 | }; |
| 16 | |
Heinz Mauelshagen | 0ba6993 | 2007-05-09 02:33:05 -0700 | [diff] [blame] | 17 | static 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | static inline void bio_list_init(struct bio_list *bl) |
| 28 | { |
| 29 | bl->head = bl->tail = NULL; |
| 30 | } |
| 31 | |
Heinz Mauelshagen | 0ba6993 | 2007-05-09 02:33:05 -0700 | [diff] [blame] | 32 | #define bio_list_for_each(bio, bl) \ |
Alasdair G Kergon | 79e15ae | 2007-07-12 17:26:19 +0100 | [diff] [blame] | 33 | for (bio = (bl)->head; bio; bio = bio->bi_next) |
Heinz Mauelshagen | 0ba6993 | 2007-05-09 02:33:05 -0700 | [diff] [blame] | 34 | |
| 35 | static 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | static 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 | |
| 58 | static inline void bio_list_merge(struct bio_list *bl, struct bio_list *bl2) |
| 59 | { |
jblunck@suse.de | 233886dd | 2005-11-21 21:32:36 -0800 | [diff] [blame] | 60 | if (!bl2->head) |
| 61 | return; |
| 62 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | 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 Ueda | 2e93ccc | 2006-12-08 02:41:09 -0800 | [diff] [blame] | 71 | static 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | static 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 | |
| 100 | static 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 |