summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2013-04-05 21:27:53 +0200
committerStefan Hajnoczi <stefanha@redhat.com>2013-04-15 08:26:18 +0200
commitcf8074b3825f7229a20c60e679511592bde41340 (patch)
tree0d44731c8ec33903dd131295f76c8cd6da9b9c7a
parente2ec3f976803b360c70d9ae2ba13852fa5d11665 (diff)
downloadqemu-cf8074b3825f7229a20c60e679511592bde41340.zip
block: Introduce bdrv_writev_vmstate
Signed-off-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
-rw-r--r--block.c25
-rw-r--r--block/qcow2.c12
-rw-r--r--block/sheepdog.c13
-rw-r--r--include/block/block.h1
-rw-r--r--include/block/block_int.h4
5 files changed, 42 insertions, 13 deletions
diff --git a/block.c b/block.c
index 602d8a443e..175497e678 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 1d180732e9..1d856af80f 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 987018e20c..1c5b53220b 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 9dc6aada99..e5fc566fbc 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 9aa98b5d12..458cde3766 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);