qemu: Extract more information about qemu drives

Extract whether a given drive has a tray and whether there is no image
inserted.

Negative logic for the image insertion is chosen so that the flag is set
only if we are certain of the fact.
This commit is contained in:
Peter Krempa 2016-05-19 14:57:41 +02:00
parent 5f963d89b1
commit f1690dc3d7
3 changed files with 32 additions and 5 deletions

View File

@ -307,7 +307,9 @@ struct _qemuDomainDiskPrivate {
struct qemuDomainDiskInfo { struct qemuDomainDiskInfo {
bool removable; bool removable;
bool locked; bool locked;
bool tray;
bool tray_open; bool tray_open;
bool empty;
int io_status; int io_status;
}; };

View File

@ -1832,11 +1832,13 @@ int qemuMonitorJSONGetBlockInfo(qemuMonitorPtr mon,
goto cleanup; goto cleanup;
} }
/* Don't check for success here, because 'tray_open' is presented iff /* 'tray_open' is present only if the device has a tray */
* medium is ejected. if (virJSONValueObjectGetBoolean(dev, "tray_open", &info->tray_open) == 0)
*/ info->tray = true;
ignore_value(virJSONValueObjectGetBoolean(dev, "tray_open",
&info->tray_open)); /* presence of 'inserted' notifies that a medium is in the device */
if (!virJSONValueObjectGetObject(dev, "inserted"))
info->empty = true;
/* Missing io-status indicates no error */ /* Missing io-status indicates no error */
if ((status = virJSONValueObjectGetString(dev, "io-status"))) { if ((status = virJSONValueObjectGetString(dev, "io-status"))) {

View File

@ -114,6 +114,14 @@ const char *queryBlockReply =
" }," " },"
" \"tray_open\": false," " \"tray_open\": false,"
" \"type\": \"unknown\"" " \"type\": \"unknown\""
" },"
" {"
" \"io-status\": \"ok\","
" \"device\": \"drive-ide0-1-1\","
" \"locked\": false,"
" \"removable\": true,"
" \"tray_open\": false,"
" \"type\": \"unknown\""
" }" " }"
" ]," " ],"
" \"id\": \"libvirt-10\"" " \"id\": \"libvirt-10\""
@ -1404,12 +1412,27 @@ testQemuMonitorJSONqemuMonitorJSONGetBlockInfo(const void *data)
info->locked = true; info->locked = true;
info->removable = true; info->removable = true;
info->tray = true;
if (virHashAddEntry(expectedBlockDevices, "ide0-1-0", info) < 0) { if (virHashAddEntry(expectedBlockDevices, "ide0-1-0", info) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
"Unable to create expectedBlockDevices hash table"); "Unable to create expectedBlockDevices hash table");
goto cleanup; goto cleanup;
} }
if (VIR_ALLOC(info) < 0)
goto cleanup;
info->removable = true;
info->tray = true;
info->empty = true;
if (virHashAddEntry(expectedBlockDevices, "ide0-1-1", info) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
"Unable to create expectedBlockDevices hash table");
goto cleanup;
}
if (qemuMonitorTestAddItem(test, "query-block", queryBlockReply) < 0) if (qemuMonitorTestAddItem(test, "query-block", queryBlockReply) < 0)
goto cleanup; goto cleanup;