[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 27/40] vdi: Use BB functions in .bdrv_create()
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 27/40] vdi: Use BB functions in .bdrv_create() |
Date: |
Mon, 14 Mar 2016 18:37:28 +0100 |
All users of the block layers are supposed to go through a BlockBackend.
The .bdrv_create() implementation is one such user, so this patch
converts it.
Signed-off-by: Kevin Wolf <address@hidden>
---
block/vdi.c | 23 ++++++++++++++---------
1 file changed, 14 insertions(+), 9 deletions(-)
diff --git a/block/vdi.c b/block/vdi.c
index 12407c4..662d14b 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -52,6 +52,7 @@
#include "qemu/osdep.h"
#include "qemu-common.h"
#include "block/block_int.h"
+#include "sysemu/block-backend.h"
#include "qemu/module.h"
#include "migration/migration.h"
#include "qemu/coroutine.h"
@@ -733,7 +734,7 @@ static int vdi_create(const char *filename, QemuOpts *opts,
Error **errp)
size_t bmap_size;
int64_t offset = 0;
Error *local_err = NULL;
- BlockDriverState *bs = NULL;
+ BlockBackend *blk = NULL;
uint32_t *bmap = NULL;
logout("\n");
@@ -766,14 +767,18 @@ static int vdi_create(const char *filename, QemuOpts
*opts, Error **errp)
error_propagate(errp, local_err);
goto exit;
}
- ret = bdrv_open(&bs, filename, NULL, NULL,
- BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_PROTOCOL,
- &local_err);
- if (ret < 0) {
+
+ blk = blk_new_open("image", filename, NULL, NULL,
+ BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_PROTOCOL,
+ &local_err);
+ if (blk == NULL) {
error_propagate(errp, local_err);
+ ret = -EIO;
goto exit;
}
+ blk_set_allow_write_beyond_eof(blk, true);
+
/* We need enough blocks to store the given disk size,
so always round up. */
blocks = DIV_ROUND_UP(bytes, block_size);
@@ -803,7 +808,7 @@ static int vdi_create(const char *filename, QemuOpts *opts,
Error **errp)
vdi_header_print(&header);
#endif
vdi_header_to_le(&header);
- ret = bdrv_pwrite_sync(bs, offset, &header, sizeof(header));
+ ret = blk_pwrite(blk, offset, &header, sizeof(header));
if (ret < 0) {
error_setg(errp, "Error writing header to %s", filename);
goto exit;
@@ -824,7 +829,7 @@ static int vdi_create(const char *filename, QemuOpts *opts,
Error **errp)
bmap[i] = VDI_UNALLOCATED;
}
}
- ret = bdrv_pwrite_sync(bs, offset, bmap, bmap_size);
+ ret = blk_pwrite(blk, offset, bmap, bmap_size);
if (ret < 0) {
error_setg(errp, "Error writing bmap to %s", filename);
goto exit;
@@ -833,7 +838,7 @@ static int vdi_create(const char *filename, QemuOpts *opts,
Error **errp)
}
if (image_type == VDI_TYPE_STATIC) {
- ret = bdrv_truncate(bs, offset + blocks * block_size);
+ ret = blk_truncate(blk, offset + blocks * block_size);
if (ret < 0) {
error_setg(errp, "Failed to statically allocate %s", filename);
goto exit;
@@ -841,7 +846,7 @@ static int vdi_create(const char *filename, QemuOpts *opts,
Error **errp)
}
exit:
- bdrv_unref(bs);
+ blk_unref(blk);
g_free(bmap);
return ret;
}
--
1.8.3.1
- [Qemu-devel] [PULL 22/40] parallels: Use BB functions in .bdrv_create(), (continued)
- [Qemu-devel] [PULL 22/40] parallels: Use BB functions in .bdrv_create(), Kevin Wolf, 2016/03/14
- [Qemu-devel] [PULL 20/40] block: Use writeback in .bdrv_create() implementations, Kevin Wolf, 2016/03/14
- [Qemu-devel] [PULL 19/40] hmp: Extend drive_del to delete nodes without BB, Kevin Wolf, 2016/03/14
- [Qemu-devel] [PULL 24/40] qcow2: Use BB functions in .bdrv_create(), Kevin Wolf, 2016/03/14
- [Qemu-devel] [PULL 25/40] qed: Use BB functions in .bdrv_create(), Kevin Wolf, 2016/03/14
- [Qemu-devel] [PULL 18/40] hmp: 'drive_add -n' for creating a node without BB, Kevin Wolf, 2016/03/14
- [Qemu-devel] [PULL 29/40] vmdk: Use BB functions in .bdrv_create(), Kevin Wolf, 2016/03/14
- [Qemu-devel] [PULL 30/40] vpc: Use BB functions in .bdrv_create(), Kevin Wolf, 2016/03/14
- [Qemu-devel] [PULL 28/40] vhdx: Use BB functions in .bdrv_create(), Kevin Wolf, 2016/03/14
- [Qemu-devel] [PULL 26/40] sheepdog: Use BB functions in .bdrv_create(), Kevin Wolf, 2016/03/14
- [Qemu-devel] [PULL 27/40] vdi: Use BB functions in .bdrv_create(),
Kevin Wolf <=
- [Qemu-devel] [PULL 32/40] block: Include hbitmap.h in block.h, Kevin Wolf, 2016/03/14
- [Qemu-devel] [PULL 33/40] typedefs: Add BdrvDirtyBitmap, Kevin Wolf, 2016/03/14
- [Qemu-devel] [PULL 37/40] quorum: Fix crash in quorum_aio_cb(), Kevin Wolf, 2016/03/14
- [Qemu-devel] [PULL 39/40] monitor: Use QEMU_CLOCK_VIRTUAL for the event queue in qtest mode, Kevin Wolf, 2016/03/14
- [Qemu-devel] [PULL 36/40] iotests: Correct 081's reference output, Kevin Wolf, 2016/03/14
- [Qemu-devel] [PULL 31/40] backup: Use Bitmap to replace "s->bitmap", Kevin Wolf, 2016/03/14
- [Qemu-devel] [PULL 35/40] block: Remove unused typedef of BlockDriverDirtyHandler, Kevin Wolf, 2016/03/14
- [Qemu-devel] [PULL 40/40] iotests: Add test for QMP event rates, Kevin Wolf, 2016/03/14
- [Qemu-devel] [PULL 38/40] monitor: Separate QUORUM_REPORT_BAD events according to the node name, Kevin Wolf, 2016/03/14
- [Qemu-devel] [PULL 34/40] block: Move block dirty bitmap code to separate files, Kevin Wolf, 2016/03/14