From patchwork Mon Apr 15 08:22:34 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 236522 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 15B032C00BE for ; Mon, 15 Apr 2013 18:23:30 +1000 (EST) Received: from localhost ([::1]:47668 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1URehE-00088p-7b for incoming@patchwork.ozlabs.org; Mon, 15 Apr 2013 04:23:28 -0400 Received: from eggs.gnu.org ([208.118.235.92]:46772) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1URege-00082o-Ac for qemu-devel@nongnu.org; Mon, 15 Apr 2013 04:22:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1URegb-0007ZC-9W for qemu-devel@nongnu.org; Mon, 15 Apr 2013 04:22:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39683) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1URega-0007Z6-RV for qemu-devel@nongnu.org; Mon, 15 Apr 2013 04:22:49 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r3F8Mmmt005679 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 15 Apr 2013 04:22:48 -0400 Received: from localhost (ovpn-112-19.ams2.redhat.com [10.36.112.19]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r3F8Mkcj029659; Mon, 15 Apr 2013 04:22:47 -0400 From: Stefan Hajnoczi To: Date: Mon, 15 Apr 2013 10:22:34 +0200 Message-Id: <1366014164-17557-2-git-send-email-stefanha@redhat.com> In-Reply-To: <1366014164-17557-1-git-send-email-stefanha@redhat.com> References: <1366014164-17557-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Anthony Liguori Subject: [Qemu-devel] [PATCH 01/11] block: Introduce bdrv_writev_vmstate 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: Kevin Wolf Signed-off-by: Kevin Wolf Signed-off-by: Stefan Hajnoczi --- block.c | 25 ++++++++++++++++++++----- block/qcow2.c | 12 +++++++++--- block/sheepdog.c | 13 ++++++++++--- include/block/block.h | 1 + include/block/block_int.h | 4 ++-- 5 files changed, 42 insertions(+), 13 deletions(-) diff --git a/block.c b/block.c index 602d8a4..175497e 100644 --- a/block.c +++ b/block.c @@ -3184,13 +3184,28 @@ int bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) int bdrv_save_vmstate(BlockDriverState *bs, const uint8_t *buf, int64_t pos, int size) { + QEMUIOVector qiov; + struct iovec iov = { + .iov_base = (void *) buf, + .iov_len = size, + }; + + qemu_iovec_init_external(&qiov, &iov, 1); + return bdrv_writev_vmstate(bs, &qiov, pos); +} + +int bdrv_writev_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos) +{ BlockDriver *drv = bs->drv; - if (!drv) + + if (!drv) { return -ENOMEDIUM; - if (drv->bdrv_save_vmstate) - return drv->bdrv_save_vmstate(bs, buf, pos, size); - if (bs->file) - return bdrv_save_vmstate(bs->file, buf, pos, size); + } else if (drv->bdrv_save_vmstate) { + return drv->bdrv_save_vmstate(bs, qiov, pos); + } else if (bs->file) { + return bdrv_writev_vmstate(bs->file, qiov, pos); + } + return -ENOTSUP; } diff --git a/block/qcow2.c b/block/qcow2.c index 1d18073..1d856af 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1652,18 +1652,24 @@ static void dump_refcounts(BlockDriverState *bs) } #endif -static int qcow2_save_vmstate(BlockDriverState *bs, const uint8_t *buf, - int64_t pos, int size) +static int qcow2_save_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, + int64_t pos) { BDRVQcowState *s = bs->opaque; int growable = bs->growable; int ret; + void *buf; + + buf = qemu_blockalign(bs, qiov->size); + qemu_iovec_to_buf(qiov, 0, buf, qiov->size); BLKDBG_EVENT(bs->file, BLKDBG_VMSTATE_SAVE); bs->growable = 1; - ret = bdrv_pwrite(bs, qcow2_vm_state_offset(s) + pos, buf, size); + ret = bdrv_pwrite(bs, qcow2_vm_state_offset(s) + pos, buf, qiov->size); bs->growable = growable; + qemu_vfree(buf); + return ret; } diff --git a/block/sheepdog.c b/block/sheepdog.c index 987018e..1c5b532 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -2054,12 +2054,19 @@ cleanup: return ret; } -static int sd_save_vmstate(BlockDriverState *bs, const uint8_t *data, - int64_t pos, int size) +static int sd_save_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, + int64_t pos) { BDRVSheepdogState *s = bs->opaque; + void *buf; + int ret; - return do_load_save_vmstate(s, (uint8_t *)data, pos, size, 0); + buf = qemu_blockalign(bs, qiov->size); + qemu_iovec_to_buf(qiov, 0, buf, qiov->size); + ret = do_load_save_vmstate(s, (uint8_t *) buf, pos, qiov->size, 0); + qemu_vfree(buf); + + return ret; } static int sd_load_vmstate(BlockDriverState *bs, uint8_t *data, diff --git a/include/block/block.h b/include/block/block.h index 9dc6aad..e5fc566 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -348,6 +348,7 @@ void path_combine(char *dest, int dest_size, const char *base_path, const char *filename); +int bdrv_writev_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos); int bdrv_save_vmstate(BlockDriverState *bs, const uint8_t *buf, int64_t pos, int size); diff --git a/include/block/block_int.h b/include/block/block_int.h index 9aa98b5..458cde3 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -164,8 +164,8 @@ struct BlockDriver { const char *snapshot_name); int (*bdrv_get_info)(BlockDriverState *bs, BlockDriverInfo *bdi); - int (*bdrv_save_vmstate)(BlockDriverState *bs, const uint8_t *buf, - int64_t pos, int size); + int (*bdrv_save_vmstate)(BlockDriverState *bs, QEMUIOVector *qiov, + int64_t pos); int (*bdrv_load_vmstate)(BlockDriverState *bs, uint8_t *buf, int64_t pos, int size);