mirror: Add 'job-id' parameter to 'blockdev-mirror' and 'drive-mirror'
This patch adds a new optional 'job-id' parameter to 'blockdev-mirror' and 'drive-mirror', allowing the user to specify the ID of the block job to be created. The HMP 'drive_mirror' command remains unchanged. Signed-off-by: Alberto Garcia <berto@igalia.com> Reviewed-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
7f0317cfc8
commit
71aa98678c
@ -843,8 +843,8 @@ static const BlockJobDriver commit_active_job_driver = {
|
|||||||
.attached_aio_context = mirror_attached_aio_context,
|
.attached_aio_context = mirror_attached_aio_context,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void mirror_start_job(BlockDriverState *bs, BlockDriverState *target,
|
static void mirror_start_job(const char *job_id, BlockDriverState *bs,
|
||||||
const char *replaces,
|
BlockDriverState *target, const char *replaces,
|
||||||
int64_t speed, uint32_t granularity,
|
int64_t speed, uint32_t granularity,
|
||||||
int64_t buf_size,
|
int64_t buf_size,
|
||||||
BlockMirrorBackingMode backing_mode,
|
BlockMirrorBackingMode backing_mode,
|
||||||
@ -873,7 +873,7 @@ static void mirror_start_job(BlockDriverState *bs, BlockDriverState *target,
|
|||||||
buf_size = DEFAULT_MIRROR_BUF_SIZE;
|
buf_size = DEFAULT_MIRROR_BUF_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
s = block_job_create(NULL, driver, bs, speed, cb, opaque, errp);
|
s = block_job_create(job_id, driver, bs, speed, cb, opaque, errp);
|
||||||
if (!s) {
|
if (!s) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -906,8 +906,8 @@ static void mirror_start_job(BlockDriverState *bs, BlockDriverState *target,
|
|||||||
qemu_coroutine_enter(s->common.co, s);
|
qemu_coroutine_enter(s->common.co, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mirror_start(BlockDriverState *bs, BlockDriverState *target,
|
void mirror_start(const char *job_id, BlockDriverState *bs,
|
||||||
const char *replaces,
|
BlockDriverState *target, const char *replaces,
|
||||||
int64_t speed, uint32_t granularity, int64_t buf_size,
|
int64_t speed, uint32_t granularity, int64_t buf_size,
|
||||||
MirrorSyncMode mode, BlockMirrorBackingMode backing_mode,
|
MirrorSyncMode mode, BlockMirrorBackingMode backing_mode,
|
||||||
BlockdevOnError on_source_error,
|
BlockdevOnError on_source_error,
|
||||||
@ -925,7 +925,7 @@ void mirror_start(BlockDriverState *bs, BlockDriverState *target,
|
|||||||
}
|
}
|
||||||
is_none_mode = mode == MIRROR_SYNC_MODE_NONE;
|
is_none_mode = mode == MIRROR_SYNC_MODE_NONE;
|
||||||
base = mode == MIRROR_SYNC_MODE_TOP ? backing_bs(bs) : NULL;
|
base = mode == MIRROR_SYNC_MODE_TOP ? backing_bs(bs) : NULL;
|
||||||
mirror_start_job(bs, target, replaces,
|
mirror_start_job(job_id, bs, target, replaces,
|
||||||
speed, granularity, buf_size, backing_mode,
|
speed, granularity, buf_size, backing_mode,
|
||||||
on_source_error, on_target_error, unmap, cb, opaque, errp,
|
on_source_error, on_target_error, unmap, cb, opaque, errp,
|
||||||
&mirror_job_driver, is_none_mode, base);
|
&mirror_job_driver, is_none_mode, base);
|
||||||
@ -973,7 +973,8 @@ void commit_active_start(BlockDriverState *bs, BlockDriverState *base,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mirror_start_job(bs, base, NULL, speed, 0, 0, MIRROR_LEAVE_BACKING_CHAIN,
|
mirror_start_job(NULL, bs, base, NULL, speed, 0, 0,
|
||||||
|
MIRROR_LEAVE_BACKING_CHAIN,
|
||||||
on_error, on_error, false, cb, opaque, &local_err,
|
on_error, on_error, false, cb, opaque, &local_err,
|
||||||
&commit_active_job_driver, false, base);
|
&commit_active_job_driver, false, base);
|
||||||
if (local_err) {
|
if (local_err) {
|
||||||
|
15
blockdev.c
15
blockdev.c
@ -3422,7 +3422,7 @@ void qmp_blockdev_backup(const char *device, const char *target,
|
|||||||
/* Parameter check and block job starting for drive mirroring.
|
/* Parameter check and block job starting for drive mirroring.
|
||||||
* Caller should hold @device and @target's aio context (must be the same).
|
* Caller should hold @device and @target's aio context (must be the same).
|
||||||
**/
|
**/
|
||||||
static void blockdev_mirror_common(BlockDriverState *bs,
|
static void blockdev_mirror_common(const char *job_id, BlockDriverState *bs,
|
||||||
BlockDriverState *target,
|
BlockDriverState *target,
|
||||||
bool has_replaces, const char *replaces,
|
bool has_replaces, const char *replaces,
|
||||||
enum MirrorSyncMode sync,
|
enum MirrorSyncMode sync,
|
||||||
@ -3482,15 +3482,15 @@ static void blockdev_mirror_common(BlockDriverState *bs,
|
|||||||
/* pass the node name to replace to mirror start since it's loose coupling
|
/* pass the node name to replace to mirror start since it's loose coupling
|
||||||
* and will allow to check whether the node still exist at mirror completion
|
* and will allow to check whether the node still exist at mirror completion
|
||||||
*/
|
*/
|
||||||
mirror_start(bs, target,
|
mirror_start(job_id, bs, target,
|
||||||
has_replaces ? replaces : NULL,
|
has_replaces ? replaces : NULL,
|
||||||
speed, granularity, buf_size, sync, backing_mode,
|
speed, granularity, buf_size, sync, backing_mode,
|
||||||
on_source_error, on_target_error, unmap,
|
on_source_error, on_target_error, unmap,
|
||||||
block_job_cb, bs, errp);
|
block_job_cb, bs, errp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void qmp_drive_mirror(const char *device, const char *target,
|
void qmp_drive_mirror(bool has_job_id, const char *job_id, const char *device,
|
||||||
bool has_format, const char *format,
|
const char *target, bool has_format, const char *format,
|
||||||
bool has_node_name, const char *node_name,
|
bool has_node_name, const char *node_name,
|
||||||
bool has_replaces, const char *replaces,
|
bool has_replaces, const char *replaces,
|
||||||
enum MirrorSyncMode sync,
|
enum MirrorSyncMode sync,
|
||||||
@ -3634,7 +3634,7 @@ void qmp_drive_mirror(const char *device, const char *target,
|
|||||||
|
|
||||||
bdrv_set_aio_context(target_bs, aio_context);
|
bdrv_set_aio_context(target_bs, aio_context);
|
||||||
|
|
||||||
blockdev_mirror_common(bs, target_bs,
|
blockdev_mirror_common(has_job_id ? job_id : NULL, bs, target_bs,
|
||||||
has_replaces, replaces, sync, backing_mode,
|
has_replaces, replaces, sync, backing_mode,
|
||||||
has_speed, speed,
|
has_speed, speed,
|
||||||
has_granularity, granularity,
|
has_granularity, granularity,
|
||||||
@ -3649,7 +3649,8 @@ out:
|
|||||||
aio_context_release(aio_context);
|
aio_context_release(aio_context);
|
||||||
}
|
}
|
||||||
|
|
||||||
void qmp_blockdev_mirror(const char *device, const char *target,
|
void qmp_blockdev_mirror(bool has_job_id, const char *job_id,
|
||||||
|
const char *device, const char *target,
|
||||||
bool has_replaces, const char *replaces,
|
bool has_replaces, const char *replaces,
|
||||||
MirrorSyncMode sync,
|
MirrorSyncMode sync,
|
||||||
bool has_speed, int64_t speed,
|
bool has_speed, int64_t speed,
|
||||||
@ -3690,7 +3691,7 @@ void qmp_blockdev_mirror(const char *device, const char *target,
|
|||||||
|
|
||||||
bdrv_set_aio_context(target_bs, aio_context);
|
bdrv_set_aio_context(target_bs, aio_context);
|
||||||
|
|
||||||
blockdev_mirror_common(bs, target_bs,
|
blockdev_mirror_common(has_job_id ? job_id : NULL, bs, target_bs,
|
||||||
has_replaces, replaces, sync, backing_mode,
|
has_replaces, replaces, sync, backing_mode,
|
||||||
has_speed, speed,
|
has_speed, speed,
|
||||||
has_granularity, granularity,
|
has_granularity, granularity,
|
||||||
|
2
hmp.c
2
hmp.c
@ -1097,7 +1097,7 @@ void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
|
|||||||
mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;
|
mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;
|
||||||
}
|
}
|
||||||
|
|
||||||
qmp_drive_mirror(device, filename, !!format, format,
|
qmp_drive_mirror(false, NULL, device, filename, !!format, format,
|
||||||
false, NULL, false, NULL,
|
false, NULL, false, NULL,
|
||||||
full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
|
full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
|
||||||
true, mode, false, 0, false, 0, false, 0,
|
true, mode, false, 0, false, 0, false, 0,
|
||||||
|
@ -697,6 +697,8 @@ void commit_active_start(BlockDriverState *bs, BlockDriverState *base,
|
|||||||
void *opaque, Error **errp);
|
void *opaque, Error **errp);
|
||||||
/*
|
/*
|
||||||
* mirror_start:
|
* mirror_start:
|
||||||
|
* @job_id: The id of the newly-created job, or %NULL to use the
|
||||||
|
* device name of @bs.
|
||||||
* @bs: Block device to operate on.
|
* @bs: Block device to operate on.
|
||||||
* @target: Block device to write to.
|
* @target: Block device to write to.
|
||||||
* @replaces: Block graph node name to replace once the mirror is done. Can
|
* @replaces: Block graph node name to replace once the mirror is done. Can
|
||||||
@ -718,8 +720,8 @@ void commit_active_start(BlockDriverState *bs, BlockDriverState *base,
|
|||||||
* manually completed. At the end of a successful mirroring job,
|
* manually completed. At the end of a successful mirroring job,
|
||||||
* @bs will be switched to read from @target.
|
* @bs will be switched to read from @target.
|
||||||
*/
|
*/
|
||||||
void mirror_start(BlockDriverState *bs, BlockDriverState *target,
|
void mirror_start(const char *job_id, BlockDriverState *bs,
|
||||||
const char *replaces,
|
BlockDriverState *target, const char *replaces,
|
||||||
int64_t speed, uint32_t granularity, int64_t buf_size,
|
int64_t speed, uint32_t granularity, int64_t buf_size,
|
||||||
MirrorSyncMode mode, BlockMirrorBackingMode backing_mode,
|
MirrorSyncMode mode, BlockMirrorBackingMode backing_mode,
|
||||||
BlockdevOnError on_source_error,
|
BlockdevOnError on_source_error,
|
||||||
|
@ -1108,6 +1108,9 @@
|
|||||||
#
|
#
|
||||||
# Start mirroring a block device's writes to a new destination.
|
# Start mirroring a block device's writes to a new destination.
|
||||||
#
|
#
|
||||||
|
# @job-id: #optional identifier for the newly-created block job. If
|
||||||
|
# omitted, the device name will be used. (Since 2.7)
|
||||||
|
#
|
||||||
# @device: the name of the device whose writes should be mirrored.
|
# @device: the name of the device whose writes should be mirrored.
|
||||||
#
|
#
|
||||||
# @target: the target of the new image. If the file exists, or if it
|
# @target: the target of the new image. If the file exists, or if it
|
||||||
@ -1160,8 +1163,8 @@
|
|||||||
# Since 1.3
|
# Since 1.3
|
||||||
##
|
##
|
||||||
{ 'command': 'drive-mirror',
|
{ 'command': 'drive-mirror',
|
||||||
'data': { 'device': 'str', 'target': 'str', '*format': 'str',
|
'data': { '*job-id': 'str', 'device': 'str', 'target': 'str',
|
||||||
'*node-name': 'str', '*replaces': 'str',
|
'*format': 'str', '*node-name': 'str', '*replaces': 'str',
|
||||||
'sync': 'MirrorSyncMode', '*mode': 'NewImageMode',
|
'sync': 'MirrorSyncMode', '*mode': 'NewImageMode',
|
||||||
'*speed': 'int', '*granularity': 'uint32',
|
'*speed': 'int', '*granularity': 'uint32',
|
||||||
'*buf-size': 'int', '*on-source-error': 'BlockdevOnError',
|
'*buf-size': 'int', '*on-source-error': 'BlockdevOnError',
|
||||||
@ -1243,6 +1246,9 @@
|
|||||||
#
|
#
|
||||||
# Start mirroring a block device's writes to a new destination.
|
# Start mirroring a block device's writes to a new destination.
|
||||||
#
|
#
|
||||||
|
# @job-id: #optional identifier for the newly-created block job. If
|
||||||
|
# omitted, the device name will be used. (Since 2.7)
|
||||||
|
#
|
||||||
# @device: the name of the device whose writes should be mirrored.
|
# @device: the name of the device whose writes should be mirrored.
|
||||||
#
|
#
|
||||||
# @target: the id or node-name of the block device to mirror to. This mustn't be
|
# @target: the id or node-name of the block device to mirror to. This mustn't be
|
||||||
@ -1279,7 +1285,7 @@
|
|||||||
# Since 2.6
|
# Since 2.6
|
||||||
##
|
##
|
||||||
{ 'command': 'blockdev-mirror',
|
{ 'command': 'blockdev-mirror',
|
||||||
'data': { 'device': 'str', 'target': 'str',
|
'data': { '*job-id': 'str', 'device': 'str', 'target': 'str',
|
||||||
'*replaces': 'str',
|
'*replaces': 'str',
|
||||||
'sync': 'MirrorSyncMode',
|
'sync': 'MirrorSyncMode',
|
||||||
'*speed': 'int', '*granularity': 'uint32',
|
'*speed': 'int', '*granularity': 'uint32',
|
||||||
|
@ -1656,8 +1656,8 @@ EQMP
|
|||||||
|
|
||||||
{
|
{
|
||||||
.name = "drive-mirror",
|
.name = "drive-mirror",
|
||||||
.args_type = "sync:s,device:B,target:s,speed:i?,mode:s?,format:s?,"
|
.args_type = "job-id:s?,sync:s,device:B,target:s,speed:i?,mode:s?,"
|
||||||
"node-name:s?,replaces:s?,"
|
"format:s?,node-name:s?,replaces:s?,"
|
||||||
"on-source-error:s?,on-target-error:s?,"
|
"on-source-error:s?,on-target-error:s?,"
|
||||||
"unmap:b?,"
|
"unmap:b?,"
|
||||||
"granularity:i?,buf-size:i?",
|
"granularity:i?,buf-size:i?",
|
||||||
@ -1677,6 +1677,8 @@ of the source.
|
|||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
|
|
||||||
|
- "job-id": Identifier for the newly-created block job. If omitted,
|
||||||
|
the device name will be used. (json-string, optional)
|
||||||
- "device": device name to operate on (json-string)
|
- "device": device name to operate on (json-string)
|
||||||
- "target": name of new image file (json-string)
|
- "target": name of new image file (json-string)
|
||||||
- "format": format of new image (json-string, optional)
|
- "format": format of new image (json-string, optional)
|
||||||
@ -1720,7 +1722,7 @@ EQMP
|
|||||||
|
|
||||||
{
|
{
|
||||||
.name = "blockdev-mirror",
|
.name = "blockdev-mirror",
|
||||||
.args_type = "sync:s,device:B,target:B,replaces:s?,speed:i?,"
|
.args_type = "job-id:s?,sync:s,device:B,target:B,replaces:s?,speed:i?,"
|
||||||
"on-source-error:s?,on-target-error:s?,"
|
"on-source-error:s?,on-target-error:s?,"
|
||||||
"granularity:i?,buf-size:i?",
|
"granularity:i?,buf-size:i?",
|
||||||
.mhandler.cmd_new = qmp_marshal_blockdev_mirror,
|
.mhandler.cmd_new = qmp_marshal_blockdev_mirror,
|
||||||
@ -1735,6 +1737,8 @@ specifies the target of mirror operation.
|
|||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
|
|
||||||
|
- "job-id": Identifier for the newly-created block job. If omitted,
|
||||||
|
the device name will be used. (json-string, optional)
|
||||||
- "device": device name to operate on (json-string)
|
- "device": device name to operate on (json-string)
|
||||||
- "target": device name to mirror to (json-string)
|
- "target": device name to mirror to (json-string)
|
||||||
- "replaces": the block driver node name to replace when finished
|
- "replaces": the block driver node name to replace when finished
|
||||||
|
Loading…
Reference in New Issue
Block a user