]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
LXC: Fix handling of RAM filesystem size units
authorJán Tomko <jtomko@redhat.com>
Wed, 9 Oct 2013 12:17:13 +0000 (14:17 +0200)
committerJán Tomko <jtomko@redhat.com>
Tue, 15 Oct 2013 11:26:55 +0000 (13:26 +0200)
Since 76b644c when the support for RAM filesystems was introduced,
libvirt accepted the following XML:
<source usage='1024' unit='KiB'/>

This was parsed correctly and internally stored in bytes, but it
was formatted as (with an extra 's'):
<source usage='1024' units='KiB'/>
When read again, this was treated as if the units were missing,
meaning libvirt was unable to parse its own XML correctly.

The usage attribute was documented as being in KiB, but it was not
scaled if the unit was missing. Transient domains still worked,
because this was balanced by an extra 'k' in the mount options.

This patch:
Changes the parser to use 'units' instead of 'unit', as the latter
was never documented (fixing persistent domains) and some programs
(libvirt-glib, libvirt-sandbox) already parse the 'units' attribute.

Removes the extra 'k' from the tmpfs mount options, which is needed
because now we parse our own XML correctly.

Changes the default input unit to KiB to match documentation, fixing:
https://bugzilla.redhat.com/show_bug.cgi?id=1015689
(cherry picked from commit 3f029fb5319b9dc9cc2fbf8d1ba4505ee9e4b1e3)

Conflicts:
src/conf/domain_conf.c
src/conf/domain_conf.h - missing format
src/lxc/lxc_container.c - virAsprintf doesn't report OOM errors
tests/lxcxml2xmltest.c - missing format test

docs/formatdomain.html.in
docs/schemas/domaincommon.rng
src/conf/domain_conf.c
src/conf/domain_conf.h
src/lxc/lxc_container.c
tests/domainschematest
tests/lxcxml2xmldata/lxc-filesystem-ram.xml [new file with mode: 0644]
tests/lxcxml2xmloutdata/lxc-filesystem-ram.xml [new file with mode: 0644]
tests/lxcxml2xmltest.c

index 8870e4630a9a62fd90bdc95b059bc106324689d3..eaa8d2d8ee6fa91430782e914b81268e669fb4e2 100644 (file)
         <dd>
           An in-memory filesystem, using memory from the host OS.
           The source element has a single attribute <code>usage</code>
-          which gives the memory usage limit in kibibytes. Only used
+          which gives the memory usage limit in KiB, unless units
+          are specified by the <code>units</code> attribute. Only used
           by LXC driver.
           <span class="since"> (since 0.9.13)</span></dd>
         <dt><code>type='bind'</code></dt>
         <code>name</code> attribute must be used with
         <code>type='template'</code>, and the <code>dir</code> attribute must
         be used with <code>type='mount'</code>. The <code>usage</code> attribute
-        is used with <code>type='ram'</code> to set the memory limit in KB.
+        is used with <code>type='ram'</code> to set the memory limit in KiB,
+        unless units are specified by the <code>units</code> attribute.
       </dd>
 
       <dt><code>target</code></dt>
index 10596dc0c0102b92494ee92dc7d0ea00a7894ef9..38b170e0a5e3b83298eb57846012d21ae0c9dc65 100644 (file)
                 <ref name="unsignedLong"/>
               </attribute>
               <optional>
-                <attribute name='unit'>
+                <attribute name='units'>
                   <ref name='unit'/>
                 </attribute>
               </optional>
index 7e72cfd5ea14a4a571ab1c67f135bd4f7af1a84c..3ec64a94329d13d6e420292b7884b50138b78175 100644 (file)
@@ -5499,7 +5499,7 @@ virDomainFSDefParseXML(xmlNodePtr node,
     char *accessmode = NULL;
     char *wrpolicy = NULL;
     char *usage = NULL;
-    char *unit = NULL;
+    char *units = NULL;
 
     ctxt->node = node;
 
@@ -5557,7 +5557,7 @@ virDomainFSDefParseXML(xmlNodePtr node,
                     source = virXMLPropString(cur, "name");
                 else if (def->type == VIR_DOMAIN_FS_TYPE_RAM) {
                     usage = virXMLPropString(cur, "usage");
-                    unit = virXMLPropString(cur, "unit");
+                    units = virXMLPropString(cur, "units");
                 }
             } else if (!target &&
                        xmlStrEqual(cur->name, BAD_CAST "target")) {
@@ -5615,8 +5615,7 @@ virDomainFSDefParseXML(xmlNodePtr node,
                            usage);
             goto error;
         }
-        if (unit &&
-            virScaleInteger(&def->usage, unit,
+        if (virScaleInteger(&def->usage, units,
                             1024, ULLONG_MAX) < 0)
             goto error;
     }
@@ -5638,7 +5637,7 @@ cleanup:
     VIR_FREE(accessmode);
     VIR_FREE(wrpolicy);
     VIR_FREE(usage);
-    VIR_FREE(unit);
+    VIR_FREE(units);
 
     return def;
 
index 0da85cffc39fcae6888d91b0f3bded0fac368a43..df8a58bd985d6b10adb7d0a2fec72cebf653a0b5 100644 (file)
@@ -822,7 +822,7 @@ struct _virDomainFSDef {
     int fsdriver;
     int accessmode;
     int wrpolicy; /* enum virDomainFSWrpolicy */
-    unsigned long long usage;
+    unsigned long long usage; /* in bytes */
     char *src;
     char *dst;
     bool readonly;
index 972486bb82d1623c196f3372e1a1b7d18362ab75..d4dafa89ae90a8749260fb61a70253e82ef16e3e 100644 (file)
@@ -1282,7 +1282,7 @@ static int lxcContainerMountFSTmpfs(virDomainFSDefPtr fs,
     char *data = NULL;
 
     if (virAsprintf(&data,
-                    "size=%lldk%s", fs->usage, sec_mount_options) < 0) {
+                    "size=%lld%s", fs->usage, sec_mount_options) < 0) {
         virReportOOMError();
         goto cleanup;
     }
index 0e360caae903fff533235c986741d45db8b7bbd3..9ebf0b9a58043aca2b9d908c3643175ecaf2bdc1 100755 (executable)
@@ -7,7 +7,7 @@
 DIRS=""
 DIRS="$DIRS domainschemadata qemuxml2argvdata sexpr2xmldata"
 DIRS="$DIRS xmconfigdata xml2sexprdata qemuxml2xmloutdata "
-DIRS="$DIRS lxcxml2xmldata"
+DIRS="$DIRS lxcxml2xmldata lxcxml2xmloutdata"
 SCHEMA="domain.rng"
 
 check_schema "$DIRS" "$SCHEMA"
diff --git a/tests/lxcxml2xmldata/lxc-filesystem-ram.xml b/tests/lxcxml2xmldata/lxc-filesystem-ram.xml
new file mode 100644 (file)
index 0000000..002fde6
--- /dev/null
@@ -0,0 +1,33 @@
+<domain type='lxc'>
+  <name>demo</name>
+  <uuid>8369f1ac-7e46-e869-4ca5-759d51478066</uuid>
+  <memory unit='KiB'>500000</memory>
+  <currentMemory unit='KiB'>500000</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='x86_64'>exe</type>
+    <init>/bin/sh</init>
+  </os>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <emulator>/usr/libexec/libvirt_lxc</emulator>
+    <filesystem type='ram'>
+        <source usage='1048576'/>
+        <target dir='/mnt/mississippi'/>
+    </filesystem>
+    <filesystem type='ram'>
+        <source usage='1048576' units='bytes'/>
+        <target dir='/mnt/antananarivo'/>
+    </filesystem>
+    <filesystem type='ram'>
+        <source usage='1024' units='KiB'/>
+        <target dir='/mnt/ouagadougou'/>
+    </filesystem>
+    <console type='pty'>
+      <target type='lxc' port='0'/>
+    </console>
+  </devices>
+</domain>
diff --git a/tests/lxcxml2xmloutdata/lxc-filesystem-ram.xml b/tests/lxcxml2xmloutdata/lxc-filesystem-ram.xml
new file mode 100644 (file)
index 0000000..d2369a2
--- /dev/null
@@ -0,0 +1,33 @@
+<domain type='lxc'>
+  <name>demo</name>
+  <uuid>8369f1ac-7e46-e869-4ca5-759d51478066</uuid>
+  <memory unit='KiB'>500000</memory>
+  <currentMemory unit='KiB'>500000</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='x86_64'>exe</type>
+    <init>/bin/sh</init>
+  </os>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <emulator>/usr/libexec/libvirt_lxc</emulator>
+    <filesystem type='ram' accessmode='passthrough'>
+      <source usage='1048576' units='KiB'/>
+      <target dir='/mnt/mississippi'/>
+    </filesystem>
+    <filesystem type='ram' accessmode='passthrough'>
+      <source usage='1024' units='KiB'/>
+      <target dir='/mnt/antananarivo'/>
+    </filesystem>
+    <filesystem type='ram' accessmode='passthrough'>
+      <source usage='1024' units='KiB'/>
+      <target dir='/mnt/ouagadougou'/>
+    </filesystem>
+    <console type='pty'>
+      <target type='lxc' port='0'/>
+    </console>
+  </devices>
+</domain>
index 4870f4282bc26dcf21515b5e529662ae496a5798..8cb9ad9e9ff4c7c370c4e906ad15604c411dec75 100644 (file)
@@ -127,6 +127,7 @@ mymain(void)
 
     DO_TEST("systemd");
     DO_TEST("hostdev");
+    DO_TEST_DIFFERENT("filesystem-ram");
 
     virObjectUnref(caps);
     virObjectUnref(xmlopt);