lvm2/0023-lv_manip-check-fs-resize-is-supported-before-LV-exte.patch
Marian Csontos 4857646a28 Additional patches for 9.6.0 lvm2
Resolves: RHEL-53866 RHEL-65845 RHEL-60943
2025-01-09 19:04:38 +01:00

177 lines
5.6 KiB
Diff
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

From 9d9c8b8676b4fe21a0ff69e4c5d9e4a4a861f76e Mon Sep 17 00:00:00 2001
From: Peter Rajnoha <prajnoha@redhat.com>
Date: Fri, 3 Jan 2025 10:52:47 +0100
Subject: [PATCH 23/27] lv_manip: check fs resize is supported before LV
extension
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This avoids a situation where we would extend an LV and then we would
not do anything to the FS on it because the FS info check failed for some
reason, like the type was not supported (e.g. swap) or we could not resize
the FS unless being in some supported state (e.g. XFS to be mounted for
the xfs_growfs to work).
Before this patch (LV resized, FS not resized):
lvextend --fs resize -L+4M vg/swap
Size of logical volume vg/swap changed from 32.00 MiB (8 extents) to 36.00 MiB (9 extents).
File system extend is not supported (swap).
File system extend error.
Logical volume vg/swap successfully resized.
With this patch (LV not resized, FS not resized):
lvextend --fs resize -L+4M vg/swap
File system extend is not supported (swap).
(cherry picked from commit 5f53ecda3600834e920eef14065d35cd0fb6c59b)
---
lib/metadata/lv_manip.c | 71 +++++++++++++++++++++--------------------
1 file changed, 36 insertions(+), 35 deletions(-)
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index 15a7f3c9a..dab160234 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -6550,23 +6550,18 @@ static int _fs_reduce(struct cmd_context *cmd, struct logical_volume *lv,
return ret;
}
-static int _fs_extend(struct cmd_context *cmd, struct logical_volume *lv,
- struct lvresize_params *lp)
+static int _fs_extend_check_fsinfo(struct cmd_context *cmd, struct logical_volume *lv, struct lvresize_params *lp,
+ struct fs_info *fsinfo, uint64_t *newsize_bytes_fs)
{
- struct fs_info fsinfo;
uint64_t newsize_bytes_lv;
- uint64_t newsize_bytes_fs;
- int ret = 0;
- memset(&fsinfo, 0, sizeof(fsinfo));
+ memset(fsinfo, 0, sizeof(*fsinfo));
- if (!fs_get_info(cmd, lv, &fsinfo, 1))
- goto_out;
+ if (!fs_get_info(cmd, lv, fsinfo, 1))
+ return 0;
- if (fsinfo.nofs) {
- ret = 1;
- goto_out;
- }
+ if (fsinfo->nofs)
+ return 1;
/*
* Note: here in the case of extend, newsize_bytes_lv/newsize_bytes_fs
@@ -6577,40 +6572,43 @@ static int _fs_extend(struct cmd_context *cmd, struct logical_volume *lv,
/* extent_size units is SECTOR_SIZE (512) */
newsize_bytes_lv = (uint64_t) lp->extents * lv->vg->extent_size * SECTOR_SIZE;
- newsize_bytes_fs = newsize_bytes_lv;
- if (fsinfo.needs_crypt) {
- newsize_bytes_fs -= fsinfo.crypt_offset_bytes;
+ *newsize_bytes_fs = newsize_bytes_lv;
+ if (fsinfo->needs_crypt) {
+ *newsize_bytes_fs -= fsinfo->crypt_offset_bytes;
log_print_unless_silent("File system size %llub is adjusted for crypt data offset %ub.",
- (unsigned long long)newsize_bytes_fs, fsinfo.crypt_offset_bytes);
+ (unsigned long long)*newsize_bytes_fs, fsinfo->crypt_offset_bytes);
}
/*
* Decide if fs should be extended based on the --fs option,
* the fs type and the mount state.
*/
- if (!_fs_extend_allow(cmd, lv, lp, &fsinfo))
- goto_out;
+ if (!_fs_extend_allow(cmd, lv, lp, fsinfo))
+ return 0;
+
+ return 1;
+}
+static int _fs_extend(struct cmd_context *cmd, struct logical_volume *lv,
+ struct lvresize_params *lp, struct fs_info *fsinfo, uint64_t newsize_bytes_fs)
+{
/*
* fs extend is not needed
*/
- if (!fsinfo.needs_extend) {
- ret = 1;
- goto_out;
- }
+ if (!fsinfo->needs_extend)
+ return 1;
if (test_mode()) {
- if (fsinfo.needs_unmount)
+ if (fsinfo->needs_unmount)
log_print_unless_silent("Skip unmount in test mode.");
- if (fsinfo.needs_fsck)
+ if (fsinfo->needs_fsck)
log_print_unless_silent("Skip fsck in test mode.");
- if (fsinfo.needs_mount)
+ if (fsinfo->needs_mount)
log_print_unless_silent("Skip mount in test mode.");
- if (fsinfo.needs_crypt)
+ if (fsinfo->needs_crypt)
log_print_unless_silent("Skip cryptsetup in test mode.");
log_print_unless_silent("Skip fs extend in test mode.");
- ret = 1;
- goto out;
+ return 1;
}
/*
@@ -6621,12 +6619,7 @@ static int _fs_extend(struct cmd_context *cmd, struct logical_volume *lv,
*/
unlock_vg(cmd, lv->vg, lv->vg->name);
- if (!fs_extend_script(cmd, lv, &fsinfo, newsize_bytes_fs, lp->fsmode))
- goto_out;
-
- ret = 1;
- out:
- return ret;
+ return fs_extend_script(cmd, lv, fsinfo, newsize_bytes_fs, lp->fsmode);
}
int lv_resize(struct cmd_context *cmd, struct logical_volume *lv,
@@ -6640,6 +6633,8 @@ int lv_resize(struct cmd_context *cmd, struct logical_volume *lv,
struct logical_volume *lv_meta = NULL;
struct logical_volume *lv_main_layer = NULL;
struct logical_volume *lv_meta_layer = NULL;
+ struct fs_info fsinfo;
+ uint64_t newsize_bytes_fs;
int main_size_matches = 0;
int meta_size_matches = 0;
int is_extend = (lp->resize == LV_EXTEND);
@@ -7100,6 +7095,12 @@ int lv_resize(struct cmd_context *cmd, struct logical_volume *lv,
if (!lv_main)
goto end_main;
+
+ if (is_extend && lp->fsopt[0] && strcmp(lp->fsopt, "resize_fsadm")) {
+ if (!_fs_extend_check_fsinfo(cmd, lv_top, lp, &fsinfo, &newsize_bytes_fs))
+ goto_out;
+ }
+
if (!_lv_resize_volume(lv_main, lp, lp->pvh))
goto_out;
if (!lp->size_changed) {
@@ -7145,7 +7146,7 @@ int lv_resize(struct cmd_context *cmd, struct logical_volume *lv,
}
} else {
/* New approach to fs handling using fs info. */
- if (!_fs_extend(cmd, lv_top, lp)) {
+ if (!_fs_extend(cmd, lv_top, lp, &fsinfo, newsize_bytes_fs)) {
log_error("File system extend error.");
lp->extend_fs_error = 1;
goto out;
--
2.47.1