From nobody Wed May 14 21:45:50 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 1516974245616153.63482360606247; Fri, 26 Jan 2018 05:44:05 -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 95246C0ADB5D; Fri, 26 Jan 2018 13:44:03 +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 658C075A02; Fri, 26 Jan 2018 13:44:03 +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 2C6C818033DC; Fri, 26 Jan 2018 13:44:03 +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 w0QDZpvn025212 for ; Fri, 26 Jan 2018 08:35:51 -0500 Received: by smtp.corp.redhat.com (Postfix) id 7A337649B2; Fri, 26 Jan 2018 13:35:51 +0000 (UTC) Received: from t460.redhat.com (unknown [10.33.36.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id BCEED79160; Fri, 26 Jan 2018 13:35:50 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 26 Jan 2018 13:35:34 +0000 Message-Id: <20180126133537.31883-8-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 07/10] nodedev: allow opening with nodedev:///system and nodedev:///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.31]); Fri, 26 Jan 2018 13:44:04 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Allow the possibility of opening a connection to only the nodedev driver, by defining nodedev:///system and nodedev:///session URIs and registering a fake hypervisor driver that supports them. The hypervisor drivers can now directly open a nodedev 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/node_device/node_device_driver.c | 73 ++++++++++++++++++++++++++++++++= +++- src/node_device/node_device_driver.h | 9 +++++ src/node_device/node_device_hal.c | 18 +++++++++ src/node_device/node_device_udev.c | 19 ++++++++++ 4 files changed, 118 insertions(+), 1 deletion(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 6216a69773..efbe898249 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -47,6 +47,78 @@ =20 virNodeDeviceDriverStatePtr driver; =20 +virDrvOpenStatus nodeConnectOpen(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, "nodedev")) + 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", + _("nodedev 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 nodedev URI path '%s', try no= dedev:///system"), + conn->uri->path); + return VIR_DRV_OPEN_ERROR; + } + } else { + if (STRNEQ(conn->uri->path, "/session")) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected nodedev URI path '%s', try no= dedev:///session"), + conn->uri->path); + return VIR_DRV_OPEN_ERROR; + } + } + } + + if (virConnectOpenEnsureACL(conn) < 0) + return VIR_DRV_OPEN_ERROR; + + return VIR_DRV_OPEN_SUCCESS; +} + +int nodeConnectClose(virConnectPtr conn ATTRIBUTE_UNUSED) +{ + return 0; +} + + +int nodeConnectIsSecure(virConnectPtr conn ATTRIBUTE_UNUSED) +{ + /* Trivially secure, since always inside the daemon */ + return 1; +} + + +int nodeConnectIsEncrypted(virConnectPtr conn ATTRIBUTE_UNUSED) +{ + /* Not encrypted, but remote driver takes care of that */ + return 0; +} + + +int nodeConnectIsAlive(virConnectPtr conn ATTRIBUTE_UNUSED) +{ + return 1; +} =20 static int nodeDeviceUpdateCaps(virNodeDeviceDefPtr def) @@ -661,7 +733,6 @@ nodeConnectNodeDeviceEventDeregisterAny(virConnectPtr c= onn, return ret; } =20 - int nodedevRegister(void) { diff --git a/src/node_device/node_device_driver.h b/src/node_device/node_de= vice_driver.h index 109c717815..83a9449139 100644 --- a/src/node_device/node_device_driver.h +++ b/src/node_device/node_device_driver.h @@ -51,6 +51,15 @@ extern virNodeDeviceDriverStatePtr driver; int nodedevRegister(void); =20 +virDrvOpenStatus nodeConnectOpen(virConnectPtr conn, + virConnectAuthPtr auth, + virConfPtr conf, + unsigned int flags); +int nodeConnectClose(virConnectPtr conn); +int nodeConnectIsSecure(virConnectPtr conn); +int nodeConnectIsEncrypted(virConnectPtr conn); +int nodeConnectIsAlive(virConnectPtr conn); + int nodeNumOfDevices(virConnectPtr conn, const char *cap, diff --git a/src/node_device/node_device_hal.c b/src/node_device/node_devic= e_hal.c index c19e327c96..9cd5bb3eec 100644 --- a/src/node_device/node_device_hal.c +++ b/src/node_device/node_device_hal.c @@ -773,6 +773,22 @@ static virNodeDeviceDriver halNodeDeviceDriver =3D { }; =20 =20 +static virHypervisorDriver halHypervisorDriver =3D { + .name =3D "nodedev", + .connectOpen =3D nodeConnectOpen, /* 4.1.0 */ + .connectClose =3D nodeConnectClose, /* 4.1.0 */ + .connectIsEncrypted =3D nodeConnectIsEncrypted, /* 4.1.0 */ + .connectIsSecure =3D nodeConnectIsSecure, /* 4.1.0 */ + .connectIsAlive =3D nodeConnectIsAlive, /* 4.1.0 */ +}; + + +static virConnectDriver halConnectDriver =3D { + .hypervisorDriver =3D &halHypervisorDriver, + .nodeDeviceDriver =3D &halNodeDeviceDriver, +}; + + static virStateDriver halStateDriver =3D { .name =3D "HAL", .stateInitialize =3D nodeStateInitialize, /* 0.5.0 */ @@ -783,6 +799,8 @@ static virStateDriver halStateDriver =3D { int halNodeRegister(void) { + if (virRegisterConnectDriver(&halConnectDriver, false) < 0) + return -1; if (virSetSharedNodeDeviceDriver(&halNodeDeviceDriver) < 0) return -1; return virRegisterStateDriver(&halStateDriver); diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index e0fca6159e..f7645b6876 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -2065,6 +2065,23 @@ static virNodeDeviceDriver udevNodeDeviceDriver =3D { .nodeDeviceDestroy =3D nodeDeviceDestroy, /* 0.7.3 */ }; =20 + +static virHypervisorDriver udevHypervisorDriver =3D { + .name =3D "nodedev", + .connectOpen =3D nodeConnectOpen, /* 4.1.0 */ + .connectClose =3D nodeConnectClose, /* 4.1.0 */ + .connectIsEncrypted =3D nodeConnectIsEncrypted, /* 4.1.0 */ + .connectIsSecure =3D nodeConnectIsSecure, /* 4.1.0 */ + .connectIsAlive =3D nodeConnectIsAlive, /* 4.1.0 */ +}; + + +static virConnectDriver udevConnectDriver =3D { + .hypervisorDriver =3D &udevHypervisorDriver, + .nodeDeviceDriver =3D &udevNodeDeviceDriver, +}; + + static virStateDriver udevStateDriver =3D { .name =3D "udev", .stateInitialize =3D nodeStateInitialize, /* 0.7.3 */ @@ -2078,6 +2095,8 @@ udevNodeRegister(void) { VIR_DEBUG("Registering udev node device backend"); =20 + if (virRegisterConnectDriver(&udevConnectDriver, false) < 0) + return -1; if (virSetSharedNodeDeviceDriver(&udevNodeDeviceDriver) < 0) return -1; =20 --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list