Implements functions for both HMP and QMP mode.
For HMP mode, qemu uses "M" as the units by default, so the passed "sized"
is divided by 1024.
For 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.
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)
int qemuMonitorGetBlockExtent(qemuMonitorPtr mon,
const char *dev_name,
unsigned long long *extent);
-
-
+int qemuMonitorBlockResize(qemuMonitorPtr mon,
+ const char *devname,
+ unsigned long long size);
int qemuMonitorSetVNCPassword(qemuMonitorPtr mon,
const char *password);
int qemuMonitorSetPassword(qemuMonitorPtr mon,
return ret;
}
+/* 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)
int qemuMonitorJSONGetBlockExtent(qemuMonitorPtr mon,
const char *dev_name,
unsigned long long *extent);
-
+int qemuMonitorJSONBlockResize(qemuMonitorPtr mon,
+ const char *devce,
+ unsigned long long size);
int qemuMonitorJSONSetVNCPassword(qemuMonitorPtr mon,
const char *password);
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,
int qemuMonitorTextGetBlockExtent(qemuMonitorPtr mon,
const char *dev_name,
unsigned long long *extent);
-
+int qemuMonitorTextBlockResize(qemuMonitorPtr mon,
+ const char *device,
+ unsigned long long size);
int qemuMonitorTextSetVNCPassword(qemuMonitorPtr mon,
const char *password);
int qemuMonitorTextSetPassword(qemuMonitorPtr mon,