}
-typedef enum {
- QEMU_MONITOR_BLOCK_EXTENT_ERROR_OK,
- QEMU_MONITOR_BLOCK_EXTENT_ERROR_NOPARENT,
- QEMU_MONITOR_BLOCK_EXTENT_ERROR_NOSTATS,
- QEMU_MONITOR_BLOCK_EXTENT_ERROR_NOOFFSET,
-} qemuMonitorBlockExtentError;
-
-
-static int
-qemuMonitorJSONDevGetBlockExtent(virJSONValuePtr dev,
- unsigned long long *extent)
-{
- virJSONValuePtr stats;
- virJSONValuePtr parent;
-
- if ((parent = virJSONValueObjectGetObject(dev, "parent")) == NULL)
- return QEMU_MONITOR_BLOCK_EXTENT_ERROR_NOPARENT;
-
- if ((stats = virJSONValueObjectGetObject(parent, "stats")) == NULL)
- return QEMU_MONITOR_BLOCK_EXTENT_ERROR_NOSTATS;
-
- if (virJSONValueObjectGetNumberUlong(stats, "wr_highest_offset",
- extent) < 0) {
- return QEMU_MONITOR_BLOCK_EXTENT_ERROR_NOOFFSET;
- }
-
- return QEMU_MONITOR_BLOCK_EXTENT_ERROR_OK;
-}
-
-
static int
qemuMonitorJSONGetOneBlockStatsInfo(virJSONValuePtr dev,
const char *dev_name,
}
-static int
-qemuMonitorJSONReportBlockExtentError(qemuMonitorBlockExtentError error)
-{
- switch (error) {
- case QEMU_MONITOR_BLOCK_EXTENT_ERROR_NOPARENT:
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("blockstats parent entry was not in "
- "expected format"));
- break;
-
- case QEMU_MONITOR_BLOCK_EXTENT_ERROR_NOSTATS:
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("blockstats stats entry was not in "
- "expected format"));
- break;
-
- case QEMU_MONITOR_BLOCK_EXTENT_ERROR_NOOFFSET:
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("cannot read %s statistic"),
- "wr_highest_offset");
- break;
-
- case QEMU_MONITOR_BLOCK_EXTENT_ERROR_OK:
- return 0;
- }
-
- return -1;
-}
-
-
-int qemuMonitorJSONGetBlockExtent(qemuMonitorPtr mon,
- const char *dev_name,
- unsigned long long *extent)
-{
- int ret = -1;
- size_t i;
- bool found = false;
- virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("query-blockstats",
- NULL);
- virJSONValuePtr reply = NULL;
- virJSONValuePtr devices;
-
- *extent = 0;
-
- if (!cmd)
- return -1;
-
- ret = qemuMonitorJSONCommand(mon, cmd, &reply);
-
- if (ret == 0)
- ret = qemuMonitorJSONCheckError(cmd, reply);
- if (ret < 0)
- goto cleanup;
- ret = -1;
-
- if (!(devices = virJSONValueObjectGetArray(reply, "return"))) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("blockstats reply was missing device list"));
- goto cleanup;
- }
-
- for (i = 0; i < virJSONValueArraySize(devices); i++) {
- virJSONValuePtr dev = virJSONValueArrayGet(devices, i);
- const char *thisdev;
- int err;
- if (!dev || dev->type != VIR_JSON_TYPE_OBJECT) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("blockstats device entry was not in expected format"));
- goto cleanup;
- }
-
- if ((thisdev = virJSONValueObjectGetString(dev, "device")) == NULL) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("blockstats device entry was not in expected format"));
- goto cleanup;
- }
-
- /* New QEMU has separate names for host & guest side of the disk
- * and libvirt gives the host side a 'drive-' prefix. The passed
- * in dev_name is the guest side though
- */
- if (STRPREFIX(thisdev, QEMU_DRIVE_HOST_PREFIX))
- thisdev += strlen(QEMU_DRIVE_HOST_PREFIX);
-
- if (STRNEQ(thisdev, dev_name))
- continue;
-
- found = true;
- if ((err = qemuMonitorJSONDevGetBlockExtent(dev, extent)) !=
- QEMU_MONITOR_BLOCK_EXTENT_ERROR_OK) {
- qemuMonitorJSONReportBlockExtentError(err);
- goto cleanup;
- }
- }
-
- if (!found) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("cannot find statistics for device '%s'"), dev_name);
- goto cleanup;
- }
- ret = 0;
-
- cleanup:
- virJSONValueFree(cmd);
- virJSONValueFree(reply);
- return ret;
-}
-
/* Return 0 on success, -1 on failure, or -2 if not supported. Size
* is in bytes. */
int qemuMonitorJSONBlockResize(qemuMonitorPtr mon,
virHashTablePtr blockstats = NULL;
qemuBlockStatsPtr stats;
int ret = -1;
- unsigned long long extent;
const char *reply =
"{"
CHECK("virtio-disk1", 85, 348160, 8232156, 0, 0, 0, 0, 0, 0ULL, true)
CHECK("ide0-1-0", 16, 49250, 1004952, 0, 0, 0, 0, 0, 0ULL, true)
- if (qemuMonitorJSONGetBlockExtent(qemuMonitorTestGetMonitor(test), "virtio-disk0",
- &extent) < 0)
- goto cleanup;
-
- if (extent != 5256018944ULL) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- "Invalid extent: %llu, expected 5256018944",
- extent);
- goto cleanup;
- }
-
- if (qemuMonitorJSONGetBlockExtent(qemuMonitorTestGetMonitor(test), "virtio-disk1",
- &extent) < 0)
- goto cleanup;
-
- if (extent != 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- "Invalid extent: %llu, expected 0",
- extent);
- goto cleanup;
- }
-
- if (qemuMonitorJSONGetBlockExtent(qemuMonitorTestGetMonitor(test), "ide0-1-0",
- &extent) < 0)
- goto cleanup;
-
- if (extent != 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- "Invalid extent: %llu, expected 0",
- extent);
- goto cleanup;
- }
-
ret = 0;
#undef CHECK