From nobody Sat Feb 7 22:06:53 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1558627682; cv=none; d=zoho.com; s=zohoarc; b=XxVEHCuKTMtFs4t8SMHGUjkgWBFdfvtheze6d6nlj9jTbdVyXwoMobNUZH5rZHGsmh+Bcvi0HGWaBvIwzdg44UyX+cxG/hk9GxUaAzhsmb0Hz8uwGYHHB8bMk9jAhxnRa7cc2+5rG0aCiOUQ1vqCoTcMWkwdFtRxLsQ1+hsZ3/0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558627682; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=0dui4QrpnVi1snEqt/xiyMg/chxl+2ByA2FCko2tNMM=; b=oDra7oBX/ShzbXrGlwmNqrW0+dwhdKHZFzqq2eH7fSjoZ6KqUt+hGbn/GpSgH3qHhNahPgr8ROsNeL9IlbR1lf7A4sLYw6GhYeoqQ/DIpdU8BlcX2z3wDMkTAxk3h8oWerM4uHOgpVMHXuCZTw6XsSiCvcC7Lecu7WzeRgXYoLE= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1558627682463440.7206490483384; Thu, 23 May 2019 09:08:02 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1DC883092675; Thu, 23 May 2019 16:07:51 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E963C36F9; Thu, 23 May 2019 16:07:44 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 9ED415B424; Thu, 23 May 2019 16:07:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x4NFXMhX006676 for ; Thu, 23 May 2019 11:33:22 -0400 Received: by smtp.corp.redhat.com (Postfix) id BE7507BE7C; Thu, 23 May 2019 15:33:22 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-64.ams2.redhat.com [10.36.112.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8FC4D6134C; Thu, 23 May 2019 15:33:21 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 23 May 2019 16:32:47 +0100 Message-Id: <20190523153302.28526-9-berrange@redhat.com> In-Reply-To: <20190523153302.28526-1-berrange@redhat.com> References: <20190523153302.28526-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Laine Stump Subject: [libvirt] [PATCH v6 08/23] network: convert hook script to take a network port XML X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Thu, 23 May 2019 16:07:56 +0000 (UTC) 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. Reviewed-by: Laine Stump Signed-off-by: Daniel P. Berrang=C3=A9 --- docs/hooks.html.in | 24 +++++++++++------------- src/network/bridge_driver.c | 27 +++++++++++---------------- src/util/virhook.c | 4 ++-- src/util/virhook.h | 4 ++-- 4 files changed, 26 insertions(+), 33 deletions(-) diff --git a/docs/hooks.html.in b/docs/hooks.html.in index 2c4c39b771..7c9d3ef7f3 100644 --- a/docs/hooks.html.in +++ b/docs/hooks.html.in @@ -91,10 +91,8 @@ </network> </hookData> =20 -

In the case of an interface - being plugged/unplugged to/from the network, the network XML will be - followed with the full XML description of the domain containing the - interface that is being plugged/unplugged:

+

In the case of an network port being created / deleted, the network + XML will be followed with the full XML description of the port:

=20
<hookData>
   <network>
@@ -102,11 +100,11 @@
      <uuid>afca425a-2c3a-420c-b2fb-dd7b4950d722</uuid>
      ...
   </network>
-  <domain type=3D'$domain_type' id=3D'$domain_id'>
-     <name>$domain_name</name>
-     <uuid>afca425a-2c3a-420c-b2fb-dd7b4950d722</uuid>
-     ...
-  </domain>
+  <networkport>
+    <uuid>5d744f21-ba4a-4d6e-bdb2-30a35ff3207d</uuid>
+    ...
+    <plug type=3D'direct' dev=3D'ens3' mode=3D'vepa'/>
+  </networkport>
 </hookData>
=20

Please note that this approach is different from other cases such as @@ -296,15 +294,15 @@

/etc/libvirt/hooks/network network_name stopped end -
=
  • Later, when network is started and there's an interface from a domain to be plugged into the network, the hook script is called a= s:
    -
    /etc/libvirt/hooks/network network_name plugged begin -
    +          
    /etc/libvirt/hooks/network network_name port-created begin =
    -
    Please note, that in this case, the script is passed both network = and - domain XMLs on its stdin.
  • + port XMLs on its stdin.
  • When network is updated, the hook script is called as:
    /etc/libvirt/hooks/network network_name updated begin -
  • When the domain from previous case is shutting down, the interfa= ce is unplugged. This leads to another script invocation:
    -
    /etc/libvirt/hooks/network network_name unplugged begin -
    -        And again, as in previous case, both network and domain XMLs are p=
    assed
    +          
    /etc/libvirt/hooks/network network_name port-deleted begin =
    -
    + And again, as in previous case, both network and port XMLs are pas= sed onto script's stdin.
  • =20 diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 615aec7142..95b7a7cce9 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -205,14 +205,13 @@ networkObjFromNetwork(virNetworkPtr net) =20 static int networkRunHook(virNetworkObjPtr obj, - virDomainDefPtr dom, - virDomainNetDefPtr iface, + virNetworkPortDefPtr port, int op, int sub_op) { virNetworkDefPtr def; virBuffer buf =3D VIR_BUFFER_INITIALIZER; - char *xml =3D NULL, *net_xml =3D NULL, *dom_xml =3D NULL; + char *xml =3D NULL; int hookret; int ret =3D -1; =20 @@ -226,11 +225,9 @@ networkRunHook(virNetworkObjPtr obj, =20 virBufferAddLit(&buf, "\n"); virBufferAdjustIndent(&buf, 2); - if (iface && virDomainNetDefFormat(&buf, iface, NULL, 0) < 0) - goto cleanup; if (virNetworkDefFormatBuf(&buf, def, 0) < 0) goto cleanup; - if (dom && virDomainDefFormatInternal(dom, NULL, 0, &buf, NULL) < = 0) + if (port && virNetworkPortDefFormatBuf(&buf, port) < 0) goto cleanup; =20 virBufferAdjustIndent(&buf, -2); @@ -256,8 +253,6 @@ networkRunHook(virNetworkObjPtr obj, cleanup: virBufferFreeAndReset(&buf); VIR_FREE(xml); - VIR_FREE(net_xml); - VIR_FREE(dom_xml); return ret; } =20 @@ -2777,7 +2772,7 @@ networkStartNetwork(virNetworkDriverStatePtr driver, =20 /* 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; @@ -2821,7 +2816,7 @@ networkStartNetwork(virNetworkDriverStatePtr driver, virNetworkObjSetFloorSum(obj, 0); =20 /* 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; @@ -2905,7 +2900,7 @@ networkShutdownNetwork(virNetworkDriverStatePtr drive= r, } =20 /* 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); =20 virNetworkObjSetActive(obj, false); @@ -3881,7 +3876,7 @@ networkUpdate(virNetworkPtr net, } =20 /* 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; =20 @@ -4706,8 +4701,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--; @@ -4901,7 +4896,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) @@ -5053,7 +5048,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, &port->mac, false); =20 diff --git a/src/util/virhook.c b/src/util/virhook.c index 57549ef8e5..84b3954872 100644 --- a/src/util/virhook.c +++ b/src/util/virhook.c @@ -100,8 +100,8 @@ VIR_ENUM_IMPL(virHookNetworkOp, "start", "started", "stopped", - "plugged", - "unplugged", + "port-created", + "port-deleted", "updated", ); =20 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 i= nto 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 ne= twork */ + VIR_HOOK_NETWORK_OP_PORT_DELETED, /* port has been deleted in the ne= twork */ VIR_HOOK_NETWORK_OP_UPDATED, /* network has been updated */ =20 VIR_HOOK_NETWORK_OP_LAST, --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list