From 34ba55e9e2d26eeafa697ed91be743783a6df1cd Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A1n=20Tomko?= Date: Wed, 9 Oct 2013 14:17:13 +0200 Subject: [PATCH] LXC: Fix handling of RAM filesystem size units Since 76b644c when the support for RAM filesystems was introduced, libvirt accepted the following XML: This was parsed correctly and internally stored in bytes, but it was formatted as (with an extra 's'): 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 | 6 ++-- docs/schemas/domaincommon.rng | 2 +- src/conf/domain_conf.c | 9 +++-- src/conf/domain_conf.h | 2 +- src/lxc/lxc_container.c | 2 +- tests/domainschematest | 2 +- tests/lxcxml2xmldata/lxc-filesystem-ram.xml | 33 +++++++++++++++++++ .../lxcxml2xmloutdata/lxc-filesystem-ram.xml | 33 +++++++++++++++++++ tests/lxcxml2xmltest.c | 1 + 9 files changed, 79 insertions(+), 11 deletions(-) create mode 100644 tests/lxcxml2xmldata/lxc-filesystem-ram.xml create mode 100644 tests/lxcxml2xmloutdata/lxc-filesystem-ram.xml diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 8870e4630a..eaa8d2d8ee 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -1925,7 +1925,8 @@
An in-memory filesystem, using memory from the host OS. The source element has a single attribute usage - which gives the memory usage limit in kibibytes. Only used + which gives the memory usage limit in KiB, unless units + are specified by the units attribute. Only used by LXC driver. (since 0.9.13)
type='bind'
@@ -1973,7 +1974,8 @@ name attribute must be used with type='template', and the dir attribute must be used with type='mount'. The usage attribute - is used with type='ram' to set the memory limit in KB. + is used with type='ram' to set the memory limit in KiB, + unless units are specified by the units attribute.
target
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 10596dc0c0..38b170e0a5 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -1610,7 +1610,7 @@ - + diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 7e72cfd5ea..3ec64a9432 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -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; diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 0da85cffc3..df8a58bd98 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -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; diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c index 972486bb82..d4dafa89ae 100644 --- a/src/lxc/lxc_container.c +++ b/src/lxc/lxc_container.c @@ -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; } diff --git a/tests/domainschematest b/tests/domainschematest index 0e360caae9..9ebf0b9a58 100755 --- a/tests/domainschematest +++ b/tests/domainschematest @@ -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 index 0000000000..002fde6ad1 --- /dev/null +++ b/tests/lxcxml2xmldata/lxc-filesystem-ram.xml @@ -0,0 +1,33 @@ + + demo + 8369f1ac-7e46-e869-4ca5-759d51478066 + 500000 + 500000 + 1 + + exe + /bin/sh + + + destroy + restart + destroy + + /usr/libexec/libvirt_lxc + + + + + + + + + + + + + + + + + diff --git a/tests/lxcxml2xmloutdata/lxc-filesystem-ram.xml b/tests/lxcxml2xmloutdata/lxc-filesystem-ram.xml new file mode 100644 index 0000000000..d2369a25d1 --- /dev/null +++ b/tests/lxcxml2xmloutdata/lxc-filesystem-ram.xml @@ -0,0 +1,33 @@ + + demo + 8369f1ac-7e46-e869-4ca5-759d51478066 + 500000 + 500000 + 1 + + exe + /bin/sh + + + destroy + restart + destroy + + /usr/libexec/libvirt_lxc + + + + + + + + + + + + + + + + + diff --git a/tests/lxcxml2xmltest.c b/tests/lxcxml2xmltest.c index 4870f4282b..8cb9ad9e9f 100644 --- a/tests/lxcxml2xmltest.c +++ b/tests/lxcxml2xmltest.c @@ -127,6 +127,7 @@ mymain(void) DO_TEST("systemd"); DO_TEST("hostdev"); + DO_TEST_DIFFERENT("filesystem-ram"); virObjectUnref(caps); virObjectUnref(xmlopt); -- 2.47.2