blob: 23c5a94428d2611bcd89e2c10758da8eeda40d48 [file] [log] [blame]
Andreas Gruenbacher0939b0e2011-01-03 17:42:00 +01001#ifndef __DRBD_INTERVAL_H
2#define __DRBD_INTERVAL_H
3
4#include <linux/types.h>
5#include <linux/rbtree.h>
6
7struct drbd_interval {
8 struct rb_node rb;
Fabian Frederick7e5fec32016-06-14 00:26:35 +02009 sector_t sector; /* start sector of the interval */
10 unsigned int size; /* size in bytes */
11 sector_t end; /* highest interval end in subtree */
12 unsigned int local:1 /* local or remote request? */;
13 unsigned int waiting:1; /* someone is waiting for completion */
14 unsigned int completed:1; /* this has been completed already;
15 * ignore for conflict detection */
Andreas Gruenbacher0939b0e2011-01-03 17:42:00 +010016};
17
18static inline void drbd_clear_interval(struct drbd_interval *i)
19{
20 RB_CLEAR_NODE(&i->rb);
21}
22
23static inline bool drbd_interval_empty(struct drbd_interval *i)
24{
25 return RB_EMPTY_NODE(&i->rb);
26}
27
Andreas Gruenbacherd0e22a22011-02-17 18:11:24 +010028extern bool drbd_insert_interval(struct rb_root *, struct drbd_interval *);
29extern bool drbd_contains_interval(struct rb_root *, sector_t,
30 struct drbd_interval *);
31extern void drbd_remove_interval(struct rb_root *, struct drbd_interval *);
32extern struct drbd_interval *drbd_find_overlap(struct rb_root *, sector_t,
Andreas Gruenbacher0939b0e2011-01-03 17:42:00 +010033 unsigned int);
Andreas Gruenbacherd0e22a22011-02-17 18:11:24 +010034extern struct drbd_interval *drbd_next_overlap(struct drbd_interval *, sector_t,
35 unsigned int);
36
37#define drbd_for_each_overlap(i, root, sector, size) \
38 for (i = drbd_find_overlap(root, sector, size); \
39 i; \
40 i = drbd_next_overlap(i, sector, size))
Andreas Gruenbacher0939b0e2011-01-03 17:42:00 +010041
42#endif /* __DRBD_INTERVAL_H */