mirror of https://github.com/xemu-project/xemu.git
block/copy-before-write: add on-cbw-error open parameter
Currently, behavior on copy-before-write operation failure is simple: report error to the guest. Let's implement alternative behavior: break the whole copy-before-write process (and corresponding backup job or NBD client) but keep guest working. It's needed if we consider guest stability as more important. The realisation is simple: on copy-before-write failure we set s->snapshot_ret and continue guest operations. s->snapshot_ret being set will lead to all further snapshot API requests. Note that all in-flight snapshot-API requests may still success: we do wait for them on BREAK_SNAPSHOT-failure path in cbw_do_copy_before_write(). Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@openvz.org> Reviewed-by: Hanna Reitz <hreitz@redhat.com> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
This commit is contained in:
parent
79ef0cebb5
commit
f1bb39a8a5
|
@ -41,6 +41,7 @@
|
||||||
typedef struct BDRVCopyBeforeWriteState {
|
typedef struct BDRVCopyBeforeWriteState {
|
||||||
BlockCopyState *bcs;
|
BlockCopyState *bcs;
|
||||||
BdrvChild *target;
|
BdrvChild *target;
|
||||||
|
OnCbwError on_cbw_error;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @lock: protects access to @access_bitmap, @done_bitmap and
|
* @lock: protects access to @access_bitmap, @done_bitmap and
|
||||||
|
@ -65,6 +66,14 @@ typedef struct BDRVCopyBeforeWriteState {
|
||||||
* node. These areas must not be rewritten by guest.
|
* node. These areas must not be rewritten by guest.
|
||||||
*/
|
*/
|
||||||
BlockReqList frozen_read_reqs;
|
BlockReqList frozen_read_reqs;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @snapshot_error is normally zero. But on first copy-before-write failure
|
||||||
|
* when @on_cbw_error == ON_CBW_ERROR_BREAK_SNAPSHOT, @snapshot_error takes
|
||||||
|
* value of this error (<0). After that all in-flight and further
|
||||||
|
* snapshot-API requests will fail with that error.
|
||||||
|
*/
|
||||||
|
int snapshot_error;
|
||||||
} BDRVCopyBeforeWriteState;
|
} BDRVCopyBeforeWriteState;
|
||||||
|
|
||||||
static coroutine_fn int cbw_co_preadv(
|
static coroutine_fn int cbw_co_preadv(
|
||||||
|
@ -95,16 +104,27 @@ static coroutine_fn int cbw_do_copy_before_write(BlockDriverState *bs,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (s->snapshot_error) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
off = QEMU_ALIGN_DOWN(offset, cluster_size);
|
off = QEMU_ALIGN_DOWN(offset, cluster_size);
|
||||||
end = QEMU_ALIGN_UP(offset + bytes, cluster_size);
|
end = QEMU_ALIGN_UP(offset + bytes, cluster_size);
|
||||||
|
|
||||||
ret = block_copy(s->bcs, off, end - off, true);
|
ret = block_copy(s->bcs, off, end - off, true);
|
||||||
if (ret < 0) {
|
if (ret < 0 && s->on_cbw_error == ON_CBW_ERROR_BREAK_GUEST_WRITE) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
WITH_QEMU_LOCK_GUARD(&s->lock) {
|
WITH_QEMU_LOCK_GUARD(&s->lock) {
|
||||||
|
if (ret < 0) {
|
||||||
|
assert(s->on_cbw_error == ON_CBW_ERROR_BREAK_SNAPSHOT);
|
||||||
|
if (!s->snapshot_error) {
|
||||||
|
s->snapshot_error = ret;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
bdrv_set_dirty_bitmap(s->done_bitmap, off, end - off);
|
bdrv_set_dirty_bitmap(s->done_bitmap, off, end - off);
|
||||||
|
}
|
||||||
reqlist_wait_all(&s->frozen_read_reqs, off, end - off, &s->lock);
|
reqlist_wait_all(&s->frozen_read_reqs, off, end - off, &s->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,6 +196,11 @@ static BlockReq *cbw_snapshot_read_lock(BlockDriverState *bs,
|
||||||
|
|
||||||
QEMU_LOCK_GUARD(&s->lock);
|
QEMU_LOCK_GUARD(&s->lock);
|
||||||
|
|
||||||
|
if (s->snapshot_error) {
|
||||||
|
g_free(req);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (bdrv_dirty_bitmap_next_zero(s->access_bitmap, offset, bytes) != -1) {
|
if (bdrv_dirty_bitmap_next_zero(s->access_bitmap, offset, bytes) != -1) {
|
||||||
g_free(req);
|
g_free(req);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -351,6 +376,7 @@ static BlockdevOptions *cbw_parse_options(QDict *options, Error **errp)
|
||||||
* object for original options.
|
* object for original options.
|
||||||
*/
|
*/
|
||||||
qdict_extract_subqdict(options, NULL, "bitmap");
|
qdict_extract_subqdict(options, NULL, "bitmap");
|
||||||
|
qdict_del(options, "on-cbw-error");
|
||||||
|
|
||||||
out:
|
out:
|
||||||
visit_free(v);
|
visit_free(v);
|
||||||
|
@ -395,6 +421,8 @@ static int cbw_open(BlockDriverState *bs, QDict *options, int flags,
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
s->on_cbw_error = opts->has_on_cbw_error ? opts->on_cbw_error :
|
||||||
|
ON_CBW_ERROR_BREAK_GUEST_WRITE;
|
||||||
|
|
||||||
bs->total_sectors = bs->file->bs->total_sectors;
|
bs->total_sectors = bs->file->bs->total_sectors;
|
||||||
bs->supported_write_flags = BDRV_REQ_WRITE_UNCHANGED |
|
bs->supported_write_flags = BDRV_REQ_WRITE_UNCHANGED |
|
||||||
|
|
|
@ -4184,6 +4184,25 @@
|
||||||
'base': 'BlockdevOptionsGenericFormat',
|
'base': 'BlockdevOptionsGenericFormat',
|
||||||
'data': { '*bottom': 'str' } }
|
'data': { '*bottom': 'str' } }
|
||||||
|
|
||||||
|
##
|
||||||
|
# @OnCbwError:
|
||||||
|
#
|
||||||
|
# An enumeration of possible behaviors for copy-before-write operation
|
||||||
|
# failures.
|
||||||
|
#
|
||||||
|
# @break-guest-write: report the error to the guest. This way, the guest
|
||||||
|
# will not be able to overwrite areas that cannot be
|
||||||
|
# backed up, so the backup process remains valid.
|
||||||
|
#
|
||||||
|
# @break-snapshot: continue guest write. Doing so will make the provided
|
||||||
|
# snapshot state invalid and any backup or export
|
||||||
|
# process based on it will finally fail.
|
||||||
|
#
|
||||||
|
# Since: 7.1
|
||||||
|
##
|
||||||
|
{ 'enum': 'OnCbwError',
|
||||||
|
'data': [ 'break-guest-write', 'break-snapshot' ] }
|
||||||
|
|
||||||
##
|
##
|
||||||
# @BlockdevOptionsCbw:
|
# @BlockdevOptionsCbw:
|
||||||
#
|
#
|
||||||
|
@ -4205,11 +4224,15 @@
|
||||||
# modifications (or removing) of specified bitmap doesn't
|
# modifications (or removing) of specified bitmap doesn't
|
||||||
# influence the filter. (Since 7.0)
|
# influence the filter. (Since 7.0)
|
||||||
#
|
#
|
||||||
|
# @on-cbw-error: Behavior on failure of copy-before-write operation.
|
||||||
|
# Default is @break-guest-write. (Since 7.1)
|
||||||
|
#
|
||||||
# Since: 6.2
|
# Since: 6.2
|
||||||
##
|
##
|
||||||
{ 'struct': 'BlockdevOptionsCbw',
|
{ 'struct': 'BlockdevOptionsCbw',
|
||||||
'base': 'BlockdevOptionsGenericFormat',
|
'base': 'BlockdevOptionsGenericFormat',
|
||||||
'data': { 'target': 'BlockdevRef', '*bitmap': 'BlockDirtyBitmap' } }
|
'data': { 'target': 'BlockdevRef', '*bitmap': 'BlockDirtyBitmap',
|
||||||
|
'*on-cbw-error': 'OnCbwError' } }
|
||||||
|
|
||||||
##
|
##
|
||||||
# @BlockdevOptions:
|
# @BlockdevOptions:
|
||||||
|
|
Loading…
Reference in New Issue