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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef BLOCK_COPY_H
|
|
|
|
#define BLOCK_COPY_H
|
|
|
|
|
|
|
|
#include "block/block.h"
|
2019-10-22 13:18:04 +02:00
|
|
|
#include "qemu/co-shared-resource.h"
|
2019-09-20 16:20:48 +02:00
|
|
|
|
2021-06-24 09:20:43 +02:00
|
|
|
/* All APIs are thread-safe */
|
|
|
|
|
2021-01-16 22:46:45 +01:00
|
|
|
typedef void (*BlockCopyAsyncCallbackFunc)(void *opaque);
|
2020-03-11 11:30:04 +01:00
|
|
|
typedef struct BlockCopyState BlockCopyState;
|
2021-01-16 22:46:45 +01:00
|
|
|
typedef struct BlockCopyCallState BlockCopyCallState;
|
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
|
|
|
BlockCopyState *block_copy_state_new(BdrvChild *source, BdrvChild *target,
|
qapi: backup: add perf.use-copy-range parameter
Experiments show, that copy_range is not always making things faster.
So, to make experimentation simpler, let's add a parameter. Some more
perf parameters will be added soon, so here is a new struct.
For now, add new backup qmp parameter with x- prefix for the following
reasons:
- We are going to add more performance parameters, some will be
related to the whole block-copy process, some only to background
copying in backup (ignored for copy-before-write operations).
- On the other hand, we are going to use block-copy interface in other
block jobs, which will need performance options as well.. And it
should be the same structure or at least somehow related.
So, there are too much unclean things about how the interface and now
we need the new options mostly for testing. Let's keep them
experimental for a while.
In do_backup_common() new x-perf parameter handled in a way to
make further options addition simpler.
We add use-copy-range with default=true, and we'll change the default
in further patch, after moving backup to use block-copy.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Message-Id: <20210116214705.822267-2-vsementsov@virtuozzo.com>
[mreitz: s/5\.2/6.0/]
Signed-off-by: Max Reitz <mreitz@redhat.com>
2021-01-16 22:46:43 +01:00
|
|
|
int64_t cluster_size, bool use_copy_range,
|
2021-08-24 10:38:28 +02:00
|
|
|
bool compress, Error **errp);
|
2019-10-01 15:14:07 +02:00
|
|
|
|
2021-08-24 10:38:29 +02:00
|
|
|
/* Function should be called prior any actual copy request */
|
|
|
|
void block_copy_set_copy_opts(BlockCopyState *s, bool use_copy_range,
|
|
|
|
bool compress);
|
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);
|
|
|
|
|
2019-09-20 16:20:48 +02:00
|
|
|
void block_copy_state_free(BlockCopyState *s);
|
|
|
|
|
|
|
|
int64_t block_copy_reset_unallocated(BlockCopyState *s,
|
|
|
|
int64_t offset, int64_t *count);
|
|
|
|
|
2020-03-11 11:30:02 +01:00
|
|
|
int coroutine_fn block_copy(BlockCopyState *s, int64_t offset, int64_t bytes,
|
2021-01-16 22:47:02 +01:00
|
|
|
bool ignore_ratelimit);
|
2019-09-20 16:20:48 +02:00
|
|
|
|
2021-01-16 22:46:45 +01:00
|
|
|
/*
|
|
|
|
* Run block-copy in a coroutine, create corresponding BlockCopyCallState
|
|
|
|
* object and return pointer to it. Never returns NULL.
|
|
|
|
*
|
|
|
|
* Caller is responsible to call block_copy_call_free() to free
|
|
|
|
* BlockCopyCallState object.
|
2021-01-16 22:46:46 +01:00
|
|
|
*
|
|
|
|
* @max_workers means maximum of parallel coroutines to execute sub-requests,
|
|
|
|
* must be > 0.
|
|
|
|
*
|
|
|
|
* @max_chunk means maximum length for one IO operation. Zero means unlimited.
|
2021-01-16 22:46:45 +01:00
|
|
|
*/
|
|
|
|
BlockCopyCallState *block_copy_async(BlockCopyState *s,
|
|
|
|
int64_t offset, int64_t bytes,
|
2021-01-16 22:46:46 +01:00
|
|
|
int max_workers, int64_t max_chunk,
|
2021-01-16 22:46:45 +01:00
|
|
|
BlockCopyAsyncCallbackFunc cb,
|
|
|
|
void *cb_opaque);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Free finished BlockCopyCallState. Trying to free running
|
|
|
|
* block-copy will crash.
|
|
|
|
*/
|
|
|
|
void block_copy_call_free(BlockCopyCallState *call_state);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Note, that block-copy call is marked finished prior to calling
|
|
|
|
* the callback.
|
|
|
|
*/
|
|
|
|
bool block_copy_call_finished(BlockCopyCallState *call_state);
|
|
|
|
bool block_copy_call_succeeded(BlockCopyCallState *call_state);
|
|
|
|
bool block_copy_call_failed(BlockCopyCallState *call_state);
|
2021-01-16 22:46:49 +01:00
|
|
|
bool block_copy_call_cancelled(BlockCopyCallState *call_state);
|
2021-01-16 22:46:45 +01:00
|
|
|
int block_copy_call_status(BlockCopyCallState *call_state, bool *error_is_read);
|
|
|
|
|
2021-01-16 22:46:48 +01:00
|
|
|
void block_copy_set_speed(BlockCopyState *s, uint64_t speed);
|
|
|
|
void block_copy_kick(BlockCopyCallState *call_state);
|
|
|
|
|
2021-01-16 22:46:49 +01:00
|
|
|
/*
|
|
|
|
* Cancel running block-copy call.
|
|
|
|
*
|
|
|
|
* Cancel leaves block-copy state valid: dirty bits are correct and you may use
|
|
|
|
* cancel + <run block_copy with same parameters> to emulate pause/resume.
|
|
|
|
*
|
|
|
|
* Note also, that the cancel is async: it only marks block-copy call to be
|
|
|
|
* cancelled. So, the call may be cancelled (block_copy_call_cancelled() reports
|
|
|
|
* true) but not yet finished (block_copy_call_finished() reports false).
|
|
|
|
*/
|
|
|
|
void block_copy_call_cancel(BlockCopyCallState *call_state);
|
|
|
|
|
2020-03-11 11:30:04 +01:00
|
|
|
BdrvDirtyBitmap *block_copy_dirty_bitmap(BlockCopyState *s);
|
|
|
|
void block_copy_set_skip_unallocated(BlockCopyState *s, bool skip);
|
|
|
|
|
2019-09-20 16:20:48 +02:00
|
|
|
#endif /* BLOCK_COPY_H */
|