From nobody Sat Feb 7 15:12:10 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=1562773674; cv=none; d=zoho.com; s=zohoarc; b=Rw6kIaofHJ2MQloA0ye/205OAZj70/o617OLEl7hwIv7O2YJp2rHGFFROo0ulMWHodk8gixdk87h+GxOpmypNWZoPalShaRFikK73rKN/po+SzMucP3Ncavbp5w7OqHzxBZaBt/VS3K9GgzqXp4Pxfir7W+102H0aoKpedIJifc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562773674; 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=f66HRFObyCo6MqPl79L94oOypxuTAfaF9OXnCJqkiiU=; b=ExTOmIRoOYAJgow0Zm6+fuOShDWAO3aQ6xH8PSgFXuQvPvjVIylVdrkE2nUzl44n3hqPRic98O+jG42ndDTUzGkq9GXhBU43OXF2ouqFqobpSkSI+JV6dykwYYWkyi1ss1Xr5kR3Y5n/LPoJql6RxldIy8tpu0vp++F0BueRc9Y= 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 15627736745379.148362692661294; Wed, 10 Jul 2019 08:47:54 -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 021AF3084243; Wed, 10 Jul 2019 15:47:53 +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 D4B6684977; Wed, 10 Jul 2019 15:47:52 +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 9E2BE206D5; Wed, 10 Jul 2019 15:47:52 +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 x6AFlpTP017768 for ; Wed, 10 Jul 2019 11:47:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id C28431001DCC; Wed, 10 Jul 2019 15:47:51 +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 EBEC11001B1B; Wed, 10 Jul 2019 15:47:50 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Wed, 10 Jul 2019 16:47:30 +0100 Message-Id: <20190710154741.17065-2-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 01/12] qemu: 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Wed, 10 Jul 2019 15:47:53 +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/qemu/driver.pid In unprivileged libvirtd this ends up locking /run/user/$UID/libvirt/qemu/run/driver.pid NB, the latter can vary depending on $XDG_RUNTIME_DIR Signed-off-by: Daniel P. Berrang=C3=A9 --- src/qemu/qemu_conf.h | 3 +++ src/qemu/qemu_driver.c | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index e51514a344..2229b76e89 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -221,6 +221,9 @@ struct _virQEMUDriver { * then lockless thereafter */ virQEMUDriverConfigPtr config; =20 + /* pid file FD, ensures two copies of the driver can't use the same ro= ot */ + int lockFD; + /* Immutable pointer, self-locking APIs */ virThreadPoolPtr workerPool; =20 diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 5a75f23981..8bc069d3e2 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -70,6 +70,7 @@ #include "node_device_conf.h" #include "virpci.h" #include "virusb.h" +#include "virpidfile.h" #include "virprocess.h" #include "libvirt_internal.h" #include "virxml.h" @@ -587,6 +588,8 @@ qemuStateInitialize(bool privileged, if (VIR_ALLOC(qemu_driver) < 0) return -1; =20 + qemu_driver->lockFD =3D -1; + if (virMutexInit(&qemu_driver->lock) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot initialize mutex")); @@ -673,6 +676,10 @@ qemuStateInitialize(bool privileged, goto error; } =20 + if ((qemu_driver->lockFD =3D + virPidFileAcquire(cfg->stateDir, "driver", true, getpid())) < 0) + goto error; + qemu_driver->qemuImgBinary =3D virFindFileInPath("qemu-img"); =20 if (!(qemu_driver->lockManager =3D @@ -1032,6 +1039,8 @@ qemuStateCleanup(void) if (!qemu_driver) return -1; =20 + if (qemu_driver->lockFD !=3D -1) + virPidFileRelease(qemu_driver->config->stateDir, "driver", qemu_dr= iver->lockFD); virThreadPoolFree(qemu_driver->workerPool); virObjectUnref(qemu_driver->config); virObjectUnref(qemu_driver->hostdevMgr); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list