From patchwork Tue Oct 30 08:32:45 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaku Yamahata X-Patchwork-Id: 195322 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 514C02C00A9 for ; Tue, 30 Oct 2012 19:33:39 +1100 (EST) Received: from localhost ([::1]:45317 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TT7GT-0004jY-6A for incoming@patchwork.ozlabs.org; Tue, 30 Oct 2012 04:33:37 -0400 Received: from eggs.gnu.org ([208.118.235.92]:60698) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TT7GE-0004hn-37 for qemu-devel@nongnu.org; Tue, 30 Oct 2012 04:33:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TT7GC-0000Xm-1w for qemu-devel@nongnu.org; Tue, 30 Oct 2012 04:33:22 -0400 Received: from mail.valinux.co.jp ([210.128.90.3]:44730) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TT7GB-0000Wz-Jt for qemu-devel@nongnu.org; Tue, 30 Oct 2012 04:33:19 -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 9CD27181B9; Tue, 30 Oct 2012 17:33:12 +0900 (JST) Received: (nullmailer pid 29420 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:45 +0900 Message-Id: <8debc2a867fdfa1f605a2f9d300267b552c8eb6b.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 09/35] savevm/QEMUFile: introduce qemu_fopen_fd 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 Introduce fd read/write backend of QEMUFile whose fd can be non-blocking This will be used by postcopy live migration. Signed-off-by: Isaku Yamahata --- qemu-file.h | 1 + savevm.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/qemu-file.h b/qemu-file.h index bc222dc..94557ea 100644 --- a/qemu-file.h +++ b/qemu-file.h @@ -68,6 +68,7 @@ QEMUFile *qemu_fopen_ops(void *opaque, QEMUFilePutBufferFunc *put_buffer, QEMUFile *qemu_fopen(const char *filename, const char *mode); QEMUFile *qemu_fdopen(int fd, const char *mode); QEMUFile *qemu_fopen_socket(int fd); +QEMUFile *qemu_fopen_fd(int fd, const char *mode); QEMUFile *qemu_popen(FILE *popen_file, const char *mode); QEMUFile *qemu_popen_cmd(const char *command, const char *mode); int qemu_file_fd(QEMUFile *f); diff --git a/savevm.c b/savevm.c index e24041b..712b7ae 100644 --- a/savevm.c +++ b/savevm.c @@ -207,6 +207,19 @@ static int socket_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size) return len; } +static int fd_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size) +{ + QEMUFileFD *s = opaque; + return qemu_read_full(s->file->fd, buf, size); +} + +static int fd_put_buffer(void *opaque, + const uint8_t *buf, int64_t pos, int size) +{ + QEMUFileFD *s = opaque; + return qemu_write_full(s->file->fd, buf, size); +} + static int fd_close(void *opaque) { QEMUFileFD *s = opaque; @@ -333,6 +346,28 @@ QEMUFile *qemu_fopen_socket(int fd) return s->file; } +QEMUFile *qemu_fopen_fd(int fd, const char *mode) +{ + QEMUFileFD *s; + + if (mode == NULL || (mode[0] != 'r' && mode[0] != 'w') || mode[1] != 0) { + fprintf(stderr, "qemu_fopen_fd: Argument validity check failed\n"); + return NULL; + } + + s = g_malloc0(sizeof(*s)); + if (mode[0] == 'r') { + s->file = qemu_fopen_ops(s, NULL, fd_get_buffer, fd_close, + NULL, NULL, NULL); + } else { + s->file = qemu_fopen_ops(s, fd_put_buffer, NULL, fd_close, + NULL, NULL, NULL); + } + + s->file->fd = fd; + return s->file; +} + static int file_put_buffer(void *opaque, const uint8_t *buf, int64_t pos, int size) {