thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
22c213
From d84814e298e3b05fb5bc61cc8e641a5e104d32d5 Mon Sep 17 00:00:00 2001
22c213
From: Juan Quintela <quintela@redhat.com>
22c213
Date: Tue, 3 Mar 2020 14:51:39 +0000
22c213
Subject: [PATCH 07/18] qemu-file: Don't do IO after shutdown
22c213
22c213
RH-Author: Juan Quintela <quintela@redhat.com>
22c213
Message-id: <20200303145143.149290-7-quintela@redhat.com>
22c213
Patchwork-id: 94116
22c213
O-Subject: [RHEL-AV-8.2.0 qemu-kvm PATCH v2 06/10] qemu-file: Don't do IO after shutdown
22c213
Bugzilla: 1738451
22c213
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
22c213
RH-Acked-by: Peter Xu <peterx@redhat.com>
22c213
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
22c213
22c213
Be sure that we are not doing neither read/write after shutdown of the
22c213
QEMUFile.
22c213
22c213
Signed-off-by: Juan Quintela <quintela@redhat.com>
22c213
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
22c213
(cherry picked from commit a555b8092abc6f1bbe4b64c516679cbd68fcfbd8)
22c213
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
22c213
---
22c213
 migration/qemu-file.c | 22 +++++++++++++++++++++-
22c213
 1 file changed, 21 insertions(+), 1 deletion(-)
22c213
22c213
diff --git a/migration/qemu-file.c b/migration/qemu-file.c
22c213
index 26fb25d..bbb2b63 100644
22c213
--- a/migration/qemu-file.c
22c213
+++ b/migration/qemu-file.c
22c213
@@ -53,6 +53,8 @@ struct QEMUFile {
22c213
 
22c213
     int last_error;
22c213
     Error *last_error_obj;
22c213
+    /* has the file has been shutdown */
22c213
+    bool shutdown;
22c213
 };
22c213
 
22c213
 /*
22c213
@@ -61,10 +63,18 @@ struct QEMUFile {
22c213
  */
22c213
 int qemu_file_shutdown(QEMUFile *f)
22c213
 {
22c213
+    int ret;
22c213
+
22c213
+    f->shutdown = true;
22c213
     if (!f->ops->shut_down) {
22c213
         return -ENOSYS;
22c213
     }
22c213
-    return f->ops->shut_down(f->opaque, true, true, NULL);
22c213
+    ret = f->ops->shut_down(f->opaque, true, true, NULL);
22c213
+
22c213
+    if (!f->last_error) {
22c213
+        qemu_file_set_error(f, -EIO);
22c213
+    }
22c213
+    return ret;
22c213
 }
22c213
 
22c213
 /*
22c213
@@ -214,6 +224,9 @@ void qemu_fflush(QEMUFile *f)
22c213
         return;
22c213
     }
22c213
 
22c213
+    if (f->shutdown) {
22c213
+        return;
22c213
+    }
22c213
     if (f->iovcnt > 0) {
22c213
         expect = iov_size(f->iov, f->iovcnt);
22c213
         ret = f->ops->writev_buffer(f->opaque, f->iov, f->iovcnt, f->pos,
22c213
@@ -328,6 +341,10 @@ static ssize_t qemu_fill_buffer(QEMUFile *f)
22c213
     f->buf_index = 0;
22c213
     f->buf_size = pending;
22c213
 
22c213
+    if (f->shutdown) {
22c213
+        return 0;
22c213
+    }
22c213
+
22c213
     len = f->ops->get_buffer(f->opaque, f->buf + pending, f->pos,
22c213
                              IO_BUF_SIZE - pending, &local_error);
22c213
     if (len > 0) {
22c213
@@ -642,6 +659,9 @@ int64_t qemu_ftell(QEMUFile *f)
22c213
 
22c213
 int qemu_file_rate_limit(QEMUFile *f)
22c213
 {
22c213
+    if (f->shutdown) {
22c213
+        return 1;
22c213
+    }
22c213
     if (qemu_file_get_error(f)) {
22c213
         return 1;
22c213
     }
22c213
-- 
22c213
1.8.3.1
22c213