[PATCH v3 11/16] Add XML config for resource partitions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "Daniel P. Berrange" <berrange@xxxxxxxxxx>

Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>
---
 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 d400e35..5551187 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>
+  ...
+  &lt;resource&gt;
+    &lt;partition&gt;/virtualmachines/production&lt;/partition&gt;
+  &lt;/resource&gt;
+  ...
+</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 2c31f76..77d020d 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 e00a532..ae1dfd3 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1797,6 +1797,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;
@@ -1804,6 +1816,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,
@@ -9685,6 +9699,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(xmlDocPtr xml,
                      xmlNodePtr root,
@@ -10255,6 +10300,25 @@ virDomainDefParseXML(xmlDocPtr xml,
     }
     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;
 
@@ -14870,6 +14934,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 |                  \
@@ -15138,6 +15213,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 08b8e48..e396e85 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1751,6 +1751,11 @@ struct _virDomainRNGDef {
 void virBlkioDeviceWeightArrayClear(virBlkioDeviceWeightPtr deviceWeights,
                                     int ndevices);
 
+typedef struct _virDomainResourceDef virDomainResourceDef;
+typedef virDomainResourceDef *virDomainResourceDefPtr;
+struct _virDomainResourceDef {
+    char *partition;
+};
 
 /*
  * Guest VM main configuration
@@ -1802,6 +1807,7 @@ struct _virDomainDef {
     } cputune;
 
     virNumaTuneDef numatune;
+    virDomainResourceDefPtr resource;
 
     /* These 3 are based on virDomainLifeCycleAction enum flags */
     int onReboot;
@@ -2018,6 +2024,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

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




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]