From nobody Sun Oct 5 19:25:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1613076362; cv=none; d=zohomail.com; s=zohoarc; b=dwIaF6qvHGkQ8JlXpt5AqSFWhQYIJq35YU1FZm9Ndc48TwuMsbxfFCXSY+P3hkWTjbkXdulc2v5g0Qq0R7196qQdjnOunom3z0W0M0zCu0yDCXtVuIPEeDkZnT4ovR6CRdTWo7XZfbXNfMzgUC4N2NpeDgEitLGr0kYXCZ4J3Xs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613076362; 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=9t4IkoAmXiHcfKk4F3GTc5helKS3pdW0WkOh9WuI2hA=; b=YXN5ZcGvXgOrr0EdP1ACWud7KBmA6YrfzMj8+Asv6n7SGGPDzU0j3DgOPq9cOBmKle7QxIb1xi9pOVPCNh1KFti21m0aohIInD60A1Yc/Kzxt0V0y4i8KPy8OuHqYeTtl1XroCtG3/auFGlEfy6ej2xbBdtuznklK+MFXmWQYQU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 16130763622211012.5046770642597; Thu, 11 Feb 2021 12:46:02 -0800 (PST) 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-553-hF7fw9CFN1KvL1p2KBS6NQ-1; Thu, 11 Feb 2021 15:45:56 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 491F3874981; Thu, 11 Feb 2021 20:45:50 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1AACC62467; Thu, 11 Feb 2021 20:45:50 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id A1F7118095CA; Thu, 11 Feb 2021 20:45:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 11BKil0K024226 for ; Thu, 11 Feb 2021 15:44:47 -0500 Received: by smtp.corp.redhat.com (Postfix) id A615410016F5; Thu, 11 Feb 2021 20:44:47 +0000 (UTC) Received: from blue.redhat.com (ovpn-114-150.phx2.redhat.com [10.3.114.150]) by smtp.corp.redhat.com (Postfix) with ESMTP id 097DD10013D7; Thu, 11 Feb 2021 20:44:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613076359; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=9t4IkoAmXiHcfKk4F3GTc5helKS3pdW0WkOh9WuI2hA=; b=OQAP9RqMualj15AQ2cAY6ywX+qnsb+4leKbSMErLSEKORZ6rOBGavqjziRx2oh/iA6+88V 29eKeZUjmRjaPZSpYtRu5uCzVSHwBtKl2JQ0OoexsXLJFbf5imEk6HNerJJKQG69gmQKDc DB7vb4lKkeL8VEIyDjdoKhhlCfcvYMg= X-MC-Unique: hF7fw9CFN1KvL1p2KBS6NQ-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH v2 4/4] utils: Deprecate inexact fractional suffix sizes Date: Thu, 11 Feb 2021 14:44:38 -0600 Message-Id: <20210211204438.1184395-5-eblake@redhat.com> In-Reply-To: <20210211204438.1184395-1-eblake@redhat.com> References: <20210211204438.1184395-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: vsementsov@virtuozzo.com, qemu-block@nongnu.org, "reviewer:Incompatible changes" , tao3.xu@intel.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The value '1.1k' is inexact; 1126.4 bytes is not possible, so we happen to truncate it to 1126. Our use of fractional sizes is intended for convenience, but when a user specifies a fraction that is not a clean translation to binary, truncating/rounding behind their backs can cause confusion. Better is to deprecate inexact values, which still leaves '1.5k' as valid, but alerts the user to spell out their values as a precise byte number in cases where they are currently being rounded. Note that values like '0.1G' in the testsuite need adjustment as a result. Since qemu_strtosz() does not have an Err** parameter, and plumbing that in would be a much larger task, we instead go with just directly emitting the deprecation warning to stderr. Signed-off-by: Eric Blake --- I'm not a fan of this patch, but am proposing it for discussion purposes. --- docs/system/deprecated.rst | 9 +++++++++ tests/test-cutils.c | 6 +++--- tests/test-keyval.c | 4 ++-- tests/test-qemu-opts.c | 4 ++-- util/cutils.c | 9 +++++++-- 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/docs/system/deprecated.rst b/docs/system/deprecated.rst index 113c2e933f1b..2c9cb849eec5 100644 --- a/docs/system/deprecated.rst +++ b/docs/system/deprecated.rst @@ -154,6 +154,15 @@ Input parameters that take a size value should only us= e a size suffix the value is hexadecimal. That is, '0x20M' is deprecated, and should be written either as '32M' or as '0x2000000'. +inexact sizes via scaled fractions (since 6.0) +'''''''''''''''''''''''''''''''''''''''''''''' + +Input parameters that take a size value should only use a fractional +size (such as '1.5M') that will result in an exact byte value. The +use of inexact values (such as '1.1M') that require truncation or +rounding is deprecated, and you should instead consider writing your +unusual size in bytes (here, '1153433' or '1153434' as desired). + QEMU Machine Protocol (QMP) commands ------------------------------------ diff --git a/tests/test-cutils.c b/tests/test-cutils.c index bad3a6099389..c6c33866277b 100644 --- a/tests/test-cutils.c +++ b/tests/test-cutils.c @@ -2124,11 +2124,11 @@ static void test_qemu_strtosz_float(void) g_assert_cmpint(res, =3D=3D, 1024); g_assert(endptr =3D=3D str + 3); - /* For convenience, we permit values that are not byte-exact */ - str =3D "12.345M"; + /* Fractional values should still be byte-exact */ + str =3D "12.125M"; err =3D qemu_strtosz(str, &endptr, &res); g_assert_cmpint(err, =3D=3D, 0); - g_assert_cmpint(res, =3D=3D, (uint64_t) (12.345 * MiB)); + g_assert_cmpint(res, =3D=3D, (uint64_t) (12.125 * MiB)); g_assert(endptr =3D=3D str + 7); } diff --git a/tests/test-keyval.c b/tests/test-keyval.c index e20c07cf3ea5..7a45c22942e6 100644 --- a/tests/test-keyval.c +++ b/tests/test-keyval.c @@ -525,7 +525,7 @@ static void test_keyval_visit_size(void) visit_free(v); /* Suffixes */ - qdict =3D keyval_parse("sz1=3D8b,sz2=3D1.5k,sz3=3D2M,sz4=3D0.1G,sz5=3D= 16777215T", + qdict =3D keyval_parse("sz1=3D8b,sz2=3D1.5k,sz3=3D2M,sz4=3D0.125G,sz5= =3D16777215T", NULL, NULL, &error_abort); v =3D qobject_input_visitor_new_keyval(QOBJECT(qdict)); qobject_unref(qdict); @@ -537,7 +537,7 @@ static void test_keyval_visit_size(void) visit_type_size(v, "sz3", &sz, &error_abort); g_assert_cmphex(sz, =3D=3D, 2 * MiB); visit_type_size(v, "sz4", &sz, &error_abort); - g_assert_cmphex(sz, =3D=3D, GiB / 10); + g_assert_cmphex(sz, =3D=3D, GiB / 8); visit_type_size(v, "sz5", &sz, &error_abort); g_assert_cmphex(sz, =3D=3D, 16777215ULL * TiB); visit_check_struct(v, &error_abort); diff --git a/tests/test-qemu-opts.c b/tests/test-qemu-opts.c index 6568e31a7229..549e994938fe 100644 --- a/tests/test-qemu-opts.c +++ b/tests/test-qemu-opts.c @@ -720,10 +720,10 @@ static void test_opts_parse_size(void) g_assert_cmphex(qemu_opt_get_size(opts, "size1", 0), =3D=3D, 8); g_assert_cmphex(qemu_opt_get_size(opts, "size2", 0), =3D=3D, 1536); g_assert_cmphex(qemu_opt_get_size(opts, "size3", 0), =3D=3D, 2 * MiB); - opts =3D qemu_opts_parse(&opts_list_02, "size1=3D0.1G,size2=3D16777215= T", + opts =3D qemu_opts_parse(&opts_list_02, "size1=3D0.125G,size2=3D167772= 15T", false, &error_abort); g_assert_cmpuint(opts_count(opts), =3D=3D, 2); - g_assert_cmphex(qemu_opt_get_size(opts, "size1", 0), =3D=3D, GiB / 10); + g_assert_cmphex(qemu_opt_get_size(opts, "size1", 0), =3D=3D, GiB / 8); g_assert_cmphex(qemu_opt_get_size(opts, "size2", 0), =3D=3D, 16777215U= LL * TiB); /* Beyond limit with suffix */ diff --git a/util/cutils.c b/util/cutils.c index 6a8a175e0d71..1154b9de131a 100644 --- a/util/cutils.c +++ b/util/cutils.c @@ -246,12 +246,13 @@ static int64_t suffix_mul(char suffix, int64_t unit) * The size parsing supports the following syntaxes * - 12345 - decimal, scale determined by @default_suffix and @unit * - 12345{bBkKmMgGtTpPeE} - decimal, scale determined by suffix and @unit - * - 12345.678{kKmMgGtTpPeE} - decimal, scale determined by suffix, and - * fractional portion is truncated to byte + * - 12345.678{kKmMgGtTpPeE} - decimal, scale determined by suffix, if + * fractional portion is exact * - 0x7fEE - hexadecimal, unit determined by @default_suffix * * The following cause a deprecation warning, and may be removed in the fu= ture * - 0xabc{kKmMgGtTpP} - hex with scaling suffix + * - 12345.678{kKmMgGtTpPeE} - decimal with inexact fraction that caused t= runcation * * The following are intentionally not supported * - octal, such as 08 @@ -342,6 +343,10 @@ static int do_strtosz(const char *nptr, const char **e= nd, retval =3D -ERANGE; goto out; } + if (mul_required && fraction * mul !=3D (uint64_t) (fraction * mul)) { + warn_report("Using a fractional size that is not an exact byte " + "multiple is deprecated: %s", nptr); + } *result =3D val * mul + (uint64_t) (fraction * mul); retval =3D 0; --=20 2.30.1