From patchwork Mon Apr 25 11:00:47 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: OHMURA Kei X-Patchwork-Id: 92727 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C1483B6F53 for ; Mon, 25 Apr 2011 21:04:54 +1000 (EST) Received: from localhost ([::1]:36317 helo=lists2.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QEJb1-0000Gp-Vp for incoming@patchwork.ozlabs.org; Mon, 25 Apr 2011 07:04:52 -0400 Received: from eggs.gnu.org ([140.186.70.92]:43587) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QEJaZ-0000EF-6Q for qemu-devel@nongnu.org; Mon, 25 Apr 2011 07:04:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QEJaX-0004qY-Jk for qemu-devel@nongnu.org; Mon, 25 Apr 2011 07:04:23 -0400 Received: from sh.osrg.net ([192.16.179.4]:50484) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QEJaW-0004pD-Uv for qemu-devel@nongnu.org; Mon, 25 Apr 2011 07:04:21 -0400 Received: from fs.osrg.net (postfix@fs.osrg.net [10.0.0.12]) by sh.osrg.net (8.14.3/8.14.3/OSRG-NET) with ESMTP id p3PB439W017072; Mon, 25 Apr 2011 20:04:03 +0900 Received: from localhost (klift-nh0.osrg.net [10.84.0.5]) by fs.osrg.net (Postfix) with ESMTP id 13D103E0307; Mon, 25 Apr 2011 20:04:01 +0900 (JST) From: OHMURA Kei To: qemu-devel@nongnu.org, kvm@vger.kernel.org Date: Mon, 25 Apr 2011 20:00:47 +0900 Message-Id: <1303729257-9034-9-git-send-email-ohmura.kei@lab.ntt.co.jp> X-Mailer: git-send-email 1.7.0.2 In-Reply-To: <1303729257-9034-1-git-send-email-ohmura.kei@lab.ntt.co.jp> References: <1303729257-9034-1-git-send-email-ohmura.kei@lab.ntt.co.jp> X-Dispatcher: imput version 20070423(IM149) Lines: 248 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-3.0 (sh.osrg.net [192.16.179.4]); Mon, 25 Apr 2011 20:04:05 +0900 (JST) X-Virus-Scanned: clamav-milter 0.97 at sh X-Virus-Status: Clean X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 192.16.179.4 Cc: kwolf@redhat.com, aliguori@us.ibm.com, mtosatti@redhat.com, ohmura.kei@lab.ntt.co.jp, ananth@in.ibm.com, mst@redhat.com, dlaor@redhat.com, vatsa@linux.vnet.ibm.com, Yoshiaki Tamura , blauwirbel@gmail.com, quintela@redhat.com, tamura.yoshiaki@gmail.com, avi@redhat.com, pbonzini@redhat.com, psuriset@linux.vnet.ibm.com, stefanha@linux.vnet.ibm.com Subject: [Qemu-devel] [PATCH 08/18] savevm: introduce util functions to control ft_trans_file from savevm layer. 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 From: Yoshiaki Tamura To utilize ft_trans_file function, savevm needs interfaces to be exported. Signed-off-by: Yoshiaki Tamura Signed-off-by: OHMURA Kei --- hw/hw.h | 5 ++ savevm.c | 150 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 155 insertions(+), 0 deletions(-) diff --git a/hw/hw.h b/hw/hw.h index f90ff15..2d4d595 100644 --- a/hw/hw.h +++ b/hw/hw.h @@ -51,6 +51,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_ft_trans(int s_fd, int c_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); @@ -60,6 +61,9 @@ void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size); void qemu_put_byte(QEMUFile *f, int v); void *qemu_realloc_buffer(QEMUFile *f, int size); void qemu_clear_buffer(QEMUFile *f); +int qemu_ft_trans_begin(QEMUFile *f); +int qemu_ft_trans_commit(QEMUFile *f); +int qemu_ft_trans_cancel(QEMUFile *f); static inline void qemu_put_ubyte(QEMUFile *f, unsigned int v) { @@ -94,6 +98,7 @@ void qemu_file_set_error(QEMUFile *f); * halted due to rate limiting or EAGAIN errors occur as it can be used to * resume output. */ void qemu_file_put_notify(QEMUFile *f); +void qemu_file_get_notify(void *opaque); static inline void qemu_put_be64s(QEMUFile *f, const uint64_t *pv) { diff --git a/savevm.c b/savevm.c index d017760..5b57e94 100644 --- a/savevm.c +++ b/savevm.c @@ -83,6 +83,7 @@ #include "qemu_socket.h" #include "qemu-queue.h" #include "cpus.h" +#include "ft_trans_file.h" #define SELF_ANNOUNCE_ROUNDS 5 @@ -190,6 +191,13 @@ typedef struct QEMUFileSocket QEMUFile *file; } QEMUFileSocket; +typedef struct QEMUFileSocketTrans +{ + int fd; + QEMUFileSocket *s; + VMChangeStateEntry *e; +} QEMUFileSocketTrans; + static int socket_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size) { QEMUFileSocket *s = opaque; @@ -205,6 +213,22 @@ static int socket_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size) return len; } +static ssize_t socket_put_buffer(void *opaque, const void *buf, size_t size) +{ + QEMUFileSocket *s = opaque; + ssize_t len; + + do { + len = send(s->fd, (void *)buf, size, 0); + } while (len == -1 && socket_error() == EINTR); + + if (len == -1) { + len = -socket_error(); + } + + return len; +} + static int socket_close(void *opaque) { QEMUFileSocket *s = opaque; @@ -212,6 +236,71 @@ static int socket_close(void *opaque) return 0; } +static int socket_trans_get_buffer(void *opaque, uint8_t *buf, int64_t pos, size_t size) +{ + QEMUFileSocketTrans *t = opaque; + QEMUFileSocket *s = t->s; + ssize_t len; + + len = socket_get_buffer(s, buf, pos, size); + + return len; +} + +static ssize_t socket_trans_put_buffer(void *opaque, const void *buf, size_t size) +{ + QEMUFileSocketTrans *t = opaque; + + return socket_put_buffer(t->s, buf, size); +} + +static int qemu_loadvm_state_no_header(QEMUFile *f); + +static int socket_trans_get_ready(void *opaque) +{ + QEMUFileSocketTrans *t = opaque; + QEMUFileSocket *s = t->s; + QEMUFile *f = s->file; + int ret = 0; + + ret = qemu_loadvm_state_no_header(f); + if (ret < 0) { + fprintf(stderr, + "socket_trans_get_ready: error while loading vmstate\n"); + } + + return ret; +} + +static int socket_trans_close(void *opaque) +{ + QEMUFileSocketTrans *t = opaque; + QEMUFileSocket *s = t->s; + + qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL); + qemu_set_fd_handler2(t->fd, NULL, NULL, NULL, NULL); + qemu_del_vm_change_state_handler(t->e); + close(s->fd); + close(t->fd); + qemu_free(s); + qemu_free(t); + + return 0; +} + +static void socket_trans_resume(void *opaque, int running, int reason) +{ + QEMUFileSocketTrans *t = opaque; + QEMUFileSocket *s = t->s; + + if (!running) { + return; + } + + qemu_announce_self(); + qemu_fclose(s->file); +} + static int stdio_put_buffer(void *opaque, const uint8_t *buf, int64_t pos, int size) { QEMUFileStdio *s = opaque; @@ -334,6 +423,26 @@ QEMUFile *qemu_fopen_socket(int fd) return s->file; } +QEMUFile *qemu_fopen_ft_trans(int s_fd, int c_fd) +{ + QEMUFileSocketTrans *t = qemu_mallocz(sizeof(QEMUFileSocketTrans)); + QEMUFileSocket *s = qemu_mallocz(sizeof(QEMUFileSocket)); + + t->s = s; + t->fd = s_fd; + t->e = qemu_add_vm_change_state_handler(socket_trans_resume, t); + + s->fd = c_fd; + s->file = qemu_fopen_ops_ft_trans(t, socket_trans_put_buffer, + socket_trans_get_buffer, NULL, + socket_trans_get_ready, + migrate_fd_wait_for_unfreeze, + socket_trans_close, 0); + socket_set_nonblock(s->fd); + + return s->file; +} + static int file_put_buffer(void *opaque, const uint8_t *buf, int64_t pos, int size) { @@ -470,6 +579,39 @@ void qemu_clear_buffer(QEMUFile *f) f->buf_size = f->buf_index = f->buf_offset = 0; } +int qemu_ft_trans_begin(QEMUFile *f) +{ + int ret; + ret = ft_trans_begin(f->opaque); + if (ret < 0) { + f->has_error = 1; + } + return ret; +} + +int qemu_ft_trans_commit(QEMUFile *f) +{ + int ret; + ret = ft_trans_commit(f->opaque); + if (ret == -EAGAIN) { + return 1; + } + if (ret < 0) { + f->has_error = 1; + } + return ret; +} + +int qemu_ft_trans_cancel(QEMUFile *f) +{ + int ret; + ret = ft_trans_cancel(f->opaque); + if (ret < 0) { + f->has_error = 1; + } + return ret; +} + static void qemu_fill_buffer(QEMUFile *f) { int len; @@ -505,6 +647,14 @@ void qemu_file_put_notify(QEMUFile *f) f->put_buffer(f->opaque, NULL, 0, 0); } +void qemu_file_get_notify(void *opaque) +{ + QEMUFile *f = opaque; + if (f->get_buffer(f->opaque, f->buf, 0, 0) < 0) { + f->has_error = 1; + } +} + void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size) { int l;