Re: [libvirt] [PATCHv2 10/15] xml: allow scaled memory on input

2012-03-06 Thread Peter Krempa

On 03/06/2012 01:34 AM, Eric Blake wrote:

Output is still in kibibytes, but input can now be in different
scales for ease of typing.

* src/conf/domain_conf.c (virDomainParseMemory): New helper.
(virDomainDefParseXML): Use it when parsing.
* docs/schemas/domaincommon.rng: Expand XML; rename memoryKBElement
to memoryElement and update callers.
* docs/formatdomain.html.in (elementsMemoryAllocation): Document
scaling.
* tests/qemuxml2argvdata/qemuxml2argv-memtune.xml: Adjust test.
* tests/qemuxml2xmltest.c: Likewise.
* tests/qemuxml2xmloutdata/qemuxml2xmlout-memtune.xml: New file.
---

v2: reuse code introduced earlier in series, add tests

  docs/formatdomain.html.in  |   42 +++--
  docs/schemas/domaincommon.rng  |   23 ++
  src/conf/domain_conf.c |   93 +++
  tests/qemuxml2argvdata/qemuxml2argv-memtune.xml|6 +-
  .../qemuxml2xmloutdata/qemuxml2xmlout-memtune.xml  |   31 +++
  tests/qemuxml2xmltest.c|2 +-
  6 files changed, 147 insertions(+), 50 deletions(-)
  create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-memtune.xml

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 0855c7f..1e4a990 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -415,8 +415,8 @@
  pre
  lt;domaingt;
...
-lt;memorygt;524288lt;/memorygt;
-lt;currentMemorygt;524288lt;/currentMemorygt;
+lt;memory unit='KiB'gt;524288lt;/memorygt;
+lt;currentMemory unit='KiB'gt;524288lt;/currentMemorygt;
...
  lt;/domaingt;
  /pre
@@ -424,12 +424,30 @@
  dl
dtcodememory/code/dt
ddThe maximum allocation of memory for the guest at boot time.
-The units for this value are kibibytes (i.e. blocks of 1024 bytes)/dd
+The units for this value are determined by the optional
+atttributecodeunit/code, which defaults to KiB
+(kibibytes, 2sup10/sup  or blocks of 1024 bytes).  Valid
+units are b or bytes for bytes, KB for kilobytes
+(10sup3/sup  or 1,000), k or KiB for kibibytes (1024),
+MB for megabytes (10sup6/sup  or 1,000,000), M or MiB
+for mebibytes (2sup20/sup  or 1,048,576), GB for


As in the previous similar sections, I'd explicitly specify that the 
numbers are bytes here.



+gigabytes (10sup9/sup  or 1,000,000,000), G or GiB for
+gibibytes (2sup30/sup  or 1,073,741,824), TB for
+terabytes (10sup12/sup  or 1,000,000,000,000), or T or
+TiB for tebibytes (2sup40/sup  or 1,099,511,627,776).
+However, the value will be rounded up to the nearest kibibyte
+by libvirt, and may be further rounded to the granularity
+supported by the hypervisor.  Some hypervisors also enforce a
+minimum, such as


This patch clears everything I was afraid in 05/15.

ACK,

Peter

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCHv2 10/15] xml: allow scaled memory on input

2012-03-05 Thread Eric Blake
Output is still in kibibytes, but input can now be in different
scales for ease of typing.

* src/conf/domain_conf.c (virDomainParseMemory): New helper.
(virDomainDefParseXML): Use it when parsing.
* docs/schemas/domaincommon.rng: Expand XML; rename memoryKBElement
to memoryElement and update callers.
* docs/formatdomain.html.in (elementsMemoryAllocation): Document
scaling.
* tests/qemuxml2argvdata/qemuxml2argv-memtune.xml: Adjust test.
* tests/qemuxml2xmltest.c: Likewise.
* tests/qemuxml2xmloutdata/qemuxml2xmlout-memtune.xml: New file.
---

v2: reuse code introduced earlier in series, add tests

 docs/formatdomain.html.in  |   42 +++--
 docs/schemas/domaincommon.rng  |   23 ++
 src/conf/domain_conf.c |   93 +++
 tests/qemuxml2argvdata/qemuxml2argv-memtune.xml|6 +-
 .../qemuxml2xmloutdata/qemuxml2xmlout-memtune.xml  |   31 +++
 tests/qemuxml2xmltest.c|2 +-
 6 files changed, 147 insertions(+), 50 deletions(-)
 create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-memtune.xml

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 0855c7f..1e4a990 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -415,8 +415,8 @@
 pre
 lt;domaingt;
   ...
-  lt;memorygt;524288lt;/memorygt;
-  lt;currentMemorygt;524288lt;/currentMemorygt;
+  lt;memory unit='KiB'gt;524288lt;/memorygt;
+  lt;currentMemory unit='KiB'gt;524288lt;/currentMemorygt;
   ...
 lt;/domaingt;
 /pre
@@ -424,12 +424,30 @@
 dl
   dtcodememory/code/dt
   ddThe maximum allocation of memory for the guest at boot time.
-The units for this value are kibibytes (i.e. blocks of 1024 bytes)/dd
+The units for this value are determined by the optional
+atttribute codeunit/code, which defaults to KiB
+(kibibytes, 2sup10/sup or blocks of 1024 bytes).  Valid
+units are b or bytes for bytes, KB for kilobytes
+(10sup3/sup or 1,000), k or KiB for kibibytes (1024),
+MB for megabytes (10sup6/sup or 1,000,000), M or MiB
+for mebibytes (2sup20/sup or 1,048,576), GB for
+gigabytes (10sup9/sup or 1,000,000,000), G or GiB for
+gibibytes (2sup30/sup or 1,073,741,824), TB for
+terabytes (10sup12/sup or 1,000,000,000,000), or T or
+TiB for tebibytes (2sup40/sup or 1,099,511,627,776).
+However, the value will be rounded up to the nearest kibibyte
+by libvirt, and may be further rounded to the granularity
+supported by the hypervisor.  Some hypervisors also enforce a
+minimum, such as
+4000KiB. span class='since'codeunit/code since
+0.9.11/span/dd
   dtcodecurrentMemory/code/dt
   ddThe actual allocation of memory for the guest. This value can
 be less than the maximum allocation, to allow for ballooning
 up the guests memory on the fly. If this is omitted, it defaults
-to the same value as the codememory/code element/dd
+to the same value as the codememory/code element.
+The codeunit/code attribute behaves the same as
+for codememory/code./dd
 /dl


@@ -460,10 +478,10 @@
 lt;domaingt;
   ...
   lt;memtunegt;
-lt;hard_limitgt;1048576lt;/hard_limitgt;
-lt;soft_limitgt;131072lt;/soft_limitgt;
-lt;swap_hard_limitgt;2097152lt;/swap_hard_limitgt;
-lt;min_guaranteegt;65536lt;/min_guaranteegt;
+lt;hard_limit unit='G'gt;1lt;/hard_limitgt;
+lt;soft_limit unit='M'gt;128lt;/soft_limitgt;
+lt;swap_hard_limit unit='G'gt;2lt;/swap_hard_limitgt;
+lt;min_guarantee unit='bytes'gt;67108864lt;/min_guaranteegt;
   lt;/memtunegt;
   ...
 lt;/domaingt;
@@ -477,7 +495,13 @@
 parameters are applied to the QEMU process as a whole. Thus, when
 counting them, one needs to add up guest RAM, guest video RAM, and
 some memory overhead of QEMU itself. The last piece is hard to
-determine so one needs guess and try./dd
+determine so one needs guess and try.  For each tunable, it
+is possible to designate which unit the number is in on
+input, using the same values as
+for codelt;memorygt;/code.  For backwards
+compatibility, output is always in
+KiB.  span class='since'codeunit/code
+since 0.9.11/span/dd
   dtcodehard_limit/code/dt
   dd The optional codehard_limit/code element is the maximum memory
 the guest can use. The units for this value are kibibytes (i.e. blocks
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 99b3861..dfa1d1e 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -412,11 +412,11 @@
   define name=resources
 interleave
   element name=memory
-ref name='memoryKBElement'/
+ref name='scaledInteger'/
   /element
   optional
 element name=currentMemory
-  ref