From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Wei Liu <wei.liu2@citrix.com>,
Xen-devel <xen-devel@lists.xenproject.org>
Cc: Samuel Thibault <samuel.thibault@ens-lyon.org>,
Ian Jackson <ian.jackson@eu.citrix.com>,
Ian Campbell <ian.campbell@citrix.com>,
David Scott <dave@recoil.org>
Subject: Re: [PATCH] oxenstored: fix short-write issue
Date: Tue, 27 Oct 2015 17:21:39 +0000 [thread overview]
Message-ID: <562FB2A3.8070603@citrix.com> (raw)
In-Reply-To: <1445965809-5144-1-git-send-email-wei.liu2@citrix.com>
On 27/10/15 17:10, Wei Liu wrote:
> When oxenstored wrote to the ring, it wrote a chunk of contiguous data.
> Originally when it tried to write across ring boundary, it returned a
> short-write when there is still room. That led to stalling mini-os's
> xenstore thread at times.
>
> Fix this by calling write function for a second time when the first
> write completes partially.
>
> Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
> Signed-off-by: Wei Liu <wei.liu2@citrix.com>
> ---
> Cc: David Scott <dave@recoil.org>
> Cc: Ian Campbell <ian.campbell@citrix.com>
> Cc: Ian Jackson <ian.jackson@eu.citrix.com>
>
> Ian, backport candidate for as far as you can manage.
> ---
> tools/ocaml/libs/xb/xb.ml | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/tools/ocaml/libs/xb/xb.ml b/tools/ocaml/libs/xb/xb.ml
> index 50944b5..0730d13 100644
> --- a/tools/ocaml/libs/xb/xb.ml
> +++ b/tools/ocaml/libs/xb/xb.ml
> @@ -91,10 +91,12 @@ let write_fd back con s len =
> Unix.write back.fd s 0 len
>
> let write_mmap back con s len =
> - let ws = Xs_ring.write back.mmap s len in
> - if ws > 0 then
> + let ws = ref (Xs_ring.write back.mmap s len) in
> + if !ws < len then
> + ws := !ws + Xs_ring.write back.mmap (String.sub s !ws (len - !ws)) (len - !ws);
This is surely a TOCTOU, as the second attempted write could return
short as well.
The correct behaviour would be for Xs_ring.write to return the actual
number of bytes it put into the ring, even if this is shorter than len.
~Andrew
next prev parent reply other threads:[~2015-10-27 17:21 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-27 17:10 [PATCH] oxenstored: fix short-write issue Wei Liu
2015-10-27 17:21 ` Samuel Thibault
2015-10-27 17:21 ` Andrew Cooper [this message]
2015-10-27 17:26 ` Samuel Thibault
2015-10-27 17:28 ` Samuel Thibault
2015-10-27 17:31 ` Samuel Thibault
2015-10-27 17:31 ` Andrew Cooper
2015-10-28 13:34 ` David Scott
2015-10-28 13:47 ` Samuel Thibault
2015-10-28 14:00 ` Andrew Cooper
2015-10-28 14:04 ` David Vrabel
2015-11-02 13:44 ` Ian Campbell
2015-11-02 14:10 ` Andrew Cooper
2015-11-02 14:24 ` Ian Campbell
2015-11-02 14:27 ` Andrew Cooper
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=562FB2A3.8070603@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=dave@recoil.org \
--cc=ian.campbell@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=samuel.thibault@ens-lyon.org \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xenproject.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.