diff options
author | David Teigland <teigland@redhat.com> | 2020-02-13 13:03:13 -0600 |
---|---|---|
committer | David Teigland <teigland@redhat.com> | 2020-02-13 13:03:13 -0600 |
commit | 3ece8166aee9e934c077489ed17211cb91d035f7 (patch) | |
tree | 5d53938fc3ddaaa0ee2c64cb61b0aa012be28fa2 | |
parent | c81a1b6ffd6d62b64b35b4a61bdfe437c4250a4e (diff) | |
download | lvm2-3ece8166aee9e934c077489ed17211cb91d035f7.tar.gz |
integrity: handle adding new raid images
-rw-r--r-- | lib/integrity/integrity.c | 2 | ||||
-rw-r--r-- | lib/metadata/integrity_manip.c | 38 | ||||
-rw-r--r-- | lib/metadata/metadata-exported.h | 1 | ||||
-rw-r--r-- | tools/lvconvert.c | 24 |
4 files changed, 63 insertions, 2 deletions
diff --git a/lib/integrity/integrity.c b/lib/integrity/integrity.c index 3f23a36f3..ad44067f6 100644 --- a/lib/integrity/integrity.c +++ b/lib/integrity/integrity.c @@ -243,7 +243,7 @@ static int _target_present(struct cmd_context *cmd, if (!_integrity_checked) { _integrity_checked = 1; - _integrity_present = target_present(cmd, TARGET_NAME_INTEGRITY, 0); + _integrity_present = target_present(cmd, TARGET_NAME_INTEGRITY, 1); if (!target_version(TARGET_NAME_INTEGRITY, &maj, &min, &patchlevel)) return 0; diff --git a/lib/metadata/integrity_manip.c b/lib/metadata/integrity_manip.c index 02be6cb09..246c7446b 100644 --- a/lib/metadata/integrity_manip.c +++ b/lib/metadata/integrity_manip.c @@ -570,7 +570,7 @@ int lv_add_integrity_to_raid(struct logical_volume *lv, const char *arg, if (!seg_is_raid1(seg_top) && !seg_is_raid4(seg_top) && !seg_is_any_raid5(seg_top) && !seg_is_any_raid6(seg_top) && !seg_is_any_raid10(seg_top)) { - log_error("Integrity can only be added to raid1,4,5,6."); + log_error("Integrity can only be added to raid1,4,5,6,10."); return 0; } @@ -604,6 +604,14 @@ int lv_add_integrity_to_raid(struct logical_volume *lv, const char *arg, lv_image = seg_lv(seg_top, s); + /* + * This function is used to add integrity to new images added + * to the raid, in which case old images will already be + * integrity. + */ + if (seg_is_integrity(first_seg(lv_image))) + continue; + if (!seg_is_striped(first_seg(lv_image))) { log_error("raid image must be linear to add integrity"); goto_bad; @@ -656,6 +664,10 @@ int lv_add_integrity_to_raid(struct logical_volume *lv, const char *arg, for (s = 0; s < area_count; s++) { lv_image = seg_lv(seg_top, s); + /* Not adding integrity to this image. */ + if (!imeta_lvs[s]) + continue; + if (!(segtype = get_segtype_from_string(cmd, SEG_TYPE_NAME_INTEGRITY))) goto_bad; @@ -1206,3 +1218,27 @@ int lv_raid_has_integrity(struct logical_volume *lv) return 0; } + +int lv_get_raid_integrity_settings(struct logical_volume *lv, struct integrity_settings **isettings) +{ + struct logical_volume *lv_image; + struct lv_segment *seg, *seg_image; + uint32_t s; + + seg = first_seg(lv); + + if (seg_is_raid(seg)) { + for (s = 0; s < seg->area_count; s++) { + lv_image = seg_lv(seg, s); + seg_image = first_seg(lv_image); + + if (seg_is_integrity(seg_image)) { + *isettings = &seg_image->integrity_settings; + return 1; + } + } + } + + return 0; +} + diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h index 03bdb7fb0..9f2c7f306 100644 --- a/lib/metadata/metadata-exported.h +++ b/lib/metadata/metadata-exported.h @@ -1424,5 +1424,6 @@ int lv_extend_integrity_in_raid(struct logical_volume *lv, struct dm_list *pvh, const char *meta_name); int lv_extend_integrity_for_origin(struct logical_volume *lv_iorig, struct dm_list *pvh, const char *meta_name); +int lv_get_raid_integrity_settings(struct logical_volume *lv, struct integrity_settings **isettings); #endif diff --git a/tools/lvconvert.c b/tools/lvconvert.c index 9587ed415..afb44062c 100644 --- a/tools/lvconvert.c +++ b/tools/lvconvert.c @@ -1396,6 +1396,14 @@ static int _lvconvert_raid(struct logical_volume *lv, struct lvconvert_params *l lp->region_size : seg->region_size , lp->pvh)) return_0; + if (lv_raid_has_integrity(lv)) { + struct integrity_settings *isettings = NULL; + if (!lv_get_raid_integrity_settings(lv, &isettings)) + return_0; + if (!lv_add_integrity_to_raid(lv, "external", NULL, isettings, lp->pvh)) + return_0; + } + log_print_unless_silent("Logical volume %s successfully converted.", display_lvname(lv)); @@ -1438,6 +1446,14 @@ static int _lvconvert_raid(struct logical_volume *lv, struct lvconvert_params *l lp->region_size, lp->pvh)) return_0; + if (lv_raid_has_integrity(lv)) { + struct integrity_settings *isettings = NULL; + if (!lv_get_raid_integrity_settings(lv, &isettings)) + return_0; + if (!lv_add_integrity_to_raid(lv, "external", NULL, isettings, lp->pvh)) + return_0; + } + log_print_unless_silent("Logical volume %s successfully converted.", display_lvname(lv)); return 1; @@ -1459,6 +1475,14 @@ try_new_takeover_or_reshape: lp->region_size : seg->region_size , lp->pvh)) return_0; + if (lv_raid_has_integrity(lv)) { + struct integrity_settings *isettings = NULL; + if (!lv_get_raid_integrity_settings(lv, &isettings)) + return_0; + if (!lv_add_integrity_to_raid(lv, "external", NULL, isettings, lp->pvh)) + return_0; + } + log_print_unless_silent("Logical volume %s successfully converted.", display_lvname(lv)); return 1; |