diff options
author | Kevin Wolf <kwolf@redhat.com> | 2019-01-29 17:13:57 +0100 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2019-03-08 12:26:46 +0100 |
commit | 0e8c08be276637a7339a05a4646b6eb8428ee802 (patch) | |
tree | b6ff1569405f5902c9f0b49627548b6ffdf76355 /block/qcow2.c | |
parent | e9f5b6deaa865e5265327de42b77553840c94880 (diff) | |
download | qemu-0e8c08be276637a7339a05a4646b6eb8428ee802.zip qemu-0e8c08be276637a7339a05a4646b6eb8428ee802.tar.gz qemu-0e8c08be276637a7339a05a4646b6eb8428ee802.tar.bz2 |
qcow2: Add basic data-file infrastructure
This adds a .bdrv_open option to specify the external data file node.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block/qcow2.c')
-rw-r--r-- | block/qcow2.c | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/block/qcow2.c b/block/qcow2.c index f048763..ddbf873 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1453,8 +1453,31 @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options, goto fail; } - /* TODO Open external data file */ - s->data_file = bs->file; + /* Open external data file */ + s->data_file = bdrv_open_child(NULL, options, "data-file", bs, &child_file, + true, &local_err); + if (local_err) { + error_propagate(errp, local_err); + ret = -EINVAL; + goto fail; + } + + if (s->incompatible_features & QCOW2_INCOMPAT_DATA_FILE) { + if (!s->data_file) { + error_setg(errp, "'data-file' is required for this image"); + ret = -EINVAL; + goto fail; + } + } else { + if (s->data_file) { + error_setg(errp, "'data-file' can only be set for images with an " + "external data file"); + ret = -EINVAL; + goto fail; + } else { + s->data_file = bs->file; + } + } /* qcow2_read_extension may have set up the crypto context * if the crypt method needs a header region, some methods @@ -1627,6 +1650,9 @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options, return ret; fail: + if (has_data_file(bs)) { + bdrv_unref_child(bs, s->data_file); + } g_free(s->unknown_header_fields); cleanup_unknown_header_ext(bs); qcow2_free_snapshots(bs); @@ -2246,6 +2272,10 @@ static void qcow2_close(BlockDriverState *bs) g_free(s->image_backing_file); g_free(s->image_backing_format); + if (has_data_file(bs)) { + bdrv_unref_child(bs, s->data_file); + } + qcow2_refcount_close(bs); qcow2_free_snapshots(bs); } |