All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: "Kevin Wolf" <kwolf@redhat.com>,
	qemu-block@nongnu.org, qemu-devel@nongnu.org,
	"P J P" <ppandit@redhat.com>, "Max Reitz" <mreitz@redhat.com>,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>
Subject: Re: [PATCH v2 1/3] util: validate whether O_DIRECT is supported after failure
Date: Wed, 08 Jul 2020 08:45:46 +0200	[thread overview]
Message-ID: <878sfu4i91.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <20200702125612.2176194-2-berrange@redhat.com> ("Daniel P. =?utf-8?Q?Berrang=C3=A9=22's?= message of "Thu, 2 Jul 2020 13:56:10 +0100")

Daniel P. Berrangé <berrange@redhat.com> writes:

> Currently we suggest that a filesystem may not support O_DIRECT after
> seeing an EINVAL. Other things can cause EINVAL though, so it is better
> to do an explicit check, and then report a definitive error message.
>
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  util/osdep.c | 15 +++++++++++----
>  1 file changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/util/osdep.c b/util/osdep.c
> index 4829c07ff6..e2b7507ee2 100644
> --- a/util/osdep.c
> +++ b/util/osdep.c
> @@ -332,9 +332,11 @@ int qemu_open(const char *name, int flags, ...)
>      }
>  
>  #ifdef O_CLOEXEC
> -    ret = open(name, flags | O_CLOEXEC, mode);
> -#else
> +    flags |= O_CLOEXEC;
> +#endif
>      ret = open(name, flags, mode);
> +
> +#ifndef O_CLOEXEC
>      if (ret >= 0) {
>          qemu_set_cloexec(ret);
>      }

I'd prefer something like

   #ifdef O_CLOEXEC
       flags |= O_CLOEXEC;
       ret = open(name, flags, mode);
   #else
       ret = open(name, flags, mode);
       if (ret >= 0) {
           qemu_set_cloexec(ret);
       }
   #endif

Continues to duplicate open(), but spares me the effort to fuse two
#ifdef sections in my head to understand what is being done in each
case.

> @@ -342,8 +344,13 @@ int qemu_open(const char *name, int flags, ...)
>  
>  #ifdef O_DIRECT
>      if (ret == -1 && errno == EINVAL && (flags & O_DIRECT)) {
> -        error_report("file system may not support O_DIRECT");
> -        errno = EINVAL; /* in case it was clobbered */
> +        int newflags = flags & ~O_DIRECT;
> +        ret = open(name, newflags, mode);

I'd prefer the more concise

           ret = open(name, flags & ~O_DIRECT, mode);

> +        if (ret != -1) {
> +            close(ret);
> +            error_report("file system does not support O_DIRECT");
> +            errno = EINVAL;
> +        }
>      }
>  #endif /* O_DIRECT */

The function now reports to stderr in just one of many failure modes.
That's wrong.  Looks like the next patch fixes this defect.  I'd swap
the two.



  parent reply	other threads:[~2020-07-08 22:53 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-02 12:56 [PATCH v2 0/3] block: improve error reporting for unsupported O_DIRECT Daniel P. Berrangé
2020-07-02 12:56 ` [PATCH v2 1/3] util: validate whether O_DIRECT is supported after failure Daniel P. Berrangé
2020-07-02 15:29   ` Philippe Mathieu-Daudé
2020-07-08  6:45   ` Markus Armbruster [this message]
2020-07-02 12:56 ` [PATCH v2 2/3] util: support detailed error reporting for qemu_open Daniel P. Berrangé
2020-07-08  6:55   ` Markus Armbruster
2020-07-02 12:56 ` [PATCH v2 3/3] block: switch to use qemu_open_err for improved errors Daniel P. Berrangé
2020-07-08  6:57   ` Markus Armbruster

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=878sfu4i91.fsf@dusky.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=f4bug@amsat.org \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=ppandit@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.