From nobody Sat Feb 7 15:22:01 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=NsUvaYxkbIC+B1EHkucaqtt32OKYCOdK+D8ZzvXG8NzjZVMZDnovuPIIXxFpnaCx6X0M5vrOyVNypvcON1gsUS5tE53W6fZugPrlZDIO3o7MRqjsvEpdFq02lp85itiunuiwnB3W19zjs/+EteOa3tFx4RFPayXFa1EBYiyeSVw= 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=8wzJxI15S3fkp+W2cfqEFPaee/HBBvJ4Ar2xLewFgD0=; b=WDx0xPEI3zJwOAhhbFXSYSRG/ZL1Wub55bCFJsWY5iOA+lKaqyKT3qwQcoCR0WrUQZ25UFXNhZFjKP00l4/lD1UFxLiN/o/vUUZP25pALb58iTmSukyE3THi/7BCjUifQck5Ssm9kSRpoBh/+YGveSdPvsRsbzlvwzh2xVZUR9Q= 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 1562773702150957.2937468152511; 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 71B1830ADC7C; Wed, 10 Jul 2019 15:48:20 +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 180F660C79; Wed, 10 Jul 2019 15:48:20 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id CD4D719727; 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 x6AFmIWU017969 for ; Wed, 10 Jul 2019 11:48:18 -0400 Received: by smtp.corp.redhat.com (Postfix) id 44BD61001B16; Wed, 10 Jul 2019 15:48:18 +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 71B281001E65; Wed, 10 Jul 2019 15:48:17 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Wed, 10 Jul 2019 16:47:41 +0100 Message-Id: <20190710154741.17065-13-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 12/12] bhyve: 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.47]); 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/bhyve/driver.pid In unprivileged libvirtd this ends up locking /run/user/$UID/libvirt/bhyve/run/driver.pid NB, the latter can vary depending on $XDG_RUNTIME_DIR Signed-off-by: Daniel P. Berrang=C3=A9 --- src/bhyve/bhyve_driver.c | 9 +++++++++ src/bhyve/bhyve_utils.h | 3 +++ 2 files changed, 12 insertions(+) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 4ce9ef0b95..cfcf4e1fba 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -43,6 +43,7 @@ #include "virthread.h" #include "virlog.h" #include "virfile.h" +#include "virpidfile.h" #include "virtypedparam.h" #include "virrandom.h" #include "virstring.h" @@ -1203,6 +1204,9 @@ bhyveStateCleanup(void) virObjectUnref(bhyve_driver->config); virPortAllocatorRangeFree(bhyve_driver->remotePorts); =20 + if (bhyve_driver->lockFD !=3D -1) + virPidFileRelease(BHYVE_STATE_DIR, "driver", bhyve_driver->lockFD); + virMutexDestroy(&bhyve_driver->lock); VIR_FREE(bhyve_driver); =20 @@ -1222,6 +1226,7 @@ bhyveStateInitialize(bool privileged, if (VIR_ALLOC(bhyve_driver) < 0) return -1; =20 + bhyve_driver->lockFD =3D -1; if (virMutexInit(&bhyve_driver->lock) < 0) { VIR_FREE(bhyve_driver); return -1; @@ -1274,6 +1279,10 @@ bhyveStateInitialize(bool privileged, goto cleanup; } =20 + if ((bhyve_driver->lockFD =3D + virPidFileAcquire(BHYVE_STATE_DIR, "driver", true, getpid())) < 0) + goto cleanup; + if (virDomainObjListLoadAllConfigs(bhyve_driver->domains, BHYVE_STATE_DIR, NULL, true, diff --git a/src/bhyve/bhyve_utils.h b/src/bhyve/bhyve_utils.h index 26956d7d21..3d212e3ccf 100644 --- a/src/bhyve/bhyve_utils.h +++ b/src/bhyve/bhyve_utils.h @@ -48,6 +48,9 @@ struct _bhyveConn { =20 virBhyveDriverConfigPtr config; =20 + /* pid file FD, ensures two copies of the driver can't use the same ro= ot */ + int lockFD; + virDomainObjListPtr domains; virCapsPtr caps; virDomainXMLOptionPtr xmlopt; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list