[PATCH 1/8] Add new virDomainDefineXMLFlags public API

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

 



The virDomainDefineXML method is one of the few that still lacks
a 'unsigned int flags' parameter. This will be needed for adding
XML validation to this API. virDomainCreateXML fortunately already
has flags.
---
 include/libvirt/libvirt-domain.h |  4 ++++
 src/driver-hypervisor.h          |  5 +++++
 src/libvirt-domain.c             | 48 ++++++++++++++++++++++++++++++++++++++++
 src/libvirt_public.syms          |  5 +++++
 src/qemu/qemu_driver.c           | 10 ++++++++-
 src/remote/remote_driver.c       |  1 +
 src/remote/remote_protocol.x     | 19 +++++++++++++++-
 7 files changed, 90 insertions(+), 2 deletions(-)

diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index 1fac2a3..864c16c 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -1415,6 +1415,10 @@ int                     virDomainMemoryPeek (virDomainPtr dom,
  */
 virDomainPtr            virDomainDefineXML      (virConnectPtr conn,
                                                  const char *xml);
+
+virDomainPtr            virDomainDefineXMLFlags (virConnectPtr conn,
+                                                 const char *xml,
+                                                 unsigned int flags);
 int                     virDomainUndefine       (virDomainPtr domain);
 
 typedef enum {
diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h
index ad66629..f73d40b 100644
--- a/src/driver-hypervisor.h
+++ b/src/driver-hypervisor.h
@@ -314,6 +314,10 @@ typedef int
 typedef virDomainPtr
 (*virDrvDomainDefineXML)(virConnectPtr conn,
                          const char *xml);
+typedef virDomainPtr
+(*virDrvDomainDefineXMLFlags)(virConnectPtr conn,
+                              const char *xml,
+                              unsigned int flags);
 
 typedef int
 (*virDrvDomainUndefine)(virDomainPtr dom);
@@ -1260,6 +1264,7 @@ struct _virHypervisorDriver {
     virDrvDomainCreateWithFlags domainCreateWithFlags;
     virDrvDomainCreateWithFiles domainCreateWithFiles;
     virDrvDomainDefineXML domainDefineXML;
+    virDrvDomainDefineXMLFlags domainDefineXMLFlags;
     virDrvDomainUndefine domainUndefine;
     virDrvDomainUndefineFlags domainUndefineFlags;
     virDrvDomainAttachDevice domainAttachDevice;
diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index 2b0defc..e9d3608 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -6473,6 +6473,54 @@ virDomainDefineXML(virConnectPtr conn, const char *xml)
 
 
 /**
+ * virDomainDefineXMLFlags:
+ * @conn: pointer to the hypervisor connection
+ * @xml: the XML description for the domain, preferably in UTF-8
+ * @flags: bitwise OR of virDomainDefineFlags
+ *
+ * Define a domain, but does not start it.
+ * This definition is persistent, until explicitly undefined with
+ * virDomainUndefine(). A previous definition for this domain would be
+ * overridden if it already exists.
+ *
+ * Some hypervisors may prevent this operation if there is a current
+ * block copy operation on a transient domain with the same id as the
+ * domain being defined; in that case, use virDomainBlockJobAbort() to
+ * stop the block copy first.
+ *
+ * virDomainFree should be used to free the resources after the
+ * domain object is no longer needed.
+ *
+ * Returns NULL in case of error, a pointer to the domain otherwise
+ */
+virDomainPtr
+virDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags)
+{
+    VIR_DEBUG("conn=%p, xml=%s flags=%x", conn, xml, flags);
+
+    virResetLastError();
+
+    virCheckConnectReturn(conn, NULL);
+    virCheckReadOnlyGoto(conn->flags, error);
+    virCheckNonNullArgGoto(xml, error);
+
+    if (conn->driver->domainDefineXMLFlags) {
+        virDomainPtr ret;
+        ret = conn->driver->domainDefineXMLFlags(conn, xml, flags);
+        if (!ret)
+            goto error;
+        return ret;
+    }
+
+    virReportUnsupportedError();
+
+ error:
+    virDispatchError(conn);
+    return NULL;
+}
+
+
+/**
  * virDomainUndefine:
  * @domain: pointer to a defined domain
  *
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index 5f95802..4d9973e 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -684,4 +684,9 @@ LIBVIRT_1.2.9 {
         virNodeAllocPages;
 } LIBVIRT_1.2.8;
 
+LIBVIRT_1.2.11 {
+    global:
+        virDomainDefineXMLFlags;
+} LIBVIRT_1.2.9;
+
 # .... define new API here using predicted next version number ....
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index a84fd47..a877b75 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -6651,7 +6651,7 @@ qemuDomainCreate(virDomainPtr dom)
     return qemuDomainCreateWithFlags(dom, 0);
 }
 
-static virDomainPtr qemuDomainDefineXML(virConnectPtr conn, const char *xml)
+static virDomainPtr qemuDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags)
 {
     virQEMUDriverPtr driver = conn->privateData;
     virDomainDefPtr def = NULL;
@@ -6663,6 +6663,8 @@ static virDomainPtr qemuDomainDefineXML(virConnectPtr conn, const char *xml)
     virQEMUDriverConfigPtr cfg;
     virCapsPtr caps = NULL;
 
+    virCheckFlags(0, NULL);
+
     cfg = virQEMUDriverGetConfig(driver);
 
     if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
@@ -6745,6 +6747,11 @@ static virDomainPtr qemuDomainDefineXML(virConnectPtr conn, const char *xml)
     return dom;
 }
 
+static virDomainPtr qemuDomainDefineXML(virConnectPtr conn, const char *xml)
+{
+    return qemuDomainDefineXMLFlags(conn, xml, 0);
+}
+
 static int
 qemuDomainUndefineFlags(virDomainPtr dom,
                         unsigned int flags)
@@ -18838,6 +18845,7 @@ static virHypervisorDriver qemuDriver = {
     .domainCreate = qemuDomainCreate, /* 0.2.0 */
     .domainCreateWithFlags = qemuDomainCreateWithFlags, /* 0.8.2 */
     .domainDefineXML = qemuDomainDefineXML, /* 0.2.0 */
+    .domainDefineXMLFlags = qemuDomainDefineXMLFlags, /* 1.2.11 */
     .domainUndefine = qemuDomainUndefine, /* 0.2.0 */
     .domainUndefineFlags = qemuDomainUndefineFlags, /* 0.9.4 */
     .domainAttachDevice = qemuDomainAttachDevice, /* 0.4.1 */
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 04e5360..c8e4d06 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -8038,6 +8038,7 @@ static virHypervisorDriver hypervisor_driver = {
     .domainCreateWithFlags = remoteDomainCreateWithFlags, /* 0.8.2 */
     .domainCreateWithFiles = remoteDomainCreateWithFiles, /* 1.1.1 */
     .domainDefineXML = remoteDomainDefineXML, /* 0.3.0 */
+    .domainDefineXMLFlags = remoteDomainDefineXMLFlags, /* 1.2.11 */
     .domainUndefine = remoteDomainUndefine, /* 0.3.0 */
     .domainUndefineFlags = remoteDomainUndefineFlags, /* 0.9.4 */
     .domainAttachDevice = remoteDomainAttachDevice, /* 0.3.0 */
diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
index ebf4530..6a7d3e0 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -1056,6 +1056,15 @@ struct remote_domain_define_xml_ret {
     remote_nonnull_domain dom;
 };
 
+struct remote_domain_define_xml_flags_args {
+    remote_nonnull_string xml;
+    unsigned int flags;
+};
+
+struct remote_domain_define_xml_flags_ret {
+    remote_nonnull_domain dom;
+};
+
 struct remote_domain_undefine_args {
     remote_nonnull_domain dom;
 };
@@ -5506,5 +5515,13 @@ enum remote_procedure {
      * @generate: none
      * @acl: connect:write
      */
-    REMOTE_PROC_NODE_ALLOC_PAGES = 347
+    REMOTE_PROC_NODE_ALLOC_PAGES = 347,
+
+    /**
+     * @generate: both
+     * @priority: high
+     * @acl: domain:write
+     * @acl: domain:save
+     */
+    REMOTE_PROC_DOMAIN_DEFINE_XML_FLAGS = 348
 };
-- 
2.1.0

--
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]