mirror of
https://github.com/xemu-project/xemu.git
synced 2024-11-24 12:09:58 +00:00
vhdx: Some more BlockBackend use in vhdx_create()
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> Reviewed-by: Max Reitz <mreitz@redhat.com> Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
parent
e858a9705c
commit
db1e80ee2e
41
block/vhdx.c
41
block/vhdx.c
@ -1387,9 +1387,10 @@ exit:
|
|||||||
* There are 2 headers, and the highest sequence number will represent
|
* There are 2 headers, and the highest sequence number will represent
|
||||||
* the active header
|
* 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)
|
uint32_t log_size)
|
||||||
{
|
{
|
||||||
|
BlockDriverState *bs = blk_bs(blk);
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
VHDXHeader *hdr = NULL;
|
VHDXHeader *hdr = NULL;
|
||||||
|
|
||||||
@ -1442,7 +1443,7 @@ exit:
|
|||||||
* The first 64KB of the Metadata section is reserved for the metadata
|
* The first 64KB of the Metadata section is reserved for the metadata
|
||||||
* header and entries; beyond that, the metadata items themselves reside.
|
* 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,
|
uint64_t image_size,
|
||||||
uint32_t block_size,
|
uint32_t block_size,
|
||||||
uint32_t sector_size,
|
uint32_t sector_size,
|
||||||
@ -1538,13 +1539,13 @@ static int vhdx_create_new_metadata(BlockDriverState *bs,
|
|||||||
VHDX_META_FLAGS_IS_VIRTUAL_DISK;
|
VHDX_META_FLAGS_IS_VIRTUAL_DISK;
|
||||||
vhdx_metadata_entry_le_export(&md_table_entry[4]);
|
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) {
|
if (ret < 0) {
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = bdrv_pwrite(bs, metadata_offset + (64 * KiB), entry_buffer,
|
ret = blk_pwrite(blk, metadata_offset + (64 * KiB), entry_buffer,
|
||||||
VHDX_METADATA_ENTRY_BUFFER_SIZE);
|
VHDX_METADATA_ENTRY_BUFFER_SIZE, 0);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
@ -1564,7 +1565,7 @@ exit:
|
|||||||
* Fixed images: default state of the BAT is fully populated, with
|
* Fixed images: default state of the BAT is fully populated, with
|
||||||
* file offsets and state PAYLOAD_BLOCK_FULLY_PRESENT.
|
* 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,
|
uint64_t image_size, VHDXImageType type,
|
||||||
bool use_zero_blocks, uint64_t file_offset,
|
bool use_zero_blocks, uint64_t file_offset,
|
||||||
uint32_t length)
|
uint32_t length)
|
||||||
@ -1588,12 +1589,12 @@ static int vhdx_create_bat(BlockDriverState *bs, BDRVVHDXState *s,
|
|||||||
if (type == VHDX_TYPE_DYNAMIC) {
|
if (type == VHDX_TYPE_DYNAMIC) {
|
||||||
/* All zeroes, so we can just extend the file - the end of the BAT
|
/* All zeroes, so we can just extend the file - the end of the BAT
|
||||||
* is the furthest thing we have written yet */
|
* 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) {
|
if (ret < 0) {
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
} else if (type == VHDX_TYPE_FIXED) {
|
} 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) {
|
if (ret < 0) {
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
@ -1604,7 +1605,7 @@ static int vhdx_create_bat(BlockDriverState *bs, BDRVVHDXState *s,
|
|||||||
|
|
||||||
if (type == VHDX_TYPE_FIXED ||
|
if (type == VHDX_TYPE_FIXED ||
|
||||||
use_zero_blocks ||
|
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 */
|
/* for a fixed file, the default BAT entry is not zero */
|
||||||
s->bat = g_try_malloc0(length);
|
s->bat = g_try_malloc0(length);
|
||||||
if (length && s->bat == NULL) {
|
if (length && s->bat == NULL) {
|
||||||
@ -1620,12 +1621,12 @@ static int vhdx_create_bat(BlockDriverState *bs, BDRVVHDXState *s,
|
|||||||
sinfo.file_offset = data_file_offset +
|
sinfo.file_offset = data_file_offset +
|
||||||
(sector_num << s->logical_sector_size_bits);
|
(sector_num << s->logical_sector_size_bits);
|
||||||
sinfo.file_offset = ROUND_UP(sinfo.file_offset, MiB);
|
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);
|
block_state);
|
||||||
cpu_to_le64s(&s->bat[sinfo.bat_idx]);
|
cpu_to_le64s(&s->bat[sinfo.bat_idx]);
|
||||||
sector_num += s->sectors_per_block;
|
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) {
|
if (ret < 0) {
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
@ -1645,7 +1646,7 @@ exit:
|
|||||||
* to create the BAT itself, we will also cause the BAT to be
|
* to create the BAT itself, we will also cause the BAT to be
|
||||||
* created.
|
* created.
|
||||||
*/
|
*/
|
||||||
static int vhdx_create_new_region_table(BlockDriverState *bs,
|
static int vhdx_create_new_region_table(BlockBackend *blk,
|
||||||
uint64_t image_size,
|
uint64_t image_size,
|
||||||
uint32_t block_size,
|
uint32_t block_size,
|
||||||
uint32_t sector_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,
|
/* The region table gives us the data we need to create the BAT,
|
||||||
* so do that now */
|
* 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);
|
bat_file_offset, bat_length);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now write out the region headers to disk */
|
/* Now write out the region headers to disk */
|
||||||
ret = bdrv_pwrite(bs, VHDX_REGION_TABLE_OFFSET, buffer,
|
ret = blk_pwrite(blk, VHDX_REGION_TABLE_OFFSET, buffer,
|
||||||
VHDX_HEADER_BLOCK_SIZE);
|
VHDX_HEADER_BLOCK_SIZE, 0);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = bdrv_pwrite(bs, VHDX_REGION_TABLE2_OFFSET, buffer,
|
ret = blk_pwrite(blk, VHDX_REGION_TABLE2_OFFSET, buffer,
|
||||||
VHDX_HEADER_BLOCK_SIZE);
|
VHDX_HEADER_BLOCK_SIZE, 0);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
@ -1871,13 +1872,13 @@ static int vhdx_create(const char *filename, QemuOpts *opts, Error **errp)
|
|||||||
|
|
||||||
|
|
||||||
/* Creates (B),(C) */
|
/* 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) {
|
if (ret < 0) {
|
||||||
goto delete_and_exit;
|
goto delete_and_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Creates (D),(E),(G) explicitly. (F) created as by-product */
|
/* 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,
|
log_size, use_zero_blocks, image_type,
|
||||||
&metadata_offset);
|
&metadata_offset);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
@ -1885,7 +1886,7 @@ static int vhdx_create(const char *filename, QemuOpts *opts, Error **errp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Creates (H) */
|
/* 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);
|
metadata_offset, image_type);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
goto delete_and_exit;
|
goto delete_and_exit;
|
||||||
|
Loading…
Reference in New Issue
Block a user