master - raid: fix (de)activation of RaidLVs with visible SubLVs
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=dd5716ddf258c4a44819fa90d3356833ccf767b4 Commit: dd5716ddf258c4a44819fa90d3356833ccf767b4 Parent: b2d1facd960e192b38ae4a9866f3bea9646e6cd5 Author: Heinz Mauelshagen <[email protected]> AuthorDate: Wed Oct 31 23:05:08 2018 +0100 Committer: Heinz Mauelshagen <[email protected]> CommitterDate: Tue Dec 11 16:35:34 2018 +0100
raid: fix (de)activation of RaidLVs with visible SubLVs
There's a small window during creation of a new RaidLV when rmeta SubLVs are made visible to wipe them in order to prevent erroneous discovery of stale RAID metadata. In case a crash prevents the SubLVs from being committed hidden after such wiping, the RaidLV can still be activated with the SubLVs visible. During deactivation though, a deadlock occurs because the visible SubLVs are deactivated before the RaidLV.
The patch adds _check_raid_sublvs to the raid validation in merge.c, an activation check to activate.c (paranoid, because the merge.c check will prevent activation in case of visible SubLVs) and shares the existing wiping function _clear_lvs in raid_manip.c moved to lv_manip.c and renamed to activate_and_wipe_lvlist to remove code duplication. Whilst on it, introduce activate_and_wipe_lv to share with (lvconvert|lvchange).c.
Resolves: rhbz1633167
--- WHATS_NEW | 1 + lib/activate/activate.c | 6 + lib/metadata/lv_manip.c | 190 ++++++++++++++++++++++++++++---------- lib/metadata/merge.c | 30 ++++++ lib/metadata/metadata-exported.h | 8 ++ lib/metadata/raid_manip.c | 91 ++++-------------- tools/lvchange.c | 32 +------ tools/lvconvert.c | 20 +--- 8 files changed, 213 insertions(+), 165 deletions(-)
WHATS_NEW +1 -0
@@ -1,5 +1,6 @@ Version 2.03.02 - =================================== + Fix (de)activation of RaidLVs with visible SubLVs Prohibit mirrored 'mirror' log via lvcreate and lvconvert Use sync io if async io_setup fails, or use_aio=0 is set in config.
lib/activate/activate.c +6 -0
@@ -2532,6 +2532,12 @@ static int _lv_activate(struct cmd_context *cmd, const char *lvid_s, goto out; } +if (lv_raid_has_visible_sublvs (lv)) { +log_error ("Refusing activation of RAID LV %s with " +"visible SubLVs." ,display_lvname (lv)); + goto out; + } +if (test_mode ()) {_skip ("Activating %s." ,display_lvname (lv)); r =1 ;
lib/metadata/lv_manip.c +139 -51
232 lines not on this page · raw message
lib/metadata/merge.c +30 -0
@@ -234,6 +234,30 @@ static void _check_non_raid_seg_members(struct lv_segment *seg, int *error_count/* .... more members? */ } +static void _check_raid_sublvs (struct lv_segment *seg,int *error_count) +{ +unsigned s; + +for (s =0 ; s < seg->area_count; s++) { +if (seg_type (seg, s) !=AREA_LV ) +raid_seg_error ("no raid image SubLV" ); + +if ((seg_lv (seg, s)->status &LVM_WRITE ) && + !(seg->lv->status &LV_ACTIVATION_SKIP ) && +lv_is_visible (seg_lv (seg, s))) +raid_seg_error ("visible raid image LV" ); + +if (!seg_is_raid_with_meta (seg) || !seg->meta_areas) +continue ; + +if (seg_metatype (seg, s) !=AREA_LV ) +raid_seg_error ("no raid meta SubLV" ); +else if (!(seg->lv->status &LV_ACTIVATION_SKIP ) && +lv_is_visible (seg_metalv (seg, s))) +raid_seg_error ("visible raid meta LV" ); + } +} +/* * Check RAID segment struct members of @seg for acceptable * properties and increment @error_count for any bogus ones.
@@ -287,10 +311,14 @@ static void _check_raid_seg(struct lv_segment *seg, int *error_count)/* Check for any MetaLV flaws like non-existing ones or size variations */ if (seg->meta_areas)for (area_len = s =0 ; s < seg->area_count; s++) { +if (seg_metatype (seg, s) ==AREA_UNASSIGNED ) +continue ; +if (seg_metatype (seg, s) !=AREA_LV ) {raid_seg_error ("no MetaLV" );continue ; } +if (!lv_is_raid_metadata (seg_metalv (seg, s)))raid_seg_error ("MetaLV without RAID metadata flag" ); if (area_len &&
@@ -314,6 +342,8 @@ static void _check_raid_seg(struct lv_segment *seg, int *error_count)_check_raid45610_seg (seg, error_count); else raid_seg_error("bogus RAID segment type"); + +_check_raid_sublvs (seg, error_count); }/* END: RAID segment property checks. */
lib/metadata/metadata-exported.h +8 -0
@@ -800,6 +800,12 @@ struct wipe_params {/* Zero out LV and/or wipe signatures */ int wipe_lv (struct logical_volume *lv,struct wipe_params params); +/* Wipe any signatures and zero first sector on @lv */ +int activate_and_wipe_lv (struct logical_volume *lv,int commit); + +/* Wipe any signatures and zero first sector of LVs listed on @lv_list */ +int activate_and_wipe_lvlist (struct dm_list *lv_list,int commit); +int lv_change_tag (struct logical_volume *lv,const char *tag,int add_tag);/* Reduce the size of an LV by extents */
@@ -1221,6 +1227,8 @@ int lv_raid_change_region_size(struct logical_volume *lv,int lv_raid_in_sync (const struct logical_volume *lv);uint32_t lv_raid_data_copies (const struct segment_type *segtype,uint32_t area_count);int lv_raid_free_reshape_space (const struct logical_volume *lv); +int lv_raid_clear_lv (struct logical_volume *lv,int commit); +int lv_raid_has_visible_sublvs (const struct logical_volume *lv);/* -- metadata/raid_manip.c */ /* ++ metadata/cache_manip.c */
lib/metadata/raid_manip.c +19 -72
105 lines not on this page · raw message
tools/lvchange.c +5 -27
@@ -311,7 +311,6 @@ static int _lvchange_resync(struct cmd_context *cmd, struct logical_volume *lv)int monitored;struct lv_segment *seg =first_seg (lv);struct dm_list device_list; -struct lv_list *lvl;dm_list_init (&device_list);
@@ -389,6 +388,7 @@ static int _lvchange_resync(struct cmd_context *cmd, struct logical_volume *lv)* Now we handle mirrors with log devices */ lv->status &= ~LV_NOTSYNCED ; + lv->status |=LV_ACTIVATION_SKIP ;/* Separate mirror log or metadata devices so we can clear them */ if (!_detach_metadata_devices (seg, &device_list)) {
@@ -407,32 +407,8 @@ static int _lvchange_resync(struct cmd_context *cmd, struct logical_volume *lv)/* No backup for intermediate metadata, so just unlock memory */ memlock_unlock (lv->vg->cmd); - dm_list_iterate_items(lvl, &device_list) { -if (!activate_lv (cmd, lvl->lv)) { -log_error ("Unable to activate %s for %s clearing." , -display_lvname (lvl->lv), (seg_is_raid (seg)) ? -"metadata area" :"mirror log" ); -return 0 ; - } - -if (!wipe_lv (lvl->lv, (struct wipe_params ) - { .do_zero =1 , .zero_sectors = lvl->lv->size })) { -log_error ("Unable to reset sync status for %s." , -display_lvname (lv)); -if (!deactivate_lv (cmd, lvl->lv)) -log_error ("Failed to deactivate log LV after " -"wiping failed" ); -return 0 ; - } - -if (!deactivate_lv (cmd, lvl->lv)) { -log_error ("Unable to deactivate %s LV %s " -"after wiping for resync." , - (seg_is_raid (seg)) ?"metadata" :"log" , -display_lvname (lvl->lv)); -return 0 ; - } - } +if (!activate_and_wipe_lvlist (&device_list,0 )) +return 0 ;/* Wait until devices are away */ if (!sync_local_dev_names (lv->vg->cmd)) {
@@ -448,6 +424,8 @@ static int _lvchange_resync(struct cmd_context *cmd, struct logical_volume *lv)return 0 ; } + lv->status &= ~LV_ACTIVATION_SKIP ; +if (!_vg_write_commit (lv,NULL ))return 0 ;
tools/lvconvert.c +5 -15
@@ -1992,19 +1992,9 @@ static int _lvconvert_snapshot(struct cmd_context *cmd,if (!zero || !(lv->status &LVM_WRITE ))log_warn ("WARNING: %s not zeroed." , snap_name); -else { - lv->status |=LV_TEMPORARY ; -if (!activate_lv (cmd, lv) || - !wipe_lv (lv, (struct wipe_params ) { .do_zero =1 })) { -log_error ("Aborting. Failed to wipe snapshot exception store." ); -return 0 ; - } - lv->status &= ~LV_TEMPORARY ; -/* Deactivates cleared metadata LV */ -if (!deactivate_lv (lv->vg->cmd, lv)) { -log_error ("Failed to deactivate zeroed snapshot exception store." ); -return 0 ; - } +else if (!activate_and_wipe_lv (lv,0 )) { +log_error ("Aborting. Failed to wipe snapshot exception store." ); +return 0 ; }if (!archive (lv->vg))
@@ -3160,12 +3150,12 @@ static int _lvconvert_to_pool(struct cmd_context *cmd, goto_bad;if (zero_metadata) { - metadata_lv->status |=LV_TEMPORARY ; + metadata_lv->status |=LV_ACTIVATION_SKIP ;if (!activate_lv (cmd, metadata_lv)) {log_error ("Aborting. Failed to activate metadata lv." ); goto bad; } - metadata_lv->status &= ~LV_TEMPORARY ; + metadata_lv->status &= ~LV_ACTIVATION_SKIP ;if (!wipe_lv (metadata_lv, (struct wipe_params ) { .do_zero =1 })) {log_error ("Aborting. Failed to wipe metadata lv." );