mirror: Do not dereference invalid pointers
v3 cover mirror: Do not dereference invalid pointers
Hi,
v2’s cover letter should explain everything:
https://lists.nongnu.org/archive/html/qemu-block/2019-09/msg01079.html
v3:
- Patch 2: Use input visitor as proposed by Vladimir
git-backport-diff against v2:
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/4:[----] [--] 'mirror: Do not dereference invalid pointers' 002/4:[0041] [FC] 'blkdebug: Allow taking/unsharing permissions' 003/4:[----] [--] 'iotests: Add @error to wait_until_completed' 004/4:[----] [--] 'iotests: Add test for failing mirror complete'
Max Reitz (4):
mirror: Do not dereference invalid pointers
blkdebug: Allow taking/unsharing permissions
iotests: Add @error to wait_until_completed
iotests: Add test for failing mirror complete
qapi/block-core.json | 14 +++++- block/blkdebug.c | 91 ++++++++++++++++++++++++++++++++++- block/mirror.c | 13 +++-- tests/qemu-iotests/041 | 44 +++++++++++++++++ tests/qemu-iotests/041.out | 4 +- tests/qemu-iotests/iotests.py | 18 ++++--- 6 files changed, 170 insertions(+), 14 deletions(-)
Signature · 1 line
2.21.0
PATCH v3 1/4 mirror: Do not dereference invalid pointers
mirror_exit_common() may be called twice (if it is called from mirror_prepare() and fails, it will be called from mirror_abort() again).
In such a case, many of the pointers in the MirrorBlockJob object will already be freed. This can be seen most reliably for s->target, which is set to NULL (and then dereferenced by blk_bs()).
--- block/mirror.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
block/mirror.c +9 -4
@@ -620,11 +620,11 @@ static int mirror_exit_common(Job *job) {MirrorBlockJob *s =container_of (job, MirrorBlockJob, common.job);BlockJob *bjob = &s->common; -MirrorBDSOpaque *bs_opaque = s->mirror_top_bs->opaque; +MirrorBDSOpaque *bs_opaque;AioContext *replace_aio_context =NULL ; -BlockDriverState *src = s->mirror_top_bs->backing->bs; -BlockDriverState *target_bs =blk_bs (s->target); -BlockDriverState *mirror_top_bs = s->mirror_top_bs; +BlockDriverState *src; +BlockDriverState *target_bs; +BlockDriverState *mirror_top_bs;Error *local_err =NULL ;bool abort = job->ret <0 ;int ret =0 ;
@@ -634,6 +634,11 @@ static int mirror_exit_common(Job *job) } s->prepared = true; + mirror_top_bs = s->mirror_top_bs; + bs_opaque = mirror_top_bs->opaque; + src = mirror_top_bs->backing->bs; + target_bs =blk_bs (s->target); +if (bdrv_chain_contains (src, target_bs)) {bdrv_unfreeze_backing_chain (mirror_top_bs, target_bs); }
Signature · 1 line
2.21.0
PATCH v3 2/4 blkdebug: Allow taking/unsharing permissions
In reply to Max ReitzSometimes it is useful to be able to add a node to the block graph that takes or unshare a certain set of permissions for debugging purposes. This patch adds this capability to blkdebug.
(Note that you cannot make blkdebug release or share permissions that it needs to take or cannot share, because this might result in assertion failures in the block layer. But if the blkdebug node has no parents, it will not take any permissions and share everything by default, so you can then freely choose what permissions to take and share.)
--- qapi/block-core.json | 14 ++++++- block/blkdebug.c | 91 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 103 insertions(+), 2 deletions(-)
qapi/block-core.json +13 -1
@@ -3453,6 +3453,16 @@ # # @set-state: array of state-change descriptions # +# @take-child-perms: Permissions to take on @image in addition to what +# is necessary anyway (which depends on how the +# blkdebug node is used). Defaults to none. +# (since 4.2) +# +# @unshare-child-perms: Permissions not to share on @image in addition +# to what cannot be shared anyway (which depends +# on how the blkdebug node is used). Defaults +# to none. (since 4.2) +# # Since: 2.9 ## { 'struct': 'BlockdevOptionsBlkdebug',
@@ -3462,7 +3472,9 @@ '*opt-write-zero': 'int32', '*max-write-zero': 'int32', '*opt-discard': 'int32', '*max-discard': 'int32', '*inject-error': ['BlkdebugInjectErrorOptions'], - '*set-state': ['BlkdebugSetStateOptions'] } } + '*set-state': ['BlkdebugSetStateOptions'], + '*take-child-perms': ['BlockPermission'], + '*unshare-child-perms': ['BlockPermission'] } } ## # @BlockdevOptionsBlklogwrites:
block/blkdebug.c +90 -1
131 lines not on this page · raw message
Signature · 1 line
2.21.0
Re: [PATCH v3 2/4] blkdebug: Allow taking/unsharing permissions
Quoted 83 lines · Max Reitz
Sometimes it is useful to be able to add a node to the block graph that takes or unshare a certain set of permissions for debugging purposes. This patch adds this capability to blkdebug.
(Note that you cannot make blkdebug release or share permissions that it needs to take or cannot share, because this might result in assertion failures in the block layer. But if the blkdebug node has no parents, it will not take any permissions and share everything by default, so you can then freely choose what permissions to take and share.)
Signed-off-by Max Reitz <[email protected]>--- qapi/block-core.json | 14 ++++++- block/blkdebug.c | 91 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 103 insertions(+), 2 deletions(-)qapi/block-core.json +13
-1@@ -3453,6 +3453,16 @@ # # @set-state: array of state-change descriptions # +# @take-child-perms: Permissions to take on @image in addition to what +# is necessary anyway (which depends on how the +# blkdebug node is used). Defaults to none. +# (since 4.2) +# +# @unshare-child-perms: Permissions not to share on @image in addition +# to what cannot be shared anyway (which depends +# on how the blkdebug node is used). Defaults +# to none. (since 4.2) +# # Since: 2.9 ## { 'struct': 'BlockdevOptionsBlkdebug',@@ -3462,7 +3472,9 @@ '*opt-write-zero': 'int32', '*max-write-zero': 'int32', '*opt-discard': 'int32', '*max-discard': 'int32', '*inject-error': ['BlkdebugInjectErrorOptions'], - '*set-state': ['BlkdebugSetStateOptions'] } } + '*set-state': ['BlkdebugSetStateOptions'], + '*take-child-perms': ['BlockPermission'], + '*unshare-child-perms': ['BlockPermission'] } } ## # @BlockdevOptionsBlklogwrites:block/blkdebug.c +9
-0@@ -28,10 +28,14 @@#include "qemu/cutils.h" #include "qemu/config-file.h" #include "block/block_int.h" +#include "block/qdict.h" #include "qemu/module.h" #include "qemu/option.h" +#include "qapi/qapi-visit-block-core.h" #include "qapi/qmp/qdict.h" +#include "qapi/qmp/qlist.h" #include "qapi/qmp/qstring.h" +#include "qapi/qobject-input-visitor.h" #include "sysemu/qtest.h" typedef struct BDRVBlkdebugState {@@ -44,6 +48,9 @@ typedef struct BDRVBlkdebugState {uint64_t opt_discard;uint64_t max_discard; +uint64_t take_child_perms; +uint64_t unshare_child_perms; +/* For blkdebug_refresh_filename() */ char *config_file;@@ -344,6 +351,67 @@ static void blkdebug_parse_filename(const char *filename, QDict *options,qdict_put_str (options,"x-image" , filename); } +static int blkdebug_parse_perm_list (uint64_t *dest,QDict *options, +const char *prefix,Error **errp)
block/blkdebug.c static void blkdebug_parse_filename(const char *filename, QDict *options, · line 365
Quoted 10 lines
block/blkdebug.c +10
-0+{ +int ret =0 ; +QDict *subqdict =NULL ; +QObject *crumpled_subqdict =NULL ; +Visitor *v =NULL ; +BlockPermissionList *perm_list =NULL , *element; +Error *local_err =NULL ; + +qdict_extract_subqdict (options, &subqdict, prefix); +if (!qdict_size (subqdict)) {
Hmm, you consider it as a success, so you mean default. Then, it's safer to set *dest = 0 here.
Quoted 7 lines
block/blkdebug.c +7
-0+ goto out; + } + + crumpled_subqdict =qdict_crumple (subqdict, errp); +if (!crumpled_subqdict) { + ret = -EINVAL ; + goto out;
block/blkdebug.c static void blkdebug_parse_filename(const char *filename, QDict *options, · line 382
Quoted 10 lines
block/blkdebug.c +10
-0+ } + + v =qobject_input_visitor_new (crumpled_subqdict); +visit_type_BlockPermissionList (v,NULL , &perm_list, &local_err); +if (local_err) { +error_propagate (errp, local_err); + ret = -EINVAL ; + goto out; + } +
I'd prefer explicitly set *dest = 0 here too.
block/blkdebug.c static void blkdebug_parse_filename(const char *filename, QDict *options, · line 384
Quoted 2 lines
block/blkdebug.c +2
-0+for (element = perm_list; element; element = element->next) { + *dest |=UINT64_C (1 ) << element->value;
Hmm, so, you rely on correct correspondence between generated BlockPermission enum and unnamed enum with BLK_PERM_* constants...
I'm afraid it's unsafe, so, in xdbg_graph_add_edge() special mapping variable is used + QEMU_BUILD_BUG_ON on BLK_PERM_ALL.
I think something like this should be done here.
Quoted 78 lines
block/blkdebug.c +52
-1+ } + +out: +qapi_free_BlockPermissionList (perm_list); +visit_free (v); +qobject_unref (subqdict); +qobject_unref (crumpled_subqdict); +return ret; +} + +static int blkdebug_parse_perms (BDRVBlkdebugState *s,QDict *options, +Error **errp) +{ +int ret; + + ret =blkdebug_parse_perm_list (&s->take_child_perms, options, +"take-child-perms." , errp); +if (ret <0 ) { +return ret; + } + + ret =blkdebug_parse_perm_list (&s->unshare_child_perms, options, +"unshare-child-perms." , errp); +if (ret <0 ) { +return ret; + } + +return 0 ; +} +static QemuOptsList runtime_opts = { .name ="blkdebug" , .head =QTAILQ_HEAD_INITIALIZER (runtime_opts.head),@@ -419,6 +487,12 @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags,/* Set initial state */ s->state =1 ; +/* Parse permissions modifiers before opening the image file */ + ret =blkdebug_parse_perms (s, options, errp); +if (ret <0 ) { + goto out; + } +/* Open the image file */ bs->file =bdrv_open_child (qemu_opt_get (opts,"x-image" ), options,"image" , bs, &child_file, false, &local_err);@@ -916,6 +990,21 @@ static int blkdebug_reopen_prepare(BDRVReopenState *reopen_state,return 0 ; } +static void blkdebug_child_perm (BlockDriverState *bs,BdrvChild *c, +const BdrvChildRole *role, +BlockReopenQueue *reopen_queue, +uint64_t perm,uint64_t shared, +uint64_t *nperm,uint64_t *nshared) +{ +BDRVBlkdebugState *s = bs->opaque; + +bdrv_filter_default_perms (bs, c, role, reopen_queue, perm, shared, + nperm, nshared); + + *nperm |= s->take_child_perms; + *nshared &= ~s->unshare_child_perms; +} +static const char *const blkdebug_strong_runtime_opts[] = {"config" ,"inject-error." ,@@ -940,7 +1029,7 @@ static BlockDriver bdrv_blkdebug = { .bdrv_file_open = blkdebug_open, .bdrv_close = blkdebug_close, .bdrv_reopen_prepare = blkdebug_reopen_prepare, - .bdrv_child_perm = bdrv_filter_default_perms, + .bdrv_child_perm = blkdebug_child_perm, .bdrv_getlength = blkdebug_getlength, .bdrv_refresh_filename = blkdebug_refresh_filename,
Signature · 2 lines
Best regards, Vladimir
Re: [PATCH v3 2/4] blkdebug: Allow taking/unsharing permissions
Quoted 82 lines · Vladimir Sementsov-Ogievskiy
Quoted 81 lines · Max Reitz
Sometimes it is useful to be able to add a node to the block graph that takes or unshare a certain set of permissions for debugging purposes. This patch adds this capability to blkdebug.
(Note that you cannot make blkdebug release or share permissions that it needs to take or cannot share, because this might result in assertion failures in the block layer. But if the blkdebug node has no parents, it will not take any permissions and share everything by default, so you can then freely choose what permissions to take and share.)
Signed-off-by Max Reitz <[email protected]>--- qapi/block-core.json | 14 ++++++- block/blkdebug.c | 91 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 103 insertions(+), 2 deletions(-)qapi/block-core.json +13
-1@@ -3453,6 +3453,16 @@ # # @set-state: array of state-change descriptions # +# @take-child-perms: Permissions to take on @image in addition to what +# is necessary anyway (which depends on how the +# blkdebug node is used). Defaults to none. +# (since 4.2) +# +# @unshare-child-perms: Permissions not to share on @image in addition +# to what cannot be shared anyway (which depends +# on how the blkdebug node is used). Defaults +# to none. (since 4.2) +# # Since: 2.9 ## { 'struct': 'BlockdevOptionsBlkdebug',@@ -3462,7 +3472,9 @@ '*opt-write-zero': 'int32', '*max-write-zero': 'int32', '*opt-discard': 'int32', '*max-discard': 'int32', '*inject-error': ['BlkdebugInjectErrorOptions'], - '*set-state': ['BlkdebugSetStateOptions'] } } + '*set-state': ['BlkdebugSetStateOptions'], + '*take-child-perms': ['BlockPermission'], + '*unshare-child-perms': ['BlockPermission'] } } ## # @BlockdevOptionsBlklogwrites:block/blkdebug.c +7
-0@@ -28,10 +28,14 @@#include "qemu/cutils.h" #include "qemu/config-file.h" #include "block/block_int.h" +#include "block/qdict.h" #include "qemu/module.h" #include "qemu/option.h" +#include "qapi/qapi-visit-block-core.h" #include "qapi/qmp/qdict.h" +#include "qapi/qmp/qlist.h" #include "qapi/qmp/qstring.h" +#include "qapi/qobject-input-visitor.h" #include "sysemu/qtest.h" typedef struct BDRVBlkdebugState {@@ -44,6 +48,9 @@ typedef struct BDRVBlkdebugState {uint64_t opt_discard;uint64_t max_discard; +uint64_t take_child_perms; +uint64_t unshare_child_perms; +/* For blkdebug_refresh_filename() */ char *config_file;@@ -344,6 +351,67 @@ static void blkdebug_parse_filename(const char *filename, QDict *options,qdict_put_str (options,"x-image" , filename); }
Quoted 16 lines
block/blkdebug.c static void blkdebug_parse_filename(const char *filename, QDict *options, · line 365
Quoted 12 lines
block/blkdebug.c +12
-0+static int blkdebug_parse_perm_list (uint64_t *dest,QDict *options, +const char *prefix,Error **errp) +{ +int ret =0 ; +QDict *subqdict =NULL ; +QObject *crumpled_subqdict =NULL ; +Visitor *v =NULL ; +BlockPermissionList *perm_list =NULL , *element; +Error *local_err =NULL ; + +qdict_extract_subqdict (options, &subqdict, prefix); +if (!qdict_size (subqdict)) {Hmm, you consider it as a success, so you mean default. Then, it's safer to set *dest = 0 here.
“Safer” depends on the purpose of this function, and right now it’s simply to set all fields that are given in the options; not to reset any that aren’t.
I suppose there’s no harm in changing the purpose of the function, though.
Quoted 23 lines
Quoted 7 lines
block/blkdebug.c +7
-0+ goto out; + } + + crumpled_subqdict =qdict_crumple (subqdict, errp); +if (!crumpled_subqdict) { + ret = -EINVAL ; + goto out;block/blkdebug.c static void blkdebug_parse_filename(const char *filename, QDict *options, · line 382
Quoted 10 lines
block/blkdebug.c +10
-0+ } + + v =qobject_input_visitor_new (crumpled_subqdict); +visit_type_BlockPermissionList (v,NULL , &perm_list, &local_err); +if (local_err) { +error_propagate (errp, local_err); + ret = -EINVAL ; + goto out; + } +I'd prefer explicitly set *dest = 0 here too.
block/blkdebug.c static void blkdebug_parse_filename(const char *filename, QDict *options, · line 384
Quoted 2 lines
block/blkdebug.c +2
-0+for (element = perm_list; element; element = element->next) { + *dest |=UINT64_C (1 ) << element->value;
Quoted 7 lines
Hmm, so, you rely on correct correspondence between generated BlockPermission enum and unnamed enum with BLK_PERM_* constants...
I'm afraid it's unsafe, so, in
xdbg_graph_add_edge()special mapping variable is used +QEMU_BUILD_BUG_ONonBLK_PERM_ALL.I think something like this should be done here.
I don’t really like it because I think it’s cool to have a 1-to-1 relationship between the BLK_PERM_* constants and what’s defined in QAPI. I don’t quite like assuming there isn’t, because there’s no reason why they wouldn’t correspond.
In fact, I’d rather define the BLK_PERM_* constants based on the QAPI enum, but I don’t know whether we want to include the QAPI header into block.h. ...Well, judging from a quick test it looks like the header is included into it recursively anyway. So maybe I’ll do that instead.
Max
Re: [PATCH v3 2/4] blkdebug: Allow taking/unsharing permissions
Quoted 142 lines · Max Reitz
Quoted 82 lines · Vladimir Sementsov-Ogievskiy
Quoted 81 lines · Max Reitz
Sometimes it is useful to be able to add a node to the block graph that takes or unshare a certain set of permissions for debugging purposes. This patch adds this capability to blkdebug.
(Note that you cannot make blkdebug release or share permissions that it needs to take or cannot share, because this might result in assertion failures in the block layer. But if the blkdebug node has no parents, it will not take any permissions and share everything by default, so you can then freely choose what permissions to take and share.)
Signed-off-by Max Reitz <[email protected]>--- qapi/block-core.json | 14 ++++++- block/blkdebug.c | 91 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 103 insertions(+), 2 deletions(-)qapi/block-core.json +13
-1@@ -3453,6 +3453,16 @@ # # @set-state: array of state-change descriptions # +# @take-child-perms: Permissions to take on @image in addition to what +# is necessary anyway (which depends on how the +# blkdebug node is used). Defaults to none. +# (since 4.2) +# +# @unshare-child-perms: Permissions not to share on @image in addition +# to what cannot be shared anyway (which depends +# on how the blkdebug node is used). Defaults +# to none. (since 4.2) +# # Since: 2.9 ## { 'struct': 'BlockdevOptionsBlkdebug',@@ -3462,7 +3472,9 @@ '*opt-write-zero': 'int32', '*max-write-zero': 'int32', '*opt-discard': 'int32', '*max-discard': 'int32', '*inject-error': ['BlkdebugInjectErrorOptions'], - '*set-state': ['BlkdebugSetStateOptions'] } } + '*set-state': ['BlkdebugSetStateOptions'], + '*take-child-perms': ['BlockPermission'], + '*unshare-child-perms': ['BlockPermission'] } } ## # @BlockdevOptionsBlklogwrites:block/blkdebug.c +7
-0@@ -28,10 +28,14 @@#include "qemu/cutils.h" #include "qemu/config-file.h" #include "block/block_int.h" +#include "block/qdict.h" #include "qemu/module.h" #include "qemu/option.h" +#include "qapi/qapi-visit-block-core.h" #include "qapi/qmp/qdict.h" +#include "qapi/qmp/qlist.h" #include "qapi/qmp/qstring.h" +#include "qapi/qobject-input-visitor.h" #include "sysemu/qtest.h" typedef struct BDRVBlkdebugState {@@ -44,6 +48,9 @@ typedef struct BDRVBlkdebugState {uint64_t opt_discard;uint64_t max_discard; +uint64_t take_child_perms; +uint64_t unshare_child_perms; +/* For blkdebug_refresh_filename() */ char *config_file;@@ -344,6 +351,67 @@ static void blkdebug_parse_filename(const char *filename, QDict *options,qdict_put_str (options,"x-image" , filename); }Quoted 16 lines
block/blkdebug.c static void blkdebug_parse_filename(const char *filename, QDict *options, · line 365
Quoted 12 lines
block/blkdebug.c +12
-0+static int blkdebug_parse_perm_list (uint64_t *dest,QDict *options, +const char *prefix,Error **errp) +{ +int ret =0 ; +QDict *subqdict =NULL ; +QObject *crumpled_subqdict =NULL ; +Visitor *v =NULL ; +BlockPermissionList *perm_list =NULL , *element; +Error *local_err =NULL ; + +qdict_extract_subqdict (options, &subqdict, prefix); +if (!qdict_size (subqdict)) {Hmm, you consider it as a success, so you mean default. Then, it's safer to set *dest = 0 here.
“Safer” depends on the purpose of this function, and right now it’s simply to set all fields that are given in the options; not to reset any that aren’t.
I suppose there’s no harm in changing the purpose of the function, though.
Quoted 23 lines
Quoted 7 lines
block/blkdebug.c +7
-0+ goto out; + } + + crumpled_subqdict =qdict_crumple (subqdict, errp); +if (!crumpled_subqdict) { + ret = -EINVAL ; + goto out;block/blkdebug.c static void blkdebug_parse_filename(const char *filename, QDict *options, · line 382
Quoted 10 lines
block/blkdebug.c +10
-0+ } + + v =qobject_input_visitor_new (crumpled_subqdict); +visit_type_BlockPermissionList (v,NULL , &perm_list, &local_err); +if (local_err) { +error_propagate (errp, local_err); + ret = -EINVAL ; + goto out; + } +I'd prefer explicitly set *dest = 0 here too.
block/blkdebug.c static void blkdebug_parse_filename(const char *filename, QDict *options, · line 384
Quoted 2 lines
block/blkdebug.c +2
-0+for (element = perm_list; element; element = element->next) { + *dest |=UINT64_C (1 ) << element->value;Quoted 7 lines
Hmm, so, you rely on correct correspondence between generated BlockPermission enum and unnamed enum with BLK_PERM_* constants...
I'm afraid it's unsafe, so, in
xdbg_graph_add_edge()special mapping variable is used +QEMU_BUILD_BUG_ONonBLK_PERM_ALL.I think something like this should be done here.
I don’t really like it because I think it’s cool to have a 1-to-1 relationship between the BLK_PERM_* constants and what’s defined in QAPI. I don’t quite like assuming there isn’t, because there’s no reason why they wouldn’t correspond.
Quoted 5 lines
In fact, I’d rather define the BLK_PERM_* constants based on the QAPI enum, but I don’t know whether we want to include the QAPI header into
block.h. ...Well, judging from a quick test it looks like the header is included into it recursively anyway. So maybe I’ll do that instead.
If BLK_PERM_* are defined in manner making the correspondence obvious, that's OK, of course.
Signature · 2 lines
Best regards, Vladimir
PATCH v3 3/4 iotests: Add @error to wait_until_completed
In reply to Max ReitzCallers can use this new parameter to expect failure during the completion process.
--- tests/qemu-iotests/iotests.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
tests/qemu-iotests/iotests.py +12 -6
@@ -770,15 +770,20 @@ class QMPTestCase(unittest.TestCase): self.assert_no_active_block_jobs() return result - def wait_until_completed(self, drive='drive0', check_offset=True, wait=60.0): + def wait_until_completed(self, drive='drive0', check_offset=True, wait=60.0, + error=None): '''Wait for a block job to finish, returning the event''' while True: for event in self.vm.get_qmp_events(wait=wait): if event['event'] == 'BLOCK_JOB_COMPLETED': self.assert_qmp(event, 'data/device', drive) - self.assert_qmp_absent(event, 'data/error') - if check_offset: - self.assert_qmp(event, 'data/offset', event['data']['len']) + if error is None: + self.assert_qmp_absent(event, 'data/error') + if check_offset: + self.assert_qmp(event, 'data/offset', + event['data']['len']) + else: + self.assert_qmp(event, 'data/error', error) self.assert_no_active_block_jobs() return event elif event['event'] == 'JOB_STATUS_CHANGE':
@@ -796,7 +801,8 @@ class QMPTestCase(unittest.TestCase): self.assert_qmp(event, 'data/type', 'mirror') self.assert_qmp(event, 'data/offset', event['data']['len']) - def complete_and_wait(self, drive='drive0', wait_ready=True): + def complete_and_wait(self, drive='drive0', wait_ready=True, + completion_error=None): '''Complete a block job and wait for it to finish''' if wait_ready: self.wait_ready(drive=drive)
@@ -804,7 +810,7 @@ class QMPTestCase(unittest.TestCase): result = self.vm.qmp('block-job-complete', device=drive) self.assert_qmp(result, 'return', {}) - event = self.wait_until_completed(drive=drive) + event = self.wait_until_completed(drive=drive, error=completion_error) self.assert_qmp(event, 'data/type', 'mirror') def pause_wait(self, job_id='job0'):
Signature · 1 line
2.21.0
PATCH v3 4/4 iotests: Add test for failing mirror complete
In reply to Max Reitz--- tests/qemu-iotests/041 | 44 ++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/041.out | 4 ++-- 2 files changed, 46 insertions(+), 2 deletions(-)
tests/qemu-iotests/041 +44 -0
@@ -1121,6 +1121,50 @@ class TestOrphanedSource(iotests.QMPTestCase): target='dest-ro') self.assert_qmp(result, 'error/class', 'GenericError') + def test_failing_permission_in_complete(self): + self.assert_no_active_block_jobs() + + # Unshare consistent-read on the target + # (The mirror job does not care) + result = self.vm.qmp('blockdev-add', + driver='blkdebug', + node_name='dest-perm', + image='dest', + unshare_child_perms=['consistent-read']) + self.assert_qmp(result, 'return', {}) + + result = self.vm.qmp('blockdev-mirror', job_id='job', device='src', + sync='full', target='dest', + filter_node_name='mirror-filter') + self.assert_qmp(result, 'return', {}) + + # Require consistent-read on the source + # (We can only add this node once the job has started, or it + # will complain that it does not want to run on non-root nodes) + result = self.vm.qmp('blockdev-add', + driver='blkdebug', + node_name='src-perm', + image='src', + take_child_perms=['consistent-read']) + self.assert_qmp(result, 'return', {}) + + # While completing, mirror will attempt to replace src by + # dest, which must fail because src-perm requires + # consistent-read but dest-perm does not share it; thus + # aborting the job when it is supposed to complete + self.complete_and_wait('job', + completion_error='Operation not permitted') + + # Assert that all of our nodes are still there (except for the + # mirror filter, which should be gone despite the failure) + nodes = self.vm.qmp('query-named-block-nodes')['return'] + nodes = [node['node-name'] for node in nodes] + + for expect in ('src', 'src-perm', 'dest', 'dest-perm'): + self.assertTrue(expect in nodes, '%s disappeared' % expect) + self.assertFalse('mirror-filter' in nodes, + 'Mirror filter node did not disappear') + if __name__ == '__main__': iotests.main(supported_fmts=['qcow2', 'qed'], supported_protocols=['file'])
tests/qemu-iotests/041.out +2 -2
@@ -1,5 +1,5 @@ -.......................................................................................... +........................................................................................... ---------------------------------------------------------------------- -Ran 90 tests +Ran 91 tests OK
Signature · 1 line
2.21.0
Quoted 24 lines · Max Reitz
Hi,
v2’s cover letter should explain everything:
https://lists.nongnu.org/archive/html/qemu-block/2019-09/msg01079.html
v3:
- Patch 2: Use input visitor as proposed by Vladimirgit-backport-diff against v2:
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/4:[----] [--] 'mirror: Do not dereference invalid pointers' 002/4:[0041] [FC] 'blkdebug: Allow taking/unsharing permissions' 003/4:[----] [--] 'iotests: Add @error to
wait_until_completed' 004/4:[----] [--] 'iotests: Add test for failing mirror complete'
Quoted 5 lines
Max Reitz (4):
mirror: Do not dereference invalid pointers
blkdebug: Allow taking/unsharing permissions
iotests: Add @error towait_until_completed
iotests: Add test for failing mirror complete
I’ve applied patch 1 to my block branch, and I’ll send a for-next series (for-5.0, I suppose?) for the rest.
Max