From patchwork Sat Oct 12 02:39:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 1175642 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.intel.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46qpw81WNCz9sCJ for ; Sat, 12 Oct 2019 13:40:40 +1100 (AEDT) Received: from localhost ([::1]:58350 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJ7Kf-00047p-RZ for incoming@patchwork.ozlabs.org; Fri, 11 Oct 2019 22:40:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54816) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJ7KA-00045i-OG for qemu-devel@nongnu.org; Fri, 11 Oct 2019 22:40:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iJ7K9-0001IK-Ov for qemu-devel@nongnu.org; Fri, 11 Oct 2019 22:40:06 -0400 Received: from mga17.intel.com ([192.55.52.151]:11741) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iJ7K9-0001Hj-Gb for qemu-devel@nongnu.org; Fri, 11 Oct 2019 22:40:05 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Oct 2019 19:40:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.67,286,1566889200"; d="scan'208";a="395935154" Received: from richard.sh.intel.com (HELO localhost) ([10.239.159.54]) by fmsmga006.fm.intel.com with ESMTP; 11 Oct 2019 19:40:03 -0700 From: Wei Yang To: quintela@redhat.com, dgilbert@redhat.com Subject: [PATCH 1/2] migration/compress: compress QEMUFile is not writable Date: Sat, 12 Oct 2019 10:39:31 +0800 Message-Id: <20191012023932.1863-2-richardw.yang@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191012023932.1863-1-richardw.yang@linux.intel.com> References: <20191012023932.1863-1-richardw.yang@linux.intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.151 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org, Wei Yang Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" We open a file with empty_ops for compress QEMUFile, which means this is not writable. Signed-off-by: Wei Yang Reviewed-by: Juan Quintela --- migration/qemu-file.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/migration/qemu-file.c b/migration/qemu-file.c index 26fb25ddc1..f3d99a96ec 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -744,11 +744,8 @@ static int qemu_compress_data(z_stream *stream, uint8_t *dest, size_t dest_len, /* Compress size bytes of data start at p and store the compressed * data to the buffer of f. * - * When f is not writable, return -1 if f has no space to save the - * compressed data. - * When f is wirtable and it has no space to save the compressed data, - * do fflush first, if f still has no space to save the compressed - * data, return -1. + * Since the file is dummy file with empty_ops, return -1 if f has no space to + * save the compressed data. */ ssize_t qemu_put_compression_data(QEMUFile *f, z_stream *stream, const uint8_t *p, size_t size) @@ -756,14 +753,7 @@ ssize_t qemu_put_compression_data(QEMUFile *f, z_stream *stream, ssize_t blen = IO_BUF_SIZE - f->buf_index - sizeof(int32_t); if (blen < compressBound(size)) { - if (!qemu_file_is_writable(f)) { - return -1; - } - qemu_fflush(f); - blen = IO_BUF_SIZE - sizeof(int32_t); - if (blen < compressBound(size)) { - return -1; - } + return -1; } blen = qemu_compress_data(stream, f->buf + f->buf_index + sizeof(int32_t), From patchwork Sat Oct 12 02:39:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 1175643 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.intel.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46qpw93HBFz9sPJ for ; Sat, 12 Oct 2019 13:40:41 +1100 (AEDT) Received: from localhost ([::1]:58352 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJ7Kg-000488-8L for incoming@patchwork.ozlabs.org; Fri, 11 Oct 2019 22:40:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54827) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJ7KB-00045l-K2 for qemu-devel@nongnu.org; Fri, 11 Oct 2019 22:40:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iJ7KA-0001Ij-FP for qemu-devel@nongnu.org; Fri, 11 Oct 2019 22:40:07 -0400 Received: from mga17.intel.com ([192.55.52.151]:11741) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iJ7KA-0001Hj-84 for qemu-devel@nongnu.org; Fri, 11 Oct 2019 22:40:06 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Oct 2019 19:40:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.67,286,1566889200"; d="scan'208";a="395935164" Received: from richard.sh.intel.com (HELO localhost) ([10.239.159.54]) by fmsmga006.fm.intel.com with ESMTP; 11 Oct 2019 19:40:04 -0700 From: Wei Yang To: quintela@redhat.com, dgilbert@redhat.com Subject: [PATCH 2/2] migration/compress: disable compress if failed to setup Date: Sat, 12 Oct 2019 10:39:32 +0800 Message-Id: <20191012023932.1863-3-richardw.yang@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191012023932.1863-1-richardw.yang@linux.intel.com> References: <20191012023932.1863-1-richardw.yang@linux.intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.151 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org, Wei Yang Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" In current logic, if compress_threads_save_setup() returns -1 the whole migration would fail, while we could handle it gracefully by disable compress. Signed-off-by: Wei Yang --- migration/migration.c | 9 +++++++++ migration/migration.h | 1 + migration/ram.c | 15 ++++++++------- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 5f7e4d15e9..02b95f4223 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2093,6 +2093,15 @@ bool migrate_use_compression(void) return s->enabled_capabilities[MIGRATION_CAPABILITY_COMPRESS]; } +void migrate_disable_compression(void) +{ + MigrationState *s; + + s = migrate_get_current(); + + s->enabled_capabilities[MIGRATION_CAPABILITY_COMPRESS] = false; +} + int migrate_compress_level(void) { MigrationState *s; diff --git a/migration/migration.h b/migration/migration.h index 4f2fe193dc..51368d3a6e 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -309,6 +309,7 @@ bool migrate_use_return_path(void); uint64_t ram_get_total_transferred_pages(void); bool migrate_use_compression(void); +void migrate_disable_compression(void); int migrate_compress_level(void); int migrate_compress_threads(void); int migrate_compress_wait_thread(void); diff --git a/migration/ram.c b/migration/ram.c index 96c9b16402..39279161a8 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -533,12 +533,12 @@ static void compress_threads_save_cleanup(void) comp_param = NULL; } -static int compress_threads_save_setup(void) +static void compress_threads_save_setup(void) { int i, thread_count; if (!migrate_use_compression()) { - return 0; + return; } thread_count = migrate_compress_threads(); compress_threads = g_new0(QemuThread, thread_count); @@ -569,11 +569,14 @@ static int compress_threads_save_setup(void) do_data_compress, comp_param + i, QEMU_THREAD_JOINABLE); } - return 0; + return; exit: compress_threads_save_cleanup(); - return -1; + migrate_disable_compression(); + error_report("%s: failed to setup compress threads, compress disabled", + __func__); + return; } /* Multiple fd's */ @@ -3338,9 +3341,7 @@ static int ram_save_setup(QEMUFile *f, void *opaque) RAMState **rsp = opaque; RAMBlock *block; - if (compress_threads_save_setup()) { - return -1; - } + compress_threads_save_setup(); /* migration has already setup the bitmap, reuse it. */ if (!migration_in_colo_state()) {