From patchwork Tue Oct 30 08:32:44 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaku Yamahata X-Patchwork-Id: 195389 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E4C452C00B4 for ; Tue, 30 Oct 2012 21:13:52 +1100 (EST) Received: from localhost ([::1]:45740 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TT7Gl-0004xz-Gl for incoming@patchwork.ozlabs.org; Tue, 30 Oct 2012 04:33:55 -0400 Received: from eggs.gnu.org ([208.118.235.92]:60766) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TT7GJ-0004j1-1r for qemu-devel@nongnu.org; Tue, 30 Oct 2012 04:33:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TT7GC-0000Y2-7F for qemu-devel@nongnu.org; Tue, 30 Oct 2012 04:33:26 -0400 Received: from mail.valinux.co.jp ([210.128.90.3]:44734) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TT7GB-0000XC-Ow for qemu-devel@nongnu.org; Tue, 30 Oct 2012 04:33:20 -0400 Received: from ps.local.valinux.co.jp (vagw.valinux.co.jp [210.128.90.14]) by mail.valinux.co.jp (Postfix) with SMTP id EE0F3181BD; Tue, 30 Oct 2012 17:33:12 +0900 (JST) Received: (nullmailer pid 29418 invoked by uid 1000); Tue, 30 Oct 2012 08:33:12 -0000 From: Isaku Yamahata To: qemu-devel@nongnu.org, kvm@vger.kernel.org Date: Tue, 30 Oct 2012 17:32:44 +0900 Message-Id: <87938ad888dca9ad4c80b559b37233200c45f466.1351582535.git.yamahata@valinux.co.jp> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: References: In-Reply-To: References: X-Virus-Scanned: clamav-milter 0.95.2 at va-mail.local.valinux.co.jp X-Virus-Status: Clean X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 210.128.90.3 Cc: benoit.hudzia@gmail.com, aarcange@redhat.com, aliguori@us.ibm.com, quintela@redhat.com, stefanha@gmail.com, t.hirofuchi@aist.go.jp, dlaor@redhat.com, satoshi.itoh@aist.go.jp, mdroth@linux.vnet.ibm.com, yoshikawa.takuya@oss.ntt.co.jp, owasserm@redhat.com, avi@redhat.com, pbonzini@redhat.com, chegu_vinod@hp.com Subject: [Qemu-devel] [PATCH v3 08/35] savevm/QEMUFile: consolidate QEMUFile functions a bit X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org - add qemu_file_fd() for later use - drop qemu_stdio_fd Now qemu_file_fd() replaces qemu_stdio_fd(). - savevm/QEMUFileSocket: drop duplicated member fd fd is already stored in QEMUFile so drop duplicated member QEMUFileSocket::fd. - remove QEMUFileSocket Signed-off-by: Isaku Yamahata --- migration-exec.c | 4 ++-- migration-fd.c | 2 +- qemu-file.h | 2 +- savevm.c | 40 +++++++++++++++++++--------------------- 4 files changed, 23 insertions(+), 25 deletions(-) diff --git a/migration-exec.c b/migration-exec.c index 6c97db9..95e9779 100644 --- a/migration-exec.c +++ b/migration-exec.c @@ -98,7 +98,7 @@ static void exec_accept_incoming_migration(void *opaque) QEMUFile *f = opaque; process_incoming_migration(f); - qemu_set_fd_handler2(qemu_stdio_fd(f), NULL, NULL, NULL, NULL); + qemu_set_fd_handler2(qemu_file_fd(f), NULL, NULL, NULL, NULL); qemu_fclose(f); } @@ -113,7 +113,7 @@ int exec_start_incoming_migration(const char *command) return -errno; } - qemu_set_fd_handler2(qemu_stdio_fd(f), NULL, + qemu_set_fd_handler2(qemu_file_fd(f), NULL, exec_accept_incoming_migration, NULL, f); return 0; diff --git a/migration-fd.c b/migration-fd.c index 7335167..b3c54e5 100644 --- a/migration-fd.c +++ b/migration-fd.c @@ -104,7 +104,7 @@ static void fd_accept_incoming_migration(void *opaque) QEMUFile *f = opaque; process_incoming_migration(f); - qemu_set_fd_handler2(qemu_stdio_fd(f), NULL, NULL, NULL, NULL); + qemu_set_fd_handler2(qemu_file_fd(f), NULL, NULL, NULL, NULL); qemu_fclose(f); } diff --git a/qemu-file.h b/qemu-file.h index 9b6dd08..bc222dc 100644 --- a/qemu-file.h +++ b/qemu-file.h @@ -70,7 +70,7 @@ QEMUFile *qemu_fdopen(int fd, const char *mode); QEMUFile *qemu_fopen_socket(int fd); QEMUFile *qemu_popen(FILE *popen_file, const char *mode); QEMUFile *qemu_popen_cmd(const char *command, const char *mode); -int qemu_stdio_fd(QEMUFile *f); +int qemu_file_fd(QEMUFile *f); int qemu_fclose(QEMUFile *f); int qemu_fflush(QEMUFile *f); void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size); diff --git a/savevm.c b/savevm.c index 0c7af43..e24041b 100644 --- a/savevm.c +++ b/savevm.c @@ -178,6 +178,7 @@ struct QEMUFile { uint8_t buf[IO_BUF_SIZE]; int last_error; + int fd; /* -1 means fd isn't associated */ }; typedef struct QEMUFileStdio @@ -186,19 +187,18 @@ typedef struct QEMUFileStdio QEMUFile *file; } QEMUFileStdio; -typedef struct QEMUFileSocket +typedef struct QEMUFileFD { - int fd; QEMUFile *file; -} QEMUFileSocket; +} QEMUFileFD; static int socket_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size) { - QEMUFileSocket *s = opaque; + QEMUFileFD *s = opaque; ssize_t len; do { - len = qemu_recv(s->fd, buf, size, 0); + len = qemu_recv(s->file->fd, buf, size, 0); } while (len == -1 && socket_error() == EINTR); if (len == -1) @@ -207,9 +207,9 @@ static int socket_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size) return len; } -static int socket_close(void *opaque) +static int fd_close(void *opaque) { - QEMUFileSocket *s = opaque; + QEMUFileFD *s = opaque; g_free(s); return 0; } @@ -276,6 +276,7 @@ QEMUFile *qemu_popen(FILE *stdio_file, const char *mode) s->file = qemu_fopen_ops(s, stdio_put_buffer, NULL, stdio_pclose, NULL, NULL, NULL); } + s->file->fd = fileno(stdio_file); return s->file; } @@ -291,17 +292,6 @@ QEMUFile *qemu_popen_cmd(const char *command, const char *mode) return qemu_popen(popen_file, mode); } -int qemu_stdio_fd(QEMUFile *f) -{ - QEMUFileStdio *p; - int fd; - - p = (QEMUFileStdio *)f->opaque; - fd = fileno(p->stdio_file); - - return fd; -} - QEMUFile *qemu_fdopen(int fd, const char *mode) { QEMUFileStdio *s; @@ -325,6 +315,7 @@ QEMUFile *qemu_fdopen(int fd, const char *mode) s->file = qemu_fopen_ops(s, stdio_put_buffer, NULL, stdio_fclose, NULL, NULL, NULL); } + s->file->fd = fd; return s->file; fail: @@ -334,11 +325,11 @@ fail: QEMUFile *qemu_fopen_socket(int fd) { - QEMUFileSocket *s = g_malloc0(sizeof(QEMUFileSocket)); + QEMUFileFD *s = g_malloc0(sizeof(QEMUFileFD)); - s->fd = fd; - s->file = qemu_fopen_ops(s, NULL, socket_get_buffer, socket_close, + s->file = qemu_fopen_ops(s, NULL, socket_get_buffer, fd_close, NULL, NULL, NULL); + s->file->fd = fd; return s->file; } @@ -381,6 +372,7 @@ QEMUFile *qemu_fopen(const char *filename, const char *mode) s->file = qemu_fopen_ops(s, NULL, file_get_buffer, stdio_fclose, NULL, NULL, NULL); } + s->file->fd = fileno(s->stdio_file); return s->file; fail: g_free(s); @@ -431,10 +423,16 @@ QEMUFile *qemu_fopen_ops(void *opaque, QEMUFilePutBufferFunc *put_buffer, f->set_rate_limit = set_rate_limit; f->get_rate_limit = get_rate_limit; f->is_write = 0; + f->fd = -1; return f; } +int qemu_file_fd(QEMUFile *f) +{ + return f->fd; +} + int qemu_file_get_error(QEMUFile *f) { return f->last_error;