dm-bio-list.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 void bio_list_init(struct bio_list *bl)
  14. {
  15. bl->head = bl->tail = NULL;
  16. }
  17. static inline void bio_list_add(struct bio_list *bl, struct bio *bio)
  18. {
  19. bio->bi_next = NULL;
  20. if (bl->tail)
  21. bl->tail->bi_next = bio;
  22. else
  23. bl->head = bio;
  24. bl->tail = bio;
  25. }
  26. static inline void bio_list_merge(struct bio_list *bl, struct bio_list *bl2)
  27. {
  28. if (!bl2->head)
  29. return;
  30. if (bl->tail)
  31. bl->tail->bi_next = bl2->head;
  32. else
  33. bl->head = bl2->head;
  34. bl->tail = bl2->tail;
  35. }
  36. static inline void bio_list_merge_head(struct bio_list *bl,
  37. struct bio_list *bl2)
  38. {
  39. if (!bl2->head)
  40. return;
  41. if (bl->head)
  42. bl2->tail->bi_next = bl->head;
  43. else
  44. bl->tail = bl2->tail;
  45. bl->head = bl2->head;
  46. }
  47. static inline struct bio *bio_list_pop(struct bio_list *bl)
  48. {
  49. struct bio *bio = bl->head;
  50. if (bio) {
  51. bl->head = bl->head->bi_next;
  52. if (!bl->head)
  53. bl->tail = NULL;
  54. bio->bi_next = NULL;
  55. }
  56. return bio;
  57. }
  58. static inline struct bio *bio_list_get(struct bio_list *bl)
  59. {
  60. struct bio *bio = bl->head;
  61. bl->head = bl->tail = NULL;
  62. return bio;
  63. }
  64. #endif