]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: process: Fix and improve disk data extraction
authorPeter Krempa <pkrempa@redhat.com>
Thu, 19 May 2016 13:29:02 +0000 (15:29 +0200)
committerCole Robinson <crobinso@redhat.com>
Thu, 23 Jun 2016 19:51:42 +0000 (15:51 -0400)
Extract information for all disks and update tray state and source only
for removable drives. Additionally store whether a drive is removable
and whether it has a tray.

(cherry picked from commit 894dc85fd1ebcd63d8c897b355c550e68a5f432d)

src/qemu/qemu_domain.h
src/qemu/qemu_monitor.c
src/qemu/qemu_monitor.h
src/qemu/qemu_process.c

index fbf5b1c9668c78e856887119549fe1138abe0494..15790ea05278fcfd8ca0fba5f192b55e0f04994c 100644 (file)
@@ -236,6 +236,10 @@ struct _qemuDomainDiskPrivate {
     bool blockJobSync; /* the block job needs synchronized termination */
 
     bool migrating; /* the disk is being migrated */
+
+    /* information about the device */
+    bool tray; /* device has tray */
+    bool removable; /* device media can be removed/changed */
 };
 
 struct qemuDomainDiskInfo {
index 96eac149113742ed370e1f9e30d1c39224d20164..c994fecf742a13370500f8c398d574760efe536c 100644 (file)
@@ -1807,24 +1807,6 @@ qemuMonitorGetBlockInfo(qemuMonitorPtr mon)
 }
 
 
-struct qemuDomainDiskInfo *
-qemuMonitorBlockInfoLookup(virHashTablePtr blockInfo,
-                           const char *dev)
-{
-    struct qemuDomainDiskInfo *info;
-
-    VIR_DEBUG("blockInfo=%p dev=%s", blockInfo, NULLSTR(dev));
-
-    if (!(info = virHashLookup(blockInfo, dev))) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("cannot find info for device '%s'"),
-                       NULLSTR(dev));
-    }
-
-    return info;
-}
-
-
 /**
  * qemuMonitorGetAllBlockStatsInfo:
  * @mon: monitor object
index 79063619e7bf35c240051898c6292022f45a0e97..1a9d009608861417e9dd7c493662d409c4bc8958 100644 (file)
@@ -385,9 +385,6 @@ int qemuMonitorSetMemoryStatsPeriod(qemuMonitorPtr mon,
 
 int qemuMonitorBlockIOStatusToError(const char *status);
 virHashTablePtr qemuMonitorGetBlockInfo(qemuMonitorPtr mon);
-struct qemuDomainDiskInfo *
-qemuMonitorBlockInfoLookup(virHashTablePtr blockInfo,
-                           const char *dev_name);
 
 typedef struct _qemuBlockStats qemuBlockStats;
 typedef qemuBlockStats *qemuBlockStatsPtr;
index f13d902c3a93d5672e966804c569fedd8f0feecd..aa56ccd34712128dea0d6b0c11488beee4106699 100644 (file)
@@ -6403,25 +6403,27 @@ qemuProcessRefreshDisks(virQEMUDriverPtr driver,
 
     for (i = 0; i < vm->def->ndisks; i++) {
         virDomainDiskDefPtr disk = vm->def->disks[i];
+        qemuDomainDiskPrivatePtr diskpriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
         struct qemuDomainDiskInfo *info;
 
-        if (disk->device == VIR_DOMAIN_DISK_DEVICE_DISK ||
-            disk->device == VIR_DOMAIN_DISK_DEVICE_LUN) {
-                 continue;
-        }
-
-        info = qemuMonitorBlockInfoLookup(table, disk->info.alias);
-        if (!info)
-            goto cleanup;
+        if (!(info = virHashLookup(table, disk->info.alias)))
+            continue;
 
-        if (info->tray_open) {
-            if (virDomainDiskGetSource(disk))
+        if (info->removable) {
+            if (info->empty)
                 ignore_value(virDomainDiskSetSource(disk, NULL));
 
-            disk->tray_status = VIR_DOMAIN_DISK_TRAY_OPEN;
-        } else {
-            disk->tray_status = VIR_DOMAIN_DISK_TRAY_CLOSED;
+            if (info->tray) {
+                if (info->tray_open)
+                    disk->tray_status = VIR_DOMAIN_DISK_TRAY_OPEN;
+                else
+                    disk->tray_status = VIR_DOMAIN_DISK_TRAY_CLOSED;
+            }
         }
+
+        /* fill in additional data */
+        diskpriv->removable = info->removable;
+        diskpriv->tray = info->tray;
     }
 
     ret = 0;