@@ -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);
@@ -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);
}
@@ -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;
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 <berrange@redhat.com> --- include/migration/qemu-file.h | 6 ++++++ migration/migration.c | 4 +--- migration/qemu-file.c | 15 +++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-)