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=1562773698; cv=none; d=zoho.com; s=zohoarc; b=U3t5DD673LMr5OW8sJ75UN2u4rPKsxhndfaoO6O24jZZ6KgzCoXcY673BKtjh+igA0yuaXldBnp5KLrLwPZnFCWedp0XJkKG+fO7rTpZQlmr5D1Pt7FsaenqD0zNfeb7pj6aFiyd9k0C9sqQ7dRvT0xVa1gPTu9DPpu6JWey5Yk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562773698; 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=ROb5glGYqPGv7cPqJuFgwXUrjzhN4zaXPmI1njkoyZM=; b=PZWqmS5kMs91X9YY9x8UAJ7+pn6kXkxh+GqwCBAfVdRio1SStmO6EUgwuNMdhHMklhOBTfWFUmcnqGn2b0ESLCTc01z5Syh6D6w3rtkzvQmEaGr0apCwr/YM9tY88Sv22cOJ5f4kZxT2msdw+AwqBqj+Zbg8vVnrMJDxmfFwCNg= 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 1562773698706588.1238264078628; Wed, 10 Jul 2019 08:48:18 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E07EB30C585C; Wed, 10 Jul 2019 15:48:16 +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 B0BF960A97; Wed, 10 Jul 2019 15:48:16 +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 6B46E19727; Wed, 10 Jul 2019 15:48:16 +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 x6AFmEmA017871 for ; Wed, 10 Jul 2019 11:48:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7DB1A10027D1; Wed, 10 Jul 2019 15:48:14 +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 B76C51001DDA; Wed, 10 Jul 2019 15:48:13 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Wed, 10 Jul 2019 16:47:38 +0100 Message-Id: <20190710154741.17065-10-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 09/12] libxl: 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Wed, 10 Jul 2019 15:48:17 +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/libxl/driver.pid In unprivileged libvirtd this ends up locking /run/user/$UID/libvirt/libxl/run/driver.pid NB, the latter can vary depending on $XDG_RUNTIME_DIR Signed-off-by: Daniel P. Berrang=C3=A9 --- src/libxl/libxl_conf.h | 3 +++ src/libxl/libxl_driver.c | 11 ++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/libxl/libxl_conf.h b/src/libxl/libxl_conf.h index 136b5ae1ac..552f039d2a 100644 --- a/src/libxl/libxl_conf.h +++ b/src/libxl/libxl_conf.h @@ -111,6 +111,9 @@ struct _libxlDriverPrivate { * then lockless thereafter */ libxlDriverConfigPtr config; =20 + /* pid file FD, ensures two copies of the driver can't use the same ro= ot */ + int lockFD; + /* Atomic inc/dec only */ unsigned int nactive; =20 diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index ac10fb6dbc..a99c7471bb 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -53,6 +53,7 @@ #include "viraccessapicheck.h" #include "viratomic.h" #include "virhostdev.h" +#include "virpidfile.h" #include "locking/domain_lock.h" #include "virnetdevtap.h" #include "cpu/cpu.h" @@ -506,7 +507,6 @@ libxlStateCleanup(void) return -1; =20 virObjectUnref(libxl_driver->hostdevMgr); - virObjectUnref(libxl_driver->config); virObjectUnref(libxl_driver->xmlopt); virObjectUnref(libxl_driver->domains); virPortAllocatorRangeFree(libxl_driver->reservedGraphicsPorts); @@ -516,6 +516,10 @@ libxlStateCleanup(void) virObjectUnref(libxl_driver->domainEventState); virSysinfoDefFree(libxl_driver->hostsysinfo); =20 + if (libxl_driver->lockFD !=3D -1) + virPidFileRelease(libxl_driver->config->stateDir, "driver", libxl_= driver->lockFD); + + virObjectUnref(libxl_driver->config); virMutexDestroy(&libxl_driver->lock); VIR_FREE(libxl_driver); =20 @@ -658,6 +662,7 @@ libxlStateInitialize(bool privileged, if (VIR_ALLOC(libxl_driver) < 0) return -1; =20 + libxl_driver->lockFD =3D -1; if (virMutexInit(&libxl_driver->lock) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot initialize mutex")); @@ -741,6 +746,10 @@ libxlStateInitialize(bool privileged, goto error; } =20 + if ((libxl_driver->lockFD =3D + virPidFileAcquire(cfg->stateDir, "driver", true, getpid())) < 0) + goto error; + if (!(libxl_driver->lockManager =3D virLockManagerPluginNew(cfg->lockManagerName ? cfg->lockManagerName : "nop", --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list