BlockDriverState *bs = NULL;
BlockDriverState *data_bs = NULL;
const char *val;
+ bool keep_data_file = false;
+ BlockdevCreateOptionsQcow2 *qcow2_opts;
int ret;
/* Only the keyval visitor supports the dotted syntax needed for
qdict_put_str(qdict, BLOCK_OPT_COMPAT_LEVEL, "v3");
}
+ val = qdict_get_try_str(qdict, BLOCK_OPT_KEEP_DATA_FILE);
+ if (val) {
+ if (!strcmp(val, "on")) {
+ keep_data_file = true;
+ } else if (!strcmp(val, "off")) {
+ keep_data_file = false;
+ } else {
+ error_setg(errp,
+ "Invalid value '%s' for '%s': Must be 'on' or 'off'",
+ val, BLOCK_OPT_KEEP_DATA_FILE);
+ ret = -EINVAL;
+ goto finish;
+ }
+ qdict_del(qdict, BLOCK_OPT_KEEP_DATA_FILE);
+ }
+
/* Change legacy command line options into QMP ones */
static const QDictRenames opt_renames[] = {
{ BLOCK_OPT_BACKING_FILE, "backing-file" },
/* Create and open an external data file (protocol layer) */
val = qdict_get_try_str(qdict, BLOCK_OPT_DATA_FILE);
if (val) {
- ret = bdrv_co_create_file(val, opts, false, errp);
- if (ret < 0) {
- goto finish;
+ if (!keep_data_file) {
+ ret = bdrv_co_create_file(val, opts, false, errp);
+ if (ret < 0) {
+ goto finish;
+ }
}
data_bs = bdrv_co_open(val, NULL, NULL,
qdict_del(qdict, BLOCK_OPT_DATA_FILE);
qdict_put_str(qdict, "data-file", data_bs->node_name);
+ } else if (keep_data_file) {
+ error_setg(errp, "Must not use '%s=on' without '%s'",
+ BLOCK_OPT_KEEP_DATA_FILE, BLOCK_OPT_DATA_FILE);
+ ret = -EINVAL;
+ goto finish;
}
/* Set 'driver' and 'node' options */
goto finish;
}
+ qcow2_opts = &create_options->u.qcow2;
+
+ if (!qcow2_opts->has_preallocation) {
+ qcow2_opts->preallocation = PREALLOC_MODE_OFF;
+ }
+
+ if (keep_data_file &&
+ qcow2_opts->preallocation != PREALLOC_MODE_OFF &&
+ qcow2_opts->preallocation != PREALLOC_MODE_METADATA)
+ {
+ error_setg(errp, "Preallocating more than only metadata would "
+ "overwrite the external data file's content and is "
+ "therefore incompatible with '%s=on'",
+ BLOCK_OPT_KEEP_DATA_FILE);
+ ret = -EINVAL;
+ goto finish;
+ }
+
+ if (keep_data_file &&
+ qcow2_opts->preallocation == PREALLOC_MODE_OFF &&
+ !qcow2_opts->data_file_raw)
+ {
+ error_setg(errp, "'%s=on' requires '%s=metadata' or '%s=on', or the "
+ "file contents will not be visible",
+ BLOCK_OPT_KEEP_DATA_FILE,
+ BLOCK_OPT_PREALLOC,
+ BLOCK_OPT_DATA_FILE_RAW);
+ ret = -EINVAL;
+ goto finish;
+ }
+
/* Silently round up size */
create_options->u.qcow2.size = ROUND_UP(create_options->u.qcow2.size,
BDRV_SECTOR_SIZE);
if (ret < 0) {
bdrv_graph_co_rdlock();
bdrv_co_delete_file_noerr(bs);
- bdrv_co_delete_file_noerr(data_bs);
+ if (!keep_data_file) {
+ bdrv_co_delete_file_noerr(data_bs);
+ }
bdrv_graph_co_rdunlock();
} else {
ret = 0;
.help = "Compression method used for image cluster " \
"compression", \
.def_value_str = "zlib" \
+ }, \
+ { \
+ .name = BLOCK_OPT_KEEP_DATA_FILE, \
+ .type = QEMU_OPT_BOOL, \
+ .help = "Assume the external data file already exists and " \
+ "do not overwrite it" \
},
QCOW_COMMON_OPTIONS,
{ /* end of list */ }
encryption=<bool (on/off)> - Encrypt the image with format 'aes'. (Deprecated in favor of encrypt.format=aes)
extended_l2=<bool (on/off)> - Extended L2 tables
extent_size_hint=<size> - Extent size hint for the image file, 0 to disable
+ keep_data_file=<bool (on/off)> - Assume the external data file already exists and do not overwrite it
lazy_refcounts=<bool (on/off)> - Postpone refcount updates
nocow=<bool (on/off)> - Turn off copy-on-write (valid only on btrfs)
preallocation=<str> - Preallocation mode (allowed values: off, metadata, falloc, full)
encryption=<bool (on/off)> - Encrypt the image with format 'aes'. (Deprecated in favor of encrypt.format=aes)
extended_l2=<bool (on/off)> - Extended L2 tables
extent_size_hint=<size> - Extent size hint for the image file, 0 to disable
+ keep_data_file=<bool (on/off)> - Assume the external data file already exists and do not overwrite it
lazy_refcounts=<bool (on/off)> - Postpone refcount updates
nocow=<bool (on/off)> - Turn off copy-on-write (valid only on btrfs)
preallocation=<str> - Preallocation mode (allowed values: off, metadata, falloc, full)
encryption=<bool (on/off)> - Encrypt the image with format 'aes'. (Deprecated in favor of encrypt.format=aes)
extended_l2=<bool (on/off)> - Extended L2 tables
extent_size_hint=<size> - Extent size hint for the image file, 0 to disable
+ keep_data_file=<bool (on/off)> - Assume the external data file already exists and do not overwrite it
lazy_refcounts=<bool (on/off)> - Postpone refcount updates
nocow=<bool (on/off)> - Turn off copy-on-write (valid only on btrfs)
preallocation=<str> - Preallocation mode (allowed values: off, metadata, falloc, full)
encryption=<bool (on/off)> - Encrypt the image with format 'aes'. (Deprecated in favor of encrypt.format=aes)
extended_l2=<bool (on/off)> - Extended L2 tables
extent_size_hint=<size> - Extent size hint for the image file, 0 to disable
+ keep_data_file=<bool (on/off)> - Assume the external data file already exists and do not overwrite it
lazy_refcounts=<bool (on/off)> - Postpone refcount updates
nocow=<bool (on/off)> - Turn off copy-on-write (valid only on btrfs)
preallocation=<str> - Preallocation mode (allowed values: off, metadata, falloc, full)
encryption=<bool (on/off)> - Encrypt the image with format 'aes'. (Deprecated in favor of encrypt.format=aes)
extended_l2=<bool (on/off)> - Extended L2 tables
extent_size_hint=<size> - Extent size hint for the image file, 0 to disable
+ keep_data_file=<bool (on/off)> - Assume the external data file already exists and do not overwrite it
lazy_refcounts=<bool (on/off)> - Postpone refcount updates
nocow=<bool (on/off)> - Turn off copy-on-write (valid only on btrfs)
preallocation=<str> - Preallocation mode (allowed values: off, metadata, falloc, full)
encryption=<bool (on/off)> - Encrypt the image with format 'aes'. (Deprecated in favor of encrypt.format=aes)
extended_l2=<bool (on/off)> - Extended L2 tables
extent_size_hint=<size> - Extent size hint for the image file, 0 to disable
+ keep_data_file=<bool (on/off)> - Assume the external data file already exists and do not overwrite it
lazy_refcounts=<bool (on/off)> - Postpone refcount updates
nocow=<bool (on/off)> - Turn off copy-on-write (valid only on btrfs)
preallocation=<str> - Preallocation mode (allowed values: off, metadata, falloc, full)
encryption=<bool (on/off)> - Encrypt the image with format 'aes'. (Deprecated in favor of encrypt.format=aes)
extended_l2=<bool (on/off)> - Extended L2 tables
extent_size_hint=<size> - Extent size hint for the image file, 0 to disable
+ keep_data_file=<bool (on/off)> - Assume the external data file already exists and do not overwrite it
lazy_refcounts=<bool (on/off)> - Postpone refcount updates
nocow=<bool (on/off)> - Turn off copy-on-write (valid only on btrfs)
preallocation=<str> - Preallocation mode (allowed values: off, metadata, falloc, full)
encryption=<bool (on/off)> - Encrypt the image with format 'aes'. (Deprecated in favor of encrypt.format=aes)
extended_l2=<bool (on/off)> - Extended L2 tables
extent_size_hint=<size> - Extent size hint for the image file, 0 to disable
+ keep_data_file=<bool (on/off)> - Assume the external data file already exists and do not overwrite it
lazy_refcounts=<bool (on/off)> - Postpone refcount updates
nocow=<bool (on/off)> - Turn off copy-on-write (valid only on btrfs)
preallocation=<str> - Preallocation mode (allowed values: off, metadata, falloc, full)
encrypt.key-secret=<str> - ID of secret providing qcow AES key or LUKS passphrase
encryption=<bool (on/off)> - Encrypt the image with format 'aes'. (Deprecated in favor of encrypt.format=aes)
extended_l2=<bool (on/off)> - Extended L2 tables
+ keep_data_file=<bool (on/off)> - Assume the external data file already exists and do not overwrite it
lazy_refcounts=<bool (on/off)> - Postpone refcount updates
preallocation=<str> - Preallocation mode (allowed values: off, metadata, falloc, full)
refcount_bits=<num> - Width of a reference count entry in bits
encryption=<bool (on/off)> - Encrypt the image with format 'aes'. (Deprecated in favor of encrypt.format=aes)
extended_l2=<bool (on/off)> - Extended L2 tables
extent_size_hint=<size> - Extent size hint for the image file, 0 to disable
+ keep_data_file=<bool (on/off)> - Assume the external data file already exists and do not overwrite it
lazy_refcounts=<bool (on/off)> - Postpone refcount updates
nocow=<bool (on/off)> - Turn off copy-on-write (valid only on btrfs)
preallocation=<str> - Preallocation mode (allowed values: off, metadata, falloc, full)
encryption=<bool (on/off)> - Encrypt the image with format 'aes'. (Deprecated in favor of encrypt.format=aes)
extended_l2=<bool (on/off)> - Extended L2 tables
extent_size_hint=<size> - Extent size hint for the image file, 0 to disable
+ keep_data_file=<bool (on/off)> - Assume the external data file already exists and do not overwrite it
lazy_refcounts=<bool (on/off)> - Postpone refcount updates
nocow=<bool (on/off)> - Turn off copy-on-write (valid only on btrfs)
preallocation=<str> - Preallocation mode (allowed values: off, metadata, falloc, full)
encryption=<bool (on/off)> - Encrypt the image with format 'aes'. (Deprecated in favor of encrypt.format=aes)
extended_l2=<bool (on/off)> - Extended L2 tables
extent_size_hint=<size> - Extent size hint for the image file, 0 to disable
+ keep_data_file=<bool (on/off)> - Assume the external data file already exists and do not overwrite it
lazy_refcounts=<bool (on/off)> - Postpone refcount updates
nocow=<bool (on/off)> - Turn off copy-on-write (valid only on btrfs)
preallocation=<str> - Preallocation mode (allowed values: off, metadata, falloc, full)
encryption=<bool (on/off)> - Encrypt the image with format 'aes'. (Deprecated in favor of encrypt.format=aes)
extended_l2=<bool (on/off)> - Extended L2 tables
extent_size_hint=<size> - Extent size hint for the image file, 0 to disable
+ keep_data_file=<bool (on/off)> - Assume the external data file already exists and do not overwrite it
lazy_refcounts=<bool (on/off)> - Postpone refcount updates
nocow=<bool (on/off)> - Turn off copy-on-write (valid only on btrfs)
preallocation=<str> - Preallocation mode (allowed values: off, metadata, falloc, full)
encryption=<bool (on/off)> - Encrypt the image with format 'aes'. (Deprecated in favor of encrypt.format=aes)
extended_l2=<bool (on/off)> - Extended L2 tables
extent_size_hint=<size> - Extent size hint for the image file, 0 to disable
+ keep_data_file=<bool (on/off)> - Assume the external data file already exists and do not overwrite it
lazy_refcounts=<bool (on/off)> - Postpone refcount updates
nocow=<bool (on/off)> - Turn off copy-on-write (valid only on btrfs)
preallocation=<str> - Preallocation mode (allowed values: off, metadata, falloc, full)
encryption=<bool (on/off)> - Encrypt the image with format 'aes'. (Deprecated in favor of encrypt.format=aes)
extended_l2=<bool (on/off)> - Extended L2 tables
extent_size_hint=<size> - Extent size hint for the image file, 0 to disable
+ keep_data_file=<bool (on/off)> - Assume the external data file already exists and do not overwrite it
lazy_refcounts=<bool (on/off)> - Postpone refcount updates
nocow=<bool (on/off)> - Turn off copy-on-write (valid only on btrfs)
preallocation=<str> - Preallocation mode (allowed values: off, metadata, falloc, full)
encryption=<bool (on/off)> - Encrypt the image with format 'aes'. (Deprecated in favor of encrypt.format=aes)
extended_l2=<bool (on/off)> - Extended L2 tables
extent_size_hint=<size> - Extent size hint for the image file, 0 to disable
+ keep_data_file=<bool (on/off)> - Assume the external data file already exists and do not overwrite it
lazy_refcounts=<bool (on/off)> - Postpone refcount updates
nocow=<bool (on/off)> - Turn off copy-on-write (valid only on btrfs)
preallocation=<str> - Preallocation mode (allowed values: off, metadata, falloc, full)
encryption=<bool (on/off)> - Encrypt the image with format 'aes'. (Deprecated in favor of encrypt.format=aes)
extended_l2=<bool (on/off)> - Extended L2 tables
extent_size_hint=<size> - Extent size hint for the image file, 0 to disable
+ keep_data_file=<bool (on/off)> - Assume the external data file already exists and do not overwrite it
lazy_refcounts=<bool (on/off)> - Postpone refcount updates
nocow=<bool (on/off)> - Turn off copy-on-write (valid only on btrfs)
preallocation=<str> - Preallocation mode (allowed values: off, metadata, falloc, full)
encrypt.key-secret=<str> - ID of secret providing qcow AES key or LUKS passphrase
encryption=<bool (on/off)> - Encrypt the image with format 'aes'. (Deprecated in favor of encrypt.format=aes)
extended_l2=<bool (on/off)> - Extended L2 tables
+ keep_data_file=<bool (on/off)> - Assume the external data file already exists and do not overwrite it
lazy_refcounts=<bool (on/off)> - Postpone refcount updates
preallocation=<str> - Preallocation mode (allowed values: off, metadata, falloc, full)
refcount_bits=<num> - Width of a reference count entry in bits