From: Fam Zheng <famz@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org, Kevin Wolf <kwolf@redhat.com>,
Max Reitz <mreitz@redhat.com>,
qemu-block@nongnu.org, eblake@redhat.com
Subject: Re: [Qemu-devel] [PATCH] file-posix: Incoporate max_segments in block limit
Date: Wed, 8 Mar 2017 14:16:47 +0800 [thread overview]
Message-ID: <20170308061647.GD7835@lemon.lan> (raw)
In-Reply-To: <453cf467-9b0c-efa8-a523-a3f35072e70d@redhat.com>
On Tue, 03/07 11:58, Paolo Bonzini wrote:
>
>
> On 07/03/2017 03:17, Fam Zheng wrote:
> > Linux exposes a separate limit, /sys/block/.../queue/max_segments, which
> > in the worst case can be more restrictive than BLKSECTGET (as they are
> > two different things). Similar to the BLKSECTGET story, guests don't see
> > this limit and send big requests will get -EINVAL error on SG_IO.
> >
> > Lean on the safer side to clamp max_transfer according to max_segments
> > and page size, because in the end what host HBA gets is the mapped host
> > pages rather than a guest buffer.
> >
> > Signed-off-by: Fam Zheng <famz@redhat.com>
> > ---
> > block/file-posix.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
> > 1 file changed, 58 insertions(+)
> >
> > diff --git a/block/file-posix.c b/block/file-posix.c
> > index 4de1abd..b615262 100644
> > --- a/block/file-posix.c
> > +++ b/block/file-posix.c
> > @@ -668,6 +668,59 @@ static int hdev_get_max_transfer_length(BlockDriverState *bs, int fd)
> > #endif
> > }
> >
> > +static int hdev_get_max_segments(BlockDriverState *bs)
> > +{
> > +#ifdef CONFIG_LINUX
> > + char buf[32];
> > + const char *end;
> > + char *sysfspath, *fullpath;
> > + int ret;
> > + int fd = -1;
> > + long max_segments;
> > +
> > + fullpath = realpath(bs->exact_filename, NULL);
> > + if (!fullpath) {
> > + return -errno;
> > + }
> > + if (strncmp(fullpath, "/dev/", 5) || !fullpath[5]) {
> > + ret = -ENOTSUP;
> > + goto out;
> > + }
> > + sysfspath = g_strdup_printf("/sys/block/%s/queue/max_segments",
> > + &fullpath[5]);
>
> I think you cannot rely on the /dev/... path. Luckily, there is an
> alternative path to "queue" via /sys/dev/block/MAJOR:MINOR/queue, where
> MAJOR:MINOR can be retrieved via fstat. This also avoids any possible
> TOC-TOU races.
Sounds good, I'll send another version.
Fam
prev parent reply other threads:[~2017-03-08 6:16 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-07 2:17 [Qemu-devel] [PATCH] file-posix: Incoporate max_segments in block limit Fam Zheng
2017-03-07 10:58 ` Paolo Bonzini
2017-03-08 6:16 ` Fam Zheng [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=20170308061647.GD7835@lemon.lan \
--to=famz@redhat.com \
--cc=eblake@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=pbonzini@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.