From nobody Thu May 2 06:33:39 2024 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 1503995666533544.3849630350967; Tue, 29 Aug 2017 01:34:26 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 58285883DC; Tue, 29 Aug 2017 08:34:24 +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 2D52760636; Tue, 29 Aug 2017 08:34:24 +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 E88FB3FC75; Tue, 29 Aug 2017 08:34:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v7T8YCmc025651 for ; Tue, 29 Aug 2017 04:34:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0F8286BC0D; Tue, 29 Aug 2017 08:34:12 +0000 (UTC) Received: from caroline.localdomain (unknown [10.43.2.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D92F76A77E for ; Tue, 29 Aug 2017 08:34:10 +0000 (UTC) Received: from caroline.brq.redhat.com (caroline.brq.redhat.com [127.0.0.1]) by caroline.localdomain (Postfix) with ESMTP id D0C6A120704 for ; Tue, 29 Aug 2017 10:34:08 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 58285883DC Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Martin Kletzander To: libvir-list@redhat.com Date: Tue, 29 Aug 2017 10:34:06 +0200 Message-Id: <1dad00c5fa6495875f2fb238fd19e77d2c019cad.1503995602.git.mkletzan@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 1/2] qemu: Don't mangle the storage format for type='dir' 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 29 Aug 2017 08:34:25 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Our backing probing code handles directory file types properly in virStorageFileGetMetadataRecurse(), by that I mean it leaves them alone. However its caller, the virStorageFileGetMetadata() resets the type to raw before probing, without even checking the type. We need to special-case TYPE_DIR in order to achieve desired results. Also, in order to properly test this, we need to stop resetting format of volumes in tests for TYPE_DIR (probably the reason why we didn't catch that and why the test data didn't need to be modified). Partially-resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D1443434 Signed-off-by: Martin Kletzander --- src/storage/storage_source.c | 12 +++++++++--- tests/virstoragetest.c | 11 +++++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/storage/storage_source.c b/src/storage/storage_source.c index b620153f1e5a..bf47622372ab 100644 --- a/src/storage/storage_source.c +++ b/src/storage/storage_source.c @@ -527,14 +527,20 @@ virStorageFileGetMetadata(virStorageSourcePtr src, allow_probe, report_broken); =20 virHashTablePtr cycle =3D NULL; + virStorageType actualType =3D virStorageSourceGetActualType(src); int ret =3D -1; =20 if (!(cycle =3D virHashCreate(5, NULL))) return -1; =20 - if (src->format <=3D VIR_STORAGE_FILE_NONE) - src->format =3D allow_probe ? - VIR_STORAGE_FILE_AUTO : VIR_STORAGE_FILE_RAW; + if (src->format <=3D VIR_STORAGE_FILE_NONE) { + if (actualType =3D=3D VIR_STORAGE_TYPE_DIR) + src->format =3D VIR_STORAGE_FILE_DIR; + else if (allow_probe) + src->format =3D VIR_STORAGE_FILE_AUTO; + else + src->format =3D VIR_STORAGE_FILE_RAW; + } =20 ret =3D virStorageFileGetMetadataRecurse(src, src, uid, gid, allow_probe, report_broken, cyc= le); diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index d83db78f566f..60e3164b0ac8 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -111,7 +111,6 @@ testStorageFileGetMetadata(const char *path, if (stat(path, &st) =3D=3D 0) { if (S_ISDIR(st.st_mode)) { ret->type =3D VIR_STORAGE_TYPE_DIR; - ret->format =3D VIR_STORAGE_FILE_DIR; } else if (S_ISBLK(st.st_mode)) { ret->type =3D VIR_STORAGE_TYPE_BLOCK; } @@ -963,7 +962,15 @@ mymain(void) .type =3D VIR_STORAGE_TYPE_DIR, .format =3D VIR_STORAGE_FILE_DIR, }; - TEST_CHAIN(absdir, VIR_STORAGE_FILE_AUTO, + testFileData dir_as_raw =3D { + .path =3D canondir, + .type =3D VIR_STORAGE_TYPE_DIR, + .format =3D VIR_STORAGE_FILE_RAW, + }; + TEST_CHAIN(absdir, VIR_STORAGE_FILE_RAW, + (&dir_as_raw), EXP_PASS, + (&dir_as_raw), ALLOW_PROBE | EXP_PASS); + TEST_CHAIN(absdir, VIR_STORAGE_FILE_NONE, (&dir), EXP_PASS, (&dir), ALLOW_PROBE | EXP_PASS); TEST_CHAIN(absdir, VIR_STORAGE_FILE_DIR, --=20 2.14.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 06:33:39 2024 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 1503995670310635.1840815674727; Tue, 29 Aug 2017 01:34:30 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2E5DD5D68A; Tue, 29 Aug 2017 08:34:28 +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 08D5A6EC9A; Tue, 29 Aug 2017 08:34:28 +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 C21B31800C8A; Tue, 29 Aug 2017 08:34:27 +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 v7T8YCqO025660 for ; Tue, 29 Aug 2017 04:34:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id 449FA183FD; Tue, 29 Aug 2017 08:34:12 +0000 (UTC) Received: from caroline.localdomain (unknown [10.43.2.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E7D3B60636 for ; Tue, 29 Aug 2017 08:34:10 +0000 (UTC) Received: from caroline.brq.redhat.com (caroline.brq.redhat.com [127.0.0.1]) by caroline.localdomain (Postfix) with ESMTP id DBBF112070C for ; Tue, 29 Aug 2017 10:34:08 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2E5DD5D68A Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Martin Kletzander To: libvir-list@redhat.com Date: Tue, 29 Aug 2017 10:34:07 +0200 Message-Id: <230378cea8c1594f65899bf0eec9781a00163a83.1503995602.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 v2 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 29 Aug 2017 08:34:28 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When recreating folders with namespaces, the directory type was not being handled at all. It's not special, we probably just didn't know that that can be used as a volume path as well. The code failed gracefully, but we want to allow that so that we can use in domains again. Partially-resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D1443434 Signed-off-by: Martin Kletzander --- src/qemu/qemu_domain.c | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 2c77a6442467..2549f9bf3290 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -7855,6 +7855,7 @@ qemuDomainCreateDeviceRecursive(const char *device, bool isLink =3D false; bool isDev =3D false; bool isReg =3D false; + bool isDir =3D false; bool create =3D false; #ifdef WITH_SELINUX char *tcon =3D NULL; @@ -7879,6 +7880,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" @@ -7996,6 +7998,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"), @@ -8057,7 +8063,7 @@ qemuDomainCreateDeviceRecursive(const char *device, #endif =20 /* Finish mount process started earlier. */ - if (isReg && + if ((isReg || isDir) && virFileBindMountDevice(device, devicePath) < 0) goto cleanup; =20 @@ -8686,6 +8692,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 @@ -8741,6 +8748,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"), @@ -8788,14 +8812,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 @@ -8818,6 +8846,7 @@ qemuDomainAttachDeviceMknodRecursive(virQEMUDriverPtr= driver, char *target =3D NULL; bool isLink; bool isReg; + bool isDir; =20 if (!ttl) { virReportSystemError(ELOOP, @@ -8840,8 +8869,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