From: Zorro Lang <zlang@redhat.com>
To: Pavel Reichl <preichl@redhat.com>
Cc: fstests@vger.kernel.org, "Darrick J. Wong" <djwong@kernel.org>
Subject: Re: [PATCH v3 1/2] common: new helper to alloacate fixed size files
Date: Wed, 21 Sep 2022 14:01:56 +0800 [thread overview]
Message-ID: <20220921060156.2glkfo26tx2fktnm@zlang-mailbox> (raw)
In-Reply-To: <Yyp8wE63C1IdtBd1@magnolia>
On Tue, Sep 20, 2022 at 07:53:52PM -0700, Darrick J. Wong wrote:
> On Wed, Sep 21, 2022 at 10:48:57AM +0800, Zorro Lang wrote:
> > On Tue, Sep 20, 2022 at 09:35:13AM +0200, Pavel Reichl wrote:
> > > Helper that creates files of specified size using falloc if supported,
> > > otherwise pwrite is used.
> > >
> > > Signed-off-by: Pavel Reichl <preichl@redhat.com>
> > > ---
> > > common/rc | 13 +++++++++++++
> > > tests/generic/694 | 2 +-
> > > 2 files changed, 14 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/common/rc b/common/rc
> > > index a25cbcd0..77866582 100644
> > > --- a/common/rc
> > > +++ b/common/rc
> > > @@ -4925,6 +4925,19 @@ hexdump()
> > > _fail "Use _hexdump(), please!"
> > > }
> > >
> > > +# Helper to write a file containing specified number of bytes using
> > > +# falloc if supported, otherwise use pwrite
> > > +_create_sizedfile()
> > > +{
> > > + length=$1
> > > + file=$2
> > > +
> > > + $XFS_IO_PROG -F -fc "falloc 0 $length" $file 2>&1 | grep -q "Operation not supported"
> > > + if [ $? -eq 0 ]; then
> > > + $XFS_IO_PROG -F -fc "pwrite -W 0 $length" $file >/dev/null
> > > + fi
> > > +}
> >
> > I think about it more, above code might ignore a failed falloc, if it's not failed
> > by "Operation not supported" but really fails, this function won't print or return
> > any valid things.
> >
> > So how about we write it like below (for reference only):
> >
> > # Try to create a file which inode->i_blocks = $length (maybe a little bigger
> > # than expect)
> > _create_file_sized()
> > {
> > local length=$1
> > local file=$2
> > local tmp=`mktemp -u`
> > local ret=0
> >
> > $XFS_IO_PROG -ft -c "falloc 0 $length" $file >$tmp.out 2>&1
> > ret=$?
> > if (grep -Eq "Operation not supported|command .* not found" $tmp.out);then
> > # fallocate isn't supported, fallback to general buffer write
> > $XFS_IO_PROG -ft -c "pwrite 0 $length" $file >$tmp.out 2>&1
> > ret=$?
> > fi
> > [ $ret -ne 0 ] && cat $tmp.out
> > rm -f $tmp.out
> > return $ret
> > }
> >
> > Even though, I think this function might still not good, feel free to tell me if
> > anyone has better idea/suggestion about how to get a file with specified
> > inode->i_blocks.
>
> Looks reasonable enough to /me...
Thanks for your review, Darrick.
Hi Pavel, the [PATCH 2/2] looks good to me. I'll merge this patchset after you
making this change.
Thanks,
Zorro
>
> --D
>
> > Thanks,
> > Zorro
> >
> > > +
> > > init_rc
> > >
> > > ################################################################################
> > > diff --git a/tests/generic/694 b/tests/generic/694
> > > index dfd988df..64c3dd9a 100755
> > > --- a/tests/generic/694
> > > +++ b/tests/generic/694
> > > @@ -30,7 +30,7 @@ junk_dir=$TEST_DIR/$seq
> > > junk_file=$junk_dir/junk
> > > mkdir -p $junk_dir
> > >
> > > -$XFS_IO_PROG -f -c "pwrite -W 0 4G" $junk_file > /dev/null
> > > +_create_sizedfile 4G $junk_file
> > >
> > > iblocks=`stat -c '%b' $junk_file`
> > >
> > > --
> > > 2.37.3
> > >
> >
>
next prev parent reply other threads:[~2022-09-21 6:02 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-20 7:35 [PATCH v3 0/2] generic: test i_blocks for truncated largefiles Pavel Reichl
2022-09-20 7:35 ` [PATCH v3 1/2] common: new helper to alloacate fixed size files Pavel Reichl
2022-09-20 15:03 ` Zorro Lang
2022-09-21 2:48 ` Zorro Lang
2022-09-21 2:53 ` Darrick J. Wong
2022-09-21 6:01 ` Zorro Lang [this message]
2022-09-20 7:35 ` [PATCH v3 2/2] generic: test i_blocks for truncated large files Pavel Reichl
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=20220921060156.2glkfo26tx2fktnm@zlang-mailbox \
--to=zlang@redhat.com \
--cc=djwong@kernel.org \
--cc=fstests@vger.kernel.org \
--cc=preichl@redhat.com \
/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