diff --git a/block.c b/block.c index ed9253c786ac238eacb23726002e6f51f9371668..0a93ee9ac84c590ab8cd399a7d60c19d11c8a69b 100644 --- a/block.c +++ b/block.c @@ -4350,11 +4350,10 @@ int bdrv_drop_intermediate(BlockDriverState *top, BlockDriverState *base, QLIST_FOREACH_SAFE(c, &top->parents, next_parent, next) { /* Check whether we are allowed to switch c from top to base */ GSList *ignore_children = g_slist_prepend(NULL, c); - bdrv_check_update_perm(base, NULL, c->perm, c->shared_perm, - ignore_children, &local_err); + ret = bdrv_check_update_perm(base, NULL, c->perm, c->shared_perm, + ignore_children, &local_err); g_slist_free(ignore_children); - if (local_err) { - ret = -EPERM; + if (ret < 0) { error_report_err(local_err); goto exit; } diff --git a/block/copy-on-read.c b/block/copy-on-read.c index 64dcc424b51c1a431dc52db3139d9ff69f4252b6..d670fec42b5130e8271ca46be5ef7c8aa0446839 100644 --- a/block/copy-on-read.c +++ b/block/copy-on-read.c @@ -134,7 +134,7 @@ static bool cor_recurse_is_first_non_filter(BlockDriverState *bs, } -BlockDriver bdrv_copy_on_read = { +static BlockDriver bdrv_copy_on_read = { .format_name = "copy-on-read", .bdrv_open = cor_open, diff --git a/block/crypto.c b/block/crypto.c index fd8c7cfac60e67388e33d23ceef01dbe5ba23fe8..3af46b805fde4ce69a875678157fce5f01cb81ce 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -625,7 +625,7 @@ static const char *const block_crypto_strong_runtime_opts[] = { NULL }; -BlockDriver bdrv_crypto_luks = { +static BlockDriver bdrv_crypto_luks = { .format_name = "luks", .instance_size = sizeof(BlockCrypto), .bdrv_probe = block_crypto_probe_luks, diff --git a/block/mirror.c b/block/mirror.c index 010fdafd79780a01c1af69319bfaa8d7c625ec1a..eb9a4cdf565378aefd0d0b86fc0d5d3e6141d495 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -80,6 +80,7 @@ typedef struct MirrorBlockJob { bool initial_zeroing_ongoing; int in_active_write_counter; bool prepared; + bool in_drain; } MirrorBlockJob; typedef struct MirrorBDSOpaque { @@ -683,6 +684,7 @@ static int mirror_exit_common(Job *job) /* The mirror job has no requests in flight any more, but we need to * drain potential other users of the BDS before changing the graph. */ + assert(s->in_drain); bdrv_drained_begin(target_bs); bdrv_replace_node(to_replace, target_bs, &local_err); bdrv_drained_end(target_bs); @@ -721,6 +723,7 @@ static int mirror_exit_common(Job *job) bs_opaque->job = NULL; bdrv_drained_end(src); + s->in_drain = false; bdrv_unref(mirror_top_bs); bdrv_unref(src); @@ -1004,10 +1007,12 @@ static int coroutine_fn mirror_run(Job *job, Error **errp) */ trace_mirror_before_drain(s, cnt); + s->in_drain = true; bdrv_drained_begin(bs); cnt = bdrv_get_dirty_count(s->dirty_bitmap); if (cnt > 0 || mirror_flush(s) < 0) { bdrv_drained_end(bs); + s->in_drain = false; continue; } @@ -1055,6 +1060,7 @@ immediate_exit: bdrv_dirty_iter_free(s->dbi); if (need_drain) { + s->in_drain = true; bdrv_drained_begin(bs); } @@ -1123,6 +1129,16 @@ static void coroutine_fn mirror_pause(Job *job) static bool mirror_drained_poll(BlockJob *job) { MirrorBlockJob *s = container_of(job, MirrorBlockJob, common); + + /* If the job isn't paused nor cancelled, we can't be sure that it won't + * issue more requests. We make an exception if we've reached this point + * from one of our own drain sections, to avoid a deadlock waiting for + * ourselves. + */ + if (!s->common.job.paused && !s->common.job.cancelled && !s->in_drain) { + return true; + } + return !!s->in_flight; } diff --git a/block/qcow2.c b/block/qcow2.c index 0dd77c6367cd739235680723ea291ea682fe5569..d507ee0686f0b295f6a655dfe14be87f03c138fd 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3073,7 +3073,7 @@ qcow2_co_create(BlockdevCreateOptions *create_options, Error **errp) goto out; } data_bs = bdrv_open_blockdev_ref(qcow2_opts->data_file, errp); - if (bs == NULL) { + if (data_bs == NULL) { ret = -EIO; goto out; } diff --git a/block/replication.c b/block/replication.c index b95bd28802c70a028b043d33c3cba49091103cd4..3d4dedddfcb564208a70adc8f1d70d75b70b5419 100644 --- a/block/replication.c +++ b/block/replication.c @@ -682,7 +682,7 @@ static const char *const replication_strong_runtime_opts[] = { NULL }; -BlockDriver bdrv_replication = { +static BlockDriver bdrv_replication = { .format_name = "replication", .instance_size = sizeof(BDRVReplicationState), diff --git a/block/vmdk.c b/block/vmdk.c index d8c0c503908b4b17512b368551e5430833fae03e..8dec6ef7677bc4f50960bf0bb0c5232c336d7cf8 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -195,13 +195,15 @@ static int vmdk_probe(const uint8_t *buf, int buf_size, const char *filename) } if (end - p >= strlen("version=X\n")) { if (strncmp("version=1\n", p, strlen("version=1\n")) == 0 || - strncmp("version=2\n", p, strlen("version=2\n")) == 0) { + strncmp("version=2\n", p, strlen("version=2\n")) == 0 || + strncmp("version=3\n", p, strlen("version=3\n")) == 0) { return 100; } } if (end - p >= strlen("version=X\r\n")) { if (strncmp("version=1\r\n", p, strlen("version=1\r\n")) == 0 || - strncmp("version=2\r\n", p, strlen("version=2\r\n")) == 0) { + strncmp("version=2\r\n", p, strlen("version=2\r\n")) == 0 || + strncmp("version=3\r\n", p, strlen("version=3\r\n")) == 0) { return 100; } } diff --git a/blockdev.c b/blockdev.c index 53df2eb875883038f983eda9f5703d39d60562dc..4775a07d930351c4f32d4b6d8fd8807c19ed6314 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3756,6 +3756,39 @@ static void blockdev_mirror_common(const char *job_id, BlockDriverState *bs, sync = MIRROR_SYNC_MODE_FULL; } + if (has_replaces) { + BlockDriverState *to_replace_bs; + AioContext *replace_aio_context; + int64_t bs_size, replace_size; + + bs_size = bdrv_getlength(bs); + if (bs_size < 0) { + error_setg_errno(errp, -bs_size, "Failed to query device's size"); + return; + } + + to_replace_bs = check_to_replace_node(bs, replaces, errp); + if (!to_replace_bs) { + return; + } + + replace_aio_context = bdrv_get_aio_context(to_replace_bs); + aio_context_acquire(replace_aio_context); + replace_size = bdrv_getlength(to_replace_bs); + aio_context_release(replace_aio_context); + + if (replace_size < 0) { + error_setg_errno(errp, -replace_size, + "Failed to query the replacement node's size"); + return; + } + if (bs_size != replace_size) { + error_setg(errp, "cannot replace image with a mirror image of " + "different size"); + return; + } + } + /* pass the node name to replace to mirror start since it's loose coupling * and will allow to check whether the node still exist at mirror completion */ @@ -3816,33 +3849,11 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp) } if (arg->has_replaces) { - BlockDriverState *to_replace_bs; - AioContext *replace_aio_context; - int64_t replace_size; - if (!arg->has_node_name) { error_setg(errp, "a node-name must be provided when replacing a" " named node of the graph"); goto out; } - - to_replace_bs = check_to_replace_node(bs, arg->replaces, &local_err); - - if (!to_replace_bs) { - error_propagate(errp, local_err); - goto out; - } - - replace_aio_context = bdrv_get_aio_context(to_replace_bs); - aio_context_acquire(replace_aio_context); - replace_size = bdrv_getlength(to_replace_bs); - aio_context_release(replace_aio_context); - - if (size != replace_size) { - error_setg(errp, "cannot replace image with a mirror image of " - "different size"); - goto out; - } } if (arg->mode == NEW_IMAGE_MODE_ABSOLUTE_PATHS) { diff --git a/blockjob.c b/blockjob.c index 58de8cb0241242647401ad682ae13ef598ac04fd..730101d282c8b0e7ae6f0982254262ba091ba498 100644 --- a/blockjob.c +++ b/blockjob.c @@ -501,9 +501,11 @@ BlockErrorAction block_job_error_action(BlockJob *job, BlockdevOnError on_err, action); } if (action == BLOCK_ERROR_ACTION_STOP) { - job_pause(&job->job); - /* make the pause user visible, which will be resumed from QMP. */ - job->job.user_paused = true; + if (!job->job.user_paused) { + job_pause(&job->job); + /* make the pause user visible, which will be resumed from QMP. */ + job->job.user_paused = true; + } block_job_iostatus_set_err(job, error); } return action; diff --git a/qapi/block-core.json b/qapi/block-core.json index 12c5e73551e3bb789c88b2cddd3d524be22429e7..7ccbfff9d0b47c810183dd57683bc083354244e7 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -565,7 +565,7 @@ # # Manage read, write and flush latency histograms for the device. # -# If only @device parameter is specified, remove all present latency histograms +# If only @id parameter is specified, remove all present latency histograms # for the device. Otherwise, add/reset some of (or all) latency histograms. # # @id: The name or QOM path of the guest device. @@ -597,7 +597,7 @@ # [0, 10), [10, 50), [50, 100), [100, +inf): # # -> { "execute": "block-latency-histogram-set", -# "arguments": { "device": "drive0", +# "arguments": { "id": "drive0", # "boundaries": [10, 50, 100] } } # <- { "return": {} } # @@ -605,7 +605,7 @@ # not changed (or not created): # # -> { "execute": "block-latency-histogram-set", -# "arguments": { "device": "drive0", +# "arguments": { "id": "drive0", # "boundaries-write": [10, 50, 100] } } # <- { "return": {} } # @@ -614,7 +614,7 @@ # write: [0, 1000), [1000, 5000), [5000, +inf) # # -> { "execute": "block-latency-histogram-set", -# "arguments": { "device": "drive0", +# "arguments": { "id": "drive0", # "boundaries": [10, 50, 100], # "boundaries-write": [1000, 5000] } } # <- { "return": {} } @@ -622,7 +622,7 @@ # Example: remove all latency histograms: # # -> { "execute": "block-latency-histogram-set", -# "arguments": { "device": "drive0" } } +# "arguments": { "id": "drive0" } } # <- { "return": {} } ## { 'command': 'block-latency-histogram-set', diff --git a/tests/qemu-iotests/051 b/tests/qemu-iotests/051 index 6a3b7c2b89edc0616bac358118a2f2bf347f5cb8..02ac960da43d96ed416a5ff681cbf3ec8d957483 100755 --- a/tests/qemu-iotests/051 +++ b/tests/qemu-iotests/051 @@ -360,7 +360,7 @@ TMPDIR=/nonexistent run_qemu -drive driver=null-co,snapshot=on echo "info block" | run_qemu -drive file="$TEST_IMG",snapshot=on,read-only=on,if=none,id=$device_id | _filter_qemu_io | - sed -e 's#"/[^"]*/vl\.[A-Za-z0-9]\{6\}"#SNAPSHOT_PATH#g' + sed -e 's#"[^"]*/vl\.[A-Za-z0-9]\{6\}"#SNAPSHOT_PATH#g' # success, all done diff --git a/tests/qemu-iotests/153 b/tests/qemu-iotests/153 index c989c2495fb5977bce152557c4ebf2849e395790..08ad8a6730153fffe499b3070de2ea5120c3be83 100755 --- a/tests/qemu-iotests/153 +++ b/tests/qemu-iotests/153 @@ -155,7 +155,7 @@ for opts1 in "" "read-only=on" "read-only=on,force-share=on"; do _img_info -U | grep 'file format' fi done - _send_qemu_cmd $h "{ 'execute': 'quit', }" "" + _send_qemu_cmd $h "{ 'execute': 'quit' }" '' echo echo "Round done" _cleanup_qemu @@ -219,7 +219,7 @@ echo "Adding drive" _send_qemu_cmd $QEMU_HANDLE \ "{ 'execute': 'human-monitor-command', 'arguments': { 'command-line': 'drive_add 0 if=none,id=d0,file=${TEST_IMG}' } }" \ - "" + 'return' _run_cmd $QEMU_IO "${TEST_IMG}" -c 'write 0 512' @@ -230,7 +230,7 @@ echo "== Closing an image should unlock it ==" _send_qemu_cmd $QEMU_HANDLE \ "{ 'execute': 'human-monitor-command', 'arguments': { 'command-line': 'drive_del d0' } }" \ - "" + 'return' _run_cmd $QEMU_IO "${TEST_IMG}" -c 'write 0 512' @@ -239,7 +239,7 @@ for d in d0 d1; do _send_qemu_cmd $QEMU_HANDLE \ "{ 'execute': 'human-monitor-command', 'arguments': { 'command-line': 'drive_add 0 if=none,id=$d,file=${TEST_IMG},readonly=on' } }" \ - "" + 'return' done _run_cmd $QEMU_IMG info "${TEST_IMG}" @@ -247,7 +247,7 @@ _run_cmd $QEMU_IMG info "${TEST_IMG}" _send_qemu_cmd $QEMU_HANDLE \ "{ 'execute': 'human-monitor-command', 'arguments': { 'command-line': 'drive_del d0' } }" \ - "" + 'return' _run_cmd $QEMU_IO "${TEST_IMG}" -c 'write 0 512' @@ -255,7 +255,7 @@ echo "Closing the other" _send_qemu_cmd $QEMU_HANDLE \ "{ 'execute': 'human-monitor-command', 'arguments': { 'command-line': 'drive_del d1' } }" \ - "" + 'return' _run_cmd $QEMU_IO "${TEST_IMG}" -c 'write 0 512' diff --git a/tests/qemu-iotests/153.out b/tests/qemu-iotests/153.out index 884254868caa7524f981c8556e5253b260f7c7fe..9747ce3c41961215d68a29657934b8ddd02a44cc 100644 --- a/tests/qemu-iotests/153.out +++ b/tests/qemu-iotests/153.out @@ -417,6 +417,7 @@ Is another process using the image [TEST_DIR/t.qcow2]? _qemu_img_wrapper commit -b TEST_DIR/t.qcow2.b TEST_DIR/t.qcow2.c {"return": {}} Adding drive +{"return": "OKrn"} _qemu_io_wrapper TEST_DIR/t.qcow2 -c write 0 512 can't open device TEST_DIR/t.qcow2: Failed to get "write" lock @@ -425,16 +426,21 @@ Creating overlay with qemu-img when the guest is running should be allowed _qemu_img_wrapper create -f qcow2 -b TEST_DIR/t.qcow2 TEST_DIR/t.qcow2.overlay == Closing an image should unlock it == +{"return": ""} _qemu_io_wrapper TEST_DIR/t.qcow2 -c write 0 512 Adding two and closing one +{"return": "OKrn"} +{"return": "OKrn"} _qemu_img_wrapper info TEST_DIR/t.qcow2 +{"return": ""} _qemu_io_wrapper TEST_DIR/t.qcow2 -c write 0 512 can't open device TEST_DIR/t.qcow2: Failed to get "write" lock Is another process using the image [TEST_DIR/t.qcow2]? Closing the other +{"return": ""} _qemu_io_wrapper TEST_DIR/t.qcow2 -c write 0 512 diff --git a/tests/qemu-iotests/232 b/tests/qemu-iotests/232 index 0de097fc88548ac4ae6f29b6a62c8b60deb6c27b..2063f78876ed72022511371ee67ff2e8f2313081 100755 --- a/tests/qemu-iotests/232 +++ b/tests/qemu-iotests/232 @@ -144,36 +144,6 @@ run_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,a run_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,auto-read-only=on run_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0 -echo -echo "=== Try commit to backing file with auto-read-only ===" -echo - -TEST_IMG="$TEST_IMG.0" _make_test_img $size -TEST_IMG="$TEST_IMG.1" _make_test_img $size -TEST_IMG="$TEST_IMG.2" _make_test_img $size -TEST_IMG="$TEST_IMG.3" _make_test_img $size -TEST_IMG="$TEST_IMG.4" _make_test_img $size - -(cat <. +# + +# creator +owner=kwolf@redhat.com + +seq=`basename $0` +echo "QA output created by $seq" + +status=1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img + rm -f $TEST_IMG.[01234] +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter + +# Requires backing files and .bdrv_change_backing_file support +_supported_fmt qcow2 qed +_supported_proto file +_supported_os Linux + +size=128M + +echo +echo "=== Try commit to backing file with auto-read-only ===" +echo +TEST_IMG="$TEST_IMG.0" _make_test_img $size +TEST_IMG="$TEST_IMG.1" _make_test_img $size +TEST_IMG="$TEST_IMG.2" _make_test_img $size +TEST_IMG="$TEST_IMG.3" _make_test_img $size +TEST_IMG="$TEST_IMG.4" _make_test_img $size + +(cat <name, machine_class->deprecation_reason); } - /* - * Migration object can only be created after global properties - * are applied correctly. - */ - migration_object_init(); - if (qtest_chrdev) { qtest_init(qtest_chrdev, qtest_log, &error_fatal); }