[libvirt] [PATCH 0/5] network: define new API virNetworkDefineXMLFlags

I would like to enhance libvirt's network API to allow enacting any changes in definition immediately, as an alternative to the current behavior of saving the changes right away, but not using them until the next time the network is destroyed and re-started. This could easily be handled by a flag passed to virNetworkDefineXML(). Unfortunately, virNetworkDefineXML() was added to libvirt before we came up with the idea of adding a flags arg to every new API (just for things like this). To remedy this, I've effectively duplicated that API with a new API, virNetworkDefineXMLFlags(), which currently behaves identically, but has an extra "flags" argument. At the end of this patch series, it's still not possible to call virNetworkDefineXMLFlags() with anything other than 0 in flags, butt this gets the API in place, and in use by virsh (although with no extra functionality). A later patchset will add a VIR_NETWORK_DEFINE_AFFECT_LIVE flag and the network driver support behind it. (It almost seems like overkill to split this into so many teeny tiny patches, but this is the currently popular/accepted format for API addition patches.)

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); + + 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; } LIBVIRT_0.9.13; # .... define new API here using predicted next version number .... -- 1.7.11.4

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.

On 08/20/2012 12:17 AM, 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).
+++ b/src/libvirt_public.syms @@ -549,6 +549,7 @@ LIBVIRT_0.10.0 { virDomainGetHostname; virConnectRegisterCloseCallback; virConnectUnregisterCloseCallback; + virNetworkDefineXMLFlags;
Your new entry is sorted, but the existing entries aren't :) -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

This is very short, becaquse almost everything is autogenerated. All that's needed are: * src/remote/remote_driver.c: add pointer to autogenerated remoteNetworkDefineXMLFlags to the function table for the remote network driver. * src/remote/remote_protocol.x: add the "args" and "ret" structs (which are nearly identical to those for virNetworkDefineXML), and add one more item to the remote_procedure enum for this function. * src/remote_protocol-struct: updated to match remote_protocol.x --- src/remote/remote_driver.c | 1 + src/remote/remote_protocol.x | 12 +++++++++++- src/remote_protocol-structs | 8 ++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index c4941c5..912233a 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -5383,6 +5383,7 @@ static virNetworkDriver network_driver = { .networkLookupByUUID = remoteNetworkLookupByUUID, /* 0.3.0 */ .networkLookupByName = remoteNetworkLookupByName, /* 0.3.0 */ .networkCreateXML = remoteNetworkCreateXML, /* 0.3.0 */ + .networkDefineXMLFlags = remoteNetworkDefineXMLFlags, /* 0.3.0 */ .networkDefineXML = remoteNetworkDefineXML, /* 0.3.0 */ .networkUndefine = remoteNetworkUndefine, /* 0.3.0 */ .networkCreate = remoteNetworkCreate, /* 0.3.0 */ diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index 200fe75..94fb6cd 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -1280,6 +1280,15 @@ struct remote_network_create_xml_ret { remote_nonnull_network net; }; +struct remote_network_define_xml_flags_args { + remote_nonnull_string xml; + unsigned int flags; +}; + +struct remote_network_define_xml_flags_ret { + remote_nonnull_network net; +}; + struct remote_network_define_xml_args { remote_nonnull_string xml; }; @@ -2854,7 +2863,8 @@ enum remote_procedure { REMOTE_PROC_DOMAIN_LIST_ALL_SNAPSHOTS = 274, /* skipgen skipgen priority:high */ REMOTE_PROC_DOMAIN_SNAPSHOT_LIST_ALL_CHILDREN = 275, /* skipgen skipgen priority:high */ REMOTE_PROC_DOMAIN_EVENT_BALLOON_CHANGE = 276, /* autogen autogen */ - REMOTE_PROC_DOMAIN_GET_HOSTNAME = 277 /* autogen autogen */ + REMOTE_PROC_DOMAIN_GET_HOSTNAME = 277, /* autogen autogen */ + REMOTE_PROC_NETWORK_DEFINE_XML_FLAGS = 278 /* autogen autogen priority:high */ /* * Notice how the entries are grouped in sets of 10 ? diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index 8d09138..693d629 100644 --- a/src/remote_protocol-structs +++ b/src/remote_protocol-structs @@ -930,6 +930,13 @@ struct remote_network_create_xml_args { struct remote_network_create_xml_ret { remote_nonnull_network net; }; +struct remote_network_define_xml_flags_args { + remote_nonnull_string xml; + u_int flags; +}; +struct remote_network_define_xml_flags_ret { + remote_nonnull_network net; +}; struct remote_network_define_xml_args { remote_nonnull_string xml; }; @@ -2259,4 +2266,5 @@ enum remote_procedure { REMOTE_PROC_DOMAIN_SNAPSHOT_LIST_ALL_CHILDREN = 275, REMOTE_PROC_DOMAIN_EVENT_BALLOON_CHANGE = 276, REMOTE_PROC_DOMAIN_GET_HOSTNAME = 277, + REMOTE_PROC_NETWORK_DEFINE_XML_FLAGS = 278, }; -- 1.7.11.4

On 2012年08月20日 14:17, Laine Stump wrote:
This is very short, becaquse almost everything is autogenerated. All that's needed are:
* src/remote/remote_driver.c: add pointer to autogenerated remoteNetworkDefineXMLFlags to the function table for the remote network driver.
* src/remote/remote_protocol.x: add the "args" and "ret" structs (which are nearly identical to those for virNetworkDefineXML), and add one more item to the remote_procedure enum for this function.
* src/remote_protocol-struct: updated to match remote_protocol.x --- src/remote/remote_driver.c | 1 + src/remote/remote_protocol.x | 12 +++++++++++- src/remote_protocol-structs | 8 ++++++++ 3 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index c4941c5..912233a 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -5383,6 +5383,7 @@ static virNetworkDriver network_driver = { .networkLookupByUUID = remoteNetworkLookupByUUID, /* 0.3.0 */ .networkLookupByName = remoteNetworkLookupByName, /* 0.3.0 */ .networkCreateXML = remoteNetworkCreateXML, /* 0.3.0 */ + .networkDefineXMLFlags = remoteNetworkDefineXMLFlags, /* 0.3.0 */
It should be 0.10.0
.networkDefineXML = remoteNetworkDefineXML, /* 0.3.0 */ .networkUndefine = remoteNetworkUndefine, /* 0.3.0 */ .networkCreate = remoteNetworkCreate, /* 0.3.0 */ diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index 200fe75..94fb6cd 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -1280,6 +1280,15 @@ struct remote_network_create_xml_ret { remote_nonnull_network net; };
+struct remote_network_define_xml_flags_args { + remote_nonnull_string xml; + unsigned int flags; +}; + +struct remote_network_define_xml_flags_ret { + remote_nonnull_network net; +}; + struct remote_network_define_xml_args { remote_nonnull_string xml; }; @@ -2854,7 +2863,8 @@ enum remote_procedure { REMOTE_PROC_DOMAIN_LIST_ALL_SNAPSHOTS = 274, /* skipgen skipgen priority:high */ REMOTE_PROC_DOMAIN_SNAPSHOT_LIST_ALL_CHILDREN = 275, /* skipgen skipgen priority:high */ REMOTE_PROC_DOMAIN_EVENT_BALLOON_CHANGE = 276, /* autogen autogen */ - REMOTE_PROC_DOMAIN_GET_HOSTNAME = 277 /* autogen autogen */ + REMOTE_PROC_DOMAIN_GET_HOSTNAME = 277, /* autogen autogen */ + REMOTE_PROC_NETWORK_DEFINE_XML_FLAGS = 278 /* autogen autogen priority:high */
/* * Notice how the entries are grouped in sets of 10 ? diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index 8d09138..693d629 100644 --- a/src/remote_protocol-structs +++ b/src/remote_protocol-structs @@ -930,6 +930,13 @@ struct remote_network_create_xml_args { struct remote_network_create_xml_ret { remote_nonnull_network net; }; +struct remote_network_define_xml_flags_args { + remote_nonnull_string xml; + u_int flags; +}; +struct remote_network_define_xml_flags_ret { + remote_nonnull_network net; +}; struct remote_network_define_xml_args { remote_nonnull_string xml; }; @@ -2259,4 +2266,5 @@ enum remote_procedure { REMOTE_PROC_DOMAIN_SNAPSHOT_LIST_ALL_CHILDREN = 275, REMOTE_PROC_DOMAIN_EVENT_BALLOON_CHANGE = 276, REMOTE_PROC_DOMAIN_GET_HOSTNAME = 277, + REMOTE_PROC_NETWORK_DEFINE_XML_FLAGS = 278, };
ACK with the version fixed.

Just add an entry to the function table, rename the original virNetworkDefineXML to virNetworkDefineXMLFlags (with a check for flags == 0), and add a one line replacement for virNetworkDefineXML that calls virNetworkDefineXMLFlags. --- src/network/bridge_driver.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index bff2d30..e2b569f 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -2339,7 +2339,10 @@ cleanup: return ret; } -static virNetworkPtr networkDefine(virConnectPtr conn, const char *xml) { +static +virNetworkPtr networkDefineXMLFlags(virConnectPtr conn, const char *xml, + unsigned int flags) +{ struct network_driver *driver = conn->networkPrivateData; virNetworkIpDefPtr ipdef, ipv4def = NULL; virNetworkDefPtr def; @@ -2349,6 +2352,8 @@ static virNetworkPtr networkDefine(virConnectPtr conn, const char *xml) { int ii; dnsmasqContext* dctx = NULL; + virCheckFlags(0, NULL); + networkDriverLock(driver); if (!(def = virNetworkDefParseString(xml))) @@ -2426,6 +2431,12 @@ cleanup: return ret; } +static +virNetworkPtr networkDefine(virConnectPtr conn, const char *xml) +{ + return networkDefineXMLFlags(conn, xml, 0); +} + static int networkUndefine(virNetworkPtr net) { struct network_driver *driver = net->conn->networkPrivateData; virNetworkObjPtr network; @@ -2739,6 +2750,7 @@ static virNetworkDriver networkDriver = { .networkLookupByUUID = networkLookupByUUID, /* 0.2.0 */ .networkLookupByName = networkLookupByName, /* 0.2.0 */ .networkCreateXML = networkCreate, /* 0.2.0 */ + .networkDefineXMLFlags = networkDefineXMLFlags, /* 0.10.0 */ .networkDefineXML = networkDefine, /* 0.2.0 */ .networkUndefine = networkUndefine, /* 0.2.0 */ .networkCreate = networkStart, /* 0.2.0 */ -- 1.7.11.4

On 2012年08月20日 14:17, Laine Stump wrote:
Just add an entry to the function table, rename the original virNetworkDefineXML to virNetworkDefineXMLFlags (with a check for flags == 0), and add a one line replacement for virNetworkDefineXML that calls virNetworkDefineXMLFlags. --- src/network/bridge_driver.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index bff2d30..e2b569f 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -2339,7 +2339,10 @@ cleanup: return ret; }
-static virNetworkPtr networkDefine(virConnectPtr conn, const char *xml) { +static +virNetworkPtr networkDefineXMLFlags(virConnectPtr conn, const char *xml, + unsigned int flags) +{ struct network_driver *driver = conn->networkPrivateData; virNetworkIpDefPtr ipdef, ipv4def = NULL; virNetworkDefPtr def; @@ -2349,6 +2352,8 @@ static virNetworkPtr networkDefine(virConnectPtr conn, const char *xml) { int ii; dnsmasqContext* dctx = NULL;
+ virCheckFlags(0, NULL); + networkDriverLock(driver);
if (!(def = virNetworkDefParseString(xml))) @@ -2426,6 +2431,12 @@ cleanup: return ret; }
+static +virNetworkPtr networkDefine(virConnectPtr conn, const char *xml) +{ + return networkDefineXMLFlags(conn, xml, 0); +} + static int networkUndefine(virNetworkPtr net) { struct network_driver *driver = net->conn->networkPrivateData; virNetworkObjPtr network; @@ -2739,6 +2750,7 @@ static virNetworkDriver networkDriver = { .networkLookupByUUID = networkLookupByUUID, /* 0.2.0 */ .networkLookupByName = networkLookupByName, /* 0.2.0 */ .networkCreateXML = networkCreate, /* 0.2.0 */ + .networkDefineXMLFlags = networkDefineXMLFlags, /* 0.10.0 */ .networkDefineXML = networkDefine, /* 0.2.0 */ .networkUndefine = networkUndefine, /* 0.2.0 */ .networkCreate = networkStart, /* 0.2.0 */
ACK

On 08/20/2012 12:17 AM, Laine Stump wrote:
Just add an entry to the function table, rename the original virNetworkDefineXML to virNetworkDefineXMLFlags (with a check for flags == 0), and add a one line replacement for virNetworkDefineXML that calls virNetworkDefineXMLFlags. --- src/network/bridge_driver.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index bff2d30..e2b569f 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -2339,7 +2339,10 @@ cleanup: return ret; }
-static virNetworkPtr networkDefine(virConnectPtr conn, const char *xml) { +static +virNetworkPtr networkDefineXMLFlags(virConnectPtr conn, const char *xml, + unsigned int flags)
Unusual formatting. When using split line declarations, our style is: static virNetworkPtr networkDefineXMLFlags(...) That is, the function name always starts in column 1 in split style. -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

Just add an entry to the function table, rename the original virNetworkDefineXML to virNetworkDefineXMLFlags (with a check for flags == 0), and add a one line replacement for virNetworkDefineXML. --- src/test/test_driver.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index a767e21..e0da9fe 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -3105,12 +3105,17 @@ cleanup: return ret; } -static virNetworkPtr testNetworkDefine(virConnectPtr conn, const char *xml) { +static +virNetworkPtr testNetworkDefineXMLFlags(virConnectPtr conn, const char *xml, + unsigned int flags) +{ testConnPtr privconn = conn->privateData; virNetworkDefPtr def; virNetworkObjPtr net = NULL; virNetworkPtr ret = NULL; + virCheckFlags(0, NULL); + testDriverLock(privconn); if ((def = virNetworkDefParseString(xml)) == NULL) goto cleanup; @@ -3130,6 +3135,12 @@ cleanup: return ret; } +static +virNetworkPtr testNetworkDefine(virConnectPtr conn, const char *xml) +{ + return testNetworkDefineXMLFlags(conn, xml, 0); +} + static int testNetworkUndefine(virNetworkPtr network) { testConnPtr privconn = network->conn->privateData; virNetworkObjPtr privnet; @@ -5616,6 +5627,7 @@ static virNetworkDriver testNetworkDriver = { .networkLookupByUUID = testLookupNetworkByUUID, /* 0.3.2 */ .networkLookupByName = testLookupNetworkByName, /* 0.3.2 */ .networkCreateXML = testNetworkCreate, /* 0.3.2 */ + .networkDefineXMLFlags = testNetworkDefineXMLFlags, /* 0.10.0 */ .networkDefineXML = testNetworkDefine, /* 0.3.2 */ .networkUndefine = testNetworkUndefine, /* 0.3.2 */ .networkCreate = testNetworkStart, /* 0.3.2 */ -- 1.7.11.4

On 2012年08月20日 14:17, Laine Stump wrote:
Just add an entry to the function table, rename the original virNetworkDefineXML to virNetworkDefineXMLFlags (with a check for flags == 0), and add a one line replacement for virNetworkDefineXML. --- src/test/test_driver.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/src/test/test_driver.c b/src/test/test_driver.c index a767e21..e0da9fe 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -3105,12 +3105,17 @@ cleanup: return ret; }
-static virNetworkPtr testNetworkDefine(virConnectPtr conn, const char *xml) { +static +virNetworkPtr testNetworkDefineXMLFlags(virConnectPtr conn, const char *xml, + unsigned int flags) +{ testConnPtr privconn = conn->privateData; virNetworkDefPtr def; virNetworkObjPtr net = NULL; virNetworkPtr ret = NULL;
+ virCheckFlags(0, NULL); + testDriverLock(privconn); if ((def = virNetworkDefParseString(xml)) == NULL) goto cleanup; @@ -3130,6 +3135,12 @@ cleanup: return ret; }
+static +virNetworkPtr testNetworkDefine(virConnectPtr conn, const char *xml) +{ + return testNetworkDefineXMLFlags(conn, xml, 0); +} + static int testNetworkUndefine(virNetworkPtr network) { testConnPtr privconn = network->conn->privateData; virNetworkObjPtr privnet; @@ -5616,6 +5627,7 @@ static virNetworkDriver testNetworkDriver = { .networkLookupByUUID = testLookupNetworkByUUID, /* 0.3.2 */ .networkLookupByName = testLookupNetworkByName, /* 0.3.2 */ .networkCreateXML = testNetworkCreate, /* 0.3.2 */ + .networkDefineXMLFlags = testNetworkDefineXMLFlags, /* 0.10.0 */ .networkDefineXML = testNetworkDefine, /* 0.3.2 */ .networkUndefine = testNetworkUndefine, /* 0.3.2 */ .networkCreate = testNetworkStart, /* 0.3.2 */
ACK

Currently there is no practical difference between this and using the old virNetworkDefinXML API, it just allows using the new API to make sure it's working. Soon there will be a flag defined for the new function (to request changes in re-definitions of existing+active networks take effect immediately), and virsh will add support for that flag. --- tools/virsh-network.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tools/virsh-network.c b/tools/virsh-network.c index 49ec34f..414ca86 100644 --- a/tools/virsh-network.c +++ b/tools/virsh-network.c @@ -181,6 +181,7 @@ cmdNetworkDefine(vshControl *ctl, const vshCmd *cmd) const char *from = NULL; bool ret = true; char *buffer; + unsigned flags = 0; if (!vshConnectionUsability(ctl, ctl->conn)) return false; @@ -191,7 +192,16 @@ cmdNetworkDefine(vshControl *ctl, const vshCmd *cmd) if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) return false; - network = virNetworkDefineXML(ctl->conn, buffer); + network = virNetworkDefineXMLFlags(ctl->conn, buffer, flags); + + if (network == NULL && last_error->code == VIR_ERR_NO_SUPPORT) { + /* fall back to older function that doesn't take flags. note + * that if we want to use flags in the future, we'll have to + * error out here when flags != 0. + */ + network = virNetworkDefineXML(ctl->conn, buffer); + } + VIR_FREE(buffer); if (network != NULL) { -- 1.7.11.4

On 2012年08月20日 14:17, Laine Stump wrote:
Currently there is no practical difference between this and using the old virNetworkDefinXML API, it just allows using the new API to make sure it's working.
Soon there will be a flag defined for the new function (to request changes in re-definitions of existing+active networks take effect immediately), and virsh will add support for that flag. --- tools/virsh-network.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/tools/virsh-network.c b/tools/virsh-network.c index 49ec34f..414ca86 100644 --- a/tools/virsh-network.c +++ b/tools/virsh-network.c @@ -181,6 +181,7 @@ cmdNetworkDefine(vshControl *ctl, const vshCmd *cmd) const char *from = NULL; bool ret = true; char *buffer; + unsigned flags = 0;
if (!vshConnectionUsability(ctl, ctl->conn)) return false; @@ -191,7 +192,16 @@ cmdNetworkDefine(vshControl *ctl, const vshCmd *cmd) if (virFileReadAll(from, VIRSH_MAX_XML_FILE,&buffer)< 0) return false;
- network = virNetworkDefineXML(ctl->conn, buffer); + network = virNetworkDefineXMLFlags(ctl->conn, buffer, flags); + + if (network == NULL&& last_error->code == VIR_ERR_NO_SUPPORT) {
It should reset the error before trying the old API: vshResetLibvirtError();
+ /* fall back to older function that doesn't take flags. note + * that if we want to use flags in the future, we'll have to + * error out here when flags != 0. + */ + network = virNetworkDefineXML(ctl->conn, buffer); + } + VIR_FREE(buffer);
if (network != NULL) {
ACK with the nit fixed (with wondering why not use new API in virsh when the flags is/are supported though). Regards, Osier

On 08/20/2012 06:46 AM, Osier Yang wrote:
On 2012年08月20日 14:17, Laine Stump wrote:
Currently there is no practical difference between this and using the old virNetworkDefinXML API, it just allows using the new API to make sure it's working.
Soon there will be a flag defined for the new function (to request changes in re-definitions of existing+active networks take effect immediately), and virsh will add support for that flag. --- tools/virsh-network.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/tools/virsh-network.c b/tools/virsh-network.c index 49ec34f..414ca86 100644 --- a/tools/virsh-network.c +++ b/tools/virsh-network.c @@ -181,6 +181,7 @@ cmdNetworkDefine(vshControl *ctl, const vshCmd *cmd) const char *from = NULL; bool ret = true; char *buffer; + unsigned flags = 0;
if (!vshConnectionUsability(ctl, ctl->conn)) return false; @@ -191,7 +192,16 @@ cmdNetworkDefine(vshControl *ctl, const vshCmd *cmd) if (virFileReadAll(from, VIRSH_MAX_XML_FILE,&buffer)< 0) return false;
- network = virNetworkDefineXML(ctl->conn, buffer); + network = virNetworkDefineXMLFlags(ctl->conn, buffer, flags); + + if (network == NULL&& last_error->code == VIR_ERR_NO_SUPPORT) {
It should reset the error before trying the old API:
vshResetLibvirtError();
Yep, I missed that. Thanks!
+ /* fall back to older function that doesn't take flags. note + * that if we want to use flags in the future, we'll have to + * error out here when flags != 0. + */ + network = virNetworkDefineXML(ctl->conn, buffer); + } + VIR_FREE(buffer);
if (network != NULL) {
ACK with the nit fixed (with wondering why not use new API in virsh when the flags is/are supported though).
Just a way of assuring that everything is in place and working. :-)

On 08/20/2012 02:17 AM, Laine Stump wrote:
I would like to enhance libvirt's network API to allow enacting any changes in definition immediately, as an alternative to the current behavior of saving the changes right away, but not using them until the next time the network is destroyed and re-started.
This could easily be handled by a flag passed to virNetworkDefineXML(). Unfortunately, virNetworkDefineXML() was added to libvirt before we came up with the idea of adding a flags arg to every new API (just for things like this). To remedy this, I've effectively duplicated that API with a new API, virNetworkDefineXMLFlags(), which currently behaves identically, but has an extra "flags" argument.
danpb has convinced me that it's better not to overload virNetworkDefine in this way, but instead to have a separate API similar to virDomain(Attach|Update|Detach)Device, so I'm withdrawing this patch, and will post a query in a separate thread about these new APIs.
participants (3)
-
Eric Blake
-
Laine Stump
-
Osier Yang