From nobody Sat Feb 7 15:35:26 2026 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=1562773702; cv=none; d=zoho.com; s=zohoarc; b=mwFdFzXG7LkM0ykTFNzYcaL5i734IHh64CpNwyDqa2ZrJqEz7eyz60sy6EMuflyvFiMmeKkZT7buow03gwskmsHhd+G63OODesP2Pxc1kT5kYLXK9/mkoFkZ2r2wVpaKDrTZI0gchduhvs8DWlmmf2PyWVcZvAF+UnLUmegF5VQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562773702; 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=BfGlxLaRe/79kgrgeBDqhK5NRle77U5+KRM/3U8jsnU=; b=O4WeQzlPdc8/NtUp51xtpwlhFKZVkn4AuodK9+GEIRSylUljQi9CxKwuwH1xbOvdzSVuYxQ1wWz4fKU+bZScgRKj6tuDVh3F3ynzxAbGexRzb7lf4PYKWsGnwrNowz39OZPTJiDjtjB5VakiSu/pESk5rWMkhfCCUCbpbWw70e8= 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 1562773702243669.9372077878664; Wed, 10 Jul 2019 08:48:22 -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 4D92D317F381; Wed, 10 Jul 2019 15:48:20 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E4E3C60C61; Wed, 10 Jul 2019 15:48:19 +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 9F60418433B2; Wed, 10 Jul 2019 15:48:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x6AFmHLS017927 for ; Wed, 10 Jul 2019 11:48:17 -0400 Received: by smtp.corp.redhat.com (Postfix) id 22EEB10190D3; Wed, 10 Jul 2019 15:48:17 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-53.ams2.redhat.com [10.36.112.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 28C8A1001B11; Wed, 10 Jul 2019 15:48:15 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Wed, 10 Jul 2019 16:47:40 +0100 Message-Id: <20190710154741.17065-12-berrange@redhat.com> In-Reply-To: <20190710154741.17065-1-berrange@redhat.com> References: <20190710154741.17065-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 11/12] vz: acquire a pidfile in the driver root directory 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.41]); Wed, 10 Jul 2019 15:48:21 +0000 (UTC) When we allow multiple instances of the driver for the same user account, using a separate root directory, we need to ensure mutual exclusion. Use a pidfile to guarantee this. In privileged libvirtd this ends up locking /var/run/libvirt/vz/driver.pid In unprivileged libvirtd this ends up locking /run/user/$UID/libvirt/vz/run/driver.pid NB, the latter can vary depending on $XDG_RUNTIME_DIR Signed-off-by: Daniel P. Berrang=C3=A9 --- src/vz/vz_driver.c | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index 2286f9a04f..c5152c309c 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -41,6 +41,7 @@ #include "vircommand.h" #include "configmake.h" #include "virfile.h" +#include "virpidfile.h" #include "virstoragefile.h" #include "virstring.h" #include "cpu/cpu.h" @@ -59,8 +60,13 @@ VIR_LOG_INIT("parallels.parallels_driver"); =20 #define PRLCTL "prlctl" =20 +#define VZ_STATEDIR LOCALSTATEDIR "/run/libvirt/vz" + static virClassPtr vzDriverClass; =20 +static bool vz_driver_privileged; +/* pid file FD, ensures two copies of the driver can't use the same root */ +static int vz_driver_lock_fd =3D -1; static virMutex vz_driver_lock; static vzDriverPtr vz_driver; static vzConnPtr vz_conn_list; @@ -166,6 +172,11 @@ VIR_ONCE_GLOBAL_INIT(vzDriver); vzDriverPtr vzGetDriverConnection(void) { + if (!vz_driver_privileged) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("vz state driver is not active")); + return NULL; + } virMutexLock(&vz_driver_lock); if (!vz_driver) vz_driver =3D vzDriverObjNew(); @@ -4087,18 +4098,37 @@ static virConnectDriver vzConnectDriver =3D { static int vzStateCleanup(void) { - virObjectUnref(vz_driver); - vz_driver =3D NULL; - virMutexDestroy(&vz_driver_lock); - prlsdkDeinit(); + if (vz_driver_privileged) { + virObjectUnref(vz_driver); + vz_driver =3D NULL; + if (vz_driver_lock_fd !=3D -1) + virPidFileRelease(VZ_STATEDIR, "driver", vz_driver_lock_fd); + virMutexDestroy(&vz_driver_lock); + prlsdkDeinit(); + } return 0; } =20 static int -vzStateInitialize(bool privileged ATTRIBUTE_UNUSED, +vzStateInitialize(bool privileged, virStateInhibitCallback callback ATTRIBUTE_UNUSED, void *opaque ATTRIBUTE_UNUSED) { + if (!privileged) + return 0; + + vz_driver_privileged =3D privileged; + + if (virFileMakePathWithMode(VZ_STATEDIR, S_IRWXU) < 0) { + virReportSystemError(errno, _("cannot create state directory '%s'"= ), + VZ_STATEDIR); + return -1; + } + + if ((vz_driver_lock_fd =3D + virPidFileAcquire(VZ_STATEDIR, "driver", true, getpid())) < 0) + return -1; + if (prlsdkInit() < 0) { VIR_DEBUG("%s", _("Can't initialize Parallels SDK")); return -1; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list