From nobody Fri May 3 07:42:29 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=1628096875; cv=none; d=zohomail.com; s=zohoarc; b=Tib23taYmBaETo/yGGZpVjNSSri9GlPOMMqU/7xPRFLxAo0Zs88iW6ndNlThY+yWSxsaVt6rebOsGdFmUHXk8c/uZqSH/bRL4EPjwgimlRGLE2WPoChatqmqdwWqr951ZBf6z977DzePt9XMVquOYWRXVGe5g3hkF7SjlGFVuqk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1628096875; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=KRM1R98L8pgrN7z3ZBnYD+IFgDAJNrYCRHgvVNJ2zXM=; b=Yzvy0kOREZhga3Mk/An++xh/y9g9ZmLF4mhAb+Nj0UOjigFXy++IXnLzWCKjmotzBrIhuKXsmpX1SEIthZPpBqHL8EMXv3j/k3sNrbXk7joYaYkRvpoBdoAPt7LQjlGFR2b1SbjWk1tazAnizXCE0K2yoks/BafM0YfMXubTpjo= 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 1628096875586444.46955196010083; Wed, 4 Aug 2021 10:07:55 -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-596-22z5lpF_MaWY8juTr1SN7g-1; Wed, 04 Aug 2021 13:07:51 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 35FEE640A0; Wed, 4 Aug 2021 17:07:46 +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 4FE2F6091B; Wed, 4 Aug 2021 17:07:45 +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 7D38B4A7C9; Wed, 4 Aug 2021 17:07:41 +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 174H5lpY003408 for ; Wed, 4 Aug 2021 13:05:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id E84D866FFF; Wed, 4 Aug 2021 17:05:47 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.39.194.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1DC5169320; Wed, 4 Aug 2021 17:05:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628096874; 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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=KRM1R98L8pgrN7z3ZBnYD+IFgDAJNrYCRHgvVNJ2zXM=; b=Ye9seQnguuuKQc10WzKLJhjCnQndHesumzgx8EXbFn982PczIp1L0JLd67cCiXN8WJwxwT HzoLxd1ifIrGosqnnxbcLoaoXrXnCzAlj74QWUZGeYGIxW0388Fhq200HK6QzTYUGnOtls 12o12LlmPNIGnnt0pwulH6ZsMGFDwA8= X-MC-Unique: 22z5lpF_MaWY8juTr1SN7g-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [PATCH] Revert "remote: remove probing logic from virtproxyd dispatcher" Date: Wed, 4 Aug 2021 18:05:41 +0100 Message-Id: <20210804170541.3448859-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 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.13 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) X-ZM-MESSAGEID: 1628096876783100001 This reverts commit 05bd8db60b35b7706100d9cbbaeb13992965e0f2. It is true that the remote driver client now contains logic for probing the driver to connect to when using modular daemons. This logic, however, only runs when the remote driver is NOT running inside a daemon since we don't want it activated inside libvirtd. Since the same remote driver build is used in all daemons, we can't rely on it in virtproxyd either. Thus we need to keep the virtproxyd probing logic Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Michal Privoznik --- src/remote/remote_daemon_dispatch.c | 77 +++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon= _dispatch.c index 65aa20f7d1..36d4d00b79 100644 --- a/src/remote/remote_daemon_dispatch.c +++ b/src/remote/remote_daemon_dispatch.c @@ -1948,6 +1948,73 @@ 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, @@ -1956,6 +2023,9 @@ remoteDispatchConnectOpen(virNetServer *server G_GNUC= _UNUSED, struct remote_connect_open_args *args) { const char *name; +#ifdef VIRTPROXYD + g_autofree char *probeduri =3D NULL; +#endif unsigned int flags; struct daemonClientPrivate *priv =3D virNetServerClientGetPrivateData(= client); int rv =3D -1; @@ -1984,6 +2054,13 @@ 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