diff options
author | David Teigland <teigland@redhat.com> | 2019-11-20 16:07:27 -0600 |
---|---|---|
committer | David Teigland <teigland@redhat.com> | 2020-04-15 12:10:32 -0500 |
commit | d9e8895a96539d75166c0f74e58f5ed4e729e551 (patch) | |
tree | 31a570fa5dfee258072f553af32cd66988eb16a8 /tools/toollib.c | |
parent | b6b4ad8e28eff7476cb04c4cb93312b06605b82f (diff) | |
download | lvm2-d9e8895a96539d75166c0f74e58f5ed4e729e551.tar.gz |
Allow dm-integrity to be used for raid images
dm-integrity stores checksums of the data written to an
LV, and returns an error if data read from the LV does
not match the previously saved checksum. When used on
raid images, dm-raid will correct the error by reading
the block from another image, and the device user sees
no error. The integrity metadata (checksums) are stored
on an internal LV allocated by lvm for each linear image.
The internal LV is allocated on the same PV as the image.
Create a raid LV with an integrity layer over each
raid image (for raid levels 1,4,5,6,10):
lvcreate --type raidN --raidintegrity y [options]
Add an integrity layer to images of an existing raid LV:
lvconvert --raidintegrity y LV
Remove the integrity layer from images of a raid LV:
lvconvert --raidintegrity n LV
Settings
Use --raidintegritymode journal|bitmap (journal is default)
to configure the method used by dm-integrity to ensure
crash consistency.
Initialization
When integrity is added to an LV, the kernel needs to
initialize the integrity metadata/checksums for all blocks
in the LV. The data corruption checking performed by
dm-integrity will only operate on areas of the LV that
are already initialized. The progress of integrity
initialization is reported by the "syncpercent" LV
reporting field (and under the Cpy%Sync lvs column.)
Example: create a raid1 LV with integrity:
$ lvcreate --type raid1 -m1 --raidintegrity y -n rr -L1G foo
Creating integrity metadata LV rr_rimage_0_imeta with size 12.00 MiB.
Logical volume "rr_rimage_0_imeta" created.
Creating integrity metadata LV rr_rimage_1_imeta with size 12.00 MiB.
Logical volume "rr_rimage_1_imeta" created.
Logical volume "rr" created.
$ lvs -a foo
LV VG Attr LSize Origin Cpy%Sync
rr foo rwi-a-r--- 1.00g 4.93
[rr_rimage_0] foo gwi-aor--- 1.00g [rr_rimage_0_iorig] 41.02
[rr_rimage_0_imeta] foo ewi-ao---- 12.00m
[rr_rimage_0_iorig] foo -wi-ao---- 1.00g
[rr_rimage_1] foo gwi-aor--- 1.00g [rr_rimage_1_iorig] 39.45
[rr_rimage_1_imeta] foo ewi-ao---- 12.00m
[rr_rimage_1_iorig] foo -wi-ao---- 1.00g
[rr_rmeta_0] foo ewi-aor--- 4.00m
[rr_rmeta_1] foo ewi-aor--- 4.00m
Diffstat (limited to 'tools/toollib.c')
-rw-r--r-- | tools/toollib.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/tools/toollib.c b/tools/toollib.c index 6386a6906..96d0d6dff 100644 --- a/tools/toollib.c +++ b/tools/toollib.c @@ -718,11 +718,26 @@ int vgcreate_params_set_from_args(struct cmd_context *cmd, return 1; } +int integrity_mode_set(const char *mode, struct integrity_settings *settings) +{ + if (!mode || !strcmp(mode, "bitmap") || !strcmp(mode, "B")) + settings->mode[0] = 'B'; + else if (!strcmp(mode, "journal") || !strcmp(mode, "J")) + settings->mode[0] = 'J'; + else { + /* FIXME: the kernel has other modes, should we allow any of those? */ + log_error("Invalid raid integrity mode (use \"bitmap\" or \"journal\")"); + return 0; + } + return 1; +} + /* Shared code for changing activation state for vgchange/lvchange */ int lv_change_activate(struct cmd_context *cmd, struct logical_volume *lv, activation_change_t activate) { int r = 1; + int integrity_recalculate; struct logical_volume *snapshot_lv; if (lv_is_cache_pool(lv)) { @@ -780,9 +795,34 @@ int lv_change_activate(struct cmd_context *cmd, struct logical_volume *lv, return 0; } + if ((integrity_recalculate = lv_has_integrity_recalculate_metadata(lv))) { + /* Don't want pvscan to write VG while running from systemd service. */ + if (!strcmp(cmd->name, "pvscan")) { + log_error("Cannot activate uninitialized integrity LV %s from pvscan.", + display_lvname(lv)); + return 0; + } + + if (vg_is_shared(lv->vg)) { + uint32_t lockd_state = 0; + if (!lockd_vg(cmd, lv->vg->name, "ex", 0, &lockd_state)) { + log_error("Cannot activate uninitialized integrity LV %s without lock.", + display_lvname(lv)); + return 0; + } + } + } + if (!lv_active_change(cmd, lv, activate)) return_0; + /* Write VG metadata to clear the integrity recalculate flag. */ + if (integrity_recalculate && lv_is_active(lv)) { + log_print_unless_silent("Updating VG to complete initialization of integrity LV %s.", + display_lvname(lv)); + lv_clear_integrity_recalculate_metadata(lv); + } + set_lv_notify(lv->vg->cmd); return r; @@ -1144,6 +1184,7 @@ out: return ok; } + /* FIXME move to lib */ static int _pv_change_tag(struct physical_volume *pv, const char *tag, int addtag) { @@ -2255,6 +2296,8 @@ static int _lv_is_prop(struct cmd_context *cmd, struct logical_volume *lv, int l return lv_is_historical(lv); case is_raid_with_tracking_LVP: return lv_is_raid_with_tracking(lv); + case is_raid_with_integrity_LVP: + return lv_raid_has_integrity(lv); default: log_error(INTERNAL_ERROR "unknown lv property value lvp_enum %d", lvp_enum); } @@ -2309,6 +2352,8 @@ static int _lv_is_type(struct cmd_context *cmd, struct logical_volume *lv, int l return seg_is_raid10(seg); case writecache_LVT: return seg_is_writecache(seg); + case integrity_LVT: + return seg_is_integrity(seg); case error_LVT: return !strcmp(seg->segtype->name, SEG_TYPE_NAME_ERROR); case zero_LVT: @@ -2367,6 +2412,8 @@ int get_lvt_enum(struct logical_volume *lv) return raid10_LVT; if (seg_is_writecache(seg)) return writecache_LVT; + if (seg_is_integrity(seg)) + return integrity_LVT; if (!strcmp(seg->segtype->name, SEG_TYPE_NAME_ERROR)) return error_LVT; |