From patchwork Wed Apr 21 05:57:18 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshiaki Tamura X-Patchwork-Id: 93825 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o3L62Lmu005310 for ; Wed, 21 Apr 2010 06:02:53 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751955Ab0DUGCV (ORCPT ); Wed, 21 Apr 2010 02:02:21 -0400 Received: from sh.osrg.net ([192.16.179.4]:58783 "EHLO sh.osrg.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752034Ab0DUGCC (ORCPT ); Wed, 21 Apr 2010 02:02:02 -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 o3L61Qjq004106; Wed, 21 Apr 2010 15:01:26 +0900 Received: from localhost (hype-wd0.osrg.net [10.72.1.16]) by fs.osrg.net (Postfix) with ESMTP id 3F7D13E02FA; Wed, 21 Apr 2010 15:01:25 +0900 (JST) From: Yoshiaki Tamura To: kvm@vger.kernel.org, qemu-devel@nongnu.org Cc: avi@redhat.com, aliguori@us.ibm.com, mtosatti@redhat.com, ohmura.kei@lab.ntt.co.jp, yoshikawa.takuya@oss.ntt.co.jp, Yoshiaki Tamura Subject: [RFC PATCH 13/20] Introduce util functions to control ft_transaction from savevm layer. Date: Wed, 21 Apr 2010 14:57:18 +0900 Message-Id: <1271829445-5328-14-git-send-email-tamura.yoshiaki@lab.ntt.co.jp> X-Mailer: git-send-email 1.7.0.31.g1df487 In-Reply-To: <1271829445-5328-1-git-send-email-tamura.yoshiaki@lab.ntt.co.jp> References: <1271829445-5328-1-git-send-email-tamura.yoshiaki@lab.ntt.co.jp> X-Dispatcher: imput version 20070423(IM149) Lines: 108 X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Wed, 21 Apr 2010 06:02:53 +0000 (UTC) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-3.0 (sh.osrg.net [192.16.179.4]); Wed, 21 Apr 2010 15:01:26 +0900 (JST) X-Virus-Scanned: clamav-milter 0.95.3 at sh X-Virus-Status: Clean Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org diff --git a/hw/hw.h b/hw/hw.h index 10e6dda..fcee660 100644 --- a/hw/hw.h +++ b/hw/hw.h @@ -70,6 +70,8 @@ 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_transaction(int fd); +QEMUFile *qemu_fopen_tranx_sender(void *opaque); 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); @@ -81,6 +83,9 @@ void qemu_put_vector(QEMUFile *f, QEMUIOVector *qiov); void qemu_put_vector_prepare(QEMUFile *f); void *qemu_realloc_buffer(QEMUFile *f, int size); void qemu_clear_buffer(QEMUFile *f); +int qemu_transaction_begin(QEMUFile *f); +int qemu_transaction_commit(QEMUFile *f); +int qemu_transaction_cancel(QEMUFile *f); static inline void qemu_put_ubyte(QEMUFile *f, unsigned int v) { diff --git a/savevm.c b/savevm.c index a401b27..292ae32 100644 --- a/savevm.c +++ b/savevm.c @@ -82,6 +82,7 @@ #include "migration.h" #include "qemu_socket.h" #include "qemu-queue.h" +#include "ft_transaction.h" /* point to the block driver where the snapshots are managed */ static BlockDriverState *bs_snapshots; @@ -210,6 +211,21 @@ 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; @@ -338,6 +354,16 @@ QEMUFile *qemu_fopen_socket(int fd) return s->file; } +QEMUFile *qemu_fopen_transaction(int fd) +{ + QEMUFileSocket *s = qemu_mallocz(sizeof(QEMUFileSocket)); + + s->fd = fd; + s->file = qemu_fopen_ops_ft_tranx(s, socket_put_buffer, NULL, + socket_get_buffer, NULL, socket_close, 0); + return s->file; +} + static int file_put_buffer(void *opaque, const uint8_t *buf, int64_t pos, int size) { @@ -485,6 +511,21 @@ void qemu_clear_buffer(QEMUFile *f) memset(f->buf, 0, f->buf_max_size); } +int qemu_transaction_begin(QEMUFile *f) +{ + return qemu_ft_tranx_begin(f->opaque); +} + +int qemu_transaction_commit(QEMUFile *f) +{ + return qemu_ft_tranx_commit(f->opaque); +} + +int qemu_transaction_cancel(QEMUFile *f) +{ + return qemu_ft_tranx_cancel(f->opaque); +} + static void qemu_fill_buffer(QEMUFile *f) { int len;