qed: Add QEMU Enhanced Disk format
Subsystems (2)
v4 cover qed: Add QEMU Enhanced Disk format
QEMU Enhanced Disk format is a disk image format that forgoes features found in qcow2 in favor of better levels of performance and data integrity. Due to its simpler on-disk layout, it is possible to safely perform metadata updates more efficiently.
Installations, suspend-to-disk, and other allocation-heavy I/O workloads will see increased performance due to fewer I/Os and syncs. Workloads that do not cause new clusters to be allocated will perform similar to raw images due to in-memory metadata caching.
The format supports sparse disk images. It does not rely on the host filesystem holes feature, making it a good choice for sparse disk images that need to be transferred over channels where holes are not supported.
Backing files are supported so only deltas against a base image can be stored. The base image may be smaller than the image file.
The file format is extensible so that additional features can be added later with graceful compatibility handling. A specification for the file format is included in this patchset.
Internal snapshots are not supported. This eliminates the need for additional metadata to track copy-on-write clusters.
Compression and encryption are not supported. They add complexity and can be implemented at other layers in the stack (i.e. inside the guest or on the host). Encryption has been identified as a potential future extension and the file format allows for this.
---
This code is also available from git:
http://repo.or.cz/w/qemu/stefanha.git/shortlog/refs/heads/qed-v4
I have preserved distinct commits against v3 for easier reviewing here:
http://repo.or.cz/w/qemu/stefanha.git/shortlog/refs/heads/qed-v4-presquash
v4:
* Use bdrv_*() instead of POSIX APIs to create an image file
* Lift the non-zero image size restriction
* Fix qed.c/qed.h style comments from Kevin
v3:
* Flush before L2 update when a backing file is used
* Use QED_F_BACKING_FORMAT_NO_PROBE instead of backing_fmt header field
* Allow non-cluster sized images
* Implement autoclear feature bits
* Implement backing image smaller size - reads from backing image should zero beyond EOF
* Preserve errno in qed_find_cluster_cb() - don't dumb down to QED_CLUSTER_ERROR
* Use ffs() instead of get_bits_from_size()
* Remove l2_cache argument to qed_unref_l2_cache_entry
* Eliminate L2TableAllocFunc function pointer
* Split qed_aio_write in-place and allocating code path to make code clearer
* Document how L2 cache is used
* Document qed_find_cluster()
* Update QED specification
* Fix COPYING.LIB LGPL license file references
* Add copyright header to qed-check.c
* Avoid the bytes_to_str()/cvtstr()/sztostr() dependency until Jes' strtosz() goes in
v2:
* Add QED format specification to documentation
* Use __builtin_ctzl() for get_bits_from_size()
* Fine-grained table locking to allow concurrent allocating write requests
* Fix qemu_free() instead of qemu_vfree() in qed_unref_l2_cache_entry()
* Comment clean-ups
Makefile.objs | 2 + block/qed-check.c | 210 +++++++ block/qed-cluster.c | 154 ++++++ block/qed-gencb.c | 32 ++ block/qed-l2-cache.c | 173 ++++++ block/qed-lock.c | 124 +++++ block/qed-table.c | 317 +++++++++++ block/qed.c | 1382 +++++++++++++++++++++++++++++++++++++++++++++++ block/qed.h | 315 +++++++++++ block_int.h | 1 + docs/specs/qed_spec.txt | 128 +++++ trace-events | 21 + 12 files changed, 2859 insertions(+), 0 deletions(-)
PATCH v4 1/5 docs: Add QED image format specification
--- docs/specs/qed_spec.txt | 128 +++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 128 insertions(+), 0 deletions(-) create mode 100644 docs/specs/qed_spec.txt
docs/specs/qed_spec.txt new file +128 -0
@@ -0,0 +1,128 @@ +=Specification= + +The file format looks like this: + + +----------+----------+----------+-----+ + | cluster0 | cluster1 | cluster2 | ... | + +----------+----------+----------+-----+ + +The first cluster begins with the '''header'''. The header contains information about where regular clusters start; this allows the header to be extensible and store extra information about the image file. A regular cluster may be a '''data cluster''', an '''L2''', or an '''L1 table'''. L1 and L2 tables are composed of one or more contiguous clusters. + +Normally the file size will be a multiple of the cluster size. If the file size is not a multiple, extra information after the last cluster may not be preserved if data is written. Legitimate extra information should use space between the header and the first regular cluster. + +All fields are little-endian. + +==Header== + Header { + uint32_t magic; /* QED\0 */ + + uint32_t cluster_size; /* in bytes */ + uint32_t table_size; /* for L1 and L2 tables, in clusters */ + uint32_t header_size; /* in clusters */ + + uint64_t features; /* format feature bits */ + uint64_t compat_features; /* compat feature bits */ + uint64_t l1_table_offset; /* in bytes */ + uint64_t image_size; /* total logical image size, in bytes */ + + /* if (features & QED_F_BACKING_FILE) */ + uint32_t backing_filename_offset; /* in bytes from start of header */ + uint32_t backing_filename_size; /* in bytes */ + } + +Field descriptions: +* ''cluster_size'' must be a power of 2 in range [2^12, 2^26]. +* ''table_size'' must be a power of 2 in range [1, 16]. +* ''header_size'' is the number of clusters used by the header and any additional information stored before regular clusters. +* ''features'', ''compat_features'', and ''autoclear_features'' are file format extension bitmaps. They work as follows: +** An image with unknown ''features'' bits enabled must not be opened. File format changes that are not backwards-compatible must use ''features'' bits. +** An image with unknown ''compat_features'' bits enabled can be opened safely. The unknown features are simply ignored and represent backwards-compatible changes to the file format. +** An image with unknown ''autoclear_features'' bits enable can be opened safely after clearing the unknown bits. This allows for backwards-compatible changes to the file format which degrade gracefully and can be re-enabled again by a new program later. +* ''l1_table_offset'' is the offset of the first byte of the L1 table in the image file and must be a multiple of ''cluster_size''. +* ''image_size'' is the block device size seen by the guest and must be a multiple of 512 bytes. +* ''backing_filename'' is a string in (byte offset, byte size) form. It is not NUL-terminated and has no alignment constraints. + +Feature bits: +* QED_F_BACKING_FILE = 0x01. The image uses a backing file. The backing filename string is given in the ''backing_filename_{offset,size}'' fields and may be an absolute path or relative to the image file. +* QED_F_NEED_CHECK = 0x02. The image needs a consistency check before use. +* QED_F_BACKING_FORMAT_NO_PROBE = 0x04. The backing file is a raw disk image and no file format autodetection should be attempted. This should be used to ensure that raw backing images are never detected as an image format if they happen to contain magic constants. + +There are currently no defined ''compat_features'' or ''autoclear_features'' bits. + +Fields predicated on a feature bit are only used when that feature is set. The fields always take up header space, regardless of whether or not the feature bit is set. + +==Tables== + +Tables provide the translation from logical offsets in the block device to cluster offsets in the file. + + #define TABLE_NOFFSETS (table_size * cluster_size / sizeof(uint64_t)) + + Table { + uint64_t offsets[TABLE_NOFFSETS]; + } + +The tables are organized as follows: + + +----------+ + | L1 table | + +----------+ + ,------' | '------. + +----------+ | +----------+ + | L2 table | ... | L2 table | + +----------+ +----------+ + ,------' | '------. + +----------+ | +----------+ + | Data | ... | Data | + +----------+ +----------+ + +A table is made up of one or more contiguous clusters. The table_size header field determines table size for an image file. For example, cluster_size=64 KB and table_size=4 results in 256 KB tables. + +The logical image size must be less than or equal to the maximum possible size of clusters rooted by the L1 table: + header.image_size <= TABLE_NOFFSETS * TABLE_NOFFSETS * header.cluster_size + +All offsets in L1 and L2 tables are cluster-aligned. The least significant bits up to ''cluster_size'' are reserved and must be zero. This may be used in future format extensions to store per-offset information. + +The following offsets have special meanings: + +===L2 table offsets=== +* 0 - unallocated. The L2 table is not yet allocated. + +===Data cluster offsets=== +* 0 - unallocated. The data cluster is not yet allocated. + +===Unallocated L2 tables and data clusters=== +Reads to an unallocated area of the image file access the backing file. If there is no backing file, then zeroes are produced. The backing file may be smaller than the image file and reads of unallocated areas beyond the end of the backing file produce zeroes. + +Writes to an unallocated area cause a new data clusters to be allocated, and a new L2 table if that is also unallocated. The new data cluster is populated with data from the backing image (or zeroes if no backing image) and the data being written. + +===Logical offset translation=== +Logical offsets are translated into cluster offsets as follows: + + table_bits table_bits cluster_bits + <--------> <--------> <---------------> + +----------+----------+-----------------+ + | L1 index | L2 index | byte offset | + +----------+----------+-----------------+ + + Structure of a logical offset + + offset_mask = ~(cluster_size - 1) # mask for the image file byte offset + + def logical_to_cluster_offset(l1_index, l2_index, byte_offset): + l2_offset = l1_table[l1_index] + l2_table = load_table(l2_offset) + cluster_offset = l2_table[l2_index] & offset_mask + return cluster_offset + byte_offset + +==Consistency checking== + +This section is informational and included to provide background on the use of the QED_F_NEED_CHECK ''features'' bit. + +The QED_F_NEED_CHECK bit is used to mark an image as dirty before starting an operation that could leave the image in an inconsistent state if interrupted by a crash or power failure. A dirty image must be checked on open because its metadata may not be consistent. + +Consistency check includes the following invariants: +# Each cluster is referenced once and only once. It is an inconsistency to have a cluster referenced more than once by L1 or L2 tables. A cluster has been leaked if it has no references. +# Offsets must be within the image file size and must be ''cluster_size'' aligned. +# Table offsets must at least ''table_size'' * ''cluster_size'' bytes from the end of the image file so that there is space for the entire table. + +The consistency check process starts by from ''l1_table_offset'' and scans all L2 tables. After the check completes with no other errors besides leaks, the QED_F_NEED_CHECK bit can be cleared and the image can be accessed.
Signature · 1 line
1.7.1
[Qemu-devel] Re: [PATCH v4 1/5] docs: Add QED image format specification
Am 28.10.2010 13:01, schrieb Stefan Hajnoczi:
Quoted 42 lines
Signed-off-by Stefan Hajnoczi <[email protected]>--- docs/specs/qed_spec.txt | 128 +++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 128 insertions(+), 0 deletions(-) create mode 100644 docs/specs/qed_spec.txtdocs/specs/qed_spec.txt new file +30
-0@@ -0,0 +1,128 @@ +=Specification= + +The file format looks like this: + + +----------+----------+----------+-----+ + | cluster0 | cluster1 | cluster2 | ... | + +----------+----------+----------+-----+ + +The first cluster begins with the '''header'''. The header contains information about where regular clusters start; this allows the header to be extensible and store extra information about the image file. A regular cluster may be a '''data cluster''', an '''L2''', or an '''L1 table'''. L1 and L2 tables are composed of one or more contiguous clusters. + +Normally the file size will be a multiple of the cluster size. If the file size is not a multiple, extra information after the last cluster may not be preserved if data is written. Legitimate extra information should use space between the header and the first regular cluster. + +All fields are little-endian. + +==Header== + Header { + uint32_t magic; /* QED\0 */ + + uint32_t cluster_size; /* in bytes */ + uint32_t table_size; /* for L1 and L2 tables, in clusters */ + uint32_t header_size; /* in clusters */ + + uint64_t features; /* format feature bits */ + uint64_t compat_features; /* compat feature bits */ + uint64_t l1_table_offset; /* in bytes */ + uint64_t image_size; /* total logical image size, in bytes */ + + /* if (features & QED_F_BACKING_FILE) */ + uint32_t backing_filename_offset; /* in bytes from start of header */ + uint32_t backing_filename_size; /* in bytes */
docs/specs/qed_spec.txt line 40
Quoted 10 lines
docs/specs/qed_spec.txt new file +10
-0+ } + +Field descriptions: +* ''cluster_size'' must be a power of 2 in range [2^12, 2^26]. +* ''table_size'' must be a power of 2 in range [1, 16]. +* ''header_size'' is the number of clusters used by the header and any additional information stored before regular clusters. +* ''features'', ''compat_features'', and ''autoclear_features'' are file format extension bitmaps. They work as follows: +** An image with unknown ''features'' bits enabled must not be opened. File format changes that are not backwards-compatible must use ''features'' bits. +** An image with unknown ''compat_features'' bits enabled can be opened safely. The unknown features are simply ignored and represent backwards-compatible changes to the file format. +** An image with unknown ''autoclear_features'' bits enable can be opened safely after clearing the unknown bits. This allows for backwards-compatible changes to the file format which degrade gracefully and can be re-enabled again by a new program later.
autoclear features aren't even part of the header in the spec.
Quoted 33 lines
docs/specs/qed_spec.txt new file +33
-0+* ''l1_table_offset'' is the offset of the first byte of the L1 table in the image file and must be a multiple of ''cluster_size''. +* ''image_size'' is the block device size seen by the guest and must be a multiple of 512 bytes. +* ''backing_filename'' is a string in (byte offset, byte size) form. It is not NUL-terminated and has no alignment constraints. + +Feature bits: +* QED_F_BACKING_FILE = 0x01. The image uses a backing file. The backing filename string is given in the ''backing_filename_{offset,size}'' fields and may be an absolute path or relative to the image file. +* QED_F_NEED_CHECK = 0x02. The image needs a consistency check before use. +* QED_F_BACKING_FORMAT_NO_PROBE = 0x04. The backing file is a raw disk image and no file format autodetection should be attempted. This should be used to ensure that raw backing images are never detected as an image format if they happen to contain magic constants. + +There are currently no defined ''compat_features'' or ''autoclear_features'' bits. + +Fields predicated on a feature bit are only used when that feature is set. The fields always take up header space, regardless of whether or not the feature bit is set. + +==Tables== + +Tables provide the translation from logical offsets in the block device to cluster offsets in the file. + + #define TABLE_NOFFSETS (table_size * cluster_size / sizeof(uint64_t)) + + Table { + uint64_t offsets[TABLE_NOFFSETS]; + } + +The tables are organized as follows: + + +----------+ + | L1 table | + +----------+ + ,------' | '------. + +----------+ | +----------+ + | L2 table | ... | L2 table | + +----------+ +----------+ + ,------' | '------.
docs/specs/qed_spec.txt
Quoted 10 lines
docs/specs/qed_spec.txt new file +10
-0+ +----------+ | +----------+ + | Data | ... | Data | + +----------+ +----------+ + +A table is made up of one or more contiguous clusters. The table_size header field determines table size for an image file. For example, cluster_size=64 KB and table_size=4 results in 256 KB tables. + +The logical image size must be less than or equal to the maximum possible size of clusters rooted by the L1 table: + header.image_size <= TABLE_NOFFSETS * TABLE_NOFFSETS * header.cluster_size + +All offsets in L1 and L2 tables are cluster-aligned. The least significant bits up to ''cluster_size'' are reserved and must be zero.
I know what you mean here, but the text leaves things a bit unclear. First I would expect a bit number instead of a byte offset for "bits up to x". Second, cluster_size is the first bit not reserved, whereas your description sounds to me as if it included cluster_size.
Quoted 36 lines
docs/specs/qed_spec.txt new file +35
-0This may be used in future format extensions to store per-offset information. + +The following offsets have special meanings: + +===L2 table offsets=== +* 0 - unallocated. The L2 table is not yet allocated. + +===Data cluster offsets=== +* 0 - unallocated. The data cluster is not yet allocated. + +===Unallocated L2 tables and data clusters=== +Reads to an unallocated area of the image file access the backing file. If there is no backing file, then zeroes are produced. The backing file may be smaller than the image file and reads of unallocated areas beyond the end of the backing file produce zeroes. + +Writes to an unallocated area cause a new data clusters to be allocated, and a new L2 table if that is also unallocated. The new data cluster is populated with data from the backing image (or zeroes if no backing image) and the data being written. + +===Logical offset translation=== +Logical offsets are translated into cluster offsets as follows: + + table_bits table_bits cluster_bits + <--------> <--------> <---------------> + +----------+----------+-----------------+ + | L1 index | L2 index | byte offset | + +----------+----------+-----------------+ + + Structure of a logical offset + + offset_mask = ~(cluster_size - 1) # mask for the image file byte offset + + def logical_to_cluster_offset(l1_index, l2_index, byte_offset): + l2_offset = l1_table[l1_index] + l2_table = load_table(l2_offset) + cluster_offset = l2_table[l2_index] & offset_mask + return cluster_offset + byte_offset + +==Consistency checking== +
docs/specs/qed_spec.txt line 128
Quoted 10 lines
docs/specs/qed_spec.txt new file +10
-0+This section is informational and included to provide background on the use of the QED_F_NEED_CHECK ''features'' bit. + +The QED_F_NEED_CHECK bit is used to mark an image as dirty before starting an operation that could leave the image in an inconsistent state if interrupted by a crash or power failure. A dirty image must be checked on open because its metadata may not be consistent. + +Consistency check includes the following invariants: +# Each cluster is referenced once and only once. It is an inconsistency to have a cluster referenced more than once by L1 or L2 tables. A cluster has been leaked if it has no references. +# Offsets must be within the image file size and must be ''cluster_size'' aligned. +# Table offsets must at least ''table_size'' * ''cluster_size'' bytes from the end of the image file so that there is space for the entire table. + +The consistency check process starts by from ''l1_table_offset'' and scans all L2 tables. After the check completes with no other errors besides leaks, the QED_F_NEED_CHECK bit can be cleared and the image can be accessed.
Looks okay otherwise.
Kevin
Re: [Qemu-devel] Re: [PATCH v4 1/5] docs: Add QED image format specification
Quoted 47 lines · Kevin Wolf
Am 28.10.2010 13:01, schrieb Stefan Hajnoczi:
Quoted 46 lines
Signed-off-by Stefan Hajnoczi <[email protected]>---
docs/specs/qed_spec.txt | 128 +++++++++++++++++++++++++++++++++++++++++++++++1 files changed, 128 insertions(+), 0 deletions(-)create mode 100644
docs/specs/qed_spec.txtdocs/specs/qed_spec.txt new file +34
-0@@ -0,0 +1,128 @@ +=Specification= + +The file format looks like this: + + +----------+----------+----------+-----+ + | cluster0 | cluster1 | cluster2 | ... | + +----------+----------+----------+-----+ + +The first cluster begins with the '''header'''. The header contains information about where regular clusters start; this allows the header to be extensible and store extra information about the image file. A regular cluster may be a '''data cluster''', an '''L2''', or an '''L1 table'''. L1 and L2 tables are composed of one or more contiguous clusters. + +Normally the file size will be a multiple of the cluster size. If the file size is not a multiple, extra information after the last cluster may not be preserved if data is written. Legitimate extra information should use space between the header and the first regular cluster. + +All fields are little-endian. + +==Header== + Header { + uint32_t magic; /* QED\0 */ + + uint32_t cluster_size; /* in bytes */ + uint32_t table_size; /* for L1 and L2 tables, in clusters */ + uint32_t header_size; /* in clusters */ + + uint64_t features; /* format feature bits */ + uint64_t compat_features; /* compat feature bits */ + uint64_t l1_table_offset; /* in bytes */ + uint64_t image_size; /* total logical image size, in bytes */ + + /* if (features & QED_F_BACKING_FILE) */ + uint32_t backing_filename_offset; /* in bytes from start of header */ + uint32_t backing_filename_size; /* in bytes */ + } + +Field descriptions: +* ''cluster_size'' must be a power of 2 in range [2^12, 2^26].
Quoted 8 lines
docs/specs/qed_spec.txt line 40
Quoted 6 lines
docs/specs/qed_spec.txt new file +6
-0+* ''table_size'' must be a power of 2 in range [1, 16]. +* ''header_size'' is the number of clusters used by the header and any additional information stored before regular clusters. +* ''features'', ''compat_features'', and ''autoclear_features'' are file format extension bitmaps. They work as follows: +** An image with unknown ''features'' bits enabled must not be opened. File format changes that are not backwards-compatible must use ''features'' bits. +** An image with unknown ''compat_features'' bits enabled can be opened safely. The unknown features are simply ignored and represent backwards-compatible changes to the file format. +** An image with unknown ''autoclear_features'' bits enable can be opened safely after clearing the unknown bits. This allows for backwards-compatible changes to the file format which degrade gracefully and can be re-enabled again by a new program later.autoclear features aren't even part of the header in the spec.
Thanks for spotting this, I forgot to sync the header with the code.
Quoted 40 lines
Quoted 40 lines
docs/specs/qed_spec.txt new file +40
-0+* ''l1_table_offset'' is the offset of the first byte of the L1 table in the image file and must be a multiple of ''cluster_size''. +* ''image_size'' is the block device size seen by the guest and must be a multiple of 512 bytes. +* ''backing_filename'' is a string in (byte offset, byte size) form. It is not NUL-terminated and has no alignment constraints. + +Feature bits: +* QED_F_BACKING_FILE = 0x01. The image uses a backing file. The backing filename string is given in the ''backing_filename_{offset,size}'' fields and may be an absolute path or relative to the image file. +* QED_F_NEED_CHECK = 0x02. The image needs a consistency check before use. +* QED_F_BACKING_FORMAT_NO_PROBE = 0x04. The backing file is a raw disk image and no file format autodetection should be attempted. This should be used to ensure that raw backing images are never detected as an image format if they happen to contain magic constants. + +There are currently no defined ''compat_features'' or ''autoclear_features'' bits. + +Fields predicated on a feature bit are only used when that feature is set. The fields always take up header space, regardless of whether or not the feature bit is set. + +==Tables== + +Tables provide the translation from logical offsets in the block device to cluster offsets in the file. + + #define TABLE_NOFFSETS (table_size * cluster_size / sizeof(uint64_t)) + + Table { + uint64_t offsets[TABLE_NOFFSETS]; + } + +The tables are organized as follows: + + +----------+ + | L1 table | + +----------+ + ,------' | '------. + +----------+ | +----------+ + | L2 table | ... | L2 table | + +----------+ +----------+ + ,------' | '------. + +----------+ | +----------+ + | Data | ... | Data | + +----------+ +----------+ + +A table is made up of one or more contiguous clusters. The table_size header field determines table size for an image file. For example, cluster_size=64 KB and table_size=4 results in 256 KB tables. + +The logical image size must be less than or equal to the maximum possible size of clusters rooted by the L1 table:
Quoted 8 lines
docs/specs/qed_spec.txt
Quoted 3 lines
docs/specs/qed_spec.txt new file +3
-0+ header.image_size <= TABLE_NOFFSETS * TABLE_NOFFSETS * header.cluster_size + +All offsets in L1 and L2 tables are cluster-aligned. The least significant bits up to ''cluster_size'' are reserved and must be zero.I know what you mean here, but the text leaves things a bit unclear. First I would expect a bit number instead of a byte offset for "bits up to x". Second,
cluster_sizeis the first bit not reserved, whereas your description sounds to me as if it includedcluster_size.
Will fix.
Stefan
PATCH v4 2/5 qed: Add QEMU Enhanced Disk image format
In reply to Stefan HajnocziThis patch introduces the qed on-disk layout and implements image creation. Later patches add read/write and other functionality.
--- Makefile.objs | 1 + block/qed.c | 548 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ block/qed.h | 145 +++++++++++++++ block_int.h | 1 + 4 files changed, 695 insertions(+), 0 deletions(-) create mode 100644 block/qed.c create mode 100644 block/qed.h
Makefile.objs +1 -0
@@ -14,6 +14,7 @@ block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o block-nested-y += raw.o cow.o qcow.o vdi.o vmdk.o cloop.o dmg.o bochs.o vpc.o vvfat.o block-nested-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o +block-nested-y += qed.o block-nested-y += parallels.o nbd.o blkdebug.o sheepdog.o blkverify.o block-nested-$(CONFIG_WIN32) += raw-win32.o block-nested-$(CONFIG_POSIX) += raw-posix.o
block/qed.c new file +548 -0
548 lines not on this page · raw message
block/qed.h new file +145 -0
145 lines not on this page · raw message
block_int.h +1 -0
@@ -38,6 +38,7 @@#define BLOCK_OPT_BACKING_FILE "backing_file"#define BLOCK_OPT_BACKING_FMT "backing_fmt"#define BLOCK_OPT_CLUSTER_SIZE "cluster_size" +#define BLOCK_OPT_TABLE_SIZE "table_size"#define BLOCK_OPT_PREALLOC "preallocation" typedef struct AIOPool {
Signature · 1 line
1.7.1
[Qemu-devel] Re: [PATCH v4 2/5] qed: Add QEMU Enhanced Disk image format
Am 28.10.2010 13:01, schrieb Stefan Hajnoczi:
Quoted 60 lines
This patch introduces the qed on-disk layout and implements image creation. Later patches add read/write and other functionality.
Signed-off-by Stefan Hajnoczi <[email protected]>--- Makefile.objs | 1 + block/qed.c | 548 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ block/qed.h | 145 +++++++++++++++ block_int.h | 1 + 4 files changed, 695 insertions(+), 0 deletions(-) create mode 100644 block/qed.c create mode 100644 block/qed.hMakefile.objs +1
-0@@ -14,6 +14,7 @@ block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o block-nested-y += raw.o cow.o qcow.o vdi.o vmdk.o cloop.o dmg.o bochs.o vpc.o vvfat.o block-nested-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o +block-nested-y += qed.o block-nested-y += parallels.o nbd.o blkdebug.o sheepdog.o blkverify.o block-nested-$(CONFIG_WIN32) += raw-win32.o block-nested-$(CONFIG_POSIX) += raw-posix.oblock/qed.c new file +29
-0@@ -0,0 +1,548 @@ +/* +* QEMU Enhanced Disk Format +* +* Copyright IBM, Corp. 2010 +* +* Authors: +* Stefan Hajnoczi <[email protected]> +* Anthony Liguori <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2 or later. +* See the COPYING.LIB file in the top-level directory. +* +*/ + +#include "qed.h" + +static int bdrv_qed_probe (const uint8_t *buf,int buf_size, +const char *filename) +{ +const QEDHeader *header = (const QEDHeader *)buf; + +if (buf_size <sizeof (*header)) { +return 0 ; + } +if (le32_to_cpu (header->magic) !=QED_MAGIC ) { +return 0 ; + } +return 100 ; +}
block/qed.c line 39
Quoted 10 lines
block/qed.c new file +10
-0+ +/** +* Check whether an image format is raw +* +* @fmt: Backing file format, may be NULL +*/ +static bool qed_fmt_is_raw (const char *fmt) +{ +return fmt &&strcmp (fmt,"raw" ) ==0 ; +}
People shouldn't use them directly, but should we also consider file, host_device, etc.?
Quoted 127 lines
block/qed.c new file +127
-0+ +static void qed_header_le_to_cpu (const QEDHeader *le,QEDHeader *cpu) +{ + cpu->magic =le32_to_cpu (le->magic); + cpu->cluster_size =le32_to_cpu (le->cluster_size); + cpu->table_size =le32_to_cpu (le->table_size); + cpu->header_size =le32_to_cpu (le->header_size); + cpu->features =le64_to_cpu (le->features); + cpu->compat_features =le64_to_cpu (le->compat_features); + cpu->autoclear_features =le64_to_cpu (le->autoclear_features); + cpu->l1_table_offset =le64_to_cpu (le->l1_table_offset); + cpu->image_size =le64_to_cpu (le->image_size); + cpu->backing_filename_offset =le32_to_cpu (le->backing_filename_offset); + cpu->backing_filename_size =le32_to_cpu (le->backing_filename_size); +} + +static void qed_header_cpu_to_le (const QEDHeader *cpu,QEDHeader *le) +{ + le->magic =cpu_to_le32 (cpu->magic); + le->cluster_size =cpu_to_le32 (cpu->cluster_size); + le->table_size =cpu_to_le32 (cpu->table_size); + le->header_size =cpu_to_le32 (cpu->header_size); + le->features =cpu_to_le64 (cpu->features); + le->compat_features =cpu_to_le64 (cpu->compat_features); + le->autoclear_features =cpu_to_le64 (cpu->autoclear_features); + le->l1_table_offset =cpu_to_le64 (cpu->l1_table_offset); + le->image_size =cpu_to_le64 (cpu->image_size); + le->backing_filename_offset =cpu_to_le32 (cpu->backing_filename_offset); + le->backing_filename_size =cpu_to_le32 (cpu->backing_filename_size); +} + +static int qed_write_header_sync (BDRVQEDState *s) +{ +QEDHeader le; +int ret; + +qed_header_cpu_to_le (&s->header, &le); + ret =bdrv_pwrite (s->bs->file,0 , &le,sizeof (le)); +if (ret !=sizeof (le)) { +return ret; + } +return 0 ; +} + +static uint64_t qed_max_image_size (uint32_t cluster_size,uint32_t table_size) +{ +uint64_t table_entries; +uint64_t l2_size; + + table_entries = (table_size * cluster_size) /sizeof (uint64_t ); + l2_size = table_entries * cluster_size; + +return l2_size * table_entries; +} + +static bool qed_is_cluster_size_valid (uint32_t cluster_size) +{ +if (cluster_size <QED_MIN_CLUSTER_SIZE || + cluster_size >QED_MAX_CLUSTER_SIZE ) { +return false; + } +if (cluster_size & (cluster_size -1 )) { +return false;/* not power of 2 */ + } +return true; +} + +static bool qed_is_table_size_valid (uint32_t table_size) +{ +if (table_size <QED_MIN_TABLE_SIZE || + table_size >QED_MAX_TABLE_SIZE ) { +return false; + } +if (table_size & (table_size -1 )) { +return false;/* not power of 2 */ + } +return true; +} + +static bool qed_is_image_size_valid (uint64_t image_size,uint32_t cluster_size, +uint32_t table_size) +{ +if (image_size %BDRV_SECTOR_SIZE !=0 ) { +return false;/* not multiple of sector size */ + } +if (image_size >qed_max_image_size (cluster_size, table_size)) { +return false;/* image is too large */ + } +return true; +} + +/** +* Read a string of known length from the image file +* +* @file: Image file +* @offset: File offset to start of string, in bytes +* @n: String length in bytes +* @buf: Destination buffer +* @buflen: Destination buffer length in bytes +* @ret: 0 on success, -errno on failure +* +* The string is NUL-terminated. +*/ +static int qed_read_string (BlockDriverState *file,uint64_t offset,size_t n, +char *buf,size_t buflen) +{ +int ret; +if (n >= buflen) { +return -EINVAL ; + } + ret =bdrv_pread (file, offset, buf, n); +if (ret <0 ) { +return ret; + } + buf[n] ='\0' ; +return 0 ; +} + +static int bdrv_qed_open (BlockDriverState *bs,int flags) +{ +BDRVQEDState *s = bs->opaque; +QEDHeader le_header; +int64_t file_size; +int ret; + + s->bs = bs; +
block/qed.c line 176
Quoted 10 lines
block/qed.c new file +10
-0+ ret =bdrv_pread (bs->file,0 , &le_header,sizeof (le_header)); +if (ret <0 ) { +return ret; + } + ret =0 ;/* ret should always be 0 or -errno */ +qed_header_le_to_cpu (&le_header, &s->header); + +if (s->header.magic !=QED_MAGIC ) { +return -ENOENT ; + }
ENOENT seems a bit odd for a wrong magic number, especially if it's used for the error message. Wouldn't EINVAL or ENOTSUP be a closer match?
Quoted 65 lines
block/qed.c new file +65
-0+if (s->header.features & ~QED_FEATURE_MASK ) { +return -ENOTSUP ;/* image uses unsupported feature bits */ + } +if (!qed_is_cluster_size_valid (s->header.cluster_size)) { +return -EINVAL ; + } + +/* Round down file size to the last cluster */ + file_size =bdrv_getlength (bs->file); +if (file_size <0 ) { +return file_size; + } + s->file_size =qed_start_of_cluster (s, file_size); + +if (!qed_is_table_size_valid (s->header.table_size)) { +return -EINVAL ; + } +if (!qed_is_image_size_valid (s->header.image_size, + s->header.cluster_size, + s->header.table_size)) { +return -EINVAL ; + } +if (!qed_check_table_offset (s, s->header.l1_table_offset)) { +return -EINVAL ; + } + + s->table_nelems = (s->header.cluster_size * s->header.table_size) / +sizeof (uint64_t ); + s->l2_shift =ffs (s->header.cluster_size) -1 ; + s->l2_mask = s->table_nelems -1 ; + s->l1_shift = s->l2_shift +ffs (s->table_nelems) -1 ; + +if ((s->header.features &QED_F_BACKING_FILE )) { + ret =qed_read_string (bs->file, s->header.backing_filename_offset, + s->header.backing_filename_size, bs->backing_file, +sizeof (bs->backing_file)); +if (ret <0 ) { +return ret; + } + +if (s->header.features &QED_F_BACKING_FORMAT_NO_PROBE ) { +pstrcpy (bs->backing_format,sizeof (bs->backing_format),"raw" ); + } + } + +/* Reset unknown autoclear feature bits. This is a backwards +* compatibility mechanism that allows images to be opened by older +* programs, which "knock out" unknown feature bits. When an image is +* opened by a newer program again it can detect that the autoclear +* feature is no longer valid. +*/ +if ((s->header.autoclear_features & ~QED_AUTOCLEAR_FEATURE_MASK ) !=0 && + !bdrv_is_read_only (bs->file)) { + s->header.autoclear_features &=QED_AUTOCLEAR_FEATURE_MASK ; + + ret =qed_write_header_sync (s); +if (ret) { +return ret; + } + +/* From here on only known autoclear feature bits are valid */ +bdrv_flush (bs->file); + } + +return ret;
block/qed.c line 251
Quoted 10 lines
block/qed.c new file +10
-0+} + +static void bdrv_qed_close (BlockDriverState *bs) +{ +} + +static void bdrv_qed_flush (BlockDriverState *bs) +{ +bdrv_flush (bs->file); +}
This conflicts with one of my recent changes. bdrv_flush should return an int now.
Quoted 70 lines
block/qed.c new file +70
-0+ +static int qed_create (const char *filename,uint32_t cluster_size, +uint64_t image_size,uint32_t table_size, +const char *backing_file,const char *backing_fmt) +{ +QEDHeader header = { + .magic =QED_MAGIC , + .cluster_size = cluster_size, + .table_size = table_size, + .header_size =1 , + .features =0 , + .compat_features =0 , + .l1_table_offset = cluster_size, + .image_size = image_size, + }; +QEDHeader le_header; +uint8_t *l1_table =NULL ; +size_t l1_size = header.cluster_size * header.table_size; +int ret =0 ; +BlockDriverState *bs =NULL ; + + ret =bdrv_create_file (filename,NULL ); +if (ret <0 ) { +return ret; + } + + ret =bdrv_file_open (&bs, filename,BDRV_O_RDWR |BDRV_O_CACHE_WB ); +if (ret <0 ) { +return ret; + } + +if (backing_file) { + header.features |=QED_F_BACKING_FILE ; + header.backing_filename_offset =sizeof (le_header); + header.backing_filename_size =strlen (backing_file); + +if (qed_fmt_is_raw (backing_fmt)) { + header.features |=QED_F_BACKING_FORMAT_NO_PROBE ; + } + } + +qed_header_cpu_to_le (&header, &le_header); + ret =bdrv_pwrite (bs,0 , &le_header,sizeof (le_header)); +if (ret <0 ) { + goto out; + } + ret =bdrv_pwrite (bs,sizeof (le_header), backing_file, + header.backing_filename_size); +if (ret <0 ) { + goto out; + } + + l1_table =qemu_mallocz (l1_size); + ret =bdrv_pwrite (bs, header.l1_table_offset, l1_table, l1_size); +if (ret <0 ) { + goto out; + } + + ret =0 ;/* success */ +out: +qemu_free (l1_table); +bdrv_delete (bs); +return ret; +} + +static int bdrv_qed_create (const char *filename,QEMUOptionParameter *options) +{ +uint64_t image_size =0 ; +uint32_t cluster_size =QED_DEFAULT_CLUSTER_SIZE ; +uint32_t table_size =QED_DEFAULT_TABLE_SIZE ;
block/qed.c line 331
Quoted 10 lines
block/qed.c new file +10
-0+const char *backing_file =NULL ; +const char *backing_fmt =NULL ; + +while (options && options->name) { +if (!strcmp (options->name,BLOCK_OPT_SIZE )) { + image_size = options->value.n; + }else if (!strcmp (options->name,BLOCK_OPT_BACKING_FILE )) { + backing_file = options->value.s; + }else if (!strcmp (options->name,BLOCK_OPT_BACKING_FMT )) { + backing_fmt = options->value.s;
I'm not sure here. It doesn't really matter for QED, but I find it strange that -o backing_fmt=foobar works and gives you a non-raw backing file. Should we check if the format exists at least?
Kevin
Re: [Qemu-devel] Re: [PATCH v4 2/5] qed: Add QEMU Enhanced Disk image format
Quoted 13 lines · Kevin Wolf
Am 28.10.2010 13:01, schrieb Stefan Hajnoczi:
block/qed.c line 39
Quoted 9 lines
block/qed.c new file +9
-0+/** +* Check whether an image format is raw +* +* @fmt: Backing file format, may be NULL +*/ +static bool qed_fmt_is_raw (const char *fmt) +{ + return fmt && strcmp(fmt, "raw") == 0; +}People shouldn't use them directly, but should we also consider file,
host_device, etc.?
Hrm..I will look into it for v5. I thought we always have a "raw" format on top of "file", "host_device", etc protocols?
Quoted 6 lines
Quoted 3 lines
+ if (
s->header.magic!=QED_MAGIC) {
+ return-ENOENT;
+ }ENOENT seems a bit odd for a wrong magic number, especially if it's used for the error message. Wouldn't EINVAL or ENOTSUP be a closer match?
You're right, ENOENT is confusing for the user.
Quoted 7 lines
block/qed.c line 251
Quoted 4 lines
block/qed.c new file +4
-0+static void bdrv_qed_flush (BlockDriverState *bs) +{ + bdrv_flush(bs->file); +}This conflicts with one of my recent changes.
bdrv_flushshould return an int now.
Will fix and will also check for bdrv_flush() failures.
Quoted 11 lines
Quoted 7 lines
+ while (options &&
options->name) {
+ if (!strcmp(options->name,BLOCK_OPT_SIZE)) {
+ image_size =options->value.n;
+ } else if (!strcmp(options->name,BLOCK_OPT_BACKING_FILE)) {
+ backing_file =options->value.s;
+ } else if (!strcmp(options->name,BLOCK_OPT_BACKING_FMT)) {
+ backing_fmt =options->value.s;I'm not sure here. It doesn't really matter for QED, but I find it strange that -o backing_fmt=foobar works and gives you a non-raw backing file. Should we check if the format exists at least?
I see the same issue in QCOW2 so let's solve this generically in a separate patch.
Stefan
Re: [Qemu-devel] Re: [PATCH v4 2/5] qed: Add QEMU Enhanced Disk image format
Am 12.11.2010 17:34, schrieb Stefan Hajnoczi:
Quoted 15 lines · Kevin Wolf
Quoted 13 lines
Am 28.10.2010 13:01, schrieb Stefan Hajnoczi:
block/qed.c line 39
Quoted 9 lines
block/qed.c new file +9
-0+/** +* Check whether an image format is raw +* +* @fmt: Backing file format, may be NULL +*/ +static bool qed_fmt_is_raw (const char *fmt) +{ +return fmt &&strcmp (fmt,"raw" ) ==0 ; +}People shouldn't use them directly, but should we also consider file,
host_device, etc.?
Quoted 2 lines
Hrm..I will look into it for v5. I thought we always have a "raw" format on top of "file", "
host_device", etc protocols?
That's how it's meant to be used. I think at the moment we still allow to directly use file etc. and you know that if something is possible, users will do it.
But instead of listing all of them here, maybe we should just make the final step and return an error if they are used directly. Unfortunately, that will bring us back to the discussion about formats and protocols... ;-)
Quoted 27 lines
Quoted 6 lines
block/qed.c line 176
Quoted 3 lines
block/qed.c new file +3
-0+if (s->header.magic !=QED_MAGIC ) { +return -ENOENT ; + }ENOENT seems a bit odd for a wrong magic number, especially if it's used for the error message. Wouldn't EINVAL or ENOTSUP be a closer match?
You're right, ENOENT is confusing for the user.
Quoted 7 lines
block/qed.c line 251
Quoted 4 lines
block/qed.c new file +4
-0+static void bdrv_qed_flush (BlockDriverState *bs) +{ +bdrv_flush (bs->file); +}This conflicts with one of my recent changes.
bdrv_flushshould return an int now.Will fix and will also check for
bdrv_flush()failures.Quoted 8 lines
Quoted 7 lines
block/qed.c new file +7
-0+while (options && options->name) { +if (!strcmp (options->name,BLOCK_OPT_SIZE )) { + image_size = options->value.n; + }else if (!strcmp (options->name,BLOCK_OPT_BACKING_FILE )) { + backing_file = options->value.s; + }else if (!strcmp (options->name,BLOCK_OPT_BACKING_FMT )) { + backing_fmt = options->value.s;
Quoted 6 lines
Quoted 3 lines
I'm not sure here. It doesn't really matter for QED, but I find it strange that -o backing_fmt=foobar works and gives you a non-raw backing file. Should we check if the format exists at least?
I see the same issue in QCOW2 so let's solve this generically in a separate patch.
Okay, that makes sense.
Kevin
Re: [Qemu-devel] Re: [PATCH v4 2/5] qed: Add QEMU Enhanced Disk image format
Quoted 16 lines · Kevin Wolf
Am 12.11.2010 17:34, schrieb Stefan Hajnoczi:
Quoted 15 lines · Kevin Wolf
Quoted 13 lines
Am 28.10.2010 13:01, schrieb Stefan Hajnoczi:
block/qed.c line 39
Quoted 9 lines
block/qed.c new file +9
-0+/** +* Check whether an image format is raw +* +* @fmt: Backing file format, may be NULL +*/ +static bool qed_fmt_is_raw (const char *fmt) +{ +return fmt &&strcmp (fmt,"raw" ) ==0 ; +}People shouldn't use them directly, but should we also consider file,
host_device, etc.?
Quoted 6 lines
Quoted 2 lines
Hrm..I will look into it for v5. I thought we always have a "raw" format on top of "file", "
host_device", etc protocols?That's how it's meant to be used. I think at the moment we still allow to directly use file etc. and you know that if something is possible, users will do it.
It's possible, it's perfectly well-defined, and it works.
Quoted 2 lines
But instead of listing all of them here, maybe we should just make the final step and return an error if they are used directly.
No.
Quoted 2 lines
Unfortunately,
that will bring us back to the discussion about formats and protocols... ;-)
/me runs away screaming
[...]
Re: [Qemu-devel] Re: [PATCH v4 2/5] qed: Add QEMU Enhanced Disk image format
Am 12.11.2010 18:24, schrieb Markus Armbruster:
Quoted 18 lines
Quoted 16 lines · Kevin Wolf
Am 12.11.2010 17:34, schrieb Stefan Hajnoczi:
Quoted 15 lines · Kevin Wolf
Quoted 13 lines
Am 28.10.2010 13:01, schrieb Stefan Hajnoczi:
block/qed.c line 39
Quoted 9 lines
block/qed.c new file +9
-0+/** +* Check whether an image format is raw +* +* @fmt: Backing file format, may be NULL +*/ +static bool qed_fmt_is_raw (const char *fmt) +{ +return fmt &&strcmp (fmt,"raw" ) ==0 ; +}People shouldn't use them directly, but should we also consider file,
host_device, etc.?
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Hrm..I will look into it for v5. I thought we always have a "raw" format on top of "file", "
host_device", etc protocols?That's how it's meant to be used. I think at the moment we still allow to directly use file etc. and you know that if something is possible, users will do it.
It's possible, it's perfectly well-defined, and it works.
Wow, I'm not used to be confirmed that quickly!
Yes, it's possible, it works, but it's only exposed because we didn't pay attention when host_* was split out. There's no real reason to use it (or do you have any example where format=raw doesn't work?) and it should be considered an implementation detail.
Kevin
PATCH v4 3/5 qed: Table, L2 cache, and cluster functions
In reply to Stefan HajnocziThis patch adds code to look up data cluster offsets in the image via the L1/L2 tables. The L2 tables are writethrough cached in memory for performance (each read/write requires a lookup so it is essential to cache the tables).
With cluster lookup code in place it is possible to implement bdrv_is_allocated() to query the number of contiguous allocated/unallocated clusters.
--- Makefile.objs | 2 +- block/qed-cluster.c | 154 ++++++++++++++++++++++++ block/qed-gencb.c | 32 +++++ block/qed-l2-cache.c | 173 +++++++++++++++++++++++++++ block/qed-table.c | 317 ++++++++++++++++++++++++++++++++++++++++++++++++++ block/qed.c | 54 +++++++++- block/qed.h | 121 +++++++++++++++++++ trace-events | 11 ++ 8 files changed, 862 insertions(+), 2 deletions(-) create mode 100644 block/qed-cluster.c create mode 100644 block/qed-gencb.c create mode 100644 block/qed-l2-cache.c create mode 100644 block/qed-table.c
Makefile.objs +1 -1
@@ -14,7 +14,7 @@ block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o block-nested-y += raw.o cow.o qcow.o vdi.o vmdk.o cloop.o dmg.o bochs.o vpc.o vvfat.o block-nested-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o -block-nested-y += qed.o +block-nested-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o block-nested-y += parallels.o nbd.o blkdebug.o sheepdog.o blkverify.o block-nested-$(CONFIG_WIN32) += raw-win32.o block-nested-$(CONFIG_POSIX) += raw-posix.o
block/qed-cluster.c new file +154 -0
154 lines not on this page · raw message
block/qed-gencb.c new file +32 -0
@@ -0,0 +1,32 @@ +/* +* QEMU Enhanced Disk Format +* +* Copyright IBM, Corp. 2010 +* +* Authors: +* Stefan Hajnoczi <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2 or later. +* See the COPYING.LIB file in the top-level directory. +* +*/ + +#include "qed.h" + +void *gencb_alloc (size_t len,BlockDriverCompletionFunc *cb,void *opaque) +{ +GenericCB *gencb =qemu_malloc (len); + gencb->cb = cb; + gencb->opaque = opaque; +return gencb; +} + +void gencb_complete (void *opaque,int ret) +{ +GenericCB *gencb = opaque; +BlockDriverCompletionFunc *cb = gencb->cb; +void *user_opaque = gencb->opaque; + +qemu_free (gencb); +cb (user_opaque, ret); +}
block/qed-l2-cache.c new file +173 -0
173 lines not on this page · raw message
block/qed-table.c new file +317 -0
317 lines not on this page · raw message
block/qed.c +53 -1
80 lines not on this page · raw message
block/qed.h +121 -0
142 lines not on this page · raw message
trace-events +11 -0
@@ -81,3 +81,14 @@ disable apic_mem_writel(uint64_t addr, uint32_t val) "%"PRIx64" = %08x" disable apic_reset_irq_delivered(int apic_irq_delivered) "old coalescing %d" disable apic_get_irq_delivered(int apic_irq_delivered) "returning coalescing %d" disable apic_set_irq(int apic_irq_delivered) "coalescing %d" + +# block/qed-l2-cache.c +disable qed_alloc_l2_cache_entry(void *l2_cache, void *entry) "l2_cache %p entry %p" +disable qed_unref_l2_cache_entry(void *entry, int ref) "entry %p ref %d" +disable qed_find_l2_cache_entry(void *l2_cache, void *entry, uint64_t offset, int ref) "l2_cache %p entry %p offset %"PRIu64" ref %d" + +# block/qed-table.c +disable qed_read_table(void *s, uint64_t offset, void *table) "s %p offset %"PRIu64" table %p" +disable qed_read_table_cb(void *s, void *table, int ret) "s %p table %p ret %d" +disable qed_write_table(void *s, uint64_t offset, void *table, unsigned int index, unsigned int n) "s %p offset %"PRIu64" table %p index %u n %u" +disable qed_write_table_cb(void *s, void *table, int ret) "s %p table %p ret %d"
Signature · 1 line
1.7.1
[Qemu-devel] Re: [PATCH v4 3/5] qed: Table, L2 cache, and cluster functions
Am 28.10.2010 13:01, schrieb Stefan Hajnoczi:
Quoted 10 lines
This patch adds code to look up data cluster offsets in the image via the L1/L2 tables. The L2 tables are writethrough cached in memory for performance (each read/write requires a lookup so it is essential to cache the tables).
With cluster lookup code in place it is possible to implement
bdrv_is_allocated()to query the number of contiguous allocated/unallocated clusters.Signed-off-by Stefan Hajnoczi <[email protected]>
Didn't find any obvious problems with this one, but maybe that just means that I'm tired and should stop working for today. ;-)
Kevin
Re: [Qemu-devel] Re: [PATCH v4 3/5] qed: Table, L2 cache, and cluster functions
Quoted 6 lines · Kevin Wolf
Am 28.10.2010 13:01, schrieb Stefan Hajnoczi:
Quoted 5 lines
This patch adds code to look up data cluster offsets in the image via the L1/L2 tables. The L2 tables are writethrough cached in memory for performance (each read/write requires a lookup so it is essential to cache the tables).
Quoted 8 lines
Quoted 5 lines
With cluster lookup code in place it is possible to implement
bdrv_is_allocated()to query the number of contiguous allocated/unallocated clusters.Signed-off-by Stefan Hajnoczi <[email protected]>Didn't find any obvious problems with this one, but maybe that just means that I'm tired and should stop working for today. ;-)
Thanks for your review effort, Kevin.
Stefan
PATCH v4 4/5 qed: Read/write support
In reply to Stefan HajnocziThis patch implements the read/write state machine. Operations are fully asynchronous and multiple operations may be active at any time.
Allocating writes lock tables to ensure metadata updates do not interfere with each other. If two allocating writes need to update the same L2 table they will run sequentially. If two allocating writes need to update different L2 tables they will run in parallel.
--- Makefile.objs | 1 + block/qed-lock.c | 124 ++++++++++ block/qed.c | 667 +++++++++++++++++++++++++++++++++++++++++++++++++++++- block/qed.h | 43 ++++ trace-events | 10 + 5 files changed, 843 insertions(+), 2 deletions(-) create mode 100644 block/qed-lock.c
Makefile.objs +1 -0
@@ -15,6 +15,7 @@ block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o block-nested-y += raw.o cow.o qcow.o vdi.o vmdk.o cloop.o dmg.o bochs.o vpc.o vvfat.o block-nested-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o block-nested-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o +block-nested-y += qed-lock.o block-nested-y += parallels.o nbd.o blkdebug.o sheepdog.o blkverify.o block-nested-$(CONFIG_WIN32) += raw-win32.o block-nested-$(CONFIG_POSIX) += raw-posix.o
block/qed-lock.c new file +124 -0
124 lines not on this page · raw message
block/qed.c +665 -2
711 lines not on this page · raw message
block/qed.h +43 -0
61 lines not on this page · raw message
trace-events +10 -0
@@ -92,3 +92,13 @@ disable qed_read_table(void *s, uint64_t offset, void *table) "s %p offset %"PRI disable qed_read_table_cb(void *s, void *table, int ret) "s %p table %p ret %d" disable qed_write_table(void *s, uint64_t offset, void *table, unsigned int index, unsigned int n) "s %p offset %"PRIu64" table %p index %u n %u" disable qed_write_table_cb(void *s, void *table, int ret) "s %p table %p ret %d" + +# block/qed.c +disable qed_aio_complete(void *s, void *acb, int ret) "s %p acb %p ret %d" +disable qed_aio_setup(void *s, void *acb, int64_t sector_num, int nb_sectors, void *opaque, int is_write) "s %p acb %p sector_num %"PRId64" nb_sectors %d opaque %p is_write %d" +disable qed_aio_next_io(void *s, void *acb, int ret, uint64_t cur_pos) "s %p acb %p ret %d cur_pos %"PRIu64"" +disable qed_aio_read_data(void *s, void *acb, int ret, uint64_t offset, size_t len) "s %p acb %p ret %d offset %"PRIu64" len %zu" +disable qed_aio_write_data(void *s, void *acb, int ret, uint64_t offset, size_t len) "s %p acb %p ret %d offset %"PRIu64" len %zu" +disable qed_aio_write_prefill(void *s, void *acb, uint64_t start, size_t len, uint64_t offset) "s %p acb %p start %"PRIu64" len %zu offset %"PRIu64"" +disable qed_aio_write_postfill(void *s, void *acb, uint64_t start, size_t len, uint64_t offset) "s %p acb %p start %"PRIu64" len %zu offset %"PRIu64"" +disable qed_aio_write_main(void *s, void *acb, int ret, uint64_t offset, size_t len) "s %p acb %p ret %d offset %"PRIu64" len %zu"
Signature · 1 line
1.7.1
PATCH v4 5/5 qed: Consistency check support
In reply to Stefan HajnocziThis patch adds support for the qemu-img check command. It also introduces a dirty bit in the qed header to mark modified images as needing a check. This bit is cleared when the image file is closed cleanly.
If an image file is opened and it has the dirty bit set, a consistency check will run and try to fix corrupted table offsets. These corruptions may occur if there is power loss while an allocating write is performed. Once the image is fixed it opens as normal again.
--- Makefile.objs | 2 +- block/qed-check.c | 210 +++++++++++++++++++++++++++++++++++++++++++++++++++++ block/qed.c | 125 +++++++++++++++++++++++++++++++- block/qed.h | 8 ++- 4 files changed, 340 insertions(+), 5 deletions(-) create mode 100644 block/qed-check.c
Makefile.objs +1 -1
@@ -15,7 +15,7 @@ block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o block-nested-y += raw.o cow.o qcow.o vdi.o vmdk.o cloop.o dmg.o bochs.o vpc.o vvfat.o block-nested-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o block-nested-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o -block-nested-y += qed-lock.o +block-nested-y += qed-lock.o qed-check.o block-nested-y += parallels.o nbd.o blkdebug.o sheepdog.o blkverify.o block-nested-$(CONFIG_WIN32) += raw-win32.o block-nested-$(CONFIG_POSIX) += raw-posix.o
block/qed-check.c new file +210 -0
210 lines not on this page · raw message
block/qed.c +122 -3
155 lines not on this page · raw message
block/qed.h +7 -1
@@ -50,11 +50,15 @@ enum {/* The image supports a backing file */ QED_F_BACKING_FILE =0x01 , +/* The image needs a consistency check before use */ +QED_F_NEED_CHECK =0x02 , +/* The backing file format must not be probed, treat as raw image */ QED_F_BACKING_FORMAT_NO_PROBE =0x04 ,/* Feature bits must be used when the on-disk format changes */ QED_FEATURE_MASK =QED_F_BACKING_FILE |/* supported feature bits */ +QED_F_NEED_CHECK |QED_F_BACKING_FORMAT_NO_PROBE ,QED_COMPAT_FEATURE_MASK =0 ,/* supported compat feature bits */ QED_AUTOCLEAR_FEATURE_MASK = 0, /* supported autoclear feature bits */
@@ -245,8 +249,10 @@ void qed_find_cluster(BDRVQEDState *s, QEDRequest *request, uint64_t pos, size_t len, QEDFindClusterFunc *cb, void *opaque);/** -* Round down offset to start of cluster +* Consistency check */ +int qed_check (BDRVQEDState *s,BdrvCheckResult *result,bool fix); +QEDTable *qed_alloc_table (BDRVQEDState *s);static inline uint64_t qed_start_of_cluster (BDRVQEDState *s,uint64_t offset)
Signature · 1 line
1.7.1