qemu-devel
[Top][All Lists]
Advanced

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

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


From: Leonid Bloch
Subject: Re: [Qemu-devel] [PATCH v9 2/9] include: Add a lookup table of sizes
Date: Fri, 21 Sep 2018 16:43:58 +0300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.0

On 9/21/18 3:17 PM, Alberto Garcia wrote:
On Tue 18 Sep 2018 05:29:16 PM CEST, 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.

I wonder in what cases you want to stringify those literals... if it's
something that you want to show the user you either:

   a) know the value in advance, and then you probably want to show
      "4 GiB" instead of "4294967296 bytes"

Then the value will need to be set in two places at any future change.


   b) don't know the value in advance (it's a variable), but then you
      can't use these macros.

Am I missing anything?

This is needed in some places:

$ ag 'stringify\(DEFAULT_CLUSTER_SIZE\)'
block/parallels.c
99:            .def_value_str = stringify(DEFAULT_CLUSTER_SIZE),

block/vdi.c
988:            .def_value_str = stringify(DEFAULT_CLUSTER_SIZE)

block/qcow2.c
4726:            .def_value_str = stringify(DEFAULT_CLUSTER_SIZE)

The latter causes failure in test case 137 if defined as (64 * KiB).

Of course the values in block/parallels.h and block/vdi.c will need to be changed as well, I'll do it in a separate patch.

Besides resolving the cases with the necessity to stringify, It also creates nice shortcuts for all feasible power-of-two sizes, which are very common.

Leonid.


Berto




reply via email to

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