From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 08/11] vdi: Use BB functions in .bdrv_create()
Date: Tue, 8 Mar 2016 17:34:29 +0100 [thread overview]
Message-ID: <1457454872-12183-9-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1457454872-12183-1-git-send-email-kwolf@redhat.com>
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 <kwolf@redhat.com>
---
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
next prev parent reply other threads:[~2016-03-08 16:34 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-08 16:34 [Qemu-devel] [PATCH 00/11] block: Use BB function in .bdrv_create() implementations Kevin Wolf
2016-03-08 16:34 ` [Qemu-devel] [PATCH 01/11] block: Use writeback " Kevin Wolf
2016-03-09 12:14 ` Paolo Bonzini
2016-03-09 12:27 ` Kevin Wolf
2016-03-08 16:34 ` [Qemu-devel] [PATCH 02/11] block: Introduce blk_set_allow_write_beyond_eof() Kevin Wolf
2016-03-08 16:34 ` [Qemu-devel] [PATCH 03/11] parallels: Use BB functions in .bdrv_create() Kevin Wolf
2016-03-08 16:34 ` [Qemu-devel] [PATCH 04/11] qcow: " Kevin Wolf
2016-03-08 16:34 ` [Qemu-devel] [PATCH 05/11] qcow2: " Kevin Wolf
2016-03-08 16:34 ` [Qemu-devel] [PATCH 06/11] qed: " Kevin Wolf
2016-03-08 16:34 ` [Qemu-devel] [PATCH 07/11] sheepdog: " Kevin Wolf
2016-03-08 16:34 ` Kevin Wolf [this message]
2016-03-08 16:34 ` [Qemu-devel] [PATCH 09/11] vhdx: " Kevin Wolf
2016-03-08 16:34 ` [Qemu-devel] [PATCH 10/11] vmdk: " Kevin Wolf
2016-03-08 16:34 ` [Qemu-devel] [PATCH 11/11] vpc: " Kevin Wolf
2016-03-14 11:31 ` [Qemu-devel] [PATCH 00/11] block: Use BB function in .bdrv_create() implementations Kevin Wolf
2016-03-14 16:55 ` Max Reitz
2016-03-14 17:34 ` Kevin Wolf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1457454872-12183-9-git-send-email-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).