2009-05-28 16:07:04 +02:00
|
|
|
/*
|
|
|
|
* Block driver for the QCOW version 2 format
|
|
|
|
*
|
|
|
|
* Copyright (c) 2004-2006 Fabrice Bellard
|
|
|
|
*
|
|
|
|
* 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 rights
|
|
|
|
* 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 OTHER
|
|
|
|
* 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_QCOW2_H
|
|
|
|
#define BLOCK_QCOW2_H
|
|
|
|
|
2017-06-23 18:24:10 +02:00
|
|
|
#include "crypto/block.h"
|
2015-09-01 15:48:02 +02:00
|
|
|
#include "qemu/coroutine.h"
|
2018-09-26 18:04:41 +02:00
|
|
|
#include "qemu/units.h"
|
2019-05-06 16:27:34 +02:00
|
|
|
#include "block/block_int.h"
|
2009-05-28 16:07:04 +02:00
|
|
|
|
2009-06-24 02:17:30 +02:00
|
|
|
//#define DEBUG_ALLOC
|
|
|
|
//#define DEBUG_ALLOC2
|
|
|
|
//#define DEBUG_EXT
|
|
|
|
|
2009-05-28 16:07:04 +02:00
|
|
|
#define QCOW_MAGIC (('Q' << 24) | ('F' << 16) | ('I' << 8) | 0xfb)
|
|
|
|
|
|
|
|
#define QCOW_CRYPT_NONE 0
|
|
|
|
#define QCOW_CRYPT_AES 1
|
qcow2: add support for LUKS encryption format
This adds support for using LUKS as an encryption format
with the qcow2 file, using the new encrypt.format parameter
to request "luks" format. e.g.
# qemu-img create --object secret,data=123456,id=sec0 \
-f qcow2 -o encrypt.format=luks,encrypt.key-secret=sec0 \
test.qcow2 10G
The legacy "encryption=on" parameter still results in
creation of the old qcow2 AES format (and is equivalent
to the new 'encryption-format=aes'). e.g. the following are
equivalent:
# qemu-img create --object secret,data=123456,id=sec0 \
-f qcow2 -o encryption=on,encrypt.key-secret=sec0 \
test.qcow2 10G
# qemu-img create --object secret,data=123456,id=sec0 \
-f qcow2 -o encryption-format=aes,encrypt.key-secret=sec0 \
test.qcow2 10G
With the LUKS format it is necessary to store the LUKS
partition header and key material in the QCow2 file. This
data can be many MB in size, so cannot go into the QCow2
header region directly. Thus the spec defines a FDE
(Full Disk Encryption) header extension that specifies
the offset of a set of clusters to hold the FDE headers,
as well as the length of that region. The LUKS header is
thus stored in these extra allocated clusters before the
main image payload.
Aside from all the cryptographic differences implied by
use of the LUKS format, there is one further key difference
between the use of legacy AES and LUKS encryption in qcow2.
For LUKS, the initialiazation vectors are generated using
the host physical sector as the input, rather than the
guest virtual sector. This guarantees unique initialization
vectors for all sectors when qcow2 internal snapshots are
used, thus giving stronger protection against watermarking
attacks.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Message-id: 20170623162419.26068-14-berrange@redhat.com
Reviewed-by: Alberto Garcia <berto@igalia.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2017-06-23 18:24:12 +02:00
|
|
|
#define QCOW_CRYPT_LUKS 2
|
2009-05-28 16:07:04 +02:00
|
|
|
|
|
|
|
#define QCOW_MAX_CRYPT_CLUSTERS 32
|
2014-03-26 13:05:45 +01:00
|
|
|
#define QCOW_MAX_SNAPSHOTS 65536
|
2009-05-28 16:07:04 +02:00
|
|
|
|
2018-11-14 00:03:18 +01:00
|
|
|
/* Field widths in qcow2 mean normal cluster offsets cannot reach
|
|
|
|
* 64PB; depending on cluster size, compressed clusters can have a
|
|
|
|
* smaller limit (64PB for up to 16k clusters, then ramps down to
|
|
|
|
* 512TB for 2M clusters). */
|
|
|
|
#define QCOW_MAX_CLUSTER_OFFSET ((1ULL << 56) - 1)
|
|
|
|
|
2014-03-26 13:05:50 +01:00
|
|
|
/* 8 MB refcount table is enough for 2 PB images at 64k cluster size
|
|
|
|
* (128 GB for 512 byte clusters, 2 EB for 2 MB clusters) */
|
2019-01-11 20:14:01 +01:00
|
|
|
#define QCOW_MAX_REFTABLE_SIZE (8 * MiB)
|
2014-03-26 13:05:50 +01:00
|
|
|
|
2014-03-26 13:06:06 +01:00
|
|
|
/* 32 MB L1 table is enough for 2 PB images at 64k cluster size
|
|
|
|
* (128 GB for 512 byte clusters, 2 EB for 2 MB clusters) */
|
2019-01-11 20:14:01 +01:00
|
|
|
#define QCOW_MAX_L1_SIZE (32 * MiB)
|
2014-03-26 13:06:06 +01:00
|
|
|
|
2014-03-26 13:06:07 +01:00
|
|
|
/* Allow for an average of 1k per snapshot table entry, should be plenty of
|
|
|
|
* space for snapshot names and IDs */
|
|
|
|
#define QCOW_MAX_SNAPSHOTS_SIZE (1024 * QCOW_MAX_SNAPSHOTS)
|
|
|
|
|
2019-10-11 17:28:02 +02:00
|
|
|
/* Maximum amount of extra data per snapshot table entry to accept */
|
|
|
|
#define QCOW_MAX_SNAPSHOT_EXTRA_DATA 1024
|
|
|
|
|
2017-06-28 14:05:08 +02:00
|
|
|
/* Bitmap header extension constraints */
|
|
|
|
#define QCOW2_MAX_BITMAPS 65535
|
|
|
|
#define QCOW2_MAX_BITMAP_DIRECTORY_SIZE (1024 * QCOW2_MAX_BITMAPS)
|
|
|
|
|
2019-09-16 19:53:24 +02:00
|
|
|
/* Maximum of parallel sub-request per guest request */
|
|
|
|
#define QCOW2_MAX_WORKERS 8
|
|
|
|
|
2009-05-28 16:07:04 +02:00
|
|
|
/* indicate that the refcount of the referenced cluster is exactly one. */
|
2013-08-23 18:35:45 +02:00
|
|
|
#define QCOW_OFLAG_COPIED (1ULL << 63)
|
2009-05-28 16:07:04 +02:00
|
|
|
/* indicate that the cluster is compressed (they never have the copied flag) */
|
2013-08-23 18:35:45 +02:00
|
|
|
#define QCOW_OFLAG_COMPRESSED (1ULL << 62)
|
2012-03-16 15:02:38 +01:00
|
|
|
/* The cluster reads as all zeros */
|
2013-08-23 18:35:45 +02:00
|
|
|
#define QCOW_OFLAG_ZERO (1ULL << 0)
|
2009-05-28 16:07:04 +02:00
|
|
|
|
2020-07-10 18:12:51 +02:00
|
|
|
#define QCOW_EXTL2_SUBCLUSTERS_PER_CLUSTER 32
|
|
|
|
|
2020-07-10 18:12:56 +02:00
|
|
|
/* The subcluster X [0..31] is allocated */
|
|
|
|
#define QCOW_OFLAG_SUB_ALLOC(X) (1ULL << (X))
|
|
|
|
/* The subcluster X [0..31] reads as zeroes */
|
|
|
|
#define QCOW_OFLAG_SUB_ZERO(X) (QCOW_OFLAG_SUB_ALLOC(X) << 32)
|
|
|
|
/* Subclusters [X, Y) (0 <= X <= Y <= 32) are allocated */
|
|
|
|
#define QCOW_OFLAG_SUB_ALLOC_RANGE(X, Y) \
|
|
|
|
(QCOW_OFLAG_SUB_ALLOC(Y) - QCOW_OFLAG_SUB_ALLOC(X))
|
|
|
|
/* Subclusters [X, Y) (0 <= X <= Y <= 32) read as zeroes */
|
|
|
|
#define QCOW_OFLAG_SUB_ZERO_RANGE(X, Y) \
|
|
|
|
(QCOW_OFLAG_SUB_ALLOC_RANGE(X, Y) << 32)
|
|
|
|
/* L2 entry bitmap with all allocation bits set */
|
|
|
|
#define QCOW_L2_BITMAP_ALL_ALLOC (QCOW_OFLAG_SUB_ALLOC_RANGE(0, 32))
|
|
|
|
/* L2 entry bitmap with all "read as zeroes" bits set */
|
|
|
|
#define QCOW_L2_BITMAP_ALL_ZEROES (QCOW_OFLAG_SUB_ZERO_RANGE(0, 32))
|
|
|
|
|
2020-07-10 18:12:54 +02:00
|
|
|
/* Size of normal and extended L2 entries */
|
|
|
|
#define L2E_SIZE_NORMAL (sizeof(uint64_t))
|
|
|
|
#define L2E_SIZE_EXTENDED (sizeof(uint64_t) * 2)
|
|
|
|
|
2020-08-28 13:08:28 +02:00
|
|
|
/* Size of L1 table entries */
|
|
|
|
#define L1E_SIZE (sizeof(uint64_t))
|
|
|
|
|
|
|
|
/* Size of reftable entries */
|
|
|
|
#define REFTABLE_ENTRY_SIZE (sizeof(uint64_t))
|
|
|
|
|
2009-05-28 16:07:04 +02:00
|
|
|
#define MIN_CLUSTER_BITS 9
|
2009-09-15 12:30:43 +02:00
|
|
|
#define MAX_CLUSTER_BITS 21
|
2009-05-28 16:07:04 +02:00
|
|
|
|
2019-05-10 18:22:54 +02:00
|
|
|
/* Defined in the qcow2 spec (compressed cluster descriptor) */
|
|
|
|
#define QCOW2_COMPRESSED_SECTOR_SIZE 512U
|
|
|
|
|
2015-06-01 18:09:17 +02:00
|
|
|
/* Must be at least 2 to cover COW */
|
2018-02-05 15:33:36 +01:00
|
|
|
#define MIN_L2_CACHE_SIZE 2 /* cache entries */
|
2009-05-28 16:07:04 +02:00
|
|
|
|
2011-01-10 17:17:28 +01:00
|
|
|
/* Must be at least 4 to cover all cases of refcount table growth */
|
2014-08-18 22:07:31 +02:00
|
|
|
#define MIN_REFCOUNT_CACHE_SIZE 4 /* clusters */
|
|
|
|
|
2018-09-26 18:04:44 +02:00
|
|
|
#ifdef CONFIG_LINUX
|
2019-01-11 20:14:01 +01:00
|
|
|
#define DEFAULT_L2_CACHE_MAX_SIZE (32 * MiB)
|
2018-09-26 18:04:46 +02:00
|
|
|
#define DEFAULT_CACHE_CLEAN_INTERVAL 600 /* seconds */
|
2018-09-26 18:04:44 +02:00
|
|
|
#else
|
2019-01-11 20:14:01 +01:00
|
|
|
#define DEFAULT_L2_CACHE_MAX_SIZE (8 * MiB)
|
2018-09-26 18:04:46 +02:00
|
|
|
/* Cache clean interval is currently available only on Linux, so must be 0 */
|
|
|
|
#define DEFAULT_CACHE_CLEAN_INTERVAL 0
|
2018-09-26 18:04:44 +02:00
|
|
|
#endif
|
2014-08-18 22:07:31 +02:00
|
|
|
|
2019-01-11 20:14:01 +01:00
|
|
|
#define DEFAULT_CLUSTER_SIZE 65536
|
2011-05-31 15:01:46 +02:00
|
|
|
|
2019-01-29 17:13:57 +01:00
|
|
|
#define QCOW2_OPT_DATA_FILE "data-file"
|
2013-07-17 14:45:34 +02:00
|
|
|
#define QCOW2_OPT_LAZY_REFCOUNTS "lazy-refcounts"
|
|
|
|
#define QCOW2_OPT_DISCARD_REQUEST "pass-discard-request"
|
|
|
|
#define QCOW2_OPT_DISCARD_SNAPSHOT "pass-discard-snapshot"
|
|
|
|
#define QCOW2_OPT_DISCARD_OTHER "pass-discard-other"
|
qcow2: add discard-no-unref option
When we for example have a sparse qcow2 image and discard: unmap is enabled,
there can be a lot of fragmentation in the image after some time. Especially on VM's
that do a lot of writes/deletes.
This causes the qcow2 image to grow even over 110% of its virtual size,
because the free gaps in the image get too small to allocate new
continuous clusters. So it allocates new space at the end of the image.
Disabling discard is not an option, as discard is needed to keep the
incremental backup size as low as possible. Without discard, the
incremental backups would become large, as qemu thinks it's just dirty
blocks but it doesn't know the blocks are unneeded.
So we need to avoid fragmentation but also 'empty' the unneeded blocks in
the image to have a small incremental backup.
In addition, we also want to send the discards further down the stack, so
the underlying blocks are still discarded.
Therefor we introduce a new qcow2 option "discard-no-unref".
When setting this option to true, discards will no longer have the qcow2
driver relinquish cluster allocations. Other than that, the request is
handled as normal: All clusters in range are marked as zero, and, if
pass-discard-request is true, it is passed further down the stack.
The only difference is that the now-zero clusters are preallocated
instead of being unallocated.
This will avoid fragmentation on the qcow2 image.
Fixes: https://gitlab.com/qemu-project/qemu/-/issues/1621
Signed-off-by: Jean-Louis Dupond <jean-louis@dupond.be>
Message-Id: <20230605084523.34134-2-jean-louis@dupond.be>
Reviewed-by: Hanna Czenczek <hreitz@redhat.com>
Signed-off-by: Hanna Czenczek <hreitz@redhat.com>
2023-06-05 10:45:24 +02:00
|
|
|
#define QCOW2_OPT_DISCARD_NO_UNREF "discard-no-unref"
|
2013-10-10 11:09:25 +02:00
|
|
|
#define QCOW2_OPT_OVERLAP "overlap-check"
|
2014-08-20 19:59:35 +02:00
|
|
|
#define QCOW2_OPT_OVERLAP_TEMPLATE "overlap-check.template"
|
2013-10-10 11:09:25 +02:00
|
|
|
#define QCOW2_OPT_OVERLAP_MAIN_HEADER "overlap-check.main-header"
|
|
|
|
#define QCOW2_OPT_OVERLAP_ACTIVE_L1 "overlap-check.active-l1"
|
|
|
|
#define QCOW2_OPT_OVERLAP_ACTIVE_L2 "overlap-check.active-l2"
|
|
|
|
#define QCOW2_OPT_OVERLAP_REFCOUNT_TABLE "overlap-check.refcount-table"
|
|
|
|
#define QCOW2_OPT_OVERLAP_REFCOUNT_BLOCK "overlap-check.refcount-block"
|
|
|
|
#define QCOW2_OPT_OVERLAP_SNAPSHOT_TABLE "overlap-check.snapshot-table"
|
|
|
|
#define QCOW2_OPT_OVERLAP_INACTIVE_L1 "overlap-check.inactive-l1"
|
|
|
|
#define QCOW2_OPT_OVERLAP_INACTIVE_L2 "overlap-check.inactive-l2"
|
2018-07-05 17:15:15 +02:00
|
|
|
#define QCOW2_OPT_OVERLAP_BITMAP_DIRECTORY "overlap-check.bitmap-directory"
|
2014-08-18 22:07:33 +02:00
|
|
|
#define QCOW2_OPT_CACHE_SIZE "cache-size"
|
|
|
|
#define QCOW2_OPT_L2_CACHE_SIZE "l2-cache-size"
|
2018-02-05 15:33:36 +01:00
|
|
|
#define QCOW2_OPT_L2_CACHE_ENTRY_SIZE "l2-cache-entry-size"
|
2014-08-18 22:07:33 +02:00
|
|
|
#define QCOW2_OPT_REFCOUNT_CACHE_SIZE "refcount-cache-size"
|
2015-08-04 14:14:40 +02:00
|
|
|
#define QCOW2_OPT_CACHE_CLEAN_INTERVAL "cache-clean-interval"
|
2013-03-18 13:08:10 +01:00
|
|
|
|
2009-05-28 16:07:04 +02:00
|
|
|
typedef struct QCowHeader {
|
|
|
|
uint32_t magic;
|
|
|
|
uint32_t version;
|
|
|
|
uint64_t backing_file_offset;
|
|
|
|
uint32_t backing_file_size;
|
|
|
|
uint32_t cluster_bits;
|
|
|
|
uint64_t size; /* in bytes */
|
|
|
|
uint32_t crypt_method;
|
|
|
|
uint32_t l1_size; /* XXX: save number of clusters instead ? */
|
|
|
|
uint64_t l1_table_offset;
|
|
|
|
uint64_t refcount_table_offset;
|
|
|
|
uint32_t refcount_table_clusters;
|
|
|
|
uint32_t nb_snapshots;
|
|
|
|
uint64_t snapshots_offset;
|
2011-12-15 12:20:58 +01:00
|
|
|
|
|
|
|
/* The following fields are only valid for version >= 3 */
|
|
|
|
uint64_t incompatible_features;
|
|
|
|
uint64_t compatible_features;
|
|
|
|
uint64_t autoclear_features;
|
|
|
|
|
|
|
|
uint32_t refcount_order;
|
|
|
|
uint32_t header_length;
|
qcow2: introduce compression type feature
The patch adds some preparation parts for incompatible compression type
feature to qcow2 allowing the use different compression methods for
image clusters (de)compressing.
It is implied that the compression type is set on the image creation and
can be changed only later by image conversion, thus compression type
defines the only compression algorithm used for the image, and thus,
for all image clusters.
The goal of the feature is to add support of other compression methods
to qcow2. For example, ZSTD which is more effective on compression than ZLIB.
The default compression is ZLIB. Images created with ZLIB compression type
are backward compatible with older qemu versions.
Adding of the compression type breaks a number of tests because now the
compression type is reported on image creation and there are some changes
in the qcow2 header in size and offsets.
The tests are fixed in the following ways:
* filter out compression_type for many tests
* fix header size, feature table size and backing file offset
affected tests: 031, 036, 061, 080
header_size +=8: 1 byte compression type
7 bytes padding
feature_table += 48: incompatible feature compression type
backing_file_offset += 56 (8 + 48 -> header_change + feature_table_change)
* add "compression type" for test output matching when it isn't filtered
affected tests: 049, 060, 061, 065, 082, 085, 144, 182, 185, 198, 206,
242, 255, 274, 280
Signed-off-by: Denis Plotnikov <dplotnikov@virtuozzo.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
QAPI part:
Acked-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20200507082521.29210-2-dplotnikov@virtuozzo.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2020-05-07 10:25:18 +02:00
|
|
|
|
|
|
|
/* Additional fields */
|
|
|
|
uint8_t compression_type;
|
|
|
|
|
|
|
|
/* header must be a multiple of 8 */
|
|
|
|
uint8_t padding[7];
|
2013-09-25 18:08:50 +02:00
|
|
|
} QEMU_PACKED QCowHeader;
|
2009-05-28 16:07:04 +02:00
|
|
|
|
qcow2: introduce compression type feature
The patch adds some preparation parts for incompatible compression type
feature to qcow2 allowing the use different compression methods for
image clusters (de)compressing.
It is implied that the compression type is set on the image creation and
can be changed only later by image conversion, thus compression type
defines the only compression algorithm used for the image, and thus,
for all image clusters.
The goal of the feature is to add support of other compression methods
to qcow2. For example, ZSTD which is more effective on compression than ZLIB.
The default compression is ZLIB. Images created with ZLIB compression type
are backward compatible with older qemu versions.
Adding of the compression type breaks a number of tests because now the
compression type is reported on image creation and there are some changes
in the qcow2 header in size and offsets.
The tests are fixed in the following ways:
* filter out compression_type for many tests
* fix header size, feature table size and backing file offset
affected tests: 031, 036, 061, 080
header_size +=8: 1 byte compression type
7 bytes padding
feature_table += 48: incompatible feature compression type
backing_file_offset += 56 (8 + 48 -> header_change + feature_table_change)
* add "compression type" for test output matching when it isn't filtered
affected tests: 049, 060, 061, 065, 082, 085, 144, 182, 185, 198, 206,
242, 255, 274, 280
Signed-off-by: Denis Plotnikov <dplotnikov@virtuozzo.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
QAPI part:
Acked-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20200507082521.29210-2-dplotnikov@virtuozzo.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2020-05-07 10:25:18 +02:00
|
|
|
QEMU_BUILD_BUG_ON(!QEMU_IS_ALIGNED(sizeof(QCowHeader), 8));
|
|
|
|
|
2014-03-26 13:05:45 +01:00
|
|
|
typedef struct QEMU_PACKED QCowSnapshotHeader {
|
|
|
|
/* header is 8 byte aligned */
|
|
|
|
uint64_t l1_table_offset;
|
|
|
|
|
|
|
|
uint32_t l1_size;
|
|
|
|
uint16_t id_str_size;
|
|
|
|
uint16_t name_size;
|
|
|
|
|
|
|
|
uint32_t date_sec;
|
|
|
|
uint32_t date_nsec;
|
|
|
|
|
|
|
|
uint64_t vm_clock_nsec;
|
|
|
|
|
|
|
|
uint32_t vm_state_size;
|
|
|
|
uint32_t extra_data_size; /* for extension */
|
|
|
|
/* extra data follows */
|
|
|
|
/* id_str follows */
|
|
|
|
/* name follows */
|
|
|
|
} QCowSnapshotHeader;
|
|
|
|
|
|
|
|
typedef struct QEMU_PACKED QCowSnapshotExtraData {
|
|
|
|
uint64_t vm_state_size_large;
|
|
|
|
uint64_t disk_size;
|
2020-10-03 19:13:02 +02:00
|
|
|
uint64_t icount;
|
2014-03-26 13:05:45 +01:00
|
|
|
} QCowSnapshotExtraData;
|
|
|
|
|
|
|
|
|
2009-05-28 16:07:04 +02:00
|
|
|
typedef struct QCowSnapshot {
|
|
|
|
uint64_t l1_table_offset;
|
|
|
|
uint32_t l1_size;
|
|
|
|
char *id_str;
|
|
|
|
char *name;
|
2012-04-11 16:33:50 +02:00
|
|
|
uint64_t disk_size;
|
2011-11-16 11:35:54 +01:00
|
|
|
uint64_t vm_state_size;
|
2009-05-28 16:07:04 +02:00
|
|
|
uint32_t date_sec;
|
|
|
|
uint32_t date_nsec;
|
|
|
|
uint64_t vm_clock_nsec;
|
2020-10-03 19:13:02 +02:00
|
|
|
/* icount value for the moment when snapshot was taken */
|
|
|
|
uint64_t icount;
|
2019-10-11 17:28:02 +02:00
|
|
|
/* Size of all extra data, including QCowSnapshotExtraData if available */
|
|
|
|
uint32_t extra_data_size;
|
|
|
|
/* Data beyond QCowSnapshotExtraData, if any */
|
|
|
|
void *unknown_extra_data;
|
2009-05-28 16:07:04 +02:00
|
|
|
} QCowSnapshot;
|
|
|
|
|
2011-01-10 17:15:10 +01:00
|
|
|
struct Qcow2Cache;
|
|
|
|
typedef struct Qcow2Cache Qcow2Cache;
|
|
|
|
|
qcow2: add support for LUKS encryption format
This adds support for using LUKS as an encryption format
with the qcow2 file, using the new encrypt.format parameter
to request "luks" format. e.g.
# qemu-img create --object secret,data=123456,id=sec0 \
-f qcow2 -o encrypt.format=luks,encrypt.key-secret=sec0 \
test.qcow2 10G
The legacy "encryption=on" parameter still results in
creation of the old qcow2 AES format (and is equivalent
to the new 'encryption-format=aes'). e.g. the following are
equivalent:
# qemu-img create --object secret,data=123456,id=sec0 \
-f qcow2 -o encryption=on,encrypt.key-secret=sec0 \
test.qcow2 10G
# qemu-img create --object secret,data=123456,id=sec0 \
-f qcow2 -o encryption-format=aes,encrypt.key-secret=sec0 \
test.qcow2 10G
With the LUKS format it is necessary to store the LUKS
partition header and key material in the QCow2 file. This
data can be many MB in size, so cannot go into the QCow2
header region directly. Thus the spec defines a FDE
(Full Disk Encryption) header extension that specifies
the offset of a set of clusters to hold the FDE headers,
as well as the length of that region. The LUKS header is
thus stored in these extra allocated clusters before the
main image payload.
Aside from all the cryptographic differences implied by
use of the LUKS format, there is one further key difference
between the use of legacy AES and LUKS encryption in qcow2.
For LUKS, the initialiazation vectors are generated using
the host physical sector as the input, rather than the
guest virtual sector. This guarantees unique initialization
vectors for all sectors when qcow2 internal snapshots are
used, thus giving stronger protection against watermarking
attacks.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Message-id: 20170623162419.26068-14-berrange@redhat.com
Reviewed-by: Alberto Garcia <berto@igalia.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2017-06-23 18:24:12 +02:00
|
|
|
typedef struct Qcow2CryptoHeaderExtension {
|
|
|
|
uint64_t offset;
|
|
|
|
uint64_t length;
|
|
|
|
} QEMU_PACKED Qcow2CryptoHeaderExtension;
|
|
|
|
|
2012-02-02 14:52:08 +01:00
|
|
|
typedef struct Qcow2UnknownHeaderExtension {
|
|
|
|
uint32_t magic;
|
|
|
|
uint32_t len;
|
|
|
|
QLIST_ENTRY(Qcow2UnknownHeaderExtension) next;
|
|
|
|
uint8_t data[];
|
|
|
|
} Qcow2UnknownHeaderExtension;
|
|
|
|
|
2012-04-12 15:20:27 +02:00
|
|
|
enum {
|
|
|
|
QCOW2_FEAT_TYPE_INCOMPATIBLE = 0,
|
|
|
|
QCOW2_FEAT_TYPE_COMPATIBLE = 1,
|
|
|
|
QCOW2_FEAT_TYPE_AUTOCLEAR = 2,
|
|
|
|
};
|
|
|
|
|
2012-07-27 10:05:19 +02:00
|
|
|
/* Incompatible feature bits */
|
|
|
|
enum {
|
2019-01-14 16:48:25 +01:00
|
|
|
QCOW2_INCOMPAT_DIRTY_BITNR = 0,
|
|
|
|
QCOW2_INCOMPAT_CORRUPT_BITNR = 1,
|
|
|
|
QCOW2_INCOMPAT_DATA_FILE_BITNR = 2,
|
qcow2: introduce compression type feature
The patch adds some preparation parts for incompatible compression type
feature to qcow2 allowing the use different compression methods for
image clusters (de)compressing.
It is implied that the compression type is set on the image creation and
can be changed only later by image conversion, thus compression type
defines the only compression algorithm used for the image, and thus,
for all image clusters.
The goal of the feature is to add support of other compression methods
to qcow2. For example, ZSTD which is more effective on compression than ZLIB.
The default compression is ZLIB. Images created with ZLIB compression type
are backward compatible with older qemu versions.
Adding of the compression type breaks a number of tests because now the
compression type is reported on image creation and there are some changes
in the qcow2 header in size and offsets.
The tests are fixed in the following ways:
* filter out compression_type for many tests
* fix header size, feature table size and backing file offset
affected tests: 031, 036, 061, 080
header_size +=8: 1 byte compression type
7 bytes padding
feature_table += 48: incompatible feature compression type
backing_file_offset += 56 (8 + 48 -> header_change + feature_table_change)
* add "compression type" for test output matching when it isn't filtered
affected tests: 049, 060, 061, 065, 082, 085, 144, 182, 185, 198, 206,
242, 255, 274, 280
Signed-off-by: Denis Plotnikov <dplotnikov@virtuozzo.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
QAPI part:
Acked-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20200507082521.29210-2-dplotnikov@virtuozzo.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2020-05-07 10:25:18 +02:00
|
|
|
QCOW2_INCOMPAT_COMPRESSION_BITNR = 3,
|
2020-07-10 18:13:13 +02:00
|
|
|
QCOW2_INCOMPAT_EXTL2_BITNR = 4,
|
2019-01-14 16:48:25 +01:00
|
|
|
QCOW2_INCOMPAT_DIRTY = 1 << QCOW2_INCOMPAT_DIRTY_BITNR,
|
|
|
|
QCOW2_INCOMPAT_CORRUPT = 1 << QCOW2_INCOMPAT_CORRUPT_BITNR,
|
|
|
|
QCOW2_INCOMPAT_DATA_FILE = 1 << QCOW2_INCOMPAT_DATA_FILE_BITNR,
|
qcow2: introduce compression type feature
The patch adds some preparation parts for incompatible compression type
feature to qcow2 allowing the use different compression methods for
image clusters (de)compressing.
It is implied that the compression type is set on the image creation and
can be changed only later by image conversion, thus compression type
defines the only compression algorithm used for the image, and thus,
for all image clusters.
The goal of the feature is to add support of other compression methods
to qcow2. For example, ZSTD which is more effective on compression than ZLIB.
The default compression is ZLIB. Images created with ZLIB compression type
are backward compatible with older qemu versions.
Adding of the compression type breaks a number of tests because now the
compression type is reported on image creation and there are some changes
in the qcow2 header in size and offsets.
The tests are fixed in the following ways:
* filter out compression_type for many tests
* fix header size, feature table size and backing file offset
affected tests: 031, 036, 061, 080
header_size +=8: 1 byte compression type
7 bytes padding
feature_table += 48: incompatible feature compression type
backing_file_offset += 56 (8 + 48 -> header_change + feature_table_change)
* add "compression type" for test output matching when it isn't filtered
affected tests: 049, 060, 061, 065, 082, 085, 144, 182, 185, 198, 206,
242, 255, 274, 280
Signed-off-by: Denis Plotnikov <dplotnikov@virtuozzo.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
QAPI part:
Acked-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20200507082521.29210-2-dplotnikov@virtuozzo.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2020-05-07 10:25:18 +02:00
|
|
|
QCOW2_INCOMPAT_COMPRESSION = 1 << QCOW2_INCOMPAT_COMPRESSION_BITNR,
|
2020-07-10 18:13:13 +02:00
|
|
|
QCOW2_INCOMPAT_EXTL2 = 1 << QCOW2_INCOMPAT_EXTL2_BITNR,
|
2019-01-14 16:48:25 +01:00
|
|
|
|
|
|
|
QCOW2_INCOMPAT_MASK = QCOW2_INCOMPAT_DIRTY
|
2019-01-29 17:13:57 +01:00
|
|
|
| QCOW2_INCOMPAT_CORRUPT
|
qcow2: introduce compression type feature
The patch adds some preparation parts for incompatible compression type
feature to qcow2 allowing the use different compression methods for
image clusters (de)compressing.
It is implied that the compression type is set on the image creation and
can be changed only later by image conversion, thus compression type
defines the only compression algorithm used for the image, and thus,
for all image clusters.
The goal of the feature is to add support of other compression methods
to qcow2. For example, ZSTD which is more effective on compression than ZLIB.
The default compression is ZLIB. Images created with ZLIB compression type
are backward compatible with older qemu versions.
Adding of the compression type breaks a number of tests because now the
compression type is reported on image creation and there are some changes
in the qcow2 header in size and offsets.
The tests are fixed in the following ways:
* filter out compression_type for many tests
* fix header size, feature table size and backing file offset
affected tests: 031, 036, 061, 080
header_size +=8: 1 byte compression type
7 bytes padding
feature_table += 48: incompatible feature compression type
backing_file_offset += 56 (8 + 48 -> header_change + feature_table_change)
* add "compression type" for test output matching when it isn't filtered
affected tests: 049, 060, 061, 065, 082, 085, 144, 182, 185, 198, 206,
242, 255, 274, 280
Signed-off-by: Denis Plotnikov <dplotnikov@virtuozzo.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
QAPI part:
Acked-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20200507082521.29210-2-dplotnikov@virtuozzo.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2020-05-07 10:25:18 +02:00
|
|
|
| QCOW2_INCOMPAT_DATA_FILE
|
2020-07-10 18:13:13 +02:00
|
|
|
| QCOW2_INCOMPAT_COMPRESSION
|
|
|
|
| QCOW2_INCOMPAT_EXTL2,
|
2012-07-27 10:05:19 +02:00
|
|
|
};
|
|
|
|
|
2012-07-27 10:05:22 +02:00
|
|
|
/* Compatible feature bits */
|
|
|
|
enum {
|
|
|
|
QCOW2_COMPAT_LAZY_REFCOUNTS_BITNR = 0,
|
|
|
|
QCOW2_COMPAT_LAZY_REFCOUNTS = 1 << QCOW2_COMPAT_LAZY_REFCOUNTS_BITNR,
|
|
|
|
|
|
|
|
QCOW2_COMPAT_FEAT_MASK = QCOW2_COMPAT_LAZY_REFCOUNTS,
|
|
|
|
};
|
|
|
|
|
2017-06-28 14:05:08 +02:00
|
|
|
/* Autoclear feature bits */
|
|
|
|
enum {
|
2019-01-14 16:48:25 +01:00
|
|
|
QCOW2_AUTOCLEAR_BITMAPS_BITNR = 0,
|
|
|
|
QCOW2_AUTOCLEAR_DATA_FILE_RAW_BITNR = 1,
|
|
|
|
QCOW2_AUTOCLEAR_BITMAPS = 1 << QCOW2_AUTOCLEAR_BITMAPS_BITNR,
|
|
|
|
QCOW2_AUTOCLEAR_DATA_FILE_RAW = 1 << QCOW2_AUTOCLEAR_DATA_FILE_RAW_BITNR,
|
2017-06-28 14:05:08 +02:00
|
|
|
|
2019-02-22 14:29:38 +01:00
|
|
|
QCOW2_AUTOCLEAR_MASK = QCOW2_AUTOCLEAR_BITMAPS
|
|
|
|
| QCOW2_AUTOCLEAR_DATA_FILE_RAW,
|
2017-06-28 14:05:08 +02:00
|
|
|
};
|
|
|
|
|
2013-06-19 13:44:18 +02:00
|
|
|
enum qcow2_discard_type {
|
|
|
|
QCOW2_DISCARD_NEVER = 0,
|
|
|
|
QCOW2_DISCARD_ALWAYS,
|
|
|
|
QCOW2_DISCARD_REQUEST,
|
|
|
|
QCOW2_DISCARD_SNAPSHOT,
|
|
|
|
QCOW2_DISCARD_OTHER,
|
|
|
|
QCOW2_DISCARD_MAX
|
|
|
|
};
|
|
|
|
|
2012-04-12 15:20:27 +02:00
|
|
|
typedef struct Qcow2Feature {
|
|
|
|
uint8_t type;
|
|
|
|
uint8_t bit;
|
|
|
|
char name[46];
|
|
|
|
} QEMU_PACKED Qcow2Feature;
|
|
|
|
|
2013-06-19 13:44:20 +02:00
|
|
|
typedef struct Qcow2DiscardRegion {
|
|
|
|
BlockDriverState *bs;
|
|
|
|
uint64_t offset;
|
|
|
|
uint64_t bytes;
|
|
|
|
QTAILQ_ENTRY(Qcow2DiscardRegion) next;
|
|
|
|
} Qcow2DiscardRegion;
|
|
|
|
|
2015-02-10 21:28:50 +01:00
|
|
|
typedef uint64_t Qcow2GetRefcountFunc(const void *refcount_array,
|
|
|
|
uint64_t index);
|
|
|
|
typedef void Qcow2SetRefcountFunc(void *refcount_array,
|
|
|
|
uint64_t index, uint64_t value);
|
|
|
|
|
2017-06-28 14:05:08 +02:00
|
|
|
typedef struct Qcow2BitmapHeaderExt {
|
|
|
|
uint32_t nb_bitmaps;
|
|
|
|
uint32_t reserved32;
|
|
|
|
uint64_t bitmap_directory_size;
|
|
|
|
uint64_t bitmap_directory_offset;
|
|
|
|
} QEMU_PACKED Qcow2BitmapHeaderExt;
|
|
|
|
|
2019-05-06 16:27:41 +02:00
|
|
|
#define QCOW2_MAX_THREADS 4
|
|
|
|
|
2015-09-07 17:12:56 +02:00
|
|
|
typedef struct BDRVQcow2State {
|
2009-05-28 16:07:04 +02:00
|
|
|
int cluster_bits;
|
|
|
|
int cluster_size;
|
2018-02-05 15:33:13 +01:00
|
|
|
int l2_slice_size;
|
2020-07-10 18:12:51 +02:00
|
|
|
int subcluster_bits;
|
|
|
|
int subcluster_size;
|
|
|
|
int subclusters_per_cluster;
|
2009-05-28 16:07:04 +02:00
|
|
|
int l2_bits;
|
|
|
|
int l2_size;
|
|
|
|
int l1_size;
|
|
|
|
int l1_vm_state_index;
|
2014-10-22 14:09:28 +02:00
|
|
|
int refcount_block_bits;
|
|
|
|
int refcount_block_size;
|
2009-05-28 16:07:04 +02:00
|
|
|
int csize_shift;
|
|
|
|
int csize_mask;
|
|
|
|
uint64_t cluster_offset_mask;
|
|
|
|
uint64_t l1_table_offset;
|
|
|
|
uint64_t *l1_table;
|
2011-01-10 17:17:28 +01:00
|
|
|
|
2020-10-30 04:35:12 +01:00
|
|
|
Qcow2Cache *l2_table_cache;
|
|
|
|
Qcow2Cache *refcount_block_cache;
|
2015-08-04 14:14:40 +02:00
|
|
|
QEMUTimer *cache_clean_timer;
|
|
|
|
unsigned cache_clean_interval;
|
2011-01-10 17:17:28 +01:00
|
|
|
|
2018-12-06 11:58:10 +01:00
|
|
|
QLIST_HEAD(, QCowL2Meta) cluster_allocs;
|
2009-05-28 16:07:04 +02:00
|
|
|
|
|
|
|
uint64_t *refcount_table;
|
|
|
|
uint64_t refcount_table_offset;
|
|
|
|
uint32_t refcount_table_size;
|
2017-02-01 13:38:28 +01:00
|
|
|
uint32_t max_refcount_table_index; /* Last used entry in refcount_table */
|
2014-03-26 13:05:51 +01:00
|
|
|
uint64_t free_cluster_index;
|
|
|
|
uint64_t free_byte_offset;
|
2009-05-28 16:07:04 +02:00
|
|
|
|
2011-06-30 17:42:09 +02:00
|
|
|
CoMutex lock;
|
|
|
|
|
qcow2: add support for LUKS encryption format
This adds support for using LUKS as an encryption format
with the qcow2 file, using the new encrypt.format parameter
to request "luks" format. e.g.
# qemu-img create --object secret,data=123456,id=sec0 \
-f qcow2 -o encrypt.format=luks,encrypt.key-secret=sec0 \
test.qcow2 10G
The legacy "encryption=on" parameter still results in
creation of the old qcow2 AES format (and is equivalent
to the new 'encryption-format=aes'). e.g. the following are
equivalent:
# qemu-img create --object secret,data=123456,id=sec0 \
-f qcow2 -o encryption=on,encrypt.key-secret=sec0 \
test.qcow2 10G
# qemu-img create --object secret,data=123456,id=sec0 \
-f qcow2 -o encryption-format=aes,encrypt.key-secret=sec0 \
test.qcow2 10G
With the LUKS format it is necessary to store the LUKS
partition header and key material in the QCow2 file. This
data can be many MB in size, so cannot go into the QCow2
header region directly. Thus the spec defines a FDE
(Full Disk Encryption) header extension that specifies
the offset of a set of clusters to hold the FDE headers,
as well as the length of that region. The LUKS header is
thus stored in these extra allocated clusters before the
main image payload.
Aside from all the cryptographic differences implied by
use of the LUKS format, there is one further key difference
between the use of legacy AES and LUKS encryption in qcow2.
For LUKS, the initialiazation vectors are generated using
the host physical sector as the input, rather than the
guest virtual sector. This guarantees unique initialization
vectors for all sectors when qcow2 internal snapshots are
used, thus giving stronger protection against watermarking
attacks.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Message-id: 20170623162419.26068-14-berrange@redhat.com
Reviewed-by: Alberto Garcia <berto@igalia.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2017-06-23 18:24:12 +02:00
|
|
|
Qcow2CryptoHeaderExtension crypto_header; /* QCow2 header extension */
|
2017-06-23 18:24:10 +02:00
|
|
|
QCryptoBlockOpenOptions *crypto_opts; /* Disk encryption runtime options */
|
|
|
|
QCryptoBlock *crypto; /* Disk encryption format driver */
|
qcow2: add support for LUKS encryption format
This adds support for using LUKS as an encryption format
with the qcow2 file, using the new encrypt.format parameter
to request "luks" format. e.g.
# qemu-img create --object secret,data=123456,id=sec0 \
-f qcow2 -o encrypt.format=luks,encrypt.key-secret=sec0 \
test.qcow2 10G
The legacy "encryption=on" parameter still results in
creation of the old qcow2 AES format (and is equivalent
to the new 'encryption-format=aes'). e.g. the following are
equivalent:
# qemu-img create --object secret,data=123456,id=sec0 \
-f qcow2 -o encryption=on,encrypt.key-secret=sec0 \
test.qcow2 10G
# qemu-img create --object secret,data=123456,id=sec0 \
-f qcow2 -o encryption-format=aes,encrypt.key-secret=sec0 \
test.qcow2 10G
With the LUKS format it is necessary to store the LUKS
partition header and key material in the QCow2 file. This
data can be many MB in size, so cannot go into the QCow2
header region directly. Thus the spec defines a FDE
(Full Disk Encryption) header extension that specifies
the offset of a set of clusters to hold the FDE headers,
as well as the length of that region. The LUKS header is
thus stored in these extra allocated clusters before the
main image payload.
Aside from all the cryptographic differences implied by
use of the LUKS format, there is one further key difference
between the use of legacy AES and LUKS encryption in qcow2.
For LUKS, the initialiazation vectors are generated using
the host physical sector as the input, rather than the
guest virtual sector. This guarantees unique initialization
vectors for all sectors when qcow2 internal snapshots are
used, thus giving stronger protection against watermarking
attacks.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Message-id: 20170623162419.26068-14-berrange@redhat.com
Reviewed-by: Alberto Garcia <berto@igalia.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2017-06-23 18:24:12 +02:00
|
|
|
bool crypt_physical_offset; /* Whether to use virtual or physical offset
|
|
|
|
for encryption initialization vector tweak */
|
2009-05-28 16:07:04 +02:00
|
|
|
uint32_t crypt_method_header;
|
|
|
|
uint64_t snapshots_offset;
|
|
|
|
int snapshots_size;
|
2014-03-26 13:05:45 +01:00
|
|
|
unsigned int nb_snapshots;
|
2009-05-28 16:07:04 +02:00
|
|
|
QCowSnapshot *snapshots;
|
2011-11-14 22:09:46 +01:00
|
|
|
|
2017-06-28 14:05:08 +02:00
|
|
|
uint32_t nb_bitmaps;
|
|
|
|
uint64_t bitmap_directory_size;
|
|
|
|
uint64_t bitmap_directory_offset;
|
|
|
|
|
2011-11-14 22:09:46 +01:00
|
|
|
int flags;
|
2011-12-15 12:20:58 +01:00
|
|
|
int qcow_version;
|
2013-03-15 10:35:08 +01:00
|
|
|
bool use_lazy_refcounts;
|
2013-09-03 10:09:53 +02:00
|
|
|
int refcount_order;
|
2015-02-10 21:28:43 +01:00
|
|
|
int refcount_bits;
|
|
|
|
uint64_t refcount_max;
|
2011-12-15 12:20:58 +01:00
|
|
|
|
2015-02-10 21:28:50 +01:00
|
|
|
Qcow2GetRefcountFunc *get_refcount;
|
|
|
|
Qcow2SetRefcountFunc *set_refcount;
|
|
|
|
|
2013-06-19 13:44:19 +02:00
|
|
|
bool discard_passthrough[QCOW2_DISCARD_MAX];
|
|
|
|
|
qcow2: add discard-no-unref option
When we for example have a sparse qcow2 image and discard: unmap is enabled,
there can be a lot of fragmentation in the image after some time. Especially on VM's
that do a lot of writes/deletes.
This causes the qcow2 image to grow even over 110% of its virtual size,
because the free gaps in the image get too small to allocate new
continuous clusters. So it allocates new space at the end of the image.
Disabling discard is not an option, as discard is needed to keep the
incremental backup size as low as possible. Without discard, the
incremental backups would become large, as qemu thinks it's just dirty
blocks but it doesn't know the blocks are unneeded.
So we need to avoid fragmentation but also 'empty' the unneeded blocks in
the image to have a small incremental backup.
In addition, we also want to send the discards further down the stack, so
the underlying blocks are still discarded.
Therefor we introduce a new qcow2 option "discard-no-unref".
When setting this option to true, discards will no longer have the qcow2
driver relinquish cluster allocations. Other than that, the request is
handled as normal: All clusters in range are marked as zero, and, if
pass-discard-request is true, it is passed further down the stack.
The only difference is that the now-zero clusters are preallocated
instead of being unallocated.
This will avoid fragmentation on the qcow2 image.
Fixes: https://gitlab.com/qemu-project/qemu/-/issues/1621
Signed-off-by: Jean-Louis Dupond <jean-louis@dupond.be>
Message-Id: <20230605084523.34134-2-jean-louis@dupond.be>
Reviewed-by: Hanna Czenczek <hreitz@redhat.com>
Signed-off-by: Hanna Czenczek <hreitz@redhat.com>
2023-06-05 10:45:24 +02:00
|
|
|
bool discard_no_unref;
|
|
|
|
|
2013-10-10 11:09:24 +02:00
|
|
|
int overlap_check; /* bitmask of Qcow2MetadataOverlap values */
|
2014-09-05 16:07:16 +02:00
|
|
|
bool signaled_corruption;
|
2013-10-10 11:09:24 +02:00
|
|
|
|
2011-12-15 12:20:58 +01:00
|
|
|
uint64_t incompatible_features;
|
|
|
|
uint64_t compatible_features;
|
|
|
|
uint64_t autoclear_features;
|
|
|
|
|
|
|
|
size_t unknown_header_fields_size;
|
2020-10-30 04:35:12 +01:00
|
|
|
void *unknown_header_fields;
|
2012-02-02 14:52:08 +01:00
|
|
|
QLIST_HEAD(, Qcow2UnknownHeaderExtension) unknown_header_ext;
|
2013-06-19 13:44:20 +02:00
|
|
|
QTAILQ_HEAD (, Qcow2DiscardRegion) discards;
|
|
|
|
bool cache_discards;
|
2015-04-07 15:03:16 +02:00
|
|
|
|
|
|
|
/* Backing file path and format as stored in the image (this is not the
|
|
|
|
* effective path/format, which may be the result of a runtime option
|
|
|
|
* override) */
|
|
|
|
char *image_backing_file;
|
|
|
|
char *image_backing_format;
|
2019-01-15 19:02:40 +01:00
|
|
|
char *image_data_file;
|
2018-06-20 16:48:37 +02:00
|
|
|
|
2019-05-06 16:27:38 +02:00
|
|
|
CoQueue thread_task_queue;
|
|
|
|
int nb_threads;
|
2019-01-14 16:48:25 +01:00
|
|
|
|
|
|
|
BdrvChild *data_file;
|
block: avoid recursive block_status call if possible
drv_co_block_status digs bs->file for additional, more accurate search
for hole inside region, reported as DATA by bs since 5daa74a6ebc.
This accuracy is not free: assume we have qcow2 disk. Actually, qcow2
knows, where are holes and where is data. But every block_status
request calls lseek additionally. Assume a big disk, full of
data, in any iterative copying block job (or img convert) we'll call
lseek(HOLE) on every iteration, and each of these lseeks will have to
iterate through all metadata up to the end of file. It's obviously
ineffective behavior. And for many scenarios we don't need this lseek
at all.
However, lseek is needed when we have metadata-preallocated image.
So, let's detect metadata-preallocation case and don't dig qcow2's
protocol file in other cases.
The idea is to compare allocation size in POV of filesystem with
allocations size in POV of Qcow2 (by refcounts). If allocation in fs is
significantly lower, consider it as metadata-preallocation case.
102 iotest changed, as our detector can't detect shrinked file as
metadata-preallocation, which don't seem to be wrong, as with metadata
preallocation we always have valid file length.
Two other iotests have a slight change in their QMP output sequence:
Active 'block-commit' returns earlier because the job coroutine yields
earlier on a blocking operation. This operation is loading the refcount
blocks in qcow2_detect_metadata_preallocation().
Suggested-by: Denis V. Lunev <den@openvz.org>
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2019-04-08 18:26:17 +02:00
|
|
|
|
|
|
|
bool metadata_preallocation_checked;
|
|
|
|
bool metadata_preallocation;
|
qcow2: introduce compression type feature
The patch adds some preparation parts for incompatible compression type
feature to qcow2 allowing the use different compression methods for
image clusters (de)compressing.
It is implied that the compression type is set on the image creation and
can be changed only later by image conversion, thus compression type
defines the only compression algorithm used for the image, and thus,
for all image clusters.
The goal of the feature is to add support of other compression methods
to qcow2. For example, ZSTD which is more effective on compression than ZLIB.
The default compression is ZLIB. Images created with ZLIB compression type
are backward compatible with older qemu versions.
Adding of the compression type breaks a number of tests because now the
compression type is reported on image creation and there are some changes
in the qcow2 header in size and offsets.
The tests are fixed in the following ways:
* filter out compression_type for many tests
* fix header size, feature table size and backing file offset
affected tests: 031, 036, 061, 080
header_size +=8: 1 byte compression type
7 bytes padding
feature_table += 48: incompatible feature compression type
backing_file_offset += 56 (8 + 48 -> header_change + feature_table_change)
* add "compression type" for test output matching when it isn't filtered
affected tests: 049, 060, 061, 065, 082, 085, 144, 182, 185, 198, 206,
242, 255, 274, 280
Signed-off-by: Denis Plotnikov <dplotnikov@virtuozzo.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
QAPI part:
Acked-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20200507082521.29210-2-dplotnikov@virtuozzo.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2020-05-07 10:25:18 +02:00
|
|
|
/*
|
|
|
|
* Compression type used for the image. Default: 0 - ZLIB
|
|
|
|
* The image compression type is set on image creation.
|
|
|
|
* For now, the only way to change the compression type
|
|
|
|
* is to convert the image with the desired compression type set.
|
|
|
|
*/
|
|
|
|
Qcow2CompressionType compression_type;
|
2015-09-07 17:12:56 +02:00
|
|
|
} BDRVQcow2State;
|
2009-05-28 16:07:04 +02:00
|
|
|
|
2012-12-07 18:08:43 +01:00
|
|
|
typedef struct Qcow2COWRegion {
|
|
|
|
/**
|
|
|
|
* Offset of the COW region in bytes from the start of the first cluster
|
|
|
|
* touched by the request.
|
|
|
|
*/
|
2017-06-19 15:40:03 +02:00
|
|
|
unsigned offset;
|
2012-12-07 18:08:43 +01:00
|
|
|
|
2016-06-01 14:08:56 +02:00
|
|
|
/** Number of bytes to copy */
|
2017-06-19 15:40:03 +02:00
|
|
|
unsigned nb_bytes;
|
2012-12-07 18:08:43 +01:00
|
|
|
} Qcow2COWRegion;
|
|
|
|
|
2012-12-07 18:08:46 +01:00
|
|
|
/**
|
|
|
|
* Describes an in-flight (part of a) write request that writes to clusters
|
2020-10-07 18:13:23 +02:00
|
|
|
* that need to have their L2 table entries updated (because they are
|
|
|
|
* newly allocated or need changes in their L2 bitmaps)
|
2012-12-07 18:08:46 +01:00
|
|
|
*/
|
2009-05-28 16:07:05 +02:00
|
|
|
typedef struct QCowL2Meta
|
|
|
|
{
|
2020-10-07 18:13:23 +02:00
|
|
|
/** Guest offset of the first updated cluster */
|
2009-05-28 16:07:05 +02:00
|
|
|
uint64_t offset;
|
2012-12-07 18:08:42 +01:00
|
|
|
|
2020-10-07 18:13:23 +02:00
|
|
|
/** Host offset of the first updated cluster */
|
2012-03-02 14:10:54 +01:00
|
|
|
uint64_t alloc_offset;
|
2012-12-07 18:08:42 +01:00
|
|
|
|
2020-10-07 18:13:23 +02:00
|
|
|
/** Number of updated clusters */
|
2009-05-28 16:07:05 +02:00
|
|
|
int nb_clusters;
|
2012-12-07 18:08:42 +01:00
|
|
|
|
2017-05-04 01:11:18 +02:00
|
|
|
/** Do not free the old clusters */
|
|
|
|
bool keep_old_clusters;
|
|
|
|
|
2012-12-07 18:08:42 +01:00
|
|
|
/**
|
|
|
|
* Requests that overlap with this allocation and wait to be restarted
|
|
|
|
* when the allocating request has completed.
|
|
|
|
*/
|
2011-06-30 17:42:09 +02:00
|
|
|
CoQueue dependent_requests;
|
2009-08-31 16:48:49 +02:00
|
|
|
|
2012-12-07 18:08:43 +01:00
|
|
|
/**
|
2020-10-07 18:13:23 +02:00
|
|
|
* The COW Region immediately before the area the guest actually
|
|
|
|
* writes to. This (part of the) write request starts at
|
|
|
|
* cow_start.offset + cow_start.nb_bytes.
|
2012-12-07 18:08:43 +01:00
|
|
|
*/
|
|
|
|
Qcow2COWRegion cow_start;
|
|
|
|
|
|
|
|
/**
|
2020-10-07 18:13:23 +02:00
|
|
|
* The COW Region immediately after the area the guest actually
|
|
|
|
* writes to. This (part of the) write request ends at cow_end.offset
|
|
|
|
* (which must always be set even when cow_end.nb_bytes is 0).
|
2012-12-07 18:08:43 +01:00
|
|
|
*/
|
|
|
|
Qcow2COWRegion cow_end;
|
|
|
|
|
2019-05-16 16:27:49 +02:00
|
|
|
/*
|
|
|
|
* Indicates that COW regions are already handled and do not require
|
|
|
|
* any more processing.
|
|
|
|
*/
|
|
|
|
bool skip_cow;
|
|
|
|
|
2020-07-10 18:13:12 +02:00
|
|
|
/**
|
|
|
|
* Indicates that this is not a normal write request but a preallocation.
|
|
|
|
* If the image has extended L2 entries this means that no new individual
|
|
|
|
* subclusters will be marked as allocated in the L2 bitmap (but any
|
|
|
|
* existing contents of that bitmap will be kept).
|
|
|
|
*/
|
|
|
|
bool prealloc;
|
|
|
|
|
2017-06-19 15:40:08 +02:00
|
|
|
/**
|
|
|
|
* The I/O vector with the data from the actual guest write request.
|
|
|
|
* If non-NULL, this is meant to be merged together with the data
|
|
|
|
* from @cow_start and @cow_end into one single write operation.
|
|
|
|
*/
|
|
|
|
QEMUIOVector *data_qiov;
|
2019-06-04 18:15:14 +02:00
|
|
|
size_t data_qiov_offset;
|
2017-06-19 15:40:08 +02:00
|
|
|
|
2013-03-26 17:50:11 +01:00
|
|
|
/** Pointer to next L2Meta of the same write request */
|
|
|
|
struct QCowL2Meta *next;
|
|
|
|
|
2009-09-12 09:36:22 +02:00
|
|
|
QLIST_ENTRY(QCowL2Meta) next_in_flight;
|
2009-05-28 16:07:05 +02:00
|
|
|
} QCowL2Meta;
|
|
|
|
|
2020-07-10 18:12:56 +02:00
|
|
|
/*
|
|
|
|
* In images with standard L2 entries all clusters are treated as if
|
|
|
|
* they had one subcluster so QCow2ClusterType and QCow2SubclusterType
|
|
|
|
* can be mapped to each other and have the exact same meaning
|
|
|
|
* (QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC cannot happen in these images).
|
|
|
|
*
|
|
|
|
* In images with extended L2 entries QCow2ClusterType refers to the
|
|
|
|
* complete cluster and QCow2SubclusterType to each of the individual
|
|
|
|
* subclusters, so there are several possible combinations:
|
|
|
|
*
|
|
|
|
* |--------------+---------------------------|
|
|
|
|
* | Cluster type | Possible subcluster types |
|
|
|
|
* |--------------+---------------------------|
|
|
|
|
* | UNALLOCATED | UNALLOCATED_PLAIN |
|
|
|
|
* | | ZERO_PLAIN |
|
|
|
|
* |--------------+---------------------------|
|
|
|
|
* | NORMAL | UNALLOCATED_ALLOC |
|
|
|
|
* | | ZERO_ALLOC |
|
|
|
|
* | | NORMAL |
|
|
|
|
* |--------------+---------------------------|
|
|
|
|
* | COMPRESSED | COMPRESSED |
|
|
|
|
* |--------------+---------------------------|
|
|
|
|
*
|
|
|
|
* QCOW2_SUBCLUSTER_INVALID means that the L2 entry is incorrect and
|
|
|
|
* the image should be marked corrupt.
|
|
|
|
*/
|
|
|
|
|
2017-05-07 02:05:45 +02:00
|
|
|
typedef enum QCow2ClusterType {
|
2012-03-14 19:15:03 +01:00
|
|
|
QCOW2_CLUSTER_UNALLOCATED,
|
2017-05-07 02:05:46 +02:00
|
|
|
QCOW2_CLUSTER_ZERO_PLAIN,
|
|
|
|
QCOW2_CLUSTER_ZERO_ALLOC,
|
2012-03-14 19:15:03 +01:00
|
|
|
QCOW2_CLUSTER_NORMAL,
|
|
|
|
QCOW2_CLUSTER_COMPRESSED,
|
2017-05-07 02:05:45 +02:00
|
|
|
} QCow2ClusterType;
|
2012-03-14 19:15:03 +01:00
|
|
|
|
2020-07-10 18:12:56 +02:00
|
|
|
typedef enum QCow2SubclusterType {
|
|
|
|
QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN,
|
|
|
|
QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC,
|
|
|
|
QCOW2_SUBCLUSTER_ZERO_PLAIN,
|
|
|
|
QCOW2_SUBCLUSTER_ZERO_ALLOC,
|
|
|
|
QCOW2_SUBCLUSTER_NORMAL,
|
|
|
|
QCOW2_SUBCLUSTER_COMPRESSED,
|
|
|
|
QCOW2_SUBCLUSTER_INVALID,
|
|
|
|
} QCow2SubclusterType;
|
|
|
|
|
2013-08-30 14:34:25 +02:00
|
|
|
typedef enum QCow2MetadataOverlap {
|
2018-07-05 17:15:15 +02:00
|
|
|
QCOW2_OL_MAIN_HEADER_BITNR = 0,
|
|
|
|
QCOW2_OL_ACTIVE_L1_BITNR = 1,
|
|
|
|
QCOW2_OL_ACTIVE_L2_BITNR = 2,
|
|
|
|
QCOW2_OL_REFCOUNT_TABLE_BITNR = 3,
|
|
|
|
QCOW2_OL_REFCOUNT_BLOCK_BITNR = 4,
|
|
|
|
QCOW2_OL_SNAPSHOT_TABLE_BITNR = 5,
|
|
|
|
QCOW2_OL_INACTIVE_L1_BITNR = 6,
|
|
|
|
QCOW2_OL_INACTIVE_L2_BITNR = 7,
|
|
|
|
QCOW2_OL_BITMAP_DIRECTORY_BITNR = 8,
|
|
|
|
|
|
|
|
QCOW2_OL_MAX_BITNR = 9,
|
|
|
|
|
|
|
|
QCOW2_OL_NONE = 0,
|
|
|
|
QCOW2_OL_MAIN_HEADER = (1 << QCOW2_OL_MAIN_HEADER_BITNR),
|
|
|
|
QCOW2_OL_ACTIVE_L1 = (1 << QCOW2_OL_ACTIVE_L1_BITNR),
|
|
|
|
QCOW2_OL_ACTIVE_L2 = (1 << QCOW2_OL_ACTIVE_L2_BITNR),
|
|
|
|
QCOW2_OL_REFCOUNT_TABLE = (1 << QCOW2_OL_REFCOUNT_TABLE_BITNR),
|
|
|
|
QCOW2_OL_REFCOUNT_BLOCK = (1 << QCOW2_OL_REFCOUNT_BLOCK_BITNR),
|
|
|
|
QCOW2_OL_SNAPSHOT_TABLE = (1 << QCOW2_OL_SNAPSHOT_TABLE_BITNR),
|
|
|
|
QCOW2_OL_INACTIVE_L1 = (1 << QCOW2_OL_INACTIVE_L1_BITNR),
|
2013-08-30 14:34:25 +02:00
|
|
|
/* NOTE: Checking overlaps with inactive L2 tables will result in bdrv
|
|
|
|
* reads. */
|
2018-07-05 17:15:15 +02:00
|
|
|
QCOW2_OL_INACTIVE_L2 = (1 << QCOW2_OL_INACTIVE_L2_BITNR),
|
|
|
|
QCOW2_OL_BITMAP_DIRECTORY = (1 << QCOW2_OL_BITMAP_DIRECTORY_BITNR),
|
2013-08-30 14:34:25 +02:00
|
|
|
} QCow2MetadataOverlap;
|
|
|
|
|
2013-10-10 11:09:27 +02:00
|
|
|
/* Perform all overlap checks which can be done in constant time */
|
|
|
|
#define QCOW2_OL_CONSTANT \
|
|
|
|
(QCOW2_OL_MAIN_HEADER | QCOW2_OL_ACTIVE_L1 | QCOW2_OL_REFCOUNT_TABLE | \
|
2018-07-05 17:15:15 +02:00
|
|
|
QCOW2_OL_SNAPSHOT_TABLE | QCOW2_OL_BITMAP_DIRECTORY)
|
2013-10-10 11:09:27 +02:00
|
|
|
|
2013-08-30 14:34:25 +02:00
|
|
|
/* Perform all overlap checks which don't require disk access */
|
|
|
|
#define QCOW2_OL_CACHED \
|
2013-10-10 11:09:27 +02:00
|
|
|
(QCOW2_OL_CONSTANT | QCOW2_OL_ACTIVE_L2 | QCOW2_OL_REFCOUNT_BLOCK | \
|
|
|
|
QCOW2_OL_INACTIVE_L1)
|
|
|
|
|
|
|
|
/* Perform all overlap checks */
|
|
|
|
#define QCOW2_OL_ALL \
|
|
|
|
(QCOW2_OL_CACHED | QCOW2_OL_INACTIVE_L2)
|
2013-08-30 14:34:25 +02:00
|
|
|
|
2014-01-21 04:30:02 +01:00
|
|
|
#define L1E_OFFSET_MASK 0x00fffffffffffe00ULL
|
2021-09-14 14:24:53 +02:00
|
|
|
#define L1E_RESERVED_MASK 0x7f000000000001ffULL
|
2014-01-21 04:30:02 +01:00
|
|
|
#define L2E_OFFSET_MASK 0x00fffffffffffe00ULL
|
2021-09-14 14:24:51 +02:00
|
|
|
#define L2E_STD_RESERVED_MASK 0x3f000000000001feULL
|
2012-03-14 19:15:03 +01:00
|
|
|
|
2014-01-21 04:30:02 +01:00
|
|
|
#define REFT_OFFSET_MASK 0xfffffffffffffe00ULL
|
2021-09-14 14:24:54 +02:00
|
|
|
#define REFT_RESERVED_MASK 0x1ffULL
|
2012-03-16 14:09:08 +01:00
|
|
|
|
2019-01-18 14:40:36 +01:00
|
|
|
#define INV_OFFSET (-1ULL)
|
|
|
|
|
2020-07-10 18:12:50 +02:00
|
|
|
static inline bool has_subclusters(BDRVQcow2State *s)
|
|
|
|
{
|
2020-07-10 18:13:13 +02:00
|
|
|
return s->incompatible_features & QCOW2_INCOMPAT_EXTL2;
|
2020-07-10 18:12:50 +02:00
|
|
|
}
|
|
|
|
|
2020-07-10 18:12:54 +02:00
|
|
|
static inline size_t l2_entry_size(BDRVQcow2State *s)
|
|
|
|
{
|
|
|
|
return has_subclusters(s) ? L2E_SIZE_EXTENDED : L2E_SIZE_NORMAL;
|
|
|
|
}
|
|
|
|
|
2020-07-10 18:12:48 +02:00
|
|
|
static inline uint64_t get_l2_entry(BDRVQcow2State *s, uint64_t *l2_slice,
|
|
|
|
int idx)
|
|
|
|
{
|
2020-07-10 18:12:55 +02:00
|
|
|
idx *= l2_entry_size(s) / sizeof(uint64_t);
|
2020-07-10 18:12:48 +02:00
|
|
|
return be64_to_cpu(l2_slice[idx]);
|
|
|
|
}
|
|
|
|
|
2020-07-10 18:12:55 +02:00
|
|
|
static inline uint64_t get_l2_bitmap(BDRVQcow2State *s, uint64_t *l2_slice,
|
|
|
|
int idx)
|
|
|
|
{
|
|
|
|
if (has_subclusters(s)) {
|
|
|
|
idx *= l2_entry_size(s) / sizeof(uint64_t);
|
|
|
|
return be64_to_cpu(l2_slice[idx + 1]);
|
|
|
|
} else {
|
|
|
|
return 0; /* For convenience only; this value has no meaning. */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-10 18:12:48 +02:00
|
|
|
static inline void set_l2_entry(BDRVQcow2State *s, uint64_t *l2_slice,
|
|
|
|
int idx, uint64_t entry)
|
|
|
|
{
|
2020-07-10 18:12:55 +02:00
|
|
|
idx *= l2_entry_size(s) / sizeof(uint64_t);
|
2020-07-10 18:12:48 +02:00
|
|
|
l2_slice[idx] = cpu_to_be64(entry);
|
|
|
|
}
|
|
|
|
|
2020-07-10 18:12:55 +02:00
|
|
|
static inline void set_l2_bitmap(BDRVQcow2State *s, uint64_t *l2_slice,
|
|
|
|
int idx, uint64_t bitmap)
|
|
|
|
{
|
|
|
|
assert(has_subclusters(s));
|
|
|
|
idx *= l2_entry_size(s) / sizeof(uint64_t);
|
|
|
|
l2_slice[idx + 1] = cpu_to_be64(bitmap);
|
|
|
|
}
|
|
|
|
|
2019-01-14 16:48:25 +01:00
|
|
|
static inline bool has_data_file(BlockDriverState *bs)
|
|
|
|
{
|
|
|
|
BDRVQcow2State *s = bs->opaque;
|
|
|
|
return (s->data_file != bs->file);
|
|
|
|
}
|
|
|
|
|
2019-02-22 14:29:38 +01:00
|
|
|
static inline bool data_file_is_raw(BlockDriverState *bs)
|
|
|
|
{
|
|
|
|
BDRVQcow2State *s = bs->opaque;
|
|
|
|
return !!(s->autoclear_features & QCOW2_AUTOCLEAR_DATA_FILE_RAW);
|
|
|
|
}
|
|
|
|
|
2015-09-07 17:12:56 +02:00
|
|
|
static inline int64_t start_of_cluster(BDRVQcow2State *s, int64_t offset)
|
2013-03-26 17:50:02 +01:00
|
|
|
{
|
|
|
|
return offset & ~(s->cluster_size - 1);
|
|
|
|
}
|
|
|
|
|
2015-09-07 17:12:56 +02:00
|
|
|
static inline int64_t offset_into_cluster(BDRVQcow2State *s, int64_t offset)
|
2013-03-26 17:50:03 +01:00
|
|
|
{
|
|
|
|
return offset & (s->cluster_size - 1);
|
|
|
|
}
|
|
|
|
|
2020-07-10 18:12:53 +02:00
|
|
|
static inline int64_t offset_into_subcluster(BDRVQcow2State *s, int64_t offset)
|
|
|
|
{
|
|
|
|
return offset & (s->subcluster_size - 1);
|
|
|
|
}
|
|
|
|
|
2015-09-14 16:39:47 +02:00
|
|
|
static inline uint64_t size_to_clusters(BDRVQcow2State *s, uint64_t size)
|
2009-05-28 16:07:04 +02:00
|
|
|
{
|
|
|
|
return (size + (s->cluster_size - 1)) >> s->cluster_bits;
|
|
|
|
}
|
|
|
|
|
2020-07-10 18:12:53 +02:00
|
|
|
static inline uint64_t size_to_subclusters(BDRVQcow2State *s, uint64_t size)
|
|
|
|
{
|
|
|
|
return (size + (s->subcluster_size - 1)) >> s->subcluster_bits;
|
|
|
|
}
|
|
|
|
|
2015-09-07 17:12:56 +02:00
|
|
|
static inline int64_t size_to_l1(BDRVQcow2State *s, int64_t size)
|
2010-04-28 12:36:11 +02:00
|
|
|
{
|
|
|
|
int shift = s->cluster_bits + s->l2_bits;
|
|
|
|
return (size + (1ULL << shift) - 1) >> shift;
|
|
|
|
}
|
|
|
|
|
2018-02-05 15:33:12 +01:00
|
|
|
static inline int offset_to_l1_index(BDRVQcow2State *s, uint64_t offset)
|
|
|
|
{
|
|
|
|
return offset >> (s->l2_bits + s->cluster_bits);
|
|
|
|
}
|
|
|
|
|
2015-09-07 17:12:56 +02:00
|
|
|
static inline int offset_to_l2_index(BDRVQcow2State *s, int64_t offset)
|
2013-03-26 17:49:56 +01:00
|
|
|
{
|
|
|
|
return (offset >> s->cluster_bits) & (s->l2_size - 1);
|
|
|
|
}
|
|
|
|
|
2018-02-05 15:33:14 +01:00
|
|
|
static inline int offset_to_l2_slice_index(BDRVQcow2State *s, int64_t offset)
|
|
|
|
{
|
|
|
|
return (offset >> s->cluster_bits) & (s->l2_slice_size - 1);
|
|
|
|
}
|
|
|
|
|
2020-07-10 18:12:52 +02:00
|
|
|
static inline int offset_to_sc_index(BDRVQcow2State *s, int64_t offset)
|
|
|
|
{
|
|
|
|
return (offset >> s->subcluster_bits) & (s->subclusters_per_cluster - 1);
|
|
|
|
}
|
|
|
|
|
2015-09-07 17:12:56 +02:00
|
|
|
static inline int64_t qcow2_vm_state_offset(BDRVQcow2State *s)
|
2013-09-06 12:20:08 +02:00
|
|
|
{
|
|
|
|
return (int64_t)s->l1_vm_state_index << (s->cluster_bits + s->l2_bits);
|
|
|
|
}
|
|
|
|
|
2019-01-17 18:42:40 +01:00
|
|
|
static inline QCow2ClusterType qcow2_get_cluster_type(BlockDriverState *bs,
|
|
|
|
uint64_t l2_entry)
|
2012-03-14 19:15:03 +01:00
|
|
|
{
|
2020-07-10 18:12:56 +02:00
|
|
|
BDRVQcow2State *s = bs->opaque;
|
|
|
|
|
2012-03-14 19:15:03 +01:00
|
|
|
if (l2_entry & QCOW_OFLAG_COMPRESSED) {
|
|
|
|
return QCOW2_CLUSTER_COMPRESSED;
|
2020-07-10 18:12:56 +02:00
|
|
|
} else if ((l2_entry & QCOW_OFLAG_ZERO) && !has_subclusters(s)) {
|
2017-05-07 02:05:46 +02:00
|
|
|
if (l2_entry & L2E_OFFSET_MASK) {
|
|
|
|
return QCOW2_CLUSTER_ZERO_ALLOC;
|
|
|
|
}
|
|
|
|
return QCOW2_CLUSTER_ZERO_PLAIN;
|
2012-03-14 19:15:03 +01:00
|
|
|
} else if (!(l2_entry & L2E_OFFSET_MASK)) {
|
2019-01-29 13:47:24 +01:00
|
|
|
/* Offset 0 generally means unallocated, but it is ambiguous with
|
|
|
|
* external data files because 0 is a valid offset there. However, all
|
|
|
|
* clusters in external data files always have refcount 1, so we can
|
|
|
|
* rely on QCOW_OFLAG_COPIED to disambiguate. */
|
|
|
|
if (has_data_file(bs) && (l2_entry & QCOW_OFLAG_COPIED)) {
|
|
|
|
return QCOW2_CLUSTER_NORMAL;
|
|
|
|
} else {
|
|
|
|
return QCOW2_CLUSTER_UNALLOCATED;
|
|
|
|
}
|
2012-03-14 19:15:03 +01:00
|
|
|
} else {
|
|
|
|
return QCOW2_CLUSTER_NORMAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-10 18:12:56 +02:00
|
|
|
/*
|
|
|
|
* In an image without subsclusters @l2_bitmap is ignored and
|
|
|
|
* @sc_index must be 0.
|
|
|
|
* Return QCOW2_SUBCLUSTER_INVALID if an invalid l2 entry is detected
|
|
|
|
* (this checks the whole entry and bitmap, not only the bits related
|
|
|
|
* to subcluster @sc_index).
|
|
|
|
*/
|
|
|
|
static inline
|
|
|
|
QCow2SubclusterType qcow2_get_subcluster_type(BlockDriverState *bs,
|
|
|
|
uint64_t l2_entry,
|
|
|
|
uint64_t l2_bitmap,
|
|
|
|
unsigned sc_index)
|
|
|
|
{
|
|
|
|
BDRVQcow2State *s = bs->opaque;
|
|
|
|
QCow2ClusterType type = qcow2_get_cluster_type(bs, l2_entry);
|
|
|
|
assert(sc_index < s->subclusters_per_cluster);
|
|
|
|
|
|
|
|
if (has_subclusters(s)) {
|
|
|
|
switch (type) {
|
|
|
|
case QCOW2_CLUSTER_COMPRESSED:
|
|
|
|
return QCOW2_SUBCLUSTER_COMPRESSED;
|
|
|
|
case QCOW2_CLUSTER_NORMAL:
|
|
|
|
if ((l2_bitmap >> 32) & l2_bitmap) {
|
|
|
|
return QCOW2_SUBCLUSTER_INVALID;
|
|
|
|
} else if (l2_bitmap & QCOW_OFLAG_SUB_ZERO(sc_index)) {
|
|
|
|
return QCOW2_SUBCLUSTER_ZERO_ALLOC;
|
|
|
|
} else if (l2_bitmap & QCOW_OFLAG_SUB_ALLOC(sc_index)) {
|
|
|
|
return QCOW2_SUBCLUSTER_NORMAL;
|
|
|
|
} else {
|
|
|
|
return QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC;
|
|
|
|
}
|
|
|
|
case QCOW2_CLUSTER_UNALLOCATED:
|
|
|
|
if (l2_bitmap & QCOW_L2_BITMAP_ALL_ALLOC) {
|
|
|
|
return QCOW2_SUBCLUSTER_INVALID;
|
|
|
|
} else if (l2_bitmap & QCOW_OFLAG_SUB_ZERO(sc_index)) {
|
|
|
|
return QCOW2_SUBCLUSTER_ZERO_PLAIN;
|
|
|
|
} else {
|
|
|
|
return QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
}
|
|
|
|
} else {
|
2020-07-10 18:13:03 +02:00
|
|
|
switch (type) {
|
|
|
|
case QCOW2_CLUSTER_COMPRESSED:
|
|
|
|
return QCOW2_SUBCLUSTER_COMPRESSED;
|
|
|
|
case QCOW2_CLUSTER_ZERO_PLAIN:
|
|
|
|
return QCOW2_SUBCLUSTER_ZERO_PLAIN;
|
|
|
|
case QCOW2_CLUSTER_ZERO_ALLOC:
|
|
|
|
return QCOW2_SUBCLUSTER_ZERO_ALLOC;
|
|
|
|
case QCOW2_CLUSTER_NORMAL:
|
|
|
|
return QCOW2_SUBCLUSTER_NORMAL;
|
|
|
|
case QCOW2_CLUSTER_UNALLOCATED:
|
|
|
|
return QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
}
|
2020-07-10 18:12:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-10 18:12:58 +02:00
|
|
|
static inline bool qcow2_cluster_is_allocated(QCow2ClusterType type)
|
|
|
|
{
|
|
|
|
return (type == QCOW2_CLUSTER_COMPRESSED || type == QCOW2_CLUSTER_NORMAL ||
|
|
|
|
type == QCOW2_CLUSTER_ZERO_ALLOC);
|
|
|
|
}
|
|
|
|
|
2012-07-27 10:05:22 +02:00
|
|
|
/* Check whether refcounts are eager or lazy */
|
2015-09-07 17:12:56 +02:00
|
|
|
static inline bool qcow2_need_accurate_refcounts(BDRVQcow2State *s)
|
2012-07-27 10:05:22 +02:00
|
|
|
{
|
|
|
|
return !(s->incompatible_features & QCOW2_INCOMPAT_DIRTY);
|
|
|
|
}
|
2009-05-28 16:07:06 +02:00
|
|
|
|
2013-03-26 17:49:58 +01:00
|
|
|
static inline uint64_t l2meta_cow_start(QCowL2Meta *m)
|
|
|
|
{
|
|
|
|
return m->offset + m->cow_start.offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint64_t l2meta_cow_end(QCowL2Meta *m)
|
|
|
|
{
|
2016-06-01 14:08:56 +02:00
|
|
|
return m->offset + m->cow_end.offset + m->cow_end.nb_bytes;
|
2013-03-26 17:49:58 +01:00
|
|
|
}
|
|
|
|
|
2015-02-10 21:28:48 +01:00
|
|
|
static inline uint64_t refcount_diff(uint64_t r1, uint64_t r2)
|
2015-02-10 21:28:47 +01:00
|
|
|
{
|
|
|
|
return r1 > r2 ? r1 - r2 : r2 - r1;
|
|
|
|
}
|
|
|
|
|
2017-09-18 14:42:29 +02:00
|
|
|
static inline
|
|
|
|
uint32_t offset_to_reftable_index(BDRVQcow2State *s, uint64_t offset)
|
|
|
|
{
|
|
|
|
return offset >> (s->refcount_block_bits + s->cluster_bits);
|
|
|
|
}
|
|
|
|
|
2009-05-28 16:07:04 +02:00
|
|
|
/* qcow2.c functions */
|
2017-06-13 22:21:03 +02:00
|
|
|
int64_t qcow2_refcount_metadata_size(int64_t clusters, size_t cluster_size,
|
|
|
|
int refcount_order, bool generous_increase,
|
|
|
|
uint64_t *refblock_count);
|
|
|
|
|
2012-12-07 18:08:47 +01:00
|
|
|
int qcow2_mark_dirty(BlockDriverState *bs);
|
2013-08-30 14:34:24 +02:00
|
|
|
int qcow2_mark_corrupt(BlockDriverState *bs);
|
2012-02-02 12:32:31 +01:00
|
|
|
int qcow2_update_header(BlockDriverState *bs);
|
2009-05-28 16:07:04 +02:00
|
|
|
|
2014-09-05 16:07:16 +02:00
|
|
|
void qcow2_signal_corruption(BlockDriverState *bs, bool fatal, int64_t offset,
|
|
|
|
int64_t size, const char *message_format, ...)
|
2022-02-20 17:39:25 +01:00
|
|
|
G_GNUC_PRINTF(5, 6);
|
2014-09-05 16:07:16 +02:00
|
|
|
|
2018-03-06 17:14:06 +01:00
|
|
|
int qcow2_validate_table(BlockDriverState *bs, uint64_t offset,
|
|
|
|
uint64_t entries, size_t entry_len,
|
|
|
|
int64_t max_size_bytes, const char *table_name,
|
|
|
|
Error **errp);
|
|
|
|
|
2009-05-28 16:07:04 +02:00
|
|
|
/* qcow2-refcount.c functions */
|
2023-02-03 16:21:50 +01:00
|
|
|
int coroutine_fn GRAPH_RDLOCK qcow2_refcount_init(BlockDriverState *bs);
|
2009-05-28 16:07:07 +02:00
|
|
|
void qcow2_refcount_close(BlockDriverState *bs);
|
2009-05-28 16:07:04 +02:00
|
|
|
|
2015-02-10 21:28:46 +01:00
|
|
|
int qcow2_get_refcount(BlockDriverState *bs, int64_t cluster_index,
|
2015-02-10 21:28:48 +01:00
|
|
|
uint64_t *refcount);
|
2014-10-27 11:12:54 +01:00
|
|
|
|
2013-09-03 10:09:52 +02:00
|
|
|
int qcow2_update_cluster_refcount(BlockDriverState *bs, int64_t cluster_index,
|
2015-02-10 21:28:48 +01:00
|
|
|
uint64_t addend, bool decrease,
|
2015-02-10 21:28:47 +01:00
|
|
|
enum qcow2_discard_type type);
|
2013-09-03 10:09:52 +02:00
|
|
|
|
2017-06-13 22:21:05 +02:00
|
|
|
int64_t qcow2_refcount_area(BlockDriverState *bs, uint64_t offset,
|
|
|
|
uint64_t additional_clusters, bool exact_size,
|
|
|
|
int new_refblock_index,
|
|
|
|
uint64_t new_refblock_offset);
|
|
|
|
|
2014-03-26 13:05:51 +01:00
|
|
|
int64_t qcow2_alloc_clusters(BlockDriverState *bs, uint64_t size);
|
2023-03-09 09:44:55 +01:00
|
|
|
int64_t coroutine_fn qcow2_alloc_clusters_at(BlockDriverState *bs, uint64_t offset,
|
|
|
|
int64_t nb_clusters);
|
2023-06-01 13:51:43 +02:00
|
|
|
int64_t coroutine_fn GRAPH_RDLOCK qcow2_alloc_bytes(BlockDriverState *bs, int size);
|
2009-05-28 16:07:07 +02:00
|
|
|
void qcow2_free_clusters(BlockDriverState *bs,
|
2013-06-19 13:44:18 +02:00
|
|
|
int64_t offset, int64_t size,
|
|
|
|
enum qcow2_discard_type type);
|
2020-09-08 16:08:28 +02:00
|
|
|
void qcow2_free_any_cluster(BlockDriverState *bs, uint64_t l2_entry,
|
|
|
|
enum qcow2_discard_type type);
|
2009-05-28 16:07:04 +02:00
|
|
|
|
2009-05-28 16:07:07 +02:00
|
|
|
int qcow2_update_snapshot_refcount(BlockDriverState *bs,
|
|
|
|
int64_t l1_table_offset, int l1_size, int addend);
|
2009-05-28 16:07:04 +02:00
|
|
|
|
2022-09-22 10:49:01 +02:00
|
|
|
int qcow2_flush_caches(BlockDriverState *bs);
|
|
|
|
int qcow2_write_caches(BlockDriverState *bs);
|
2023-06-01 13:51:43 +02:00
|
|
|
int coroutine_fn qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
|
|
|
|
BdrvCheckMode fix);
|
2009-05-28 16:07:04 +02:00
|
|
|
|
2013-06-19 13:44:20 +02:00
|
|
|
void qcow2_process_discards(BlockDriverState *bs, int ret);
|
|
|
|
|
2013-10-10 11:09:23 +02:00
|
|
|
int qcow2_check_metadata_overlap(BlockDriverState *bs, int ign, int64_t offset,
|
2013-08-30 14:34:25 +02:00
|
|
|
int64_t size);
|
2013-10-10 11:09:23 +02:00
|
|
|
int qcow2_pre_write_overlap_check(BlockDriverState *bs, int ign, int64_t offset,
|
2019-01-15 20:39:06 +01:00
|
|
|
int64_t size, bool data_file);
|
2023-06-01 13:51:43 +02:00
|
|
|
int coroutine_fn qcow2_inc_refcounts_imrt(BlockDriverState *bs, BdrvCheckResult *res,
|
|
|
|
void **refcount_table,
|
|
|
|
int64_t *refcount_table_size,
|
|
|
|
int64_t offset, int64_t size);
|
2013-08-30 14:34:25 +02:00
|
|
|
|
2015-07-27 17:51:37 +02:00
|
|
|
int qcow2_change_refcount_order(BlockDriverState *bs, int refcount_order,
|
|
|
|
BlockDriverAmendStatusCB *status_cb,
|
|
|
|
void *cb_opaque, Error **errp);
|
2023-02-03 16:21:51 +01:00
|
|
|
int coroutine_fn GRAPH_RDLOCK qcow2_shrink_reftable(BlockDriverState *bs);
|
2023-03-09 09:44:55 +01:00
|
|
|
int64_t coroutine_fn qcow2_get_last_cluster(BlockDriverState *bs, int64_t size);
|
2023-05-04 13:57:31 +02:00
|
|
|
|
|
|
|
int coroutine_fn GRAPH_RDLOCK
|
|
|
|
qcow2_detect_metadata_preallocation(BlockDriverState *bs);
|
2015-07-27 17:51:37 +02:00
|
|
|
|
2009-05-28 16:07:05 +02:00
|
|
|
/* qcow2-cluster.c functions */
|
2013-05-14 16:14:33 +02:00
|
|
|
int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size,
|
|
|
|
bool exact_size);
|
2023-02-03 16:21:46 +01:00
|
|
|
|
|
|
|
int coroutine_fn GRAPH_RDLOCK
|
|
|
|
qcow2_shrink_l1_table(BlockDriverState *bs, uint64_t max_size);
|
|
|
|
|
2013-08-30 14:34:28 +02:00
|
|
|
int qcow2_write_l1_entry(BlockDriverState *bs, int l1_index);
|
2015-09-07 17:12:56 +02:00
|
|
|
int qcow2_encrypt_sectors(BDRVQcow2State *s, int64_t sector_num,
|
2017-06-23 18:24:09 +02:00
|
|
|
uint8_t *buf, int nb_sectors, bool enc, Error **errp);
|
2009-05-28 16:07:05 +02:00
|
|
|
|
2020-07-10 18:12:44 +02:00
|
|
|
int qcow2_get_host_offset(BlockDriverState *bs, uint64_t offset,
|
2020-07-10 18:12:59 +02:00
|
|
|
unsigned int *bytes, uint64_t *host_offset,
|
2020-07-10 18:13:00 +02:00
|
|
|
QCow2SubclusterType *subcluster_type);
|
2022-09-22 10:49:12 +02:00
|
|
|
int coroutine_fn qcow2_alloc_host_offset(BlockDriverState *bs, uint64_t offset,
|
|
|
|
unsigned int *bytes,
|
|
|
|
uint64_t *host_offset, QCowL2Meta **m);
|
2023-06-01 13:51:43 +02:00
|
|
|
int coroutine_fn GRAPH_RDLOCK
|
|
|
|
qcow2_alloc_compressed_cluster_offset(BlockDriverState *bs, uint64_t offset,
|
|
|
|
int compressed_size, uint64_t *host_offset);
|
2021-09-14 14:24:47 +02:00
|
|
|
void qcow2_parse_compressed_l2_entry(BlockDriverState *bs, uint64_t l2_entry,
|
|
|
|
uint64_t *coffset, int *csize);
|
2009-05-28 16:07:05 +02:00
|
|
|
|
2023-02-03 16:21:49 +01:00
|
|
|
int coroutine_fn GRAPH_RDLOCK
|
|
|
|
qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m);
|
|
|
|
|
2023-03-09 09:44:55 +01:00
|
|
|
void coroutine_fn qcow2_alloc_cluster_abort(BlockDriverState *bs, QCowL2Meta *m);
|
qcow2: Discard/zero clusters by byte count
Passing a byte offset, but sector count, when we ultimately
want to operate on cluster granularity, is madness. Clean up
the external interfaces to take both offset and count as bytes,
while still keeping the assertion added previously that the
caller must align the values to a cluster. Then rename things
to make sure backports don't get confused by changed units:
instead of qcow2_discard_clusters() and qcow2_zero_clusters(),
we now have qcow2_cluster_discard() and qcow2_cluster_zeroize().
The internal functions still operate on clusters at a time, and
return an int for number of cleared clusters; but on an image
with 2M clusters, a single L2 table holds 256k entries that each
represent a 2M cluster, totalling well over INT_MAX bytes if we
ever had a request for that many bytes at once. All our callers
currently limit themselves to 32-bit bytes (and therefore fewer
clusters), but by making this function 64-bit clean, we have one
less place to clean up if we later improve the block layer to
support 64-bit bytes through all operations (with the block layer
auto-fragmenting on behalf of more-limited drivers), rather than
the current state where some interfaces are artificially limited
to INT_MAX at a time.
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Message-id: 20170507000552.20847-13-eblake@redhat.com
Signed-off-by: Max Reitz <mreitz@redhat.com>
2017-05-07 02:05:52 +02:00
|
|
|
int qcow2_cluster_discard(BlockDriverState *bs, uint64_t offset,
|
|
|
|
uint64_t bytes, enum qcow2_discard_type type,
|
|
|
|
bool full_discard);
|
2023-02-03 16:21:48 +01:00
|
|
|
|
|
|
|
int coroutine_fn GRAPH_RDLOCK
|
|
|
|
qcow2_subcluster_zeroize(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
|
|
|
|
int flags);
|
2009-05-28 16:07:05 +02:00
|
|
|
|
2014-10-27 11:12:53 +01:00
|
|
|
int qcow2_expand_zero_clusters(BlockDriverState *bs,
|
2015-07-27 17:51:32 +02:00
|
|
|
BlockDriverAmendStatusCB *status_cb,
|
|
|
|
void *cb_opaque);
|
2013-09-03 10:09:52 +02:00
|
|
|
|
2009-05-28 16:07:06 +02:00
|
|
|
/* qcow2-snapshot.c functions */
|
2009-05-28 16:07:07 +02:00
|
|
|
int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info);
|
|
|
|
int qcow2_snapshot_goto(BlockDriverState *bs, const char *snapshot_id);
|
snapshot: distinguish id and name in snapshot delete
Snapshot creation actually already distinguish id and name since it take
a structured parameter *sn, but delete can't. Later an accurate delete
is needed in qmp_transaction abort and blockdev-snapshot-delete-sync,
so change its prototype. Also *errp is added to tip error, but return
value is kepted to let caller check what kind of error happens. Existing
caller for it are savevm, delvm and qemu-img, they are not impacted by
introducing a new function bdrv_snapshot_delete_by_id_or_name(), which
check the return value and do the operation again.
Before this patch:
For qcow2, it search id first then name to find the one to delete.
For rbd, it search name.
For sheepdog, it does nothing.
After this patch:
For qcow2, logic is the same by call it twice in caller.
For rbd, it always fails in delete with id, but still search for name
in second try, no change to user.
Some code for *errp is based on Pavel's patch.
Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2013-09-11 08:04:33 +02:00
|
|
|
int qcow2_snapshot_delete(BlockDriverState *bs,
|
|
|
|
const char *snapshot_id,
|
|
|
|
const char *name,
|
|
|
|
Error **errp);
|
2009-05-28 16:07:07 +02:00
|
|
|
int qcow2_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab);
|
2013-12-04 10:10:54 +01:00
|
|
|
int qcow2_snapshot_load_tmp(BlockDriverState *bs,
|
|
|
|
const char *snapshot_id,
|
|
|
|
const char *name,
|
|
|
|
Error **errp);
|
2009-05-28 16:07:06 +02:00
|
|
|
|
2009-05-28 16:07:07 +02:00
|
|
|
void qcow2_free_snapshots(BlockDriverState *bs);
|
2023-03-09 09:44:55 +01:00
|
|
|
int coroutine_fn GRAPH_RDLOCK
|
|
|
|
qcow2_read_snapshots(BlockDriverState *bs, Error **errp);
|
2019-10-11 17:28:03 +02:00
|
|
|
int qcow2_write_snapshots(BlockDriverState *bs);
|
2009-05-28 16:07:06 +02:00
|
|
|
|
2023-02-03 16:21:50 +01:00
|
|
|
int coroutine_fn GRAPH_RDLOCK
|
|
|
|
qcow2_check_read_snapshot_table(BlockDriverState *bs, BdrvCheckResult *result,
|
|
|
|
BdrvCheckMode fix);
|
|
|
|
|
2019-10-11 17:28:07 +02:00
|
|
|
int coroutine_fn qcow2_check_fix_snapshot_table(BlockDriverState *bs,
|
|
|
|
BdrvCheckResult *result,
|
|
|
|
BdrvCheckMode fix);
|
2019-10-11 17:28:06 +02:00
|
|
|
|
2011-01-10 17:15:10 +01:00
|
|
|
/* qcow2-cache.c functions */
|
2018-02-05 15:33:36 +01:00
|
|
|
Qcow2Cache *qcow2_cache_create(BlockDriverState *bs, int num_tables,
|
|
|
|
unsigned table_size);
|
2018-02-05 15:33:08 +01:00
|
|
|
int qcow2_cache_destroy(Qcow2Cache *c);
|
2011-01-10 17:15:10 +01:00
|
|
|
|
2018-02-05 15:33:06 +01:00
|
|
|
void qcow2_cache_entry_mark_dirty(Qcow2Cache *c, void *table);
|
2011-01-10 17:15:10 +01:00
|
|
|
int qcow2_cache_flush(BlockDriverState *bs, Qcow2Cache *c);
|
2016-06-02 17:58:15 +02:00
|
|
|
int qcow2_cache_write(BlockDriverState *bs, Qcow2Cache *c);
|
2011-01-10 17:15:10 +01:00
|
|
|
int qcow2_cache_set_dependency(BlockDriverState *bs, Qcow2Cache *c,
|
|
|
|
Qcow2Cache *dependency);
|
2011-01-14 15:55:38 +01:00
|
|
|
void qcow2_cache_depends_on_flush(Qcow2Cache *c);
|
2011-01-10 17:15:10 +01:00
|
|
|
|
2018-02-05 15:33:09 +01:00
|
|
|
void qcow2_cache_clean_unused(Qcow2Cache *c);
|
2013-09-03 10:09:51 +02:00
|
|
|
int qcow2_cache_empty(BlockDriverState *bs, Qcow2Cache *c);
|
|
|
|
|
2011-01-10 17:15:10 +01:00
|
|
|
int qcow2_cache_get(BlockDriverState *bs, Qcow2Cache *c, uint64_t offset,
|
|
|
|
void **table);
|
|
|
|
int qcow2_cache_get_empty(BlockDriverState *bs, Qcow2Cache *c, uint64_t offset,
|
|
|
|
void **table);
|
2018-02-05 15:33:07 +01:00
|
|
|
void qcow2_cache_put(Qcow2Cache *c, void **table);
|
2018-02-05 15:33:11 +01:00
|
|
|
void *qcow2_cache_is_table_offset(Qcow2Cache *c, uint64_t offset);
|
2018-02-05 15:33:10 +01:00
|
|
|
void qcow2_cache_discard(Qcow2Cache *c, void *table);
|
2011-01-10 17:15:10 +01:00
|
|
|
|
2017-06-28 14:05:08 +02:00
|
|
|
/* qcow2-bitmap.c functions */
|
2023-06-01 13:51:43 +02:00
|
|
|
int coroutine_fn
|
|
|
|
qcow2_check_bitmaps_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
|
|
|
|
void **refcount_table,
|
|
|
|
int64_t *refcount_table_size);
|
|
|
|
bool coroutine_fn GRAPH_RDLOCK
|
|
|
|
qcow2_load_dirty_bitmaps(BlockDriverState *bs, bool *header_updated, Error **errp);
|
2021-02-02 13:49:50 +01:00
|
|
|
bool qcow2_get_bitmap_info_list(BlockDriverState *bs,
|
|
|
|
Qcow2BitmapInfoList **info_list, Error **errp);
|
2017-06-28 14:05:14 +02:00
|
|
|
int qcow2_reopen_bitmaps_rw(BlockDriverState *bs, Error **errp);
|
2023-03-09 09:44:55 +01:00
|
|
|
int coroutine_fn qcow2_truncate_bitmaps_check(BlockDriverState *bs, Error **errp);
|
2021-02-02 13:49:52 +01:00
|
|
|
bool qcow2_store_persistent_dirty_bitmaps(BlockDriverState *bs,
|
2019-09-27 14:23:52 +02:00
|
|
|
bool release_stored, Error **errp);
|
2017-06-28 14:05:20 +02:00
|
|
|
int qcow2_reopen_bitmaps_ro(BlockDriverState *bs, Error **errp);
|
2022-10-13 14:36:55 +02:00
|
|
|
bool coroutine_fn qcow2_co_can_store_new_dirty_bitmap(BlockDriverState *bs,
|
|
|
|
const char *name,
|
|
|
|
uint32_t granularity,
|
|
|
|
Error **errp);
|
|
|
|
int coroutine_fn qcow2_co_remove_persistent_dirty_bitmap(BlockDriverState *bs,
|
|
|
|
const char *name,
|
|
|
|
Error **errp);
|
block: Make it easier to learn which BDS support bitmaps
Upcoming patches will enhance bitmap support in qemu-img, but in doing
so, it turns out to be nice to suppress output when persistent bitmaps
make no sense (such as on a qcow2 v2 image). Add a hook to make this
easier to query.
This patch adds a new callback .bdrv_supports_persistent_dirty_bitmap,
rather than trying to shoehorn the answer in via existing callbacks.
In particular, while it might have been possible to overload
.bdrv_co_can_store_new_dirty_bitmap to special-case a NULL input to
answer whether any persistent bitmaps are supported, that is at odds
with whether a particular bitmap can be stored (for example, even on
an image that supports persistent bitmaps but has currently filled up
the maximum number of bitmaps, attempts to store another one should
fail); and the new functionality doesn't require coroutine safety.
Similarly, we could have added one more piece of information to
.bdrv_get_info, but then again, most callers to that function tend to
already discard extraneous information, and making it a catch-all
rather than a series of dedicated scalar queries hasn't really
simplified life.
In the future, when we improve the ability to look up bitmaps through
a filter, we will probably also want to teach the block layer to
automatically let filters pass this request on through.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <20200513011648.166876-4-eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
2020-05-13 03:16:42 +02:00
|
|
|
bool qcow2_supports_persistent_dirty_bitmap(BlockDriverState *bs);
|
qcow2: Expose bitmaps' size during measure
It's useful to know how much space can be occupied by qcow2 persistent
bitmaps, even though such metadata is unrelated to the guest-visible
data. Report this value as an additional QMP field, present when
measuring an existing image and output format that both support
bitmaps. Update iotest 178 and 190 to updated output, as well as new
coverage in 190 demonstrating non-zero values made possible with the
recently-added qemu-img bitmap command (see 3b51ab4b).
The new 'bitmaps size:' field is displayed automatically as part of
'qemu-img measure' any time it is present in QMP (that is, any time
both the source image being measured and destination format support
bitmaps, even if the measurement is 0 because there are no bitmaps
present). If the field is absent, it means that no bitmaps can be
copied (source, destination, or both lack bitmaps, including when
measuring based on size rather than on a source image). This behavior
is compatible with an upcoming patch adding 'qemu-img convert
--bitmaps': that command will fail in the same situations where this
patch omits the field.
The addition of a new field demonstrates why we should always
zero-initialize qapi C structs; while the qcow2 driver still fully
populates all fields, the raw and crypto drivers had to be tweaked to
avoid uninitialized data.
Consideration was also given towards having a 'qemu-img measure
--bitmaps' which errors out when bitmaps are not possible, and
otherwise sums the bitmaps into the existing allocation totals rather
than displaying as a separate field, as a potential convenience
factor. But this was ultimately decided to be more complexity than
necessary when the QMP interface was sufficient enough with bitmaps
remaining a separate field.
See also: https://bugzilla.redhat.com/1779904
Reported-by: Nir Soffer <nsoffer@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <20200521192137.1120211-3-eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
2020-05-21 21:21:34 +02:00
|
|
|
uint64_t qcow2_get_persistent_dirty_bitmap_size(BlockDriverState *bs,
|
|
|
|
uint32_t cluster_size);
|
2017-06-28 14:05:11 +02:00
|
|
|
|
2019-05-06 16:27:35 +02:00
|
|
|
ssize_t coroutine_fn
|
|
|
|
qcow2_co_compress(BlockDriverState *bs, void *dest, size_t dest_size,
|
|
|
|
const void *src, size_t src_size);
|
|
|
|
ssize_t coroutine_fn
|
|
|
|
qcow2_co_decompress(BlockDriverState *bs, void *dest, size_t dest_size,
|
|
|
|
const void *src, size_t src_size);
|
2019-05-06 16:27:41 +02:00
|
|
|
int coroutine_fn
|
2019-09-15 22:36:54 +02:00
|
|
|
qcow2_co_encrypt(BlockDriverState *bs, uint64_t host_offset,
|
|
|
|
uint64_t guest_offset, void *buf, size_t len);
|
2019-05-06 16:27:41 +02:00
|
|
|
int coroutine_fn
|
2019-09-15 22:36:54 +02:00
|
|
|
qcow2_co_decrypt(BlockDriverState *bs, uint64_t host_offset,
|
|
|
|
uint64_t guest_offset, void *buf, size_t len);
|
2019-05-06 16:27:35 +02:00
|
|
|
|
2009-05-28 16:07:04 +02:00
|
|
|
#endif
|