Implements functions for both HMP and QMP mode. (command "block_resize"
is supported by qemu in both HMP and QMP mode).
In HMP mode, qemu uses "M" as the units by default, so the passed
"sized"
is divided by 1024.
In QMP mode, qemu uses "Bytes" as the units by default, the passed
"sized"
is multiplied by 1024.
All of the monitor functions return -1 on failure, 0 on success, or -2 if
not supported.
---
src/qemu/qemu_monitor.c | 16 ++++++++++++++++
src/qemu/qemu_monitor.h | 3 +++
src/qemu/qemu_monitor_json.c | 33 +++++++++++++++++++++++++++++++++
src/qemu/qemu_monitor_json.h | 3 +++
src/qemu/qemu_monitor_text.c | 33 +++++++++++++++++++++++++++++++++
src/qemu/qemu_monitor_text.h | 3 +++
6 files changed, 91 insertions(+), 0 deletions(-)
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index db6107c..26302f2 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -1243,6 +1243,22 @@ int qemuMonitorGetBlockExtent(qemuMonitorPtr mon,
return ret;
}
+int qemuMonitorBlockResize(qemuMonitorPtr mon,
+ const char *device,
+ unsigned long long size)
+{
+ int ret;
+ VIR_DEBUG("mon=%p, fd=%d, devname=%p size=%llu",
+ mon, mon->fd, device, size);
+
+ if (mon->json)
+ ret = qemuMonitorJSONBlockResize(mon, device, size);
+ else
+ ret = qemuMonitorTextBlockResize(mon, device, size);
+
+ return ret;
+}
+
int qemuMonitorSetVNCPassword(qemuMonitorPtr mon,
const char *password)
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index f241c9e..ba63550 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -220,6 +220,9 @@ int qemuMonitorGetBlockExtent(qemuMonitorPtr mon,
const char *devname,
unsigned long long *extent);
+int qemuMonitorBlockResize(qemuMonitorPtr mon,
+ const char *devname,
+ unsigned long long size);
int qemuMonitorSetVNCPassword(qemuMonitorPtr mon,
const char *password);
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 715b26e..7098b5c 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -1520,6 +1520,39 @@ cleanup:
}
+/* Return 0 on success, -1 on failure, or -2 if not supported. */
+int qemuMonitorJSONBlockResize(qemuMonitorPtr mon,
+ const char *device,
+ unsigned long long size)
+{
+ int ret;
+ virJSONValuePtr cmd;
+ virJSONValuePtr reply = NULL;
+
+ cmd = qemuMonitorJSONMakeCommand("block_resize",
+ "s:device", device,
+ "U:size", size * 1024,
+ NULL);
+ if (!cmd)
+ return -1;
+
+ ret = qemuMonitorJSONCommand(mon, cmd, &reply);
+
+ if (ret == 0) {
+ if (qemuMonitorJSONHasError(reply, "CommandNotFound")) {
+ ret = -2;
+ goto cleanup;
+ }
+
+ ret = qemuMonitorJSONCheckError(cmd, reply);
+ }
+
+cleanup:
+ virJSONValueFree(cmd);
+ virJSONValueFree(reply);
+ return ret;
+}
+
int qemuMonitorJSONSetVNCPassword(qemuMonitorPtr mon,
const char *password)
{
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index 9512793..8f511a3 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -70,6 +70,9 @@ int qemuMonitorJSONGetBlockStatsInfo(qemuMonitorPtr mon,
int qemuMonitorJSONGetBlockExtent(qemuMonitorPtr mon,
const char *devname,
unsigned long long *extent);
+int qemuMonitorJSONBlockResize(qemuMonitorPtr mon,
+ const char *devce,
+ unsigned long long size);
int qemuMonitorJSONSetVNCPassword(qemuMonitorPtr mon,
diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c
index f37c98c..7fff906 100644
--- a/src/qemu/qemu_monitor_text.c
+++ b/src/qemu/qemu_monitor_text.c
@@ -820,6 +820,39 @@ int qemuMonitorTextGetBlockExtent(qemuMonitorPtr mon
ATTRIBUTE_UNUSED,
return -1;
}
+/* Return 0 on success, -1 on failure, or -2 if not supported. */
+int qemuMonitorTextBlockResize(qemuMonitorPtr mon,
+ const char *device,
+ unsigned long long size)
+{
+ char *cmd = NULL;
+ char *reply = NULL;
+ int ret = -1;
+
+ if (virAsprintf(&cmd, "block_resize %s %llu",
+ device, VIR_DIV_UP(size, 1024)) < 0) {
+ virReportOOMError();
+ goto cleanup;
+ }
+
+ if (qemuMonitorHMPCommand(mon, cmd, &reply) < 0) {
+ qemuReportError(VIR_ERR_OPERATION_FAILED,
+ "%s", _("failed to resize block"));
+ goto cleanup;
+ }
+
+ if (strstr(reply, "unknown command:")) {
+ ret = -2;
+ goto cleanup;
+ }
+
+ ret = 0;
+
+cleanup:
+ VIR_FREE(cmd);
+ VIR_FREE(reply);
+ return ret;
+}
static int
qemuMonitorSendVNCPassphrase(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
diff --git a/src/qemu/qemu_monitor_text.h b/src/qemu/qemu_monitor_text.h
index b250738..0c2f916 100644
--- a/src/qemu/qemu_monitor_text.h
+++ b/src/qemu/qemu_monitor_text.h
@@ -67,6 +67,9 @@ int qemuMonitorTextGetBlockStatsInfo(qemuMonitorPtr mon,
int qemuMonitorTextGetBlockExtent(qemuMonitorPtr mon,
const char *devname,
unsigned long long *extent);
+int qemuMonitorTextBlockResize(qemuMonitorPtr mon,
+ const char *device,
+ unsigned long long size);
int qemuMonitorTextSetVNCPassword(qemuMonitorPtr mon,
const char *password);
--
1.7.6