block: Remove "growable", add blk_new_open()
v4 cover block: Remove "growable", add blk_new_open()
This series removes the "growable" field from the BlockDriverState object. Its use was to clamp guest requests against the limits of the BDS; however, this can now be done more easily by moving those checks into the BlockBackend functions.
In a future series, "growable" may be reintroduced (maybe with a different name); it will then signify whether a BDS is able to grow (in contrast to the current "growable", which signifies whether it is allowed to). Maybe I will add it to the BlockDriver instead of the BDS, though.
To be able to remove that field, qemu-io needs to be converted to BlockBackend, which is done by this series as well. While working on that I decided to convert blk_new_with_bs()+bdrv_open() to blk_new_open(). I was skeptical about that decision at first, but it seems good now that I was able to replace nearly every blk_new_with_bs() call by blk_new_open(). In a future series I may try to convert some remaining bdrv_open() calls to blk_new_open() as well. (And, in fact, in a future series I *will* replace the last remaining blk_new_with_bs() outside of blk_new_open() by blk_new_open().)
Finally, the question needs to be asked: If, after this series, every BDS is allowed to grow, are there any users which do not use BB, but should still be disallowed from reading/writing beyond a BDS's limits? The only users I could see were the block jobs. Some of them should indeed be converted to BB; but none of them takes a user-supplied offset or size, all work on the full BDS (or only on parts which have been modified, etc.). Therefore, it is by design impossible for them to exceed the BDS's limits, which makes making all BDS's growable safe.
v4:
- Patch 1: Added blk_nb_sectors() [Eric]
- Patch 3: Added in order to get a more useful error message than just "Unknown protocol" [Eric]
- Patch 4: Added [Eric]
- Patch 5:
- Use qdict_put() instead of qdict_put_obj() [Kevin]
- Rebased onto the new patches 3 and 4
- Patch 6:
- Note the fix for invalid drivers in the commit message; and note that the fix is not complete [Kevin]
- Use qdict_put() instead of qdict_put_obj() [Kevin]
- Patch 7: Use qdict_put() instead of qdict_put_obj() [Kevin]
- Patch 8:
- Do not skip output format validity test on unsafe [Kevin]
- Dropped superfluous !unsafe in condition [Eric]
- Use qdict_put() instead of qdict_put_obj() [Kevin]
- Patch 9: Use blk_nb_sectors() to replace bdrv_nb_sectors() (instead of blk_getlength() with a later division by BDRV_SECTOR_SIZE) [Eric]
- Patch 10: Use qdict_put() instead of qdict_put_obj() [Kevin]
- Patch 11: Dropped the hunk which removed the reset of qemuio_bs to NULL in close_f() [Kevin]
- Patch 12: Added a comment to the group file stating that 016 should not be reused [Eric/Kevin]
- Patch 13:
- Use blk_nb_sectors() to replace bdrv_nb-sectors() [Eric]
- Drop qemuio_bs [Kevin]
- Patch 15: Kept the "if (offset < 0)" check in bdrv_check_byte_request() [Kevin]
v3:
- Rebased (onto Stefan's branch rebased onto master)
- Fixed patch 4 [Stefano]
v2:
- Rebased [Kevin]
- Patch 2: Added a TODO comment about removing @filename and @flags from blk_new_open() when possible [Kevin]
git-backport-diff against v3:
Key:
[----] : patches are identical
[####] : number of functional differences between upstream/downstream patch [down] : patch is downstream-only
The flags [FC] indicate (F)unctional and (C)ontextual differences, respectively
001/16:[0006] [FC] 'block: Lift some BDS functions to the BlockBackend' 002/16:[----] [--] 'block: Add blk_new_open()'
003/16:[down] 'block: Add Error parameter to bdrv_find_protocol()' 004/16:[down] 'iotests: Add test for driver=qcow2,format=qcow2' 005/16:[0012] [FC] 'blockdev: Use blk_new_open() in blockdev_init()' 006/16:[0003] [FC] 'block/xen: Use blk_new_open() in blk_connect()' 007/16:[0002] [FC] 'qemu-img: Use blk_new_open() in img_open()' 008/16:[0016] [FC] 'qemu-img: Use blk_new_open() in img_rebase()' 009/16:[0030] [FC] 'qemu-img: Use BlockBackend as far as possible' 010/16:[0002] [FC] 'qemu-nbd: Use blk_new_open() in main()' 011/16:[0003] [FC] 'qemu-io: Use blk_new_open() in openfile()' 012/16:[0001] [FC] 'qemu-io: Remove "growable" option' 013/16:[0006] [FC] 'qemu-io: Use BlockBackend'
014/16:[----] [--] 'block: Clamp BlockBackend requests' 015/16:[0004] [FC] 'block: Remove "growable" from BDS' 016/16:[----] [--] 'block: Keep bdrv_check*_request()'s return value'
Max Reitz (16):
block: Lift some BDS functions to the BlockBackend
block: Add blk_new_open()
block: Add Error parameter to bdrv_find_protocol()
iotests: Add test for driver=qcow2,format=qcow2
blockdev: Use blk_new_open() in blockdev_init() block/xen: Use blk_new_open() in blk_connect()
qemu-img: Use blk_new_open() in img_open()
qemu-img: Use blk_new_open() in img_rebase()
qemu-img: Use BlockBackend as far as possible
qemu-nbd: Use blk_new_open() in main()
qemu-io: Use blk_new_open() in openfile()
qemu-io: Remove "growable" option
qemu-io: Use BlockBackend
block: Clamp BlockBackend requests
block: Remove "growable" from BDS
block: Keep bdrv_check*_request()'s return value
block.c | 73 +++++++------ block/block-backend.c | 224 ++++++++++++++++++++++++++++++++++++++ block/qcow2.c | 6 -- block/raw-posix.c | 2 +- block/raw-win32.c | 2 +- block/sheepdog.c | 4 +- blockdev.c | 92 ++++++++-------- hmp.c | 9 +- hw/block/xen_disk.c | 27 ++--- include/block/block.h | 3 +- include/block/block_int.h | 3 - include/qemu-io.h | 4 +- include/sysemu/block-backend.h | 13 +++ qemu-img.c | 158 +++++++++++++-------------- qemu-io-cmds.c | 237 +++++++++++++++++++++-------------------- qemu-io.c | 58 +++------- qemu-nbd.c | 25 ++--- tests/qemu-iotests/016 | 73 ------------- tests/qemu-iotests/016.out | 23 ---- tests/qemu-iotests/051 | 1 + tests/qemu-iotests/051.out | 63 +++++------ tests/qemu-iotests/087.out | 8 +- tests/qemu-iotests/group | 2 +- 23 files changed, 603 insertions(+), 507 deletions(-) delete mode 100755 tests/qemu-iotests/016 delete mode 100644 tests/qemu-iotests/016.out
Signature · 1 line
2.1.0
PATCH v4 1/16 block: Lift some BDS functions to the BlockBackend
Create the blk_* counterparts for the following bdrv_* functions (which make sense to call on the BlockBackend level):
- bdrv_co_write_zeroes()
- bdrv_write_compressed()
- bdrv_truncate()
- bdrv_nb_sectors()
- bdrv_discard()
- bdrv_load_vmstate()
- bdrv_save_vmstate()
--- block/block-backend.c | 38 ++++++++++++++++++++++++++++++++++++++ include/sysemu/block-backend.h | 10 ++++++++++ 2 files changed, 48 insertions(+)
block/block-backend.c +38 -0
@@ -440,6 +440,11 @@ void blk_get_geometry(BlockBackend *blk, uint64_t *nb_sectors_ptr)bdrv_get_geometry (blk->bs, nb_sectors_ptr); } +int64_t blk_nb_sectors (BlockBackend *blk) +{ +return bdrv_nb_sectors (blk->bs); +} +BlockAIOCB *blk_aio_readv (BlockBackend *blk,int64_t sector_num,QEMUIOVector *iov,int nb_sectors,BlockCompletionFunc *cb,void *opaque)
@@ -668,3 +673,36 @@ void *blk_aio_get(const AIOCBInfo *aiocb_info, BlockBackend *blk, {return qemu_aio_get (aiocb_info,blk_bs (blk), cb, opaque); } + +int coroutine_fn blk_co_write_zeroes(BlockBackend *blk, int64_t sector_num, +int nb_sectors,BdrvRequestFlags flags) +{ +return bdrv_co_write_zeroes (blk->bs, sector_num, nb_sectors, flags); +} + +int blk_write_compressed (BlockBackend *blk,int64_t sector_num, +const uint8_t *buf,int nb_sectors) +{ +return bdrv_write_compressed (blk->bs, sector_num, buf, nb_sectors); +} + +int blk_truncate (BlockBackend *blk,int64_t offset) +{ +return bdrv_truncate (blk->bs, offset); +} + +int blk_discard (BlockBackend *blk,int64_t sector_num,int nb_sectors) +{ +return bdrv_discard (blk->bs, sector_num, nb_sectors); +} + +int blk_save_vmstate (BlockBackend *blk,const uint8_t *buf, +int64_t pos,int size) +{ +return bdrv_save_vmstate (blk->bs, buf, pos, size); +} + +int blk_load_vmstate (BlockBackend *blk,uint8_t *buf,int64_t pos,int size) +{ +return bdrv_load_vmstate (blk->bs, buf, pos, size); +}
include/sysemu/block-backend.h +10 -0
@@ -91,6 +91,7 @@ int blk_pread(BlockBackend *blk, int64_t offset, void *buf, int count);int blk_pwrite (BlockBackend *blk,int64_t offset,const void *buf,int count);int64_t blk_getlength (BlockBackend *blk);void blk_get_geometry (BlockBackend *blk,uint64_t *nb_sectors_ptr); +int64_t blk_nb_sectors (BlockBackend *blk);BlockAIOCB *blk_aio_readv (BlockBackend *blk,int64_t sector_num,QEMUIOVector *iov,int nb_sectors,BlockCompletionFunc *cb,void *opaque);
@@ -151,5 +152,14 @@ BlockAcctStats *blk_get_stats(BlockBackend *blk);void *blk_aio_get (const AIOCBInfo *aiocb_info,BlockBackend *blk,BlockCompletionFunc *cb,void *opaque); +int coroutine_fn blk_co_write_zeroes(BlockBackend *blk, int64_t sector_num, +int nb_sectors,BdrvRequestFlags flags); +int blk_write_compressed (BlockBackend *blk,int64_t sector_num, +const uint8_t *buf,int nb_sectors); +int blk_truncate (BlockBackend *blk,int64_t offset); +int blk_discard (BlockBackend *blk,int64_t sector_num,int nb_sectors); +int blk_save_vmstate (BlockBackend *blk,const uint8_t *buf, +int64_t pos,int size); +int blk_load_vmstate (BlockBackend *blk,uint8_t *buf,int64_t pos,int size);#endif
Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH v4 01/16] block: Lift some BDS functions to the BlockBackend
Quoted 10 lines · Max Reitz
Create the blk_* counterparts for the following bdrv_* functions (which make sense to call on the BlockBackend level):
-bdrv_co_write_zeroes()
-bdrv_write_compressed()
-bdrv_truncate()
-bdrv_nb_sectors()
-bdrv_discard()
-bdrv_load_vmstate()
-bdrv_save_vmstate()
Quoted 5 lines
Signed-off-by Max Reitz <[email protected]>--- block/block-backend.c | 38 ++++++++++++++++++++++++++++++++++++++ include/sysemu/block-backend.h | 10 ++++++++++ 2 files changed, 48 insertions(+)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH v4 01/16] block: Lift some BDS functions to the BlockBackend
In reply to Max ReitzQuoted 10 lines · Max Reitz
Create the blk_* counterparts for the following bdrv_* functions (which make sense to call on the BlockBackend level):
-bdrv_co_write_zeroes()
-bdrv_write_compressed()
-bdrv_truncate()
-bdrv_nb_sectors()
-bdrv_discard()
-bdrv_load_vmstate()
-bdrv_save_vmstate()
Quoted 5 lines
Signed-off-by Max Reitz <[email protected]>--- block/block-backend.c | 38 ++++++++++++++++++++++++++++++++++++++ include/sysemu/block-backend.h | 10 ++++++++++ 2 files changed, 48 insertions(+)
PATCH v4 2/16 block: Add blk_new_open()
In reply to Max Reitzblk_new_with_bs() creates a BlockBackend with an empty BlockDriverState attached to it. Empty BDSs are not nice, therefore add an alternative function which combines blk_new_with_bs() with bdrv_open().
Note: In contrast to bdrv_open() which takes a BlockDriver parameter, blk_new_open() does not take such a parameter. This is because bdrv_open() opens a BlockDriverState, therefore it is natural to be able to set the BlockDriver for that BDS. The fact that bdrv_open() can open more than a single BDS is merely some form of a byproduct.
blk_new_open() on the other hand is intended to be used to create a whole tree of BlockDriverStates. Therefore, setting a single BlockDriver does not make much sense. Instead, the drivers to be used for each of the nodes must be configured through the "options" QDict; including the driver of the root BDS.
--- block/block-backend.c | 34 ++++++++++++++++++++++++++++++++++ include/sysemu/block-backend.h | 3 +++ 2 files changed, 37 insertions(+)
block/block-backend.c +34 -0
@@ -91,6 +91,40 @@ BlockBackend *blk_new_with_bs(const char *name, Error **errp)return blk; } +/* +* Calls blk_new_with_bs() and then calls bdrv_open() on the BlockDriverState. +* +* Just as with bdrv_open(), after having called this function the reference to +* @options belongs to the block layer (even on failure). +* +* TODO: Remove @filename and @flags; it should be possible to specify a whole +* BDS tree just by specifying the @options QDict (or @reference, +* alternatively). At the time of adding this function, this is not possible, +* though, so callers of this function have to be able to specify @filename and +* @flags. +*/ +BlockBackend *blk_new_open (const char *name,const char *filename, +const char *reference,QDict *options,int flags, +Error **errp) +{ +BlockBackend *blk; +int ret; + + blk =blk_new_with_bs (name, errp); +if (!blk) { +QDECREF (options); +return NULL ; + } + + ret =bdrv_open (&blk->bs, filename, reference, options, flags,NULL , errp); +if (ret <0 ) { +blk_unref (blk); +return NULL ; + } + +return blk; +} +static void blk_delete (BlockBackend *blk) {assert (!blk->refcnt);
include/sysemu/block-backend.h +3 -0
@@ -62,6 +62,9 @@ typedef struct BlockDevOps {BlockBackend *blk_new (const char *name,Error **errp);BlockBackend *blk_new_with_bs (const char *name,Error **errp); +BlockBackend *blk_new_open (const char *name,const char *filename, +const char *reference,QDict *options,int flags, +Error **errp);void blk_ref (BlockBackend *blk);void blk_unref (BlockBackend *blk);const char *blk_name (BlockBackend *blk);
Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH v4 02/16] block: Add blk_new_open()
Quoted 16 lines · Max Reitz
blk_new_with_bs()creates a BlockBackend with an empty BlockDriverState attached to it. Empty BDSs are not nice, therefore add an alternative function which combinesblk_new_with_bs()withbdrv_open().Note: In contrast to
bdrv_open()which takes a BlockDriver parameter,blk_new_open()does not take such a parameter. This is becausebdrv_open()opens a BlockDriverState, therefore it is natural to be able to set the BlockDriver for that BDS. The fact thatbdrv_open()can open more than a single BDS is merely some form of a byproduct.
blk_new_open()on the other hand is intended to be used to create a whole tree of BlockDriverStates. Therefore, setting a single BlockDriver does not make much sense. Instead, the drivers to be used for each of the nodes must be configured through the "options" QDict; including the driver of the root BDS.
Quoted 7 lines
Signed-off-by Max Reitz <[email protected]>Reviewed-by Eric Blake <[email protected]>Reviewed-by Kevin Wolf <[email protected]>--- block/block-backend.c | 34 ++++++++++++++++++++++++++++++++++ include/sysemu/block-backend.h | 3 +++ 2 files changed, 37 insertions(+)
PATCH v4 3/16 block: Add Error parameter to bdrv_find_protocol()
In reply to Max ReitzThe argument given to bdrv_find_protocol() is just a file name, which makes it difficult for the caller to reconstruct what protocol bdrv_find_protocol() was hoping to find. This patch adds an Error parameter to that function to solve this issue.
--- block.c | 14 +++++++------- block/sheepdog.c | 2 +- include/block/block.h | 3 ++- qemu-img.c | 11 +++++++---- tests/qemu-iotests/051.out | 4 ++-- 5 files changed, 19 insertions(+), 15 deletions(-)
block.c +7 -7
@@ -508,9 +508,8 @@ int bdrv_create_file(const char *filename, QemuOpts *opts, Error **errp)Error *local_err =NULL ;int ret; - drv =bdrv_find_protocol (filename, true); + drv =bdrv_find_protocol (filename, true, errp);if (drv ==NULL ) { -error_setg (errp,"Could not find protocol for file '%s'" , filename);return -ENOENT ; }
@@ -628,7 +627,8 @@ static BlockDriver *find_hdev_driver(const char *filename) }BlockDriver *bdrv_find_protocol (const char *filename, -bool allow_protocol_prefix) +bool allow_protocol_prefix, +Error **errp) {BlockDriver *drv1;char protocol[128 ];
@@ -666,6 +666,8 @@ BlockDriver *bdrv_find_protocol(const char *filename,return drv1; } } + +error_setg (errp,"Unknown protocol '%s'" , protocol);return NULL ; }
@@ -1136,9 +1138,8 @@ static int bdrv_fill_options(QDict **options, const char **pfilename, int flags, }else {if (!drvname && protocol) {if (filename) { - drv =bdrv_find_protocol (filename, parse_filename); + drv =bdrv_find_protocol (filename, parse_filename, errp);if (!drv) { -error_setg (errp,"Unknown protocol" );return -EINVAL ; }
@@ -5626,9 +5627,8 @@ void bdrv_img_create(const char *filename, const char *fmt,return ; } - proto_drv =bdrv_find_protocol (filename, true); + proto_drv =bdrv_find_protocol (filename, true, errp);if (!proto_drv) { -error_setg (errp,"Unknown protocol '%s'" , filename);return ; }
block/sheepdog.c +1 -1
@@ -1730,7 +1730,7 @@ static int sd_create(const char *filename, QemuOpts *opts,BlockDriver *drv;/* Currently, only Sheepdog backing image is supported. */ - drv =bdrv_find_protocol (backing_file, true); + drv =bdrv_find_protocol (backing_file, true,NULL );if (!drv ||strcmp (drv->protocol_name,"sheepdog" ) !=0 ) {error_setg (errp,"backing_file must be a sheepdog image" ); ret = -EINVAL ;
include/block/block.h +2 -1
@@ -165,7 +165,8 @@ void bdrv_io_limits_disable(BlockDriverState *bs);void bdrv_init (void );void bdrv_init_with_whitelist (void );BlockDriver *bdrv_find_protocol (const char *filename, -bool allow_protocol_prefix); +bool allow_protocol_prefix, +Error **errp);BlockDriver *bdrv_find_format (const char *format_name);BlockDriver *bdrv_find_whitelisted_format (const char *format_name,bool readonly);
qemu-img.c +7 -4
@@ -261,6 +261,7 @@ static int print_block_option_help(const char *filename, const char *fmt) {BlockDriver *drv, *proto_drv;QemuOptsList *create_opts =NULL ; +Error *local_err =NULL ;/* Find driver and parse its options */ drv =bdrv_find_format (fmt);
@@ -271,9 +272,10 @@ static int print_block_option_help(const char *filename, const char *fmt) create_opts =qemu_opts_append (create_opts, drv->create_opts);if (filename) { - proto_drv =bdrv_find_protocol (filename, true); + proto_drv =bdrv_find_protocol (filename, true, &local_err);if (!proto_drv) { -error_report ("Unknown protocol '%s'" , filename); +qerror_report_err (local_err); +error_free (local_err);qemu_opts_free (create_opts);return 1 ; }
@@ -1524,9 +1526,10 @@ static int img_convert(int argc, char **argv) goto out; } - proto_drv =bdrv_find_protocol (out_filename, true); + proto_drv =bdrv_find_protocol (out_filename, true, &local_err);if (!proto_drv) { -error_report ("Unknown protocol '%s'" , out_filename); +qerror_report_err (local_err); +error_free (local_err); ret =-1 ; goto out; }
tests/qemu-iotests/051.out +2 -2
@@ -323,10 +323,10 @@ QEMU_PROG: -drive file=TEST_DIR/t.qcow2,readonly=on,read-only=off: 'read-only' a === Parsing protocol from file name === Testing: -hda foo:bar -QEMU_PROG: -hda foo:bar: could not open disk image foo:bar: Unknown protocol +QEMU_PROG: -hda foo:bar: could not open disk image foo:bar: Unknown protocol 'foo' Testing: -drive file=foo:bar -QEMU_PROG: -drive file=foo:bar: could not open disk image foo:bar: Unknown protocol +QEMU_PROG: -drive file=foo:bar: could not open disk image foo:bar: Unknown protocol 'foo' Testing: -drive file.filename=foo:bar QEMU_PROG: -drive file.filename=foo:bar: could not open disk image ide0-hd0: Could not open 'foo:bar': No such file or directory
Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH v4 03/16] block: Add Error parameter to bdrv_find_protocol()
Quoted 18 lines · Max Reitz
The argument given to
bdrv_find_protocol()is just a file name, which makes it difficult for the caller to reconstruct what protocolbdrv_find_protocol()was hoping to find. This patch adds an Error parameter to that function to solve this issue.Suggested-by Eric Blake <[email protected]>Signed-off-by Max Reitz <[email protected]>--- block.c | 14 +++++++------- block/sheepdog.c | 2 +- include/block/block.h | 3 ++- qemu-img.c | 11 +++++++---- tests/qemu-iotests/051.out | 4 ++-- 5 files changed, 19 insertions(+), 15 deletions(-)Testing: -hda foo:bar
tests/qemu-iotests/051.out QEMU_PROG: -drive file=TEST_DIR/t.qcow2,readonly=on,read-only=off: 'read-only' a · line 326
Quoted 2 lines
tests/qemu-iotests/051.out +1
-1-QEMU_PROG: -hda foo:bar: could not open disk image foo:bar: Unknown protocol +QEMU_PROG: -hda foo:bar: could not open disk image foo:bar: Unknown protocol 'foo'
Indeed a nicer message.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH v4 03/16] block: Add Error parameter to bdrv_find_protocol()
In reply to Max ReitzQuoted 7 lines · Max Reitz
The argument given to
bdrv_find_protocol()is just a file name, which makes it difficult for the caller to reconstruct what protocolbdrv_find_protocol()was hoping to find. This patch adds an Error parameter to that function to solve this issue.Suggested-by Eric Blake <[email protected]>Signed-off-by Max Reitz <[email protected]>
Quoted 7 lines
--- block.c | 14 +++++++------- block/sheepdog.c | 2 +- include/block/block.h | 3 ++- qemu-img.c | 11 +++++++---- tests/qemu-iotests/051.out | 4 ++-- 5 files changed, 19 insertions(+), 15 deletions(-)
PATCH v4 4/16 iotests: Add test for driver=qcow2, format=qcow2
In reply to Max ReitzWhile specifying a different driver and format is obviously invalid, specifying the same driver once through driver and once through format is invalid as well. Add a test for it.
--- tests/qemu-iotests/051 | 1 + tests/qemu-iotests/051.out | 3 +++ 2 files changed, 4 insertions(+)
tests/qemu-iotests/051 +1 -0
@@ -93,6 +93,7 @@ echo run_qemu -drive file="$TEST_IMG",format=foo run_qemu -drive file="$TEST_IMG",driver=foo run_qemu -drive file="$TEST_IMG",driver=raw,format=qcow2 +run_qemu -drive file="$TEST_IMG",driver=qcow2,format=qcow2 echo echo === Overriding backing file ===
tests/qemu-iotests/051.out +3 -0
@@ -43,6 +43,9 @@ QEMU_PROG: -drive file=TEST_DIR/t.qcow2,driver=foo: could not open disk image TE Testing: -drive file=TEST_DIR/t.qcow2,driver=raw,format=qcow2 QEMU_PROG: -drive file=TEST_DIR/t.qcow2,driver=raw,format=qcow2: could not open disk image TEST_DIR/t.qcow2: Driver specified twice +Testing: -drive file=TEST_DIR/t.qcow2,driver=qcow2,format=qcow2 +QEMU_PROG: -drive file=TEST_DIR/t.qcow2,driver=qcow2,format=qcow2: could not open disk image TEST_DIR/t.qcow2: Driver specified twice + === Overriding backing file ===
Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH v4 04/16] iotests: Add test for driver=qcow2, format=qcow2
Quoted 10 lines · Max Reitz
While specifying a different driver and format is obviously invalid, specifying the same driver once through driver and once through format is invalid as well. Add a test for it.
Signed-off-by Max Reitz <[email protected]>--- tests/qemu-iotests/051 | 1 + tests/qemu-iotests/051.out | 3 +++ 2 files changed, 4 insertions(+)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH v4 04/16] iotests: Add test for driver=qcow2, format=qcow2
In reply to Max ReitzQuoted 9 lines · Max Reitz
While specifying a different driver and format is obviously invalid, specifying the same driver once through driver and once through format is invalid as well. Add a test for it.
Signed-off-by Max Reitz <[email protected]>--- tests/qemu-iotests/051 | 1 + tests/qemu-iotests/051.out | 3 +++ 2 files changed, 4 insertions(+)
PATCH v4 5/16 blockdev: Use blk_new_open() in blockdev_init()
In reply to Max ReitzDue to different error propagation, this breaks tests 051 and 087; fix their output.
--- blockdev.c | 92 +++++++++++++++++++++------------------------- tests/qemu-iotests/051.out | 62 +++++++++++++++---------------- tests/qemu-iotests/087.out | 8 ++-- 3 files changed, 77 insertions(+), 85 deletions(-)
blockdev.c +42 -50
@@ -354,13 +354,11 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,ThrottleConfig cfg;int snapshot =0 ;bool copy_on_read; -int ret;Error *error =NULL ;QemuOpts *opts;const char *id;bool has_driver_specific_opts;BlockdevDetectZeroesOptions detect_zeroes; -BlockDriver *drv =NULL ;/* Check common options by copying from bs_opts to opts, all other options * stay in bs_opts for processing by bdrv_open(). */
@@ -426,11 +424,11 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts, goto early_err; } - drv =bdrv_find_format (buf); -if (!drv) { -error_setg (errp,"'%s' invalid format" , buf); +if (qdict_haskey (bs_opts,"driver" )) { +error_setg (errp,"Cannot specify both 'driver' and 'format'" ); goto early_err; } +qdict_put (bs_opts,"driver" ,qstring_from_str (buf)); }/* disk I/O throttling */
@@ -505,70 +503,64 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts, }/* init */ - blk =blk_new_with_bs (qemu_opts_id (opts), errp); -if (!blk) { - goto early_err; - } - bs =blk_bs (blk); - bs->open_flags = snapshot ?BDRV_O_SNAPSHOT :0 ; - bs->read_only = ro; - bs->detect_zeroes = detect_zeroes; - -bdrv_set_on_error (bs, on_read_error, on_write_error); +if ((!file || !*file) && !has_driver_specific_opts) { + blk =blk_new_with_bs (qemu_opts_id (opts), errp); +if (!blk) { + goto early_err; + } -/* disk I/O throttling */ -if (throttle_enabled (&cfg)) { -bdrv_io_limits_enable (bs); -bdrv_set_io_limits (bs, &cfg); - } + bs =blk_bs (blk); + bs->open_flags = snapshot ?BDRV_O_SNAPSHOT :0 ; + bs->read_only = ro; -if (!file || !*file) { -if (has_driver_specific_opts) { +QDECREF (bs_opts); + }else { +if (file && !*file) { file =NULL ; - }else { -QDECREF (bs_opts); -qemu_opts_del (opts); -return blk; } - } -if (snapshot) { -/* always use cache=unsafe with snapshot */ - bdrv_flags &= ~BDRV_O_CACHE_MASK ; - bdrv_flags |= (BDRV_O_SNAPSHOT |BDRV_O_CACHE_WB |BDRV_O_NO_FLUSH ); - } -if (copy_on_read) { - bdrv_flags |=BDRV_O_COPY_ON_READ ; - } +if (snapshot) { +/* always use cache=unsafe with snapshot */ + bdrv_flags &= ~BDRV_O_CACHE_MASK ; + bdrv_flags |= (BDRV_O_SNAPSHOT |BDRV_O_CACHE_WB |BDRV_O_NO_FLUSH ); + } + +if (copy_on_read) { + bdrv_flags |=BDRV_O_COPY_ON_READ ; + } + +if (runstate_check (RUN_STATE_INMIGRATE )) { + bdrv_flags |=BDRV_O_INCOMING ; + } -if (runstate_check (RUN_STATE_INMIGRATE )) { - bdrv_flags |=BDRV_O_INCOMING ; + bdrv_flags |= ro ?0 :BDRV_O_RDWR ; + + blk =blk_new_open (qemu_opts_id (opts), file,NULL , bs_opts, bdrv_flags, + errp); +if (!blk) { + goto err_no_bs_opts; + } + bs =blk_bs (blk); } - bdrv_flags |= ro ?0 :BDRV_O_RDWR ; + bs->detect_zeroes = detect_zeroes; -QINCREF (bs_opts); - ret =bdrv_open (&bs, file,NULL , bs_opts, bdrv_flags, drv, &error); -assert (bs ==blk_bs (blk)); +bdrv_set_on_error (bs, on_read_error, on_write_error); -if (ret <0 ) { -error_setg (errp,"could not open disk image %s: %s" , - file ?:blk_name (blk),error_get_pretty (error)); -error_free (error); - goto err; +/* disk I/O throttling */ +if (throttle_enabled (&cfg)) { +bdrv_io_limits_enable (bs); +bdrv_set_io_limits (bs, &cfg); }if (bdrv_key_required (bs)) { autostart =0 ; } -QDECREF (bs_opts); +err_no_bs_opts:qemu_opts_del (opts); -return blk; -err: -blk_unref (blk); early_err:qemu_opts_del (opts); err_no_opts:
tests/qemu-iotests/051.out +31 -31
161 lines not on this page · raw message
tests/qemu-iotests/087.out +4 -4
@@ -21,9 +21,9 @@ QMP_VERSION {"return": {}} {"error": {"class": "GenericError", "desc": "Device with id 'disk' already exists"}} {"error": {"class": "GenericError", "desc": "Device name 'test-node' conflicts with an existing node name"}} -{"error": {"class": "GenericError", "desc": "could not open disk image disk2: node-name=disk is conflicting with a device id"}} -{"error": {"class": "GenericError", "desc": "could not open disk image disk2: Duplicate node name"}} -{"error": {"class": "GenericError", "desc": "could not open disk image disk3: node-name=disk3 is conflicting with a device id"}} +{"error": {"class": "GenericError", "desc": "node-name=disk is conflicting with a device id"}} +{"error": {"class": "GenericError", "desc": "Duplicate node name"}} +{"error": {"class": "GenericError", "desc": "node-name=disk3 is conflicting with a device id"}} {"return": {}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN"} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "DEVICE_TRAY_MOVED", "data": {"device": "ide1-cd0", "tray-open": true}}
@@ -57,7 +57,7 @@ QMP_VERSION Testing: QMP_VERSION {"return": {}} -{"error": {"class": "GenericError", "desc": "could not open disk image disk: Guest must be stopped for opening of encrypted image"}} +{"error": {"class": "GenericError", "desc": "Guest must be stopped for opening of encrypted image"}} {"return": {}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN"} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "DEVICE_TRAY_MOVED", "data": {"device": "ide1-cd0", "tray-open": true}}
Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH v4 05/16] blockdev: Use blk_new_open() in blockdev_init()
Quoted 13 lines · Max Reitz
Due to different error propagation, this breaks tests 051 and 087; fix their output.
Signed-off-by Max Reitz <[email protected]>--- blockdev.c | 92 +++++++++++++++++++++------------------------- tests/qemu-iotests/051.out | 62 +++++++++++++++---------------- tests/qemu-iotests/087.out | 8 ++-- 3 files changed, 77 insertions(+), 85 deletions(-)Testing: -drive file=TEST_DIR/t.qcow2,driver=qcow2,format=qcow2
tests/qemu-iotests/051.out Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 backing_file='TEST_DIR · line 47
Quoted 2 lines
tests/qemu-iotests/051.out +1
-1-QEMU_PROG: -drive file=TEST_DIR/t.qcow2,driver=qcow2,format=qcow2: could not open disk image TEST_DIR/t.qcow2: Driver specified twice +QEMU_PROG: -drive file=TEST_DIR/t.qcow2,driver=qcow2,format=qcow2: Cannot specify both 'driver' and 'format'
This one is a nice improvement; I'm glad we added the test in 4/16.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH v4 05/16] blockdev: Use blk_new_open() in blockdev_init()
In reply to Max ReitzQuoted 9 lines · Max Reitz
Due to different error propagation, this breaks tests 051 and 087; fix their output.
Signed-off-by Max Reitz <[email protected]>--- blockdev.c | 92 +++++++++++++++++++++------------------------- tests/qemu-iotests/051.out | 62 +++++++++++++++---------------- tests/qemu-iotests/087.out | 8 ++-- 3 files changed, 77 insertions(+), 85 deletions(-)
PATCH v4 6/16 block/xen: Use blk_new_open() in blk_connect()
In reply to Max ReitzAs part of the required changes, this fixes a bug where specifying an invalid driver would result in the block layer probing the image format; now it will result in an error, unless "<unset>" is specified as the driver name. Fixing this would require further work on the xen_disk code which does not seem worth it (at this point and for this patch).
--- hw/block/xen_disk.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-)
hw/block/xen_disk.c +11 -16
@@ -40,6 +40,8 @@#include "xen_blkif.h" #include "sysemu/blockdev.h" #include "sysemu/block-backend.h" +#include "qapi/qmp/qdict.h" +#include "qapi/qmp/qstring.h" /* ------------------------------------------------------------- */
@@ -897,30 +899,23 @@ static int blk_connect(struct XenDevice *xendev) blkdev->dinfo =drive_get (IF_XEN ,0 , index);if (!blkdev->dinfo) {Error *local_err =NULL ; -BlockBackend *blk; -BlockDriver *drv; -BlockDriverState *bs; +QDict *options =NULL ; -/* setup via xenbus -> create new block driver instance */ -xen_be_printf (&blkdev->xendev,2 ,"create new bdrv (xenbus setup)\n" ); - blk =blk_new_with_bs (blkdev->dev,NULL ); -if (!blk) { -return -1 ; +if (strcmp (blkdev->fileproto,"<unset>" )) { + options =qdict_new (); +qdict_put (options,"driver" ,qstring_from_str (blkdev->fileproto)); } - blkdev->blk = blk; - bs =blk_bs (blk); - drv =bdrv_find_whitelisted_format (blkdev->fileproto, readonly); -if (bdrv_open (&bs, blkdev->filename,NULL ,NULL , qflags, - drv, &local_err) !=0 ) { +/* setup via xenbus -> create new block driver instance */ +xen_be_printf (&blkdev->xendev,2 ,"create new bdrv (xenbus setup)\n" ); + blkdev->blk =blk_new_open (blkdev->dev, blkdev->filename,NULL , options, + qflags, &local_err); +if (!blkdev->blk) {xen_be_printf (&blkdev->xendev,0 ,"error: %s\n" ,error_get_pretty (local_err));error_free (local_err); -blk_unref (blk); - blkdev->blk =NULL ;return -1 ; } -assert (bs ==blk_bs (blk)); }else {/* setup via qemu cmdline -> already setup for us */ xen_be_printf (&blkdev->xendev,2 ,"get configured bdrv (cmdline setup)\n" );
Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH v4 06/16] block/xen: Use blk_new_open() in blk_connect()
Quoted 5 lines · Max Reitz
As part of the required changes, this fixes a bug where specifying an invalid driver would result in the block layer probing the image format; now it will result in an error, unless "<unset>" is specified as the driver name. Fixing this would require further work on the
xen_diskcode which does not seem worth it (at this point and for this patch).
With enough hand-waving in the commit message, you can justify practically any partial fix :)
Strictly better than pre-patch, and I agree that worrying about the remaining warts is out of scope for this series.
Quoted 6 lines
Signed-off-by Max Reitz <[email protected]>--- hw/block/xen_disk.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH v4 06/16] block/xen: Use blk_new_open() in blk_connect()
In reply to Max ReitzQuoted 10 lines · Max Reitz
As part of the required changes, this fixes a bug where specifying an invalid driver would result in the block layer probing the image format; now it will result in an error, unless "<unset>" is specified as the driver name. Fixing this would require further work on the
xen_diskcode which does not seem worth it (at this point and for this patch).Signed-off-by Max Reitz <[email protected]>--- hw/block/xen_disk.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-)
PATCH v4 7/16 qemu-img: Use blk_new_open() in img_open()
In reply to Max Reitz--- qemu-img.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-)
qemu-img.c +6 -14
@@ -293,32 +293,24 @@ static BlockBackend *img_open(const char *id, const char *filename, {BlockBackend *blk;BlockDriverState *bs; -BlockDriver *drv;char password[256 ];Error *local_err =NULL ; -int ret; - - blk =blk_new_with_bs (id, &error_abort); - bs =blk_bs (blk); +QDict *options =NULL ;if (fmt) { - drv =bdrv_find_format (fmt); -if (!drv) { -error_report ("Unknown file format '%s'" , fmt); - goto fail; - } - }else { - drv =NULL ; + options =qdict_new (); +qdict_put (options,"driver" ,qstring_from_str (fmt)); } - ret =bdrv_open (&bs, filename,NULL ,NULL , flags, drv, &local_err); -if (ret <0 ) { + blk =blk_new_open (id, filename,NULL , options, flags, &local_err); +if (!blk) {error_report ("Could not open '%s': %s" , filename,error_get_pretty (local_err));error_free (local_err); goto fail; } + bs =blk_bs (blk);if (bdrv_is_encrypted (bs) && require_io) {qprintf (quiet,"Disk image '%s' is encrypted.\n" , filename);if (read_password (password,sizeof (password)) <0 ) {
Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH v4 07/16] qemu-img: Use blk_new_open() in img_open()
Quoted 5 lines · Max Reitz
Signed-off-by Max Reitz <[email protected]>--- qemu-img.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH v4 07/16] qemu-img: Use blk_new_open() in img_open()
In reply to Max ReitzQuoted 4 lines · Max Reitz
Signed-off-by Max Reitz <[email protected]>--- qemu-img.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-)
PATCH v4 8/16 qemu-img: Use blk_new_open() in img_rebase()
In reply to Max Reitz--- qemu-img.c | 49 +++++++++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 26 deletions(-)
qemu-img.c +23 -26
@@ -2433,7 +2433,6 @@ static int img_rebase(int argc, char **argv) {BlockBackend *blk =NULL , *blk_old_backing =NULL , *blk_new_backing =NULL ;BlockDriverState *bs =NULL , *bs_old_backing =NULL , *bs_new_backing =NULL ; -BlockDriver *old_backing_drv, *new_backing_drv;char *filename;const char *fmt, *cache, *src_cache, *out_basefmt, *out_baseimg;int c, flags, src_flags, ret;
@@ -2527,22 +2526,8 @@ static int img_rebase(int argc, char **argv) } bs =blk_bs (blk); -/* Find the right drivers for the backing files */ - old_backing_drv =NULL ; - new_backing_drv =NULL ; - -if (!unsafe && bs->backing_format[0 ] !='\0' ) { - old_backing_drv =bdrv_find_format (bs->backing_format); -if (old_backing_drv ==NULL ) { -error_report ("Invalid format name: '%s'" , bs->backing_format); - ret =-1 ; - goto out; - } - } -if (out_basefmt !=NULL ) { - new_backing_drv =bdrv_find_format (out_basefmt); -if (new_backing_drv ==NULL ) { +if (bdrv_find_format (out_basefmt) ==NULL ) {error_report ("Invalid format name: '%s'" , out_basefmt); ret =-1 ; goto out;
@@ -2552,29 +2537,41 @@ static int img_rebase(int argc, char **argv)/* For safe rebasing we need to compare old and new backing file */ if (!unsafe) {char backing_name[PATH_MAX ]; +QDict *options =NULL ; + +if (bs->backing_format[0 ] !='\0' ) { + options =qdict_new (); +qdict_put (options,"driver" ,qstring_from_str (bs->backing_format)); + } - blk_old_backing =blk_new_with_bs ("old_backing" , &error_abort); - bs_old_backing =blk_bs (blk_old_backing);bdrv_get_backing_filename (bs, backing_name,sizeof (backing_name)); - ret =bdrv_open (&bs_old_backing, backing_name,NULL ,NULL , src_flags, - old_backing_drv, &local_err); -if (ret) { + blk_old_backing =blk_new_open ("old_backing" , backing_name,NULL , + options, src_flags, &local_err); +if (!blk_old_backing) {error_report ("Could not open old backing file '%s': %s" , backing_name,error_get_pretty (local_err));error_free (local_err); goto out; } + bs_old_backing =blk_bs (blk_old_backing); +if (out_baseimg[0 ]) { - blk_new_backing =blk_new_with_bs ("new_backing" , &error_abort); - bs_new_backing =blk_bs (blk_new_backing); - ret =bdrv_open (&bs_new_backing, out_baseimg,NULL ,NULL , src_flags, - new_backing_drv, &local_err); -if (ret) { +if (out_basefmt) { + options =qdict_new (); +qdict_put (options,"driver" ,qstring_from_str (out_basefmt)); + }else { + options =NULL ; + } + + blk_new_backing =blk_new_open ("new_backing" , out_baseimg,NULL , + options, src_flags, &local_err); +if (!blk_new_backing) {error_report ("Could not open new backing file '%s': %s" , out_baseimg,error_get_pretty (local_err));error_free (local_err); goto out; } + bs_new_backing =blk_bs (blk_new_backing); } }
Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH v4 08/16] qemu-img: Use blk_new_open() in img_rebase()
Quoted 5 lines · Max Reitz
Signed-off-by Max Reitz <[email protected]>--- qemu-img.c | 49 +++++++++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 26 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH v4 08/16] qemu-img: Use blk_new_open() in img_rebase()
In reply to Max ReitzQuoted 4 lines · Max Reitz
Signed-off-by Max Reitz <[email protected]>--- qemu-img.c | 49 +++++++++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 26 deletions(-)
PATCH v4 9/16 qemu-img: Use BlockBackend as far as possible
In reply to Max ReitzAlthough qemu-img already creates BlockBackends, it does not do accesses to the images through them. This patch converts all of the bdrv_* calls for which this is currently possible to blk_* calls. Most of the remaining calls will probably stay bdrv_* calls because they really do operate on the BDS level instead of the BB level.
--- qemu-img.c | 82 ++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 39 insertions(+), 43 deletions(-)
qemu-img.c +39 -43
@@ -1010,19 +1010,19 @@ static int64_t sectors_to_process(int64_t total, int64_t from)* Returns 0 in case sectors are filled with 0, 1 if sectors contain non-zero * data and negative value on error. * -* @param bs: Driver used for accessing file +* @param blk: BlockBackend for the image * @param sect_num: Number of first sector to check * @param sect_count: Number of sectors to check * @param filename: Name of disk file we are checking (logging purpose) * @param buffer: Allocated buffer for storing read data * @param quiet: Flag for quiet mode */ -static int check_empty_sectors (BlockDriverState *bs,int64_t sect_num, +static int check_empty_sectors (BlockBackend *blk,int64_t sect_num,int sect_count,const char *filename,uint8_t *buffer,bool quiet) {int pnum, ret =0 ; - ret =bdrv_read (bs, sect_num, buffer, sect_count); + ret =blk_read (blk, sect_num, buffer, sect_count);if (ret <0 ) {error_report ("Error while reading offset %" PRId64" of %s: %s" ,sectors_to_bytes (sect_num), filename,strerror (-ret));
@@ -1132,16 +1132,16 @@ static int img_compare(int argc, char **argv) } bs2 =blk_bs (blk2); - buf1 =qemu_blockalign (bs1,IO_BUF_SIZE ); - buf2 =qemu_blockalign (bs2,IO_BUF_SIZE ); - total_sectors1 =bdrv_nb_sectors (bs1); + buf1 =blk_blockalign (blk1,IO_BUF_SIZE ); + buf2 =blk_blockalign (blk2,IO_BUF_SIZE ); + total_sectors1 =blk_nb_sectors (blk1);if (total_sectors1 <0 ) {error_report ("Can't get size of %s: %s" , filename1,strerror (-total_sectors1)); ret =4 ; goto out; } - total_sectors2 =bdrv_nb_sectors (bs2); + total_sectors2 =blk_nb_sectors (blk2);if (total_sectors2 <0 ) {error_report ("Can't get size of %s: %s" , filename2,strerror (-total_sectors2));
@@ -1183,7 +1183,7 @@ static int img_compare(int argc, char **argv)if (allocated1 == allocated2) {if (allocated1) { - ret =bdrv_read (bs1, sector_num, buf1, nb_sectors); + ret =blk_read (blk1, sector_num, buf1, nb_sectors);if (ret <0 ) { error_report("Error while reading offset %" PRId64 " of %s:" " %s", sectors_to_bytes(sector_num), filename1,
@@ -1191,7 +1191,7 @@ static int img_compare(int argc, char **argv) ret =4 ; goto out; } - ret =bdrv_read (bs2, sector_num, buf2, nb_sectors); + ret =blk_read (blk2, sector_num, buf2, nb_sectors);if (ret <0 ) { error_report("Error while reading offset %" PRId64 " of %s: %s", sectors_to_bytes(sector_num),
@@ -1218,10 +1218,10 @@ static int img_compare(int argc, char **argv) }if (allocated1) { - ret =check_empty_sectors (bs1, sector_num, nb_sectors, + ret =check_empty_sectors (blk1, sector_num, nb_sectors, filename1, buf1, quiet); }else { - ret =check_empty_sectors (bs2, sector_num, nb_sectors, + ret =check_empty_sectors (blk2, sector_num, nb_sectors, filename2, buf1, quiet); }if (ret) {
@@ -1238,18 +1238,18 @@ static int img_compare(int argc, char **argv) }if (total_sectors1 != total_sectors2) { -BlockDriverState *bs_over; +BlockBackend *blk_over;int64_t total_sectors_over;const char *filename_over;qprintf (quiet,"Warning: Image size mismatch!\n" );if (total_sectors1 > total_sectors2) { total_sectors_over = total_sectors1; - bs_over = bs1; + blk_over = blk1; filename_over = filename1; }else { total_sectors_over = total_sectors2; - bs_over = bs2; + blk_over = blk2; filename_over = filename2; }
@@ -1258,7 +1258,7 @@ static int img_compare(int argc, char **argv)if (nb_sectors <=0 ) {break ; } - ret =bdrv_is_allocated_above (bs_over,NULL , sector_num, + ret =bdrv_is_allocated_above (blk_bs (blk_over),NULL , sector_num, nb_sectors, &pnum);if (ret <0 ) { ret =3 ;
@@ -1269,7 +1269,7 @@ static int img_compare(int argc, char **argv) } nb_sectors = pnum;if (ret) { - ret =check_empty_sectors (bs_over, sector_num, nb_sectors, + ret =check_empty_sectors (blk_over, sector_num, nb_sectors, filename_over, buf1, quiet);if (ret) {if (ret <0 ) {
@@ -1478,7 +1478,7 @@ static int img_convert(int argc, char **argv) goto out; } bs[bs_i] =blk_bs (blk[bs_i]); - bs_sectors[bs_i] =bdrv_nb_sectors (bs[bs_i]); + bs_sectors[bs_i] =blk_nb_sectors (blk[bs_i]);if (bs_sectors[bs_i] <0 ) {error_report ("Could not get size of %s: %s" , argv[optind + bs_i],strerror (-bs_sectors[bs_i]));
@@ -1628,10 +1628,10 @@ static int img_convert(int argc, char **argv) out_bs->bl.discard_alignment)) ); - buf =qemu_blockalign (out_bs, bufsectors *BDRV_SECTOR_SIZE ); + buf =blk_blockalign (out_blk, bufsectors *BDRV_SECTOR_SIZE );if (skip_create) { -int64_t output_sectors =bdrv_nb_sectors (out_bs); +int64_t output_sectors =blk_nb_sectors (out_blk);if (output_sectors <0 ) {error_report ("unable to get output image length: %s\n" ,strerror (-output_sectors));
@@ -1699,7 +1699,7 @@ static int img_convert(int argc, char **argv) nlow = remainder > bs_sectors[bs_i] - bs_num ? bs_sectors[bs_i] - bs_num : remainder; - ret =bdrv_read (bs[bs_i], bs_num, buf2, nlow); + ret =blk_read (blk[bs_i], bs_num, buf2, nlow);if (ret <0 ) {error_report ("error while reading sector %" PRId64": %s" , bs_num,strerror (-ret));
@@ -1714,7 +1714,7 @@ static int img_convert(int argc, char **argv)assert (remainder ==0 );if (!buffer_is_zero (buf, n *BDRV_SECTOR_SIZE )) { - ret =bdrv_write_compressed (out_bs, sector_num, buf, n); + ret =blk_write_compressed (out_blk, sector_num, buf, n);if (ret !=0 ) {error_report ("error while compressing sector %" PRId64": %s" , sector_num,strerror (-ret));
@@ -1725,7 +1725,7 @@ static int img_convert(int argc, char **argv)qemu_progress_print (100.0 * sector_num / total_sectors,0 ); }/* signal EOF to align */ -bdrv_write_compressed (out_bs,0 ,NULL ,0 ); +blk_write_compressed (out_blk,0 ,NULL ,0 ); }else {int64_t sectors_to_read, sectors_read, sector_num_next_status;bool count_allocated_sectors;
@@ -1826,7 +1826,7 @@ restart: } n1 = n; - ret =bdrv_read (bs[bs_i], sector_num - bs_offset, buf, n); + ret =blk_read (blk[bs_i], sector_num - bs_offset, buf, n);if (ret <0 ) {error_report ("error while reading sector %" PRId64": %s" , sector_num - bs_offset,strerror (-ret));
@@ -1839,7 +1839,7 @@ restart:while (n >0 ) {if (!has_zero_init ||is_allocated_sectors_min (buf1, n, &n1, min_sparse)) { - ret =bdrv_write (out_bs, sector_num, buf1, n1); + ret =blk_write (out_blk, sector_num, buf1, n1);if (ret <0 ) {error_report ("error while writing sector %" PRId64": %s" , sector_num,strerror (-ret));
@@ -2263,7 +2263,7 @@ static int img_map(int argc, char **argv)printf ("%-16s%-16s%-16s%s\n" ,"Offset" ,"Length" ,"Mapped to" ,"File" ); } - length =bdrv_getlength (bs); + length =blk_getlength (blk);while (curr.start + curr.length < length) {int64_t nsectors_left;int64_t sector_num;
@@ -2432,7 +2432,7 @@ static int img_snapshot(int argc, char **argv)static int img_rebase (int argc,char **argv) {BlockBackend *blk =NULL , *blk_old_backing =NULL , *blk_new_backing =NULL ; -BlockDriverState *bs =NULL , *bs_old_backing =NULL , *bs_new_backing =NULL ; +BlockDriverState *bs =NULL ;char *filename;const char *fmt, *cache, *src_cache, *out_basefmt, *out_baseimg;int c, flags, src_flags, ret;
@@ -2553,7 +2553,6 @@ static int img_rebase(int argc, char **argv)error_free (local_err); goto out; } - bs_old_backing =blk_bs (blk_old_backing);if (out_baseimg[0 ]) {if (out_basefmt) {
@@ -2571,7 +2570,6 @@ static int img_rebase(int argc, char **argv)error_free (local_err); goto out; } - bs_new_backing =blk_bs (blk_new_backing); } }
@@ -2594,17 +2592,17 @@ static int img_rebase(int argc, char **argv)uint8_t * buf_new;float local_progress =0 ; - buf_old =qemu_blockalign (bs,IO_BUF_SIZE ); - buf_new =qemu_blockalign (bs,IO_BUF_SIZE ); + buf_old =blk_blockalign (blk,IO_BUF_SIZE ); + buf_new =blk_blockalign (blk,IO_BUF_SIZE ); - num_sectors =bdrv_nb_sectors (bs); + num_sectors =blk_nb_sectors (blk);if (num_sectors <0 ) {error_report ("Could not get size of '%s': %s" , filename,strerror (-num_sectors)); ret =-1 ; goto out; } - old_backing_num_sectors =bdrv_nb_sectors (bs_old_backing); + old_backing_num_sectors =blk_nb_sectors (blk_old_backing);if (old_backing_num_sectors <0 ) {char backing_name[PATH_MAX ];
@@ -2614,8 +2612,8 @@ static int img_rebase(int argc, char **argv) ret =-1 ; goto out; } -if (bs_new_backing) { - new_backing_num_sectors =bdrv_nb_sectors (bs_new_backing); +if (blk_new_backing) { + new_backing_num_sectors =blk_nb_sectors (blk_new_backing);if (new_backing_num_sectors <0 ) {error_report ("Could not get size of '%s': %s" , out_baseimg,strerror (-new_backing_num_sectors));
@@ -2660,21 +2658,21 @@ static int img_rebase(int argc, char **argv) n = old_backing_num_sectors - sector; } - ret =bdrv_read (bs_old_backing, sector, buf_old, n); + ret =blk_read (blk_old_backing, sector, buf_old, n);if (ret <0 ) {error_report ("error while reading from old backing file" ); goto out; } } -if (sector >= new_backing_num_sectors || !bs_new_backing) { +if (sector >= new_backing_num_sectors || !blk_new_backing) {memset (buf_new,0 , n *BDRV_SECTOR_SIZE ); }else {if (sector + n > new_backing_num_sectors) { n = new_backing_num_sectors - sector; } - ret =bdrv_read (bs_new_backing, sector, buf_new, n); + ret =blk_read (blk_new_backing, sector, buf_new, n);if (ret <0 ) {error_report ("error while reading from new backing file" ); goto out;
@@ -2690,8 +2688,8 @@ static int img_rebase(int argc, char **argv)if (compare_sectors (buf_old + written *512 , buf_new + written *512 , n - written, &pnum)) { - ret =bdrv_write (bs, sector + written, - buf_old + written *512 , pnum); + ret =blk_write (blk, sector + written, + buf_old + written *512 , pnum);if (ret <0 ) {error_report ("Error while writing to COW image: %s" ,strerror (-ret));
@@ -2756,7 +2754,6 @@ static int img_resize(int argc, char **argv)int64_t n, total_size;bool quiet = false;BlockBackend *blk =NULL ; -BlockDriverState *bs =NULL ;QemuOpts *param;static QemuOptsList resize_options = { .name ="resize_options" ,
@@ -2838,10 +2835,9 @@ static int img_resize(int argc, char **argv) ret =-1 ; goto out; } - bs =blk_bs (blk);if (relative) { - total_size =bdrv_getlength (bs) + n * relative; + total_size =blk_getlength (blk) + n * relative; }else { total_size = n; }
@@ -2851,7 +2847,7 @@ static int img_resize(int argc, char **argv) goto out; } - ret =bdrv_truncate (bs, total_size); + ret =blk_truncate (blk, total_size);switch (ret) {case 0 :qprintf (quiet,"Image resized.\n" );
Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH v4 09/16] qemu-img: Use BlockBackend as far as possible
Quoted 16 lines · Max Reitz
Although qemu-img already creates BlockBackends, it does not do accesses to the images through them. This patch converts all of the bdrv_* calls for which this is currently possible to blk_* calls. Most of the remaining calls will probably stay bdrv_* calls because they really do operate on the BDS level instead of the BB level.
Signed-off-by Max Reitz <[email protected]>--- qemu-img.c | 82 ++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 39 insertions(+), 43 deletions(-)qemu-img.c +0
-0
qemu-img.c static int64_t sectors_to_process(int64_t total, int64_t from) · line 1015
Quoted 7 lines
qemu-img.c +1
-1@@ -1010,19 +1010,19 @@ static int64_t sectors_to_process(int64_t total, int64_t from)* Returns 0 in case sectors are filled with 0, 1 if sectors contain non-zero * data and negative value on error. * -* @param bs: Driver used for accessing file +* @param blk: BlockBackend for the image * @param sect_num: Number of first sector to check * @param sect_count: Number of sectors to check
As long as you are touching this, is it worth compressing the double space into one for consistency with the other lines?
That's minor, and it DOES look a lot nicer without the conversions from bytes to sectors.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH v4 09/16] qemu-img: Use BlockBackend as far as possible
In reply to Max ReitzQuoted 10 lines · Max Reitz
Although qemu-img already creates BlockBackends, it does not do accesses to the images through them. This patch converts all of the bdrv_* calls for which this is currently possible to blk_* calls. Most of the remaining calls will probably stay bdrv_* calls because they really do operate on the BDS level instead of the BB level.
Signed-off-by Max Reitz <[email protected]>--- qemu-img.c | 82 ++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 39 insertions(+), 43 deletions(-)
PATCH v4 10/16 qemu-nbd: Use blk_new_open() in main()
In reply to Max Reitz--- qemu-nbd.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-)
qemu-nbd.c +9 -16
@@ -391,7 +391,6 @@ int main(int argc, char **argv) {BlockBackend *blk;BlockDriverState *bs; -BlockDriver *drv;off_t dev_offset =0 ;uint32_t nbdflags =0 ;bool disconnect = false;
@@ -434,7 +433,7 @@ int main(int argc, char **argv)char *end;int flags =BDRV_O_RDWR ;int partition =-1 ; -int ret; +int ret =0 ;int fd;bool seen_cache = false;bool seen_discard = false;
@@ -445,6 +444,7 @@ int main(int argc, char **argv)const char *fmt =NULL ;Error *local_err =NULL ;BlockdevDetectZeroesOptions detect_zeroes =BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF ; +QDict *options =NULL ;/* The client thread uses SIGTERM to interrupt the server. A signal * handler ensures that "qemu-nbd -v -c" exits with a nice status code.
@@ -689,24 +689,17 @@ int main(int argc, char **argv)atexit (bdrv_close_all);if (fmt) { - drv =bdrv_find_format (fmt); -if (!drv) { -errx (EXIT_FAILURE ,"Unknown file format '%s'" , fmt); - } - }else { - drv =NULL ; + options =qdict_new (); +qdict_put (options,"driver" ,qstring_from_str (fmt)); } - blk =blk_new_with_bs ("hda" , &error_abort); - bs =blk_bs (blk); - srcpath = argv[optind]; - ret =bdrv_open (&bs, srcpath,NULL ,NULL , flags, drv, &local_err); -if (ret <0 ) { - errno = -ret; -err (EXIT_FAILURE ,"Failed to bdrv_open '%s': %s" , argv[optind], -error_get_pretty (local_err)); + blk =blk_new_open ("hda" , srcpath,NULL , options, flags, &local_err); +if (!blk) { +errx (EXIT_FAILURE ,"Failed to blk_new_open '%s': %s" , argv[optind], +error_get_pretty (local_err)); } + bs =blk_bs (blk);if (sn_opts) { ret = bdrv_snapshot_load_tmp(bs,
Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH v4 10/16] qemu-nbd: Use blk_new_open() in main()
Quoted 5 lines · Max Reitz
Signed-off-by Max Reitz <[email protected]>Reviewed-by Kevin Wolf <[email protected]>--- qemu-nbd.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-)
PATCH v4 11/16 qemu-io: Use blk_new_open() in openfile()
In reply to Max Reitz--- qemu-io.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-)
qemu-io.c +12 -18
@@ -51,34 +51,29 @@ static const cmdinfo_t close_cmd = { .oneline = "close the current open file", }; -static int openfile (char *name,BlockDriver *drv,int flags,int growable, -QDict *opts) +static int openfile (char *name,int flags,int growable,QDict *opts) {Error *local_err =NULL ; -if (qemuio_bs) { +if (qemuio_blk) {fprintf (stderr,"file open already, try 'help close'\n" );QDECREF (opts);return 1 ; } - qemuio_blk =blk_new_with_bs ("hda" , &error_abort); - qemuio_bs =blk_bs (qemuio_blk); -if (growable) { flags |=BDRV_O_PROTOCOL ; } -if (bdrv_open (&qemuio_bs, name,NULL , opts, flags, drv, &local_err) <0 ) { + qemuio_blk =blk_new_open ("hda" , name,NULL , opts, flags, &local_err); +if (!qemuio_blk) {fprintf (stderr,"%s: can't open%s%s: %s\n" , progname, name ?" device " :"" , name ?:"" ,error_get_pretty (local_err));error_free (local_err); -blk_unref (qemuio_blk); - qemuio_bs =NULL ; - qemuio_blk =NULL ;return 1 ; } + qemuio_bs =blk_bs (qemuio_blk);return 0 ; }
@@ -170,9 +165,9 @@ static int open_f(BlockDriverState *bs, int argc, char **argv)qemu_opts_reset (&empty_opts);if (optind == argc -1 ) { -return openfile (argv[optind],NULL , flags, growable, opts); +return openfile (argv[optind], flags, growable, opts); }else if (optind == argc) { -return openfile (NULL ,NULL , flags, growable, opts); +return openfile (NULL , flags, growable, opts); }else {QDECREF (opts);return qemuio_command_usage (&open_cmd);
@@ -387,8 +382,8 @@ int main(int argc, char **argv)int c;int opt_index =0 ;int flags =BDRV_O_UNMAP ; -BlockDriver *drv =NULL ;Error *local_error =NULL ; +QDict *opts =NULL ;#ifdef CONFIG_POSIX signal (SIGPIPE ,SIG_IGN );
@@ -414,11 +409,10 @@ int main(int argc, char **argv) }break ;case 'f' : - drv =bdrv_find_format (optarg); -if (!drv) { -error_report ("Invalid format '%s'" , optarg); -exit (EXIT_FAILURE ); +if (!opts) { + opts =qdict_new (); } +qdict_put (opts,"driver" ,qstring_from_str (optarg));break ;case 'c' :add_user_command (optarg);
@@ -489,7 +483,7 @@ int main(int argc, char **argv) }if ((argc - optind) ==1 ) { -openfile (argv[optind], drv, flags, growable,NULL ); +openfile (argv[optind], flags, growable, opts); }command_loop ();
Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH v4 11/16] qemu-io: Use blk_new_open() in openfile()
Quoted 5 lines · Max Reitz
Signed-off-by Max Reitz <[email protected]>--- qemu-io.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH v4 11/16] qemu-io: Use blk_new_open() in openfile()
In reply to Max ReitzQuoted 4 lines · Max Reitz
Signed-off-by Max Reitz <[email protected]>--- qemu-io.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-)
PATCH v4 12/16 qemu-io: Remove "growable" option
In reply to Max ReitzRemove "growable" option from the "open" command and from the qemu-io command line. qemu-io is about to be converted to BlockBackend which will make sure that no request exceeds the image size, so the only way to keep "growable" would be to use BlockBackend if it is not given and to directly access the BDS if it is.
qemu-io is a debugging tool, therefore removing a rarely used option will have only a very small impact, if any. There was only one qemu-iotest which used the option; since it is not critical, this patch just removes it.
--- qemu-io.c | 23 +++------------ tests/qemu-iotests/016 | 73 ---------------------------------------------- tests/qemu-iotests/016.out | 23 --------------- tests/qemu-iotests/group | 2 +- 4 files changed, 5 insertions(+), 116 deletions(-) delete mode 100755 tests/qemu-iotests/016 delete mode 100644 tests/qemu-iotests/016.out
qemu-io.c +4 -19
@@ -51,7 +51,7 @@ static const cmdinfo_t close_cmd = { .oneline = "close the current open file", }; -static int openfile (char *name,int flags,int growable,QDict *opts) +static int openfile (char *name,int flags,QDict *opts) {Error *local_err =NULL ;
@@ -61,10 +61,6 @@ static int openfile(char *name, int flags, int growable, QDict *opts)return 1 ; } -if (growable) { - flags |=BDRV_O_PROTOCOL ; - } - qemuio_blk =blk_new_open ("hda" , name,NULL , opts, flags, &local_err);if (!qemuio_blk) { fprintf(stderr, "%s: can't open%s%s: %s\n", progname,
@@ -91,7 +87,6 @@ static void open_help(void)" -r, -- open file read-only\n" " -s, -- use snapshot file\n" " -n, -- disable host cache\n" -" -g, -- allow file to grow (only applies to protocols)\n" " -o, -- options to be given to the block driver" "\n"); }
@@ -124,7 +119,6 @@ static int open_f(BlockDriverState *bs, int argc, char **argv) {int flags =0 ;int readonly =0 ; -int growable =0 ;int c;QemuOpts *qopts;QDict *opts;
@@ -140,9 +134,6 @@ static int open_f(BlockDriverState *bs, int argc, char **argv)case 'r' : readonly =1 ;break ; -case 'g' : - growable =1 ; -break ;case 'o' :if (!qemu_opts_parse (&empty_opts, optarg,0 )) {printf ("could not parse option list -- %s\n" , optarg);
@@ -165,9 +156,9 @@ static int open_f(BlockDriverState *bs, int argc, char **argv)qemu_opts_reset (&empty_opts);if (optind == argc -1 ) { -return openfile (argv[optind], flags, growable, opts); +return openfile (argv[optind], flags, opts); }else if (optind == argc) { -return openfile (NULL , flags, growable, opts); +return openfile (NULL , flags, opts); }else {QDECREF (opts);return qemuio_command_usage (&open_cmd);
@@ -201,7 +192,6 @@ static void usage(const char *name)" -r, --read-only export read-only\n" " -s, --snapshot use snapshot file\n" " -n, --nocache disable host cache\n" -" -g, --growable allow file to grow (only applies to protocols)\n" " -m, --misalign misalign allocations for O_DIRECT\n" " -k, --native-aio use kernel AIO implementation (on Linux only)\n" " -t, --cache=MODE use the given cache mode for the image\n"
@@ -360,7 +350,6 @@ static void reenable_tty_echo(void)int main (int argc,char **argv) {int readonly =0 ; -int growable =0 ;const char *sopt ="hVc:d:f:rsnmgkt:T:" ;const struct option lopt[] = { {"help" ,0 ,NULL ,'h' },
@@ -372,7 +361,6 @@ int main(int argc, char **argv) { "snapshot", 0, NULL, 's' }, { "nocache", 0, NULL, 'n' }, { "misalign", 0, NULL, 'm' }, - { "growable", 0, NULL, 'g' }, { "native-aio", 0, NULL, 'k' }, { "discard", 1, NULL, 'd' }, { "cache", 1, NULL, 't' },
@@ -423,9 +411,6 @@ int main(int argc, char **argv)case 'm' : qemuio_misalign = true;break ; -case 'g' : - growable =1 ; -break ;case 'k' : flags |=BDRV_O_NATIVE_AIO ;break ;
@@ -483,7 +468,7 @@ int main(int argc, char **argv) }if ((argc - optind) ==1 ) { -openfile (argv[optind], flags, growable, opts); +openfile (argv[optind], flags, opts); }command_loop ();
tests/qemu-iotests/016 deleted +0 -73
73 lines not on this page · raw message
tests/qemu-iotests/016.out deleted +0 -23
@@ -1,23 +0,0 @@ -QA output created by 016 -Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 - -== reading at EOF == -read 512/512 bytes at offset 134217728 -512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) - -== reading far past EOF == -read 512/512 bytes at offset 268435456 -512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) - -== writing at EOF == -wrote 512/512 bytes at offset 134217728 -512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) -read 512/512 bytes at offset 134217728 -512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) - -== writing far past EOF == -wrote 512/512 bytes at offset 268435456 -512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) -read 512/512 bytes at offset 268435456 -512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) -*** done
tests/qemu-iotests/group +1 -1
@@ -22,7 +22,7 @@ 013 rw auto 014 rw auto 015 rw snapshot auto -016 rw auto quick +# 016 was removed, do not reuse 017 rw backing auto quick 018 rw backing auto quick 019 rw backing auto quick
Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH v4 12/16] qemu-io: Remove "growable" option
Quoted 24 lines · Max Reitz
Remove "growable" option from the "open" command and from the qemu-io command line. qemu-io is about to be converted to BlockBackend which will make sure that no request exceeds the image size, so the only way to keep "growable" would be to use BlockBackend if it is not given and to directly access the BDS if it is.
qemu-io is a debugging tool, therefore removing a rarely used option will have only a very small impact, if any. There was only one qemu-iotest which used the option; since it is not critical, this patch just removes it.
Signed-off-by Max Reitz <[email protected]>--- qemu-io.c | 23 +++------------ tests/qemu-iotests/016 | 73 ---------------------------------------------- tests/qemu-iotests/016.out | 23 --------------- tests/qemu-iotests/group | 2 +- 4 files changed, 5 insertions(+), 116 deletions(-) delete mode 100755 tests/qemu-iotests/016 delete mode 100644 tests/qemu-iotests/016.out+++ b/tests/qemu-iotests/group
tests/qemu-iotests/group line 25
Quoted 5 lines
tests/qemu-iotests/group +1
-1@@ -22,7 +22,7 @@ 013 rw auto 014 rw auto 015 rw snapshot auto -016 rw auto quick +# 016 was removed, do not reuse
Works for me.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH v4 13/16 qemu-io: Use BlockBackend
In reply to Max Reitzqemu-io should behave like a guest, therefore it should use BlockBackend to access the block layer.
There are a couple of places where that is infeasible: First, the bdrv_debug_* functions could theoretically be mirrored in the BlockBackend, but since these are functions internal to the block layer, they should not be visible externally (qemu-io as a test tool is exempt from this).
Second, bdrv_get_info() and bdrv_get_specific_info() work on a single BDS alone, therefore they should stay BDS-specific.
Third, bdrv_is_allocated() mainly works on a single BDS as well. Some data may be passed through from the BDS's file (if sectors which are apparently allocated in the file are not really allocated there but just zero).
--- hmp.c | 9 ++- include/qemu-io.h | 4 +- qemu-io-cmds.c | 237 ++++++++++++++++++++++++++++-------------------------- qemu-io.c | 15 ++-- 4 files changed, 137 insertions(+), 128 deletions(-)
hmp.c +5 -4
@@ -16,6 +16,7 @@#include "hmp.h" #include "net/net.h" #include "sysemu/char.h" +#include "sysemu/block-backend.h" #include "qemu/option.h" #include "qemu/timer.h" #include "qmp-commands.h"
@@ -1718,14 +1719,14 @@ void hmp_chardev_remove(Monitor *mon, const QDict *qdict)void hmp_qemu_io (Monitor *mon,const QDict *qdict) { -BlockDriverState *bs; +BlockBackend *blk;const char * device =qdict_get_str (qdict,"device" );const char * command =qdict_get_str (qdict,"command" );Error *err =NULL ; - bs =bdrv_find (device); -if (bs) { -qemuio_command (bs, command); + blk =blk_by_name (device); +if (blk) { +qemuio_command (blk, command); }else {error_set (&err,QERR_DEVICE_NOT_FOUND , device); }
include/qemu-io.h +2 -2
@@ -22,7 +22,7 @@#define CMD_FLAG_GLOBAL ((int)0x80000000)/* don't iterate "args" */ -typedef int (*cfunc_t )(BlockDriverState *bs,int argc,char **argv); +typedef int (*cfunc_t )(BlockBackend *blk,int argc,char **argv);typedef void (*helpfunc_t )(void ); typedef struct cmdinfo {
@@ -40,7 +40,7 @@ typedef struct cmdinfo {extern bool qemuio_misalign; -bool qemuio_command (BlockDriverState *bs,const char *cmd); +bool qemuio_command (BlockBackend *blk,const char *cmd);void qemuio_add_command (const cmdinfo_t *ci);int qemuio_command_usage (const cmdinfo_t *ci);
qemu-io-cmds.c +124 -113
757 lines not on this page · raw message
qemu-io.c +6 -9
@@ -28,7 +28,6 @@static char *progname;static BlockBackend *qemuio_blk; -static BlockDriverState *qemuio_bs;/* qemu-io commands passed using -c */ static int ncmdline;
@@ -36,10 +35,9 @@ static char **cmdline;static ReadLineState *readline_state; -static int close_f (BlockDriverState *bs,int argc,char **argv) +static int close_f (BlockBackend *blk,int argc,char **argv) {blk_unref (qemuio_blk); - qemuio_bs =NULL ; qemuio_blk =NULL ;return 0 ; }
@@ -69,7 +67,6 @@ static int openfile(char *name, int flags, QDict *opts)error_free (local_err);return 1 ; } - qemuio_bs =blk_bs (qemuio_blk);return 0 ; }
@@ -91,7 +88,7 @@ static void open_help(void) "\n"); } -static int open_f (BlockDriverState *bs,int argc,char **argv); +static int open_f (BlockBackend *blk,int argc,char **argv);static const cmdinfo_t open_cmd = { .name ="open" ,
@@ -115,7 +112,7 @@ static QemuOptsList empty_opts = { }, }; -static int open_f (BlockDriverState *bs,int argc,char **argv) +static int open_f (BlockBackend *blk,int argc,char **argv) {int flags =0 ;int readonly =0 ;
@@ -165,7 +162,7 @@ static int open_f(BlockDriverState *bs, int argc, char **argv) } } -static int quit_f (BlockDriverState *bs,int argc,char **argv) +static int quit_f (BlockBackend *blk,int argc,char **argv) {return 1 ; }
@@ -302,7 +299,7 @@ static void command_loop(void)char *input;for (i =0 ; !done && i < ncmdline; i++) { - done =qemuio_command (qemuio_bs, cmdline[i]); + done =qemuio_command (qemuio_blk, cmdline[i]); }if (cmdline) {g_free (cmdline);
@@ -327,7 +324,7 @@ static void command_loop(void)if (input ==NULL ) {break ; } - done =qemuio_command (qemuio_bs, input); + done =qemuio_command (qemuio_blk, input);g_free (input); prompted =0 ;
Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH v4 13/16] qemu-io: Use BlockBackend
Quoted 17 lines · Max Reitz
qemu-io should behave like a guest, therefore it should use BlockBackend to access the block layer.
There are a couple of places where that is infeasible: First, the bdrv_debug_* functions could theoretically be mirrored in the BlockBackend, but since these are functions internal to the block layer, they should not be visible externally (qemu-io as a test tool is exempt from this).
Second,
bdrv_get_info()andbdrv_get_specific_info()work on a single BDS alone, therefore they should stay BDS-specific.Third,
bdrv_is_allocated()mainly works on a single BDS as well. Some data may be passed through from the BDS's file (if sectors which are apparently allocated in the file are not really allocated there but just zero).
Quoted 8 lines
Signed-off-by Max Reitz <[email protected]>--- hmp.c | 9 ++- include/qemu-io.h | 4 +- qemu-io-cmds.c | 237 ++++++++++++++++++++++++++++-------------------------- qemu-io.c | 15 ++-- 4 files changed, 137 insertions(+), 128 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH v4 14/16 block: Clamp BlockBackend requests
In reply to Max ReitzBlockBackend is used as the interface between the block layer and guest devices. It should therefore assure that all requests are clamped to the image size.
--- block/block-backend.c | 152 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+)
block/block-backend.c +152 -0
@@ -31,6 +31,16 @@ struct BlockBackend {void *dev_opaque; }; +typedef struct BlockBackendAIOCB { +BlockAIOCB common; +QEMUBH *bh; +int ret; +}BlockBackendAIOCB ; + +static const AIOCBInfo block_backend_aiocb_info = { + .aiocb_size =sizeof (BlockBackendAIOCB), +}; +static void drive_info_del (DriveInfo *dinfo);/* All the BlockBackends (except for hidden ones) */
@@ -428,39 +438,137 @@ void blk_iostatus_enable(BlockBackend *blk)bdrv_iostatus_enable (blk->bs); } +static int blk_check_byte_request (BlockBackend *blk,int64_t offset, +size_t size) +{ +int64_t len; + +if (size >INT_MAX ) { +return -EIO ; + } + +if (!blk_is_inserted (blk)) { +return -ENOMEDIUM ; + } + + len =blk_getlength (blk); +if (len <0 ) { +return len; + } + +if (offset <0 ) { +return -EIO ; + } + +if (offset > len || len - offset < size) { +return -EIO ; + } + +return 0 ; +} + +static int blk_check_request (BlockBackend *blk,int64_t sector_num, +int nb_sectors) +{ +if (sector_num <0 || sector_num >INT64_MAX /BDRV_SECTOR_SIZE ) { +return -EIO ; + } + +if (nb_sectors <0 || nb_sectors >INT_MAX /BDRV_SECTOR_SIZE ) { +return -EIO ; + } + +return blk_check_byte_request (blk, sector_num *BDRV_SECTOR_SIZE , + nb_sectors *BDRV_SECTOR_SIZE ); +} +int blk_read (BlockBackend *blk,int64_t sector_num,uint8_t *buf,int nb_sectors) { +int ret =blk_check_request (blk, sector_num, nb_sectors); +if (ret <0 ) { +return ret; + } +return bdrv_read (blk->bs, sector_num, buf, nb_sectors); }int blk_read_unthrottled (BlockBackend *blk,int64_t sector_num,uint8_t *buf,int nb_sectors) { +int ret =blk_check_request (blk, sector_num, nb_sectors); +if (ret <0 ) { +return ret; + } +return bdrv_read_unthrottled (blk->bs, sector_num, buf, nb_sectors); }int blk_write (BlockBackend *blk,int64_t sector_num,const uint8_t *buf,int nb_sectors) { +int ret =blk_check_request (blk, sector_num, nb_sectors); +if (ret <0 ) { +return ret; + } +return bdrv_write (blk->bs, sector_num, buf, nb_sectors); } +static void error_callback_bh (void *opaque) +{ +struct BlockBackendAIOCB *acb = opaque; +qemu_bh_delete (acb->bh); + acb->common.cb (acb->common.opaque, acb->ret); +qemu_aio_unref (acb); +} + +static BlockAIOCB *abort_aio_request (BlockBackend *blk,BlockCompletionFunc *cb, +void *opaque,int ret) +{ +struct BlockBackendAIOCB *acb; +QEMUBH *bh; + + acb =blk_aio_get (&block_backend_aiocb_info, blk, cb, opaque); + acb->ret = ret; + + bh =aio_bh_new (blk_get_aio_context (blk), error_callback_bh, acb); + acb->bh = bh; +qemu_bh_schedule (bh); + +return &acb->common; +} +BlockAIOCB *blk_aio_write_zeroes (BlockBackend *blk,int64_t sector_num,int nb_sectors,BdrvRequestFlags flags,BlockCompletionFunc *cb,void *opaque) { +int ret =blk_check_request (blk, sector_num, nb_sectors); +if (ret <0 ) { +return abort_aio_request (blk, cb, opaque, ret); + } +return bdrv_aio_write_zeroes (blk->bs, sector_num, nb_sectors, flags, cb, opaque); }int blk_pread (BlockBackend *blk,int64_t offset,void *buf,int count) { +int ret =blk_check_byte_request (blk, offset, count); +if (ret <0 ) { +return ret; + } +return bdrv_pread (blk->bs, offset, buf, count); }int blk_pwrite (BlockBackend *blk,int64_t offset,const void *buf,int count) { +int ret =blk_check_byte_request (blk, offset, count); +if (ret <0 ) { +return ret; + } +return bdrv_pwrite (blk->bs, offset, buf, count); }
@@ -483,6 +591,11 @@ BlockAIOCB *blk_aio_readv(BlockBackend *blk, int64_t sector_num, QEMUIOVector *iov, int nb_sectors, BlockCompletionFunc *cb, void *opaque) { + int ret = blk_check_request(blk, sector_num, nb_sectors); +if (ret <0 ) { +return abort_aio_request (blk, cb, opaque, ret); + } +return bdrv_aio_readv (blk->bs, sector_num, iov, nb_sectors, cb, opaque); }
@@ -490,6 +603,11 @@ BlockAIOCB *blk_aio_writev(BlockBackend *blk, int64_t sector_num, QEMUIOVector *iov, int nb_sectors, BlockCompletionFunc *cb, void *opaque) { + int ret = blk_check_request(blk, sector_num, nb_sectors); +if (ret <0 ) { +return abort_aio_request (blk, cb, opaque, ret); + } +return bdrv_aio_writev (blk->bs, sector_num, iov, nb_sectors, cb, opaque); }
@@ -503,6 +621,11 @@ BlockAIOCB *blk_aio_discard(BlockBackend *blk, int64_t sector_num, int nb_sectors, BlockCompletionFunc *cb, void *opaque) { + int ret = blk_check_request(blk, sector_num, nb_sectors); +if (ret <0 ) { +return abort_aio_request (blk, cb, opaque, ret); + } +return bdrv_aio_discard (blk->bs, sector_num, nb_sectors, cb, opaque); }
@@ -518,6 +641,15 @@ void blk_aio_cancel_async(BlockAIOCB *acb)int blk_aio_multiwrite (BlockBackend *blk,BlockRequest *reqs,int num_reqs) { +int i, ret; + +for (i =0 ; i < num_reqs; i++) { + ret =blk_check_request (blk, reqs[i].sector, reqs[i].nb_sectors); +if (ret <0 ) { +return ret; + } + } +return bdrv_aio_multiwrite (blk->bs, reqs, num_reqs); }
@@ -534,6 +666,11 @@ BlockAIOCB *blk_aio_ioctl(BlockBackend *blk, unsigned long int req, void *buf,int blk_co_discard (BlockBackend *blk,int64_t sector_num,int nb_sectors) { +int ret =blk_check_request (blk, sector_num, nb_sectors); +if (ret <0 ) { +return ret; + } +return bdrv_co_discard (blk->bs, sector_num, nb_sectors); }
@@ -711,12 +848,22 @@ void *blk_aio_get(const AIOCBInfo *aiocb_info, BlockBackend *blk, int coroutine_fn blk_co_write_zeroes(BlockBackend *blk, int64_t sector_num,int nb_sectors,BdrvRequestFlags flags) { +int ret =blk_check_request (blk, sector_num, nb_sectors); +if (ret <0 ) { +return ret; + } +return bdrv_co_write_zeroes (blk->bs, sector_num, nb_sectors, flags); }int blk_write_compressed (BlockBackend *blk,int64_t sector_num,const uint8_t *buf,int nb_sectors) { +int ret =blk_check_request (blk, sector_num, nb_sectors); +if (ret <0 ) { +return ret; + } +return bdrv_write_compressed (blk->bs, sector_num, buf, nb_sectors); }
@@ -727,6 +874,11 @@ int blk_truncate(BlockBackend *blk, int64_t offset)int blk_discard (BlockBackend *blk,int64_t sector_num,int nb_sectors) { +int ret =blk_check_request (blk, sector_num, nb_sectors); +if (ret <0 ) { +return ret; + } +return bdrv_discard (blk->bs, sector_num, nb_sectors); }
Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH v4 14/16] block: Clamp BlockBackend requests
Quoted 10 lines · Max Reitz
BlockBackend is used as the interface between the block layer and guest devices. It should therefore assure that all requests are clamped to the image size.
Signed-off-by Max Reitz <[email protected]>Reviewed-by Eric Blake <[email protected]>Reviewed-by Kevin Wolf <[email protected]>--- block/block-backend.c | 152 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+)
PATCH v4 15/16 block: Remove "growable" from BDS
In reply to Max ReitzNow that request clamping is done in the BlockBackend, the "growable" field can be removed from the BlockDriverState. All BDSs are now treated as being "growable" (that is, they are allowed to grow; they are not necessarily actually able to).
--- block.c | 24 +++++++----------------- block/qcow2.c | 6 ------ block/raw-posix.c | 2 +- block/raw-win32.c | 2 +- block/sheepdog.c | 2 +- include/block/block_int.h | 3 --- 6 files changed, 10 insertions(+), 29 deletions(-)
block.c +7 -17
@@ -972,7 +972,6 @@ static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file, bs->zero_beyond_eof = true; open_flags =bdrv_open_flags (bs, flags); bs->read_only = !(open_flags &BDRV_O_RDWR ); - bs->growable = !!(flags &BDRV_O_PROTOCOL );if (use_bdrv_whitelist && !bdrv_is_whitelisted (drv, bs->read_only)) { error_setg(errp,
@@ -1886,7 +1885,6 @@ void bdrv_close(BlockDriverState *bs) bs->encrypted =0 ; bs->valid_key =0 ; bs->sg =0 ; - bs->growable =0 ; bs->zero_beyond_eof = false;QDECREF (bs->options); bs->options =NULL ;
@@ -2646,25 +2644,17 @@ exit:static int bdrv_check_byte_request (BlockDriverState *bs,int64_t offset,size_t size) { -int64_t len; -if (size >INT_MAX ) {return -EIO ; } -if (!bdrv_is_inserted (bs)) +if (!bdrv_is_inserted (bs)) {return -ENOMEDIUM ; + } -if (bs->growable) -return 0 ; - - len =bdrv_getlength (bs); - -if (offset <0 ) -return -EIO ; - -if ((offset > len) || (len - offset < size)) +if (offset <0 ) {return -EIO ; + }return 0 ; }
@@ -3046,10 +3036,10 @@ static int coroutine_fn bdrv_aligned_preadv(BlockDriverState *bs, }/* Forward the request to the BlockDriver */ -if (!(bs->zero_beyond_eof && bs->growable)) { +if (!bs->zero_beyond_eof) { ret = drv->bdrv_co_readv (bs, sector_num, nb_sectors, qiov); }else { -/* Read zeros after EOF of growable BDSes */ +/* Read zeros after EOF */ int64_t total_sectors, max_nb_sectors; total_sectors =bdrv_nb_sectors (bs);
@@ -3326,7 +3316,7 @@ static int coroutine_fn bdrv_aligned_pwritev(BlockDriverState *bs,block_acct_highest_sector (&bs->stats, sector_num, nb_sectors); -if (bs->growable && ret >=0 ) { +if (ret >=0 ) { bs->total_sectors =MAX (bs->total_sectors, sector_num + nb_sectors); }
block/qcow2.c +0 -6
@@ -2521,15 +2521,12 @@ static int qcow2_save_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, {BDRVQcowState *s = bs->opaque;int64_t total_sectors = bs->total_sectors; -int growable = bs->growable;bool zero_beyond_eof = bs->zero_beyond_eof;int ret;BLKDBG_EVENT (bs->file,BLKDBG_VMSTATE_SAVE ); - bs->growable =1 ; bs->zero_beyond_eof = false; ret =bdrv_pwritev (bs,qcow2_vm_state_offset (s) + pos, qiov); - bs->growable = growable; bs->zero_beyond_eof = zero_beyond_eof;/* bdrv_co_do_writev will have increased the total_sectors value to include
@@ -2544,15 +2541,12 @@ static int qcow2_load_vmstate(BlockDriverState *bs, uint8_t *buf, int64_t pos, int size) {BDRVQcowState *s = bs->opaque; -int growable = bs->growable;bool zero_beyond_eof = bs->zero_beyond_eof;int ret;BLKDBG_EVENT (bs->file,BLKDBG_VMSTATE_LOAD ); - bs->growable =1 ; bs->zero_beyond_eof = false; ret =bdrv_pread (bs,qcow2_vm_state_offset (s) + pos, buf, size); - bs->growable = growable; bs->zero_beyond_eof = zero_beyond_eof;return ret;
block/raw-posix.c +1 -1
@@ -1047,7 +1047,7 @@ static int aio_worker(void *arg)switch (aiocb->aio_type &QEMU_AIO_TYPE_MASK ) {case QEMU_AIO_READ : ret =handle_aiocb_rw (aiocb); -if (ret >=0 && ret < aiocb->aio_nbytes && aiocb->bs->growable) { +if (ret >=0 && ret < aiocb->aio_nbytes) {iov_memset (aiocb->aio_iov, aiocb->aio_niov, ret,0 , aiocb->aio_nbytes - ret);
block/raw-win32.c +1 -1
@@ -101,7 +101,7 @@ static int aio_worker(void *arg)switch (aiocb->aio_type &QEMU_AIO_TYPE_MASK ) {case QEMU_AIO_READ : count =handle_aiocb_rw (aiocb); -if (count < aiocb->aio_nbytes && aiocb->bs->growable) { +if (count < aiocb->aio_nbytes) {/* A short read means that we have reached EOF. Pad the buffer * with zeros for bytes after EOF. */ iov_memset(aiocb->aio_iov, aiocb->aio_niov, count,
block/sheepdog.c +1 -1
@@ -2117,7 +2117,7 @@ static coroutine_fn int sd_co_writev(BlockDriverState *bs, int64_t sector_num,int64_t offset = (sector_num + nb_sectors) *BDRV_SECTOR_SIZE ;BDRVSheepdogState *s = bs->opaque; -if (bs->growable && offset > s->inode.vdi_size) { +if (offset > s->inode.vdi_size) { ret =sd_truncate (bs, offset);if (ret <0 ) {return ret;
include/block/block_int.h +0 -3
@@ -369,9 +369,6 @@ struct BlockDriverState {/* I/O Limits */ BlockLimits bl; -/* Whether the disk can expand beyond total_sectors */ -int growable; -/* Whether produces zeros when read beyond eof */ bool zero_beyond_eof;
Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH v4 15/16] block: Remove "growable" from BDS
Quoted 6 lines · Max Reitz
Now that request clamping is done in the BlockBackend, the "growable" field can be removed from the BlockDriverState. All BDSs are now treated as being "growable" (that is, they are allowed to grow; they are not necessarily actually able to).
Signed-off-by Max Reitz <[email protected]>
Quoted 8 lines
--- block.c | 24 +++++++----------------- block/qcow2.c | 6 ------ block/raw-posix.c | 2 +- block/raw-win32.c | 2 +- block/sheepdog.c | 2 +- include/block/block_int.h | 3 --- 6 files changed, 10 insertions(+), 29 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH v4 15/16] block: Remove "growable" from BDS
In reply to Max ReitzQuoted 6 lines · Max Reitz
Now that request clamping is done in the BlockBackend, the "growable" field can be removed from the BlockDriverState. All BDSs are now treated as being "growable" (that is, they are allowed to grow; they are not necessarily actually able to).
Signed-off-by Max Reitz <[email protected]>
Quoted 8 lines
--- block.c | 24 +++++++----------------- block/qcow2.c | 6 ------ block/raw-posix.c | 2 +- block/raw-win32.c | 2 +- block/sheepdog.c | 2 +- include/block/block_int.h | 3 --- 6 files changed, 10 insertions(+), 29 deletions(-)
PATCH v4 16/16 block: Keep bdrv_check*_request()'s return value
In reply to Max ReitzDo not throw away the value returned by bdrv_check_request() and bdrv_check_byte_request().
Fix up some coding style issues in the proximity of the affected hunks.
--- block.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-)
block.c +24 -11
@@ -3101,8 +3101,10 @@ static int coroutine_fn bdrv_co_do_preadv(BlockDriverState *bs,if (!drv) {return -ENOMEDIUM ; } -if (bdrv_check_byte_request (bs, offset, bytes)) { -return -EIO ; + + ret =bdrv_check_byte_request (bs, offset, bytes); +if (ret <0 ) { +return ret; }if (bs->copy_on_read) {
@@ -3345,8 +3347,10 @@ static int coroutine_fn bdrv_co_do_pwritev(BlockDriverState *bs,if (bs->read_only) {return -EACCES ; } -if (bdrv_check_byte_request (bs, offset, bytes)) { -return -EIO ; + + ret =bdrv_check_byte_request (bs, offset, bytes); +if (ret <0 ) { +return ret; }/* throttling disk I/O */
@@ -4200,12 +4204,18 @@ int bdrv_write_compressed(BlockDriverState *bs, int64_t sector_num, const uint8_t *buf, int nb_sectors) {BlockDriver *drv = bs->drv; -if (!drv) +int ret; + +if (!drv) {return -ENOMEDIUM ; -if (!drv->bdrv_write_compressed) + } +if (!drv->bdrv_write_compressed) {return -ENOTSUP ; -if (bdrv_check_request (bs, sector_num, nb_sectors)) -return -EIO ; + } + ret =bdrv_check_request (bs, sector_num, nb_sectors); +if (ret <0 ) { +return ret; + }assert (QLIST_EMPTY (&bs->dirty_bitmaps));
@@ -5120,12 +5130,15 @@ static void coroutine_fn bdrv_discard_co_entry(void *opaque) int coroutine_fn bdrv_co_discard(BlockDriverState *bs, int64_t sector_num,int nb_sectors) { -int max_discard; +int max_discard, ret;if (!bs->drv) {return -ENOMEDIUM ; - }else if (bdrv_check_request (bs, sector_num, nb_sectors)) { -return -EIO ; + } + + ret =bdrv_check_request (bs, sector_num, nb_sectors); +if (ret <0 ) { +return ret; }else if (bs->read_only) {return -EROFS ; }
Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH v4 16/16] block: Keep bdrv_check*_request()'s return value
Quoted 11 lines · Max Reitz
Do not throw away the value returned by
bdrv_check_request()andbdrv_check_byte_request().Fix up some coding style issues in the proximity of the affected hunks.
Signed-off-by Max Reitz <[email protected]>Reviewed-by Eric Blake <[email protected]>Reviewed-by Kevin Wolf <[email protected]>--- block.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-)
Stefan Hajnoczi
AppliedQuoted 134 lines · Max Reitz
This series removes the "growable" field from the BlockDriverState object. Its use was to clamp guest requests against the limits of the BDS; however, this can now be done more easily by moving those checks into the BlockBackend functions.
In a future series, "growable" may be reintroduced (maybe with a different name); it will then signify whether a BDS is able to grow (in contrast to the current "growable", which signifies whether it is allowed to). Maybe I will add it to the BlockDriver instead of the BDS, though.
To be able to remove that field, qemu-io needs to be converted to BlockBackend, which is done by this series as well. While working on that I decided to convert blk_new_with_bs()+bdrv_open() to
blk_new_open(). I was skeptical about that decision at first, but it seems good now that I was able to replace nearly everyblk_new_with_bs()call byblk_new_open(). In a future series I may try to convert some remainingbdrv_open()calls toblk_new_open()as well. (And, in fact, in a future series I *will* replace the last remainingblk_new_with_bs()outside ofblk_new_open()byblk_new_open().)Finally, the question needs to be asked: If, after this series, every BDS is allowed to grow, are there any users which do not use BB, but should still be disallowed from reading/writing beyond a BDS's limits? The only users I could see were the block jobs. Some of them should indeed be converted to BB; but none of them takes a user-supplied offset or size, all work on the full BDS (or only on parts which have been modified, etc.). Therefore, it is by design impossible for them to exceed the BDS's limits, which makes making all BDS's growable safe.
v4:
- Patch 1: Addedblk_nb_sectors()[Eric]
- Patch 3: Added in order to get a more useful error message than just "Unknown protocol" [Eric]
- Patch 4: Added [Eric]
- Patch 5:
- Useqdict_put()instead ofqdict_put_obj()[Kevin]
- Rebased onto the new patches 3 and 4
- Patch 6:
- Note the fix for invalid drivers in the commit message; and note that the fix is not complete [Kevin]
- Useqdict_put()instead ofqdict_put_obj()[Kevin]
- Patch 7: Useqdict_put()instead ofqdict_put_obj()[Kevin]
- Patch 8:
- Do not skip output format validity test on unsafe [Kevin]
- Dropped superfluous !unsafe in condition [Eric]
- Useqdict_put()instead ofqdict_put_obj()[Kevin]
- Patch 9: Useblk_nb_sectors()to replacebdrv_nb_sectors()(instead ofblk_getlength()with a later division byBDRV_SECTOR_SIZE) [Eric]
- Patch 10: Useqdict_put()instead ofqdict_put_obj()[Kevin]
- Patch 11: Dropped the hunk which removed the reset ofqemuio_bsto NULL inclose_f()[Kevin]
- Patch 12: Added a comment to the group file stating that 016 should not be reused [Eric/Kevin]
- Patch 13:
- Useblk_nb_sectors()to replace bdrv_nb-sectors() [Eric]
- Dropqemuio_bs[Kevin]
- Patch 15: Kept the "if (offset < 0)" check inbdrv_check_byte_request()[Kevin]v3:
- Rebased (onto Stefan's branch rebased onto master)
- Fixed patch 4 [Stefano]v2:
- Rebased [Kevin]
- Patch 2: Added a TODO comment about removing @filename and @flags fromblk_new_open()when possible [Kevin]git-backport-diff against v3:
Key:
[----] : patches are identical
[####] : number of functional differences between upstream/downstream patch [down] : patch is downstream-only
The flags [FC] indicate (F)unctional and (C)ontextual differences, respectively001/16:[0006] [FC] 'block: Lift some BDS functions to the BlockBackend' 002/16:[----] [--] 'block: Add
blk_new_open()'
003/16:[down] 'block: Add Error parameter tobdrv_find_protocol()' 004/16:[down] 'iotests: Add test for driver=qcow2,format=qcow2' 005/16:[0012] [FC] 'blockdev: Useblk_new_open()inblockdev_init()' 006/16:[0003] [FC] 'block/xen: Useblk_new_open()inblk_connect()' 007/16:[0002] [FC] 'qemu-img: Useblk_new_open()inimg_open()' 008/16:[0016] [FC] 'qemu-img: Useblk_new_open()inimg_rebase()' 009/16:[0030] [FC] 'qemu-img: Use BlockBackend as far as possible' 010/16:[0002] [FC] 'qemu-nbd: Useblk_new_open()inmain()' 011/16:[0003] [FC] 'qemu-io: Useblk_new_open()inopenfile()' 012/16:[0001] [FC] 'qemu-io: Remove "growable" option' 013/16:[0006] [FC] 'qemu-io: Use BlockBackend'
014/16:[----] [--] 'block: Clamp BlockBackend requests' 015/16:[0004] [FC] 'block: Remove "growable" from BDS' 016/16:[----] [--] 'block: Keep bdrv_check*_request()'s return value'Max Reitz (16):
block: Lift some BDS functions to the BlockBackend
block: Addblk_new_open()
block: Add Error parameter tobdrv_find_protocol()
iotests: Add test for driver=qcow2,format=qcow2
blockdev: Useblk_new_open()inblockdev_init()block/xen: Useblk_new_open()inblk_connect()
qemu-img: Useblk_new_open()inimg_open()
qemu-img: Useblk_new_open()inimg_rebase()
qemu-img: Use BlockBackend as far as possible
qemu-nbd: Useblk_new_open()inmain()
qemu-io: Useblk_new_open()inopenfile()
qemu-io: Remove "growable" option
qemu-io: Use BlockBackend
block: Clamp BlockBackend requests
block: Remove "growable" from BDS
block: Keep bdrv_check*_request()'s return valueblock.c | 73 +++++++------ block/block-backend.c | 224 ++++++++++++++++++++++++++++++++++++++ block/qcow2.c | 6 -- block/raw-posix.c | 2 +- block/raw-win32.c | 2 +- block/sheepdog.c | 4 +- blockdev.c | 92 ++++++++-------- hmp.c | 9 +- hw/block/xen_disk.c | 27 ++--- include/block/block.h | 3 +- include/block/block_int.h | 3 - include/qemu-io.h | 4 +- include/sysemu/block-backend.h | 13 +++ qemu-img.c | 158 +++++++++++++-------------- qemu-io-cmds.c | 237 +++++++++++++++++++++-------------------- qemu-io.c | 58 +++------- qemu-nbd.c | 25 ++--- tests/qemu-iotests/016 | 73 -------------
Quoted 13 lines
tests/qemu-iotests/016.out | 23 ---- tests/qemu-iotests/051 | 1 + tests/qemu-iotests/051.out | 63 +++++------ tests/qemu-iotests/087.out | 8 +- tests/qemu-iotests/group | 2 +- 23 files changed, 603 insertions(+), 507 deletions(-) delete mode 100755 tests/qemu-iotests/016 delete mode 100644 tests/qemu-iotests/016.outSignature · 1 line
2.1.0
Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block
Stefan