linux-xfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dave Chinner <david@fromorbit.com>
To: Goldwyn Rodrigues <rgoldwyn@suse.de>
Cc: "Darrick J. Wong" <darrick.wong@oracle.com>,
	linux-xfs@vger.kernel.org, Goldwyn Rodrigues <rgoldwyn@suse.com>
Subject: Re: [PATCH v2 2/3] xfs_io: Add RWF_NOWAIT to pwritev2()
Date: Tue, 10 Oct 2017 09:37:14 +1100	[thread overview]
Message-ID: <20171009223714.GS3666@dastard> (raw)
In-Reply-To: <4e15ed18-b30c-1fb1-56ee-9bf5b0c6a73f@suse.de>

On Mon, Oct 09, 2017 at 04:11:17PM -0500, Goldwyn Rodrigues wrote:
> 
> 
> On 10/09/2017 12:19 PM, Darrick J. Wong wrote:
> > On Fri, Sep 29, 2017 at 08:00:34AM -0500, Goldwyn Rodrigues wrote:
> >> From: Goldwyn Rodrigues <rgoldwyn@suse.com>
> >>
> >> This allows to make pwritev2() calls with RWF_NOWAIT,
> >> which would fail in case the call blocks.
> >>
> >> Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
> >> ---
> >>  io/pwrite.c       | 8 +++++++-
> >>  man/man8/xfs_io.8 | 6 ++++++
> >>  2 files changed, 13 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/io/pwrite.c b/io/pwrite.c
> >> index e7d411bb..2b85a528 100644
> >> --- a/io/pwrite.c
> >> +++ b/io/pwrite.c
> >> @@ -52,6 +52,9 @@ pwrite_help(void)
> >>  "         (heh, zorry, the -s/-S arguments were already in use in pwrite)\n"
> >>  #ifdef HAVE_PWRITEV
> >>  " -V N -- use vectored IO with N iovecs of blocksize each (pwritev)\n"
> >> +#ifdef HAVE_PWRITEV2
> >> +" -N   -- Perform the pwritev2() with RWF_NOWAIT\n"
> >> +#endif
> > 
> > Separate these two? i.e.
> > 
> > #ifdef HAVE_PWRITEV
> > " -V N..."
> > #endif
> > #ifdef HAVE_PWRITEV2
> > " -N ..."
> > #endif
> > 
> > They're tested separately in configure, so the ifdefs needn't be nested.
> > 
> >>  #endif
> >>  "\n"));
> >>  }
> >> @@ -276,7 +279,7 @@ pwrite_f(
> >>  	init_cvtnum(&fsblocksize, &fssectsize);
> >>  	bsize = fsblocksize;
> >>  
> >> -	while ((c = getopt(argc, argv, "b:BCdf:Fi:qRs:S:uV:wWZ:")) != EOF) {
> >> +	while ((c = getopt(argc, argv, "b:BCdf:Fi:NqRs:S:uV:wWZ:")) != EOF) {
> >>  		switch (c) {
> >>  		case 'b':
> >>  			tmp = cvtnum(fsblocksize, fssectsize, optarg);
> >> @@ -305,6 +308,9 @@ pwrite_f(
> >>  		case 'i':
> >>  			infile = optarg;
> >>  			break;
> >> +		case 'N':
> >> +			pwritev2_flags |= RWF_NOWAIT;
> >> +			break;
> > 
> > Needs #ifdef HAVE_PWRITEV2.
> > 
> > If you feel the need to be extra cautious, you could also put:
> > 
> > #ifndef HAVE_PWRITEV2
> > 	assert(pwritev2_flags == 0);
> > #endif
> > 
> > ...just after the getopt parsing to make sure that we never silently
> > drop RWF_* flags due to code bugs.
> > 
> 
> Instead I am planning to put an #else to #ifdef in the case 'N' to make
> sure that people who do not have pwritev2() get the proper message
> instead of the command failing without reason.
> 
> +               case 'N':
> +#ifdef HAVE_PWRITEV2
> +                       pwritev2_flags |= RWF_NOWAIT;
> +                       break;
> +#else
> +                       printf(_("-N: Kernel does not support
> pwritev2()\n"));
> +                       return 0;
> +#endif

Why add support for a command only to say "command not supported"?
The error message is also incorrect - the build environment didn't
support pwritev2, not the kernel the xfs_io binary is currently
running on.

As it is, I really don't like this sort of ifdef pattern because it
means over time we'll end up with an ifdef mess in the option
parsing as more flags are added. Just make the default case say
"command -%c not supported", and that removes the need for any of
these else cases.

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

  reply	other threads:[~2017-10-09 22:37 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-29 13:00 [PATCH v2 1/3] xfs_io: Add support for pwritev2() Goldwyn Rodrigues
2017-09-29 13:00 ` [PATCH v2 2/3] xfs_io: Add RWF_NOWAIT to pwritev2() Goldwyn Rodrigues
2017-10-09 15:02   ` Brian Foster
2017-10-09 17:19   ` Darrick J. Wong
2017-10-09 21:11     ` Goldwyn Rodrigues
2017-10-09 22:37       ` Dave Chinner [this message]
2017-10-09 22:51         ` Goldwyn Rodrigues
2017-09-29 13:00 ` [PATCH v2 3/3] xfs_io: Allow partial writes Goldwyn Rodrigues
2017-10-09 15:02   ` Brian Foster
2017-10-09 17:15   ` Darrick J. Wong
2017-10-09 11:14 ` [PATCH v2 1/3] xfs_io: Add support for pwritev2() Goldwyn Rodrigues
2017-10-09 15:02 ` 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=20171009223714.GS3666@dastard \
    --to=david@fromorbit.com \
    --cc=darrick.wong@oracle.com \
    --cc=linux-xfs@vger.kernel.org \
    --cc=rgoldwyn@suse.com \
    --cc=rgoldwyn@suse.de \
    /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).