[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 01/21] qcow2: Add two new fields to BDRVQcowState
From: |
Max Reitz |
Subject: |
[Qemu-devel] [PATCH v2 01/21] qcow2: Add two new fields to BDRVQcowState |
Date: |
Fri, 14 Nov 2014 14:05:54 +0100 |
Add two new fields regarding refcount information (the bit width of
every entry and the maximum refcount value) to the BDRVQcowState.
Signed-off-by: Max Reitz <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
---
block/qcow2-refcount.c | 2 +-
block/qcow2.c | 9 +++++++++
block/qcow2.h | 2 ++
3 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index 9afdb40..6016211 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -584,7 +584,7 @@ static int QEMU_WARN_UNUSED_RESULT
update_refcount(BlockDriverState *bs,
refcount = be16_to_cpu(refcount_block[block_index]);
refcount += addend;
- if (refcount < 0 || refcount > 0xffff) {
+ if (refcount < 0 || refcount > s->refcount_max) {
ret = -EINVAL;
goto fail;
}
diff --git a/block/qcow2.c b/block/qcow2.c
index d120494..f57aff9 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -684,6 +684,15 @@ static int qcow2_open(BlockDriverState *bs, QDict
*options, int flags,
goto fail;
}
s->refcount_order = header.refcount_order;
+ s->refcount_bits = 1 << s->refcount_order;
+ if (s->refcount_order < 6) {
+ s->refcount_max = (UINT64_C(1) << s->refcount_bits) - 1;
+ } else {
+ /* The above shift would overflow with s->refcount_bits == 64;
+ * furthermore, we do not want to use UINT64_MAX because refcounts will
+ * be passed around in int64_ts (negative values for -errno) */
+ s->refcount_max = INT64_MAX;
+ }
if (header.crypt_method > QCOW_CRYPT_AES) {
error_setg(errp, "Unsupported encryption method: %" PRIu32,
diff --git a/block/qcow2.h b/block/qcow2.h
index 6e39a1b..4d8c902 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -258,6 +258,8 @@ typedef struct BDRVQcowState {
int qcow_version;
bool use_lazy_refcounts;
int refcount_order;
+ int refcount_bits;
+ uint64_t refcount_max;
bool discard_passthrough[QCOW2_DISCARD_MAX];
--
1.9.3
- [Qemu-devel] [PATCH v2 00/21] qcow2: Support refcount orders != 4, Max Reitz, 2014/11/14
- [Qemu-devel] [PATCH v2 01/21] qcow2: Add two new fields to BDRVQcowState,
Max Reitz <=
- [Qemu-devel] [PATCH v2 02/21] qcow2: Add refcount_width to format-specific info, Max Reitz, 2014/11/14
- [Qemu-devel] [PATCH v2 03/21] qcow2: Use 64 bits for refcount values, Max Reitz, 2014/11/14
- [Qemu-devel] [PATCH v2 04/21] qcow2: Respect error in qcow2_alloc_bytes(), Max Reitz, 2014/11/14
- [Qemu-devel] [PATCH v2 05/21] qcow2: Refcount overflow and qcow2_alloc_bytes(), Max Reitz, 2014/11/14
- [Qemu-devel] [PATCH v2 06/21] qcow2: Helper for refcount array reallocation, Max Reitz, 2014/11/14
- [Qemu-devel] [PATCH v2 07/21] qcow2: Helper function for refcount modification, Max Reitz, 2014/11/14