From patchwork Thu Apr 14 19:54:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 8842731 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id BCDA69F54F for ; Thu, 14 Apr 2016 19:56:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CF8CB2034C for ; Thu, 14 Apr 2016 19:56:44 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DA90720295 for ; Thu, 14 Apr 2016 19:56:43 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1aqnLJ-0001CG-Na; Thu, 14 Apr 2016 19:54:21 +0000 Received: from mail6.bemta6.messagelabs.com ([85.158.143.247]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1aqnLI-0001CA-Lo for xen-devel@lists.xen.org; Thu, 14 Apr 2016 19:54:20 +0000 Received: from [85.158.143.35] by server-3.bemta-6.messagelabs.com id 35/08-07120-B65FF075; Thu, 14 Apr 2016 19:54:19 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrGLMWRWlGSWpSXmKPExsXitHSDvW72V/5 wgwl3mS2WfFzM4sDocXT3b6YAxijWzLyk/IoE1oyDhxsYC7bLV8xfKN3A+Fuii5GTQ0LAX2Lr 5AUsIDabgL7E7hefmEBsEQF1idMdF1m7GLk4mAUmMUm09T8Fcjg4hAXigIrcQGpYBFQlZn75A VbPK+Ah8fbNNnaImXIS54//ZAaxhQTUJK71X2KHqBGUODnzCdguZgEJiYMvXjCDjJQQ4Jb422 0/gZFnFpKqWUiqFjAyrWJUL04tKkst0jXWSyrKTM8oyU3MzNE1NDDTy00tLk5MT81JTCrWS87 P3cQIDA8GINjB2PHP6RCjJAeTkiiv6R7+cCG+pPyUyozE4oz4otKc1OJDjDIcHEoSvDFfgHKC RanpqRVpmTnAQIVJS3DwKInwpoGkeYsLEnOLM9MhUqcYFaXEeZtBEgIgiYzSPLg2WHRcYpSVE uZlBDpEiKcgtSg3swRV/hWjOAejkjBvKcgUnsy8Erjpr4AWMwEtLnvHC7K4JBEhJdXAWHhYYL vIM0lBH40qmSMTVmxa1a8/5W7q6jnPPpcKBpUo89gv4vNLDI1YOIvzzYO9jTIvJ9VdrI2axGS wRqxBc+ovjWMlH9839wUUuVjqbjmSU5SbvZsh94WIWceEmB+Pgjp8/67KPbqzZ1mHNmPJfdkp Z2d2fblrv7L2WN+5Iw11/7njJkTsUmIpzkg01GIuKk4EAJGpgXSJAgAA X-Env-Sender: prvs=905e07e97=Andrew.Cooper3@citrix.com X-Msg-Ref: server-13.tower-21.messagelabs.com!1460663657!9518055!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 8.28; banners=-,-,- X-VirusChecked: Checked Received: (qmail 50741 invoked from network); 14 Apr 2016 19:54:18 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-13.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 14 Apr 2016 19:54:18 -0000 X-IronPort-AV: E=Sophos;i="5.24,485,1454976000"; d="scan'208";a="353815774" From: Andrew Cooper To: Xen-devel Date: Thu, 14 Apr 2016 20:54:15 +0100 Message-ID: <1460663655-8226-1-git-send-email-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.1.4 MIME-Version: 1.0 X-DLP: MIA1 Cc: Olaf Hering , Changlong Xie , Wei Liu , Wen Congyang , Andrew Cooper , Ian Jackson , Yang Hongyang Subject: [Xen-devel] [PATCH for-4.7] tools/libxl: Fix legacy migration following COLO backchannel breakage X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP c/s f5d947bf1b "tools/libxl: add back channel support to read stream" made a bogus adjustment to libxl__stream_read_start(), including removing the comment hinting at what was going on, which breaks conversion of a legacy migration stream. Symptoms look like: root@anonymi:~ # xl migrate domU host migration target: Ready to receive domain. Saving to migration stream new xl format (info 0x1/0x0/2677) xc: error: error polling suspend notification channel: -1: Internal error Loading new save file (new xl fmt info 0x1/0x0/2677) Savefile contains xl domain config in JSON format Parsing config from libxl: error: libxl_stream_read.c:327:stream_header_done: Invalid ident: expected 0x4c6962786c466d74, got 0x01f00f0000000000 libxl: error: libxl_utils.c:430:libxl_read_exactly: file/stream truncated reading ipc msg header from domain 1 save/restore helper stdout pipe The adjustment is not required for backchannel support (as there is no interaction between back channels and legacy conversion), and caused stream->fd to be latched in the datacopier before legacy conversion substitutes it for the fd which is the output of the conversion script. This causes libxl to consume data from the legacy stream rather than the v2 stream, and for the conversion script to encounter an error as the legacy stream appears to skip ahead. Undo the adjustments to libxl__stream_read_start(), and introduce a better description of what is going on. Introduce some extra assertions to try and catch similar breakage in the future. Reported-by: Olaf Hering Signed-off-by: Andrew Cooper Reviewed-by: Wen Congyang Reviewed-by: Wei Liu Tested-by: Olaf Hering --- CC: Ian Jackson CC: Wei Liu CC: Olaf Hering CC: Yang Hongyang CC: Wen Congyang CC: Changlong Xie --- tools/libxl/libxl_stream_read.c | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/tools/libxl/libxl_stream_read.c b/tools/libxl/libxl_stream_read.c index 9659051..89c2f21 100644 --- a/tools/libxl/libxl_stream_read.c +++ b/tools/libxl/libxl_stream_read.c @@ -234,16 +234,16 @@ void libxl__stream_read_start(libxl__egc *egc, stream->running = true; stream->phase = SRS_PHASE_NORMAL; - dc->ao = stream->ao; - dc->copywhat = "restore v2 stream"; - dc->readfd = stream->fd; - dc->writefd = -1; - - if (stream->back_channel) - return; - if (stream->legacy) { - /* Convert the legacy stream. */ + /* + * Convert the legacy stream. + * + * This results in a fork()/exec() of conversion helper script. It is + * passed the exiting stream->fd as an input, and returns the + * transformed stream via a new pipe. The fd of this new pipe then + * replaces stream->fd, to make the rest of the stream read code + * agnostic to whether legacy conversion is happening or not. + */ libxl__conversion_helper_state *chs = &stream->chs; chs->legacy_fd = stream->fd; @@ -258,10 +258,25 @@ void libxl__stream_read_start(libxl__egc *egc, goto err; } + /* There should be no interaction of COLO backchannels and legacy + * stream conversion. */ + assert(!stream->back_channel); + + /* Confirm *dc is still zeroed out, while we shuffle stream->fd. */ + assert(dc->ao == NULL); assert(stream->chs.v2_carefd); stream->fd = libxl__carefd_fd(stream->chs.v2_carefd); stream->dcs->libxc_fd = stream->fd; } + /* stream->fd is now a v2 stream. */ + + dc->ao = stream->ao; + dc->copywhat = "restore v2 stream"; + dc->readfd = stream->fd; + dc->writefd = -1; + + if (stream->back_channel) + return; /* Start reading the stream header. */ rc = setup_read(stream, "stream header",