All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ian Campbell <ian.campbell@citrix.com>
To: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: "Andrew Cooper" <andrew.cooper3@citrix.com>,
	xen-devel@lists.xensource.com,
	"Ross Lagerwall" <ross.lagerwall@citrix.com>,
	"Wei Liu" <wei.liu2@citrix.com>,
	"Roger Pau Monné" <roger.pau@citrix.com>
Subject: Re: [PATCH 2/3] libxl: Cope with pipes which signal POLLHUP|POLLIN on read eof
Date: Thu, 2 Apr 2015 16:13:44 +0100	[thread overview]
Message-ID: <1427987624.4037.88.camel@citrix.com> (raw)
In-Reply-To: <1427987045-23435-2-git-send-email-ian.jackson@eu.citrix.com>

On Thu, 2015-04-02 at 16:04 +0100, Ian Jackson wrote:
> Some operating systems (including FreeBSD[1]) signal not just POLLIN
> when a reading pipe reaches EOF, but also POLLHUP.  This is
> permitted[2].  But datacopiers mishandle this, because they always
> treat POLLHUP exceptionally (either reporting it via callback_pollhup,
> or treating it as an error).  datacopiers reading from pipes on such
> OSs can fail (perhaps leaving some data unprocessed) rather than
> completing successfully.
> 
> [1] http://www.greenend.org.uk/rjk/tech/poll.html
> [2] http://pubs.opengroup.org/onlinepubs/9699919799/functions/poll.html
> 
> Most callers in libxl do not care about POLLHUP except as an error
> condition.
> 
> So change the datacopier semantics so that unless callback_pollhup is
> specified we treat POLLHUP|POLLIN as if it were POLLIN - and, read all
> available data).

Punctuation is odd towards the end, a stray looking "-" and an unmatched
")". 

> This fixes the problem which 7e9ec50b0535 was aimed at.
> 
> Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
> CC: Andrew Cooper <andrew.cooper3@citrix.com>
> CC: Roger Pau Monné <roger.pau@citrix.com>

Acked-by: Ian Campbell <ian.campbell@citrix.com>

> CC: Ross Lagerwall <ross.lagerwall@citrix.com>
> CC: Wei Liu <wei.liu2@citrix.com>
> ---
>  tools/libxl/libxl_aoutils.c  |    2 +-
>  tools/libxl/libxl_internal.h |    3 ++-
>  2 files changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/libxl/libxl_aoutils.c b/tools/libxl/libxl_aoutils.c
> index 3942634..c3232a6 100644
> --- a/tools/libxl/libxl_aoutils.c
> +++ b/tools/libxl/libxl_aoutils.c
> @@ -208,7 +208,7 @@ static void datacopier_readable(libxl__egc *egc, libxl__ev_fd *ev,
>      if (datacopier_pollhup_handled(egc, dc, revents, 0))
>          return;
>  
> -    if (revents & ~POLLIN) {
> +    if (revents & ~POLLIN && revents != (POLLIN|POLLHUP)) {

AIUI you are checking "revents != (POLLIN|POLLHUP)" rather than
"(revents&((POLLIN|POLLHUP)) != (POLLIN|POLLHUP)" because e.g. POLLIN|
POLLHUP|POLLOUT is nonsensical and is never expected.

>          LOG(ERROR, "unexpected poll event 0x%x (should be POLLIN)"
>              " on %s during copy of %s", revents, dc->readwhat, dc->copywhat);
>          datacopier_callback(egc, dc, -1, 0);
> diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
> index 7f81dd3..c6969f0 100644
> --- a/tools/libxl/libxl_internal.h
> +++ b/tools/libxl/libxl_internal.h
> @@ -2535,7 +2535,8 @@ typedef struct libxl__datacopier_buf libxl__datacopier_buf;
>   *     errnoval!=0 means we had a read error, logged
>   * onwrite==-1 means some other internal failure, errnoval not valid, logged
>   * If we get POLLHUP, we call callback_pollhup(..., onwrite, -1);
> - * or if callback_pollhup==0 this is an internal failure, as above.
> + * or if callback_pollhup==0 this is treated as eof (if POLLIN|POLLHUP
> + * on the reading fd) or an internal failure (otherwise), as above.
>   * In all cases copier is killed before calling this callback */
>  typedef void libxl__datacopier_callback(libxl__egc *egc,
>       libxl__datacopier_state *dc, int onwrite, int errnoval);



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

  reply	other threads:[~2015-04-02 15:13 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-16 13:29 [PATCH v3 1/6] tools/libxl: Introduce min and max macros Ross Lagerwall
2015-03-16 13:29 ` [PATCH v3 2/6] tools/libxl: Update datacopier to support sending data only Ross Lagerwall
2015-03-16 13:29 ` [PATCH v3 3/6] tools/libxl: Avoid overrunning static buffer with prefixdata Ross Lagerwall
2015-03-16 13:29 ` [PATCH v3 4/6] tools/libxl: Allow limiting amount copied by datacopier Ross Lagerwall
2015-03-18 11:12   ` Ian Campbell
2015-03-16 13:29 ` [PATCH v3 5/6] tools/libxl: Extend datacopier to support reading into a buffer Ross Lagerwall
2015-03-18 11:18   ` Ian Campbell
2015-04-01 15:53   ` Ian Jackson
2015-04-01 15:59     ` Ian Campbell
2015-03-16 13:29 ` [PATCH v3 6/6] tools/libxl: Adjust datacopiers POLLHUP handling when the fd is also readable Ross Lagerwall
2015-03-18 11:31   ` Ian Campbell
2015-03-26 15:20   ` Roger Pau Monné
2015-03-30 10:40     ` Ian Campbell
2015-04-01 10:34       ` Roger Pau Monné
2015-04-01 14:36         ` Andrew Cooper
2015-04-02 15:03           ` [PATCH 0/3] datacopier POLLHUP fixes " Ian Jackson
2015-04-02 15:04             ` [PATCH 1/3] Revert "tools/libxl: Adjust datacopiers POLLHUP handling when the fd is also readable" Ian Jackson
2015-04-02 15:08               ` Ian Campbell
2015-04-02 15:27                 ` Ian Jackson
2015-04-02 15:10               ` Andrew Cooper
2015-04-02 15:11               ` Ian Jackson
2015-04-02 15:04             ` [PATCH 2/3] libxl: Cope with pipes which signal POLLHUP|POLLIN on read eof Ian Jackson
2015-04-02 15:13               ` Ian Campbell [this message]
2015-04-02 15:04             ` [PATCH 3/3] libxl: datacopier: Avoid theoretical eof/POLLHUP race Ian Jackson
2015-04-02 15:15               ` Ian Campbell
2015-04-02 16:29               ` Ian Jackson
2015-04-07 11:14                 ` Roger Pau Monné
2015-04-07 12:26                   ` Ian Jackson
2015-04-02 15:09             ` [PATCH 0/3] datacopier POLLHUP fixes handling when the fd is also readable Ian Jackson

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=1427987624.4037.88.camel@citrix.com \
    --to=ian.campbell@citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=roger.pau@citrix.com \
    --cc=ross.lagerwall@citrix.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xensource.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.