qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH FYI 34/46] migration: introduce qemu_fset_blocking f


From: Daniel P. Berrange
Subject: [Qemu-devel] [PATCH FYI 34/46] migration: introduce qemu_fset_blocking function on QEMUFile
Date: Thu, 3 Sep 2015 16:39:16 +0100

Remove the assumption that every QEMUFile implementation has
a file descriptor available by introducing a new function
to change the blocking state of a QEMUFile.

Provide a default impl of the new method based on the get_fd
method.

Signed-off-by: Daniel P. Berrange <address@hidden>
---
 include/migration/qemu-file.h |  6 ++++++
 migration/migration.c         |  4 +---
 migration/qemu-file.c         | 15 +++++++++++++++
 3 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/include/migration/qemu-file.h b/include/migration/qemu-file.h
index a4e5468..2625d9b 100644
--- a/include/migration/qemu-file.h
+++ b/include/migration/qemu-file.h
@@ -55,6 +55,10 @@ typedef int (QEMUFileCloseFunc)(void *opaque);
  */
 typedef int (QEMUFileGetFD)(void *opaque);
 
+/* Called to change the blocking mode of the file
+ */
+typedef int (QEMUFileSetBlocking)(void *opaque, bool enabled);
+
 /*
  * This function writes an iovec to file. The handler must write all
  * of the data or return a negative errno value.
@@ -103,6 +107,7 @@ typedef struct QEMUFileOps {
     QEMUFileGetBufferFunc *get_buffer;
     QEMUFileCloseFunc *close;
     QEMUFileGetFD *get_fd;
+    QEMUFileSetBlocking *set_blocking;
     QEMUFileWritevBufferFunc *writev_buffer;
     QEMUFileShutdownFunc *shut_down;
 } QEMUFileOps;
@@ -128,6 +133,7 @@ QEMUFile *qemu_fopen_socket(int fd, const char *mode);
 QEMUFile *qemu_popen_cmd(const char *command, const char *mode);
 void qemu_file_set_hooks(QEMUFile *f, const QEMUFileHooks *hooks);
 int qemu_get_fd(QEMUFile *f);
+int qemu_fset_blocking(QEMUFile *f, bool enabled);
 int qemu_fclose(QEMUFile *f);
 int64_t qemu_ftell(QEMUFile *f);
 int64_t qemu_ftell_fast(QEMUFile *f);
diff --git a/migration/migration.c b/migration/migration.c
index 662e77e..83a3960 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -317,11 +317,9 @@ static void process_incoming_migration_co(void *opaque)
 void process_incoming_migration(QEMUFile *f)
 {
     Coroutine *co = qemu_coroutine_create(process_incoming_migration_co);
-    int fd = qemu_get_fd(f);
 
-    assert(fd != -1);
     migrate_decompress_threads_create();
-    qemu_set_nonblock(fd);
+    qemu_fset_blocking(f, false);
     qemu_coroutine_enter(co, f);
 }
 
diff --git a/migration/qemu-file.c b/migration/qemu-file.c
index 9f42f5c..c8b0b79 100644
--- a/migration/qemu-file.c
+++ b/migration/qemu-file.c
@@ -270,6 +270,21 @@ int qemu_get_fd(QEMUFile *f)
     return -1;
 }
 
+int qemu_fset_blocking(QEMUFile *f, bool enabled)
+{
+    if (f->ops->set_blocking) {
+        return f->ops->set_blocking(f->opaque, enabled);
+    } else if (f->ops->get_fd) {
+        int fd = f->ops->get_fd(f->opaque);
+        if (enabled) {
+            qemu_set_block(fd);
+        } else {
+            qemu_set_nonblock(fd);
+        }
+    }
+    return -1;
+}
+
 void qemu_update_position(QEMUFile *f, size_t size)
 {
     f->pos += size;
-- 
2.4.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]