From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36276) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZXWdL-0005Mi-G0 for qemu-devel@nongnu.org; Thu, 03 Sep 2015 11:41:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZXWdH-00088L-Dk for qemu-devel@nongnu.org; Thu, 03 Sep 2015 11:41:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59387) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZXWdG-00087K-V4 for qemu-devel@nongnu.org; Thu, 03 Sep 2015 11:40:59 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id A8C41461D4 for ; Thu, 3 Sep 2015 15:40:58 +0000 (UTC) From: "Daniel P. Berrange" Date: Thu, 3 Sep 2015 16:39:16 +0100 Message-Id: <1441294768-8712-35-git-send-email-berrange@redhat.com> In-Reply-To: <1441294768-8712-1-git-send-email-berrange@redhat.com> References: <1441294768-8712-1-git-send-email-berrange@redhat.com> Subject: [Qemu-devel] [PATCH FYI 34/46] migration: introduce qemu_fset_blocking function on QEMUFile List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Juan Quintela , "Dr. David Alan Gilbert" , Gerd Hoffmann , Amit Shah , Paolo Bonzini 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 --- 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