[libvirt] [PATCH 1/2] BlockJob: Bandwidth parameter is in MB when using text monitor

Due to an unfortunate precedent in qemu, the units for the bandwidth parameter to block_job_set_speed are different between the text monitor and the qmp monitor. While the qmp monitor uses bytes/s, the text monitor expects MB/s. Correct the units for the text interface. Signed-off-by: Adam Litke <agl@us.ibm.com> --- src/qemu/qemu_monitor_text.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c index f37c98c..854ee7f 100644 --- a/src/qemu/qemu_monitor_text.c +++ b/src/qemu/qemu_monitor_text.c @@ -3067,8 +3067,7 @@ int qemuMonitorTextBlockJob(qemuMonitorPtr mon, ret = virAsprintf(&cmd, "%s", cmd_name); } else if (mode == BLOCK_JOB_SPEED) { cmd_name = "block_job_set_speed"; - ret = virAsprintf(&cmd, "%s %s %llu", cmd_name, device, - bandwidth * 1024ULL * 1024ULL); + ret = virAsprintf(&cmd, "%s %s %luM", cmd_name, device, bandwidth); } else if (mode == BLOCK_JOB_PULL) { cmd_name = "block_stream"; ret = virAsprintf(&cmd, "%s %s", cmd_name, device); -- 1.7.3

The libvirt BlockPull API supports the use of an initial bandwidth limit. To implement this in the text monitor we first start the operation with a 'block_stream' command and then issue a 'block_job_set_speed' command to apply the limit. This functionality is already present for json mode. Signed-off-by: Adam Litke <agl@us.ibm.com> --- src/qemu/qemu_monitor_text.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-) diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c index 854ee7f..2159209 100644 --- a/src/qemu/qemu_monitor_text.c +++ b/src/qemu/qemu_monitor_text.c @@ -3096,6 +3096,11 @@ int qemuMonitorTextBlockJob(qemuMonitorPtr mon, ret = qemuMonitorTextParseBlockJob(reply, device, info); + /* If non-zero, set the bandwidth limit with a separate command */ + if (ret == 0 && mode == BLOCK_JOB_PULL && bandwidth != 0) + ret = qemuMonitorTextBlockJob(mon, device, bandwidth, info, + BLOCK_JOB_SPEED); + cleanup: VIR_FREE(cmd); VIR_FREE(reply); -- 1.7.3

On Wed, Aug 31, 2011 at 05:15:44PM -0500, Adam Litke wrote:
The libvirt BlockPull API supports the use of an initial bandwidth limit. To implement this in the text monitor we first start the operation with a 'block_stream' command and then issue a 'block_job_set_speed' command to apply the limit.
This functionality is already present for json mode.
Signed-off-by: Adam Litke <agl@us.ibm.com> --- src/qemu/qemu_monitor_text.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c index 854ee7f..2159209 100644 --- a/src/qemu/qemu_monitor_text.c +++ b/src/qemu/qemu_monitor_text.c @@ -3096,6 +3096,11 @@ int qemuMonitorTextBlockJob(qemuMonitorPtr mon,
ret = qemuMonitorTextParseBlockJob(reply, device, info);
+ /* If non-zero, set the bandwidth limit with a separate command */ + if (ret == 0 && mode == BLOCK_JOB_PULL && bandwidth != 0) + ret = qemuMonitorTextBlockJob(mon, device, bandwidth, info, + BLOCK_JOB_SPEED); + cleanup: VIR_FREE(cmd); VIR_FREE(reply);
Since it needs to be done for both json & text monitor, could we push this chunk of code up one level into qemu_monitor.c, thus avoiding the duplication ? Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On Wed, Aug 31, 2011 at 05:15:43PM -0500, Adam Litke wrote:
Due to an unfortunate precedent in qemu, the units for the bandwidth parameter to block_job_set_speed are different between the text monitor and the qmp monitor. While the qmp monitor uses bytes/s, the text monitor expects MB/s.
Correct the units for the text interface.
Signed-off-by: Adam Litke <agl@us.ibm.com> --- src/qemu/qemu_monitor_text.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c index f37c98c..854ee7f 100644 --- a/src/qemu/qemu_monitor_text.c +++ b/src/qemu/qemu_monitor_text.c @@ -3067,8 +3067,7 @@ int qemuMonitorTextBlockJob(qemuMonitorPtr mon, ret = virAsprintf(&cmd, "%s", cmd_name); } else if (mode == BLOCK_JOB_SPEED) { cmd_name = "block_job_set_speed"; - ret = virAsprintf(&cmd, "%s %s %llu", cmd_name, device, - bandwidth * 1024ULL * 1024ULL); + ret = virAsprintf(&cmd, "%s %s %luM", cmd_name, device, bandwidth); } else if (mode == BLOCK_JOB_PULL) { cmd_name = "block_stream"; ret = virAsprintf(&cmd, "%s %s", cmd_name, device);
ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On 09/01/2011 03:03 AM, Daniel P. Berrange wrote:
On Wed, Aug 31, 2011 at 05:15:43PM -0500, Adam Litke wrote:
Due to an unfortunate precedent in qemu, the units for the bandwidth parameter to block_job_set_speed are different between the text monitor and the qmp monitor. While the qmp monitor uses bytes/s, the text monitor expects MB/s.
Correct the units for the text interface.
Signed-off-by: Adam Litke<agl@us.ibm.com> --- src/qemu/qemu_monitor_text.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c index f37c98c..854ee7f 100644 --- a/src/qemu/qemu_monitor_text.c +++ b/src/qemu/qemu_monitor_text.c @@ -3067,8 +3067,7 @@ int qemuMonitorTextBlockJob(qemuMonitorPtr mon, ret = virAsprintf(&cmd, "%s", cmd_name); } else if (mode == BLOCK_JOB_SPEED) { cmd_name = "block_job_set_speed"; - ret = virAsprintf(&cmd, "%s %s %llu", cmd_name, device, - bandwidth * 1024ULL * 1024ULL); + ret = virAsprintf(&cmd, "%s %s %luM", cmd_name, device, bandwidth); } else if (mode == BLOCK_JOB_PULL) { cmd_name = "block_stream"; ret = virAsprintf(&cmd, "%s %s", cmd_name, device);
ACK
Pushed. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org
participants (3)
-
Adam Litke
-
Daniel P. Berrange
-
Eric Blake