qemu-block
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-block] [PATCH v10 2/9] include: Add a lookup table of sizes


From: Eric Blake
Subject: Re: [Qemu-block] [PATCH v10 2/9] include: Add a lookup table of sizes
Date: Mon, 24 Sep 2018 09:09:40 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.0

On 9/21/18 12:23 PM, Leonid Bloch wrote:
Adding a lookup table for the powers of two, with the appropriate size
prefixes. This is needed when a size has to be stringified, in which
case something like '(1 * KiB)' would become a literal '(1 * (1L << 10))'
string. Powers of two are used very often for sizes, so such a table
will also make it easier and more intuitive to write them.

Would it be better to provide a generic util function that takes an arbitrary runtime value and converts it to a human-readable form?

---
  include/qemu/units.h | 55 ++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 55 insertions(+)

diff --git a/include/qemu/units.h b/include/qemu/units.h
index 692db3fbb2..68a7758650 100644
--- a/include/qemu/units.h
+++ b/include/qemu/units.h
@@ -17,4 +17,59 @@
  #define PiB     (INT64_C(1) << 50)
  #define EiB     (INT64_C(1) << 60)
+#define S_1KiB 1024
+#define S_2KiB                  2048

These look redundant with the earlier macros while still being limited to compile-time situations, whereas a human-readable converter form will be useful not only for printing compile-time constants, but also beneficial for arbitrary user-provided values.

--
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org



reply via email to

[Prev in Thread] Current Thread [Next in Thread]