main - lvresize: add new options and defaults for fs handling
Subsystems (2)
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=264827cb98458f7100456eeebf7fdde8dcbc0ad4 Commit: 264827cb98458f7100456eeebf7fdde8dcbc0ad4 Parent: 18722dfdf4d3e6f172d0b2af8bbdc4a154ea1dc0 Author: David Teigland <[email protected]> AuthorDate: Tue Jun 14 15:20:21 2022 -0500 Committer: David Teigland <[email protected]> CommitterDate: Tue Sep 13 15:15:05 2022 -0500
lvresize: add new options and defaults for fs handling
The new option "--fs String" for lvresize/lvreduce/lvextend controls the handling of file systems before/after resizing the LV. --resizefs is the same as --fs resize.
The new option "--fsmode String" can be used to control mounting and unmounting of the fs during resizing.
Possible --fs values:
checksize
Only applies to reducing size; does nothing for extend. Check the fs size and reduce the LV if the fs is not using the affected space, i.e. the fs does not need to be shrunk. Fail the command without reducing the fs or LV if the fs is using the affected space.
resize
Resize the fs using the fs-specific resize command. This may include mounting, unmounting, or running fsck. See --fsmode to control mounting behavior, and --nofsck to disable fsck.
resize_fsadm
Use the old method of calling fsadm to handle the fs (deprecated.) Warning: this option does not prevent lvreduce from destroying file systems that are unmounted (or mounted if prompts are skipped.)
ignore
Resize the LV without checking for or handling a file system.
Warning: using ignore when reducing the LV size may destroy the file system.
Possible --fsmode values:
manage
Mount or unmount the fs as needed to resize the fs, and attempt to restore the original mount state at the end.
nochange
Do not mount or unmount the fs. If mounting or unmounting is required to resize the fs, then do not resize the fs or the LV and fail the command.
offline
Unmount the fs if it is mounted, and resize the fs while it is unmounted. If mounting is required to resize the fs, then do not resize the fs or the LV and fail the command.
Notes on lvreduce:
When no --fs or --resizefs option is specified:
. lvextend default behavior is fs ignore.
. lvreduce default behavior is fs checksize
(includes activating the LV.)
With the exception of --fs resize_fsadm|ignore, lvreduce requires the recent libblkid fields FSLASTBLOCK and FSBLOCKSIZE. FSLASTBLOCK*FSBLOCKSIZE is the last byte used by the fs on the LV, which determines if reducing the fs is necessary.
--- configure.ac | 12 + include/configure.h.in | 3 +- lib/Makefile.in | 1 + lib/activate/dev_manager.c | 75 +++ lib/activate/dev_manager.h | 2 + lib/device/dev-type.c | 91 +++ lib/device/dev-type.h | 2 + lib/device/filesystem.c | 400 ++++++++++++ lib/device/filesystem.h | 50 ++ lib/metadata/lv_manip.c | 763 ++++++++++++++++++++-- lib/metadata/metadata-exported.h | 7 +- lib/metadata/metadata.c | 4 +- lib/metadata/metadata.h | 2 + scripts/Makefile.in | 6 +- scripts/fsadm.sh | 2 +- scripts/lvresize_fs_helper.sh | 466 ++++++++++++++ spec/packages.inc | 1 + test/shell/fsadm-crypt-fsresize.sh | 612 ++++++++++++++++++ test/shell/fsadm-crypt.sh | 130 ++-- test/shell/fsadm.sh | 37 +- test/shell/hints.sh | 4 +- test/shell/lvresize-fs-crypt.sh | 131 ++++ test/shell/lvresize-fs.sh | 1186 +++++++++++++++++++++++++++++++++++ test/shell/lvresize-full.sh | 7 +- test/shell/lvresize-mirror.sh | 2 +- test/shell/lvresize-rounding.sh | 10 +- test/shell/relative-sign-options.sh | 16 +- tools/args.h | 35 +- tools/command-lines.in | 12 +- tools/lvresize.c | 115 +++- 30 files changed, 3987 insertions(+), 197 deletions(-)
configure.ac +12 -0
@@ -1605,6 +1605,11 @@ AC_ARG_WITH(usrsbindir, [usrsbin executables in DIR [PREFIX/sbin]]), usrsbindir=$withval, usrsbindir='${prefix}/sbin') +AC_ARG_WITH(libexecdir, + AS_HELP_STRING([--with-libexecdir=DIR], + [libexec executables in DIR [PREFIX/libexec]]), + libexecdir=$withval, libexecdir='${prefix}/libexec') + ################################################################################ AC_ARG_WITH(udev_prefix, AS_HELP_STRING([--with-udev-prefix=UPREFIX],
@@ -1709,6 +1714,11 @@ AC_DEFINE_UNQUOTED(FSADM_PATH, ["$FSADM_PATH"], [Path to fsadm binary.]) LVMIMPORTVDO_PATH="$SBINDIR/lvm_import_vdo" AC_DEFINE_UNQUOTED(LVMIMPORTVDO_PATH, ["$LVMIMPORTVDO_PATH"], [Path to lvm_import_vdo script.]) +LIBEXECDIR="$(eval echo $(eval echo $libexecdir))" + +LVRESIZE_FS_HELPER_PATH="$LIBEXECDIR/lvresize_fs_helper" +AC_DEFINE_UNQUOTED(LVRESIZE_FS_HELPER_PATH, ["$LVRESIZE_FS_HELPER_PATH"], [Path to lvresize_fs_helper script.]) + ################################################################################ dnl -- dmeventd pidfile and executable path if test "$BUILD_DMEVENTD" = yes; then
@@ -1878,6 +1888,7 @@ AC_SUBST(DM_LIB_PATCHLEVEL) AC_SUBST(ELDFLAGS) AC_SUBST(FSADM) AC_SUBST(FSADM_PATH) +AC_SUBST(LVRESIZE_FS_HELPER_PATH) AC_SUBST(BLKDEACTIVATE) AC_SUBST(HAVE_LIBDL) AC_SUBST(HAVE_REALTIME)
@@ -1976,6 +1987,7 @@ AC_SUBST(systemdutildir) AC_SUBST(tmpfilesdir) AC_SUBST(usrlibdir) AC_SUBST(usrsbindir) +AC_SUBST(libexecdir) ################################################################################ dnl -- First and last lines should not contain files to generate in order to
include/configure.h.in +2 -1
@@ -127,8 +127,9 @@ /* Define to 1 to include the LVM editline shell. */ #undef EDITLINE_SUPPORT -/* Path to fsadm binary. */ +/* Paths to binaries. */ #undef FSADM_PATH +#undef LVRESIZE_FS_HELPER_PATH /* Define to use GNU versioning in the shared library. */ #undef GNU_SYMVER
lib/Makefile.in +1 -0
@@ -40,6 +40,7 @@ SOURCES =\ device/dev-luks.c \ device/dev-dasd.c \ device/dev-lvm1-pool.c \ + device/filesystem.c \ device/online.c \ device/parse_vpd.c \ display/display.c \
lib/activate/dev_manager.c +75 -0
78 lines not on this page · raw message
lib/activate/dev_manager.h +2 -0
@@ -29,6 +29,8 @@ struct lv_seg_status;int read_only_lv (const struct logical_volume *lv,const struct lv_activate_opts *laopts,const char *layer); +int get_crypt_table_offset (dev_t crypt_devt,uint32_t *offset_bytes); +/* * Constructor and destructor. */
lib/device/dev-type.c +91 -0
109 lines not on this page · raw message
lib/device/dev-type.h +2 -0
@@ -18,6 +18,7 @@#include "lib/device/device.h" #include "lib/display/display.h" #include "lib/label/label.h" +#include "lib/device/filesystem.h" #define NUMBER_OF_MAJORS 4096
@@ -103,6 +104,7 @@ int dev_is_lv(struct device *dev);#define FSTYPE_MAX 16int fs_block_size_and_type (const char *pathname,uint32_t *fs_block_size_bytes,char *fstype,int *nofs); +int fs_get_blkid (const char *pathname,struct fs_info *fsi);int dev_is_used_by_active_lv (struct cmd_context *cmd,struct device *dev,int *used_by_lv_count,char **used_by_dm_name,char **used_by_vg_uuid,char **used_by_lv_uuid);
lib/device/filesystem.c new file +400 -0
400 lines not on this page · raw message
lib/device/filesystem.h new file +50 -0
50 lines not on this page · raw message
lib/metadata/lv_manip.c +696 -67
857 lines not on this page · raw message
lib/metadata/metadata-exported.h +6 -1
@@ -674,8 +674,11 @@ struct lvresize_params {int force;int nosync;int nofsck; -int resizefs;int use_policies; +int user_set_fs; +int user_set_fsmode; +char fsopt[16 ];/* set by --resizefs|--fs, empty for --fs ignore */ +char fsmode[16 ];/* set by --fsmode */ const struct segment_type *segtype;unsigned mirrors;
@@ -695,6 +698,8 @@ struct lvresize_params {int approx_alloc;int extents_are_pes;/* Is 'extents' counting PEs or LEs? */ int size_changed;/* Was there actually a size change */ +int extend_fs_error;/* FS extend error after LV extend success */ +int vg_changed_error;/* VG metadata was modified during fs resize */ const char *lockopt;char *lockd_lv_refresh_path;/* set during resize to use for refresh at the end */
lib/metadata/metadata.c +2 -2
@@ -4533,7 +4533,7 @@ void vg_write_commit_bad_mdas(struct cmd_context *cmd, struct volume_group *vg)* reread metadata. */ -static bool _scan_text_mismatch (struct cmd_context *cmd,const char *vgname,const char *vgid) +bool scan_text_mismatch (struct cmd_context *cmd,const char *vgname,const char *vgid) {DM_LIST_INIT (mda_list);struct mda_list *mdal, *safe;
@@ -4706,7 +4706,7 @@ static struct volume_group *_vg_read(struct cmd_context *cmd,* probably unnecessary; all commands could likely just check a single mda. */ -if (lvmcache_scan_mismatch (cmd, vgname, vgid) ||_scan_text_mismatch (cmd, vgname, vgid)) { +if (lvmcache_scan_mismatch (cmd, vgname, vgid) ||scan_text_mismatch (cmd, vgname, vgid)) {log_debug_metadata ("Rescanning devices for %s %s" , vgname, writing ?"rw" :"" );if (writing)lvmcache_label_rescan_vg_rw (cmd, vgname, vgid);
lib/metadata/metadata.h +2 -0
@@ -541,5 +541,7 @@ void set_pv_devices(struct format_instance *fid, struct volume_group *vg);int get_visible_lvs_using_pv (struct cmd_context *cmd,struct volume_group *vg,struct device *dev,struct dm_list *lvs_list); +bool scan_text_mismatch (struct cmd_context *cmd,const char *vgname,const char *vgid); +#endif
scripts/Makefile.in +5 -1
@@ -56,7 +56,11 @@ install_device-mapper: $(DM_SCRIPTS:.sh=_install) install_ocf: $(OCF_SCRIPTS:.ocf=_install) -install: install_lvm2 install_ocf install_device-mapper +install_libexec: + $(Q) $(INSTALL_SCRIPT) lvresize_fs_helper.sh $(libexecdir)/lvresize_fs_helper + +install: install_lvm2 install_ocf install_device-mapper install_libexec + # FIXME Customise for other distributions install_initscripts:
scripts/fsadm.sh +1 -1
@@ -164,7 +164,7 @@ cleanup() { export _FSADM_YES _FSADM_EXTOFF unset FSADM_RUNNING test -n "${LVM_BINARY-}" && PATH=$_SAVEPATH - dry exec "$LVM" lvresize $VERB $FORCE -r -L"${NEWSIZE_ORIG}b" "$VOLUME_ORIG" + dry exec "$LVM" lvresize $VERB $FORCE $YES --fs resize_fsadm -L"${NEWSIZE_ORIG}b" "$VOLUME_ORIG" fi # error exit status for break
scripts/lvresize_fs_helper.sh new file +466 -0
466 lines not on this page · raw message
spec/packages.inc +1 -0
@@ -34,6 +34,7 @@ fi %doc COPYING COPYING.LIB INSTALL README VERSION WHATS_NEW %doc doc/lvm_fault_handling.txt %{_sbindir}/fsadm +%{_libexecdir}/lvresize_fs_helper %{_sbindir}/lvchange %{_sbindir}/lvconvert %{_sbindir}/lvcreate
test/shell/fsadm-crypt-fsresize.sh new file +612 -0
612 lines not on this page · raw message
test/shell/fsadm-crypt.sh +65 -65
283 lines not on this page · raw message
test/shell/lvresize-fs-crypt.sh new file +131 -0
131 lines not on this page · raw message
test/shell/lvresize-fs.sh new file +1186 -0
1,186 lines not on this page · raw message
tools/lvresize.c +102 -13
115 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.