]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuMonitorBlockJobInfo: Store 'ready' and 'ready_present' separately
authorPeter Krempa <pkrempa@redhat.com>
Fri, 4 Dec 2020 15:07:58 +0000 (16:07 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 7 Dec 2020 09:15:00 +0000 (10:15 +0100)
Don't make the logic confusing by representing the 3 options using an
integer with negative values.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
src/qemu/qemu_driver.c
src/qemu/qemu_monitor.h
src/qemu/qemu_monitor_json.c
src/qemu/qemu_process.c

index 4fd70ed30064f9a0114aa4e386a938f6e1ff71bc..800f98e4741ab5f1efc4c7e46d653050528f8e7d 100644 (file)
@@ -14650,17 +14650,18 @@ qemuBlockJobInfoTranslate(qemuMonitorBlockJobInfoPtr rawInfo,
      * and end are zero, in which case qemu hasn't started the
      * job yet. */
     if (!info->cur && !info->end) {
-        if (rawInfo->ready > 0) {
-            info->cur = info->end = 1;
-        } else if (!rawInfo->ready) {
+        if (rawInfo->ready_present) {
             info->end = 1;
+            if (rawInfo->ready)
+                info->cur = 1;
         }
     }
 
     /* If qemu reports that it's not ready yet don't make the job go to
      * cur == end as some apps wrote code polling this instead of waiting for
      * the ready event */
-    if (rawInfo->ready == 0 &&
+    if (rawInfo->ready_present &&
+        !rawInfo->ready &&
         info->cur == info->end &&
         info->cur > 0)
         info->cur -= 1;
index 49be2d5412b3b8da15b85e786472be6b7ab14c0b..a2f28f949217d0ef9b2e58d3779c11a95a5e3b70 100644 (file)
@@ -1117,7 +1117,8 @@ struct _qemuMonitorBlockJobInfo {
     unsigned long long bandwidth; /* in bytes/s */
     virDomainBlockJobCursor cur;
     virDomainBlockJobCursor end;
-    int ready; /* -1 if unknown, 0 if not ready, 1 if ready */
+    bool ready_present;
+    bool ready;
 };
 
 GHashTable *qemuMonitorGetAllBlockJobInfo(qemuMonitorPtr mon,
index 8480338f469d5e72e9e0f6754ff2aa19ce6b9e7c..936254f0ec4d9e66f2f0c49a09681d0a510782c3 100644 (file)
@@ -5049,7 +5049,6 @@ qemuMonitorJSONParseBlockJobInfo(GHashTable *blockJobs,
     qemuMonitorBlockJobInfoPtr info = NULL;
     const char *device;
     const char *type;
-    bool ready;
 
     if (!(device = virJSONValueObjectGetString(entry, "device"))) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -5067,9 +5066,6 @@ qemuMonitorJSONParseBlockJobInfo(GHashTable *blockJobs,
         return -1;
     }
 
-    /* assume we don't know the state */
-    info->ready = -1;
-
     if (!(type = virJSONValueObjectGetString(entry, "type"))) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("entry was missing 'type'"));
@@ -5104,8 +5100,8 @@ qemuMonitorJSONParseBlockJobInfo(GHashTable *blockJobs,
         return -1;
     }
 
-    if (virJSONValueObjectGetBoolean(entry, "ready", &ready) == 0)
-        info->ready = ready;
+    if (virJSONValueObjectGetBoolean(entry, "ready", &info->ready) == 0)
+        info->ready_present = true;
 
     return 0;
 }
index 9d83825190f02bd59c64607769402544bdff6cc7..cbd29d867b126d715c3f2d7e21fe5f6316c7c081 100644 (file)
@@ -8176,8 +8176,8 @@ qemuProcessRefreshLegacyBlockjob(void *payload,
         return -1;
 
     if (disk->mirror) {
-        if (info->ready == 1 ||
-            (info->ready == -1 && info->end == info->cur)) {
+        if ((!info->ready_present && info->end == info->cur) ||
+            info->ready) {
             disk->mirrorState = VIR_DOMAIN_DISK_MIRROR_STATE_READY;
             job->state = VIR_DOMAIN_BLOCK_JOB_READY;
         }