From nobody Mon Feb 9 07:38:18 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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=1595413692; cv=none; d=zohomail.com; s=zohoarc; b=bIq7R6/2zZ97Qqs6PpN9ViYQxJ7EBpVrNFQ0EBOlfdAcYUrbaMtBacDNwybrUtyDS4+0t2AbyZJdG6u6msI2Q/1MWbstCAOajUIfuWbM4NY6VsozTUJ0F7EBwGh/3nmpqKAE2I0xFIh3oA02vOZasig/RPEXVuid/ovAKztIPY0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595413692; 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=RdK7lgl7i8FZsKCBhuK0bdttg2MVH7gjy1+jQf+Vr1Y=; b=fF+OU19d/TQ46Wtcyy4bS0UvGUKAC8/oPxg0dQ8RZU9MOsrBuZYVsCCjvtg7niZgZMgiuHXFHFZ+zZfgpD2zyPVptdcsaXCBL++sM5SA38pOvy4LlGTybu4DlUwd4QTw8teGuvj1UU/fMmrddCmlMSCTL9e3j506DLema+IS79o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1595413692978164.46202833244536; Wed, 22 Jul 2020 03:28:12 -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-137-7Y6TfcVsNZSSU4XlqZ4PQA-1; Wed, 22 Jul 2020 06:28:09 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5B31C189CF10; Wed, 22 Jul 2020 10:28:04 +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 3B3118BECE; Wed, 22 Jul 2020 10:28:04 +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 0B9A6730F1; Wed, 22 Jul 2020 10:28:04 +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 06M9f0EO000992 for ; Wed, 22 Jul 2020 05:41:00 -0400 Received: by smtp.corp.redhat.com (Postfix) id AAF121A90F; Wed, 22 Jul 2020 09:41:00 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.195.120]) by smtp.corp.redhat.com (Postfix) with ESMTP id 29D0E1A8F7 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=1595413691; 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=RdK7lgl7i8FZsKCBhuK0bdttg2MVH7gjy1+jQf+Vr1Y=; b=WKKIWm7J8g7zPPx41brpZ767AayATHcumme0Rgy1neoZTbSC9GIikX5w5JEb7x4q4HPp6e vrpETpj6G6K/23fRTYzUNRj+w/lof2kDDWX0+z7DhScQHZ3yILrWWA95JIQsvipx2mc8XQ ct1oYvRzRCK/fhEfJKld9hRSWlGwx3I= X-MC-Unique: 7Y6TfcVsNZSSU4XlqZ4PQA-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v1 18/34] qemuDomainBuildNamespace: Populate hostdevs from daemon's namespace Date: Wed, 22 Jul 2020 11:40:12 +0200 Message-Id: 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.13 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 hostdevs into daemon's namespace. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_domain_namespace.c | 43 ++++++++++++++++---------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/src/qemu/qemu_domain_namespace.c b/src/qemu/qemu_domain_namesp= ace.c index 61f7846009..2517832a8d 100644 --- a/src/qemu/qemu_domain_namespace.c +++ b/src/qemu/qemu_domain_namespace.c @@ -555,19 +555,22 @@ qemuDomainSetupAllDisks(virDomainObjPtr vm, =20 =20 static int -qemuDomainSetupHostdev(virDomainHostdevDefPtr dev, - const struct qemuDomainCreateDeviceData *data) +qemuDomainSetupHostdev(virDomainObjPtr vm, + virDomainHostdevDefPtr hostdev, + bool hotplug, + char ***paths) { g_autofree char *path =3D NULL; =20 - if (qemuDomainGetHostdevPath(dev, &path, NULL) < 0) + if (qemuDomainGetHostdevPath(hostdev, &path, NULL) < 0) return -1; =20 - if (path && qemuDomainCreateDevice(path, data, false) < 0) + if (path && virStringListAdd(paths, path) < 0) return -1; =20 - if (qemuHostdevNeedsVFIO(dev) && - qemuDomainCreateDevice(QEMU_DEV_VFIO, data, false) < 0) + if (qemuHostdevNeedsVFIO(hostdev) && + (!hotplug || !qemuDomainNeedsVFIO(vm->def)) && + virStringListAdd(paths, QEMU_DEV_VFIO) < 0) return -1; =20 return 0; @@ -576,14 +579,16 @@ qemuDomainSetupHostdev(virDomainHostdevDefPtr dev, =20 static int qemuDomainSetupAllHostdevs(virDomainObjPtr vm, - const struct qemuDomainCreateDeviceData *data) + char ***paths) { size_t i; =20 VIR_DEBUG("Setting up hostdevs"); for (i =3D 0; i < vm->def->nhostdevs; i++) { - if (qemuDomainSetupHostdev(vm->def->hostdevs[i], - data) < 0) + if (qemuDomainSetupHostdev(vm, + vm->def->hostdevs[i], + false, + paths) < 0) return -1; } VIR_DEBUG("Setup all hostdevs"); @@ -866,6 +871,9 @@ qemuDomainBuildNamespace(virQEMUDriverConfigPtr cfg, if (qemuDomainSetupAllDisks(vm, &paths) < 0) return -1; =20 + if (qemuDomainSetupAllHostdevs(vm, &paths) < 0) + return -1; + if (qemuDomainNamespaceMknodPaths(vm, (const char **) paths) < 0) return -1; =20 @@ -917,9 +925,6 @@ qemuDomainUnshareNamespace(virQEMUDriverConfigPtr cfg, if (qemuDomainSetupDev(mgr, vm, devPath) < 0) goto cleanup; =20 - if (qemuDomainSetupAllHostdevs(vm, &data) < 0) - goto cleanup; - if (qemuDomainSetupAllMemories(vm, &data) < 0) goto cleanup; =20 @@ -1681,21 +1686,15 @@ int qemuDomainNamespaceSetupHostdev(virDomainObjPtr vm, virDomainHostdevDefPtr hostdev) { - g_autofree char *path =3D NULL; VIR_AUTOSTRINGLIST paths =3D NULL; =20 if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT)) return 0; =20 - if (qemuDomainGetHostdevPath(hostdev, &path, NULL) < 0) - return -1; - - if (path && virStringListAdd(&paths, path) < 0) - return -1; - - if (qemuHostdevNeedsVFIO(hostdev) && - !qemuDomainNeedsVFIO(vm->def) && - virStringListAdd(&paths, QEMU_DEV_VFIO) < 0) + if (qemuDomainSetupHostdev(vm, + hostdev, + true, + &paths) < 0) return -1; =20 if (qemuDomainNamespaceMknodPaths(vm, (const char **) paths) < 0) --=20 2.26.2