dm-bio-list.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. #ifdef CONFIG_BLOCK
  10. struct bio_list {
  11. struct bio *head;
  12. struct bio *tail;
  13. };
  14. static inline int bio_list_empty(const struct bio_list *bl)
  15. {
  16. return bl->head == NULL;
  17. }
  18. #define BIO_LIST_INIT { .head = NULL, .tail = NULL }
  19. #define BIO_LIST(bl) \
  20. struct bio_list bl = BIO_LIST_INIT
  21. static inline void bio_list_init(struct bio_list *bl)
  22. {
  23. bl->head = bl->tail = NULL;
  24. }
  25. #define bio_list_for_each(bio, bl) \
  26. for (bio = (bl)->head; bio; bio = bio->bi_next)
  27. static inline unsigned bio_list_size(const struct bio_list *bl)
  28. {
  29. unsigned sz = 0;
  30. struct bio *bio;
  31. bio_list_for_each(bio, bl)
  32. sz++;
  33. return sz;
  34. }
  35. static inline void bio_list_add(struct bio_list *bl, struct bio *bio)
  36. {
  37. bio->bi_next = NULL;
  38. if (bl->tail)
  39. bl->tail->bi_next = bio;
  40. else
  41. bl->head = bio;
  42. bl->tail = bio;
  43. }
  44. static inline void bio_list_merge(struct bio_list *bl, struct bio_list *bl2)
  45. {
  46. if (!bl2->head)
  47. return;
  48. if (bl->tail)
  49. bl->tail->bi_next = bl2->head;
  50. else
  51. bl->head = bl2->head;
  52. bl->tail = bl2->tail;
  53. }
  54. static inline void bio_list_merge_head(struct bio_list *bl,
  55. struct bio_list *bl2)
  56. {
  57. if (!bl2->head)
  58. return;
  59. if (bl->head)
  60. bl2->tail->bi_next = bl->head;
  61. else
  62. bl->tail = bl2->tail;
  63. bl->head = bl2->head;
  64. }
  65. static inline struct bio *bio_list_pop(struct bio_list *bl)
  66. {
  67. struct bio *bio = bl->head;
  68. if (bio) {
  69. bl->head = bl->head->bi_next;
  70. if (!bl->head)
  71. bl->tail = NULL;
  72. bio->bi_next = NULL;
  73. }
  74. return bio;
  75. }
  76. static inline struct bio *bio_list_get(struct bio_list *bl)
  77. {
  78. struct bio *bio = bl->head;
  79. bl->head = bl->tail = NULL;
  80. return bio;
  81. }
  82. #endif /* CONFIG_BLOCK */
  83. #endif