block: Fix op blockers for inactive images
cover block: Fix op blockers for inactive images
Fam's image locking series introduced some special-casing in the file-posix driver that avoids taking locks when the image is inactive. While this works, it really isn't the job of the file-posix driver, but the core block layer should consider that inactive nodes require a lot less permissions.
This series integrates op blockers with bdrv_inactivate/invalidate_cache() to solve this problem gennerically, and removes the workaround in file-posix.
Kevin Wolf (6):
migration: Unify block node activation error handling
block: New BdrvChildRole.activate() for blk_resume_after_migration()
block: Drop permissions when migration completes
block: Inactivate parents before children
block: Fix write/resize permissions for inactive images
file-posix: Remove .bdrv_inactivate/invalidate_cache
block.c | 76 ++++++++++++++++++++++++++++++++++++++++---- block/block-backend.c | 81 +++++++++++++++++++++++++++++++---------------- block/file-posix.c | 33 ------------------- include/block/block.h | 3 +- include/block/block_int.h | 6 ++++ migration/migration.c | 13 ++------ migration/savevm.c | 9 ++---- qmp.c | 18 ++++------- 8 files changed, 139 insertions(+), 100 deletions(-)
Signature · 1 line
1.8.3.1
PATCH 1/6 migration: Unify block node activation error handling
Migration code activates all block driver nodes on the destination when the migration completes. It does so by calling bdrv_invalidate_cache_all() and blk_resume_after_migration(). There is one code path for precopy and one for postcopy migration, resulting in four function calls, which used to have three different failure modes.
This patch unifies the behaviour so that failure to activate all block nodes is non-fatal, but the error message is logged and the VM isn't automatically started. 'cont' will retry activating the block nodes.
--- migration/migration.c | 16 +++++----------- migration/savevm.c | 12 +++++------- qmp.c | 18 +++++++++--------- 3 files changed, 19 insertions(+), 27 deletions(-)
migration/migration.c +5 -11
@@ -338,20 +338,14 @@ static void process_incoming_migration_bh(void *opaque)Error *local_err =NULL ;MigrationIncomingState *mis = opaque; -/* Make sure all file formats flush their mutable metadata */ +/* Make sure all file formats flush their mutable metadata. +* If we get an error here, just don't restart the VM yet. */ bdrv_invalidate_cache_all (&local_err); -if (local_err) { -migrate_set_state (&mis->state,MIGRATION_STATUS_ACTIVE , -MIGRATION_STATUS_FAILED ); -error_report_err (local_err); -migrate_decompress_threads_join (); -exit (EXIT_FAILURE ); +if (!local_err) { +blk_resume_after_migration (&local_err); } - -/* If we get an error here, just don't restart the VM yet. */ -blk_resume_after_migration (&local_err);if (local_err) { -error_free (local_err); +error_report_err (local_err); local_err =NULL ; autostart = false; }
migration/savevm.c +5 -7
@@ -1616,16 +1616,14 @@ static void loadvm_postcopy_handle_run_bh(void *opaque)qemu_announce_self (); -/* Make sure all file formats flush their mutable metadata */ +/* Make sure all file formats flush their mutable metadata. +* If we get an error here, just don't restart the VM yet. */ bdrv_invalidate_cache_all (&local_err); -if (local_err) { -error_report_err (local_err); +if (!local_err) { +blk_resume_after_migration (&local_err); } - -/* If we get an error here, just don't restart the VM yet. */ -blk_resume_after_migration (&local_err);if (local_err) { -error_free (local_err); +error_report_err (local_err); local_err =NULL ; autostart = false; }
qmp.c +9 -9
@@ -196,15 +196,15 @@ void qmp_cont(Error **errp) }/* Continuing after completed migration. Images have been inactivated to -* allow the destination to take control. Need to get control back now. */ -if (runstate_check (RUN_STATE_FINISH_MIGRATE ) || -runstate_check (RUN_STATE_POSTMIGRATE )) - { -bdrv_invalidate_cache_all (&local_err); -if (local_err) { -error_propagate (errp, local_err); -return ; - } +* allow the destination to take control. Need to get control back now. +* +* If there are no inactive block nodes (e.g. because the VM was just +* paused rather than completing a migration), bdrv_inactivate_all() simply +* doesn't do anything. */ +bdrv_invalidate_cache_all (&local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; }blk_resume_after_migration (&local_err);
Signature · 1 line
1.8.3.1
PATCH 2/6 block: New BdrvChildRole.activate() for blk_resume_after_migration()
In reply to Kevin WolfInstead of manually calling blk_resume_after_migration() in migration code after doing bdrv_invalidate_cache_all(), integrate the BlockBackend activation with cache invalidation into a single function. This is achieved with a new callback in BdrvChildRole that is called by bdrv_invalidate_cache_all().
--- block.c | 12 +++++++++- block/block-backend.c | 56 +++++++++++++++++++++++------------------------ include/block/block.h | 2 -- include/block/block_int.h | 5 +++++ migration/migration.c | 3 --- migration/savevm.c | 3 --- qmp.c | 6 ----- 7 files changed, 44 insertions(+), 43 deletions(-)
block.c +11 -1
@@ -3958,7 +3958,7 @@ void bdrv_init_with_whitelist(void)void bdrv_invalidate_cache (BlockDriverState *bs,Error **errp) { -BdrvChild *child; +BdrvChild *child, *parent;Error *local_err =NULL ;int ret;
@@ -3994,6 +3994,16 @@ void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp)error_setg_errno (errp, -ret,"Could not refresh total sector count" );return ; } + + QLIST_FOREACH(parent, &bs->parents, next_parent) { +if (parent->role->activate) { + parent->role->activate (parent, &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + } + } }void bdrv_invalidate_cache_all (Error **errp)
block/block-backend.c +28 -28
74 lines not on this page · raw message
include/block/block.h +0 -2
@@ -369,8 +369,6 @@ void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp);void bdrv_invalidate_cache_all (Error **errp);int bdrv_inactivate_all (void ); -void blk_resume_after_migration (Error **errp); -/* Ensure contents are flushed to disk. */ int bdrv_flush (BlockDriverState *bs); int coroutine_fn bdrv_co_flush(BlockDriverState *bs);
include/block/block_int.h +5 -0
@@ -473,6 +473,11 @@ struct BdrvChildRole {void (*drained_begin)(BdrvChild *child);void (*drained_end)(BdrvChild *child); +/* Notifies the parent that the child has been activated (e.g. when +* migration is completing) and it can start requesting permissions and +* doing I/O on it. */ +void (*activate)(BdrvChild *child,Error **errp); +void (*attach)(BdrvChild *child);void (*detach)(BdrvChild *child); };
migration/migration.c +0 -3
@@ -341,9 +341,6 @@ static void process_incoming_migration_bh(void *opaque)/* Make sure all file formats flush their mutable metadata. * If we get an error here, just don't restart the VM yet. */ bdrv_invalidate_cache_all (&local_err); -if (!local_err) { -blk_resume_after_migration (&local_err); - }if (local_err) {error_report_err (local_err); local_err =NULL ;
migration/savevm.c +0 -3
@@ -1619,9 +1619,6 @@ static void loadvm_postcopy_handle_run_bh(void *opaque)/* Make sure all file formats flush their mutable metadata. * If we get an error here, just don't restart the VM yet. */ bdrv_invalidate_cache_all (&local_err); -if (!local_err) { -blk_resume_after_migration (&local_err); - }if (local_err) {error_report_err (local_err); local_err =NULL ;
qmp.c +0 -6
@@ -207,12 +207,6 @@ void qmp_cont(Error **errp)return ; } -blk_resume_after_migration (&local_err); -if (local_err) { -error_propagate (errp, local_err); -return ; - } -if (runstate_check (RUN_STATE_INMIGRATE )) { autostart =1 ; }else {
Signature · 1 line
1.8.3.1
PATCH 3/6 block: Drop permissions when migration completes
In reply to Kevin WolfWith image locking, permissions affect other qemu processes as well. We want to be sure that the destination can run, so let's drop permissions on the source when migration completes.
--- block.c | 12 +++++++++++- block/block-backend.c | 25 +++++++++++++++++++++++++ include/block/block_int.h | 7 ++++--- 3 files changed, 40 insertions(+), 4 deletions(-)
block.c +11 -1
@@ -4028,7 +4028,7 @@ void bdrv_invalidate_cache_all(Error **errp)static int bdrv_inactivate_recurse (BlockDriverState *bs,bool setting_flag) { -BdrvChild *child; +BdrvChild *child, *parent;int ret;if (!setting_flag && bs->drv->bdrv_inactivate) {
@@ -4047,6 +4047,16 @@ static int bdrv_inactivate_recurse(BlockDriverState *bs,if (setting_flag) { bs->open_flags |=BDRV_O_INACTIVE ; + + QLIST_FOREACH(parent, &bs->parents, next_parent) { +if (parent->role->inactivate) { + ret = parent->role->inactivate (parent); +if (ret <0 ) { + bs->open_flags &= ~BDRV_O_INACTIVE ; +return ret; + } + } + } }return 0 ; }
block/block-backend.c +25 -0
@@ -156,6 +156,30 @@ static void blk_root_activate(BdrvChild *child, Error **errp) } } +static int blk_root_inactivate (BdrvChild *child) +{ +BlockBackend *blk = child->opaque; + +if (blk->disable_perm) { +return 0 ; + } + +/* Only inactivate BlockBackends for guest devices (which are inactive at +* this point because the VM is stopped) and unattached monitor-owned +* BlockBackends. If there is still any other user like a block job, then +* we simply can't inactivate the image. */ +if (!blk->dev && !blk->name[0 ]) { +return -EPERM ; + } + + blk->disable_perm = true; +if (blk->root) { +bdrv_child_try_set_perm (blk->root,0 ,BLK_PERM_ALL , &error_abort); + } + +return 0 ; +} +static const BdrvChildRole child_root = { .inherit_options = blk_root_inherit_options,
@@ -168,6 +192,7 @@ static const BdrvChildRole child_root = { .drained_end = blk_root_drained_end, .activate = blk_root_activate, + .inactivate = blk_root_inactivate, };/*
include/block/block_int.h +4 -3
@@ -473,10 +473,11 @@ struct BdrvChildRole {void (*drained_begin)(BdrvChild *child);void (*drained_end)(BdrvChild *child); -/* Notifies the parent that the child has been activated (e.g. when -* migration is completing) and it can start requesting permissions and -* doing I/O on it. */ +/* Notifies the parent that the child has been activated/inactivated (e.g. +* when migration is completing) and it can start/stop requesting +* permissions and doing I/O on it. */ void (*activate)(BdrvChild *child,Error **errp); +int (*inactivate)(BdrvChild *child);void (*attach)(BdrvChild *child);void (*detach)(BdrvChild *child);
Signature · 1 line
1.8.3.1
PATCH 4/6 block: Inactivate parents before children
In reply to Kevin WolfThe proper order for inactivating block nodes is that first the parents get inactivated and then the children. If we do things in this order, we can assert that we didn't accidentally leave a parent activated when one of its child nodes is inactive.
--- block.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-)
block.c +18 -7
@@ -762,6 +762,13 @@ static void bdrv_child_cb_drained_end(BdrvChild *child)bdrv_drained_end (bs); } +static int bdrv_child_cb_inactivate (BdrvChild *child) +{ +BlockDriverState *bs = child->opaque; +assert (bs->open_flags &BDRV_O_INACTIVE ); +return 0 ; +} +/* * Returns the options and flags that a temporary snapshot should get, based on * the originally requested flags (the originally requested image will have
@@ -822,6 +829,7 @@ const BdrvChildRole child_file = { .inherit_options = bdrv_inherited_options, .drained_begin = bdrv_child_cb_drained_begin, .drained_end = bdrv_child_cb_drained_end, + .inactivate = bdrv_child_cb_inactivate, };/*
@@ -843,6 +851,7 @@ const BdrvChildRole child_format = { .inherit_options = bdrv_inherited_fmt_options, .drained_begin = bdrv_child_cb_drained_begin, .drained_end = bdrv_child_cb_drained_end, + .inactivate = bdrv_child_cb_inactivate, };static void bdrv_backing_attach (BdrvChild *c)
@@ -928,6 +937,7 @@ const BdrvChildRole child_backing = { .inherit_options = bdrv_backing_options, .drained_begin = bdrv_child_cb_drained_begin, .drained_end = bdrv_child_cb_drained_end, + .inactivate = bdrv_child_cb_inactivate, };static int bdrv_open_flags (BlockDriverState *bs,int flags)
@@ -4038,13 +4048,6 @@ static int bdrv_inactivate_recurse(BlockDriverState *bs, } } - QLIST_FOREACH(child, &bs->children, next) { - ret =bdrv_inactivate_recurse (child->bs, setting_flag); -if (ret <0 ) { -return ret; - } - } -if (setting_flag) { bs->open_flags |=BDRV_O_INACTIVE ;
@@ -4058,6 +4061,14 @@ static int bdrv_inactivate_recurse(BlockDriverState *bs, } } } + + QLIST_FOREACH(child, &bs->children, next) { + ret =bdrv_inactivate_recurse (child->bs, setting_flag); +if (ret <0 ) { +return ret; + } + } +return 0 ; }
Signature · 1 line
1.8.3.1
PATCH 5/6 block: Fix write/resize permissions for inactive images
In reply to Kevin WolfFormat drivers for inactive nodes don't need write/resize permissions on their bs->file and can share write/resize with another VM (in fact, this is the whole point of keeping images inactive). Represent this fact in the op blocker system, so that image locking does the right thing without special-casing inactive images.
--- block.c | 35 +++++++++++++++++++++++++++++++++-- include/block/block.h | 1 + 2 files changed, 34 insertions(+), 2 deletions(-)
block.c +33 -2
@@ -192,11 +192,20 @@ void path_combine(char *dest, int dest_size, } } +/* Returns whether the image file is opened as read-only. Note that this can +* return false and writing to the image file is still not possible because the +* image is inactivated. */ bool bdrv_is_read_only (BlockDriverState *bs) {return bs->read_only; } +/* Returns whether the image file can be written to right now */ +bool bdrv_is_writable (BlockDriverState *bs) +{ +return !bdrv_is_read_only (bs) && !(bs->open_flags &BDRV_O_INACTIVE ); +} +int bdrv_can_set_read_only (BlockDriverState *bs,bool read_only,Error **errp) {/* Do not set read_only if copy_on_read is enabled */
@@ -1512,7 +1521,7 @@ static int bdrv_check_perm(BlockDriverState *bs, uint64_t cumulative_perms,/* Write permissions never work with read-only images */ if ((cumulative_perms & (BLK_PERM_WRITE |BLK_PERM_WRITE_UNCHANGED )) && -bdrv_is_read_only (bs)) + !bdrv_is_writable (bs)) {error_setg (errp,"Block node is read-only" );return -EPERM ;
@@ -1797,7 +1806,7 @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c,bdrv_filter_default_perms (bs, c, role, perm, shared, &perm, &shared);/* Format drivers may touch metadata even if the guest doesn't write */ -if (!bdrv_is_read_only (bs)) { +if (bdrv_is_writable (bs)) { perm |=BLK_PERM_WRITE |BLK_PERM_RESIZE ; }
@@ -1823,6 +1832,10 @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c,BLK_PERM_WRITE_UNCHANGED ; } +if (bs->open_flags &BDRV_O_INACTIVE ) { + shared |=BLK_PERM_WRITE |BLK_PERM_RESIZE ; + } + *nperm = perm; *nshared = shared; }
@@ -3969,6 +3982,7 @@ void bdrv_init_with_whitelist(void)void bdrv_invalidate_cache (BlockDriverState *bs,Error **errp) {BdrvChild *child, *parent; +uint64_t perm, shared_perm;Error *local_err =NULL ;int ret;
@@ -4005,6 +4019,16 @@ void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp)return ; } +/* Update permissions, they may differ for inactive nodes */ +bdrv_get_cumulative_perm (bs, &perm, &shared_perm); + ret =bdrv_check_perm (bs, perm, shared_perm,NULL , &local_err); +if (ret <0 ) { + bs->open_flags |=BDRV_O_INACTIVE ; +error_propagate (errp, local_err); +return ; + } +bdrv_set_perm (bs, perm, shared_perm); + QLIST_FOREACH(parent, &bs->parents, next_parent) {if (parent->role->activate) { parent->role->activate (parent, &local_err);
@@ -4049,6 +4073,8 @@ static int bdrv_inactivate_recurse(BlockDriverState *bs, }if (setting_flag) { +uint64_t perm, shared_perm; + bs->open_flags |=BDRV_O_INACTIVE ; QLIST_FOREACH(parent, &bs->parents, next_parent) {
@@ -4060,6 +4086,11 @@ static int bdrv_inactivate_recurse(BlockDriverState *bs, } } } + +/* Update permissions, they may differ for inactive nodes */ +bdrv_get_cumulative_perm (bs, &perm, &shared_perm); +bdrv_check_perm (bs, perm, shared_perm,NULL , &error_abort); +bdrv_set_perm (bs, perm, shared_perm); } QLIST_FOREACH(child, &bs->children, next) {
include/block/block.h +1 -0
@@ -435,6 +435,7 @@ int bdrv_is_allocated_above(BlockDriverState *top, BlockDriverState *base, int64_t sector_num, int nb_sectors, int *pnum);bool bdrv_is_read_only (BlockDriverState *bs); +bool bdrv_is_writable (BlockDriverState *bs);int bdrv_can_set_read_only (BlockDriverState *bs,bool read_only,Error **errp);int bdrv_set_read_only (BlockDriverState *bs,bool read_only,Error **errp);bool bdrv_is_sg (BlockDriverState *bs);
Signature · 1 line
1.8.3.1
PATCH 6/6 file-posix: Remove .bdrv_inactivate/invalidate_cache
In reply to Kevin WolfNow that the block layer takes care to request a lot less permissions for inactive nodes, the special-casing in file-posix isn't necessary any more.
--- block/file-posix.c | 33 --------------------------------- 1 file changed, 33 deletions(-)
block/file-posix.c +0 -33
@@ -2190,35 +2190,6 @@ static void raw_abort_perm_update(BlockDriverState *bs)raw_handle_perm_lock (bs,RAW_PL_ABORT ,0 ,0 ,NULL ); } -static int raw_inactivate (BlockDriverState *bs) -{ -int ret; -uint64_t perm =0 ; -uint64_t shared =BLK_PERM_ALL ; - - ret =raw_handle_perm_lock (bs,RAW_PL_PREPARE , perm, shared,NULL ); -if (ret) { -return ret; - } -raw_handle_perm_lock (bs,RAW_PL_COMMIT , perm, shared,NULL ); -return 0 ; -} - - -static void raw_invalidate_cache (BlockDriverState *bs,Error **errp) -{ -BDRVRawState *s = bs->opaque; -int ret; - -assert (!(bdrv_get_flags (bs) &BDRV_O_INACTIVE )); - ret =raw_handle_perm_lock (bs,RAW_PL_PREPARE , s->perm, s->shared_perm, - errp); -if (ret) { -return ; - } -raw_handle_perm_lock (bs,RAW_PL_COMMIT , s->perm, s->shared_perm,NULL ); -} -BlockDriver bdrv_file = { .format_name ="file" , .protocol_name ="file" ,
@@ -2249,8 +2220,6 @@ BlockDriver bdrv_file = { .bdrv_get_info = raw_get_info, .bdrv_get_allocated_file_size = raw_get_allocated_file_size, - .bdrv_inactivate = raw_inactivate, - .bdrv_invalidate_cache = raw_invalidate_cache, .bdrv_check_perm = raw_check_perm, .bdrv_set_perm = raw_set_perm, .bdrv_abort_perm_update = raw_abort_perm_update,
@@ -2712,8 +2681,6 @@ static BlockDriver bdrv_host_device = { .bdrv_get_info = raw_get_info, .bdrv_get_allocated_file_size = raw_get_allocated_file_size, - .bdrv_inactivate = raw_inactivate, - .bdrv_invalidate_cache = raw_invalidate_cache, .bdrv_check_perm = raw_check_perm, .bdrv_set_perm = raw_set_perm, .bdrv_abort_perm_update = raw_abort_perm_update,
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH 1/6] migration: Unify block node activation error handling
In reply to Kevin WolfQuoted 10 lines · Kevin Wolf
Migration code activates all block driver nodes on the destination when the migration completes. It does so by calling
bdrv_invalidate_cache_all()andblk_resume_after_migration(). There is one code path for precopy and one for postcopy migration, resulting in four function calls, which used to have three different failure modes.This patch unifies the behaviour so that failure to activate all block nodes is non-fatal, but the error message is logged and the VM isn't automatically started. 'cont' will retry activating the block nodes.
Quoted 7 lines
Signed-off-by Kevin Wolf <[email protected]>--- migration/migration.c | 16 +++++----------- migration/savevm.c | 12 +++++------- qmp.c | 18 +++++++++--------- 3 files changed, 19 insertions(+), 27 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH 2/6] block: New BdrvChildRole.activate() for blk_resume_after_migration()
In reply to Kevin WolfQuoted 8 lines · Kevin Wolf
Instead of manually calling
blk_resume_after_migration()in migration code after doingbdrv_invalidate_cache_all(), integrate the BlockBackend activation with cache invalidation into a single function. This is achieved with a new callback in BdrvChildRole that is called bybdrv_invalidate_cache_all().Signed-off-by Kevin Wolf <[email protected]>---
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH 3/6] block: Drop permissions when migration completes
In reply to Kevin WolfQuoted 11 lines · Kevin Wolf
With image locking, permissions affect other qemu processes as well. We want to be sure that the destination can run, so let's drop permissions on the source when migration completes.
Signed-off-by Kevin Wolf <[email protected]>--- block.c | 12 +++++++++++- block/block-backend.c | 25 +++++++++++++++++++++++++ include/block/block_int.h | 7 ++++--- 3 files changed, 40 insertions(+), 4 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH 4/6] block: Inactivate parents before children
In reply to Kevin WolfQuoted 10 lines · Kevin Wolf
The proper order for inactivating block nodes is that first the parents get inactivated and then the children. If we do things in this order, we can assert that we didn't accidentally leave a parent activated when one of its child nodes is inactive.
Signed-off-by Kevin Wolf <[email protected]>--- block.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH 5/6] block: Fix write/resize permissions for inactive images
In reply to Kevin WolfQuoted 17 lines · Kevin Wolf
Format drivers for inactive nodes don't need write/resize permissions on their
bs->fileand can share write/resize with another VM (in fact, this is the whole point of keeping images inactive). Represent this fact in the op blocker system, so that image locking does the right thing without special-casing inactive images.Signed-off-by Kevin Wolf <[email protected]>--- block.c | 35 +++++++++++++++++++++++++++++++++-- include/block/block.h | 1 + 2 files changed, 34 insertions(+), 2 deletions(-)block.c +0
-0
block.c void path_combine(char *dest, int dest_size, · line 196
Quoted 5 lines
block.c +2
-0@@ -192,11 +192,20 @@ void path_combine(char *dest, int dest_size, } } +/* Returns whether the image file is opened as read-only. Note that this can +* return false and writing to the image file is still not possible because the
s/false and/false but/
s/is still not/still not be/
block.c void path_combine(char *dest, int dest_size, · line 207
Quoted 11 lines
block.c +6
-0+* image is inactivated. */ bool bdrv_is_read_only (BlockDriverState *bs) {return bs->read_only; } +/* Returns whether the image file can be written to right now */ +bool bdrv_is_writable (BlockDriverState *bs) +{ +return !bdrv_is_read_only (bs) && !(bs->open_flags &BDRV_O_INACTIVE ); +}
Nice.
Up to you if you think the grammar suggestion helps.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH 6/6] file-posix: Remove .bdrv_inactivate/invalidate_cache
In reply to Kevin WolfQuoted 9 lines · Kevin Wolf
Now that the block layer takes care to request a lot less permissions for inactive nodes, the special-casing in file-posix isn't necessary any more.
Signed-off-by Kevin Wolf <[email protected]>--- block/file-posix.c | 33 --------------------------------- 1 file changed, 33 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Kevin Wolf
AppliedAm 04.05.2017 um 18:52 hat Kevin Wolf geschrieben:
Quoted 7 lines
Fam's image locking series introduced some special-casing in the file-posix driver that avoids taking locks when the image is inactive. While this works, it really isn't the job of the file-posix driver, but the core block layer should consider that inactive nodes require a lot less permissions.
This series integrates op blockers with bdrv_inactivate/invalidate_cache() to solve this problem gennerically, and removes the workaround in file-posix.
Applied to the block branch.
Kevin
Re: [Qemu-devel] [PATCH 5/6] block: Fix write/resize permissions for inactive images
In reply to Kevin Wolfblock.c void path_combine(char *dest, int dest_size, · line 208
Quoted 7 lines · Kevin Wolf
block.c +6
-0+/* Returns whether the image file can be written to right now */ +bool bdrv_is_writable (BlockDriverState *bs) +{ +return !bdrv_is_read_only (bs) && !(bs->open_flags &BDRV_O_INACTIVE ); +} +
This commit use BDRV_O_INACTIVE to judge whether the image file can be written or not. But it blocks replication driver on the secondary node. For replication in secondary, we must ensure that the whole chain are writable:
|| || .---------- || | Secondary || '---------- || ||
virtio-blk
^
------> 3 NBD |
|| server 2 filter
|| ^ ^
|| | |
|| Secondary disk <--------- hidden-disk 5 <--------- active-disk 4
|| | backing ^ backing
|| | |
|| | |
|| '-------------------------'
|| drive-backup sync=none 6The root casue is when we run replication in secondary, vmstate changes to RUN_STATE_INMIGRATE, then blockdev_init() sets bdrv_flags |= BDRV_O_INACTIVE. So the whole chain become readonly. I've tried on my side, but it seems not easy to fix it. I wonder if there is any way to bypass this? Any suggestion would be appreciated.
It's very easy to reproduce this scenario:
(gdb) r
Starting program: /root/.xie/qemu-colo/x86_64-softmmu/qemu-system-x86_64 -boot c -m 2048 -smp 2 -qmp stdio -vnc :0 -name secondary -enable-kvm -cpu qemu64,+kvmclock -device piix3-usb-uhci -device usb-tablet -drive if=none,id=colo-disk,file.filename=/root/.xie/suse.qcow2.orgin,file.node-name=secondary_disk,driver=qcow2,node-name=sec-qcow2-driver-for-nbd -drive if=ide,id=active-disk0,node-name=active-disk111,throttling.bps-total=70000000,driver=replication,node-name=secondary-replication-driver,mode=secondary,top-id=active-disk0,file.driver=qcow2,file.node-name=active-qcow2-driver,file.file.filename=/mnt/ramfs/active_disk.img,file.file.node-name=active_disk,file.backing.driver=qcow2,file.backing.file.filename=/mnt/ramfs/hidden_disk.img,file.backing.node-name=hidden-qcow2-driver,file.backing.file.node-name=hidden_disk,file.backing.backing=colo-disk -incoming tcp:0:8888 [Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
[New Thread 0x7ffff4801700 (LWP 25252)]
[New Thread 0x7ffff4000700 (LWP 25255)]
qemu-system-x86_64: -drive if=ide,id=active-disk0,node-name=active-disk111,throttling.bps-total=70000000,driver=replication,node-name=secondary-replication-driver,mode=secondary,top-id=active-disk0,file.driver=qcow2,file.node-name=active-qcow2-driver,file.file.filename=/mnt/ramfs/active_disk.img,file.file.node-name=active_disk,file.backing.driver=qcow2,file.backing.file.filename=/mnt/ramfs/hidden_disk.img,file.backing.node-name=hidden-qcow2-driver,file.backing.file.node-name=hidden_disk,file.backing.backing=colo-disk: Block node is read-only
[Thread 0x7ffff4000700 (LWP 25255) exited]
[Thread 0x7ffff4801700 (LWP 25252) exited]
[Inferior 1 (process 25248) exited with code 01]
Missing separate debuginfos, use: debuginfo-install glib2-2.46.2-4.el7.x86_64 glibc-2.17-157.el7_3.4.x86_64 libacl-2.2.51-12.el7.x86_64 libattr-2.4.46-12.el7.x86_64 libgcc-4.8.5-11.el7.x86_64 libgcrypt-1.5.3-13.el7_3.1.x86_64 libgpg-error-1.12-3.el7.x86_64 libstdc++-4.8.5-11.el7.x86_64 libuuid-2.23.2-33.el7_3.2.x86_64 openssl-libs-1.0.1e-60.el7_3.1.x86_64 pixman-0.34.0-1.el7.x86_64 zlib-1.2.7-17.el7.x86_64
(gdb)
Signature · 2 lines
Thanks
-XieRe: [Qemu-devel] [PATCH 5/6] block: Fix write/resize permissions for inactive images
Quoted 5 lines · Xie Changlong
The root casue is when we run replication in secondary, vmstate changes to
RUN_STATE_INMIGRATE, thenblockdev_init()setsbdrv_flags|=BDRV_O_INACTIVE. So the whole chain become readonly. I've tried on my side, but it seems not easy to fix it. I wonder if there is any way to bypass this? Any suggestion would be appreciated.
The non-shared storage migration uses "nbd_server_add -w" at destinition side where BDRV_O_INACTIVE is set for images like your case, the way it handles it is by calling bdrv_invalidate_cache(). See nbd_export_new().
See also commit 3dff24f2dffc5f3aa46dc014122012848bd7959d.
I'm not sure if this is enough for block replication?
Fam