From nobody Mon Feb 9 11:06:33 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1604913463; cv=none; d=zohomail.com; s=zohoarc; b=QqCuyZOEANqFDOC/A9mGAxPn1NIDd2i7movDEQc2tLlbK7P9LXX9k5B/M3Dvw3t6Xe4siQ1XEMjEV+T6dJKrMiZmLh3UxGAF2AG2VLx6Ky57w1qnwdoue1SVmtNnx9XsIEWVuR2/koKXNG0PaIOhF84gFJ3wW39MdbQGAb6XemA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604913463; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=qoZbLUcP0idhMfbAiqW6DvrUrEmZIb+eogiPXfp//9M=; b=RUSGQZYAYORSU6PyAQey5iK7fKP7m86VN6tGizJKrluV3wy6hTzqr8fXdZuE0gUwZQHVFcKRRqQZFr3m68ZgLftzfKRqNsoFHZJzZrZ4hbaPkY5nQJmY/K/bWB8UH5y3SSf0mSgreNvWdhFTbvBx7IUUwSMygtA7Qi7GSX5W1n0= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1604913463843460.97761332054245; Mon, 9 Nov 2020 01:17:43 -0800 (PST) Received: from localhost ([::1]:37554 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kc3J0-0005HR-OI for importer@patchew.org; Mon, 09 Nov 2020 04:17:42 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53484) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kc3Ay-0004Rd-Qz for qemu-devel@nongnu.org; Mon, 09 Nov 2020 04:09:24 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:2082) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kc3Av-0006yB-Py for qemu-devel@nongnu.org; Mon, 09 Nov 2020 04:09:24 -0500 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4CV4tW0hf3zhhsv; Mon, 9 Nov 2020 17:09:07 +0800 (CST) Received: from localhost (10.174.186.67) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.487.0; Mon, 9 Nov 2020 17:09:04 +0800 From: Zeyu Jin To: , Subject: [RFC PATCH 5/6] migration: Add compress_level sanity check Date: Mon, 9 Nov 2020 17:08:49 +0800 Message-ID: <20201109090850.2424-6-jinzeyu@huawei.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20201109090850.2424-1-jinzeyu@huawei.com> References: <20201109090850.2424-1-jinzeyu@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.174.186.67] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.32; envelope-from=jinzeyu@huawei.com; helo=szxga06-in.huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/09 04:09:11 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: Ying Fang , qemu-devel@nongnu.org, Zeyu Jin , zhang.zhanghailiang@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Zlib compression has level from 1 to 9. However Zstd compression has level from 1 to 22 (level >=3D 20 not recommanded). Let's do sanity check here to make sure a vaild compress_level is given by user. Signed-off-by: Zeyu Jin Signed-off-by: Ying Fang --- migration/migration.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 2c68012029..6fc0c3b532 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1235,16 +1235,40 @@ void qmp_migrate_set_capabilities(MigrationCapabili= tyStatusList *params, } } =20 +static bool compress_level_check(MigrationParameters *params, Error **errp) +{ + switch (params->compress_method) { + case COMPRESS_METHOD_ZLIB: + if (params->compress_level > 9 || params->compress_level < 1) { + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "compress_level= ", + "a value in the range of 0 to 9 for Zlib method= "); + return false; + } + break; +#ifdef CONFIG_ZSTD + case COMPRESS_METHOD_ZSTD: + if (params->compress_level > 19 || params->compress_level < 1) { + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "compress_level= ", + "a value in the range of 1 to 19 for Zstd method"); + return false; + } + break; +#endif + default: + error_setg(errp, "Checking compress_level failed for unknown reaso= n"); + return false; + } + + return true; +} + /* * Check whether the parameters are valid. Error will be put into errp * (if provided). Return true if valid, otherwise false. */ static bool migrate_params_check(MigrationParameters *params, Error **errp) { - if (params->has_compress_level && - (params->compress_level > 9)) { - error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "compress_level", - "is invalid, it should be in the range of 0 to 9"); + if (params->has_compress_level && !compress_level_check(params, errp))= { return false; } =20 --=20 2.23.0