From nobody Fri May 16 00:54:05 2025 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.zohomail.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 15030705962057.049220888703871; Fri, 18 Aug 2017 08:36:36 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id D967581DF4; Fri, 18 Aug 2017 15:36:33 +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 82C0D60468; Fri, 18 Aug 2017 15:36:33 +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 16D551800C8E; Fri, 18 Aug 2017 15:36:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v7IFaANX021376 for ; Fri, 18 Aug 2017 11:36:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7DB2B60BF2; Fri, 18 Aug 2017 15:36:10 +0000 (UTC) Received: from caroline.localdomain (unknown [10.43.2.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 28EFC707B1 for ; Fri, 18 Aug 2017 15:36:07 +0000 (UTC) Received: from caroline.brq.redhat.com (caroline.brq.redhat.com [127.0.0.1]) by caroline.localdomain (Postfix) with ESMTP id 5A00612036E for ; Fri, 18 Aug 2017 17:36:06 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D967581DF4 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Martin Kletzander To: libvir-list@redhat.com Date: Fri, 18 Aug 2017 17:36:04 +0200 Message-Id: <4cc6f55c14b38d616c9518659bbe2f47d7ee8f0e.1503070458.git.mkletzan@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/2] qemu: Also treat directories properly when using namespaces 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 18 Aug 2017 15:36:34 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Partially-resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D1443434 Signed-off-by: Martin Kletzander Reviewed-by: John Ferlan --- src/qemu/qemu_domain.c | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 40608554c473..b5fc6697ed29 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -7837,6 +7837,7 @@ qemuDomainCreateDeviceRecursive(const char *device, isLink =3D S_ISLNK(sb.st_mode); isDev =3D S_ISCHR(sb.st_mode) || S_ISBLK(sb.st_mode); isReg =3D S_ISREG(sb.st_mode) || S_ISFIFO(sb.st_mode) || S_ISSOCK(sb.s= t_mode); + isDir =3D S_ISDIR(sb.st_mode); =20 /* Here, @device might be whatever path in the system. We * should create the path in the namespace iff it's "/dev" @@ -7954,6 +7955,10 @@ qemuDomainCreateDeviceRecursive(const char *device, goto cleanup; /* Just create the file here so that code below sets * proper owner and mode. Bind mount only after that. */ + } else if (isDir) { + if (create && + virFileMakePathWithMode(devicePath, sb.st_mode) < 0) + goto cleanup; } else { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, _("unsupported device type %s 0%o"), @@ -8015,7 +8020,7 @@ qemuDomainCreateDeviceRecursive(const char *device, #endif =20 /* Finish mount process started earlier. */ - if (isReg && + if ((isReg || isDir) && virFileBindMountDevice(device, devicePath) < 0) goto cleanup; =20 @@ -8644,6 +8649,7 @@ qemuDomainAttachDeviceMknodHelper(pid_t pid ATTRIBUTE= _UNUSED, bool isLink =3D S_ISLNK(data->sb.st_mode); bool isDev =3D S_ISCHR(data->sb.st_mode) || S_ISBLK(data->sb.st_mode); bool isReg =3D S_ISREG(data->sb.st_mode) || S_ISFIFO(data->sb.st_mode)= || S_ISSOCK(data->sb.st_mode); + bool isDir =3D S_ISDIR(data->sb.st_mode); =20 qemuSecurityPostFork(data->driver->securityManager); =20 @@ -8699,6 +8705,23 @@ qemuDomainAttachDeviceMknodHelper(pid_t pid ATTRIBUT= E_UNUSED, delDevice =3D true; /* Just create the file here so that code below sets * proper owner and mode. Move the mount only after that. */ + } else if (isDir) { + /* We are not cleaning up disks on virDomainDetachDevice + * because disk might be still in use by different disk + * as its backing chain. This might however clash here. + * Therefore do the cleanup here. */ + if (umount(data->file) < 0 && + errno !=3D ENOENT && errno !=3D EINVAL) { + virReportSystemError(errno, + _("Unable to umount %s"), + data->file); + goto cleanup; + } + if (virFileMakePathWithMode(data->file, data->sb.st_mode) < 0) + goto cleanup; + delDevice =3D true; + /* Just create the folder here so that code below sets + * proper owner and mode. Move the mount only after that. */ } else { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, _("unsupported device type %s 0%o"), @@ -8746,14 +8769,18 @@ qemuDomainAttachDeviceMknodHelper(pid_t pid ATTRIBU= TE_UNUSED, # endif =20 /* Finish mount process started earlier. */ - if (isReg && + if ((isReg || isDir) && virFileMoveMount(data->target, data->file) < 0) goto cleanup; =20 ret =3D 0; cleanup: - if (ret < 0 && delDevice) - unlink(data->file); + if (ret < 0 && delDevice) { + if (isDir) + virFileDeleteTree(data->file); + else + unlink(data->file); + } # ifdef WITH_SELINUX freecon(data->tcon); # endif @@ -8798,8 +8825,9 @@ qemuDomainAttachDeviceMknodRecursive(virQEMUDriverPtr= 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); =20 - if (isReg && STRPREFIX(file, DEVPREFIX)) { + if ((isReg || isDir) && STRPREFIX(file, DEVPREFIX)) { cfg =3D virQEMUDriverGetConfig(driver); if (!(target =3D qemuDomainGetPreservedMountPath(cfg, vm, file))) goto cleanup; --=20 2.14.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list