From nobody Mon Feb 9 06:26:32 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=1595410869; cv=none; d=zohomail.com; s=zohoarc; b=VrRtOK6dgocQTxVKXAbGu5yzC0DzA9126L4/4eBUtzZn+tMru7+pNXkDWzFsLa+aqEkGgyP2LJKE90VSmOLZ+gpn+W9QEY2dGq4z7seu7uWElmCK14ufTmyQY8iSccou5fc3S3wccSTWHB4VctkMtviGqsnMUK4FVk+CMnnUfwk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595410869; 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=eNF5lQEiby5yDwkwYPdlYmV5xNF/slHP9tE3+jUXOIc=; b=FsSiN7JZ0pCkhu4R3l+cOe6z/EI9QQfH1+SnzkY42kC+kfOHPg1j16Jp9cd2uHCArrK85DcEBjCOPYwAnEiOVpyvw/mL3BWuYFc4Hj+xlro4w2bJgg4QymtNWs2Rlqw5BybVgxUOECNDbs6qB/wpcCSZQcoOXi4mSse4xMhGv5o= 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 1595410869001403.42965171115225; Wed, 22 Jul 2020 02:41:09 -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-343-pyL17SEXNYi6kFjxVUa5DQ-1; Wed, 22 Jul 2020 05:41:05 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A9E2118C63D2; Wed, 22 Jul 2020 09:40:57 +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 8A41878540; Wed, 22 Jul 2020 09:40:57 +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 59AB7730E7; Wed, 22 Jul 2020 09:40:57 +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 06M9ek1H000904 for ; Wed, 22 Jul 2020 05:40:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id BFE231A8F7; Wed, 22 Jul 2020 09:40:46 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.195.120]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3ED531A90F for ; Wed, 22 Jul 2020 09:40:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595410867; 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=eNF5lQEiby5yDwkwYPdlYmV5xNF/slHP9tE3+jUXOIc=; b=MlnRFjuBN/jeCJwcdkAlVjtMUhoO/m0m3dS6JswcFzCOZeifNdNgKVqYNa8Zg50SDNx1+7 JveKLMfSj/G3kCQkEvUDI9dISQw/dcIDuhDs9j/Ew0WHscEegLHxOTr5+mkHIj8m19jgTn Xd9Av5YurfZlDHWT1awiWQloD7OGnbc= X-MC-Unique: pyL17SEXNYi6kFjxVUa5DQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v1 10/34] qemuDomainAttachDeviceMknodRecursive: Isolate bind mounted devices condition Date: Wed, 22 Jul 2020 11:40:04 +0200 Message-Id: <630689607eb47b42d0944b8602e51d2d46d44af3.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.79 on 10.5.11.11 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" When attaching a device into a domain, the corresponding /dev node might need to be created in the domain's namespace. For some types of files we call mknod(), for symlinks we call symlink(), but for others - which exist in the host namespace - we need to so called 'bind mount' them (which is a way of passing a file/directory between mount namespaces). There is this condition in qemuDomainAttachDeviceMknodRecursive() which decides whether a bind mount will be used, move it into a separate function so that it can be reused later. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_domain_namespace.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_domain_namespace.c b/src/qemu/qemu_domain_namesp= ace.c index 40c4fb36cb..0c40118938 100644 --- a/src/qemu/qemu_domain_namespace.c +++ b/src/qemu/qemu_domain_namespace.c @@ -1253,6 +1253,17 @@ qemuDomainAttachDeviceMknodHelper(pid_t pid G_GNUC_U= NUSED, } =20 =20 +static bool +qemuDomainMknodItemIsBindMounted(mode_t st_mode) +{ + /* A block device S_ISBLK() or a chardev S_ISCHR() is intentionally not + * handled. We want to mknod() it instead of passing in through bind + * mounting. */ + return S_ISREG(st_mode) || S_ISFIFO(st_mode) || + S_ISSOCK(st_mode) || S_ISDIR(st_mode); +} + + static int qemuDomainAttachDeviceMknodRecursive(virQEMUDriverPtr driver, virDomainObjPtr vm, @@ -1267,7 +1278,6 @@ qemuDomainAttachDeviceMknodRecursive(virQEMUDriverPtr= driver, g_autofree char *target =3D NULL; bool isLink; bool isReg; - bool isDir; =20 if (!ttl) { virReportSystemError(ELOOP, @@ -1289,10 +1299,9 @@ qemuDomainAttachDeviceMknodRecursive(virQEMUDriverPt= r driver, } =20 isLink =3D S_ISLNK(data.sb.st_mode); - isReg =3D S_ISREG(data.sb.st_mode) || S_ISFIFO(data.sb.st_mode) || S_I= SSOCK(data.sb.st_mode); - isDir =3D S_ISDIR(data.sb.st_mode); + isReg =3D qemuDomainMknodItemIsBindMounted(data.sb.st_mode); =20 - if ((isReg || isDir) && STRPREFIX(file, QEMU_DEVPREFIX)) { + if (isReg && STRPREFIX(file, QEMU_DEVPREFIX)) { cfg =3D virQEMUDriverGetConfig(driver); if (!(target =3D qemuDomainGetPreservedMountPath(cfg, vm, file))) goto cleanup; --=20 2.26.2