From: Fam Zheng <famz@redhat.com>
To: qemu-devel@nongnu.org
Cc: qemu-block@nongnu.org, Fam Zheng <famz@redhat.com>,
Kevin Wolf <kwolf@redhat.com>, Max Reitz <mreitz@redhat.com>,
Eric Blake <eblake@redhat.com>,
Markus Armbruster <armbru@redhat.com>,
Michael Roth <mdroth@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH 2/5] vmdk: Refactor vmdk_create_extent
Date: Wed, 9 May 2018 13:57:59 +0800 [thread overview]
Message-ID: <20180509055802.28423-3-famz@redhat.com> (raw)
In-Reply-To: <20180509055802.28423-1-famz@redhat.com>
The extracted vmdk_init_extent takes a BlockBackend object and
initializes the format metadata. It is the common part between "qemu-img
create" and "blockdev-create".
Add a "BlockBackend *pbb" parameter to vmdk_create_extent, to return the
opened BB to the caller in the next patch.
Signed-off-by: Fam Zheng <famz@redhat.com>
---
block/vmdk.c | 71 +++++++++++++++++++++++++++++++++++++-----------------------
1 file changed, 44 insertions(+), 27 deletions(-)
diff --git a/block/vmdk.c b/block/vmdk.c
index 84f8bbe480..083942f806 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -1714,35 +1714,17 @@ static int coroutine_fn vmdk_co_pwrite_zeroes(BlockDriverState *bs,
return ret;
}
-static int vmdk_create_extent(const char *filename, int64_t filesize,
- bool flat, bool compress, bool zeroed_grain,
- QemuOpts *opts, Error **errp)
+static int vmdk_init_extent(BlockBackend *blk,
+ int64_t filesize, bool flat,
+ bool compress, bool zeroed_grain,
+ Error **errp)
{
int ret, i;
- BlockBackend *blk = NULL;
VMDK4Header header;
- Error *local_err = NULL;
uint32_t tmp, magic, grains, gd_sectors, gt_size, gt_count;
uint32_t *gd_buf = NULL;
int gd_buf_size;
- ret = bdrv_create_file(filename, opts, &local_err);
- if (ret < 0) {
- error_propagate(errp, local_err);
- goto exit;
- }
-
- blk = blk_new_open(filename, NULL, NULL,
- BDRV_O_RDWR | BDRV_O_RESIZE | 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);
-
if (flat) {
ret = blk_truncate(blk, filesize, PREALLOC_MODE_OFF, errp);
goto exit;
@@ -1836,18 +1818,53 @@ static int vmdk_create_extent(const char *filename, int64_t filesize,
gd_buf, gd_buf_size, 0);
if (ret < 0) {
error_setg(errp, QERR_IO_ERROR);
- goto exit;
}
ret = 0;
exit:
- if (blk) {
- blk_unref(blk);
- }
g_free(gd_buf);
return ret;
}
+static int vmdk_create_extent(const char *filename, int64_t filesize,
+ bool flat, bool compress, bool zeroed_grain,
+ BlockBackend **pbb,
+ QemuOpts *opts, Error **errp)
+{
+ int ret;
+ BlockBackend *blk = NULL;
+ Error *local_err = NULL;
+
+ ret = bdrv_create_file(filename, opts, &local_err);
+ if (ret < 0) {
+ error_propagate(errp, local_err);
+ goto exit;
+ }
+
+ blk = blk_new_open(filename, NULL, NULL,
+ BDRV_O_RDWR | BDRV_O_RESIZE | 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);
+
+ ret = vmdk_init_extent(blk, filesize, flat, compress, zeroed_grain, errp);
+exit:
+ if (blk) {
+ if (pbb) {
+ *pbb = blk;
+ } else {
+ blk_unref(blk);
+ blk = NULL;
+ }
+ }
+ return ret;
+}
+
static int filename_decompose(const char *filename, char *path, char *prefix,
char *postfix, size_t buf_len, Error **errp)
{
@@ -2067,7 +2084,7 @@ static int coroutine_fn vmdk_co_create_opts(const char *filename, QemuOpts *opts
snprintf(ext_filename, PATH_MAX, "%s%s", path, desc_filename);
if (vmdk_create_extent(ext_filename, size,
- flat, compress, zeroed_grain, opts, errp)) {
+ flat, compress, zeroed_grain, NULL, opts, errp)) {
ret = -EINVAL;
goto exit;
}
--
2.14.3
next prev parent reply other threads:[~2018-05-09 5:58 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-09 5:57 [Qemu-devel] [PATCH 0/5] vmdk: Implement x-blockdev-create Fam Zheng
2018-05-09 5:57 ` [Qemu-devel] [PATCH 1/5] qapi: Add qapi_enum_parse_full Fam Zheng
2018-05-09 11:53 ` Markus Armbruster
2018-05-09 5:57 ` Fam Zheng [this message]
2018-05-09 5:58 ` [Qemu-devel] [PATCH 3/5] vmdk: Implement .bdrv_co_create callback Fam Zheng
2018-05-09 12:41 ` Markus Armbruster
2018-05-09 14:19 ` Fam Zheng
2018-05-09 18:59 ` Markus Armbruster
2018-05-09 5:58 ` [Qemu-devel] [PATCH 4/5] iotests: Filter cid numbers in VMDK extent info Fam Zheng
2018-05-09 5:58 ` [Qemu-devel] [PATCH 5/5] iotests: Add VMDK tests for blockdev-create Fam Zheng
2018-05-09 6:08 ` [Qemu-devel] [PATCH 0/5] vmdk: Implement x-blockdev-create no-reply
2018-05-09 9:35 ` Fam Zheng
2018-05-09 6:10 ` no-reply
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=20180509055802.28423-3-famz@redhat.com \
--to=famz@redhat.com \
--cc=armbru@redhat.com \
--cc=eblake@redhat.com \
--cc=kwolf@redhat.com \
--cc=mdroth@linux.vnet.ibm.com \
--cc=mreitz@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).