block: Use BB function in .bdrv_create() implementations
PATCH 5/11 qcow2: Use BB functions in .bdrv_create()
In reply to Kevin WolfAll 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.
--- block/qcow2.c | 62 +++++++++++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 29 deletions(-)
block/qcow2.c +33 -29
@@ -24,6 +24,7 @@#include "qemu/osdep.h" #include "qemu-common.h" #include "block/block_int.h" +#include "sysemu/block-backend.h" #include "qemu/module.h" #include <zlib.h> #include "block/qcow2.h"
@@ -2097,7 +2098,7 @@ static int qcow2_create2(const char *filename, int64_t total_size,* 2 GB for 64k clusters, and we don't want to have a 2 GB initial file * size for any qcow2 image. */ -BlockDriverState * bs; +BlockBackend *blk;QCowHeader *header;uint64_t * refcount_table;Error *local_err =NULL ;
@@ -2172,15 +2173,16 @@ static int qcow2_create2(const char *filename, int64_t total_size,return ret; } - bs =NULL ; - 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); -return ret; +return -EIO ; } +blk_set_allow_write_beyond_eof (blk, true); +/* Write the header */ QEMU_BUILD_BUG_ON ((1 <<MIN_CLUSTER_BITS ) <sizeof (*header)); header =g_malloc0 (cluster_size);
@@ -2208,7 +2210,7 @@ static int qcow2_create2(const char *filename, int64_t total_size,cpu_to_be64 (QCOW2_COMPAT_LAZY_REFCOUNTS ); } - ret =bdrv_pwrite (bs,0 , header, cluster_size); + ret =blk_pwrite (blk,0 , header, cluster_size);g_free (header);if (ret <0 ) {error_setg_errno (errp, -ret,"Could not write qcow2 header" );
@@ -2218,7 +2220,7 @@ static int qcow2_create2(const char *filename, int64_t total_size,/* Write a refcount table with one refcount block */ refcount_table =g_malloc0 (2 * cluster_size); refcount_table[0 ] =cpu_to_be64 (2 * cluster_size); - ret =bdrv_pwrite (bs, cluster_size, refcount_table,2 * cluster_size); + ret =blk_pwrite (blk, cluster_size, refcount_table,2 * cluster_size);g_free (refcount_table);if (ret <0 ) {
@@ -2226,8 +2228,8 @@ static int qcow2_create2(const char *filename, int64_t total_size, goto out; } -bdrv_unref (bs); - bs =NULL ; +blk_unref (blk); + blk =NULL ;/* * And now open the image and make it consistent first (i.e. increase the
@@ -2236,15 +2238,16 @@ static int qcow2_create2(const char *filename, int64_t total_size,*/ options =qdict_new ();qdict_put (options,"driver" ,qstring_from_str ("qcow2" )); - ret =bdrv_open (&bs, filename,NULL , options, -BDRV_O_RDWR |BDRV_O_CACHE_WB |BDRV_O_NO_FLUSH , - &local_err); -if (ret <0 ) { + blk =blk_new_open ("image-qcow2" , filename,NULL , options, +BDRV_O_RDWR |BDRV_O_CACHE_WB |BDRV_O_NO_FLUSH , + &local_err); +if (blk ==NULL ) {error_propagate (errp, local_err); + ret = -EIO ; goto out; } - ret =qcow2_alloc_clusters (bs,3 * cluster_size); + ret =qcow2_alloc_clusters (blk_bs (blk),3 * cluster_size);if (ret <0 ) {error_setg_errno (errp, -ret,"Could not allocate clusters for qcow2 " "header and refcount table" );
@@ -2256,14 +2259,14 @@ static int qcow2_create2(const char *filename, int64_t total_size, }/* Create a full header (including things like feature table) */ - ret =qcow2_update_header (bs); + ret =qcow2_update_header (blk_bs (blk));if (ret <0 ) {error_setg_errno (errp, -ret,"Could not update qcow2 header" ); goto out; }/* Okay, now that we have a valid image, let's give it the right size */ - ret =bdrv_truncate (bs, total_size); + ret =blk_truncate (blk, total_size);if (ret <0 ) {error_setg_errno (errp, -ret,"Could not resize image" ); goto out;
@@ -2271,7 +2274,7 @@ static int qcow2_create2(const char *filename, int64_t total_size,/* Want a backing file? There you go.*/ if (backing_file) { - ret =bdrv_change_backing_file (bs, backing_file, backing_format); + ret =bdrv_change_backing_file (blk_bs (blk), backing_file, backing_format);if (ret <0 ) {error_setg_errno (errp, -ret,"Could not assign backing file '%s' " "with format '%s'" , backing_file, backing_format);
@@ -2281,9 +2284,9 @@ static int qcow2_create2(const char *filename, int64_t total_size,/* And if we're supposed to preallocate metadata, do that now */ if (prealloc !=PREALLOC_MODE_OFF ) { -BDRVQcow2State *s = bs->opaque; +BDRVQcow2State *s =blk_bs (blk)->opaque;qemu_co_mutex_lock (&s->lock); - ret =preallocate (bs); + ret =preallocate (blk_bs (blk));qemu_co_mutex_unlock (&s->lock);if (ret <0 ) {error_setg_errno (errp, -ret,"Could not preallocate metadata" );
@@ -2291,24 +2294,25 @@ static int qcow2_create2(const char *filename, int64_t total_size, } } -bdrv_unref (bs); - bs =NULL ; +blk_unref (blk); + blk =NULL ;/* Reopen the image without BDRV_O_NO_FLUSH to flush it before returning */ options =qdict_new ();qdict_put (options,"driver" ,qstring_from_str ("qcow2" )); - ret =bdrv_open (&bs, filename,NULL , options, -BDRV_O_RDWR |BDRV_O_CACHE_WB |BDRV_O_NO_BACKING , - &local_err); -if (local_err) { + blk =blk_new_open ("image-flush" , filename,NULL , options, +BDRV_O_RDWR |BDRV_O_CACHE_WB |BDRV_O_NO_BACKING , + &local_err); +if (blk ==NULL ) {error_propagate (errp, local_err); + ret = -EIO ; goto out; } ret =0 ; out: -if (bs) { -bdrv_unref (bs); +if (blk) { +blk_unref (blk); }return ret; }
Signature · 1 line
1.8.3.1
PATCH 4/11 qcow: Use BB functions in .bdrv_create()
In reply to Kevin WolfAll 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.
--- block/qcow.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-)
block/qcow.c +14 -11
@@ -24,6 +24,7 @@#include "qemu/osdep.h" #include "qemu-common.h" #include "block/block_int.h" +#include "sysemu/block-backend.h" #include "qemu/module.h" #include <zlib.h> #include "qapi/qmp/qerror.h"
@@ -780,7 +781,7 @@ static int qcow_create(const char *filename, QemuOpts *opts, Error **errp)int flags =0 ;Error *local_err =NULL ;int ret; -BlockDriverState *qcow_bs; +BlockBackend *qcow_blk;/* Read out options */ total_size = ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0),
@@ -796,16 +797,18 @@ static int qcow_create(const char *filename, QemuOpts *opts, Error **errp) goto cleanup; } - qcow_bs =NULL ; - ret =bdrv_open (&qcow_bs, filename,NULL ,NULL , -BDRV_O_RDWR |BDRV_O_CACHE_WB |BDRV_O_PROTOCOL , - &local_err); -if (ret <0 ) { + qcow_blk =blk_new_open ("image" , filename,NULL ,NULL , +BDRV_O_RDWR |BDRV_O_CACHE_WB |BDRV_O_PROTOCOL , + &local_err); +if (qcow_blk ==NULL ) {error_propagate (errp, local_err); + ret = -EIO ; goto cleanup; } - ret =bdrv_truncate (qcow_bs,0 ); +blk_set_allow_write_beyond_eof (qcow_blk, true); + + ret =blk_truncate (qcow_blk,0 );if (ret <0 ) { goto exit; }
@@ -845,13 +848,13 @@ static int qcow_create(const char *filename, QemuOpts *opts, Error **errp) }/* write all the data */ - ret =bdrv_pwrite (qcow_bs,0 , &header,sizeof (header)); + ret =blk_pwrite (qcow_blk,0 , &header,sizeof (header));if (ret !=sizeof (header)) { goto exit; }if (backing_file) { - ret =bdrv_pwrite (qcow_bs,sizeof (header), + ret =blk_pwrite (qcow_blk,sizeof (header), backing_file, backing_filename_len);if (ret != backing_filename_len) { goto exit;
@@ -861,7 +864,7 @@ static int qcow_create(const char *filename, QemuOpts *opts, Error **errp) tmp =g_malloc0 (BDRV_SECTOR_SIZE );for (i =0 ; i < ((sizeof (uint64_t )*l1_size +BDRV_SECTOR_SIZE -1 )/BDRV_SECTOR_SIZE ); i++) { - ret =bdrv_pwrite (qcow_bs, header_size + + ret =blk_pwrite (qcow_blk, header_size +BDRV_SECTOR_SIZE *i, tmp,BDRV_SECTOR_SIZE );if (ret !=BDRV_SECTOR_SIZE ) {g_free (tmp);
@@ -872,7 +875,7 @@ static int qcow_create(const char *filename, QemuOpts *opts, Error **errp)g_free (tmp); ret =0 ; exit: -bdrv_unref (qcow_bs); +blk_unref (qcow_blk); cleanup:g_free (backing_file);return ret;
Signature · 1 line
1.8.3.1
cover block: Use BB function in .bdrv_create() implementations
All users of the block layers are supposed to go through a BlockBackend. The .bdrv_create() implementations are such users, so this series converts them.
This series (specifically patch 1) will also help with moving the writethrough cache implementation from BDS to BB, where it really belongs. Once this is moved, it wouldn't be possible to use bdrv_open() to use a standalone BDS writethrough any more.
Of course, writethrough doesn't make any sense in .bdrv_create() anyway, so while I'm still converting everything to BB where it would keep working (because that's the Right Thing), the drivers don't actually make use of this fact any more after this series.
Kevin Wolf (11):
block: Use writeback in .bdrv_create() implementations
block: Introduce blk_set_allow_write_beyond_eof()
parallels: Use BB functions in .bdrv_create()
qcow: Use BB functions in .bdrv_create()
qcow2: Use BB functions in .bdrv_create()
qed: Use BB functions in .bdrv_create()
sheepdog: Use BB functions in .bdrv_create()
vdi: Use BB functions in .bdrv_create()
vhdx: Use BB functions in .bdrv_create()
vmdk: Use BB functions in .bdrv_create()
vpc: Use BB functions in .bdrv_create()
block/block-backend.c | 23 +++++++++---- block/parallels.c | 24 ++++++++------ block/qcow.c | 24 ++++++++------ block/qcow2.c | 61 ++++++++++++++++++---------------- block/qed.c | 28 ++++++++-------- block/sheepdog.c | 41 +++++++++++++---------- block/vdi.c | 22 ++++++++----- block/vhdx.c | 28 +++++++++------- block/vmdk.c | 74 ++++++++++++++++++++++++------------------ block/vpc.c | 36 +++++++++++--------- include/sysemu/block-backend.h | 1 + 11 files changed, 211 insertions(+), 151 deletions(-)
Signature · 1 line
1.8.3.1
PATCH 7/11 sheepdog: Use BB functions in .bdrv_create()
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.
--- block/sheepdog.c | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-)
block/sheepdog.c +24 -19
@@ -18,6 +18,7 @@#include "qemu/error-report.h" #include "qemu/sockets.h" #include "block/block_int.h" +#include "sysemu/block-backend.h" #include "qemu/bitops.h" #define SD_PROTO_VER 0x01
@@ -1637,7 +1638,7 @@ static int do_sd_create(BDRVSheepdogState *s, uint32_t *vdi_id, int snapshot,static int sd_prealloc (const char *filename,Error **errp) { -BlockDriverState *bs =NULL ; +BlockBackend *blk =NULL ;BDRVSheepdogState *base =NULL ;unsigned long buf_size;uint32_t idx, max_idx;
@@ -1646,20 +1647,23 @@ static int sd_prealloc(const char *filename, Error **errp)void *buf =NULL ;int ret; - ret =bdrv_open (&bs, filename,NULL ,NULL , -BDRV_O_RDWR |BDRV_O_CACHE_WB |BDRV_O_PROTOCOL , - errp); -if (ret <0 ) { + blk =blk_new_open ("image-prealloc" , filename,NULL ,NULL , +BDRV_O_RDWR |BDRV_O_CACHE_WB |BDRV_O_PROTOCOL , + errp); +if (blk ==NULL ) { + ret = -EIO ; goto out_with_err_set; } - vdi_size =bdrv_getlength (bs); +blk_set_allow_write_beyond_eof (blk, true); + + vdi_size =blk_getlength (blk);if (vdi_size <0 ) { ret = vdi_size; goto out; } - base = bs->opaque; + base =blk_bs (blk)->opaque; object_size = (UINT32_C (1 ) << base->inode.block_size_shift); buf_size =MIN (object_size,SD_DATA_OBJ_SIZE ); buf =g_malloc0 (buf_size);
@@ -1671,23 +1675,24 @@ static int sd_prealloc(const char *filename, Error **errp)* The created image can be a cloned image, so we need to read * a data from the source image. */ - ret =bdrv_pread (bs, idx * buf_size, buf, buf_size); + ret =blk_pread (blk, idx * buf_size, buf, buf_size);if (ret <0 ) { goto out; } - ret =bdrv_pwrite (bs, idx * buf_size, buf, buf_size); + ret =blk_pwrite (blk, idx * buf_size, buf, buf_size);if (ret <0 ) { goto out; } } + ret =0 ; out:if (ret <0 ) {error_setg_errno (errp, -ret,"Can't pre-allocate" ); } out_with_err_set: -if (bs) { -bdrv_unref (bs); +if (blk) { +blk_unref (blk); }g_free (buf);
@@ -1827,7 +1832,7 @@ static int sd_create(const char *filename, QemuOpts *opts, }if (backing_file) { -BlockDriverState *bs; +BlockBackend *blk;BDRVSheepdogState *base;BlockDriver *drv;
@@ -1839,23 +1844,23 @@ static int sd_create(const char *filename, QemuOpts *opts, goto out; } - bs =NULL ; - ret =bdrv_open (&bs, backing_file,NULL ,NULL , -BDRV_O_PROTOCOL |BDRV_O_CACHE_WB , errp); -if (ret <0 ) { + blk =blk_new_open ("backing" , backing_file,NULL ,NULL , +BDRV_O_PROTOCOL |BDRV_O_CACHE_WB , errp); +if (blk ==NULL ) { + ret = -EIO ; goto out; } - base = bs->opaque; + base =blk_bs (blk)->opaque;if (!is_snapshot (&base->inode)) {error_setg (errp,"cannot clone from a non snapshot vdi" ); -bdrv_unref (bs); +blk_unref (blk); ret = -EINVAL ; goto out; } s->inode.vdi_id = base->inode.vdi_id; -bdrv_unref (bs); +blk_unref (blk); } s->aio_context =qemu_get_aio_context ();
Signature · 1 line
1.8.3.1
PATCH 3/11 parallels: Use BB functions in .bdrv_create()
In reply to Kevin WolfAll 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.
--- block/parallels.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-)
block/parallels.c +14 -11
@@ -30,6 +30,7 @@#include "qemu/osdep.h" #include "qemu-common.h" #include "block/block_int.h" +#include "sysemu/block-backend.h" #include "qemu/module.h" #include "qemu/bitmap.h" #include "qapi/util.h"
@@ -461,7 +462,7 @@ static int parallels_create(const char *filename, QemuOpts *opts, Error **errp)int64_t total_size, cl_size;uint8_t tmp[BDRV_SECTOR_SIZE ];Error *local_err =NULL ; -BlockDriverState *file; +BlockBackend *file;uint32_t bat_entries, bat_sectors;ParallelsHeader header;int ret;
@@ -477,15 +478,17 @@ static int parallels_create(const char *filename, QemuOpts *opts, Error **errp)return ret; } - file =NULL ; - ret =bdrv_open (&file, filename,NULL ,NULL , -BDRV_O_RDWR |BDRV_O_CACHE_WB |BDRV_O_PROTOCOL , - &local_err); -if (ret <0 ) { + file =blk_new_open ("image" , filename,NULL ,NULL , +BDRV_O_RDWR |BDRV_O_CACHE_WB |BDRV_O_PROTOCOL , + &local_err); +if (file ==NULL ) {error_propagate (errp, local_err); -return ret; +return -EIO ; } - ret =bdrv_truncate (file,0 ); + +blk_set_allow_write_beyond_eof (file, true); + + ret =blk_truncate (file,0 );if (ret <0 ) { goto exit; }
@@ -509,18 +512,18 @@ static int parallels_create(const char *filename, QemuOpts *opts, Error **errp)memset (tmp,0 ,sizeof (tmp));memcpy (tmp, &header,sizeof (header)); - ret =bdrv_pwrite (file,0 , tmp,BDRV_SECTOR_SIZE ); + ret =blk_pwrite (file,0 , tmp,BDRV_SECTOR_SIZE );if (ret <0 ) { goto exit; } - ret =bdrv_write_zeroes (file,1 , bat_sectors -1 ,0 ); + ret =blk_write_zeroes (file,1 , bat_sectors -1 ,0 );if (ret <0 ) { goto exit; } ret =0 ; done: -bdrv_unref (file); +blk_unref (file);return ret; exit:
Signature · 1 line
1.8.3.1
PATCH 8/11 vdi: Use BB functions in .bdrv_create()
In reply to Kevin WolfAll 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.
--- block/vdi.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-)
block/vdi.c +14 -9
@@ -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; }
Signature · 1 line
1.8.3.1
PATCH 1/11 block: Use writeback in .bdrv_create() implementations
In reply to Kevin WolfThere's no reason to use a writethrough cache mode while creating an image.
--- block/parallels.c | 3 ++- block/qcow.c | 3 ++- block/qcow2.c | 3 ++- block/sheepdog.c | 6 ++++-- block/vdi.c | 3 ++- block/vhdx.c | 3 ++- block/vmdk.c | 9 ++++++--- block/vpc.c | 3 ++- 8 files changed, 22 insertions(+), 11 deletions(-)
block/parallels.c +2 -1
@@ -479,7 +479,8 @@ static int parallels_create(const char *filename, QemuOpts *opts, Error **errp) file =NULL ; ret =bdrv_open (&file, filename,NULL ,NULL , -BDRV_O_RDWR |BDRV_O_PROTOCOL , &local_err); +BDRV_O_RDWR |BDRV_O_CACHE_WB |BDRV_O_PROTOCOL , + &local_err);if (ret <0 ) {error_propagate (errp, local_err);return ret;
block/qcow.c +2 -1
@@ -798,7 +798,8 @@ static int qcow_create(const char *filename, QemuOpts *opts, Error **errp) qcow_bs =NULL ; ret =bdrv_open (&qcow_bs, filename,NULL ,NULL , -BDRV_O_RDWR |BDRV_O_PROTOCOL , &local_err); +BDRV_O_RDWR |BDRV_O_CACHE_WB |BDRV_O_PROTOCOL , + &local_err);if (ret <0 ) {error_propagate (errp, local_err); goto cleanup;
block/qcow2.c +2 -1
@@ -2173,7 +2173,8 @@ static int qcow2_create2(const char *filename, int64_t total_size, } bs =NULL ; - ret =bdrv_open (&bs, filename,NULL ,NULL ,BDRV_O_RDWR |BDRV_O_PROTOCOL , + ret =bdrv_open (&bs, filename,NULL ,NULL , +BDRV_O_RDWR |BDRV_O_CACHE_WB |BDRV_O_PROTOCOL , &local_err);if (ret <0 ) {error_propagate (errp, local_err);
block/sheepdog.c +4 -2
@@ -1646,7 +1646,8 @@ static int sd_prealloc(const char *filename, Error **errp)void *buf =NULL ;int ret; - ret =bdrv_open (&bs, filename,NULL ,NULL ,BDRV_O_RDWR |BDRV_O_PROTOCOL , + ret =bdrv_open (&bs, filename,NULL ,NULL , +BDRV_O_RDWR |BDRV_O_CACHE_WB |BDRV_O_PROTOCOL , errp);if (ret <0 ) { goto out_with_err_set;
@@ -1839,7 +1840,8 @@ static int sd_create(const char *filename, QemuOpts *opts, } bs =NULL ; - ret =bdrv_open (&bs, backing_file,NULL ,NULL ,BDRV_O_PROTOCOL , errp); + ret =bdrv_open (&bs, backing_file,NULL ,NULL , +BDRV_O_PROTOCOL |BDRV_O_CACHE_WB , errp);if (ret <0 ) { goto out; }
block/vdi.c +2 -1
@@ -766,7 +766,8 @@ 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_PROTOCOL , + ret =bdrv_open (&bs, filename,NULL ,NULL , +BDRV_O_RDWR |BDRV_O_CACHE_WB |BDRV_O_PROTOCOL , &local_err);if (ret <0 ) {error_propagate (errp, local_err);
block/vhdx.c +2 -1
@@ -1838,7 +1838,8 @@ static int vhdx_create(const char *filename, QemuOpts *opts, Error **errp) } bs =NULL ; - ret =bdrv_open (&bs, filename,NULL ,NULL ,BDRV_O_RDWR |BDRV_O_PROTOCOL , + ret =bdrv_open (&bs, filename,NULL ,NULL , +BDRV_O_RDWR |BDRV_O_CACHE_WB |BDRV_O_PROTOCOL , &local_err);if (ret <0 ) {error_propagate (errp, local_err);
block/vmdk.c +6 -3
@@ -1664,7 +1664,8 @@ static int vmdk_create_extent(const char *filename, int64_t filesize, }assert (bs ==NULL ); - ret =bdrv_open (&bs, filename,NULL ,NULL ,BDRV_O_RDWR |BDRV_O_PROTOCOL , + ret =bdrv_open (&bs, filename,NULL ,NULL , +BDRV_O_RDWR |BDRV_O_CACHE_WB |BDRV_O_PROTOCOL , &local_err);if (ret <0 ) {error_propagate (errp, local_err);
@@ -1944,7 +1945,8 @@ static int vmdk_create(const char *filename, QemuOpts *opts, Error **errp) ret = -ENOENT ; goto exit; } - ret =bdrv_open (&bs, full_backing,NULL ,NULL ,BDRV_O_NO_BACKING , errp); + ret =bdrv_open (&bs, full_backing,NULL ,NULL , +BDRV_O_NO_BACKING |BDRV_O_CACHE_WB , errp);g_free (full_backing);if (ret !=0 ) { goto exit;
@@ -2015,7 +2017,8 @@ static int vmdk_create(const char *filename, QemuOpts *opts, Error **errp) }assert (new_bs ==NULL ); ret =bdrv_open (&new_bs, filename,NULL ,NULL , -BDRV_O_RDWR |BDRV_O_PROTOCOL , &local_err); +BDRV_O_RDWR |BDRV_O_CACHE_WB |BDRV_O_PROTOCOL , + &local_err);if (ret <0 ) {error_propagate (errp, local_err); goto exit;
block/vpc.c +2 -1
@@ -886,7 +886,8 @@ static int vpc_create(const char *filename, QemuOpts *opts, Error **errp)error_propagate (errp, local_err); goto out; } - ret =bdrv_open (&bs, filename,NULL ,NULL ,BDRV_O_RDWR |BDRV_O_PROTOCOL , + ret =bdrv_open (&bs, filename,NULL ,NULL , +BDRV_O_RDWR |BDRV_O_CACHE_WB |BDRV_O_PROTOCOL , &local_err);if (ret <0 ) {error_propagate (errp, local_err);
Signature · 1 line
1.8.3.1
PATCH 2/11 block: Introduce blk_set_allow_write_beyond_eof()
In reply to Kevin WolfWe check that the guest can't write beyond the end of its disk, but for other internal users it can make sense to allow growing a file.
--- block/block-backend.c | 23 ++++++++++++++++------- include/sysemu/block-backend.h | 1 + 2 files changed, 17 insertions(+), 7 deletions(-)
block/block-backend.c +16 -7
@@ -50,6 +50,8 @@ struct BlockBackend {bool iostatus_enabled;BlockDeviceIoStatus iostatus; +bool allow_write_beyond_eof; +NotifierList remove_bs_notifiers, insert_bs_notifiers; };
@@ -579,6 +581,11 @@ void blk_iostatus_set_err(BlockBackend *blk, int error) } } +void blk_set_allow_write_beyond_eof (BlockBackend *blk,bool allow) +{ + blk->allow_write_beyond_eof = allow; +} +static int blk_check_byte_request (BlockBackend *blk,int64_t offset,size_t size) {
@@ -592,17 +599,19 @@ static int blk_check_byte_request(BlockBackend *blk, int64_t offset,return -ENOMEDIUM ; } - len =blk_getlength (blk); -if (len <0 ) { -return len; - } -if (offset <0 ) {return -EIO ; } -if (offset > len || len - offset < size) { -return -EIO ; +if (!blk->allow_write_beyond_eof) { + len =blk_getlength (blk); +if (len <0 ) { +return len; + } + +if (offset > len || len - offset < size) { +return -EIO ; + } }return 0 ;
include/sysemu/block-backend.h +1 -0
@@ -78,6 +78,7 @@ void blk_insert_bs(BlockBackend *blk, BlockDriverState *bs);void blk_hide_on_behalf_of_hmp_drive_del (BlockBackend *blk); +void blk_set_allow_write_beyond_eof (BlockBackend *blk,bool allow);void blk_iostatus_enable (BlockBackend *blk);bool blk_iostatus_is_enabled (const BlockBackend *blk);BlockDeviceIoStatus blk_iostatus (const BlockBackend *blk);
Signature · 1 line
1.8.3.1
PATCH 6/11 qed: Use BB functions in .bdrv_create()
In reply to Kevin WolfAll 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.
--- block/qed.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-)
block/qed.c +15 -13
@@ -18,6 +18,7 @@#include "qed.h" #include "qapi/qmp/qerror.h" #include "migration/migration.h" +#include "sysemu/block-backend.h" static const AIOCBInfo qed_aiocb_info = { .aiocb_size =sizeof (QEDAIOCB ),
@@ -580,7 +581,7 @@ static int qed_create(const char *filename, uint32_t cluster_size,size_t l1_size = header.cluster_size * header.table_size;Error *local_err =NULL ;int ret =0 ; -BlockDriverState *bs; +BlockBackend *blk; ret =bdrv_create_file (filename, opts, &local_err);if (ret <0 ) {
@@ -588,17 +589,18 @@ static int qed_create(const char *filename, uint32_t cluster_size,return ret; } - bs =NULL ; - 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); -return ret; +return -EIO ; } +blk_set_allow_write_beyond_eof (blk, true); +/* File must start empty and grow, check truncate is supported */ - ret =bdrv_truncate (bs,0 ); + ret =blk_truncate (blk,0 );if (ret <0 ) { goto out; }
@@ -614,18 +616,18 @@ static int qed_create(const char *filename, uint32_t cluster_size, }qed_header_cpu_to_le (&header, &le_header); - ret =bdrv_pwrite (bs,0 , &le_header,sizeof (le_header)); + ret =blk_pwrite (blk,0 , &le_header,sizeof (le_header));if (ret <0 ) { goto out; } - ret =bdrv_pwrite (bs,sizeof (le_header), backing_file, - header.backing_filename_size); + ret =blk_pwrite (blk,sizeof (le_header), backing_file, + header.backing_filename_size);if (ret <0 ) { goto out; } l1_table =g_malloc0 (l1_size); - ret =bdrv_pwrite (bs, header.l1_table_offset, l1_table, l1_size); + ret =blk_pwrite (blk, header.l1_table_offset, l1_table, l1_size);if (ret <0 ) { goto out; }
@@ -633,7 +635,7 @@ static int qed_create(const char *filename, uint32_t cluster_size, ret =0 ;/* success */ out:g_free (l1_table); -bdrv_unref (bs); +blk_unref (blk);return ret; }
Signature · 1 line
1.8.3.1
PATCH 9/11 vhdx: Use BB functions in .bdrv_create()
In reply to Kevin WolfAll 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.
--- block/vhdx.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-)
block/vhdx.c +16 -13
@@ -18,6 +18,7 @@#include "qemu/osdep.h" #include "qemu-common.h" #include "block/block_int.h" +#include "sysemu/block-backend.h" #include "qemu/module.h" #include "qemu/crc32c.h" #include "block/vhdx.h"
@@ -1772,7 +1773,7 @@ static int vhdx_create(const char *filename, QemuOpts *opts, Error **errp)gunichar2 *creator =NULL ;glong creator_items; -BlockDriverState *bs; +BlockBackend *blk;char *type =NULL ;VHDXImageType image_type;Error *local_err =NULL ;
@@ -1837,15 +1838,17 @@ static int vhdx_create(const char *filename, QemuOpts *opts, Error **errp) goto exit; } - bs =NULL ; - 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); +/* Create (A) */ /* The creator field is optional, but may be useful for
@@ -1853,13 +1856,13 @@ static int vhdx_create(const char *filename, QemuOpts *opts, Error **errp) creator =g_utf8_to_utf16 ("QEMU v" QEMU_VERSION ,-1 ,NULL , &creator_items,NULL ); signature =cpu_to_le64 (VHDX_FILE_SIGNATURE ); - ret =bdrv_pwrite (bs,VHDX_FILE_ID_OFFSET , &signature,sizeof (signature)); + ret =blk_pwrite (blk,VHDX_FILE_ID_OFFSET , &signature,sizeof (signature));if (ret <0 ) { goto delete_and_exit; }if (creator) { - ret =bdrv_pwrite (bs,VHDX_FILE_ID_OFFSET +sizeof (signature), - creator, creator_items *sizeof (gunichar2)); + ret =blk_pwrite (blk,VHDX_FILE_ID_OFFSET +sizeof (signature), + creator, creator_items *sizeof (gunichar2));if (ret <0 ) { goto delete_and_exit; }
@@ -1867,13 +1870,13 @@ static int vhdx_create(const char *filename, QemuOpts *opts, Error **errp)/* Creates (B),(C) */ - ret =vhdx_create_new_headers (bs, image_size, log_size); + ret =vhdx_create_new_headers (blk_bs (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 (bs, image_size, block_size,512 , + ret =vhdx_create_new_region_table (blk_bs (blk), image_size, block_size,512 , log_size, use_zero_blocks, image_type, &metadata_offset);if (ret <0 ) {
@@ -1881,7 +1884,7 @@ static int vhdx_create(const char *filename, QemuOpts *opts, Error **errp) }/* Creates (H) */ - ret =vhdx_create_new_metadata (bs, image_size, block_size,512 , + ret =vhdx_create_new_metadata (blk_bs (blk), image_size, block_size,512 , metadata_offset, image_type);if (ret <0 ) { goto delete_and_exit;
@@ -1889,7 +1892,7 @@ static int vhdx_create(const char *filename, QemuOpts *opts, Error **errp) delete_and_exit: -bdrv_unref (bs); +blk_unref (blk); exit:g_free (type);g_free (creator);
Signature · 1 line
1.8.3.1
PATCH 11/11 vpc: Use BB functions in .bdrv_create()
In reply to Kevin WolfAll 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.
--- block/vpc.c | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-)
block/vpc.c +21 -16
@@ -25,6 +25,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" #if defined(CONFIG_UUID )
@@ -758,7 +759,7 @@ static int calculate_geometry(int64_t total_sectors, uint16_t* cyls,return 0 ; } -static int create_dynamic_disk (BlockDriverState *bs,uint8_t *buf, +static int create_dynamic_disk (BlockBackend *blk,uint8_t *buf,int64_t total_sectors) { VHDDynDiskHeader *dyndisk_header =
@@ -772,13 +773,13 @@ static int create_dynamic_disk(BlockDriverState *bs, uint8_t *buf, block_size =0x200000 ; num_bat_entries = (total_sectors + block_size /512 ) / (block_size /512 ); - ret =bdrv_pwrite_sync (bs, offset, buf,HEADER_SIZE ); + ret =blk_pwrite (blk, offset, buf,HEADER_SIZE );if (ret) { goto fail; } offset =1536 + ((num_bat_entries *4 +511 ) & ~511 ); - ret =bdrv_pwrite_sync (bs, offset, buf,HEADER_SIZE ); + ret =blk_pwrite (blk, offset, buf,HEADER_SIZE );if (ret <0 ) { goto fail; }
@@ -788,7 +789,7 @@ static int create_dynamic_disk(BlockDriverState *bs, uint8_t *buf,memset (buf,0xFF ,512 );for (i =0 ; i < (num_bat_entries *4 +511 ) /512 ; i++) { - ret =bdrv_pwrite_sync (bs, offset, buf,512 ); + ret =blk_pwrite (blk, offset, buf,512 );if (ret <0 ) { goto fail; }
@@ -815,7 +816,7 @@ static int create_dynamic_disk(BlockDriverState *bs, uint8_t *buf,// Write the header offset =512 ; - ret =bdrv_pwrite_sync (bs, offset, buf,1024 ); + ret =blk_pwrite (blk, offset, buf,1024 );if (ret <0 ) { goto fail; }
@@ -824,7 +825,7 @@ static int create_dynamic_disk(BlockDriverState *bs, uint8_t *buf,return ret; } -static int create_fixed_disk (BlockDriverState *bs,uint8_t *buf, +static int create_fixed_disk (BlockBackend *blk,uint8_t *buf,int64_t total_size) {int ret;
@@ -832,12 +833,12 @@ static int create_fixed_disk(BlockDriverState *bs, uint8_t *buf,/* Add footer to total size */ total_size +=HEADER_SIZE ; - ret =bdrv_truncate (bs, total_size); + ret =blk_truncate (blk, total_size);if (ret <0 ) {return ret; } - ret =bdrv_pwrite_sync (bs, total_size -HEADER_SIZE , buf,HEADER_SIZE ); + ret =blk_pwrite (blk, total_size -HEADER_SIZE , buf,HEADER_SIZE );if (ret <0 ) {return ret; }
@@ -860,7 +861,7 @@ static int vpc_create(const char *filename, QemuOpts *opts, Error **errp)int ret = -EIO ;bool force_size;Error *local_err =NULL ; -BlockDriverState *bs =NULL ; +BlockBackend *blk =NULL ;/* Read out options */ total_size = ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0),
@@ -886,14 +887,18 @@ static int vpc_create(const char *filename, QemuOpts *opts, Error **errp)error_propagate (errp, local_err); goto out; } - 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 out; } +blk_set_allow_write_beyond_eof (blk, true); +/* * Calculate matching total_size and geometry. Increase the number of * sectors requested until we get enough (or fail). This ensures that
@@ -965,13 +970,13 @@ static int vpc_create(const char *filename, QemuOpts *opts, Error **errp) footer->checksum =cpu_to_be32 (vpc_checksum (buf,HEADER_SIZE ));if (disk_type ==VHD_DYNAMIC ) { - ret =create_dynamic_disk (bs, buf, total_sectors); + ret =create_dynamic_disk (blk, buf, total_sectors); }else { - ret =create_fixed_disk (bs, buf, total_size); + ret =create_fixed_disk (blk, buf, total_size); } out: -bdrv_unref (bs); +blk_unref (blk);g_free (disk_type_param);return ret; }
Signature · 1 line
1.8.3.1
PATCH 10/11 vmdk: Use BB functions in .bdrv_create()
In reply to Kevin WolfAll 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.
--- block/vmdk.c | 77 +++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 43 insertions(+), 34 deletions(-)
block/vmdk.c +43 -34
@@ -26,6 +26,7 @@#include "qemu/osdep.h" #include "qemu-common.h" #include "block/block_int.h" +#include "sysemu/block-backend.h" #include "qapi/qmp/qerror.h" #include "qemu/error-report.h" #include "qemu/module.h"
@@ -1650,7 +1651,7 @@ static int vmdk_create_extent(const char *filename, int64_t filesize, QemuOpts *opts, Error **errp) {int ret, i; -BlockDriverState *bs =NULL ; +BlockBackend *blk =NULL ;VMDK4Header header;Error *local_err =NULL ;uint32_t tmp, magic, grains, gd_sectors, gt_size, gt_count;
@@ -1663,17 +1664,19 @@ static int vmdk_create_extent(const char *filename, int64_t filesize, goto exit; } -assert (bs ==NULL ); - 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 ("extent" , 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); +if (flat) { - ret =bdrv_truncate (bs, filesize); + ret =blk_truncate (blk, filesize);if (ret <0 ) {error_setg_errno (errp, -ret,"Could not truncate file" ); }
@@ -1728,18 +1731,18 @@ static int vmdk_create_extent(const char *filename, int64_t filesize, header.check_bytes[3 ] =0xa ;/* write all the data */ - ret =bdrv_pwrite (bs,0 , &magic,sizeof (magic)); + ret =blk_pwrite (blk,0 , &magic,sizeof (magic));if (ret <0 ) {error_setg (errp,QERR_IO_ERROR ); goto exit; } - ret =bdrv_pwrite (bs,sizeof (magic), &header,sizeof (header)); + ret =blk_pwrite (blk,sizeof (magic), &header,sizeof (header));if (ret <0 ) {error_setg (errp,QERR_IO_ERROR ); goto exit; } - ret =bdrv_truncate (bs,le64_to_cpu (header.grain_offset) <<9 ); + ret =blk_truncate (blk,le64_to_cpu (header.grain_offset) <<9 );if (ret <0 ) {error_setg_errno (errp, -ret,"Could not truncate file" ); goto exit;
@@ -1752,8 +1755,8 @@ static int vmdk_create_extent(const char *filename, int64_t filesize, i < gt_count; i++, tmp += gt_size) { gd_buf[i] =cpu_to_le32 (tmp); } - ret =bdrv_pwrite (bs,le64_to_cpu (header.rgd_offset) *BDRV_SECTOR_SIZE , - gd_buf, gd_buf_size); + ret =blk_pwrite (blk,le64_to_cpu (header.rgd_offset) *BDRV_SECTOR_SIZE , + gd_buf, gd_buf_size);if (ret <0 ) {error_setg (errp,QERR_IO_ERROR ); goto exit;
@@ -1764,8 +1767,8 @@ static int vmdk_create_extent(const char *filename, int64_t filesize, i < gt_count; i++, tmp += gt_size) { gd_buf[i] =cpu_to_le32 (tmp); } - ret =bdrv_pwrite (bs,le64_to_cpu (header.gd_offset) *BDRV_SECTOR_SIZE , - gd_buf, gd_buf_size); + ret =blk_pwrite (blk,le64_to_cpu (header.gd_offset) *BDRV_SECTOR_SIZE , + gd_buf, gd_buf_size);if (ret <0 ) {error_setg (errp,QERR_IO_ERROR ); goto exit;
@@ -1773,8 +1776,8 @@ static int vmdk_create_extent(const char *filename, int64_t filesize, ret =0 ; exit: -if (bs) { -bdrv_unref (bs); +if (blk) { +blk_unref (blk); }g_free (gd_buf);return ret;
@@ -1823,7 +1826,7 @@ static int filename_decompose(const char *filename, char *path, char *prefix,static int vmdk_create (const char *filename,QemuOpts *opts,Error **errp) {int idx =0 ; -BlockDriverState *new_bs =NULL ; +BlockBackend *new_blk =NULL ;Error *local_err =NULL ;char *desc =NULL ;int64_t total_size =0 , filesize;
@@ -1934,7 +1937,7 @@ static int vmdk_create(const char *filename, QemuOpts *opts, Error **errp) goto exit; }if (backing_file) { -BlockDriverState *bs =NULL ; +BlockBackend *blk;char *full_backing =g_new0 (char,PATH_MAX ); bdrv_get_full_backing_filename_from_filename(filename, backing_file, full_backing, PATH_MAX,
@@ -1945,19 +1948,21 @@ static int vmdk_create(const char *filename, QemuOpts *opts, Error **errp) ret = -ENOENT ; goto exit; } - ret =bdrv_open (&bs, full_backing,NULL ,NULL , -BDRV_O_NO_BACKING |BDRV_O_CACHE_WB , errp); + + blk =blk_new_open ("backing" , full_backing,NULL ,NULL , +BDRV_O_NO_BACKING |BDRV_O_CACHE_WB , errp);g_free (full_backing); -if (ret !=0 ) { +if (blk ==NULL ) { + ret = -EIO ; goto exit; } -if (strcmp (bs->drv->format_name,"vmdk" )) { -bdrv_unref (bs); +if (strcmp (blk_bs (blk)->drv->format_name,"vmdk" )) { +blk_unref (blk); ret = -EINVAL ; goto exit; } - parent_cid =vmdk_read_cid (bs,0 ); -bdrv_unref (bs); + parent_cid =vmdk_read_cid (blk_bs (blk),0 ); +blk_unref (blk);snprintf (parent_desc_line,BUF_SIZE ,"parentFileNameHint=\"%s\"" , backing_file); }
@@ -2015,15 +2020,19 @@ static int vmdk_create(const char *filename, QemuOpts *opts, Error **errp) goto exit; } } -assert (new_bs ==NULL ); - ret =bdrv_open (&new_bs, filename,NULL ,NULL , -BDRV_O_RDWR |BDRV_O_CACHE_WB |BDRV_O_PROTOCOL , - &local_err); -if (ret <0 ) { + + new_blk =blk_new_open ("descriptor" , filename,NULL ,NULL , +BDRV_O_RDWR |BDRV_O_CACHE_WB |BDRV_O_PROTOCOL , + &local_err); +if (new_blk ==NULL ) {error_propagate (errp, local_err); + ret = -EIO ; goto exit; } - ret =bdrv_pwrite (new_bs, desc_offset, desc, desc_len); + +blk_set_allow_write_beyond_eof (new_blk, true); + + ret =blk_pwrite (new_blk, desc_offset, desc, desc_len);if (ret <0 ) {error_setg_errno (errp, -ret,"Could not write description" ); goto exit;
@@ -2031,14 +2040,14 @@ static int vmdk_create(const char *filename, QemuOpts *opts, Error **errp)/* bdrv_pwrite write padding zeros to align to sector, we don't need that * for description file */ if (desc_offset ==0 ) { - ret =bdrv_truncate (new_bs, desc_len); + ret =blk_truncate (new_blk, desc_len);if (ret <0 ) {error_setg_errno (errp, -ret,"Could not truncate file" ); } } exit: -if (new_bs) { -bdrv_unref (new_bs); +if (new_blk) { +blk_unref (new_blk); }g_free (adapter_type);g_free (backing_file);
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH 01/11] block: Use writeback in .bdrv_create() implementations
In reply to Kevin WolfQuoted 2 lines · Kevin Wolf
There's no reason to use a writethrough cache mode while creating an image.
There's no reason to do flushes in fact, so you could use BDRV_O_NO_FLUSH too. :)
Paolo
Quoted 155 lines
Signed-off-by Kevin Wolf <[email protected]>--- block/parallels.c | 3 ++- block/qcow.c | 3 ++- block/qcow2.c | 3 ++- block/sheepdog.c | 6 ++++-- block/vdi.c | 3 ++- block/vhdx.c | 3 ++- block/vmdk.c | 9 ++++++--- block/vpc.c | 3 ++- 8 files changed, 22 insertions(+), 11 deletions(-)block/parallels.c +2
-1@@ -479,7 +479,8 @@ static int parallels_create(const char *filename, QemuOpts *opts, Error **errp) file =NULL ; ret =bdrv_open (&file, filename,NULL ,NULL , -BDRV_O_RDWR |BDRV_O_PROTOCOL , &local_err); +BDRV_O_RDWR |BDRV_O_CACHE_WB |BDRV_O_PROTOCOL , + &local_err);if (ret <0 ) {error_propagate (errp, local_err);return ret;block/qcow.c +2
-1@@ -798,7 +798,8 @@ static int qcow_create(const char *filename, QemuOpts *opts, Error **errp) qcow_bs =NULL ; ret =bdrv_open (&qcow_bs, filename,NULL ,NULL , -BDRV_O_RDWR |BDRV_O_PROTOCOL , &local_err); +BDRV_O_RDWR |BDRV_O_CACHE_WB |BDRV_O_PROTOCOL , + &local_err);if (ret <0 ) {error_propagate (errp, local_err); goto cleanup;block/qcow2.c +2
-1@@ -2173,7 +2173,8 @@ static int qcow2_create2(const char *filename, int64_t total_size, } bs =NULL ; - ret =bdrv_open (&bs, filename,NULL ,NULL ,BDRV_O_RDWR |BDRV_O_PROTOCOL , + ret =bdrv_open (&bs, filename,NULL ,NULL , +BDRV_O_RDWR |BDRV_O_CACHE_WB |BDRV_O_PROTOCOL , &local_err);if (ret <0 ) {error_propagate (errp, local_err);block/sheepdog.c +4
-2@@ -1646,7 +1646,8 @@ static int sd_prealloc(const char *filename, Error **errp)void *buf =NULL ;int ret; - ret =bdrv_open (&bs, filename,NULL ,NULL ,BDRV_O_RDWR |BDRV_O_PROTOCOL , + ret =bdrv_open (&bs, filename,NULL ,NULL , +BDRV_O_RDWR |BDRV_O_CACHE_WB |BDRV_O_PROTOCOL , errp);if (ret <0 ) { goto out_with_err_set;@@ -1839,7 +1840,8 @@ static int sd_create(const char *filename, QemuOpts *opts, } bs =NULL ; - ret =bdrv_open (&bs, backing_file,NULL ,NULL ,BDRV_O_PROTOCOL , errp); + ret =bdrv_open (&bs, backing_file,NULL ,NULL , +BDRV_O_PROTOCOL |BDRV_O_CACHE_WB , errp);if (ret <0 ) { goto out; }block/vdi.c +2
-1@@ -766,7 +766,8 @@ 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_PROTOCOL , + ret =bdrv_open (&bs, filename,NULL ,NULL , +BDRV_O_RDWR |BDRV_O_CACHE_WB |BDRV_O_PROTOCOL , &local_err);if (ret <0 ) {error_propagate (errp, local_err);block/vhdx.c +2
-1@@ -1838,7 +1838,8 @@ static int vhdx_create(const char *filename, QemuOpts *opts, Error **errp) } bs =NULL ; - ret =bdrv_open (&bs, filename,NULL ,NULL ,BDRV_O_RDWR |BDRV_O_PROTOCOL , + ret =bdrv_open (&bs, filename,NULL ,NULL , +BDRV_O_RDWR |BDRV_O_CACHE_WB |BDRV_O_PROTOCOL , &local_err);if (ret <0 ) {error_propagate (errp, local_err);block/vmdk.c +6
-3@@ -1664,7 +1664,8 @@ static int vmdk_create_extent(const char *filename, int64_t filesize, }assert (bs ==NULL ); - ret =bdrv_open (&bs, filename,NULL ,NULL ,BDRV_O_RDWR |BDRV_O_PROTOCOL , + ret =bdrv_open (&bs, filename,NULL ,NULL , +BDRV_O_RDWR |BDRV_O_CACHE_WB |BDRV_O_PROTOCOL , &local_err);if (ret <0 ) {error_propagate (errp, local_err);@@ -1944,7 +1945,8 @@ static int vmdk_create(const char *filename, QemuOpts *opts, Error **errp) ret = -ENOENT ; goto exit; } - ret =bdrv_open (&bs, full_backing,NULL ,NULL ,BDRV_O_NO_BACKING , errp); + ret =bdrv_open (&bs, full_backing,NULL ,NULL , +BDRV_O_NO_BACKING |BDRV_O_CACHE_WB , errp);g_free (full_backing);if (ret !=0 ) { goto exit;@@ -2015,7 +2017,8 @@ static int vmdk_create(const char *filename, QemuOpts *opts, Error **errp) }assert (new_bs ==NULL ); ret =bdrv_open (&new_bs, filename,NULL ,NULL , -BDRV_O_RDWR |BDRV_O_PROTOCOL , &local_err); +BDRV_O_RDWR |BDRV_O_CACHE_WB |BDRV_O_PROTOCOL , + &local_err);if (ret <0 ) {error_propagate (errp, local_err); goto exit;block/vpc.c +2
-1@@ -886,7 +886,8 @@ static int vpc_create(const char *filename, QemuOpts *opts, Error **errp)error_propagate (errp, local_err); goto out; } - ret =bdrv_open (&bs, filename,NULL ,NULL ,BDRV_O_RDWR |BDRV_O_PROTOCOL , + ret =bdrv_open (&bs, filename,NULL ,NULL , +BDRV_O_RDWR |BDRV_O_CACHE_WB |BDRV_O_PROTOCOL , &local_err);if (ret <0 ) {error_propagate (errp, local_err);
Re: [Qemu-devel] [PATCH 01/11] block: Use writeback in .bdrv_create() implementations
Am 09.03.2016 um 13:14 hat Paolo Bonzini geschrieben:
Quoted 8 lines · Kevin Wolf
Quoted 2 lines
There's no reason to use a writethrough cache mode while creating an image.
There's no reason to do flushes in fact, so you could use
BDRV_O_NO_FLUSHtoo. :)
That's true. On the other hand, we don't issue flushes anyway, so there's little reason to ignore non-existing flushes. :-)
The only part where it might make sense is where image formats don't open the raw image file, but actually open the image with themselves and allocate things. qcow2 at least already sets BDRV_O_NO_FLUSH for that part.
In fact, the only bdrv_open() touched in this patch that doesn't have BDRV_O_PROTOCOL set, is one instance in VMDK where it opens the backing file to read some ID from the header. So no flush involved there.
Kevin
Kevin Wolf
AppliedAm 08.03.2016 um 17:34 hat Kevin Wolf geschrieben:
Quoted 9 lines
All users of the block layers are supposed to go through a BlockBackend. The .bdrv_create() implementations are such users, so this series converts them.
This series (specifically patch 1) will also help with moving the writethrough cache implementation from BDS to BB, where it really belongs. Once this is moved, it wouldn't be possible to use
bdrv_open()to use a standalone BDS writethrough any more.
Quoted 4 lines
Of course, writethrough doesn't make any sense in .bdrv_create() anyway, so while I'm still converting everything to BB where it would keep working (because that's the Right Thing), the drivers don't actually make use of this fact any more after this series.
Applied to the block branch.
Kevin
Quoted 10 lines · Kevin Wolf
Am 08.03.2016 um 17:34 hat Kevin Wolf geschrieben:
Quoted 9 lines
All users of the block layers are supposed to go through a BlockBackend. The .bdrv_create() implementations are such users, so this series converts them.
This series (specifically patch 1) will also help with moving the writethrough cache implementation from BDS to BB, where it really belongs. Once this is moved, it wouldn't be possible to use
bdrv_open()to use a standalone BDS writethrough any more.
Quoted 6 lines
Quoted 4 lines
Of course, writethrough doesn't make any sense in .bdrv_create() anyway, so while I'm still converting everything to BB where it would keep working (because that's the Right Thing), the drivers don't actually make use of this fact any more after this series.
Applied to the block branch.
Now you can't name any BB "image" any more if you want to use e.g. drive-mirror. Intended?
Example:
$ x86_64-softmmu/qemu-system-x86_64 -drive
if=none,id=image,file=null-co://,driver=raw -qmp stdio
{'execute':'qmp_capabilities'}
{"return": {}}
{'execute':'drive-mirror','arguments':{'device':'image','target':'foo.qcow2','sync':'full','format':'qcow2'}}
Formatting 'foo.qcow2', fmt=qcow2 size=1073741824 encryption=off
cluster_size=65536 lazy_refcounts=off refcount_bits=16
{"error": {"class": "GenericError", "desc": "Device with id 'image'
already exists"}}Max
Am 14.03.2016 um 17:55 hat Max Reitz geschrieben:
Quoted 16 lines · Kevin Wolf
Quoted 15 lines
Am 08.03.2016 um 17:34 hat Kevin Wolf geschrieben:
Quoted 13 lines
All users of the block layers are supposed to go through a BlockBackend. The .bdrv_create() implementations are such users, so this series converts them.
This series (specifically patch 1) will also help with moving the writethrough cache implementation from BDS to BB, where it really belongs. Once this is moved, it wouldn't be possible to use
bdrv_open()to use a standalone BDS writethrough any more.Of course, writethrough doesn't make any sense in .bdrv_create() anyway, so while I'm still converting everything to BB where it would keep working (because that's the Right Thing), the drivers don't actually make use of this fact any more after this series.
Quoted 4 lines
Quoted 1 line
Applied to the block branch.
Now you can't name any BB "image" any more if you want to use e.g. drive-mirror. Intended?
Not really. :-/
Of course, you're supposed to use blockdev-mirror anyway (does it even exist?), but we should avoid that. Fortunately, your "Further BB work" will tie the name to a monitor reference and BBs without a name become valid then, I think.
So this might be a good excuse for getting that series into 2.6. :-)
Kevin
Quoted 14 lines
Example:
$ x86_64-softmmu/qemu-system-x86_64 -drive if=none,id=image,file=null-co://,driver=raw -qmp stdio {'execute':'qmp_capabilities'} {"return": {}} {'execute':'drive-mirror','arguments':{'device':'image','target':'foo.qcow2','sync':'full','format':'qcow2'}} Formatting 'foo.qcow2', fmt=qcow2 size=1073741824 encryption=off cluster_size=65536 lazy_refcounts=off refcount_bits=16 {"error": {"class": "GenericError", "desc": "Device with id 'image' already exists"}}Max