dm-bio-list.h 1.8 KB

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