[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 50/69] qcow2: Put qcow2_upgrade() into its own function
From: |
Max Reitz |
Subject: |
[PULL 50/69] qcow2: Put qcow2_upgrade() into its own function |
Date: |
Mon, 28 Oct 2019 13:14:42 +0100 |
This does not make sense right now, but it will make sense once we need
to do more than to just update s->qcow_version.
Signed-off-by: Max Reitz <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Message-id: address@hidden
Signed-off-by: Max Reitz <address@hidden>
---
block/qcow2.c | 43 ++++++++++++++++++++++++++++++++++++++-----
1 file changed, 38 insertions(+), 5 deletions(-)
diff --git a/block/qcow2.c b/block/qcow2.c
index 60ed084e5c..af08757055 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -4912,12 +4912,46 @@ static int qcow2_downgrade(BlockDriverState *bs, int
target_version,
return 0;
}
+/*
+ * Upgrades an image's version. While newer versions encompass all
+ * features of older versions, some things may have to be presented
+ * differently.
+ */
+static int qcow2_upgrade(BlockDriverState *bs, int target_version,
+ BlockDriverAmendStatusCB *status_cb, void *cb_opaque,
+ Error **errp)
+{
+ BDRVQcow2State *s = bs->opaque;
+ int current_version = s->qcow_version;
+ int ret;
+
+ /* This is qcow2_upgrade(), not qcow2_downgrade() */
+ assert(target_version > current_version);
+
+ /* There are no other versions (yet) that you can upgrade to */
+ assert(target_version == 3);
+
+ status_cb(bs, 0, 1, cb_opaque);
+
+ s->qcow_version = target_version;
+ ret = qcow2_update_header(bs);
+ if (ret < 0) {
+ s->qcow_version = current_version;
+ error_setg_errno(errp, -ret, "Failed to update the image header");
+ return ret;
+ }
+ status_cb(bs, 1, 1, cb_opaque);
+
+ return 0;
+}
+
typedef enum Qcow2AmendOperation {
/* This is the value Qcow2AmendHelperCBInfo::last_operation will be
* statically initialized to so that the helper CB can discern the first
* invocation from an operation change */
QCOW2_NO_OPERATION = 0,
+ QCOW2_UPGRADING,
QCOW2_CHANGING_REFCOUNT_ORDER,
QCOW2_DOWNGRADING,
} Qcow2AmendOperation;
@@ -5100,17 +5134,16 @@ static int qcow2_amend_options(BlockDriverState *bs,
QemuOpts *opts,
helper_cb_info = (Qcow2AmendHelperCBInfo){
.original_status_cb = status_cb,
.original_cb_opaque = cb_opaque,
- .total_operations = (new_version < old_version)
+ .total_operations = (new_version != old_version)
+ (s->refcount_bits != refcount_bits)
};
/* Upgrade first (some features may require compat=1.1) */
if (new_version > old_version) {
- s->qcow_version = new_version;
- ret = qcow2_update_header(bs);
+ helper_cb_info.current_operation = QCOW2_UPGRADING;
+ ret = qcow2_upgrade(bs, new_version, &qcow2_amend_helper_cb,
+ &helper_cb_info, errp);
if (ret < 0) {
- s->qcow_version = old_version;
- error_setg_errno(errp, -ret, "Failed to update the image header");
return ret;
}
}
--
2.21.0
- [PULL 40/69] block/block-copy: add memory limit, (continued)
- [PULL 40/69] block/block-copy: add memory limit, Max Reitz, 2019/10/28
- [PULL 41/69] block/block-copy: increase buffered copy request, Max Reitz, 2019/10/28
- [PULL 42/69] block/nvme: add support for write zeros, Max Reitz, 2019/10/28
- [PULL 43/69] block/nvme: add support for discard, Max Reitz, 2019/10/28
- [PULL 44/69] mirror: Do not dereference invalid pointers, Max Reitz, 2019/10/28
- [PULL 45/69] include: Move endof() up from hw/virtio/virtio.h, Max Reitz, 2019/10/28
- [PULL 46/69] qcow2: Use endof(), Max Reitz, 2019/10/28
- [PULL 49/69] qcow2: Make qcow2_write_snapshots() public, Max Reitz, 2019/10/28
- [PULL 47/69] qcow2: Add Error ** to qcow2_read_snapshots(), Max Reitz, 2019/10/28
- [PULL 51/69] qcow2: Write v3-compliant snapshot list on upgrade, Max Reitz, 2019/10/28
- [PULL 50/69] qcow2: Put qcow2_upgrade() into its own function,
Max Reitz <=
- [PULL 53/69] qcow2: Add qcow2_check_fix_snapshot_table(), Max Reitz, 2019/10/28
- [PULL 48/69] qcow2: Keep unknown extra snapshot data, Max Reitz, 2019/10/28
- [PULL 62/69] block/cor: Drop cor_co_truncate(), Max Reitz, 2019/10/28
- [PULL 59/69] iotests: Add peek_file* functions, Max Reitz, 2019/10/28
- [PULL 52/69] qcow2: Separate qcow2_check_read_snapshot_table(), Max Reitz, 2019/10/28
- [PULL 54/69] qcow2: Fix broken snapshot table entries, Max Reitz, 2019/10/28
- [PULL 57/69] qcow2: Repair snapshot table with too many entries, Max Reitz, 2019/10/28
- [PULL 55/69] qcow2: Keep track of the snapshot table length, Max Reitz, 2019/10/28
- [PULL 58/69] qcow2: Fix v3 snapshot table entry compliancy, Max Reitz, 2019/10/28
- [PULL 61/69] block: Handle filter truncation like native impl., Max Reitz, 2019/10/28