Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / block / drbd / drbd_interval.h
blobb8c2dee5edc8112ef667b959c5e168b06f7d8395
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __DRBD_INTERVAL_H
3 #define __DRBD_INTERVAL_H
5 #include <linux/types.h>
6 #include <linux/rbtree.h>
8 struct drbd_interval {
9 struct rb_node rb;
10 sector_t sector; /* start sector of the interval */
11 unsigned int size; /* size in bytes */
12 sector_t end; /* highest interval end in subtree */
13 unsigned int local:1 /* local or remote request? */;
14 unsigned int waiting:1; /* someone is waiting for completion */
15 unsigned int completed:1; /* this has been completed already;
16 * ignore for conflict detection */
19 static inline void drbd_clear_interval(struct drbd_interval *i)
21 RB_CLEAR_NODE(&i->rb);
24 static inline bool drbd_interval_empty(struct drbd_interval *i)
26 return RB_EMPTY_NODE(&i->rb);
29 extern bool drbd_insert_interval(struct rb_root *, struct drbd_interval *);
30 extern bool drbd_contains_interval(struct rb_root *, sector_t,
31 struct drbd_interval *);
32 extern void drbd_remove_interval(struct rb_root *, struct drbd_interval *);
33 extern struct drbd_interval *drbd_find_overlap(struct rb_root *, sector_t,
34 unsigned int);
35 extern struct drbd_interval *drbd_next_overlap(struct drbd_interval *, sector_t,
36 unsigned int);
38 #define drbd_for_each_overlap(i, root, sector, size) \
39 for (i = drbd_find_overlap(root, sector, size); \
40 i; \
41 i = drbd_next_overlap(i, sector, size))
43 #endif /* __DRBD_INTERVAL_H */