Don't make the logic confusing by representing the 3 options using an
integer with negative values.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/qemu/qemu_driver.c | 9 +++++----
src/qemu/qemu_monitor.h | 3 ++-
src/qemu/qemu_monitor_json.c | 8 ++------
src/qemu/qemu_process.c | 4 ++--
4 files changed, 11 insertions(+), 13 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 4fd70ed300..800f98e474 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -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;
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 49be2d5412..a2f28f9492 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -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,
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 4db00e284a..94e482cc97 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -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;
}
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 9d83825190..cbd29d867b 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -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;
}
--
2.28.0