From nobody Mon Feb 9 00:30:15 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.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; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1493378551564482.89221132401894; Fri, 28 Apr 2017 04:22:31 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0B3C761D38; Fri, 28 Apr 2017 11:22:30 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D9BA18BC25; Fri, 28 Apr 2017 11:22:29 +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 7A0FF4EBD7; Fri, 28 Apr 2017 11:22:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v3SBMOah006942 for ; Fri, 28 Apr 2017 07:22:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id 49B398FBF0; Fri, 28 Apr 2017 11:22:24 +0000 (UTC) Received: from moe.brq.redhat.com (dhcp129-131.brq.redhat.com [10.34.129.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id A49A28EE5C; Fri, 28 Apr 2017 11:22:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0B3C761D38 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 0B3C761D38 From: Michal Privoznik To: libvir-list@redhat.com Date: Fri, 28 Apr 2017 13:22:13 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: cbosdonnat@suse.com Subject: [libvirt] [PATCH 4/5] qemuDomainAttachDeviceMknodRecursive: Don't try to create devices under preserved mount points 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: , MIME-Version: 1.0 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 28 Apr 2017 11:22:30 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Just like in previous commit, this fixes the same issue for hotplug. Signed-off-by: Michal Privoznik --- src/qemu/qemu_domain.c | 112 ++++++++++++++++++++++++++++++++++++++++++---= ---- 1 file changed, 97 insertions(+), 15 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 5840c57..60f8f01 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -8238,6 +8238,8 @@ static int qemuDomainAttachDeviceMknodRecursive(virQEMUDriverPtr driver, virDomainObjPtr vm, const char *file, + char * const *devMountsPath, + size_t ndevMountsPath, unsigned int ttl) { struct qemuDomainAttachDeviceMknodData data; @@ -8315,20 +8317,36 @@ qemuDomainAttachDeviceMknodRecursive(virQEMUDriverP= tr driver, #endif =20 if (STRPREFIX(file, DEVPREFIX)) { - if (qemuSecurityPreFork(driver->securityManager) < 0) - goto cleanup; + size_t i; =20 - if (virProcessRunInMountNamespace(vm->pid, - qemuDomainAttachDeviceMknodHelpe= r, - &data) < 0) { + for (i =3D 0; i < ndevMountsPath; i++) { + if (STREQ(devMountsPath[i], "/dev")) + continue; + if (STRPREFIX(file, devMountsPath[i])) + break; + } + + if (i =3D=3D ndevMountsPath) { + if (qemuSecurityPreFork(driver->securityManager) < 0) + goto cleanup; + + if (virProcessRunInMountNamespace(vm->pid, + qemuDomainAttachDeviceMknodH= elper, + &data) < 0) { + qemuSecurityPostFork(driver->securityManager); + goto cleanup; + } qemuSecurityPostFork(driver->securityManager); - goto cleanup; + } else { + VIR_DEBUG("Skipping dev %s because of %s mount point", + file, devMountsPath[i]); } - qemuSecurityPostFork(driver->securityManager); } =20 if (isLink && - qemuDomainAttachDeviceMknodRecursive(driver, vm, target, ttl -1) <= 0) + qemuDomainAttachDeviceMknodRecursive(driver, vm, target, + devMountsPath, ndevMountsPath, + ttl -1) < 0) goto cleanup; =20 ret =3D 0; @@ -8345,11 +8363,15 @@ qemuDomainAttachDeviceMknodRecursive(virQEMUDriverP= tr driver, static int qemuDomainAttachDeviceMknod(virQEMUDriverPtr driver, virDomainObjPtr vm, - const char *file) + const char *file, + char * const *devMountsPath, + size_t ndevMountsPath) { long symloop_max =3D sysconf(_SC_SYMLOOP_MAX); =20 - return qemuDomainAttachDeviceMknodRecursive(driver, vm, file, symloop_= max); + return qemuDomainAttachDeviceMknodRecursive(driver, vm, file, + devMountsPath, ndevMountsP= ath, + symloop_max); } =20 =20 @@ -8389,6 +8411,9 @@ qemuDomainNamespaceSetupDisk(virQEMUDriverPtr driver, virDomainObjPtr vm, virStorageSourcePtr src) { + virQEMUDriverConfigPtr cfg =3D NULL; + char **devMountsPath =3D NULL; + size_t ndevMountsPath =3D 0; virStorageSourcePtr next; struct stat sb; int ret =3D -1; @@ -8396,6 +8421,12 @@ qemuDomainNamespaceSetupDisk(virQEMUDriverPtr driver, if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT)) return 0; =20 + cfg =3D virQEMUDriverGetConfig(driver); + if (qemuDomainGetPreservedMounts(cfg, vm, + &devMountsPath, NULL, + &ndevMountsPath) < 0) + goto cleanup; + for (next =3D src; next; next =3D next->backingStore) { if (virStorageSourceIsEmpty(next) || !virStorageSourceIsLocalStorage(next)) { @@ -8414,12 +8445,15 @@ qemuDomainNamespaceSetupDisk(virQEMUDriverPtr drive= r, =20 if (qemuDomainAttachDeviceMknod(driver, vm, - next->path) < 0) + next->path, + devMountsPath, ndevMountsPath) < 0) goto cleanup; } =20 ret =3D 0; cleanup: + virStringListFreeCount(devMountsPath, ndevMountsPath); + virObjectUnref(cfg); return ret; } =20 @@ -8444,6 +8478,9 @@ qemuDomainNamespaceSetupHostdev(virQEMUDriverPtr driv= er, virDomainObjPtr vm, virDomainHostdevDefPtr hostdev) { + virQEMUDriverConfigPtr cfg =3D NULL; + char **devMountsPath =3D NULL; + size_t ndevMountsPath =3D 0; int ret =3D -1; char **path =3D NULL; size_t i, npaths =3D 0; @@ -8454,10 +8491,17 @@ qemuDomainNamespaceSetupHostdev(virQEMUDriverPtr dr= iver, if (qemuDomainGetHostdevPath(NULL, hostdev, false, &npaths, &path, NUL= L) < 0) goto cleanup; =20 + cfg =3D virQEMUDriverGetConfig(driver); + if (qemuDomainGetPreservedMounts(cfg, vm, + &devMountsPath, NULL, + &ndevMountsPath) < 0) + goto cleanup; + for (i =3D 0; i < npaths; i++) { if (qemuDomainAttachDeviceMknod(driver, vm, - path[i]) < 0) + path[i], + devMountsPath, ndevMountsPath) < 0) goto cleanup; } =20 @@ -8466,6 +8510,8 @@ qemuDomainNamespaceSetupHostdev(virQEMUDriverPtr driv= er, for (i =3D 0; i < npaths; i++) VIR_FREE(path[i]); VIR_FREE(path); + virStringListFreeCount(devMountsPath, ndevMountsPath); + virObjectUnref(cfg); return ret; } =20 @@ -8505,6 +8551,9 @@ qemuDomainNamespaceSetupMemory(virQEMUDriverPtr drive= r, virDomainObjPtr vm, virDomainMemoryDefPtr mem) { + virQEMUDriverConfigPtr cfg =3D NULL; + char **devMountsPath =3D NULL; + size_t ndevMountsPath =3D 0; int ret =3D -1; =20 if (mem->model !=3D VIR_DOMAIN_MEMORY_MODEL_NVDIMM) @@ -8513,10 +8562,19 @@ qemuDomainNamespaceSetupMemory(virQEMUDriverPtr dri= ver, if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT)) return 0; =20 - if (qemuDomainAttachDeviceMknod(driver, vm, mem->nvdimmPath) < 0) + cfg =3D virQEMUDriverGetConfig(driver); + if (qemuDomainGetPreservedMounts(cfg, vm, + &devMountsPath, NULL, + &ndevMountsPath) < 0) + goto cleanup; + + if (qemuDomainAttachDeviceMknod(driver, vm, mem->nvdimmPath, + devMountsPath, ndevMountsPath) < 0) goto cleanup; ret =3D 0; cleanup: + virStringListFreeCount(devMountsPath, ndevMountsPath); + virObjectUnref(cfg); return ret; } =20 @@ -8547,6 +8605,9 @@ qemuDomainNamespaceSetupChardev(virQEMUDriverPtr driv= er, virDomainObjPtr vm, virDomainChrDefPtr chr) { + virQEMUDriverConfigPtr cfg =3D NULL; + char **devMountsPath =3D NULL; + size_t ndevMountsPath =3D 0; const char *path; int ret =3D -1; =20 @@ -8558,12 +8619,21 @@ qemuDomainNamespaceSetupChardev(virQEMUDriverPtr dr= iver, =20 path =3D chr->source->data.file.path; =20 + cfg =3D virQEMUDriverGetConfig(driver); + if (qemuDomainGetPreservedMounts(cfg, vm, + &devMountsPath, NULL, + &ndevMountsPath) < 0) + goto cleanup; + if (qemuDomainAttachDeviceMknod(driver, vm, - path) < 0) + path, + devMountsPath, ndevMountsPath) < 0) goto cleanup; ret =3D 0; cleanup: + virStringListFreeCount(devMountsPath, ndevMountsPath); + virObjectUnref(cfg); return ret; } =20 @@ -8598,6 +8668,9 @@ qemuDomainNamespaceSetupRNG(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainRNGDefPtr rng) { + virQEMUDriverConfigPtr cfg =3D NULL; + char **devMountsPath =3D NULL; + size_t ndevMountsPath =3D 0; const char *path =3D NULL; int ret =3D -1; =20 @@ -8615,12 +8688,21 @@ qemuDomainNamespaceSetupRNG(virQEMUDriverPtr driver, goto cleanup; } =20 + cfg =3D virQEMUDriverGetConfig(driver); + if (qemuDomainGetPreservedMounts(cfg, vm, + &devMountsPath, NULL, + &ndevMountsPath) < 0) + goto cleanup; + if (qemuDomainAttachDeviceMknod(driver, vm, - path) < 0) + path, + devMountsPath, ndevMountsPath) < 0) goto cleanup; ret =3D 0; cleanup: + virStringListFreeCount(devMountsPath, ndevMountsPath); + virObjectUnref(cfg); return ret; } =20 --=20 2.10.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list