libdm-deptree-return-failure-activate-and-preload-children
PATCH 1/5 libdm-deptree-return-failure-activate-and-preload-children
Return error immediately to dm_tree_preload_children() and dm_tree_activate_children() callers.
Otherwise resume_lv and its variants can fail silently.
Catching these failures is especially important now that dm targets like crypt and snapshot-merge can fail in .preresume
--- libdm/libdm-deptree.c | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-)
libdm/libdm-deptree.c +6 -4
@@ -1158,7 +1158,8 @@ int dm_tree_activate_children(struct dm_tree_node *dnode,continue ;if (dm_tree_node_num_children (child,0 )) -dm_tree_activate_children (child, uuid_prefix, uuid_prefix_len); +if (!dm_tree_activate_children (child, uuid_prefix, uuid_prefix_len)) + return_0; } handle =NULL ;
@@ -1204,7 +1205,7 @@ int dm_tree_activate_children(struct dm_tree_node *dnode,log_error ("Unable to resume %s (%" PRIu32":%" PRIu32")" , child->name, child->info.major, child->info.minor); -continue ; +return 0 ; }/* Update cached info */
@@ -1621,7 +1622,8 @@ int dm_tree_preload_children(struct dm_tree_node *dnode,continue ;if (dm_tree_node_num_children (child,0 )) -dm_tree_preload_children (child, uuid_prefix, uuid_prefix_len); +if (!dm_tree_preload_children (child, uuid_prefix, uuid_prefix_len)) + return_0;/* FIXME Cope if name exists with no uuid? */ if (!child->info.exists) {
@@ -1655,7 +1657,7 @@ int dm_tree_preload_children(struct dm_tree_node *dnode,log_error ("Unable to resume %s (%" PRIu32":%" PRIu32")" , child->name, child->info.major, child->info.minor); -continue ; +return 0 ; }/* Update cached info */
Signature · 1 line
1.6.5.2
PATCH 2/5 libdm-deptree-return-failure-suspend-children
Return error immediately to dm_tree_suspend_children() callers.
Otherwise suspend_lv and its variants can fail silently.
--- libdm/libdm-deptree.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
libdm/libdm-deptree.c +3 -2
@@ -1109,7 +1109,7 @@ int dm_tree_suspend_children(struct dm_tree_node *dnode,log_error ("Unable to suspend %s (%" PRIu32":%" PRIu32")" , name, info.major, info.minor); -continue ; +return 0 ; }/* Update cached info */
@@ -1130,7 +1130,8 @@ int dm_tree_suspend_children(struct dm_tree_node *dnode,continue ;if (dm_tree_node_num_children (child,0 )) -dm_tree_suspend_children (child, uuid_prefix, uuid_prefix_len); +if (!dm_tree_suspend_children (child, uuid_prefix, uuid_prefix_len)) + return_0; }return 1 ;
Signature · 1 line
1.6.5.2
PATCH 2/5 libdm-deptree-return-failure-suspend-children
Dne 20.11.2009 22:29, Mike Snitzer napsal(a):
Quoted 14 lines
Return error immediately to
dm_tree_suspend_children()callers.Otherwise
suspend_lvand its variants can fail silently.Signed-off-by Mike Snitzer <[email protected]>--- libdm/libdm-deptree.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)libdm/libdm-deptree.c +0
-0
libdm/libdm-deptree.c int dm_tree_suspend_children(struct dm_tree_node *dnode, · line 1113
Quoted 6 lines
libdm/libdm-deptree.c +1
-1@@ -1109,7 +1109,7 @@ int dm_tree_suspend_children(struct dm_tree_node *dnode,log_error ("Unable to suspend %s (%" PRIu32":%" PRIu32")" , name, info.major, info.minor); -continue ; +return 0 ; }
This is a bit hard to tell what's the right way here - either to continue suspending 'the rest of the monster' or to stop with the first failure.
In case of the replicator - when suspend of one head would fail - I would probably prefer to see the code to continue suspending remaing heads.
Zdenek
Quoted 12 lines
libdm/libdm-deptree.c +2
-1/* Update cached info */ @@ -1130,7 +1130,8 @@ int dm_tree_suspend_children(struct dm_tree_node *dnode,continue ;if (dm_tree_node_num_children (child,0 )) -dm_tree_suspend_children (child, uuid_prefix, uuid_prefix_len); +if (!dm_tree_suspend_children (child, uuid_prefix, uuid_prefix_len)) + return_0; }return 1 ;
Re: [PATCH 2/5] libdm-deptree-return-failure-suspend-children
Quoted 26 lines · Zdenek Kabelac
Dne 20.11.2009 22:29, Mike Snitzer napsal(a):
Quoted 14 lines
Return error immediately to
dm_tree_suspend_children()callers.Otherwise
suspend_lvand its variants can fail silently.Signed-off-by Mike Snitzer <[email protected]>--- libdm/libdm-deptree.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)libdm/libdm-deptree.c +0
-0libdm/libdm-deptree.c int dm_tree_suspend_children(struct dm_tree_node *dnode, · line 1113
Quoted 6 lines
libdm/libdm-deptree.c +1
-1@@ -1109,7 +1109,7 @@ int dm_tree_suspend_children(struct dm_tree_node *dnode,log_error ("Unable to suspend %s (%" PRIu32":%" PRIu32")" , name, info.major, info.minor); -continue ; +return 0 ; }This is a bit hard to tell what's the right way here - either to continue suspending 'the rest of the monster' or to stop with the first failure.
Quoted 2 lines
In case of the replicator - when suspend of one head would fail - I would probably prefer to see the code to continue suspending remaing heads.
OK, the other possibility that Alasdair and I discussed is that we could return failure once all nodes at the same level have been processed.
Would that work for replicator? Are all heads at the same level in the tree?
Mike
Re: [PATCH 2/5] libdm-deptree-return-failure-suspend-children
Dne 21.11.2009 03:26, Mike Snitzer napsal(a):
Quoted 29 lines
Quoted 26 lines · Zdenek Kabelac
Dne 20.11.2009 22:29, Mike Snitzer napsal(a):
Quoted 14 lines
Return error immediately to
dm_tree_suspend_children()callers.Otherwise
suspend_lvand its variants can fail silently.Signed-off-by Mike Snitzer <[email protected]>--- libdm/libdm-deptree.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)libdm/libdm-deptree.c +0
-0libdm/libdm-deptree.c int dm_tree_suspend_children(struct dm_tree_node *dnode, · line 1113
Quoted 6 lines
libdm/libdm-deptree.c +1
-1@@ -1109,7 +1109,7 @@ int dm_tree_suspend_children(struct dm_tree_node *dnode,log_error ("Unable to suspend %s (%" PRIu32":%" PRIu32")" , name, info.major, info.minor); -continue ; +return 0 ; }This is a bit hard to tell what's the right way here - either to continue suspending 'the rest of the monster' or to stop with the first failure.
Quoted 7 lines
Quoted 2 lines
In case of the replicator - when suspend of one head would fail - I would probably prefer to see the code to continue suspending remaing heads.
OK, the other possibility that Alasdair and I discussed is that we could return failure once all nodes at the same level have been processed.
Would that work for replicator? Are all heads at the same level in the tree?
Yes - that would probably work well for replicator (though the error in the suspend as rather hypothetical in this case anyway)
But - still - is it the best thing to stop suspending elements from tree - if one path fails?
Zdenek
PATCH 3/5 libdm-deptree-return-failure-deactivate-children
In reply to Mike SnitzerReturn error immediately to dm_tree_deactivate_children() callers.
Otherwise deactivate_lv can fail silently.
--- libdm/libdm-deptree.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
libdm/libdm-deptree.c +3 -2
@@ -1043,11 +1043,12 @@ int dm_tree_deactivate_children(struct dm_tree_node *dnode,log_error ("Unable to deactivate %s (%" PRIu32":%" PRIu32")" , name, info.major, info.minor); -continue ; +return 0 ; }if (dm_tree_node_num_children (child,0 )) -dm_tree_deactivate_children (child, uuid_prefix, uuid_prefix_len); +if (!dm_tree_deactivate_children (child, uuid_prefix, uuid_prefix_len)) + return_0; }return 1 ;
Signature · 1 line
1.6.5.2
PATCH 4/5 lvm-stack-on-resume-and-suspend-failures
In reply to Mike SnitzerAdd missing 'stack;' for all suspend_lv and resume_lv callers.
--- lib/locking/locking.c | 6 ++++-- lib/metadata/lv_manip.c | 3 ++- lib/metadata/mirror.c | 5 +++-- tools/lvchange.c | 6 ++++-- tools/lvconvert.c | 3 ++- tools/lvresize.c | 3 ++- tools/pvmove.c | 21 ++++++++++++++------- tools/toollib.c | 13 ++++++++++++- 8 files changed, 43 insertions(+), 17 deletions(-)
lib/locking/locking.c +4 -2
@@ -439,7 +439,8 @@ int resume_lvs(struct cmd_context *cmd, struct dm_list *lvs)struct lv_list *lvl; dm_list_iterate_items(lvl, lvs) -resume_lv (cmd, lvl->lv); +if (!resume_lv (cmd, lvl->lv)) + stack;return 1 ; }
@@ -455,7 +456,8 @@ int suspend_lvs(struct cmd_context *cmd, struct dm_list *lvs)log_error ("Failed to suspend %s" , lvl->lv->name); dm_list_uniterate(lvh, lvs, &lvl->list) { lvl = dm_list_item(lvh, struct lv_list); -resume_lv (cmd, lvl->lv); +if (!resume_lv (cmd, lvl->lv)) + stack; }return 0 ;
lib/metadata/lv_manip.c +2 -1
@@ -1822,7 +1822,8 @@ int lv_rename(struct cmd_context *cmd, struct logical_volume *lv,if (!(r =vg_commit (vg))) stack; -resume_lvs (cmd, &lvs_changed); +if (!resume_lvs (cmd, &lvs_changed)) + stack; out:backup (vg);return r;
lib/metadata/mirror.c +3 -2
@@ -596,8 +596,9 @@ static int _remove_mirror_images(struct logical_volume *lv, }if (!vg_commit (mirrored_seg->lv->vg)) { -resume_lv (mirrored_seg->lv->vg->cmd, mirrored_seg->lv); -return 0 ; +if (!resume_lv (mirrored_seg->lv->vg->cmd, mirrored_seg->lv)) + stack; + return_0; }log_very_verbose ("Updating \"%s\" in kernel" , mirrored_seg->lv->name);
tools/lvchange.c +4 -2
@@ -64,7 +64,8 @@ static int lvchange_permission(struct cmd_context *cmd, }if (!vg_commit (lv->vg)) { -resume_lv (cmd, lv); +if (!resume_lv (cmd, lv)) + stack; goto_out; }
@@ -385,7 +386,8 @@ static int lvchange_readahead(struct cmd_context *cmd, }if (!vg_commit (lv->vg)) { -resume_lv (cmd, lv); +if (!resume_lv (cmd, lv)) + stack; goto_out; }
tools/lvconvert.c +2 -1
@@ -790,7 +790,8 @@ static int _lvconvert_mirrors(struct cmd_context *cmd, struct logical_volume *lv }if (!vg_commit (lv->vg)) { -resume_lv (cmd, lv); +if (!resume_lv (cmd, lv)) + stack; goto_out; }
tools/lvresize.c +2 -1
@@ -638,7 +638,8 @@ static int _lvresize(struct cmd_context *cmd, struct volume_group *vg,if (!vg_commit (vg)) { stack; -resume_lv (cmd, lock_lv); +if (!resume_lv (cmd, lock_lv)) + stack;backup (vg);return ECMD_FAILED ; }
tools/pvmove.c +14 -7
@@ -292,7 +292,8 @@ static int _update_metadata(struct cmd_context *cmd, struct volume_group *vg,/* Suspend mirrors on subsequent calls */ if (!first_time) {if (!suspend_lv (cmd, lv_mirr)) { -resume_lvs (cmd, lvs_changed); +if (!resume_lvs (cmd, lvs_changed)) + stack;vg_revert (vg); goto_out; }
@@ -302,8 +303,10 @@ static int _update_metadata(struct cmd_context *cmd, struct volume_group *vg,if (!vg_commit (vg)) {log_error ("ABORTING: Volume group metadata update failed." );if (!first_time) -resume_lv (cmd, lv_mirr); -resume_lvs (cmd, lvs_changed); +if (!resume_lv (cmd, lv_mirr)) + stack; +if (!resume_lvs (cmd, lvs_changed)) + stack; goto out; }
@@ -327,7 +330,8 @@ static int _update_metadata(struct cmd_context *cmd, struct volume_group *vg, }else if (!resume_lv (cmd, lv_mirr)) {log_error ("Unable to reactivate logical volume \"%s\"" , lv_mirr->name); -resume_lvs (cmd, lvs_changed); +if (!resume_lvs (cmd, lvs_changed)) + stack; goto out; }
@@ -501,8 +505,10 @@ static int _finish_pvmove(struct cmd_context *cmd, struct volume_group *vg,log_error ("ABORTING: Failed to write new data locations " "to disk." );vg_revert (vg); -resume_lv (cmd, lv_mirr); -resume_lvs (cmd, lvs_changed); +if (!resume_lv (cmd, lv_mirr)) + stack; +if (!resume_lvs (cmd, lvs_changed)) + stack;return 0 ; }
@@ -514,7 +520,8 @@ static int _finish_pvmove(struct cmd_context *cmd, struct volume_group *vg, }/* Unsuspend LVs */ -resume_lvs (cmd, lvs_changed); +if (!resume_lvs (cmd, lvs_changed)) + stack;/* Deactivate mirror LV */ if (!deactivate_lv (cmd, lv_mirr)) {
tools/toollib.c +12 -1
@@ -1252,7 +1252,18 @@ int vgcreate_params_set_from_args(struct cmd_context *cmd,int lv_refresh (struct cmd_context *cmd,struct logical_volume *lv) { -return suspend_lv (cmd, lv) &&resume_lv (cmd, lv); +int r =0 ; + + r =suspend_lv (cmd, lv); +if (!r) + goto_out; + + r =resume_lv (cmd, lv); +if (!r) + goto_out; + +out: +return r; }int vg_refresh_visible (struct cmd_context *cmd,struct volume_group *vg)
Signature · 1 line
1.6.5.2
PATCH 4/5 lvm-stack-on-resume-and-suspend-failures
Dne 20.11.2009 22:29, Mike Snitzer napsal(a):
Quoted 2 lines
Add missing 'stack;' for all
suspend_lvandresume_lvcallers.
How about using some macro like:
#define test_stack(a...) \
do { \
if (!a) \
stack; \
} while(0);Well the name is randomly picked - but it could make code more compact and readable ?
Zdenek
Quoted 12 lines
Signed-off-by Mike Snitzer <[email protected]>--- lib/locking/locking.c | 6 ++++-- lib/metadata/lv_manip.c | 3 ++- lib/metadata/mirror.c | 5 +++-- tools/lvchange.c | 6 ++++-- tools/lvconvert.c | 3 ++- tools/lvresize.c | 3 ++- tools/pvmove.c | 21 ++++++++++++++------- tools/toollib.c | 13 ++++++++++++- 8 files changed, 43 insertions(+), 17 deletions(-)
PATCH 5/5 lvm-stack-on-activate-and-deactivate-failures
In reply to Mike SnitzerAdd missing 'stack;' for all activate_lv and deactivate_lv callers.
--- lib/activate/activate.c | 3 ++- lib/locking/locking.c | 3 ++- tools/pvmove.c | 11 +++++++++-- tools/vgchange.c | 20 +++++++++++++++----- 4 files changed, 28 insertions(+), 9 deletions(-)
lib/activate/activate.c +2 -1
@@ -710,7 +710,8 @@ int lv_is_active(struct logical_volume *lv)* FIXME: check status to not deactivate already activate device */ if (activate_lv_excl (lv->vg->cmd, lv)) { -deactivate_lv (lv->vg->cmd, lv); +if (!deactivate_lv (lv->vg->cmd, lv)) + stack;return 0 ; }
lib/locking/locking.c +2 -1
@@ -483,7 +483,8 @@ int activate_lvs(struct cmd_context *cmd, struct dm_list *lvs, unsigned exclusivlog_error ("Failed to activate %s" , lvl->lv->name); dm_list_uniterate(lvh, lvs, &lvl->list) { lvl = dm_list_item(lvh, struct lv_list); -activate_lv (cmd, lvl->lv); +if (!activate_lv (cmd, lvl->lv)) + stack; }return 0 ; }
tools/pvmove.c +9 -2
@@ -261,10 +261,17 @@ static struct logical_volume *_set_up_pvmove_lv(struct cmd_context *cmd,static int _activate_lv (struct cmd_context *cmd,struct logical_volume *lv_mirr,unsigned exclusive) { +int r =0 ; +if (exclusive) -return activate_lv_excl (cmd, lv_mirr); + r =activate_lv_excl (cmd, lv_mirr); +else + r =activate_lv (cmd, lv_mirr); -return activate_lv (cmd, lv_mirr); +if (!r) + stack; + +return r; } static int _finish_pvmove(struct cmd_context *cmd, struct volume_group *vg,
tools/vgchange.c +15 -5
@@ -79,19 +79,29 @@ static int _activate_lvs_in_vg(struct cmd_context *cmd,continue ;if (activate ==CHANGE_AN ) { -if (!deactivate_lv (cmd, lv)) +if (!deactivate_lv (cmd, lv)) { + stack;continue ; + } }else if (activate ==CHANGE_ALN ) { -if (!deactivate_lv_local (cmd, lv)) +if (!deactivate_lv_local (cmd, lv)) { + stack;continue ; + } }else if (lv_is_origin (lv) || (activate ==CHANGE_AE )) { -if (!activate_lv_excl (cmd, lv)) +if (!activate_lv_excl (cmd, lv)) { + stack;continue ; + } }else if (activate ==CHANGE_ALY ) { -if (!activate_lv_local (cmd, lv)) +if (!activate_lv_local (cmd, lv)) { + stack;continue ; - }else if (!activate_lv (cmd, lv)) + } + }else if (!activate_lv (cmd, lv)) { + stack;continue ; + }if (activate !=CHANGE_AN && activate !=CHANGE_ALN && (lv->status & (PVMOVE |CONVERTING )))
Signature · 1 line
1.6.5.2
PATCH 1/5 libdm-deptree-return-failure-activate-and-preload-children
In reply to Mike SnitzerDne 20.11.2009 22:29, Mike Snitzer napsal(a):
Quoted 8 lines
Return error immediately to
dm_tree_preload_children()anddm_tree_activate_children()callers.Otherwise
resume_lvand its variants can fail silently.Catching these failures is especially important now that dm targets like crypt and snapshot-merge can fail in .preresume
Similar case applies for replicator - and I'm using similar code in my own patch set.
So it's definitely needed.
Ack
Quoted 22 lines
Signed-off-by Mike Snitzer <[email protected]>--- libdm/libdm-deptree.c | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-)libdm/libdm-deptree.c +2
-1@@ -1158,7 +1158,8 @@ int dm_tree_activate_children(struct dm_tree_node *dnode,continue ;if (dm_tree_node_num_children (child,0 )) -dm_tree_activate_children (child, uuid_prefix, uuid_prefix_len); +if (!dm_tree_activate_children (child, uuid_prefix, uuid_prefix_len)) + return_0; } handle =NULL ;@@ -1204,7 +1205,7 @@ int dm_tree_activate_children(struct dm_tree_node *dnode, log_error("Unable to resume %s (%" PRIu32 ":%" PRIu32 ")", child->name, child->info.major,