Similar to the recent race fix for 'block-stream', it is possible
to set the speed of a block copy job up front thanks to an optional
'speed' parameter to 'drive-mirror'.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONDriveMirror): Set
speed at job start.
* src/qemu/qemu_monitor_json.h (qemuMonitorJSONDriveMirror): Add
parameter.
* src/qemu/qemu_monitor.h (qemuMonitorDriveMirror): Likewise.
* src/qemu/qemu_driver.c (qemuDomainBlockCopy): Adjust caller.
* src/qemu/qemu_monitor.c (qemuMonitorDriveMirror): Likewise.
---
v6: new patch. I haven't actually seen a qemu patch implementing this
yet, but it is a logical extension of the recent block-stream patch.
src/qemu/qemu_driver.c | 3 ++-
src/qemu/qemu_monitor.c | 22 +++++++++++++++++-----
src/qemu/qemu_monitor.h | 1 +
src/qemu/qemu_monitor_json.c | 5 ++++-
src/qemu/qemu_monitor_json.h | 1 +
5 files changed, 25 insertions(+), 7 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 3a9e2d0..994393a 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -12108,7 +12108,8 @@ qemuDomainBlockCopy(virDomainPtr dom, const char *path,
/* Actually start the mirroring */
qemuDomainObjEnterMonitorWithDriver(driver, vm);
- ret = qemuMonitorDriveMirror(priv->mon, device, dest, format, flags);
+ ret = qemuMonitorDriveMirror(priv->mon, device, dest, format, bandwidth,
+ flags);
virDomainAuditDisk(vm, NULL, dest, "mirror", ret >= 0);
qemuDomainObjExitMonitorWithDriver(driver, vm);
if (ret < 0) {
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index fc84146..0c2ab48 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -2685,19 +2685,31 @@ qemuMonitorDiskSnapshot(qemuMonitorPtr mon, virJSONValuePtr
actions,
return ret;
}
-/* Start a drive-mirror block job. */
+/* Start a drive-mirror block job. bandwidth is in MB/sec. */
int
qemuMonitorDriveMirror(qemuMonitorPtr mon,
const char *device, const char *file,
- const char *format, unsigned int flags)
+ const char *format, unsigned long bandwidth,
+ unsigned int flags)
{
int ret = -1;
+ unsigned long long speed;
+
+ VIR_DEBUG("mon=%p, device=%s, file=%s, format=%s, bandwidth=%luM,
flags=%x",
+ mon, device, file, NULLSTR(format), bandwidth, flags);
- VIR_DEBUG("mon=%p, device=%s, file=%s, format=%s, flags=%x",
- mon, device, file, NULLSTR(format), flags);
+ /* Convert bandwidth MiB to bytes */
+ if (bandwidth > ULLONG_MAX / 1024 / 1024) {
+ qemuReportError(VIR_ERR_OVERFLOW,
+ _("bandwidth must be less than %llu"),
+ ULLONG_MAX / 1024 / 1024);
+ return -1;
+ }
+ speed = bandwidth * 1024ULL * 1024ULL;
if (mon->json)
- ret = qemuMonitorJSONDriveMirror(mon, device, file, format, flags);
+ ret = qemuMonitorJSONDriveMirror(mon, device, file, format, speed,
+ flags);
else
qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("drive-mirror requires JSON monitor"));
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 9ff8578..9dd0302 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -514,6 +514,7 @@ int qemuMonitorDriveMirror(qemuMonitorPtr mon,
const char *device,
const char *file,
const char *format,
+ unsigned long bandwidth,
unsigned int flags)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
int qemuMonitorDriveReopen(qemuMonitorPtr mon,
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 7b459ff..51b19cd 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -3204,10 +3204,12 @@ cleanup:
return ret;
}
+/* speed is in bytes/sec */
int
qemuMonitorJSONDriveMirror(qemuMonitorPtr mon,
const char *device, const char *file,
- const char *format, unsigned int flags)
+ const char *format, unsigned long long speed,
+ unsigned int flags)
{
int ret = -1;
virJSONValuePtr cmd;
@@ -3219,6 +3221,7 @@ qemuMonitorJSONDriveMirror(qemuMonitorPtr mon,
"s:device", device,
"s:target", file,
"b:full", !shallow,
+ "U:speed", speed,
"s:mode",
reuse ? "existing" :
"absolute-paths",
format ? "s:format" : NULL, format,
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index 71bd2cf..5371384 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -239,6 +239,7 @@ int qemuMonitorJSONDriveMirror(qemuMonitorPtr mon,
const char *device,
const char *file,
const char *format,
+ unsigned long long speed,
unsigned int flags)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
int qemuMonitorJSONDriveReopen(qemuMonitorPtr mon,
--
1.7.7.6