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"
|
|
|
|
|
|
|
|
#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)
|
2019-09-20 16:20:48 +02:00
|
|
|
|
2019-10-01 15:14:05 +02:00
|
|
|
static void coroutine_fn block_copy_wait_inflight_reqs(BlockCopyState *s,
|
|
|
|
int64_t start,
|
|
|
|
int64_t end)
|
|
|
|
{
|
|
|
|
BlockCopyInFlightReq *req;
|
|
|
|
bool waited;
|
|
|
|
|
|
|
|
do {
|
|
|
|
waited = false;
|
|
|
|
QLIST_FOREACH(req, &s->inflight_reqs, list) {
|
|
|
|
if (end > req->start_byte && start < req->end_byte) {
|
|
|
|
qemu_co_queue_wait(&req->wait_queue, NULL);
|
|
|
|
waited = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (waited);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void block_copy_inflight_req_begin(BlockCopyState *s,
|
|
|
|
BlockCopyInFlightReq *req,
|
|
|
|
int64_t start, int64_t end)
|
|
|
|
{
|
|
|
|
req->start_byte = start;
|
|
|
|
req->end_byte = end;
|
|
|
|
qemu_co_queue_init(&req->wait_queue);
|
|
|
|
QLIST_INSERT_HEAD(&s->inflight_reqs, req, list);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void coroutine_fn block_copy_inflight_req_end(BlockCopyInFlightReq *req)
|
|
|
|
{
|
|
|
|
QLIST_REMOVE(req, list);
|
|
|
|
qemu_co_queue_restart_all(&req->wait_queue);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
uint32_t max_transfer =
|
2019-10-22 13:18:05 +02:00
|
|
|
MIN_NON_ZERO(INT_MAX,
|
2019-10-22 13:18:01 +02:00
|
|
|
MIN_NON_ZERO(source->bs->bl.max_transfer,
|
|
|
|
target->bs->bl.max_transfer));
|
2019-09-20 16:20:48 +02:00
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2019-10-22 13:18:05 +02:00
|
|
|
if (max_transfer < cluster_size) {
|
|
|
|
/*
|
|
|
|
* 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 {
|
|
|
|
/*
|
|
|
|
* copy_range does not respect max_transfer (it's a TODO), so we factor
|
|
|
|
* that in here.
|
|
|
|
*/
|
|
|
|
s->use_copy_range = true;
|
|
|
|
s->copy_size = MIN(MAX(cluster_size, BLOCK_COPY_MAX_COPY_RANGE),
|
|
|
|
QEMU_ALIGN_DOWN(max_transfer, cluster_size));
|
|
|
|
}
|
2019-09-20 16:20:48 +02:00
|
|
|
|
2019-10-01 15:14:05 +02:00
|
|
|
QLIST_INIT(&s->inflight_reqs);
|
|
|
|
|
2019-09-20 16:20:48 +02:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2019-10-01 15:14:07 +02:00
|
|
|
void block_copy_set_callbacks(
|
|
|
|
BlockCopyState *s,
|
|
|
|
ProgressBytesCallbackFunc progress_bytes_callback,
|
|
|
|
ProgressResetCallbackFunc progress_reset_callback,
|
|
|
|
void *progress_opaque)
|
|
|
|
{
|
|
|
|
s->progress_bytes_callback = progress_bytes_callback;
|
|
|
|
s->progress_reset_callback = progress_reset_callback;
|
|
|
|
s->progress_opaque = progress_opaque;
|
|
|
|
}
|
|
|
|
|
2019-09-20 16:20:48 +02:00
|
|
|
/*
|
2019-10-22 13:18:02 +02:00
|
|
|
* block_copy_do_copy
|
|
|
|
*
|
|
|
|
* Do copy of cluser-aligned chunk. @end is allowed to exceed s->len only to
|
|
|
|
* cover last cluster when s->len is not aligned to clusters.
|
|
|
|
*
|
|
|
|
* 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,
|
|
|
|
int64_t start, int64_t end,
|
|
|
|
bool *error_is_read)
|
2019-09-20 16:20:48 +02:00
|
|
|
{
|
|
|
|
int ret;
|
2019-10-22 13:18:02 +02:00
|
|
|
int nbytes = MIN(end, s->len) - start;
|
|
|
|
void *bounce_buffer = NULL;
|
2019-09-20 16:20:48 +02:00
|
|
|
|
|
|
|
assert(QEMU_IS_ALIGNED(start, s->cluster_size));
|
2019-10-22 13:18:02 +02:00
|
|
|
assert(QEMU_IS_ALIGNED(end, s->cluster_size));
|
|
|
|
assert(end < s->len || end == QEMU_ALIGN_UP(s->len, s->cluster_size));
|
|
|
|
|
|
|
|
if (s->use_copy_range) {
|
|
|
|
ret = bdrv_co_copy_range(s->source, start, s->target, start, nbytes,
|
|
|
|
0, s->write_flags);
|
|
|
|
if (ret < 0) {
|
|
|
|
trace_block_copy_copy_range_fail(s, start, ret);
|
|
|
|
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 {
|
|
|
|
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
|
|
|
|
* be properly limited, so don't care too much.
|
|
|
|
*/
|
|
|
|
|
2019-10-22 13:18:02 +02:00
|
|
|
bounce_buffer = qemu_blockalign(s->source->bs, nbytes);
|
2019-09-20 16:20:48 +02:00
|
|
|
|
2019-10-22 13:18:00 +02:00
|
|
|
ret = bdrv_co_pread(s->source, start, nbytes, bounce_buffer, 0);
|
2019-09-20 16:20:48 +02:00
|
|
|
if (ret < 0) {
|
2019-10-22 13:18:02 +02:00
|
|
|
trace_block_copy_read_fail(s, start, ret);
|
2019-09-20 16:20:48 +02:00
|
|
|
if (error_is_read) {
|
|
|
|
*error_is_read = true;
|
|
|
|
}
|
2019-10-22 13:18:02 +02:00
|
|
|
goto out;
|
2019-09-20 16:20:48 +02:00
|
|
|
}
|
|
|
|
|
2019-10-22 13:18:00 +02:00
|
|
|
ret = bdrv_co_pwrite(s->target, start, 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) {
|
2019-10-22 13:18:02 +02:00
|
|
|
trace_block_copy_write_fail(s, start, ret);
|
2019-09-20 16:20:48 +02:00
|
|
|
if (error_is_read) {
|
|
|
|
*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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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);
|
|
|
|
s->progress_reset_callback(s->progress_opaque);
|
|
|
|
}
|
|
|
|
|
|
|
|
*count = bytes;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int coroutine_fn block_copy(BlockCopyState *s,
|
|
|
|
int64_t start, uint64_t bytes,
|
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
|
|
|
bool *error_is_read)
|
2019-09-20 16:20:48 +02:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
int64_t end = bytes + start; /* bytes */
|
|
|
|
int64_t status_bytes;
|
2019-10-01 15:14:05 +02:00
|
|
|
BlockCopyInFlightReq req;
|
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
|
|
|
|
|
|
|
assert(QEMU_IS_ALIGNED(start, s->cluster_size));
|
|
|
|
assert(QEMU_IS_ALIGNED(end, s->cluster_size));
|
|
|
|
|
2019-10-01 15:14:05 +02:00
|
|
|
block_copy_wait_inflight_reqs(s, start, bytes);
|
|
|
|
block_copy_inflight_req_begin(s, &req, start, end);
|
|
|
|
|
2019-09-20 16:20:48 +02:00
|
|
|
while (start < end) {
|
2019-10-22 13:18:02 +02:00
|
|
|
int64_t next_zero, chunk_end;
|
2019-09-20 16:20:48 +02:00
|
|
|
|
|
|
|
if (!bdrv_dirty_bitmap_get(s->copy_bitmap, start)) {
|
|
|
|
trace_block_copy_skip(s, start);
|
|
|
|
start += s->cluster_size;
|
|
|
|
continue; /* already copied */
|
|
|
|
}
|
|
|
|
|
2019-10-22 13:18:05 +02:00
|
|
|
chunk_end = MIN(end, start + s->copy_size);
|
2019-10-22 13:18:02 +02:00
|
|
|
|
|
|
|
next_zero = bdrv_dirty_bitmap_next_zero(s->copy_bitmap, start,
|
|
|
|
chunk_end - start);
|
|
|
|
if (next_zero >= 0) {
|
|
|
|
assert(next_zero > start); /* start is dirty */
|
|
|
|
assert(next_zero < chunk_end); /* no need to do MIN() */
|
|
|
|
chunk_end = next_zero;
|
2019-09-20 16:20:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (s->skip_unallocated) {
|
|
|
|
ret = block_copy_reset_unallocated(s, start, &status_bytes);
|
|
|
|
if (ret == 0) {
|
|
|
|
trace_block_copy_skip_range(s, start, status_bytes);
|
|
|
|
start += status_bytes;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* Clamp to known allocated region */
|
2019-10-22 13:18:02 +02:00
|
|
|
chunk_end = MIN(chunk_end, start + status_bytes);
|
2019-09-20 16:20:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
trace_block_copy_process(s, start);
|
|
|
|
|
2019-10-22 13:18:02 +02:00
|
|
|
bdrv_reset_dirty_bitmap(s->copy_bitmap, start, chunk_end - start);
|
|
|
|
|
2019-10-22 13:18:04 +02:00
|
|
|
co_get_from_shres(s->mem, chunk_end - start);
|
2019-10-22 13:18:02 +02:00
|
|
|
ret = block_copy_do_copy(s, start, chunk_end, error_is_read);
|
2019-10-22 13:18:04 +02:00
|
|
|
co_put_to_shres(s->mem, chunk_end - start);
|
2019-09-20 16:20:48 +02:00
|
|
|
if (ret < 0) {
|
2019-10-22 13:18:02 +02:00
|
|
|
bdrv_set_dirty_bitmap(s->copy_bitmap, start, chunk_end - start);
|
2019-09-20 16:20:48 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-10-22 13:18:02 +02:00
|
|
|
s->progress_bytes_callback(chunk_end - start, s->progress_opaque);
|
|
|
|
start = chunk_end;
|
2019-09-20 16:20:48 +02:00
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
|
2019-10-01 15:14:05 +02:00
|
|
|
block_copy_inflight_req_end(&req);
|
|
|
|
|
2019-09-20 16:20:48 +02:00
|
|
|
return ret;
|
|
|
|
}
|