dm-bio-list.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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_merge(struct bio_list *bl, struct bio_list *bl2)
  42. {
  43. if (!bl2->head)
  44. return;
  45. if (bl->tail)
  46. bl->tail->bi_next = bl2->head;
  47. else
  48. bl->head = bl2->head;
  49. bl->tail = bl2->tail;
  50. }
  51. static inline void bio_list_merge_head(struct bio_list *bl,
  52. struct bio_list *bl2)
  53. {
  54. if (!bl2->head)
  55. return;
  56. if (bl->head)
  57. bl2->tail->bi_next = bl->head;
  58. else
  59. bl->tail = bl2->tail;
  60. bl->head = bl2->head;
  61. }
  62. static inline struct bio *bio_list_pop(struct bio_list *bl)
  63. {
  64. struct bio *bio = bl->head;
  65. if (bio) {
  66. bl->head = bl->head->bi_next;
  67. if (!bl->head)
  68. bl->tail = NULL;
  69. bio->bi_next = NULL;
  70. }
  71. return bio;
  72. }
  73. static inline struct bio *bio_list_get(struct bio_list *bl)
  74. {
  75. struct bio *bio = bl->head;
  76. bl->head = bl->tail = NULL;
  77. return bio;
  78. }
  79. #endif /* CONFIG_BLOCK */
  80. #endif