From nobody Mon Feb 9 08:06:09 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=1595411061; cv=none; d=zohomail.com; s=zohoarc; b=NyB4f2znVuDXxSmXUayIhM7nFAUFfYwfO/kVk1cH8zZfvxf6uEB08vWltGRO35NBbebE+wlL7JMbszTZ4EcYV68eFhyl2P746+p8WLd93WPYn2NoLFpNVZKqfhmKcl4D67ubbQPOJ0hw8pQX+7EAtaPiQLRxGCHo2PjrLF5+fLM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595411061; 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=jaUwJfbDSbVMelau9iv1CfB+WMUntJ3RKiOwDazw7Co=; b=hBTC7woV+pX4LX406l8e44avfHBztTIk+YcyjKWsAFVjzvP1bupQU7RMdYP2OA8Nvvzh9HqnV7RYoF96y9ZmVQm8M+ksFLI7MP4GxEffkECE4Rx+EMmHVKvY3BvQQG3uJCL3vpw+NlL+qdp9eTHR0g29dtyVBWb1ZOTrl3tgspg= 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 1595411061234596.5119609513094; Wed, 22 Jul 2020 02:44:21 -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-38-TtKcJCwBNaW-NG3UnQjNtA-1; Wed, 22 Jul 2020 05:44:17 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B774218C63C1; Wed, 22 Jul 2020 09:44:11 +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 9D74169321; Wed, 22 Jul 2020 09:44:11 +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 1AF3A1809561; Wed, 22 Jul 2020 09:44:11 +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 06M9f9rQ001093 for ; Wed, 22 Jul 2020 05:41:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id 70AC02B5BF; Wed, 22 Jul 2020 09:41:09 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.195.120]) by smtp.corp.redhat.com (Postfix) with ESMTP id E31762DE68 for ; Wed, 22 Jul 2020 09:41:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595411059; 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=jaUwJfbDSbVMelau9iv1CfB+WMUntJ3RKiOwDazw7Co=; b=P1w8x6V8uDMpHMg47GnLNm+F+FMOqMMlDSaU54ho7hhsccHUWpQ7LRTKVM8BPaF8g/uaIU XuMwXWAYZyqd97Pp8JJU9XiRiozo+36qxDQYniEbrl1k/zby6ce7zTyOHNYmjmwpvmXqYa R+Dj5OOY3lGFvy68kg/bwzdlweL69P0= X-MC-Unique: TtKcJCwBNaW-NG3UnQjNtA-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v1 28/34] qemuDomainDetachDeviceUnlink: Unlink paths in one go Date: Wed, 22 Jul 2020 11:40:22 +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.16 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) Content-Type: text/plain; charset="utf-8" Simirarly to qemuDomainAttachDeviceMknodHelper() which was modified just a couple of commits ago, modify the unlink helper which is called on device detach so that it can unlink multiple files in one go instead of forking off for every single one of them. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_domain_namespace.c | 65 +++++++++++++++----------------- 1 file changed, 30 insertions(+), 35 deletions(-) diff --git a/src/qemu/qemu_domain_namespace.c b/src/qemu/qemu_domain_namesp= ace.c index 41d79559f9..4e0b50d885 100644 --- a/src/qemu/qemu_domain_namespace.c +++ b/src/qemu/qemu_domain_namespace.c @@ -1286,44 +1286,21 @@ static int qemuDomainDetachDeviceUnlinkHelper(pid_t pid G_GNUC_UNUSED, void *opaque) { - const char *path =3D opaque; - - VIR_DEBUG("Unlinking %s", path); - if (unlink(path) < 0 && errno !=3D ENOENT) { - virReportSystemError(errno, - _("Unable to remove device %s"), path); - return -1; - } - - return 0; -} - - -static int -qemuDomainDetachDeviceUnlink(virQEMUDriverPtr driver G_GNUC_UNUSED, - virDomainObjPtr vm, - const char *file, - char * const *devMountsPath, - size_t ndevMountsPath) -{ + char **paths =3D opaque; size_t i; =20 - if (STRPREFIX(file, QEMU_DEVPREFIX)) { - for (i =3D 0; i < ndevMountsPath; i++) { - if (STREQ(devMountsPath[i], "/dev")) - continue; - if (STRPREFIX(file, devMountsPath[i])) - break; - } + for (i =3D 0; paths[i]; i++) { + const char *path =3D paths[i]; =20 - if (i =3D=3D ndevMountsPath) { - if (virProcessRunInMountNamespace(vm->pid, - qemuDomainDetachDeviceUnlink= Helper, - (void *)file) < 0) - return -1; + VIR_DEBUG("Unlinking %s", path); + if (unlink(path) < 0 && errno !=3D ENOENT) { + virReportSystemError(errno, + _("Unable to remove device %s"), path); + return -1; } } =20 + virStringListFree(paths); return 0; } =20 @@ -1336,6 +1313,7 @@ qemuDomainNamespaceUnlinkPaths(virDomainObjPtr vm, qemuDomainObjPrivatePtr priv =3D vm->privateData; virQEMUDriverPtr driver =3D priv->driver; g_autoptr(virQEMUDriverConfig) cfg =3D NULL; + VIR_AUTOSTRINGLIST unlinkPaths =3D NULL; char **devMountsPath =3D NULL; size_t ndevMountsPath =3D 0; size_t i; @@ -1352,11 +1330,28 @@ qemuDomainNamespaceUnlinkPaths(virDomainObjPtr vm, goto cleanup; =20 for (i =3D 0; i < npaths; i++) { - if (qemuDomainDetachDeviceUnlink(driver, vm, paths[i], - devMountsPath, ndevMountsPath) < = 0) - goto cleanup; + const char *file =3D paths[i]; + + if (STRPREFIX(file, QEMU_DEVPREFIX)) { + for (i =3D 0; i < ndevMountsPath; i++) { + if (STREQ(devMountsPath[i], "/dev")) + continue; + if (STRPREFIX(file, devMountsPath[i])) + break; + } + + if (i =3D=3D ndevMountsPath && + virStringListAdd(&unlinkPaths, file) < 0) + return -1; + } } =20 + if (unlinkPaths && + virProcessRunInMountNamespace(vm->pid, + qemuDomainDetachDeviceUnlinkHelper, + unlinkPaths) < 0) + return -1; + ret =3D 0; cleanup: virStringListFreeCount(devMountsPath, ndevMountsPath); --=20 2.26.2