dm-bio-list.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 struct bio *bio_list_pop(struct bio_list *bl)
  37. {
  38. struct bio *bio = bl->head;
  39. if (bio) {
  40. bl->head = bl->head->bi_next;
  41. if (!bl->head)
  42. bl->tail = NULL;
  43. bio->bi_next = NULL;
  44. }
  45. return bio;
  46. }
  47. static inline struct bio *bio_list_get(struct bio_list *bl)
  48. {
  49. struct bio *bio = bl->head;
  50. bl->head = bl->tail = NULL;
  51. return bio;
  52. }
  53. #endif