diff options
author | David Teigland <teigland@redhat.com> | 2023-01-19 11:36:51 -0600 |
---|---|---|
committer | David Teigland <teigland@redhat.com> | 2023-01-19 11:52:14 -0600 |
commit | 3bb55765286dc8e4f0000957d85a6b8ee2752852 (patch) | |
tree | c8491f88de7d9435988ea92ae5b7e02211e1f9cc /lib/metadata | |
parent | 92199ad0b98586182a52e2f8cd82c06336e306f1 (diff) | |
download | lvm2-3bb55765286dc8e4f0000957d85a6b8ee2752852.tar.gz |
lvresize: only resize crypt when fs resize is enabled
There were a couple of cases where lvresize, without --fs resize,
was resizing the crypt layer above the LV. Resizing the crypt
layer should only be done when fs resizing is enabled (even if the
fs is already small enough due to being independently reduced.)
Also, check the size of the crypt device to see if it's already
been reduced independently, and skip the cryptsetup resize if
it's not needed.
Diffstat (limited to 'lib/metadata')
-rw-r--r-- | lib/metadata/lv_manip.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c index cb7f26069..cfb118f11 100644 --- a/lib/metadata/lv_manip.c +++ b/lib/metadata/lv_manip.c @@ -6408,7 +6408,23 @@ static int _fs_reduce(struct cmd_context *cmd, struct logical_volume *lv, * but the crypt dev over the LV should be shrunk to correspond with * the LV size, so that the FS does not see an incorrect device size. */ - if (!fsinfo.needs_reduce && fsinfo.needs_crypt && !test_mode()) { + if (!fsinfo.needs_reduce && fsinfo.needs_crypt) { + /* Check if the crypt device is already sufficiently reduced. */ + if (fsinfo.crypt_dev_size_bytes <= newsize_bytes_fs) { + log_print("crypt device is already reduced to %llu bytes.", + (unsigned long long)fsinfo.crypt_dev_size_bytes); + ret = 1; + goto out; + } + if (!strcmp(lp->fsopt, "checksize")) { + log_error("crypt reduce is required (see --resizefs or cryptsetup resize.)"); + ret = 0; + goto out; + } + if (test_mode()) { + ret = 1; + goto_out; + } ret = crypt_resize_script(cmd, lv, &fsinfo, newsize_bytes_fs); goto out; } |