2012-10-18 22:49:23 +08:00
|
|
|
/*
|
|
|
|
* Image mirroring
|
|
|
|
*
|
|
|
|
* Copyright Red Hat, Inc. 2012
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Paolo Bonzini <pbonzini@redhat.com>
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU LGPL, version 2 or later.
|
|
|
|
* See the COPYING.LIB file in the top-level directory.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-01-19 02:01:42 +08:00
|
|
|
#include "qemu/osdep.h"
|
2017-03-09 18:49:16 +08:00
|
|
|
#include "qemu/cutils.h"
|
2018-06-14 02:18:12 +08:00
|
|
|
#include "qemu/coroutine.h"
|
2018-06-14 02:18:13 +08:00
|
|
|
#include "qemu/range.h"
|
2012-10-18 22:49:23 +08:00
|
|
|
#include "trace.h"
|
2016-10-28 00:07:00 +08:00
|
|
|
#include "block/blockjob_int.h"
|
2012-12-18 01:19:44 +08:00
|
|
|
#include "block/block_int.h"
|
2022-12-21 21:35:49 +08:00
|
|
|
#include "block/dirty-bitmap.h"
|
2015-10-19 23:53:22 +08:00
|
|
|
#include "sysemu/block-backend.h"
|
include/qemu/osdep.h: Don't include qapi/error.h
Commit 57cb38b included qapi/error.h into qemu/osdep.h to get the
Error typedef. Since then, we've moved to include qemu/osdep.h
everywhere. Its file comment explains: "To avoid getting into
possible circular include dependencies, this file should not include
any other QEMU headers, with the exceptions of config-host.h,
compiler.h, os-posix.h and os-win32.h, all of which are doing a
similar job to this file and are under similar constraints."
qapi/error.h doesn't do a similar job, and it doesn't adhere to
similar constraints: it includes qapi-types.h. That's in excess of
100KiB of crap most .c files don't actually need.
Add the typedef to qemu/typedefs.h, and include that instead of
qapi/error.h. Include qapi/error.h in .c files that need it and don't
get it now. Include qapi-types.h in qom/object.h for uint16List.
Update scripts/clean-includes accordingly. Update it further to match
reality: replace config.h by config-target.h, add sysemu/os-posix.h,
sysemu/os-win32.h. Update the list of includes in the qemu/osdep.h
comment quoted above similarly.
This reduces the number of objects depending on qapi/error.h from "all
of them" to less than a third. Unfortunately, the number depending on
qapi-types.h shrinks only a little. More work is needed for that one.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
[Fix compilation without the spice devel packages. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-03-14 16:01:28 +08:00
|
|
|
#include "qapi/error.h"
|
2012-10-18 22:49:23 +08:00
|
|
|
#include "qemu/ratelimit.h"
|
2013-01-22 00:09:43 +08:00
|
|
|
#include "qemu/bitmap.h"
|
2022-02-27 02:07:23 +08:00
|
|
|
#include "qemu/memalign.h"
|
2012-10-18 22:49:23 +08:00
|
|
|
|
2013-01-22 16:03:14 +08:00
|
|
|
#define MAX_IN_FLIGHT 16
|
2017-07-07 20:44:46 +08:00
|
|
|
#define MAX_IO_BYTES (1 << 20) /* 1 Mb */
|
|
|
|
#define DEFAULT_MIRROR_BUF_SIZE (MAX_IN_FLIGHT * MAX_IO_BYTES)
|
2013-01-22 16:03:14 +08:00
|
|
|
|
|
|
|
/* The mirroring buffer is a list of granularity-sized chunks.
|
|
|
|
* Free chunks are organized in a list.
|
|
|
|
*/
|
|
|
|
typedef struct MirrorBuffer {
|
|
|
|
QSIMPLEQ_ENTRY(MirrorBuffer) next;
|
|
|
|
} MirrorBuffer;
|
2012-10-18 22:49:23 +08:00
|
|
|
|
2018-06-14 02:18:12 +08:00
|
|
|
typedef struct MirrorOp MirrorOp;
|
|
|
|
|
2012-10-18 22:49:23 +08:00
|
|
|
typedef struct MirrorBlockJob {
|
|
|
|
BlockJob common;
|
2016-04-12 22:17:41 +08:00
|
|
|
BlockBackend *target;
|
2017-01-26 02:16:34 +08:00
|
|
|
BlockDriverState *mirror_top_bs;
|
2013-12-16 14:45:29 +08:00
|
|
|
BlockDriverState *base;
|
2019-06-12 22:27:32 +08:00
|
|
|
BlockDriverState *base_overlay;
|
2017-01-26 02:16:34 +08:00
|
|
|
|
2014-06-28 00:25:25 +08:00
|
|
|
/* The name of the graph node to replace */
|
|
|
|
char *replaces;
|
|
|
|
/* The BDS to replace */
|
|
|
|
BlockDriverState *to_replace;
|
|
|
|
/* Used to block operations on the drive-mirror-replace target */
|
|
|
|
Error *replace_blocker;
|
2013-12-16 14:45:30 +08:00
|
|
|
bool is_none_mode;
|
block/mirror: Fix target backing BDS
Currently, we are trying to move the backing BDS from the source to the
target in bdrv_replace_in_backing_chain() which is called from
mirror_exit(). However, mirror_complete() already tries to open the
target's backing chain with a call to bdrv_open_backing_file().
First, we should only set the target's backing BDS once. Second, the
mirroring block job has a better idea of what to set it to than the
generic code in bdrv_replace_in_backing_chain() (in fact, the latter's
conditions on when to move the backing BDS from source to target are not
really correct).
Therefore, remove that code from bdrv_replace_in_backing_chain() and
leave it to mirror_complete().
Depending on what kind of mirroring is performed, we furthermore want to
use different strategies to open the target's backing chain:
- If blockdev-mirror is used, we can assume the user made sure that the
target already has the correct backing chain. In particular, we should
not try to open a backing file if the target does not have any yet.
- If drive-mirror with mode=absolute-paths is used, we can and should
reuse the already existing chain of nodes that the source BDS is in.
In case of sync=full, no backing BDS is required; with sync=top, we
just link the source's backing BDS to the target, and with sync=none,
we use the source BDS as the target's backing BDS.
We should not try to open these backing files anew because this would
lead to two BDSs existing per physical file in the backing chain, and
we would like to avoid such concurrent access.
- If drive-mirror with mode=existing is used, we have to use the
information provided in the physical image file which means opening
the target's backing chain completely anew, just as it has been done
already.
If the target's backing chain shares images with the source, this may
lead to multiple BDSs per physical image file. But since we cannot
reliably ascertain this case, there is nothing we can do about it.
Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-id: 20160610185750.30956-3-mreitz@redhat.com
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Fam Zheng <famz@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2016-06-11 02:57:47 +08:00
|
|
|
BlockMirrorBackingMode backing_mode;
|
2019-07-25 01:12:30 +08:00
|
|
|
/* Whether the target image requires explicit zero-initialization */
|
|
|
|
bool zero_target;
|
2023-10-31 21:54:26 +08:00
|
|
|
/*
|
|
|
|
* To be accesssed with atomics. Written only under the BQL (required by the
|
|
|
|
* current implementation of mirror_change()).
|
|
|
|
*/
|
2018-06-14 02:18:21 +08:00
|
|
|
MirrorCopyMode copy_mode;
|
2012-10-18 22:49:28 +08:00
|
|
|
BlockdevOnError on_source_error, on_target_error;
|
2023-10-31 21:54:30 +08:00
|
|
|
/*
|
|
|
|
* To be accessed with atomics.
|
|
|
|
*
|
|
|
|
* Set when the target is synced (dirty bitmap is clean, nothing in flight)
|
|
|
|
* and the job is running in active mode.
|
|
|
|
*/
|
2018-06-14 02:18:21 +08:00
|
|
|
bool actively_synced;
|
2012-10-18 22:49:25 +08:00
|
|
|
bool should_complete;
|
2013-01-22 00:09:46 +08:00
|
|
|
int64_t granularity;
|
2013-01-22 00:09:43 +08:00
|
|
|
size_t buf_size;
|
2014-10-24 21:57:36 +08:00
|
|
|
int64_t bdev_length;
|
2013-01-22 00:09:43 +08:00
|
|
|
unsigned long *cow_bitmap;
|
2013-11-13 18:29:43 +08:00
|
|
|
BdrvDirtyBitmap *dirty_bitmap;
|
2016-10-14 05:58:21 +08:00
|
|
|
BdrvDirtyBitmapIter *dbi;
|
2012-10-18 22:49:23 +08:00
|
|
|
uint8_t *buf;
|
2013-01-22 16:03:14 +08:00
|
|
|
QSIMPLEQ_HEAD(, MirrorBuffer) buf_free;
|
|
|
|
int buf_free_count;
|
2013-01-22 16:03:12 +08:00
|
|
|
|
2016-07-14 21:33:24 +08:00
|
|
|
uint64_t last_pause_ns;
|
2013-01-22 16:03:14 +08:00
|
|
|
unsigned long *in_flight_bitmap;
|
2022-05-30 18:39:57 +08:00
|
|
|
unsigned in_flight;
|
2017-07-07 20:44:46 +08:00
|
|
|
int64_t bytes_in_flight;
|
2018-12-06 18:58:10 +08:00
|
|
|
QTAILQ_HEAD(, MirrorOp) ops_in_flight;
|
2013-01-22 16:03:12 +08:00
|
|
|
int ret;
|
2015-06-08 13:56:08 +08:00
|
|
|
bool unmap;
|
2017-07-07 20:44:46 +08:00
|
|
|
int target_cluster_size;
|
2016-02-05 10:00:29 +08:00
|
|
|
int max_iov;
|
2017-02-02 22:25:15 +08:00
|
|
|
bool initial_zeroing_ongoing;
|
2018-06-14 02:18:21 +08:00
|
|
|
int in_active_write_counter;
|
block/mirror: Do not wait for active writes
Waiting for all active writes to settle before daring to create a
background copying operation means that we will never do background
operations while the guest does anything (in write-blocking mode), and
therefore cannot converge. Yes, we also will not diverge, but actually
converging would be even nicer.
It is unclear why we did decide to wait for all active writes to settle
before creating a background operation, but it just does not seem
necessary. Active writes will put themselves into the in_flight bitmap
and thus properly block actually conflicting background requests.
It is important for active requests to wait on overlapping background
requests, which we do in active_write_prepare(). However, so far it was
not documented why it is important. Add such documentation now, and
also to the other call of mirror_wait_on_conflicts(), so that it becomes
more clear why and when requests need to actively wait for other
requests to settle.
Another thing to note is that of course we need to ensure that there are
no active requests when the job completes, but that is done by virtue of
the BDS being drained anyway, so there cannot be any active requests at
that point.
With this change, we will need to explicitly keep track of how many
bytes are in flight in active requests so that
job_progress_set_remaining() in mirror_run() can set the correct number
of remaining bytes.
Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=2123297
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
Message-Id: <20221109165452.67927-2-hreitz@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2022-11-10 00:54:48 +08:00
|
|
|
int64_t active_write_bytes_in_flight;
|
2018-09-06 21:02:15 +08:00
|
|
|
bool prepared;
|
2019-03-08 23:48:53 +08:00
|
|
|
bool in_drain;
|
2012-10-18 22:49:23 +08:00
|
|
|
} MirrorBlockJob;
|
|
|
|
|
2018-06-14 02:18:19 +08:00
|
|
|
typedef struct MirrorBDSOpaque {
|
|
|
|
MirrorBlockJob *job;
|
2019-05-23 01:03:47 +08:00
|
|
|
bool stop;
|
block/mirror: Fix mirror_top's permissions
mirror_top currently shares all permissions, and takes only the WRITE
permission (if some parent has taken that permission, too).
That is wrong, though; mirror_top is a filter, so it should take
permissions like any other filter does. For example, if the parent
needs CONSISTENT_READ, we need to take that, too, and if it cannot share
the WRITE permission, we cannot share it either.
The exception is when mirror_top is used for active commit, where we
cannot take CONSISTENT_READ (because it is deliberately unshared above
the base node) and where we must share WRITE (so that it is shared for
all images in the backing chain, so the mirror job can take it for the
target BB).
Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-Id: <20210211172242.146671-2-mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
2021-02-12 01:22:41 +08:00
|
|
|
bool is_commit;
|
2018-06-14 02:18:19 +08:00
|
|
|
} MirrorBDSOpaque;
|
|
|
|
|
2018-06-14 02:18:12 +08:00
|
|
|
struct MirrorOp {
|
2013-01-22 16:03:12 +08:00
|
|
|
MirrorBlockJob *s;
|
|
|
|
QEMUIOVector qiov;
|
2017-07-07 20:44:46 +08:00
|
|
|
int64_t offset;
|
|
|
|
uint64_t bytes;
|
2018-06-14 02:18:11 +08:00
|
|
|
|
|
|
|
/* The pointee is set by mirror_co_read(), mirror_co_zero(), and
|
|
|
|
* mirror_co_discard() before yielding for the first time */
|
|
|
|
int64_t *bytes_handled;
|
2018-06-14 02:18:12 +08:00
|
|
|
|
2018-06-14 02:18:13 +08:00
|
|
|
bool is_pseudo_op;
|
2018-06-14 02:18:21 +08:00
|
|
|
bool is_active_write;
|
2020-03-26 23:36:28 +08:00
|
|
|
bool is_in_flight;
|
2018-06-14 02:18:12 +08:00
|
|
|
CoQueue waiting_requests;
|
2020-01-28 23:06:41 +08:00
|
|
|
Coroutine *co;
|
2021-07-03 05:16:36 +08:00
|
|
|
MirrorOp *waiting_for_op;
|
2018-06-14 02:18:12 +08:00
|
|
|
|
|
|
|
QTAILQ_ENTRY(MirrorOp) next;
|
|
|
|
};
|
2013-01-22 16:03:12 +08:00
|
|
|
|
2018-06-14 02:18:10 +08:00
|
|
|
typedef enum MirrorMethod {
|
|
|
|
MIRROR_METHOD_COPY,
|
|
|
|
MIRROR_METHOD_ZERO,
|
|
|
|
MIRROR_METHOD_DISCARD,
|
|
|
|
} MirrorMethod;
|
|
|
|
|
2012-10-18 22:49:28 +08:00
|
|
|
static BlockErrorAction mirror_error_action(MirrorBlockJob *s, bool read,
|
|
|
|
int error)
|
|
|
|
{
|
2023-10-31 21:54:30 +08:00
|
|
|
qatomic_set(&s->actively_synced, false);
|
2012-10-18 22:49:28 +08:00
|
|
|
if (read) {
|
2016-04-18 17:36:38 +08:00
|
|
|
return block_job_error_action(&s->common, s->on_source_error,
|
|
|
|
true, error);
|
2012-10-18 22:49:28 +08:00
|
|
|
} else {
|
2016-04-18 17:36:38 +08:00
|
|
|
return block_job_error_action(&s->common, s->on_target_error,
|
|
|
|
false, error);
|
2012-10-18 22:49:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-14 02:18:13 +08:00
|
|
|
static void coroutine_fn mirror_wait_on_conflicts(MirrorOp *self,
|
|
|
|
MirrorBlockJob *s,
|
|
|
|
uint64_t offset,
|
|
|
|
uint64_t bytes)
|
|
|
|
{
|
|
|
|
uint64_t self_start_chunk = offset / s->granularity;
|
|
|
|
uint64_t self_end_chunk = DIV_ROUND_UP(offset + bytes, s->granularity);
|
|
|
|
uint64_t self_nb_chunks = self_end_chunk - self_start_chunk;
|
|
|
|
|
|
|
|
while (find_next_bit(s->in_flight_bitmap, self_end_chunk,
|
|
|
|
self_start_chunk) < self_end_chunk &&
|
|
|
|
s->ret >= 0)
|
|
|
|
{
|
|
|
|
MirrorOp *op;
|
|
|
|
|
|
|
|
QTAILQ_FOREACH(op, &s->ops_in_flight, next) {
|
|
|
|
uint64_t op_start_chunk = op->offset / s->granularity;
|
|
|
|
uint64_t op_nb_chunks = DIV_ROUND_UP(op->offset + op->bytes,
|
|
|
|
s->granularity) -
|
|
|
|
op_start_chunk;
|
|
|
|
|
|
|
|
if (op == self) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ranges_overlap(self_start_chunk, self_nb_chunks,
|
|
|
|
op_start_chunk, op_nb_chunks))
|
|
|
|
{
|
2021-09-10 20:45:33 +08:00
|
|
|
if (self) {
|
|
|
|
/*
|
|
|
|
* If the operation is already (indirectly) waiting for us,
|
|
|
|
* or will wait for us as soon as it wakes up, then just go
|
|
|
|
* on (instead of producing a deadlock in the former case).
|
|
|
|
*/
|
|
|
|
if (op->waiting_for_op) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
self->waiting_for_op = op;
|
2021-07-03 05:16:36 +08:00
|
|
|
}
|
|
|
|
|
2018-06-14 02:18:13 +08:00
|
|
|
qemu_co_queue_wait(&op->waiting_requests, NULL);
|
2021-09-10 20:45:33 +08:00
|
|
|
|
|
|
|
if (self) {
|
|
|
|
self->waiting_for_op = NULL;
|
|
|
|
}
|
|
|
|
|
2018-06-14 02:18:13 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-14 02:18:11 +08:00
|
|
|
static void coroutine_fn mirror_iteration_done(MirrorOp *op, int ret)
|
2013-01-22 16:03:12 +08:00
|
|
|
{
|
|
|
|
MirrorBlockJob *s = op->s;
|
2013-01-22 16:03:14 +08:00
|
|
|
struct iovec *iov;
|
2013-01-22 16:03:12 +08:00
|
|
|
int64_t chunk_num;
|
2017-07-07 20:44:46 +08:00
|
|
|
int i, nb_chunks;
|
2013-01-22 16:03:12 +08:00
|
|
|
|
2017-07-07 20:44:46 +08:00
|
|
|
trace_mirror_iteration_done(s, op->offset, op->bytes, ret);
|
2013-01-22 16:03:12 +08:00
|
|
|
|
|
|
|
s->in_flight--;
|
2017-07-07 20:44:46 +08:00
|
|
|
s->bytes_in_flight -= op->bytes;
|
2013-01-22 16:03:14 +08:00
|
|
|
iov = op->qiov.iov;
|
|
|
|
for (i = 0; i < op->qiov.niov; i++) {
|
|
|
|
MirrorBuffer *buf = (MirrorBuffer *) iov[i].iov_base;
|
|
|
|
QSIMPLEQ_INSERT_TAIL(&s->buf_free, buf, next);
|
|
|
|
s->buf_free_count++;
|
|
|
|
}
|
|
|
|
|
2017-07-07 20:44:46 +08:00
|
|
|
chunk_num = op->offset / s->granularity;
|
|
|
|
nb_chunks = DIV_ROUND_UP(op->bytes, s->granularity);
|
2018-06-14 02:18:12 +08:00
|
|
|
|
2013-01-22 16:03:14 +08:00
|
|
|
bitmap_clear(s->in_flight_bitmap, chunk_num, nb_chunks);
|
2018-06-14 02:18:12 +08:00
|
|
|
QTAILQ_REMOVE(&s->ops_in_flight, op, next);
|
2014-10-24 21:57:36 +08:00
|
|
|
if (ret >= 0) {
|
|
|
|
if (s->cow_bitmap) {
|
|
|
|
bitmap_set(s->cow_bitmap, chunk_num, nb_chunks);
|
|
|
|
}
|
2017-02-02 22:25:15 +08:00
|
|
|
if (!s->initial_zeroing_ongoing) {
|
2018-05-04 18:17:20 +08:00
|
|
|
job_progress_update(&s->common.job, op->bytes);
|
2017-02-02 22:25:15 +08:00
|
|
|
}
|
2013-01-22 16:03:12 +08:00
|
|
|
}
|
2014-01-23 15:59:16 +08:00
|
|
|
qemu_iovec_destroy(&op->qiov);
|
2014-03-21 20:55:19 +08:00
|
|
|
|
2018-06-14 02:18:12 +08:00
|
|
|
qemu_co_queue_restart_all(&op->waiting_requests);
|
|
|
|
g_free(op);
|
2013-01-22 16:03:12 +08:00
|
|
|
}
|
|
|
|
|
2018-06-14 02:18:11 +08:00
|
|
|
static void coroutine_fn mirror_write_complete(MirrorOp *op, int ret)
|
2013-01-22 16:03:12 +08:00
|
|
|
{
|
|
|
|
MirrorBlockJob *s = op->s;
|
2017-02-13 21:52:32 +08:00
|
|
|
|
2013-01-22 16:03:12 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
BlockErrorAction action;
|
|
|
|
|
2017-09-25 22:55:20 +08:00
|
|
|
bdrv_set_dirty_bitmap(s->dirty_bitmap, op->offset, op->bytes);
|
2013-01-22 16:03:12 +08:00
|
|
|
action = mirror_error_action(s, false, -ret);
|
2014-06-18 14:43:30 +08:00
|
|
|
if (action == BLOCK_ERROR_ACTION_REPORT && s->ret >= 0) {
|
2013-01-22 16:03:12 +08:00
|
|
|
s->ret = ret;
|
|
|
|
}
|
|
|
|
}
|
mirror: fix dead-lock
Let start from the beginning:
Commit b9e413dd375 (in 2.9)
"block: explicitly acquire aiocontext in aio callbacks that need it"
added pairs of aio_context_acquire/release to mirror_write_complete and
mirror_read_complete, when they were aio callbacks for blk_aio_* calls.
Then, commit 2e1990b26e5 (in 3.0) "block/mirror: Convert to coroutines"
dropped these blk_aio_* calls, than mirror_write_complete and
mirror_read_complete are not callbacks more, and don't need additional
aiocontext acquiring. Furthermore, mirror_read_complete calls
blk_co_pwritev inside these pair of aio_context_acquire/release, which
leads to the following dead-lock with mirror:
(gdb) info thr
Id Target Id Frame
3 Thread (LWP 145412) "qemu-system-x86" syscall ()
2 Thread (LWP 145416) "qemu-system-x86" __lll_lock_wait ()
* 1 Thread (LWP 145411) "qemu-system-x86" __lll_lock_wait ()
(gdb) bt
#0 __lll_lock_wait ()
#1 _L_lock_812 ()
#2 __GI___pthread_mutex_lock
#3 qemu_mutex_lock_impl (mutex=0x561032dce420 <qemu_global_mutex>,
file=0x5610327d8654 "util/main-loop.c", line=236) at
util/qemu-thread-posix.c:66
#4 qemu_mutex_lock_iothread_impl
#5 os_host_main_loop_wait (timeout=480116000) at util/main-loop.c:236
#6 main_loop_wait (nonblocking=0) at util/main-loop.c:497
#7 main_loop () at vl.c:1892
#8 main
Printing contents of qemu_global_mutex, I see that "__owner = 145416",
so, thr1 is main loop, and now it wants BQL, which is owned by thr2.
(gdb) thr 2
(gdb) bt
#0 __lll_lock_wait ()
#1 _L_lock_870 ()
#2 __GI___pthread_mutex_lock
#3 qemu_mutex_lock_impl (mutex=0x561034d25dc0, ...
#4 aio_context_acquire (ctx=0x561034d25d60)
#5 dma_blk_cb
#6 dma_blk_io
#7 dma_blk_read
#8 ide_dma_cb
#9 bmdma_cmd_writeb
#10 bmdma_write
#11 memory_region_write_accessor
#12 access_with_adjusted_size
#15 flatview_write
#16 address_space_write
#17 address_space_rw
#18 kvm_handle_io
#19 kvm_cpu_exec
#20 qemu_kvm_cpu_thread_fn
#21 qemu_thread_start
#22 start_thread
#23 clone ()
Printing mutex in fr 2, I see "__owner = 145411", so thr2 wants aio
context mutex, which is owned by thr1. Classic dead-lock.
Then, let's check that aio context is hold by mirror coroutine: just
print coroutine stack of first tracked request in mirror job target:
(gdb) [...]
(gdb) qemu coroutine 0x561035dd0860
#0 qemu_coroutine_switch
#1 qemu_coroutine_yield
#2 qemu_co_mutex_lock_slowpath
#3 qemu_co_mutex_lock
#4 qcow2_co_pwritev
#5 bdrv_driver_pwritev
#6 bdrv_aligned_pwritev
#7 bdrv_co_pwritev
#8 blk_co_pwritev
#9 mirror_read_complete () at block/mirror.c:232
#10 mirror_co_read () at block/mirror.c:370
#11 coroutine_trampoline
#12 __start_context
Yes it is mirror_read_complete calling blk_co_pwritev after acquiring
aio context.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2018-11-29 18:18:00 +08:00
|
|
|
|
2013-01-22 16:03:12 +08:00
|
|
|
mirror_iteration_done(op, ret);
|
|
|
|
}
|
|
|
|
|
2018-06-14 02:18:11 +08:00
|
|
|
static void coroutine_fn mirror_read_complete(MirrorOp *op, int ret)
|
2013-01-22 16:03:12 +08:00
|
|
|
{
|
|
|
|
MirrorBlockJob *s = op->s;
|
2017-02-13 21:52:32 +08:00
|
|
|
|
2013-01-22 16:03:12 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
BlockErrorAction action;
|
|
|
|
|
2017-09-25 22:55:20 +08:00
|
|
|
bdrv_set_dirty_bitmap(s->dirty_bitmap, op->offset, op->bytes);
|
2013-01-22 16:03:12 +08:00
|
|
|
action = mirror_error_action(s, true, -ret);
|
2014-06-18 14:43:30 +08:00
|
|
|
if (action == BLOCK_ERROR_ACTION_REPORT && s->ret >= 0) {
|
2013-01-22 16:03:12 +08:00
|
|
|
s->ret = ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
mirror_iteration_done(op, ret);
|
mirror: fix dead-lock
Let start from the beginning:
Commit b9e413dd375 (in 2.9)
"block: explicitly acquire aiocontext in aio callbacks that need it"
added pairs of aio_context_acquire/release to mirror_write_complete and
mirror_read_complete, when they were aio callbacks for blk_aio_* calls.
Then, commit 2e1990b26e5 (in 3.0) "block/mirror: Convert to coroutines"
dropped these blk_aio_* calls, than mirror_write_complete and
mirror_read_complete are not callbacks more, and don't need additional
aiocontext acquiring. Furthermore, mirror_read_complete calls
blk_co_pwritev inside these pair of aio_context_acquire/release, which
leads to the following dead-lock with mirror:
(gdb) info thr
Id Target Id Frame
3 Thread (LWP 145412) "qemu-system-x86" syscall ()
2 Thread (LWP 145416) "qemu-system-x86" __lll_lock_wait ()
* 1 Thread (LWP 145411) "qemu-system-x86" __lll_lock_wait ()
(gdb) bt
#0 __lll_lock_wait ()
#1 _L_lock_812 ()
#2 __GI___pthread_mutex_lock
#3 qemu_mutex_lock_impl (mutex=0x561032dce420 <qemu_global_mutex>,
file=0x5610327d8654 "util/main-loop.c", line=236) at
util/qemu-thread-posix.c:66
#4 qemu_mutex_lock_iothread_impl
#5 os_host_main_loop_wait (timeout=480116000) at util/main-loop.c:236
#6 main_loop_wait (nonblocking=0) at util/main-loop.c:497
#7 main_loop () at vl.c:1892
#8 main
Printing contents of qemu_global_mutex, I see that "__owner = 145416",
so, thr1 is main loop, and now it wants BQL, which is owned by thr2.
(gdb) thr 2
(gdb) bt
#0 __lll_lock_wait ()
#1 _L_lock_870 ()
#2 __GI___pthread_mutex_lock
#3 qemu_mutex_lock_impl (mutex=0x561034d25dc0, ...
#4 aio_context_acquire (ctx=0x561034d25d60)
#5 dma_blk_cb
#6 dma_blk_io
#7 dma_blk_read
#8 ide_dma_cb
#9 bmdma_cmd_writeb
#10 bmdma_write
#11 memory_region_write_accessor
#12 access_with_adjusted_size
#15 flatview_write
#16 address_space_write
#17 address_space_rw
#18 kvm_handle_io
#19 kvm_cpu_exec
#20 qemu_kvm_cpu_thread_fn
#21 qemu_thread_start
#22 start_thread
#23 clone ()
Printing mutex in fr 2, I see "__owner = 145411", so thr2 wants aio
context mutex, which is owned by thr1. Classic dead-lock.
Then, let's check that aio context is hold by mirror coroutine: just
print coroutine stack of first tracked request in mirror job target:
(gdb) [...]
(gdb) qemu coroutine 0x561035dd0860
#0 qemu_coroutine_switch
#1 qemu_coroutine_yield
#2 qemu_co_mutex_lock_slowpath
#3 qemu_co_mutex_lock
#4 qcow2_co_pwritev
#5 bdrv_driver_pwritev
#6 bdrv_aligned_pwritev
#7 bdrv_co_pwritev
#8 blk_co_pwritev
#9 mirror_read_complete () at block/mirror.c:232
#10 mirror_co_read () at block/mirror.c:370
#11 coroutine_trampoline
#12 __start_context
Yes it is mirror_read_complete calling blk_co_pwritev after acquiring
aio context.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2018-11-29 18:18:00 +08:00
|
|
|
return;
|
2013-01-22 16:03:12 +08:00
|
|
|
}
|
mirror: fix dead-lock
Let start from the beginning:
Commit b9e413dd375 (in 2.9)
"block: explicitly acquire aiocontext in aio callbacks that need it"
added pairs of aio_context_acquire/release to mirror_write_complete and
mirror_read_complete, when they were aio callbacks for blk_aio_* calls.
Then, commit 2e1990b26e5 (in 3.0) "block/mirror: Convert to coroutines"
dropped these blk_aio_* calls, than mirror_write_complete and
mirror_read_complete are not callbacks more, and don't need additional
aiocontext acquiring. Furthermore, mirror_read_complete calls
blk_co_pwritev inside these pair of aio_context_acquire/release, which
leads to the following dead-lock with mirror:
(gdb) info thr
Id Target Id Frame
3 Thread (LWP 145412) "qemu-system-x86" syscall ()
2 Thread (LWP 145416) "qemu-system-x86" __lll_lock_wait ()
* 1 Thread (LWP 145411) "qemu-system-x86" __lll_lock_wait ()
(gdb) bt
#0 __lll_lock_wait ()
#1 _L_lock_812 ()
#2 __GI___pthread_mutex_lock
#3 qemu_mutex_lock_impl (mutex=0x561032dce420 <qemu_global_mutex>,
file=0x5610327d8654 "util/main-loop.c", line=236) at
util/qemu-thread-posix.c:66
#4 qemu_mutex_lock_iothread_impl
#5 os_host_main_loop_wait (timeout=480116000) at util/main-loop.c:236
#6 main_loop_wait (nonblocking=0) at util/main-loop.c:497
#7 main_loop () at vl.c:1892
#8 main
Printing contents of qemu_global_mutex, I see that "__owner = 145416",
so, thr1 is main loop, and now it wants BQL, which is owned by thr2.
(gdb) thr 2
(gdb) bt
#0 __lll_lock_wait ()
#1 _L_lock_870 ()
#2 __GI___pthread_mutex_lock
#3 qemu_mutex_lock_impl (mutex=0x561034d25dc0, ...
#4 aio_context_acquire (ctx=0x561034d25d60)
#5 dma_blk_cb
#6 dma_blk_io
#7 dma_blk_read
#8 ide_dma_cb
#9 bmdma_cmd_writeb
#10 bmdma_write
#11 memory_region_write_accessor
#12 access_with_adjusted_size
#15 flatview_write
#16 address_space_write
#17 address_space_rw
#18 kvm_handle_io
#19 kvm_cpu_exec
#20 qemu_kvm_cpu_thread_fn
#21 qemu_thread_start
#22 start_thread
#23 clone ()
Printing mutex in fr 2, I see "__owner = 145411", so thr2 wants aio
context mutex, which is owned by thr1. Classic dead-lock.
Then, let's check that aio context is hold by mirror coroutine: just
print coroutine stack of first tracked request in mirror job target:
(gdb) [...]
(gdb) qemu coroutine 0x561035dd0860
#0 qemu_coroutine_switch
#1 qemu_coroutine_yield
#2 qemu_co_mutex_lock_slowpath
#3 qemu_co_mutex_lock
#4 qcow2_co_pwritev
#5 bdrv_driver_pwritev
#6 bdrv_aligned_pwritev
#7 bdrv_co_pwritev
#8 blk_co_pwritev
#9 mirror_read_complete () at block/mirror.c:232
#10 mirror_co_read () at block/mirror.c:370
#11 coroutine_trampoline
#12 __start_context
Yes it is mirror_read_complete calling blk_co_pwritev after acquiring
aio context.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2018-11-29 18:18:00 +08:00
|
|
|
|
|
|
|
ret = blk_co_pwritev(s->target, op->offset, op->qiov.size, &op->qiov, 0);
|
|
|
|
mirror_write_complete(op, ret);
|
2013-01-22 16:03:12 +08:00
|
|
|
}
|
|
|
|
|
2017-07-07 20:44:49 +08:00
|
|
|
/* Clip bytes relative to offset to not exceed end-of-file */
|
|
|
|
static inline int64_t mirror_clip_bytes(MirrorBlockJob *s,
|
|
|
|
int64_t offset,
|
|
|
|
int64_t bytes)
|
|
|
|
{
|
|
|
|
return MIN(bytes, s->bdev_length - offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Round offset and/or bytes to target cluster if COW is needed, and
|
|
|
|
* return the offset of the adjusted tail against original. */
|
2023-04-06 18:17:52 +08:00
|
|
|
static int coroutine_fn mirror_cow_align(MirrorBlockJob *s, int64_t *offset,
|
|
|
|
uint64_t *bytes)
|
2012-10-18 22:49:23 +08:00
|
|
|
{
|
2016-02-05 10:00:29 +08:00
|
|
|
bool need_cow;
|
|
|
|
int ret = 0;
|
2017-07-07 20:44:49 +08:00
|
|
|
int64_t align_offset = *offset;
|
2017-10-12 11:46:59 +08:00
|
|
|
int64_t align_bytes = *bytes;
|
2017-07-07 20:44:49 +08:00
|
|
|
int max_bytes = s->granularity * s->max_iov;
|
2016-02-05 10:00:29 +08:00
|
|
|
|
2017-07-07 20:44:49 +08:00
|
|
|
need_cow = !test_bit(*offset / s->granularity, s->cow_bitmap);
|
|
|
|
need_cow |= !test_bit((*offset + *bytes - 1) / s->granularity,
|
2016-02-05 10:00:29 +08:00
|
|
|
s->cow_bitmap);
|
|
|
|
if (need_cow) {
|
2023-07-12 01:25:52 +08:00
|
|
|
bdrv_round_to_subclusters(blk_bs(s->target), *offset, *bytes,
|
|
|
|
&align_offset, &align_bytes);
|
2016-02-05 10:00:29 +08:00
|
|
|
}
|
2015-07-09 17:56:47 +08:00
|
|
|
|
2017-07-07 20:44:49 +08:00
|
|
|
if (align_bytes > max_bytes) {
|
|
|
|
align_bytes = max_bytes;
|
2016-02-05 10:00:29 +08:00
|
|
|
if (need_cow) {
|
2017-07-07 20:44:49 +08:00
|
|
|
align_bytes = QEMU_ALIGN_DOWN(align_bytes, s->target_cluster_size);
|
2016-02-05 10:00:29 +08:00
|
|
|
}
|
2013-01-22 00:09:41 +08:00
|
|
|
}
|
2017-07-07 20:44:49 +08:00
|
|
|
/* Clipping may result in align_bytes unaligned to chunk boundary, but
|
2016-04-20 10:48:34 +08:00
|
|
|
* that doesn't matter because it's already the end of source image. */
|
2017-07-07 20:44:49 +08:00
|
|
|
align_bytes = mirror_clip_bytes(s, align_offset, align_bytes);
|
2013-01-22 00:09:41 +08:00
|
|
|
|
2017-07-07 20:44:49 +08:00
|
|
|
ret = align_offset + align_bytes - (*offset + *bytes);
|
|
|
|
*offset = align_offset;
|
|
|
|
*bytes = align_bytes;
|
2016-02-05 10:00:29 +08:00
|
|
|
assert(ret >= 0);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-12-13 19:24:34 +08:00
|
|
|
static inline void coroutine_fn
|
2022-11-10 00:54:49 +08:00
|
|
|
mirror_wait_for_free_in_flight_slot(MirrorBlockJob *s)
|
2016-02-05 10:00:30 +08:00
|
|
|
{
|
2018-06-14 02:18:12 +08:00
|
|
|
MirrorOp *op;
|
|
|
|
|
2018-06-14 02:18:13 +08:00
|
|
|
QTAILQ_FOREACH(op, &s->ops_in_flight, next) {
|
2022-11-10 00:54:49 +08:00
|
|
|
/*
|
|
|
|
* Do not wait on pseudo ops, because it may in turn wait on
|
2018-06-14 02:18:13 +08:00
|
|
|
* some other operation to start, which may in fact be the
|
|
|
|
* caller of this function. Since there is only one pseudo op
|
|
|
|
* at any given time, we will always find some real operation
|
2022-11-10 00:54:49 +08:00
|
|
|
* to wait on.
|
|
|
|
* Also, do not wait on active operations, because they do not
|
|
|
|
* use up in-flight slots.
|
|
|
|
*/
|
|
|
|
if (!op->is_pseudo_op && op->is_in_flight && !op->is_active_write) {
|
2018-06-14 02:18:13 +08:00
|
|
|
qemu_co_queue_wait(&op->waiting_requests, NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
abort();
|
2016-02-05 10:00:30 +08:00
|
|
|
}
|
|
|
|
|
2018-06-14 02:18:11 +08:00
|
|
|
/* Perform a mirror copy operation.
|
|
|
|
*
|
|
|
|
* *op->bytes_handled is set to the number of bytes copied after and
|
|
|
|
* including offset, excluding any bytes copied prior to offset due
|
|
|
|
* to alignment. This will be op->bytes if no alignment is necessary,
|
|
|
|
* or (new_end - op->offset) if the tail is rounded up or down due to
|
|
|
|
* alignment or buffer limit.
|
2016-02-05 10:00:29 +08:00
|
|
|
*/
|
2018-06-14 02:18:11 +08:00
|
|
|
static void coroutine_fn mirror_co_read(void *opaque)
|
2016-02-05 10:00:29 +08:00
|
|
|
{
|
2018-06-14 02:18:11 +08:00
|
|
|
MirrorOp *op = opaque;
|
|
|
|
MirrorBlockJob *s = op->s;
|
2017-07-07 20:44:50 +08:00
|
|
|
int nb_chunks;
|
|
|
|
uint64_t ret;
|
|
|
|
uint64_t max_bytes;
|
2016-02-05 10:00:29 +08:00
|
|
|
|
2017-07-07 20:44:50 +08:00
|
|
|
max_bytes = s->granularity * s->max_iov;
|
2013-01-22 16:03:14 +08:00
|
|
|
|
2016-02-05 10:00:29 +08:00
|
|
|
/* We can only handle as much as buf_size at a time. */
|
2018-06-14 02:18:11 +08:00
|
|
|
op->bytes = MIN(s->buf_size, MIN(max_bytes, op->bytes));
|
|
|
|
assert(op->bytes);
|
|
|
|
assert(op->bytes < BDRV_REQUEST_MAX_BYTES);
|
|
|
|
*op->bytes_handled = op->bytes;
|
2013-01-22 16:03:14 +08:00
|
|
|
|
2016-02-05 10:00:29 +08:00
|
|
|
if (s->cow_bitmap) {
|
2018-06-14 02:18:11 +08:00
|
|
|
*op->bytes_handled += mirror_cow_align(s, &op->offset, &op->bytes);
|
2016-02-05 10:00:29 +08:00
|
|
|
}
|
2018-06-14 02:18:11 +08:00
|
|
|
/* Cannot exceed BDRV_REQUEST_MAX_BYTES + INT_MAX */
|
|
|
|
assert(*op->bytes_handled <= UINT_MAX);
|
|
|
|
assert(op->bytes <= s->buf_size);
|
2017-07-07 20:44:50 +08:00
|
|
|
/* The offset is granularity-aligned because:
|
2016-02-05 10:00:29 +08:00
|
|
|
* 1) Caller passes in aligned values;
|
|
|
|
* 2) mirror_cow_align is used only when target cluster is larger. */
|
2018-06-14 02:18:11 +08:00
|
|
|
assert(QEMU_IS_ALIGNED(op->offset, s->granularity));
|
2017-07-07 20:44:50 +08:00
|
|
|
/* The range is sector-aligned, since bdrv_getlength() rounds up. */
|
2018-06-14 02:18:11 +08:00
|
|
|
assert(QEMU_IS_ALIGNED(op->bytes, BDRV_SECTOR_SIZE));
|
|
|
|
nb_chunks = DIV_ROUND_UP(op->bytes, s->granularity);
|
2016-02-05 10:00:29 +08:00
|
|
|
|
|
|
|
while (s->buf_free_count < nb_chunks) {
|
2018-06-14 02:18:11 +08:00
|
|
|
trace_mirror_yield_in_flight(s, op->offset, s->in_flight);
|
2020-03-26 23:36:27 +08:00
|
|
|
mirror_wait_for_free_in_flight_slot(s);
|
2013-01-22 00:09:43 +08:00
|
|
|
}
|
|
|
|
|
2013-01-22 16:03:14 +08:00
|
|
|
/* Now make a QEMUIOVector taking enough granularity-sized chunks
|
|
|
|
* from s->buf_free.
|
|
|
|
*/
|
|
|
|
qemu_iovec_init(&op->qiov, nb_chunks);
|
|
|
|
while (nb_chunks-- > 0) {
|
|
|
|
MirrorBuffer *buf = QSIMPLEQ_FIRST(&s->buf_free);
|
2018-06-14 02:18:11 +08:00
|
|
|
size_t remaining = op->bytes - op->qiov.size;
|
2014-07-01 22:52:21 +08:00
|
|
|
|
2013-01-22 16:03:14 +08:00
|
|
|
QSIMPLEQ_REMOVE_HEAD(&s->buf_free, next);
|
|
|
|
s->buf_free_count--;
|
2014-07-01 22:52:21 +08:00
|
|
|
qemu_iovec_add(&op->qiov, buf, MIN(s->granularity, remaining));
|
2013-01-22 16:03:14 +08:00
|
|
|
}
|
2013-01-22 16:03:12 +08:00
|
|
|
|
2012-10-18 22:49:23 +08:00
|
|
|
/* Copy the dirty cluster. */
|
2013-01-22 16:03:12 +08:00
|
|
|
s->in_flight++;
|
2018-06-14 02:18:11 +08:00
|
|
|
s->bytes_in_flight += op->bytes;
|
2020-03-26 23:36:28 +08:00
|
|
|
op->is_in_flight = true;
|
2018-06-14 02:18:11 +08:00
|
|
|
trace_mirror_one_iteration(s, op->offset, op->bytes);
|
2015-06-08 13:56:09 +08:00
|
|
|
|
2023-02-03 23:21:50 +08:00
|
|
|
WITH_GRAPH_RDLOCK_GUARD() {
|
|
|
|
ret = bdrv_co_preadv(s->mirror_top_bs->backing, op->offset, op->bytes,
|
|
|
|
&op->qiov, 0);
|
|
|
|
}
|
2018-06-14 02:18:11 +08:00
|
|
|
mirror_read_complete(op, ret);
|
2016-02-05 10:00:29 +08:00
|
|
|
}
|
|
|
|
|
2018-06-14 02:18:11 +08:00
|
|
|
static void coroutine_fn mirror_co_zero(void *opaque)
|
2016-02-05 10:00:29 +08:00
|
|
|
{
|
2018-06-14 02:18:11 +08:00
|
|
|
MirrorOp *op = opaque;
|
|
|
|
int ret;
|
2016-02-05 10:00:29 +08:00
|
|
|
|
2018-06-14 02:18:11 +08:00
|
|
|
op->s->in_flight++;
|
|
|
|
op->s->bytes_in_flight += op->bytes;
|
|
|
|
*op->bytes_handled = op->bytes;
|
2020-03-26 23:36:28 +08:00
|
|
|
op->is_in_flight = true;
|
2016-02-05 10:00:29 +08:00
|
|
|
|
2018-06-14 02:18:11 +08:00
|
|
|
ret = blk_co_pwrite_zeroes(op->s->target, op->offset, op->bytes,
|
|
|
|
op->s->unmap ? BDRV_REQ_MAY_UNMAP : 0);
|
|
|
|
mirror_write_complete(op, ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void coroutine_fn mirror_co_discard(void *opaque)
|
|
|
|
{
|
|
|
|
MirrorOp *op = opaque;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
op->s->in_flight++;
|
|
|
|
op->s->bytes_in_flight += op->bytes;
|
|
|
|
*op->bytes_handled = op->bytes;
|
2020-03-26 23:36:28 +08:00
|
|
|
op->is_in_flight = true;
|
2018-06-14 02:18:11 +08:00
|
|
|
|
|
|
|
ret = blk_co_pdiscard(op->s->target, op->offset, op->bytes);
|
|
|
|
mirror_write_complete(op, ret);
|
2016-02-05 10:00:29 +08:00
|
|
|
}
|
|
|
|
|
2018-06-14 02:18:10 +08:00
|
|
|
static unsigned mirror_perform(MirrorBlockJob *s, int64_t offset,
|
|
|
|
unsigned bytes, MirrorMethod mirror_method)
|
|
|
|
{
|
2018-06-14 02:18:11 +08:00
|
|
|
MirrorOp *op;
|
|
|
|
Coroutine *co;
|
|
|
|
int64_t bytes_handled = -1;
|
|
|
|
|
|
|
|
op = g_new(MirrorOp, 1);
|
|
|
|
*op = (MirrorOp){
|
|
|
|
.s = s,
|
|
|
|
.offset = offset,
|
|
|
|
.bytes = bytes,
|
|
|
|
.bytes_handled = &bytes_handled,
|
|
|
|
};
|
2018-06-14 02:18:12 +08:00
|
|
|
qemu_co_queue_init(&op->waiting_requests);
|
2018-06-14 02:18:11 +08:00
|
|
|
|
2018-06-14 02:18:10 +08:00
|
|
|
switch (mirror_method) {
|
|
|
|
case MIRROR_METHOD_COPY:
|
2018-06-14 02:18:11 +08:00
|
|
|
co = qemu_coroutine_create(mirror_co_read, op);
|
|
|
|
break;
|
2018-06-14 02:18:10 +08:00
|
|
|
case MIRROR_METHOD_ZERO:
|
2018-06-14 02:18:11 +08:00
|
|
|
co = qemu_coroutine_create(mirror_co_zero, op);
|
|
|
|
break;
|
2018-06-14 02:18:10 +08:00
|
|
|
case MIRROR_METHOD_DISCARD:
|
2018-06-14 02:18:11 +08:00
|
|
|
co = qemu_coroutine_create(mirror_co_discard, op);
|
|
|
|
break;
|
2018-06-14 02:18:10 +08:00
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
2020-01-28 23:06:41 +08:00
|
|
|
op->co = co;
|
2018-06-14 02:18:11 +08:00
|
|
|
|
2018-06-14 02:18:12 +08:00
|
|
|
QTAILQ_INSERT_TAIL(&s->ops_in_flight, op, next);
|
2018-06-14 02:18:11 +08:00
|
|
|
qemu_coroutine_enter(co);
|
|
|
|
/* At this point, ownership of op has been moved to the coroutine
|
|
|
|
* and the object may already be freed */
|
|
|
|
|
|
|
|
/* Assert that this value has been set */
|
|
|
|
assert(bytes_handled >= 0);
|
|
|
|
|
|
|
|
/* Same assertion as in mirror_co_read() (and for mirror_co_read()
|
|
|
|
* and mirror_co_discard(), bytes_handled == op->bytes, which
|
|
|
|
* is the @bytes parameter given to this function) */
|
|
|
|
assert(bytes_handled <= UINT_MAX);
|
|
|
|
return bytes_handled;
|
2018-06-14 02:18:10 +08:00
|
|
|
}
|
|
|
|
|
2023-10-27 23:53:26 +08:00
|
|
|
static void coroutine_fn GRAPH_RDLOCK mirror_iteration(MirrorBlockJob *s)
|
2016-02-05 10:00:29 +08:00
|
|
|
{
|
2018-06-14 02:18:14 +08:00
|
|
|
BlockDriverState *source = s->mirror_top_bs->backing->bs;
|
2018-06-14 02:18:13 +08:00
|
|
|
MirrorOp *pseudo_op;
|
|
|
|
int64_t offset;
|
2016-02-05 10:00:29 +08:00
|
|
|
/* At least the first dirty chunk is mirrored in one iteration. */
|
|
|
|
int nb_chunks = 1;
|
2016-07-14 21:33:29 +08:00
|
|
|
bool write_zeroes_ok = bdrv_can_write_zeroes_with_unmap(blk_bs(s->target));
|
2017-07-07 20:44:46 +08:00
|
|
|
int max_io_bytes = MAX(s->buf_size / MAX_IN_FLIGHT, MAX_IO_BYTES);
|
2016-02-05 10:00:29 +08:00
|
|
|
|
2017-06-05 20:39:05 +08:00
|
|
|
bdrv_dirty_bitmap_lock(s->dirty_bitmap);
|
2017-09-25 22:55:17 +08:00
|
|
|
offset = bdrv_dirty_iter_next(s->dbi);
|
2017-07-07 20:44:51 +08:00
|
|
|
if (offset < 0) {
|
2016-10-14 05:58:21 +08:00
|
|
|
bdrv_set_dirty_iter(s->dbi, 0);
|
2017-09-25 22:55:17 +08:00
|
|
|
offset = bdrv_dirty_iter_next(s->dbi);
|
2017-09-25 22:55:18 +08:00
|
|
|
trace_mirror_restart_iter(s, bdrv_get_dirty_count(s->dirty_bitmap));
|
2017-07-07 20:44:51 +08:00
|
|
|
assert(offset >= 0);
|
2016-02-05 10:00:29 +08:00
|
|
|
}
|
2017-06-05 20:39:05 +08:00
|
|
|
bdrv_dirty_bitmap_unlock(s->dirty_bitmap);
|
2016-02-05 10:00:29 +08:00
|
|
|
|
block/mirror: Do not wait for active writes
Waiting for all active writes to settle before daring to create a
background copying operation means that we will never do background
operations while the guest does anything (in write-blocking mode), and
therefore cannot converge. Yes, we also will not diverge, but actually
converging would be even nicer.
It is unclear why we did decide to wait for all active writes to settle
before creating a background operation, but it just does not seem
necessary. Active writes will put themselves into the in_flight bitmap
and thus properly block actually conflicting background requests.
It is important for active requests to wait on overlapping background
requests, which we do in active_write_prepare(). However, so far it was
not documented why it is important. Add such documentation now, and
also to the other call of mirror_wait_on_conflicts(), so that it becomes
more clear why and when requests need to actively wait for other
requests to settle.
Another thing to note is that of course we need to ensure that there are
no active requests when the job completes, but that is done by virtue of
the BDS being drained anyway, so there cannot be any active requests at
that point.
With this change, we will need to explicitly keep track of how many
bytes are in flight in active requests so that
job_progress_set_remaining() in mirror_run() can set the correct number
of remaining bytes.
Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=2123297
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
Message-Id: <20221109165452.67927-2-hreitz@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2022-11-10 00:54:48 +08:00
|
|
|
/*
|
|
|
|
* Wait for concurrent requests to @offset. The next loop will limit the
|
|
|
|
* copied area based on in_flight_bitmap so we only copy an area that does
|
|
|
|
* not overlap with concurrent in-flight requests. Still, we would like to
|
|
|
|
* copy something, so wait until there are at least no more requests to the
|
|
|
|
* very beginning of the area.
|
|
|
|
*/
|
2018-06-14 02:18:13 +08:00
|
|
|
mirror_wait_on_conflicts(NULL, s, offset, 1);
|
2016-04-20 06:59:47 +08:00
|
|
|
|
2018-04-13 23:31:02 +08:00
|
|
|
job_pause_point(&s->common.job);
|
2016-06-17 00:56:28 +08:00
|
|
|
|
2023-07-14 19:06:05 +08:00
|
|
|
/* Find the number of consecutive dirty chunks following the first dirty
|
2016-02-05 10:00:29 +08:00
|
|
|
* one, and wait for in flight requests in them. */
|
2017-06-05 20:39:05 +08:00
|
|
|
bdrv_dirty_bitmap_lock(s->dirty_bitmap);
|
2017-07-07 20:44:51 +08:00
|
|
|
while (nb_chunks * s->granularity < s->buf_size) {
|
2016-10-14 05:58:21 +08:00
|
|
|
int64_t next_dirty;
|
2017-07-07 20:44:51 +08:00
|
|
|
int64_t next_offset = offset + nb_chunks * s->granularity;
|
|
|
|
int64_t next_chunk = next_offset / s->granularity;
|
|
|
|
if (next_offset >= s->bdev_length ||
|
2019-07-30 04:35:53 +08:00
|
|
|
!bdrv_dirty_bitmap_get_locked(s->dirty_bitmap, next_offset)) {
|
2016-02-05 10:00:29 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (test_bit(next_chunk, s->in_flight_bitmap)) {
|
2016-04-20 06:59:47 +08:00
|
|
|
break;
|
2016-02-05 10:00:29 +08:00
|
|
|
}
|
2016-04-20 06:59:47 +08:00
|
|
|
|
2017-09-25 22:55:17 +08:00
|
|
|
next_dirty = bdrv_dirty_iter_next(s->dbi);
|
2017-07-07 20:44:51 +08:00
|
|
|
if (next_dirty > next_offset || next_dirty < 0) {
|
2016-04-20 06:59:48 +08:00
|
|
|
/* The bitmap iterator's cache is stale, refresh it */
|
2017-09-25 22:55:16 +08:00
|
|
|
bdrv_set_dirty_iter(s->dbi, next_offset);
|
2017-09-25 22:55:17 +08:00
|
|
|
next_dirty = bdrv_dirty_iter_next(s->dbi);
|
2016-04-20 06:59:48 +08:00
|
|
|
}
|
2017-07-07 20:44:51 +08:00
|
|
|
assert(next_dirty == next_offset);
|
2016-04-20 06:59:47 +08:00
|
|
|
nb_chunks++;
|
2016-02-05 10:00:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear dirty bits before querying the block status, because
|
block: Convert bdrv_get_block_status_above() to bytes
We are gradually moving away from sector-based interfaces, towards
byte-based. In the common case, allocation is unlikely to ever use
values that are not naturally sector-aligned, but it is possible
that byte-based values will let us be more precise about allocation
at the end of an unaligned file that can do byte-based access.
Changing the name of the function from bdrv_get_block_status_above()
to bdrv_block_status_above() ensures that the compiler enforces that
all callers are updated. Likewise, since it a byte interface allows
an offset mapping that might not be sector aligned, split the mapping
out of the return value and into a pass-by-reference parameter. For
now, the io.c layer still assert()s that all uses are sector-aligned,
but that can be relaxed when a later patch implements byte-based
block status in the drivers.
For the most part this patch is just the addition of scaling at the
callers followed by inverse scaling at bdrv_block_status(), plus
updates for the new split return interface. But some code,
particularly bdrv_block_status(), gets a lot simpler because it no
longer has to mess with sectors. Likewise, mirror code no longer
computes s->granularity >> BDRV_SECTOR_BITS, and can therefore drop
an assertion about alignment because the loop no longer depends on
alignment (never mind that we don't really have a driver that
reports sub-sector alignments, so it's not really possible to test
the effect of sub-sector mirroring). Fix a neighboring assertion to
use is_power_of_2 while there.
For ease of review, bdrv_get_block_status() was tackled separately.
Signed-off-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2017-10-12 11:47:08 +08:00
|
|
|
* calling bdrv_block_status_above could yield - if some blocks are
|
2016-02-05 10:00:29 +08:00
|
|
|
* marked dirty in this window, we need to know.
|
|
|
|
*/
|
2017-09-25 22:55:20 +08:00
|
|
|
bdrv_reset_dirty_bitmap_locked(s->dirty_bitmap, offset,
|
|
|
|
nb_chunks * s->granularity);
|
2017-06-05 20:39:05 +08:00
|
|
|
bdrv_dirty_bitmap_unlock(s->dirty_bitmap);
|
|
|
|
|
2018-06-14 02:18:13 +08:00
|
|
|
/* Before claiming an area in the in-flight bitmap, we have to
|
|
|
|
* create a MirrorOp for it so that conflicting requests can wait
|
|
|
|
* for it. mirror_perform() will create the real MirrorOps later,
|
|
|
|
* for now we just create a pseudo operation that will wake up all
|
|
|
|
* conflicting requests once all real operations have been
|
|
|
|
* launched. */
|
|
|
|
pseudo_op = g_new(MirrorOp, 1);
|
|
|
|
*pseudo_op = (MirrorOp){
|
|
|
|
.offset = offset,
|
|
|
|
.bytes = nb_chunks * s->granularity,
|
|
|
|
.is_pseudo_op = true,
|
|
|
|
};
|
|
|
|
qemu_co_queue_init(&pseudo_op->waiting_requests);
|
|
|
|
QTAILQ_INSERT_TAIL(&s->ops_in_flight, pseudo_op, next);
|
|
|
|
|
2017-07-07 20:44:51 +08:00
|
|
|
bitmap_set(s->in_flight_bitmap, offset / s->granularity, nb_chunks);
|
|
|
|
while (nb_chunks > 0 && offset < s->bdev_length) {
|
block: Convert bdrv_get_block_status_above() to bytes
We are gradually moving away from sector-based interfaces, towards
byte-based. In the common case, allocation is unlikely to ever use
values that are not naturally sector-aligned, but it is possible
that byte-based values will let us be more precise about allocation
at the end of an unaligned file that can do byte-based access.
Changing the name of the function from bdrv_get_block_status_above()
to bdrv_block_status_above() ensures that the compiler enforces that
all callers are updated. Likewise, since it a byte interface allows
an offset mapping that might not be sector aligned, split the mapping
out of the return value and into a pass-by-reference parameter. For
now, the io.c layer still assert()s that all uses are sector-aligned,
but that can be relaxed when a later patch implements byte-based
block status in the drivers.
For the most part this patch is just the addition of scaling at the
callers followed by inverse scaling at bdrv_block_status(), plus
updates for the new split return interface. But some code,
particularly bdrv_block_status(), gets a lot simpler because it no
longer has to mess with sectors. Likewise, mirror code no longer
computes s->granularity >> BDRV_SECTOR_BITS, and can therefore drop
an assertion about alignment because the loop no longer depends on
alignment (never mind that we don't really have a driver that
reports sub-sector alignments, so it's not really possible to test
the effect of sub-sector mirroring). Fix a neighboring assertion to
use is_power_of_2 while there.
For ease of review, bdrv_get_block_status() was tackled separately.
Signed-off-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2017-10-12 11:47:08 +08:00
|
|
|
int ret;
|
2017-10-12 11:46:59 +08:00
|
|
|
int64_t io_bytes;
|
2017-07-07 20:44:39 +08:00
|
|
|
int64_t io_bytes_acct;
|
2018-06-14 02:18:10 +08:00
|
|
|
MirrorMethod mirror_method = MIRROR_METHOD_COPY;
|
2016-02-05 10:00:29 +08:00
|
|
|
|
2017-07-07 20:44:51 +08:00
|
|
|
assert(!(offset % s->granularity));
|
2023-02-03 23:21:43 +08:00
|
|
|
WITH_GRAPH_RDLOCK_GUARD() {
|
2023-09-04 18:03:06 +08:00
|
|
|
ret = bdrv_co_block_status_above(source, NULL, offset,
|
|
|
|
nb_chunks * s->granularity,
|
|
|
|
&io_bytes, NULL, NULL);
|
2023-02-03 23:21:43 +08:00
|
|
|
}
|
2016-02-05 10:00:29 +08:00
|
|
|
if (ret < 0) {
|
2017-07-07 20:44:51 +08:00
|
|
|
io_bytes = MIN(nb_chunks * s->granularity, max_io_bytes);
|
2016-07-15 01:19:01 +08:00
|
|
|
} else if (ret & BDRV_BLOCK_DATA) {
|
2017-07-07 20:44:51 +08:00
|
|
|
io_bytes = MIN(io_bytes, max_io_bytes);
|
2016-02-05 10:00:29 +08:00
|
|
|
}
|
|
|
|
|
2017-07-07 20:44:51 +08:00
|
|
|
io_bytes -= io_bytes % s->granularity;
|
|
|
|
if (io_bytes < s->granularity) {
|
|
|
|
io_bytes = s->granularity;
|
2016-02-05 10:00:29 +08:00
|
|
|
} else if (ret >= 0 && !(ret & BDRV_BLOCK_DATA)) {
|
2017-07-07 20:44:51 +08:00
|
|
|
int64_t target_offset;
|
2017-10-12 11:46:59 +08:00
|
|
|
int64_t target_bytes;
|
2023-05-04 19:57:44 +08:00
|
|
|
WITH_GRAPH_RDLOCK_GUARD() {
|
2023-07-12 01:25:52 +08:00
|
|
|
bdrv_round_to_subclusters(blk_bs(s->target), offset, io_bytes,
|
|
|
|
&target_offset, &target_bytes);
|
2023-05-04 19:57:44 +08:00
|
|
|
}
|
2017-07-07 20:44:51 +08:00
|
|
|
if (target_offset == offset &&
|
|
|
|
target_bytes == io_bytes) {
|
2016-02-05 10:00:29 +08:00
|
|
|
mirror_method = ret & BDRV_BLOCK_ZERO ?
|
|
|
|
MIRROR_METHOD_ZERO :
|
|
|
|
MIRROR_METHOD_DISCARD;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-22 20:35:27 +08:00
|
|
|
while (s->in_flight >= MAX_IN_FLIGHT) {
|
2017-07-07 20:44:51 +08:00
|
|
|
trace_mirror_yield_in_flight(s, offset, s->in_flight);
|
2020-03-26 23:36:27 +08:00
|
|
|
mirror_wait_for_free_in_flight_slot(s);
|
2016-06-22 20:35:27 +08:00
|
|
|
}
|
|
|
|
|
2016-08-03 20:56:44 +08:00
|
|
|
if (s->ret < 0) {
|
2018-06-14 02:18:13 +08:00
|
|
|
ret = 0;
|
|
|
|
goto fail;
|
2016-08-03 20:56:44 +08:00
|
|
|
}
|
|
|
|
|
2017-07-07 20:44:51 +08:00
|
|
|
io_bytes = mirror_clip_bytes(s, offset, io_bytes);
|
2018-06-14 02:18:10 +08:00
|
|
|
io_bytes = mirror_perform(s, offset, io_bytes, mirror_method);
|
|
|
|
if (mirror_method != MIRROR_METHOD_COPY && write_zeroes_ok) {
|
|
|
|
io_bytes_acct = 0;
|
|
|
|
} else {
|
|
|
|
io_bytes_acct = io_bytes;
|
2016-02-05 10:00:29 +08:00
|
|
|
}
|
2017-07-07 20:44:51 +08:00
|
|
|
assert(io_bytes);
|
|
|
|
offset += io_bytes;
|
|
|
|
nb_chunks -= DIV_ROUND_UP(io_bytes, s->granularity);
|
2023-05-11 04:36:00 +08:00
|
|
|
block_job_ratelimit_processed_bytes(&s->common, io_bytes_acct);
|
2015-06-08 13:56:09 +08:00
|
|
|
}
|
2018-06-14 02:18:13 +08:00
|
|
|
|
|
|
|
fail:
|
|
|
|
QTAILQ_REMOVE(&s->ops_in_flight, pseudo_op, next);
|
|
|
|
qemu_co_queue_restart_all(&pseudo_op->waiting_requests);
|
|
|
|
g_free(pseudo_op);
|
2013-01-22 16:03:12 +08:00
|
|
|
}
|
2012-10-18 22:49:28 +08:00
|
|
|
|
2013-01-22 16:03:14 +08:00
|
|
|
static void mirror_free_init(MirrorBlockJob *s)
|
|
|
|
{
|
|
|
|
int granularity = s->granularity;
|
|
|
|
size_t buf_size = s->buf_size;
|
|
|
|
uint8_t *buf = s->buf;
|
|
|
|
|
|
|
|
assert(s->buf_free_count == 0);
|
|
|
|
QSIMPLEQ_INIT(&s->buf_free);
|
|
|
|
while (buf_size != 0) {
|
|
|
|
MirrorBuffer *cur = (MirrorBuffer *)buf;
|
|
|
|
QSIMPLEQ_INSERT_TAIL(&s->buf_free, cur, next);
|
|
|
|
s->buf_free_count++;
|
|
|
|
buf_size -= granularity;
|
|
|
|
buf += granularity;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-27 18:48:50 +08:00
|
|
|
/* This is also used for the .pause callback. There is no matching
|
|
|
|
* mirror_resume() because mirror_run() will begin iterating again
|
|
|
|
* when the job is resumed.
|
|
|
|
*/
|
2018-12-13 19:24:34 +08:00
|
|
|
static void coroutine_fn mirror_wait_for_all_io(MirrorBlockJob *s)
|
2013-01-22 16:03:12 +08:00
|
|
|
{
|
|
|
|
while (s->in_flight > 0) {
|
2020-03-26 23:36:27 +08:00
|
|
|
mirror_wait_for_free_in_flight_slot(s);
|
2013-01-22 16:03:12 +08:00
|
|
|
}
|
2012-10-18 22:49:23 +08:00
|
|
|
}
|
|
|
|
|
2018-09-06 21:02:15 +08:00
|
|
|
/**
|
|
|
|
* mirror_exit_common: handle both abort() and prepare() cases.
|
|
|
|
* for .prepare, returns 0 on success and -errno on failure.
|
|
|
|
* for .abort cases, denoted by abort = true, MUST return 0.
|
|
|
|
*/
|
|
|
|
static int mirror_exit_common(Job *job)
|
2014-10-21 19:03:58 +08:00
|
|
|
{
|
2018-04-17 22:41:17 +08:00
|
|
|
MirrorBlockJob *s = container_of(job, MirrorBlockJob, common.job);
|
|
|
|
BlockJob *bjob = &s->common;
|
2019-10-14 23:39:28 +08:00
|
|
|
MirrorBDSOpaque *bs_opaque;
|
|
|
|
BlockDriverState *src;
|
|
|
|
BlockDriverState *target_bs;
|
|
|
|
BlockDriverState *mirror_top_bs;
|
2017-02-18 03:42:32 +08:00
|
|
|
Error *local_err = NULL;
|
2018-09-06 21:02:15 +08:00
|
|
|
bool abort = job->ret < 0;
|
|
|
|
int ret = 0;
|
|
|
|
|
2023-05-25 20:47:06 +08:00
|
|
|
GLOBAL_STATE_CODE();
|
|
|
|
|
2018-09-06 21:02:15 +08:00
|
|
|
if (s->prepared) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
s->prepared = true;
|
2015-09-15 17:58:23 +08:00
|
|
|
|
2023-10-27 23:53:18 +08:00
|
|
|
bdrv_graph_rdlock_main_loop();
|
2023-05-25 20:47:06 +08:00
|
|
|
|
2019-10-14 23:39:28 +08:00
|
|
|
mirror_top_bs = s->mirror_top_bs;
|
|
|
|
bs_opaque = mirror_top_bs->opaque;
|
|
|
|
src = mirror_top_bs->backing->bs;
|
|
|
|
target_bs = blk_bs(s->target);
|
|
|
|
|
2019-03-13 00:48:42 +08:00
|
|
|
if (bdrv_chain_contains(src, target_bs)) {
|
|
|
|
bdrv_unfreeze_backing_chain(mirror_top_bs, target_bs);
|
|
|
|
}
|
|
|
|
|
2019-09-16 22:19:09 +08:00
|
|
|
bdrv_release_dirty_bitmap(s->dirty_bitmap);
|
2017-06-05 20:39:03 +08:00
|
|
|
|
2018-08-30 09:57:30 +08:00
|
|
|
/* Make sure that the source BDS doesn't go away during bdrv_replace_node,
|
|
|
|
* before we can call bdrv_drained_end */
|
2015-09-15 17:58:23 +08:00
|
|
|
bdrv_ref(src);
|
2017-01-26 02:16:34 +08:00
|
|
|
bdrv_ref(mirror_top_bs);
|
2017-03-03 00:48:14 +08:00
|
|
|
bdrv_ref(target_bs);
|
|
|
|
|
2023-10-27 23:53:18 +08:00
|
|
|
bdrv_graph_rdunlock_main_loop();
|
|
|
|
|
2019-08-29 17:09:53 +08:00
|
|
|
/*
|
|
|
|
* Remove target parent that still uses BLK_PERM_WRITE/RESIZE before
|
2017-03-03 00:48:14 +08:00
|
|
|
* inserting target_bs at s->to_replace, where we might not be able to get
|
2017-05-29 20:08:32 +08:00
|
|
|
* these permissions.
|
2019-08-29 17:09:53 +08:00
|
|
|
*/
|
2017-03-03 00:48:14 +08:00
|
|
|
blk_unref(s->target);
|
|
|
|
s->target = NULL;
|
2017-01-26 02:16:34 +08:00
|
|
|
|
|
|
|
/* We don't access the source any more. Dropping any WRITE/RESIZE is
|
2019-07-22 23:44:27 +08:00
|
|
|
* required before it could become a backing file of target_bs. Not having
|
|
|
|
* these permissions any more means that we can't allow any new requests on
|
|
|
|
* mirror_top_bs from now on, so keep it drained. */
|
|
|
|
bdrv_drained_begin(mirror_top_bs);
|
2023-10-27 23:53:25 +08:00
|
|
|
bdrv_drained_begin(target_bs);
|
2019-05-23 01:03:47 +08:00
|
|
|
bs_opaque->stop = true;
|
2023-09-11 17:46:12 +08:00
|
|
|
|
|
|
|
bdrv_graph_rdlock_main_loop();
|
2019-05-23 01:03:47 +08:00
|
|
|
bdrv_child_refresh_perms(mirror_top_bs, mirror_top_bs->backing,
|
|
|
|
&error_abort);
|
2023-09-11 17:46:12 +08:00
|
|
|
|
2018-09-06 21:02:15 +08:00
|
|
|
if (!abort && s->backing_mode == MIRROR_SOURCE_BACKING_CHAIN) {
|
2017-01-26 02:16:34 +08:00
|
|
|
BlockDriverState *backing = s->is_none_mode ? src : s->base;
|
2019-06-12 22:27:32 +08:00
|
|
|
BlockDriverState *unfiltered_target = bdrv_skip_filters(target_bs);
|
|
|
|
|
|
|
|
if (bdrv_cow_bs(unfiltered_target) != backing) {
|
|
|
|
bdrv_set_backing_hd(unfiltered_target, backing, &local_err);
|
2017-02-18 03:42:32 +08:00
|
|
|
if (local_err) {
|
|
|
|
error_report_err(local_err);
|
2020-03-24 23:36:26 +08:00
|
|
|
local_err = NULL;
|
2018-08-30 09:57:30 +08:00
|
|
|
ret = -EPERM;
|
2017-02-18 03:42:32 +08:00
|
|
|
}
|
2017-01-26 02:16:34 +08:00
|
|
|
}
|
2021-04-09 20:04:18 +08:00
|
|
|
} else if (!abort && s->backing_mode == MIRROR_OPEN_BACKING_CHAIN) {
|
|
|
|
assert(!bdrv_backing_chain_next(target_bs));
|
|
|
|
ret = bdrv_open_backing_file(bdrv_skip_filters(target_bs), NULL,
|
|
|
|
"backing", &local_err);
|
|
|
|
if (ret < 0) {
|
|
|
|
error_report_err(local_err);
|
|
|
|
local_err = NULL;
|
|
|
|
}
|
2017-01-26 02:16:34 +08:00
|
|
|
}
|
2023-10-27 23:53:17 +08:00
|
|
|
bdrv_graph_rdunlock_main_loop();
|
2014-10-21 19:03:58 +08:00
|
|
|
|
2018-09-06 21:02:15 +08:00
|
|
|
if (s->should_complete && !abort) {
|
|
|
|
BlockDriverState *to_replace = s->to_replace ?: src;
|
2018-11-12 22:00:40 +08:00
|
|
|
bool ro = bdrv_is_read_only(to_replace);
|
2015-10-28 20:24:26 +08:00
|
|
|
|
2018-11-12 22:00:40 +08:00
|
|
|
if (ro != bdrv_is_read_only(target_bs)) {
|
|
|
|
bdrv_reopen_set_read_only(target_bs, ro, NULL);
|
2014-10-21 19:03:58 +08:00
|
|
|
}
|
2016-04-12 22:20:59 +08:00
|
|
|
|
|
|
|
/* 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. */
|
2019-03-08 23:48:53 +08:00
|
|
|
assert(s->in_drain);
|
2023-10-27 23:53:25 +08:00
|
|
|
bdrv_drained_begin(to_replace);
|
2020-02-18 18:34:46 +08:00
|
|
|
/*
|
|
|
|
* Cannot use check_to_replace_node() here, because that would
|
|
|
|
* check for an op blocker on @to_replace, and we have our own
|
|
|
|
* there.
|
|
|
|
*/
|
2023-12-06 02:20:02 +08:00
|
|
|
bdrv_graph_wrlock();
|
2020-02-18 18:34:46 +08:00
|
|
|
if (bdrv_recurse_can_replace(src, to_replace)) {
|
|
|
|
bdrv_replace_node(to_replace, target_bs, &local_err);
|
|
|
|
} else {
|
|
|
|
error_setg(&local_err, "Can no longer replace '%s' by '%s', "
|
|
|
|
"because it can no longer be guaranteed that doing so "
|
|
|
|
"would not lead to an abrupt change of visible data",
|
|
|
|
to_replace->node_name, target_bs->node_name);
|
|
|
|
}
|
2023-12-06 02:20:02 +08:00
|
|
|
bdrv_graph_wrunlock();
|
2023-10-27 23:53:25 +08:00
|
|
|
bdrv_drained_end(to_replace);
|
2017-03-06 23:20:51 +08:00
|
|
|
if (local_err) {
|
|
|
|
error_report_err(local_err);
|
2018-08-30 09:57:30 +08:00
|
|
|
ret = -EPERM;
|
2017-03-06 23:20:51 +08:00
|
|
|
}
|
2014-10-21 19:03:58 +08:00
|
|
|
}
|
|
|
|
if (s->to_replace) {
|
|
|
|
bdrv_op_unblock_all(s->to_replace, s->replace_blocker);
|
|
|
|
error_free(s->replace_blocker);
|
|
|
|
bdrv_unref(s->to_replace);
|
|
|
|
}
|
|
|
|
g_free(s->replaces);
|
2017-01-26 02:16:34 +08:00
|
|
|
|
2019-05-23 01:03:47 +08:00
|
|
|
/*
|
|
|
|
* Remove the mirror filter driver from the graph. Before this, get rid of
|
2017-01-26 02:16:34 +08:00
|
|
|
* the blockers on the intermediate nodes so that the resulting state is
|
2019-05-23 01:03:47 +08:00
|
|
|
* valid.
|
|
|
|
*/
|
2018-04-17 22:41:17 +08:00
|
|
|
block_job_remove_all_bdrv(bjob);
|
2023-12-06 02:20:02 +08:00
|
|
|
bdrv_graph_wrlock();
|
2019-06-12 22:27:32 +08:00
|
|
|
bdrv_replace_node(mirror_top_bs, mirror_top_bs->backing->bs, &error_abort);
|
2023-12-06 02:20:02 +08:00
|
|
|
bdrv_graph_wrunlock();
|
2023-10-27 23:53:25 +08:00
|
|
|
|
|
|
|
bdrv_drained_end(target_bs);
|
|
|
|
bdrv_unref(target_bs);
|
2017-01-26 02:16:34 +08:00
|
|
|
|
2018-06-14 02:18:19 +08:00
|
|
|
bs_opaque->job = NULL;
|
2017-01-26 02:16:34 +08:00
|
|
|
|
2015-11-23 10:28:04 +08:00
|
|
|
bdrv_drained_end(src);
|
2019-07-22 23:44:27 +08:00
|
|
|
bdrv_drained_end(mirror_top_bs);
|
2019-03-08 23:48:53 +08:00
|
|
|
s->in_drain = false;
|
2017-01-26 02:16:34 +08:00
|
|
|
bdrv_unref(mirror_top_bs);
|
2015-09-15 17:58:23 +08:00
|
|
|
bdrv_unref(src);
|
2018-08-30 09:57:30 +08:00
|
|
|
|
2018-09-06 21:02:15 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mirror_prepare(Job *job)
|
|
|
|
{
|
|
|
|
return mirror_exit_common(job);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mirror_abort(Job *job)
|
|
|
|
{
|
|
|
|
int ret = mirror_exit_common(job);
|
|
|
|
assert(ret == 0);
|
2014-10-21 19:03:58 +08:00
|
|
|
}
|
|
|
|
|
2018-12-13 19:24:34 +08:00
|
|
|
static void coroutine_fn mirror_throttle(MirrorBlockJob *s)
|
2016-07-14 21:33:24 +08:00
|
|
|
{
|
|
|
|
int64_t now = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
|
|
|
|
|
2018-01-19 03:25:40 +08:00
|
|
|
if (now - s->last_pause_ns > BLOCK_JOB_SLICE_TIME) {
|
2016-07-14 21:33:24 +08:00
|
|
|
s->last_pause_ns = now;
|
2018-04-18 22:32:20 +08:00
|
|
|
job_sleep_ns(&s->common.job, 0);
|
2016-07-14 21:33:24 +08:00
|
|
|
} else {
|
2018-04-13 23:31:02 +08:00
|
|
|
job_pause_point(&s->common.job);
|
2016-07-14 21:33:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-27 23:53:26 +08:00
|
|
|
static int coroutine_fn GRAPH_UNLOCKED mirror_dirty_init(MirrorBlockJob *s)
|
2016-07-14 21:33:25 +08:00
|
|
|
{
|
2017-09-25 22:55:21 +08:00
|
|
|
int64_t offset;
|
2023-10-27 23:53:26 +08:00
|
|
|
BlockDriverState *bs;
|
2016-07-14 21:33:25 +08:00
|
|
|
BlockDriverState *target_bs = blk_bs(s->target);
|
2017-09-25 22:55:21 +08:00
|
|
|
int ret;
|
block: Make bdrv_is_allocated_above() byte-based
We are gradually moving away from sector-based interfaces, towards
byte-based. In the common case, allocation is unlikely to ever use
values that are not naturally sector-aligned, but it is possible
that byte-based values will let us be more precise about allocation
at the end of an unaligned file that can do byte-based access.
Changing the signature of the function to use int64_t *pnum ensures
that the compiler enforces that all callers are updated. For now,
the io.c layer still assert()s that all callers are sector-aligned,
but that can be relaxed when a later patch implements byte-based
block status. Therefore, for the most part this patch is just the
addition of scaling at the callers followed by inverse scaling at
bdrv_is_allocated(). But some code, particularly stream_run(),
gets a lot simpler because it no longer has to mess with sectors.
Leave comments where we can further simplify by switching to
byte-based iterations, once later patches eliminate the need for
sector-aligned operations.
For ease of review, bdrv_is_allocated() was tackled separately.
Signed-off-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2017-07-07 20:44:59 +08:00
|
|
|
int64_t count;
|
2016-07-14 21:33:25 +08:00
|
|
|
|
2023-10-27 23:53:26 +08:00
|
|
|
bdrv_graph_co_rdlock();
|
|
|
|
bs = s->mirror_top_bs->backing->bs;
|
|
|
|
bdrv_graph_co_rdunlock();
|
|
|
|
|
2019-07-25 01:12:30 +08:00
|
|
|
if (s->zero_target) {
|
2016-07-14 21:33:28 +08:00
|
|
|
if (!bdrv_can_write_zeroes_with_unmap(target_bs)) {
|
2017-09-25 22:55:20 +08:00
|
|
|
bdrv_set_dirty_bitmap(s->dirty_bitmap, 0, s->bdev_length);
|
2016-07-14 21:33:28 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-02-02 22:25:15 +08:00
|
|
|
s->initial_zeroing_ongoing = true;
|
2017-09-25 22:55:21 +08:00
|
|
|
for (offset = 0; offset < s->bdev_length; ) {
|
|
|
|
int bytes = MIN(s->bdev_length - offset,
|
|
|
|
QEMU_ALIGN_DOWN(INT_MAX, s->granularity));
|
2016-07-14 21:33:28 +08:00
|
|
|
|
|
|
|
mirror_throttle(s);
|
|
|
|
|
2018-04-17 18:56:07 +08:00
|
|
|
if (job_is_cancelled(&s->common.job)) {
|
2017-02-02 22:25:15 +08:00
|
|
|
s->initial_zeroing_ongoing = false;
|
2016-07-14 21:33:28 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s->in_flight >= MAX_IN_FLIGHT) {
|
2017-03-14 03:55:18 +08:00
|
|
|
trace_mirror_yield(s, UINT64_MAX, s->buf_free_count,
|
|
|
|
s->in_flight);
|
2020-03-26 23:36:27 +08:00
|
|
|
mirror_wait_for_free_in_flight_slot(s);
|
2016-07-14 21:33:28 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-06-14 02:18:10 +08:00
|
|
|
mirror_perform(s, offset, bytes, MIRROR_METHOD_ZERO);
|
2017-09-25 22:55:21 +08:00
|
|
|
offset += bytes;
|
2016-07-14 21:33:28 +08:00
|
|
|
}
|
|
|
|
|
2016-10-27 18:48:50 +08:00
|
|
|
mirror_wait_for_all_io(s);
|
2017-02-02 22:25:15 +08:00
|
|
|
s->initial_zeroing_ongoing = false;
|
2016-07-14 21:33:27 +08:00
|
|
|
}
|
|
|
|
|
2016-07-14 21:33:25 +08:00
|
|
|
/* First part, loop on the sectors and initialize the dirty bitmap. */
|
2017-09-25 22:55:21 +08:00
|
|
|
for (offset = 0; offset < s->bdev_length; ) {
|
2016-07-14 21:33:25 +08:00
|
|
|
/* Just to make sure we are not exceeding int limit. */
|
2017-09-25 22:55:21 +08:00
|
|
|
int bytes = MIN(s->bdev_length - offset,
|
|
|
|
QEMU_ALIGN_DOWN(INT_MAX, s->granularity));
|
2016-07-14 21:33:25 +08:00
|
|
|
|
|
|
|
mirror_throttle(s);
|
|
|
|
|
2018-04-17 18:56:07 +08:00
|
|
|
if (job_is_cancelled(&s->common.job)) {
|
2016-07-14 21:33:25 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-02-03 23:21:43 +08:00
|
|
|
WITH_GRAPH_RDLOCK_GUARD() {
|
2023-09-04 18:03:06 +08:00
|
|
|
ret = bdrv_co_is_allocated_above(bs, s->base_overlay, true, offset,
|
|
|
|
bytes, &count);
|
2023-02-03 23:21:43 +08:00
|
|
|
}
|
2016-07-14 21:33:25 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-09-25 22:55:21 +08:00
|
|
|
assert(count);
|
2020-10-27 13:05:53 +08:00
|
|
|
if (ret > 0) {
|
2017-09-25 22:55:21 +08:00
|
|
|
bdrv_set_dirty_bitmap(s->dirty_bitmap, offset, count);
|
2016-07-14 21:33:25 +08:00
|
|
|
}
|
2017-09-25 22:55:21 +08:00
|
|
|
offset += count;
|
2016-07-14 21:33:25 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-11-10 00:20:08 +08:00
|
|
|
/* Called when going out of the streaming phase to flush the bulk of the
|
|
|
|
* data to the medium, or just before completing.
|
|
|
|
*/
|
2023-03-09 16:44:50 +08:00
|
|
|
static int coroutine_fn mirror_flush(MirrorBlockJob *s)
|
2016-11-10 00:20:08 +08:00
|
|
|
{
|
2023-03-09 16:44:50 +08:00
|
|
|
int ret = blk_co_flush(s->target);
|
2016-11-10 00:20:08 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
if (mirror_error_action(s, false, -ret) == BLOCK_ERROR_ACTION_REPORT) {
|
|
|
|
s->ret = ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-08-30 09:57:26 +08:00
|
|
|
static int coroutine_fn mirror_run(Job *job, Error **errp)
|
2012-10-18 22:49:23 +08:00
|
|
|
{
|
2018-08-30 09:57:26 +08:00
|
|
|
MirrorBlockJob *s = container_of(job, MirrorBlockJob, common.job);
|
2023-10-27 23:53:26 +08:00
|
|
|
BlockDriverState *bs;
|
2023-02-03 23:21:41 +08:00
|
|
|
MirrorBDSOpaque *mirror_top_opaque = s->mirror_top_bs->opaque;
|
2016-04-12 22:17:41 +08:00
|
|
|
BlockDriverState *target_bs = blk_bs(s->target);
|
2016-10-27 18:48:51 +08:00
|
|
|
bool need_drain = true;
|
2022-09-26 17:32:09 +08:00
|
|
|
BlockDeviceIoStatus iostatus;
|
2016-07-14 21:33:25 +08:00
|
|
|
int64_t length;
|
2020-05-11 21:58:24 +08:00
|
|
|
int64_t target_length;
|
2013-01-22 00:09:43 +08:00
|
|
|
BlockDriverInfo bdi;
|
2015-01-22 21:03:29 +08:00
|
|
|
char backing_filename[2]; /* we only need 2 characters because we are only
|
|
|
|
checking for a NULL string */
|
2012-10-18 22:49:23 +08:00
|
|
|
int ret = 0;
|
|
|
|
|
2023-10-27 23:53:26 +08:00
|
|
|
bdrv_graph_co_rdlock();
|
|
|
|
bs = bdrv_filter_bs(s->mirror_top_bs);
|
|
|
|
bdrv_graph_co_rdunlock();
|
|
|
|
|
2018-04-17 18:56:07 +08:00
|
|
|
if (job_is_cancelled(&s->common.job)) {
|
2012-10-18 22:49:23 +08:00
|
|
|
goto immediate_exit;
|
|
|
|
}
|
|
|
|
|
2023-02-03 23:22:02 +08:00
|
|
|
bdrv_graph_co_rdlock();
|
2023-01-14 04:42:04 +08:00
|
|
|
s->bdev_length = bdrv_co_getlength(bs);
|
2023-02-03 23:22:02 +08:00
|
|
|
bdrv_graph_co_rdunlock();
|
|
|
|
|
2014-10-24 21:57:36 +08:00
|
|
|
if (s->bdev_length < 0) {
|
|
|
|
ret = s->bdev_length;
|
2014-04-29 18:09:09 +08:00
|
|
|
goto immediate_exit;
|
2017-02-17 18:11:28 +08:00
|
|
|
}
|
|
|
|
|
2023-01-14 04:42:04 +08:00
|
|
|
target_length = blk_co_getlength(s->target);
|
2020-05-11 21:58:24 +08:00
|
|
|
if (target_length < 0) {
|
|
|
|
ret = target_length;
|
|
|
|
goto immediate_exit;
|
|
|
|
}
|
|
|
|
|
2017-02-17 18:11:28 +08:00
|
|
|
/* Active commit must resize the base image if its size differs from the
|
|
|
|
* active layer. */
|
|
|
|
if (s->base == blk_bs(s->target)) {
|
2020-05-11 21:58:24 +08:00
|
|
|
if (s->bdev_length > target_length) {
|
2022-10-13 20:37:03 +08:00
|
|
|
ret = blk_co_truncate(s->target, s->bdev_length, false,
|
|
|
|
PREALLOC_MODE_OFF, 0, NULL);
|
2017-02-17 18:11:28 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
goto immediate_exit;
|
|
|
|
}
|
|
|
|
}
|
2020-05-11 21:58:24 +08:00
|
|
|
} else if (s->bdev_length != target_length) {
|
|
|
|
error_setg(errp, "Source and target image have different sizes");
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto immediate_exit;
|
2017-02-17 18:11:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (s->bdev_length == 0) {
|
2018-04-25 20:56:09 +08:00
|
|
|
/* Transition to the READY state and wait for complete. */
|
|
|
|
job_transition_to_ready(&s->common.job);
|
2023-10-31 21:54:30 +08:00
|
|
|
qatomic_set(&s->actively_synced, true);
|
job: Add job_cancel_requested()
Most callers of job_is_cancelled() actually want to know whether the job
is on its way to immediate termination. For example, we refuse to pause
jobs that are cancelled; but this only makes sense for jobs that are
really actually cancelled.
A mirror job that is cancelled during READY with force=false should
absolutely be allowed to pause. This "cancellation" (which is actually
a kind of completion) may take an indefinite amount of time, and so
should behave like any job during normal operation. For example, with
on-target-error=stop, the job should stop on write errors. (In
contrast, force-cancelled jobs should not get write errors, as they
should just terminate and not do further I/O.)
Therefore, redefine job_is_cancelled() to only return true for jobs that
are force-cancelled (which as of HEAD^ means any job that interprets the
cancellation request as a request for immediate termination), and add
job_cancel_requested() as the general variant, which returns true for
any jobs which have been requested to be cancelled, whether it be
immediately or after an arbitrarily long completion phase.
Finally, here is a justification for how different job_is_cancelled()
invocations are treated by this patch:
- block/mirror.c (mirror_run()):
- The first invocation is a while loop that should loop until the job
has been cancelled or scheduled for completion. What kind of cancel
does not matter, only the fact that the job is supposed to end.
- The second invocation wants to know whether the job has been
soft-cancelled. Calling job_cancel_requested() is a bit too broad,
but if the job were force-cancelled, we should leave the main loop
as soon as possible anyway, so this should not matter here.
- The last two invocations already check force_cancel, so they should
continue to use job_is_cancelled().
- block/backup.c, block/commit.c, block/stream.c, anything in tests/:
These jobs know only force-cancel, so there is no difference between
job_is_cancelled() and job_cancel_requested(). We can continue using
job_is_cancelled().
- job.c:
- job_pause_point(), job_yield(), job_sleep_ns(): Only force-cancelled
jobs should be prevented from being paused. Continue using job_is_cancelled().
- job_update_rc(), job_finalize_single(), job_finish_sync(): These
functions are all called after the job has left its main loop. The
mirror job (the only job that can be soft-cancelled) will clear
.cancelled before leaving the main loop if it has been
soft-cancelled. Therefore, these functions will observe .cancelled
to be true only if the job has been force-cancelled. We can
continue to use job_is_cancelled().
(Furthermore, conceptually, a soft-cancelled mirror job should not
report to have been cancelled. It should report completion (see
also the block-job-cancel QAPI documentation). Therefore, it makes
sense for these functions not to distinguish between a
soft-cancelled mirror job and a job that has completed as normal.)
- job_completed_txn_abort(): All jobs other than @job have been
force-cancelled. job_is_cancelled() must be true for them.
Regarding @job itself: job_completed_txn_abort() is mostly called
when the job's return value is not 0. A soft-cancelled mirror has a
return value of 0, and so will not end up here then.
However, job_cancel() invokes job_completed_txn_abort() if the job
has been deferred to the main loop, which is mostly the case for
completed jobs (which skip the assertion), but not for sure.
To be safe, use job_cancel_requested() in this assertion.
- job_complete(): This is function eventually invoked by the user
(through qmp_block_job_complete() or qmp_job_complete(), or
job_complete_sync(), which comes from qemu-img). The intention here
is to prevent a user from invoking job-complete after the job has
been cancelled. This should also apply to soft cancelling: After a
mirror job has been soft-cancelled, the user should not be able to
decide otherwise and have it complete as normal (i.e. pivoting to
the target).
- job_cancel(): Both functions are equivalent (see comment there), but
we want to use job_is_cancelled(), because this shows that we call
job_completed_txn_abort() only for force-cancelled jobs. (As
explained for job_update_rc(), soft-cancelled jobs should be treated
as if they have completed as normal.)
Buglink: https://gitlab.com/qemu-project/qemu/-/issues/462
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20211006151940.214590-9-hreitz@redhat.com>
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
2021-10-06 23:19:35 +08:00
|
|
|
while (!job_cancel_requested(&s->common.job) && !s->should_complete) {
|
2018-04-24 22:55:04 +08:00
|
|
|
job_yield(&s->common.job);
|
2014-06-24 20:26:36 +08:00
|
|
|
}
|
|
|
|
goto immediate_exit;
|
2012-10-18 22:49:23 +08:00
|
|
|
}
|
|
|
|
|
2014-10-24 21:57:36 +08:00
|
|
|
length = DIV_ROUND_UP(s->bdev_length, s->granularity);
|
2013-01-22 16:03:14 +08:00
|
|
|
s->in_flight_bitmap = bitmap_new(length);
|
|
|
|
|
2013-01-22 00:09:43 +08:00
|
|
|
/* If we have no backing file yet in the destination, we cannot let
|
|
|
|
* the destination do COW. Instead, we copy sectors around the
|
|
|
|
* dirty data if needed. We need a bitmap to do that.
|
|
|
|
*/
|
2016-04-12 22:17:41 +08:00
|
|
|
bdrv_get_backing_filename(target_bs, backing_filename,
|
2013-01-22 00:09:43 +08:00
|
|
|
sizeof(backing_filename));
|
2023-05-04 19:57:44 +08:00
|
|
|
bdrv_graph_co_rdlock();
|
2023-01-14 04:42:08 +08:00
|
|
|
if (!bdrv_co_get_info(target_bs, &bdi) && bdi.cluster_size) {
|
2017-07-07 20:44:46 +08:00
|
|
|
s->target_cluster_size = bdi.cluster_size;
|
|
|
|
} else {
|
|
|
|
s->target_cluster_size = BDRV_SECTOR_SIZE;
|
2016-02-05 10:00:29 +08:00
|
|
|
}
|
2019-06-12 22:27:32 +08:00
|
|
|
if (backing_filename[0] && !bdrv_backing_chain_next(target_bs) &&
|
2017-07-07 20:44:46 +08:00
|
|
|
s->granularity < s->target_cluster_size) {
|
|
|
|
s->buf_size = MAX(s->buf_size, s->target_cluster_size);
|
2016-02-05 10:00:29 +08:00
|
|
|
s->cow_bitmap = bitmap_new(length);
|
2013-01-22 00:09:43 +08:00
|
|
|
}
|
2016-04-12 22:17:41 +08:00
|
|
|
s->max_iov = MIN(bs->bl.max_iov, target_bs->bl.max_iov);
|
2023-10-27 23:53:17 +08:00
|
|
|
bdrv_graph_co_rdunlock();
|
2013-01-22 00:09:43 +08:00
|
|
|
|
2014-05-22 00:16:21 +08:00
|
|
|
s->buf = qemu_try_blockalign(bs, s->buf_size);
|
|
|
|
if (s->buf == NULL) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto immediate_exit;
|
|
|
|
}
|
|
|
|
|
2013-01-22 16:03:14 +08:00
|
|
|
mirror_free_init(s);
|
2012-10-18 22:49:23 +08:00
|
|
|
|
2016-07-14 21:33:24 +08:00
|
|
|
s->last_pause_ns = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
|
2013-12-16 14:45:30 +08:00
|
|
|
if (!s->is_none_mode) {
|
2016-07-14 21:33:25 +08:00
|
|
|
ret = mirror_dirty_init(s);
|
2018-04-17 18:56:07 +08:00
|
|
|
if (ret < 0 || job_is_cancelled(&s->common.job)) {
|
2016-07-14 21:33:25 +08:00
|
|
|
goto immediate_exit;
|
2012-10-18 22:49:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-03 23:21:41 +08:00
|
|
|
/*
|
|
|
|
* Only now the job is fully initialised and mirror_top_bs should start
|
|
|
|
* accessing it.
|
|
|
|
*/
|
|
|
|
mirror_top_opaque->job = s;
|
|
|
|
|
2016-10-14 05:58:21 +08:00
|
|
|
assert(!s->dbi);
|
2017-09-25 22:55:16 +08:00
|
|
|
s->dbi = bdrv_dirty_iter_new(s->dirty_bitmap);
|
2012-10-18 22:49:23 +08:00
|
|
|
for (;;) {
|
2016-07-14 21:33:24 +08:00
|
|
|
int64_t cnt, delta;
|
2012-10-18 22:49:23 +08:00
|
|
|
bool should_complete;
|
|
|
|
|
2013-01-22 16:03:12 +08:00
|
|
|
if (s->ret < 0) {
|
|
|
|
ret = s->ret;
|
|
|
|
goto immediate_exit;
|
|
|
|
}
|
|
|
|
|
2018-04-13 23:31:02 +08:00
|
|
|
job_pause_point(&s->common.job);
|
2016-06-17 00:56:28 +08:00
|
|
|
|
2021-10-06 23:19:37 +08:00
|
|
|
if (job_is_cancelled(&s->common.job)) {
|
|
|
|
ret = 0;
|
|
|
|
goto immediate_exit;
|
|
|
|
}
|
|
|
|
|
2015-04-18 07:50:02 +08:00
|
|
|
cnt = bdrv_get_dirty_count(s->dirty_bitmap);
|
2018-01-19 01:08:22 +08:00
|
|
|
/* cnt is the number of dirty bytes remaining and s->bytes_in_flight is
|
|
|
|
* the number of bytes currently being processed; together those are
|
|
|
|
* the current remaining operation length */
|
block/mirror: Do not wait for active writes
Waiting for all active writes to settle before daring to create a
background copying operation means that we will never do background
operations while the guest does anything (in write-blocking mode), and
therefore cannot converge. Yes, we also will not diverge, but actually
converging would be even nicer.
It is unclear why we did decide to wait for all active writes to settle
before creating a background operation, but it just does not seem
necessary. Active writes will put themselves into the in_flight bitmap
and thus properly block actually conflicting background requests.
It is important for active requests to wait on overlapping background
requests, which we do in active_write_prepare(). However, so far it was
not documented why it is important. Add such documentation now, and
also to the other call of mirror_wait_on_conflicts(), so that it becomes
more clear why and when requests need to actively wait for other
requests to settle.
Another thing to note is that of course we need to ensure that there are
no active requests when the job completes, but that is done by virtue of
the BDS being drained anyway, so there cannot be any active requests at
that point.
With this change, we will need to explicitly keep track of how many
bytes are in flight in active requests so that
job_progress_set_remaining() in mirror_run() can set the correct number
of remaining bytes.
Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=2123297
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
Message-Id: <20221109165452.67927-2-hreitz@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2022-11-10 00:54:48 +08:00
|
|
|
job_progress_set_remaining(&s->common.job,
|
|
|
|
s->bytes_in_flight + cnt +
|
|
|
|
s->active_write_bytes_in_flight);
|
2013-01-22 16:03:12 +08:00
|
|
|
|
|
|
|
/* Note that even when no rate limit is applied we need to yield
|
2015-04-03 22:05:21 +08:00
|
|
|
* periodically with no pending I/O so that bdrv_drain_all() returns.
|
2018-01-19 03:25:40 +08:00
|
|
|
* We do so every BLKOCK_JOB_SLICE_TIME nanoseconds, or when there is
|
|
|
|
* an error, or when the source is clean, whichever comes first. */
|
2016-07-14 21:33:24 +08:00
|
|
|
delta = qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - s->last_pause_ns;
|
2022-09-26 17:32:09 +08:00
|
|
|
WITH_JOB_LOCK_GUARD() {
|
|
|
|
iostatus = s->common.iostatus;
|
|
|
|
}
|
2018-01-19 03:25:40 +08:00
|
|
|
if (delta < BLOCK_JOB_SLICE_TIME &&
|
2022-09-26 17:32:09 +08:00
|
|
|
iostatus == BLOCK_DEVICE_IO_STATUS_OK) {
|
2016-06-22 20:35:27 +08:00
|
|
|
if (s->in_flight >= MAX_IN_FLIGHT || s->buf_free_count == 0 ||
|
2013-01-22 16:03:14 +08:00
|
|
|
(cnt == 0 && s->in_flight > 0)) {
|
2017-09-25 22:55:18 +08:00
|
|
|
trace_mirror_yield(s, cnt, s->buf_free_count, s->in_flight);
|
2020-03-26 23:36:27 +08:00
|
|
|
mirror_wait_for_free_in_flight_slot(s);
|
2013-01-22 16:03:12 +08:00
|
|
|
continue;
|
|
|
|
} else if (cnt != 0) {
|
2023-10-27 23:53:26 +08:00
|
|
|
bdrv_graph_co_rdlock();
|
2023-05-11 04:36:00 +08:00
|
|
|
mirror_iteration(s);
|
2023-10-27 23:53:26 +08:00
|
|
|
bdrv_graph_co_rdunlock();
|
2012-10-18 22:49:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
should_complete = false;
|
2013-01-22 16:03:12 +08:00
|
|
|
if (s->in_flight == 0 && cnt == 0) {
|
2012-10-18 22:49:23 +08:00
|
|
|
trace_mirror_before_flush(s);
|
2021-10-06 23:19:30 +08:00
|
|
|
if (!job_is_ready(&s->common.job)) {
|
2016-11-10 00:20:08 +08:00
|
|
|
if (mirror_flush(s) < 0) {
|
|
|
|
/* Go check s->ret. */
|
|
|
|
continue;
|
2012-10-18 22:49:28 +08:00
|
|
|
}
|
|
|
|
/* We're out of the streaming phase. From now on, if the job
|
|
|
|
* is cancelled we will actually complete all pending I/O and
|
|
|
|
* report completion. This way, block-job-cancel will leave
|
|
|
|
* the target in a consistent state.
|
|
|
|
*/
|
2018-04-25 20:56:09 +08:00
|
|
|
job_transition_to_ready(&s->common.job);
|
2023-10-31 21:54:23 +08:00
|
|
|
}
|
2023-10-31 21:54:26 +08:00
|
|
|
if (qatomic_read(&s->copy_mode) != MIRROR_COPY_MODE_BACKGROUND) {
|
2023-10-31 21:54:30 +08:00
|
|
|
qatomic_set(&s->actively_synced, true);
|
2012-10-18 22:49:25 +08:00
|
|
|
}
|
2016-11-10 00:20:08 +08:00
|
|
|
|
|
|
|
should_complete = s->should_complete ||
|
job: Add job_cancel_requested()
Most callers of job_is_cancelled() actually want to know whether the job
is on its way to immediate termination. For example, we refuse to pause
jobs that are cancelled; but this only makes sense for jobs that are
really actually cancelled.
A mirror job that is cancelled during READY with force=false should
absolutely be allowed to pause. This "cancellation" (which is actually
a kind of completion) may take an indefinite amount of time, and so
should behave like any job during normal operation. For example, with
on-target-error=stop, the job should stop on write errors. (In
contrast, force-cancelled jobs should not get write errors, as they
should just terminate and not do further I/O.)
Therefore, redefine job_is_cancelled() to only return true for jobs that
are force-cancelled (which as of HEAD^ means any job that interprets the
cancellation request as a request for immediate termination), and add
job_cancel_requested() as the general variant, which returns true for
any jobs which have been requested to be cancelled, whether it be
immediately or after an arbitrarily long completion phase.
Finally, here is a justification for how different job_is_cancelled()
invocations are treated by this patch:
- block/mirror.c (mirror_run()):
- The first invocation is a while loop that should loop until the job
has been cancelled or scheduled for completion. What kind of cancel
does not matter, only the fact that the job is supposed to end.
- The second invocation wants to know whether the job has been
soft-cancelled. Calling job_cancel_requested() is a bit too broad,
but if the job were force-cancelled, we should leave the main loop
as soon as possible anyway, so this should not matter here.
- The last two invocations already check force_cancel, so they should
continue to use job_is_cancelled().
- block/backup.c, block/commit.c, block/stream.c, anything in tests/:
These jobs know only force-cancel, so there is no difference between
job_is_cancelled() and job_cancel_requested(). We can continue using
job_is_cancelled().
- job.c:
- job_pause_point(), job_yield(), job_sleep_ns(): Only force-cancelled
jobs should be prevented from being paused. Continue using job_is_cancelled().
- job_update_rc(), job_finalize_single(), job_finish_sync(): These
functions are all called after the job has left its main loop. The
mirror job (the only job that can be soft-cancelled) will clear
.cancelled before leaving the main loop if it has been
soft-cancelled. Therefore, these functions will observe .cancelled
to be true only if the job has been force-cancelled. We can
continue to use job_is_cancelled().
(Furthermore, conceptually, a soft-cancelled mirror job should not
report to have been cancelled. It should report completion (see
also the block-job-cancel QAPI documentation). Therefore, it makes
sense for these functions not to distinguish between a
soft-cancelled mirror job and a job that has completed as normal.)
- job_completed_txn_abort(): All jobs other than @job have been
force-cancelled. job_is_cancelled() must be true for them.
Regarding @job itself: job_completed_txn_abort() is mostly called
when the job's return value is not 0. A soft-cancelled mirror has a
return value of 0, and so will not end up here then.
However, job_cancel() invokes job_completed_txn_abort() if the job
has been deferred to the main loop, which is mostly the case for
completed jobs (which skip the assertion), but not for sure.
To be safe, use job_cancel_requested() in this assertion.
- job_complete(): This is function eventually invoked by the user
(through qmp_block_job_complete() or qmp_job_complete(), or
job_complete_sync(), which comes from qemu-img). The intention here
is to prevent a user from invoking job-complete after the job has
been cancelled. This should also apply to soft cancelling: After a
mirror job has been soft-cancelled, the user should not be able to
decide otherwise and have it complete as normal (i.e. pivoting to
the target).
- job_cancel(): Both functions are equivalent (see comment there), but
we want to use job_is_cancelled(), because this shows that we call
job_completed_txn_abort() only for force-cancelled jobs. (As
explained for job_update_rc(), soft-cancelled jobs should be treated
as if they have completed as normal.)
Buglink: https://gitlab.com/qemu-project/qemu/-/issues/462
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20211006151940.214590-9-hreitz@redhat.com>
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
2021-10-06 23:19:35 +08:00
|
|
|
job_cancel_requested(&s->common.job);
|
2016-11-10 00:20:08 +08:00
|
|
|
cnt = bdrv_get_dirty_count(s->dirty_bitmap);
|
2012-10-18 22:49:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cnt == 0 && should_complete) {
|
|
|
|
/* The dirty bitmap is not updated while operations are pending.
|
|
|
|
* If we're about to exit, wait for pending operations before
|
|
|
|
* calling bdrv_get_dirty_count(bs), or we may exit while the
|
|
|
|
* source has dirty data to copy!
|
|
|
|
*
|
|
|
|
* Note that I/O can be submitted by the guest while
|
2016-10-27 18:48:51 +08:00
|
|
|
* mirror_populate runs, so pause it now. Before deciding
|
|
|
|
* whether to switch to target check one last time if I/O has
|
|
|
|
* come in the meanwhile, and if not flush the data to disk.
|
2012-10-18 22:49:23 +08:00
|
|
|
*/
|
2017-09-25 22:55:18 +08:00
|
|
|
trace_mirror_before_drain(s, cnt);
|
2016-10-27 18:48:51 +08:00
|
|
|
|
2019-03-08 23:48:53 +08:00
|
|
|
s->in_drain = true;
|
2016-10-27 18:48:51 +08:00
|
|
|
bdrv_drained_begin(bs);
|
block/mirror: Do not wait for active writes
Waiting for all active writes to settle before daring to create a
background copying operation means that we will never do background
operations while the guest does anything (in write-blocking mode), and
therefore cannot converge. Yes, we also will not diverge, but actually
converging would be even nicer.
It is unclear why we did decide to wait for all active writes to settle
before creating a background operation, but it just does not seem
necessary. Active writes will put themselves into the in_flight bitmap
and thus properly block actually conflicting background requests.
It is important for active requests to wait on overlapping background
requests, which we do in active_write_prepare(). However, so far it was
not documented why it is important. Add such documentation now, and
also to the other call of mirror_wait_on_conflicts(), so that it becomes
more clear why and when requests need to actively wait for other
requests to settle.
Another thing to note is that of course we need to ensure that there are
no active requests when the job completes, but that is done by virtue of
the BDS being drained anyway, so there cannot be any active requests at
that point.
With this change, we will need to explicitly keep track of how many
bytes are in flight in active requests so that
job_progress_set_remaining() in mirror_run() can set the correct number
of remaining bytes.
Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=2123297
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
Message-Id: <20221109165452.67927-2-hreitz@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2022-11-10 00:54:48 +08:00
|
|
|
|
|
|
|
/* Must be zero because we are drained */
|
|
|
|
assert(s->in_active_write_counter == 0);
|
|
|
|
|
2015-04-18 07:50:02 +08:00
|
|
|
cnt = bdrv_get_dirty_count(s->dirty_bitmap);
|
2016-11-10 00:20:08 +08:00
|
|
|
if (cnt > 0 || mirror_flush(s) < 0) {
|
2016-10-27 18:48:51 +08:00
|
|
|
bdrv_drained_end(bs);
|
2019-03-08 23:48:53 +08:00
|
|
|
s->in_drain = false;
|
2016-10-27 18:48:51 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The two disks are in sync. Exit and report successful
|
|
|
|
* completion.
|
|
|
|
*/
|
|
|
|
assert(QLIST_EMPTY(&bs->tracked_requests));
|
|
|
|
need_drain = false;
|
|
|
|
break;
|
2012-10-18 22:49:23 +08:00
|
|
|
}
|
|
|
|
|
2021-10-06 23:19:30 +08:00
|
|
|
if (job_is_ready(&s->common.job) && !should_complete) {
|
2023-05-11 04:36:00 +08:00
|
|
|
if (s->in_flight == 0 && cnt == 0) {
|
|
|
|
trace_mirror_before_sleep(s, cnt, job_is_ready(&s->common.job),
|
|
|
|
BLOCK_JOB_SLICE_TIME);
|
|
|
|
job_sleep_ns(&s->common.job, BLOCK_JOB_SLICE_TIME);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
block_job_ratelimit_sleep(&s->common);
|
2018-04-24 20:35:27 +08:00
|
|
|
}
|
2016-07-14 21:33:24 +08:00
|
|
|
s->last_pause_ns = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
|
2012-10-18 22:49:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
immediate_exit:
|
2013-01-22 16:03:12 +08:00
|
|
|
if (s->in_flight > 0) {
|
|
|
|
/* We get here only if something went wrong. Either the job failed,
|
|
|
|
* or it was cancelled prematurely so that we do not guarantee that
|
|
|
|
* the target is a copy of the source.
|
|
|
|
*/
|
job: Add job_cancel_requested()
Most callers of job_is_cancelled() actually want to know whether the job
is on its way to immediate termination. For example, we refuse to pause
jobs that are cancelled; but this only makes sense for jobs that are
really actually cancelled.
A mirror job that is cancelled during READY with force=false should
absolutely be allowed to pause. This "cancellation" (which is actually
a kind of completion) may take an indefinite amount of time, and so
should behave like any job during normal operation. For example, with
on-target-error=stop, the job should stop on write errors. (In
contrast, force-cancelled jobs should not get write errors, as they
should just terminate and not do further I/O.)
Therefore, redefine job_is_cancelled() to only return true for jobs that
are force-cancelled (which as of HEAD^ means any job that interprets the
cancellation request as a request for immediate termination), and add
job_cancel_requested() as the general variant, which returns true for
any jobs which have been requested to be cancelled, whether it be
immediately or after an arbitrarily long completion phase.
Finally, here is a justification for how different job_is_cancelled()
invocations are treated by this patch:
- block/mirror.c (mirror_run()):
- The first invocation is a while loop that should loop until the job
has been cancelled or scheduled for completion. What kind of cancel
does not matter, only the fact that the job is supposed to end.
- The second invocation wants to know whether the job has been
soft-cancelled. Calling job_cancel_requested() is a bit too broad,
but if the job were force-cancelled, we should leave the main loop
as soon as possible anyway, so this should not matter here.
- The last two invocations already check force_cancel, so they should
continue to use job_is_cancelled().
- block/backup.c, block/commit.c, block/stream.c, anything in tests/:
These jobs know only force-cancel, so there is no difference between
job_is_cancelled() and job_cancel_requested(). We can continue using
job_is_cancelled().
- job.c:
- job_pause_point(), job_yield(), job_sleep_ns(): Only force-cancelled
jobs should be prevented from being paused. Continue using job_is_cancelled().
- job_update_rc(), job_finalize_single(), job_finish_sync(): These
functions are all called after the job has left its main loop. The
mirror job (the only job that can be soft-cancelled) will clear
.cancelled before leaving the main loop if it has been
soft-cancelled. Therefore, these functions will observe .cancelled
to be true only if the job has been force-cancelled. We can
continue to use job_is_cancelled().
(Furthermore, conceptually, a soft-cancelled mirror job should not
report to have been cancelled. It should report completion (see
also the block-job-cancel QAPI documentation). Therefore, it makes
sense for these functions not to distinguish between a
soft-cancelled mirror job and a job that has completed as normal.)
- job_completed_txn_abort(): All jobs other than @job have been
force-cancelled. job_is_cancelled() must be true for them.
Regarding @job itself: job_completed_txn_abort() is mostly called
when the job's return value is not 0. A soft-cancelled mirror has a
return value of 0, and so will not end up here then.
However, job_cancel() invokes job_completed_txn_abort() if the job
has been deferred to the main loop, which is mostly the case for
completed jobs (which skip the assertion), but not for sure.
To be safe, use job_cancel_requested() in this assertion.
- job_complete(): This is function eventually invoked by the user
(through qmp_block_job_complete() or qmp_job_complete(), or
job_complete_sync(), which comes from qemu-img). The intention here
is to prevent a user from invoking job-complete after the job has
been cancelled. This should also apply to soft cancelling: After a
mirror job has been soft-cancelled, the user should not be able to
decide otherwise and have it complete as normal (i.e. pivoting to
the target).
- job_cancel(): Both functions are equivalent (see comment there), but
we want to use job_is_cancelled(), because this shows that we call
job_completed_txn_abort() only for force-cancelled jobs. (As
explained for job_update_rc(), soft-cancelled jobs should be treated
as if they have completed as normal.)
Buglink: https://gitlab.com/qemu-project/qemu/-/issues/462
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20211006151940.214590-9-hreitz@redhat.com>
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
2021-10-06 23:19:35 +08:00
|
|
|
assert(ret < 0 || job_is_cancelled(&s->common.job));
|
2016-10-27 18:48:51 +08:00
|
|
|
assert(need_drain);
|
2016-10-27 18:48:50 +08:00
|
|
|
mirror_wait_for_all_io(s);
|
2013-01-22 16:03:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
assert(s->in_flight == 0);
|
2013-01-15 22:29:10 +08:00
|
|
|
qemu_vfree(s->buf);
|
2013-01-22 00:09:43 +08:00
|
|
|
g_free(s->cow_bitmap);
|
2013-01-22 16:03:14 +08:00
|
|
|
g_free(s->in_flight_bitmap);
|
2016-10-14 05:58:21 +08:00
|
|
|
bdrv_dirty_iter_free(s->dbi);
|
2014-10-21 19:03:58 +08:00
|
|
|
|
2016-10-27 18:48:51 +08:00
|
|
|
if (need_drain) {
|
2019-03-08 23:48:53 +08:00
|
|
|
s->in_drain = true;
|
2016-10-27 18:48:51 +08:00
|
|
|
bdrv_drained_begin(bs);
|
|
|
|
}
|
2018-08-30 09:57:26 +08:00
|
|
|
|
|
|
|
return ret;
|
2012-10-18 22:49:23 +08:00
|
|
|
}
|
|
|
|
|
2018-04-23 18:24:16 +08:00
|
|
|
static void mirror_complete(Job *job, Error **errp)
|
2012-10-18 22:49:25 +08:00
|
|
|
{
|
2018-04-23 18:24:16 +08:00
|
|
|
MirrorBlockJob *s = container_of(job, MirrorBlockJob, common.job);
|
2012-10-18 22:49:25 +08:00
|
|
|
|
2021-10-06 23:19:30 +08:00
|
|
|
if (!job_is_ready(job)) {
|
2016-07-05 22:28:53 +08:00
|
|
|
error_setg(errp, "The active block job '%s' cannot be completed",
|
2018-04-23 18:24:16 +08:00
|
|
|
job->id);
|
2012-10-18 22:49:25 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-06-23 16:57:21 +08:00
|
|
|
/* block all operations on to_replace bs */
|
2014-06-28 00:25:25 +08:00
|
|
|
if (s->replaces) {
|
2015-07-17 10:12:22 +08:00
|
|
|
s->to_replace = bdrv_find_node(s->replaces);
|
2014-06-28 00:25:25 +08:00
|
|
|
if (!s->to_replace) {
|
2015-07-17 10:12:22 +08:00
|
|
|
error_setg(errp, "Node name '%s' not found", s->replaces);
|
2014-06-28 00:25:25 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
block: drop BLK_PERM_GRAPH_MOD
First, this permission never protected a node from being changed, as
generic child-replacing functions don't check it.
Second, it's a strange thing: it presents a permission of parent node
to change its child. But generally, children are replaced by different
mechanisms, like jobs or qmp commands, not by nodes.
Graph-mod permission is hard to understand. All other permissions
describe operations which done by parent node on its child: read,
write, resize. Graph modification operations are something completely
different.
The only place where BLK_PERM_GRAPH_MOD is used as "perm" (not shared
perm) is mirror_start_job, for s->target. Still modern code should use
bdrv_freeze_backing_chain() to protect from graph modification, if we
don't do it somewhere it may be considered as a bug. So, it's a bit
risky to drop GRAPH_MOD, and analyzing of possible loss of protection
is hard. But one day we should do it, let's do it now.
One more bit of information is that locking the corresponding byte in
file-posix doesn't make sense at all.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20210902093754.2352-1-vsementsov@virtuozzo.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2021-09-02 17:37:54 +08:00
|
|
|
/* TODO Translate this into child freeze system. */
|
2014-06-28 00:25:25 +08:00
|
|
|
error_setg(&s->replace_blocker,
|
|
|
|
"block device is in use by block-job-complete");
|
|
|
|
bdrv_op_block_all(s->to_replace, s->replace_blocker);
|
|
|
|
bdrv_ref(s->to_replace);
|
|
|
|
}
|
|
|
|
|
2012-10-18 22:49:25 +08:00
|
|
|
s->should_complete = true;
|
2021-04-09 20:04:19 +08:00
|
|
|
|
|
|
|
/* If the job is paused, it will be re-entered when it is resumed */
|
2022-09-26 17:32:03 +08:00
|
|
|
WITH_JOB_LOCK_GUARD() {
|
|
|
|
if (!job->paused) {
|
|
|
|
job_enter_cond_locked(job, NULL);
|
|
|
|
}
|
2021-04-09 20:04:19 +08:00
|
|
|
}
|
2012-10-18 22:49:25 +08:00
|
|
|
}
|
|
|
|
|
2018-12-13 19:24:34 +08:00
|
|
|
static void coroutine_fn mirror_pause(Job *job)
|
2016-06-17 00:56:28 +08:00
|
|
|
{
|
2018-04-13 23:31:02 +08:00
|
|
|
MirrorBlockJob *s = container_of(job, MirrorBlockJob, common.job);
|
2016-06-17 00:56:28 +08:00
|
|
|
|
2016-10-27 18:48:50 +08:00
|
|
|
mirror_wait_for_all_io(s);
|
2016-06-17 00:56:28 +08:00
|
|
|
}
|
|
|
|
|
2018-03-22 21:11:20 +08:00
|
|
|
static bool mirror_drained_poll(BlockJob *job)
|
|
|
|
{
|
|
|
|
MirrorBlockJob *s = container_of(job, MirrorBlockJob, common);
|
2019-03-08 23:48:53 +08:00
|
|
|
|
|
|
|
/* 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.
|
|
|
|
*/
|
2022-09-26 17:32:03 +08:00
|
|
|
WITH_JOB_LOCK_GUARD() {
|
|
|
|
if (!s->common.job.paused && !job_is_cancelled_locked(&job->job)
|
|
|
|
&& !s->in_drain) {
|
|
|
|
return true;
|
|
|
|
}
|
2019-03-08 23:48:53 +08:00
|
|
|
}
|
|
|
|
|
2018-03-22 21:11:20 +08:00
|
|
|
return !!s->in_flight;
|
|
|
|
}
|
|
|
|
|
jobs: Give Job.force_cancel more meaning
We largely have two cancel modes for jobs:
First, there is actual cancelling. The job is terminated as soon as
possible, without trying to reach a consistent result.
Second, we have mirror in the READY state. Technically, the job is not
really cancelled, but it just is a different completion mode. The job
can still run for an indefinite amount of time while it tries to reach a
consistent result.
We want to be able to clearly distinguish which cancel mode a job is in
(when it has been cancelled). We can use Job.force_cancel for this, but
right now it only reflects cancel requests from the user with
force=true, but clearly, jobs that do not even distinguish between
force=false and force=true are effectively always force-cancelled.
So this patch has Job.force_cancel signify whether the job will
terminate as soon as possible (force_cancel=true) or whether it will
effectively remain running despite being "cancelled"
(force_cancel=false).
To this end, we let jobs that provide JobDriver.cancel() tell the
generic job code whether they will terminate as soon as possible or not,
and for jobs that do not provide that method we assume they will.
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20211006151940.214590-7-hreitz@redhat.com>
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
2021-10-06 23:19:33 +08:00
|
|
|
static bool mirror_cancel(Job *job, bool force)
|
2021-02-06 00:37:15 +08:00
|
|
|
{
|
|
|
|
MirrorBlockJob *s = container_of(job, MirrorBlockJob, common.job);
|
|
|
|
BlockDriverState *target = blk_bs(s->target);
|
|
|
|
|
jobs: Give Job.force_cancel more meaning
We largely have two cancel modes for jobs:
First, there is actual cancelling. The job is terminated as soon as
possible, without trying to reach a consistent result.
Second, we have mirror in the READY state. Technically, the job is not
really cancelled, but it just is a different completion mode. The job
can still run for an indefinite amount of time while it tries to reach a
consistent result.
We want to be able to clearly distinguish which cancel mode a job is in
(when it has been cancelled). We can use Job.force_cancel for this, but
right now it only reflects cancel requests from the user with
force=true, but clearly, jobs that do not even distinguish between
force=false and force=true are effectively always force-cancelled.
So this patch has Job.force_cancel signify whether the job will
terminate as soon as possible (force_cancel=true) or whether it will
effectively remain running despite being "cancelled"
(force_cancel=false).
To this end, we let jobs that provide JobDriver.cancel() tell the
generic job code whether they will terminate as soon as possible or not,
and for jobs that do not provide that method we assume they will.
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20211006151940.214590-7-hreitz@redhat.com>
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
2021-10-06 23:19:33 +08:00
|
|
|
/*
|
|
|
|
* Before the job is READY, we treat any cancellation like a
|
|
|
|
* force-cancellation.
|
|
|
|
*/
|
|
|
|
force = force || !job_is_ready(job);
|
|
|
|
|
|
|
|
if (force) {
|
2021-04-21 15:58:58 +08:00
|
|
|
bdrv_cancel_in_flight(target);
|
|
|
|
}
|
jobs: Give Job.force_cancel more meaning
We largely have two cancel modes for jobs:
First, there is actual cancelling. The job is terminated as soon as
possible, without trying to reach a consistent result.
Second, we have mirror in the READY state. Technically, the job is not
really cancelled, but it just is a different completion mode. The job
can still run for an indefinite amount of time while it tries to reach a
consistent result.
We want to be able to clearly distinguish which cancel mode a job is in
(when it has been cancelled). We can use Job.force_cancel for this, but
right now it only reflects cancel requests from the user with
force=true, but clearly, jobs that do not even distinguish between
force=false and force=true are effectively always force-cancelled.
So this patch has Job.force_cancel signify whether the job will
terminate as soon as possible (force_cancel=true) or whether it will
effectively remain running despite being "cancelled"
(force_cancel=false).
To this end, we let jobs that provide JobDriver.cancel() tell the
generic job code whether they will terminate as soon as possible or not,
and for jobs that do not provide that method we assume they will.
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20211006151940.214590-7-hreitz@redhat.com>
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
2021-10-06 23:19:33 +08:00
|
|
|
return force;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool commit_active_cancel(Job *job, bool force)
|
|
|
|
{
|
|
|
|
/* Same as above in mirror_cancel() */
|
|
|
|
return force || !job_is_ready(job);
|
2021-02-06 00:37:15 +08:00
|
|
|
}
|
|
|
|
|
2023-10-31 21:54:26 +08:00
|
|
|
static void mirror_change(BlockJob *job, BlockJobChangeOptions *opts,
|
|
|
|
Error **errp)
|
|
|
|
{
|
|
|
|
MirrorBlockJob *s = container_of(job, MirrorBlockJob, common);
|
|
|
|
BlockJobChangeOptionsMirror *change_opts = &opts->u.mirror;
|
|
|
|
MirrorCopyMode current;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The implementation relies on the fact that copy_mode is only written
|
|
|
|
* under the BQL. Otherwise, further synchronization would be required.
|
|
|
|
*/
|
|
|
|
|
|
|
|
GLOBAL_STATE_CODE();
|
|
|
|
|
|
|
|
if (qatomic_read(&s->copy_mode) == change_opts->copy_mode) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (change_opts->copy_mode != MIRROR_COPY_MODE_WRITE_BLOCKING) {
|
|
|
|
error_setg(errp, "Change to copy mode '%s' is not implemented",
|
|
|
|
MirrorCopyMode_str(change_opts->copy_mode));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
current = qatomic_cmpxchg(&s->copy_mode, MIRROR_COPY_MODE_BACKGROUND,
|
|
|
|
change_opts->copy_mode);
|
|
|
|
if (current != MIRROR_COPY_MODE_BACKGROUND) {
|
|
|
|
error_setg(errp, "Expected current copy mode '%s', got '%s'",
|
|
|
|
MirrorCopyMode_str(MIRROR_COPY_MODE_BACKGROUND),
|
|
|
|
MirrorCopyMode_str(current));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-31 21:54:30 +08:00
|
|
|
static void mirror_query(BlockJob *job, BlockJobInfo *info)
|
|
|
|
{
|
|
|
|
MirrorBlockJob *s = container_of(job, MirrorBlockJob, common);
|
|
|
|
|
|
|
|
info->u.mirror = (BlockJobInfoMirror) {
|
|
|
|
.actively_synced = qatomic_read(&s->actively_synced),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2013-10-08 17:29:38 +08:00
|
|
|
static const BlockJobDriver mirror_job_driver = {
|
2018-04-12 23:29:59 +08:00
|
|
|
.job_driver = {
|
|
|
|
.instance_size = sizeof(MirrorBlockJob),
|
2018-04-12 23:57:08 +08:00
|
|
|
.job_type = JOB_TYPE_MIRROR,
|
2018-04-14 00:50:05 +08:00
|
|
|
.free = block_job_free,
|
2018-04-18 23:10:26 +08:00
|
|
|
.user_resume = block_job_user_resume,
|
2018-08-30 09:57:26 +08:00
|
|
|
.run = mirror_run,
|
2018-09-06 21:02:15 +08:00
|
|
|
.prepare = mirror_prepare,
|
|
|
|
.abort = mirror_abort,
|
2018-04-13 23:31:02 +08:00
|
|
|
.pause = mirror_pause,
|
2018-04-23 18:24:16 +08:00
|
|
|
.complete = mirror_complete,
|
2021-02-06 00:37:15 +08:00
|
|
|
.cancel = mirror_cancel,
|
2018-04-12 23:29:59 +08:00
|
|
|
},
|
2018-03-22 21:11:20 +08:00
|
|
|
.drained_poll = mirror_drained_poll,
|
2023-10-31 21:54:26 +08:00
|
|
|
.change = mirror_change,
|
2023-10-31 21:54:30 +08:00
|
|
|
.query = mirror_query,
|
2012-10-18 22:49:23 +08:00
|
|
|
};
|
|
|
|
|
2013-12-16 14:45:30 +08:00
|
|
|
static const BlockJobDriver commit_active_job_driver = {
|
2018-04-12 23:29:59 +08:00
|
|
|
.job_driver = {
|
|
|
|
.instance_size = sizeof(MirrorBlockJob),
|
2018-04-12 23:57:08 +08:00
|
|
|
.job_type = JOB_TYPE_COMMIT,
|
2018-04-14 00:50:05 +08:00
|
|
|
.free = block_job_free,
|
2018-04-18 23:10:26 +08:00
|
|
|
.user_resume = block_job_user_resume,
|
2018-08-30 09:57:26 +08:00
|
|
|
.run = mirror_run,
|
2018-09-06 21:02:15 +08:00
|
|
|
.prepare = mirror_prepare,
|
|
|
|
.abort = mirror_abort,
|
2018-04-13 23:31:02 +08:00
|
|
|
.pause = mirror_pause,
|
2018-04-23 18:24:16 +08:00
|
|
|
.complete = mirror_complete,
|
jobs: Give Job.force_cancel more meaning
We largely have two cancel modes for jobs:
First, there is actual cancelling. The job is terminated as soon as
possible, without trying to reach a consistent result.
Second, we have mirror in the READY state. Technically, the job is not
really cancelled, but it just is a different completion mode. The job
can still run for an indefinite amount of time while it tries to reach a
consistent result.
We want to be able to clearly distinguish which cancel mode a job is in
(when it has been cancelled). We can use Job.force_cancel for this, but
right now it only reflects cancel requests from the user with
force=true, but clearly, jobs that do not even distinguish between
force=false and force=true are effectively always force-cancelled.
So this patch has Job.force_cancel signify whether the job will
terminate as soon as possible (force_cancel=true) or whether it will
effectively remain running despite being "cancelled"
(force_cancel=false).
To this end, we let jobs that provide JobDriver.cancel() tell the
generic job code whether they will terminate as soon as possible or not,
and for jobs that do not provide that method we assume they will.
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20211006151940.214590-7-hreitz@redhat.com>
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
2021-10-06 23:19:33 +08:00
|
|
|
.cancel = commit_active_cancel,
|
2018-04-12 23:29:59 +08:00
|
|
|
},
|
2018-03-22 21:11:20 +08:00
|
|
|
.drained_poll = mirror_drained_poll,
|
2013-12-16 14:45:30 +08:00
|
|
|
};
|
|
|
|
|
2018-12-13 19:24:34 +08:00
|
|
|
static void coroutine_fn
|
|
|
|
do_sync_target_write(MirrorBlockJob *job, MirrorMethod method,
|
|
|
|
uint64_t offset, uint64_t bytes,
|
|
|
|
QEMUIOVector *qiov, int flags)
|
2018-06-14 02:18:21 +08:00
|
|
|
{
|
2019-10-11 17:07:08 +08:00
|
|
|
int ret;
|
block/mirror: support unaligned write in active mirror
Prior 9adc1cb49af8d do_sync_target_write had a bug: it reset aligned-up
region in the dirty bitmap, which means that we may not copy some bytes
and assume them copied, which actually leads to producing corrupted
target.
So 9adc1cb49af8d forced dirty bitmap granularity to be
request_alignment for mirror-top filter, so we are not working with
unaligned requests. However forcing large alignment obviously decreases
performance of unaligned requests.
This commit provides another solution for the problem: if unaligned
padding is already dirty, we can safely ignore it, as
1. It's dirty, it will be copied by mirror_iteration anyway
2. It's dirty, so skipping it now we don't increase dirtiness of the
bitmap and therefore don't damage "synchronicity" of the
write-blocking mirror.
If unaligned padding is not dirty, we just write it, no reason to touch
dirty bitmap if we succeed (on failure we'll set the whole region
ofcourse, but we loss "synchronicity" on failure anyway).
Note: we need to disable dirty_bitmap, otherwise we will not be able to
see in do_sync_target_write bitmap state before current operation. We
may of course check dirty bitmap before the operation in
bdrv_mirror_top_do_write and remember it, but we don't need active
dirty bitmap for write-blocking mirror anyway.
New code-path is unused until the following commit reverts
9adc1cb49af8d.
Suggested-by: Denis V. Lunev <den@openvz.org>
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-id: 20191011090711.19940-5-vsementsov@virtuozzo.com
Reviewed-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2019-10-11 17:07:10 +08:00
|
|
|
size_t qiov_offset = 0;
|
|
|
|
int64_t bitmap_offset, bitmap_end;
|
2018-06-14 02:18:21 +08:00
|
|
|
|
block/mirror: support unaligned write in active mirror
Prior 9adc1cb49af8d do_sync_target_write had a bug: it reset aligned-up
region in the dirty bitmap, which means that we may not copy some bytes
and assume them copied, which actually leads to producing corrupted
target.
So 9adc1cb49af8d forced dirty bitmap granularity to be
request_alignment for mirror-top filter, so we are not working with
unaligned requests. However forcing large alignment obviously decreases
performance of unaligned requests.
This commit provides another solution for the problem: if unaligned
padding is already dirty, we can safely ignore it, as
1. It's dirty, it will be copied by mirror_iteration anyway
2. It's dirty, so skipping it now we don't increase dirtiness of the
bitmap and therefore don't damage "synchronicity" of the
write-blocking mirror.
If unaligned padding is not dirty, we just write it, no reason to touch
dirty bitmap if we succeed (on failure we'll set the whole region
ofcourse, but we loss "synchronicity" on failure anyway).
Note: we need to disable dirty_bitmap, otherwise we will not be able to
see in do_sync_target_write bitmap state before current operation. We
may of course check dirty bitmap before the operation in
bdrv_mirror_top_do_write and remember it, but we don't need active
dirty bitmap for write-blocking mirror anyway.
New code-path is unused until the following commit reverts
9adc1cb49af8d.
Suggested-by: Denis V. Lunev <den@openvz.org>
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-id: 20191011090711.19940-5-vsementsov@virtuozzo.com
Reviewed-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2019-10-11 17:07:10 +08:00
|
|
|
if (!QEMU_IS_ALIGNED(offset, job->granularity) &&
|
|
|
|
bdrv_dirty_bitmap_get(job->dirty_bitmap, offset))
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Dirty unaligned padding: ignore it.
|
|
|
|
*
|
|
|
|
* Reasoning:
|
|
|
|
* 1. If we copy it, we can't reset corresponding bit in
|
|
|
|
* dirty_bitmap as there may be some "dirty" bytes still not
|
|
|
|
* copied.
|
|
|
|
* 2. It's already dirty, so skipping it we don't diverge mirror
|
|
|
|
* progress.
|
|
|
|
*
|
|
|
|
* Note, that because of this, guest write may have no contribution
|
|
|
|
* into mirror converge, but that's not bad, as we have background
|
|
|
|
* process of mirroring. If under some bad circumstances (high guest
|
|
|
|
* IO load) background process starve, we will not converge anyway,
|
|
|
|
* even if each write will contribute, as guest is not guaranteed to
|
|
|
|
* rewrite the whole disk.
|
|
|
|
*/
|
|
|
|
qiov_offset = QEMU_ALIGN_UP(offset, job->granularity) - offset;
|
|
|
|
if (bytes <= qiov_offset) {
|
|
|
|
/* nothing to do after shrink */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
offset += qiov_offset;
|
|
|
|
bytes -= qiov_offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!QEMU_IS_ALIGNED(offset + bytes, job->granularity) &&
|
|
|
|
bdrv_dirty_bitmap_get(job->dirty_bitmap, offset + bytes - 1))
|
|
|
|
{
|
|
|
|
uint64_t tail = (offset + bytes) % job->granularity;
|
|
|
|
|
|
|
|
if (bytes <= tail) {
|
|
|
|
/* nothing to do after shrink */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
bytes -= tail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Tails are either clean or shrunk, so for bitmap resetting
|
|
|
|
* we safely align the range down.
|
|
|
|
*/
|
|
|
|
bitmap_offset = QEMU_ALIGN_UP(offset, job->granularity);
|
|
|
|
bitmap_end = QEMU_ALIGN_DOWN(offset + bytes, job->granularity);
|
|
|
|
if (bitmap_offset < bitmap_end) {
|
|
|
|
bdrv_reset_dirty_bitmap(job->dirty_bitmap, bitmap_offset,
|
|
|
|
bitmap_end - bitmap_offset);
|
|
|
|
}
|
2018-06-14 02:18:21 +08:00
|
|
|
|
2019-10-11 17:07:08 +08:00
|
|
|
job_progress_increase_remaining(&job->common.job, bytes);
|
block/mirror: Do not wait for active writes
Waiting for all active writes to settle before daring to create a
background copying operation means that we will never do background
operations while the guest does anything (in write-blocking mode), and
therefore cannot converge. Yes, we also will not diverge, but actually
converging would be even nicer.
It is unclear why we did decide to wait for all active writes to settle
before creating a background operation, but it just does not seem
necessary. Active writes will put themselves into the in_flight bitmap
and thus properly block actually conflicting background requests.
It is important for active requests to wait on overlapping background
requests, which we do in active_write_prepare(). However, so far it was
not documented why it is important. Add such documentation now, and
also to the other call of mirror_wait_on_conflicts(), so that it becomes
more clear why and when requests need to actively wait for other
requests to settle.
Another thing to note is that of course we need to ensure that there are
no active requests when the job completes, but that is done by virtue of
the BDS being drained anyway, so there cannot be any active requests at
that point.
With this change, we will need to explicitly keep track of how many
bytes are in flight in active requests so that
job_progress_set_remaining() in mirror_run() can set the correct number
of remaining bytes.
Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=2123297
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
Message-Id: <20221109165452.67927-2-hreitz@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2022-11-10 00:54:48 +08:00
|
|
|
job->active_write_bytes_in_flight += bytes;
|
2018-06-14 02:18:21 +08:00
|
|
|
|
2019-10-11 17:07:08 +08:00
|
|
|
switch (method) {
|
|
|
|
case MIRROR_METHOD_COPY:
|
block/mirror: support unaligned write in active mirror
Prior 9adc1cb49af8d do_sync_target_write had a bug: it reset aligned-up
region in the dirty bitmap, which means that we may not copy some bytes
and assume them copied, which actually leads to producing corrupted
target.
So 9adc1cb49af8d forced dirty bitmap granularity to be
request_alignment for mirror-top filter, so we are not working with
unaligned requests. However forcing large alignment obviously decreases
performance of unaligned requests.
This commit provides another solution for the problem: if unaligned
padding is already dirty, we can safely ignore it, as
1. It's dirty, it will be copied by mirror_iteration anyway
2. It's dirty, so skipping it now we don't increase dirtiness of the
bitmap and therefore don't damage "synchronicity" of the
write-blocking mirror.
If unaligned padding is not dirty, we just write it, no reason to touch
dirty bitmap if we succeed (on failure we'll set the whole region
ofcourse, but we loss "synchronicity" on failure anyway).
Note: we need to disable dirty_bitmap, otherwise we will not be able to
see in do_sync_target_write bitmap state before current operation. We
may of course check dirty bitmap before the operation in
bdrv_mirror_top_do_write and remember it, but we don't need active
dirty bitmap for write-blocking mirror anyway.
New code-path is unused until the following commit reverts
9adc1cb49af8d.
Suggested-by: Denis V. Lunev <den@openvz.org>
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-id: 20191011090711.19940-5-vsementsov@virtuozzo.com
Reviewed-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2019-10-11 17:07:10 +08:00
|
|
|
ret = blk_co_pwritev_part(job->target, offset, bytes,
|
|
|
|
qiov, qiov_offset, flags);
|
2019-10-11 17:07:08 +08:00
|
|
|
break;
|
2018-06-14 02:18:21 +08:00
|
|
|
|
2019-10-11 17:07:08 +08:00
|
|
|
case MIRROR_METHOD_ZERO:
|
|
|
|
assert(!qiov);
|
|
|
|
ret = blk_co_pwrite_zeroes(job->target, offset, bytes, flags);
|
|
|
|
break;
|
2018-06-14 02:18:21 +08:00
|
|
|
|
2019-10-11 17:07:08 +08:00
|
|
|
case MIRROR_METHOD_DISCARD:
|
|
|
|
assert(!qiov);
|
|
|
|
ret = blk_co_pdiscard(job->target, offset, bytes);
|
|
|
|
break;
|
2018-06-14 02:18:21 +08:00
|
|
|
|
2019-10-11 17:07:08 +08:00
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
2018-06-14 02:18:21 +08:00
|
|
|
|
block/mirror: Do not wait for active writes
Waiting for all active writes to settle before daring to create a
background copying operation means that we will never do background
operations while the guest does anything (in write-blocking mode), and
therefore cannot converge. Yes, we also will not diverge, but actually
converging would be even nicer.
It is unclear why we did decide to wait for all active writes to settle
before creating a background operation, but it just does not seem
necessary. Active writes will put themselves into the in_flight bitmap
and thus properly block actually conflicting background requests.
It is important for active requests to wait on overlapping background
requests, which we do in active_write_prepare(). However, so far it was
not documented why it is important. Add such documentation now, and
also to the other call of mirror_wait_on_conflicts(), so that it becomes
more clear why and when requests need to actively wait for other
requests to settle.
Another thing to note is that of course we need to ensure that there are
no active requests when the job completes, but that is done by virtue of
the BDS being drained anyway, so there cannot be any active requests at
that point.
With this change, we will need to explicitly keep track of how many
bytes are in flight in active requests so that
job_progress_set_remaining() in mirror_run() can set the correct number
of remaining bytes.
Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=2123297
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
Message-Id: <20221109165452.67927-2-hreitz@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2022-11-10 00:54:48 +08:00
|
|
|
job->active_write_bytes_in_flight -= bytes;
|
2019-10-11 17:07:08 +08:00
|
|
|
if (ret >= 0) {
|
|
|
|
job_progress_update(&job->common.job, bytes);
|
|
|
|
} else {
|
|
|
|
BlockErrorAction action;
|
2018-06-14 02:18:21 +08:00
|
|
|
|
block/mirror: support unaligned write in active mirror
Prior 9adc1cb49af8d do_sync_target_write had a bug: it reset aligned-up
region in the dirty bitmap, which means that we may not copy some bytes
and assume them copied, which actually leads to producing corrupted
target.
So 9adc1cb49af8d forced dirty bitmap granularity to be
request_alignment for mirror-top filter, so we are not working with
unaligned requests. However forcing large alignment obviously decreases
performance of unaligned requests.
This commit provides another solution for the problem: if unaligned
padding is already dirty, we can safely ignore it, as
1. It's dirty, it will be copied by mirror_iteration anyway
2. It's dirty, so skipping it now we don't increase dirtiness of the
bitmap and therefore don't damage "synchronicity" of the
write-blocking mirror.
If unaligned padding is not dirty, we just write it, no reason to touch
dirty bitmap if we succeed (on failure we'll set the whole region
ofcourse, but we loss "synchronicity" on failure anyway).
Note: we need to disable dirty_bitmap, otherwise we will not be able to
see in do_sync_target_write bitmap state before current operation. We
may of course check dirty bitmap before the operation in
bdrv_mirror_top_do_write and remember it, but we don't need active
dirty bitmap for write-blocking mirror anyway.
New code-path is unused until the following commit reverts
9adc1cb49af8d.
Suggested-by: Denis V. Lunev <den@openvz.org>
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-id: 20191011090711.19940-5-vsementsov@virtuozzo.com
Reviewed-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2019-10-11 17:07:10 +08:00
|
|
|
/*
|
|
|
|
* We failed, so we should mark dirty the whole area, aligned up.
|
|
|
|
* Note that we don't care about shrunk tails if any: they were dirty
|
|
|
|
* at function start, and they must be still dirty, as we've locked
|
|
|
|
* the region for in-flight op.
|
|
|
|
*/
|
|
|
|
bitmap_offset = QEMU_ALIGN_DOWN(offset, job->granularity);
|
|
|
|
bitmap_end = QEMU_ALIGN_UP(offset + bytes, job->granularity);
|
|
|
|
bdrv_set_dirty_bitmap(job->dirty_bitmap, bitmap_offset,
|
|
|
|
bitmap_end - bitmap_offset);
|
2023-10-31 21:54:30 +08:00
|
|
|
qatomic_set(&job->actively_synced, false);
|
2018-06-14 02:18:21 +08:00
|
|
|
|
2019-10-11 17:07:08 +08:00
|
|
|
action = mirror_error_action(job, false, -ret);
|
|
|
|
if (action == BLOCK_ERROR_ACTION_REPORT) {
|
|
|
|
if (!job->ret) {
|
|
|
|
job->ret = ret;
|
2018-06-14 02:18:21 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static MirrorOp *coroutine_fn active_write_prepare(MirrorBlockJob *s,
|
|
|
|
uint64_t offset,
|
|
|
|
uint64_t bytes)
|
|
|
|
{
|
|
|
|
MirrorOp *op;
|
|
|
|
uint64_t start_chunk = offset / s->granularity;
|
|
|
|
uint64_t end_chunk = DIV_ROUND_UP(offset + bytes, s->granularity);
|
|
|
|
|
|
|
|
op = g_new(MirrorOp, 1);
|
|
|
|
*op = (MirrorOp){
|
|
|
|
.s = s,
|
|
|
|
.offset = offset,
|
|
|
|
.bytes = bytes,
|
|
|
|
.is_active_write = true,
|
2020-03-26 23:36:28 +08:00
|
|
|
.is_in_flight = true,
|
2021-07-03 05:16:34 +08:00
|
|
|
.co = qemu_coroutine_self(),
|
2018-06-14 02:18:21 +08:00
|
|
|
};
|
|
|
|
qemu_co_queue_init(&op->waiting_requests);
|
|
|
|
QTAILQ_INSERT_TAIL(&s->ops_in_flight, op, next);
|
|
|
|
|
|
|
|
s->in_active_write_counter++;
|
|
|
|
|
block/mirror: Do not wait for active writes
Waiting for all active writes to settle before daring to create a
background copying operation means that we will never do background
operations while the guest does anything (in write-blocking mode), and
therefore cannot converge. Yes, we also will not diverge, but actually
converging would be even nicer.
It is unclear why we did decide to wait for all active writes to settle
before creating a background operation, but it just does not seem
necessary. Active writes will put themselves into the in_flight bitmap
and thus properly block actually conflicting background requests.
It is important for active requests to wait on overlapping background
requests, which we do in active_write_prepare(). However, so far it was
not documented why it is important. Add such documentation now, and
also to the other call of mirror_wait_on_conflicts(), so that it becomes
more clear why and when requests need to actively wait for other
requests to settle.
Another thing to note is that of course we need to ensure that there are
no active requests when the job completes, but that is done by virtue of
the BDS being drained anyway, so there cannot be any active requests at
that point.
With this change, we will need to explicitly keep track of how many
bytes are in flight in active requests so that
job_progress_set_remaining() in mirror_run() can set the correct number
of remaining bytes.
Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=2123297
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
Message-Id: <20221109165452.67927-2-hreitz@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2022-11-10 00:54:48 +08:00
|
|
|
/*
|
|
|
|
* Wait for concurrent requests affecting the area. If there are already
|
|
|
|
* running requests that are copying off now-to-be stale data in the area,
|
|
|
|
* we must wait for them to finish before we begin writing fresh data to the
|
|
|
|
* target so that the write operations appear in the correct order.
|
|
|
|
* Note that background requests (see mirror_iteration()) in contrast only
|
|
|
|
* wait for conflicting requests at the start of the dirty area, and then
|
|
|
|
* (based on the in_flight_bitmap) truncate the area to copy so it will not
|
|
|
|
* conflict with any requests beyond that. For active writes, however, we
|
|
|
|
* cannot truncate that area. The request from our parent must be blocked
|
|
|
|
* until the area is copied in full. Therefore, we must wait for the whole
|
|
|
|
* area to become free of concurrent requests.
|
|
|
|
*/
|
2018-06-14 02:18:21 +08:00
|
|
|
mirror_wait_on_conflicts(op, s, offset, bytes);
|
|
|
|
|
|
|
|
bitmap_set(s->in_flight_bitmap, start_chunk, end_chunk - start_chunk);
|
|
|
|
|
|
|
|
return op;
|
|
|
|
}
|
|
|
|
|
2023-05-04 19:57:42 +08:00
|
|
|
static void coroutine_fn GRAPH_RDLOCK active_write_settle(MirrorOp *op)
|
2018-06-14 02:18:21 +08:00
|
|
|
{
|
|
|
|
uint64_t start_chunk = op->offset / op->s->granularity;
|
|
|
|
uint64_t end_chunk = DIV_ROUND_UP(op->offset + op->bytes,
|
|
|
|
op->s->granularity);
|
|
|
|
|
2023-10-31 21:54:30 +08:00
|
|
|
if (!--op->s->in_active_write_counter &&
|
|
|
|
qatomic_read(&op->s->actively_synced)) {
|
2018-06-14 02:18:21 +08:00
|
|
|
BdrvChild *source = op->s->mirror_top_bs->backing;
|
|
|
|
|
|
|
|
if (QLIST_FIRST(&source->bs->parents) == source &&
|
|
|
|
QLIST_NEXT(source, next_parent) == NULL)
|
|
|
|
{
|
|
|
|
/* Assert that we are back in sync once all active write
|
|
|
|
* operations are settled.
|
|
|
|
* Note that we can only assert this if the mirror node
|
|
|
|
* is the source node's only parent. */
|
|
|
|
assert(!bdrv_get_dirty_count(op->s->dirty_bitmap));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bitmap_clear(op->s->in_flight_bitmap, start_chunk, end_chunk - start_chunk);
|
|
|
|
QTAILQ_REMOVE(&op->s->ops_in_flight, op, next);
|
|
|
|
qemu_co_queue_restart_all(&op->waiting_requests);
|
|
|
|
g_free(op);
|
|
|
|
}
|
|
|
|
|
2023-02-03 23:21:50 +08:00
|
|
|
static int coroutine_fn GRAPH_RDLOCK
|
|
|
|
bdrv_mirror_top_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes,
|
|
|
|
QEMUIOVector *qiov, BdrvRequestFlags flags)
|
2017-01-26 02:16:34 +08:00
|
|
|
{
|
|
|
|
return bdrv_co_preadv(bs->backing, offset, bytes, qiov, flags);
|
|
|
|
}
|
|
|
|
|
2023-10-31 21:54:25 +08:00
|
|
|
static bool should_copy_to_target(MirrorBDSOpaque *s)
|
|
|
|
{
|
|
|
|
return s->job && s->job->ret >= 0 &&
|
|
|
|
!job_is_cancelled(&s->job->common.job) &&
|
2023-10-31 21:54:26 +08:00
|
|
|
qatomic_read(&s->job->copy_mode) == MIRROR_COPY_MODE_WRITE_BLOCKING;
|
2023-10-31 21:54:25 +08:00
|
|
|
}
|
|
|
|
|
2023-02-03 23:21:47 +08:00
|
|
|
static int coroutine_fn GRAPH_RDLOCK
|
|
|
|
bdrv_mirror_top_do_write(BlockDriverState *bs, MirrorMethod method,
|
2023-10-31 21:54:25 +08:00
|
|
|
bool copy_to_target, uint64_t offset, uint64_t bytes,
|
|
|
|
QEMUIOVector *qiov, int flags)
|
2018-06-14 02:18:21 +08:00
|
|
|
{
|
|
|
|
MirrorOp *op = NULL;
|
|
|
|
MirrorBDSOpaque *s = bs->opaque;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (copy_to_target) {
|
|
|
|
op = active_write_prepare(s->job, offset, bytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (method) {
|
|
|
|
case MIRROR_METHOD_COPY:
|
|
|
|
ret = bdrv_co_pwritev(bs->backing, offset, bytes, qiov, flags);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MIRROR_METHOD_ZERO:
|
|
|
|
ret = bdrv_co_pwrite_zeroes(bs->backing, offset, bytes, flags);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MIRROR_METHOD_DISCARD:
|
2018-07-10 14:31:17 +08:00
|
|
|
ret = bdrv_co_pdiscard(bs->backing, offset, bytes);
|
2018-06-14 02:18:21 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
2023-10-31 21:54:24 +08:00
|
|
|
if (!copy_to_target && s->job && s->job->dirty_bitmap) {
|
2023-10-31 21:54:30 +08:00
|
|
|
qatomic_set(&s->job->actively_synced, false);
|
2023-10-31 21:54:24 +08:00
|
|
|
bdrv_set_dirty_bitmap(s->job->dirty_bitmap, offset, bytes);
|
|
|
|
}
|
|
|
|
|
2018-06-14 02:18:21 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (copy_to_target) {
|
|
|
|
do_sync_target_write(s->job, method, offset, bytes, qiov, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (copy_to_target) {
|
|
|
|
active_write_settle(op);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-02-03 23:21:50 +08:00
|
|
|
static int coroutine_fn GRAPH_RDLOCK
|
|
|
|
bdrv_mirror_top_pwritev(BlockDriverState *bs, int64_t offset, int64_t bytes,
|
|
|
|
QEMUIOVector *qiov, BdrvRequestFlags flags)
|
2017-01-26 02:16:34 +08:00
|
|
|
{
|
2018-06-14 02:18:21 +08:00
|
|
|
QEMUIOVector bounce_qiov;
|
|
|
|
void *bounce_buf;
|
|
|
|
int ret = 0;
|
2023-10-31 21:54:25 +08:00
|
|
|
bool copy_to_target = should_copy_to_target(bs->opaque);
|
2018-06-14 02:18:21 +08:00
|
|
|
|
|
|
|
if (copy_to_target) {
|
|
|
|
/* The guest might concurrently modify the data to write; but
|
|
|
|
* the data on source and destination must match, so we have
|
|
|
|
* to use a bounce buffer if we are going to write to the
|
|
|
|
* target now. */
|
|
|
|
bounce_buf = qemu_blockalign(bs, bytes);
|
|
|
|
iov_to_buf_full(qiov->iov, qiov->niov, 0, bounce_buf, bytes);
|
|
|
|
|
|
|
|
qemu_iovec_init(&bounce_qiov, 1);
|
|
|
|
qemu_iovec_add(&bounce_qiov, bounce_buf, bytes);
|
|
|
|
qiov = &bounce_qiov;
|
2022-10-14 02:59:01 +08:00
|
|
|
|
|
|
|
flags &= ~BDRV_REQ_REGISTERED_BUF;
|
2018-06-14 02:18:21 +08:00
|
|
|
}
|
|
|
|
|
2023-10-31 21:54:25 +08:00
|
|
|
ret = bdrv_mirror_top_do_write(bs, MIRROR_METHOD_COPY, copy_to_target,
|
|
|
|
offset, bytes, qiov, flags);
|
2018-06-14 02:18:21 +08:00
|
|
|
|
|
|
|
if (copy_to_target) {
|
|
|
|
qemu_iovec_destroy(&bounce_qiov);
|
|
|
|
qemu_vfree(bounce_buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2017-01-26 02:16:34 +08:00
|
|
|
}
|
|
|
|
|
2023-02-03 23:21:46 +08:00
|
|
|
static int coroutine_fn GRAPH_RDLOCK bdrv_mirror_top_flush(BlockDriverState *bs)
|
2017-01-26 02:16:34 +08:00
|
|
|
{
|
2017-09-29 23:22:55 +08:00
|
|
|
if (bs->backing == NULL) {
|
|
|
|
/* we can be here after failed bdrv_append in mirror_start_job */
|
|
|
|
return 0;
|
|
|
|
}
|
2017-01-26 02:16:34 +08:00
|
|
|
return bdrv_co_flush(bs->backing->bs);
|
|
|
|
}
|
|
|
|
|
2023-02-03 23:21:48 +08:00
|
|
|
static int coroutine_fn GRAPH_RDLOCK
|
|
|
|
bdrv_mirror_top_pwrite_zeroes(BlockDriverState *bs, int64_t offset,
|
|
|
|
int64_t bytes, BdrvRequestFlags flags)
|
2017-01-26 02:16:34 +08:00
|
|
|
{
|
2023-10-31 21:54:25 +08:00
|
|
|
bool copy_to_target = should_copy_to_target(bs->opaque);
|
|
|
|
return bdrv_mirror_top_do_write(bs, MIRROR_METHOD_ZERO, copy_to_target,
|
|
|
|
offset, bytes, NULL, flags);
|
2017-01-26 02:16:34 +08:00
|
|
|
}
|
|
|
|
|
2023-02-03 23:21:47 +08:00
|
|
|
static int coroutine_fn GRAPH_RDLOCK
|
|
|
|
bdrv_mirror_top_pdiscard(BlockDriverState *bs, int64_t offset, int64_t bytes)
|
2017-01-26 02:16:34 +08:00
|
|
|
{
|
2023-10-31 21:54:25 +08:00
|
|
|
bool copy_to_target = should_copy_to_target(bs->opaque);
|
|
|
|
return bdrv_mirror_top_do_write(bs, MIRROR_METHOD_DISCARD, copy_to_target,
|
|
|
|
offset, bytes, NULL, 0);
|
2017-01-26 02:16:34 +08:00
|
|
|
}
|
|
|
|
|
2023-10-27 23:53:26 +08:00
|
|
|
static void GRAPH_RDLOCK bdrv_mirror_top_refresh_filename(BlockDriverState *bs)
|
2017-03-09 18:49:16 +08:00
|
|
|
{
|
2017-09-28 20:03:00 +08:00
|
|
|
if (bs->backing == NULL) {
|
|
|
|
/* we can be here after failed bdrv_attach_child in
|
|
|
|
* bdrv_set_backing_hd */
|
|
|
|
return;
|
|
|
|
}
|
2017-03-09 18:49:16 +08:00
|
|
|
pstrcpy(bs->exact_filename, sizeof(bs->exact_filename),
|
|
|
|
bs->backing->bs->filename);
|
|
|
|
}
|
|
|
|
|
2017-01-26 02:16:34 +08:00
|
|
|
static void bdrv_mirror_top_child_perm(BlockDriverState *bs, BdrvChild *c,
|
2020-05-13 19:05:16 +08:00
|
|
|
BdrvChildRole role,
|
2017-09-14 18:47:11 +08:00
|
|
|
BlockReopenQueue *reopen_queue,
|
2017-01-26 02:16:34 +08:00
|
|
|
uint64_t perm, uint64_t shared,
|
|
|
|
uint64_t *nperm, uint64_t *nshared)
|
|
|
|
{
|
2019-05-23 01:03:47 +08:00
|
|
|
MirrorBDSOpaque *s = bs->opaque;
|
|
|
|
|
|
|
|
if (s->stop) {
|
|
|
|
/*
|
|
|
|
* If the job is to be stopped, we do not need to forward
|
|
|
|
* anything to the real image.
|
|
|
|
*/
|
|
|
|
*nperm = 0;
|
|
|
|
*nshared = BLK_PERM_ALL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
block/mirror: Fix mirror_top's permissions
mirror_top currently shares all permissions, and takes only the WRITE
permission (if some parent has taken that permission, too).
That is wrong, though; mirror_top is a filter, so it should take
permissions like any other filter does. For example, if the parent
needs CONSISTENT_READ, we need to take that, too, and if it cannot share
the WRITE permission, we cannot share it either.
The exception is when mirror_top is used for active commit, where we
cannot take CONSISTENT_READ (because it is deliberately unshared above
the base node) and where we must share WRITE (so that it is shared for
all images in the backing chain, so the mirror job can take it for the
target BB).
Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-Id: <20210211172242.146671-2-mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
2021-02-12 01:22:41 +08:00
|
|
|
bdrv_default_perms(bs, c, role, reopen_queue,
|
|
|
|
perm, shared, nperm, nshared);
|
2017-01-26 02:16:34 +08:00
|
|
|
|
block/mirror: Fix mirror_top's permissions
mirror_top currently shares all permissions, and takes only the WRITE
permission (if some parent has taken that permission, too).
That is wrong, though; mirror_top is a filter, so it should take
permissions like any other filter does. For example, if the parent
needs CONSISTENT_READ, we need to take that, too, and if it cannot share
the WRITE permission, we cannot share it either.
The exception is when mirror_top is used for active commit, where we
cannot take CONSISTENT_READ (because it is deliberately unshared above
the base node) and where we must share WRITE (so that it is shared for
all images in the backing chain, so the mirror job can take it for the
target BB).
Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-Id: <20210211172242.146671-2-mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
2021-02-12 01:22:41 +08:00
|
|
|
if (s->is_commit) {
|
|
|
|
/*
|
|
|
|
* For commit jobs, we cannot take CONSISTENT_READ, because
|
|
|
|
* that permission is unshared for everything above the base
|
|
|
|
* node (except for filters on the base node).
|
|
|
|
* We also have to force-share the WRITE permission, or
|
|
|
|
* otherwise we would block ourselves at the base node (if
|
|
|
|
* writes are blocked for a node, they are also blocked for
|
|
|
|
* its backing file).
|
|
|
|
* (We could also share RESIZE, because it may be needed for
|
|
|
|
* the target if its size is less than the top node's; but
|
|
|
|
* bdrv_default_perms_for_cow() automatically shares RESIZE
|
|
|
|
* for backing nodes if WRITE is shared, so there is no need
|
|
|
|
* to do it here.)
|
|
|
|
*/
|
|
|
|
*nperm &= ~BLK_PERM_CONSISTENT_READ;
|
|
|
|
*nshared |= BLK_PERM_WRITE;
|
|
|
|
}
|
2017-01-26 02:16:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Dummy node that provides consistent read to its users without requiring it
|
|
|
|
* from its backing file and that allows writes on the backing file chain. */
|
|
|
|
static BlockDriver bdrv_mirror_top = {
|
|
|
|
.format_name = "mirror_top",
|
|
|
|
.bdrv_co_preadv = bdrv_mirror_top_preadv,
|
|
|
|
.bdrv_co_pwritev = bdrv_mirror_top_pwritev,
|
|
|
|
.bdrv_co_pwrite_zeroes = bdrv_mirror_top_pwrite_zeroes,
|
|
|
|
.bdrv_co_pdiscard = bdrv_mirror_top_pdiscard,
|
|
|
|
.bdrv_co_flush = bdrv_mirror_top_flush,
|
2017-03-09 18:49:16 +08:00
|
|
|
.bdrv_refresh_filename = bdrv_mirror_top_refresh_filename,
|
2017-01-26 02:16:34 +08:00
|
|
|
.bdrv_child_perm = bdrv_mirror_top_child_perm,
|
2020-05-13 19:05:11 +08:00
|
|
|
|
|
|
|
.is_filter = true,
|
2022-07-27 04:11:20 +08:00
|
|
|
.filtered_child_is_backing = true,
|
2017-01-26 02:16:34 +08:00
|
|
|
};
|
|
|
|
|
2019-06-06 23:41:29 +08:00
|
|
|
static BlockJob *mirror_start_job(
|
|
|
|
const char *job_id, BlockDriverState *bs,
|
2016-10-28 00:06:57 +08:00
|
|
|
int creation_flags, BlockDriverState *target,
|
|
|
|
const char *replaces, int64_t speed,
|
|
|
|
uint32_t granularity, int64_t buf_size,
|
block/mirror: Fix target backing BDS
Currently, we are trying to move the backing BDS from the source to the
target in bdrv_replace_in_backing_chain() which is called from
mirror_exit(). However, mirror_complete() already tries to open the
target's backing chain with a call to bdrv_open_backing_file().
First, we should only set the target's backing BDS once. Second, the
mirroring block job has a better idea of what to set it to than the
generic code in bdrv_replace_in_backing_chain() (in fact, the latter's
conditions on when to move the backing BDS from source to target are not
really correct).
Therefore, remove that code from bdrv_replace_in_backing_chain() and
leave it to mirror_complete().
Depending on what kind of mirroring is performed, we furthermore want to
use different strategies to open the target's backing chain:
- If blockdev-mirror is used, we can assume the user made sure that the
target already has the correct backing chain. In particular, we should
not try to open a backing file if the target does not have any yet.
- If drive-mirror with mode=absolute-paths is used, we can and should
reuse the already existing chain of nodes that the source BDS is in.
In case of sync=full, no backing BDS is required; with sync=top, we
just link the source's backing BDS to the target, and with sync=none,
we use the source BDS as the target's backing BDS.
We should not try to open these backing files anew because this would
lead to two BDSs existing per physical file in the backing chain, and
we would like to avoid such concurrent access.
- If drive-mirror with mode=existing is used, we have to use the
information provided in the physical image file which means opening
the target's backing chain completely anew, just as it has been done
already.
If the target's backing chain shares images with the source, this may
lead to multiple BDSs per physical image file. But since we cannot
reliably ascertain this case, there is nothing we can do about it.
Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-id: 20160610185750.30956-3-mreitz@redhat.com
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Fam Zheng <famz@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2016-06-11 02:57:47 +08:00
|
|
|
BlockMirrorBackingMode backing_mode,
|
2019-07-25 01:12:30 +08:00
|
|
|
bool zero_target,
|
2014-06-28 00:25:25 +08:00
|
|
|
BlockdevOnError on_source_error,
|
|
|
|
BlockdevOnError on_target_error,
|
2015-06-08 13:56:08 +08:00
|
|
|
bool unmap,
|
2014-10-07 19:59:15 +08:00
|
|
|
BlockCompletionFunc *cb,
|
2017-04-21 20:27:03 +08:00
|
|
|
void *opaque,
|
2014-06-28 00:25:25 +08:00
|
|
|
const BlockJobDriver *driver,
|
2016-07-27 15:01:47 +08:00
|
|
|
bool is_none_mode, BlockDriverState *base,
|
2017-04-21 20:27:03 +08:00
|
|
|
bool auto_complete, const char *filter_node_name,
|
2018-06-14 02:18:22 +08:00
|
|
|
bool is_mirror, MirrorCopyMode copy_mode,
|
2017-04-21 20:27:03 +08:00
|
|
|
Error **errp)
|
2012-10-18 22:49:23 +08:00
|
|
|
{
|
|
|
|
MirrorBlockJob *s;
|
2018-06-14 02:18:19 +08:00
|
|
|
MirrorBDSOpaque *bs_opaque;
|
2017-01-26 02:16:34 +08:00
|
|
|
BlockDriverState *mirror_top_bs;
|
|
|
|
bool target_is_backing;
|
2019-06-12 22:27:32 +08:00
|
|
|
uint64_t target_perms, target_shared_perms;
|
2017-01-14 02:02:32 +08:00
|
|
|
int ret;
|
2012-10-18 22:49:23 +08:00
|
|
|
|
2023-09-11 17:46:12 +08:00
|
|
|
GLOBAL_STATE_CODE();
|
|
|
|
|
2013-01-22 00:09:46 +08:00
|
|
|
if (granularity == 0) {
|
2015-04-18 07:49:52 +08:00
|
|
|
granularity = bdrv_get_default_bitmap_granularity(target);
|
2013-01-22 00:09:46 +08:00
|
|
|
}
|
|
|
|
|
block: Convert bdrv_get_block_status_above() to bytes
We are gradually moving away from sector-based interfaces, towards
byte-based. In the common case, allocation is unlikely to ever use
values that are not naturally sector-aligned, but it is possible
that byte-based values will let us be more precise about allocation
at the end of an unaligned file that can do byte-based access.
Changing the name of the function from bdrv_get_block_status_above()
to bdrv_block_status_above() ensures that the compiler enforces that
all callers are updated. Likewise, since it a byte interface allows
an offset mapping that might not be sector aligned, split the mapping
out of the return value and into a pass-by-reference parameter. For
now, the io.c layer still assert()s that all uses are sector-aligned,
but that can be relaxed when a later patch implements byte-based
block status in the drivers.
For the most part this patch is just the addition of scaling at the
callers followed by inverse scaling at bdrv_block_status(), plus
updates for the new split return interface. But some code,
particularly bdrv_block_status(), gets a lot simpler because it no
longer has to mess with sectors. Likewise, mirror code no longer
computes s->granularity >> BDRV_SECTOR_BITS, and can therefore drop
an assertion about alignment because the loop no longer depends on
alignment (never mind that we don't really have a driver that
reports sub-sector alignments, so it's not really possible to test
the effect of sub-sector mirroring). Fix a neighboring assertion to
use is_power_of_2 while there.
For ease of review, bdrv_get_block_status() was tackled separately.
Signed-off-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2017-10-12 11:47:08 +08:00
|
|
|
assert(is_power_of_2(granularity));
|
2013-01-22 00:09:46 +08:00
|
|
|
|
2015-05-15 15:51:36 +08:00
|
|
|
if (buf_size < 0) {
|
|
|
|
error_setg(errp, "Invalid parameter 'buf-size'");
|
2019-06-06 23:41:29 +08:00
|
|
|
return NULL;
|
2015-05-15 15:51:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (buf_size == 0) {
|
|
|
|
buf_size = DEFAULT_MIRROR_BUF_SIZE;
|
|
|
|
}
|
2013-12-16 14:45:29 +08:00
|
|
|
|
2023-10-27 23:53:17 +08:00
|
|
|
bdrv_graph_rdlock_main_loop();
|
2019-06-12 22:27:32 +08:00
|
|
|
if (bdrv_skip_filters(bs) == bdrv_skip_filters(target)) {
|
2018-08-14 17:52:25 +08:00
|
|
|
error_setg(errp, "Can't mirror node into itself");
|
2023-10-27 23:53:17 +08:00
|
|
|
bdrv_graph_rdunlock_main_loop();
|
2019-06-06 23:41:29 +08:00
|
|
|
return NULL;
|
2018-08-14 17:52:25 +08:00
|
|
|
}
|
|
|
|
|
block/mirror: Fix mirror_top's permissions
mirror_top currently shares all permissions, and takes only the WRITE
permission (if some parent has taken that permission, too).
That is wrong, though; mirror_top is a filter, so it should take
permissions like any other filter does. For example, if the parent
needs CONSISTENT_READ, we need to take that, too, and if it cannot share
the WRITE permission, we cannot share it either.
The exception is when mirror_top is used for active commit, where we
cannot take CONSISTENT_READ (because it is deliberately unshared above
the base node) and where we must share WRITE (so that it is shared for
all images in the backing chain, so the mirror job can take it for the
target BB).
Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-Id: <20210211172242.146671-2-mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
2021-02-12 01:22:41 +08:00
|
|
|
target_is_backing = bdrv_chain_contains(bs, target);
|
2023-10-27 23:53:17 +08:00
|
|
|
bdrv_graph_rdunlock_main_loop();
|
block/mirror: Fix mirror_top's permissions
mirror_top currently shares all permissions, and takes only the WRITE
permission (if some parent has taken that permission, too).
That is wrong, though; mirror_top is a filter, so it should take
permissions like any other filter does. For example, if the parent
needs CONSISTENT_READ, we need to take that, too, and if it cannot share
the WRITE permission, we cannot share it either.
The exception is when mirror_top is used for active commit, where we
cannot take CONSISTENT_READ (because it is deliberately unshared above
the base node) and where we must share WRITE (so that it is shared for
all images in the backing chain, so the mirror job can take it for the
target BB).
Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-Id: <20210211172242.146671-2-mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
2021-02-12 01:22:41 +08:00
|
|
|
|
2017-01-26 02:16:34 +08:00
|
|
|
/* In the case of active commit, add dummy driver to provide consistent
|
|
|
|
* reads on the top, while disabling it in the intermediate nodes, and make
|
|
|
|
* the backing chain writable. */
|
2017-02-21 01:10:05 +08:00
|
|
|
mirror_top_bs = bdrv_new_open_driver(&bdrv_mirror_top, filter_node_name,
|
|
|
|
BDRV_O_RDWR, errp);
|
2017-01-26 02:16:34 +08:00
|
|
|
if (mirror_top_bs == NULL) {
|
2019-06-06 23:41:29 +08:00
|
|
|
return NULL;
|
2017-01-26 02:16:34 +08:00
|
|
|
}
|
2017-07-18 23:24:05 +08:00
|
|
|
if (!filter_node_name) {
|
|
|
|
mirror_top_bs->implicit = true;
|
|
|
|
}
|
2019-07-04 01:28:02 +08:00
|
|
|
|
|
|
|
/* So that we can always drop this node */
|
|
|
|
mirror_top_bs->never_freeze = true;
|
|
|
|
|
2017-01-26 02:16:34 +08:00
|
|
|
mirror_top_bs->total_sectors = bs->total_sectors;
|
2018-04-21 21:29:26 +08:00
|
|
|
mirror_top_bs->supported_write_flags = BDRV_REQ_WRITE_UNCHANGED;
|
2019-03-22 20:42:39 +08:00
|
|
|
mirror_top_bs->supported_zero_flags = BDRV_REQ_WRITE_UNCHANGED |
|
|
|
|
BDRV_REQ_NO_FALLBACK;
|
2018-06-14 02:18:19 +08:00
|
|
|
bs_opaque = g_new0(MirrorBDSOpaque, 1);
|
|
|
|
mirror_top_bs->opaque = bs_opaque;
|
2017-01-26 02:16:34 +08:00
|
|
|
|
block/mirror: Fix mirror_top's permissions
mirror_top currently shares all permissions, and takes only the WRITE
permission (if some parent has taken that permission, too).
That is wrong, though; mirror_top is a filter, so it should take
permissions like any other filter does. For example, if the parent
needs CONSISTENT_READ, we need to take that, too, and if it cannot share
the WRITE permission, we cannot share it either.
The exception is when mirror_top is used for active commit, where we
cannot take CONSISTENT_READ (because it is deliberately unshared above
the base node) and where we must share WRITE (so that it is shared for
all images in the backing chain, so the mirror job can take it for the
target BB).
Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-Id: <20210211172242.146671-2-mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
2021-02-12 01:22:41 +08:00
|
|
|
bs_opaque->is_commit = target_is_backing;
|
|
|
|
|
2017-01-26 02:16:34 +08:00
|
|
|
bdrv_drained_begin(bs);
|
2021-02-02 20:49:44 +08:00
|
|
|
ret = bdrv_append(mirror_top_bs, bs, errp);
|
2017-01-26 02:16:34 +08:00
|
|
|
bdrv_drained_end(bs);
|
|
|
|
|
2021-02-02 20:49:44 +08:00
|
|
|
if (ret < 0) {
|
2017-02-20 19:46:42 +08:00
|
|
|
bdrv_unref(mirror_top_bs);
|
2019-06-06 23:41:29 +08:00
|
|
|
return NULL;
|
2017-02-20 19:46:42 +08:00
|
|
|
}
|
|
|
|
|
2017-01-26 02:16:34 +08:00
|
|
|
/* Make sure that the source is not resized while the job is running */
|
2018-03-10 16:27:27 +08:00
|
|
|
s = block_job_create(job_id, driver, NULL, mirror_top_bs,
|
2017-01-26 02:16:34 +08:00
|
|
|
BLK_PERM_CONSISTENT_READ,
|
|
|
|
BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANGED |
|
block: drop BLK_PERM_GRAPH_MOD
First, this permission never protected a node from being changed, as
generic child-replacing functions don't check it.
Second, it's a strange thing: it presents a permission of parent node
to change its child. But generally, children are replaced by different
mechanisms, like jobs or qmp commands, not by nodes.
Graph-mod permission is hard to understand. All other permissions
describe operations which done by parent node on its child: read,
write, resize. Graph modification operations are something completely
different.
The only place where BLK_PERM_GRAPH_MOD is used as "perm" (not shared
perm) is mirror_start_job, for s->target. Still modern code should use
bdrv_freeze_backing_chain() to protect from graph modification, if we
don't do it somewhere it may be considered as a bug. So, it's a bit
risky to drop GRAPH_MOD, and analyzing of possible loss of protection
is hard. But one day we should do it, let's do it now.
One more bit of information is that locking the corresponding byte in
file-posix doesn't make sense at all.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20210902093754.2352-1-vsementsov@virtuozzo.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2021-09-02 17:37:54 +08:00
|
|
|
BLK_PERM_WRITE, speed,
|
2017-01-17 00:18:09 +08:00
|
|
|
creation_flags, cb, opaque, errp);
|
2012-10-18 22:49:23 +08:00
|
|
|
if (!s) {
|
2017-01-26 02:16:34 +08:00
|
|
|
goto fail;
|
2012-10-18 22:49:23 +08:00
|
|
|
}
|
2018-06-14 02:18:19 +08:00
|
|
|
|
2017-04-04 01:51:49 +08:00
|
|
|
/* The block job now has a reference to this node */
|
|
|
|
bdrv_unref(mirror_top_bs);
|
|
|
|
|
2017-01-26 02:16:34 +08:00
|
|
|
s->mirror_top_bs = mirror_top_bs;
|
|
|
|
|
|
|
|
/* No resize for the target either; while the mirror is still running, a
|
|
|
|
* consistent read isn't necessarily possible. We could possibly allow
|
|
|
|
* writes and graph modifications, though it would likely defeat the
|
|
|
|
* purpose of a mirror, so leave them blocked for now.
|
|
|
|
*
|
|
|
|
* In the case of active commit, things look a bit different, though,
|
|
|
|
* because the target is an already populated backing file in active use.
|
|
|
|
* We can allow anything except resize there.*/
|
2019-06-12 22:27:32 +08:00
|
|
|
|
|
|
|
target_perms = BLK_PERM_WRITE;
|
|
|
|
target_shared_perms = BLK_PERM_WRITE_UNCHANGED;
|
|
|
|
|
|
|
|
if (target_is_backing) {
|
|
|
|
int64_t bs_size, target_size;
|
|
|
|
bs_size = bdrv_getlength(bs);
|
|
|
|
if (bs_size < 0) {
|
|
|
|
error_setg_errno(errp, -bs_size,
|
|
|
|
"Could not inquire top image size");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
target_size = bdrv_getlength(target);
|
|
|
|
if (target_size < 0) {
|
|
|
|
error_setg_errno(errp, -target_size,
|
|
|
|
"Could not inquire base image size");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (target_size < bs_size) {
|
|
|
|
target_perms |= BLK_PERM_RESIZE;
|
|
|
|
}
|
|
|
|
|
block: drop BLK_PERM_GRAPH_MOD
First, this permission never protected a node from being changed, as
generic child-replacing functions don't check it.
Second, it's a strange thing: it presents a permission of parent node
to change its child. But generally, children are replaced by different
mechanisms, like jobs or qmp commands, not by nodes.
Graph-mod permission is hard to understand. All other permissions
describe operations which done by parent node on its child: read,
write, resize. Graph modification operations are something completely
different.
The only place where BLK_PERM_GRAPH_MOD is used as "perm" (not shared
perm) is mirror_start_job, for s->target. Still modern code should use
bdrv_freeze_backing_chain() to protect from graph modification, if we
don't do it somewhere it may be considered as a bug. So, it's a bit
risky to drop GRAPH_MOD, and analyzing of possible loss of protection
is hard. But one day we should do it, let's do it now.
One more bit of information is that locking the corresponding byte in
file-posix doesn't make sense at all.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20210902093754.2352-1-vsementsov@virtuozzo.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2021-09-02 17:37:54 +08:00
|
|
|
target_shared_perms |= BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE;
|
2023-10-27 23:53:17 +08:00
|
|
|
} else {
|
|
|
|
bdrv_graph_rdlock_main_loop();
|
|
|
|
if (bdrv_chain_contains(bs, bdrv_skip_filters(target))) {
|
|
|
|
/*
|
|
|
|
* We may want to allow this in the future, but it would
|
|
|
|
* require taking some extra care.
|
|
|
|
*/
|
|
|
|
error_setg(errp, "Cannot mirror to a filter on top of a node in "
|
|
|
|
"the source's backing chain");
|
|
|
|
bdrv_graph_rdunlock_main_loop();
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
bdrv_graph_rdunlock_main_loop();
|
2019-06-12 22:27:32 +08:00
|
|
|
}
|
|
|
|
|
2019-04-25 20:25:10 +08:00
|
|
|
s->target = blk_new(s->common.job.aio_context,
|
2019-06-12 22:27:32 +08:00
|
|
|
target_perms, target_shared_perms);
|
2017-01-14 02:02:32 +08:00
|
|
|
ret = blk_insert_bs(s->target, target, errp);
|
|
|
|
if (ret < 0) {
|
2017-01-26 02:16:34 +08:00
|
|
|
goto fail;
|
2017-01-14 02:02:32 +08:00
|
|
|
}
|
2017-08-23 21:42:41 +08:00
|
|
|
if (is_mirror) {
|
|
|
|
/* XXX: Mirror target could be a NBD server of target QEMU in the case
|
|
|
|
* of non-shared block migration. To allow migration completion, we
|
|
|
|
* have to allow "inactivate" of the target BB. When that happens, we
|
|
|
|
* know the job is drained, and the vcpus are stopped, so no write
|
|
|
|
* operation will be performed. Block layer already has assertions to
|
|
|
|
* ensure that. */
|
|
|
|
blk_set_force_allow_inactivate(s->target);
|
|
|
|
}
|
2019-05-07 01:18:03 +08:00
|
|
|
blk_set_allow_aio_context_change(s->target, true);
|
block-backend: Queue requests while drained
This fixes devices like IDE that can still start new requests from I/O
handlers in the CPU thread while the block backend is drained.
The basic assumption is that in a drain section, no new requests should
be allowed through a BlockBackend (blk_drained_begin/end don't exist,
we get drain sections only on the node level). However, there are two
special cases where requests should not be queued:
1. Block jobs: We already make sure that block jobs are paused in a
drain section, so they won't start new requests. However, if the
drain_begin is called on the job's BlockBackend first, it can happen
that we deadlock because the job stays busy until it reaches a pause
point - which it can't if its requests aren't processed any more.
The proper solution here would be to make all requests through the
job's filter node instead of using a BlockBackend. For now, just
disabling request queuing on the job BlockBackend is simpler.
2. In test cases where making requests through bdrv_* would be
cumbersome because we'd need a BdrvChild. As we already got the
functionality to disable request queuing from 1., use it in tests,
too, for convenience.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
2019-07-22 23:46:23 +08:00
|
|
|
blk_set_disable_request_queuing(s->target, true);
|
2016-04-12 22:17:41 +08:00
|
|
|
|
2023-10-27 23:53:17 +08:00
|
|
|
bdrv_graph_rdlock_main_loop();
|
2014-06-28 00:25:25 +08:00
|
|
|
s->replaces = g_strdup(replaces);
|
2012-10-18 22:49:28 +08:00
|
|
|
s->on_source_error = on_source_error;
|
|
|
|
s->on_target_error = on_target_error;
|
2013-12-16 14:45:30 +08:00
|
|
|
s->is_none_mode = is_none_mode;
|
block/mirror: Fix target backing BDS
Currently, we are trying to move the backing BDS from the source to the
target in bdrv_replace_in_backing_chain() which is called from
mirror_exit(). However, mirror_complete() already tries to open the
target's backing chain with a call to bdrv_open_backing_file().
First, we should only set the target's backing BDS once. Second, the
mirroring block job has a better idea of what to set it to than the
generic code in bdrv_replace_in_backing_chain() (in fact, the latter's
conditions on when to move the backing BDS from source to target are not
really correct).
Therefore, remove that code from bdrv_replace_in_backing_chain() and
leave it to mirror_complete().
Depending on what kind of mirroring is performed, we furthermore want to
use different strategies to open the target's backing chain:
- If blockdev-mirror is used, we can assume the user made sure that the
target already has the correct backing chain. In particular, we should
not try to open a backing file if the target does not have any yet.
- If drive-mirror with mode=absolute-paths is used, we can and should
reuse the already existing chain of nodes that the source BDS is in.
In case of sync=full, no backing BDS is required; with sync=top, we
just link the source's backing BDS to the target, and with sync=none,
we use the source BDS as the target's backing BDS.
We should not try to open these backing files anew because this would
lead to two BDSs existing per physical file in the backing chain, and
we would like to avoid such concurrent access.
- If drive-mirror with mode=existing is used, we have to use the
information provided in the physical image file which means opening
the target's backing chain completely anew, just as it has been done
already.
If the target's backing chain shares images with the source, this may
lead to multiple BDSs per physical image file. But since we cannot
reliably ascertain this case, there is nothing we can do about it.
Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-id: 20160610185750.30956-3-mreitz@redhat.com
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Fam Zheng <famz@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2016-06-11 02:57:47 +08:00
|
|
|
s->backing_mode = backing_mode;
|
2019-07-25 01:12:30 +08:00
|
|
|
s->zero_target = zero_target;
|
2023-10-31 21:54:26 +08:00
|
|
|
qatomic_set(&s->copy_mode, copy_mode);
|
2013-12-16 14:45:29 +08:00
|
|
|
s->base = base;
|
2019-06-12 22:27:32 +08:00
|
|
|
s->base_overlay = bdrv_find_overlay(bs, base);
|
2013-01-22 00:09:46 +08:00
|
|
|
s->granularity = granularity;
|
2015-05-15 15:51:36 +08:00
|
|
|
s->buf_size = ROUND_UP(buf_size, granularity);
|
2015-06-08 13:56:08 +08:00
|
|
|
s->unmap = unmap;
|
2016-07-27 15:01:47 +08:00
|
|
|
if (auto_complete) {
|
|
|
|
s->should_complete = true;
|
|
|
|
}
|
2023-10-27 23:53:17 +08:00
|
|
|
bdrv_graph_rdunlock_main_loop();
|
2013-01-22 00:09:43 +08:00
|
|
|
|
2023-10-31 21:54:24 +08:00
|
|
|
s->dirty_bitmap = bdrv_create_dirty_bitmap(s->mirror_top_bs, granularity,
|
|
|
|
NULL, errp);
|
2014-04-16 09:34:30 +08:00
|
|
|
if (!s->dirty_bitmap) {
|
2017-03-06 23:12:44 +08:00
|
|
|
goto fail;
|
2014-04-16 09:34:30 +08:00
|
|
|
}
|
2023-10-31 21:54:24 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The dirty bitmap is set by bdrv_mirror_top_do_write() when not in active
|
|
|
|
* mode.
|
|
|
|
*/
|
|
|
|
bdrv_disable_dirty_bitmap(s->dirty_bitmap);
|
2015-11-02 22:51:53 +08:00
|
|
|
|
2023-12-06 02:20:02 +08:00
|
|
|
bdrv_graph_wrlock();
|
mirror: Block the source BlockDriverState in mirror_start_job()
The mirror_start_job() function used for the commit-active job blocks
the source, target and all intermediate nodes for the duration of the
job.
target <- intermediate <- source
Since 4ef85a9c2339 this function creates a dummy mirror_top_bs that
goes on top of the source node, and it is this dummy node that gets
blocked instead. The source node is never blocked or added to the
job's list of nodes.
target <- intermediate <- source <- mirror_top
At the moment I don't think it is possible to exploit this problem
because any additional job on 'source' would either be forbidden for
other reasons or it would need to involve an additional node that is
blocked, causing an error.
This can be seen in the error messages, however, because they never
refer to the source node being blocked:
$ qemu-img create -f qcow2 hd0.qcow2 1M
$ qemu-img create -f qcow2 -b hd0.qcow2 hd1.qcow2
$ qemu-io -c 'write 0 1M' hd0.qcow2
$ $QEMU -drive if=none,file=hd1.qcow2,node-name=hd1
{ "execute": "qmp_capabilities" }
{ "execute": "block-commit", "arguments": {"device": "hd1", "speed": 256}}
{ "execute": "block-stream", "arguments": {"device": "hd1"}}
{ "error": {"class": "GenericError",
"desc": "Node 'hd0' is busy: block device is in use by block job: commit"}}
After this patch the error message refers to 'hd1', as it should.
The expected output of iotest 141 also needs to be updated for the
same reason.
Signed-off-by: Alberto Garcia <berto@igalia.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2018-11-22 23:00:27 +08:00
|
|
|
ret = block_job_add_bdrv(&s->common, "source", bs, 0,
|
|
|
|
BLK_PERM_WRITE_UNCHANGED | BLK_PERM_WRITE |
|
|
|
|
BLK_PERM_CONSISTENT_READ,
|
|
|
|
errp);
|
|
|
|
if (ret < 0) {
|
2023-12-06 02:20:02 +08:00
|
|
|
bdrv_graph_wrunlock();
|
mirror: Block the source BlockDriverState in mirror_start_job()
The mirror_start_job() function used for the commit-active job blocks
the source, target and all intermediate nodes for the duration of the
job.
target <- intermediate <- source
Since 4ef85a9c2339 this function creates a dummy mirror_top_bs that
goes on top of the source node, and it is this dummy node that gets
blocked instead. The source node is never blocked or added to the
job's list of nodes.
target <- intermediate <- source <- mirror_top
At the moment I don't think it is possible to exploit this problem
because any additional job on 'source' would either be forbidden for
other reasons or it would need to involve an additional node that is
blocked, causing an error.
This can be seen in the error messages, however, because they never
refer to the source node being blocked:
$ qemu-img create -f qcow2 hd0.qcow2 1M
$ qemu-img create -f qcow2 -b hd0.qcow2 hd1.qcow2
$ qemu-io -c 'write 0 1M' hd0.qcow2
$ $QEMU -drive if=none,file=hd1.qcow2,node-name=hd1
{ "execute": "qmp_capabilities" }
{ "execute": "block-commit", "arguments": {"device": "hd1", "speed": 256}}
{ "execute": "block-stream", "arguments": {"device": "hd1"}}
{ "error": {"class": "GenericError",
"desc": "Node 'hd0' is busy: block device is in use by block job: commit"}}
After this patch the error message refers to 'hd1', as it should.
The expected output of iotest 141 also needs to be updated for the
same reason.
Signed-off-by: Alberto Garcia <berto@igalia.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2018-11-22 23:00:27 +08:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2017-01-26 02:16:34 +08:00
|
|
|
/* Required permissions are already taken with blk_new() */
|
2017-01-17 18:56:42 +08:00
|
|
|
block_job_add_bdrv(&s->common, "target", target, 0, BLK_PERM_ALL,
|
|
|
|
&error_abort);
|
|
|
|
|
2016-10-28 15:08:09 +08:00
|
|
|
/* In commit_active_start() all intermediate nodes disappear, so
|
|
|
|
* any jobs in them must be blocked */
|
2017-01-26 02:16:34 +08:00
|
|
|
if (target_is_backing) {
|
2019-06-12 22:27:32 +08:00
|
|
|
BlockDriverState *iter, *filtered_target;
|
|
|
|
uint64_t iter_shared_perms;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The topmost node with
|
|
|
|
* bdrv_skip_filters(filtered_target) == bdrv_skip_filters(target)
|
|
|
|
*/
|
|
|
|
filtered_target = bdrv_cow_bs(bdrv_find_overlay(bs, target));
|
|
|
|
|
|
|
|
assert(bdrv_skip_filters(filtered_target) ==
|
|
|
|
bdrv_skip_filters(target));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX BLK_PERM_WRITE needs to be allowed so we don't block
|
|
|
|
* ourselves at s->base (if writes are blocked for a node, they are
|
|
|
|
* also blocked for its backing file). The other options would be a
|
|
|
|
* second filter driver above s->base (== target).
|
|
|
|
*/
|
|
|
|
iter_shared_perms = BLK_PERM_WRITE_UNCHANGED | BLK_PERM_WRITE;
|
|
|
|
|
|
|
|
for (iter = bdrv_filter_or_cow_bs(bs); iter != target;
|
|
|
|
iter = bdrv_filter_or_cow_bs(iter))
|
|
|
|
{
|
|
|
|
if (iter == filtered_target) {
|
|
|
|
/*
|
|
|
|
* From here on, all nodes are filters on the base.
|
|
|
|
* This allows us to share BLK_PERM_CONSISTENT_READ.
|
|
|
|
*/
|
|
|
|
iter_shared_perms |= BLK_PERM_CONSISTENT_READ;
|
|
|
|
}
|
|
|
|
|
2017-01-26 02:16:34 +08:00
|
|
|
ret = block_job_add_bdrv(&s->common, "intermediate node", iter, 0,
|
2019-06-12 22:27:32 +08:00
|
|
|
iter_shared_perms, errp);
|
2017-01-26 02:16:34 +08:00
|
|
|
if (ret < 0) {
|
2023-12-06 02:20:02 +08:00
|
|
|
bdrv_graph_wrunlock();
|
2017-01-26 02:16:34 +08:00
|
|
|
goto fail;
|
|
|
|
}
|
2016-10-28 15:08:09 +08:00
|
|
|
}
|
2019-03-13 00:48:42 +08:00
|
|
|
|
|
|
|
if (bdrv_freeze_backing_chain(mirror_top_bs, target, errp) < 0) {
|
2023-12-06 02:20:02 +08:00
|
|
|
bdrv_graph_wrunlock();
|
2019-03-13 00:48:42 +08:00
|
|
|
goto fail;
|
|
|
|
}
|
2016-10-28 15:08:09 +08:00
|
|
|
}
|
2023-12-06 02:20:02 +08:00
|
|
|
bdrv_graph_wrunlock();
|
2015-11-02 22:51:53 +08:00
|
|
|
|
2018-06-14 02:18:12 +08:00
|
|
|
QTAILQ_INIT(&s->ops_in_flight);
|
|
|
|
|
2016-11-08 14:50:37 +08:00
|
|
|
trace_mirror_start(bs, s, opaque);
|
2018-04-13 23:31:02 +08:00
|
|
|
job_start(&s->common.job);
|
2019-06-06 23:41:29 +08:00
|
|
|
|
|
|
|
return &s->common;
|
2017-01-26 02:16:34 +08:00
|
|
|
|
|
|
|
fail:
|
|
|
|
if (s) {
|
2017-04-04 01:51:49 +08:00
|
|
|
/* Make sure this BDS does not go away until we have completed the graph
|
|
|
|
* changes below */
|
|
|
|
bdrv_ref(mirror_top_bs);
|
|
|
|
|
2017-01-26 02:16:34 +08:00
|
|
|
g_free(s->replaces);
|
|
|
|
blk_unref(s->target);
|
2018-06-14 02:18:19 +08:00
|
|
|
bs_opaque->job = NULL;
|
2018-11-22 23:00:26 +08:00
|
|
|
if (s->dirty_bitmap) {
|
2019-09-16 22:19:09 +08:00
|
|
|
bdrv_release_dirty_bitmap(s->dirty_bitmap);
|
2018-11-22 23:00:26 +08:00
|
|
|
}
|
2018-04-19 23:30:16 +08:00
|
|
|
job_early_fail(&s->common.job);
|
2017-01-26 02:16:34 +08:00
|
|
|
}
|
|
|
|
|
2019-05-23 01:03:47 +08:00
|
|
|
bs_opaque->stop = true;
|
2023-10-27 23:53:25 +08:00
|
|
|
bdrv_drained_begin(bs);
|
2023-12-06 02:20:02 +08:00
|
|
|
bdrv_graph_wrlock();
|
2023-10-27 23:53:25 +08:00
|
|
|
assert(mirror_top_bs->backing->bs == bs);
|
2019-05-23 01:03:47 +08:00
|
|
|
bdrv_child_refresh_perms(mirror_top_bs, mirror_top_bs->backing,
|
|
|
|
&error_abort);
|
2023-10-27 23:53:25 +08:00
|
|
|
bdrv_replace_node(mirror_top_bs, bs, &error_abort);
|
2023-12-06 02:20:02 +08:00
|
|
|
bdrv_graph_wrunlock();
|
2023-10-27 23:53:25 +08:00
|
|
|
bdrv_drained_end(bs);
|
2017-04-04 01:51:49 +08:00
|
|
|
|
|
|
|
bdrv_unref(mirror_top_bs);
|
2019-06-06 23:41:29 +08:00
|
|
|
|
|
|
|
return NULL;
|
2012-10-18 22:49:23 +08:00
|
|
|
}
|
2013-12-16 14:45:30 +08:00
|
|
|
|
2016-07-05 22:28:57 +08:00
|
|
|
void mirror_start(const char *job_id, BlockDriverState *bs,
|
|
|
|
BlockDriverState *target, const char *replaces,
|
2018-09-06 21:02:11 +08:00
|
|
|
int creation_flags, int64_t speed,
|
|
|
|
uint32_t granularity, int64_t buf_size,
|
block/mirror: Fix target backing BDS
Currently, we are trying to move the backing BDS from the source to the
target in bdrv_replace_in_backing_chain() which is called from
mirror_exit(). However, mirror_complete() already tries to open the
target's backing chain with a call to bdrv_open_backing_file().
First, we should only set the target's backing BDS once. Second, the
mirroring block job has a better idea of what to set it to than the
generic code in bdrv_replace_in_backing_chain() (in fact, the latter's
conditions on when to move the backing BDS from source to target are not
really correct).
Therefore, remove that code from bdrv_replace_in_backing_chain() and
leave it to mirror_complete().
Depending on what kind of mirroring is performed, we furthermore want to
use different strategies to open the target's backing chain:
- If blockdev-mirror is used, we can assume the user made sure that the
target already has the correct backing chain. In particular, we should
not try to open a backing file if the target does not have any yet.
- If drive-mirror with mode=absolute-paths is used, we can and should
reuse the already existing chain of nodes that the source BDS is in.
In case of sync=full, no backing BDS is required; with sync=top, we
just link the source's backing BDS to the target, and with sync=none,
we use the source BDS as the target's backing BDS.
We should not try to open these backing files anew because this would
lead to two BDSs existing per physical file in the backing chain, and
we would like to avoid such concurrent access.
- If drive-mirror with mode=existing is used, we have to use the
information provided in the physical image file which means opening
the target's backing chain completely anew, just as it has been done
already.
If the target's backing chain shares images with the source, this may
lead to multiple BDSs per physical image file. But since we cannot
reliably ascertain this case, there is nothing we can do about it.
Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-id: 20160610185750.30956-3-mreitz@redhat.com
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Fam Zheng <famz@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2016-06-11 02:57:47 +08:00
|
|
|
MirrorSyncMode mode, BlockMirrorBackingMode backing_mode,
|
2019-07-25 01:12:30 +08:00
|
|
|
bool zero_target,
|
block/mirror: Fix target backing BDS
Currently, we are trying to move the backing BDS from the source to the
target in bdrv_replace_in_backing_chain() which is called from
mirror_exit(). However, mirror_complete() already tries to open the
target's backing chain with a call to bdrv_open_backing_file().
First, we should only set the target's backing BDS once. Second, the
mirroring block job has a better idea of what to set it to than the
generic code in bdrv_replace_in_backing_chain() (in fact, the latter's
conditions on when to move the backing BDS from source to target are not
really correct).
Therefore, remove that code from bdrv_replace_in_backing_chain() and
leave it to mirror_complete().
Depending on what kind of mirroring is performed, we furthermore want to
use different strategies to open the target's backing chain:
- If blockdev-mirror is used, we can assume the user made sure that the
target already has the correct backing chain. In particular, we should
not try to open a backing file if the target does not have any yet.
- If drive-mirror with mode=absolute-paths is used, we can and should
reuse the already existing chain of nodes that the source BDS is in.
In case of sync=full, no backing BDS is required; with sync=top, we
just link the source's backing BDS to the target, and with sync=none,
we use the source BDS as the target's backing BDS.
We should not try to open these backing files anew because this would
lead to two BDSs existing per physical file in the backing chain, and
we would like to avoid such concurrent access.
- If drive-mirror with mode=existing is used, we have to use the
information provided in the physical image file which means opening
the target's backing chain completely anew, just as it has been done
already.
If the target's backing chain shares images with the source, this may
lead to multiple BDSs per physical image file. But since we cannot
reliably ascertain this case, there is nothing we can do about it.
Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-id: 20160610185750.30956-3-mreitz@redhat.com
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Fam Zheng <famz@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2016-06-11 02:57:47 +08:00
|
|
|
BlockdevOnError on_source_error,
|
2013-12-16 14:45:30 +08:00
|
|
|
BlockdevOnError on_target_error,
|
2018-06-14 02:18:22 +08:00
|
|
|
bool unmap, const char *filter_node_name,
|
|
|
|
MirrorCopyMode copy_mode, Error **errp)
|
2013-12-16 14:45:30 +08:00
|
|
|
{
|
|
|
|
bool is_none_mode;
|
|
|
|
BlockDriverState *base;
|
|
|
|
|
2022-03-03 23:15:57 +08:00
|
|
|
GLOBAL_STATE_CODE();
|
|
|
|
|
2019-07-30 04:35:52 +08:00
|
|
|
if ((mode == MIRROR_SYNC_MODE_INCREMENTAL) ||
|
|
|
|
(mode == MIRROR_SYNC_MODE_BITMAP)) {
|
|
|
|
error_setg(errp, "Sync mode '%s' not supported",
|
|
|
|
MirrorSyncMode_str(mode));
|
2015-04-18 07:49:58 +08:00
|
|
|
return;
|
|
|
|
}
|
2023-10-27 23:53:17 +08:00
|
|
|
|
|
|
|
bdrv_graph_rdlock_main_loop();
|
2013-12-16 14:45:30 +08:00
|
|
|
is_none_mode = mode == MIRROR_SYNC_MODE_NONE;
|
2019-06-12 22:27:32 +08:00
|
|
|
base = mode == MIRROR_SYNC_MODE_TOP ? bdrv_backing_chain_next(bs) : NULL;
|
2023-10-27 23:53:17 +08:00
|
|
|
bdrv_graph_rdunlock_main_loop();
|
|
|
|
|
2018-09-06 21:02:11 +08:00
|
|
|
mirror_start_job(job_id, bs, creation_flags, target, replaces,
|
2019-07-25 01:12:30 +08:00
|
|
|
speed, granularity, buf_size, backing_mode, zero_target,
|
2017-04-21 20:27:03 +08:00
|
|
|
on_source_error, on_target_error, unmap, NULL, NULL,
|
2017-02-21 01:10:05 +08:00
|
|
|
&mirror_job_driver, is_none_mode, base, false,
|
2018-06-14 02:18:22 +08:00
|
|
|
filter_node_name, true, copy_mode, errp);
|
2013-12-16 14:45:30 +08:00
|
|
|
}
|
|
|
|
|
2019-06-06 23:41:29 +08:00
|
|
|
BlockJob *commit_active_start(const char *job_id, BlockDriverState *bs,
|
|
|
|
BlockDriverState *base, int creation_flags,
|
|
|
|
int64_t speed, BlockdevOnError on_error,
|
|
|
|
const char *filter_node_name,
|
|
|
|
BlockCompletionFunc *cb, void *opaque,
|
|
|
|
bool auto_complete, Error **errp)
|
2013-12-16 14:45:30 +08:00
|
|
|
{
|
2018-11-12 22:00:40 +08:00
|
|
|
bool base_read_only;
|
2021-02-02 20:49:48 +08:00
|
|
|
BlockJob *job;
|
2014-01-24 22:02:36 +08:00
|
|
|
|
2022-03-03 23:15:57 +08:00
|
|
|
GLOBAL_STATE_CODE();
|
|
|
|
|
2018-11-12 22:00:40 +08:00
|
|
|
base_read_only = bdrv_is_read_only(base);
|
2014-01-24 22:02:36 +08:00
|
|
|
|
2018-11-12 22:00:40 +08:00
|
|
|
if (base_read_only) {
|
|
|
|
if (bdrv_reopen_set_read_only(base, false, errp) < 0) {
|
2019-06-06 23:41:29 +08:00
|
|
|
return NULL;
|
2018-11-12 22:00:40 +08:00
|
|
|
}
|
2013-12-16 14:45:31 +08:00
|
|
|
}
|
2014-01-24 22:02:36 +08:00
|
|
|
|
2021-02-02 20:49:48 +08:00
|
|
|
job = mirror_start_job(
|
2019-06-06 23:41:29 +08:00
|
|
|
job_id, bs, creation_flags, base, NULL, speed, 0, 0,
|
2019-07-25 01:12:30 +08:00
|
|
|
MIRROR_LEAVE_BACKING_CHAIN, false,
|
2017-04-21 20:27:03 +08:00
|
|
|
on_error, on_error, true, cb, opaque,
|
2017-02-21 01:10:05 +08:00
|
|
|
&commit_active_job_driver, false, base, auto_complete,
|
2018-06-14 02:18:22 +08:00
|
|
|
filter_node_name, false, MIRROR_COPY_MODE_BACKGROUND,
|
2021-02-02 20:49:48 +08:00
|
|
|
errp);
|
|
|
|
if (!job) {
|
2014-01-24 22:02:36 +08:00
|
|
|
goto error_restore_flags;
|
|
|
|
}
|
|
|
|
|
2021-02-02 20:49:48 +08:00
|
|
|
return job;
|
2014-01-24 22:02:36 +08:00
|
|
|
|
|
|
|
error_restore_flags:
|
|
|
|
/* ignore error and errp for bdrv_reopen, because we want to propagate
|
|
|
|
* the original error */
|
2018-11-12 22:00:40 +08:00
|
|
|
if (base_read_only) {
|
|
|
|
bdrv_reopen_set_read_only(base, true, NULL);
|
|
|
|
}
|
2019-06-06 23:41:29 +08:00
|
|
|
return NULL;
|
2013-12-16 14:45:30 +08:00
|
|
|
}
|