From nobody Sun May 19 00:17:13 2024 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=1558095915; cv=none; d=zoho.com; s=zohoarc; b=Z8ASoMu8xUyF76kfYJ1fL8AhlP2AZhNjB4n9Lmb+Cri3hwdl4tdvG2ed3sc3cHCkoi4yFjgRH+o8b0Jmr6LN7uG+7uAIylz1NCUWyrp6xsXcVqDl1w+rvppm+u0NjgaGbFATiGQ8i/bZbl1WustfGjxYJkAtUSUy98Ss3So8KRM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558095915; h=Content-Type:Content-Transfer-Encoding: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=V0KZrhIa3FmlHcyupJA0oiLgOu+zaH4v0g/QdNeeEAQ=; b=iWIk66QRSi1JzmrXppLaPMHYt5/aBbQNBBb1SOqNWYFz938Z1LlA+/FD+QjpAUfISXH9/22ykRDXJUiA9aOXheIVMemPPo4/nTnpygLmtrOqxLwoXxX4yWTp9s9rRUs3VZQqVWMOg96l8E5F4JeR3CxFs7f0SVeW1e+RfoG39Zc= 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 1558095915424480.83085541944854; Fri, 17 May 2019 05:25:15 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AD4B13087948; Fri, 17 May 2019 12:25:13 +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 817EB348F0; Fri, 17 May 2019 12:25:13 +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 3E1F8206D5; Fri, 17 May 2019 12:25:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x4HCP6Sf014247 for ; Fri, 17 May 2019 08:25:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id CF0EC5D71B; Fri, 17 May 2019 12:25:06 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id C01775D707; Fri, 17 May 2019 12:25:02 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 17 May 2019 13:24:53 +0100 Message-Id: <20190517122457.26291-2-berrange@redhat.com> In-Reply-To: <20190517122457.26291-1-berrange@redhat.com> References: <20190517122457.26291-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/5] access: report an error if no access manager is present 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.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Fri, 17 May 2019 12:25:14 +0000 (UTC) Signed-off-by: Daniel P. Berrang=C3=A9 --- src/access/viraccessmanager.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/access/viraccessmanager.c b/src/access/viraccessmanager.c index f5d62604cf..26a16c6fb3 100644 --- a/src/access/viraccessmanager.c +++ b/src/access/viraccessmanager.c @@ -65,6 +65,11 @@ VIR_ONCE_GLOBAL_INIT(virAccessManager); =20 virAccessManagerPtr virAccessManagerGetDefault(void) { + if (virAccessManagerDefault =3D=3D NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("No access manager registered")); + return NULL; + } return virObjectRef(virAccessManagerDefault); } =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 00:17:13 2024 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=1558095913; cv=none; d=zoho.com; s=zohoarc; b=h8TYLrGjZpsGp4oZkuwqZfexxBZPDulw00KVxAGTk7B8bNY/ehWTbiB9XCYxW3pCjhzWQbsOXDXQw7/C28PI3xOLybHd3il3QDTTonsB7K92niEaE4ZmbIuEB5KxOL5G2lmGOdvu4stvGCKgh16KJrlOGtyIOvM4Q/ou/87ybsI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558095913; h=Content-Type:Content-Transfer-Encoding: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=aUEvHw8h2gZdL8K9F1mR7AxfkyoTdAkqASvZ+oqFN+w=; b=HSlfJQv+4umUSvk8PJM+18bAkOkzKF3Q0cPoXdKsAfU4q3r48NJDLKnWsbyZWtYQmcOnBkLuHwBNVJRyVK7iyPzoee4wjUbleUbTiTtnu1rcXF6EsGEdsDvBhJ635wZyTyPAby50X98pDR5uUXyfi7fm0q+mETJstQOaH6FQ6lQ= 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 1558095913439763.6052428024699; Fri, 17 May 2019 05:25:13 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7E11C3003B53; Fri, 17 May 2019 12:25:11 +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 53AF660BE0; Fri, 17 May 2019 12:25:11 +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 BDDED206D3; Fri, 17 May 2019 12:25:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x4HCP8qB014257 for ; Fri, 17 May 2019 08:25:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id 988425D71B; Fri, 17 May 2019 12:25:08 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id 635265D6A9; Fri, 17 May 2019 12:25:07 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 17 May 2019 13:24:54 +0100 Message-Id: <20190517122457.26291-3-berrange@redhat.com> In-Reply-To: <20190517122457.26291-1-berrange@redhat.com> References: <20190517122457.26291-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/5] libvirt: pass a root directory path into drivers 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Fri, 17 May 2019 12:25:12 +0000 (UTC) Allow drivers to be run against a different virtual root directory. The intent here is to allow the virt drivers to be run directly embedded in an arbitrary process without interfering with libvirtd. This can be useful for doing testing of the virt drivers in "make check" without interfering with the user's own libvirtd instances. It can also be used for an application like libguestfs which doesn't want its VMs to show up in the main libvirtd VM list. XXX make drivers reject root !=3D "" until they are ported to support it. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/driver-state.h | 1 + src/interface/interface_backend_netcf.c | 1 + src/interface/interface_backend_udev.c | 1 + src/libvirt.c | 2 ++ src/libvirt_internal.h | 1 + src/libxl/libxl_driver.c | 1 + src/lxc/lxc_driver.c | 2 ++ src/network/bridge_driver.c | 1 + src/node_device/node_device_hal.c | 1 + src/node_device/node_device_udev.c | 1 + src/nwfilter/nwfilter_driver.c | 1 + src/qemu/qemu_driver.c | 1 + src/remote/remote_daemon.c | 1 + src/remote/remote_driver.c | 1 + src/secret/secret_driver.c | 1 + src/storage/storage_driver.c | 1 + src/vz/vz_driver.c | 1 + 17 files changed, 19 insertions(+) diff --git a/src/driver-state.h b/src/driver-state.h index a8595662af..68bbf75e06 100644 --- a/src/driver-state.h +++ b/src/driver-state.h @@ -27,6 +27,7 @@ =20 typedef int (*virDrvStateInitialize)(bool privileged, + const char *root, virStateInhibitCallback callback, void *opaque); =20 diff --git a/src/interface/interface_backend_netcf.c b/src/interface/interf= ace_backend_netcf.c index cf8eb9488d..e9a0fee606 100644 --- a/src/interface/interface_backend_netcf.c +++ b/src/interface/interface_backend_netcf.c @@ -76,6 +76,7 @@ virNetcfDriverStateDispose(void *obj) =20 static int netcfStateInitialize(bool privileged, + const char *root ATTRIBUTE_UNUSED, virStateInhibitCallback callback ATTRIBUTE_UNUSED, void *opaque ATTRIBUTE_UNUSED) { diff --git a/src/interface/interface_backend_udev.c b/src/interface/interfa= ce_backend_udev.c index 1373356246..7c315c315a 100644 --- a/src/interface/interface_backend_udev.c +++ b/src/interface/interface_backend_udev.c @@ -1159,6 +1159,7 @@ udevInterfaceIsActive(virInterfacePtr ifinfo) =20 static int udevStateInitialize(bool privileged, + const char *root ATTRIBUTE_UNUSED, virStateInhibitCallback callback ATTRIBUTE_UNUSED, void *opaque ATTRIBUTE_UNUSED) { diff --git a/src/libvirt.c b/src/libvirt.c index 7e665b6cba..677f1cef5f 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -638,6 +638,7 @@ virRegisterStateDriver(virStateDriverPtr driver) */ int virStateInitialize(bool privileged, + const char *root, virStateInhibitCallback callback, void *opaque) { @@ -651,6 +652,7 @@ virStateInitialize(bool privileged, VIR_DEBUG("Running global init for %s state driver", virStateDriverTab[i]->name); if (virStateDriverTab[i]->stateInitialize(privileged, + root, callback, opaque) < 0) { VIR_ERROR(_("Initialization of %s state driver failed: %s"= ), diff --git a/src/libvirt_internal.h b/src/libvirt_internal.h index 8be1257814..c3964d4c38 100644 --- a/src/libvirt_internal.h +++ b/src/libvirt_internal.h @@ -31,6 +31,7 @@ typedef void (*virStateInhibitCallback)(bool inhibit, void *opaque); =20 int virStateInitialize(bool privileged, + const char *root, virStateInhibitCallback inhibit, void *opaque); int virStateCleanup(void); diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 2b9c6f1866..59e0d7229d 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -633,6 +633,7 @@ libxlAddDom0(libxlDriverPrivatePtr driver) =20 static int libxlStateInitialize(bool privileged, + const char *root ATTRIBUTE_UNUSED, virStateInhibitCallback callback ATTRIBUTE_UNUSED, void *opaque ATTRIBUTE_UNUSED) { diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 9db2a02dee..6d0d3a8ace 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -85,6 +85,7 @@ VIR_LOG_INIT("lxc.lxc_driver"); =20 =20 static int lxcStateInitialize(bool privileged, + const char *root ATTRIBUTE_UNUSED, virStateInhibitCallback callback, void *opaque); static int lxcStateCleanup(void); @@ -1536,6 +1537,7 @@ lxcSecurityInit(virLXCDriverConfigPtr cfg) =20 =20 static int lxcStateInitialize(bool privileged, + const char *root ATTRIBUTE_UNUSED, virStateInhibitCallback callback ATTRIBUTE_U= NUSED, void *opaque ATTRIBUTE_UNUSED) { diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 26f7f80418..ca9deaab4b 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -588,6 +588,7 @@ firewalld_dbus_filter_bridge(DBusConnection *connection= ATTRIBUTE_UNUSED, */ static int networkStateInitialize(bool privileged, + const char *root ATTRIBUTE_UNUSED, virStateInhibitCallback callback ATTRIBUTE_UNUSED, void *opaque ATTRIBUTE_UNUSED) { diff --git a/src/node_device/node_device_hal.c b/src/node_device/node_devic= e_hal.c index d1eb6c7851..7b11d4d7f7 100644 --- a/src/node_device/node_device_hal.c +++ b/src/node_device/node_device_hal.c @@ -588,6 +588,7 @@ device_prop_modified(LibHalContext *ctx ATTRIBUTE_UNUSE= D, =20 static int nodeStateInitialize(bool privileged ATTRIBUTE_UNUSED, + const char *root ATTRIBUTE_UNUSED, virStateInhibitCallback callback ATTRIBUTE_UNUSED, void *opaque ATTRIBUTE_UNUSED) { diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 5df2fd72f3..2d772d85c3 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1800,6 +1800,7 @@ udevPCITranslateInit(bool privileged ATTRIBUTE_UNUSED) =20 static int nodeStateInitialize(bool privileged, + const char *root ATTRIBUTE_UNUSED, virStateInhibitCallback callback ATTRIBUTE_UNUSED, void *opaque ATTRIBUTE_UNUSED) { diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c index fdfc6f48fa..58adcdbeb1 100644 --- a/src/nwfilter/nwfilter_driver.c +++ b/src/nwfilter/nwfilter_driver.c @@ -176,6 +176,7 @@ virNWFilterTriggerRebuildImpl(void *opaque) */ static int nwfilterStateInitialize(bool privileged, + const char *root ATTRIBUTE_UNUSED, virStateInhibitCallback callback ATTRIBUTE_UNUSED, void *opaque ATTRIBUTE_UNUSED) { diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 0a425b82e5..659d7b89e1 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -574,6 +574,7 @@ qemuDomainFindMaxID(virDomainObjPtr vm, */ static int qemuStateInitialize(bool privileged, + const char *root ATTRIBUTE_UNUSED, virStateInhibitCallback callback, void *opaque) { diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c index c3782971f1..2e47263bb9 100644 --- a/src/remote/remote_daemon.c +++ b/src/remote/remote_daemon.c @@ -796,6 +796,7 @@ static void daemonRunStateInit(void *opaque) * we're ready, since it can take a long time and this will * seriously delay OS bootup process */ if (virStateInitialize(virNetDaemonIsPrivileged(dmn), + "", daemonInhibitCallback, dmn) < 0) { VIR_ERROR(_("Driver state initialization failed")); diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 5c4dd41227..244e384607 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -184,6 +184,7 @@ static int remoteSplitURIScheme(virURIPtr uri, =20 static int remoteStateInitialize(bool privileged ATTRIBUTE_UNUSED, + const char *root ATTRIBUTE_UNUSED, virStateInhibitCallback callback ATTRIBUTE_UNUSED, void *opaque ATTRIBUTE_UNUSED) { diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c index ac85f5d195..1b4826e597 100644 --- a/src/secret/secret_driver.c +++ b/src/secret/secret_driver.c @@ -444,6 +444,7 @@ secretStateCleanup(void) =20 static int secretStateInitialize(bool privileged, + const char *root ATTRIBUTE_UNUSED, virStateInhibitCallback callback ATTRIBUTE_UNUSED, void *opaque ATTRIBUTE_UNUSED) { diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 496d51b1e0..a13eabf134 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -247,6 +247,7 @@ storageDriverAutostart(void) */ static int storageStateInitialize(bool privileged, + const char *root ATTRIBUTE_UNUSED, virStateInhibitCallback callback ATTRIBUTE_UNUSED, void *opaque ATTRIBUTE_UNUSED) { diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index dfd49e7cc7..92a9cfeaac 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -4096,6 +4096,7 @@ vzStateCleanup(void) =20 static int vzStateInitialize(bool privileged ATTRIBUTE_UNUSED, + const char *root ATTRIBUTE_UNUSED, virStateInhibitCallback callback ATTRIBUTE_UNUSED, void *opaque ATTRIBUTE_UNUSED) { --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 00:17:13 2024 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=1558095918; cv=none; d=zoho.com; s=zohoarc; b=PFXufvAOO4FxOto8aQr7+xRAT2XR02fVkNbBv8xeYdF0nLesBkQmY83+JlC4kPT9TnwoAx5oaS97RFJ/jFRMrZm94fqOeq1kibCQ6NwuwOPGzdPppQWKaemvI8NuB5W6kPMi6WOAbmTBUNh8QlJmNuMpWnkMC41iFgmErR9bd7Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558095918; h=Content-Type:Content-Transfer-Encoding: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=NATyxu3FKN40+EPlGOBpmD0dyJbtUT5rk1p/oSwAq20=; b=BxMm1yGa8HX6W0dRtq7hbTN8PNmknwaJgCJFInJtbDtrufVlU0ECHWewh/G9ZT2JymsuCwU0QexqZrUUZuinxZwAoXIt/9MiqcMiGs5Q0TGmivcjfqGrSO+/OgTm2eif79KllQHc3RwdudKJQ0AlkvEljIRoCkrVnTev0CLEzAM= 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 155809591896110.387060683427762; Fri, 17 May 2019 05:25:18 -0700 (PDT) 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 3A49F81F18; Fri, 17 May 2019 12:25:17 +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 044BF6C349; Fri, 17 May 2019 12:25:17 +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 ADB7D206D9; Fri, 17 May 2019 12:25:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x4HCPAp7014262 for ; Fri, 17 May 2019 08:25:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3F2B25D784; Fri, 17 May 2019 12:25:10 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0D6585D6A9; Fri, 17 May 2019 12:25:08 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 17 May 2019 13:24:55 +0100 Message-Id: <20190517122457.26291-4-berrange@redhat.com> In-Reply-To: <20190517122457.26291-1-berrange@redhat.com> References: <20190517122457.26291-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/5] qemu: honour the root parameter during driver initialization 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.25]); Fri, 17 May 2019 12:25:17 +0000 (UTC) Signed-off-by: Daniel P. Berrang=C3=A9 --- src/qemu/qemu_conf.c | 41 ++++++++++++++++++++++++++--------------- src/qemu/qemu_conf.h | 3 ++- src/qemu/qemu_driver.c | 2 +- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index daea11dacb..35ecb19b29 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -123,7 +123,8 @@ void qemuDomainCmdlineDefFree(qemuDomainCmdlineDefPtr d= ef) #endif =20 =20 -virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged) +virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged, + const char *root) { virQEMUDriverConfigPtr cfg; =20 @@ -150,30 +151,31 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool pr= ivileged) =20 if (privileged) { if (virAsprintf(&cfg->logDir, - "%s/log/libvirt/qemu", LOCALSTATEDIR) < 0) + "%s%s/log/libvirt/qemu", root, LOCALSTATEDIR) < 0) goto error; =20 if (virAsprintf(&cfg->swtpmLogDir, - "%s/log/swtpm/libvirt/qemu", LOCALSTATEDIR) < 0) + "%s%s/log/swtpm/libvirt/qemu", root, LOCALSTATEDIR= ) < 0) goto error; =20 - if (VIR_STRDUP(cfg->configBaseDir, SYSCONFDIR "/libvirt") < 0) + if (virAsprintf(&cfg->configBaseDir, + "%s%s/libvirt", root, SYSCONFDIR) < 0) goto error; =20 if (virAsprintf(&cfg->stateDir, - "%s/run/libvirt/qemu", LOCALSTATEDIR) < 0) + "%s%s/run/libvirt/qemu", root, LOCALSTATEDIR) < 0) goto error; =20 if (virAsprintf(&cfg->swtpmStateDir, - "%s/run/libvirt/qemu/swtpm", LOCALSTATEDIR) < 0) + "%s%s/run/libvirt/qemu/swtpm", root, LOCALSTATEDIR= ) < 0) goto error; =20 if (virAsprintf(&cfg->cacheDir, - "%s/cache/libvirt/qemu", LOCALSTATEDIR) < 0) + "%s%s/cache/libvirt/qemu", root, LOCALSTATEDIR) < = 0) goto error; =20 if (virAsprintf(&cfg->libDir, - "%s/lib/libvirt/qemu", LOCALSTATEDIR) < 0) + "%s%s/lib/libvirt/qemu", root, LOCALSTATEDIR) < 0) goto error; if (virAsprintf(&cfg->saveDir, "%s/save", cfg->libDir) < 0) goto error; @@ -188,8 +190,8 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool priv= ileged) goto error; if (virAsprintf(&cfg->memoryBackingDir, "%s/ram", cfg->libDir) < 0) goto error; - if (virAsprintf(&cfg->swtpmStorageDir, "%s/lib/libvirt/swtpm", - LOCALSTATEDIR) < 0) + if (virAsprintf(&cfg->swtpmStorageDir, "%s%s/lib/libvirt/swtpm", + root, LOCALSTATEDIR) < 0) goto error; if (!virDoesUserExist("tss") || virGetUserID("tss", &cfg->swtpm_user) < 0) @@ -200,22 +202,23 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool pr= ivileged) } else { char *rundir; char *cachedir; + char *cfgdir; =20 cachedir =3D virGetUserCacheDirectory(); if (!cachedir) goto error; =20 if (virAsprintf(&cfg->logDir, - "%s/qemu/log", cachedir) < 0) { + "%s%s/qemu/log", root, cachedir) < 0) { VIR_FREE(cachedir); goto error; } if (virAsprintf(&cfg->swtpmLogDir, - "%s/qemu/log", cachedir) < 0) { + "%s%s/qemu/log", root, cachedir) < 0) { VIR_FREE(cachedir); goto error; } - if (virAsprintf(&cfg->cacheDir, "%s/qemu/cache", cachedir) < 0) { + if (virAsprintf(&cfg->cacheDir, "%s%s/qemu/cache", root, cachedir)= < 0) { VIR_FREE(cachedir); goto error; } @@ -224,7 +227,7 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool priv= ileged) rundir =3D virGetUserRuntimeDirectory(); if (!rundir) goto error; - if (virAsprintf(&cfg->stateDir, "%s/qemu/run", rundir) < 0) { + if (virAsprintf(&cfg->stateDir, "%s%s/qemu/run", root, rundir) < 0= ) { VIR_FREE(rundir); goto error; } @@ -233,9 +236,16 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool pri= vileged) if (virAsprintf(&cfg->swtpmStateDir, "%s/swtpm", cfg->stateDir) < = 0) goto error; =20 - if (!(cfg->configBaseDir =3D virGetUserConfigDirectory())) + cfgdir =3D virGetUserConfigDirectory(); + if (!cfgdir) goto error; =20 + if (virAsprintf(&cfg->configBaseDir, "%s%s", root, cfgdir) < 0) { + VIR_FREE(cfgdir); + goto error; + } + VIR_FREE(cfgdir); + if (virAsprintf(&cfg->libDir, "%s/qemu/lib", cfg->configBaseDir) <= 0) goto error; if (virAsprintf(&cfg->saveDir, "%s/qemu/save", cfg->configBaseDir)= < 0) @@ -267,6 +277,7 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool priv= ileged) * This will then be used as a fallback if the service specific * directory doesn't exist (although we don't check if this exists). */ + // XXX root ? if (VIR_STRDUP(cfg->defaultTLSx509certdir, SYSCONFDIR "/pki/qemu") < 0) goto error; diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 983e74a3cf..f93b09c4fe 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -312,7 +312,8 @@ struct _qemuDomainCmdlineDef { =20 void qemuDomainCmdlineDefFree(qemuDomainCmdlineDefPtr def); =20 -virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged); +virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged, + const char *root); =20 int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg, const char *filename, diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 659d7b89e1..019f6b2bf3 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -613,7 +613,7 @@ qemuStateInitialize(bool privileged, if (privileged) qemu_driver->hostsysinfo =3D virSysinfoRead(); =20 - if (!(qemu_driver->config =3D cfg =3D virQEMUDriverConfigNew(privilege= d))) + if (!(qemu_driver->config =3D cfg =3D virQEMUDriverConfigNew(privilege= d, root))) goto error; =20 if (virAsprintf(&driverConf, "%s/qemu.conf", cfg->configBaseDir) < 0) --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 00:17:13 2024 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=1558095919; cv=none; d=zoho.com; s=zohoarc; b=UBvFJHazw2jvjAc0f0gL4lBAoYx3QurCYkyWOCuHePKU7/LduFeMQjwtK/1XJmWOf1e1EfRiKfN7RlVdVWoNCRyhf14Pq4ItJnJR1Z0mtkvvnXkvKZFNFYva07o8hLj60lTL6qwsKrnI/2m9FE8St0eFEXLU03HlGB77Te7/Y3I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558095919; h=Content-Type:Content-Transfer-Encoding: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=Rr8/jytWaKkct/WZ8l/cJJkb3Aix27AQh1ub8MFgPPc=; b=IEtToon0iUXvL/nCjQpVY4tRkpPU0nrLPw9aZWIrIBdigi7WUdKRjGqu0XMP+9MDOvrA0n2afmmGu2TQDPLHtairc4zOGrqGE0hDGNuzeHknPW82tGogSbHzn1p0tMeN40ePMNXOuJiJ3J9Bht9+rXlzqD2vobUINXacq/eaz4M= 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 1558095919741118.97972513058107; Fri, 17 May 2019 05:25:19 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9660A307D96F; Fri, 17 May 2019 12:25:17 +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 6ECAC5D784; Fri, 17 May 2019 12:25:17 +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 287871806B14; Fri, 17 May 2019 12:25:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x4HCPBRk014273 for ; Fri, 17 May 2019 08:25:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id EB6565D71B; Fri, 17 May 2019 12:25:11 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9C4905D6A9; Fri, 17 May 2019 12:25:10 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 17 May 2019 13:24:56 +0100 Message-Id: <20190517122457.26291-5-berrange@redhat.com> In-Reply-To: <20190517122457.26291-1-berrange@redhat.com> References: <20190517122457.26291-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 4/5] libvirt: support an "embed" URI path selector for QEMU driver 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Fri, 17 May 2019 12:25:18 +0000 (UTC) The driver URI: "qemu:///embed?root=3D/some/path" enables a new way to use the QEMU driver by embedding it directly in the calling process. To use this the process must have a thread running the libvirt event loop. This URI will then cause libvirt to dynamically load the QEMU driver module and call its global initialization function. The application can now make normal libvirt API calls which are all serviced in-process with no RPC layer involved. To avoid conflicting with the existing libvirtd daemon it is important to specify an alternative root directory. All the paths the QEMU driver normal creates will be placed under this root. For example using the path /home/berrange/tmp/embed, as an unprivileged process cause the creation of the following directories /home/berrange/tmp/embed/home/berrange/.config/libvirt/qemu/lib /home/berrange/tmp/embed/home/berrange/.config/libvirt/qemu/snapshot /home/berrange/tmp/embed/home/berrange/.config/libvirt/qemu/save /home/berrange/tmp/embed/home/berrange/.config/libvirt/qemu/channel/target /home/berrange/tmp/embed/home/berrange/.config/libvirt/qemu/ram/libvirt /home/berrange/tmp/embed/home/berrange/.config/libvirt/qemu/ram/libvirt/q= emu /home/berrange/tmp/embed/home/berrange/.config/libvirt/qemu/nvram /home/berrange/tmp/embed/home/berrange/.config/libvirt/qemu/dump /home/berrange/tmp/embed/home/berrange/.cache/libvirt/qemu/cache/capabili= ties /home/berrange/tmp/embed/home/berrange/.cache/libvirt/qemu/log /home/berrange/tmp/embed/run/user/501/libvirt/qemu/run The application is responsible for purging everything underneath this root directory when no longer required. Note that QEMU is still daemonized right now and so the application embedding the QEMU driver can quit & restart and still have its VMs present, just as libvirtd would. A future patch will hook up VIR_DOMAIN_CREATE_AUTO_DESTROY flag such that the VM are not daemonized and still retain the parent/child relationship forcing them to die the the application exits. Thanks to previous refactoring, it is still possible to use functionality that calls out to other secondary drivers. For example it can open the network, secret or storage drivers. The network driver stuff is not fully functional though until the pending refactoring is done to introduce the virNetworkPort object concept. A key thing to note is that for this to work, the application that links to libvirt *MUST* be built with -Wl,--export-dynamic to ensure that symbols from libvirt.so are exported & thus available to the dynamically loaded QEMU driver module. If libvirt.so itself was dynamically loaded then RTLD_GLOBAL must be passed to dlopen(). Signed-off-by: Daniel P. Berrang=C3=A9 --- src/libvirt.c | 39 +++++++++++++++++++++++++++++++++++++- src/qemu/qemu_driver.c | 6 ++++-- src/remote/remote_driver.c | 7 +++++++ 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/src/libvirt.c b/src/libvirt.c index 677f1cef5f..e34fd5c96d 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -87,6 +87,7 @@ #ifdef WITH_BHYVE # include "bhyve/bhyve_driver.h" #endif +#include "access/viraccessmanager.h" =20 #define VIR_FROM_THIS VIR_FROM_NONE =20 @@ -841,6 +842,7 @@ virConnectOpenInternal(const char *name, virConnectPtr ret; virConfPtr conf =3D NULL; char *uristr =3D NULL; + bool embed =3D false; =20 ret =3D virGetConnect(); if (ret =3D=3D NULL) @@ -939,6 +941,36 @@ virConnectOpenInternal(const char *name, ret->uri) < 0) { goto failed; } + + if (STREQ(ret->uri->scheme, "qemu") && + STREQ(ret->uri->path, "/embed")) { + const char *root =3D NULL; + for (i =3D 0; i < ret->uri->paramsCount; i++) { + virURIParamPtr var =3D &ret->uri->params[i]; + if (STREQ(var->name, "root")) + root =3D var->value; + } + + if (!root) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("root parameter required for embedded dri= ver")); + goto failed; + } + + if (virDriverLoadModule("qemu", "qemuRegister", false) < 0) + goto failed; + + if (virAccessManagerGetDefault() =3D=3D NULL) { + virAccessManagerPtr acl; + acl =3D virAccessManagerNew("none"); + virAccessManagerSetDefault(acl); + } + + if (virStateInitialize(geteuid() =3D=3D 0, root, NULL, NULL) <= 0) + goto failed; + + embed =3D true; + } } else { VIR_DEBUG("no name, allowing driver auto-select"); } @@ -1011,7 +1043,12 @@ virConnectOpenInternal(const char *name, continue; } } else { - VIR_DEBUG("Matching any URI scheme for '%s'", ret->uri ? ret->= uri->scheme : ""); + if (embed) { + VIR_DEBUG("Skipping wildcard for embedded URI"); + continue; + } else { + VIR_DEBUG("Matching any URI scheme for '%s'", ret->uri ? r= et->uri->scheme : ""); + } } =20 /* before starting the new connection, check if the driver only wo= rks diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 019f6b2bf3..cdd483a338 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1105,14 +1105,16 @@ static virDrvOpenStatus qemuConnectOpen(virConnectP= tr conn, =20 if (virQEMUDriverIsPrivileged(qemu_driver)) { if (STRNEQ(conn->uri->path, "/system") && - STRNEQ(conn->uri->path, "/session")) { + STRNEQ(conn->uri->path, "/session") && + STRNEQ(conn->uri->path, "/embed")) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected QEMU URI path '%s', try qemu:///s= ystem"), conn->uri->path); return VIR_DRV_OPEN_ERROR; } } else { - if (STRNEQ(conn->uri->path, "/session")) { + if (STRNEQ(conn->uri->path, "/session") && + STRNEQ(conn->uri->path, "/embed")) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected QEMU URI path '%s', try qemu:///s= ession"), conn->uri->path); diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 244e384607..976f311060 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -1343,6 +1343,13 @@ remoteConnectOpen(virConnectPtr conn, if (flags & VIR_CONNECT_RO) rflags |=3D VIR_DRV_OPEN_REMOTE_RO; =20 + if (conn->uri && + conn->uri->path && + STREQ(conn->uri->path, "/embed")) { + ret =3D VIR_DRV_OPEN_DECLINED; + goto cleanup; + } + /* * If no servername is given, and no +XXX * transport is listed, or transport is unix, --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 00:17:13 2024 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=1558095922; cv=none; d=zoho.com; s=zohoarc; b=f4zuSnhe3vp3PXkpAbJFAkCLsBaFu/4KIsIW8SnxK/eecjz1rwtTso0qZVIhcZ9PSxjvQFsjzwueH1uyn0wAJ5BQFDjO5K8/fSTK1YdLsGD4ypDEEvrhRVVrL9DGXqNuetc4ou3r2MrtQ1OFrrj9QPa1BKROqWygDwVMQAGsGrs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558095922; h=Content-Type:Content-Transfer-Encoding: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=z9BdcqvY+lirqhSz0uTFmXhCMwfdUJt4xDLOyEklfAw=; b=mZNAiw1amFUGt9ChxwfYAw+nFjMnRdD0uBZC5ekTcEZmhmaNCFgTdejOanh8Pz8Z4iqnCcHaFWtClcBA38plW4vANng2it90gbYMme1hwNPZhto1ByWroFKa+6k756Sj5k3CjVAugEH/BPKyYR6iXRpaK8mGn/NBco4Cj5CcWaM= 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 1558095922605992.9450245853338; Fri, 17 May 2019 05:25:22 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BBD8B30842B2; Fri, 17 May 2019 12:25:20 +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 917031B482; Fri, 17 May 2019 12:25:20 +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 4E1891806B16; Fri, 17 May 2019 12:25:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x4HCPD9J014295 for ; Fri, 17 May 2019 08:25:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3939F5D707; Fri, 17 May 2019 12:25:13 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id 590955D6A9; Fri, 17 May 2019 12:25:12 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 17 May 2019 13:24:57 +0100 Message-Id: <20190517122457.26291-6-berrange@redhat.com> In-Reply-To: <20190517122457.26291-1-berrange@redhat.com> References: <20190517122457.26291-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 5/5] qemu: introduce a new style libvirt_qemu_shim program 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Fri, 17 May 2019 12:25:21 +0000 (UTC) The previous "QEMU shim" proof of concept was taking an approach of only caring about initial spawning of the QEMU process. It was then registered with the libvirtd daemon who took over management of it. The intent was that later libvirtd would be refactored so that the shim retained control over the QEMU monitor and libvirt just forwarded APIs to each shim as needed. This forwarding of APIs would require quite alot of significant refactoring of libvirtd to achieve. This impl thus takes a quite different approach, explicitly deciding to keep the VMs completely separate from those seen & managed by libvirtd. Instead it uses the new "qemu:///embed" URI scheme to embed the entire QEMU driver in the shim, running with a custom root directory. Once the driver is initialization, the shim starts a VM and then waits to shutdown automatically when QEMU shuts down, or should kill QEMU if it is terminated itself. This is pending the AUTO_DESTROY improvements mentioned in the previous patch. Note this program does not expose any way to manage the QEMU process, since there's no RPC interface enabled. It merely starts the VM and cleans up at the end. It is probably quite rare this would be used as is, though potentially users might find it useful scripting throwaway VMs during automation that they wish to keep hidden from the rest of libvirtd instances. Mostly though it serves as example code for how to use the new "qemu:///embed" URI syntax. A more advanced application can copy this code into their own codebase, and thus have the full range of QEMU driver APIs available. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/qemu/Makefile.inc.am | 7 ++++ src/qemu/qemu_shim.c | 70 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 src/qemu/qemu_shim.c diff --git a/src/qemu/Makefile.inc.am b/src/qemu/Makefile.inc.am index fd32a90d56..461704c79d 100644 --- a/src/qemu/Makefile.inc.am +++ b/src/qemu/Makefile.inc.am @@ -166,3 +166,10 @@ EXTRA_DIST +=3D \ qemu/THREADS.txt \ libvirt_qemu_probes.d \ $(NULL) + +libexec_PROGRAMS +=3D libvirt_qemu_shim + +libvirt_qemu_shim_SOURCES =3D qemu/qemu_shim.c + +libvirt_qemu_shim_LDADD =3D libvirt.la +libvirt_qemu_shim_LDFLAGS =3D -Wl,--export-dynamic diff --git a/src/qemu/qemu_shim.c b/src/qemu/qemu_shim.c new file mode 100644 index 0000000000..df4385d956 --- /dev/null +++ b/src/qemu/qemu_shim.c @@ -0,0 +1,70 @@ + +#include "config.h" + +#include +#include +#include +#include +#include + +#include "virfile.h" +#include "virstring.h" + +#define VIR_FROM_THIS VIR_FROM_QEMU + +static void *eventLoop(void *opaque) +{ + bool *quit =3D opaque; + while (!*quit) + virEventRunDefaultImpl(); + return NULL; +} + +int main(int argc, char **argv) +{ + pthread_t eventLoopThread; + bool quit =3D false; + virConnectPtr conn; + virDomainPtr dom; + char *xml =3D NULL; + char *uri; + + if (argc !=3D 3) { + fprintf(stderr, "syntax: %s ROOT XML\n", argv[0]); + return 1; + } + if (virFileReadAll(argv[2], 102400, &xml) < 0) { + fprintf(stderr, "cannot read %s: %s\n", argv[2], virGetLastErrorMe= ssage()); + return 1; + } + + virFileActivateDirOverride(argv[0]); + virEventRegisterDefaultImpl(); + + pthread_create(&eventLoopThread, NULL, eventLoop, &quit); + + if (virAsprintf(&uri, "qemu:///embed?root=3D%s", argv[1]) < 0) { + return 1; + } + conn =3D virConnectOpen(uri); + if (!conn) { + fprintf(stderr, "cannot open QEMU: %s\n", virGetLastErrorMessage()= ); + return 1; + } + + dom =3D virDomainCreateXML(conn, xml, 0); + if (!dom) { + fprintf(stderr, "cannot start VM: %s\n", virGetLastErrorMessage()); + virConnectClose(conn); + return 1; + } + + fprintf(stderr, "Running for 10 seconds\n"); + sleep(10); + + virDomainDestroy(dom); + + virConnectClose(conn); + + return 0; +} --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list