Skip to content

Commit 06cf321

Browse files
weiny2davejiang
authored andcommitted
range: Add range_overlaps()
Code to support CXL Dynamic Capacity devices will have extent ranges which need to be compared for intersection not a subset as is being checked in range_contains(). range_overlaps() is defined in btrfs with a different meaning from what is required in the standard range code. Dan Williams pointed this out in [1]. Adjust the btrfs call according to his suggestion there. Then add a generic range_overlaps(). Cc: Dan Williams <dan.j.williams@intel.com> Cc: Chris Mason <clm@fb.com> Cc: Josef Bacik <josef@toxicpanda.com> Cc: David Sterba <dsterba@suse.com> Cc: linux-btrfs@vger.kernel.org Link: https://lore.kernel.org/all/65949f79ef908_8dc68294f2@dwillia2-xfh.jf.intel.com.notmuch/ [1] Acked-by: David Sterba <dsterba@suse.com> Reviewed-by: Davidlohr Bueso <dave@stgolabs.net> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Reviewed-by: Fan Ni <fan.ni@samsung.com> Reviewed-by: Dave Jiang <dave.jiang@intel.com> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Ira Weiny <ira.weiny@intel.com> Link: https://patch.msgid.link/20241107-dcd-type2-upstream-v7-1-56a84e66bc36@intel.com Signed-off-by: Dave Jiang <dave.jiang@intel.com>
1 parent 8198375 commit 06cf321

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

fs/btrfs/ordered-data.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ static struct rb_node *__tree_search(struct rb_root *root, u64 file_offset,
111111
return NULL;
112112
}
113113

114-
static int range_overlaps(struct btrfs_ordered_extent *entry, u64 file_offset,
115-
u64 len)
114+
static int btrfs_range_overlaps(struct btrfs_ordered_extent *entry, u64 file_offset,
115+
u64 len)
116116
{
117117
if (file_offset + len <= entry->file_offset ||
118118
entry->file_offset + entry->num_bytes <= file_offset)
@@ -985,7 +985,7 @@ struct btrfs_ordered_extent *btrfs_lookup_ordered_range(
985985

986986
while (1) {
987987
entry = rb_entry(node, struct btrfs_ordered_extent, rb_node);
988-
if (range_overlaps(entry, file_offset, len))
988+
if (btrfs_range_overlaps(entry, file_offset, len))
989989
break;
990990

991991
if (entry->file_offset >= file_offset + len) {
@@ -1114,12 +1114,12 @@ struct btrfs_ordered_extent *btrfs_lookup_first_ordered_range(
11141114
}
11151115
if (prev) {
11161116
entry = rb_entry(prev, struct btrfs_ordered_extent, rb_node);
1117-
if (range_overlaps(entry, file_offset, len))
1117+
if (btrfs_range_overlaps(entry, file_offset, len))
11181118
goto out;
11191119
}
11201120
if (next) {
11211121
entry = rb_entry(next, struct btrfs_ordered_extent, rb_node);
1122-
if (range_overlaps(entry, file_offset, len))
1122+
if (btrfs_range_overlaps(entry, file_offset, len))
11231123
goto out;
11241124
}
11251125
/* No ordered extent in the range */

include/linux/range.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,19 @@ static inline u64 range_len(const struct range *range)
1313
return range->end - range->start + 1;
1414
}
1515

16+
/* True if r1 completely contains r2 */
1617
static inline bool range_contains(struct range *r1, struct range *r2)
1718
{
1819
return r1->start <= r2->start && r1->end >= r2->end;
1920
}
2021

22+
/* True if any part of r1 overlaps r2 */
23+
static inline bool range_overlaps(const struct range *r1,
24+
const struct range *r2)
25+
{
26+
return r1->start <= r2->end && r1->end >= r2->start;
27+
}
28+
2129
int add_range(struct range *range, int az, int nr_range,
2230
u64 start, u64 end);
2331

0 commit comments

Comments
 (0)