[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 05/17] utils: Deprecate hex-with-suffix sizes
From: |
Eric Blake |
Subject: |
[PULL 05/17] utils: Deprecate hex-with-suffix sizes |
Date: |
Tue, 9 Mar 2021 09:51:50 -0600 |
Supporting '0x20M' looks odd, particularly since we have a 'B' suffix
that is ambiguous for bytes, as well as a less-frequently-used 'E'
suffix for extremely large exibytes. In practice, people using hex
inputs are specifying values in bytes (and would have written
0x2000000, or possibly relied on default_suffix in the case of
qemu_strtosz_MiB), and the use of scaling suffixes makes the most
sense for inputs in decimal (where the user would write 32M). But
rather than outright dropping support for hex-with-suffix, let's
follow our deprecation policy. Sadly, 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 <eblake@redhat.com>
Message-Id: <20210211204438.1184395-4-eblake@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
---
docs/system/deprecated.rst | 8 ++++++++
util/cutils.c | 10 +++++++++-
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/docs/system/deprecated.rst b/docs/system/deprecated.rst
index cfabe6984677..ecff6bf8c633 100644
--- a/docs/system/deprecated.rst
+++ b/docs/system/deprecated.rst
@@ -166,6 +166,14 @@ Using ``-M kernel-irqchip=off`` with x86 machine types
that include a local
APIC is deprecated. The ``split`` setting is supported, as is using
``-M kernel-irqchip=off`` with the ISA PC machine type.
+hexadecimal sizes with scaling multipliers (since 6.0)
+''''''''''''''''''''''''''''''''''''''''''''''''''''''
+
+Input parameters that take a size value should only use a size suffix
+(such as 'k' or 'M') when the base is written in decimal, and not when
+the value is hexadecimal. That is, '0x20M' is deprecated, and should
+be written either as '32M' or as '0x2000000'.
+
QEMU Machine Protocol (QMP) commands
------------------------------------
diff --git a/util/cutils.c b/util/cutils.c
index 189a184859c0..d89a40a8c325 100644
--- a/util/cutils.c
+++ b/util/cutils.c
@@ -250,6 +250,9 @@ static int64_t suffix_mul(char suffix, int64_t unit)
* fractional portion is truncated to byte
* - 0x7fEE - hexadecimal, unit determined by @default_suffix
*
+ * The following cause a deprecation warning, and may be removed in the future
+ * - 0xabc{kKmMgGtTpP} - hex with scaling suffix
+ *
* The following are intentionally not supported
* - octal, such as 08
* - fractional hex, such as 0x1.8
@@ -272,7 +275,7 @@ static int do_strtosz(const char *nptr, const char **end,
int retval;
const char *endptr, *f;
unsigned char c;
- bool mul_required = false;
+ bool mul_required = false, hex = false;
uint64_t val;
int64_t mul;
double fraction = 0.0;
@@ -298,6 +301,7 @@ static int do_strtosz(const char *nptr, const char **end,
retval = -EINVAL;
goto out;
}
+ hex = true;
} else if (*endptr == '.') {
/*
* Input looks like a fraction. Make sure even 1.k works
@@ -320,6 +324,10 @@ static int do_strtosz(const char *nptr, const char **end,
c = *endptr;
mul = suffix_mul(c, unit);
if (mul > 0) {
+ if (hex) {
+ warn_report("Using a multiplier suffix on hex numbers "
+ "is deprecated: %s", nptr);
+ }
endptr++;
} else {
mul = suffix_mul(default_suffix, unit);
--
2.30.1
- [PULL 00/17] NBD patches through 2021-03-09, Eric Blake, 2021/03/09
- [PULL 02/17] nbd: server: Report holes for raw images, Eric Blake, 2021/03/09
- [PULL 03/17] utils: Enhance testsuite for do_strtosz(), Eric Blake, 2021/03/09
- [PULL 04/17] utils: Improve qemu_strtosz() to have 64 bits of precision, Eric Blake, 2021/03/09
- [PULL 01/17] MAINTAINERS: add Vladimir as co-maintainer of NBD, Eric Blake, 2021/03/09
- [PULL 07/17] blockdev: fix drive_backup_prepare() missed error, Eric Blake, 2021/03/09
- [PULL 06/17] block: check return value of bdrv_open_child and drop error propagation, Eric Blake, 2021/03/09
- [PULL 05/17] utils: Deprecate hex-with-suffix sizes,
Eric Blake <=
- [PULL 12/17] block/qcow2-bitmap: improve qcow2_load_dirty_bitmaps() interface, Eric Blake, 2021/03/09
- [PULL 11/17] block/qcow2: qcow2_get_specific_info(): drop error propagation, Eric Blake, 2021/03/09
- [PULL 13/17] block/qcow2-bitmap: return status from qcow2_store_persistent_dirty_bitmaps, Eric Blake, 2021/03/09
- [PULL 10/17] blockjob: return status from block_job_set_speed(), Eric Blake, 2021/03/09
- [PULL 16/17] block/qed: bdrv_qed_do_open: deal with errp, Eric Blake, 2021/03/09
- [PULL 17/17] block/qcow2: refactor qcow2_update_options_prepare error paths, Eric Blake, 2021/03/09
- [PULL 08/17] block: drop extra error propagation for bdrv_set_backing_hd, Eric Blake, 2021/03/09
- [PULL 14/17] block/qcow2: read_cache_sizes: return status value, Eric Blake, 2021/03/09
- [PULL 09/17] block/mirror: drop extra error propagation in commit_active_start(), Eric Blake, 2021/03/09
- [PULL 15/17] block/qcow2: simplify qcow2_co_invalidate_cache(), Eric Blake, 2021/03/09