From: Peter Krempa <[email protected]>

The only thing that 'qemuProcessRefreshDisks' currently does is to
update tray state for disks. This makes no sense on cold boot since only
cdroms have tray and the tray is closed.

Avoid the extra call to 'query-block' on cold boot and just assume CDROM
has a closed tray.

Signed-off-by: Peter Krempa <[email protected]>
---
 src/qemu/qemu_process.c | 47 ++++++++++++++++++++++++++++++-----------
 1 file changed, 35 insertions(+), 12 deletions(-)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 2628a89cbf..51b91f2b98 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -8640,6 +8640,7 @@ qemuProcessRefreshRxFilters(virDomainObj *vm,

 static int
 qemuProcessRefreshDisks(virDomainObj *vm,
+                        bool cold_start,
                         virDomainAsyncJob asyncJob)
 {
     qemuDomainObjPrivate *priv = vm->privateData;
@@ -8647,13 +8648,15 @@ qemuProcessRefreshDisks(virDomainObj *vm,
     g_autoptr(GHashTable) table = NULL;
     size_t i;

-    if (qemuDomainObjEnterMonitorAsync(vm, asyncJob) == 0) {
-        table = qemuMonitorGetBlockInfo(priv->mon);
-        qemuDomainObjExitMonitor(vm);
-    }
+    if (!cold_start) {
+        if (qemuDomainObjEnterMonitorAsync(vm, asyncJob) == 0) {
+            table = qemuMonitorGetBlockInfo(priv->mon);
+            qemuDomainObjExitMonitor(vm);
+        }

-    if (!table)
-        return -1;
+        if (!table)
+            return -1;
+    }

     for (i = 0; i < vm->def->ndisks; i++) {
         virDomainDiskDef *disk = vm->def->disks[i];
@@ -8661,6 +8664,14 @@ qemuProcessRefreshDisks(virDomainObj *vm,
         struct qemuDomainDiskInfo *info;
         const char *entryname = disk->info.alias;

+        /* At startup, when the rest of the detection will be skipped cdroms
+         * have empty trays */
+        if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM)
+            disk->tray_status = VIR_DOMAIN_DISK_TRAY_CLOSED;
+
+        if (!table)
+            continue;
+
         if (diskpriv->qomName)
             entryname = diskpriv->qomName;

@@ -8690,15 +8701,17 @@ qemuProcessRefreshDisks(virDomainObj *vm,
 /**
  * qemuProcessRefreshState:
  * @vm: domain to refresh
+ * @cold_boot: starting a fresh VM
  * @asyncJob: async job type
  *
  * This function gathers calls to refresh qemu state after startup. This
  * function is called after a deferred migration finishes so that we can update
  * state influenced by the migration stream.
  */
-int
-qemuProcessRefreshState(virDomainObj *vm,
-                        virDomainAsyncJob asyncJob)
+static int
+qemuProcessRefreshStateInternal(virDomainObj *vm,
+                                bool cold_boot,
+                                virDomainAsyncJob asyncJob)
 {
     VIR_DEBUG("Fetching list of active devices");
     if (qemuDomainUpdateDeviceList(vm, asyncJob) < 0)
@@ -8713,7 +8726,7 @@ qemuProcessRefreshState(virDomainObj *vm,
         return -1;

     VIR_DEBUG("Updating disk data");
-    if (qemuProcessRefreshDisks(vm, asyncJob) < 0)
+    if (qemuProcessRefreshDisks(vm, cold_boot, asyncJob) < 0)
         return -1;

     VIR_DEBUG("Updating rx-filter data");
@@ -8724,6 +8737,14 @@ qemuProcessRefreshState(virDomainObj *vm,
 }


+int
+qemuProcessRefreshState(virDomainObj *vm,
+                        virDomainAsyncJob asyncJob)
+{
+    return qemuProcessRefreshStateInternal(vm, false, asyncJob);
+}
+
+
 /**
  * qemuProcessFinishStartup:
  *
@@ -8836,7 +8857,9 @@ qemuProcessStart(virConnectPtr conn,
         /* Refresh state of devices from QEMU. During migration this happens
          * in qemuMigrationDstFinish to ensure that state information is fully
          * transferred. */
-        if (qemuProcessRefreshState(vm, asyncJob) < 0)
+        if (qemuProcessRefreshStateInternal(vm,
+                                            !!(flags & 
VIR_QEMU_PROCESS_START_COLD),
+                                            asyncJob) < 0)
             goto stop;
     }

@@ -9930,7 +9953,7 @@ qemuProcessReconnect(void *opaque)

     qemuProcessFiltersInstantiate(obj->def);

-    if (qemuProcessRefreshDisks(obj, VIR_ASYNC_JOB_NONE) < 0)
+    if (qemuProcessRefreshDisks(obj, false, VIR_ASYNC_JOB_NONE) < 0)
         goto error;

     /* At this point we've already checked that the startup of the VM was
-- 
2.53.0

Reply via email to