From nobody Sun Feb 8 19:56:05 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=1595410854; cv=none; d=zohomail.com; s=zohoarc; b=YHxdpA8QUm8wNp54BEI1YcZdGuxfovSC64CtvhxQbNMoMCsX7GVIcKfhKFV4f4gcgIk5D6fJoTH/U5bcwhF7EMlIH4T8elwqVHVonyqWuMpSY3X6/NC/WUWha5ugeV5HrOAdGTF/4u5CIU1P4O22xxkryXRzhYMK1vik8ptIsNY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595410854; 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=DWObagLzx+u+LoGYpk5sq8thoNFdDxBIL9ofbaumzhM=; b=Ej8YkGL9JEkgczA/d/DfTB/pJYfot4R35C7y1seGOdI18kQ0O9buwMV8Q0BOMtv/2HUValNkN/EZXYRqVM0L5vfRuq1zCER+wi5RjmgaHy7DtqqmdfvnxVgKGTiPmec0ROCZ13uS/KlvELc6tWmgXGiB7z2pAURjfp6jkWQ8WwI= 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-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1595410854219750.1735070174088; Wed, 22 Jul 2020 02:40:54 -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-482-ortt23FXMzqP1nXSr4O3Iw-1; Wed, 22 Jul 2020 05:40:49 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3B06E800C64; Wed, 22 Jul 2020 09:40:44 +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 38EF61001B2C; Wed, 22 Jul 2020 09:40:43 +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 B97CF1809554; Wed, 22 Jul 2020 09:40:39 +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 06M9ebBS000822 for ; Wed, 22 Jul 2020 05:40:37 -0400 Received: by smtp.corp.redhat.com (Postfix) id 444CC1A8F7; Wed, 22 Jul 2020 09:40:37 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.195.120]) by smtp.corp.redhat.com (Postfix) with ESMTP id B72372855B for ; Wed, 22 Jul 2020 09:40:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595410853; 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=DWObagLzx+u+LoGYpk5sq8thoNFdDxBIL9ofbaumzhM=; b=eJDfiDFLSs1vfB2FdPDh+ojJWrGlh7KayRzNtvYryc7apeaCAvlnou9oiR350O5X9ZBeZT wA8B6ODYG60Nazn6Xmphsx+wesEZStY4TZxmUZZwhQdbDNkuXN7657G+xxNPDfOHr8NRiH y2q+7kGwh6ZBzucIuhOzkXV+S0io8iY= X-MC-Unique: ortt23FXMzqP1nXSr4O3Iw-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v1 02/34] virDevMapperGetTargets: Don't ignore EBADF Date: Wed, 22 Jul 2020 11:39:56 +0200 Message-Id: <7b7f8a3dd5e2ec476f27729c356841ad520ed468.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.84 on 10.5.11.22 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" One of the symptoms of the bug [1] is that on the second start of a domain we get EBADF when talking to libdevmapper. The reason is that libdevmapper opens /dev/mapper/control to talk to kernel and saves the FD into a global variable. This works well when starting a domain for the first time: the pre-exec hook (which is a separate process) gets info it needs; then the daemon sets up CGroups (where it will open the file again, because it's a different process). Now, libdevmapper won't close this FD until library is unloaded (in destructor) or dm_lib_release() is called. We were not doing any of that, hence, when starting a domain (any domain, even a different one), we forked off a child process (which will eventually become QEMU), mass close all FDs (including the libdevmapper's one), and run pre-exec hook. Since we closed the FD, libdevmapper will pass closed FD into an ioctl() and thus we got EBADF. After previous patch, this approach is history and thus we should not see EBADF anymore. 1: https://bugzilla.redhat.com/show_bug.cgi?id=3D1858260 Signed-off-by: Michal Privoznik --- src/qemu/qemu_cgroup.c | 2 +- src/qemu/qemu_domain.c | 4 ++-- src/util/virdevmapper.c | 3 --- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index 914bf640ca..e88da02341 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -87,7 +87,7 @@ qemuSetupImagePathCgroup(virDomainObjPtr vm, } =20 if (virDevMapperGetTargets(path, &targetPaths) < 0 && - errno !=3D ENOSYS && errno !=3D EBADF) { + errno !=3D ENOSYS) { virReportSystemError(errno, _("Unable to get devmapper targets for %s"), path); diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 5b22eb2eaa..2058290870 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -10264,7 +10264,7 @@ qemuDomainSetupDisk(virQEMUDriverConfigPtr cfg G_GN= UC_UNUSED, return -1; =20 if (virDevMapperGetTargets(next->path, &targetPaths) < 0 && - errno !=3D ENOSYS && errno !=3D EBADF) { + errno !=3D ENOSYS) { virReportSystemError(errno, _("Unable to get devmapper targets fo= r %s"), next->path); @@ -11328,7 +11328,7 @@ qemuDomainNamespaceSetupDisk(virDomainObjPtr vm, tmpPath =3D g_strdup(next->path); =20 if (virDevMapperGetTargets(next->path, &targetPaths) < 0 && - errno !=3D ENOSYS && errno !=3D EBADF) { + errno !=3D ENOSYS) { virReportSystemError(errno, _("Unable to get devmapper targets fo= r %s"), next->path); diff --git a/src/util/virdevmapper.c b/src/util/virdevmapper.c index 1c216fb6c1..139d70b854 100644 --- a/src/util/virdevmapper.c +++ b/src/util/virdevmapper.c @@ -176,9 +176,6 @@ virDevMapperGetTargetsImpl(const char *path, * If @path consists of yet another devmapper targets these are * consulted recursively. * - * If we don't have permissions to talk to kernel, -1 is returned - * and errno is set to EBADF. - * * Returns 0 on success, * -1 otherwise (with errno set, no libvirt error is * reported) --=20 2.26.2