提交 59539ebf 编写于 作者: J John Ferlan

qemu: Create helper qemuMonitorJSONGetBlockDevDevice

This will fetch "this device" from the recently returned 'dev' and perform
common error checking for the paths that call it.
上级 c6c5fc0b
...@@ -1822,6 +1822,21 @@ qemuMonitorJSONGetBlockDev(virJSONValuePtr devices, ...@@ -1822,6 +1822,21 @@ qemuMonitorJSONGetBlockDev(virJSONValuePtr devices,
} }
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, int qemuMonitorJSONGetBlockInfo(qemuMonitorPtr mon,
virHashTablePtr table) virHashTablePtr table)
{ {
...@@ -1842,11 +1857,8 @@ int qemuMonitorJSONGetBlockInfo(qemuMonitorPtr mon, ...@@ -1842,11 +1857,8 @@ int qemuMonitorJSONGetBlockInfo(qemuMonitorPtr mon,
if (!(dev = qemuMonitorJSONGetBlockDev(devices, i))) if (!(dev = qemuMonitorJSONGetBlockDev(devices, i)))
goto cleanup; goto cleanup;
if ((thisdev = virJSONValueObjectGetString(dev, "device")) == NULL) { if (!(thisdev = qemuMonitorJSONGetBlockDevDevice(dev)))
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("block info device entry was not in expected format"));
goto cleanup; goto cleanup;
}
thisdev = qemuAliasDiskDriveSkipPrefix(thisdev); thisdev = qemuAliasDiskDriveSkipPrefix(thisdev);
...@@ -2102,12 +2114,8 @@ qemuMonitorJSONBlockStatsUpdateCapacity(qemuMonitorPtr mon, ...@@ -2102,12 +2114,8 @@ qemuMonitorJSONBlockStatsUpdateCapacity(qemuMonitorPtr mon,
if (!(dev = qemuMonitorJSONGetBlockDev(devices, i))) if (!(dev = qemuMonitorJSONGetBlockDev(devices, i)))
goto cleanup; goto cleanup;
if (!(dev_name = virJSONValueObjectGetString(dev, "device"))) { if (!(dev_name = qemuMonitorJSONGetBlockDevDevice(dev)))
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("query-block device entry was not "
"in expected format"));
goto cleanup; goto cleanup;
}
/* drive may be empty */ /* drive may be empty */
if (!(inserted = virJSONValueObjectGetObject(dev, "inserted")) || if (!(inserted = virJSONValueObjectGetObject(dev, "inserted")) ||
...@@ -4013,11 +4021,8 @@ qemuMonitorJSONDiskNameLookup(qemuMonitorPtr mon, ...@@ -4013,11 +4021,8 @@ qemuMonitorJSONDiskNameLookup(qemuMonitorPtr mon,
if (!(dev = qemuMonitorJSONGetBlockDev(devices, i))) if (!(dev = qemuMonitorJSONGetBlockDev(devices, i)))
goto cleanup; goto cleanup;
if (!(thisdev = virJSONValueObjectGetString(dev, "device"))) { if (!(thisdev = qemuMonitorJSONGetBlockDevDevice(dev)))
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("block info device entry was not in expected format"));
goto cleanup; goto cleanup;
}
if (STREQ(thisdev, device)) { if (STREQ(thisdev, device)) {
if ((inserted = virJSONValueObjectGetObject(dev, "inserted")) && if ((inserted = virJSONValueObjectGetObject(dev, "inserted")) &&
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册