|
|
43fe83 |
From 2109b3f2a7cfd9abf1ae17905508abdc1b492532 Mon Sep 17 00:00:00 2001
|
|
|
43fe83 |
Message-Id: <2109b3f2a7cfd9abf1ae17905508abdc1b492532.1381871412.git.jdenemar@redhat.com>
|
|
|
43fe83 |
From: =?UTF-8?q?J=C3=A1n=20Tomko?= <jtomko@redhat.com>
|
|
|
43fe83 |
Date: Wed, 9 Oct 2013 17:49:36 +0200
|
|
|
43fe83 |
Subject: [PATCH] LXC: Fix handling of RAM filesystem size units
|
|
|
43fe83 |
|
|
|
43fe83 |
Since 76b644c when the support for RAM filesystems was introduced,
|
|
|
43fe83 |
libvirt accepted the following XML:
|
|
|
43fe83 |
<source usage='1024' unit='KiB'/>
|
|
|
43fe83 |
|
|
|
43fe83 |
This was parsed correctly and internally stored in bytes, but it
|
|
|
43fe83 |
was formatted as (with an extra 's'):
|
|
|
43fe83 |
<source usage='1024' units='KiB'/>
|
|
|
43fe83 |
When read again, this was treated as if the units were missing,
|
|
|
43fe83 |
meaning libvirt was unable to parse its own XML correctly.
|
|
|
43fe83 |
|
|
|
43fe83 |
The usage attribute was documented as being in KiB, but it was not
|
|
|
43fe83 |
scaled if the unit was missing. Transient domains still worked,
|
|
|
43fe83 |
because this was balanced by an extra 'k' in the mount options.
|
|
|
43fe83 |
|
|
|
43fe83 |
This patch:
|
|
|
43fe83 |
Changes the parser to use 'units' instead of 'unit', as the latter
|
|
|
43fe83 |
was never documented (fixing persistent domains) and some programs
|
|
|
43fe83 |
(libvirt-glib, libvirt-sandbox) already parse the 'units' attribute.
|
|
|
43fe83 |
|
|
|
43fe83 |
Removes the extra 'k' from the tmpfs mount options, which is needed
|
|
|
43fe83 |
because now we parse our own XML correctly.
|
|
|
43fe83 |
|
|
|
43fe83 |
Changes the default input unit to KiB to match documentation, fixing:
|
|
|
43fe83 |
https://bugzilla.redhat.com/show_bug.cgi?id=1015689
|
|
|
43fe83 |
(cherry picked from commit 3f029fb5319b9dc9cc2fbf8d1ba4505ee9e4b1e3)
|
|
|
43fe83 |
|
|
|
43fe83 |
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
|
|
|
43fe83 |
---
|
|
|
43fe83 |
docs/formatdomain.html.in | 6 +++--
|
|
|
43fe83 |
docs/schemas/domaincommon.rng | 2 +-
|
|
|
43fe83 |
src/conf/domain_conf.c | 9 ++++---
|
|
|
43fe83 |
src/conf/domain_conf.h | 2 +-
|
|
|
43fe83 |
src/lxc/lxc_container.c | 2 +-
|
|
|
43fe83 |
tests/domainschematest | 2 +-
|
|
|
43fe83 |
tests/lxcxml2xmldata/lxc-filesystem-ram.xml | 33 ++++++++++++++++++++++++++
|
|
|
43fe83 |
tests/lxcxml2xmloutdata/lxc-filesystem-ram.xml | 33 ++++++++++++++++++++++++++
|
|
|
43fe83 |
tests/lxcxml2xmltest.c | 1 +
|
|
|
43fe83 |
9 files changed, 79 insertions(+), 11 deletions(-)
|
|
|
43fe83 |
create mode 100644 tests/lxcxml2xmldata/lxc-filesystem-ram.xml
|
|
|
43fe83 |
create mode 100644 tests/lxcxml2xmloutdata/lxc-filesystem-ram.xml
|
|
|
43fe83 |
|
|
|
43fe83 |
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
|
|
|
43fe83 |
index 4308dbe..4fecdee 100644
|
|
|
43fe83 |
--- a/docs/formatdomain.html.in
|
|
|
43fe83 |
+++ b/docs/formatdomain.html.in
|
|
|
43fe83 |
@@ -2169,7 +2169,8 @@
|
|
|
43fe83 |
|
|
|
43fe83 |
An in-memory filesystem, using memory from the host OS.
|
|
|
43fe83 |
The source element has a single attribute usage
|
|
|
43fe83 |
- which gives the memory usage limit in kibibytes. Only used
|
|
|
43fe83 |
+ which gives the memory usage limit in KiB, unless units
|
|
|
43fe83 |
+ are specified by the units attribute. Only used
|
|
|
43fe83 |
by LXC driver.
|
|
|
43fe83 |
(since 0.9.13)
|
|
|
43fe83 |
type='bind'
|
|
|
43fe83 |
@@ -2235,7 +2236,8 @@
|
|
|
43fe83 |
name attribute must be used with
|
|
|
43fe83 |
type='template' , and the dir attribute must
|
|
|
43fe83 |
be used with type='mount' . The usage attribute
|
|
|
43fe83 |
- is used with type='ram' to set the memory limit in KB.
|
|
|
43fe83 |
+ is used with type='ram' to set the memory limit in KiB,
|
|
|
43fe83 |
+ unless units are specified by the units attribute.
|
|
|
43fe83 |
|
|
|
43fe83 |
|
|
|
43fe83 |
target
|
|
|
43fe83 |
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
|
|
|
43fe83 |
index 838f657..5540745 100644
|
|
|
43fe83 |
--- a/docs/schemas/domaincommon.rng
|
|
|
43fe83 |
+++ b/docs/schemas/domaincommon.rng
|
|
|
43fe83 |
@@ -1681,7 +1681,7 @@
|
|
|
43fe83 |
<ref name="unsignedLong"/>
|
|
|
43fe83 |
</attribute>
|
|
|
43fe83 |
<optional>
|
|
|
43fe83 |
- <attribute name='unit'>
|
|
|
43fe83 |
+ <attribute name='units'>
|
|
|
43fe83 |
<ref name='unit'/>
|
|
|
43fe83 |
</attribute>
|
|
|
43fe83 |
</optional>
|
|
|
43fe83 |
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
|
|
|
43fe83 |
index bca2151..dea8130 100644
|
|
|
43fe83 |
--- a/src/conf/domain_conf.c
|
|
|
43fe83 |
+++ b/src/conf/domain_conf.c
|
|
|
43fe83 |
@@ -5862,7 +5862,7 @@ virDomainFSDefParseXML(xmlNodePtr node,
|
|
|
43fe83 |
char *accessmode = NULL;
|
|
|
43fe83 |
char *wrpolicy = NULL;
|
|
|
43fe83 |
char *usage = NULL;
|
|
|
43fe83 |
- char *unit = NULL;
|
|
|
43fe83 |
+ char *units = NULL;
|
|
|
43fe83 |
|
|
|
43fe83 |
ctxt->node = node;
|
|
|
43fe83 |
|
|
|
43fe83 |
@@ -5918,7 +5918,7 @@ virDomainFSDefParseXML(xmlNodePtr node,
|
|
|
43fe83 |
source = virXMLPropString(cur, "name");
|
|
|
43fe83 |
else if (def->type == VIR_DOMAIN_FS_TYPE_RAM) {
|
|
|
43fe83 |
usage = virXMLPropString(cur, "usage");
|
|
|
43fe83 |
- unit = virXMLPropString(cur, "unit");
|
|
|
43fe83 |
+ units = virXMLPropString(cur, "units");
|
|
|
43fe83 |
}
|
|
|
43fe83 |
} else if (!target &&
|
|
|
43fe83 |
xmlStrEqual(cur->name, BAD_CAST "target")) {
|
|
|
43fe83 |
@@ -5988,8 +5988,7 @@ virDomainFSDefParseXML(xmlNodePtr node,
|
|
|
43fe83 |
usage);
|
|
|
43fe83 |
goto error;
|
|
|
43fe83 |
}
|
|
|
43fe83 |
- if (unit &&
|
|
|
43fe83 |
- virScaleInteger(&def->usage, unit,
|
|
|
43fe83 |
+ if (virScaleInteger(&def->usage, units,
|
|
|
43fe83 |
1024, ULLONG_MAX) < 0)
|
|
|
43fe83 |
goto error;
|
|
|
43fe83 |
}
|
|
|
43fe83 |
@@ -6011,7 +6010,7 @@ cleanup:
|
|
|
43fe83 |
VIR_FREE(accessmode);
|
|
|
43fe83 |
VIR_FREE(wrpolicy);
|
|
|
43fe83 |
VIR_FREE(usage);
|
|
|
43fe83 |
- VIR_FREE(unit);
|
|
|
43fe83 |
+ VIR_FREE(units);
|
|
|
43fe83 |
VIR_FREE(format);
|
|
|
43fe83 |
|
|
|
43fe83 |
return def;
|
|
|
43fe83 |
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
|
|
|
43fe83 |
index 5d2cb83..5a21576 100644
|
|
|
43fe83 |
--- a/src/conf/domain_conf.h
|
|
|
43fe83 |
+++ b/src/conf/domain_conf.h
|
|
|
43fe83 |
@@ -874,7 +874,7 @@ struct _virDomainFSDef {
|
|
|
43fe83 |
int accessmode; /* enum virDomainFSAccessMode */
|
|
|
43fe83 |
int wrpolicy; /* enum virDomainFSWrpolicy */
|
|
|
43fe83 |
int format; /* enum virStorageFileFormat */
|
|
|
43fe83 |
- unsigned long long usage;
|
|
|
43fe83 |
+ unsigned long long usage; /* in bytes */
|
|
|
43fe83 |
char *src;
|
|
|
43fe83 |
char *dst;
|
|
|
43fe83 |
bool readonly;
|
|
|
43fe83 |
diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
|
|
|
43fe83 |
index f851fcc..43178e2 100644
|
|
|
43fe83 |
--- a/src/lxc/lxc_container.c
|
|
|
43fe83 |
+++ b/src/lxc/lxc_container.c
|
|
|
43fe83 |
@@ -1434,7 +1434,7 @@ static int lxcContainerMountFSTmpfs(virDomainFSDefPtr fs,
|
|
|
43fe83 |
VIR_DEBUG("usage=%lld sec=%s", fs->usage, sec_mount_options);
|
|
|
43fe83 |
|
|
|
43fe83 |
if (virAsprintf(&data,
|
|
|
43fe83 |
- "size=%lldk%s", fs->usage, sec_mount_options) < 0)
|
|
|
43fe83 |
+ "size=%lld%s", fs->usage, sec_mount_options) < 0)
|
|
|
43fe83 |
goto cleanup;
|
|
|
43fe83 |
|
|
|
43fe83 |
if (virFileMakePath(fs->dst) < 0) {
|
|
|
43fe83 |
diff --git a/tests/domainschematest b/tests/domainschematest
|
|
|
43fe83 |
index 0e360ca..9ebf0b9 100755
|
|
|
43fe83 |
--- a/tests/domainschematest
|
|
|
43fe83 |
+++ b/tests/domainschematest
|
|
|
43fe83 |
@@ -7,7 +7,7 @@
|
|
|
43fe83 |
DIRS=""
|
|
|
43fe83 |
DIRS="$DIRS domainschemadata qemuxml2argvdata sexpr2xmldata"
|
|
|
43fe83 |
DIRS="$DIRS xmconfigdata xml2sexprdata qemuxml2xmloutdata "
|
|
|
43fe83 |
-DIRS="$DIRS lxcxml2xmldata"
|
|
|
43fe83 |
+DIRS="$DIRS lxcxml2xmldata lxcxml2xmloutdata"
|
|
|
43fe83 |
SCHEMA="domain.rng"
|
|
|
43fe83 |
|
|
|
43fe83 |
check_schema "$DIRS" "$SCHEMA"
|
|
|
43fe83 |
diff --git a/tests/lxcxml2xmldata/lxc-filesystem-ram.xml b/tests/lxcxml2xmldata/lxc-filesystem-ram.xml
|
|
|
43fe83 |
new file mode 100644
|
|
|
43fe83 |
index 0000000..002fde6
|
|
|
43fe83 |
--- /dev/null
|
|
|
43fe83 |
+++ b/tests/lxcxml2xmldata/lxc-filesystem-ram.xml
|
|
|
43fe83 |
@@ -0,0 +1,33 @@
|
|
|
43fe83 |
+<domain type='lxc'>
|
|
|
43fe83 |
+ <name>demo</name>
|
|
|
43fe83 |
+ <uuid>8369f1ac-7e46-e869-4ca5-759d51478066</uuid>
|
|
|
43fe83 |
+ <memory unit='KiB'>500000</memory>
|
|
|
43fe83 |
+ <currentMemory unit='KiB'>500000</currentMemory>
|
|
|
43fe83 |
+ <vcpu placement='static'>1</vcpu>
|
|
|
43fe83 |
+ <os>
|
|
|
43fe83 |
+ <type arch='x86_64'>exe</type>
|
|
|
43fe83 |
+ <init>/bin/sh</init>
|
|
|
43fe83 |
+ </os>
|
|
|
43fe83 |
+ <clock offset='utc'/>
|
|
|
43fe83 |
+ <on_poweroff>destroy</on_poweroff>
|
|
|
43fe83 |
+ <on_reboot>restart</on_reboot>
|
|
|
43fe83 |
+ <on_crash>destroy</on_crash>
|
|
|
43fe83 |
+ <devices>
|
|
|
43fe83 |
+ <emulator>/usr/libexec/libvirt_lxc</emulator>
|
|
|
43fe83 |
+ <filesystem type='ram'>
|
|
|
43fe83 |
+ <source usage='1048576'/>
|
|
|
43fe83 |
+ <target dir='/mnt/mississippi'/>
|
|
|
43fe83 |
+ </filesystem>
|
|
|
43fe83 |
+ <filesystem type='ram'>
|
|
|
43fe83 |
+ <source usage='1048576' units='bytes'/>
|
|
|
43fe83 |
+ <target dir='/mnt/antananarivo'/>
|
|
|
43fe83 |
+ </filesystem>
|
|
|
43fe83 |
+ <filesystem type='ram'>
|
|
|
43fe83 |
+ <source usage='1024' units='KiB'/>
|
|
|
43fe83 |
+ <target dir='/mnt/ouagadougou'/>
|
|
|
43fe83 |
+ </filesystem>
|
|
|
43fe83 |
+ <console type='pty'>
|
|
|
43fe83 |
+ <target type='lxc' port='0'/>
|
|
|
43fe83 |
+ </console>
|
|
|
43fe83 |
+ </devices>
|
|
|
43fe83 |
+</domain>
|
|
|
43fe83 |
diff --git a/tests/lxcxml2xmloutdata/lxc-filesystem-ram.xml b/tests/lxcxml2xmloutdata/lxc-filesystem-ram.xml
|
|
|
43fe83 |
new file mode 100644
|
|
|
43fe83 |
index 0000000..d2369a2
|
|
|
43fe83 |
--- /dev/null
|
|
|
43fe83 |
+++ b/tests/lxcxml2xmloutdata/lxc-filesystem-ram.xml
|
|
|
43fe83 |
@@ -0,0 +1,33 @@
|
|
|
43fe83 |
+<domain type='lxc'>
|
|
|
43fe83 |
+ <name>demo</name>
|
|
|
43fe83 |
+ <uuid>8369f1ac-7e46-e869-4ca5-759d51478066</uuid>
|
|
|
43fe83 |
+ <memory unit='KiB'>500000</memory>
|
|
|
43fe83 |
+ <currentMemory unit='KiB'>500000</currentMemory>
|
|
|
43fe83 |
+ <vcpu placement='static'>1</vcpu>
|
|
|
43fe83 |
+ <os>
|
|
|
43fe83 |
+ <type arch='x86_64'>exe</type>
|
|
|
43fe83 |
+ <init>/bin/sh</init>
|
|
|
43fe83 |
+ </os>
|
|
|
43fe83 |
+ <clock offset='utc'/>
|
|
|
43fe83 |
+ <on_poweroff>destroy</on_poweroff>
|
|
|
43fe83 |
+ <on_reboot>restart</on_reboot>
|
|
|
43fe83 |
+ <on_crash>destroy</on_crash>
|
|
|
43fe83 |
+ <devices>
|
|
|
43fe83 |
+ <emulator>/usr/libexec/libvirt_lxc</emulator>
|
|
|
43fe83 |
+ <filesystem type='ram' accessmode='passthrough'>
|
|
|
43fe83 |
+ <source usage='1048576' units='KiB'/>
|
|
|
43fe83 |
+ <target dir='/mnt/mississippi'/>
|
|
|
43fe83 |
+ </filesystem>
|
|
|
43fe83 |
+ <filesystem type='ram' accessmode='passthrough'>
|
|
|
43fe83 |
+ <source usage='1024' units='KiB'/>
|
|
|
43fe83 |
+ <target dir='/mnt/antananarivo'/>
|
|
|
43fe83 |
+ </filesystem>
|
|
|
43fe83 |
+ <filesystem type='ram' accessmode='passthrough'>
|
|
|
43fe83 |
+ <source usage='1024' units='KiB'/>
|
|
|
43fe83 |
+ <target dir='/mnt/ouagadougou'/>
|
|
|
43fe83 |
+ </filesystem>
|
|
|
43fe83 |
+ <console type='pty'>
|
|
|
43fe83 |
+ <target type='lxc' port='0'/>
|
|
|
43fe83 |
+ </console>
|
|
|
43fe83 |
+ </devices>
|
|
|
43fe83 |
+</domain>
|
|
|
43fe83 |
diff --git a/tests/lxcxml2xmltest.c b/tests/lxcxml2xmltest.c
|
|
|
43fe83 |
index ca05d29..f8b5959 100644
|
|
|
43fe83 |
--- a/tests/lxcxml2xmltest.c
|
|
|
43fe83 |
+++ b/tests/lxcxml2xmltest.c
|
|
|
43fe83 |
@@ -131,6 +131,7 @@ mymain(void)
|
|
|
43fe83 |
DO_TEST("systemd");
|
|
|
43fe83 |
DO_TEST("hostdev");
|
|
|
43fe83 |
DO_TEST("disk-formats");
|
|
|
43fe83 |
+ DO_TEST_DIFFERENT("filesystem-ram");
|
|
|
43fe83 |
|
|
|
43fe83 |
virObjectUnref(caps);
|
|
|
43fe83 |
virObjectUnref(xmlopt);
|
|
|
43fe83 |
--
|
|
|
43fe83 |
1.8.3.2
|
|
|
43fe83 |
|