When (un)plugging an interface into a network, the 'plugged'
and 'unplugged' operations are invoked in the hook script.
The data provided to the script contains the network XML, the
domain XML and the domain interface XML. When we strictly split the
drivers up this will no longer be possible and thus breakage is
unavoidable. The hook scripts are not considered to be covered by the
API guarantee so this is OK.
To avoid existing scripts taking the wrong action, the existing
operations are changed to 'port-created' and 'port-deleted'
instead. These will receive the network XML and the network port
XML.
Signed-off-by: Daniel P. Berrangé <berrange(a)redhat.com>
---
src/network/bridge_driver.c | 27 +++++++++++----------------
src/util/virhook.c | 4 ++--
src/util/virhook.h | 4 ++--
3 files changed, 15 insertions(+), 20 deletions(-)
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index e75c596120..c3875cb68e 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -206,14 +206,13 @@ networkObjFromNetwork(virNetworkPtr net)
static int
networkRunHook(virNetworkObjPtr obj,
- virDomainDefPtr dom,
- virDomainNetDefPtr iface,
+ virNetworkPortDefPtr port,
int op,
int sub_op)
{
virNetworkDefPtr def;
virBuffer buf = VIR_BUFFER_INITIALIZER;
- char *xml = NULL, *net_xml = NULL, *dom_xml = NULL;
+ char *xml = NULL;
int hookret;
int ret = -1;
@@ -227,12 +226,10 @@ networkRunHook(virNetworkObjPtr obj,
virBufferAddLit(&buf, "<hookData>\n");
virBufferAdjustIndent(&buf, 2);
- if (iface && virDomainNetDefFormat(&buf, iface, NULL, 0) < 0)
+ if (port && virNetworkPortDefFormatBuf(&buf, port) < 0)
goto cleanup;
if (virNetworkDefFormatBuf(&buf, def, 0) < 0)
goto cleanup;
- if (dom && virDomainDefFormatInternal(dom, NULL, 0, &buf, NULL) <
0)
- goto cleanup;
virBufferAdjustIndent(&buf, -2);
virBufferAddLit(&buf, "</hookData>");
@@ -257,8 +254,6 @@ networkRunHook(virNetworkObjPtr obj,
cleanup:
virBufferFreeAndReset(&buf);
VIR_FREE(xml);
- VIR_FREE(net_xml);
- VIR_FREE(dom_xml);
return ret;
}
@@ -2847,7 +2842,7 @@ networkStartNetwork(virNetworkDriverStatePtr driver,
/* Run an early hook to set-up missing devices.
* If the script raised an error abort the launch. */
- if (networkRunHook(obj, NULL, NULL,
+ if (networkRunHook(obj, NULL,
VIR_HOOK_NETWORK_OP_START,
VIR_HOOK_SUBOP_BEGIN) < 0)
goto cleanup;
@@ -2889,7 +2884,7 @@ networkStartNetwork(virNetworkDriverStatePtr driver,
}
/* finally we can call the 'started' hook script if any */
- if (networkRunHook(obj, NULL, NULL,
+ if (networkRunHook(obj, NULL,
VIR_HOOK_NETWORK_OP_STARTED,
VIR_HOOK_SUBOP_BEGIN) < 0)
goto cleanup;
@@ -2973,7 +2968,7 @@ networkShutdownNetwork(virNetworkDriverStatePtr driver,
}
/* now that we know it's stopped call the hook if present */
- networkRunHook(obj, NULL, NULL, VIR_HOOK_NETWORK_OP_STOPPED,
+ networkRunHook(obj, NULL, VIR_HOOK_NETWORK_OP_STOPPED,
VIR_HOOK_SUBOP_END);
virNetworkObjSetActive(obj, false);
@@ -3947,7 +3942,7 @@ networkUpdate(virNetworkPtr net,
}
/* call the 'updated' network hook script */
- if (networkRunHook(obj, NULL, NULL, VIR_HOOK_NETWORK_OP_UPDATED,
+ if (networkRunHook(obj, NULL, VIR_HOOK_NETWORK_OP_UPDATED,
VIR_HOOK_SUBOP_BEGIN) < 0)
goto cleanup;
@@ -4768,8 +4763,8 @@ networkAllocateActualDevice(virNetworkPtr net,
if (dev)
dev->connections++;
/* finally we can call the 'plugged' hook script if any */
- if (networkRunHook(obj, dom, iface,
- VIR_HOOK_NETWORK_OP_IFACE_PLUGGED,
+ if (networkRunHook(obj, port,
+ VIR_HOOK_NETWORK_OP_PORT_CREATED,
VIR_HOOK_SUBOP_BEGIN) < 0) {
/* adjust for failure */
netdef->connections--;
@@ -5022,7 +5017,7 @@ networkNotifyActualDevice(virNetworkPtr net,
if (dev)
dev->connections++;
/* finally we can call the 'plugged' hook script if any */
- if (networkRunHook(obj, dom, iface, VIR_HOOK_NETWORK_OP_IFACE_PLUGGED,
+ if (networkRunHook(obj, port, VIR_HOOK_NETWORK_OP_PORT_CREATED,
VIR_HOOK_SUBOP_BEGIN) < 0) {
/* adjust for failure */
if (dev)
@@ -5173,7 +5168,7 @@ networkReleaseActualDevice(virNetworkPtr net,
if (dev)
dev->connections--;
/* finally we can call the 'unplugged' hook script if any */
- networkRunHook(obj, dom, iface, VIR_HOOK_NETWORK_OP_IFACE_UNPLUGGED,
+ networkRunHook(obj, port, VIR_HOOK_NETWORK_OP_PORT_DELETED,
VIR_HOOK_SUBOP_BEGIN);
networkLogAllocation(netdef, dev, &iface->mac, false);
diff --git a/src/util/virhook.c b/src/util/virhook.c
index 2b91603dcf..51a9df3e4e 100644
--- a/src/util/virhook.c
+++ b/src/util/virhook.c
@@ -90,8 +90,8 @@ VIR_ENUM_IMPL(virHookNetworkOp, VIR_HOOK_NETWORK_OP_LAST,
"start",
"started",
"stopped",
- "plugged",
- "unplugged",
+ "port-created",
+ "port-deleted",
"updated")
VIR_ENUM_IMPL(virHookLibxlOp, VIR_HOOK_LIBXL_OP_LAST,
diff --git a/src/util/virhook.h b/src/util/virhook.h
index 034fb8f263..fa188c89e3 100644
--- a/src/util/virhook.h
+++ b/src/util/virhook.h
@@ -79,8 +79,8 @@ typedef enum {
VIR_HOOK_NETWORK_OP_START, /* network is about to start */
VIR_HOOK_NETWORK_OP_STARTED, /* network has start */
VIR_HOOK_NETWORK_OP_STOPPED, /* network has stopped */
- VIR_HOOK_NETWORK_OP_IFACE_PLUGGED, /* an interface has been plugged into the network
*/
- VIR_HOOK_NETWORK_OP_IFACE_UNPLUGGED, /* an interface was unplugged from the
network */
+ VIR_HOOK_NETWORK_OP_PORT_CREATED, /* port has been created in the network */
+ VIR_HOOK_NETWORK_OP_PORT_DELETED, /* port has been deleted in the network */
VIR_HOOK_NETWORK_OP_UPDATED, /* network has been updated */
VIR_HOOK_NETWORK_OP_LAST,
--
2.19.2