2019-09-20 16:20:48 +02:00
|
|
|
|
/*
|
|
|
|
|
* block_copy API
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2013 Proxmox Server Solutions
|
|
|
|
|
* Copyright (c) 2019 Virtuozzo International GmbH.
|
|
|
|
|
*
|
|
|
|
|
* Authors:
|
|
|
|
|
* Dietmar Maurer (dietmar@proxmox.com)
|
|
|
|
|
* Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
|
|
|
|
|
*
|
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
|
|
|
* See the COPYING file in the top-level directory.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "qemu/osdep.h"
|
|
|
|
|
|
|
|
|
|
#include "trace.h"
|
|
|
|
|
#include "qapi/error.h"
|
|
|
|
|
#include "block/block-copy.h"
|
|
|
|
|
#include "sysemu/block-backend.h"
|
2019-10-22 13:18:01 +02:00
|
|
|
|
#include "qemu/units.h"
|
2020-04-29 15:08:47 +02:00
|
|
|
|
#include "qemu/coroutine.h"
|
|
|
|
|
#include "block/aio_task.h"
|
2019-10-22 13:18:01 +02:00
|
|
|
|
|
|
|
|
|
#define BLOCK_COPY_MAX_COPY_RANGE (16 * MiB)
|
2019-10-22 13:18:05 +02:00
|
|
|
|
#define BLOCK_COPY_MAX_BUFFER (1 * MiB)
|
2019-10-22 13:18:04 +02:00
|
|
|
|
#define BLOCK_COPY_MAX_MEM (128 * MiB)
|
2020-04-29 15:08:47 +02:00
|
|
|
|
#define BLOCK_COPY_MAX_WORKERS 64
|
|
|
|
|
|
|
|
|
|
static coroutine_fn int block_copy_task_entry(AioTask *task);
|
|
|
|
|
|
|
|
|
|
typedef struct BlockCopyCallState {
|
|
|
|
|
bool failed;
|
|
|
|
|
bool error_is_read;
|
|
|
|
|
} BlockCopyCallState;
|
2019-09-20 16:20:48 +02:00
|
|
|
|
|
2020-04-29 15:08:43 +02:00
|
|
|
|
typedef struct BlockCopyTask {
|
2020-04-29 15:08:47 +02:00
|
|
|
|
AioTask task;
|
|
|
|
|
|
2020-04-29 15:08:45 +02:00
|
|
|
|
BlockCopyState *s;
|
2020-04-29 15:08:47 +02:00
|
|
|
|
BlockCopyCallState *call_state;
|
2020-03-11 11:30:04 +01:00
|
|
|
|
int64_t offset;
|
|
|
|
|
int64_t bytes;
|
2020-04-29 15:08:47 +02:00
|
|
|
|
bool zeroes;
|
2020-04-29 15:08:43 +02:00
|
|
|
|
QLIST_ENTRY(BlockCopyTask) list;
|
|
|
|
|
CoQueue wait_queue; /* coroutines blocked on this task */
|
|
|
|
|
} BlockCopyTask;
|
2020-03-11 11:30:04 +01:00
|
|
|
|
|
2020-04-29 15:08:46 +02:00
|
|
|
|
static int64_t task_end(BlockCopyTask *task)
|
|
|
|
|
{
|
|
|
|
|
return task->offset + task->bytes;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-11 11:30:04 +01:00
|
|
|
|
typedef struct BlockCopyState {
|
|
|
|
|
/*
|
|
|
|
|
* BdrvChild objects are not owned or managed by block-copy. They are
|
|
|
|
|
* provided by block-copy user and user is responsible for appropriate
|
|
|
|
|
* permissions on these children.
|
|
|
|
|
*/
|
|
|
|
|
BdrvChild *source;
|
|
|
|
|
BdrvChild *target;
|
|
|
|
|
BdrvDirtyBitmap *copy_bitmap;
|
|
|
|
|
int64_t in_flight_bytes;
|
|
|
|
|
int64_t cluster_size;
|
|
|
|
|
bool use_copy_range;
|
|
|
|
|
int64_t copy_size;
|
|
|
|
|
uint64_t len;
|
2020-04-29 15:08:43 +02:00
|
|
|
|
QLIST_HEAD(, BlockCopyTask) tasks;
|
2020-03-11 11:30:04 +01:00
|
|
|
|
|
|
|
|
|
BdrvRequestFlags write_flags;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* skip_unallocated:
|
|
|
|
|
*
|
|
|
|
|
* Used by sync=top jobs, which first scan the source node for unallocated
|
|
|
|
|
* areas and clear them in the copy_bitmap. During this process, the bitmap
|
|
|
|
|
* is thus not fully initialized: It may still have bits set for areas that
|
|
|
|
|
* are unallocated and should actually not be copied.
|
|
|
|
|
*
|
|
|
|
|
* This is indicated by skip_unallocated.
|
|
|
|
|
*
|
|
|
|
|
* In this case, block_copy() will query the source’s allocation status,
|
|
|
|
|
* skip unallocated regions, clear them in the copy_bitmap, and invoke
|
|
|
|
|
* block_copy_reset_unallocated() every time it does.
|
|
|
|
|
*/
|
|
|
|
|
bool skip_unallocated;
|
|
|
|
|
|
|
|
|
|
ProgressMeter *progress;
|
|
|
|
|
/* progress_bytes_callback: called when some copying progress is done. */
|
|
|
|
|
ProgressBytesCallbackFunc progress_bytes_callback;
|
|
|
|
|
void *progress_opaque;
|
|
|
|
|
|
|
|
|
|
SharedResource *mem;
|
|
|
|
|
} BlockCopyState;
|
|
|
|
|
|
2020-04-29 15:08:43 +02:00
|
|
|
|
static BlockCopyTask *find_conflicting_task(BlockCopyState *s,
|
|
|
|
|
int64_t offset, int64_t bytes)
|
2020-03-11 11:30:00 +01:00
|
|
|
|
{
|
2020-04-29 15:08:43 +02:00
|
|
|
|
BlockCopyTask *t;
|
2020-03-11 11:30:00 +01:00
|
|
|
|
|
2020-04-29 15:08:43 +02:00
|
|
|
|
QLIST_FOREACH(t, &s->tasks, list) {
|
|
|
|
|
if (offset + bytes > t->offset && offset < t->offset + t->bytes) {
|
|
|
|
|
return t;
|
2020-03-11 11:30:00 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-11 11:30:03 +01:00
|
|
|
|
/*
|
2020-04-29 15:08:43 +02:00
|
|
|
|
* If there are no intersecting tasks return false. Otherwise, wait for the
|
|
|
|
|
* first found intersecting tasks to finish and return true.
|
2020-03-11 11:30:03 +01:00
|
|
|
|
*/
|
|
|
|
|
static bool coroutine_fn block_copy_wait_one(BlockCopyState *s, int64_t offset,
|
|
|
|
|
int64_t bytes)
|
2019-10-01 15:14:05 +02:00
|
|
|
|
{
|
2020-04-29 15:08:43 +02:00
|
|
|
|
BlockCopyTask *task = find_conflicting_task(s, offset, bytes);
|
2020-03-11 11:30:00 +01:00
|
|
|
|
|
2020-04-29 15:08:43 +02:00
|
|
|
|
if (!task) {
|
2020-03-11 11:30:03 +01:00
|
|
|
|
return false;
|
2020-03-11 11:30:00 +01:00
|
|
|
|
}
|
2020-03-11 11:30:03 +01:00
|
|
|
|
|
2020-04-29 15:08:43 +02:00
|
|
|
|
qemu_co_queue_wait(&task->wait_queue, NULL);
|
2020-03-11 11:30:03 +01:00
|
|
|
|
|
|
|
|
|
return true;
|
2019-10-01 15:14:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-29 15:08:46 +02:00
|
|
|
|
/*
|
|
|
|
|
* Search for the first dirty area in offset/bytes range and create task at
|
|
|
|
|
* the beginning of it.
|
|
|
|
|
*/
|
2020-04-29 15:08:44 +02:00
|
|
|
|
static BlockCopyTask *block_copy_task_create(BlockCopyState *s,
|
2020-04-29 15:08:47 +02:00
|
|
|
|
BlockCopyCallState *call_state,
|
2020-04-29 15:08:44 +02:00
|
|
|
|
int64_t offset, int64_t bytes)
|
2019-10-01 15:14:05 +02:00
|
|
|
|
{
|
2020-04-29 15:08:46 +02:00
|
|
|
|
BlockCopyTask *task;
|
2020-04-29 15:08:44 +02:00
|
|
|
|
|
2020-04-29 15:08:46 +02:00
|
|
|
|
if (!bdrv_dirty_bitmap_next_dirty_area(s->copy_bitmap,
|
|
|
|
|
offset, offset + bytes,
|
|
|
|
|
s->copy_size, &offset, &bytes))
|
|
|
|
|
{
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-10 11:55:22 +02:00
|
|
|
|
assert(QEMU_IS_ALIGNED(offset, s->cluster_size));
|
|
|
|
|
bytes = QEMU_ALIGN_UP(bytes, s->cluster_size);
|
|
|
|
|
|
2020-04-29 15:08:46 +02:00
|
|
|
|
/* region is dirty, so no existent tasks possible in it */
|
2020-04-29 15:08:43 +02:00
|
|
|
|
assert(!find_conflicting_task(s, offset, bytes));
|
2020-03-11 11:30:03 +01:00
|
|
|
|
|
|
|
|
|
bdrv_reset_dirty_bitmap(s->copy_bitmap, offset, bytes);
|
|
|
|
|
s->in_flight_bytes += bytes;
|
|
|
|
|
|
2020-04-29 15:08:46 +02:00
|
|
|
|
task = g_new(BlockCopyTask, 1);
|
2020-04-29 15:08:45 +02:00
|
|
|
|
*task = (BlockCopyTask) {
|
2020-04-29 15:08:47 +02:00
|
|
|
|
.task.func = block_copy_task_entry,
|
2020-04-29 15:08:45 +02:00
|
|
|
|
.s = s,
|
2020-04-29 15:08:47 +02:00
|
|
|
|
.call_state = call_state,
|
2020-04-29 15:08:45 +02:00
|
|
|
|
.offset = offset,
|
|
|
|
|
.bytes = bytes,
|
|
|
|
|
};
|
2020-04-29 15:08:43 +02:00
|
|
|
|
qemu_co_queue_init(&task->wait_queue);
|
|
|
|
|
QLIST_INSERT_HEAD(&s->tasks, task, list);
|
2020-04-29 15:08:44 +02:00
|
|
|
|
|
|
|
|
|
return task;
|
2019-10-01 15:14:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-11 11:30:03 +01:00
|
|
|
|
/*
|
2020-04-29 15:08:43 +02:00
|
|
|
|
* block_copy_task_shrink
|
2020-03-11 11:30:03 +01:00
|
|
|
|
*
|
2020-04-29 15:08:43 +02:00
|
|
|
|
* Drop the tail of the task to be handled later. Set dirty bits back and
|
|
|
|
|
* wake up all tasks waiting for us (may be some of them are not intersecting
|
|
|
|
|
* with shrunk task)
|
2020-03-11 11:30:03 +01:00
|
|
|
|
*/
|
2020-04-29 15:08:45 +02:00
|
|
|
|
static void coroutine_fn block_copy_task_shrink(BlockCopyTask *task,
|
2020-04-29 15:08:43 +02:00
|
|
|
|
int64_t new_bytes)
|
2019-10-01 15:14:05 +02:00
|
|
|
|
{
|
2020-04-29 15:08:43 +02:00
|
|
|
|
if (new_bytes == task->bytes) {
|
2020-03-11 11:30:03 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-29 15:08:43 +02:00
|
|
|
|
assert(new_bytes > 0 && new_bytes < task->bytes);
|
2020-03-11 11:30:03 +01:00
|
|
|
|
|
2020-04-29 15:08:45 +02:00
|
|
|
|
task->s->in_flight_bytes -= task->bytes - new_bytes;
|
|
|
|
|
bdrv_set_dirty_bitmap(task->s->copy_bitmap,
|
2020-04-29 15:08:43 +02:00
|
|
|
|
task->offset + new_bytes, task->bytes - new_bytes);
|
2020-03-11 11:30:03 +01:00
|
|
|
|
|
2020-04-29 15:08:43 +02:00
|
|
|
|
task->bytes = new_bytes;
|
|
|
|
|
qemu_co_queue_restart_all(&task->wait_queue);
|
2020-03-11 11:30:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-29 15:08:45 +02:00
|
|
|
|
static void coroutine_fn block_copy_task_end(BlockCopyTask *task, int ret)
|
2020-03-11 11:30:03 +01:00
|
|
|
|
{
|
2020-04-29 15:08:45 +02:00
|
|
|
|
task->s->in_flight_bytes -= task->bytes;
|
2020-03-11 11:30:03 +01:00
|
|
|
|
if (ret < 0) {
|
2020-04-29 15:08:45 +02:00
|
|
|
|
bdrv_set_dirty_bitmap(task->s->copy_bitmap, task->offset, task->bytes);
|
2020-03-11 11:30:03 +01:00
|
|
|
|
}
|
2020-04-29 15:08:43 +02:00
|
|
|
|
QLIST_REMOVE(task, list);
|
|
|
|
|
qemu_co_queue_restart_all(&task->wait_queue);
|
2019-10-01 15:14:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-20 16:20:48 +02:00
|
|
|
|
void block_copy_state_free(BlockCopyState *s)
|
|
|
|
|
{
|
|
|
|
|
if (!s) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-16 16:19:09 +02:00
|
|
|
|
bdrv_release_dirty_bitmap(s->copy_bitmap);
|
2019-10-22 13:18:04 +02:00
|
|
|
|
shres_destroy(s->mem);
|
2019-09-20 16:20:48 +02:00
|
|
|
|
g_free(s);
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-11 11:29:58 +01:00
|
|
|
|
static uint32_t block_copy_max_transfer(BdrvChild *source, BdrvChild *target)
|
|
|
|
|
{
|
|
|
|
|
return MIN_NON_ZERO(INT_MAX,
|
|
|
|
|
MIN_NON_ZERO(source->bs->bl.max_transfer,
|
|
|
|
|
target->bs->bl.max_transfer));
|
|
|
|
|
}
|
|
|
|
|
|
block/backup: use backup-top instead of write notifiers
Drop write notifiers and use filter node instead.
= Changes =
1. Add filter-node-name argument for backup qmp api. We have to do it
in this commit, as 257 needs to be fixed.
2. There are no more write notifiers here, so is_write_notifier
parameter is dropped from block-copy paths.
3. To sync with in-flight requests at job finish we now have drained
removing of the filter, we don't need rw-lock.
4. Block-copy is now using BdrvChildren instead of BlockBackends
5. As backup-top owns these children, we also move block-copy state
into backup-top's ownership.
= Iotest changes =
56: op-blocker doesn't shoot now, as we set it on source, but then
check on filter, when trying to start second backup.
To keep the test we instead can catch another collision: both jobs will
get 'drive0' job-id, as job-id parameter is unspecified. To prevent
interleaving with file-posix locks (as they are dependent on config)
let's use another target for second backup.
Also, it's obvious now that we'd like to drop this op-blocker at all
and add a test-case for two backups from one node (to different
destinations) actually works. But not in these series.
141: Output changed: prepatch, "Node is in use" comes from bdrv_has_blk
check inside qmp_blockdev_del. But we've dropped block-copy blk
objects, so no more blk objects on source bs (job blk is on backup-top
filter bs). New message is from op-blocker, which is the next check in
qmp_blockdev_add.
257: The test wants to emulate guest write during backup. They should
go to filter node, not to original source node, of course. Therefore we
need to specify filter node name and use it.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-id: 20191001131409.14202-6-vsementsov@virtuozzo.com
Reviewed-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2019-10-01 15:14:09 +02:00
|
|
|
|
BlockCopyState *block_copy_state_new(BdrvChild *source, BdrvChild *target,
|
2019-10-01 15:14:07 +02:00
|
|
|
|
int64_t cluster_size,
|
|
|
|
|
BdrvRequestFlags write_flags, Error **errp)
|
2019-09-20 16:20:48 +02:00
|
|
|
|
{
|
|
|
|
|
BlockCopyState *s;
|
|
|
|
|
BdrvDirtyBitmap *copy_bitmap;
|
|
|
|
|
|
block/backup: use backup-top instead of write notifiers
Drop write notifiers and use filter node instead.
= Changes =
1. Add filter-node-name argument for backup qmp api. We have to do it
in this commit, as 257 needs to be fixed.
2. There are no more write notifiers here, so is_write_notifier
parameter is dropped from block-copy paths.
3. To sync with in-flight requests at job finish we now have drained
removing of the filter, we don't need rw-lock.
4. Block-copy is now using BdrvChildren instead of BlockBackends
5. As backup-top owns these children, we also move block-copy state
into backup-top's ownership.
= Iotest changes =
56: op-blocker doesn't shoot now, as we set it on source, but then
check on filter, when trying to start second backup.
To keep the test we instead can catch another collision: both jobs will
get 'drive0' job-id, as job-id parameter is unspecified. To prevent
interleaving with file-posix locks (as they are dependent on config)
let's use another target for second backup.
Also, it's obvious now that we'd like to drop this op-blocker at all
and add a test-case for two backups from one node (to different
destinations) actually works. But not in these series.
141: Output changed: prepatch, "Node is in use" comes from bdrv_has_blk
check inside qmp_blockdev_del. But we've dropped block-copy blk
objects, so no more blk objects on source bs (job blk is on backup-top
filter bs). New message is from op-blocker, which is the next check in
qmp_blockdev_add.
257: The test wants to emulate guest write during backup. They should
go to filter node, not to original source node, of course. Therefore we
need to specify filter node name and use it.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-id: 20191001131409.14202-6-vsementsov@virtuozzo.com
Reviewed-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2019-10-01 15:14:09 +02:00
|
|
|
|
copy_bitmap = bdrv_create_dirty_bitmap(source->bs, cluster_size, NULL,
|
|
|
|
|
errp);
|
2019-09-20 16:20:48 +02:00
|
|
|
|
if (!copy_bitmap) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
bdrv_disable_dirty_bitmap(copy_bitmap);
|
|
|
|
|
|
|
|
|
|
s = g_new(BlockCopyState, 1);
|
|
|
|
|
*s = (BlockCopyState) {
|
block/backup: use backup-top instead of write notifiers
Drop write notifiers and use filter node instead.
= Changes =
1. Add filter-node-name argument for backup qmp api. We have to do it
in this commit, as 257 needs to be fixed.
2. There are no more write notifiers here, so is_write_notifier
parameter is dropped from block-copy paths.
3. To sync with in-flight requests at job finish we now have drained
removing of the filter, we don't need rw-lock.
4. Block-copy is now using BdrvChildren instead of BlockBackends
5. As backup-top owns these children, we also move block-copy state
into backup-top's ownership.
= Iotest changes =
56: op-blocker doesn't shoot now, as we set it on source, but then
check on filter, when trying to start second backup.
To keep the test we instead can catch another collision: both jobs will
get 'drive0' job-id, as job-id parameter is unspecified. To prevent
interleaving with file-posix locks (as they are dependent on config)
let's use another target for second backup.
Also, it's obvious now that we'd like to drop this op-blocker at all
and add a test-case for two backups from one node (to different
destinations) actually works. But not in these series.
141: Output changed: prepatch, "Node is in use" comes from bdrv_has_blk
check inside qmp_blockdev_del. But we've dropped block-copy blk
objects, so no more blk objects on source bs (job blk is on backup-top
filter bs). New message is from op-blocker, which is the next check in
qmp_blockdev_add.
257: The test wants to emulate guest write during backup. They should
go to filter node, not to original source node, of course. Therefore we
need to specify filter node name and use it.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-id: 20191001131409.14202-6-vsementsov@virtuozzo.com
Reviewed-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2019-10-01 15:14:09 +02:00
|
|
|
|
.source = source,
|
|
|
|
|
.target = target,
|
2019-09-20 16:20:48 +02:00
|
|
|
|
.copy_bitmap = copy_bitmap,
|
|
|
|
|
.cluster_size = cluster_size,
|
|
|
|
|
.len = bdrv_dirty_bitmap_size(copy_bitmap),
|
|
|
|
|
.write_flags = write_flags,
|
2019-10-22 13:18:04 +02:00
|
|
|
|
.mem = shres_create(BLOCK_COPY_MAX_MEM),
|
2019-09-20 16:20:48 +02:00
|
|
|
|
};
|
|
|
|
|
|
2020-03-11 11:29:58 +01:00
|
|
|
|
if (block_copy_max_transfer(source, target) < cluster_size) {
|
2019-10-22 13:18:05 +02:00
|
|
|
|
/*
|
|
|
|
|
* copy_range does not respect max_transfer. We don't want to bother
|
|
|
|
|
* with requests smaller than block-copy cluster size, so fallback to
|
|
|
|
|
* buffered copying (read and write respect max_transfer on their
|
|
|
|
|
* behalf).
|
|
|
|
|
*/
|
|
|
|
|
s->use_copy_range = false;
|
|
|
|
|
s->copy_size = cluster_size;
|
|
|
|
|
} else if (write_flags & BDRV_REQ_WRITE_COMPRESSED) {
|
2019-10-29 16:09:34 +01:00
|
|
|
|
/* Compression supports only cluster-size writes and no copy-range. */
|
2019-10-22 13:18:05 +02:00
|
|
|
|
s->use_copy_range = false;
|
2019-10-29 16:09:34 +01:00
|
|
|
|
s->copy_size = cluster_size;
|
2019-10-22 13:18:05 +02:00
|
|
|
|
} else {
|
|
|
|
|
/*
|
2020-03-11 11:29:58 +01:00
|
|
|
|
* We enable copy-range, but keep small copy_size, until first
|
|
|
|
|
* successful copy_range (look at block_copy_do_copy).
|
2019-10-22 13:18:05 +02:00
|
|
|
|
*/
|
|
|
|
|
s->use_copy_range = true;
|
2020-03-11 11:29:58 +01:00
|
|
|
|
s->copy_size = MAX(s->cluster_size, BLOCK_COPY_MAX_BUFFER);
|
2019-10-22 13:18:05 +02:00
|
|
|
|
}
|
2019-09-20 16:20:48 +02:00
|
|
|
|
|
2020-04-29 15:08:43 +02:00
|
|
|
|
QLIST_INIT(&s->tasks);
|
2019-10-01 15:14:05 +02:00
|
|
|
|
|
2019-09-20 16:20:48 +02:00
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
block/block-copy: fix progress calculation
Assume we have two regions, A and B, and region B is in-flight now,
region A is not yet touched, but it is unallocated and should be
skipped.
Correspondingly, as progress we have
total = A + B
current = 0
If we reset unallocated region A and call progress_reset_callback,
it will calculate 0 bytes dirty in the bitmap and call
job_progress_set_remaining, which will set
total = current + 0 = 0 + 0 = 0
So, B bytes are actually removed from total accounting. When job
finishes we'll have
total = 0
current = B
, which doesn't sound good.
This is because we didn't considered in-flight bytes, actually when
calculating remaining, we should have set (in_flight + dirty_bytes)
as remaining, not only dirty_bytes.
To fix it, let's refactor progress calculation, moving it to block-copy
itself instead of fixing callback. And, of course, track in_flight
bytes count.
We still have to keep one callback, to maintain backup job bytes_read
calculation, but it will go on soon, when we turn the whole backup
process into one block_copy call.
Cc: qemu-stable@nongnu.org
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
Message-Id: <20200311103004.7649-3-vsementsov@virtuozzo.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2020-03-11 11:29:57 +01:00
|
|
|
|
void block_copy_set_progress_callback(
|
2019-10-01 15:14:07 +02:00
|
|
|
|
BlockCopyState *s,
|
|
|
|
|
ProgressBytesCallbackFunc progress_bytes_callback,
|
|
|
|
|
void *progress_opaque)
|
|
|
|
|
{
|
|
|
|
|
s->progress_bytes_callback = progress_bytes_callback;
|
|
|
|
|
s->progress_opaque = progress_opaque;
|
|
|
|
|
}
|
|
|
|
|
|
block/block-copy: fix progress calculation
Assume we have two regions, A and B, and region B is in-flight now,
region A is not yet touched, but it is unallocated and should be
skipped.
Correspondingly, as progress we have
total = A + B
current = 0
If we reset unallocated region A and call progress_reset_callback,
it will calculate 0 bytes dirty in the bitmap and call
job_progress_set_remaining, which will set
total = current + 0 = 0 + 0 = 0
So, B bytes are actually removed from total accounting. When job
finishes we'll have
total = 0
current = B
, which doesn't sound good.
This is because we didn't considered in-flight bytes, actually when
calculating remaining, we should have set (in_flight + dirty_bytes)
as remaining, not only dirty_bytes.
To fix it, let's refactor progress calculation, moving it to block-copy
itself instead of fixing callback. And, of course, track in_flight
bytes count.
We still have to keep one callback, to maintain backup job bytes_read
calculation, but it will go on soon, when we turn the whole backup
process into one block_copy call.
Cc: qemu-stable@nongnu.org
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
Message-Id: <20200311103004.7649-3-vsementsov@virtuozzo.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2020-03-11 11:29:57 +01:00
|
|
|
|
void block_copy_set_progress_meter(BlockCopyState *s, ProgressMeter *pm)
|
|
|
|
|
{
|
|
|
|
|
s->progress = pm;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-29 15:08:47 +02:00
|
|
|
|
/*
|
|
|
|
|
* Takes ownership of @task
|
|
|
|
|
*
|
|
|
|
|
* If pool is NULL directly run the task, otherwise schedule it into the pool.
|
|
|
|
|
*
|
|
|
|
|
* Returns: task.func return code if pool is NULL
|
|
|
|
|
* otherwise -ECANCELED if pool status is bad
|
|
|
|
|
* otherwise 0 (successfully scheduled)
|
|
|
|
|
*/
|
|
|
|
|
static coroutine_fn int block_copy_task_run(AioTaskPool *pool,
|
|
|
|
|
BlockCopyTask *task)
|
|
|
|
|
{
|
|
|
|
|
if (!pool) {
|
|
|
|
|
int ret = task->task.func(&task->task);
|
|
|
|
|
|
|
|
|
|
g_free(task);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
aio_task_pool_wait_slot(pool);
|
|
|
|
|
if (aio_task_pool_status(pool) < 0) {
|
|
|
|
|
co_put_to_shres(task->s->mem, task->bytes);
|
|
|
|
|
block_copy_task_end(task, -ECANCELED);
|
|
|
|
|
g_free(task);
|
|
|
|
|
return -ECANCELED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
aio_task_pool_start_task(pool, &task->task);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-20 16:20:48 +02:00
|
|
|
|
/*
|
2019-10-22 13:18:02 +02:00
|
|
|
|
* block_copy_do_copy
|
|
|
|
|
*
|
2020-03-11 11:30:01 +01:00
|
|
|
|
* Do copy of cluster-aligned chunk. Requested region is allowed to exceed
|
|
|
|
|
* s->len only to cover last cluster when s->len is not aligned to clusters.
|
2019-10-22 13:18:02 +02:00
|
|
|
|
*
|
|
|
|
|
* No sync here: nor bitmap neighter intersecting requests handling, only copy.
|
|
|
|
|
*
|
|
|
|
|
* Returns 0 on success.
|
2019-09-20 16:20:48 +02:00
|
|
|
|
*/
|
2019-10-22 13:18:02 +02:00
|
|
|
|
static int coroutine_fn block_copy_do_copy(BlockCopyState *s,
|
2020-03-11 11:30:02 +01:00
|
|
|
|
int64_t offset, int64_t bytes,
|
2020-03-11 11:29:59 +01:00
|
|
|
|
bool zeroes, bool *error_is_read)
|
2019-09-20 16:20:48 +02:00
|
|
|
|
{
|
|
|
|
|
int ret;
|
2020-03-11 11:30:02 +01:00
|
|
|
|
int64_t nbytes = MIN(offset + bytes, s->len) - offset;
|
2019-10-22 13:18:02 +02:00
|
|
|
|
void *bounce_buffer = NULL;
|
2019-09-20 16:20:48 +02:00
|
|
|
|
|
2020-03-11 11:30:02 +01:00
|
|
|
|
assert(offset >= 0 && bytes > 0 && INT64_MAX - offset >= bytes);
|
|
|
|
|
assert(QEMU_IS_ALIGNED(offset, s->cluster_size));
|
2020-03-11 11:30:01 +01:00
|
|
|
|
assert(QEMU_IS_ALIGNED(bytes, s->cluster_size));
|
2020-03-11 11:30:02 +01:00
|
|
|
|
assert(offset < s->len);
|
|
|
|
|
assert(offset + bytes <= s->len ||
|
|
|
|
|
offset + bytes == QEMU_ALIGN_UP(s->len, s->cluster_size));
|
2020-03-11 11:30:01 +01:00
|
|
|
|
assert(nbytes < INT_MAX);
|
2019-10-22 13:18:02 +02:00
|
|
|
|
|
2020-03-11 11:29:59 +01:00
|
|
|
|
if (zeroes) {
|
2020-03-11 11:30:02 +01:00
|
|
|
|
ret = bdrv_co_pwrite_zeroes(s->target, offset, nbytes, s->write_flags &
|
2020-03-11 11:29:59 +01:00
|
|
|
|
~BDRV_REQ_WRITE_COMPRESSED);
|
|
|
|
|
if (ret < 0) {
|
2020-03-11 11:30:02 +01:00
|
|
|
|
trace_block_copy_write_zeroes_fail(s, offset, ret);
|
2020-05-07 14:11:29 +02:00
|
|
|
|
*error_is_read = false;
|
2020-03-11 11:29:59 +01:00
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-22 13:18:02 +02:00
|
|
|
|
if (s->use_copy_range) {
|
2020-03-11 11:30:02 +01:00
|
|
|
|
ret = bdrv_co_copy_range(s->source, offset, s->target, offset, nbytes,
|
2019-10-22 13:18:02 +02:00
|
|
|
|
0, s->write_flags);
|
|
|
|
|
if (ret < 0) {
|
2020-03-11 11:30:02 +01:00
|
|
|
|
trace_block_copy_copy_range_fail(s, offset, ret);
|
2019-10-22 13:18:02 +02:00
|
|
|
|
s->use_copy_range = false;
|
2019-10-22 13:18:05 +02:00
|
|
|
|
s->copy_size = MAX(s->cluster_size, BLOCK_COPY_MAX_BUFFER);
|
2019-10-22 13:18:02 +02:00
|
|
|
|
/* Fallback to read+write with allocated buffer */
|
|
|
|
|
} else {
|
2020-03-11 11:29:58 +01:00
|
|
|
|
if (s->use_copy_range) {
|
|
|
|
|
/*
|
|
|
|
|
* Successful copy-range. Now increase copy_size. copy_range
|
|
|
|
|
* does not respect max_transfer (it's a TODO), so we factor
|
|
|
|
|
* that in here.
|
|
|
|
|
*
|
|
|
|
|
* Note: we double-check s->use_copy_range for the case when
|
|
|
|
|
* parallel block-copy request unsets it during previous
|
|
|
|
|
* bdrv_co_copy_range call.
|
|
|
|
|
*/
|
|
|
|
|
s->copy_size =
|
|
|
|
|
MIN(MAX(s->cluster_size, BLOCK_COPY_MAX_COPY_RANGE),
|
|
|
|
|
QEMU_ALIGN_DOWN(block_copy_max_transfer(s->source,
|
|
|
|
|
s->target),
|
|
|
|
|
s->cluster_size));
|
|
|
|
|
}
|
2019-10-22 13:18:02 +02:00
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-22 13:18:05 +02:00
|
|
|
|
/*
|
|
|
|
|
* In case of failed copy_range request above, we may proceed with buffered
|
|
|
|
|
* request larger than BLOCK_COPY_MAX_BUFFER. Still, further requests will
|
2020-03-11 11:29:58 +01:00
|
|
|
|
* be properly limited, so don't care too much. Moreover the most likely
|
|
|
|
|
* case (copy_range is unsupported for the configuration, so the very first
|
|
|
|
|
* copy_range request fails) is handled by setting large copy_size only
|
|
|
|
|
* after first successful copy_range.
|
2019-10-22 13:18:05 +02:00
|
|
|
|
*/
|
|
|
|
|
|
2019-10-22 13:18:02 +02:00
|
|
|
|
bounce_buffer = qemu_blockalign(s->source->bs, nbytes);
|
2019-09-20 16:20:48 +02:00
|
|
|
|
|
2020-03-11 11:30:02 +01:00
|
|
|
|
ret = bdrv_co_pread(s->source, offset, nbytes, bounce_buffer, 0);
|
2019-09-20 16:20:48 +02:00
|
|
|
|
if (ret < 0) {
|
2020-03-11 11:30:02 +01:00
|
|
|
|
trace_block_copy_read_fail(s, offset, ret);
|
2020-05-07 14:11:29 +02:00
|
|
|
|
*error_is_read = true;
|
2019-10-22 13:18:02 +02:00
|
|
|
|
goto out;
|
2019-09-20 16:20:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-11 11:30:02 +01:00
|
|
|
|
ret = bdrv_co_pwrite(s->target, offset, nbytes, bounce_buffer,
|
block/backup: use backup-top instead of write notifiers
Drop write notifiers and use filter node instead.
= Changes =
1. Add filter-node-name argument for backup qmp api. We have to do it
in this commit, as 257 needs to be fixed.
2. There are no more write notifiers here, so is_write_notifier
parameter is dropped from block-copy paths.
3. To sync with in-flight requests at job finish we now have drained
removing of the filter, we don't need rw-lock.
4. Block-copy is now using BdrvChildren instead of BlockBackends
5. As backup-top owns these children, we also move block-copy state
into backup-top's ownership.
= Iotest changes =
56: op-blocker doesn't shoot now, as we set it on source, but then
check on filter, when trying to start second backup.
To keep the test we instead can catch another collision: both jobs will
get 'drive0' job-id, as job-id parameter is unspecified. To prevent
interleaving with file-posix locks (as they are dependent on config)
let's use another target for second backup.
Also, it's obvious now that we'd like to drop this op-blocker at all
and add a test-case for two backups from one node (to different
destinations) actually works. But not in these series.
141: Output changed: prepatch, "Node is in use" comes from bdrv_has_blk
check inside qmp_blockdev_del. But we've dropped block-copy blk
objects, so no more blk objects on source bs (job blk is on backup-top
filter bs). New message is from op-blocker, which is the next check in
qmp_blockdev_add.
257: The test wants to emulate guest write during backup. They should
go to filter node, not to original source node, of course. Therefore we
need to specify filter node name and use it.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-id: 20191001131409.14202-6-vsementsov@virtuozzo.com
Reviewed-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2019-10-01 15:14:09 +02:00
|
|
|
|
s->write_flags);
|
2019-09-20 16:20:48 +02:00
|
|
|
|
if (ret < 0) {
|
2020-03-11 11:30:02 +01:00
|
|
|
|
trace_block_copy_write_fail(s, offset, ret);
|
2020-05-07 14:11:29 +02:00
|
|
|
|
*error_is_read = false;
|
2019-10-22 13:18:02 +02:00
|
|
|
|
goto out;
|
2019-09-20 16:20:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-22 13:18:02 +02:00
|
|
|
|
out:
|
2019-10-22 13:18:00 +02:00
|
|
|
|
qemu_vfree(bounce_buffer);
|
|
|
|
|
|
2019-09-20 16:20:48 +02:00
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-29 15:08:47 +02:00
|
|
|
|
static coroutine_fn int block_copy_task_entry(AioTask *task)
|
|
|
|
|
{
|
|
|
|
|
BlockCopyTask *t = container_of(task, BlockCopyTask, task);
|
2020-05-07 14:11:28 +02:00
|
|
|
|
bool error_is_read = false;
|
2020-04-29 15:08:47 +02:00
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
ret = block_copy_do_copy(t->s, t->offset, t->bytes, t->zeroes,
|
|
|
|
|
&error_is_read);
|
|
|
|
|
if (ret < 0 && !t->call_state->failed) {
|
|
|
|
|
t->call_state->failed = true;
|
|
|
|
|
t->call_state->error_is_read = error_is_read;
|
|
|
|
|
} else {
|
|
|
|
|
progress_work_done(t->s->progress, t->bytes);
|
|
|
|
|
t->s->progress_bytes_callback(t->bytes, t->s->progress_opaque);
|
|
|
|
|
}
|
|
|
|
|
co_put_to_shres(t->s->mem, t->bytes);
|
|
|
|
|
block_copy_task_end(t, ret);
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-11 11:29:59 +01:00
|
|
|
|
static int block_copy_block_status(BlockCopyState *s, int64_t offset,
|
|
|
|
|
int64_t bytes, int64_t *pnum)
|
|
|
|
|
{
|
|
|
|
|
int64_t num;
|
|
|
|
|
BlockDriverState *base;
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
if (s->skip_unallocated && s->source->bs->backing) {
|
|
|
|
|
base = s->source->bs->backing->bs;
|
|
|
|
|
} else {
|
|
|
|
|
base = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ret = bdrv_block_status_above(s->source->bs, base, offset, bytes, &num,
|
|
|
|
|
NULL, NULL);
|
|
|
|
|
if (ret < 0 || num < s->cluster_size) {
|
|
|
|
|
/*
|
|
|
|
|
* On error or if failed to obtain large enough chunk just fallback to
|
|
|
|
|
* copy one cluster.
|
|
|
|
|
*/
|
|
|
|
|
num = s->cluster_size;
|
|
|
|
|
ret = BDRV_BLOCK_ALLOCATED | BDRV_BLOCK_DATA;
|
|
|
|
|
} else if (offset + num == s->len) {
|
|
|
|
|
num = QEMU_ALIGN_UP(num, s->cluster_size);
|
|
|
|
|
} else {
|
|
|
|
|
num = QEMU_ALIGN_DOWN(num, s->cluster_size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*pnum = num;
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-20 16:20:48 +02:00
|
|
|
|
/*
|
|
|
|
|
* Check if the cluster starting at offset is allocated or not.
|
|
|
|
|
* return via pnum the number of contiguous clusters sharing this allocation.
|
|
|
|
|
*/
|
|
|
|
|
static int block_copy_is_cluster_allocated(BlockCopyState *s, int64_t offset,
|
|
|
|
|
int64_t *pnum)
|
|
|
|
|
{
|
block/backup: use backup-top instead of write notifiers
Drop write notifiers and use filter node instead.
= Changes =
1. Add filter-node-name argument for backup qmp api. We have to do it
in this commit, as 257 needs to be fixed.
2. There are no more write notifiers here, so is_write_notifier
parameter is dropped from block-copy paths.
3. To sync with in-flight requests at job finish we now have drained
removing of the filter, we don't need rw-lock.
4. Block-copy is now using BdrvChildren instead of BlockBackends
5. As backup-top owns these children, we also move block-copy state
into backup-top's ownership.
= Iotest changes =
56: op-blocker doesn't shoot now, as we set it on source, but then
check on filter, when trying to start second backup.
To keep the test we instead can catch another collision: both jobs will
get 'drive0' job-id, as job-id parameter is unspecified. To prevent
interleaving with file-posix locks (as they are dependent on config)
let's use another target for second backup.
Also, it's obvious now that we'd like to drop this op-blocker at all
and add a test-case for two backups from one node (to different
destinations) actually works. But not in these series.
141: Output changed: prepatch, "Node is in use" comes from bdrv_has_blk
check inside qmp_blockdev_del. But we've dropped block-copy blk
objects, so no more blk objects on source bs (job blk is on backup-top
filter bs). New message is from op-blocker, which is the next check in
qmp_blockdev_add.
257: The test wants to emulate guest write during backup. They should
go to filter node, not to original source node, of course. Therefore we
need to specify filter node name and use it.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-id: 20191001131409.14202-6-vsementsov@virtuozzo.com
Reviewed-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2019-10-01 15:14:09 +02:00
|
|
|
|
BlockDriverState *bs = s->source->bs;
|
2019-09-20 16:20:48 +02:00
|
|
|
|
int64_t count, total_count = 0;
|
|
|
|
|
int64_t bytes = s->len - offset;
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
assert(QEMU_IS_ALIGNED(offset, s->cluster_size));
|
|
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
|
ret = bdrv_is_allocated(bs, offset, bytes, &count);
|
|
|
|
|
if (ret < 0) {
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
total_count += count;
|
|
|
|
|
|
|
|
|
|
if (ret || count == 0) {
|
|
|
|
|
/*
|
|
|
|
|
* ret: partial segment(s) are considered allocated.
|
|
|
|
|
* otherwise: unallocated tail is treated as an entire segment.
|
|
|
|
|
*/
|
|
|
|
|
*pnum = DIV_ROUND_UP(total_count, s->cluster_size);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Unallocated segment(s) with uncertain following segment(s) */
|
|
|
|
|
if (total_count >= s->cluster_size) {
|
|
|
|
|
*pnum = total_count / s->cluster_size;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
offset += count;
|
|
|
|
|
bytes -= count;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Reset bits in copy_bitmap starting at offset if they represent unallocated
|
|
|
|
|
* data in the image. May reset subsequent contiguous bits.
|
|
|
|
|
* @return 0 when the cluster at @offset was unallocated,
|
|
|
|
|
* 1 otherwise, and -ret on error.
|
|
|
|
|
*/
|
|
|
|
|
int64_t block_copy_reset_unallocated(BlockCopyState *s,
|
|
|
|
|
int64_t offset, int64_t *count)
|
|
|
|
|
{
|
|
|
|
|
int ret;
|
|
|
|
|
int64_t clusters, bytes;
|
|
|
|
|
|
|
|
|
|
ret = block_copy_is_cluster_allocated(s, offset, &clusters);
|
|
|
|
|
if (ret < 0) {
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bytes = clusters * s->cluster_size;
|
|
|
|
|
|
|
|
|
|
if (!ret) {
|
|
|
|
|
bdrv_reset_dirty_bitmap(s->copy_bitmap, offset, bytes);
|
block/block-copy: fix progress calculation
Assume we have two regions, A and B, and region B is in-flight now,
region A is not yet touched, but it is unallocated and should be
skipped.
Correspondingly, as progress we have
total = A + B
current = 0
If we reset unallocated region A and call progress_reset_callback,
it will calculate 0 bytes dirty in the bitmap and call
job_progress_set_remaining, which will set
total = current + 0 = 0 + 0 = 0
So, B bytes are actually removed from total accounting. When job
finishes we'll have
total = 0
current = B
, which doesn't sound good.
This is because we didn't considered in-flight bytes, actually when
calculating remaining, we should have set (in_flight + dirty_bytes)
as remaining, not only dirty_bytes.
To fix it, let's refactor progress calculation, moving it to block-copy
itself instead of fixing callback. And, of course, track in_flight
bytes count.
We still have to keep one callback, to maintain backup job bytes_read
calculation, but it will go on soon, when we turn the whole backup
process into one block_copy call.
Cc: qemu-stable@nongnu.org
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
Message-Id: <20200311103004.7649-3-vsementsov@virtuozzo.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2020-03-11 11:29:57 +01:00
|
|
|
|
progress_set_remaining(s->progress,
|
|
|
|
|
bdrv_get_dirty_count(s->copy_bitmap) +
|
|
|
|
|
s->in_flight_bytes);
|
2019-09-20 16:20:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*count = bytes;
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-11 11:30:03 +01:00
|
|
|
|
/*
|
|
|
|
|
* block_copy_dirty_clusters
|
|
|
|
|
*
|
|
|
|
|
* Copy dirty clusters in @offset/@bytes range.
|
|
|
|
|
* Returns 1 if dirty clusters found and successfully copied, 0 if no dirty
|
|
|
|
|
* clusters found and -errno on failure.
|
|
|
|
|
*/
|
|
|
|
|
static int coroutine_fn block_copy_dirty_clusters(BlockCopyState *s,
|
|
|
|
|
int64_t offset, int64_t bytes,
|
|
|
|
|
bool *error_is_read)
|
2019-09-20 16:20:48 +02:00
|
|
|
|
{
|
|
|
|
|
int ret = 0;
|
2020-03-11 11:30:03 +01:00
|
|
|
|
bool found_dirty = false;
|
2020-04-29 15:08:46 +02:00
|
|
|
|
int64_t end = offset + bytes;
|
2020-04-29 15:08:47 +02:00
|
|
|
|
AioTaskPool *aio = NULL;
|
|
|
|
|
BlockCopyCallState call_state = {false, false};
|
2019-09-20 16:20:48 +02:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* block_copy() user is responsible for keeping source and target in same
|
|
|
|
|
* aio context
|
|
|
|
|
*/
|
block/backup: use backup-top instead of write notifiers
Drop write notifiers and use filter node instead.
= Changes =
1. Add filter-node-name argument for backup qmp api. We have to do it
in this commit, as 257 needs to be fixed.
2. There are no more write notifiers here, so is_write_notifier
parameter is dropped from block-copy paths.
3. To sync with in-flight requests at job finish we now have drained
removing of the filter, we don't need rw-lock.
4. Block-copy is now using BdrvChildren instead of BlockBackends
5. As backup-top owns these children, we also move block-copy state
into backup-top's ownership.
= Iotest changes =
56: op-blocker doesn't shoot now, as we set it on source, but then
check on filter, when trying to start second backup.
To keep the test we instead can catch another collision: both jobs will
get 'drive0' job-id, as job-id parameter is unspecified. To prevent
interleaving with file-posix locks (as they are dependent on config)
let's use another target for second backup.
Also, it's obvious now that we'd like to drop this op-blocker at all
and add a test-case for two backups from one node (to different
destinations) actually works. But not in these series.
141: Output changed: prepatch, "Node is in use" comes from bdrv_has_blk
check inside qmp_blockdev_del. But we've dropped block-copy blk
objects, so no more blk objects on source bs (job blk is on backup-top
filter bs). New message is from op-blocker, which is the next check in
qmp_blockdev_add.
257: The test wants to emulate guest write during backup. They should
go to filter node, not to original source node, of course. Therefore we
need to specify filter node name and use it.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-id: 20191001131409.14202-6-vsementsov@virtuozzo.com
Reviewed-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2019-10-01 15:14:09 +02:00
|
|
|
|
assert(bdrv_get_aio_context(s->source->bs) ==
|
|
|
|
|
bdrv_get_aio_context(s->target->bs));
|
2019-09-20 16:20:48 +02:00
|
|
|
|
|
2020-03-11 11:30:02 +01:00
|
|
|
|
assert(QEMU_IS_ALIGNED(offset, s->cluster_size));
|
2020-03-11 11:30:01 +01:00
|
|
|
|
assert(QEMU_IS_ALIGNED(bytes, s->cluster_size));
|
2019-09-20 16:20:48 +02:00
|
|
|
|
|
2020-04-29 15:08:47 +02:00
|
|
|
|
while (bytes && aio_task_pool_status(aio) == 0) {
|
|
|
|
|
BlockCopyTask *task;
|
2020-04-29 15:08:46 +02:00
|
|
|
|
int64_t status_bytes;
|
2019-09-20 16:20:48 +02:00
|
|
|
|
|
2020-04-29 15:08:47 +02:00
|
|
|
|
task = block_copy_task_create(s, &call_state, offset, bytes);
|
2020-04-29 15:08:46 +02:00
|
|
|
|
if (!task) {
|
|
|
|
|
/* No more dirty bits in the bitmap */
|
|
|
|
|
trace_block_copy_skip_range(s, offset, bytes);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (task->offset > offset) {
|
|
|
|
|
trace_block_copy_skip_range(s, offset, task->offset - offset);
|
2019-09-20 16:20:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-11 11:30:03 +01:00
|
|
|
|
found_dirty = true;
|
|
|
|
|
|
2020-04-29 15:08:46 +02:00
|
|
|
|
ret = block_copy_block_status(s, task->offset, task->bytes,
|
|
|
|
|
&status_bytes);
|
2020-03-11 11:30:03 +01:00
|
|
|
|
assert(ret >= 0); /* never fail */
|
2020-04-29 15:08:46 +02:00
|
|
|
|
if (status_bytes < task->bytes) {
|
|
|
|
|
block_copy_task_shrink(task, status_bytes);
|
|
|
|
|
}
|
2020-03-11 11:29:59 +01:00
|
|
|
|
if (s->skip_unallocated && !(ret & BDRV_BLOCK_ALLOCATED)) {
|
2020-04-29 15:08:45 +02:00
|
|
|
|
block_copy_task_end(task, 0);
|
2020-03-11 11:29:59 +01:00
|
|
|
|
progress_set_remaining(s->progress,
|
|
|
|
|
bdrv_get_dirty_count(s->copy_bitmap) +
|
|
|
|
|
s->in_flight_bytes);
|
2020-04-29 15:08:46 +02:00
|
|
|
|
trace_block_copy_skip_range(s, task->offset, task->bytes);
|
|
|
|
|
offset = task_end(task);
|
|
|
|
|
bytes = end - offset;
|
2020-05-07 20:38:00 +02:00
|
|
|
|
g_free(task);
|
2020-03-11 11:29:59 +01:00
|
|
|
|
continue;
|
2019-09-20 16:20:48 +02:00
|
|
|
|
}
|
2020-04-29 15:08:47 +02:00
|
|
|
|
task->zeroes = ret & BDRV_BLOCK_ZERO;
|
2019-09-20 16:20:48 +02:00
|
|
|
|
|
2020-04-29 15:08:46 +02:00
|
|
|
|
trace_block_copy_process(s, task->offset);
|
2019-09-20 16:20:48 +02:00
|
|
|
|
|
2020-04-29 15:08:46 +02:00
|
|
|
|
co_get_from_shres(s->mem, task->bytes);
|
2019-09-20 16:20:48 +02:00
|
|
|
|
|
2020-04-29 15:08:46 +02:00
|
|
|
|
offset = task_end(task);
|
|
|
|
|
bytes = end - offset;
|
2020-04-29 15:08:47 +02:00
|
|
|
|
|
|
|
|
|
if (!aio && bytes) {
|
|
|
|
|
aio = aio_task_pool_new(BLOCK_COPY_MAX_WORKERS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ret = block_copy_task_run(aio, task);
|
|
|
|
|
if (ret < 0) {
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
if (aio) {
|
|
|
|
|
aio_task_pool_wait_all(aio);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* We are not really interested in -ECANCELED returned from
|
|
|
|
|
* block_copy_task_run. If it fails, it means some task already failed
|
|
|
|
|
* for real reason, let's return first failure.
|
|
|
|
|
* Still, assert that we don't rewrite failure by success.
|
2020-05-26 20:13:47 +02:00
|
|
|
|
*
|
|
|
|
|
* Note: ret may be positive here because of block-status result.
|
2020-04-29 15:08:47 +02:00
|
|
|
|
*/
|
2020-05-26 20:13:47 +02:00
|
|
|
|
assert(ret >= 0 || aio_task_pool_status(aio) < 0);
|
2020-04-29 15:08:47 +02:00
|
|
|
|
ret = aio_task_pool_status(aio);
|
|
|
|
|
|
|
|
|
|
aio_task_pool_free(aio);
|
|
|
|
|
}
|
|
|
|
|
if (error_is_read && ret < 0) {
|
|
|
|
|
*error_is_read = call_state.error_is_read;
|
2019-09-20 16:20:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-29 15:08:47 +02:00
|
|
|
|
return ret < 0 ? ret : found_dirty;
|
2020-03-11 11:30:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* block_copy
|
|
|
|
|
*
|
|
|
|
|
* Copy requested region, accordingly to dirty bitmap.
|
|
|
|
|
* Collaborate with parallel block_copy requests: if they succeed it will help
|
|
|
|
|
* us. If they fail, we will retry not-copied regions. So, if we return error,
|
|
|
|
|
* it means that some I/O operation failed in context of _this_ block_copy call,
|
|
|
|
|
* not some parallel operation.
|
|
|
|
|
*/
|
|
|
|
|
int coroutine_fn block_copy(BlockCopyState *s, int64_t offset, int64_t bytes,
|
|
|
|
|
bool *error_is_read)
|
|
|
|
|
{
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
ret = block_copy_dirty_clusters(s, offset, bytes, error_is_read);
|
|
|
|
|
|
|
|
|
|
if (ret == 0) {
|
|
|
|
|
ret = block_copy_wait_one(s, offset, bytes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* We retry in two cases:
|
|
|
|
|
* 1. Some progress done
|
|
|
|
|
* Something was copied, which means that there were yield points
|
|
|
|
|
* and some new dirty bits may have appeared (due to failed parallel
|
|
|
|
|
* block-copy requests).
|
|
|
|
|
* 2. We have waited for some intersecting block-copy request
|
|
|
|
|
* It may have failed and produced new dirty bits.
|
|
|
|
|
*/
|
|
|
|
|
} while (ret > 0);
|
2019-10-01 15:14:05 +02:00
|
|
|
|
|
2019-09-20 16:20:48 +02:00
|
|
|
|
return ret;
|
|
|
|
|
}
|
2020-03-11 11:30:04 +01:00
|
|
|
|
|
|
|
|
|
BdrvDirtyBitmap *block_copy_dirty_bitmap(BlockCopyState *s)
|
|
|
|
|
{
|
|
|
|
|
return s->copy_bitmap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void block_copy_set_skip_unallocated(BlockCopyState *s, bool skip)
|
|
|
|
|
{
|
|
|
|
|
s->skip_unallocated = skip;
|
|
|
|
|
}
|