From nobody Mon Feb 9 00:30:45 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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=1595413691; cv=none; d=zohomail.com; s=zohoarc; b=MXZhS7LcGesifqhIJ9w+8tauvfLi4rjlyjJpXwM7O3cAiQ6kc3gmQ/eKwmpQ4D6VyM/aP3Wu1TFT0mcuf+fZA0WFP31d9K6nW455ashorATByhvEofbso/YA7TNof/FqFY43e6wQekkFc6NSIetrbhlGMn6GBKHgoipckCYQZMQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595413691; 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; bh=LoTAClexmsCxErIToyqLK1jP3aXOqaF1/3IjQas56aI=; b=XMxHcs0ynO6QxdIntcP0INsOqDaHutsg4fohAVC/OHiq99I3D51h2N+RzJANEqVrUNCZCIGeBkGEFGApF4FZUab4urovtvjKwSdJheDlsbK+PhAjQfGuVz7uWieCUt58nyjx6EltFIS/tCv13Qybo8tZ3KU49hB4Eb+vxkq5HNs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1595413691396902.9882529500588; Wed, 22 Jul 2020 03:28:11 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-386-tEPl4cxDMXSsa-eTKOfDVg-1; Wed, 22 Jul 2020 06:28:07 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 193C58015F3; Wed, 22 Jul 2020 10:28:02 +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 E71AB61176; Wed, 22 Jul 2020 10:28: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 B7CBB730E9; Wed, 22 Jul 2020 10:28:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 06M9exBr000983 for ; Wed, 22 Jul 2020 05:40:59 -0400 Received: by smtp.corp.redhat.com (Postfix) id C9B0F1A90F; Wed, 22 Jul 2020 09:40:59 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.195.120]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4807E1A8F7 for ; Wed, 22 Jul 2020 09:40:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595413690; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=LoTAClexmsCxErIToyqLK1jP3aXOqaF1/3IjQas56aI=; b=IvanDj8NaZWab/VNmtyf1hnc3fg0a/FQs6+Sl7PYSbKMSjL/8zweA/qxb0tYoUkU2U5PxR tCuUlxJe8orucc82s5zD239ACMdZ94JxbIM5CELFOtZQQ44JHj+aI+0+byEqxhjxJmXm+k HL4IqTf0PebU3F2P8l7WJVUXnPbdPS4= X-MC-Unique: tEPl4cxDMXSsa-eTKOfDVg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v1 17/34] qemuDomainBuildNamespace: Populate disks from daemon's namespace Date: Wed, 22 Jul 2020 11:40:11 +0200 Message-Id: <5256d044ea9d2efa1f774b37ac24019b7a49113d.1595410402.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com 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: , 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-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" As mentioned in one of previous commits, populating domain's namespace from pre-exec() hook is dangerous. This commit moves population of the namespace with domain disks into daemon's namespace. Fixes: a30078cb832646177defd256e77c632905f1e6d0 Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D1858260 Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_domain_namespace.c | 89 ++++++++------------------------ 1 file changed, 22 insertions(+), 67 deletions(-) diff --git a/src/qemu/qemu_domain_namespace.c b/src/qemu/qemu_domain_namesp= ace.c index 17c804dfca..61f7846009 100644 --- a/src/qemu/qemu_domain_namespace.c +++ b/src/qemu/qemu_domain_namespace.c @@ -482,33 +482,29 @@ qemuDomainSetupDev(virSecurityManagerPtr mgr, =20 static int qemuDomainSetupDisk(virStorageSourcePtr src, - const struct qemuDomainCreateDeviceData *data) + char ***paths) { virStorageSourcePtr next; bool hasNVMe =3D false; =20 for (next =3D src; virStorageSourceIsBacking(next); next =3D next->bac= kingStore) { - VIR_AUTOSTRINGLIST targetPaths =3D NULL; - size_t i; + g_autofree char *tmpPath =3D NULL; =20 if (next->type =3D=3D VIR_STORAGE_TYPE_NVME) { - g_autofree char *nvmePath =3D NULL; - hasNVMe =3D true; =20 - if (!(nvmePath =3D virPCIDeviceAddressGetIOMMUGroupDev(&next->= nvme->pciAddr))) - return -1; - - if (qemuDomainCreateDevice(nvmePath, data, false) < 0) + if (!(tmpPath =3D virPCIDeviceAddressGetIOMMUGroupDev(&next->n= vme->pciAddr))) return -1; } else { - if (!next->path || !virStorageSourceIsLocalStorage(next)) { + VIR_AUTOSTRINGLIST targetPaths =3D NULL; + + if (virStorageSourceIsEmpty(next) || + !virStorageSourceIsLocalStorage(next)) { /* Not creating device. Just continue. */ continue; } =20 - if (qemuDomainCreateDevice(next->path, data, false) < 0) - return -1; + tmpPath =3D g_strdup(next->path); =20 if (virDevMapperGetTargets(next->path, &targetPaths) < 0 && errno !=3D ENOSYS) { @@ -518,20 +514,21 @@ qemuDomainSetupDisk(virStorageSourcePtr src, return -1; } =20 - for (i =3D 0; targetPaths && targetPaths[i]; i++) { - if (qemuDomainCreateDevice(targetPaths[i], data, false) < = 0) - return -1; - } + if (virStringListMerge(paths, &targetPaths) < 0) + return -1; } + + if (virStringListAdd(paths, tmpPath) < 0) + return -1; } =20 /* qemu-pr-helper might require access to /dev/mapper/control. */ if (src->pr && - qemuDomainCreateDevice(QEMU_DEVICE_MAPPER_CONTROL_PATH, data, true= ) < 0) + virStringListAdd(paths, QEMU_DEVICE_MAPPER_CONTROL_PATH) < 0) return -1; =20 if (hasNVMe && - qemuDomainCreateDevice(QEMU_DEV_VFIO, data, false) < 0) + virStringListAdd(paths, QEMU_DEV_VFIO) < 0) return -1; =20 return 0; @@ -540,14 +537,15 @@ qemuDomainSetupDisk(virStorageSourcePtr src, =20 static int qemuDomainSetupAllDisks(virDomainObjPtr vm, - const struct qemuDomainCreateDeviceData *data) + char ***paths) { size_t i; + VIR_DEBUG("Setting up disks"); =20 for (i =3D 0; i < vm->def->ndisks; i++) { if (qemuDomainSetupDisk(vm->def->disks[i]->src, - data) < 0) + paths) < 0) return -1; } =20 @@ -865,6 +863,9 @@ qemuDomainBuildNamespace(virQEMUDriverConfigPtr cfg, if (qemuDomainPopulateDevices(cfg, &paths) < 0) return -1; =20 + if (qemuDomainSetupAllDisks(vm, &paths) < 0) + return -1; + if (qemuDomainNamespaceMknodPaths(vm, (const char **) paths) < 0) return -1; =20 @@ -916,9 +917,6 @@ qemuDomainUnshareNamespace(virQEMUDriverConfigPtr cfg, if (qemuDomainSetupDev(mgr, vm, devPath) < 0) goto cleanup; =20 - if (qemuDomainSetupAllDisks(vm, &data) < 0) - goto cleanup; - if (qemuDomainSetupAllHostdevs(vm, &data) < 0) goto cleanup; =20 @@ -1639,55 +1637,12 @@ int qemuDomainNamespaceSetupDisk(virDomainObjPtr vm, virStorageSourcePtr src) { - virStorageSourcePtr next; VIR_AUTOSTRINGLIST paths =3D NULL; - bool hasNVMe =3D false; =20 if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT)) return 0; =20 - for (next =3D src; virStorageSourceIsBacking(next); next =3D next->bac= kingStore) { - g_autofree char *tmpPath =3D NULL; - - if (next->type =3D=3D VIR_STORAGE_TYPE_NVME) { - hasNVMe =3D true; - - if (!(tmpPath =3D virPCIDeviceAddressGetIOMMUGroupDev(&next->n= vme->pciAddr))) - return -1; - } else { - VIR_AUTOSTRINGLIST targetPaths =3D NULL; - - if (virStorageSourceIsEmpty(next) || - !virStorageSourceIsLocalStorage(next)) { - /* Not creating device. Just continue. */ - continue; - } - - tmpPath =3D g_strdup(next->path); - - if (virDevMapperGetTargets(next->path, &targetPaths) < 0 && - errno !=3D ENOSYS) { - virReportSystemError(errno, - _("Unable to get devmapper targets fo= r %s"), - next->path); - return -1; - } - - if (virStringListMerge(&paths, &targetPaths) < 0) - return -1; - } - - if (virStringListAdd(&paths, tmpPath) < 0) - return -1; - } - - /* qemu-pr-helper might require access to /dev/mapper/control. */ - if (src->pr && - virStringListAdd(&paths, QEMU_DEVICE_MAPPER_CONTROL_PATH) < 0) - return -1; - - if (hasNVMe && - virStringListAdd(&paths, QEMU_DEV_VFIO) < 0) + if (qemuDomainSetupDisk(src, &paths) < 0) return -1; =20 if (qemuDomainNamespaceMknodPaths(vm, (const char **) paths) < 0) --=20 2.26.2