}
+static const char *
+qemuMonitorJSONGetBlockDevDevice(virJSONValuePtr dev)
+{
+ const char *thisdev;
+
+ if (!(thisdev = virJSONValueObjectGetString(dev, "device"))) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("query-block device entry was not in expected format"));
+ return NULL;
+ }
+
+ return thisdev;
+}
+
+
int qemuMonitorJSONGetBlockInfo(qemuMonitorPtr mon,
virHashTablePtr table)
{
if (!(dev = qemuMonitorJSONGetBlockDev(devices, i)))
goto cleanup;
- if ((thisdev = virJSONValueObjectGetString(dev, "device")) == NULL) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("block info device entry was not in expected format"));
+ if (!(thisdev = qemuMonitorJSONGetBlockDevDevice(dev)))
goto cleanup;
- }
thisdev = qemuAliasDiskDriveSkipPrefix(thisdev);
if (!(dev = qemuMonitorJSONGetBlockDev(devices, i)))
goto cleanup;
- if (!(dev_name = virJSONValueObjectGetString(dev, "device"))) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("query-block device entry was not "
- "in expected format"));
+ if (!(dev_name = qemuMonitorJSONGetBlockDevDevice(dev)))
goto cleanup;
- }
/* drive may be empty */
if (!(inserted = virJSONValueObjectGetObject(dev, "inserted")) ||
if (!(dev = qemuMonitorJSONGetBlockDev(devices, i)))
goto cleanup;
- if (!(thisdev = virJSONValueObjectGetString(dev, "device"))) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("block info device entry was not in expected format"));
+ if (!(thisdev = qemuMonitorJSONGetBlockDevDevice(dev)))
goto cleanup;
- }
if (STREQ(thisdev, device)) {
if ((inserted = virJSONValueObjectGetObject(dev, "inserted")) &&