From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: Filipe Manana <fdmanana@kernel.org>
Cc: fstests <fstests@vger.kernel.org>,
linux-btrfs <linux-btrfs@vger.kernel.org>,
Filipe Manana <fdmanana@suse.com>
Subject: Re: [PATCH 4/4] fsx: move range generation logic into a common helper
Date: Wed, 8 Apr 2020 10:22:55 -0700 [thread overview]
Message-ID: <20200408172255.GA6749@magnolia> (raw)
In-Reply-To: <CAL3q7H6cSUibGXCKnOUge8+C5i6qFZB8m-SquHwXqMBjBZdLCg@mail.gmail.com>
On Wed, Apr 08, 2020 at 05:57:26PM +0100, Filipe Manana wrote:
> On Wed, Apr 8, 2020 at 4:48 PM Darrick J. Wong <darrick.wong@oracle.com> wrote:
> >
> > On Wed, Apr 08, 2020 at 11:36:27AM +0100, fdmanana@kernel.org wrote:
> > > From: Filipe Manana <fdmanana@suse.com>
> > >
> > > 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@suse.com>
> > > ---
> > > ltp/fsx.c | 91 +++++++++++++++++++++++++--------------------------------------
> > > 1 file changed, 36 insertions(+), 55 deletions(-)
> > >
> > > diff --git a/ltp/fsx.c b/ltp/fsx.c
> > > index 89a5f60e..8873cd01 100644
> > > --- a/ltp/fsx.c
> > > +++ b/ltp/fsx.c
> > > @@ -1930,6 +1930,36 @@ range_overlaps(
> > > return llabs((unsigned long long)off1 - off0) < size;
> > > }
> > >
> > > +static void generate_dest_range(unsigned long op,
> > > + unsigned long max_range_end,
> > > + unsigned long *src_offset,
> > > + unsigned long *size,
> > > + unsigned long *dst_offset)
> > > +{
> > > + int tries = 0;
> > > +
> > > + TRIM_OFF_LEN(*src_offset, *size, file_size);
> > > + if (op == OP_COPY_RANGE) {
> >
> > It feels funny that we pass in @op just to let COPY RANGE relax the
> > block size alignment requirements. How about passing a block_align
> > parameter (instead of op) which would be the subject of the if test?
> > This way we concentrate the alignment requirement knowlege of each type
> > of call in the "case OP_FOO" part of the code instead of scattering it?
>
> You mean something like the following:
>
> https://pastebin.com/e2NZKbZV
>
> ?
Yep.
--D
>
> >
> > --D
> >
> > > + *src_offset -= *src_offset % readbdy;
> > > + if (o_direct)
> > > + *size -= *size % readbdy;
> > > + } else {
> > > + *src_offset = *src_offset & ~(block_size - 1);
> > > + *size = *size & ~(block_size - 1);
> > > + }
> > > +
> > > + do {
> > > + if (tries++ >= 30) {
> > > + *size = 0;
> > > + break;
> > > + }
> > > + *dst_offset = random();
> > > + TRIM_OFF(*dst_offset, max_range_end);
> > > + *dst_offset = *dst_offset & ~(block_size - 1);
> > > + } while (range_overlaps(*src_offset, *dst_offset, *size) ||
> > > + *dst_offset + *size > max_range_end);
> > > +}
> > > +
> > > int
> > > test(void)
> > > {
> > > @@ -2004,63 +2034,14 @@ test(void)
> > > keep_size = random() % 2;
> > > break;
> > > case OP_CLONE_RANGE:
> > > - {
> > > - int tries = 0;
> > > -
> > > - TRIM_OFF_LEN(offset, size, file_size);
> > > - offset = offset & ~(block_size - 1);
> > > - size = size & ~(block_size - 1);
> > > - do {
> > > - if (tries++ >= 30) {
> > > - size = 0;
> > > - break;
> > > - }
> > > - offset2 = random();
> > > - TRIM_OFF(offset2, maxfilelen);
> > > - offset2 = offset2 & ~(block_size - 1);
> > > - } while (range_overlaps(offset, offset2, size) ||
> > > - offset2 + size > maxfilelen);
> > > - break;
> > > - }
> > > + generate_dest_range(op, maxfilelen, &offset, &size, &offset2);
> > > + break;
> > > case OP_DEDUPE_RANGE:
> > > - {
> > > - int tries = 0;
> > > -
> > > - TRIM_OFF_LEN(offset, size, file_size);
> > > - offset = offset & ~(block_size - 1);
> > > - size = size & ~(block_size - 1);
> > > - do {
> > > - if (tries++ >= 30) {
> > > - size = 0;
> > > - break;
> > > - }
> > > - offset2 = random();
> > > - TRIM_OFF(offset2, file_size);
> > > - offset2 = offset2 & ~(block_size - 1);
> > > - } while (range_overlaps(offset, offset2, size) ||
> > > - offset2 + size > file_size);
> > > - break;
> > > - }
> > > + generate_dest_range(op, file_size, &offset, &size, &offset2);
> > > + 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;
> > > - } while (range_overlaps(offset, offset2, size) ||
> > > - offset2 + size > maxfilelen);
> > > - break;
> > > - }
> > > + generate_dest_range(op, maxfilelen, &offset, &size, &offset2);
> > > + break;
> > > }
> > >
> > > have_op:
> > > --
> > > 2.11.0
> > >
next prev parent reply other threads:[~2020-04-08 17:23 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-08 10:36 [PATCH 4/4] fsx: move range generation logic into a common helper fdmanana
2020-04-08 15:48 ` Darrick J. Wong
2020-04-08 16:57 ` Filipe Manana
2020-04-08 17:22 ` Darrick J. Wong [this message]
2020-04-08 18:12 ` [PATCH v2 " fdmanana
2020-04-17 17:10 ` Brian Foster
2020-04-17 17:20 ` Filipe Manana
2020-04-17 17:32 ` [PATCH " fdmanana
2020-04-20 14:33 ` Brian Foster
2020-04-20 17:05 ` Filipe Manana
-- strict thread matches above, loose matches on Subject: below --
2020-04-20 17:09 fdmanana
2020-04-21 14:22 ` Brian Foster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200408172255.GA6749@magnolia \
--to=darrick.wong@oracle.com \
--cc=fdmanana@kernel.org \
--cc=fdmanana@suse.com \
--cc=fstests@vger.kernel.org \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).