cryptospore / rpms / qemu-kvm

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