drbd_interval.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #ifndef __DRBD_INTERVAL_H
  2. #define __DRBD_INTERVAL_H
  3. #include <linux/types.h>
  4. #include <linux/rbtree.h>
  5. struct drbd_interval {
  6. struct rb_node rb;
  7. sector_t sector; /* start sector of the interval */
  8. unsigned int size; /* size in bytes */
  9. sector_t end; /* highest interval end in subtree */
  10. unsigned int local:1 /* local or remote request? */;
  11. unsigned int waiting:1; /* someone is waiting for completion */
  12. unsigned int completed:1; /* this has been completed already;
  13. * ignore for conflict detection */
  14. };
  15. static inline void drbd_clear_interval(struct drbd_interval *i)
  16. {
  17. RB_CLEAR_NODE(&i->rb);
  18. }
  19. static inline bool drbd_interval_empty(struct drbd_interval *i)
  20. {
  21. return RB_EMPTY_NODE(&i->rb);
  22. }
  23. extern bool drbd_insert_interval(struct rb_root *, struct drbd_interval *);
  24. extern bool drbd_contains_interval(struct rb_root *, sector_t,
  25. struct drbd_interval *);
  26. extern void drbd_remove_interval(struct rb_root *, struct drbd_interval *);
  27. extern struct drbd_interval *drbd_find_overlap(struct rb_root *, sector_t,
  28. unsigned int);
  29. extern struct drbd_interval *drbd_next_overlap(struct drbd_interval *, sector_t,
  30. unsigned int);
  31. #define drbd_for_each_overlap(i, root, sector, size) \
  32. for (i = drbd_find_overlap(root, sector, size); \
  33. i; \
  34. i = drbd_next_overlap(i, sector, size))
  35. #endif /* __DRBD_INTERVAL_H */