dm-bio-list.h 1.8 KB

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