From nobody Mon Feb 9 00:26:55 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 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=1626274061; cv=none; d=zohomail.com; s=zohoarc; b=DWB9Dl3cNzu0bzyIYJ4Fb2mBokh4Vem7C9LiuieZikmK8pEPW56bOvyk3LsX82un5px4UpEd2YSwpa9AyOeGS/corK0V3Bmh9N4VjIvf4N7wfldKHQadQN52DjVpEo8bg96y3EbwRbB4h5zOjHTKU9mZCPmAVloO7Dxeebjzna4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1626274061; 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=rDFL7su+b1nd5TBp2o++8UEdUrbNDCbbJhs6/8nIZW0=; b=LLXBS3XN/PJn9osQiMaTr/zpiTpb7DqOu603+cgcCOPbw1iVHTnMEOTOK7ykAIOi1KgZIXPQCCkgMBaKfulz9f0/p5od96NMHdex8FEi55XbjT4ie1AO62yKK5Mv1C0eiS4UNAsAt6Z9wVCSxPuEkaP5FNboTGiG7jD65kEzyN0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1626274061763852.0140418402544; Wed, 14 Jul 2021 07:47:41 -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-492-V95WnnX2OV-J4qZ_TWxNgw-1; Wed, 14 Jul 2021 10:47:38 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 73AC1192FDCA; Wed, 14 Jul 2021 14:47:25 +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 4EAF85DA61; Wed, 14 Jul 2021 14:47:25 +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 143EC1809C9A; Wed, 14 Jul 2021 14:47:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 16EElHGY007386 for ; Wed, 14 Jul 2021 10:47:17 -0400 Received: by smtp.corp.redhat.com (Postfix) id 270DE60CA1; Wed, 14 Jul 2021 14:47:17 +0000 (UTC) Received: from 48-A4-72-0B-E8-25.redhat.com (unknown [10.40.195.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id CEE087FCEA for ; Wed, 14 Jul 2021 14:47:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626274060; 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=rDFL7su+b1nd5TBp2o++8UEdUrbNDCbbJhs6/8nIZW0=; b=ctbWP0Fog4+9N8eKzIpo3hk7oUYyczspi+P7CkkEPVqmq2MP2PYGRBwobFgCexD/ktqVEC AIhvj2+SKz/lTrhB89EMNWmi7k2uTDvkruZC0xP3JGYXLfSmvJKKG/mtl9Gb5CSN3pZQyL FPZBuN9fTPej+Y2zocxfRN9I7WcTSfg= X-MC-Unique: V95WnnX2OV-J4qZ_TWxNgw-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH v2 3/3] qemu: Do not erase duplicate devices from namespace if error occurs Date: Wed, 14 Jul 2021 16:46:54 +0200 Message-Id: <1890a680fcf1a7fcf30141abf337a447defbe25d.1626270217.git.khanicov@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1626274062319100002 Content-Type: text/plain; charset="utf-8" If the attempt to attach a device failed, we erased the unattached device from the namespace. This resulted in erasing an already attached device in case of a duplicate. We need to check for existing file in the namespace in order to determine erasing it in case of a failure. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D1780508 Signed-off-by: Kristina Hanicova --- src/qemu/qemu_domain.c | 4 +-- src/qemu/qemu_hotplug.c | 27 +++++++------------ src/qemu/qemu_namespace.c | 55 +++++++++++++++++++++++---------------- src/qemu/qemu_namespace.h | 18 ++++++++----- src/qemu/qemu_process.c | 2 +- 5 files changed, 55 insertions(+), 51 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 89e03fdf72..ac1d8ef151 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -7934,10 +7934,8 @@ qemuDomainStorageSourceAccessModify(virQEMUDriver *d= river, =20 revoke_nvme =3D true; =20 - if (qemuDomainNamespaceSetupDisk(vm, src) < 0) + if (qemuDomainNamespaceSetupDisk(vm, src, &revoke_namespace) < 0) goto revoke; - - revoke_namespace =3D true; } =20 if (qemuSecuritySetImageLabel(driver, vm, src, chain, chain_top) < 0) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index cb6a4e4ea5..6743a8a742 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1685,9 +1685,8 @@ qemuDomainAttachHostPCIDevice(virQEMUDriver *driver, goto error; teardownmemlock =3D true; =20 - if (qemuDomainNamespaceSetupHostdev(vm, hostdev) < 0) + if (qemuDomainNamespaceSetupHostdev(vm, hostdev, &teardowndevice) < 0) goto error; - teardowndevice =3D true; =20 if (qemuSetupHostdevCgroup(vm, hostdev) < 0) goto error; @@ -2219,9 +2218,8 @@ int qemuDomainAttachChrDevice(virQEMUDriver *driver, if (rc =3D=3D 1) need_release =3D true; =20 - if (qemuDomainNamespaceSetupChardev(vm, chr) < 0) + if (qemuDomainNamespaceSetupChardev(vm, chr, &teardowndevice) < 0) goto cleanup; - teardowndevice =3D true; =20 if (qemuSecuritySetChardevLabel(driver, vm, chr) < 0) goto cleanup; @@ -2332,9 +2330,8 @@ qemuDomainAttachRNGDevice(virQEMUDriver *driver, if (qemuDomainEnsureVirtioAddress(&releaseaddr, vm, &dev) < 0) return -1; =20 - if (qemuDomainNamespaceSetupRNG(vm, rng) < 0) + if (qemuDomainNamespaceSetupRNG(vm, rng, &teardowndevice) < 0) goto cleanup; - teardowndevice =3D true; =20 if (qemuSetupRNGCgroup(vm, rng) < 0) goto cleanup; @@ -2476,9 +2473,8 @@ qemuDomainAttachMemory(virQEMUDriver *driver, if (qemuProcessBuildDestroyMemoryPaths(driver, vm, mem, true) < 0) goto cleanup; =20 - if (qemuDomainNamespaceSetupMemory(vm, mem) < 0) + if (qemuDomainNamespaceSetupMemory(vm, mem, &teardowndevice) < 0) goto cleanup; - teardowndevice =3D true; =20 if (qemuSetupMemoryDevicesCgroup(vm, mem) < 0) goto cleanup; @@ -2592,9 +2588,8 @@ qemuDomainAttachHostUSBDevice(virQEMUDriver *driver, =20 added =3D true; =20 - if (qemuDomainNamespaceSetupHostdev(vm, hostdev) < 0) + if (qemuDomainNamespaceSetupHostdev(vm, hostdev, &teardowndevice) < 0) goto cleanup; - teardowndevice =3D true; =20 if (qemuSetupHostdevCgroup(vm, hostdev) < 0) goto cleanup; @@ -2673,9 +2668,8 @@ qemuDomainAttachHostSCSIDevice(virQEMUDriver *driver, if (qemuHostdevPrepareSCSIDevices(driver, vm->def->name, &hostdev, 1) = < 0) return -1; =20 - if (qemuDomainNamespaceSetupHostdev(vm, hostdev) < 0) + if (qemuDomainNamespaceSetupHostdev(vm, hostdev, &teardowndevice) < 0) goto cleanup; - teardowndevice =3D true; =20 if (qemuSetupHostdevCgroup(vm, hostdev) < 0) goto cleanup; @@ -2767,9 +2761,8 @@ qemuDomainAttachSCSIVHostDevice(virQEMUDriver *driver, if (qemuHostdevPrepareSCSIVHostDevices(driver, vm->def->name, &hostdev= , 1) < 0) return -1; =20 - if (qemuDomainNamespaceSetupHostdev(vm, hostdev) < 0) + if (qemuDomainNamespaceSetupHostdev(vm, hostdev, &teardowndevice) < 0) goto cleanup; - teardowndevice =3D true; =20 if (qemuSetupHostdevCgroup(vm, hostdev) < 0) goto cleanup; @@ -2894,9 +2887,8 @@ qemuDomainAttachMediatedDevice(virQEMUDriver *driver, goto cleanup; added =3D true; =20 - if (qemuDomainNamespaceSetupHostdev(vm, hostdev) < 0) + if (qemuDomainNamespaceSetupHostdev(vm, hostdev, &teardowndevice) < 0) goto cleanup; - teardowndevice =3D true; =20 if (qemuSetupHostdevCgroup(vm, hostdev) < 0) goto cleanup; @@ -3231,9 +3223,8 @@ qemuDomainAttachInputDevice(virQEMUDriver *driver, if (qemuBuildInputDevStr(&devstr, vm->def, input, priv->qemuCaps) < 0) goto cleanup; =20 - if (qemuDomainNamespaceSetupInput(vm, input) < 0) + if (qemuDomainNamespaceSetupInput(vm, input, &teardowndevice) < 0) goto cleanup; - teardowndevice =3D true; =20 if (qemuSetupInputCgroup(vm, input) < 0) goto cleanup; diff --git a/src/qemu/qemu_namespace.c b/src/qemu/qemu_namespace.c index eb048a2faa..46ee95b8c8 100644 --- a/src/qemu/qemu_namespace.c +++ b/src/qemu/qemu_namespace.c @@ -610,7 +610,8 @@ qemuDomainSetupLaunchSecurity(virDomainObj *vm, =20 static int qemuNamespaceMknodPaths(virDomainObj *vm, - GSList *paths); + GSList *paths, + bool *created); =20 =20 int @@ -657,7 +658,7 @@ qemuDomainBuildNamespace(virQEMUDriverConfig *cfg, if (qemuDomainSetupLaunchSecurity(vm, &paths) < 0) return -1; =20 - if (qemuNamespaceMknodPaths(vm, paths) < 0) + if (qemuNamespaceMknodPaths(vm, paths, NULL) < 0) return -1; =20 return 0; @@ -1235,7 +1236,8 @@ qemuNamespacePrepareOneItem(qemuNamespaceMknodData *d= ata, =20 static int qemuNamespaceMknodPaths(virDomainObj *vm, - GSList *paths) + GSList *paths, + bool *created) { qemuDomainObjPrivate *priv =3D vm->privateData; virQEMUDriver *driver =3D priv->driver; @@ -1280,15 +1282,13 @@ qemuNamespaceMknodPaths(virDomainObj *vm, if (qemuSecurityPreFork(driver->securityManager) < 0) goto cleanup; =20 - if (virProcessRunInMountNamespace(vm->pid, - qemuNamespaceMknodHelper, - &data) < 0) { - qemuSecurityPostFork(driver->securityManager); - goto cleanup; - } + ret =3D virProcessRunInMountNamespace(vm->pid, qemuNamespaceMknodHelpe= r, + &data); + if (ret =3D=3D 0 && created !=3D NULL) + *created =3D true; + qemuSecurityPostFork(driver->securityManager); =20 - ret =3D 0; cleanup: for (i =3D 0; i < data.nitems; i++) { if (data.items[i].bindmounted && @@ -1307,7 +1307,8 @@ qemuNamespaceMknodPaths(virDomainObj *vm, =20 static int qemuNamespaceMknodPaths(virDomainObj *vm G_GNUC_UNUSED, - GSList *paths G_GNUC_UNUSED) + GSList *paths G_GNUC_UNUSED, + bool *created G_GNUC_UNUSED) { virReportSystemError(ENOSYS, "%s", _("Namespaces are not supported on this platform.= ")); @@ -1393,7 +1394,8 @@ qemuNamespaceUnlinkPaths(virDomainObj *vm, =20 int qemuDomainNamespaceSetupDisk(virDomainObj *vm, - virStorageSource *src) + virStorageSource *src, + bool *created) { g_autoptr(virGSListString) paths =3D NULL; =20 @@ -1403,7 +1405,7 @@ qemuDomainNamespaceSetupDisk(virDomainObj *vm, if (qemuDomainSetupDisk(src, &paths) < 0) return -1; =20 - if (qemuNamespaceMknodPaths(vm, paths) < 0) + if (qemuNamespaceMknodPaths(vm, paths, created) < 0) return -1; =20 return 0; @@ -1437,7 +1439,8 @@ qemuDomainNamespaceTeardownDisk(virDomainObj *vm G_GN= UC_UNUSED, */ int qemuDomainNamespaceSetupHostdev(virDomainObj *vm, - virDomainHostdevDef *hostdev) + virDomainHostdevDef *hostdev, + bool *created) { g_autoptr(virGSListString) paths =3D NULL; =20 @@ -1450,7 +1453,7 @@ qemuDomainNamespaceSetupHostdev(virDomainObj *vm, &paths) < 0) return -1; =20 - if (qemuNamespaceMknodPaths(vm, paths) < 0) + if (qemuNamespaceMknodPaths(vm, paths, created) < 0) return -1; =20 return 0; @@ -1492,7 +1495,8 @@ qemuDomainNamespaceTeardownHostdev(virDomainObj *vm, =20 int qemuDomainNamespaceSetupMemory(virDomainObj *vm, - virDomainMemoryDef *mem) + virDomainMemoryDef *mem, + bool *created) { g_autoptr(virGSListString) paths =3D NULL; =20 @@ -1502,7 +1506,7 @@ qemuDomainNamespaceSetupMemory(virDomainObj *vm, if (qemuDomainSetupMemory(mem, &paths) < 0) return -1; =20 - if (qemuNamespaceMknodPaths(vm, paths) < 0) + if (qemuNamespaceMknodPaths(vm, paths, created) < 0) return -1; =20 return 0; @@ -1530,7 +1534,8 @@ qemuDomainNamespaceTeardownMemory(virDomainObj *vm, =20 int qemuDomainNamespaceSetupChardev(virDomainObj *vm, - virDomainChrDef *chr) + virDomainChrDef *chr, + bool *created) { g_autoptr(virGSListString) paths =3D NULL; =20 @@ -1540,7 +1545,7 @@ qemuDomainNamespaceSetupChardev(virDomainObj *vm, if (qemuDomainSetupChardev(vm->def, chr, &paths) < 0) return -1; =20 - if (qemuNamespaceMknodPaths(vm, paths) < 0) + if (qemuNamespaceMknodPaths(vm, paths, created) < 0) return -1; =20 return 0; @@ -1568,7 +1573,8 @@ qemuDomainNamespaceTeardownChardev(virDomainObj *vm, =20 int qemuDomainNamespaceSetupRNG(virDomainObj *vm, - virDomainRNGDef *rng) + virDomainRNGDef *rng, + bool *created) { g_autoptr(virGSListString) paths =3D NULL; =20 @@ -1578,7 +1584,7 @@ qemuDomainNamespaceSetupRNG(virDomainObj *vm, if (qemuDomainSetupRNG(rng, &paths) < 0) return -1; =20 - if (qemuNamespaceMknodPaths(vm, paths) < 0) + if (qemuNamespaceMknodPaths(vm, paths, created) < 0) return -1; =20 return 0; @@ -1606,9 +1612,11 @@ qemuDomainNamespaceTeardownRNG(virDomainObj *vm, =20 int qemuDomainNamespaceSetupInput(virDomainObj *vm, - virDomainInputDef *input) + virDomainInputDef *input, + bool *created) { g_autoptr(virGSListString) paths =3D NULL; + int ret =3D 0; =20 if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT)) return 0; @@ -1616,8 +1624,9 @@ qemuDomainNamespaceSetupInput(virDomainObj *vm, if (qemuDomainSetupInput(input, &paths) < 0) return -1; =20 - if (qemuNamespaceMknodPaths(vm, paths) < 0) + if ((ret =3D qemuNamespaceMknodPaths(vm, paths, created)) < 0) return -1; + return 0; } =20 diff --git a/src/qemu/qemu_namespace.h b/src/qemu/qemu_namespace.h index 771d7873ef..020aca13d8 100644 --- a/src/qemu/qemu_namespace.h +++ b/src/qemu/qemu_namespace.h @@ -50,37 +50,43 @@ void qemuDomainDestroyNamespace(virQEMUDriver *driver, bool qemuDomainNamespaceAvailable(qemuDomainNamespace ns); =20 int qemuDomainNamespaceSetupDisk(virDomainObj *vm, - virStorageSource *src); + virStorageSource *src, + bool *created); =20 int qemuDomainNamespaceTeardownDisk(virDomainObj *vm, virStorageSource *src); =20 int qemuDomainNamespaceSetupHostdev(virDomainObj *vm, - virDomainHostdevDef *hostdev); + virDomainHostdevDef *hostdev, + bool *created); =20 int qemuDomainNamespaceTeardownHostdev(virDomainObj *vm, virDomainHostdevDef *hostdev); =20 int qemuDomainNamespaceSetupMemory(virDomainObj *vm, - virDomainMemoryDef *memory); + virDomainMemoryDef *memory, + bool *created); =20 int qemuDomainNamespaceTeardownMemory(virDomainObj *vm, virDomainMemoryDef *memory); =20 int qemuDomainNamespaceSetupChardev(virDomainObj *vm, - virDomainChrDef *chr); + virDomainChrDef *chr, + bool *created); =20 int qemuDomainNamespaceTeardownChardev(virDomainObj *vm, virDomainChrDef *chr); =20 int qemuDomainNamespaceSetupRNG(virDomainObj *vm, - virDomainRNGDef *rng); + virDomainRNGDef *rng, + bool *created); =20 int qemuDomainNamespaceTeardownRNG(virDomainObj *vm, virDomainRNGDef *rng); =20 int qemuDomainNamespaceSetupInput(virDomainObj *vm, - virDomainInputDef *input); + virDomainInputDef *input, + bool *created); =20 int qemuDomainNamespaceTeardownInput(virDomainObj *vm, virDomainInputDef *input); diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 7487e12640..c972c90801 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -8452,7 +8452,7 @@ qemuProcessRefreshLegacyBlockjob(void *payload, =20 if (disk->mirror->format && disk->mirror->format !=3D VIR_STORAGE_FILE_RAW && - (qemuDomainNamespaceSetupDisk(vm, disk->mirror) < 0 || + (qemuDomainNamespaceSetupDisk(vm, disk->mirror, NULL) < 0 = || qemuSetupImageChainCgroup(vm, disk->mirror) < 0 || qemuSecuritySetImageLabel(priv->driver, vm, disk->mirror, true, true) < 0)) --=20 2.31.1