From: Andrew Cooper Subject: [PATCH v2 6/6] tools/libxl: Adjust datacopiers POLLHUP handling when the fd is also readable Date: Fri, 6 Mar 2015 19:05:41 +0000 Message-ID: <1425668741-28003-7-git-send-email-andrew.cooper3@citrix.com> References: <1425668741-28003-1-git-send-email-andrew.cooper3@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1425668741-28003-1-git-send-email-andrew.cooper3@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Xen-devel Cc: Andrew Cooper , Ian Jackson , Ian Campbell , Wei Liu List-Id: xen-devel@lists.xenproject.org POLLHUP|POLLIN is a valid revent to receive when there is readable data in a pipe, but the writable fd has been closed. This occurs in migration v2 when the legacy conversion process (which transforms the data inline) completes and exits successfully. In the case that there is data to read, suppress the POLLHUP. POSIX states that the hangup state is latched[1], which means it will reoccur on subsequent poll() calls. The datacopier is thus provided the opportunity to read until EOF, if possible. A POLLHUP on its own is treated exactly as before, indicating a different error with the fd. [1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/poll.html Signed-off-by: Andrew Cooper CC: Ian Campbell CC: Ian Jackson CC: Wei Liu --- v2: Rework solution from scratch --- tools/libxl/libxl_aoutils.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/libxl/libxl_aoutils.c b/tools/libxl/libxl_aoutils.c index a402e5c..a5ad3e5 100644 --- a/tools/libxl/libxl_aoutils.c +++ b/tools/libxl/libxl_aoutils.c @@ -204,6 +204,9 @@ static void datacopier_readable(libxl__egc *egc, libxl__ev_fd *ev, libxl__datacopier_state *dc = CONTAINER_OF(ev, *dc, toread); STATE_AO_GC(dc->ao); + if ((revents & (POLLHUP|POLLIN)) == (POLLHUP|POLLIN)) + revents &= ~POLLHUP; + if (datacopier_pollhup_handled(egc, dc, revents, 0)) return; -- 1.7.10.4