* [PATCH] fsx: fix range overlap check
@ 2019-12-24 4:41 Darrick J. Wong
0 siblings, 0 replies; only message in thread
From: Darrick J. Wong @ 2019-12-24 4:41 UTC (permalink / raw)
To: Eryu Guan; +Cc: xfs, fstests
From: Darrick J. Wong <darrick.wong@oracle.com>
On 32-bit systems, the offsets are 'unsigned long' (32-bit) which means
that we must cast the explicitly to unsigned long long before feeding
them to llabs. Without the type conversion we fail to sign-extend the
llabs parameter, try to make a copy/clone/dedupe call with overlapping
ranges, and fsx aborts and the test fails.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
ltp/fsx.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/ltp/fsx.c b/ltp/fsx.c
index 06d08e4e..00001117 100644
--- a/ltp/fsx.c
+++ b/ltp/fsx.c
@@ -1911,6 +1911,14 @@ read_op(struct log_entry *log_entry)
return 0;
}
+static inline bool
+range_overlaps(
+ unsigned long off0,
+ unsigned long off1,
+ unsigned long size)
+{
+ return llabs((unsigned long long)off1 - off0) < size;
+}
int
test(void)
@@ -1993,7 +2001,7 @@ test(void)
offset2 = random();
TRIM_OFF(offset2, maxfilelen);
offset2 = offset2 & ~(block_size - 1);
- } while (llabs(offset2 - offset) < size ||
+ } while (range_overlaps(offset, offset2, size) ||
offset2 + size > maxfilelen);
break;
case OP_DEDUPE_RANGE:
@@ -2011,7 +2019,7 @@ test(void)
offset2 = random();
TRIM_OFF(offset2, file_size);
offset2 = offset2 & ~(block_size - 1);
- } while (llabs(offset2 - offset) < size ||
+ } while (range_overlaps(offset, offset2, size) ||
offset2 + size > file_size);
break;
}
@@ -2024,7 +2032,7 @@ test(void)
offset2 = random();
TRIM_OFF(offset2, maxfilelen);
offset2 -= offset2 % writebdy;
- } while (llabs(offset2 - offset) < size ||
+ } while (range_overlaps(offset, offset2, size) ||
offset2 + size > maxfilelen);
break;
}
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2019-12-24 4:43 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-24 4:41 [PATCH] fsx: fix range overlap check Darrick J. Wong
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.