Skip to content

Commit eb2c66b

Browse files
committed
Merge remote-tracking branch 'remotes/maxreitz/tags/pull-block-2020-07-06' into staging
Block patches for 5.1: - LUKS keyslot amendment (+ patches to make the iotests pass on non-Linux systems, and to keep the tests passing for qcow v1, and to skip LUKS tests (including qcow2 LUKS) when the built qemu does not support it) - Refactoring in the block layer: Drop the basically unnecessary unallocated_blocks_are_zero field from BlockDriverInfo - Fix qcow2 preallocation when the image size is not a multiple of the cluster size - Fix in block-copy code # gpg: Signature made Mon 06 Jul 2020 11:02:53 BST # gpg: using RSA key 91BEB60A30DB3E8857D11829F407DB0061D5CF40 # gpg: issuer "[email protected]" # gpg: Good signature from "Max Reitz <[email protected]>" [full] # Primary key fingerprint: 91BE B60A 30DB 3E88 57D1 1829 F407 DB00 61D5 CF40 * remotes/maxreitz/tags/pull-block-2020-07-06: (31 commits) qed: Simplify backing reads block: drop unallocated_blocks_are_zero block/vhdx: drop unallocated_blocks_are_zero block/file-posix: drop unallocated_blocks_are_zero block/iscsi: drop unallocated_blocks_are_zero block/crypto: drop unallocated_blocks_are_zero block/vpc: return ZERO block-status when appropriate block/vdi: return ZERO block-status when appropriate block: inline bdrv_unallocated_blocks_are_zero() qemu-img: convert: don't use unallocated_blocks_are_zero iotests: add tests for blockdev-amend block/qcow2: implement blockdev-amend block/crypto: implement blockdev-amend block/core: add generic infrastructure for x-blockdev-amend qmp command iotests: qemu-img tests for luks key management block/qcow2: extend qemu-img amend interface with crypto options block/crypto: implement the encryption key management block/crypto: rename two functions block/amend: refactor qcow2 amend options block/amend: separate amend and create options for qemu-img ... Signed-off-by: Peter Maydell <[email protected]>
2 parents c8eaf81 + 365fed5 commit eb2c66b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+3103
-632
lines changed

block.c

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5408,21 +5408,6 @@ int bdrv_has_zero_init(BlockDriverState *bs)
54085408
return 0;
54095409
}
54105410

5411-
bool bdrv_unallocated_blocks_are_zero(BlockDriverState *bs)
5412-
{
5413-
BlockDriverInfo bdi;
5414-
5415-
if (bs->backing) {
5416-
return false;
5417-
}
5418-
5419-
if (bdrv_get_info(bs, &bdi) == 0) {
5420-
return bdi.unallocated_blocks_are_zero;
5421-
}
5422-
5423-
return false;
5424-
}
5425-
54265411
bool bdrv_can_write_zeroes_with_unmap(BlockDriverState *bs)
54275412
{
54285413
if (!(bs->open_flags & BDRV_O_UNMAP)) {
@@ -6482,6 +6467,7 @@ void bdrv_remove_aio_context_notifier(BlockDriverState *bs,
64826467

64836468
int bdrv_amend_options(BlockDriverState *bs, QemuOpts *opts,
64846469
BlockDriverAmendStatusCB *status_cb, void *cb_opaque,
6470+
bool force,
64856471
Error **errp)
64866472
{
64876473
if (!bs->drv) {
@@ -6493,7 +6479,8 @@ int bdrv_amend_options(BlockDriverState *bs, QemuOpts *opts,
64936479
bs->drv->format_name);
64946480
return -ENOTSUP;
64956481
}
6496-
return bs->drv->bdrv_amend_options(bs, opts, status_cb, cb_opaque, errp);
6482+
return bs->drv->bdrv_amend_options(bs, opts, status_cb,
6483+
cb_opaque, force, errp);
64976484
}
64986485

64996486
/*

block/Makefile.objs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ block-obj-$(CONFIG_WIN32) += file-win32.o win32-aio.o
1919
block-obj-$(CONFIG_POSIX) += file-posix.o
2020
block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o
2121
block-obj-$(CONFIG_LINUX_IO_URING) += io_uring.o
22-
block-obj-y += null.o mirror.o commit.o io.o create.o
22+
block-obj-y += null.o mirror.o commit.o io.o create.o amend.o
2323
block-obj-y += throttle-groups.o
2424
block-obj-$(CONFIG_LINUX) += nvme.o
2525

block/amend.c

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
* Block layer code related to image options amend
3+
*
4+
* Copyright (c) 2018 Kevin Wolf <[email protected]>
5+
* Copyright (c) 2020 Red Hat. Inc
6+
*
7+
* Heavily based on create.c
8+
*
9+
* Permission is hereby granted, free of charge, to any person obtaining a copy
10+
* of this software and associated documentation files (the "Software"), to deal
11+
* in the Software without restriction, including without limitation the rights
12+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
* copies of the Software, and to permit persons to whom the Software is
14+
* furnished to do so, subject to the following conditions:
15+
*
16+
* The above copyright notice and this permission notice shall be included in
17+
* all copies or substantial portions of the Software.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
* THE SOFTWARE.
26+
*/
27+
28+
#include "qemu/osdep.h"
29+
#include "block/block_int.h"
30+
#include "qemu/job.h"
31+
#include "qemu/main-loop.h"
32+
#include "qapi/qapi-commands-block-core.h"
33+
#include "qapi/qapi-visit-block-core.h"
34+
#include "qapi/clone-visitor.h"
35+
#include "qapi/error.h"
36+
37+
typedef struct BlockdevAmendJob {
38+
Job common;
39+
BlockdevAmendOptions *opts;
40+
BlockDriverState *bs;
41+
bool force;
42+
} BlockdevAmendJob;
43+
44+
static int coroutine_fn blockdev_amend_run(Job *job, Error **errp)
45+
{
46+
BlockdevAmendJob *s = container_of(job, BlockdevAmendJob, common);
47+
int ret;
48+
49+
job_progress_set_remaining(&s->common, 1);
50+
ret = s->bs->drv->bdrv_co_amend(s->bs, s->opts, s->force, errp);
51+
job_progress_update(&s->common, 1);
52+
qapi_free_BlockdevAmendOptions(s->opts);
53+
return ret;
54+
}
55+
56+
static const JobDriver blockdev_amend_job_driver = {
57+
.instance_size = sizeof(BlockdevAmendJob),
58+
.job_type = JOB_TYPE_AMEND,
59+
.run = blockdev_amend_run,
60+
};
61+
62+
void qmp_x_blockdev_amend(const char *job_id,
63+
const char *node_name,
64+
BlockdevAmendOptions *options,
65+
bool has_force,
66+
bool force,
67+
Error **errp)
68+
{
69+
BlockdevAmendJob *s;
70+
const char *fmt = BlockdevDriver_str(options->driver);
71+
BlockDriver *drv = bdrv_find_format(fmt);
72+
BlockDriverState *bs = bdrv_find_node(node_name);
73+
74+
75+
if (!drv) {
76+
error_setg(errp, "Block driver '%s' not found or not supported", fmt);
77+
return;
78+
}
79+
80+
/*
81+
* If the driver is in the schema, we know that it exists. But it may not
82+
* be whitelisted.
83+
*/
84+
if (bdrv_uses_whitelist() && !bdrv_is_whitelisted(drv, false)) {
85+
error_setg(errp, "Driver is not whitelisted");
86+
return;
87+
}
88+
89+
if (bs->drv != drv) {
90+
error_setg(errp,
91+
"x-blockdev-amend doesn't support changing the block driver");
92+
return;
93+
}
94+
95+
/* Error out if the driver doesn't support .bdrv_co_amend */
96+
if (!drv->bdrv_co_amend) {
97+
error_setg(errp, "Driver does not support x-blockdev-amend");
98+
return;
99+
}
100+
101+
/* Create the block job */
102+
s = job_create(job_id, &blockdev_amend_job_driver, NULL,
103+
bdrv_get_aio_context(bs), JOB_DEFAULT | JOB_MANUAL_DISMISS,
104+
NULL, NULL, errp);
105+
if (!s) {
106+
return;
107+
}
108+
109+
s->bs = bs,
110+
s->opts = QAPI_CLONE(BlockdevAmendOptions, options),
111+
s->force = has_force ? force : false;
112+
job_start(&s->common);
113+
}

block/block-copy.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,8 +622,10 @@ static int coroutine_fn block_copy_dirty_clusters(BlockCopyState *s,
622622
* block_copy_task_run. If it fails, it means some task already failed
623623
* for real reason, let's return first failure.
624624
* Still, assert that we don't rewrite failure by success.
625+
*
626+
* Note: ret may be positive here because of block-status result.
625627
*/
626-
assert(ret == 0 || aio_task_pool_status(aio) < 0);
628+
assert(ret >= 0 || aio_task_pool_status(aio) < 0);
627629
ret = aio_task_pool_status(aio);
628630

629631
aio_task_pool_free(aio);

0 commit comments

Comments
 (0)