Andreas Gruenbacher | 0939b0e | 2011-01-03 17:42:00 +0100 | [diff] [blame] | 1 | #ifndef __DRBD_INTERVAL_H |
| 2 | #define __DRBD_INTERVAL_H |
| 3 | |
| 4 | #include <linux/types.h> |
| 5 | #include <linux/rbtree.h> |
| 6 | |
| 7 | struct drbd_interval { |
| 8 | struct rb_node rb; |
| 9 | sector_t sector; /* start sector of the interval */ |
| 10 | unsigned int size; /* size in bytes */ |
| 11 | sector_t end; /* highest interval end in subtree */ |
Andreas Gruenbacher | 5e47226 | 2011-01-27 14:42:51 +0100 | [diff] [blame] | 12 | int local:1 /* local or remote request? */; |
Andreas Gruenbacher | 5384064 | 2011-01-28 10:31:04 +0100 | [diff] [blame] | 13 | int waiting:1; |
Andreas Gruenbacher | 0939b0e | 2011-01-03 17:42:00 +0100 | [diff] [blame] | 14 | }; |
| 15 | |
| 16 | static inline void drbd_clear_interval(struct drbd_interval *i) |
| 17 | { |
| 18 | RB_CLEAR_NODE(&i->rb); |
| 19 | } |
| 20 | |
| 21 | static inline bool drbd_interval_empty(struct drbd_interval *i) |
| 22 | { |
| 23 | return RB_EMPTY_NODE(&i->rb); |
| 24 | } |
| 25 | |
Andreas Gruenbacher | d0e22a2 | 2011-02-17 18:11:24 +0100 | [diff] [blame^] | 26 | extern bool drbd_insert_interval(struct rb_root *, struct drbd_interval *); |
| 27 | extern bool drbd_contains_interval(struct rb_root *, sector_t, |
| 28 | struct drbd_interval *); |
| 29 | extern void drbd_remove_interval(struct rb_root *, struct drbd_interval *); |
| 30 | extern struct drbd_interval *drbd_find_overlap(struct rb_root *, sector_t, |
Andreas Gruenbacher | 0939b0e | 2011-01-03 17:42:00 +0100 | [diff] [blame] | 31 | unsigned int); |
Andreas Gruenbacher | d0e22a2 | 2011-02-17 18:11:24 +0100 | [diff] [blame^] | 32 | extern struct drbd_interval *drbd_next_overlap(struct drbd_interval *, sector_t, |
| 33 | unsigned int); |
| 34 | |
| 35 | #define drbd_for_each_overlap(i, root, sector, size) \ |
| 36 | for (i = drbd_find_overlap(root, sector, size); \ |
| 37 | i; \ |
| 38 | i = drbd_next_overlap(i, sector, size)) |
Andreas Gruenbacher | 0939b0e | 2011-01-03 17:42:00 +0100 | [diff] [blame] | 39 | |
| 40 | #endif /* __DRBD_INTERVAL_H */ |