* [PATCH] ltp/fsx: avoid infinite loop while finding offset2 in clone/dedupe/copy range ops
@ 2019-08-23 7:22 Eryu Guan
2019-08-23 7:27 ` Eryu Guan
2019-08-23 14:33 ` Darrick J. Wong
0 siblings, 2 replies; 4+ messages in thread
From: Eryu Guan @ 2019-08-23 7:22 UTC (permalink / raw)
To: fstests; +Cc: Darrick J. Wong, Eryu Guan
In CLONE/DEDUPE/COPY RANGE operations, we pick a "offset" and "size"
first, then find a suitable "offset2" by looping if there's overlap
(|offset2-offset| < size) or final file size is greater than max file
size (offset2 + size > maxfilelen).
But it's possible that there's no such suitable offset2 and we loop
forever. e.g. block_size = 4096, offset = 0, size = 4096 and maxfilelen
is a value smaller than 8212 (which could be set via '-l' option).
Fix it by making sure maxfilelen/file_size is big enough to hold 'size'
bytes from 'offset2', and just skip this operation if not.
Signed-off-by: Eryu Guan <eguan@linux.alibaba.com>
---
ltp/fsx.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/ltp/fsx.c b/ltp/fsx.c
index 06d08e4e93f3..f6eb3308e8bc 100644
--- a/ltp/fsx.c
+++ b/ltp/fsx.c
@@ -1825,6 +1825,14 @@ do { \
TRIM_LEN(off, len, size); \
} while (0)
+#define CHECK_RANGE(off, len, size) \
+do { \
+ if ((off + len * 2) > size) { \
+ log5(op, offset, size, -1, FL_SKIPPED); \
+ goto out; \
+ } \
+} while (0)
+
void
cleanup(int sig)
{
@@ -1989,6 +1997,7 @@ test(void)
TRIM_OFF_LEN(offset, size, file_size);
offset = offset & ~(block_size - 1);
size = size & ~(block_size - 1);
+ CHECK_RANGE(offset, size, maxfilelen);
do {
offset2 = random();
TRIM_OFF(offset2, maxfilelen);
@@ -2003,6 +2012,7 @@ test(void)
TRIM_OFF_LEN(offset, size, file_size);
offset = offset & ~(block_size - 1);
size = size & ~(block_size - 1);
+ CHECK_RANGE(offset, size, file_size);
do {
if (tries++ >= 30) {
size = 0;
@@ -2020,6 +2030,7 @@ test(void)
offset -= offset % readbdy;
if (o_direct)
size -= size % readbdy;
+ CHECK_RANGE(offset, size, maxfilelen);
do {
offset2 = random();
TRIM_OFF(offset2, maxfilelen);
--
2.14.4.44.g2045bb6
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] ltp/fsx: avoid infinite loop while finding offset2 in clone/dedupe/copy range ops
2019-08-23 7:22 [PATCH] ltp/fsx: avoid infinite loop while finding offset2 in clone/dedupe/copy range ops Eryu Guan
@ 2019-08-23 7:27 ` Eryu Guan
2019-08-23 14:33 ` Darrick J. Wong
1 sibling, 0 replies; 4+ messages in thread
From: Eryu Guan @ 2019-08-23 7:27 UTC (permalink / raw)
To: fstests; +Cc: Darrick J. Wong
On Fri, Aug 23, 2019 at 03:22:59PM +0800, Eryu Guan wrote:
> In CLONE/DEDUPE/COPY RANGE operations, we pick a "offset" and "size"
> first, then find a suitable "offset2" by looping if there's overlap
> (|offset2-offset| < size) or final file size is greater than max file
> size (offset2 + size > maxfilelen).
>
> But it's possible that there's no such suitable offset2 and we loop
> forever. e.g. block_size = 4096, offset = 0, size = 4096 and maxfilelen
> is a value smaller than 8212 (which could be set via '-l' option).
^^^^ should be 8192
Thanks,
Eryu
>
> Fix it by making sure maxfilelen/file_size is big enough to hold 'size'
> bytes from 'offset2', and just skip this operation if not.
>
> Signed-off-by: Eryu Guan <eguan@linux.alibaba.com>
> ---
> ltp/fsx.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/ltp/fsx.c b/ltp/fsx.c
> index 06d08e4e93f3..f6eb3308e8bc 100644
> --- a/ltp/fsx.c
> +++ b/ltp/fsx.c
> @@ -1825,6 +1825,14 @@ do { \
> TRIM_LEN(off, len, size); \
> } while (0)
>
> +#define CHECK_RANGE(off, len, size) \
> +do { \
> + if ((off + len * 2) > size) { \
> + log5(op, offset, size, -1, FL_SKIPPED); \
> + goto out; \
> + } \
> +} while (0)
> +
> void
> cleanup(int sig)
> {
> @@ -1989,6 +1997,7 @@ test(void)
> TRIM_OFF_LEN(offset, size, file_size);
> offset = offset & ~(block_size - 1);
> size = size & ~(block_size - 1);
> + CHECK_RANGE(offset, size, maxfilelen);
> do {
> offset2 = random();
> TRIM_OFF(offset2, maxfilelen);
> @@ -2003,6 +2012,7 @@ test(void)
> TRIM_OFF_LEN(offset, size, file_size);
> offset = offset & ~(block_size - 1);
> size = size & ~(block_size - 1);
> + CHECK_RANGE(offset, size, file_size);
> do {
> if (tries++ >= 30) {
> size = 0;
> @@ -2020,6 +2030,7 @@ test(void)
> offset -= offset % readbdy;
> if (o_direct)
> size -= size % readbdy;
> + CHECK_RANGE(offset, size, maxfilelen);
> do {
> offset2 = random();
> TRIM_OFF(offset2, maxfilelen);
> --
> 2.14.4.44.g2045bb6
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] ltp/fsx: avoid infinite loop while finding offset2 in clone/dedupe/copy range ops
2019-08-23 7:22 [PATCH] ltp/fsx: avoid infinite loop while finding offset2 in clone/dedupe/copy range ops Eryu Guan
2019-08-23 7:27 ` Eryu Guan
@ 2019-08-23 14:33 ` Darrick J. Wong
2019-08-24 1:07 ` Eryu Guan
1 sibling, 1 reply; 4+ messages in thread
From: Darrick J. Wong @ 2019-08-23 14:33 UTC (permalink / raw)
To: Eryu Guan; +Cc: fstests
On Fri, Aug 23, 2019 at 03:22:59PM +0800, Eryu Guan wrote:
> In CLONE/DEDUPE/COPY RANGE operations, we pick a "offset" and "size"
> first, then find a suitable "offset2" by looping if there's overlap
> (|offset2-offset| < size) or final file size is greater than max file
> size (offset2 + size > maxfilelen).
>
> But it's possible that there's no such suitable offset2 and we loop
> forever. e.g. block_size = 4096, offset = 0, size = 4096 and maxfilelen
> is a value smaller than 8212 (which could be set via '-l' option).
>
> Fix it by making sure maxfilelen/file_size is big enough to hold 'size'
> bytes from 'offset2', and just skip this operation if not.
>
> Signed-off-by: Eryu Guan <eguan@linux.alibaba.com>
> ---
> ltp/fsx.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/ltp/fsx.c b/ltp/fsx.c
> index 06d08e4e93f3..f6eb3308e8bc 100644
> --- a/ltp/fsx.c
> +++ b/ltp/fsx.c
> @@ -1825,6 +1825,14 @@ do { \
> TRIM_LEN(off, len, size); \
> } while (0)
>
> +#define CHECK_RANGE(off, len, size) \
> +do { \
> + if ((off + len * 2) > size) { \
> + log5(op, offset, size, -1, FL_SKIPPED); \
> + goto out; \
> + } \
> +} while (0)
Eww, macros.
Worse, macros that don't parenthesize the arguments.
Worse^2, macros that require variables to be defined in the caller's
scope that aren't passed as explicit parameters.
Worse^3, macros with gotos.
Why not:
static inline bool CHECK_RANGE(...)
{
bool ret = ((off + len * 2) <= size);
if (!ret)
log5(...);
return ret;
}
and then
if (!CHECK_RANGE(offset, size, maxfilelen))
goto out;
--D
}
> +
> void
> cleanup(int sig)
> {
> @@ -1989,6 +1997,7 @@ test(void)
> TRIM_OFF_LEN(offset, size, file_size);
> offset = offset & ~(block_size - 1);
> size = size & ~(block_size - 1);
> + CHECK_RANGE(offset, size, maxfilelen);
> do {
> offset2 = random();
> TRIM_OFF(offset2, maxfilelen);
> @@ -2003,6 +2012,7 @@ test(void)
> TRIM_OFF_LEN(offset, size, file_size);
> offset = offset & ~(block_size - 1);
> size = size & ~(block_size - 1);
> + CHECK_RANGE(offset, size, file_size);
> do {
> if (tries++ >= 30) {
> size = 0;
> @@ -2020,6 +2030,7 @@ test(void)
> offset -= offset % readbdy;
> if (o_direct)
> size -= size % readbdy;
> + CHECK_RANGE(offset, size, maxfilelen);
> do {
> offset2 = random();
> TRIM_OFF(offset2, maxfilelen);
> --
> 2.14.4.44.g2045bb6
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] ltp/fsx: avoid infinite loop while finding offset2 in clone/dedupe/copy range ops
2019-08-23 14:33 ` Darrick J. Wong
@ 2019-08-24 1:07 ` Eryu Guan
0 siblings, 0 replies; 4+ messages in thread
From: Eryu Guan @ 2019-08-24 1:07 UTC (permalink / raw)
To: Darrick J. Wong; +Cc: Eryu Guan, fstests
On Fri, Aug 23, 2019 at 07:33:54AM -0700, Darrick J. Wong wrote:
> On Fri, Aug 23, 2019 at 03:22:59PM +0800, Eryu Guan wrote:
> > In CLONE/DEDUPE/COPY RANGE operations, we pick a "offset" and "size"
> > first, then find a suitable "offset2" by looping if there's overlap
> > (|offset2-offset| < size) or final file size is greater than max file
> > size (offset2 + size > maxfilelen).
> >
> > But it's possible that there's no such suitable offset2 and we loop
> > forever. e.g. block_size = 4096, offset = 0, size = 4096 and maxfilelen
> > is a value smaller than 8212 (which could be set via '-l' option).
> >
> > Fix it by making sure maxfilelen/file_size is big enough to hold 'size'
> > bytes from 'offset2', and just skip this operation if not.
> >
> > Signed-off-by: Eryu Guan <eguan@linux.alibaba.com>
> > ---
> > ltp/fsx.c | 11 +++++++++++
> > 1 file changed, 11 insertions(+)
> >
> > diff --git a/ltp/fsx.c b/ltp/fsx.c
> > index 06d08e4e93f3..f6eb3308e8bc 100644
> > --- a/ltp/fsx.c
> > +++ b/ltp/fsx.c
> > @@ -1825,6 +1825,14 @@ do { \
> > TRIM_LEN(off, len, size); \
> > } while (0)
> >
> > +#define CHECK_RANGE(off, len, size) \
> > +do { \
> > + if ((off + len * 2) > size) { \
> > + log5(op, offset, size, -1, FL_SKIPPED); \
> > + goto out; \
> > + } \
> > +} while (0)
>
> Eww, macros.
>
> Worse, macros that don't parenthesize the arguments.
>
> Worse^2, macros that require variables to be defined in the caller's
> scope that aren't passed as explicit parameters.
>
> Worse^3, macros with gotos.
Yeah, these are ugly :) I was meant to define this macro in the context
where it's used, and undefine it when it's out of scope.
>
> Why not:
>
> static inline bool CHECK_RANGE(...)
> {
> bool ret = ((off + len * 2) <= size);
>
> if (!ret)
> log5(...);
> return ret;
> }
>
> and then
>
> if (!CHECK_RANGE(offset, size, maxfilelen))
> goto out;
Looks good, will rework. Thanks for the review!
Eryu
>
> --D
>
> }
> > +
> > void
> > cleanup(int sig)
> > {
> > @@ -1989,6 +1997,7 @@ test(void)
> > TRIM_OFF_LEN(offset, size, file_size);
> > offset = offset & ~(block_size - 1);
> > size = size & ~(block_size - 1);
> > + CHECK_RANGE(offset, size, maxfilelen);
> > do {
> > offset2 = random();
> > TRIM_OFF(offset2, maxfilelen);
> > @@ -2003,6 +2012,7 @@ test(void)
> > TRIM_OFF_LEN(offset, size, file_size);
> > offset = offset & ~(block_size - 1);
> > size = size & ~(block_size - 1);
> > + CHECK_RANGE(offset, size, file_size);
> > do {
> > if (tries++ >= 30) {
> > size = 0;
> > @@ -2020,6 +2030,7 @@ test(void)
> > offset -= offset % readbdy;
> > if (o_direct)
> > size -= size % readbdy;
> > + CHECK_RANGE(offset, size, maxfilelen);
> > do {
> > offset2 = random();
> > TRIM_OFF(offset2, maxfilelen);
> > --
> > 2.14.4.44.g2045bb6
> >
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-08-24 1:07 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-08-23 7:22 [PATCH] ltp/fsx: avoid infinite loop while finding offset2 in clone/dedupe/copy range ops Eryu Guan
2019-08-23 7:27 ` Eryu Guan
2019-08-23 14:33 ` Darrick J. Wong
2019-08-24 1:07 ` Eryu Guan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox