From nobody Fri Apr 19 01:49:01 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=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 Reviewed-by: Michal Privoznik --- 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 From nobody Fri Apr 19 01:49:01 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=1562773678; cv=none; d=zoho.com; s=zohoarc; b=HTtGmOHKIqTm9KZ1B/gw9IlZ/Y1p5gyj4Dipv/DoeHYaVdD6n0lwaqf7oYYtB04LOCJy7td9mHp1iUwtamjTlfpCE0tl0uwWAvUQtXIoM9D/VM7QNUvwdsw+W1WuP138UMKv/BAQL9a7LhaAgvA1+jQO/Ie9uCpOy4bb6PS5QVA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562773678; 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=+lBfLlt9fVclRT7qSr4nWOawVpjCFpMWRA9JHUGqvqw=; b=UuD8K5T1CEY+91r0EjxioIcn9XA0KItHa6+9HP5QM5Svo0UBEUq1HnUD1ls8FV43+Pi8KU1GXRE4k7LsjsDjOaboV9qeTXFusagLcon3TCMFv7xskoJ4zx9TOAYUQXNx1U7S2ACcq376/thoMsnnMrAmHZPXzApaQ//Or+N+Ekw= 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 1562773678211574.220477568253; Wed, 10 Jul 2019 08:47:58 -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 AC39430001D8; Wed, 10 Jul 2019 15:47:56 +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 7DF887E2D; Wed, 10 Jul 2019 15:47: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 37449206D8; Wed, 10 Jul 2019 15:47:56 +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 x6AFlrLv017776 for ; Wed, 10 Jul 2019 11:47:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id 01B971001DDD; Wed, 10 Jul 2019 15:47:53 +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 3066D1001B1B; Wed, 10 Jul 2019 15:47:51 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Wed, 10 Jul 2019 16:47:31 +0100 Message-Id: <20190710154741.17065-3-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 02/12] secrets: 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.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.46]); Wed, 10 Jul 2019 15:47:57 +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/secrets/driver.pid In unprivileged libvirtd this ends up locking /run/user/$UID/libvirt/secrets/run/driver.pid NB, the latter can vary depending on $XDG_RUNTIME_DIR Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Michal Privoznik --- src/secret/secret_driver.c | 44 +++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c index ac85f5d195..9344948db4 100644 --- a/src/secret/secret_driver.c +++ b/src/secret/secret_driver.c @@ -37,6 +37,7 @@ #include "viruuid.h" #include "virerror.h" #include "virfile.h" +#include "virpidfile.h" #include "configmake.h" #include "virstring.h" #include "viraccessapicheck.h" @@ -56,8 +57,12 @@ struct _virSecretDriverState { virMutex lock; bool privileged; /* readonly */ virSecretObjListPtr secrets; + char *stateDir; char *configDir; =20 + /* pid file FD, ensures two copies of the driver can't use the same ro= ot */ + int lockFD; + /* Immutable pointer, self-locking APIs */ virObjectEventStatePtr secretEventState; }; @@ -434,6 +439,10 @@ secretStateCleanup(void) =20 virObjectUnref(driver->secretEventState); =20 + if (driver->lockFD !=3D -1) + virPidFileRelease(driver->stateDir, "driver", driver->lockFD); + + VIR_FREE(driver->stateDir); secretDriverUnlock(); virMutexDestroy(&driver->lock); VIR_FREE(driver); @@ -447,11 +456,10 @@ secretStateInitialize(bool privileged, virStateInhibitCallback callback ATTRIBUTE_UNUSED, void *opaque ATTRIBUTE_UNUSED) { - char *base =3D NULL; - if (VIR_ALLOC(driver) < 0) return -1; =20 + driver->lockFD =3D -1; if (virMutexInit(&driver->lock) < 0) { VIR_FREE(driver); return -1; @@ -462,15 +470,26 @@ secretStateInitialize(bool privileged, driver->privileged =3D privileged; =20 if (privileged) { - if (VIR_STRDUP(base, SYSCONFDIR "/libvirt") < 0) + if (virAsprintf(&driver->configDir, + "%s/libvirt/secrets", SYSCONFDIR) < 0) + goto error; + if (virAsprintf(&driver->stateDir, + "%s/run/libvirt/secrets", LOCALSTATEDIR) < 0) goto error; } else { - if (!(base =3D virGetUserConfigDirectory())) + VIR_AUTOFREE(char *) rundir =3D NULL; + VIR_AUTOFREE(char *) cfgdir =3D NULL; + + if (!(cfgdir =3D virGetUserConfigDirectory())) + goto error; + if (virAsprintf(&driver->configDir, "%s/secrets/", cfgdir) < 0) + goto error; + + if (!(rundir =3D virGetUserRuntimeDirectory())) + goto error; + if (virAsprintf(&driver->stateDir, "%s/secrets/run", rundir) < 0) goto error; } - if (virAsprintf(&driver->configDir, "%s/secrets", base) < 0) - goto error; - VIR_FREE(base); =20 if (virFileMakePathWithMode(driver->configDir, S_IRWXU) < 0) { virReportSystemError(errno, _("cannot create config directory '%s'= "), @@ -478,6 +497,16 @@ secretStateInitialize(bool privileged, goto error; } =20 + if (virFileMakePathWithMode(driver->stateDir, S_IRWXU) < 0) { + virReportSystemError(errno, _("cannot create state directory '%s'"= ), + driver->stateDir); + goto error; + } + + if ((driver->lockFD =3D + virPidFileAcquire(driver->stateDir, "driver", true, getpid())) < = 0) + goto error; + if (!(driver->secrets =3D virSecretObjListNew())) goto error; =20 @@ -488,7 +517,6 @@ secretStateInitialize(bool privileged, return 0; =20 error: - VIR_FREE(base); secretDriverUnlock(); secretStateCleanup(); return -1; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 01:49:01 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=1562773683; cv=none; d=zoho.com; s=zohoarc; b=IbcrlE7wxlxk3MdPsZru58aBzSLT42d2NHbP7tEs7dZRD5HWnMNnurwWm6eGRxIwgHMgedYvDnbfzdqF1EgVgU5LmJaTIyAsaEkjz2SX0q05yrWWG6yQX47ilSz+vtgcHPYRvmkdNrhNpo/fuQ8y84p1iWV48wOg0yNJ5NJpgZE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562773683; 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=ACpX7X5R8MUije8VjQpLKJ+vUU+5Sz6yXwIRAuKTkNI=; b=GrAplw2mMaSNNLRp+cHXmnG86G8AoZNyCk+a0wQgD4KSfMId/hYolP8S6qJxqKwtyxdqirjt7FAYp28x/V62WGZN6t19JtYxdCm20fwbRzLpo7JjQj+jj6WzIJaQHTqHkjruMgUo/MHw05NS8EEzNLDfnKfXE+AvgVQfd49lVxM= 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 15627736831091008.8251891181874; Wed, 10 Jul 2019 08:48:03 -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 4B90A2EF17D; Wed, 10 Jul 2019 15:48:01 +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 189BE608A6; Wed, 10 Jul 2019 15:48: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 9612918433A9; Wed, 10 Jul 2019 15:48:00 +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 x6AFlsAS017783 for ; Wed, 10 Jul 2019 11:47:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id 246871001B34; Wed, 10 Jul 2019 15:47:54 +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 679E510190A1; Wed, 10 Jul 2019 15:47:53 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Wed, 10 Jul 2019 16:47:32 +0100 Message-Id: <20190710154741.17065-4-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 03/12] network: 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.29]); Wed, 10 Jul 2019 15:48:01 +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/network/driver.pid In unprivileged libvirtd this ends up locking /run/user/$UID/libvirt/network/run/driver.pid NB, the latter can vary depending on $XDG_RUNTIME_DIR Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Michal Privoznik --- src/network/bridge_driver.c | 10 ++++++++++ src/network/bridge_driver_platform.h | 3 +++ 2 files changed, 13 insertions(+) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 19faf7d514..6292e3b90a 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -597,6 +597,7 @@ networkStateInitialize(bool privileged, if (VIR_ALLOC(network_driver) < 0) goto error; =20 + network_driver->lockFD =3D -1; if (virMutexInit(&network_driver->lock) < 0) { VIR_FREE(network_driver); goto error; @@ -651,6 +652,11 @@ networkStateInitialize(bool privileged, goto error; } =20 + if ((network_driver->lockFD =3D + virPidFileAcquire(network_driver->stateDir, "driver", + true, getpid())) < 0) + goto error; + /* if this fails now, it will be retried later with dnsmasqCapsRefresh= () */ network_driver->dnsmasqCaps =3D dnsmasqCapsNewFromBinary(DNSMASQ); =20 @@ -764,6 +770,10 @@ networkStateCleanup(void) /* free inactive networks */ virObjectUnref(network_driver->networks); =20 + if (network_driver->lockFD !=3D -1) + virPidFileRelease(network_driver->stateDir, "driver", + network_driver->lockFD); + VIR_FREE(network_driver->networkConfigDir); VIR_FREE(network_driver->networkAutostartDir); VIR_FREE(network_driver->stateDir); diff --git a/src/network/bridge_driver_platform.h b/src/network/bridge_driv= er_platform.h index 1efa0d2af4..95993c5e31 100644 --- a/src/network/bridge_driver_platform.h +++ b/src/network/bridge_driver_platform.h @@ -34,6 +34,9 @@ struct _virNetworkDriverState { /* Read-only */ bool privileged; =20 + /* pid file FD, ensures two copies of the driver can't use the same ro= ot */ + int lockFD; + /* Immutable pointer, self-locking APIs */ virNetworkObjListPtr networks; =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 01:49:01 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=1562773679; cv=none; d=zoho.com; s=zohoarc; b=Q+rHCPHX9zuySH2IwrKU2YGtogfQ9FmcmXftGhPngQmnOvtttEGzT4oVZWJh2+2AWpZvWrEl65plCLAFmej/LvnNuATYVkW4MnYGZXT4og4xmLpzz8eNGrNj8y5KGASu63IJaxZnZdph4d7EBmnjYneyZg6ux0xu2MaTQtK6j9A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562773679; 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=voTYYHwC2nj+pKjmZdVciRZwfzWnYZeKEikaDDCpubM=; b=CSgZh35rA9GPyEwyDmfiLqy9IrZV6+I+10eok7/jUqtL7pcD3N5qgnftGuzNXijbexQ2IVgeMsnnhHXlyLzESDaBN//PPRDn2KMK2ZwoD/0BOH2tROVV+ARnz9wibCEKnZ7tr4eDnfJPOqzff26v8GnuOZIbr9nrliUWfsNtw6A= 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 1562773679747591.9522600515301; Wed, 10 Jul 2019 08:47:59 -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 1B25530C1333; Wed, 10 Jul 2019 15:47: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 E270460603; Wed, 10 Jul 2019 15:47:57 +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 A6B3018433A4; Wed, 10 Jul 2019 15:47:57 +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 x6AFltkq017794 for ; Wed, 10 Jul 2019 11:47:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id BD5F21001DD9; Wed, 10 Jul 2019 15:47:55 +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 9430E1001DCF; Wed, 10 Jul 2019 15:47:54 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Wed, 10 Jul 2019 16:47:33 +0100 Message-Id: <20190710154741.17065-5-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 04/12] storage: 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.45]); Wed, 10 Jul 2019 15:47:58 +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/storage/driver.pid In unprivileged libvirtd this ends up locking /run/user/$UID/libvirt/storage/run/driver.pid NB, the latter can vary depending on $XDG_RUNTIME_DIR Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Michal Privoznik --- src/conf/virstorageobj.h | 3 +++ src/storage/storage_driver.c | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/conf/virstorageobj.h b/src/conf/virstorageobj.h index 92d229f9b4..4547a0df9b 100644 --- a/src/conf/virstorageobj.h +++ b/src/conf/virstorageobj.h @@ -37,6 +37,9 @@ typedef virStorageDriverState *virStorageDriverStatePtr; struct _virStorageDriverState { virMutex lock; =20 + /* pid file FD, ensures two copies of the driver can't use the same ro= ot */ + int lockFD; + virStoragePoolObjListPtr pools; =20 char *configDir; diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 496d51b1e0..03ac6a6845 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -43,6 +43,7 @@ #include "virlog.h" #include "virfile.h" #include "virfdstream.h" +#include "virpidfile.h" #include "configmake.h" #include "virsecret.h" #include "virstring.h" @@ -256,6 +257,7 @@ storageStateInitialize(bool privileged, if (VIR_ALLOC(driver) < 0) return -1; =20 + driver->lockFD =3D -1; if (virMutexInit(&driver->lock) < 0) { VIR_FREE(driver); return -1; @@ -296,6 +298,11 @@ storageStateInitialize(bool privileged, goto error; } =20 + if ((driver->lockFD =3D + virPidFileAcquire(driver->stateDir, "driver", + true, getpid())) < 0) + goto error; + if (virStoragePoolObjLoadAllState(driver->pools, driver->stateDir) < 0) goto error; @@ -371,6 +378,10 @@ storageStateCleanup(void) /* free inactive pools */ virObjectUnref(driver->pools); =20 + if (driver->lockFD !=3D -1) + virPidFileRelease(driver->stateDir, "driver", + driver->lockFD); + VIR_FREE(driver->configDir); VIR_FREE(driver->autostartDir); VIR_FREE(driver->stateDir); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 01:49:01 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=1562773683; cv=none; d=zoho.com; s=zohoarc; b=Y/0isoiRz5EMOijzH1cRWQEHQYgrQ8yzUG1BA3INB+0boC5rEBVD3rB32vl7/8n4BiOS9hYWtxR+8uK7t4ReqYTCfpsWAR+aYxs0vqjCV5oBpHz4R3TA20ah7qPPR7s5aWFp6gCA6TuQUq/B8f6BhHorISjcIf75T6fgC7+mhd0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562773683; 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=lUny9mmSpLzTLA4v0LepMr/mFWoYFLABnkgPFPIvNZY=; b=bIgt0tD0eSKAdU7V2NpK4e+4Vqcs3rkmetR7gwjG+TDUwQBOfC0W8EeTdIS+76gsgpC9uJOknVxaa2VCth9vQDK0KXQjCJ/u6vDZGllQBuYL+f1Zo5vhktk36L4gsEsjGvb2Di35OlBu/t1lKJCCO5hrzDEJnOh9ThWKvtIUbRM= 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 1562773683333105.11913281604711; Wed, 10 Jul 2019 08:48:03 -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 A21B530C1E2B; Wed, 10 Jul 2019 15:48:01 +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 794D584D85; Wed, 10 Jul 2019 15:48: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 41CC4206D9; Wed, 10 Jul 2019 15:48:01 +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 x6AFluQp017804 for ; Wed, 10 Jul 2019 11:47:56 -0400 Received: by smtp.corp.redhat.com (Postfix) id EB3B41001DDD; Wed, 10 Jul 2019 15:47:56 +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 2E21F1001E63; Wed, 10 Jul 2019 15:47:55 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Wed, 10 Jul 2019 16:47:34 +0100 Message-Id: <20190710154741.17065-6-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 05/12] nodedev: 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.47]); Wed, 10 Jul 2019 15:48:02 +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/nodedev/driver.pid In unprivileged libvirtd this ends up locking /run/user/$UID/libvirt/nodedev/run/driver.pid NB, the latter can vary depending on $XDG_RUNTIME_DIR Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Michal Privoznik --- src/conf/virnodedeviceobj.h | 5 +++++ src/node_device/node_device_hal.c | 31 +++++++++++++++++++++++++++++ src/node_device/node_device_udev.c | 32 ++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) diff --git a/src/conf/virnodedeviceobj.h b/src/conf/virnodedeviceobj.h index 1abfcb9af4..c4d3c55d73 100644 --- a/src/conf/virnodedeviceobj.h +++ b/src/conf/virnodedeviceobj.h @@ -37,6 +37,11 @@ typedef virNodeDeviceDriverState *virNodeDeviceDriverSta= tePtr; struct _virNodeDeviceDriverState { virMutex lock; =20 + /* pid file FD, ensures two copies of the driver can't use the same ro= ot */ + int lockFD; + + char *stateDir; + virNodeDeviceObjListPtr devs; /* currently-known devices */ void *privateData; /* driver-specific private data */ bool privileged; /* whether we run in privileged mo= de */ diff --git a/src/node_device/node_device_hal.c b/src/node_device/node_devic= e_hal.c index d1eb6c7851..876e808dce 100644 --- a/src/node_device/node_device_hal.c +++ b/src/node_device/node_device_hal.c @@ -33,10 +33,13 @@ #include "viralloc.h" #include "viruuid.h" #include "virpci.h" +#include "virpidfile.h" #include "virlog.h" #include "virdbus.h" #include "virstring.h" =20 +#include "configmake.h" + #define VIR_FROM_THIS VIR_FROM_NODEDEV =20 VIR_LOG_INIT("node_device.node_device_hal"); @@ -606,12 +609,36 @@ nodeStateInitialize(bool privileged ATTRIBUTE_UNUSED, if (VIR_ALLOC(driver) < 0) return -1; =20 + driver->lockFD =3D -1; if (virMutexInit(&driver->lock) < 0) { VIR_FREE(driver); return -1; } nodeDeviceLock(); =20 + if (privileged) { + if (virAsprintf(&driver->stateDir, + "%s/run/libvirt/nodedev", LOCALSTATEDIR) < 0) + goto failure; + } else { + VIR_AUTOFREE(char *) rundir =3D NULL; + + if (!(rundir =3D virGetUserRuntimeDirectory())) + goto failure; + if (virAsprintf(&driver->stateDir, "%s/nodedev/run", rundir) < 0) + goto failure; + } + + if (virFileMakePathWithMode(driver->stateDir, S_IRWXU) < 0) { + virReportSystemError(errno, _("cannot create state directory '%s'"= ), + driver->stateDir); + goto failure; + } + + if ((driver->lockFD =3D + virPidFileAcquire(driver->stateDir, "driver", true, getpid())) < = 0) + goto failure; + if (!(driver->devs =3D virNodeDeviceObjListNew())) goto failure; =20 @@ -708,6 +735,10 @@ nodeStateCleanup(void) virNodeDeviceObjListFree(driver->devs); (void)libhal_ctx_shutdown(hal_ctx, NULL); (void)libhal_ctx_free(hal_ctx); + if (driver->lockFD !=3D -1) + virPidFileRelease(driver->stateDir, "driver", driver->lockFD); + + VIR_FREE(driver->stateDir); nodeDeviceUnlock(); virMutexDestroy(&driver->lock); VIR_FREE(driver); diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 276bf3dd99..d883462948 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -38,10 +38,13 @@ #include "virbuffer.h" #include "virfile.h" #include "virpci.h" +#include "virpidfile.h" #include "virstring.h" #include "virnetdev.h" #include "virmdev.h" =20 +#include "configmake.h" + #define VIR_FROM_THIS VIR_FROM_NODEDEV =20 VIR_LOG_INIT("node_device.node_device_udev"); @@ -1494,6 +1497,11 @@ nodeStateCleanup(void) virObjectUnref(driver->nodeDeviceEventState); =20 virNodeDeviceObjListFree(driver->devs); + + if (driver->lockFD !=3D -1) + virPidFileRelease(driver->stateDir, "driver", driver->lockFD); + + VIR_FREE(driver->stateDir); virMutexDestroy(&driver->lock); VIR_FREE(driver); =20 @@ -1810,6 +1818,7 @@ nodeStateInitialize(bool privileged, if (VIR_ALLOC(driver) < 0) return -1; =20 + driver->lockFD =3D -1; if (virMutexInit(&driver->lock) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Unable to initialize mutex")); @@ -1819,6 +1828,29 @@ nodeStateInitialize(bool privileged, =20 driver->privileged =3D privileged; =20 + if (privileged) { + if (virAsprintf(&driver->stateDir, + "%s/run/libvirt/nodedev", LOCALSTATEDIR) < 0) + goto cleanup; + } else { + VIR_AUTOFREE(char *) rundir =3D NULL; + + if (!(rundir =3D virGetUserRuntimeDirectory())) + goto cleanup; + if (virAsprintf(&driver->stateDir, "%s/nodedev/run", rundir) < 0) + goto cleanup; + } + + if (virFileMakePathWithMode(driver->stateDir, S_IRWXU) < 0) { + virReportSystemError(errno, _("cannot create state directory '%s'"= ), + driver->stateDir); + goto cleanup; + } + + if ((driver->lockFD =3D + virPidFileAcquire(driver->stateDir, "driver", true, getpid())) < = 0) + goto cleanup; + if (!(driver->devs =3D virNodeDeviceObjListNew()) || !(priv =3D udevEventDataNew())) goto cleanup; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 01:49:01 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=1562773682; cv=none; d=zoho.com; s=zohoarc; b=JGbGp/EJQktghN75DVEQsvby3G1jiZi+KZ8VU785rScUSNNOBLqXLntVZJcPeNHi7/KQ/qAe00f7VU9apfbgvZd7rV/SaaNGk4vQlOZLxrgmNkdV1OQh+xmMrNYJCQ8JxJUfvu7URkBCM2DPjVcR1PDg8a0PxPtJ5yV2+Ai3q8Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562773682; 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=DgjrHVSUGjUZjNPf8DrNQs7fNhWaKktOyvAIo1/aHL4=; b=GfHf9ZIRlmEuoscIerP4+QfB0SvFpSLmM6C/Jj6AObuaUz6Arj1C7iTE6EbA0ajGJwifqQp1oKtD4tDdLSXzqzq+tM8hK/qPQRop2ettX807IRZD4WQIrkqQJbhtrXPz/VbCe2ZiTu0Cxt8Rq2QOLRveqtyBwanZS/E3zQ5GRrA= 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 1562773682264866.9701951600152; Wed, 10 Jul 2019 08:48:02 -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 934AE30860D7; Wed, 10 Jul 2019 15:48:00 +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 4B87311A4E3; Wed, 10 Jul 2019 15:48:00 +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 F3E6718433A7; Wed, 10 Jul 2019 15:47:59 +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 x6AFlwnU017814 for ; Wed, 10 Jul 2019 11:47:58 -0400 Received: by smtp.corp.redhat.com (Postfix) id 507F31001B28; Wed, 10 Jul 2019 15:47:58 +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 4A0721001E9A; Wed, 10 Jul 2019 15:47:57 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Wed, 10 Jul 2019 16:47:35 +0100 Message-Id: <20190710154741.17065-7-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 06/12] interface: 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 10 Jul 2019 15:48:01 +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/interface/driver.pid In unprivileged libvirtd this ends up locking /run/user/$UID/libvirt/interface/run/driver.pid NB, the latter can vary depending on $XDG_RUNTIME_DIR Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Michal Privoznik --- src/interface/interface_backend_netcf.c | 45 +++++++++++++++++++++++-- src/interface/interface_backend_udev.c | 44 +++++++++++++++++++++++- 2 files changed, 85 insertions(+), 4 deletions(-) diff --git a/src/interface/interface_backend_netcf.c b/src/interface/interf= ace_backend_netcf.c index cf8eb9488d..868e49c56e 100644 --- a/src/interface/interface_backend_netcf.c +++ b/src/interface/interface_backend_netcf.c @@ -29,10 +29,14 @@ #include "interface_conf.h" #include "viralloc.h" #include "virlog.h" +#include "virfile.h" +#include "virpidfile.h" #include "virstring.h" #include "viraccessapicheck.h" #include "virinterfaceobj.h" =20 +#include "configmake.h" + #define VIR_FROM_THIS VIR_FROM_INTERFACE =20 VIR_LOG_INIT("interface.interface_backend_netcf"); @@ -43,6 +47,10 @@ VIR_LOG_INIT("interface.interface_backend_netcf"); typedef struct { virObjectLockable parent; + /* pid file FD, ensures two copies of the driver can't use the same ro= ot */ + int lockFD; + + char *stateDir; struct netcf *netcf; bool privileged; } virNetcfDriverState, *virNetcfDriverStatePtr; @@ -71,6 +79,11 @@ virNetcfDriverStateDispose(void *obj) =20 if (_driver->netcf) ncf_close(_driver->netcf); + + if (_driver->lockFD !=3D -1) + virPidFileRelease(_driver->stateDir, "driver", _driver->lockFD); + + VIR_FREE(_driver->stateDir); } =20 =20 @@ -87,15 +100,41 @@ netcfStateInitialize(bool privileged, =20 driver->privileged =3D privileged; =20 + if (privileged) { + if (virAsprintf(&driver->stateDir, + "%s/run/libvirt/nodedev", LOCALSTATEDIR) < 0) + goto error; + } else { + VIR_AUTOFREE(char *) rundir =3D NULL; + + if (!(rundir =3D virGetUserRuntimeDirectory())) + goto error; + if (virAsprintf(&driver->stateDir, "%s/nodedev/run", rundir) < 0) + goto error; + } + + if (virFileMakePathWithMode(driver->stateDir, S_IRWXU) < 0) { + virReportSystemError(errno, _("cannot create state directory '%s'"= ), + driver->stateDir); + goto error; + } + + if ((driver->lockFD =3D + virPidFileAcquire(driver->stateDir, "driver", true, getpid())) < = 0) + goto error; + /* open netcf */ if (ncf_init(&driver->netcf, NULL) !=3D 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("failed to initialize netcf")); - virObjectUnref(driver); - driver =3D NULL; - return -1; + goto error; } return 0; + + error: + virObjectUnref(driver); + driver =3D NULL; + return -1; } =20 =20 diff --git a/src/interface/interface_backend_udev.c b/src/interface/interfa= ce_backend_udev.c index 1373356246..fcd7f1c04a 100644 --- a/src/interface/interface_backend_udev.c +++ b/src/interface/interface_backend_udev.c @@ -32,14 +32,21 @@ #include "interface_conf.h" #include "viralloc.h" #include "virstring.h" +#include "virpidfile.h" #include "viraccessapicheck.h" #include "virinterfaceobj.h" #include "virnetdev.h" =20 +#include "configmake.h" + #define VIR_FROM_THIS VIR_FROM_INTERFACE =20 struct udev_iface_driver { struct udev *udev; + /* pid file FD, ensures two copies of the driver can't use the same ro= ot */ + int lockFD; + + char *stateDir; bool privileged; }; =20 @@ -1157,6 +1164,9 @@ udevInterfaceIsActive(virInterfacePtr ifinfo) } =20 =20 +static int +udevStateCleanup(void); + static int udevStateInitialize(bool privileged, virStateInhibitCallback callback ATTRIBUTE_UNUSED, @@ -1167,6 +1177,31 @@ udevStateInitialize(bool privileged, if (VIR_ALLOC(driver) < 0) goto cleanup; =20 + driver->lockFD =3D -1; + + if (privileged) { + if (virAsprintf(&driver->stateDir, + "%s/run/libvirt/nodedev", LOCALSTATEDIR) < 0) + goto cleanup; + } else { + VIR_AUTOFREE(char *) rundir =3D NULL; + + if (!(rundir =3D virGetUserRuntimeDirectory())) + goto cleanup; + if (virAsprintf(&driver->stateDir, "%s/nodedev/run", rundir) < 0) + goto cleanup; + } + + if (virFileMakePathWithMode(driver->stateDir, S_IRWXU) < 0) { + virReportSystemError(errno, _("cannot create state directory '%s'"= ), + driver->stateDir); + goto cleanup; + } + + if ((driver->lockFD =3D + virPidFileAcquire(driver->stateDir, "driver", true, getpid())) < = 0) + goto cleanup; + driver->udev =3D udev_new(); if (!driver->udev) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -1178,6 +1213,8 @@ udevStateInitialize(bool privileged, ret =3D 0; =20 cleanup: + if (ret < 0) + udevStateCleanup(); return ret; } =20 @@ -1187,8 +1224,13 @@ udevStateCleanup(void) if (!driver) return -1; =20 - udev_unref(driver->udev); + if (driver->udev) + udev_unref(driver->udev); + + if (driver->lockFD !=3D -1) + virPidFileRelease(driver->stateDir, "driver", driver->lockFD); =20 + VIR_FREE(driver->stateDir); VIR_FREE(driver); return 0; } --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 01:49:01 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=1562773687; cv=none; d=zoho.com; s=zohoarc; b=hikQnpouGeEigjRe4UhIbs8JyouGuu7GfHREujsAeY+gPUYPpNdp8TUrFBB+2O9Jbu/uBtQYODL3GQ+QA7pJDsYe99HGSpdLSKlfWb0qn4a9DID36QkI1IOUNz1rYWqdttV2QLpDkaqwen74XKP764qIrA0+jQ5bHpCrXJa/XBE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562773687; 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=zkr7S5hhOtlZY0ekbsWmNpzg6TJOoIP6Z5tcqaHiAe4=; b=VjvKQ7xsW0SjtTas+TwEpQbykJANXabmt4rskyymhCCqJWmWa+USyN5IlGuInS7LuJN5IQZooDaiZiKlY2DqkN7sHn5gd6+apOtgroAJ5cVq7XSL7y8mqSh7fJttxTlxXPSoCpSR6WIcjcyw2oJpzPIA5NIQ0eyzrkS2CWiYcgQ= 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 1562773687470175.0388668336101; Wed, 10 Jul 2019 08:48:07 -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 4993C7BEFB; Wed, 10 Jul 2019 15:48:05 +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 252C21001DDD; Wed, 10 Jul 2019 15:48:05 +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 DA8E4206DE; Wed, 10 Jul 2019 15:48:04 +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 x6AFlx9J017824 for ; Wed, 10 Jul 2019 11:47:59 -0400 Received: by smtp.corp.redhat.com (Postfix) id BE19210027BF; Wed, 10 Jul 2019 15:47:59 +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 C28541001DDD; Wed, 10 Jul 2019 15:47:58 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Wed, 10 Jul 2019 16:47:36 +0100 Message-Id: <20190710154741.17065-8-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 07/12] nwfilter: 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.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.28]); Wed, 10 Jul 2019 15:48:06 +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/nwfilter/driver.pid In unprivileged libvirtd this ends up locking /run/user/$UID/libvirt/nwfilter/run/driver.pid NB, the latter can vary depending on $XDG_RUNTIME_DIR Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Michal Privoznik --- src/conf/virnwfilterobj.h | 4 ++++ src/nwfilter/nwfilter_driver.c | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/conf/virnwfilterobj.h b/src/conf/virnwfilterobj.h index bdf5c51fe2..a6bdfb3864 100644 --- a/src/conf/virnwfilterobj.h +++ b/src/conf/virnwfilterobj.h @@ -36,10 +36,14 @@ struct _virNWFilterDriverState { virMutex lock; bool privileged; =20 + /* pid file FD, ensures two copies of the driver can't use the same ro= ot */ + int lockFD; + virNWFilterObjListPtr nwfilters; =20 virNWFilterBindingObjListPtr bindings; =20 + char *stateDir; char *configDir; char *bindingDir; }; diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c index fdfc6f48fa..43561241f6 100644 --- a/src/nwfilter/nwfilter_driver.c +++ b/src/nwfilter/nwfilter_driver.c @@ -38,6 +38,7 @@ #include "nwfilter_gentech_driver.h" #include "configmake.h" #include "virfile.h" +#include "virpidfile.h" #include "virstring.h" #include "viraccessapicheck.h" =20 @@ -188,6 +189,7 @@ nwfilterStateInitialize(bool privileged, if (VIR_ALLOC(driver) < 0) return -1; =20 + driver->lockFD =3D -1; if (virMutexInit(&driver->lock) < 0) goto err_free_driverstate; =20 @@ -203,6 +205,19 @@ nwfilterStateInitialize(bool privileged, =20 nwfilterDriverLock(); =20 + if (VIR_STRDUP(driver->stateDir, LOCALSTATEDIR "/run/libvirt/nwfilter"= ) < 0) + goto error; + + if (virFileMakePathWithMode(driver->stateDir, S_IRWXU) < 0) { + virReportSystemError(errno, _("cannot create state directory '%s'"= ), + driver->stateDir); + goto error; + } + + if ((driver->lockFD =3D + virPidFileAcquire(driver->stateDir, "driver", true, getpid())) < = 0) + goto error; + if (virNWFilterIPAddrMapInit() < 0) goto err_free_driverstate; if (virNWFilterLearnInit() < 0) @@ -346,6 +361,10 @@ nwfilterStateCleanup(void) =20 nwfilterDriverRemoveDBusMatches(); =20 + if (driver->lockFD !=3D -1) + virPidFileRelease(driver->stateDir, "driver", driver->lockFD); + + VIR_FREE(driver->stateDir); VIR_FREE(driver->configDir); VIR_FREE(driver->bindingDir); nwfilterDriverUnlock(); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 01:49:01 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=1562773698; cv=none; d=zoho.com; s=zohoarc; b=ej3GjntuhIOMFXHYQagWttdf1sXxVU/MLUUFRifnelaLM5X8SLJfTA/AIBjG7s/OMqkHaaVpk2mSoQAQEoGkYNskAPNl6SWx9yaWe1XFStxoH0WEQhixsLXDvP7MJj2vffe2NCFJjvQVJyRtobI5wC1vl6gSpnU8sFOxnP1zjVM= 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=vGLxreZKRRYM2YdUgV6VHl9oXfHQzpxyedv/bGIm/4U=; b=WCn0A/6UzEyT5V7kzWMauMkugbdKnrFm/p8XXtyyUQ8brglL80YOXAJLHu0v/C18uCDnWPduiyNB+FIfc+uImlljZuhmPhV8uR/bMthDg4o7fthWlfYaorIXIT7/Uhd1es5rzVuC8KBmCylCGLqby0fc8kcPTeSh6/gSr1kaoxg= 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 1562773698248729.6077946608953; Wed, 10 Jul 2019 08:48:18 -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 3418CC0669D5; 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 AF24860C95; Wed, 10 Jul 2019 15:48: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 4981F1CE5C; Wed, 10 Jul 2019 15:48:15 +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 x6AFmDKa017860 for ; Wed, 10 Jul 2019 11:48:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id 32FA91001DDA; Wed, 10 Jul 2019 15:48:13 +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 1445D1024703; Wed, 10 Jul 2019 15:48:00 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Wed, 10 Jul 2019 16:47:37 +0100 Message-Id: <20190710154741.17065-9-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 08/12] libxl: remove obsolete check for xend during driver startup 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]); Wed, 10 Jul 2019 15:48:17 +0000 (UTC) No supported build targets for libvirt still ship xend, so there is no need for the libxl driver to check for it anymore. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Michal Privoznik --- src/libxl/libxl_driver.c | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 731700ded6..ac10fb6dbc 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -525,12 +525,10 @@ libxlStateCleanup(void) static bool libxlDriverShouldLoad(bool privileged) { - bool ret =3D false; - /* Don't load if non-root */ if (!privileged) { VIR_INFO("Not running privileged, disabling libxenlight driver"); - return ret; + return false; } =20 if (virFileExists(HYPERVISOR_CAPABILITIES)) { @@ -549,31 +547,15 @@ libxlDriverShouldLoad(bool privileged) VIR_INFO("No Xen capabilities detected, probably not running " "in a Xen Dom0. Disabling libxenlight driver"); =20 - return ret; + return false; } } else if (!virFileExists(HYPERVISOR_XENSTORED)) { VIR_INFO("Disabling driver as neither " HYPERVISOR_CAPABILITIES " nor " HYPERVISOR_XENSTORED " exist"); - return ret; + return false; } =20 - /* Don't load if legacy xen toolstack (xend) is in use */ - if (virFileExists("/usr/sbin/xend")) { - virCommandPtr cmd; - - cmd =3D virCommandNewArgList("/usr/sbin/xend", "status", NULL); - if (virCommandRun(cmd, NULL) =3D=3D 0) { - VIR_INFO("Legacy xen tool stack seems to be in use, disabling " - "libxenlight driver."); - } else { - ret =3D true; - } - virCommandFree(cmd); - } else { - ret =3D true; - } - - return ret; + return true; } =20 /* Callbacks wrapping libvirt's event loop interface */ --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 01:49:01 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=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 Reviewed-by: Michal Privoznik --- 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 From nobody Fri Apr 19 01:49:01 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=1562773702; cv=none; d=zoho.com; s=zohoarc; b=Xem3Bbplv+vmmqSq/IWK6N91E841rrFjJ8RJ7oe1dRFnafX9cheeoB3gbQsAF4okcz/9HsNKU8E/t1vlVWGmvMIje4rUWyOcT/MV1NT9XFYHWfXTOVBQotvcw4nrNKP6TnNLyQHcwUJgvjcgwT9jDqsX5LTbV/f0PDDA8aCxscE= 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=LFse0likQZmVOFK/0AoB6qCyJDZo6f/7ytXbQLTtWog=; b=mKvbIKSBwPypsUsNbYhYfZ/wd3QiAMy8kxIYoHrzmuJIUdrliwMjMBc57WAsk6uM90+nVZRZ6sIC7JPcFaBwPIdh7VD1qZihFuyDI8bNORcKR9a8S/06xPlyWL1KjIQOUIwnk1uu1n3H9nW0w+68C1vNdu7qz2UmrDNAaMdTPuo= 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 1562773702197956.4424941865732; Wed, 10 Jul 2019 08:48:22 -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 78241F9E88; 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 2DB5C60C7F; 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 D3A5418433B3; 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 x6AFmF0J017888 for ; Wed, 10 Jul 2019 11:48:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id B64DF1001B11; Wed, 10 Jul 2019 15:48:15 +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 CF07D1001E9A; Wed, 10 Jul 2019 15:48:14 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Wed, 10 Jul 2019 16:47:39 +0100 Message-Id: <20190710154741.17065-11-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 10/12] lxc: 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.38]); 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/lxc/driver.pid In unprivileged libvirtd this ends up locking /run/user/$UID/libvirt/lxc/run/driver.pid NB, the latter can vary depending on $XDG_RUNTIME_DIR Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Michal Privoznik --- src/lxc/lxc_conf.h | 3 +++ src/lxc/lxc_driver.c | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/src/lxc/lxc_conf.h b/src/lxc/lxc_conf.h index dc5531ebf9..e26ca22d3c 100644 --- a/src/lxc/lxc_conf.h +++ b/src/lxc/lxc_conf.h @@ -70,6 +70,9 @@ struct _virLXCDriver { * then lockless thereafter */ virLXCDriverConfigPtr config; =20 + /* pid file FD, ensures two copies of the driver can't use the same ro= ot */ + int lockFD; + /* Require lock to get a reference on the object, * lockless access thereafter */ virCapsPtr caps; diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 9db2a02dee..3982c24f34 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -1559,6 +1559,7 @@ static int lxcStateInitialize(bool privileged, =20 if (VIR_ALLOC(lxc_driver) < 0) return -1; + lxc_driver->lockFD =3D -1; if (virMutexInit(&lxc_driver->lock) < 0) { VIR_FREE(lxc_driver); return -1; @@ -1605,6 +1606,10 @@ static int lxcStateInitialize(bool privileged, goto cleanup; } =20 + if ((lxc_driver->lockFD =3D + virPidFileAcquire(cfg->stateDir, "driver", true, getpid())) < 0) + goto cleanup; + /* Get all the running persistent or transient configs first */ if (virDomainObjListLoadAllConfigs(lxc_driver->domains, cfg->stateDir, @@ -1696,6 +1701,10 @@ static int lxcStateCleanup(void) virObjectUnref(lxc_driver->caps); virObjectUnref(lxc_driver->securityManager); virObjectUnref(lxc_driver->xmlopt); + + if (lxc_driver->lockFD !=3D -1) + virPidFileRelease(lxc_driver->config->stateDir, "driver", lxc_driv= er->lockFD); + virObjectUnref(lxc_driver->config); virMutexDestroy(&lxc_driver->lock); VIR_FREE(lxc_driver); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 01:49:01 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=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 Reviewed-by: Michal Privoznik --- 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 From nobody Fri Apr 19 01:49:01 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=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 Reviewed-by: Michal Privoznik --- 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