From nobody Sun Apr 28 06:48:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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=1623332762; cv=none; d=zohomail.com; s=zohoarc; b=ZVVpHLRxlPMTIz+zJWNiuKLpbymqDqeLFYOTLl0Fc0Bj0xUYsVsi/Ge3oRy42Jgd6jb4qNI3K/BAINsHF1GmJ3Ge+hrQ54XexKyt7T2WyEFIWcG2Ck/PAjF+D5FO6Dh0Nm33aJ+ygRWI0/7uSOaty/26252ibb8owPS4aDtCNPE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623332762; 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; bh=HkZ5L09VJVgJdtB5LHqmo2KKbBeoW4mQz58bLFYfbjQ=; b=LF2NtibEiLFFSMOYcLa/xWqCM+IstHOBDGRmz19qeb1xJqggUH8cejpwljvvqF3YGe6wAW1njtE6hs/hyT8fqhJJYkmD905F5ZovPPpPZtZk+vdAhBS2p/F5Xf8UaaUjm7FsdIp+rKjgmaGPhQ9muIFZbKIqe2hEQiIfMunlVCA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1623332762573970.1795309597802; Thu, 10 Jun 2021 06:46:02 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-579-qKse6XnRP0uSSrRfpD9Tzw-1; Thu, 10 Jun 2021 09:45:59 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id E95D2100CF64; Thu, 10 Jun 2021 13:45:52 +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 7307D189BB; Thu, 10 Jun 2021 13:45:52 +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 C54F84EE7F; Thu, 10 Jun 2021 13:45:51 +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 15ADhS1U004216 for ; Thu, 10 Jun 2021 09:43:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id CE57419630; Thu, 10 Jun 2021 13:43:28 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-115-203.ams2.redhat.com [10.36.115.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id C9B6D63B8C; Thu, 10 Jun 2021 13:43:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623332761; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=HkZ5L09VJVgJdtB5LHqmo2KKbBeoW4mQz58bLFYfbjQ=; b=cHco+lwV4YwePdxQcrd7ytnWZQntZdx/3BHLf6VLsbwbibGianEGn+INFViFT0mEJE9b+P JJ0i4d3QW4YH6V8cYMzbrTpajAUnqx35PWcwQe255GhS90tYaSgZ1x7KwWOORFW23fT4f2 wJ96m1+6G8/QV7NtYyD5zZRlyJ2bD6A= X-MC-Unique: qKse6XnRP0uSSrRfpD9Tzw-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH 1/4] remote: extract logic for probing for modular daemons Date: Thu, 10 Jun 2021 14:43:14 +0100 Message-Id: <20210610134317.368010-2-berrange@redhat.com> In-Reply-To: <20210610134317.368010-1-berrange@redhat.com> References: <20210610134317.368010-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 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) When virtproxyd gets a NULL URI, it needs to implement probing logic similar to that found in virConnectOpen. The latter can't be used directly since it relied on directly calling into the internal drivers in libvirtd. virtproxyd approximates this behaviour by looking to see what modular daemon sockets exist, or what daemon binaries are installed. This same logic is also going to be needed when the regular libvirt remote client switches to prefer modular daemons by default, as we don't want to continue spawning libvirtd going forward. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Michal Privoznik --- src/libvirt_remote.syms | 5 + src/remote/remote_daemon_dispatch.c | 98 +++++--------------- src/remote/remote_sockets.c | 139 ++++++++++++++++++++++++++++ src/remote/remote_sockets.h | 7 ++ 4 files changed, 173 insertions(+), 76 deletions(-) diff --git a/src/libvirt_remote.syms b/src/libvirt_remote.syms index 11c9e2cb73..b4265adf2e 100644 --- a/src/libvirt_remote.syms +++ b/src/libvirt_remote.syms @@ -14,6 +14,11 @@ xdr_*; xdr_virNetMessageError; =20 =20 +# remote/remote_sockets.h +remoteProbeSessionDriverFromBinary; +remoteProbeSessionDriverFromSocket; +remoteProbeSystemDriverFromSocket; + # rpc/virnetclient.h virNetClientAddProgram; virNetClientAddStream; diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon= _dispatch.c index 838f4a925f..36d4d00b79 100644 --- a/src/remote/remote_daemon_dispatch.c +++ b/src/remote/remote_daemon_dispatch.c @@ -24,6 +24,7 @@ =20 #include "remote_daemon_dispatch.h" #include "remote_daemon.h" +#include "remote_sockets.h" #include "libvirt_internal.h" #include "datatypes.h" #include "viralloc.h" @@ -1968,6 +1969,8 @@ static int remoteDispatchProbeURI(bool readonly, char **probeduri) { + g_autofree char *driver =3D NULL; + const char *suffix; *probeduri =3D NULL; VIR_DEBUG("Probing for driver daemon sockets"); =20 @@ -1976,94 +1979,37 @@ remoteDispatchProbeURI(bool readonly, * exists, or we're using socket activation so the socket exists * too. * - * If running non-root, chances are that the daemon won't be - * running, nor any socket activation is used. We need to - * be able to auto-spawn the daemon. We thus just check to - * see what daemons are installed. This is not a big deal as - * only QEMU & VBox run as non-root, anyway. + * If running non-root, the daemon may or may not already be + * running, and socket activation probably isn't relevant. + * So if no viable socket exists, we need to check which daemons + * are actually installed. This is not a big deal as only QEMU & + * VBox run as non-root, anyway. */ if (geteuid() !=3D 0) { - /* Order these the same as virDriverLoadModule - * calls in daemonInitialize */ - const char *drivers[] =3D { -# ifdef WITH_QEMU - "qemu", -# endif -# ifdef WITH_VBOX - "vbox", -# endif - }; - ssize_t i; - - for (i =3D 0; i < (ssize_t) G_N_ELEMENTS(drivers) && !*probeduri; = i++) { - g_autofree char *daemonname =3D NULL; - g_autofree char *daemonpath =3D NULL; - - daemonname =3D g_strdup_printf("virt%sd", drivers[i]); - - if (!(daemonpath =3D virFileFindResource(daemonname, - abs_top_builddir "/src", - SBINDIR))) - return -1; - - if (!virFileExists(daemonpath)) { - VIR_DEBUG("Missing daemon %s for driver %s", daemonpath, d= rivers[i]); - continue; - } + if (remoteProbeSessionDriverFromSocket(false, &driver) < 0) + return -1; =20 - *probeduri =3D g_strdup_printf("%s:///session", drivers[i]); + if (driver =3D=3D NULL && + remoteProbeSessionDriverFromBinary(&driver) < 0) + return -1; =20 - VIR_DEBUG("Probed URI %s via daemon %s", *probeduri, daemonpat= h); - return 0; - } + suffix =3D "session"; } else { - /* Order these the same as virDriverLoadModule - * calls in daemonInitialize */ - const char *drivers[] =3D { -# ifdef WITH_LIBXL - "libxl", -# endif -# ifdef WITH_QEMU - "qemu", -# endif -# ifdef WITH_LXC - "lxc", -# endif -# ifdef WITH_VBOX - "vbox", -# endif -# ifdef WITH_BHYVE - "bhyve", -# endif -# ifdef WITH_VZ - "vz", -# endif - }; - ssize_t i; - - for (i =3D 0; i < (ssize_t) G_N_ELEMENTS(drivers) && !*probeduri; = i++) { - g_autofree char *sockname =3D NULL; - - sockname =3D g_strdup_printf("%s/libvirt/virt%sd-%s", RUNSTATE= DIR, - drivers[i], readonly ? "sock-ro" : = "sock"); - - if (!virFileExists(sockname)) { - VIR_DEBUG("Missing sock %s for driver %s", sockname, drive= rs[i]); - continue; - } - - *probeduri =3D g_strdup_printf("%s:///system", drivers[i]); + if (remoteProbeSystemDriverFromSocket(readonly, &driver) < 0) + return -1; =20 - VIR_DEBUG("Probed URI %s via sock %s", *probeduri, sockname); - return 0; - } + suffix =3D "system"; } =20 /* Even if we didn't probe any socket, we won't * return error. Just let virConnectOpen's normal * logic run which will likely return an error anyway */ - VIR_DEBUG("No driver sock exists"); + if (!driver) + return 0; + + *probeduri =3D g_strdup_printf("%s:///%s", driver, suffix); + VIR_DEBUG("Probed URI %s for driver %s", *probeduri, driver); return 0; } #endif /* VIRTPROXYD */ diff --git a/src/remote/remote_sockets.c b/src/remote/remote_sockets.c index 0f85b999fd..dd28c9dd5e 100644 --- a/src/remote/remote_sockets.c +++ b/src/remote/remote_sockets.c @@ -146,6 +146,145 @@ remoteGetUNIXSocketHelper(remoteDriverTransport trans= port, return sockname; } =20 +/* + * Determine which driver is probably usable based on + * which modular daemon binaries are installed. + */ +int +remoteProbeSessionDriverFromBinary(char **driver) +{ + /* Order these the same as virDriverLoadModule + * calls in daemonInitialize, so we replicate + * probing order that virConnectOpen would use + * if running inside libvirtd */ + const char *drivers[] =3D { +#ifdef WITH_QEMU + "qemu", +#endif +#ifdef WITH_VBOX + "vbox", +#endif + }; + ssize_t i; + + VIR_DEBUG("Probing for driver from daemon binaries"); + + *driver =3D NULL; + + for (i =3D 0; i < (ssize_t) G_N_ELEMENTS(drivers); i++) { + g_autofree char *daemonname =3D NULL; + g_autofree char *daemonpath =3D NULL; + + daemonname =3D g_strdup_printf("virt%sd", drivers[i]); + VIR_DEBUG("Probing driver '%s' via daemon %s", drivers[i], daemonp= ath); + + if (!(daemonpath =3D virFileFindResource(daemonname, + abs_top_builddir "/src", + SBINDIR))) + return -1; + + if (virFileExists(daemonpath)) { + VIR_DEBUG("Found driver '%s' via daemon %s", drivers[i], daemo= npath); + *driver =3D g_strdup(drivers[i]); + return 0; + } + + VIR_DEBUG("Missing daemon %s for driver %s", daemonpath, drivers[i= ]); + } + + VIR_DEBUG("No more drivers to probe for"); + return 0; +} + + +int +remoteProbeSystemDriverFromSocket(bool readonly, char **driver) +{ + /* Order these the same as virDriverLoadModule + * calls in daemonInitialize, so we replicate + * probing order that virConnectOpen would use + * if running inside libvirtd */ + const char *drivers[] =3D { +#ifdef WITH_LIBXL + "libxl", +#endif +#ifdef WITH_QEMU + "qemu", +#endif +#ifdef WITH_LXC + "lxc", +#endif +#ifdef WITH_VBOX + "vbox", +#endif +#ifdef WITH_BHYVE + "bhyve", +#endif +#ifdef WITH_VZ + "vz", +#endif + }; + ssize_t i; + + for (i =3D 0; i < (ssize_t) G_N_ELEMENTS(drivers); i++) { + g_autofree char *sockname =3D + g_strdup_printf("%s/libvirt/virt%sd-%s", RUNSTATEDIR, + drivers[i], readonly ? "sock-ro" : "sock"); + + if (virFileExists(sockname)) { + VIR_DEBUG("Probed driver '%s' via sock '%s'", drivers[i], sock= name); + *driver =3D g_strdup(drivers[i]); + return 0; + } + + VIR_DEBUG("Missing sock %s for driver %s", sockname, drivers[i]); + } + + /* Even if we didn't probe any socket, we won't + * return error. Just let virConnectOpen's normal + * logic run which will likely return an error anyway + */ + VIR_DEBUG("No more drivers to probe for"); + return 0; +} + +int +remoteProbeSessionDriverFromSocket(bool readonly, char **driver) +{ + /* Order these the same as virDriverLoadModule + * calls in daemonInitialize */ + const char *drivers[] =3D { +#ifdef WITH_QEMU + "qemu", +#endif +#ifdef WITH_VBOX + "vbox", +#endif + }; + ssize_t i; + + for (i =3D 0; i < (ssize_t) G_N_ELEMENTS(drivers); i++) { + g_autofree char *userdir =3D virGetUserRuntimeDirectory(); + g_autofree char *sockname =3D + g_strdup_printf("%s/virt%sd-%s", + userdir, drivers[i], readonly ? "sock-ro" : "s= ock"); + + if (virFileExists(sockname)) { + VIR_DEBUG("Probed driver '%s' via sock '%s'", drivers[i], sock= name); + *driver =3D g_strdup(drivers[i]); + return 0; + } + + VIR_DEBUG("Missing sock %s for driver %s", sockname, drivers[i]); + } + + /* Even if we didn't probe any socket, we won't + * return error. Just let virConnectOpen's normal + * logic run which will likely return an error anyway + */ + VIR_DEBUG("No more drivers to probe for"); + return 0; +} =20 char * remoteGetUNIXSocket(remoteDriverTransport transport, diff --git a/src/remote/remote_sockets.h b/src/remote/remote_sockets.h index 11934dbf70..00e654d46c 100644 --- a/src/remote/remote_sockets.h +++ b/src/remote/remote_sockets.h @@ -62,6 +62,13 @@ remoteSplitURIScheme(virURI *uri, char **driver, remoteDriverTransport *transport); =20 +int +remoteProbeSessionDriverFromBinary(char **driver); +int +remoteProbeSystemDriverFromSocket(bool readonly, char **driver); +int +remoteProbeSessionDriverFromSocket(bool readonly, char **driver); + char * remoteGetUNIXSocket(remoteDriverTransport transport, remoteDriverMode mode, --=20 2.31.1 From nobody Sun Apr 28 06:48:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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=1623332776; cv=none; d=zohomail.com; s=zohoarc; b=DGAf/9Cl0z0n6wJxuRsGr1dP3KehLyhrp4CkD8bckJegHTaFDnYCPmWxQt1LQU81AHNzyLdJqHHlCAuz/wQhcnW5G6StkBT6cIVMJKHQYS0qsukkMyHTYnlIF7a1GK5Elk3WSr2LppjZRGYeKMY1RHCnNpAmrV1O5V4QpmsLKzQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623332776; 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; bh=g1CDMn8kqQyYMmTuApg496+3re2So09sM663EnfKE+0=; b=KrVYHYA0WS8GWMt3Q03fsoLelWghB6hSHcSSemg0lO7/9tJ88y1ywNCKi3+JTwR1Eo+aJDXOzBzLkcRZMoCDw1Ad4oNQNlIHSK3InhJdjsp0n8VGIfJND4MVhsFJhUEuWN36VTdZ4adBQiP3x2BF3GVXUQnlPqgXaS5ILBzVWi4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1623332776428869.6334195301796; Thu, 10 Jun 2021 06:46:16 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-229-hgqOHn_wPdy3oae8FrVFfw-1; Thu, 10 Jun 2021 09:46:12 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0A47A100C669; Thu, 10 Jun 2021 13:46:07 +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 D9B925C238; Thu, 10 Jun 2021 13:46:06 +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 9E38C1809CBB; Thu, 10 Jun 2021 13:46:06 +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 15ADhUXB004226 for ; Thu, 10 Jun 2021 09:43:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id 15CE718AD4; Thu, 10 Jun 2021 13:43:30 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-115-203.ams2.redhat.com [10.36.115.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3F6D263B8C; Thu, 10 Jun 2021 13:43:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623332775; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=g1CDMn8kqQyYMmTuApg496+3re2So09sM663EnfKE+0=; b=CUfbxzajB0gqqjRx3EC5o71CD4bF7Pt6paq5bgiKBabpqnT4y/VYlARWntJzGP4EBhggXw CEsOlxgwHxa5+DvvGW9DSVpP/mzrDX3G3KRWQEoQU8AYqMRFSwYylJd+vf4PwfhKYzhZNV QGA9mc6E4XZM91c5Dt4+Tjx13gYW91g= X-MC-Unique: hgqOHn_wPdy3oae8FrVFfw-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH 2/4] remote: add support for probing drivers with modular daemons Date: Thu, 10 Jun 2021 14:43:15 +0100 Message-Id: <20210610134317.368010-3-berrange@redhat.com> In-Reply-To: <20210610134317.368010-1-berrange@redhat.com> References: <20210610134317.368010-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 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) With the traditional libvirtd, the virConnectOpen call will probe active drivers server side to find which one to use when the URI is NULL/empty. With the modular daemons though, the remote client does not know which daemon to connect in the first place, so we can't rely on virConnectOpen probing. Currently the virtproxyd daemon has code to probe for a possible driver by looking at which sockets are listening or which binaries are installed. The remote client can thus connect to virtproxyd which in turn can connect to a real hypervisor driver. The virtproxyd probing code though isn't something that needs to live in virtproxyd. By moving it into the remote client we can get probing client side in all scenarios and avoid the extra trip via virtproxyd in the common case. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Michal Privoznik --- meson.build | 6 +++-- src/remote/remote_sockets.c | 53 +++++++++++++++++++++++++++++++------ 2 files changed, 49 insertions(+), 10 deletions(-) diff --git a/meson.build b/meson.build index 40e99fec0c..91d51492a4 100644 --- a/meson.build +++ b/meson.build @@ -1415,8 +1415,10 @@ if not get_option('driver_remote').disabled() endif endif =20 -remote_default_mode =3D get_option('remote_default_mode').to_upper() -conf.set('REMOTE_DRIVER_MODE_DEFAULT', 'REMOTE_DRIVER_MODE_@0@'.format(rem= ote_default_mode)) +remote_default_mode =3D get_option('remote_default_mode') +if remote_default_mode =3D=3D 'direct' + conf.set('REMOTE_DRIVER_AUTOSTART_DIRECT', '1') +endif =20 if not get_option('driver_libvirtd').disabled() use_libvirtd =3D true diff --git a/src/remote/remote_sockets.c b/src/remote/remote_sockets.c index dd28c9dd5e..506e267201 100644 --- a/src/remote/remote_sockets.c +++ b/src/remote/remote_sockets.c @@ -299,6 +299,9 @@ remoteGetUNIXSocket(remoteDriverTransport transport, g_autofree char *daemon_name =3D NULL; g_autofree char *direct_sock_name =3D NULL; g_autofree char *legacy_sock_name =3D NULL; +#ifdef REMOTE_DRIVER_AUTOSTART_DIRECT + g_autofree char *guessdriver =3D NULL; +#endif #ifndef WIN32 const char *env_name =3D remoteGetDaemonPathEnv(); #else @@ -310,12 +313,35 @@ remoteGetUNIXSocket(remoteDriverTransport transport, remoteDriverModeTypeToString(mode), driver, flags); =20 +#ifdef REMOTE_DRIVER_AUTOSTART_DIRECT + if (!driver && mode !=3D REMOTE_DRIVER_MODE_LEGACY) { + VIR_DEBUG("Client side modular daemon probe"); + /* + * If we don't have a driver (because URI is empty) + * in the direct case, we don't know which daemon + * to connect to. This logic attempts to be a rough + * equivalent of auto-probing from virConnectOpen + * in the libvirtd days. + */ + if (geteuid() !=3D 0) { + if (remoteProbeSessionDriverFromSocket(false, &guessdriver) < = 0) + return NULL; + + if (guessdriver =3D=3D NULL && + remoteProbeSessionDriverFromBinary(&guessdriver) < 0) + return NULL; + } else { + if (remoteProbeSystemDriverFromSocket(flags & REMOTE_DRIVER_OP= EN_RO, + &guessdriver) < 0) + return NULL; + } + driver =3D guessdriver; + } +#endif + if (driver) { direct_daemon =3D g_strdup_printf("virt%sd", driver); direct_sock_name =3D remoteGetUNIXSocketHelper(transport, direct_d= aemon, flags); - } else { - direct_daemon =3D g_strdup("virtproxyd"); - direct_sock_name =3D remoteGetUNIXSocketHelper(transport, "libvirt= ", flags); } =20 legacy_daemon =3D g_strdup("libvirtd"); @@ -323,18 +349,29 @@ remoteGetUNIXSocket(remoteDriverTransport transport, =20 if (mode =3D=3D REMOTE_DRIVER_MODE_AUTO) { if (transport =3D=3D REMOTE_DRIVER_TRANSPORT_UNIX) { + /* + * When locally accessing libvirtd, we pick legacy or + * modular daemons depending on which sockets we see + * existing. + */ if (direct_sock_name && virFileExists(direct_sock_name)) { mode =3D REMOTE_DRIVER_MODE_DIRECT; } else if (virFileExists(legacy_sock_name)) { mode =3D REMOTE_DRIVER_MODE_LEGACY; } else { - /* - * This constant comes from the configure script and - * maps to either the direct or legacy mode constant - */ - mode =3D REMOTE_DRIVER_MODE_DEFAULT; +#ifdef REMOTE_DRIVER_AUTOSTART_DIRECT + mode =3D REMOTE_DRIVER_MODE_DIRECT; +#else + mode =3D REMOTE_DRIVER_MODE_LEGACY; +#endif } } else { + /* + * When remotely accessing libvirtd, we always default to a le= gacy socket + * path, as there's no way for us to probe what's configured. = This does + * not matter, since 'virt-ssh-helper' will be used if it is a= vailable + * and thus probe from context of the remote host + */ mode =3D REMOTE_DRIVER_MODE_LEGACY; } } --=20 2.31.1 From nobody Sun Apr 28 06:48:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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=1623332779; cv=none; d=zohomail.com; s=zohoarc; b=KNYpMEolPkcX1XXsrjYG0E4S+7Ho7n8K7IfHfQ7G9yTt8Zbzhb91CRFfltH73d4nlBqGdj6vzcZwP8GkW/zl/za747qfV0TciF1mYGLwbs5M9/osquNeqD14En1geRMesxq25igyWrswy2wqJMKBu6Msnm3DLWvPPr2ZcLNvrbE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623332779; 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; bh=588iLdjR43Qek3qAffTItGVqpykhtyLCVeAb/o6PHSo=; b=Vy61OyOMTO8/a7TtzICdwY0+DJV8XjcCzRsX3Sbar7KiBJ0xC4ZA21UYNMivdOX/zDOxWMX7oLnEr6qaLc2+RaJorX7ci6r0VJnaxuRWN9DrRMxZtU24pwuGDPA3kWHc+po4W5y7TcNnWXvXjV3hpzdoPYoo2k4Zq3YFejUqyu0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1623332779819113.72739885665862; Thu, 10 Jun 2021 06:46:19 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-445-AEjd5R7VOT63wBaKUBjZ2w-1; Thu, 10 Jun 2021 09:46:16 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4A4A180623E; Thu, 10 Jun 2021 13:46:10 +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 29D0F5C1CF; Thu, 10 Jun 2021 13:46:10 +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 D121E1809CBE; Thu, 10 Jun 2021 13:46:09 +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 15ADhVRR004237 for ; Thu, 10 Jun 2021 09:43:31 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1BE5B189BB; Thu, 10 Jun 2021 13:43:31 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-115-203.ams2.redhat.com [10.36.115.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id 60A3463B8C; Thu, 10 Jun 2021 13:43:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623332778; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=588iLdjR43Qek3qAffTItGVqpykhtyLCVeAb/o6PHSo=; b=HmfE/QYSCoI2twZlWmnPWER8qtUMsIk736PW7fjw8F0uX2ON9BmgJiIz9NxaLMAU7eR3+D Ju9Gk6AWIgBiJEW8GPK3pyUd9f94DRTZ3Qw0PlUzC+zrRPkLFE6RpqyPPUW03mlqKv5cSM HSiI1ryV5f6Af91iTiSmY7LEQy6UBmM= X-MC-Unique: AEjd5R7VOT63wBaKUBjZ2w-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH 3/4] remote: remove probing logic from virtproxyd dispatcher Date: Thu, 10 Jun 2021 14:43:16 +0100 Message-Id: <20210610134317.368010-4-berrange@redhat.com> In-Reply-To: <20210610134317.368010-1-berrange@redhat.com> References: <20210610134317.368010-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 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Now that the remote driver itself can probe for listening sockets / running daemons, virtproxyd doesn't need to probe URIs itself. Instead it can just delegate to the remote driver. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Michal Privoznik --- src/remote/remote_daemon_dispatch.c | 74 ----------------------------- 1 file changed, 74 deletions(-) diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon= _dispatch.c index 36d4d00b79..8cec0a2a01 100644 --- a/src/remote/remote_daemon_dispatch.c +++ b/src/remote/remote_daemon_dispatch.c @@ -1948,73 +1948,6 @@ void *remoteClientNew(virNetServerClient *client, =20 /*----- Functions. -----*/ =20 -#ifdef VIRTPROXYD -/* - * When running in virtproxyd regular auto-probing of drivers - * does not work as we don't have any drivers present (except - * stateless ones inside libvirt.so). All the interesting - * drivers are in separate daemons. Thus when we get a NULL - * URI we need to simulate probing that virConnectOpen would - * previously do. We use the existence of the UNIX domain - * socket as our hook for probing. - * - * This assumes no stale sockets left over from a now dead - * daemon, but that's reasonable since libvirtd unlinks - * sockets it creates on shutdown, or uses systemd activation - * - * We only try to probe for primary hypervisor drivers, - * not the secondary drivers. - */ -static int -remoteDispatchProbeURI(bool readonly, - char **probeduri) -{ - g_autofree char *driver =3D NULL; - const char *suffix; - *probeduri =3D NULL; - VIR_DEBUG("Probing for driver daemon sockets"); - - /* - * If running root, either the daemon is running and the socket - * exists, or we're using socket activation so the socket exists - * too. - * - * If running non-root, the daemon may or may not already be - * running, and socket activation probably isn't relevant. - * So if no viable socket exists, we need to check which daemons - * are actually installed. This is not a big deal as only QEMU & - * VBox run as non-root, anyway. - */ - if (geteuid() !=3D 0) { - if (remoteProbeSessionDriverFromSocket(false, &driver) < 0) - return -1; - - if (driver =3D=3D NULL && - remoteProbeSessionDriverFromBinary(&driver) < 0) - return -1; - - suffix =3D "session"; - } else { - if (remoteProbeSystemDriverFromSocket(readonly, &driver) < 0) - return -1; - - suffix =3D "system"; - } - - /* Even if we didn't probe any socket, we won't - * return error. Just let virConnectOpen's normal - * logic run which will likely return an error anyway - */ - if (!driver) - return 0; - - *probeduri =3D g_strdup_printf("%s:///%s", driver, suffix); - VIR_DEBUG("Probed URI %s for driver %s", *probeduri, driver); - return 0; -} -#endif /* VIRTPROXYD */ - - static int remoteDispatchConnectOpen(virNetServer *server G_GNUC_UNUSED, virNetServerClient *client, @@ -2054,13 +1987,6 @@ remoteDispatchConnectOpen(virNetServer *server G_GNU= C_UNUSED, priv->readonly =3D flags & VIR_CONNECT_RO; =20 #ifdef VIRTPROXYD - if (!name || STREQ(name, "")) { - if (remoteDispatchProbeURI(priv->readonly, &probeduri) < 0) - goto cleanup; - - name =3D probeduri; - } - preserveIdentity =3D true; #endif /* VIRTPROXYD */ =20 --=20 2.31.1 From nobody Sun Apr 28 06:48:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 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=1623332774; cv=none; d=zohomail.com; s=zohoarc; b=Ce7tPpFoHDNgWntY4QLSPLg3ICLHb4iBsvMyKaSre+SHAgjrTHDd8XV2AszfIwSEkK23hh5/xZ0rIziXwZKgp4DOvIUg6VW5ptoJsKBrZ9z+ClzmQwiG0FctgATpg4duvkHLpCG83S9koWNHskXXTLEQEXanw/xiQGPSX6M5yIw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623332774; 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; bh=3X82U4aIfmVe5vpG5dOLpRCpsQMstSRLRvteryALA0A=; b=KMllFvJEPKN7qRjQtcErYuP8goYPYRhaFBlJJXvmo7h0izi4MuqGUZVfK0It7hG/J+LfH/KG8UexUlWbTGTA2G7531zzBP9BI5Ly83NopYm0msFKRbb5w7nYInNcGGbjPOmfGHezq+UqPrvwOGN3SBWmBVch6nAgFZ4oUscIRVg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1623332774756644.0912609035173; Thu, 10 Jun 2021 06:46:14 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-394-3jycADQMNYWrdKbjNbX-oQ-1; Thu, 10 Jun 2021 09:46:11 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2CA331927800; Thu, 10 Jun 2021 13:46:07 +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 0A7F35D9E2; Thu, 10 Jun 2021 13:46:07 +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 C2C3F46F5A; Thu, 10 Jun 2021 13:46:06 +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 15ADhWth004249 for ; Thu, 10 Jun 2021 09:43:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id 528C518A9E; Thu, 10 Jun 2021 13:43:32 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-115-203.ams2.redhat.com [10.36.115.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7CF59189BB; Thu, 10 Jun 2021 13:43:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623332773; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=3X82U4aIfmVe5vpG5dOLpRCpsQMstSRLRvteryALA0A=; b=RoSpxqo5Kau/dNnPrL19xdG6J4VcvXARjVR1uuOk/XPChQJ4vIfbffdL44QRQsoLuXV8SX E4zaWUhC4mEfwRO3BVGf9kNcjZTA7BY+NsDnTdrSzU0XWkndT53kdMoqoXmlRaLuCfmVSs 5PDietb1j1QLy283y0eanRILsPe4oM0= X-MC-Unique: 3jycADQMNYWrdKbjNbX-oQ-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH 4/4] remote: switch to auto-spawn modular daemons by default Date: Thu, 10 Jun 2021 14:43:17 +0100 Message-Id: <20210610134317.368010-5-berrange@redhat.com> In-Reply-To: <20210610134317.368010-1-berrange@redhat.com> References: <20210610134317.368010-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 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) When determining what socket path to connect to for a given URI we will - Connect to the driver specific daemon if its UNIX socket exists - Connect to libvirtd if its UNIX socket exists - If non-root, auto-spawn a daemon based on the default mode Historically the last point would result in spawning libvirtd, but with this change we now spawn a modular daemon. Remote client probing logic will pick a specific hypervisor daemon to connect to when the URI is NULL. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Michal Privoznik --- meson_options.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson_options.txt b/meson_options.txt index d0f84dbfa6..859ed36b8f 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -63,7 +63,7 @@ option('qemu_user', type: 'string', value: '', descriptio= n: 'username to run QEM option('qemu_group', type: 'string', value: '', description: 'groupname to= run QEMU system instance as') option('qemu_moddir', type: 'string', value: '', description: 'set the dir= ectory where QEMU modules are located') option('driver_remote', type: 'feature', value: 'auto', description: 'remo= te driver') -option('remote_default_mode', type: 'combo', choices: ['legacy', 'direct']= , value: 'legacy', description: 'remote driver default mode') +option('remote_default_mode', type: 'combo', choices: ['legacy', 'direct']= , value: 'direct', description: 'remote driver default mode') option('driver_secrets', type: 'feature', value: 'auto', description: 'loc= al secrets management driver') option('driver_test', type: 'feature', value: 'auto', description: 'test d= river') option('driver_vbox', type: 'feature', value: 'auto', description: 'Virtua= lBox XPCOMC driver') --=20 2.31.1