From patchwork Mon Sep 3 09:26:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 10585633 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3040D920 for ; Mon, 3 Sep 2018 09:27:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2987F2956A for ; Mon, 3 Sep 2018 09:27:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1DED529573; Mon, 3 Sep 2018 09:27:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B9C122956A for ; Mon, 3 Sep 2018 09:27:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727156AbeICNq0 (ORCPT ); Mon, 3 Sep 2018 09:46:26 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:35797 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726234AbeICNq0 (ORCPT ); Mon, 3 Sep 2018 09:46:26 -0400 Received: by mail-pg1-f194.google.com with SMTP id 7-v6so3407172pgf.2 for ; Mon, 03 Sep 2018 02:27:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4v1KhMeqsfctLzh5wAQ3nkZnkCI9ZncjoRGmCxofBzo=; b=NNRIsmVLsJwkQb06jVyGP7uEc4dNijylB8CtVSF/8hlNrRIIvq17CCCo7YfPaP1/Dg Z/AQT/P/TZQPzx6aju7vI4LrTMiqoQ0/4IesPxBD4I3fOTyGwR2GVTGXMVf0Cyc1Ek7o 4u/9pS4ZEqsUm3zBnqAjNug5dIk1L38qBaGZN5/rB0jPnoVYQfvooEKxfYQVovz9dF1I 4N8rqMCkKo8tbWwf4CjZE7fnIt9Ug/bzYeyEsCaIgkoP3lU0kxr7eO/TWyof2xTOkgE0 UUhdJW5B3NtPDm3bWPl74Yt+t6XvvVJXUyDRcS0KUn/49ki+jDzvr0OcJ14Tiq4XssEy AOnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4v1KhMeqsfctLzh5wAQ3nkZnkCI9ZncjoRGmCxofBzo=; b=frZ1Cg/S0P6eEaFEAJJpywHlqOYeFoLkGTxlGk/QJgxi0UvfLnn72Hyy4mCdal0+kq E+lZWJI5NbAck1m9Xx2P39X7ij/1jDEap3VgIZR6icBuP7XGx52fBE1ZOU9WliLmLubn UnWQ3jFMyi5WaLzfrYFar+rusMnLFG+0q3dLgn3CyykRCIJ6XrHTW8h8o+wNaWHjlfq2 aD+szwwqk9yR/w+1Fp1ePkgrLuzEOhX7lQR8+0Y77iBg5V0NlgOkqd9Fbkk4pZgZtr38 KCHAwt55eIqe3aKn3zgahAoi2FpIkDrA3wMantkg0kh9nZUyxpl9KQ7nV/mimJYNdk0P mV7A== X-Gm-Message-State: APzg51DAHQbF7EnCBhjwHTeQkqziCa+jE471eVY/FBB+7Q8yv6vkxsll BHYDFMgrQFlg+ibiFPJcEiu9ljRZ X-Google-Smtp-Source: ANB0VdboP1++JJ2smUf5KqZD0+43Yl7nel/LrN/cnGmCz8u0PQyy0vM17PhwPuME1iTEBAbcLn506A== X-Received: by 2002:a62:7d8d:: with SMTP id y135-v6mr28095270pfc.259.1535966828784; Mon, 03 Sep 2018 02:27:08 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.40]) by smtp.gmail.com with ESMTPSA id 3-v6sm33543102pfq.10.2018.09.03.02.27.04 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 03 Sep 2018 02:27:08 -0700 (PDT) From: guangrong.xiao@gmail.com X-Google-Original-From: xiaoguangrong@tencent.com To: pbonzini@redhat.com, mst@redhat.com, mtosatti@redhat.com Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, dgilbert@redhat.com, peterx@redhat.com, wei.w.wang@intel.com, jiang.biao2@zte.com.cn, eblake@redhat.com, quintela@redhat.com, Xiao Guangrong Subject: [PATCH v5 4/4] migration: handle the error condition properly Date: Mon, 3 Sep 2018 17:26:44 +0800 Message-Id: <20180903092644.25812-5-xiaoguangrong@tencent.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180903092644.25812-1-xiaoguangrong@tencent.com> References: <20180903092644.25812-1-xiaoguangrong@tencent.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Xiao Guangrong ram_find_and_save_block() can return negative if any error hanppens, however, it is completely ignored in current code Signed-off-by: Xiao Guangrong Reviewed-by: Juan Quintela --- migration/ram.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 0e8c3ca33d..cb402ca6c8 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -2413,7 +2413,8 @@ static int ram_save_host_page(RAMState *rs, PageSearchStatus *pss, * * Called within an RCU critical section. * - * Returns the number of pages written where zero means no dirty pages + * Returns the number of pages written where zero means no dirty pages, + * or negative on error * * @rs: current RAM state * @last_stage: if we are at the completion stage @@ -3248,6 +3249,12 @@ static int ram_save_iterate(QEMUFile *f, void *opaque) done = 1; break; } + + if (pages < 0) { + qemu_file_set_error(f, pages); + break; + } + rs->target_page_count += pages; /* we want to check in the 1st loop, just in case it was the 1st time @@ -3289,7 +3296,7 @@ out: /** * ram_save_complete: function called to send the remaining amount of ram * - * Returns zero to indicate success + * Returns zero to indicate success or negative on error * * Called with iothread lock * @@ -3300,6 +3307,7 @@ static int ram_save_complete(QEMUFile *f, void *opaque) { RAMState **temp = opaque; RAMState *rs = *temp; + int ret = 0; rcu_read_lock(); @@ -3320,6 +3328,10 @@ static int ram_save_complete(QEMUFile *f, void *opaque) if (pages == 0) { break; } + if (pages < 0) { + ret = pages; + break; + } } flush_compressed_data(rs); @@ -3331,7 +3343,7 @@ static int ram_save_complete(QEMUFile *f, void *opaque) qemu_put_be64(f, RAM_SAVE_FLAG_EOS); qemu_fflush(f); - return 0; + return ret; } static void ram_save_pending(QEMUFile *f, void *opaque, uint64_t max_size,