From nobody Wed Oct 29 05:57:26 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513595751427931.0841785539455; Mon, 18 Dec 2017 03:15:51 -0800 (PST) Received: from localhost ([::1]:57958 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eQtOa-0007fn-AF for importer@patchew.org; Mon, 18 Dec 2017 06:15:44 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57305) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eQtIV-0003Bm-0z for qemu-devel@nongnu.org; Mon, 18 Dec 2017 06:09:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eQtIO-0007Zx-IV for qemu-devel@nongnu.org; Mon, 18 Dec 2017 06:09:26 -0500 Received: from mailhub.sw.ru ([195.214.232.25]:7306 helo=relay.sw.ru) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eQtIO-0007Z5-1z for qemu-devel@nongnu.org; Mon, 18 Dec 2017 06:09:20 -0500 Received: from iris.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id vBHC7I6u013555; Sun, 17 Dec 2017 15:07:18 +0300 (MSK) From: "Denis V. Lunev" To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Mon, 18 Dec 2017 14:09:07 +0300 Message-Id: <1513595351-5899-2-git-send-email-den@openvz.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513595351-5899-1-git-send-email-den@openvz.org> References: <1513595351-5899-1-git-send-email-den@openvz.org> X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x [fuzzy] X-Received-From: 195.214.232.25 Subject: [Qemu-devel] [PATCH 1/5] docs/interop/prl-xml: description of Parallels Disk format X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Klim Kireev , Vladimir Sementsov-Ogievskiy , Edgar Kaziakhmedov , Stefan Hajnoczi , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Klim Kireev This patch adds main information about Parallels Disk format, which consists of DiskDescriptor.xml and other files. Signed-off-by: Edgar Kaziakhmedov Signed-off-by: Klim Kireev Signed-off-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Denis V. Lunev CC: Stefan Hajnoczi --- docs/interop/prl-xml.txt | 155 +++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 155 insertions(+) create mode 100644 docs/interop/prl-xml.txt diff --git a/docs/interop/prl-xml.txt b/docs/interop/prl-xml.txt new file mode 100644 index 0000000..8ccb91a --- /dev/null +++ b/docs/interop/prl-xml.txt @@ -0,0 +1,155 @@ +=3D License =3D + +Copyright (c) 2015 Denis Lunev +Copyright (c) 2015 Vladimir Sementsov-Ogievskiy +Copyright (c) 2016-2017 Klim Kireev +Copyright (c) 2016-2017 Edgar Kaziakhmedov + +This work is licensed under the terms of the GNU GPL, version 2 or later. +See the COPYING file in the top-level directory. + +This specification contains minimal information about Parallels Disk Forma= t, +which is enough to proper work with QEMU. Nevertheless, Parallels Cloud Se= rver +and Parallels Desktop are able to add some unspecified nodes to xml and use +them, but they are for internal work and don't affect functionality. Also = it +uses auxiliary xml "Snapshot.xml", which allows to store optional snapshot +information, but it doesn't influence open/read/write functionality. QEMU = and +other software should not use unspecified here fields and Snapshot.xml file +and must leave them as is. + +=3D Parallels Disk Format =3D + +Parallels disk consists of two parts: the set of snapshots and the disk +descriptor file, which stores information about all files and snapshots. + +=3D=3D Definitions =3D=3D + Snapshot a record of the contents captured at a particular time, + capable of storing current state. A snapshot has UUID a= nd + parent UUID. + + Snapshot image an overlay representing the difference between this + snapshot and some earlier snapshot + + Overlay an image storing the different sectors between two capt= ured + states. + + Root image snapshot image without parent, the root of snapshot tre= e. + + Storage a special conception of data, which consists of disk + parameters and a list of images. One of this image is r= oot, + others are overlays. Images must be expandable (paralle= ls + image file), however root image could be expandable or + plain. There may be more then one storage in the Parall= els + disk and it is defined as a split image. + In this case every storage covers specific address + space area of the disk and has its particular root imag= e. + Split images are not considered here and isn't supported + in QEMU. + + Description DiskDescriptor.xml stores information about disk parame= ters, + file snapshots, storages. + + Top The overlay between actual state and some previous snap= shot. + Snapshot It is not a snapshot in classical meaning. + + Sector a 512-byte data chunk. + +=3D=3D Description file =3D=3D +All information is placed in single XML section Parallels_disk_image. +The section has only one attribute "Version", that must be 1.0. +General structure of DiskDescriptor.xml: + + + + ... + + + ... + + + ... + + + +=3D=3D Disk_Parameters section =3D=3D +The Disk_Parameters section describes the physical layout of the virtual d= isk +and some general settings. + +The Disk_Parameters section MUST contain the following subsections: + * Disk_size - number of sectors in the disk, + desired size of the disk + * Cylinders - number of the disk cylinders + * Heads - number of the disk heads + * Sectors - number of the disk sectors per cylinder + (sector size is 512 bytes) + Limitation: Product of the Heads, Sectors and Cylinders + values MUST be equal to the value of the Disk_size param= eter. + * Padding - must be 0. Parallels Cloud Server and Parallels Desktop = may + use padding set to 1, however this case is not covered + by this spec, QEMU and other software should not open + such disks and should not create them. + Attention: this field affects the read/write functionali= ty. + +=3D=3D StorageData section =3D=3D +This section of the file describes root image and all snapshot images. + +The StorageData section consists of the Storage subsection, as shown below: + + + ... + + + +A Storage descriptor consists of the following subsections: + * Start - start sector of the storage, equals to 0. + * End - number of sectors in storage, equals to Disk_size. + * Blocksize - storage cluster size, number of sectors per one cluster. + Cluster size for each "Compressed" (see below) image in + parallels disk must be equal to this field. Note: cluster + size for Parallels Expandable Image is in 'tracks' field= of + its header (see docs/interop/parallels.txt). + * Several Image subsections. + +Each Image section consists of the following subsections: + * GUID - image identifier, UUID in curly brackets. + For instance, {12345678-9abc-def1-2345-6789abcdef12}. + * Type - image type of the element. It can be: + "Plain" for plain disks. + "Compressed" for expanding disks. + * File - path to image file. Path can be relative to DiskDecriptor.xml= or + absolute. + +=3D=3D Snapshots section =3D=3D +The Snapshots section describes the snapshot relations with the snapshot t= ree. + +The section contains the set of Shot subsections, as shown below: + + ... //Optional subsection + + ... + + + ... + + ... + + +Each Shot section contains the following subsections: + * GUID - an image GUID. + * ParentGUID - GUID of the image of the parent snapshot. + +The software may traverse snapshots from child to parent using +field as reference. ParentGUID of root snapshot is +{00000000-0000-0000-0000-000000000000}. There should be only one one root +snapshot. Top snapshot could be described via two ways: via TopGUID subsec= tion +in the Snapshots section or via predefined GUID +{5fbaabe3-6958-40ff-92a7-860e329aab41} If TopGUID is defined, predefined G= UID is +interpreted as usual GUID. All snapshot images (except Top Snapshot) sould= be +opened read-only. +There is another predefined GIUD, +BackupID =3D {704718e1-2314-44c8-9087-d78ed36b0f4e}, which is used by orig= inal and +some third-party software for backup, QEMU and other software may operate = with +images with GUID =3D BackupID as usual, however, it is not recommended to = use this +GUID for new disks. Top snapshot cannot have this GUID. + +NOTE: To address top snapshot QEMU supports only predefined GUID mode. --=20 2.7.4 From nobody Wed Oct 29 05:57:26 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513595588030722.6045146492827; Mon, 18 Dec 2017 03:13:08 -0800 (PST) Received: from localhost ([::1]:57934 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eQtLq-0005So-8D for importer@patchew.org; Mon, 18 Dec 2017 06:12:54 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57203) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eQtIO-000374-8l for qemu-devel@nongnu.org; Mon, 18 Dec 2017 06:09:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eQtIL-0007Yf-Au for qemu-devel@nongnu.org; Mon, 18 Dec 2017 06:09:20 -0500 Received: from mailhub.sw.ru ([195.214.232.25]:28938 helo=relay.sw.ru) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eQtIK-0007XL-Vf; Mon, 18 Dec 2017 06:09:17 -0500 Received: from iris.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id vBHC7I6v013555; Sun, 17 Dec 2017 15:07:18 +0300 (MSK) From: "Denis V. Lunev" To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Mon, 18 Dec 2017 14:09:08 +0300 Message-Id: <1513595351-5899-3-git-send-email-den@openvz.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513595351-5899-1-git-send-email-den@openvz.org> References: <1513595351-5899-1-git-send-email-den@openvz.org> X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x [fuzzy] X-Received-From: 195.214.232.25 Subject: [Qemu-devel] [PATCH 2/5] configure: add dependency X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Klim Kireev , Edgar Kaziakhmedov , Stefan Hajnoczi , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Klim Kireev This dependency is required for adequate Parallels images support. Typically the disk consists of several images which are glued by XML disk descriptor. Also XML hides inside several important parameters which are not available in the image header. The patch also adds clause to checkpatch.pl to understand libxml2 types. Signed-off-by: Denis V. Lunev Signed-off-by: Klim Kireev Signed-off-by: Edgar Kaziakhmedov CC: Stefan Hajnoczi --- configure | 27 +++++++++++++++++++++++++++ block/Makefile.objs | 2 ++ scripts/checkpatch.pl | 1 + 3 files changed, 30 insertions(+) diff --git a/configure b/configure index 0c6e757..e988fd0 100755 --- a/configure +++ b/configure @@ -422,6 +422,7 @@ tcmalloc=3D"no" jemalloc=3D"no" replication=3D"yes" vxhs=3D"" +libxml2=3D"" =20 supported_cpu=3D"no" supported_os=3D"no" @@ -1275,6 +1276,10 @@ for opt do ;; --enable-numa) numa=3D"yes" ;; + --disable-libxml2) libxml2=3D"no" + ;; + --enable-libxml2) libxml2=3D"yes" + ;; --disable-tcmalloc) tcmalloc=3D"no" ;; --enable-tcmalloc) tcmalloc=3D"yes" @@ -1548,6 +1553,7 @@ disabled with --disable-FEATURE, default is enabled i= f available: tpm TPM support libssh2 ssh block device support numa libnuma support + libxml2 for Parallels image format tcmalloc tcmalloc support jemalloc jemalloc support replication replication support @@ -1592,6 +1598,20 @@ if test "$ARCH" =3D "unknown"; then fi fi =20 +# check for libxml2 +if test "$libxml2" !=3D "no" ; then + if $pkg_config --exists libxml-2.0; then + libxml2=3D"yes" + libxml2_cflags=3D$($pkg_config --cflags libxml-2.0) + libxml2_libs=3D$($pkg_config --libs libxml-2.0) + else + if test "$libxml2" =3D "yes"; then + feature_not_found "libxml2" "Install libxml2 devel" + fi + libxml2=3D"no" + fi +fi + # Consult white-list to determine whether to enable werror # by default. Only enable by default for git builds if test -z "$werror" ; then @@ -5549,6 +5569,7 @@ echo "lzo support $lzo" echo "snappy support $snappy" echo "bzip2 support $bzip2" echo "NUMA host support $numa" +echo "libxml2 $libxml2" echo "tcmalloc support $tcmalloc" echo "jemalloc support $jemalloc" echo "avx2 optimization $avx2_opt" @@ -6208,6 +6229,12 @@ if test "$have_rtnetlink" =3D "yes" ; then echo "CONFIG_RTNETLINK=3Dy" >> $config_host_mak fi =20 +if test "$libxml2" =3D "yes" ; then + echo "CONFIG_LIBXML2=3Dy" >> $config_host_mak + echo "LIBXML2_CFLAGS=3D$libxml2_cflags" >> $config_host_mak + echo "LIBXML2_LIBS=3D$libxml2_libs" >> $config_host_mak +fi + if test "$replication" =3D "yes" ; then echo "CONFIG_REPLICATION=3Dy" >> $config_host_mak fi diff --git a/block/Makefile.objs b/block/Makefile.objs index 6eaf78a..a73387f 100644 --- a/block/Makefile.objs +++ b/block/Makefile.objs @@ -47,3 +47,5 @@ block-obj-$(if $(CONFIG_BZIP2),m,n) +=3D dmg-bz2.o dmg-bz2.o-libs :=3D $(BZIP2_LIBS) qcow.o-libs :=3D -lz linux-aio.o-libs :=3D -laio +parallels.o-cflags :=3D $(LIBXML2_CFLAGS) +parallels.o-libs :=3D $(LIBXML2_LIBS) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 34df753..e76cc85 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -265,6 +265,7 @@ our @typeList =3D ( qr{${Ident}_handler_fn}, qr{target_(?:u)?long}, qr{hwaddr}, + qr{xml${Ident}}, ); =20 # This can be modified by sub possible. Since it can be empty, be careful --=20 2.7.4 From nobody Wed Oct 29 05:57:26 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513595674765676.827966284426; Mon, 18 Dec 2017 03:14:34 -0800 (PST) Received: from localhost ([::1]:57949 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eQtNQ-0006yG-Rh for importer@patchew.org; Mon, 18 Dec 2017 06:14:32 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57257) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eQtIR-000387-Cu for qemu-devel@nongnu.org; Mon, 18 Dec 2017 06:09:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eQtIL-0007Ya-9m for qemu-devel@nongnu.org; Mon, 18 Dec 2017 06:09:23 -0500 Received: from mailhub.sw.ru ([195.214.232.25]:4540 helo=relay.sw.ru) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eQtIK-0007XJ-Qe; Mon, 18 Dec 2017 06:09:17 -0500 Received: from iris.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id vBHC7I6w013555; Sun, 17 Dec 2017 15:07:18 +0300 (MSK) From: "Denis V. Lunev" To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Mon, 18 Dec 2017 14:09:09 +0300 Message-Id: <1513595351-5899-4-git-send-email-den@openvz.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513595351-5899-1-git-send-email-den@openvz.org> References: <1513595351-5899-1-git-send-email-den@openvz.org> X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x [fuzzy] X-Received-From: 195.214.232.25 Subject: [Qemu-devel] [PATCH 3/5] block/parallels: move some structures into header X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Klim Kireev , Stefan Hajnoczi , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Klim Kireev To implement xml format, some defines and structures from parallels.c are required. Signed-off-by: Klim Kireev Reviewed-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Denis V. Lunev CC: Stefan Hajnoczi --- block/parallels.h | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++= ++++ block/parallels.c | 53 +---------------------------------- 2 files changed, 84 insertions(+), 52 deletions(-) create mode 100644 block/parallels.h diff --git a/block/parallels.h b/block/parallels.h new file mode 100644 index 0000000..7d0fb73 --- /dev/null +++ b/block/parallels.h @@ -0,0 +1,83 @@ +/* +* Block driver for Parallels disk image format +* +* Copyright (c) 2016-2017 Klim S. Kireev +* Copyright (c) 2015 Denis V. Lunev +* +* This code was originally based on comparing different disk images created +* by Parallels. Currently it is based on opened OpenVZ sources +* available at +* https://github.com/OpenVZ/ploop +* +* Permission is hereby granted, free of charge, to any person obtaining a = copy +* of this software and associated documentation files (the "Software"), to= deal +* in the Software without restriction, including without limitation the ri= ghts +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included = in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS = OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTH= ER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING = FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ +#ifndef BLOCK_PARALLELS_H +#define BLOCK_PARALLELS_H +#include "qemu/module.h" + +#define DEFAULT_CLUSTER_SIZE 1048576 /* 1 MiB */ + +/* always little-endian */ +typedef struct ParallelsHeader { + char magic[16]; /* "WithoutFreeSpace" */ + uint32_t version; + uint32_t heads; + uint32_t cylinders; + uint32_t tracks; + uint32_t bat_entries; + uint64_t nb_sectors; + uint32_t inuse; + uint32_t data_off; + char padding[12]; +} QEMU_PACKED ParallelsHeader; + +typedef enum ParallelsPreallocMode { + PRL_PREALLOC_MODE_FALLOCATE =3D 0, + PRL_PREALLOC_MODE_TRUNCATE =3D 1, + PRL_PREALLOC_MODE__MAX =3D 2, +} ParallelsPreallocMode; + +typedef struct BDRVParallelsState { + /** Locking is conservative, the lock protects + * - image file extending (truncate, fallocate) + * - any access to block allocation table + */ + CoMutex lock; + + ParallelsHeader *header; + uint32_t header_size; + bool header_unclean; + + unsigned long *bat_dirty_bmap; + unsigned int bat_dirty_block; + + uint32_t *bat_bitmap; + unsigned int bat_size; + + int64_t data_end; + uint64_t prealloc_size; + ParallelsPreallocMode prealloc_mode; + + unsigned int tracks; + + unsigned int off_multiplier; + Error *migration_blocker; +} BDRVParallelsState; + +#endif diff --git a/block/parallels.c b/block/parallels.c index 9545761..f9a3b99 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -36,6 +36,7 @@ #include "qemu/bswap.h" #include "qemu/bitmap.h" #include "migration/blocker.h" +#include "parallels.h" =20 /**************************************************************/ =20 @@ -45,30 +46,6 @@ #define HEADER_INUSE_MAGIC (0x746F6E59) #define MAX_PARALLELS_IMAGE_FACTOR (1ull << 32) =20 -#define DEFAULT_CLUSTER_SIZE 1048576 /* 1 MiB */ - - -// always little-endian -typedef struct ParallelsHeader { - char magic[16]; // "WithoutFreeSpace" - uint32_t version; - uint32_t heads; - uint32_t cylinders; - uint32_t tracks; - uint32_t bat_entries; - uint64_t nb_sectors; - uint32_t inuse; - uint32_t data_off; - char padding[12]; -} QEMU_PACKED ParallelsHeader; - - -typedef enum ParallelsPreallocMode { - PRL_PREALLOC_MODE_FALLOCATE =3D 0, - PRL_PREALLOC_MODE_TRUNCATE =3D 1, - PRL_PREALLOC_MODE__MAX =3D 2, -} ParallelsPreallocMode; - static QEnumLookup prealloc_mode_lookup =3D { .array =3D (const char *const[]) { "falloc", @@ -77,34 +54,6 @@ static QEnumLookup prealloc_mode_lookup =3D { .size =3D PRL_PREALLOC_MODE__MAX }; =20 -typedef struct BDRVParallelsState { - /** Locking is conservative, the lock protects - * - image file extending (truncate, fallocate) - * - any access to block allocation table - */ - CoMutex lock; - - ParallelsHeader *header; - uint32_t header_size; - bool header_unclean; - - unsigned long *bat_dirty_bmap; - unsigned int bat_dirty_block; - - uint32_t *bat_bitmap; - unsigned int bat_size; - - int64_t data_end; - uint64_t prealloc_size; - ParallelsPreallocMode prealloc_mode; - - unsigned int tracks; - - unsigned int off_multiplier; - Error *migration_blocker; -} BDRVParallelsState; - - #define PARALLELS_OPT_PREALLOC_MODE "prealloc-mode" #define PARALLELS_OPT_PREALLOC_SIZE "prealloc-size" =20 --=20 2.7.4 From nobody Wed Oct 29 05:57:26 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513595580088359.6958147010472; Mon, 18 Dec 2017 03:13:00 -0800 (PST) Received: from localhost ([::1]:57935 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eQtLs-0005Ta-1h for importer@patchew.org; Mon, 18 Dec 2017 06:12:56 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57240) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eQtIQ-00037V-M7 for qemu-devel@nongnu.org; Mon, 18 Dec 2017 06:09:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eQtIK-0007YR-Uz for qemu-devel@nongnu.org; Mon, 18 Dec 2017 06:09:22 -0500 Received: from mailhub.sw.ru ([195.214.232.25]:12205 helo=relay.sw.ru) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eQtIK-0007XI-Jg; Mon, 18 Dec 2017 06:09:16 -0500 Received: from iris.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id vBHC7I6x013555; Sun, 17 Dec 2017 15:07:19 +0300 (MSK) From: "Denis V. Lunev" To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Mon, 18 Dec 2017 14:09:10 +0300 Message-Id: <1513595351-5899-5-git-send-email-den@openvz.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513595351-5899-1-git-send-email-den@openvz.org> References: <1513595351-5899-1-git-send-email-den@openvz.org> X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x [fuzzy] X-Received-From: 195.214.232.25 Subject: [Qemu-devel] [PATCH 4/5] block/parallels: replace some magic numbers X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Klim Kireev , Stefan Hajnoczi , "Denis V . Lunev" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Klim Kireev Signed-off-by: Klim Kireev Reviewed-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Denis V. Lunev CC: Stefan Hajnoczi Reviewed-by: Stefan Hajnoczi --- block/parallels.h | 2 ++ block/parallels.c | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/block/parallels.h b/block/parallels.h index 7d0fb73..9be29fe 100644 --- a/block/parallels.h +++ b/block/parallels.h @@ -31,6 +31,8 @@ #define BLOCK_PARALLELS_H #include "qemu/module.h" =20 +#define HEADS_NUMBER 16 +#define SEC_IN_CYL 32 #define DEFAULT_CLUSTER_SIZE 1048576 /* 1 MiB */ =20 /* always little-endian */ diff --git a/block/parallels.c b/block/parallels.c index f9a3b99..7a8e8b0 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -476,8 +476,9 @@ static int parallels_create(const char *filename, QemuO= pts *opts, Error **errp) memcpy(header.magic, HEADER_MAGIC2, sizeof(header.magic)); header.version =3D cpu_to_le32(HEADER_VERSION); /* don't care much about geometry, it is not used on image level */ - header.heads =3D cpu_to_le32(16); - header.cylinders =3D cpu_to_le32(total_size / BDRV_SECTOR_SIZE / 16 / = 32); + header.heads =3D cpu_to_le32(HEADS_NUMBER); + header.cylinders =3D cpu_to_le32(total_size / BDRV_SECTOR_SIZE + / HEADS_NUMBER / SEC_IN_CYL); header.tracks =3D cpu_to_le32(cl_size >> BDRV_SECTOR_BITS); header.bat_entries =3D cpu_to_le32(bat_entries); header.nb_sectors =3D cpu_to_le64(DIV_ROUND_UP(total_size, BDRV_SECTOR= _SIZE)); --=20 2.7.4 From nobody Wed Oct 29 05:57:26 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513595448719690.9769815694868; Mon, 18 Dec 2017 03:10:48 -0800 (PST) Received: from localhost ([::1]:57924 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eQtJi-0003pb-Mr for importer@patchew.org; Mon, 18 Dec 2017 06:10:42 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57205) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eQtIO-000375-9F for qemu-devel@nongnu.org; Mon, 18 Dec 2017 06:09:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eQtIL-0007Yl-Fc for qemu-devel@nongnu.org; Mon, 18 Dec 2017 06:09:20 -0500 Received: from mailhub.sw.ru ([195.214.232.25]:32542 helo=relay.sw.ru) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eQtIL-0007XK-4Y; Mon, 18 Dec 2017 06:09:17 -0500 Received: from iris.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id vBHC7I70013555; Sun, 17 Dec 2017 15:07:19 +0300 (MSK) From: "Denis V. Lunev" To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Mon, 18 Dec 2017 14:09:11 +0300 Message-Id: <1513595351-5899-6-git-send-email-den@openvz.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513595351-5899-1-git-send-email-den@openvz.org> References: <1513595351-5899-1-git-send-email-den@openvz.org> X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x [fuzzy] X-Received-From: 195.214.232.25 Subject: [Qemu-devel] [PATCH 5/5] block/parallels: add backing support to readv/writev X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Denis V . Lunev" , Vladimir Sementsov-Ogievskiy , Edgar Kaziakhmedov , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Edgar Kaziakhmedov Since parallels format supports backing files, refine readv/writev (allocate_clusters) to redirect read/write requests to a backing file (if cluster is not available in the current bs). Signed-off-by: Edgar Kaziakhmedov Signed-off-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Denis V. Lunev CC: Stefan Hajnoczi Reviewed-by: Stefan Hajnoczi --- block/parallels.c | 50 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index 7a8e8b0..d380208 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -142,6 +142,7 @@ static int64_t block_status(BDRVParallelsState *s, int6= 4_t sector_num, static int64_t allocate_clusters(BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum) { + int ret; BDRVParallelsState *s =3D bs->opaque; int64_t pos, space, idx, to_allocate, i, len; =20 @@ -170,7 +171,6 @@ static int64_t allocate_clusters(BlockDriverState *bs, = int64_t sector_num, return len; } if (s->data_end + space > (len >> BDRV_SECTOR_BITS)) { - int ret; space +=3D s->prealloc_size; if (s->prealloc_mode =3D=3D PRL_PREALLOC_MODE_FALLOCATE) { ret =3D bdrv_pwrite_zeroes(bs->file, @@ -186,6 +186,37 @@ static int64_t allocate_clusters(BlockDriverState *bs,= int64_t sector_num, } } =20 + /* Try to read from backing to fill empty clusters + * FIXME: 1. previous write_zeroes may be redundant + * 2. most of data we read from backing will be rewritten by + * parallels_co_writev. On aligned-to-cluster write we do no= t need + * this read at all. + * 3. it would be good to combine write of data from backing an= d new + * data into one write call */ + if (bs->backing) { + int64_t nb_cow_sectors =3D to_allocate * s->tracks; + int64_t nb_cow_bytes =3D nb_cow_sectors << BDRV_SECTOR_BITS; + QEMUIOVector qiov; + struct iovec iov =3D { + .iov_len =3D nb_cow_bytes, + .iov_base =3D qemu_blockalign(bs, nb_cow_bytes) + }; + qemu_iovec_init_external(&qiov, &iov, 1); + + ret =3D bdrv_co_readv(bs->backing, idx * s->tracks, nb_cow_sectors, + &qiov); + if (ret < 0) { + qemu_vfree(iov.iov_base); + return ret; + } + + ret =3D bdrv_co_writev(bs->file, s->data_end, nb_cow_sectors, &qio= v); + qemu_vfree(iov.iov_base); + if (ret < 0) { + return ret; + } + } + for (i =3D 0; i < to_allocate; i++) { s->bat_bitmap[idx + i] =3D cpu_to_le32(s->data_end / s->off_multip= lier); s->data_end +=3D s->tracks; @@ -309,12 +340,19 @@ static coroutine_fn int parallels_co_readv(BlockDrive= rState *bs, =20 nbytes =3D n << BDRV_SECTOR_BITS; =20 + qemu_iovec_reset(&hd_qiov); + qemu_iovec_concat(&hd_qiov, qiov, bytes_done, nbytes); + if (position < 0) { - qemu_iovec_memset(qiov, bytes_done, 0, nbytes); + if (bs->backing) { + ret =3D bdrv_co_readv(bs->backing, sector_num, n, &hd_qiov= ); + if (ret < 0) { + break; + } + } else { + qemu_iovec_memset(&hd_qiov, 0, 0, nbytes); + } } else { - qemu_iovec_reset(&hd_qiov); - qemu_iovec_concat(&hd_qiov, qiov, bytes_done, nbytes); - ret =3D bdrv_co_readv(bs->file, position, n, &hd_qiov); if (ret < 0) { break; @@ -748,7 +786,7 @@ static BlockDriver bdrv_parallels =3D { .bdrv_co_flush_to_os =3D parallels_co_flush_to_os, .bdrv_co_readv =3D parallels_co_readv, .bdrv_co_writev =3D parallels_co_writev, - + .supports_backing =3D true, .bdrv_create =3D parallels_create, .bdrv_check =3D parallels_check, .create_opts =3D ¶llels_create_opts, --=20 2.7.4