From: "Daniel P. Berrange" <berrange(a)redhat.com>
Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
docs/formatdomain.html.in | 26 ++++++++++
docs/schemas/domaincommon.rng | 12 +++++
src/conf/domain_conf.c | 78 ++++++++++++++++++++++++++++
src/conf/domain_conf.h | 7 +++
tests/domainschemadata/domain-lxc-simple.xml | 3 ++
5 files changed, 126 insertions(+)
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index cf382e8..3e7ab65 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -716,6 +716,32 @@
</dl>
+ <h3><a name="resPartition">Resource
partitioning</a></h3>
+
+ <p>
+ Hypervisors may allow for virtual machines to be placed into
+ resource partitions, potentially with nesting of said partitions.
+ The <code>resource</code> element groups together configuration
+ related to resource partitioning. It currently supports a child
+ element <code>partition</code> whose content defines the path
+ of the resource partition in which to place the domain. If no
+ partition is listed, then the domain will be placed in a default
+ partition.
+ </p>
+<pre>
+ ...
+ <resource>
+ <partition>/virtualmachines/production</partition>
+ </resource>
+ ...
+</pre>
+
+ <p>
+ Resource partitions are currently supported by the QEMU and
+ LXC drivers, which map partition paths onto cgroups directories,
+ in all mounted controllers. <span class="since">Since
1.0.5</pan>
+ </p>
+
<h3><a name="elementsCPU">CPU model and
topology</a></h3>
<p>
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 63ba7d1..296f8f9 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -537,6 +537,10 @@
<optional>
<ref name="numatune"/>
</optional>
+
+ <optional>
+ <ref name="respartition"/>
+ </optional>
</interleave>
</define>
@@ -680,6 +684,14 @@
</element>
</define>
+ <define name="respartition">
+ <element name="resource">
+ <element name="partition">
+ <ref name="absFilePath"/>
+ </element>
+ </element>
+ </define>
+
<define name="clock">
<optional>
<element name="clock">
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index cc26f21..d44bb5d 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1748,6 +1748,18 @@ virDomainVcpuPinDefArrayFree(virDomainVcpuPinDefPtr *def,
VIR_FREE(def);
}
+
+void
+virDomainResourceDefFree(virDomainResourceDefPtr resource)
+{
+ if (!resource)
+ return;
+
+ VIR_FREE(resource->partition);
+ VIR_FREE(resource);
+}
+
+
void virDomainDefFree(virDomainDefPtr def)
{
unsigned int i;
@@ -1755,6 +1767,8 @@ void virDomainDefFree(virDomainDefPtr def)
if (!def)
return;
+ virDomainResourceDefFree(def->resource);
+
/* hostdevs must be freed before nets (or any future "intelligent
* hostdevs") because the pointer to the hostdev is really
* pointing into the middle of the higher level device's object,
@@ -9378,6 +9392,37 @@ cleanup:
}
+static virDomainResourceDefPtr
+virDomainResourceDefParse(xmlNodePtr node,
+ xmlXPathContextPtr ctxt)
+{
+ virDomainResourceDefPtr def = NULL;
+ xmlNodePtr tmp = ctxt->node;
+
+ ctxt->node = node;
+
+ if (VIR_ALLOC(def) < 0) {
+ virReportOOMError();
+ goto error;
+ }
+
+ /* Find out what type of virtualization to use */
+ if (!(def->partition = virXPathString("string(./partition)", ctxt))) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ "%s", _("missing resource partition
attribute"));
+ goto error;
+ }
+
+ ctxt->node = tmp;
+ return def;
+
+error:
+ ctxt->node = tmp;
+ virDomainResourceDefFree(def);
+ return NULL;
+}
+
+
static virDomainDefPtr
virDomainDefParseXML(virCapsPtr caps,
virDomainXMLConfPtr xmlconf,
@@ -9948,6 +9993,25 @@ virDomainDefParseXML(virCapsPtr caps,
}
VIR_FREE(nodes);
+ /* Extract numatune if exists. */
+ if ((n = virXPathNodeSet("./resource", ctxt, &nodes)) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ "%s", _("cannot extract resource nodes"));
+ goto error;
+ }
+
+ if (n > 1) {
+ virReportError(VIR_ERR_XML_ERROR, "%s",
+ _("only one resource element is supported"));
+ VIR_FREE(nodes);
+ goto error;
+ }
+
+ if (n &&
+ !(def->resource = virDomainResourceDefParse(nodes[0], ctxt)))
+ goto error;
+ VIR_FREE(nodes);
+
if ((n = virXPathNodeSet("./features/*", ctxt, &nodes)) < 0)
goto error;
@@ -14605,6 +14669,17 @@ virDomainIsAllVcpupinInherited(virDomainDefPtr def)
}
}
+
+static void
+virDomainResourceDefFormat(virBufferPtr buf,
+ virDomainResourceDefPtr def)
+{
+ virBufferAddLit(buf, " <resource>\n");
+ virBufferEscapeString(buf, " <partition>%s</partition>\n",
def->partition);
+ virBufferAddLit(buf, " </resource>\n");
+}
+
+
#define DUMPXML_FLAGS \
(VIR_DOMAIN_XML_SECURE | \
VIR_DOMAIN_XML_INACTIVE | \
@@ -14873,6 +14948,9 @@ virDomainDefFormatInternal(virDomainDefPtr def,
virBufferAddLit(buf, " </numatune>\n");
}
+ if (def->resource)
+ virDomainResourceDefFormat(buf, def->resource);
+
if (def->sysinfo)
virDomainSysinfoDefFormat(buf, def->sysinfo);
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index edddf25..b05cd34 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1735,6 +1735,11 @@ struct _virDomainRNGDef {
void virBlkioDeviceWeightArrayClear(virBlkioDeviceWeightPtr deviceWeights,
int ndevices);
+typedef struct _virDomainResourceDef virDomainResourceDef;
+typedef virDomainResourceDef *virDomainResourceDefPtr;
+struct _virDomainResourceDef {
+ char *partition;
+};
/*
* Guest VM main configuration
@@ -1786,6 +1791,7 @@ struct _virDomainDef {
} cputune;
virNumaTuneDef numatune;
+ virDomainResourceDefPtr resource;
/* These 3 are based on virDomainLifeCycleAction enum flags */
int onReboot;
@@ -1976,6 +1982,7 @@ virDomainObjPtr virDomainObjListFindByName(const virDomainObjListPtr
doms,
bool virDomainObjTaint(virDomainObjPtr obj,
enum virDomainTaintFlags taint);
+void virDomainResourceDefFree(virDomainResourceDefPtr resource);
void virDomainGraphicsDefFree(virDomainGraphicsDefPtr def);
void virDomainInputDefFree(virDomainInputDefPtr def);
void virDomainDiskDefFree(virDomainDiskDefPtr def);
diff --git a/tests/domainschemadata/domain-lxc-simple.xml
b/tests/domainschemadata/domain-lxc-simple.xml
index e61434f..56a0117 100644
--- a/tests/domainschemadata/domain-lxc-simple.xml
+++ b/tests/domainschemadata/domain-lxc-simple.xml
@@ -5,6 +5,9 @@
<type>exe</type>
<init>/sh</init>
</os>
+ <resource>
+ <partition>/virtualmachines</partition>
+ </resource>
<memory unit='KiB'>500000</memory>
<devices>
<filesystem type='mount'>
--
1.8.1.4