dm-bio-list.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Copyright (C) 2004 Red Hat UK Ltd.
  3. *
  4. * This file is released under the GPL.
  5. */
  6. #ifndef DM_BIO_LIST_H
  7. #define DM_BIO_LIST_H
  8. #include <linux/bio.h>
  9. struct bio_list {
  10. struct bio *head;
  11. struct bio *tail;
  12. };
  13. static inline int bio_list_empty(const struct bio_list *bl)
  14. {
  15. return bl->head == NULL;
  16. }
  17. #define BIO_LIST_INIT { .head = NULL, .tail = NULL }
  18. #define BIO_LIST(bl) \
  19. struct bio_list bl = BIO_LIST_INIT
  20. static inline void bio_list_init(struct bio_list *bl)
  21. {
  22. bl->head = bl->tail = NULL;
  23. }
  24. #define bio_list_for_each(bio, bl) \
  25. for (bio = (bl)->head; bio; bio = bio->bi_next)
  26. static inline unsigned bio_list_size(const struct bio_list *bl)
  27. {
  28. unsigned sz = 0;
  29. struct bio *bio;
  30. bio_list_for_each(bio, bl)
  31. sz++;
  32. return sz;
  33. }
  34. static inline void bio_list_add(struct bio_list *bl, struct bio *bio)
  35. {
  36. bio->bi_next = NULL;
  37. if (bl->tail)
  38. bl->tail->bi_next = bio;
  39. else
  40. bl->head = bio;
  41. bl->tail = bio;
  42. }
  43. static inline void bio_list_merge(struct bio_list *bl, struct bio_list *bl2)
  44. {
  45. if (!bl2->head)
  46. return;
  47. if (bl->tail)
  48. bl->tail->bi_next = bl2->head;
  49. else
  50. bl->head = bl2->head;
  51. bl->tail = bl2->tail;
  52. }
  53. static inline void bio_list_merge_head(struct bio_list *bl,
  54. struct bio_list *bl2)
  55. {
  56. if (!bl2->head)
  57. return;
  58. if (bl->head)
  59. bl2->tail->bi_next = bl->head;
  60. else
  61. bl->tail = bl2->tail;
  62. bl->head = bl2->head;
  63. }
  64. static inline struct bio *bio_list_pop(struct bio_list *bl)
  65. {
  66. struct bio *bio = bl->head;
  67. if (bio) {
  68. bl->head = bl->head->bi_next;
  69. if (!bl->head)
  70. bl->tail = NULL;
  71. bio->bi_next = NULL;
  72. }
  73. return bio;
  74. }
  75. static inline struct bio *bio_list_get(struct bio_list *bl)
  76. {
  77. struct bio *bio = bl->head;
  78. bl->head = bl->tail = NULL;
  79. return bio;
  80. }
  81. #endif