aboutsummaryrefslogtreecommitdiff
path: root/block
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2018-03-26 17:13:31 +0100
committerPeter Maydell <peter.maydell@linaro.org>2018-03-26 17:13:31 +0100
commit62a2b55e8d098d91908b17fc37cb1a4f2a854f8f (patch)
tree5e2a810f32f3467bf78fcf4037e80aa03b5b8130 /block
parent7b93d78a04aa242d377ae213b79db6c319c71847 (diff)
parent0b7e7f66813a7e346e12d47be977a32a530a6316 (diff)
downloadqemu-62a2b55e8d098d91908b17fc37cb1a4f2a854f8f.zip
qemu-62a2b55e8d098d91908b17fc37cb1a4f2a854f8f.tar.gz
qemu-62a2b55e8d098d91908b17fc37cb1a4f2a854f8f.tar.bz2
Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging
Block layer patches # gpg: Signature made Mon 26 Mar 2018 15:33:01 BST # gpg: using RSA key 7F09B272C88F2FD6 # gpg: Good signature from "Kevin Wolf <kwolf@redhat.com>" # Primary key fingerprint: DC3D EB15 9A9A F95D 3D74 56FE 7F09 B272 C88F 2FD6 * remotes/kevin/tags/for-upstream: qemu-iotests: Test vhdx image creation with QMP vhdx: Check for 4 GB maximum log size on creation vhdx: Don't use error_setg_errno() with constant errno vhdx: Require power-of-two block size on create qemu-iotests: Test parallels image creation with QMP parallels: Check maximum cluster size on create qemu-iotests: Test invalid resize on luks luks: Turn another invalid assertion into check qemu-iotests: Enable 025 for luks qemu-iotests: Test vdi image creation with QMP vdi: Fix build with CONFIG_VDI_DEBUG vdi: Change 'static' create option to 'preallocation' in QMP qcow2: Reset free_cluster_index when allocating a new refcount block include/block/block_int: Document protocol related functions block/blkreplay: Remove protocol-related fields block/throttle: Remove protocol-related fields block/quorum: Remove protocol-related fields block/replication: Remove protocol_name field iotests: 163 is not quick Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'block')
-rwxr-xr-xblock/blkreplay.c3
-rw-r--r--block/crypto.c6
-rw-r--r--block/parallels.c5
-rw-r--r--block/qcow2-refcount.c7
-rw-r--r--block/quorum.c3
-rw-r--r--block/replication.c1
-rw-r--r--block/throttle.c3
-rw-r--r--block/vdi.c46
-rw-r--r--block/vhdx.c17
9 files changed, 64 insertions, 27 deletions
diff --git a/block/blkreplay.c b/block/blkreplay.c
index 61e44a1..fe5a9b4 100755
--- a/block/blkreplay.c
+++ b/block/blkreplay.c
@@ -129,10 +129,9 @@ static int coroutine_fn blkreplay_co_flush(BlockDriverState *bs)
static BlockDriver bdrv_blkreplay = {
.format_name = "blkreplay",
- .protocol_name = "blkreplay",
.instance_size = 0,
- .bdrv_file_open = blkreplay_open,
+ .bdrv_open = blkreplay_open,
.bdrv_close = blkreplay_close,
.bdrv_child_perm = bdrv_filter_default_perms,
.bdrv_getlength = blkreplay_getlength,
diff --git a/block/crypto.c b/block/crypto.c
index e0b8856..bc6c7e3 100644
--- a/block/crypto.c
+++ b/block/crypto.c
@@ -357,7 +357,11 @@ static int block_crypto_truncate(BlockDriverState *bs, int64_t offset,
BlockCrypto *crypto = bs->opaque;
uint64_t payload_offset =
qcrypto_block_get_payload_offset(crypto->block);
- assert(payload_offset < (INT64_MAX - offset));
+
+ if (payload_offset > INT64_MAX - offset) {
+ error_setg(errp, "The requested file size is too large");
+ return -EFBIG;
+ }
offset += payload_offset;
diff --git a/block/parallels.c b/block/parallels.c
index e2515de..799215e 100644
--- a/block/parallels.c
+++ b/block/parallels.c
@@ -526,6 +526,11 @@ static int coroutine_fn parallels_co_create(BlockdevCreateOptions* opts,
cl_size = DEFAULT_CLUSTER_SIZE;
}
+ /* XXX What is the real limit here? This is an insanely large maximum. */
+ if (cl_size >= INT64_MAX / MAX_PARALLELS_IMAGE_FACTOR) {
+ error_setg(errp, "Cluster size is too large");
+ return -EINVAL;
+ }
if (total_size >= MAX_PARALLELS_IMAGE_FACTOR * cl_size) {
error_setg(errp, "Image size is too large for this cluster size");
return -E2BIG;
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index 362deaf..6b8b635 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -839,6 +839,13 @@ static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs,
qcow2_cache_put(s->refcount_block_cache, &refcount_block);
}
ret = alloc_refcount_block(bs, cluster_index, &refcount_block);
+ /* If the caller needs to restart the search for free clusters,
+ * try the same ones first to see if they're still free. */
+ if (ret == -EAGAIN) {
+ if (s->free_cluster_index > (start >> s->cluster_bits)) {
+ s->free_cluster_index = (start >> s->cluster_bits);
+ }
+ }
if (ret < 0) {
goto fail;
}
diff --git a/block/quorum.c b/block/quorum.c
index 14333c1..cfe484a 100644
--- a/block/quorum.c
+++ b/block/quorum.c
@@ -1098,11 +1098,10 @@ static void quorum_refresh_filename(BlockDriverState *bs, QDict *options)
static BlockDriver bdrv_quorum = {
.format_name = "quorum",
- .protocol_name = "quorum",
.instance_size = sizeof(BDRVQuorumState),
- .bdrv_file_open = quorum_open,
+ .bdrv_open = quorum_open,
.bdrv_close = quorum_close,
.bdrv_refresh_filename = quorum_refresh_filename,
diff --git a/block/replication.c b/block/replication.c
index f98ef09..6c0c718 100644
--- a/block/replication.c
+++ b/block/replication.c
@@ -703,7 +703,6 @@ static void replication_stop(ReplicationState *rs, bool failover, Error **errp)
BlockDriver bdrv_replication = {
.format_name = "replication",
- .protocol_name = "replication",
.instance_size = sizeof(BDRVReplicationState),
.bdrv_open = replication_open,
diff --git a/block/throttle.c b/block/throttle.c
index 5f4d43d..95ed06a 100644
--- a/block/throttle.c
+++ b/block/throttle.c
@@ -215,10 +215,9 @@ static void coroutine_fn throttle_co_drain_end(BlockDriverState *bs)
static BlockDriver bdrv_throttle = {
.format_name = "throttle",
- .protocol_name = "throttle",
.instance_size = sizeof(ThrottleGroupMember),
- .bdrv_file_open = throttle_open,
+ .bdrv_open = throttle_open,
.bdrv_close = throttle_close,
.bdrv_co_flush = throttle_co_flush,
diff --git a/block/vdi.c b/block/vdi.c
index d939b03..4a2d1ff 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -235,7 +235,6 @@ static void vdi_header_to_le(VdiHeader *header)
qemu_uuid_bswap(&header->uuid_parent);
}
-#if defined(CONFIG_VDI_DEBUG)
static void vdi_header_print(VdiHeader *header)
{
char uuid[37];
@@ -257,16 +256,15 @@ static void vdi_header_print(VdiHeader *header)
logout("block extra 0x%04x\n", header->block_extra);
logout("blocks tot. 0x%04x\n", header->blocks_in_image);
logout("blocks all. 0x%04x\n", header->blocks_allocated);
- uuid_unparse(header->uuid_image, uuid);
+ qemu_uuid_unparse(&header->uuid_image, uuid);
logout("uuid image %s\n", uuid);
- uuid_unparse(header->uuid_last_snap, uuid);
+ qemu_uuid_unparse(&header->uuid_last_snap, uuid);
logout("uuid snap %s\n", uuid);
- uuid_unparse(header->uuid_link, uuid);
+ qemu_uuid_unparse(&header->uuid_link, uuid);
logout("uuid link %s\n", uuid);
- uuid_unparse(header->uuid_parent, uuid);
+ qemu_uuid_unparse(&header->uuid_parent, uuid);
logout("uuid parent %s\n", uuid);
}
-#endif
static int coroutine_fn vdi_co_check(BlockDriverState *bs, BdrvCheckResult *res,
BdrvCheckMode fix)
@@ -387,9 +385,9 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags,
}
vdi_header_to_cpu(&header);
-#if defined(CONFIG_VDI_DEBUG)
- vdi_header_print(&header);
-#endif
+ if (VDI_DEBUG) {
+ vdi_header_print(&header);
+ }
if (header.disk_size > VDI_DISK_SIZE_MAX) {
error_setg(errp, "Unsupported VDI image size (size is 0x%" PRIx64
@@ -728,7 +726,7 @@ static int coroutine_fn vdi_co_do_create(BlockdevCreateOptions *create_options,
int ret = 0;
uint64_t bytes = 0;
uint32_t blocks;
- uint32_t image_type = VDI_TYPE_DYNAMIC;
+ uint32_t image_type;
VdiHeader header;
size_t i;
size_t bmap_size;
@@ -744,9 +742,22 @@ static int coroutine_fn vdi_co_do_create(BlockdevCreateOptions *create_options,
/* Validate options and set default values */
bytes = vdi_opts->size;
- if (vdi_opts->q_static) {
+
+ if (!vdi_opts->has_preallocation) {
+ vdi_opts->preallocation = PREALLOC_MODE_OFF;
+ }
+ switch (vdi_opts->preallocation) {
+ case PREALLOC_MODE_OFF:
+ image_type = VDI_TYPE_DYNAMIC;
+ break;
+ case PREALLOC_MODE_METADATA:
image_type = VDI_TYPE_STATIC;
+ break;
+ default:
+ error_setg(errp, "Preallocation mode not supported for vdi");
+ return -EINVAL;
}
+
#ifndef CONFIG_VDI_STATIC_IMAGE
if (image_type == VDI_TYPE_STATIC) {
ret = -ENOTSUP;
@@ -812,9 +823,9 @@ static int coroutine_fn vdi_co_do_create(BlockdevCreateOptions *create_options,
qemu_uuid_generate(&header.uuid_image);
qemu_uuid_generate(&header.uuid_last_snap);
/* There is no need to set header.uuid_link or header.uuid_parent here. */
-#if defined(CONFIG_VDI_DEBUG)
- vdi_header_print(&header);
-#endif
+ if (VDI_DEBUG) {
+ vdi_header_print(&header);
+ }
vdi_header_to_le(&header);
ret = blk_pwrite(blk, offset, &header, sizeof(header), 0);
if (ret < 0) {
@@ -874,6 +885,7 @@ static int coroutine_fn vdi_co_create_opts(const char *filename, QemuOpts *opts,
BlockdevCreateOptions *create_options = NULL;
BlockDriverState *bs_file = NULL;
uint64_t block_size = DEFAULT_CLUSTER_SIZE;
+ bool is_static = false;
Visitor *v;
Error *local_err = NULL;
int ret;
@@ -895,6 +907,9 @@ static int coroutine_fn vdi_co_create_opts(const char *filename, QemuOpts *opts,
goto done;
}
#endif
+ if (qemu_opt_get_bool_del(opts, BLOCK_OPT_STATIC, false)) {
+ is_static = true;
+ }
qdict = qemu_opts_to_qdict_filtered(opts, NULL, &vdi_create_opts, true);
@@ -913,6 +928,9 @@ static int coroutine_fn vdi_co_create_opts(const char *filename, QemuOpts *opts,
qdict_put_str(qdict, "driver", "vdi");
qdict_put_str(qdict, "file", bs_file->node_name);
+ if (is_static) {
+ qdict_put_str(qdict, "preallocation", "metadata");
+ }
/* Get the QAPI object */
v = qobject_input_visitor_new_keyval(QOBJECT(qdict));
diff --git a/block/vhdx.c b/block/vhdx.c
index d2c54b7..6ac0424 100644
--- a/block/vhdx.c
+++ b/block/vhdx.c
@@ -1822,17 +1822,21 @@ static int coroutine_fn vhdx_co_create(BlockdevCreateOptions *opts,
/* Validate options and set default values */
image_size = vhdx_opts->size;
if (image_size > VHDX_MAX_IMAGE_SIZE) {
- error_setg_errno(errp, EINVAL, "Image size too large; max of 64TB");
+ error_setg(errp, "Image size too large; max of 64TB");
return -EINVAL;
}
if (!vhdx_opts->has_log_size) {
log_size = DEFAULT_LOG_SIZE;
} else {
+ if (vhdx_opts->log_size > UINT32_MAX) {
+ error_setg(errp, "Log size must be smaller than 4 GB");
+ return -EINVAL;
+ }
log_size = vhdx_opts->log_size;
}
if (log_size < MiB || (log_size % MiB) != 0) {
- error_setg_errno(errp, EINVAL, "Log size must be a multiple of 1 MB");
+ error_setg(errp, "Log size must be a multiple of 1 MB");
return -EINVAL;
}
@@ -1874,12 +1878,15 @@ static int coroutine_fn vhdx_co_create(BlockdevCreateOptions *opts,
}
if (block_size < MiB || (block_size % MiB) != 0) {
- error_setg_errno(errp, EINVAL, "Block size must be a multiple of 1 MB");
+ error_setg(errp, "Block size must be a multiple of 1 MB");
+ return -EINVAL;
+ }
+ if (!is_power_of_2(block_size)) {
+ error_setg(errp, "Block size must be a power of two");
return -EINVAL;
}
if (block_size > VHDX_BLOCK_SIZE_MAX) {
- error_setg_errno(errp, EINVAL, "Block size must not exceed %d",
- VHDX_BLOCK_SIZE_MAX);
+ error_setg(errp, "Block size must not exceed %d", VHDX_BLOCK_SIZE_MAX);
return -EINVAL;
}