From patchwork Fri Jun 19 12:01:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 11614021 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F2B7C90 for ; Fri, 19 Jun 2020 12:05:05 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id CAE34207FC for ; Fri, 19 Jun 2020 12:05:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="eUCyokQy" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CAE34207FC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:52560 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jmFlY-00022t-VL for patchwork-qemu-devel@patchwork.kernel.org; Fri, 19 Jun 2020 08:05:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51342) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmFin-0005sb-Dp for qemu-devel@nongnu.org; Fri, 19 Jun 2020 08:02:13 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:24065 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jmFih-0006fH-SE for qemu-devel@nongnu.org; Fri, 19 Jun 2020 08:02:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592568127; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/qerQErdalHQiK49BHtasKxC2XsYO05yy8OaZy5W7ME=; b=eUCyokQytwRS7biEYUdmGMYftYx9n7Iz5e2eO7VB50FPKTY0Rd7+MrpMPsYUbjwL4PvM8k +ueJxbHi5xgNL6MJfyr3Re1Sm11BzMI3lagCCkyCOHTVQj1n6lxOcXB/mfO5aWtkK4mKuH j7cQMRNZsEucH/CxLxEpOT5AMtDd6d8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-241--qo0FxrrMEuv0MsJMtwAjg-1; Fri, 19 Jun 2020 08:02:05 -0400 X-MC-Unique: -qo0FxrrMEuv0MsJMtwAjg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 22BEBA0BD7; Fri, 19 Jun 2020 12:02:04 +0000 (UTC) Received: from localhost (ovpn-113-212.ams2.redhat.com [10.36.113.212]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5F3035D9CA; Fri, 19 Jun 2020 12:02:00 +0000 (UTC) From: Stefan Hajnoczi To: Coiby Xu Subject: [PATCH 1/6] block-helpers: move MIN/MAX_BLOCK_SIZE constants into header file Date: Fri, 19 Jun 2020 13:01:52 +0100 Message-Id: <20200619120157.2422429-1-stefanha@redhat.com> In-Reply-To: <20200614183907.514282-4-coiby.xu@gmail.com> References: <20200614183907.514282-4-coiby.xu@gmail.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=207.211.31.81; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/19 01:50:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -13 X-Spam_score: -1.4 X-Spam_bar: - X-Spam_report: (-1.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN 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: kwolf@redhat.com, bharatlkmlkvm@gmail.com, qemu-devel@nongnu.org, Stefan Hajnoczi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Move the constants from hw/core/qdev-properties.c to util/block-helpers.h so that knowledge of the min/max values is encapsulated in block-helpers code. Callers should not assume specific min/max values. In fact, the values in hw/core/qdev-properties.c and util/block-helpers.c did not match. Use the hw/core/qdev-properties.c values since that's what existing code expects. Signed-off-by: Stefan Hajnoczi --- util/block-helpers.h | 12 ++++++++++++ hw/core/qdev-properties.c | 11 ----------- util/block-helpers.c | 7 ++----- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/util/block-helpers.h b/util/block-helpers.h index f06be282a1..46975ca7af 100644 --- a/util/block-helpers.h +++ b/util/block-helpers.h @@ -1,6 +1,18 @@ #ifndef BLOCK_HELPERS_H #define BLOCK_HELPERS_H +#include "qemu/units.h" + +/* lower limit is sector size */ +#define MIN_BLOCK_SIZE INT64_C(512) +#define MIN_BLOCK_SIZE_STR "512 B" +/* + * upper limit is arbitrary, 2 MiB looks sufficient for all sensible uses, and + * matches qcow2 cluster size limit + */ +#define MAX_BLOCK_SIZE (2 * MiB) +#define MAX_BLOCK_SIZE_STR "2 MiB" + void check_logical_block_size(const char *id, const char *name, uint16_t value, Error **errp); diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index b478f100af..03981feb02 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -14,7 +14,6 @@ #include "qapi/visitor.h" #include "chardev/char.h" #include "qemu/uuid.h" -#include "qemu/units.h" #include "util/block-helpers.h" void qdev_prop_set_after_realize(DeviceState *dev, const char *name, @@ -782,16 +781,6 @@ const PropertyInfo qdev_prop_size32 = { /* --- blocksize --- */ -/* lower limit is sector size */ -#define MIN_BLOCK_SIZE 512 -#define MIN_BLOCK_SIZE_STR "512 B" -/* - * upper limit is arbitrary, 2 MiB looks sufficient for all sensible uses, and - * matches qcow2 cluster size limit - */ -#define MAX_BLOCK_SIZE (2 * MiB) -#define MAX_BLOCK_SIZE_STR "2 MiB" - static void set_blocksize(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { diff --git a/util/block-helpers.c b/util/block-helpers.c index d31309cc0e..089fe3401d 100644 --- a/util/block-helpers.c +++ b/util/block-helpers.c @@ -25,13 +25,10 @@ void check_logical_block_size(const char *id, const char *name, uint16_t value, Error **errp) { - const int64_t min = 512; - const int64_t max = 32768; - /* value of 0 means "unset" */ - if (value && (value < min || value > max)) { + if (value && (value < MIN_BLOCK_SIZE || value > MAX_BLOCK_SIZE)) { error_setg(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE, - id, name, (int64_t)value, min, max); + id, name, value, MIN_BLOCK_SIZE, MAX_BLOCK_SIZE); return; } From patchwork Fri Jun 19 12:01:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 11614025 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 14D8413A0 for ; Fri, 19 Jun 2020 12:05:15 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id DFCF9206D7 for ; Fri, 19 Jun 2020 12:05:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Vy8H68yI" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DFCF9206D7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:53112 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jmFli-0002J9-31 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 19 Jun 2020 08:05:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51366) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmFip-0005wv-0g for qemu-devel@nongnu.org; Fri, 19 Jun 2020 08:02:15 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:46433 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jmFim-0006fX-MJ for qemu-devel@nongnu.org; Fri, 19 Jun 2020 08:02:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592568132; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7/lfnL4sZXHtl+qlzPzdmzfltq9+rSdml1mjkHgKpYs=; b=Vy8H68yIAKQUda2LlAGAQZ8s+wRAGtkc6RYeCi599KbjdWCQ6oFzh0VzQF3RovwurYmqwF L0q0a2tHijHootCkLTrVrWw+0SvXWsG4iIs6Bls8zI4dsK9hb5kvRyxmdAlMRlhaIpiMrN fbMqFnENKpN4RmrVmg0wsQMiUNofL0I= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-121-DoWWaWtcPUW-V4zFzHcp7w-1; Fri, 19 Jun 2020 08:02:09 -0400 X-MC-Unique: DoWWaWtcPUW-V4zFzHcp7w-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D2ADB18FE864; Fri, 19 Jun 2020 12:02:08 +0000 (UTC) Received: from localhost (ovpn-113-212.ams2.redhat.com [10.36.113.212]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7027D7C1EC; Fri, 19 Jun 2020 12:02:05 +0000 (UTC) From: Stefan Hajnoczi To: Coiby Xu Subject: [PATCH 2/6] block-helpers: switch to int64_t block size values Date: Fri, 19 Jun 2020 13:01:53 +0100 Message-Id: <20200619120157.2422429-2-stefanha@redhat.com> In-Reply-To: <20200619120157.2422429-1-stefanha@redhat.com> References: <20200614183907.514282-4-coiby.xu@gmail.com> <20200619120157.2422429-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=207.211.31.120; envelope-from=stefanha@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/19 03:15:03 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -13 X-Spam_score: -1.4 X-Spam_bar: - X-Spam_report: (-1.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN 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: kwolf@redhat.com, bharatlkmlkvm@gmail.com, qemu-devel@nongnu.org, Stefan Hajnoczi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" The uint16_t type is too small for MAX_BLOCK_SIZE (2 MiB). The int64_t type is widely used in QEMU as a type for disk offsets and sizes, so it's an appropriate type to use here. It will work for all callers. Signed-off-by: Stefan Hajnoczi --- util/block-helpers.h | 2 +- util/block-helpers.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/util/block-helpers.h b/util/block-helpers.h index 46975ca7af..ec6421560c 100644 --- a/util/block-helpers.h +++ b/util/block-helpers.h @@ -13,7 +13,7 @@ #define MAX_BLOCK_SIZE (2 * MiB) #define MAX_BLOCK_SIZE_STR "2 MiB" -void check_logical_block_size(const char *id, const char *name, uint16_t value, +void check_logical_block_size(const char *id, const char *name, int64_t value, Error **errp); #endif /* BLOCK_HELPERS_H */ diff --git a/util/block-helpers.c b/util/block-helpers.c index 089fe3401d..9e68954c46 100644 --- a/util/block-helpers.c +++ b/util/block-helpers.c @@ -22,7 +22,7 @@ * * Moved from hw/core/qdev-properties.c:set_blocksize() */ -void check_logical_block_size(const char *id, const char *name, uint16_t value, +void check_logical_block_size(const char *id, const char *name, int64_t value, Error **errp) { /* value of 0 means "unset" */ @@ -37,7 +37,7 @@ void check_logical_block_size(const char *id, const char *name, uint16_t value, error_setg(errp, "Property %s.%s doesn't take value '%" PRId64 "', it's not a power of 2", - id, name, (int64_t)value); + id, name, value); return; } } From patchwork Fri Jun 19 12:01:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 11614035 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4F55D90 for ; Fri, 19 Jun 2020 12:09:05 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 271852083B for ; Fri, 19 Jun 2020 12:09:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="VpQKx16G" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 271852083B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:38088 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jmFpQ-00088N-BZ for patchwork-qemu-devel@patchwork.kernel.org; Fri, 19 Jun 2020 08:09:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51468) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmFiw-0006Is-Mz for qemu-devel@nongnu.org; Fri, 19 Jun 2020 08:02:22 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:32935 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jmFiu-0006gr-Tv for qemu-devel@nongnu.org; Fri, 19 Jun 2020 08:02:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592568140; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NJFzzQUK4oUGscimCZCDMzmOjZZhjC5cSgVU5jzFQ8A=; b=VpQKx16G6tI8f5hEIlvvCV1C3MBrmyb/eGiJFm1uwOyNSrNmjQIB5VDghK8QseStW4UOF5 Bq4zvnMCc3nd6pw96+L1MwuGPKKlVhiYNq3+ejvrBrwpLjbnajnCpdcJreg+3MYb037t1x Ornlt7822mk4UlMEx3wKKJvPXWB5YGM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-229-BW25WVnpNcqUBnMl1v18ig-1; Fri, 19 Jun 2020 08:02:18 -0400 X-MC-Unique: BW25WVnpNcqUBnMl1v18ig-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3B65F464; Fri, 19 Jun 2020 12:02:17 +0000 (UTC) Received: from localhost (ovpn-113-212.ams2.redhat.com [10.36.113.212]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3EB425C1D0; Fri, 19 Jun 2020 12:02:10 +0000 (UTC) From: Stefan Hajnoczi To: Coiby Xu Subject: [PATCH 3/6] block-helpers: rename check_logical_block_size() to check_block_size() Date: Fri, 19 Jun 2020 13:01:54 +0100 Message-Id: <20200619120157.2422429-3-stefanha@redhat.com> In-Reply-To: <20200619120157.2422429-1-stefanha@redhat.com> References: <20200614183907.514282-4-coiby.xu@gmail.com> <20200619120157.2422429-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=207.211.31.81; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/19 01:50:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -13 X-Spam_score: -1.4 X-Spam_bar: - X-Spam_report: (-1.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN 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: kwolf@redhat.com, bharatlkmlkvm@gmail.com, qemu-devel@nongnu.org, Stefan Hajnoczi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Block size checking is the same whether it's a physical, logical, or other block size value. Use a more general name to show this function can be used in other cases too (just like the qdev property that this code originally comes from). Signed-off-by: Stefan Hajnoczi --- util/block-helpers.h | 4 ++-- hw/core/qdev-properties.c | 2 +- util/block-helpers.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/util/block-helpers.h b/util/block-helpers.h index ec6421560c..b53295a529 100644 --- a/util/block-helpers.h +++ b/util/block-helpers.h @@ -13,7 +13,7 @@ #define MAX_BLOCK_SIZE (2 * MiB) #define MAX_BLOCK_SIZE_STR "2 MiB" -void check_logical_block_size(const char *id, const char *name, int64_t value, - Error **errp); +void check_block_size(const char *id, const char *name, int64_t value, + Error **errp); #endif /* BLOCK_HELPERS_H */ diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index 03981feb02..28a6d8b2ee 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -800,7 +800,7 @@ static void set_blocksize(Object *obj, Visitor *v, const char *name, error_propagate(errp, local_err); return; } - check_logical_block_size(dev->id ? : "", name, value, errp); + check_block_size(dev->id ? : "", name, value, errp); if (errp) { return; } diff --git a/util/block-helpers.c b/util/block-helpers.c index 9e68954c46..51d9d02c43 100644 --- a/util/block-helpers.c +++ b/util/block-helpers.c @@ -22,8 +22,8 @@ * * Moved from hw/core/qdev-properties.c:set_blocksize() */ -void check_logical_block_size(const char *id, const char *name, int64_t value, - Error **errp) +void check_block_size(const char *id, const char *name, int64_t value, + Error **errp) { /* value of 0 means "unset" */ if (value && (value < MIN_BLOCK_SIZE || value > MAX_BLOCK_SIZE)) { From patchwork Fri Jun 19 12:01:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 11614027 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3466014E3 for ; Fri, 19 Jun 2020 12:06:48 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 0AAEC207FC for ; Fri, 19 Jun 2020 12:06:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="biQYEVTh" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0AAEC207FC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:59294 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jmFnD-00055D-97 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 19 Jun 2020 08:06:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51512) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmFj0-0006Tz-Vl for qemu-devel@nongnu.org; Fri, 19 Jun 2020 08:02:26 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:25964 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jmFiz-0006iJ-AJ for qemu-devel@nongnu.org; Fri, 19 Jun 2020 08:02:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592568144; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=56JOwKR/P0lQLHwY/SoohBFH+hJsKtQ2Z3JzQYThtgI=; b=biQYEVThkjvmVKChM4a+3H3wjOgYB6E6By5oupihYyKOyTstiCj5ETc0Bj8LYbghjCWjgv wIhqqA/Ti9x3p2OhUzUF8CxANI6TU5znOpvrppFRUWS17NsynK1bZZFuB6gqN6dEMNg2QO de24g2ZLhUmgWqLtAkRBK9JgOo72Wsk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-231-pObxXxAlMwuBbptuzeNibA-1; Fri, 19 Jun 2020 08:02:23 -0400 X-MC-Unique: pObxXxAlMwuBbptuzeNibA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E8C92105250A; Fri, 19 Jun 2020 12:02:21 +0000 (UTC) Received: from localhost (ovpn-113-212.ams2.redhat.com [10.36.113.212]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9F9AB60BF4; Fri, 19 Jun 2020 12:02:18 +0000 (UTC) From: Stefan Hajnoczi To: Coiby Xu Subject: [PATCH 4/6] block-helpers: use local_err in case errp is NULL Date: Fri, 19 Jun 2020 13:01:55 +0100 Message-Id: <20200619120157.2422429-4-stefanha@redhat.com> In-Reply-To: <20200619120157.2422429-1-stefanha@redhat.com> References: <20200614183907.514282-4-coiby.xu@gmail.com> <20200619120157.2422429-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=207.211.31.120; envelope-from=stefanha@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/19 03:15:03 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -13 X-Spam_score: -1.4 X-Spam_bar: - X-Spam_report: (-1.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN 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: kwolf@redhat.com, bharatlkmlkvm@gmail.com, qemu-devel@nongnu.org, Stefan Hajnoczi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" If we use errp then we won't know when check_block_size() fails when errp is NULL. The purpose of local_err is to detect an error has occurred even if the caller doesn't care about the specific error and has passed a NULL errp. Signed-off-by: Stefan Hajnoczi --- hw/core/qdev-properties.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index 28a6d8b2ee..0a651c7d32 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -800,8 +800,9 @@ static void set_blocksize(Object *obj, Visitor *v, const char *name, error_propagate(errp, local_err); return; } - check_block_size(dev->id ? : "", name, value, errp); - if (errp) { + check_block_size(dev->id ? : "", name, value, &local_err); + if (local_err) { + error_propagate(errp, local_err); return; } *ptr = value; From patchwork Fri Jun 19 12:01:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 11614037 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C7FA31392 for ; Fri, 19 Jun 2020 12:10:48 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 9F14720720 for ; Fri, 19 Jun 2020 12:10:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="O31z4MYl" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9F14720720 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:44070 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jmFr5-0002Pq-V4 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 19 Jun 2020 08:10:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51534) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmFj6-0006hh-Ar for qemu-devel@nongnu.org; Fri, 19 Jun 2020 08:02:32 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:21458 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jmFj1-0006iS-Dp for qemu-devel@nongnu.org; Fri, 19 Jun 2020 08:02:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592568146; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SPgrR4R9Oo9/YK4V8AYXaJYDMLtJ1EvUmM3yk6JzvC0=; b=O31z4MYloWWrgUpGnakrIgFpMN/BvsJxBoHX2F1EY/gBUemjnvPEAH8J4ulYmLUpoeSte5 lqCQ1tnu13ADN3q5vTXFPkhpEuPNkhuZcA/nANsd9skl6yJQJABAK9WaiyFwXdXhkciNN4 TDSvifAzDyNKrISBKzEhKpDp2k19/mg= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-470-zQKLk9gzNlCluKMkOsxbkg-1; Fri, 19 Jun 2020 08:02:24 -0400 X-MC-Unique: zQKLk9gzNlCluKMkOsxbkg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C2ECE1005512; Fri, 19 Jun 2020 12:02:23 +0000 (UTC) Received: from localhost (ovpn-113-212.ams2.redhat.com [10.36.113.212]) by smtp.corp.redhat.com (Postfix) with ESMTP id 58EF27C1EC; Fri, 19 Jun 2020 12:02:23 +0000 (UTC) From: Stefan Hajnoczi To: Coiby Xu Subject: [PATCH 5/6] block-helpers: keep the copyright line from the original file Date: Fri, 19 Jun 2020 13:01:56 +0100 Message-Id: <20200619120157.2422429-5-stefanha@redhat.com> In-Reply-To: <20200619120157.2422429-1-stefanha@redhat.com> References: <20200614183907.514282-4-coiby.xu@gmail.com> <20200619120157.2422429-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=205.139.110.120; envelope-from=stefanha@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/19 05:19:18 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -13 X-Spam_score: -1.4 X-Spam_bar: - X-Spam_report: (-1.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN 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: kwolf@redhat.com, bharatlkmlkvm@gmail.com, qemu-devel@nongnu.org, Stefan Hajnoczi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" The check_block_size() code comes from hw/core/qdev-properties.c. Keep the copyright. Signed-off-by: Stefan Hajnoczi --- util/block-helpers.c | 1 + 1 file changed, 1 insertion(+) diff --git a/util/block-helpers.c b/util/block-helpers.c index 51d9d02c43..9d12368032 100644 --- a/util/block-helpers.c +++ b/util/block-helpers.c @@ -1,6 +1,7 @@ /* * Block utility functions * + * Copyright IBM, Corp. 2011 * Copyright (c) 2020 Coiby Xu * * This work is licensed under the terms of the GNU GPL, version 2 or later.