All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: "Roger Pau Monné" <roger.pau@citrix.com>
Cc: qemu-devel@nongnu.org, Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [Qemu-devel] [PATCH] block: char devices on FreeBSD are not behind a pager
Date: Tue, 21 Oct 2014 11:36:26 +0200	[thread overview]
Message-ID: <20141021093626.GD4409@noname.redhat.com> (raw)
In-Reply-To: <54461601.3040207@citrix.com>

Am 21.10.2014 um 10:14 hat Roger Pau Monné geschrieben:
> El 20/10/14 a les 19.22, Kevin Wolf ha escrit:
> > Am 20.10.2014 um 18:39 hat Roger Pau Monne geschrieben:
> >> Acknowledge this and forcefully set BDRV_O_NOCACHE and O_DIRECT in order to
> >> force QEMU to use aligned buffers.
> >>
> >> Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
> >> Cc: Kevin Wolf <kwolf@redhat.com>
> >> Cc: Stefan Hajnoczi <stefanha@redhat.com>
> >> ---
> >>  block/raw-posix.c | 12 ++++++++++++
> >>  1 file changed, 12 insertions(+)
> >>
> >> diff --git a/block/raw-posix.c b/block/raw-posix.c
> >> index 86ce4f2..63841dd 100644
> >> --- a/block/raw-posix.c
> >> +++ b/block/raw-posix.c
> >> @@ -472,6 +472,18 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
> >>          }
> >>  #endif
> >>      }
> >> +#ifdef __FreeBSD__
> >> +    if (S_ISCHR(st.st_mode)) {
> >> +        /*
> >> +         * The file is a char device (disk), which on FreeBSD isn't behind
> >> +         * a pager, so set BDRV_O_NOCACHE unconditionally. This is needed
> >> +         * so Qemu makes sure all IO operations on the device are aligned
> >> +         * to sector size, or else FreeBSD will reject them with EINVAL.
> >> +         */
> >> +        bs->open_flags |= BDRV_O_NOCACHE;
> >> +        s->open_flags |= O_DIRECT;
> >> +    }
> >> +#endif
> > 
> > No, this doesn't look right. Block drivers must not modify the options
> > that they get. (Yes, the Linux AIO case is broken in this respect.
> > Hopefully we'll be able to fix it soon.)
> > 
> > Depending on what the real requirements are, I can see two options:
> > 
> > 1. Require cache.direct=on (i.e. O_DIRECT) for char devices on FreeBSD.
> >    If the user didn't set the option, print a nice error message telling
> >    them what option to set.
> > 
> > 2. If O_DIRECT isn't actually required to open the file, but you only
> >    need to make sure to use the right alignment, modify
> >    raw_probe_alignment() so that it returns an alignment > 1 even for
> >    non-O_DIRECT files on FreeBSD if they are character devices.
> > 
> > I don't know FreeBSD good enough, but if it fulfills the requirements,
> > option 2 is certainly the more elegant one.
> 
> Thanks for the review. O_DIRECT is not required to open the file, so
> option 2 seems sensible.
> 
> I've added a new flag to BDRVRawState that's used to check if underlying
> device needs requests to be aligned. This flag is set by default if
> BDRV_O_NOCACHE is used, or if the OS is FreeBSD and the underlying
> device is a char dev. This new flag is used as a replacement of the
> O_DIRECT and BDRV_O_NOCACHE checks that were used in raw_probe_alignment
> and raw_aio_submit. Does this sound OK?

Yes, this sounds reasonable to me.

Kevin

      reply	other threads:[~2014-10-21  9:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-20 16:39 [Qemu-devel] [PATCH] block: char devices on FreeBSD are not behind a pager Roger Pau Monne
2014-10-20 17:22 ` Kevin Wolf
2014-10-21  8:14   ` Roger Pau Monné
2014-10-21  9:36     ` Kevin Wolf [this message]

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=20141021093626.GD4409@noname.redhat.com \
    --to=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=roger.pau@citrix.com \
    --cc=stefanha@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 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.