28f4698a20
Fix floppy media change (bz #1341998)
102 lines
3.4 KiB
Diff
102 lines
3.4 KiB
Diff
From: Peter Krempa <pkrempa@redhat.com>
|
|
Date: Thu, 19 May 2016 14:57:41 +0200
|
|
Subject: [PATCH] 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.
|
|
|
|
(cherry picked from commit f1690dc3d7934bf70f4fbc84d55bf210276c6f27)
|
|
---
|
|
src/qemu/qemu_domain.h | 2 ++
|
|
src/qemu/qemu_monitor_json.c | 12 +++++++-----
|
|
tests/qemumonitorjsontest.c | 23 +++++++++++++++++++++++
|
|
3 files changed, 32 insertions(+), 5 deletions(-)
|
|
|
|
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
|
|
index ada4a17..fbf5b1c 100644
|
|
--- a/src/qemu/qemu_domain.h
|
|
+++ b/src/qemu/qemu_domain.h
|
|
@@ -241,7 +241,9 @@ struct _qemuDomainDiskPrivate {
|
|
struct qemuDomainDiskInfo {
|
|
bool removable;
|
|
bool locked;
|
|
+ bool tray;
|
|
bool tray_open;
|
|
+ bool empty;
|
|
int io_status;
|
|
};
|
|
|
|
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
|
|
index e140d0e..bd5537a 100644
|
|
--- a/src/qemu/qemu_monitor_json.c
|
|
+++ b/src/qemu/qemu_monitor_json.c
|
|
@@ -1797,11 +1797,13 @@ int qemuMonitorJSONGetBlockInfo(qemuMonitorPtr mon,
|
|
goto cleanup;
|
|
}
|
|
|
|
- /* Don't check for success here, because 'tray_open' is presented iff
|
|
- * medium is ejected.
|
|
- */
|
|
- ignore_value(virJSONValueObjectGetBoolean(dev, "tray_open",
|
|
- &info->tray_open));
|
|
+ /* 'tray_open' is present only if the device has a tray */
|
|
+ if (virJSONValueObjectGetBoolean(dev, "tray_open", &info->tray_open) == 0)
|
|
+ info->tray = true;
|
|
+
|
|
+ /* presence of 'inserted' notifies that a medium is in the device */
|
|
+ if (!virJSONValueObjectGetObject(dev, "inserted"))
|
|
+ info->empty = true;
|
|
|
|
/* Missing io-status indicates no error */
|
|
if ((status = virJSONValueObjectGetString(dev, "io-status"))) {
|
|
diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c
|
|
index cb917c2..315baea 100644
|
|
--- a/tests/qemumonitorjsontest.c
|
|
+++ b/tests/qemumonitorjsontest.c
|
|
@@ -114,6 +114,14 @@ const char *queryBlockReply =
|
|
" },"
|
|
" \"tray_open\": false,"
|
|
" \"type\": \"unknown\""
|
|
+" },"
|
|
+" {"
|
|
+" \"io-status\": \"ok\","
|
|
+" \"device\": \"drive-ide0-1-1\","
|
|
+" \"locked\": false,"
|
|
+" \"removable\": true,"
|
|
+" \"tray_open\": false,"
|
|
+" \"type\": \"unknown\""
|
|
" }"
|
|
" ],"
|
|
" \"id\": \"libvirt-10\""
|
|
@@ -1404,12 +1412,27 @@ testQemuMonitorJSONqemuMonitorJSONGetBlockInfo(const void *data)
|
|
|
|
info->locked = true;
|
|
info->removable = true;
|
|
+ info->tray = true;
|
|
+
|
|
if (virHashAddEntry(expectedBlockDevices, "ide0-1-0", info) < 0) {
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
"Unable to create expectedBlockDevices hash table");
|
|
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)
|
|
goto cleanup;
|
|
|