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.h110
1 files changed, 110 insertions, 0 deletions
diff --git a/include/linux/bio.h b/include/linux/bio.h
index b900d2c67d29..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)
@@ -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)]))