[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC PATCH 12/16] qcow2: Support for feature table header e
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [RFC PATCH 12/16] qcow2: Support for feature table header extension |
Date: |
Tue, 27 Mar 2012 17:03:31 +0200 |
Instead of printing an ugly bitmask, qemu can now print a more helpful
string even for yet unknown features.
Signed-off-by: Kevin Wolf <address@hidden>
---
block/qcow2.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++-------
block/qcow2.h | 12 +++++++++
2 files changed, 77 insertions(+), 9 deletions(-)
diff --git a/block/qcow2.c b/block/qcow2.c
index aef8282..002e138 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -54,6 +54,7 @@ typedef struct {
} QCowExtension;
#define QCOW2_EXT_MAGIC_END 0
#define QCOW2_EXT_MAGIC_BACKING_FORMAT 0xE2792ACA
+#define QCOW2_EXT_MAGIC_FEATURE_TABLE 0x6803f857
static int qcow2_probe(const uint8_t *buf, int buf_size, const char *filename)
{
@@ -76,7 +77,7 @@ static int qcow2_probe(const uint8_t *buf, int buf_size,
const char *filename)
* return 0 upon success, non-0 otherwise
*/
static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset,
- uint64_t end_offset)
+ uint64_t end_offset, void **p_feature_table)
{
BDRVQcowState *s = bs->opaque;
QCowExtension ext;
@@ -134,6 +135,18 @@ static int qcow2_read_extensions(BlockDriverState *bs,
uint64_t start_offset,
#endif
break;
+ case QCOW2_EXT_MAGIC_FEATURE_TABLE:
+ if (p_feature_table != NULL) {
+ void* feature_table = g_malloc0(ext.len + 2 *
sizeof(Qcow2Feature));
+ ret = bdrv_pread(bs->file, offset , feature_table, ext.len);
+ if (ret < 0) {
+ return ret;
+ }
+
+ *p_feature_table = feature_table;
+ }
+ break;
+
default:
/* unknown magic - save it in case we need to rewrite the header */
{
@@ -182,6 +195,24 @@ static void report_unsupported(BlockDriverState *bs, const
char *fmt, ...)
bs->device_name, "qcow2", msg);
}
+static void report_unsupported_feature(BlockDriverState *bs,
+ Qcow2Feature *table, uint64_t mask)
+{
+ while (table && table->name[0] != '\0') {
+ if (table->type == QCOW2_FEAT_TYPE_INCOMPATIBLE) {
+ if (mask & (1 << table->bit)) {
+ report_unsupported(bs, "%.46s",table->name);
+ mask &= ~(1 << table->bit);
+ }
+ }
+ table++;
+ }
+
+ if (mask) {
+ report_unsupported(bs, "Unknown incompatible feature: %" PRIx64, mask);
+ }
+}
+
static int qcow2_open(BlockDriverState *bs, int flags)
{
BDRVQcowState *s = bs->opaque;
@@ -245,14 +276,23 @@ static int qcow2_open(BlockDriverState *bs, int flags)
}
}
+ if (header.backing_file_offset) {
+ ext_end = header.backing_file_offset;
+ } else {
+ ext_end = 1 << header.cluster_bits;
+ }
+
/* Handle feature bits */
s->incompatible_features = header.incompatible_features;
s->compatible_features = header.compatible_features;
s->autoclear_features = header.autoclear_features;
if (s->incompatible_features != 0) {
- report_unsupported(bs, "incompatible features mask %" PRIx64,
- header.incompatible_features);
+ void *feature_table = NULL;
+ qcow2_read_extensions(bs, header.header_length, ext_end,
+ &feature_table);
+ report_unsupported_feature(bs, feature_table,
+ s->incompatible_features);
ret = -ENOTSUP;
goto fail;
}
@@ -343,12 +383,7 @@ static int qcow2_open(BlockDriverState *bs, int flags)
QLIST_INIT(&s->cluster_allocs);
/* read qcow2 extensions */
- if (header.backing_file_offset) {
- ext_end = header.backing_file_offset;
- } else {
- ext_end = s->cluster_size;
- }
- if (qcow2_read_extensions(bs, header.header_length, ext_end)) {
+ if (qcow2_read_extensions(bs, header.header_length, ext_end, NULL)) {
ret = -EINVAL;
goto fail;
}
@@ -912,6 +947,27 @@ int qcow2_update_header(BlockDriverState *bs)
buflen -= ret;
}
+ /* Feature table */
+ Qcow2Feature features[] = {
+ {
+ .type = QCOW2_FEAT_TYPE_INCOMPATIBLE,
+ .bit = 0,
+ .name = "Reference count recovery",
+ }, {
+ .type = QCOW2_FEAT_TYPE_INCOMPATIBLE,
+ .bit = 1,
+ .name = "Subclusters",
+ }
+ };
+
+ ret = header_ext_add(buf, QCOW2_EXT_MAGIC_FEATURE_TABLE,
+ features, sizeof(features), buflen);
+ if (ret < 0) {
+ goto fail;
+ }
+ buf += ret;
+ buflen -= ret;
+
/* Keep unknown header extensions */
QLIST_FOREACH(uext, &s->unknown_header_ext, next) {
ret = header_ext_add(buf, uext->magic, uext->data, uext->len, buflen);
diff --git a/block/qcow2.h b/block/qcow2.h
index 64cfa69..1adf01d 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -103,6 +103,18 @@ typedef struct Qcow2UnknownHeaderExtension {
uint8_t data[];
} Qcow2UnknownHeaderExtension;
+enum {
+ QCOW2_FEAT_TYPE_INCOMPATIBLE = 0,
+ QCOW2_FEAT_TYPE_COMPATIBLE = 1,
+ QCOW2_FEAT_TYPE_AUTOCLEAR = 2,
+};
+
+typedef struct Qcow2Feature {
+ uint8_t type;
+ uint8_t bit;
+ char name[46];
+} QEMU_PACKED Qcow2Feature;
+
typedef struct BDRVQcowState {
int cluster_bits;
int cluster_size;
--
1.7.6.5
- [Qemu-devel] [RFC PATCH 00/16] qcow2: Basic version 3 support, Kevin Wolf, 2012/03/27
- [Qemu-devel] [RFC PATCH 08/16] qcow2: Ignore reserved bits in refcount table entries, Kevin Wolf, 2012/03/27
- [Qemu-devel] [RFC PATCH 03/16] qcow2: Ignore reserved bits in count_contiguous_clusters(), Kevin Wolf, 2012/03/27
- [Qemu-devel] [RFC PATCH 05/16] qcow2: Ignore reserved bits in L1/L2 entries, Kevin Wolf, 2012/03/27
- [Qemu-devel] [RFC PATCH 12/16] qcow2: Support for feature table header extension,
Kevin Wolf <=
- [Qemu-devel] [RFC PATCH 01/16] Specification for qcow2 version 3, Kevin Wolf, 2012/03/27
- [Qemu-devel] [RFC PATCH 04/16] qcow2: Fail write_compressed when overwriting data, Kevin Wolf, 2012/03/27
- [Qemu-devel] [RFC PATCH 06/16] qcow2: Refactor qcow2_free_any_clusters, Kevin Wolf, 2012/03/27
- [Qemu-devel] [RFC PATCH 09/16] qcow2: Ignore reserved bits in check_refcounts, Kevin Wolf, 2012/03/27
- [Qemu-devel] [RFC PATCH 02/16] qcow2: Ignore reserved bits in get_cluster_offset, Kevin Wolf, 2012/03/27
- [Qemu-devel] [RFC PATCH 14/16] qemu-iotests: Test COW with zero clusters, Kevin Wolf, 2012/03/27
- [Qemu-devel] [RFC PATCH 11/16] qcow2: Support reading zero clusters, Kevin Wolf, 2012/03/27
- [Qemu-devel] [RFC PATCH 13/16] qemu-iotests: add a simple test for write_zeroes, Kevin Wolf, 2012/03/27
- [Qemu-devel] [RFC PATCH 15/16] qcow2: Zero write support, Kevin Wolf, 2012/03/27