From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, stefanha@redhat.com, famz@redhat.com,
mreitz@redhat.com, jcody@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 03/17] vhdx: Some more BlockBackend use in vhdx_create()
Date: Tue, 21 Jun 2016 11:21:20 +0200 [thread overview]
Message-ID: <1466500894-9710-4-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1466500894-9710-1-git-send-email-kwolf@redhat.com>
This does some easy conversions from bdrv_* to blk_* functions in
vhdx_create(). We should avoid bypassing the BlockBackend layer whenever
possible.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block/vhdx.c | 41 +++++++++++++++++++++--------------------
1 file changed, 21 insertions(+), 20 deletions(-)
diff --git a/block/vhdx.c b/block/vhdx.c
index f5605a2..33b81e2 100644
--- a/block/vhdx.c
+++ b/block/vhdx.c
@@ -1387,9 +1387,10 @@ exit:
* There are 2 headers, and the highest sequence number will represent
* the active header
*/
-static int vhdx_create_new_headers(BlockDriverState *bs, uint64_t image_size,
+static int vhdx_create_new_headers(BlockBackend *blk, uint64_t image_size,
uint32_t log_size)
{
+ BlockDriverState *bs = blk_bs(blk);
int ret = 0;
VHDXHeader *hdr = NULL;
@@ -1442,7 +1443,7 @@ exit:
* The first 64KB of the Metadata section is reserved for the metadata
* header and entries; beyond that, the metadata items themselves reside.
*/
-static int vhdx_create_new_metadata(BlockDriverState *bs,
+static int vhdx_create_new_metadata(BlockBackend *blk,
uint64_t image_size,
uint32_t block_size,
uint32_t sector_size,
@@ -1538,13 +1539,13 @@ static int vhdx_create_new_metadata(BlockDriverState *bs,
VHDX_META_FLAGS_IS_VIRTUAL_DISK;
vhdx_metadata_entry_le_export(&md_table_entry[4]);
- ret = bdrv_pwrite(bs, metadata_offset, buffer, VHDX_HEADER_BLOCK_SIZE);
+ ret = blk_pwrite(blk, metadata_offset, buffer, VHDX_HEADER_BLOCK_SIZE, 0);
if (ret < 0) {
goto exit;
}
- ret = bdrv_pwrite(bs, metadata_offset + (64 * KiB), entry_buffer,
- VHDX_METADATA_ENTRY_BUFFER_SIZE);
+ ret = blk_pwrite(blk, metadata_offset + (64 * KiB), entry_buffer,
+ VHDX_METADATA_ENTRY_BUFFER_SIZE, 0);
if (ret < 0) {
goto exit;
}
@@ -1564,7 +1565,7 @@ exit:
* Fixed images: default state of the BAT is fully populated, with
* file offsets and state PAYLOAD_BLOCK_FULLY_PRESENT.
*/
-static int vhdx_create_bat(BlockDriverState *bs, BDRVVHDXState *s,
+static int vhdx_create_bat(BlockBackend *blk, BDRVVHDXState *s,
uint64_t image_size, VHDXImageType type,
bool use_zero_blocks, uint64_t file_offset,
uint32_t length)
@@ -1588,12 +1589,12 @@ static int vhdx_create_bat(BlockDriverState *bs, BDRVVHDXState *s,
if (type == VHDX_TYPE_DYNAMIC) {
/* All zeroes, so we can just extend the file - the end of the BAT
* is the furthest thing we have written yet */
- ret = bdrv_truncate(bs, data_file_offset);
+ ret = blk_truncate(blk, data_file_offset);
if (ret < 0) {
goto exit;
}
} else if (type == VHDX_TYPE_FIXED) {
- ret = bdrv_truncate(bs, data_file_offset + image_size);
+ ret = blk_truncate(blk, data_file_offset + image_size);
if (ret < 0) {
goto exit;
}
@@ -1604,7 +1605,7 @@ static int vhdx_create_bat(BlockDriverState *bs, BDRVVHDXState *s,
if (type == VHDX_TYPE_FIXED ||
use_zero_blocks ||
- bdrv_has_zero_init(bs) == 0) {
+ bdrv_has_zero_init(blk_bs(blk)) == 0) {
/* for a fixed file, the default BAT entry is not zero */
s->bat = g_try_malloc0(length);
if (length && s->bat == NULL) {
@@ -1620,12 +1621,12 @@ static int vhdx_create_bat(BlockDriverState *bs, BDRVVHDXState *s,
sinfo.file_offset = data_file_offset +
(sector_num << s->logical_sector_size_bits);
sinfo.file_offset = ROUND_UP(sinfo.file_offset, MiB);
- vhdx_update_bat_table_entry(bs, s, &sinfo, &unused, &unused,
+ vhdx_update_bat_table_entry(blk_bs(blk), s, &sinfo, &unused, &unused,
block_state);
cpu_to_le64s(&s->bat[sinfo.bat_idx]);
sector_num += s->sectors_per_block;
}
- ret = bdrv_pwrite(bs, file_offset, s->bat, length);
+ ret = blk_pwrite(blk, file_offset, s->bat, length, 0);
if (ret < 0) {
goto exit;
}
@@ -1645,7 +1646,7 @@ exit:
* to create the BAT itself, we will also cause the BAT to be
* created.
*/
-static int vhdx_create_new_region_table(BlockDriverState *bs,
+static int vhdx_create_new_region_table(BlockBackend *blk,
uint64_t image_size,
uint32_t block_size,
uint32_t sector_size,
@@ -1720,21 +1721,21 @@ static int vhdx_create_new_region_table(BlockDriverState *bs,
/* The region table gives us the data we need to create the BAT,
* so do that now */
- ret = vhdx_create_bat(bs, s, image_size, type, use_zero_blocks,
+ ret = vhdx_create_bat(blk, s, image_size, type, use_zero_blocks,
bat_file_offset, bat_length);
if (ret < 0) {
goto exit;
}
/* Now write out the region headers to disk */
- ret = bdrv_pwrite(bs, VHDX_REGION_TABLE_OFFSET, buffer,
- VHDX_HEADER_BLOCK_SIZE);
+ ret = blk_pwrite(blk, VHDX_REGION_TABLE_OFFSET, buffer,
+ VHDX_HEADER_BLOCK_SIZE, 0);
if (ret < 0) {
goto exit;
}
- ret = bdrv_pwrite(bs, VHDX_REGION_TABLE2_OFFSET, buffer,
- VHDX_HEADER_BLOCK_SIZE);
+ ret = blk_pwrite(blk, VHDX_REGION_TABLE2_OFFSET, buffer,
+ VHDX_HEADER_BLOCK_SIZE, 0);
if (ret < 0) {
goto exit;
}
@@ -1871,13 +1872,13 @@ static int vhdx_create(const char *filename, QemuOpts *opts, Error **errp)
/* Creates (B),(C) */
- ret = vhdx_create_new_headers(blk_bs(blk), image_size, log_size);
+ ret = vhdx_create_new_headers(blk, image_size, log_size);
if (ret < 0) {
goto delete_and_exit;
}
/* Creates (D),(E),(G) explicitly. (F) created as by-product */
- ret = vhdx_create_new_region_table(blk_bs(blk), image_size, block_size, 512,
+ ret = vhdx_create_new_region_table(blk, image_size, block_size, 512,
log_size, use_zero_blocks, image_type,
&metadata_offset);
if (ret < 0) {
@@ -1885,7 +1886,7 @@ static int vhdx_create(const char *filename, QemuOpts *opts, Error **errp)
}
/* Creates (H) */
- ret = vhdx_create_new_metadata(blk_bs(blk), image_size, block_size, 512,
+ ret = vhdx_create_new_metadata(blk, image_size, block_size, 512,
metadata_offset, image_type);
if (ret < 0) {
goto delete_and_exit;
--
1.8.3.1
next prev parent reply other threads:[~2016-06-21 9:22 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-21 9:21 [Qemu-devel] [PATCH 00/17] block: Convert common I/O path to BdrvChild Kevin Wolf
2016-06-21 9:21 ` [Qemu-devel] [PATCH 01/17] vvfat: Use BdrvChild for s->qcow Kevin Wolf
2016-06-22 16:54 ` Max Reitz
2016-06-21 9:21 ` [Qemu-devel] [PATCH 02/17] blkreplay: Convert to byte-based I/O Kevin Wolf
2016-06-22 17:03 ` Max Reitz
2016-06-22 17:15 ` Eric Blake
2016-06-21 9:21 ` Kevin Wolf [this message]
2016-06-22 17:08 ` [Qemu-devel] [PATCH 03/17] vhdx: Some more BlockBackend use in vhdx_create() Max Reitz
2016-06-21 9:21 ` [Qemu-devel] [PATCH 04/17] block: Convert bdrv_co_readv() to BdrvChild Kevin Wolf
2016-06-25 15:07 ` Max Reitz
2016-06-21 9:21 ` [Qemu-devel] [PATCH 05/17] block: Convert bdrv_co_writev() " Kevin Wolf
2016-06-25 15:14 ` Max Reitz
2016-06-27 8:56 ` Kevin Wolf
2016-06-21 9:21 ` [Qemu-devel] [PATCH 06/17] block: Convert bdrv_aio_readv() " Kevin Wolf
2016-06-25 15:16 ` Max Reitz
2016-06-21 9:21 ` [Qemu-devel] [PATCH 07/17] block: Convert bdrv_aio_writev() " Kevin Wolf
2016-06-25 15:20 ` Max Reitz
2016-06-21 9:21 ` [Qemu-devel] [PATCH 08/17] block: Convert bdrv_co_do_readv/writev " Kevin Wolf
2016-06-25 15:26 ` Max Reitz
2016-06-21 9:21 ` [Qemu-devel] [PATCH 09/17] block: Move bdrv_commit() to block/commit.c Kevin Wolf
2016-06-24 15:37 ` Eric Blake
2016-06-21 9:21 ` [Qemu-devel] [PATCH 10/17] block: Use BlockBackend for I/O in bdrv_commit() Kevin Wolf
2016-06-25 15:34 ` Max Reitz
2016-06-21 9:21 ` [Qemu-devel] [PATCH 11/17] block: Convert bdrv_read() to BdrvChild Kevin Wolf
2016-06-27 13:24 ` Max Reitz
2016-06-21 9:21 ` [Qemu-devel] [PATCH 12/17] block: Convert bdrv_write() " Kevin Wolf
2016-06-27 13:44 ` Max Reitz
2016-06-27 13:47 ` Max Reitz
2016-06-29 12:11 ` [Qemu-devel] [PATCH v2 " Kevin Wolf
2016-06-29 15:22 ` Max Reitz
2016-06-29 15:33 ` Kevin Wolf
2016-06-29 15:37 ` Max Reitz
2016-06-21 9:21 ` [Qemu-devel] [PATCH 13/17] block: Convert bdrv_pread(v) " Kevin Wolf
2016-06-27 14:55 ` Max Reitz
2016-06-21 9:21 ` [Qemu-devel] [PATCH 14/17] block: Convert bdrv_pwrite(v/_sync) " Kevin Wolf
2016-06-27 15:07 ` Max Reitz
2016-06-21 9:21 ` [Qemu-devel] [PATCH 15/17] block: Convert bdrv_pwrite_zeroes() " Kevin Wolf
2016-06-27 15:12 ` Max Reitz
2016-06-21 9:21 ` [Qemu-devel] [PATCH 16/17] block: Convert bdrv_prwv_co() " Kevin Wolf
2016-06-27 15:19 ` Max Reitz
2016-06-21 9:21 ` [Qemu-devel] [PATCH 17/17] block: Convert bdrv_co_preadv/pwritev " Kevin Wolf
2016-06-21 9:47 ` [Qemu-devel] [PATCH 00/17] block: Convert common I/O path " Paolo Bonzini
2016-06-21 10:56 ` Kevin Wolf
2016-06-21 11:01 ` Paolo Bonzini
2016-06-21 11:31 ` Kevin Wolf
2016-06-22 8:37 ` Fam Zheng
2016-06-28 13:28 ` Stefan Hajnoczi
2016-06-29 11:58 ` 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=1466500894-9710-4-git-send-email-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=famz@redhat.com \
--cc=jcody@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/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).