| 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 |  | 
| aherrman@arcor.de | 2123a09 | 2007-09-14 01:28:56 +0200 | [diff] [blame] | 12 | #ifdef CONFIG_BLOCK | 
 | 13 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | struct bio_list { | 
 | 15 | 	struct bio *head; | 
 | 16 | 	struct bio *tail; | 
 | 17 | }; | 
 | 18 |  | 
| Heinz Mauelshagen | 0ba6993 | 2007-05-09 02:33:05 -0700 | [diff] [blame] | 19 | static inline int bio_list_empty(const struct bio_list *bl) | 
 | 20 | { | 
 | 21 | 	return bl->head == NULL; | 
 | 22 | } | 
 | 23 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | static inline void bio_list_init(struct bio_list *bl) | 
 | 25 | { | 
 | 26 | 	bl->head = bl->tail = NULL; | 
 | 27 | } | 
 | 28 |  | 
| Heinz Mauelshagen | 0ba6993 | 2007-05-09 02:33:05 -0700 | [diff] [blame] | 29 | #define bio_list_for_each(bio, bl) \ | 
| Alasdair G Kergon | 79e15ae | 2007-07-12 17:26:19 +0100 | [diff] [blame] | 30 | 	for (bio = (bl)->head; bio; bio = bio->bi_next) | 
| Heinz Mauelshagen | 0ba6993 | 2007-05-09 02:33:05 -0700 | [diff] [blame] | 31 |  | 
 | 32 | static inline unsigned bio_list_size(const struct bio_list *bl) | 
 | 33 | { | 
 | 34 | 	unsigned sz = 0; | 
 | 35 | 	struct bio *bio; | 
 | 36 |  | 
 | 37 | 	bio_list_for_each(bio, bl) | 
 | 38 | 		sz++; | 
 | 39 |  | 
 | 40 | 	return sz; | 
 | 41 | } | 
 | 42 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | static inline void bio_list_add(struct bio_list *bl, struct bio *bio) | 
 | 44 | { | 
 | 45 | 	bio->bi_next = NULL; | 
 | 46 |  | 
 | 47 | 	if (bl->tail) | 
 | 48 | 		bl->tail->bi_next = bio; | 
 | 49 | 	else | 
 | 50 | 		bl->head = bio; | 
 | 51 |  | 
 | 52 | 	bl->tail = bio; | 
 | 53 | } | 
 | 54 |  | 
 | 55 | static inline void bio_list_merge(struct bio_list *bl, struct bio_list *bl2) | 
 | 56 | { | 
| jblunck@suse.de | 233886dd | 2005-11-21 21:32:36 -0800 | [diff] [blame] | 57 | 	if (!bl2->head) | 
 | 58 | 		return; | 
 | 59 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | 	if (bl->tail) | 
 | 61 | 		bl->tail->bi_next = bl2->head; | 
 | 62 | 	else | 
 | 63 | 		bl->head = bl2->head; | 
 | 64 |  | 
 | 65 | 	bl->tail = bl2->tail; | 
 | 66 | } | 
 | 67 |  | 
| Kiyoshi Ueda | 2e93ccc | 2006-12-08 02:41:09 -0800 | [diff] [blame] | 68 | static inline void bio_list_merge_head(struct bio_list *bl, | 
 | 69 | 				       struct bio_list *bl2) | 
 | 70 | { | 
 | 71 | 	if (!bl2->head) | 
 | 72 | 		return; | 
 | 73 |  | 
 | 74 | 	if (bl->head) | 
 | 75 | 		bl2->tail->bi_next = bl->head; | 
 | 76 | 	else | 
 | 77 | 		bl->tail = bl2->tail; | 
 | 78 |  | 
 | 79 | 	bl->head = bl2->head; | 
 | 80 | } | 
 | 81 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | static inline struct bio *bio_list_pop(struct bio_list *bl) | 
 | 83 | { | 
 | 84 | 	struct bio *bio = bl->head; | 
 | 85 |  | 
 | 86 | 	if (bio) { | 
 | 87 | 		bl->head = bl->head->bi_next; | 
 | 88 | 		if (!bl->head) | 
 | 89 | 			bl->tail = NULL; | 
 | 90 |  | 
 | 91 | 		bio->bi_next = NULL; | 
 | 92 | 	} | 
 | 93 |  | 
 | 94 | 	return bio; | 
 | 95 | } | 
 | 96 |  | 
 | 97 | static inline struct bio *bio_list_get(struct bio_list *bl) | 
 | 98 | { | 
 | 99 | 	struct bio *bio = bl->head; | 
 | 100 |  | 
 | 101 | 	bl->head = bl->tail = NULL; | 
 | 102 |  | 
 | 103 | 	return bio; | 
 | 104 | } | 
 | 105 |  | 
| aherrman@arcor.de | 2123a09 | 2007-09-14 01:28:56 +0200 | [diff] [blame] | 106 | #endif /* CONFIG_BLOCK */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | #endif |