On 2012年08月20日 14:17, Laine Stump wrote:
We need to be able to pass a flag when (re)defining a network that
says to enact the changes immediately rather than waiting until the
next restart of the network, but the existing virNetworkDefineXML has
no flags arg.
This patch adds a new public API virNetworkDefineXMLFlags that will be
identical to virNetworkDefineXML, but with an added flags arg (which
initially will only accept "0" on the remote end).
---
include/libvirt/libvirt.h.in | 11 ++++++++++
src/driver.h | 5 +++++
src/libvirt.c | 49 +++++++++++++++++++++++++++++++++++++++++++-
src/libvirt_public.syms | 1 +
4 files changed, 65 insertions(+), 1 deletion(-)
diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 91e0a29..70bb594 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -2266,6 +2266,17 @@ virNetworkPtr virNetworkLookupByUUIDString
(virConnectPtr conn,
virNetworkPtr virNetworkCreateXML (virConnectPtr conn,
const char *xmlDesc);
+typedef enum {
+ VIR_NETWORK_DEFINE_NONE = 0, /* default behavior */
+} virNetworkDefineFlags;
+
+/*
+ * Define inactive persistent network with flags
+ */
+virNetworkPtr virNetworkDefineXMLFlags(virConnectPtr conn,
+ const char *xmlDesc,
+ unsigned int flags);
+
/*
* Define inactive persistent network
*/
diff --git a/src/driver.h b/src/driver.h
index aab9766..b25a6ac 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -1072,6 +1072,10 @@ typedef virNetworkPtr
(*virDrvNetworkCreateXML) (virConnectPtr conn,
const char *xmlDesc);
typedef virNetworkPtr
+ (*virDrvNetworkDefineXMLFlags) (virConnectPtr conn,
+ const char *xml,
+ unsigned int flags);
+typedef virNetworkPtr
(*virDrvNetworkDefineXML) (virConnectPtr conn,
const char *xml);
typedef int
@@ -1123,6 +1127,7 @@ struct _virNetworkDriver {
virDrvNetworkLookupByUUID networkLookupByUUID;
virDrvNetworkLookupByName networkLookupByName;
virDrvNetworkCreateXML networkCreateXML;
+ virDrvNetworkDefineXMLFlags networkDefineXMLFlags;
virDrvNetworkDefineXML networkDefineXML;
virDrvNetworkUndefine networkUndefine;
virDrvNetworkCreate networkCreate;
diff --git a/src/libvirt.c b/src/libvirt.c
index 893d380..aa9f101 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -9920,11 +9920,58 @@ error:
}
/**
+ * virNetworkDefineXMLFlags:
+ * @conn: pointer to the hypervisor connection
+ * @xml: the XML description for the network, preferably in UTF-8
+ * @flags: bitwise or of virNetworkDefineFlags (currently must be 0).
+ *
+ * Define a network, but do not create it. This function is
+ * identical to the older virNetworkDefineXML, but with the addition
+ * of the flags argument.
+ *
+ * Returns NULL in case of error, a pointer to the network otherwise
+ */
+virNetworkPtr
+virNetworkDefineXMLFlags(virConnectPtr conn, const char *xml,
+ unsigned int flags)
+{
+ VIR_DEBUG("conn=%p, xml=%s, flags=0x%x", conn, xml, flags);
Indention problem.
+
+ virResetLastError();
+
+ if (!VIR_IS_CONNECT(conn)) {
+ virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__);
+ virDispatchError(NULL);
+ return NULL;
+ }
+ if (conn->flags& VIR_CONNECT_RO) {
+ virLibConnError(VIR_ERR_OPERATION_DENIED, __FUNCTION__);
+ goto error;
+ }
+ virCheckNonNullArgGoto(xml, error);
+
+ if (conn->networkDriver&&
conn->networkDriver->networkDefineXMLFlags) {
+ virNetworkPtr ret;
+ ret = conn->networkDriver->networkDefineXMLFlags(conn, xml, flags);
+ if (!ret)
+ goto error;
+ return ret;
+ }
+
+ virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+ virDispatchError(conn);
+ return NULL;
+}
+
+/**
* virNetworkDefineXML:
* @conn: pointer to the hypervisor connection
* @xml: the XML description for the network, preferably in UTF-8
*
- * Define a network, but does not create it
+ * Define a network, but do not create it. See
+ * virNetworkDefineXMLFlags() for more control.
*
* Returns NULL in case of error, a pointer to the network otherwise
*/
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index e3ba119..c814cb7 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -549,6 +549,7 @@ LIBVIRT_0.10.0 {
virDomainGetHostname;
virConnectRegisterCloseCallback;
virConnectUnregisterCloseCallback;
+ virNetworkDefineXMLFlags;
Conflicts with the atomic APIs, I can rebase if you push first. :-)
ACK.