aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/bio.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/bio.h')
-rw-r--r--include/linux/bio.h145
1 files changed, 124 insertions, 21 deletions
diff --git a/include/linux/bio.h b/include/linux/bio.h
index 1b16108a5417..7b214fd672a2 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -132,6 +132,7 @@ struct bio {
132 * top 4 bits of bio flags indicate the pool this bio came from 132 * top 4 bits of bio flags indicate the pool this bio came from
133 */ 133 */
134#define BIO_POOL_BITS (4) 134#define BIO_POOL_BITS (4)
135#define BIO_POOL_NONE ((1UL << BIO_POOL_BITS) - 1)
135#define BIO_POOL_OFFSET (BITS_PER_LONG - BIO_POOL_BITS) 136#define BIO_POOL_OFFSET (BITS_PER_LONG - BIO_POOL_BITS)
136#define BIO_POOL_MASK (1UL << BIO_POOL_OFFSET) 137#define BIO_POOL_MASK (1UL << BIO_POOL_OFFSET)
137#define BIO_POOL_IDX(bio) ((bio)->bi_flags >> BIO_POOL_OFFSET) 138#define BIO_POOL_IDX(bio) ((bio)->bi_flags >> BIO_POOL_OFFSET)
@@ -145,20 +146,21 @@ struct bio {
145 * bit 2 -- barrier 146 * bit 2 -- barrier
146 * Insert a serialization point in the IO queue, forcing previously 147 * Insert a serialization point in the IO queue, forcing previously
147 * submitted IO to be completed before this one is issued. 148 * submitted IO to be completed before this one is issued.
148 * bit 3 -- synchronous I/O hint: the block layer will unplug immediately 149 * bit 3 -- synchronous I/O hint.
149 * Note that this does NOT indicate that the IO itself is sync, just 150 * bit 4 -- Unplug the device immediately after submitting this bio.
150 * that the block layer will not postpone issue of this IO by plugging. 151 * bit 5 -- metadata request
151 * bit 4 -- metadata request
152 * Used for tracing to differentiate metadata and data IO. May also 152 * Used for tracing to differentiate metadata and data IO. May also
153 * get some preferential treatment in the IO scheduler 153 * get some preferential treatment in the IO scheduler
154 * bit 5 -- discard sectors 154 * bit 6 -- discard sectors
155 * Informs the lower level device that this range of sectors is no longer 155 * Informs the lower level device that this range of sectors is no longer
156 * used by the file system and may thus be freed by the device. Used 156 * used by the file system and may thus be freed by the device. Used
157 * for flash based storage. 157 * for flash based storage.
158 * bit 6 -- fail fast device errors 158 * bit 7 -- fail fast device errors
159 * bit 7 -- fail fast transport errors 159 * bit 8 -- fail fast transport errors
160 * bit 8 -- fail fast driver errors 160 * bit 9 -- fail fast driver errors
161 * Don't want driver retries for any fast fail whatever the reason. 161 * Don't want driver retries for any fast fail whatever the reason.
162 * bit 10 -- Tell the IO scheduler not to wait for more requests after this
163 one has been submitted, even if it is a SYNC request.
162 */ 164 */
163#define BIO_RW 0 /* Must match RW in req flags (blkdev.h) */ 165#define BIO_RW 0 /* Must match RW in req flags (blkdev.h) */
164#define BIO_RW_AHEAD 1 /* Must match FAILFAST in req flags */ 166#define BIO_RW_AHEAD 1 /* Must match FAILFAST in req flags */
@@ -170,6 +172,7 @@ struct bio {
170#define BIO_RW_FAILFAST_DEV 7 172#define BIO_RW_FAILFAST_DEV 7
171#define BIO_RW_FAILFAST_TRANSPORT 8 173#define BIO_RW_FAILFAST_TRANSPORT 8
172#define BIO_RW_FAILFAST_DRIVER 9 174#define BIO_RW_FAILFAST_DRIVER 9
175#define BIO_RW_NOIDLE 10
173 176
174#define bio_rw_flagged(bio, flag) ((bio)->bi_rw & (1 << (flag))) 177#define bio_rw_flagged(bio, flag) ((bio)->bi_rw & (1 << (flag)))
175 178
@@ -188,6 +191,7 @@ struct bio {
188#define bio_rw_ahead(bio) bio_rw_flagged(bio, BIO_RW_AHEAD) 191#define bio_rw_ahead(bio) bio_rw_flagged(bio, BIO_RW_AHEAD)
189#define bio_rw_meta(bio) bio_rw_flagged(bio, BIO_RW_META) 192#define bio_rw_meta(bio) bio_rw_flagged(bio, BIO_RW_META)
190#define bio_discard(bio) bio_rw_flagged(bio, BIO_RW_DISCARD) 193#define bio_discard(bio) bio_rw_flagged(bio, BIO_RW_DISCARD)
194#define bio_noidle(bio) bio_rw_flagged(bio, BIO_RW_NOIDLE)
191 195
192/* 196/*
193 * upper 16 bits of bi_rw define the io priority of this bio 197 * upper 16 bits of bi_rw define the io priority of this bio
@@ -426,9 +430,6 @@ struct bio_set {
426 unsigned int front_pad; 430 unsigned int front_pad;
427 431
428 mempool_t *bio_pool; 432 mempool_t *bio_pool;
429#if defined(CONFIG_BLK_DEV_INTEGRITY)
430 mempool_t *bio_integrity_pool;
431#endif
432 mempool_t *bvec_pool; 433 mempool_t *bvec_pool;
433}; 434};
434 435
@@ -504,6 +505,115 @@ static inline int bio_has_data(struct bio *bio)
504 return bio && bio->bi_io_vec != NULL; 505 return bio && bio->bi_io_vec != NULL;
505} 506}
506 507
508/*
509 * BIO list managment for use by remapping drivers (e.g. DM or MD).
510 *
511 * A bio_list anchors a singly-linked list of bios chained through the bi_next
512 * member of the bio. The bio_list also caches the last list member to allow
513 * fast access to the tail.
514 */
515struct bio_list {
516 struct bio *head;
517 struct bio *tail;
518};
519
520static inline int bio_list_empty(const struct bio_list *bl)
521{
522 return bl->head == NULL;
523}
524
525static inline void bio_list_init(struct bio_list *bl)
526{
527 bl->head = bl->tail = NULL;
528}
529
530#define bio_list_for_each(bio, bl) \
531 for (bio = (bl)->head; bio; bio = bio->bi_next)
532
533static inline unsigned bio_list_size(const struct bio_list *bl)
534{
535 unsigned sz = 0;
536 struct bio *bio;
537
538 bio_list_for_each(bio, bl)
539 sz++;
540
541 return sz;
542}
543
544static inline void bio_list_add(struct bio_list *bl, struct bio *bio)
545{
546 bio->bi_next = NULL;
547
548 if (bl->tail)
549 bl->tail->bi_next = bio;
550 else
551 bl->head = bio;
552
553 bl->tail = bio;
554}
555
556static inline void bio_list_add_head(struct bio_list *bl, struct bio *bio)
557{
558 bio->bi_next = bl->head;
559
560 bl->head = bio;
561
562 if (!bl->tail)
563 bl->tail = bio;
564}
565
566static inline void bio_list_merge(struct bio_list *bl, struct bio_list *bl2)
567{
568 if (!bl2->head)
569 return;
570
571 if (bl->tail)
572 bl->tail->bi_next = bl2->head;
573 else
574 bl->head = bl2->head;
575
576 bl->tail = bl2->tail;
577}
578
579static inline void bio_list_merge_head(struct bio_list *bl,
580 struct bio_list *bl2)
581{
582 if (!bl2->head)
583 return;
584
585 if (bl->head)
586 bl2->tail->bi_next = bl->head;
587 else
588 bl->tail = bl2->tail;
589
590 bl->head = bl2->head;
591}
592
593static inline struct bio *bio_list_pop(struct bio_list *bl)
594{
595 struct bio *bio = bl->head;
596
597 if (bio) {
598 bl->head = bl->head->bi_next;
599 if (!bl->head)
600 bl->tail = NULL;
601
602 bio->bi_next = NULL;
603 }
604
605 return bio;
606}
607
608static inline struct bio *bio_list_get(struct bio_list *bl)
609{
610 struct bio *bio = bl->head;
611
612 bl->head = bl->tail = NULL;
613
614 return bio;
615}
616
507#if defined(CONFIG_BLK_DEV_INTEGRITY) 617#if defined(CONFIG_BLK_DEV_INTEGRITY)
508 618
509#define bip_vec_idx(bip, idx) (&(bip->bip_vec[(idx)])) 619#define bip_vec_idx(bip, idx) (&(bip->bip_vec[(idx)]))
@@ -519,9 +629,8 @@ static inline int bio_has_data(struct bio *bio)
519 629
520#define bio_integrity(bio) (bio->bi_integrity != NULL) 630#define bio_integrity(bio) (bio->bi_integrity != NULL)
521 631
522extern struct bio_integrity_payload *bio_integrity_alloc_bioset(struct bio *, gfp_t, unsigned int, struct bio_set *);
523extern struct bio_integrity_payload *bio_integrity_alloc(struct bio *, gfp_t, unsigned int); 632extern struct bio_integrity_payload *bio_integrity_alloc(struct bio *, gfp_t, unsigned int);
524extern void bio_integrity_free(struct bio *, struct bio_set *); 633extern void bio_integrity_free(struct bio *);
525extern int bio_integrity_add_page(struct bio *, struct page *, unsigned int, unsigned int); 634extern int bio_integrity_add_page(struct bio *, struct page *, unsigned int, unsigned int);
526extern int bio_integrity_enabled(struct bio *bio); 635extern int bio_integrity_enabled(struct bio *bio);
527extern int bio_integrity_set_tag(struct bio *, void *, unsigned int); 636extern int bio_integrity_set_tag(struct bio *, void *, unsigned int);
@@ -531,27 +640,21 @@ extern void bio_integrity_endio(struct bio *, int);
531extern void bio_integrity_advance(struct bio *, unsigned int); 640extern void bio_integrity_advance(struct bio *, unsigned int);
532extern void bio_integrity_trim(struct bio *, unsigned int, unsigned int); 641extern void bio_integrity_trim(struct bio *, unsigned int, unsigned int);
533extern void bio_integrity_split(struct bio *, struct bio_pair *, int); 642extern void bio_integrity_split(struct bio *, struct bio_pair *, int);
534extern int bio_integrity_clone(struct bio *, struct bio *, struct bio_set *); 643extern int bio_integrity_clone(struct bio *, struct bio *, gfp_t);
535extern int bioset_integrity_create(struct bio_set *, int);
536extern void bioset_integrity_free(struct bio_set *);
537extern void bio_integrity_init_slab(void);
538 644
539#else /* CONFIG_BLK_DEV_INTEGRITY */ 645#else /* CONFIG_BLK_DEV_INTEGRITY */
540 646
541#define bio_integrity(a) (0) 647#define bio_integrity(a) (0)
542#define bioset_integrity_create(a, b) (0)
543#define bio_integrity_prep(a) (0) 648#define bio_integrity_prep(a) (0)
544#define bio_integrity_enabled(a) (0) 649#define bio_integrity_enabled(a) (0)
545#define bio_integrity_clone(a, b, c) (0) 650#define bio_integrity_clone(a, b, c) (0)
546#define bioset_integrity_free(a) do { } while (0) 651#define bio_integrity_free(a) do { } while (0)
547#define bio_integrity_free(a, b) do { } while (0)
548#define bio_integrity_endio(a, b) do { } while (0) 652#define bio_integrity_endio(a, b) do { } while (0)
549#define bio_integrity_advance(a, b) do { } while (0) 653#define bio_integrity_advance(a, b) do { } while (0)
550#define bio_integrity_trim(a, b, c) do { } while (0) 654#define bio_integrity_trim(a, b, c) do { } while (0)
551#define bio_integrity_split(a, b, c) do { } while (0) 655#define bio_integrity_split(a, b, c) do { } while (0)
552#define bio_integrity_set_tag(a, b, c) do { } while (0) 656#define bio_integrity_set_tag(a, b, c) do { } while (0)
553#define bio_integrity_get_tag(a, b, c) do { } while (0) 657#define bio_integrity_get_tag(a, b, c) do { } while (0)
554#define bio_integrity_init_slab(a) do { } while (0)
555 658
556#endif /* CONFIG_BLK_DEV_INTEGRITY */ 659#endif /* CONFIG_BLK_DEV_INTEGRITY */
557 660