From nobody Wed May 14 21:42:25 2025 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1516973760698700.101292659145; Fri, 26 Jan 2018 05:36:00 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 39C0A13A52F; Fri, 26 Jan 2018 13:35:59 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8F09A75A11; Fri, 26 Jan 2018 13:35:58 +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 1050318033DA; Fri, 26 Jan 2018 13:35:58 +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 w0QDZoKf025197 for ; Fri, 26 Jan 2018 08:35:50 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4436375A1B; Fri, 26 Jan 2018 13:35:50 +0000 (UTC) Received: from t460.redhat.com (unknown [10.33.36.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id A577475A0E; Fri, 26 Jan 2018 13:35:49 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 26 Jan 2018 13:35:33 +0000 Message-Id: <20180126133537.31883-7-berrange@redhat.com> In-Reply-To: <20180126133537.31883-1-berrange@redhat.com> References: <20180126133537.31883-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 Subject: [libvirt] [PATCH 06/10] interface: allow opening with interface:///system and interface:///session URIs 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 26 Jan 2018 13:35:59 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Allow the possibility of opening a connection to only the interface driver, by defining interface:///system and interface:///session URIs and registering a fake hypervisor driver that supports them. The hypervisor drivers can now directly open a interface driver connection at time of need, instead of having to pass around a virConnectPtr through many functions. This will facilitate the later change to support separate daemons for each driver. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/interface/interface_backend_netcf.c | 98 +++++++++++++++++++++++++++++= +++- src/interface/interface_backend_udev.c | 97 +++++++++++++++++++++++++++++= ++- 2 files changed, 193 insertions(+), 2 deletions(-) diff --git a/src/interface/interface_backend_netcf.c b/src/interface/interf= ace_backend_netcf.c index c7cc07122a..9b04271647 100644 --- a/src/interface/interface_backend_netcf.c +++ b/src/interface/interface_backend_netcf.c @@ -46,6 +46,7 @@ typedef struct { virObjectLockable parent; struct netcf *netcf; + bool privileged; } virNetcfDriverState, *virNetcfDriverStatePtr; =20 static virClassPtr virNetcfDriverStateClass; @@ -78,7 +79,7 @@ virNetcfDriverStateDispose(void *obj) =20 =20 static int -netcfStateInitialize(bool privileged ATTRIBUTE_UNUSED, +netcfStateInitialize(bool privileged, virStateInhibitCallback callback ATTRIBUTE_UNUSED, void *opaque ATTRIBUTE_UNUSED) { @@ -88,6 +89,8 @@ netcfStateInitialize(bool privileged ATTRIBUTE_UNUSED, if (!(driver =3D virObjectLockableNew(virNetcfDriverStateClass))) return -1; =20 + driver->privileged =3D privileged; + /* open netcf */ if (ncf_init(&driver->netcf, NULL) !=3D 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -148,6 +151,80 @@ netcfStateReload(void) } =20 =20 +static virDrvOpenStatus netcfConnectOpen(virConnectPtr conn, + virConnectAuthPtr auth ATTRIBUTE_= UNUSED, + virConfPtr conf ATTRIBUTE_UNUSED, + unsigned int flags) +{ + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + + /* Verify uri was specified */ + if (conn->uri =3D=3D NULL) { + /* Only hypervisor drivers are permitted to auto-open on NULL uri = */ + return VIR_DRV_OPEN_DECLINED; + } else { + if (STRNEQ_NULLABLE(conn->uri->scheme, "interface")) + return VIR_DRV_OPEN_DECLINED; + + /* Leave for remote driver */ + if (conn->uri->server !=3D NULL) + return VIR_DRV_OPEN_DECLINED; + + if (driver =3D=3D NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("interface state driver is not active")); + return VIR_DRV_OPEN_ERROR; + } + + if (driver->privileged) { + if (STRNEQ(conn->uri->path, "/system")) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected interface URI path '%s', try = interface:///system"), + conn->uri->path); + return VIR_DRV_OPEN_ERROR; + } + } else { + if (STRNEQ(conn->uri->path, "/session")) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected interface URI path '%s', try = interface:///session"), + conn->uri->path); + return VIR_DRV_OPEN_ERROR; + } + } + } + + if (virConnectOpenEnsureACL(conn) < 0) + return VIR_DRV_OPEN_ERROR; + + return VIR_DRV_OPEN_SUCCESS; +} + +static int netcfConnectClose(virConnectPtr conn ATTRIBUTE_UNUSED) +{ + return 0; +} + + +static int netcfConnectIsSecure(virConnectPtr conn ATTRIBUTE_UNUSED) +{ + /* Trivially secure, since always inside the daemon */ + return 1; +} + + +static int netcfConnectIsEncrypted(virConnectPtr conn ATTRIBUTE_UNUSED) +{ + /* Not encrypted, but remote driver takes care of that */ + return 0; +} + + +static int netcfConnectIsAlive(virConnectPtr conn ATTRIBUTE_UNUSED) +{ + return 1; +} + + /* * Get a minimal virInterfaceDef containing enough metadata * for access control checks to be performed. Currently @@ -1134,6 +1211,23 @@ static virInterfaceDriver interfaceDriver =3D { #endif /* HAVE_NETCF_TRANSACTIONS */ }; =20 + +static virHypervisorDriver interfaceHypervisorDriver =3D { + .name =3D "interface", + .connectOpen =3D netcfConnectOpen, /* 4.1.0 */ + .connectClose =3D netcfConnectClose, /* 4.1.0 */ + .connectIsEncrypted =3D netcfConnectIsEncrypted, /* 4.1.0 */ + .connectIsSecure =3D netcfConnectIsSecure, /* 4.1.0 */ + .connectIsAlive =3D netcfConnectIsAlive, /* 4.1.0 */ +}; + + +static virConnectDriver interfaceConnectDriver =3D { + .hypervisorDriver =3D &interfaceHypervisorDriver, + .interfaceDriver =3D &interfaceDriver, +}; + + static virStateDriver interfaceStateDriver =3D { .name =3D INTERFACE_DRIVER_NAME, .stateInitialize =3D netcfStateInitialize, @@ -1143,6 +1237,8 @@ static virStateDriver interfaceStateDriver =3D { =20 int netcfIfaceRegister(void) { + if (virRegisterConnectDriver(&interfaceConnectDriver, false) < 0) + return -1; if (virSetSharedInterfaceDriver(&interfaceDriver) < 0) return -1; if (virRegisterStateDriver(&interfaceStateDriver) < 0) diff --git a/src/interface/interface_backend_udev.c b/src/interface/interfa= ce_backend_udev.c index 1cd84060a8..2e8e105ffc 100644 --- a/src/interface/interface_backend_udev.c +++ b/src/interface/interface_backend_udev.c @@ -41,6 +41,7 @@ =20 struct udev_iface_driver { struct udev *udev; + bool privileged; }; =20 typedef enum { @@ -1158,7 +1159,7 @@ udevInterfaceIsActive(virInterfacePtr ifinfo) =20 =20 static int -udevStateInitialize(bool privileged ATTRIBUTE_UNUSED, +udevStateInitialize(bool privileged, virStateInhibitCallback callback ATTRIBUTE_UNUSED, void *opaque ATTRIBUTE_UNUSED) { @@ -1173,6 +1174,7 @@ udevStateInitialize(bool privileged ATTRIBUTE_UNUSED, _("failed to create udev context")); goto cleanup; } + driver->privileged =3D privileged; =20 ret =3D 0; =20 @@ -1193,6 +1195,80 @@ udevStateCleanup(void) } =20 =20 +static virDrvOpenStatus udevConnectOpen(virConnectPtr conn, + virConnectAuthPtr auth ATTRIBUTE_U= NUSED, + virConfPtr conf ATTRIBUTE_UNUSED, + unsigned int flags) +{ + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + + /* Verify uri was specified */ + if (conn->uri =3D=3D NULL) { + /* Only hypervisor drivers are permitted to auto-open on NULL uri = */ + return VIR_DRV_OPEN_DECLINED; + } else { + if (STRNEQ_NULLABLE(conn->uri->scheme, "interface")) + return VIR_DRV_OPEN_DECLINED; + + /* Leave for remote driver */ + if (conn->uri->server !=3D NULL) + return VIR_DRV_OPEN_DECLINED; + + if (driver =3D=3D NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("interface state driver is not active")); + return VIR_DRV_OPEN_ERROR; + } + + if (driver->privileged) { + if (STRNEQ(conn->uri->path, "/system")) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected interface URI path '%s', try = interface:///system"), + conn->uri->path); + return VIR_DRV_OPEN_ERROR; + } + } else { + if (STRNEQ(conn->uri->path, "/session")) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected interface URI path '%s', try = interface:///session"), + conn->uri->path); + return VIR_DRV_OPEN_ERROR; + } + } + } + + if (virConnectOpenEnsureACL(conn) < 0) + return VIR_DRV_OPEN_ERROR; + + return VIR_DRV_OPEN_SUCCESS; +} + +static int udevConnectClose(virConnectPtr conn ATTRIBUTE_UNUSED) +{ + return 0; +} + + +static int udevConnectIsSecure(virConnectPtr conn ATTRIBUTE_UNUSED) +{ + /* Trivially secure, since always inside the daemon */ + return 1; +} + + +static int udevConnectIsEncrypted(virConnectPtr conn ATTRIBUTE_UNUSED) +{ + /* Not encrypted, but remote driver takes care of that */ + return 0; +} + + +static int udevConnectIsAlive(virConnectPtr conn ATTRIBUTE_UNUSED) +{ + return 1; +} + + static virInterfaceDriver udevIfaceDriver =3D { .name =3D "udev", .connectNumOfInterfaces =3D udevConnectNumOfInterfaces, /* 1.0.0 */ @@ -1206,6 +1282,23 @@ static virInterfaceDriver udevIfaceDriver =3D { .interfaceGetXMLDesc =3D udevInterfaceGetXMLDesc, /* 1.0.0 */ }; =20 + +static virHypervisorDriver udevHypervisorDriver =3D { + .name =3D "interface", + .connectOpen =3D udevConnectOpen, /* 4.1.0 */ + .connectClose =3D udevConnectClose, /* 4.1.0 */ + .connectIsEncrypted =3D udevConnectIsEncrypted, /* 4.1.0 */ + .connectIsSecure =3D udevConnectIsSecure, /* 4.1.0 */ + .connectIsAlive =3D udevConnectIsAlive, /* 4.1.0 */ +}; + + +static virConnectDriver udevConnectDriver =3D { + .hypervisorDriver =3D &udevHypervisorDriver, + .interfaceDriver =3D &udevIfaceDriver, +}; + + static virStateDriver interfaceStateDriver =3D { .name =3D "udev", .stateInitialize =3D udevStateInitialize, @@ -1215,6 +1308,8 @@ static virStateDriver interfaceStateDriver =3D { int udevIfaceRegister(void) { + if (virRegisterConnectDriver(&udevConnectDriver, false) < 0) + return -1; if (virSetSharedInterfaceDriver(&udevIfaceDriver) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("failed to register udev interface driver")); --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list