On Wed, Apr 08, 2020 at 07:12:08PM +0100, fdmanana@xxxxxxxxxx wrote: > From: Filipe Manana <fdmanana@xxxxxxxx> > > We have very similar code that generates the destination range for clone, > dedupe and copy_file_range operations, so avoid duplicating the code three > times and move it into a helper function. > > Signed-off-by: Filipe Manana <fdmanana@xxxxxxxx> > --- > > V2: Turned the first parameter of the helper into a boolean as Darrick suggested. > > ltp/fsx.c | 91 +++++++++++++++++++++++++-------------------------------------- > 1 file changed, 36 insertions(+), 55 deletions(-) > > diff --git a/ltp/fsx.c b/ltp/fsx.c > index 89a5f60e..9bfc98e0 100644 > --- a/ltp/fsx.c > +++ b/ltp/fsx.c ... > @@ -2004,63 +2034,14 @@ test(void) > keep_size = random() % 2; > break; ... > case OP_COPY_RANGE: > - { > - int tries = 0; > - > - TRIM_OFF_LEN(offset, size, file_size); > - offset -= offset % readbdy; > - if (o_direct) > - size -= size % readbdy; > - do { > - if (tries++ >= 30) { > - size = 0; > - break; > - } > - offset2 = random(); > - TRIM_OFF(offset2, maxfilelen); > - offset2 -= offset2 % writebdy; It looks like this writebdy bit is lost in the new helper... Brian > - } while (range_overlaps(offset, offset2, size) || > - offset2 + size > maxfilelen); > - break; > - } > + generate_dest_range(true, maxfilelen, &offset, &size, &offset2); > + break; > } > > have_op: > -- > 2.11.0 >