From nobody Fri May 3 09:09:17 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 1503070602956808.1572212843874; Fri, 18 Aug 2017 08:36:42 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F38B2C0587C4; Fri, 18 Aug 2017 15:36:40 +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 BFCEB5D965; Fri, 18 Aug 2017 15:36:40 +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 8A72D3FC72; Fri, 18 Aug 2017 15:36:40 +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 v7IFaAR0021377 for ; Fri, 18 Aug 2017 11:36:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7D4BA60636; 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 29314707B5 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 4EEF512036C for ; Fri, 18 Aug 2017 17:36:06 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com F38B2C0587C4 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.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:03 +0200 Message-Id: <4ca7d5c3c8e0f37966b88ec9864c7b71ee98c6eb.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 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 18 Aug 2017 15:36:41 +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/storage/storage_source.c | 5 ++++ .../qemuxml2argv-floppy-drive-noformat.args | 24 +++++++++++++++++ .../qemuxml2argv-floppy-drive-noformat.xml | 31 ++++++++++++++++++= ++++ tests/qemuxml2argvtest.c | 2 ++ 4 files changed, 62 insertions(+) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-floppy-drive-noform= at.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-floppy-drive-noform= at.xml diff --git a/src/storage/storage_source.c b/src/storage/storage_source.c index b620153f1e5a..bbc5cc77be1a 100644 --- a/src/storage/storage_source.c +++ b/src/storage/storage_source.c @@ -527,11 +527,16 @@ 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 + /* No backing chains for type=3D'dir' */ + if (actualType =3D=3D VIR_STORAGE_TYPE_DIR) + return 0; + if (src->format <=3D VIR_STORAGE_FILE_NONE) src->format =3D allow_probe ? VIR_STORAGE_FILE_AUTO : VIR_STORAGE_FILE_RAW; diff --git a/tests/qemuxml2argvdata/qemuxml2argv-floppy-drive-noformat.args= b/tests/qemuxml2argvdata/qemuxml2argv-floppy-drive-noformat.args new file mode 100644 index 000000000000..214067b50345 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-floppy-drive-noformat.args @@ -0,0 +1,24 @@ +LC_ALL=3DC \ +PATH=3D/bin \ +HOME=3D/home/test \ +USER=3Dtest \ +LOGNAME=3Dtest \ +QEMU_AUDIO_DRV=3Dnone \ +/usr/bin/qemu-system-i686 \ +-name QEMUGuest1 \ +-S \ +-M pc \ +-m 214 \ +-smp 1,sockets=3D1,cores=3D1,threads=3D1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-nographic \ +-nodefaults \ +-chardev socket,id=3Dcharmonitor,path=3D/tmp/lib/domain--1-QEMUGuest1/moni= tor.sock,\ +server,nowait \ +-mon chardev=3Dcharmonitor,id=3Dmonitor,mode=3Dreadline \ +-no-acpi \ +-boot a \ +-usb \ +-drive file=3Dfat:floppy:/var/somefiles,if=3Dnone,id=3Ddrive-fdc0-0-0,read= only=3Don \ +-global isa-fdc.driveA=3Ddrive-fdc0-0-0 \ +-device virtio-balloon-pci,id=3Dballoon0,bus=3Dpci.0,addr=3D0x3 diff --git a/tests/qemuxml2argvdata/qemuxml2argv-floppy-drive-noformat.xml = b/tests/qemuxml2argvdata/qemuxml2argv-floppy-drive-noformat.xml new file mode 100644 index 000000000000..9d9dcfe5e603 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-floppy-drive-noformat.xml @@ -0,0 +1,31 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-i686 + + + + +
+ + + + + + + + + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 77cfe8d28fd1..b7cf2a22b196 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -887,6 +887,8 @@ mymain(void) QEMU_CAPS_DRIVE_BOOT); DO_TEST("floppy-drive-fat", QEMU_CAPS_DRIVE_BOOT); + DO_TEST("floppy-drive-noformat", + QEMU_CAPS_DRIVE_BOOT); DO_TEST("disk-drive-readonly-disk", QEMU_CAPS_NODEFCONFIG); DO_TEST("disk-drive-readonly-no-device", --=20 2.14.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 09:09:17 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 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