From nobody Sun Apr 28 04:29:18 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=1561629416; cv=none; d=zoho.com; s=zohoarc; b=m/tVKb90oh1N9RZNECvsjsyWRGYb/03eW+ztLYyXw0N0RFGDWpJW0RLpEJMC1v4fRGph/4MtBw3STHY5Zf9d5f34eAuwUcpsxecWmFkE0/x70iYfAnjCfwYtdRXPzVLks7mnP7sr8RHk98JUXPBB+20FaUQ0ZOS+2e1Mb/ALizY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561629416; 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=Zg00T083JL9n0k0nFYeClKH6Wu3VotlTXgze5Tl5otE=; b=U4og6kqW5KniiWBYdq1+GmLDOO9S61h65wMfgj23uj97fnjkmM+ynlxuWQtV72UlUGRKwfvI5/v3WowFXu1rFL0pGp0dFTIryoLD76Jn66ydAWM1cmfbw1t3q8n3hkmNWmvxrU7+M7sRt4XA7nRTsXoXSUwdVLnCyXo9vhdSdm8= 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 1561629416349698.8076273717431; Thu, 27 Jun 2019 02:56:56 -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 C07C22F8BDA; Thu, 27 Jun 2019 09:56:44 +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 9791C60C4E; Thu, 27 Jun 2019 09:56:43 +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 5437219729; Thu, 27 Jun 2019 09:56:42 +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 x5R9sxZG005673 for ; Thu, 27 Jun 2019 05:54:59 -0400 Received: by smtp.corp.redhat.com (Postfix) id 96D286012E; Thu, 27 Jun 2019 09:54:59 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-68.ams2.redhat.com [10.36.112.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8745760126; Thu, 27 Jun 2019 09:54:56 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 27 Jun 2019 10:54:30 +0100 Message-Id: <20190627095452.28217-2-berrange@redhat.com> In-Reply-To: <20190627095452.28217-1-berrange@redhat.com> References: <20190627095452.28217-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 01/23] locking, logging: put a strong dep from admin socket to main socket 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.38]); Thu, 27 Jun 2019 09:56:55 +0000 (UTC) It doesn't make sense to have the admin socket active if the main socket is not running, so bind their lifecycle together. This ensures that if primary socket is stopped, the corresponding admin socket is also stopped. In the reverse, starting the admin socket will also automatically start the primary socket. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: J=C3=A1n Tomko --- src/locking/virtlockd-admin.socket.in | 2 ++ src/logging/virtlogd-admin.socket.in | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/locking/virtlockd-admin.socket.in b/src/locking/virtlockd-= admin.socket.in index f674c492f7..cd7072238c 100644 --- a/src/locking/virtlockd-admin.socket.in +++ b/src/locking/virtlockd-admin.socket.in @@ -1,6 +1,8 @@ [Unit] Description=3DVirtual machine lock manager admin socket Before=3Dlibvirtd.service +BindsTo=3Dvirtlockd.socket +After=3Dvirtlockd.socket =20 [Socket] ListenStream=3D@localstatedir@/run/libvirt/virtlockd-admin-sock diff --git a/src/logging/virtlogd-admin.socket.in b/src/logging/virtlogd-ad= min.socket.in index 5c41dfeb7b..672bd7470d 100644 --- a/src/logging/virtlogd-admin.socket.in +++ b/src/logging/virtlogd-admin.socket.in @@ -1,6 +1,8 @@ [Unit] Description=3DVirtual machine log manager socket Before=3Dlibvirtd.service +BindsTo=3Dvirtlogd.socket +After=3Dvirtlogd.socket =20 [Socket] ListenStream=3D@localstatedir@/run/libvirt/virtlogd-admin-sock --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 04:29:18 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=1561629377; cv=none; d=zoho.com; s=zohoarc; b=Wb5E5hbp7f39P+stU/2kQ3iJqJsLh4Sm7Ae7d/dgURohg/iIaR6laXEITN4u+xuz7WO4sxQqVVNyaWVHSrzVBnyGuD10ALnkWEStYs2gQqstbFafY2gnhOwKnvNoCxHmEi+PR4axVwl8hMniQAFyQDo5eVcxEyLW8DsNK0rORMk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561629377; 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=l9cabrc1n5TlGHQiGVPmpl7kjExLXuSbVjlfdrPLoCo=; b=XO64SW6XuiskKwYIyPmFVlOZhOxB1MREPys8uKxaoa2x6xccQiMsWw1NlRcUQYAwaYAOgf50LAepa9jgNxpktzs33ctXwWfGuHm9ayiY30/2l6w9Z+GeqTwzzC6b27fbwdAbonAgKa5I0l1lBv4g58fLuK6dIAVZRxCjaeEko3k= 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 1561629377765409.41011831579397; Thu, 27 Jun 2019 02:56:17 -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 EADF6356FF; Thu, 27 Jun 2019 09:55:47 +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 86A8419936; Thu, 27 Jun 2019 09:55:39 +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 DBC8F1806B18; Thu, 27 Jun 2019 09:55:04 +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 x5R9t0h5005705 for ; Thu, 27 Jun 2019 05:55:00 -0400 Received: by smtp.corp.redhat.com (Postfix) id B512C6012E; Thu, 27 Jun 2019 09:55:00 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-68.ams2.redhat.com [10.36.112.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id E8188600CC; Thu, 27 Jun 2019 09:54:59 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 27 Jun 2019 10:54:31 +0100 Message-Id: <20190627095452.28217-3-berrange@redhat.com> In-Reply-To: <20190627095452.28217-1-berrange@redhat.com> References: <20190627095452.28217-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 02/23] util: add helper API for getting UNIX path from socket address 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.30]); Thu, 27 Jun 2019 09:56:03 +0000 (UTC) Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: J=C3=A1n Tomko --- src/libvirt_private.syms | 1 + src/util/virsocketaddr.c | 42 ++++++++++++++++++++++++++++++++++++++++ src/util/virsocketaddr.h | 2 ++ 3 files changed, 45 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 34937adc5d..ce614e04bd 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2903,6 +2903,7 @@ virSocketAddrFormat; virSocketAddrFormatFull; virSocketAddrGetIPPrefix; virSocketAddrGetNumNetmaskBits; +virSocketAddrGetPath; virSocketAddrGetPort; virSocketAddrGetRange; virSocketAddrIsNetmask; diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c index 182e18aa8c..7a50cbe040 100644 --- a/src/util/virsocketaddr.c +++ b/src/util/virsocketaddr.c @@ -500,6 +500,7 @@ virSocketAddrSetPort(virSocketAddrPtr addr, int port) return 0; } =20 + /* * virSocketGetPort: * @addr: an initialized virSocketAddrPtr @@ -522,6 +523,47 @@ virSocketAddrGetPort(virSocketAddrPtr addr) return -1; } =20 + +/* + * virSocketGetPath: + * @addr: an initialized virSocketAddrPtr + * + * Returns the UNIX socket path of the given virtSocketAddr + * + * Returns -1 if @addr is invalid or does not refer to an + * address of type AF_UNIX; + */ +char * +virSocketAddrGetPath(virSocketAddrPtr addr ATTRIBUTE_UNUSED) +{ +#ifndef WIN32 + char *path =3D NULL; + if (addr =3D=3D NULL) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("No socket address provided")); + return NULL; + } + + if (addr->data.sa.sa_family !=3D AF_UNIX) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("UNIX socket address is required")); + return NULL; + } + + if (VIR_STRNDUP(path, + addr->data.un.sun_path, + sizeof(addr->data.un.sun_path)) < 0) + return NULL; + + return path; +#else + virReportError(VIR_ERR_NO_SUPPORT, "%s", + _("UNIX sockets not supported on this platform")); + return NULL; +#endif +} + + /** * virSocketAddrIsNetmask: * @netmask: the netmask address diff --git a/src/util/virsocketaddr.h b/src/util/virsocketaddr.h index b2ecb3c748..9dbd8caa0d 100644 --- a/src/util/virsocketaddr.h +++ b/src/util/virsocketaddr.h @@ -108,6 +108,8 @@ char *virSocketAddrFormatFull(const virSocketAddr *addr, bool withService, const char *separator); =20 +char *virSocketAddrGetPath(virSocketAddrPtr addr); + int virSocketAddrSetPort(virSocketAddrPtr addr, int port); =20 int virSocketAddrGetPort(virSocketAddrPtr addr); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 04:29:18 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=1561629367; cv=none; d=zoho.com; s=zohoarc; b=UfJ8Q7F3CXtQ1u8GT8vbYo16rP9s7GOTYqZJpBEJZwB3OiV42FXsefpEXk88U7tY7cdH3XmqDEpJhWCDsZ6iR2Nm8pvMULYE8cOhnPR2Awbc8ljt9flk/p3HMkWpRsqVztzYQKG1Je5HF4DVyo/zxCvIeWjbP7BB8EreUv7AQMw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561629367; 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=K8jtq+FxK9GWnQEHmI/nlXou1L0VLx27wvelqMi5KA4=; b=JpUYk3Hw7aJuqixduvrNFg5kZC7AsC3B6AUZnBAOStluGP29evDSyqdr79IgV+GLM/nVzW4CdCAW3LbuvNknZsNQ0NnwwFfhI7CaeBdDrV7MA6KyD4QjcCuCgHzm3x13Lzp40senN1t5VALnv52B7mVfZ0kwiPNbl+kNJ7gQBuY= 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 1561629367047195.4620478149966; Thu, 27 Jun 2019 02:56:07 -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 222F8300194A; Thu, 27 Jun 2019 09:55:44 +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 4A1235D719; Thu, 27 Jun 2019 09:55:36 +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 1527219725; Thu, 27 Jun 2019 09:55: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 x5R9t3Ge005764 for ; Thu, 27 Jun 2019 05:55:03 -0400 Received: by smtp.corp.redhat.com (Postfix) id 517CB60126; Thu, 27 Jun 2019 09:55:03 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-68.ams2.redhat.com [10.36.112.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4FC0E600CC; Thu, 27 Jun 2019 09:55:00 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 27 Jun 2019 10:54:32 +0100 Message-Id: <20190627095452.28217-4-berrange@redhat.com> In-Reply-To: <20190627095452.28217-1-berrange@redhat.com> References: <20190627095452.28217-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 03/23] rpc: add helper API for getting UNIX path from socket object 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]); Thu, 27 Jun 2019 09:56:05 +0000 (UTC) Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: J=C3=A1n Tomko --- src/libvirt_remote.syms | 1 + src/rpc/virnetsocket.c | 8 ++++++++ src/rpc/virnetsocket.h | 1 + 3 files changed, 10 insertions(+) diff --git a/src/libvirt_remote.syms b/src/libvirt_remote.syms index b63eac123f..99fe3dd07c 100644 --- a/src/libvirt_remote.syms +++ b/src/libvirt_remote.syms @@ -219,6 +219,7 @@ virNetSocketCheckProtocols; virNetSocketClose; virNetSocketDupFD; virNetSocketGetFD; +virNetSocketGetPath; virNetSocketGetPort; virNetSocketGetSELinuxContext; virNetSocketGetUNIXIdentity; diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c index bfa1952989..254f39c4ec 100644 --- a/src/rpc/virnetsocket.c +++ b/src/rpc/virnetsocket.c @@ -1408,6 +1408,14 @@ bool virNetSocketHasPassFD(virNetSocketPtr sock) return hasPassFD; } =20 +char *virNetSocketGetPath(virNetSocketPtr sock) +{ + char *path =3D NULL; + virObjectLock(sock); + path =3D virSocketAddrGetPath(&sock->localAddr); + virObjectUnlock(sock); + return path; +} =20 int virNetSocketGetPort(virNetSocketPtr sock) { diff --git a/src/rpc/virnetsocket.h b/src/rpc/virnetsocket.h index 343c8f43e0..de5a465cde 100644 --- a/src/rpc/virnetsocket.h +++ b/src/rpc/virnetsocket.h @@ -127,6 +127,7 @@ bool virNetSocketIsLocal(virNetSocketPtr sock); =20 bool virNetSocketHasPassFD(virNetSocketPtr sock); =20 +char *virNetSocketGetPath(virNetSocketPtr sock); int virNetSocketGetPort(virNetSocketPtr sock); =20 int virNetSocketGetUNIXIdentity(virNetSocketPtr sock, --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 04:29:18 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=1561629406; cv=none; d=zoho.com; s=zohoarc; b=Gro3ZSIbXiESux0VtpUU9FDBV40M9CbOf8IQXORcdBelgzbDOaODfARFlL7DZ1m+9SJR9LREwMo7AvCJDo0NuL0UoDTQJfPy1bU215/CNKQqtcFJd63L4RZn2az92aBv+4/WtYJeePuWT/fZFO5QYu4hRndVEImL/WH4rEYjqAs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561629406; 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=doIutCusafSCjzXLHnUG0lXY7Wh8uvv+v7pKruz+83k=; b=eyoNcruhHnt/XEJVqXrHsYUes7eN1V15jQIvb/Wc2NUlTnPmhxUOTcOp2rWWG76oV5vNWYlvLfojbitjf9dn/O/ejeDx77S0ZNaSEdeERJaldTzxcHEKE1E0Wb2ErMQacbIFUkdtOb2u0v5l+f4Jx7UfLOkUyznkdN44djR8o7Y= 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 15616294065511005.5629150909921; Thu, 27 Jun 2019 02:56:46 -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 BCE722F8BDF; Thu, 27 Jun 2019 09:56:44 +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 96F79600CC; Thu, 27 Jun 2019 09:56:44 +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 D32BA1806B1C; Thu, 27 Jun 2019 09:56:41 +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 x5R9t4AT005809 for ; Thu, 27 Jun 2019 05:55:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id DDAA76013C; Thu, 27 Jun 2019 09:55:04 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-68.ams2.redhat.com [10.36.112.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id D033460126; Thu, 27 Jun 2019 09:55:03 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 27 Jun 2019 10:54:33 +0100 Message-Id: <20190627095452.28217-5-berrange@redhat.com> In-Reply-To: <20190627095452.28217-1-berrange@redhat.com> References: <20190627095452.28217-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 04/23] util: add VIR_AUTOSTRUCT for directly calling a struct free function 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.38]); Thu, 27 Jun 2019 09:56:45 +0000 (UTC) The current VIR_AUTOPTR macro assumes that the struct needs to have a auto-free function auto-generated to call the real free function. The new VIR_AUTOSTRUCT macro allows for structs which already have a free function which takes a pointer to a pointer to the struct and can thus be used directly for auto-cleanup. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: J=C3=A1n Tomko --- src/util/viralloc.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/util/viralloc.h b/src/util/viralloc.h index 2b82096fde..5de18b9ea0 100644 --- a/src/util/viralloc.h +++ b/src/util/viralloc.h @@ -614,3 +614,16 @@ void virAllocTestHook(void (*func)(int, void*), void *= data); * when the variable goes out of scope. */ #define VIR_AUTOFREE(type) __attribute__((cleanup(virFree))) type + +/** + * VIR_AUTOSTRUCT: + * @type: type of the struct variable to be freed automatically + * + * Macro to automatically free the memory allocated to + * the struct variable declared with it by calling vir$STRUCTFree + * when the variable goes out of scope. + * + * The vir$STRUCTFree function must take a pointer to a pointer + * to the struct. + */ +#define VIR_AUTOSTRUCT(type) __attribute__((cleanup(type ## Free))) type --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 04:29:18 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=1561629410; cv=none; d=zoho.com; s=zohoarc; b=QIuzjtN2ZnvjctthezR37Jhjp44Y733AvfvgYvBdfeTOeukQq0m34RoRCG7jJ1HNf7fhJ36BjH80Xz8ikxSd2uCr6WpCPNudFwabLlCbvxGvCPV/WVUNJTm9plbmq7FOSiWFQTZL40A8p0Ao+F6S8DjPrPuXqM/WI5136cYTWbc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561629410; 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=nvKT6K7XcJF3z/gXIvPIwPEnWjNAbq+LulAfqsWGjbU=; b=NSfXQCLKeTqxnQlfywQlXZc6uDopNMBoNHKyZZyktYIMlsM/cIcds65/iOEthJSlrFMRq5If7YKQb0N57NoclqmrU+0uFIeWrkqVa+k5T6rrh35lT4LBfybV+Viz3DOLVgHaYvwBJEzroi9/xDPEZf9gOBvp8FXc9pqL1qA2dCc= 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 1561629410905304.02195385731284; Thu, 27 Jun 2019 02:56:50 -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 26E7CC00732A; Thu, 27 Jun 2019 09:56:44 +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 E083360BE0; Thu, 27 Jun 2019 09:56:42 +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 99A691806B1B; Thu, 27 Jun 2019 09:56:39 +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 x5R9t6j5005844 for ; Thu, 27 Jun 2019 05:55:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id 305CA6012E; Thu, 27 Jun 2019 09:55:06 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-68.ams2.redhat.com [10.36.112.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5E45A600CC; Thu, 27 Jun 2019 09:55:05 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 27 Jun 2019 10:54:34 +0100 Message-Id: <20190627095452.28217-6-berrange@redhat.com> In-Reply-To: <20190627095452.28217-1-berrange@redhat.com> References: <20190627095452.28217-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 05/23] util: add API for resolving socket service names 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.32]); Thu, 27 Jun 2019 09:56:49 +0000 (UTC) The getservent() APIs are not re-entrant safe so cannot be used in any threaded program. Add a wrapper around getaddrinfo() for resolving the service names to a port number. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: J=C3=A1n Tomko --- src/libvirt_private.syms | 1 + src/util/virsocketaddr.c | 51 ++++++++++++++++++++++++++++++++++++++++ src/util/virsocketaddr.h | 2 ++ 3 files changed, 54 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index ce614e04bd..1adf735a38 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2919,6 +2919,7 @@ virSocketAddrParseIPv4; virSocketAddrParseIPv6; virSocketAddrPrefixToNetmask; virSocketAddrPTRDomain; +virSocketAddrResolveService; virSocketAddrSetIPv4Addr; virSocketAddrSetIPv4AddrNetOrder; virSocketAddrSetIPv6Addr; diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c index 7a50cbe040..790bc0ebec 100644 --- a/src/util/virsocketaddr.c +++ b/src/util/virsocketaddr.c @@ -235,6 +235,57 @@ virSocketAddrParseIPv6(virSocketAddrPtr addr, const ch= ar *val) return virSocketAddrParse(addr, val, AF_INET6); } =20 +/** + * virSocketAddrResolveService: + * @service: a service name or port number + * + * Resolve a service, which might be a plain port or service name, + * into a port number for IPv4/IPv6 usage + * + * Returns a numberic port number + */ +int virSocketAddrResolveService(const char *service) +{ + struct addrinfo *res, *tmp; + struct addrinfo hints; + int err; + int port =3D -1; + + memset(&hints, 0, sizeof(hints)); + + if ((err =3D getaddrinfo(NULL, service, &hints, &res)) !=3D 0) { + virReportError(VIR_ERR_SYSTEM_ERROR, + _("Cannot parse socket service '%s': %s"), + service, gai_strerror(err)); + return -1; + } + + tmp =3D res; + while (tmp) { + if (tmp->ai_family =3D=3D AF_INET) { + struct sockaddr_in in; + memcpy(&in, tmp->ai_addr, sizeof(in)); + port =3D in.sin_port; + goto cleanup; + } else if (tmp->ai_family =3D=3D AF_INET6) { + struct sockaddr_in6 in; + memcpy(&in, tmp->ai_addr, sizeof(in)); + port =3D in.sin6_port; + goto cleanup; + } + tmp++; + } + + virReportError(VIR_ERR_SYSTEM_ERROR, + _("No matches for socket service '%s': %s"), + service, gai_strerror(err)); + + cleanup: + freeaddrinfo(res); + + return port; +} + /* * virSocketAddrSetIPv4AddrNetOrder: * @addr: the location to store the result diff --git a/src/util/virsocketaddr.h b/src/util/virsocketaddr.h index 9dbd8caa0d..bb97e6e3a0 100644 --- a/src/util/virsocketaddr.h +++ b/src/util/virsocketaddr.h @@ -98,6 +98,8 @@ int virSocketAddrParseIPv4(virSocketAddrPtr addr, int virSocketAddrParseIPv6(virSocketAddrPtr addr, const char *val); =20 +int virSocketAddrResolveService(const char *service); + void virSocketAddrSetIPv4AddrNetOrder(virSocketAddrPtr s, uint32_t addr); void virSocketAddrSetIPv4Addr(virSocketAddrPtr s, uint32_t addr); void virSocketAddrSetIPv6AddrNetOrder(virSocketAddrPtr s, uint32_t addr[4]= ); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 04:29:18 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=1561629425; cv=none; d=zoho.com; s=zohoarc; b=HnAPDrlEfmZtoNvSPTljZgT+OjHG0N+oHn2/XFdB0JLUJOrXnaLgnlucgUHylxvdhvSi1cIteUCYpxZQBYHhu6hEGKcVd0i9HLgQjIU0OG4wQmwH6r2IRyJkOdsZOGQ0ahMu+j/T46kpRKV33gK9xkmRVWsZbDJfcAEx65VTghE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561629425; 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=WBgqGsKaZyJ1ejog5U+YX1qw7TDwPlI+XJyk3D5F6Zo=; b=Kj0o9VulNXcB7yTdQKwOTfA+Cin5Fvcr7Z9R3ksrtoqcPAHIlDWfoRKzdOsxMdVicw+ydxaotFNCdGNvH50hj/DAhFmzKPqmCdLsGwLJJSa5ma9Ml73NwUWbETUN9nQiMlF/0ba/r3UELMcjbnF4nFAzmPsJ3vQJzf3hFQlVOg4= 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 1561629425602708.9925263157996; Thu, 27 Jun 2019 02:57:05 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E920F3082E64; Thu, 27 Jun 2019 09:56:58 +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 BFE1B1001925; Thu, 27 Jun 2019 09:56:56 +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 85E151806B1F; Thu, 27 Jun 2019 09:56:55 +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 x5R9t9lc005934 for ; Thu, 27 Jun 2019 05:55:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id AB02B6012E; Thu, 27 Jun 2019 09:55:09 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-68.ams2.redhat.com [10.36.112.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2018160126; Thu, 27 Jun 2019 09:55:06 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 27 Jun 2019 10:54:35 +0100 Message-Id: <20190627095452.28217-7-berrange@redhat.com> In-Reply-To: <20190627095452.28217-1-berrange@redhat.com> References: <20190627095452.28217-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 06/23] util: add APIs for facilitating use of systemd activation FDs 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.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Thu, 27 Jun 2019 09:57:04 +0000 (UTC) When receiving multiple FDs from systemd during service activation it is neccessary to identify which purpose each FD is used for. While this could be inferred by looking for the specific IP ports or UNIX socket paths, this requires the systemd config to always match what is expected by the code. Using systemd FD names we can remove this restriction and simply identify FDs based on an arbitrary name. The FD names are passed by systemd in the LISTEN_FDNAMES env variable which is populated with the socket unit file names, unless overriden by using the FileDescriptorName setting. This is supported since the system 227 release and unfortunately RHEL7 lacks this version. Thus the code has some back compat support whereby we look at the TCP ports or the UNIX socket paths to identify what socket maps to which name. This back compat code is written such that is it easly deleted when we are able to mandate newer systemd. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: J=C3=A1n Tomko --- src/libvirt_private.syms | 5 + src/util/virsystemd.c | 362 +++++++++++++++++++++++++++++++++++++++ src/util/virsystemd.h | 30 ++++ tests/virsystemdtest.c | 169 ++++++++++++++++++ 4 files changed, 566 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 1adf735a38..ee1073e680 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3102,6 +3102,11 @@ virSysinfoReadS390; =20 =20 # util/virsystemd.h +virSystemdGetActivation; +virSystemdActivationClaimFDs; +virSystemdActivationComplete; +virSystemdActivationFree; +virSystemdActivationHasName; virSystemdCanHibernate; virSystemdCanHybridSleep; virSystemdCanSuspend; diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c index 3f03e3bd63..ae8401343d 100644 --- a/src/util/virsystemd.c +++ b/src/util/virsystemd.c @@ -39,6 +39,8 @@ #include "virlog.h" #include "virerror.h" #include "virfile.h" +#include "virhash.h" +#include "virsocketaddr.h" =20 #define VIR_FROM_THIS VIR_FROM_SYSTEMD =20 @@ -48,6 +50,18 @@ VIR_LOG_INIT("util.systemd"); # define MSG_NOSIGNAL 0 #endif =20 +struct _virSystemdActivation { + virHashTablePtr fds; +}; + +typedef struct _virSystemdActivationEntry virSystemdActivationEntry; +typedef virSystemdActivationEntry *virSystemdActivationEntryPtr; + +struct _virSystemdActivationEntry { + int *fds; + size_t nfds; +}; + static void virSystemdEscapeName(virBufferPtr buf, const char *name) { @@ -561,3 +575,351 @@ int virSystemdCanHybridSleep(bool *result) { return virSystemdPMSupportTarget("CanHybridSleep", result); } + + +static void +virSystemdActivationEntryFree(void *data, const void *name) +{ + virSystemdActivationEntryPtr ent =3D data; + size_t i; + + VIR_DEBUG("Closing activation FDs for %s", (const char *)name); + for (i =3D 0; i < ent->nfds; i++) { + VIR_DEBUG("Closing activation FD %d", ent->fds[i]); + VIR_FORCE_CLOSE(ent->fds[i]); + } + + VIR_FREE(ent->fds); + VIR_FREE(ent); +} + + +static int +virSystemdActivationAddFD(virSystemdActivationPtr act, + const char *name, + int fd) +{ + virSystemdActivationEntryPtr ent =3D virHashLookup(act->fds, name); + + if (!ent) { + if (VIR_ALLOC(ent) < 0) + return -1; + + if (VIR_ALLOC_N(ent->fds, 1) < 0) { + virSystemdActivationEntryFree(ent, name); + return -1; + } + + ent->fds[ent->nfds++] =3D fd; + + VIR_DEBUG("Record first FD %d with name %s", fd, name); + if (virHashAddEntry(act->fds, name, ent) < 0) { + virSystemdActivationEntryFree(ent, name); + return -1; + } + + return 0; + } + + if (VIR_EXPAND_N(ent->fds, ent->nfds, 1) < 0) + return -1; + + VIR_DEBUG("Record extra FD %d with name %s", fd, name); + ent->fds[ent->nfds - 1] =3D fd; + + return 0; +} + + +static int +virSystemdActivationInitFromNames(virSystemdActivationPtr act, + int nfds, + const char *fdnames) +{ + VIR_AUTOSTRINGLIST fdnamelistptr =3D NULL; + char **fdnamelist; + size_t nfdnames; + size_t i; + int nextfd =3D STDERR_FILENO + 1; + + VIR_DEBUG("FD names %s", fdnames); + + if (!(fdnamelistptr =3D virStringSplitCount(fdnames, ":", 0, &nfdnames= ))) + goto error; + + if (nfdnames !=3D nfds) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Expecting %d FD names but got %zu"), + nfds, nfdnames); + goto error; + } + + fdnamelist =3D fdnamelistptr; + while (nfds) { + if (virSystemdActivationAddFD(act, *fdnamelist, nextfd) < 0) + goto error; + + fdnamelist++; + nextfd++; + nfds--; + } + + return 0; + + error: + for (i =3D 0; i < nfds; i++) { + int fd =3D nextfd + i; + VIR_FORCE_CLOSE(fd); + } + return -1; +} + + +/* + * Back compat for systemd < v227 which lacks LISTEN_FDNAMES. + * Delete when min systemd is increased ie RHEL7 dropped + */ +static int +virSystemdActivationInitFromMap(virSystemdActivationPtr act, + int nfds, + virSystemdActivationMap *map, + size_t nmap) +{ + int nextfd =3D STDERR_FILENO + 1; + size_t i; + + while (nfds) { + virSocketAddr addr; + const char *name =3D NULL; + + memset(&addr, 0, sizeof(addr)); + + addr.len =3D sizeof(addr.data); + if (getsockname(nextfd, &addr.data.sa, &addr.len) < 0) { + virReportSystemError(errno, "%s", _("Unable to get local socke= t name")); + goto error; + } + + for (i =3D 0; i < nmap && !name; i++) { + if (map[i].name =3D=3D NULL) + continue; + + if (addr.data.sa.sa_family =3D=3D AF_INET) { + if (map[i].family =3D=3D AF_INET && + addr.data.inet4.sin_port =3D=3D htons(map[i].port)) + name =3D map[i].name; + } else if (addr.data.sa.sa_family =3D=3D AF_INET6) { + /* NB use of AF_INET here is correct. The "map" struct + * only refers to AF_INET. The socket may be AF_INET + * or AF_INET6 + */ + if (map[i].family =3D=3D AF_INET && + addr.data.inet6.sin6_port =3D=3D htons(map[i].port)) + name =3D map[i].name; +#ifndef WIN32 + } else if (addr.data.sa.sa_family =3D=3D AF_UNIX) { + if (map[i].family =3D=3D AF_UNIX && + STREQLEN(map[i].path, + addr.data.un.sun_path, + sizeof(addr.data.un.sun_path))) + name =3D map[i].name; +#endif + } else { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unexpected socket family %d"), + addr.data.sa.sa_family); + goto error; + } + } + + if (!name) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Cannot find name for FD %d socket family %d"= ), + nextfd, addr.data.sa.sa_family); + goto error; + } + + if (virSystemdActivationAddFD(act, name, nextfd) < 0) + goto error; + + nfds--; + nextfd++; + } + + return 0; + + error: + for (i =3D 0; i < nfds; i++) { + int fd =3D nextfd + i; + VIR_FORCE_CLOSE(fd); + } + return -1; +} + + +static virSystemdActivationPtr +virSystemdActivationNew(virSystemdActivationMap *map, + size_t nmap, + int nfds) +{ + virSystemdActivationPtr act; + const char *fdnames; + + VIR_DEBUG("Activated with %d FDs", nfds); + if (VIR_ALLOC(act) < 0) + return NULL; + + if (!(act->fds =3D virHashCreate(10, virSystemdActivationEntryFree))) + goto error; + + fdnames =3D virGetEnvAllowSUID("LISTEN_FDNAMES"); + if (fdnames) { + if (virSystemdActivationInitFromNames(act, nfds, fdnames) < 0) + goto error; + } else { + if (virSystemdActivationInitFromMap(act, nfds, map, nmap) < 0) + goto error; + } + + VIR_DEBUG("Created activation object for %d FDs", nfds); + return act; + + error: + virSystemdActivationFree(&act); + return NULL; +} + + +/** + * virSystemdGetActivation: + * @map: mapping of socket addresses to names + * @nmap: number of entries in @map + * @act: filled with allocated activation object + * + * Acquire an object for handling systemd activation. + * If no activation FDs have been provided the returned object + * will be NULL, indicating normal sevice setup can be performed + * If the returned object is non-NULL then at least one file + * descriptor will be present. No normal service setup should + * be performed. + * + * Returns: 0 on success, -1 on failure + */ +int +virSystemdGetActivation(virSystemdActivationMap *map, + size_t nmap, + virSystemdActivationPtr *act) +{ + int nfds =3D 0; + + if ((nfds =3D virGetListenFDs()) < 0) + return -1; + + if (nfds =3D=3D 0) { + VIR_DEBUG("No activation FDs present"); + *act =3D NULL; + return 0; + } + + *act =3D virSystemdActivationNew(map, nmap, nfds); + return 0; +} + + +/** + * virSystemdActivationHasName: + * @act: the activation object + * @name: the file descriptor name + * + * Check whether there is a file descriptor present + * for the requested name. + * + * Returns: true if a FD is present, false otherwise + */ +bool +virSystemdActivationHasName(virSystemdActivationPtr act, + const char *name) +{ + return virHashLookup(act->fds, name) !=3D NULL; +} + + +/** + * virSystemdActivationComplete: + * @act: the activation object + * + * Indicate that processing of activation has been + * completed. All provided file descriptors should + * have been claimed. If any are unclaimed then + * an error will be reported + * + * Returns: 0 on success, -1 if some FDs are unclaimed + */ +int +virSystemdActivationComplete(virSystemdActivationPtr act) +{ + if (virHashSize(act->fds) !=3D 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Some activation file descriptors are unclaimed")= ); + return -1; + } + + return 0; +} + + +/** + * virSystemdActivationClaimFDs: + * @act: the activation object + * @name: the file descriptor name + * @fds: to be filled with claimed FDs + * @nfds: to be filled with number of FDs in @fds + * + * Claims the file descriptors associated with + * @name. + * + * The caller is responsible for closing all + * returned file descriptors when they are no + * longer required. The caller must also free + * the array memory in @fds. + */ +void +virSystemdActivationClaimFDs(virSystemdActivationPtr act, + const char *name, + int **fds, + size_t *nfds) +{ + virSystemdActivationEntryPtr ent =3D virHashSteal(act->fds, name); + + if (!ent) { + *fds =3D NULL; + *nfds =3D 0; + VIR_DEBUG("No FD with name %s", name); + return; + } + + VIR_DEBUG("Found %zu FDs with name %s", ent->nfds, name); + *fds =3D ent->fds; + *nfds =3D ent->nfds; + + VIR_FREE(ent); +} + + +/** + * virSystemdActivationFree: + * @act: the activation object + * + * Free memory and close unclaimed file descriptors + * associated with the activation object + */ +void +virSystemdActivationFree(virSystemdActivationPtr *act) +{ + if (!*act) + return; + + virHashFree((*act)->fds); + + VIR_FREE(*act); +} diff --git a/src/util/virsystemd.h b/src/util/virsystemd.h index db4ecbff60..2858732d00 100644 --- a/src/util/virsystemd.h +++ b/src/util/virsystemd.h @@ -23,6 +23,20 @@ =20 #include "internal.h" =20 +typedef struct _virSystemdActivation virSystemdActivation; +typedef virSystemdActivation *virSystemdActivationPtr; + +/* + * Back compat for systemd < v227 which lacks LISTEN_FDNAMES. + * Delete when min systemd is increased ie RHEL7 dropped + */ +typedef struct _virSystemdActivationMap { + const char *name; + int family; + int port; /* if family =3D=3D AF_INET/AF_INET6 */ + const char *path; /* if family =3D=3D AF_UNIX */ +} virSystemdActivationMap; + char *virSystemdMakeScopeName(const char *name, const char *drivername, bool legacy_behaviour); @@ -49,3 +63,19 @@ int virSystemdCanHibernate(bool *result); int virSystemdCanHybridSleep(bool *result); =20 char *virSystemdGetMachineNameByPID(pid_t pid); + +int virSystemdGetActivation(virSystemdActivationMap *map, + size_t nmap, + virSystemdActivationPtr *act); + +bool virSystemdActivationHasName(virSystemdActivationPtr act, + const char *name); + +int virSystemdActivationComplete(virSystemdActivationPtr act); + +void virSystemdActivationClaimFDs(virSystemdActivationPtr act, + const char *name, + int **fds, + size_t *nfds); + +void virSystemdActivationFree(virSystemdActivationPtr *act); diff --git a/tests/virsystemdtest.c b/tests/virsystemdtest.c index 82c02decd1..edca45d9f0 100644 --- a/tests/virsystemdtest.c +++ b/tests/virsystemdtest.c @@ -31,6 +31,8 @@ # include "virdbus.h" # include "virlog.h" # include "virmock.h" +# include "rpc/virnetsocket.h" +# include "intprops.h" # define VIR_FROM_THIS VIR_FROM_NONE =20 VIR_LOG_INIT("tests.systemdtest"); @@ -507,6 +509,166 @@ static int testPMSupportSystemdNotRunning(const void = *opaque) return 0; } =20 + +static int +testActivationCreateFDs(virNetSocketPtr *sockUNIX, + virNetSocketPtr **sockIP, + size_t *nsockIP) +{ + *sockUNIX =3D NULL; + *sockIP =3D NULL; + *nsockIP =3D 0; + + if (virNetSocketNewListenUNIX("virsystemdtest.sock", + 0777, + 0, + 0, + sockUNIX) < 0) + return -1; + + if (virNetSocketNewListenTCP("localhost", + NULL, + AF_UNSPEC, + sockIP, + nsockIP) < 0) { + virObjectUnref(*sockUNIX); + return -1; + } + + return 0; +} + + +static int +testActivation(bool useNames) +{ + virNetSocketPtr sockUNIX; + virNetSocketPtr *sockIP; + size_t nsockIP; + int ret =3D -1; + size_t i; + const char *names2 =3D "demo-unix.socket:demo-ip.socket"; + const char *names3 =3D "demo-unix.socket:demo-ip.socket:demo-ip.socket= "; + char nfdstr[INT_BUFSIZE_BOUND(size_t)]; + char pidstr[INT_BUFSIZE_BOUND(pid_t)]; + virSystemdActivationMap map[2]; + int *fds =3D NULL; + size_t nfds =3D 0; + VIR_AUTOSTRUCT(virSystemdActivation) *act =3D NULL; + + if (testActivationCreateFDs(&sockUNIX, &sockIP, &nsockIP) < 0) + return -1; + + if (nsockIP !=3D 1 && nsockIP !=3D 2) { + fprintf(stderr, "Got %zu IP sockets but expected only 1 or 2\n", n= sockIP); + goto cleanup; + } + + snprintf(nfdstr, sizeof(nfdstr), "%zu", 1 + nsockIP); + snprintf(pidstr, sizeof(pidstr), "%lld", (long long)getpid()); + + setenv("LISTEN_FDS", nfdstr, 1); + setenv("LISTEN_PID", pidstr, 1); + + if (useNames) + setenv("LISTEN_FDNAMES", nsockIP =3D=3D 1 ? names2 : names3, 1); + else + unsetenv("LISTEN_FDNAMES"); + + map[0].name =3D "demo-unix.socket"; + map[0].family =3D AF_UNIX; + map[0].path =3D virNetSocketGetPath(sockUNIX); + + map[1].name =3D "demo-ip.socket"; + map[1].family =3D AF_INET; + map[1].port =3D virNetSocketGetPort(sockIP[0]); + + if (virSystemdGetActivation(map, ARRAY_CARDINALITY(map), &act) < 0) + goto cleanup; + + if (act =3D=3D NULL) { + fprintf(stderr, "Activation object was not created: %s", virGetLas= tErrorMessage()); + goto cleanup; + } + + if (virSystemdActivationComplete(act) =3D=3D 0) { + fprintf(stderr, "Activation did not report unclaimed FDs"); + goto cleanup; + } + + virSystemdActivationClaimFDs(act, "demo-unix.socket", &fds, &nfds); + + if (nfds !=3D 1) { + fprintf(stderr, "Expected 1 UNIX fd, but got %zu\n", nfds); + goto cleanup; + } + VIR_FREE(fds); + + virSystemdActivationClaimFDs(act, "demo-ip.socket", &fds, &nfds); + + if (nfds !=3D nsockIP) { + fprintf(stderr, "Expected %zu IP fd, but got %zu\n", nsockIP, nfds= ); + goto cleanup; + } + VIR_FREE(fds); + + virSystemdActivationClaimFDs(act, "demo-ip-alt.socket", &fds, &nfds); + + if (nfds !=3D 0) { + fprintf(stderr, "Expected 0 IP fd, but got %zu\n", nfds); + goto cleanup; + } + + if (virSystemdActivationComplete(act) < 0) { + fprintf(stderr, "Action was not complete: %s\n", virGetLastErrorMe= ssage()); + goto cleanup; + } + + ret =3D 0; + cleanup: + virObjectUnref(sockUNIX); + for (i =3D 0; i < nsockIP; i++) + virObjectUnref(sockIP[i]); + VIR_FREE(sockIP); + VIR_FREE(fds); + return ret; +} + + +static int +testActivationEmpty(const void *opaque ATTRIBUTE_UNUSED) +{ + virSystemdActivationPtr act; + + unsetenv("LISTEN_FDS"); + + if (virSystemdGetActivation(NULL, 0, &act) < 0) + return -1; + + if (act !=3D NULL) { + fprintf(stderr, "Unexpectedly got activation object"); + virSystemdActivationFree(&act); + return -1; + } + + return 0; +} + + +static int +testActivationFDNames(const void *opaque ATTRIBUTE_UNUSED) +{ + return testActivation(true); +} + + +static int +testActivationFDAddrs(const void *opaque ATTRIBUTE_UNUSED) +{ + return testActivation(false); +} + + static int mymain(void) { @@ -598,6 +760,13 @@ mymain(void) TESTS_PM_SUPPORT_HELPER("canHibernate", &virSystemdCanHibernate); TESTS_PM_SUPPORT_HELPER("canHybridSleep", &virSystemdCanHybridSleep); =20 + if (virTestRun("Test activation empty", testActivationEmpty, NULL) < 0) + ret =3D -1; + if (virTestRun("Test activation names", testActivationFDNames, NULL) <= 0) + ret =3D -1; + if (virTestRun("Test activation addrs", testActivationFDAddrs, NULL) <= 0) + ret =3D -1; + return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; } =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 04:29:18 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=1561629435; cv=none; d=zoho.com; s=zohoarc; b=IFtALZ1j29XPEjyy7Zgcd/kS7MNa/wYZ4qwSWZutrS9yaSgn8lnPUxAuOu/9xL3oXfkW9fVNhjBYdCcrJetglf7IZRR+AnyGNNDLj/zFLmk6b7eC4aqYj02aBa5MtoeVVEobXir6E3uv8Txf3LKLMlX9c1uhCVklqwPNsT7wydY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561629435; 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=GeCatd2MAcquqvQOrNezcPPfpAXXt+OmMBLKUFrA6xI=; b=OjeNtgqzouPAMBxz/4vE31uXDY1ZAHjm/+syyeSY+nV/JWzuO8W/+1gf+ZCbSG1lzhlrtaAPTnwdPXxsBwS+lMzUUw4Wlg+S7QVjcQsv6Ed5eCT15XcqPUcUHdxxMx26NtgkuL1g3ja5CbHwg9SMko6l9XsNaZNzsjG80slHmWM= 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 1561629435086120.28690423108378; Thu, 27 Jun 2019 02:57:15 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id E61D43086204; Thu, 27 Jun 2019 09:57: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 B94375C22F; Thu, 27 Jun 2019 09:57: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 780EB1972E; Thu, 27 Jun 2019 09:57:04 +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 x5R9tBxO005976 for ; Thu, 27 Jun 2019 05:55:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 14A3460126; Thu, 27 Jun 2019 09:55:11 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-68.ams2.redhat.com [10.36.112.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 49FD9600CC; Thu, 27 Jun 2019 09:55:09 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 27 Jun 2019 10:54:36 +0100 Message-Id: <20190627095452.28217-8-berrange@redhat.com> In-Reply-To: <20190627095452.28217-1-berrange@redhat.com> References: <20190627095452.28217-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/23] rpc: ensure all sockets bind to same port when service is NULL 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Thu, 27 Jun 2019 09:57:08 +0000 (UTC) When the service passed to getaddrinfo is NULL the kernel will choose a free port to bind to. In a dual stack though we will get separate sockets for IPv4 and IPv6 and we need them to bind to the same port number. Thus once the kerel has auto-selected a port for the first socket, we must disable auto-select for subsequent IP sockets and force reuse of the first port. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/rpc/virnetsocket.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c index 254f39c4ec..fc13b1654a 100644 --- a/src/rpc/virnetsocket.c +++ b/src/rpc/virnetsocket.c @@ -311,6 +311,7 @@ int virNetSocketNewListenTCP(const char *nodename, int socketErrno =3D 0; int bindErrno =3D 0; virSocketAddr tmp_addr; + int port =3D 0; =20 *retsocks =3D NULL; *nretsocks =3D 0; @@ -379,7 +380,24 @@ int virNetSocketNewListenTCP(const char *nodename, } #endif =20 - if (bind(fd, runp->ai_addr, runp->ai_addrlen) < 0) { + addr.len =3D runp->ai_addrlen; + memcpy(&addr.data.sa, runp->ai_addr, runp->ai_addrlen); + + /* When service is NULL, we let the kernel auto-select the + * port. Once we've selected a port for one IP protocol + * though, we want to ensure we pick the same port for the + * other IP protocol + */ + if (port !=3D 0 && service =3D=3D NULL) { + if (runp->ai_addr->sa_family =3D=3D AF_INET) { + addr.data.inet4.sin_port =3D port; + } else if (addr.data.sa.sa_family =3D=3D AF_INET6) { + addr.data.inet6.sin6_port =3D port; + } + VIR_DEBUG("Used saved port %d", port); + } + + if (bind(fd, &addr.data.sa, addr.len) < 0) { if (errno !=3D EADDRINUSE && errno !=3D EADDRNOTAVAIL) { virReportSystemError(errno, "%s", _("Unable to bind to por= t")); goto error; @@ -396,6 +414,14 @@ int virNetSocketNewListenTCP(const char *nodename, goto error; } =20 + if (port =3D=3D 0 && service =3D=3D NULL) { + if (addr.data.sa.sa_family =3D=3D AF_INET) + port =3D addr.data.inet4.sin_port; + else if (addr.data.sa.sa_family =3D=3D AF_INET6) + port =3D addr.data.inet6.sin6_port; + VIR_DEBUG("Saved port %d", port); + } + VIR_DEBUG("%p f=3D%d f=3D%d", &addr, runp->ai_family, addr.data.sa= .sa_family); =20 if (VIR_EXPAND_N(socks, nsocks, 1) < 0) --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 04:29:18 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=1561629429; cv=none; d=zoho.com; s=zohoarc; b=YIiJTVWLBp8icV373PBahB9Rdv8RsNDT8E8MLNBanbUCJ7bTxAShkKETk5ivY605DorH5H/gD9FkjLJZOR32TmKsDwn1f4mxlMB0BTqXcLcf2S2Gds4V4r9/qwfrRLXg/YWWG8cl+wrvrr0dR2qrDU+COiUClSJid10TDgGvJ70= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561629429; 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=EVxT0leP7TnOPJtuiVq6Y8wW62WLgNahn6YrIOPfAyc=; b=kABDAK4wE/G/1BMNVw1DmjHlll+nU2j8CCuP1fvLqVuKRYso+QN2gldsBLkHK0/DaZUsCjFO8uv/c40JhPK0RfWdRLW160Z+ig+cHMjN3AJDOMce1qCcWQsCzCj/FbRcECXbR0CQ8fn7LZ0Oz6210V4sW/PvKlW8Aeq1jrYVdO4= 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 1561629429964909.7583628409445; Thu, 27 Jun 2019 02:57:09 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3DFBC81E00; Thu, 27 Jun 2019 09:57: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 120D110013D9; Thu, 27 Jun 2019 09:57:01 +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 BD9A81806B22; Thu, 27 Jun 2019 09:56:59 +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 x5R9tETL006073 for ; Thu, 27 Jun 2019 05:55:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id E62E8600CC; Thu, 27 Jun 2019 09:55:14 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-68.ams2.redhat.com [10.36.112.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9EA8760126; Thu, 27 Jun 2019 09:55:11 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 27 Jun 2019 10:54:37 +0100 Message-Id: <20190627095452.28217-9-berrange@redhat.com> In-Reply-To: <20190627095452.28217-1-berrange@redhat.com> References: <20190627095452.28217-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 08/23] rpc: refactor RPC service constructors to share more code 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.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 27 Jun 2019 09:57:08 +0000 (UTC) Introduce a virNetServerServiceNewSocket API that allows the various constructors to share more code. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/rpc/virnetserverservice.c | 165 +++++++++++++++------------------- 1 file changed, 74 insertions(+), 91 deletions(-) diff --git a/src/rpc/virnetserverservice.c b/src/rpc/virnetserverservice.c index 97341d1546..69043ccc0e 100644 --- a/src/rpc/virnetserverservice.c +++ b/src/rpc/virnetserverservice.c @@ -128,14 +128,14 @@ virNetServerServiceNewFDOrUNIX(const char *path, } =20 =20 -virNetServerServicePtr virNetServerServiceNewTCP(const char *nodename, - const char *service, - int family, - int auth, - virNetTLSContextPtr tls, - bool readonly, - size_t max_queued_clients, - size_t nrequests_client_m= ax) +static virNetServerServicePtr +virNetServerServiceNewSocket(virNetSocketPtr *socks, + size_t nsocks, + int auth, + virNetTLSContextPtr tls, + bool readonly, + size_t max_queued_clients, + size_t nrequests_client_max) { virNetServerServicePtr svc; size_t i; @@ -146,18 +146,18 @@ virNetServerServicePtr virNetServerServiceNewTCP(cons= t char *nodename, if (!(svc =3D virObjectNew(virNetServerServiceClass))) return NULL; =20 + if (VIR_ALLOC_N(svc->socks, nsocks) < 0) + goto error; + svc->nsocks =3D nsocks; + for (i =3D 0; i < svc->nsocks; i++) { + svc->socks[i] =3D socks[i]; + virObjectRef(svc->socks[i]); + } svc->auth =3D auth; svc->readonly =3D readonly; svc->nrequests_client_max =3D nrequests_client_max; svc->tls =3D virObjectRef(tls); =20 - if (virNetSocketNewListenTCP(nodename, - service, - family, - &svc->socks, - &svc->nsocks) < 0) - goto error; - for (i =3D 0; i < svc->nsocks; i++) { if (virNetSocketListen(svc->socks[i], max_queued_clients) < 0) goto error; @@ -184,6 +184,43 @@ virNetServerServicePtr virNetServerServiceNewTCP(const= char *nodename, } =20 =20 +virNetServerServicePtr virNetServerServiceNewTCP(const char *nodename, + const char *service, + int family, + int auth, + virNetTLSContextPtr tls, + bool readonly, + size_t max_queued_clients, + size_t nrequests_client_m= ax) +{ + virNetServerServicePtr svc; + size_t i; + virNetSocketPtr *socks; + size_t nsocks; + + if (virNetSocketNewListenTCP(nodename, + service, + family, + &socks, + &nsocks) < 0) + return NULL; + + svc =3D virNetServerServiceNewSocket(socks, + nsocks, + auth, + tls, + readonly, + max_queued_clients, + nrequests_client_max); + + for (i =3D 0; i < nsocks; i++) + virObjectUnref(socks[i]); + VIR_FREE(socks); + + return svc; +} + + virNetServerServicePtr virNetServerServiceNewUNIX(const char *path, mode_t mask, gid_t grp, @@ -194,53 +231,26 @@ virNetServerServicePtr virNetServerServiceNewUNIX(con= st char *path, size_t nrequests_client_= max) { virNetServerServicePtr svc; - size_t i; - - if (virNetServerServiceInitialize() < 0) - return NULL; - - if (!(svc =3D virObjectNew(virNetServerServiceClass))) - return NULL; - - svc->auth =3D auth; - svc->readonly =3D readonly; - svc->nrequests_client_max =3D nrequests_client_max; - svc->tls =3D virObjectRef(tls); - - if (VIR_ALLOC_N(svc->socks, 1) < 0) - goto error; - svc->nsocks =3D 1; + virNetSocketPtr sock; =20 if (virNetSocketNewListenUNIX(path, mask, -1, grp, - &svc->socks[0]) < 0) - goto error; - - for (i =3D 0; i < svc->nsocks; i++) { - if (virNetSocketListen(svc->socks[i], max_queued_clients) < 0) - goto error; + &sock) < 0) + return NULL; =20 - /* IO callback is initially disabled, until we're ready - * to deal with incoming clients */ - virObjectRef(svc); - if (virNetSocketAddIOCallback(svc->socks[i], - 0, - virNetServerServiceAccept, - svc, - virObjectFreeCallback) < 0) { - virObjectUnref(svc); - goto error; - } - } + svc =3D virNetServerServiceNewSocket(&sock, + 1, + auth, + tls, + readonly, + max_queued_clients, + nrequests_client_max); =20 + virObjectUnref(sock); =20 return svc; - - error: - virObjectUnref(svc); - return NULL; } =20 virNetServerServicePtr virNetServerServiceNewFD(int fd, @@ -251,50 +261,23 @@ virNetServerServicePtr virNetServerServiceNewFD(int f= d, size_t nrequests_client_ma= x) { virNetServerServicePtr svc; - size_t i; - - if (virNetServerServiceInitialize() < 0) - return NULL; - - if (!(svc =3D virObjectNew(virNetServerServiceClass))) - return NULL; - - svc->auth =3D auth; - svc->readonly =3D readonly; - svc->nrequests_client_max =3D nrequests_client_max; - svc->tls =3D virObjectRef(tls); - - if (VIR_ALLOC_N(svc->socks, 1) < 0) - goto error; - svc->nsocks =3D 1; + virNetSocketPtr sock; =20 if (virNetSocketNewListenFD(fd, - &svc->socks[0]) < 0) - goto error; - - for (i =3D 0; i < svc->nsocks; i++) { - if (virNetSocketListen(svc->socks[i], max_queued_clients) < 0) - goto error; + &sock) < 0) + return NULL; =20 - /* IO callback is initially disabled, until we're ready - * to deal with incoming clients */ - virObjectRef(svc); - if (virNetSocketAddIOCallback(svc->socks[i], - 0, - virNetServerServiceAccept, - svc, - virObjectFreeCallback) < 0) { - virObjectUnref(svc); - goto error; - } - } + svc =3D virNetServerServiceNewSocket(&sock, + 1, + auth, + tls, + readonly, + max_queued_clients, + nrequests_client_max); =20 + virObjectUnref(sock); =20 return svc; - - error: - virObjectUnref(svc); - return NULL; } =20 =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 04:29:18 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=1561629436; cv=none; d=zoho.com; s=zohoarc; b=fEdkrViI2YXseXUM40qPlmpe6/IqiijWCPmIS2M6pe94ipYNXax91WYdPtqrygiKwAigjYqH/zUTp5G89vNiXliVwdXw9jcODbPs9kUZ0H3PW7OiFhQnBfxxy0yzUF27gLnwiCmZ81Fp6hloSvHMQiVmlQ5njDT9LDKcY6XCC9Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561629436; 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=Z6xVQwuogem/0lFXXzKurIoKPHiVa2gIlPWMVzH2gEk=; b=NQZkk1RREr5bxI+HvFa+Yo8f/E6+I15MFWGaQi2VFrx1RHURpnPkWAlDHyzSC9LhplVHLwKj8zSXfDOzLLUeytTMliNYbI6edEKCP73XmOLnWUmfIRNkaWxxKClN890eFYNlZsprJyDkKwLvRFtgudyg2kAuxppRNZPl8w5UTdI= 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 1561629436965648.3859239524041; Thu, 27 Jun 2019 02:57:16 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 255F4356F6; Thu, 27 Jun 2019 09:57:10 +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 EBDDF1001B16; Thu, 27 Jun 2019 09:57:08 +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 8EE3619731; Thu, 27 Jun 2019 09:57:07 +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 x5R9tGfr006112 for ; Thu, 27 Jun 2019 05:55:16 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5657660126; Thu, 27 Jun 2019 09:55:16 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-68.ams2.redhat.com [10.36.112.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4E95B600CC; Thu, 27 Jun 2019 09:55:15 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 27 Jun 2019 10:54:38 +0100 Message-Id: <20190627095452.28217-10-berrange@redhat.com> In-Reply-To: <20190627095452.28217-1-berrange@redhat.com> References: <20190627095452.28217-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 09/23] rpc: allow creating RPC service from an array of FDs 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.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 27 Jun 2019 09:57:10 +0000 (UTC) The virNetServerServiceNewFD API only accepts a single FD, but it is easily changed to allow for an array of FDs to be passed in. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/libvirt_remote.syms | 2 +- src/locking/lock_daemon.c | 9 ++++-- src/logging/log_daemon.c | 9 ++++-- src/rpc/virnetserverservice.c | 53 +++++++++++++++++++++-------------- src/rpc/virnetserverservice.h | 13 +++++---- 5 files changed, 52 insertions(+), 34 deletions(-) diff --git a/src/libvirt_remote.syms b/src/libvirt_remote.syms index 99fe3dd07c..e0f10400db 100644 --- a/src/libvirt_remote.syms +++ b/src/libvirt_remote.syms @@ -202,7 +202,7 @@ virNetServerServiceGetMaxRequests; virNetServerServiceGetPort; virNetServerServiceGetTLSContext; virNetServerServiceIsReadonly; -virNetServerServiceNewFD; +virNetServerServiceNewFDs; virNetServerServiceNewFDOrUNIX; virNetServerServiceNewPostExecRestart; virNetServerServiceNewTCP; diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c index bc2fb4a7fb..c10b2d383c 100644 --- a/src/locking/lock_daemon.c +++ b/src/locking/lock_daemon.c @@ -597,6 +597,7 @@ virLockDaemonSetupNetworkingSystemD(virNetServerPtr loc= kSrv, virNetServerPtr adm virNetServerServicePtr svc; char *path =3D virGetUNIXSocketPath(3 + i); virNetServerPtr srv; + int fds[] =3D { 3 + i }; =20 if (!path) return -1; @@ -616,9 +617,11 @@ virLockDaemonSetupNetworkingSystemD(virNetServerPtr lo= ckSrv, virNetServerPtr adm =20 /* Systemd passes FDs, starting immediately after stderr, * so the first FD we'll get is '3'. */ - if (!(svc =3D virNetServerServiceNewFD(3 + i, 0, - NULL, - false, 0, 1))) + if (!(svc =3D virNetServerServiceNewFDs(fds, + ARRAY_CARDINALITY(fds), + 0, + NULL, + false, 0, 1))) return -1; =20 if (virNetServerAddService(srv, svc) < 0) { diff --git a/src/logging/log_daemon.c b/src/logging/log_daemon.c index 014596b280..6531999381 100644 --- a/src/logging/log_daemon.c +++ b/src/logging/log_daemon.c @@ -532,6 +532,7 @@ virLogDaemonSetupNetworkingSystemD(virNetServerPtr logS= rv, virNetServerPtr admin virNetServerServicePtr svc; char *path =3D virGetUNIXSocketPath(3 + i); virNetServerPtr srv; + int fds[] =3D { 3 + i }; =20 if (!path) return -1; @@ -551,9 +552,11 @@ virLogDaemonSetupNetworkingSystemD(virNetServerPtr log= Srv, virNetServerPtr admin =20 /* Systemd passes FDs, starting immediately after stderr, * so the first FD we'll get is '3'. */ - if (!(svc =3D virNetServerServiceNewFD(3 + i, 0, - NULL, - false, 0, 1))) + if (!(svc =3D virNetServerServiceNewFDs(fds, + ARRAY_CARDINALITY(fds), + 0, + NULL, + false, 0, 1))) return -1; =20 if (virNetServerAddService(srv, svc) < 0) { diff --git a/src/rpc/virnetserverservice.c b/src/rpc/virnetserverservice.c index 69043ccc0e..0d2f264696 100644 --- a/src/rpc/virnetserverservice.c +++ b/src/rpc/virnetserverservice.c @@ -112,18 +112,20 @@ virNetServerServiceNewFDOrUNIX(const char *path, nrequests_client_max); =20 } else { + int fds[] =3D {(*cur_fd)++}; /* * There's still enough file descriptors. In this case we'll * use the current one and increment it afterwards. Take care * with order of operation for pointer arithmetic and auto * increment on cur_fd - the parentheses are necessary. */ - return virNetServerServiceNewFD((*cur_fd)++, - auth, - tls, - readonly, - max_queued_clients, - nrequests_client_max); + return virNetServerServiceNewFDs(fds, + ARRAY_CARDINALITY(fds), + auth, + tls, + readonly, + max_queued_clients, + nrequests_client_max); } } =20 @@ -253,30 +255,39 @@ virNetServerServicePtr virNetServerServiceNewUNIX(con= st char *path, return svc; } =20 -virNetServerServicePtr virNetServerServiceNewFD(int fd, - int auth, - virNetTLSContextPtr tls, - bool readonly, - size_t max_queued_clients, - size_t nrequests_client_ma= x) +virNetServerServicePtr virNetServerServiceNewFDs(int *fds, + size_t nfds, + int auth, + virNetTLSContextPtr tls, + bool readonly, + size_t max_queued_clients, + size_t nrequests_client_m= ax) { - virNetServerServicePtr svc; - virNetSocketPtr sock; + virNetServerServicePtr svc =3D NULL; + virNetSocketPtr *socks; + size_t i; =20 - if (virNetSocketNewListenFD(fd, - &sock) < 0) - return NULL; + if (VIR_ALLOC_N(socks, nfds) < 0) + goto cleanup; =20 - svc =3D virNetServerServiceNewSocket(&sock, - 1, + for (i =3D 0; i < nfds; i++) { + if (virNetSocketNewListenFD(fds[i], + &socks[i]) < 0) + goto cleanup; + } + + svc =3D virNetServerServiceNewSocket(socks, + nfds, auth, tls, readonly, max_queued_clients, nrequests_client_max); =20 - virObjectUnref(sock); - + cleanup: + for (i =3D 0; i < nfds && socks; i++) + virObjectUnref(socks[i]); + VIR_FREE(socks); return svc; } =20 diff --git a/src/rpc/virnetserverservice.h b/src/rpc/virnetserverservice.h index 5dd22bd929..59ee51e5ee 100644 --- a/src/rpc/virnetserverservice.h +++ b/src/rpc/virnetserverservice.h @@ -60,12 +60,13 @@ virNetServerServicePtr virNetServerServiceNewUNIX(const= char *path, bool readonly, size_t max_queued_client= s, size_t nrequests_client_= max); -virNetServerServicePtr virNetServerServiceNewFD(int fd, - int auth, - virNetTLSContextPtr tls, - bool readonly, - size_t max_queued_clients, - size_t nrequests_client_ma= x); +virNetServerServicePtr virNetServerServiceNewFDs(int *fd, + size_t nfds, + int auth, + virNetTLSContextPtr tls, + bool readonly, + size_t max_queued_clients, + size_t nrequests_client_m= ax); =20 virNetServerServicePtr virNetServerServiceNewPostExecRestart(virJSONValueP= tr object); =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 04:29:18 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=1561629440; cv=none; d=zoho.com; s=zohoarc; b=cOY8lo0UVZ3qJEg6NTFHxd+NlJaocMv2big1M6gT8E0EKWatIukZH58iFQLpMqx9NdNTyWxNroWd6LiIlZ8hLhQURvzv/S1Z+C56SWwR52LUlu/cjec4ZRPz5WSkNffmvfX4nUrJ4WGwAQtzbN++fcu11Hhb9MnlM+gkgsJ7epA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561629440; 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=fmUJ8rp26nr9+h1WvXIolV1TMl9BCrx24INRaXNXe/s=; b=QNxAs7FvIs5R6DpXeYe42W9e/FTXT7r+UTprT+aziHeXcun+QOf5tnui/6bM0wU0TZw+C+Prn/B1slBOzN6v31ihKw24w27NsTjh+HL2L7nBnpwusdXI4to/0PPGik6ScCSwsBfo2NthpKY0TJ89m0Tp0YPmNKVfjDjfIfwy4VY= 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 1561629440581119.27420927683795; Thu, 27 Jun 2019 02:57:20 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0FE53316290D; Thu, 27 Jun 2019 09:57:16 +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 DBBFF10013D9; Thu, 27 Jun 2019 09:57: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 939C31806B1F; Thu, 27 Jun 2019 09:57:12 +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 x5R9tHsB006152 for ; Thu, 27 Jun 2019 05:55:18 -0400 Received: by smtp.corp.redhat.com (Postfix) id E1CB86012E; Thu, 27 Jun 2019 09:55:17 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-68.ams2.redhat.com [10.36.112.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id E38B1600CC; Thu, 27 Jun 2019 09:55:16 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 27 Jun 2019 10:54:39 +0100 Message-Id: <20190627095452.28217-11-berrange@redhat.com> In-Reply-To: <20190627095452.28217-1-berrange@redhat.com> References: <20190627095452.28217-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 10/23] rpc: avoid unlinking sockets passed in from systemd 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.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Thu, 27 Jun 2019 09:57:19 +0000 (UTC) Currently the socket code will unlink any UNIX socket path which is associated with a server socket. This is not fine grained enough, as we need to avoid unlinking server sockets we were passed by systemd. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/locking/lock_daemon.c | 1 + src/logging/log_daemon.c | 1 + src/rpc/virnetserverservice.c | 3 ++ src/rpc/virnetserverservice.h | 1 + src/rpc/virnetsocket.c | 57 ++++++++++++++++++++--------------- src/rpc/virnetsocket.h | 1 + 6 files changed, 40 insertions(+), 24 deletions(-) diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c index c10b2d383c..0f90606be6 100644 --- a/src/locking/lock_daemon.c +++ b/src/locking/lock_daemon.c @@ -619,6 +619,7 @@ virLockDaemonSetupNetworkingSystemD(virNetServerPtr loc= kSrv, virNetServerPtr adm * so the first FD we'll get is '3'. */ if (!(svc =3D virNetServerServiceNewFDs(fds, ARRAY_CARDINALITY(fds), + false, 0, NULL, false, 0, 1))) diff --git a/src/logging/log_daemon.c b/src/logging/log_daemon.c index 6531999381..30c70a20dd 100644 --- a/src/logging/log_daemon.c +++ b/src/logging/log_daemon.c @@ -554,6 +554,7 @@ virLogDaemonSetupNetworkingSystemD(virNetServerPtr logS= rv, virNetServerPtr admin * so the first FD we'll get is '3'. */ if (!(svc =3D virNetServerServiceNewFDs(fds, ARRAY_CARDINALITY(fds), + false, 0, NULL, false, 0, 1))) diff --git a/src/rpc/virnetserverservice.c b/src/rpc/virnetserverservice.c index 0d2f264696..315a4950df 100644 --- a/src/rpc/virnetserverservice.c +++ b/src/rpc/virnetserverservice.c @@ -121,6 +121,7 @@ virNetServerServiceNewFDOrUNIX(const char *path, */ return virNetServerServiceNewFDs(fds, ARRAY_CARDINALITY(fds), + false, auth, tls, readonly, @@ -257,6 +258,7 @@ virNetServerServicePtr virNetServerServiceNewUNIX(const= char *path, =20 virNetServerServicePtr virNetServerServiceNewFDs(int *fds, size_t nfds, + bool unlinkUNIX, int auth, virNetTLSContextPtr tls, bool readonly, @@ -272,6 +274,7 @@ virNetServerServicePtr virNetServerServiceNewFDs(int *f= ds, =20 for (i =3D 0; i < nfds; i++) { if (virNetSocketNewListenFD(fds[i], + unlinkUNIX, &socks[i]) < 0) goto cleanup; } diff --git a/src/rpc/virnetserverservice.h b/src/rpc/virnetserverservice.h index 59ee51e5ee..73d61dde99 100644 --- a/src/rpc/virnetserverservice.h +++ b/src/rpc/virnetserverservice.h @@ -62,6 +62,7 @@ virNetServerServicePtr virNetServerServiceNewUNIX(const c= har *path, size_t nrequests_client_= max); virNetServerServicePtr virNetServerServiceNewFDs(int *fd, size_t nfds, + bool unlinkUNIX, int auth, virNetTLSContextPtr tls, bool readonly, diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c index fc13b1654a..a462c3eb05 100644 --- a/src/rpc/virnetsocket.c +++ b/src/rpc/virnetsocket.c @@ -81,6 +81,7 @@ struct _virNetSocket { bool client; bool ownsFd; bool quietEOF; + bool unlinkUNIX; =20 /* Event callback fields */ virNetSocketIOFunc func; @@ -216,10 +217,13 @@ int virNetSocketCheckProtocols(bool *hasIPv4, } =20 =20 -static virNetSocketPtr virNetSocketNew(virSocketAddrPtr localAddr, - virSocketAddrPtr remoteAddr, - bool isClient, - int fd, int errfd, pid_t pid) +static virNetSocketPtr +virNetSocketNew(virSocketAddrPtr localAddr, + virSocketAddrPtr remoteAddr, + int fd, + int errfd, + pid_t pid, + bool unlinkUNIX) { virNetSocketPtr sock; int no_slow_start =3D 1; @@ -254,6 +258,7 @@ static virNetSocketPtr virNetSocketNew(virSocketAddrPtr= localAddr, sock->pid =3D pid; sock->watch =3D -1; sock->ownsFd =3D true; + sock->unlinkUNIX =3D unlinkUNIX; =20 /* Disable nagle for TCP sockets */ if (sock->localAddr.data.sa.sa_family =3D=3D AF_INET || @@ -280,8 +285,6 @@ static virNetSocketPtr virNetSocketNew(virSocketAddrPtr= localAddr, !(sock->remoteAddrStrURI =3D virSocketAddrFormatFull(remoteAddr, t= rue, NULL))) goto error; =20 - sock->client =3D isClient; - PROBE(RPC_SOCKET_NEW, "sock=3D%p fd=3D%d errfd=3D%d pid=3D%lld localAddr=3D%s, remoteA= ddr=3D%s", sock, fd, errfd, (long long)pid, @@ -427,7 +430,7 @@ int virNetSocketNewListenTCP(const char *nodename, if (VIR_EXPAND_N(socks, nsocks, 1) < 0) goto error; =20 - if (!(socks[nsocks-1] =3D virNetSocketNew(&addr, NULL, false, fd, = -1, 0))) + if (!(socks[nsocks-1] =3D virNetSocketNew(&addr, NULL, fd, -1, 0, = false))) goto error; runp =3D runp->ai_next; fd =3D -1; @@ -513,7 +516,7 @@ int virNetSocketNewListenUNIX(const char *path, goto error; } =20 - if (!(*retsock =3D virNetSocketNew(&addr, NULL, false, fd, -1, 0))) + if (!(*retsock =3D virNetSocketNew(&addr, NULL, fd, -1, 0, true))) goto error; =20 return 0; @@ -538,6 +541,7 @@ int virNetSocketNewListenUNIX(const char *path ATTRIBUT= E_UNUSED, #endif =20 int virNetSocketNewListenFD(int fd, + bool unlinkUNIX, virNetSocketPtr *retsock) { virSocketAddr addr; @@ -551,7 +555,7 @@ int virNetSocketNewListenFD(int fd, return -1; } =20 - if (!(*retsock =3D virNetSocketNew(&addr, NULL, false, fd, -1, 0))) + if (!(*retsock =3D virNetSocketNew(&addr, NULL, fd, -1, 0, unlinkUNIX)= )) return -1; =20 return 0; @@ -627,7 +631,7 @@ int virNetSocketNewConnectTCP(const char *nodename, goto error; } =20 - if (!(*retsock =3D virNetSocketNew(&localAddr, &remoteAddr, true, fd, = -1, 0))) + if (!(*retsock =3D virNetSocketNew(&localAddr, &remoteAddr, fd, -1, 0,= false))) goto error; =20 freeaddrinfo(ai); @@ -752,7 +756,7 @@ int virNetSocketNewConnectUNIX(const char *path, goto cleanup; } =20 - if (!(*retsock =3D virNetSocketNew(&localAddr, &remoteAddr, true, fd, = -1, 0))) + if (!(*retsock =3D virNetSocketNew(&localAddr, &remoteAddr, fd, -1, 0,= false))) goto cleanup; =20 ret =3D 0; @@ -820,7 +824,7 @@ int virNetSocketNewConnectCommand(virCommandPtr cmd, VIR_FORCE_CLOSE(sv[1]); VIR_FORCE_CLOSE(errfd[1]); =20 - if (!(*retsock =3D virNetSocketNew(NULL, NULL, true, sv[0], errfd[0], = pid))) + if (!(*retsock =3D virNetSocketNew(NULL, NULL, sv[0], errfd[0], pid, f= alse))) goto error; =20 virCommandFree(cmd); @@ -1219,7 +1223,7 @@ int virNetSocketNewConnectSockFD(int sockfd, return -1; } =20 - if (!(*retsock =3D virNetSocketNew(&localAddr, NULL, true, sockfd, -1,= -1))) + if (!(*retsock =3D virNetSocketNew(&localAddr, NULL, sockfd, -1, -1, f= alse))) return -1; =20 return 0; @@ -1231,7 +1235,7 @@ virNetSocketPtr virNetSocketNewPostExecRestart(virJSO= NValuePtr object) virSocketAddr localAddr; virSocketAddr remoteAddr; int fd, thepid, errfd; - bool isClient; + bool unlinkUNIX; =20 if (virJSONValueObjectGetNumberInt(object, "fd", &fd) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -1250,10 +1254,15 @@ virNetSocketPtr virNetSocketNewPostExecRestart(virJ= SONValuePtr object) _("Missing errfd data in JSON document")); return NULL; } - if (virJSONValueObjectGetBoolean(object, "isClient", &isClient) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Missing isClient data in JSON document")); - return NULL; + + if (virJSONValueObjectGetBoolean(object, "unlinkUNIX", &unlinkUNIX) < = 0) { + bool isClient; + if (virJSONValueObjectGetBoolean(object, "isClient", &isClient) < = 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Missing unlinkUNIX/isClient data in JSON doc= ument")); + return NULL; + } + unlinkUNIX =3D !isClient; } =20 memset(&localAddr, 0, sizeof(localAddr)); @@ -1272,7 +1281,7 @@ virNetSocketPtr virNetSocketNewPostExecRestart(virJSO= NValuePtr object) } =20 return virNetSocketNew(&localAddr, &remoteAddr, - isClient, fd, errfd, thepid); + fd, errfd, thepid, unlinkUNIX); } =20 =20 @@ -1309,7 +1318,7 @@ virJSONValuePtr virNetSocketPreExecRestart(virNetSock= etPtr sock) if (virJSONValueObjectAppendNumberInt(object, "pid", sock->pid) < 0) goto error; =20 - if (virJSONValueObjectAppendBoolean(object, "isClient", sock->client) = < 0) + if (virJSONValueObjectAppendBoolean(object, "unlinkUNIX", sock->unlink= UNIX) < 0) goto error; =20 if (virSetInherit(sock->fd, true) < 0) { @@ -1350,7 +1359,7 @@ void virNetSocketDispose(void *obj) =20 #ifdef HAVE_SYS_UN_H /* If a server socket, then unlink UNIX path */ - if (!sock->client && + if (sock->unlinkUNIX && sock->localAddr.data.sa.sa_family =3D=3D AF_UNIX && sock->localAddr.data.un.sun_path[0] !=3D '\0') unlink(sock->localAddr.data.un.sun_path); @@ -2140,8 +2149,8 @@ int virNetSocketAccept(virNetSocketPtr sock, virNetSo= cketPtr *clientsock) =20 if (!(*clientsock =3D virNetSocketNew(&localAddr, &remoteAddr, - true, - fd, -1, 0))) + fd, -1, 0, + false))) goto cleanup; =20 fd =3D -1; @@ -2272,7 +2281,7 @@ void virNetSocketClose(virNetSocketPtr sock) =20 #ifdef HAVE_SYS_UN_H /* If a server socket, then unlink UNIX path */ - if (!sock->client && + if (sock->unlinkUNIX && sock->localAddr.data.sa.sa_family =3D=3D AF_UNIX && sock->localAddr.data.un.sun_path[0] !=3D '\0') { if (unlink(sock->localAddr.data.un.sun_path) =3D=3D 0) diff --git a/src/rpc/virnetsocket.h b/src/rpc/virnetsocket.h index de5a465cde..2f626cb08f 100644 --- a/src/rpc/virnetsocket.h +++ b/src/rpc/virnetsocket.h @@ -58,6 +58,7 @@ int virNetSocketNewListenUNIX(const char *path, virNetSocketPtr *addr); =20 int virNetSocketNewListenFD(int fd, + bool unlinkUNIX, virNetSocketPtr *addr); =20 int virNetSocketNewConnectTCP(const char *nodename, --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 04:29:18 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=1561629450; cv=none; d=zoho.com; s=zohoarc; b=U85WTzTJhagUEzsif55nFl06fLv5Hhr1Cbl0EVOOc5PBgMpaLpbpxGrR9JC9/exChtjQdacoRfrzTUmLkVeIA2N1UVdiFr2+5N9iSwUbwpAt98+OmKJw638x0QWstLpZT0RajUgJOALsI1mHe5JijDsPAQREJ5RsfwoWI1vP3tk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561629450; 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=VdR78MLDyfqWI8KtAo9Ibs5VjmRGXw9OpXOacSlbXLM=; b=k22N6doXxA4RB/Mce4ans2rGJh+cb96WTEiKpIEApyLkQxD5Ixcv3LabL0d1mOgRebuNnfH2pHhsr1Drvec/QXFRun/rQmQEzCnj/Z3KvmiEFCOeQwBPwnAiave0euc/zdOoA0/VqDeYZQyjhUdwZ2dv77QgxdBFWrXCfQIj78g= 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 1561629450782969.8678038611565; Thu, 27 Jun 2019 02:57:30 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 2D49C308402A; Thu, 27 Jun 2019 09:57:19 +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 EB6065C237; Thu, 27 Jun 2019 09:57:18 +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 99B7F1806B26; Thu, 27 Jun 2019 09:57:18 +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 x5R9tJTh006187 for ; Thu, 27 Jun 2019 05:55:19 -0400 Received: by smtp.corp.redhat.com (Postfix) id 16D1F6013A; Thu, 27 Jun 2019 09:55:19 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-68.ams2.redhat.com [10.36.112.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 463C3600CC; Thu, 27 Jun 2019 09:55:18 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 27 Jun 2019 10:54:40 +0100 Message-Id: <20190627095452.28217-12-berrange@redhat.com> In-Reply-To: <20190627095452.28217-1-berrange@redhat.com> References: <20190627095452.28217-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 11/23] rpc: add helper APIs for adding services with systemd activation 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Thu, 27 Jun 2019 09:57:24 +0000 (UTC) Currently code has to first create the service and then separately register it with the server. If the socket associated with a particular service is not passed from systemd we want to skip creating the service altogether. This means we can't put the systemd activation logic into the constructors for virNetServerService. This patch thus creates some helper methods against virNetServer which combine systemd activation, service creation and service registration into one single operation. This operation is automatically a no-op if systemd activation is present and no sockets were passed in. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/libvirt_remote.syms | 2 + src/rpc/virnetserver.c | 145 ++++++++++++++++++++++++++++++++++++++++ src/rpc/virnetserver.h | 23 +++++++ 3 files changed, 170 insertions(+) diff --git a/src/libvirt_remote.syms b/src/libvirt_remote.syms index e0f10400db..892091dd83 100644 --- a/src/libvirt_remote.syms +++ b/src/libvirt_remote.syms @@ -114,6 +114,8 @@ virNetMessageSaveError; virNetServerAddClient; virNetServerAddProgram; virNetServerAddService; +virNetServerAddServiceTCP; +virNetServerAddServiceUNIX; virNetServerClose; virNetServerGetClient; virNetServerGetClients; diff --git a/src/rpc/virnetserver.c b/src/rpc/virnetserver.c index 0f3fa63fbb..894feae406 100644 --- a/src/rpc/virnetserver.c +++ b/src/rpc/virnetserver.c @@ -668,6 +668,151 @@ int virNetServerAddService(virNetServerPtr srv, return -1; } =20 + +static int +virNetServerAddServiceActivation(virNetServerPtr srv, + virSystemdActivationPtr act, + const char *actname, + int auth, + virNetTLSContextPtr tls, + bool readonly, + size_t max_queued_clients, + size_t nrequests_client_max) +{ + int *fds; + size_t nfds; + + if (act =3D=3D NULL) + return 0; + + virSystemdActivationClaimFDs(act, actname, &fds, &nfds); + + if (nfds) { + virNetServerServicePtr svc; + + svc =3D virNetServerServiceNewFDs(fds, + nfds, + false, + auth, + tls, + readonly, + max_queued_clients, + nrequests_client_max); + if (!svc) + return -1; + + if (virNetServerAddService(srv, svc) < 0) { + virObjectUnref(svc); + return -1; + } + } + + /* Intentionally return 1 any time activation is present, + * even if we didn't find any sockets with the matching + * name. The user needs to be free to disable some of the + * services via unit files without causing us to fallback + * to creating the service manually. + */ + return 1; +} + + +int virNetServerAddServiceTCP(virNetServerPtr srv, + virSystemdActivationPtr act, + const char *actname, + const char *nodename, + const char *service, + int family, + int auth, + virNetTLSContextPtr tls, + bool readonly, + size_t max_queued_clients, + size_t nrequests_client_max) +{ + virNetServerServicePtr svc =3D NULL; + int ret; + + ret =3D virNetServerAddServiceActivation(srv, act, actname, + auth, + tls, + readonly, + max_queued_clients, + nrequests_client_max); + if (ret < 0) + return -1; + + if (ret =3D=3D 1) + return 0; + + if (!(svc =3D virNetServerServiceNewTCP(nodename, + service, + family, + auth, + tls, + readonly, + max_queued_clients, + nrequests_client_max))) + return -1; + + if (virNetServerAddService(srv, svc) < 0) { + virObjectUnref(svc); + return -1; + } + + virObjectUnref(svc); + + return 0; +} + + +int virNetServerAddServiceUNIX(virNetServerPtr srv, + virSystemdActivationPtr act, + const char *actname, + const char *path, + mode_t mask, + gid_t grp, + int auth, + virNetTLSContextPtr tls, + bool readonly, + size_t max_queued_clients, + size_t nrequests_client_max) +{ + virNetServerServicePtr svc =3D NULL; + int ret; + + ret =3D virNetServerAddServiceActivation(srv, act, actname, + auth, + tls, + readonly, + max_queued_clients, + nrequests_client_max); + if (ret < 0) + return -1; + + if (ret =3D=3D 1) + return 0; + + if (!(svc =3D virNetServerServiceNewUNIX(path, + mask, + grp, + auth, + tls, + readonly, + max_queued_clients, + nrequests_client_max))) + return -1; + + if (virNetServerAddService(srv, svc) < 0) { + virObjectUnref(svc); + return -1; + } + + virObjectUnref(svc); + + return 0; +} + + int virNetServerAddProgram(virNetServerPtr srv, virNetServerProgramPtr prog) { diff --git a/src/rpc/virnetserver.h b/src/rpc/virnetserver.h index b47b71b4b2..3205dde78f 100644 --- a/src/rpc/virnetserver.h +++ b/src/rpc/virnetserver.h @@ -27,6 +27,7 @@ #include "virnetserverservice.h" #include "virobject.h" #include "virjson.h" +#include "virsystemd.h" =20 =20 virNetServerPtr virNetServerNew(const char *name, @@ -60,6 +61,28 @@ virJSONValuePtr virNetServerPreExecRestart(virNetServerP= tr srv); =20 int virNetServerAddService(virNetServerPtr srv, virNetServerServicePtr svc); +int virNetServerAddServiceTCP(virNetServerPtr srv, + virSystemdActivationPtr act, + const char *actname, + const char *nodename, + const char *service, + int family, + int auth, + virNetTLSContextPtr tls, + bool readonly, + size_t max_queued_clients, + size_t nrequests_client_max); +int virNetServerAddServiceUNIX(virNetServerPtr srv, + virSystemdActivationPtr act, + const char *actname, + const char *path, + mode_t mask, + gid_t grp, + int auth, + virNetTLSContextPtr tls, + bool readonly, + size_t max_queued_clients, + size_t nrequests_client_max); =20 int virNetServerAddProgram(virNetServerPtr srv, virNetServerProgramPtr prog); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 04:29:18 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=1561629429; cv=none; d=zoho.com; s=zohoarc; b=On2uDpPzctDpgyXBFP8Fwx77OtRjS+mYnfB57rNrHYJegW33lDqw3plXCCi+cCIGHyxxfjOGtMLNpB4iqtaIKMeb4f2RrjzkwIkKBGUWCRusPIc+qLxEPXdbfsbmpUkTXD83R+CQQAfkQb5KEPkK5TlNcqFEGzpvCE+pbtT0nlA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561629429; 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=XNdP1QQ/UAIp//4no/ta2CCk4ogBFS4/JcyMwgxzUrk=; b=CQGk8Bi8p/M/kailUu2Ekbc3mRkCh1Q95Z9I8M02CgtO47ovwwOmYF5przuB0/WvlXHFBmtrSERvQmz7D5Jg6QQZolBgKi6DRiXAmICKReBae9caUsEt74jtqGML7h9gXHEcvNIdFDdXBzaE2ISxu8Kxjw9MVJr/r4+vpQG5ykA= 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 1561629429081735.5439984132661; Thu, 27 Jun 2019 02:57:09 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 28C9A30832E9; Thu, 27 Jun 2019 09:57:02 +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 EEF095C238; Thu, 27 Jun 2019 09:56:59 +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 B633E19729; Thu, 27 Jun 2019 09:56:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5R9tKVd006232 for ; Thu, 27 Jun 2019 05:55:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9C22E6013C; Thu, 27 Jun 2019 09:55:20 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-68.ams2.redhat.com [10.36.112.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6CFAF600CC; Thu, 27 Jun 2019 09:55:19 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 27 Jun 2019 10:54:41 +0100 Message-Id: <20190627095452.28217-13-berrange@redhat.com> In-Reply-To: <20190627095452.28217-1-berrange@redhat.com> References: <20190627095452.28217-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 12/23] rpc: add API for checking whether an auth scheme is in use on a server 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Thu, 27 Jun 2019 09:57:07 +0000 (UTC) Signed-off-by: Daniel P. Berrang=C3=A9 --- src/libvirt_remote.syms | 1 + src/rpc/virnetserver.c | 17 +++++++++++++++++ src/rpc/virnetserver.h | 3 +++ 3 files changed, 21 insertions(+) diff --git a/src/libvirt_remote.syms b/src/libvirt_remote.syms index 892091dd83..f4a62491e5 100644 --- a/src/libvirt_remote.syms +++ b/src/libvirt_remote.syms @@ -126,6 +126,7 @@ virNetServerGetMaxUnauthClients; virNetServerGetName; virNetServerGetThreadPoolParameters; virNetServerHasClients; +virNetServerNeedsAuth; virNetServerNew; virNetServerNewPostExecRestart; virNetServerNextClientID; diff --git a/src/rpc/virnetserver.c b/src/rpc/virnetserver.c index 894feae406..e229f57bab 100644 --- a/src/rpc/virnetserver.c +++ b/src/rpc/virnetserver.c @@ -1098,6 +1098,23 @@ virNetServerGetCurrentUnauthClients(virNetServerPtr = srv) return ret; } =20 + +bool virNetServerNeedsAuth(virNetServerPtr srv, + int auth) +{ + bool ret =3D false; + size_t i; + + virObjectLock(srv); + for (i =3D 0; i < srv->nservices; i++) { + if (virNetServerServiceGetAuth(srv->services[i]) =3D=3D auth) + ret =3D true; + } + virObjectUnlock(srv); + + return ret; +} + int virNetServerGetClients(virNetServerPtr srv, virNetServerClientPtr **clts) diff --git a/src/rpc/virnetserver.h b/src/rpc/virnetserver.h index 3205dde78f..5e42c7f23b 100644 --- a/src/rpc/virnetserver.h +++ b/src/rpc/virnetserver.h @@ -119,6 +119,9 @@ unsigned long long virNetServerNextClientID(virNetServe= rPtr srv); virNetServerClientPtr virNetServerGetClient(virNetServerPtr srv, unsigned long long id); =20 +bool virNetServerNeedsAuth(virNetServerPtr srv, + int auth); + int virNetServerGetClients(virNetServerPtr srv, virNetServerClientPtr **clients); =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 04:29:18 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=1561629440; cv=none; d=zoho.com; s=zohoarc; b=JMSAmBaITLISjN1MG8Zv4ikbrACEh8KR3uVw3d9INEReGEjD5muGoYdcFfdhcLloNQ/r8h1KxbUIR//QRtc5ywNlP28NXqqFaTNclVcVJYscmWN2Mqk571rF42hi07+d1u1YUk2JCH7GJIJljwzcWCXNAr3Z+MbQ+WMTY16rbRE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561629440; 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=NP6PBuuxBG0qhvj9bKDJmg9Oy0opfZ3rLiXw9ga+EyY=; b=KUwdgcSu3QTa4FVe2AKz9gnJIV4Orhf9tyfbVarSM23XPwQWI8pYzaNVhMpyNxoQYgOQd0C1EAHK6083yEl6aQ3exCP9PA02RR5IcAVOZTYd4Cgq0JSUICCHJNUjje7bNpU7EAyOYeJ93/vmnF/wDhpHs0EU506BVYD56OVbei0= 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 1561629440075653.7484008062853; Thu, 27 Jun 2019 02:57:20 -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 E4EA030820DD; Thu, 27 Jun 2019 09:57: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 AFF5F600CC; Thu, 27 Jun 2019 09:57:15 +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 66FBF19734; Thu, 27 Jun 2019 09:57:13 +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 x5R9tLqZ006260 for ; Thu, 27 Jun 2019 05:55:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id B29E860126; Thu, 27 Jun 2019 09:55:21 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-68.ams2.redhat.com [10.36.112.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id EF4DC600CC; Thu, 27 Jun 2019 09:55:20 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 27 Jun 2019 10:54:42 +0100 Message-Id: <20190627095452.28217-14-berrange@redhat.com> In-Reply-To: <20190627095452.28217-1-berrange@redhat.com> References: <20190627095452.28217-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 13/23] remote: simplify libvirtd code for deciding if SASL auth is needed 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.47]); Thu, 27 Jun 2019 09:57:18 +0000 (UTC) Signed-off-by: Daniel P. Berrang=C3=A9 --- src/remote/remote_daemon.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c index fdc9e4333a..0dabd3dff8 100644 --- a/src/remote/remote_daemon.c +++ b/src/remote/remote_daemon.c @@ -534,15 +534,10 @@ daemonSetupNetworking(virNetServerPtr srv, } =20 #if WITH_SASL - if (config->auth_unix_rw =3D=3D REMOTE_AUTH_SASL || - (sock_path_ro && config->auth_unix_ro =3D=3D REMOTE_AUTH_SASL) || - (ipsock && config->listen_tls && config->auth_tls =3D=3D REMOTE_AU= TH_SASL) || - (ipsock && config->listen_tcp && config->auth_tcp =3D=3D REMOTE_AU= TH_SASL)) { - saslCtxt =3D virNetSASLContextNewServer( - (const char *const*)config->sasl_allowed_username_list); - if (!saslCtxt) + if (virNetServerNeedsAuth(srv, REMOTE_AUTH_SASL) && + !(saslCtxt =3D virNetSASLContextNewServer( + (const char *const*)config->sasl_allowed_username_list))) goto cleanup; - } #endif =20 ret =3D 0; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 04:29:18 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=1561629454; cv=none; d=zoho.com; s=zohoarc; b=F0GvwrDxUaDnhrzd+/C8gci0HXEdCf8V2xFsu7Im76SMriofUe9MUqp+Dgkmuvqq8oBL9uVsNuvCprGo6/df+3JtS3xBaIYGckvCH90351LE5iFx4V58p4w0lN93qdf+pXYXrURXR3SNPCRfYM/EbfDVyCkO8DMKnqYi+BpbZBo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561629454; 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=TMuIEQ6AZUV2uSjP33oWK4BUGsngDnaGD5kN+h81tl0=; b=WTLJhtoDAYXUle9RdviARkgriHCy4Depe03HcGBokt4Be2pXQwylVd2gfJa5IyBk2KLohwzbYAUWJRQWXVgaufGfHeLKEAsRpeGaYGUwBc/F7QwmKzmwXRJ2psd7OaOQFu3Ry7TSMT5EsoLRE4MGR1DSxt3ANkOomHGiab6itKs= 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 1561629454795968.5907251952971; Thu, 27 Jun 2019 02:57:34 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 00419308424C; Thu, 27 Jun 2019 09:57:23 +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 C84821001281; Thu, 27 Jun 2019 09:57:22 +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 85BA019731; Thu, 27 Jun 2019 09:57:22 +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 x5R9tOJ0006337 for ; Thu, 27 Jun 2019 05:55:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id DD2A060126; Thu, 27 Jun 2019 09:55:24 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-68.ams2.redhat.com [10.36.112.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id E9D1B600CC; Thu, 27 Jun 2019 09:55:21 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 27 Jun 2019 10:54:43 +0100 Message-Id: <20190627095452.28217-15-berrange@redhat.com> In-Reply-To: <20190627095452.28217-1-berrange@redhat.com> References: <20190627095452.28217-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 14/23] remote: fix handling of systemd activation wrt socket ordering 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.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Thu, 27 Jun 2019 09:57:28 +0000 (UTC) The current libvirtd code for systemd socket activation assumes socket FDs are passed in the order unix-rw, unix-ro, unix-admin. There is in fact no ordering guarantee made by systemd. Applications are expected to check the address or name associated with each FD to figure out its identity. This rewrites libvirtd to make use of the new systemd activation APIs to make it robust wrt socket ordering changes. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/remote/remote_daemon.c | 244 ++++++++++++++++------------------ src/rpc/virnetserverservice.c | 7 + 2 files changed, 125 insertions(+), 126 deletions(-) diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c index 0dabd3dff8..cbdad69014 100644 --- a/src/remote/remote_daemon.c +++ b/src/remote/remote_daemon.c @@ -56,6 +56,7 @@ #include "virutil.h" #include "virgettext.h" #include "util/virnetdevopenvswitch.h" +#include "virsystemd.h" =20 #include "driver.h" =20 @@ -367,30 +368,34 @@ daemonSetupNetworking(virNetServerPtr srv, bool ipsock, bool privileged) { - virNetServerServicePtr svc =3D NULL; - virNetServerServicePtr svcAdm =3D NULL; - virNetServerServicePtr svcRO =3D NULL; - virNetServerServicePtr svcTCP =3D NULL; - virNetServerServicePtr svcTLS =3D NULL; gid_t unix_sock_gid =3D 0; int unix_sock_ro_mask =3D 0; int unix_sock_rw_mask =3D 0; int unix_sock_adm_mask =3D 0; int ret =3D -1; + VIR_AUTOSTRUCT(virSystemdActivation) *act =3D NULL; + virSystemdActivationMap actmap[] =3D { + { .name =3D "libvirtd.socket", .family =3D AF_UNIX, .path =3D sock= _path }, + { .name =3D "libvirtd-ro.socket", .family =3D AF_UNIX, .path =3D s= ock_path_ro }, + { .name =3D "libvirtd-admin.socket", .family =3D AF_UNIX, .path = =3D sock_path_adm }, + { .name =3D "libvirtd-tcp.socket", .family =3D AF_INET }, + { .name =3D "libvirtd-tls.socket", .family =3D AF_INET }, + }; + + if ((actmap[3].port =3D virSocketAddrResolveService(config->tcp_port))= < 0) + return -1; + + if ((actmap[4].port =3D virSocketAddrResolveService(config->tls_port))= < 0) + return -1; =20 - unsigned int cur_fd =3D STDERR_FILENO + 1; - unsigned int nfds =3D virGetListenFDs(); + if (virSystemdGetActivation(actmap, ARRAY_CARDINALITY(actmap), &act) <= 0) + return -1; =20 if (config->unix_sock_group) { if (virGetGroupID(config->unix_sock_group, &unix_sock_gid) < 0) return ret; } =20 - if (nfds > (sock_path_ro ? 2 : 1)) { - VIR_ERROR(_("Too many (%u) FDs passed from caller"), nfds); - return ret; - } - if (virStrToLong_i(config->unix_sock_ro_perms, NULL, 8, &unix_sock_ro_= mask) !=3D 0) { VIR_ERROR(_("Failed to parse mode '%s'"), config->unix_sock_ro_per= ms); goto cleanup; @@ -406,148 +411,135 @@ daemonSetupNetworking(virNetServerPtr srv, goto cleanup; } =20 - if (!(svc =3D virNetServerServiceNewFDOrUNIX(sock_path, - unix_sock_rw_mask, - unix_sock_gid, - config->auth_unix_rw, - NULL, - false, - config->max_queued_clients, - config->max_client_requests, - nfds, &cur_fd))) + if (virNetServerAddServiceUNIX(srv, + act, + "libvirtd.socket", + sock_path, + unix_sock_rw_mask, + unix_sock_gid, + config->auth_unix_rw, + NULL, + false, + config->max_queued_clients, + config->max_client_requests) < 0) goto cleanup; - if (sock_path_ro) { - if (!(svcRO =3D virNetServerServiceNewFDOrUNIX(sock_path_ro, - unix_sock_ro_mask, - unix_sock_gid, - config->auth_unix_ro, - NULL, - true, - config->max_queued_cl= ients, - config->max_client_re= quests, - nfds, &cur_fd))) - goto cleanup; - } - - if (virNetServerAddService(srv, svc) < 0) + if (sock_path_ro && + virNetServerAddServiceUNIX(srv, + act, + "libvirtd-ro.socket", + sock_path_ro, + unix_sock_ro_mask, + unix_sock_gid, + config->auth_unix_ro, + NULL, + true, + config->max_queued_clients, + config->max_client_requests) < 0) goto cleanup; =20 - if (svcRO && - virNetServerAddService(srv, svcRO) < 0) + if (sock_path_adm && + virNetServerAddServiceUNIX(srvAdm, + act, + "libvirtd-admin.socket", + sock_path_adm, + unix_sock_adm_mask, + unix_sock_gid, + REMOTE_AUTH_NONE, + NULL, + false, + config->admin_max_queued_clients, + config->admin_max_client_requests) < 0) goto cleanup; =20 - if (sock_path_adm) { - VIR_DEBUG("Registering unix socket %s", sock_path_adm); - if (!(svcAdm =3D virNetServerServiceNewUNIX(sock_path_adm, - unix_sock_adm_mask, - unix_sock_gid, - REMOTE_AUTH_NONE, - NULL, - false, - config->admin_max_queued= _clients, - config->admin_max_client= _requests))) - goto cleanup; + if (((ipsock && config->listen_tcp) || act) && + virNetServerAddServiceTCP(srv, + act, + "libvirtd-tcp.socket", + config->listen_addr, + config->tcp_port, + AF_UNSPEC, + config->auth_tcp, + NULL, + false, + config->max_queued_clients, + config->max_client_requests) < 0) + goto cleanup; =20 - if (virNetServerAddService(srvAdm, svcAdm) < 0) - goto cleanup; - } + if (((ipsock && config->listen_tls) || (act && virSystemdActivationHas= Name(act, "ip-tls")))) { + virNetTLSContextPtr ctxt =3D NULL; =20 - if (ipsock) { - if (config->listen_tcp) { - VIR_DEBUG("Registering TCP socket %s:%s", - config->listen_addr, config->tcp_port); - if (!(svcTCP =3D virNetServerServiceNewTCP(config->listen_addr, - config->tcp_port, - AF_UNSPEC, - config->auth_tcp, - NULL, - false, - config->max_queued_cl= ients, - config->max_client_re= quests))) + if (config->ca_file || + config->cert_file || + config->key_file) { + if (!config->ca_file) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("No CA certificate path set to match serv= er key/cert")); goto cleanup; - - if (virNetServerAddService(srv, svcTCP) < 0) + } + if (!config->cert_file) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("No server certificate path set to match = server key")); goto cleanup; - } - - if (config->listen_tls) { - virNetTLSContextPtr ctxt =3D NULL; - - if (config->ca_file || - config->cert_file || - config->key_file) { - if (!config->ca_file) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("No CA certificate path set to match = server key/cert")); - goto cleanup; - } - if (!config->cert_file) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("No server certificate path set to ma= tch server key")); - goto cleanup; - } - if (!config->key_file) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("No server key path set to match serv= er cert")); - goto cleanup; - } - VIR_DEBUG("Using CA=3D'%s' cert=3D'%s' key=3D'%s'", - config->ca_file, config->cert_file, config->key_= file); - if (!(ctxt =3D virNetTLSContextNewServer(config->ca_file, - config->crl_file, - config->cert_file, - config->key_file, + } + if (!config->key_file) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("No server key path set to match server c= ert")); + goto cleanup; + } + VIR_DEBUG("Using CA=3D'%s' cert=3D'%s' key=3D'%s'", + config->ca_file, config->cert_file, config->key_file= ); + if (!(ctxt =3D virNetTLSContextNewServer(config->ca_file, + config->crl_file, + config->cert_file, + config->key_file, + (const char *const*)con= fig->tls_allowed_dn_list, + config->tls_priority, + config->tls_no_sanity_c= ertificate ? false : true, + config->tls_no_verify_c= ertificate ? false : true))) + goto cleanup; + } else { + if (!(ctxt =3D virNetTLSContextNewServerPath(NULL, + !privileged, (const char *const*= )config->tls_allowed_dn_list, config->tls_priorit= y, config->tls_no_sani= ty_certificate ? false : true, config->tls_no_veri= fy_certificate ? false : true))) - goto cleanup; - } else { - if (!(ctxt =3D virNetTLSContextNewServerPath(NULL, - !privileged, - (const char *co= nst*)config->tls_allowed_dn_list, - config->tls_pri= ority, - config->tls_no_= sanity_certificate ? false : true, - config->tls_no_= verify_certificate ? false : true))) - goto cleanup; - } - - VIR_DEBUG("Registering TLS socket %s:%s", - config->listen_addr, config->tls_port); - if (!(svcTLS =3D - virNetServerServiceNewTCP(config->listen_addr, - config->tls_port, - AF_UNSPEC, - config->auth_tls, - ctxt, - false, - config->max_queued_clients, - config->max_client_requests)))= { - virObjectUnref(ctxt); - goto cleanup; - } - if (virNetServerAddService(srv, svcTLS) < 0) goto cleanup; + } =20 + VIR_DEBUG("Registering TLS socket %s:%s", + config->listen_addr, config->tls_port); + if (virNetServerAddServiceTCP(srv, + act, + "libvirtd-tls.socket", + config->listen_addr, + config->tls_port, + AF_UNSPEC, + config->auth_tls, + ctxt, + false, + config->max_queued_clients, + config->max_client_requests) < 0) { virObjectUnref(ctxt); + goto cleanup; } + virObjectUnref(ctxt); } =20 + if (act && + virSystemdActivationComplete(act) < 0) + goto cleanup; + #if WITH_SASL if (virNetServerNeedsAuth(srv, REMOTE_AUTH_SASL) && !(saslCtxt =3D virNetSASLContextNewServer( (const char *const*)config->sasl_allowed_username_list))) - goto cleanup; + goto cleanup; #endif =20 ret =3D 0; =20 cleanup: - virObjectUnref(svcTLS); - virObjectUnref(svcTCP); - virObjectUnref(svcRO); - virObjectUnref(svcAdm); - virObjectUnref(svc); return ret; } =20 diff --git a/src/rpc/virnetserverservice.c b/src/rpc/virnetserverservice.c index 315a4950df..d5df5d5c20 100644 --- a/src/rpc/virnetserverservice.c +++ b/src/rpc/virnetserverservice.c @@ -28,9 +28,12 @@ #include "viralloc.h" #include "virerror.h" #include "virthread.h" +#include "virlog.h" =20 #define VIR_FROM_THIS VIR_FROM_RPC =20 +VIR_LOG_INIT("rpc.netserverservice"); + struct _virNetServerService { virObject parent; =20 @@ -201,6 +204,8 @@ virNetServerServicePtr virNetServerServiceNewTCP(const = char *nodename, virNetSocketPtr *socks; size_t nsocks; =20 + VIR_DEBUG("Creating new TCP server nodename=3D'%s' service=3D'%s'", + NULLSTR(nodename), NULLSTR(service)); if (virNetSocketNewListenTCP(nodename, service, family, @@ -236,6 +241,8 @@ virNetServerServicePtr virNetServerServiceNewUNIX(const= char *path, virNetServerServicePtr svc; virNetSocketPtr sock; =20 + VIR_DEBUG("Creating new UNIX server path=3D'%s' mask=3D%o gid=3D%u", + path, mask, grp); if (virNetSocketNewListenUNIX(path, mask, -1, --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 04:29:18 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=1561629455; cv=none; d=zoho.com; s=zohoarc; b=iZqJTciy58fBuqORy26gjuk13pPXoYayOivun8DarjiRxWW5J6qkGST3P5FZYdw++SPL9iG8UwH5VERV4PJkdgghZ1b7Ghmo7lTZA62ul8HZBqkVN/nY0F5YcNTz0FMTgzOdMJeKFT3VRZdtyQUNR/aU9hONaZWcfc4LQlI+xDg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561629455; 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=Z3OPrxywEEvYoBE5/M/SP4MFSxEg2ydsNXFTcKgTmq8=; b=Vil1LdxeuKZtY4XaZAONCTa4dnUv1VB+VR6yFRhAmzX8up6CAa0DOo9xWdqqiB/knSJJyXlCbX5A1p6QW7jbNDluGEWBN++nwPZwx9G2Wlpv3+sSh5xBGp23QdiMJZE8Jdlxz3jXM/Ss8XB3BNr5PLsuiBXAENYtP+27jpvk3w4= 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 156162945581714.552394575142557; Thu, 27 Jun 2019 02:57:35 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DD77C21BA4; Thu, 27 Jun 2019 09:57:25 +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 B990C1001B23; Thu, 27 Jun 2019 09:57:24 +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 7854A1806B1A; Thu, 27 Jun 2019 09:57:23 +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 x5R9tQwV006372 for ; Thu, 27 Jun 2019 05:55:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id 29397600CC; Thu, 27 Jun 2019 09:55:26 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-68.ams2.redhat.com [10.36.112.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3D9D360126; Thu, 27 Jun 2019 09:55:25 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 27 Jun 2019 10:54:44 +0100 Message-Id: <20190627095452.28217-16-berrange@redhat.com> In-Reply-To: <20190627095452.28217-1-berrange@redhat.com> References: <20190627095452.28217-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 15/23] rpc: remove unused API for creating services from FDs 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.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 27 Jun 2019 09:57:29 +0000 (UTC) The virNetServerServiceNewFDOrUNIX method cannot be correctly used when dealing with systemd activation of a service which can receive more than one socket FD as there is not guaranteed ordering of FDs. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/libvirt_remote.syms | 1 - src/rpc/virnetserverservice.c | 46 ----------------------------------- src/rpc/virnetserverservice.h | 10 -------- 3 files changed, 57 deletions(-) diff --git a/src/libvirt_remote.syms b/src/libvirt_remote.syms index f4a62491e5..3307d74324 100644 --- a/src/libvirt_remote.syms +++ b/src/libvirt_remote.syms @@ -206,7 +206,6 @@ virNetServerServiceGetPort; virNetServerServiceGetTLSContext; virNetServerServiceIsReadonly; virNetServerServiceNewFDs; -virNetServerServiceNewFDOrUNIX; virNetServerServiceNewPostExecRestart; virNetServerServiceNewTCP; virNetServerServiceNewUNIX; diff --git a/src/rpc/virnetserverservice.c b/src/rpc/virnetserverservice.c index d5df5d5c20..66af27d9f7 100644 --- a/src/rpc/virnetserverservice.c +++ b/src/rpc/virnetserverservice.c @@ -88,52 +88,6 @@ static void virNetServerServiceAccept(virNetSocketPtr so= ck, } =20 =20 -virNetServerServicePtr -virNetServerServiceNewFDOrUNIX(const char *path, - mode_t mask, - gid_t grp, - int auth, - virNetTLSContextPtr tls, - bool readonly, - size_t max_queued_clients, - size_t nrequests_client_max, - unsigned int nfds, - unsigned int *cur_fd) -{ - if (*cur_fd - STDERR_FILENO > nfds) { - /* - * There are no more file descriptors to use, so we have to - * fallback to UNIX socket. - */ - return virNetServerServiceNewUNIX(path, - mask, - grp, - auth, - tls, - readonly, - max_queued_clients, - nrequests_client_max); - - } else { - int fds[] =3D {(*cur_fd)++}; - /* - * There's still enough file descriptors. In this case we'll - * use the current one and increment it afterwards. Take care - * with order of operation for pointer arithmetic and auto - * increment on cur_fd - the parentheses are necessary. - */ - return virNetServerServiceNewFDs(fds, - ARRAY_CARDINALITY(fds), - false, - auth, - tls, - readonly, - max_queued_clients, - nrequests_client_max); - } -} - - static virNetServerServicePtr virNetServerServiceNewSocket(virNetSocketPtr *socks, size_t nsocks, diff --git a/src/rpc/virnetserverservice.h b/src/rpc/virnetserverservice.h index 73d61dde99..d58fc43437 100644 --- a/src/rpc/virnetserverservice.h +++ b/src/rpc/virnetserverservice.h @@ -34,16 +34,6 @@ typedef int (*virNetServerServiceDispatchFunc)(virNetSer= verServicePtr svc, virNetSocketPtr sock, void *opaque); =20 -virNetServerServicePtr virNetServerServiceNewFDOrUNIX(const char *path, - mode_t mask, - gid_t grp, - int auth, - virNetTLSContextPtr = tls, - bool readonly, - size_t max_queued_cl= ients, - size_t nrequests_cli= ent_max, - unsigned int nfds, - unsigned int *cur_fd= ); virNetServerServicePtr virNetServerServiceNewTCP(const char *nodename, const char *service, int family, --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 04:29:18 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=1561629432; cv=none; d=zoho.com; s=zohoarc; b=lV6pMtDwCaVKUd5/bFxj9EVXpu1hyddmOJtI2VTn3wShR3Aj3+O0rfOYR3aAqznDcD8abOHwbS9MTk0Sq3i2ZD5EHL7pU8ECJhffPvAtGlo6xRgPdpwOhi+s50A9p31mxSCUQNgcI0RA4QJur5E8LvwLXeWuxp3n8Tz0x36jwNw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561629432; 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=06Tw77YJLxf3Crz8ZxKxIGm7B7mgYjDke6JpYtY4w0k=; b=IZTU+Oj4f3601XJglam6bSzr9zNuUFWX2WnbhxZg4vpaDDvE+saSr6o/3VrBXfLQN3j6H7EL3tvYUpk5qxsE2pFgFDSYlbdYWrhDAzSwdCLOd0UILsmxKMafH+XBLEaXtrf+EEQTotU5m9IppvOGODIBroYQQNef38AXrCC5qeo= 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 1561629432739216.4030526214416; Thu, 27 Jun 2019 02:57:12 -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 25BBD308427C; Thu, 27 Jun 2019 09:57:11 +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 B235C60C4E; Thu, 27 Jun 2019 09:57: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 648D01806B18; Thu, 27 Jun 2019 09:57: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 x5R9tR3i006413 for ; Thu, 27 Jun 2019 05:55:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id C8B8D6012E; Thu, 27 Jun 2019 09:55:27 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-68.ams2.redhat.com [10.36.112.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8F09B600CC; Thu, 27 Jun 2019 09:55:26 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 27 Jun 2019 10:54:45 +0100 Message-Id: <20190627095452.28217-17-berrange@redhat.com> In-Reply-To: <20190627095452.28217-1-berrange@redhat.com> References: <20190627095452.28217-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 16/23] remote: add systemd socket units for UNIX/TCP sockets 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.40]); Thu, 27 Jun 2019 09:57:11 +0000 (UTC) We don't do socket activation of libvirtd, since we need to unconditionally start libvirtd in order to perform autostart. This doesn't mean we can't have systemd socket units. Some use cases will not need libvirt's autostart & are thus free to use activation. Signed-off-by: Daniel P. Berrang=C3=A9 --- libvirt.spec.in | 24 +++++++++++++++++++- src/remote/Makefile.inc.am | 35 +++++++++++++++++++++++++++++ src/remote/libvirtd-admin.socket.in | 13 +++++++++++ src/remote/libvirtd-ro.socket.in | 13 +++++++++++ src/remote/libvirtd-tcp.socket.in | 12 ++++++++++ src/remote/libvirtd-tls.socket.in | 12 ++++++++++ src/remote/libvirtd.service.in | 10 ++++----- src/remote/libvirtd.socket.in | 11 +++++++++ 8 files changed, 124 insertions(+), 6 deletions(-) create mode 100644 src/remote/libvirtd-admin.socket.in create mode 100644 src/remote/libvirtd-ro.socket.in create mode 100644 src/remote/libvirtd-tcp.socket.in create mode 100644 src/remote/libvirtd-tls.socket.in create mode 100644 src/remote/libvirtd.socket.in diff --git a/libvirt.spec.in b/libvirt.spec.in index d54f58f1d4..ec562d5f7a 100644 --- a/libvirt.spec.in +++ b/libvirt.spec.in @@ -1342,6 +1342,8 @@ exit 0 =20 %systemd_post virtlockd.socket virtlockd-admin.socket %systemd_post virtlogd.socket virtlogd-admin.socket +%systemd_post libvirtd.socket libvirtd-ro.socket libvirtd-admin.socket +%systemd_post libvirtd-tcp.socket libvirtd-tls.socket %systemd_post libvirtd.service =20 # request daemon restart in posttrans @@ -1350,6 +1352,8 @@ touch %{_localstatedir}/lib/rpm-state/libvirt/restart= || : =20 %preun daemon %systemd_preun libvirtd.service +%systemd_preun libvirtd-tcp.socket libvirtd-tls.socket +%systemd_preun libvirtd.socket libvirtd-ro.socket libvirtd-admin.socket %systemd_preun virtlogd.socket virtlogd-admin.socket virtlogd.service %systemd_preun virtlockd.socket virtlockd-admin.socket virtlockd.service =20 @@ -1374,7 +1378,20 @@ fi =20 %posttrans daemon if [ -f %{_localstatedir}/lib/rpm-state/libvirt/restart ]; then - /bin/systemctl try-restart libvirtd.service >/dev/null 2>&1 || : + /bin/systemctl is-active libvirtd.service 1>/dev/null 2>&1 + # Old libvirtd owns the sockets and will delete them on + # shutdown. Can't use a try-restart as libvirtd will simply + # own the sockets again when it comes back up. Thus we must + # do this particular ordering + if test $? =3D=3D 0 ; then + /bin/systemctl stop libvirtd.service >/dev/null 2>&1 || : + + /bin/systemctl try-restart libvirtd.socket >/dev/null 2>&1 || : + /bin/systemctl try-restart libvirtd-ro.socket >/dev/null 2>&1 || : + /bin/systemctl try-restart libvirtd-admin.socket >/dev/null 2>&1 |= | : + + /bin/systemctl start libvirtd.service >/dev/null 2>&1 || : + fi fi rm -rf %{_localstatedir}/lib/rpm-state/libvirt || : =20 @@ -1505,6 +1522,11 @@ exit 0 %dir %attr(0700, root, root) %{_sysconfdir}/libvirt/ =20 %{_unitdir}/libvirtd.service +%{_unitdir}/libvirtd.socket +%{_unitdir}/libvirtd-ro.socket +%{_unitdir}/libvirtd-admin.socket +%{_unitdir}/libvirtd-tcp.socket +%{_unitdir}/libvirtd-tls.socket %{_unitdir}/virt-guest-shutdown.target %{_unitdir}/virtlogd.service %{_unitdir}/virtlogd.socket diff --git a/src/remote/Makefile.inc.am b/src/remote/Makefile.inc.am index 06714249b4..0479c2ddd1 100644 --- a/src/remote/Makefile.inc.am +++ b/src/remote/Makefile.inc.am @@ -51,6 +51,11 @@ MANINFILES +=3D libvirtd.8.in =20 SYSTEMD_UNIT_FILES_IN +=3D \ remote/libvirtd.service.in \ + remote/libvirtd.socket.in \ + remote/libvirtd-ro.socket.in \ + remote/libvirtd-admin.socket.in \ + remote/libvirtd-tcp.socket.in \ + remote/libvirtd-tls.socket.in \ remote/virt-guest-shutdown.target.in \ $(NULL) =20 @@ -276,6 +281,36 @@ libvirtd.service: remote/libvirtd.service.in $(top_bui= lddir)/config.status < $< > $@-t && \ mv $@-t $@ =20 +libvirtd.socket: remote/libvirtd.socket.in $(top_builddir)/config.status + $(AM_V_GEN)sed \ + -e 's|[@]localstatedir[@]|$(localstatedir)|g' \ + < $< > $@-t && \ + mv $@-t $@ + +libvirtd-ro.socket: remote/libvirtd-ro.socket.in $(top_builddir)/config.st= atus + $(AM_V_GEN)sed \ + -e 's|[@]localstatedir[@]|$(localstatedir)|g' \ + < $< > $@-t && \ + mv $@-t $@ + +libvirtd-admin.socket: remote/libvirtd-admin.socket.in $(top_builddir)/con= fig.status + $(AM_V_GEN)sed \ + -e 's|[@]localstatedir[@]|$(localstatedir)|g' \ + < $< > $@-t && \ + mv $@-t $@ + +libvirtd-tcp.socket: remote/libvirtd-tcp.socket.in $(top_builddir)/config.= status + $(AM_V_GEN)sed \ + -e 's|[@]localstatedir[@]|$(localstatedir)|g' \ + < $< > $@-t && \ + mv $@-t $@ + +libvirtd-tls.socket: remote/libvirtd-tls.socket.in $(top_builddir)/config.= status + $(AM_V_GEN)sed \ + -e 's|[@]localstatedir[@]|$(localstatedir)|g' \ + < $< > $@-t && \ + mv $@-t $@ + virt-guest-shutdown.target: remote/virt-guest-shutdown.target.in \ $(top_builddir)/config.status $(AM_V_GEN)cp $< $@ diff --git a/src/remote/libvirtd-admin.socket.in b/src/remote/libvirtd-admi= n.socket.in new file mode 100644 index 0000000000..b791a2eb1b --- /dev/null +++ b/src/remote/libvirtd-admin.socket.in @@ -0,0 +1,13 @@ +[Unit] +Description=3DLibvirt admin socket +Before=3Dlibvirtd.service +BindsTo=3Dlibvirtd.socket +After=3Dlibvirtd.socket + +[Socket] +ListenStream=3D@localstatedir@/run/libvirt/libvirt-admin-sock +Service=3Dlibvirtd.service +SocketMode=3D0600 + +[Install] +WantedBy=3Dsockets.target diff --git a/src/remote/libvirtd-ro.socket.in b/src/remote/libvirtd-ro.sock= et.in new file mode 100644 index 0000000000..55c44944b4 --- /dev/null +++ b/src/remote/libvirtd-ro.socket.in @@ -0,0 +1,13 @@ +[Unit] +Description=3DLibvirt local read-only socket +Before=3Dlibvirtd.service +BindsTo=3Dlibvirtd.socket +After=3Dlibvirtd.socket + +[Socket] +ListenStream=3D@localstatedir@/run/libvirt/libvirt-sock-ro +Service=3Dlibvirtd.service +SocketMode=3D0666 + +[Install] +WantedBy=3Dsockets.target diff --git a/src/remote/libvirtd-tcp.socket.in b/src/remote/libvirtd-tcp.so= cket.in new file mode 100644 index 0000000000..09d5d3d67a --- /dev/null +++ b/src/remote/libvirtd-tcp.socket.in @@ -0,0 +1,12 @@ +[Unit] +Description=3DLibvirt non-TLS IP socket +Before=3Dlibvirtd.service +BindsTo=3Dlibvirtd.socket +After=3Dlibvirtd.socket + +[Socket] +ListenStream=3D16509 +Service=3Dlibvirtd.service + +[Install] +WantedBy=3Dsockets.target diff --git a/src/remote/libvirtd-tls.socket.in b/src/remote/libvirtd-tls.so= cket.in new file mode 100644 index 0000000000..c60f0c9c77 --- /dev/null +++ b/src/remote/libvirtd-tls.socket.in @@ -0,0 +1,12 @@ +[Unit] +Description=3DLibvirt TLS IP socket +Before=3Dlibvirtd.service +BindsTo=3Dlibvirtd.socket +After=3Dlibvirtd.socket + +[Socket] +ListenStream=3D16514 +Service=3Dlibvirtd.service + +[Install] +WantedBy=3Dsockets.target diff --git a/src/remote/libvirtd.service.in b/src/remote/libvirtd.service.in index 7f689e08a8..047620f79b 100644 --- a/src/remote/libvirtd.service.in +++ b/src/remote/libvirtd.service.in @@ -1,12 +1,10 @@ -# NB we don't use socket activation. When libvirtd starts it will -# spawn any virtual machines registered for autostart. We want this -# to occur on every boot, regardless of whether any client connects -# to a socket. Thus socket activation doesn't have any benefit - [Unit] Description=3DVirtualization daemon Requires=3Dvirtlogd.socket Requires=3Dvirtlockd.socket +Requires=3Dlibvirtd.socket +Requires=3Dlibvirtd-ro.socket +Requires=3Dlibvirtd-admin.socket Wants=3Dsystemd-machined.service Before=3Dlibvirt-guests.service After=3Dnetwork.target @@ -42,3 +40,5 @@ TasksMax=3D32768 WantedBy=3Dmulti-user.target Also=3Dvirtlockd.socket Also=3Dvirtlogd.socket +Also=3Dlibvirtd.socket +Also=3Dlibvirtd-ro.socket diff --git a/src/remote/libvirtd.socket.in b/src/remote/libvirtd.socket.in new file mode 100644 index 0000000000..e194c6e76e --- /dev/null +++ b/src/remote/libvirtd.socket.in @@ -0,0 +1,11 @@ +[Unit] +Description=3DLibvirt local socket +Before=3Dlibvirtd.service + +[Socket] +ListenStream=3D@localstatedir@/run/libvirt/libvirt-sock +Service=3Dlibvirtd.service +SocketMode=3D0666 + +[Install] +WantedBy=3Dsockets.target --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 04:29:18 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=1561629462; cv=none; d=zoho.com; s=zohoarc; b=kNQoiD8ybr5MTlOkrJyTdCJ5gwTVhvTuJYk/qknlOz99nlcONUishyEpux5T/h0pzOfEWBXHa/5HmI4YG1tYGQknpW6evQF+3kaoSwIp6k1SnhOcov729Ertt83EvIRMgwCET/y1G7f7gZ/FinODibqzbr8ThugxG7R8DCA0hF0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561629462; 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=vR6LsvOOtjikeLp124w6T0Tibv9Kb+d+0XToK3YbaHE=; b=Zawoa6LRLYV7IaAKfVR9eqfR463Fq4XogNMjfDNRrZkzxGk2DPPMJZgRdi6DHV0I5pi2ckFkSPvlrL18kPTiYcfjaPklkJglu4jBxmcsArZ4QX3yE5e1wLUzFLpGfU44jLHBAW7gKbMX+m/F/aj9Yj3vXs5Ba3vWuZOShx8Dl/I= 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 156162946255156.89603878088826; Thu, 27 Jun 2019 02:57:42 -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 B65778553B; Thu, 27 Jun 2019 09:57:30 +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 921C25D719; Thu, 27 Jun 2019 09:57:29 +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 B96AB1806B21; Thu, 27 Jun 2019 09:57:28 +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 x5R9tTxm006452 for ; Thu, 27 Jun 2019 05:55:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3173C60126; Thu, 27 Jun 2019 09:55:29 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-68.ams2.redhat.com [10.36.112.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 68434600CC; Thu, 27 Jun 2019 09:55:28 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 27 Jun 2019 10:54:46 +0100 Message-Id: <20190627095452.28217-18-berrange@redhat.com> In-Reply-To: <20190627095452.28217-1-berrange@redhat.com> References: <20190627095452.28217-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 17/23] remote: make system libvirtd exit when idle via timeout 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.28]); Thu, 27 Jun 2019 09:57:36 +0000 (UTC) Since we have socket activation available now, we can let the system libvirtd exit when it is idle. This allows it to still do autostart when the host boots up, but when nothing was started it will quickly exit again until some mgmt app connects to the socket. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/remote/libvirtd.service.in | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/remote/libvirtd.service.in b/src/remote/libvirtd.service.in index 047620f79b..2e51429e7a 100644 --- a/src/remote/libvirtd.service.in +++ b/src/remote/libvirtd.service.in @@ -21,7 +21,11 @@ Documentation=3Dhttps://libvirt.org [Service] Type=3Dnotify EnvironmentFile=3D-/etc/sysconfig/libvirtd -ExecStart=3D@sbindir@/libvirtd $LIBVIRTD_ARGS +# libvirtd.service is set to run on boot so that autostart of +# VMs can be performed. We don't want it to stick around if +# unused though, so we set a timeout. The socket activation +# then ensures it gets started again if anything needs it +ExecStart=3D@sbindir@/libvirtd --timeout 30 $LIBVIRTD_ARGS ExecReload=3D/bin/kill -HUP $MAINPID KillMode=3Dprocess Restart=3Don-failure --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 04:29:18 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=1561629465; cv=none; d=zoho.com; s=zohoarc; b=ZLPbLmoYhfYlmti51+013dbUk9dKCy5RzoxclfABBQZKmzCmg8LrOBYTh/Hq2bxPnkxUUn1YcoRjYzZuR8DYfilbMZ5eEKf59XkFl4OvE9DCFnc1bSM/cGN166moY2siD1d6k4IZ1gkUgsbsWulHJ2KNmLPWVsDOBYnn/Vuxz3I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561629465; 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=aoV+uEVd5y8tkXwbGPrBP4iet1xYVMkWCohWEOF2f1Y=; b=V44usTvSqPOIZYYWPhqtSXGbFwJqOIFK+4aLzCATWx/VglePA4bySfd5iPmDtN1kjfjcTZwb7MNv8LIMdqbFGEpvtGli0DcE25mEJYWby5r9670DxfTLAhOPkBbFOUS7shCDM+7EyMu24nIDsxUUJGju/kb6P4huPvPc961k2Tg= 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 156162946527082.66731797772854; Thu, 27 Jun 2019 02:57:45 -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 AA73A30BBE7A; Thu, 27 Jun 2019 09:57:43 +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 85FBA60C6A; Thu, 27 Jun 2019 09:57:42 +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 3BB1919729; Thu, 27 Jun 2019 09:57:41 +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 x5R9tW9G006534 for ; Thu, 27 Jun 2019 05:55:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id B401A60126; Thu, 27 Jun 2019 09:55:32 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-68.ams2.redhat.com [10.36.112.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id ACA85600CC; Thu, 27 Jun 2019 09:55:29 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 27 Jun 2019 10:54:47 +0100 Message-Id: <20190627095452.28217-19-berrange@redhat.com> In-Reply-To: <20190627095452.28217-1-berrange@redhat.com> References: <20190627095452.28217-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 18/23] remote: update config files to note usage wrt systemd socket activation 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.49]); Thu, 27 Jun 2019 09:57:44 +0000 (UTC) Certain libvirtd.conf settings are not honoured when using systemd socket activation. Certain systemd unit file settings must match those defined in libvirtd.conf for systemd socket activation to work with systemd version < 227, otherwise libvirtd cannot determine which inherited FD to use for which service. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/remote/libvirtd-admin.socket.in | 2 ++ src/remote/libvirtd-ro.socket.in | 2 ++ src/remote/libvirtd-tcp.socket.in | 2 ++ src/remote/libvirtd-tls.socket.in | 2 ++ src/remote/libvirtd.conf | 31 +++++++++++++++++++++++++++++ src/remote/libvirtd.socket.in | 2 ++ src/remote/libvirtd.sysconf | 3 ++- 7 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/remote/libvirtd-admin.socket.in b/src/remote/libvirtd-admi= n.socket.in index b791a2eb1b..307c9ba24b 100644 --- a/src/remote/libvirtd-admin.socket.in +++ b/src/remote/libvirtd-admin.socket.in @@ -5,6 +5,8 @@ BindsTo=3Dlibvirtd.socket After=3Dlibvirtd.socket =20 [Socket] +# The directory must match the /etc/libvirt/libvirtd.conf unix_sock_dir se= tting +# when using systemd version < 227 ListenStream=3D@localstatedir@/run/libvirt/libvirt-admin-sock Service=3Dlibvirtd.service SocketMode=3D0600 diff --git a/src/remote/libvirtd-ro.socket.in b/src/remote/libvirtd-ro.sock= et.in index 55c44944b4..876daf0c9c 100644 --- a/src/remote/libvirtd-ro.socket.in +++ b/src/remote/libvirtd-ro.socket.in @@ -5,6 +5,8 @@ BindsTo=3Dlibvirtd.socket After=3Dlibvirtd.socket =20 [Socket] +# The directory must match the /etc/libvirt/libvirtd.conf unix_sock_dir se= tting +# when using systemd version < 227 ListenStream=3D@localstatedir@/run/libvirt/libvirt-sock-ro Service=3Dlibvirtd.service SocketMode=3D0666 diff --git a/src/remote/libvirtd-tcp.socket.in b/src/remote/libvirtd-tcp.so= cket.in index 09d5d3d67a..16a4764283 100644 --- a/src/remote/libvirtd-tcp.socket.in +++ b/src/remote/libvirtd-tcp.socket.in @@ -5,6 +5,8 @@ BindsTo=3Dlibvirtd.socket After=3Dlibvirtd.socket =20 [Socket] +# This must match the /etc/libvirt/libvirtd.conf tcp_port setting +# when using systemd version < 227 ListenStream=3D16509 Service=3Dlibvirtd.service =20 diff --git a/src/remote/libvirtd-tls.socket.in b/src/remote/libvirtd-tls.so= cket.in index c60f0c9c77..e904583cf9 100644 --- a/src/remote/libvirtd-tls.socket.in +++ b/src/remote/libvirtd-tls.socket.in @@ -5,6 +5,8 @@ BindsTo=3Dlibvirtd.socket After=3Dlibvirtd.socket =20 [Socket] +# This must match the /etc/libvirt/libvirtd.conf tls_port setting +# when using systemd version < 227 ListenStream=3D16514 Service=3Dlibvirtd.service =20 diff --git a/src/remote/libvirtd.conf b/src/remote/libvirtd.conf index bbeb053495..b63b8d61b7 100644 --- a/src/remote/libvirtd.conf +++ b/src/remote/libvirtd.conf @@ -10,6 +10,9 @@ # NB, must pass the --listen flag to the libvirtd process for this to # have any effect. # +# This setting is not required or honoured if using systemd socket +# activation. +# # It is necessary to setup a CA and issue server certificates before # using this capability. # @@ -20,6 +23,9 @@ # NB, must pass the --listen flag to the libvirtd process for this to # have any effect. # +# This setting is not required or honoured if using systemd socket +# activation. +# # Using the TCP socket requires SASL authentication by default. Only # SASL mechanisms which support data encryption are allowed. This is # DIGEST_MD5 and GSSAPI (Kerberos5) @@ -32,17 +38,26 @@ # Override the port for accepting secure TLS connections # This can be a port number, or service name # +# This setting is not required or honoured if using systemd socket +# activation with systemd version >=3D 227 +# #tls_port =3D "16514" =20 # Override the port for accepting insecure TCP connections # This can be a port number, or service name # +# This setting is not required or honoured if using systemd socket +# activation with systemd version >=3D 227 +# #tcp_port =3D "16509" =20 =20 # Override the default configuration which binds to all network # interfaces. This can be a numeric IPv4/6 address, or hostname # +# This setting is not required or honoured if using systemd socket +# activation. +# # If the libvirtd service is started in parallel with network # startup (e.g. with systemd), binding to addresses other than # the wildcards (0.0.0.0/::) might not be available yet. @@ -59,12 +74,18 @@ # allow a 'trusted' set of users access to management capabilities # without becoming root. # +# This setting is not required or honoured if using systemd socket +# activation. +# # This is restricted to 'root' by default. #unix_sock_group =3D "libvirt" =20 # Set the UNIX socket permissions for the R/O socket. This is used # for monitoring VM status only # +# This setting is not required or honoured if using systemd socket +# activation. +# # Default allows any user. If setting group ownership, you may want to # restrict this too. #unix_sock_ro_perms =3D "0777" @@ -72,6 +93,9 @@ # Set the UNIX socket permissions for the R/W socket. This is used # for full management of VMs # +# This setting is not required or honoured if using systemd socket +# activation. +# # Default allows only root. If PolicyKit is enabled on the socket, # the default will change to allow everyone (eg, 0777) # @@ -81,11 +105,18 @@ =20 # Set the UNIX socket permissions for the admin interface socket. # +# This setting is not required or honoured if using systemd socket +# activation. +# # Default allows only owner (root), do not change it unless you are # sure to whom you are exposing the access to. #unix_sock_admin_perms =3D "0700" =20 # Set the name of the directory in which sockets will be found/created. +# +# This setting is not required or honoured if using systemd socket +# activation with systemd version >=3D 227 +# #unix_sock_dir =3D "/var/run/libvirt" =20 =20 diff --git a/src/remote/libvirtd.socket.in b/src/remote/libvirtd.socket.in index e194c6e76e..2ee4d7d7a2 100644 --- a/src/remote/libvirtd.socket.in +++ b/src/remote/libvirtd.socket.in @@ -3,6 +3,8 @@ Description=3DLibvirt local socket Before=3Dlibvirtd.service =20 [Socket] +# The directory must match the /etc/libvirt/libvirtd.conf unix_sock_dir se= tting +# when using systemd version < 227 ListenStream=3D@localstatedir@/run/libvirt/libvirt-sock Service=3Dlibvirtd.service SocketMode=3D0666 diff --git a/src/remote/libvirtd.sysconf b/src/remote/libvirtd.sysconf index f15e5956eb..7af41c207f 100644 --- a/src/remote/libvirtd.sysconf +++ b/src/remote/libvirtd.sysconf @@ -4,7 +4,8 @@ # in LIBVIRTD_ARGS instead. #LIBVIRTD_CONFIG=3D/etc/libvirt/libvirtd.conf =20 -# Listen for TCP/IP connections +# Listen for TCP/IP connections. This is not required if using systemd +# socket activation. # NB. must setup TLS/SSL keys prior to using this #LIBVIRTD_ARGS=3D"--listen" =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 04:29:18 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=1561629477; cv=none; d=zoho.com; s=zohoarc; b=GW+TJ0YyVcTKtACAbjYVjX4cQGU3h1AKzbvSJgYHgoA1+tYdP+Naydu5bpXEFmytVLzW2UYxAdZk/I6MXGSZ9lQonjQfN0HYKwleQSQPUZ6fbSCNf+FRiR3HLtRHTDRX5r92xqLHgGv3Im/wfDOgSKfs1hEnVhEVZremEyWkj50= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561629477; 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=6wdnHs2RoT7/VlyO7xSv6mHCXT847NvL6pvNLvAE7Gg=; b=IsFMao08GevTcI5UqI6T0xw3VrODwXNRPXWhDXoW9gyigVT1L+Mr5+iBHCTFWQ6Ip7ljyEf3aH92KIyPOJ/OR3TTPNDL0OEi3xUjq7Cdzq7K0P0hnLlF+TdPZTC1naRtOUqP8es29peWIENP8w7KK7yJ41XXwVV/EZ74eY1xAM0= 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 1561629477675373.069482998745; Thu, 27 Jun 2019 02:57:57 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 71D655277D; Thu, 27 Jun 2019 09:57:49 +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 48C261001B1B; Thu, 27 Jun 2019 09:57:49 +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 03C471972A; Thu, 27 Jun 2019 09:57:49 +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 x5R9tYmU006571 for ; Thu, 27 Jun 2019 05:55:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1D4096012E; Thu, 27 Jun 2019 09:55:34 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-68.ams2.redhat.com [10.36.112.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 53974600CC; Thu, 27 Jun 2019 09:55:32 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 27 Jun 2019 10:54:48 +0100 Message-Id: <20190627095452.28217-20-berrange@redhat.com> In-Reply-To: <20190627095452.28217-1-berrange@redhat.com> References: <20190627095452.28217-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 19/23] util: remove code spawning with systemd activation env vars 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-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.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 27 Jun 2019 09:57:51 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The only use of this code was removed by: commit be78814ae07f092d9c4e71fd82dd1947aba2f029 Author: Michal Privoznik Date: Thu Apr 2 14:41:17 2015 +0200 virNetSocketNewConnectUNIX: Use flocks when spawning a daemon less than a year after it was first introduced in commit 1b807f92dbb617db5b9d551777d3026d8ff0903f Author: Martin Kletzander Date: Wed Jul 16 08:00:19 2014 +0200 rpc: pass listen FD to the daemon being started --- src/libvirt_private.syms | 1 - src/util/vircommand.c | 99 ------------------------------------ src/util/vircommand.h | 2 - tests/commanddata/test24.log | 8 --- tests/commandtest.c | 58 --------------------- 5 files changed, 168 deletions(-) delete mode 100644 tests/commanddata/test24.log diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index ee1073e680..c560dda5e8 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1699,7 +1699,6 @@ virCommandNewVAList; virCommandNonblockingFDs; virCommandPassFD; virCommandPassFDGetFDIndex; -virCommandPassListenFDs; virCommandRawStatus; virCommandRequireHandshake; virCommandRun; diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 8695c98d1b..c81ddfc0d0 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -66,7 +66,6 @@ enum { VIR_EXEC_CLEAR_CAPS =3D (1 << 2), VIR_EXEC_RUN_SYNC =3D (1 << 3), VIR_EXEC_ASYNC_IO =3D (1 << 4), - VIR_EXEC_LISTEN_FDS =3D (1 << 5), }; =20 typedef struct _virCommandFD virCommandFD; @@ -205,78 +204,6 @@ virCommandFDSet(virCommandPtr cmd, =20 #ifndef WIN32 =20 -static void -virCommandReorderFDs(virCommandPtr cmd) -{ - int maxfd =3D 0; - int openmax =3D 0; - size_t i =3D 0; - - if (!cmd || cmd->has_error || !cmd->npassfd) - return; - - for (i =3D 0; i < cmd->npassfd; i++) - maxfd =3D MAX(cmd->passfd[i].fd, maxfd); - - openmax =3D sysconf(_SC_OPEN_MAX); - if (openmax < 0 || - maxfd + cmd->npassfd > openmax) - goto error; - - /* - * Simple two-pass sort, nothing fancy. This is not designed for - * anything else than passing around 2 FDs into the child. - * - * So first dup2() them somewhere else. - */ - for (i =3D 0; i < cmd->npassfd; i++) { - int newfd =3D maxfd + i + 1; - int oldfd =3D cmd->passfd[i].fd; - if (dup2(oldfd, newfd) !=3D newfd) { - virReportSystemError(errno, - _("Cannot dup2() fd %d before " - "passing it to the child"), - oldfd); - goto error; - } - VIR_FORCE_CLOSE(cmd->passfd[i].fd); - } - - VIR_DEBUG("First reorder pass done"); - - /* - * And then dup2() them in orderly manner. - */ - for (i =3D 0; i < cmd->npassfd; i++) { - int newfd =3D STDERR_FILENO + i + 1; - int oldfd =3D maxfd + i + 1; - if (dup2(oldfd, newfd) !=3D newfd) { - virReportSystemError(errno, - _("Cannot dup2() fd %d before " - "passing it to the child"), - oldfd); - goto error; - } - if (virSetInherit(newfd, true) < 0) { - virReportSystemError(errno, - _("Cannot set O_CLOEXEC on fd %d before " - "passing it to the child"), - newfd); - goto error; - } - VIR_FORCE_CLOSE(oldfd); - cmd->passfd[i].fd =3D newfd; - } - - VIR_DEBUG("Second reorder pass done"); - - return; - - error: - cmd->has_error =3D -1; - return; -} - /** * virFork: * @@ -763,15 +690,6 @@ virExec(virCommandPtr cmd) goto fork_error; } =20 - if (cmd->flags & VIR_EXEC_LISTEN_FDS) { - virCommandReorderFDs(cmd); - virCommandAddEnvFormat(cmd, "LISTEN_PID=3D%u", getpid()); - virCommandAddEnvFormat(cmd, "LISTEN_FDS=3D%zu", cmd->npassfd); - - if (cmd->has_error) - goto fork_error; - } - /* Close logging again to ensure no FDs leak to child */ virLogReset(); =20 @@ -1002,23 +920,6 @@ virCommandPassFD(virCommandPtr cmd, int fd, unsigned = int flags) } } =20 -/** - * virCommandPassListenFDs: - * @cmd: the command to modify - * - * Pass LISTEN_FDS and LISTEN_PID environment variables into the - * child. LISTEN_PID has the value of the child's PID and LISTEN_FDS - * is a number of passed file descriptors starting from 3. - */ -void -virCommandPassListenFDs(virCommandPtr cmd) -{ - if (!cmd || cmd->has_error) - return; - - cmd->flags |=3D VIR_EXEC_LISTEN_FDS; -} - /* * virCommandPassFDGetFDIndex: * @cmd: pointer to virCommand diff --git a/src/util/vircommand.h b/src/util/vircommand.h index c9a8d3c41c..2a9ee5cdc7 100644 --- a/src/util/vircommand.h +++ b/src/util/vircommand.h @@ -60,8 +60,6 @@ void virCommandPassFD(virCommandPtr cmd, int fd, unsigned int flags) ATTRIBUTE_NOINLINE; =20 -void virCommandPassListenFDs(virCommandPtr cmd); - int virCommandPassFDGetFDIndex(virCommandPtr cmd, int fd); =20 diff --git a/tests/commanddata/test24.log b/tests/commanddata/test24.log deleted file mode 100644 index 38cbb5451b..0000000000 --- a/tests/commanddata/test24.log +++ /dev/null @@ -1,8 +0,0 @@ -FD:0 -FD:1 -FD:2 -FD:3 -FD:4 -DAEMON:yes -CWD:/ -UMASK:0022 diff --git a/tests/commandtest.c b/tests/commandtest.c index 146cc4c1bf..ce0832fb0c 100644 --- a/tests/commandtest.c +++ b/tests/commandtest.c @@ -1003,63 +1003,6 @@ test23(const void *unused ATTRIBUTE_UNUSED) return ret; } =20 -static int test24(const void *unused ATTRIBUTE_UNUSED) -{ - char *pidfile =3D virPidFileBuildPath(abs_builddir, "commandhelper"); - char *prefix =3D NULL; - int newfd1 =3D dup(STDERR_FILENO); - int newfd2 =3D dup(STDERR_FILENO); - int newfd3 =3D dup(STDERR_FILENO); - int ret =3D -1; - pid_t pid; - virCommandPtr cmd =3D virCommandNew(abs_builddir "/commandhelper"); - - if (!pidfile) - goto cleanup; - - if (VIR_CLOSE(newfd1) < 0) - printf("Cannot close fd %d\n", newfd1); - - virCommandSetPidFile(cmd, pidfile); - virCommandDaemonize(cmd); - virCommandPassFD(cmd, newfd2, VIR_COMMAND_PASS_FD_CLOSE_PARENT); - virCommandPassFD(cmd, newfd3, VIR_COMMAND_PASS_FD_CLOSE_PARENT); - newfd2 =3D newfd3 =3D -1; - virCommandPassListenFDs(cmd); - - if (virCommandRun(cmd, NULL) < 0) { - printf("Cannot run child %s\n", virGetLastErrorMessage()); - goto cleanup; - } - - if (virPidFileRead(abs_builddir, "commandhelper", &pid) < 0) { - printf("cannot read pidfile\n"); - goto cleanup; - } - - if (virAsprintf(&prefix, - "ENV:LISTEN_FDS=3D2\nENV:LISTEN_PID=3D%u\n", - pid) < 0) - goto cleanup; - - while (kill(pid, 0) !=3D -1) - usleep(100*1000); - - ret =3D checkoutput("test24", prefix); - - cleanup: - if (pidfile) - unlink(pidfile); - VIR_FREE(pidfile); - VIR_FREE(prefix); - virCommandFree(cmd); - VIR_FORCE_CLOSE(newfd1); - VIR_FORCE_CLOSE(newfd2); - VIR_FORCE_CLOSE(newfd3); - return ret; -} - - static int test25(const void *unused ATTRIBUTE_UNUSED) { int ret =3D -1; @@ -1347,7 +1290,6 @@ mymain(void) DO_TEST(test21); DO_TEST(test22); DO_TEST(test23); - DO_TEST(test24); DO_TEST(test25); DO_TEST(test26); =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 04:29:18 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=1561629485; cv=none; d=zoho.com; s=zohoarc; b=jAHhR6T8EHyQ12YkiHq6e2HUkrC8cc1pqtRcqLMidh3LXqyK7pHrKT04Zw0iJkp8LadiZUBU1OQ3TpQxK4SSX/rspbfBTG7h47Yn9lEs05Pq3uThgZ1NzJUbAU/YB96Akim0uRWKBvJo/qvZwXDA8OKowrtEJjoB2pxbNhOtKIk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561629485; 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=oIZRJQ4xqUPoiWZr7gGHEsNjeuTi9wTlk0+brEHgCY8=; b=dBAYAimQV6qeF9Gru9ux+R3STWSgXp+RtH8+QknjWelT5Glkr/48WQS+uYlqTZcxllmk2Qvp3NmkH6z5+WstLQpLzyUqtRgGazTw2puoO75S4z6GPdbVCcqeZCACm27JCWg6TEhOXdhqqvsGMujNuPix96MMWfojsFnAnJgOKRc= 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 156162948550771.18539797356834; Thu, 27 Jun 2019 02:58:05 -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 281CC3082126; Thu, 27 Jun 2019 09:57:59 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F2E736013A; Thu, 27 Jun 2019 09:57:58 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id B06EA1806B1A; Thu, 27 Jun 2019 09:57:57 +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 x5R9tZWI006614 for ; Thu, 27 Jun 2019 05:55:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id AD44460126; Thu, 27 Jun 2019 09:55:35 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-68.ams2.redhat.com [10.36.112.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 72611600CC; Thu, 27 Jun 2019 09:55:34 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 27 Jun 2019 10:54:49 +0100 Message-Id: <20190627095452.28217-21-berrange@redhat.com> In-Reply-To: <20190627095452.28217-1-berrange@redhat.com> References: <20190627095452.28217-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 20/23] locking: convert lock daemon to use systemd activation APIs 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.42]); Thu, 27 Jun 2019 09:58:02 +0000 (UTC) Using the new system activation APIs allows for simpler code setting up the network services. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/locking/lock_daemon.c | 125 +++++++++++--------------------------- 1 file changed, 37 insertions(+), 88 deletions(-) diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c index 0f90606be6..92d6c717d2 100644 --- a/src/locking/lock_daemon.c +++ b/src/locking/lock_daemon.c @@ -582,78 +582,6 @@ virLockDaemonSetupSignals(virNetDaemonPtr dmn) } =20 =20 -static int -virLockDaemonSetupNetworkingSystemD(virNetServerPtr lockSrv, virNetServerP= tr adminSrv) -{ - unsigned int nfds; - size_t i; - - if ((nfds =3D virGetListenFDs()) =3D=3D 0) - return 0; - if (nfds > 2) - VIR_DEBUG("Too many (%d) file descriptors from systemd", nfds); - - for (i =3D 0; i < nfds && i < 2; i++) { - virNetServerServicePtr svc; - char *path =3D virGetUNIXSocketPath(3 + i); - virNetServerPtr srv; - int fds[] =3D { 3 + i }; - - if (!path) - return -1; - - if (strstr(path, "virtlockd-admin-sock")) { - srv =3D adminSrv; - } else if (strstr(path, "virtlockd-sock")) { - srv =3D lockSrv; - } else { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unknown UNIX socket %s passed in"), - path); - VIR_FREE(path); - return -1; - } - VIR_FREE(path); - - /* Systemd passes FDs, starting immediately after stderr, - * so the first FD we'll get is '3'. */ - if (!(svc =3D virNetServerServiceNewFDs(fds, - ARRAY_CARDINALITY(fds), - false, - 0, - NULL, - false, 0, 1))) - return -1; - - if (virNetServerAddService(srv, svc) < 0) { - virObjectUnref(svc); - return -1; - } - } - return 1; -} - - -static int -virLockDaemonSetupNetworkingNative(virNetServerPtr srv, const char *sock_p= ath) -{ - virNetServerServicePtr svc; - - VIR_DEBUG("Setting up networking natively"); - - if (!(svc =3D virNetServerServiceNewUNIX(sock_path, 0700, 0, 0, - NULL, - false, 0, 1))) - return -1; - - if (virNetServerAddService(srv, svc) < 0) { - virObjectUnref(svc); - return -1; - } - return 0; -} - - struct virLockDaemonClientReleaseData { virLockDaemonClientPtr client; bool hadSomeLeases; @@ -1356,6 +1284,12 @@ int main(int argc, char **argv) { * (but still need to add @lockProgram into @srv). rv =3D=3D 0 means t= hat no * saved state is present, therefore initialize from scratch here. */ if (rv =3D=3D 0) { + VIR_AUTOSTRUCT(virSystemdActivation) *act =3D NULL; + virSystemdActivationMap actmap[] =3D { + { .name =3D "virtlockd.socket", .family =3D AF_UNIX, .path =3D= sock_file }, + { .name =3D "virtlockd-admin.socket", .family =3D AF_UNIX, .pa= th =3D admin_sock_file }, + }; + if (godaemon) { char ebuf[1024]; =20 @@ -1383,31 +1317,46 @@ int main(int argc, char **argv) { goto cleanup; } =20 + if (virSystemdGetActivation(actmap, + ARRAY_CARDINALITY(actmap), + &act) < 0) { + ret =3D VIR_LOCK_DAEMON_ERR_NETWORK; + goto cleanup; + } + lockSrv =3D virNetDaemonGetServer(lockDaemon->dmn, "virtlockd"); adminSrv =3D virNetDaemonGetServer(lockDaemon->dmn, "admin"); - if ((rv =3D virLockDaemonSetupNetworkingSystemD(lockSrv, adminSrv)= ) < 0) { + + if (virNetServerAddServiceUNIX(lockSrv, + act, "virtlockd.socket", + sock_file, 0700, 0, 0, + NULL, + false, 0, 1) < 0) { + ret =3D VIR_LOCK_DAEMON_ERR_NETWORK; + goto cleanup; + } + if (virNetServerAddServiceUNIX(adminSrv, + act, "virtlockd-admin.socket", + admin_sock_file, 0700, 0, 0, + NULL, + false, 0, 1) < 0) { ret =3D VIR_LOCK_DAEMON_ERR_NETWORK; goto cleanup; } =20 - /* Only do this, if systemd did not pass a FD */ - if (rv =3D=3D 0) { - if (virLockDaemonSetupNetworkingNative(lockSrv, sock_file) < 0= || - virLockDaemonSetupNetworkingNative(adminSrv, admin_sock_fi= le) < 0) { - ret =3D VIR_LOCK_DAEMON_ERR_NETWORK; - goto cleanup; - } + if (act && + virSystemdActivationComplete(act) < 0) { + ret =3D VIR_LOCK_DAEMON_ERR_NETWORK; + goto cleanup; } - virObjectUnref(lockSrv); - virObjectUnref(adminSrv); + } else { + lockSrv =3D virNetDaemonGetServer(lockDaemon->dmn, "virtlockd"); + /* If exec-restarting from old virtlockd, we won't have an + * admin server present */ + if (virNetDaemonHasServer(lockDaemon->dmn, "admin")) + adminSrv =3D virNetDaemonGetServer(lockDaemon->dmn, "admin"); } =20 - lockSrv =3D virNetDaemonGetServer(lockDaemon->dmn, "virtlockd"); - /* If exec-restarting from old virtlockd, we won't have an - * admin server present */ - if (virNetDaemonHasServer(lockDaemon->dmn, "admin")) - adminSrv =3D virNetDaemonGetServer(lockDaemon->dmn, "admin"); - if (timeout !=3D -1) { VIR_DEBUG("Registering shutdown timeout %d", timeout); virNetDaemonAutoShutdown(lockDaemon->dmn, --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 04:29:18 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=1561629463; cv=none; d=zoho.com; s=zohoarc; b=c7uLeetCS6CuUUulu4gOq+FEBDdGfA16GX/SvPzb7AImRAAlxSjMLaQaqeViAnAgHHlJm5lBqtETCiawxBNFXYPfIYszL1zQUdbzMEzdG39HoxYro/wu6l8kcIESvjo/pu1+ETBA+nBguZC7Zn6Pmy2xzFoD5BZzinNHT4SSuyQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561629463; 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=juR9G46Ud4vI4mETIBR8yjByky+sPzt4RjaeyFbZ5Y0=; b=Ra9YsEf3snpkb7FSchUJ5B4HRHLkJ11ipG9sJ3j55onNWv6QK+Bx50J1wKZ98G9qaYVEEjN47F3FbK67BcnmvMRVxzI5FYRaJQI597jPBSb+cWHZjbmsfkK46GJbbMXoBm3CVMrMCbBngImUliHGEZVTbBnqsi61T1hBHcQIOPg= 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 1561629463149509.08080468853916; Thu, 27 Jun 2019 02:57:43 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 665D07FDF0; Thu, 27 Jun 2019 09:57:36 +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 40B185DA34; Thu, 27 Jun 2019 09:57:36 +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 029F319727; Thu, 27 Jun 2019 09:57:36 +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 x5R9tb6u006656 for ; Thu, 27 Jun 2019 05:55:37 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5060A6012E; Thu, 27 Jun 2019 09:55:37 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-68.ams2.redhat.com [10.36.112.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 61648600CC; Thu, 27 Jun 2019 09:55:35 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 27 Jun 2019 10:54:50 +0100 Message-Id: <20190627095452.28217-22-berrange@redhat.com> In-Reply-To: <20190627095452.28217-1-berrange@redhat.com> References: <20190627095452.28217-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 21/23] logging: convert log daemon to use systemd activation APIs 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 27 Jun 2019 09:57:36 +0000 (UTC) Using the new system activation APIs allows for simpler code setting up the network services. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/logging/log_daemon.c | 125 ++++++++++++--------------------------- 1 file changed, 37 insertions(+), 88 deletions(-) diff --git a/src/logging/log_daemon.c b/src/logging/log_daemon.c index 30c70a20dd..2dd91d3c3d 100644 --- a/src/logging/log_daemon.c +++ b/src/logging/log_daemon.c @@ -517,78 +517,6 @@ virLogDaemonSetupSignals(virNetDaemonPtr dmn) } =20 =20 -static int -virLogDaemonSetupNetworkingSystemD(virNetServerPtr logSrv, virNetServerPtr= adminSrv) -{ - unsigned int nfds; - size_t i; - - if ((nfds =3D virGetListenFDs()) =3D=3D 0) - return 0; - if (nfds > 2) - VIR_DEBUG("Too many (%d) file descriptors from systemd", nfds); - - for (i =3D 0; i < nfds && i < 2; i++) { - virNetServerServicePtr svc; - char *path =3D virGetUNIXSocketPath(3 + i); - virNetServerPtr srv; - int fds[] =3D { 3 + i }; - - if (!path) - return -1; - - if (strstr(path, "virtlogd-admin-sock")) { - srv =3D adminSrv; - } else if (strstr(path, "virtlogd-sock")) { - srv =3D logSrv; - } else { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unknown UNIX socket %s passed in"), - path); - VIR_FREE(path); - return -1; - } - VIR_FREE(path); - - /* Systemd passes FDs, starting immediately after stderr, - * so the first FD we'll get is '3'. */ - if (!(svc =3D virNetServerServiceNewFDs(fds, - ARRAY_CARDINALITY(fds), - false, - 0, - NULL, - false, 0, 1))) - return -1; - - if (virNetServerAddService(srv, svc) < 0) { - virObjectUnref(svc); - return -1; - } - } - return 1; -} - - -static int -virLogDaemonSetupNetworkingNative(virNetServerPtr srv, const char *sock_pa= th) -{ - virNetServerServicePtr svc; - - VIR_DEBUG("Setting up networking natively"); - - if (!(svc =3D virNetServerServiceNewUNIX(sock_path, 0700, 0, 0, - NULL, - false, 0, 1))) - return -1; - - if (virNetServerAddService(srv, svc) < 0) { - virObjectUnref(svc); - return -1; - } - return 0; -} - - static void virLogDaemonClientFree(void *opaque) { @@ -1129,6 +1057,12 @@ int main(int argc, char **argv) { * scratch if rv =3D=3D 0 */ if (rv =3D=3D 0) { + VIR_AUTOSTRUCT(virSystemdActivation) *act =3D NULL; + virSystemdActivationMap actmap[] =3D { + { .name =3D "virtlogd.socket", .family =3D AF_UNIX, .path =3D = sock_file }, + { .name =3D "virtlogd-admin.socket", .family =3D AF_UNIX, .pat= h =3D admin_sock_file }, + }; + if (godaemon) { char ebuf[1024]; =20 @@ -1156,31 +1090,46 @@ int main(int argc, char **argv) { goto cleanup; } =20 + if (virSystemdGetActivation(actmap, + ARRAY_CARDINALITY(actmap), + &act) < 0) { + ret =3D VIR_LOG_DAEMON_ERR_NETWORK; + goto cleanup; + } + logSrv =3D virNetDaemonGetServer(logDaemon->dmn, "virtlogd"); adminSrv =3D virNetDaemonGetServer(logDaemon->dmn, "admin"); - if ((rv =3D virLogDaemonSetupNetworkingSystemD(logSrv, adminSrv)) = < 0) { + + if (virNetServerAddServiceUNIX(logSrv, + act, "virtlogd.socket", + sock_file, 0700, 0, 0, + NULL, + false, 0, 1) < 0) { + ret =3D VIR_LOG_DAEMON_ERR_NETWORK; + goto cleanup; + } + if (virNetServerAddServiceUNIX(adminSrv, + act, "virtlogd-admin.socket", + admin_sock_file, 0700, 0, 0, + NULL, + false, 0, 1) < 0) { ret =3D VIR_LOG_DAEMON_ERR_NETWORK; goto cleanup; } =20 - /* Only do this, if systemd did not pass a FD */ - if (rv =3D=3D 0) { - if (virLogDaemonSetupNetworkingNative(logSrv, sock_file) < 0 || - virLogDaemonSetupNetworkingNative(adminSrv, admin_sock_fil= e) < 0) { - ret =3D VIR_LOG_DAEMON_ERR_NETWORK; - goto cleanup; - } + if (act && + virSystemdActivationComplete(act) < 0) { + ret =3D VIR_LOG_DAEMON_ERR_NETWORK; + goto cleanup; } - virObjectUnref(logSrv); - virObjectUnref(adminSrv); + } else { + logSrv =3D virNetDaemonGetServer(logDaemon->dmn, "virtlogd"); + /* If exec-restarting from old virtlogd, we won't have an + * admin server present */ + if (virNetDaemonHasServer(logDaemon->dmn, "admin")) + adminSrv =3D virNetDaemonGetServer(logDaemon->dmn, "admin"); } =20 - logSrv =3D virNetDaemonGetServer(logDaemon->dmn, "virtlogd"); - /* If exec-restarting from old virtlogd, we won't have an - * admin server present */ - if (virNetDaemonHasServer(logDaemon->dmn, "admin")) - adminSrv =3D virNetDaemonGetServer(logDaemon->dmn, "admin"); - if (timeout !=3D -1) { VIR_DEBUG("Registering shutdown timeout %d", timeout); virNetDaemonAutoShutdown(logDaemon->dmn, --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 04:29:18 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=1561629485; cv=none; d=zoho.com; s=zohoarc; b=ZgDt3ESmkUG+dsSKeUdQiueSM63YEVfGs216N0kjWvnFZ2wTfCKEIilquAjRD8QTe60AHQs7DlVvBknN9t2PKMwTij1Rlayzr4i+fM1V95rdsUy4a0GMcIRmXlZ2xb62KIFF1PM1hopGx+BYGHgk4VGgCbAHVRSjwE08bKAb8Ok= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561629485; 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=psrWavsV0HZXR5lLHhdp/cDlZA5ykFBKKsYl8a9Q47I=; b=eY5il4EDO/e8p1hXwT2QFcwqa5BrohFTh/GAshzQNAlf9o42vL1ZZuPwFj3ZSdyYv3H63xbfmd63mp2lnsGp4Vh6BYlxGW5EH8T7ojtJ4zq96Hwj5wxUHRWLG/qGEjpN69F0ErZnyJvkAhI+UTfiVt3KgOuYnA3x4yxB1brYFTs= 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 1561629485645443.32719970117955; Thu, 27 Jun 2019 02:58:05 -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 155018552A; Thu, 27 Jun 2019 09:58: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 DEC0E60C6A; Thu, 27 Jun 2019 09:58:02 +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 94CE11806B21; Thu, 27 Jun 2019 09:58:02 +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 x5R9tdTh006699 for ; Thu, 27 Jun 2019 05:55:39 -0400 Received: by smtp.corp.redhat.com (Postfix) id 03E736012E; Thu, 27 Jun 2019 09:55:39 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-68.ams2.redhat.com [10.36.112.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id E4FE060126; Thu, 27 Jun 2019 09:55:37 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 27 Jun 2019 10:54:51 +0100 Message-Id: <20190627095452.28217-23-berrange@redhat.com> In-Reply-To: <20190627095452.28217-1-berrange@redhat.com> References: <20190627095452.28217-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 22/23] util: move code for getting listen FDs into systemd module 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.28]); Thu, 27 Jun 2019 09:58:03 +0000 (UTC) The virGetListenFDs method no longer needs to be called directly, so it can be a static function internal to the systemd code. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/libvirt_private.syms | 1 - src/util/virsystemd.c | 74 +++++++++++++++++++++++++++++++++++++++- src/util/virutil.c | 72 -------------------------------------- src/util/virutil.h | 1 - 4 files changed, 73 insertions(+), 75 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index c560dda5e8..37a8ff1285 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3247,7 +3247,6 @@ virGetGroupList; virGetGroupName; virGetHostname; virGetHostnameQuiet; -virGetListenFDs; virGetSelfLastChanged; virGetSystemPageSize; virGetSystemPageSizeKB; diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c index ae8401343d..f6c5adc5ef 100644 --- a/src/util/virsystemd.c +++ b/src/util/virsystemd.c @@ -756,6 +756,78 @@ virSystemdActivationInitFromMap(virSystemdActivationPt= r act, return -1; } =20 +#ifndef WIN32 + +/** + * virSystemdGetListenFDs: + * + * Parse LISTEN_PID and LISTEN_FDS passed from caller. + * + * Returns number of passed FDs. + */ +static unsigned int +virSystemdGetListenFDs(void) +{ + const char *pidstr; + const char *fdstr; + size_t i =3D 0; + unsigned long long procid; + unsigned int nfds; + + VIR_DEBUG("Setting up networking from caller"); + + if (!(pidstr =3D virGetEnvAllowSUID("LISTEN_PID"))) { + VIR_DEBUG("No LISTEN_PID from caller"); + return 0; + } + + if (virStrToLong_ull(pidstr, NULL, 10, &procid) < 0) { + VIR_DEBUG("Malformed LISTEN_PID from caller %s", pidstr); + return 0; + } + + if ((pid_t)procid !=3D getpid()) { + VIR_DEBUG("LISTEN_PID %s is not for us %lld", + pidstr, (long long) getpid()); + return 0; + } + + if (!(fdstr =3D virGetEnvAllowSUID("LISTEN_FDS"))) { + VIR_DEBUG("No LISTEN_FDS from caller"); + return 0; + } + + if (virStrToLong_ui(fdstr, NULL, 10, &nfds) < 0) { + VIR_DEBUG("Malformed LISTEN_FDS from caller %s", fdstr); + return 0; + } + + unsetenv("LISTEN_PID"); + unsetenv("LISTEN_FDS"); + + VIR_DEBUG("Got %u file descriptors", nfds); + + for (i =3D 0; i < nfds; i++) { + int fd =3D STDERR_FILENO + i + 1; + + VIR_DEBUG("Disabling inheritance of passed FD %d", fd); + + if (virSetInherit(fd, false) < 0) + VIR_WARN("Couldn't disable inheritance of passed FD %d", fd); + } + + return nfds; +} + +#else /* WIN32 */ + +static unsigned int +virSystemdGetListenFDs(void) +{ + return 0; +} + +#endif /* WIN32 */ =20 static virSystemdActivationPtr virSystemdActivationNew(virSystemdActivationMap *map, @@ -812,7 +884,7 @@ virSystemdGetActivation(virSystemdActivationMap *map, { int nfds =3D 0; =20 - if ((nfds =3D virGetListenFDs()) < 0) + if ((nfds =3D virSystemdGetListenFDs()) < 0) return -1; =20 if (nfds =3D=3D 0) { diff --git a/src/util/virutil.c b/src/util/virutil.c index b85769d936..4bd719127b 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -1784,78 +1784,6 @@ void virUpdateSelfLastChanged(const char *path) } } =20 -#ifndef WIN32 - -/** - * virGetListenFDs: - * - * Parse LISTEN_PID and LISTEN_FDS passed from caller. - * - * Returns number of passed FDs. - */ -unsigned int -virGetListenFDs(void) -{ - const char *pidstr; - const char *fdstr; - size_t i =3D 0; - unsigned long long procid; - unsigned int nfds; - - VIR_DEBUG("Setting up networking from caller"); - - if (!(pidstr =3D virGetEnvAllowSUID("LISTEN_PID"))) { - VIR_DEBUG("No LISTEN_PID from caller"); - return 0; - } - - if (virStrToLong_ull(pidstr, NULL, 10, &procid) < 0) { - VIR_DEBUG("Malformed LISTEN_PID from caller %s", pidstr); - return 0; - } - - if ((pid_t)procid !=3D getpid()) { - VIR_DEBUG("LISTEN_PID %s is not for us %lld", - pidstr, (long long) getpid()); - return 0; - } - - if (!(fdstr =3D virGetEnvAllowSUID("LISTEN_FDS"))) { - VIR_DEBUG("No LISTEN_FDS from caller"); - return 0; - } - - if (virStrToLong_ui(fdstr, NULL, 10, &nfds) < 0) { - VIR_DEBUG("Malformed LISTEN_FDS from caller %s", fdstr); - return 0; - } - - unsetenv("LISTEN_PID"); - unsetenv("LISTEN_FDS"); - - VIR_DEBUG("Got %u file descriptors", nfds); - - for (i =3D 0; i < nfds; i++) { - int fd =3D STDERR_FILENO + i + 1; - - VIR_DEBUG("Disabling inheritance of passed FD %d", fd); - - if (virSetInherit(fd, false) < 0) - VIR_WARN("Couldn't disable inheritance of passed FD %d", fd); - } - - return nfds; -} - -#else /* WIN32 */ - -unsigned int -virGetListenFDs(void) -{ - return 0; -} - -#endif /* WIN32 */ =20 #ifdef HAVE_SYS_UN_H char *virGetUNIXSocketPath(int fd) diff --git a/src/util/virutil.h b/src/util/virutil.h index 67a21c86bd..b9715e5e66 100644 --- a/src/util/virutil.h +++ b/src/util/virutil.h @@ -149,7 +149,6 @@ bool virIsSUID(void); time_t virGetSelfLastChanged(void); void virUpdateSelfLastChanged(const char *path); =20 -unsigned int virGetListenFDs(void); char *virGetUNIXSocketPath(int fd); =20 long virGetSystemPageSize(void) ATTRIBUTE_NOINLINE; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 04:29:18 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=1561629467; cv=none; d=zoho.com; s=zohoarc; b=QRCuOs4vQO0ItLfD8FNvGItveKoBsiV/b3naU14LKTi+f66bkhsVwZ426xTx5CPSiyZAzeyBC5g6wW5HHosVQW0Oe/L/fSvnMNap9n9kKf+tRiZzZY1Lt//Vzh3eLWB/r9tcgHgyl7oZASv029MMSR0lhVDgEzsQgpNSoBhUKNM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561629467; 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=TNFr1gYRpuWHKra60p1KNiZOymI7T726yYVzSn+uoHA=; b=LDGTZtkRmSrJUOtvMl03lOKrw6Q/9SBy5HW2O9YA/QMQrXyRCb0+qsHLGSbHJtA9r/0EVi+ydztCsC9W4hr4Oq+NUSKwqfnw+E4VHkmJ1OKCwiARVugiSuH9vfq3rmnmYfNJlTYhGp8/h77z+/jU30s/gIIfA21eBM98HCsTpYQ= 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 1561629467566401.85530544525; Thu, 27 Jun 2019 02:57:47 -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 4CCA834CF; Thu, 27 Jun 2019 09:57:43 +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 200FD1974B; Thu, 27 Jun 2019 09:57:43 +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 D80421806B1A; Thu, 27 Jun 2019 09:57:42 +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 x5R9te1i006737 for ; Thu, 27 Jun 2019 05:55:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4850460126; Thu, 27 Jun 2019 09:55:40 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-68.ams2.redhat.com [10.36.112.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5D2BD600CC; Thu, 27 Jun 2019 09:55:39 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 27 Jun 2019 10:54:52 +0100 Message-Id: <20190627095452.28217-24-berrange@redhat.com> In-Reply-To: <20190627095452.28217-1-berrange@redhat.com> References: <20190627095452.28217-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 23/23] util: remove unused helper for getting UNIX socket path 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.29]); Thu, 27 Jun 2019 09:57:43 +0000 (UTC) The new systemd activation APIs mean there is no longer a need to get the UNIX socket path associated with a plain FD. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/libvirt_private.syms | 1 - src/util/virutil.c | 44 ---------------------------------------- src/util/virutil.h | 2 -- 3 files changed, 47 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 37a8ff1285..600a4dea13 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3250,7 +3250,6 @@ virGetHostnameQuiet; virGetSelfLastChanged; virGetSystemPageSize; virGetSystemPageSizeKB; -virGetUNIXSocketPath; virGetUnprivSGIOSysfsPath; virGetUserCacheDirectory; virGetUserConfigDirectory; diff --git a/src/util/virutil.c b/src/util/virutil.c index 4bd719127b..019009be8c 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -1785,50 +1785,6 @@ void virUpdateSelfLastChanged(const char *path) } =20 =20 -#ifdef HAVE_SYS_UN_H -char *virGetUNIXSocketPath(int fd) -{ - union { - struct sockaddr sa; - struct sockaddr_storage ss; - struct sockaddr_un un; - } addr =3D { .ss =3D { 0 } }; - socklen_t len =3D sizeof(addr.ss); - char *path; - - if (getsockname(fd, &addr.sa, &len) < 0) { - virReportSystemError(errno, _("Unable to get address of FD %d"), f= d); - return NULL; - } - - if (addr.ss.ss_family !=3D AF_UNIX) { - virReportSystemError(EINVAL, _("FD %d is not a UNIX socket, has af= =3D%d"), - fd, addr.ss.ss_family); - return NULL; - } - - if (addr.un.sun_path[0] =3D=3D '\0') - addr.un.sun_path[0] =3D '@'; - - if (VIR_ALLOC_N(path, sizeof(addr.un.sun_path) + 1) < 0) - return NULL; - - memcpy(path, addr.un.sun_path, sizeof(addr.un.sun_path)); - path[sizeof(addr.un.sun_path)] =3D '\0'; - return path; -} - -#else /* HAVE_SYS_UN_H */ - -char *virGetUNIXSocketPath(int fd ATTRIBUTE_UNUSED) -{ - virReportSystemError(ENOSYS, "%s", - _("UNIX sockets not supported on this platform")); - return NULL; -} - -#endif /* HAVE_SYS_UN_H */ - #ifndef WIN32 long virGetSystemPageSize(void) { diff --git a/src/util/virutil.h b/src/util/virutil.h index b9715e5e66..7ea702f27a 100644 --- a/src/util/virutil.h +++ b/src/util/virutil.h @@ -149,8 +149,6 @@ bool virIsSUID(void); time_t virGetSelfLastChanged(void); void virUpdateSelfLastChanged(const char *path); =20 -char *virGetUNIXSocketPath(int fd); - long virGetSystemPageSize(void) ATTRIBUTE_NOINLINE; long virGetSystemPageSizeKB(void) ATTRIBUTE_NOINLINE; =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list