master - lv_manip: add space into message
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=9740e98cbdba114457d...
Commit: 9740e98cbdba114457dc20bf43ad4c4b8994876f
Parent: be94410446d381ab0512d347421a921c7966a10e
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Oct 19 10:28:06 2020 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Sat Oct 24 01:42:16 2020 +0200
lv_manip: add space into message
Just add space between %s(.
---
lib/metadata/lv_manip.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index 72c85914d..e66342022 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -1022,7 +1022,7 @@ static uint32_t _round_to_stripe_boundary(struct volume_group *vg, uint32_t exte
/* Round up extents to stripe divisible amount */
if ((size_rest = extents % stripes)) {
new_extents += extend ? stripes - size_rest : -size_rest;
- log_print_unless_silent("Rounding size %s (%u extents) %s to stripe boundary size %s(%u extents).",
+ log_print_unless_silent("Rounding size %s (%u extents) %s to stripe boundary size %s (%u extents).",
display_size(vg->cmd, (uint64_t) extents * vg->extent_size), extents,
new_extents < extents ? "down" : "up",
display_size(vg->cmd, (uint64_t) new_extents * vg->extent_size), new_extents);
3 years, 6 months
master - tests: fsadm test continue after fs repair
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=be94410446d381ab051...
Commit: be94410446d381ab0512d347421a921c7966a10e
Parent: 8c2779ba349e5ced3c9ea440929a6808ca443bf4
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sat Oct 24 00:29:45 2020 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Sat Oct 24 01:42:16 2020 +0200
tests: fsadm test continue after fs repair
Test case where filesystem has been corrected via fsck.
In such case fsck returns '1' as success and should be
handled in a same way as '0' since fs is correct.
---
test/shell/fsadm.sh | 27 ++++++++++++++++++++++++++-
1 file changed, 26 insertions(+), 1 deletion(-)
diff --git a/test/shell/fsadm.sh b/test/shell/fsadm.sh
index 8141da42c..3e7f9083c 100644
--- a/test/shell/fsadm.sh
+++ b/test/shell/fsadm.sh
@@ -61,7 +61,8 @@ cleanup_mounted_and_teardown()
fscheck_ext3()
{
- fsck.ext3 -p -F -f "$dev_vg_lv"
+ # fsck with result code '1' is success
+ fsck.ext3 -p -F -f "$dev_vg_lv" || test "$?" -eq 1
}
fscheck_xfs()
@@ -113,6 +114,30 @@ if check_missing ext2; then
fscheck_ext3
lvresize -f -L20M $vg_lv
+
+ if which debugfs ; then
+ mkfs.ext2 -b4096 -j "$dev_vg_lv"
+ mount "$dev_vg_lv" "$mount_dir"
+ touch "$mount_dir/file"
+ umount "$mount_dir"
+ # generate a 'repariable' corruption
+ # so fsck returns code 1 (fs repaired)
+ debugfs -R "clri file" -w "$dev_vg_lv"
+
+ fsadm -v -f check "$dev_vg_lv"
+
+ # corrupting again
+ mount "$dev_vg_lv" "$mount_dir"
+ touch "$mount_dir/file"
+ umount "$mount_dir"
+ debugfs -R "clri file" -w "$dev_vg_lv"
+
+ mount "$dev_vg_lv" "$mount_dir"
+ fsadm -v -y --lvresize resize $vg_lv 10M
+ lvresize -L+10M -y -r -n $vg_lv
+ umount "$mount_dir" 2>/dev/null || true
+ fscheck_ext3
+ fi
fi
if check_missing ext3; then
3 years, 6 months
master - fsadm: enhance error handling
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=8c2779ba349e5ced3c9...
Commit: 8c2779ba349e5ced3c9ea440929a6808ca443bf4
Parent: 51a532719c80a91bf32339741d8df30ef593a8d4
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sat Oct 24 01:13:42 2020 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Sat Oct 24 01:42:16 2020 +0200
fsadm: enhance error handling
Set more secure bash failure mode for pipilines.
Avoid using unset variables.
Enhnace error reporting for failing command.
Avoid using error via 'case..esac || error'.
---
scripts/fsadm.sh | 47 ++++++++++++++++++++++++++++-------------------
1 file changed, 28 insertions(+), 19 deletions(-)
diff --git a/scripts/fsadm.sh b/scripts/fsadm.sh
index 5ca80b4dd..5bba5ff40 100755
--- a/scripts/fsadm.sh
+++ b/scripts/fsadm.sh
@@ -29,6 +29,8 @@
# 2 break detected
# 3 unsupported online filesystem check for given mounted fs
+set -euE -o pipefail
+
TOOL=fsadm
_SAVEPATH=$PATH
@@ -61,7 +63,7 @@ CRYPTSETUP=cryptsetup
# user may override lvm location by setting LVM_BINARY
LVM=${LVM_BINARY:-lvm}
-YES=${_FSADM_YES}
+YES="${_FSADM_YES-}"
DRY=0
VERB=
FORCE=
@@ -206,7 +208,7 @@ decode_major_minor() {
# detect filesystem on the given device
# dereference device name if it is symbolic link
detect_fs() {
- test -n "$VOLUME_ORIG" || VOLUME_ORIG=$1
+ test -n "${VOLUME_ORIG-}" || VOLUME_ORIG=$1
VOLUME=${1/#"${DM_DEV_DIR}/"/}
VOLUME=$("$READLINK" $READLINK_E "$DM_DEV_DIR/$VOLUME")
test -n "$VOLUME" || error "Cannot get readlink \"$1\"."
@@ -257,11 +259,11 @@ check_valid_mounted_device() {
local MOUNTEDMAJORMINOR
local VOL
local CURNAME
- local SUGGEST="Possibly device \"$1\" has been renamed to \"$CURNAME\"?"
VOL=$("$READLINK" $READLINK_E "$1")
CURNAME=$(dmsetup info -c -j "$MAJOR" -m "$MINOR" -o name --noheadings)
# more confused, device is not DM....
+ local SUGGEST="Possibly device \"$1\" has been renamed to \"$CURNAME\"?"
test -n "$CURNAME" || SUGGEST="Mounted volume is not a device mapper device???"
test -n "$VOL" ||
@@ -270,7 +272,7 @@ check_valid_mounted_device() {
"Filesystem utilities currently do not support renamed devices."
case "$VOL" in
- # hardcoded /dev since udev does not create these entries elsewhere
+ # hardcoded /dev since kernel does not create these entries elsewhere
/dev/dm-[0-9]*)
read -r <"/sys/block/${VOL#/dev/}/dev" MOUNTEDMAJORMINOR 2>&1 || error "Cannot get major:minor for \"$VOLUME\"."
;;
@@ -674,20 +676,23 @@ resize() {
# if the size parameter is missing use device size
#if [ -n "$NEWSIZE" -a $NEWSIZE <
test -z "$NEWSIZE" && NEWSIZE=${DEVSIZE}b
- test -n "$NEWSIZE_ORIG" || NEWSIZE_ORIG=$NEWSIZE
+ NEWSIZE_ORIG=${NEWSIZE_ORIG:-$NEWSIZE}
IFS=$NL
- test -z "$DO_CRYPTRESIZE" || detect_crypt_device "$VOLUME_ORIG" "$NEWSIZE_ORIG"
- test -z "$CRYPT_GROW" || resize_crypt "$VOLUME_ORIG"
+ test -z "${DO_CRYPTRESIZE-}" || detect_crypt_device "$VOLUME_ORIG" "$NEWSIZE_ORIG"
+ test -z "${CRYPT_GROW-}" || resize_crypt "$VOLUME_ORIG"
+
case "$FSTYPE" in
- "ext3"|"ext2"|"ext4") resize_ext $NEWSIZE ;;
- "reiserfs") resize_reiser $NEWSIZE ;;
- "xfs") resize_xfs $NEWSIZE ;;
+ ext[234]) CMD=resize_ext ;;
+ "reiserfs") CMD=resize_reiser ;;
+ "xfs") CMD=resize_xfs ;;
"crypto_LUKS")
which "$CRYPTSETUP" >"$NULL" 2>&1 || error "$CRYPTSETUP utility required to resize LUKS volume"
- resize_luks $NEWSIZE ;;
+ CMD=resize_luks ;;
*) error "Filesystem \"$FSTYPE\" on device \"$VOLUME\" is not supported by this tool." ;;
- esac || error "Resize $FSTYPE failed."
- test -z "$CRYPT_SHRINK" || resize_crypt "$VOLUME_ORIG"
+ esac
+
+ $CMD $NEWSIZE || error "$FSTYPE resize failed."
+ test -z "${CRYPT_SHRINK-}" || resize_crypt "$VOLUME_ORIG"
}
####################################
@@ -716,7 +721,7 @@ check() {
fi
case "$FSTYPE" in
- "ext2"|"ext3"|"ext4")
+ ext[234])
IFS_CHECK=$IFS
IFS=$NL
for i in $(LC_ALL=C "$TUNE_EXT" -l "$VOLUME"); do
@@ -740,15 +745,15 @@ check() {
case "$FSTYPE" in
"xfs") if which "$XFS_CHECK" >"$NULL" 2>&1 ; then
- dry "$XFS_CHECK" "$VOLUME"
+ dry "$XFS_CHECK" "$VOLUME" || error "Xfs check failed."
else
# Replacement for outdated xfs_check
# FIXME: for small devices we need to force_geometry,
# since we run in '-n' mode, it shouldn't be problem.
# Think about better way....
- dry "$XFS_REPAIR" -n -o force_geometry "$VOLUME"
+ dry "$XFS_REPAIR" -n -o force_geometry "$VOLUME" || error "Xfs repair failed."
fi ;;
- "ext2"|"ext3"|"ext4"|"reiserfs")
+ ext[234]|"reiserfs")
# check if executed from interactive shell environment
case "$-" in
*i*) FLAG=$YES ;;
@@ -758,7 +763,8 @@ check() {
;;
"crypto_LUKS")
which "$CRYPTSETUP" >"$NULL" 2>&1 || error "$CRYPTSETUP utility required."
- check_luks ;;
+ check_luks || error "Crypto luks check failed."
+ ;;
*)
error "Filesystem \"$FSTYPE\" on device \"$VOLUME\" is not supported by this tool." ;;
esac
@@ -771,7 +777,7 @@ check() {
trap "cleanup 2" 2
# test if we are not invoked recursively
-test -n "$FSADM_RUNNING" && exit 0
+test -n "${FSADM_RUNNING-}" && exit 0
# test some prerequisities
for i in "$TUNE_EXT" "$RESIZE_EXT" "$TUNE_REISER" "$RESIZE_REISER" \
@@ -793,6 +799,9 @@ if [ "$#" -eq 0 ] ; then
tool_usage
fi
+CHECK=""
+RESIZE=""
+
while [ "$#" -ne 0 ]
do
case "$1" in
3 years, 6 months
master - fsadm: handle fsck return 1 for corrected fs
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=51a532719c80a91bf32...
Commit: 51a532719c80a91bf32339741d8df30ef593a8d4
Parent: 73ef86ae3fd51c921c3437a8c3da474e2861d217
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sat Oct 24 00:42:31 2020 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Sat Oct 24 01:42:16 2020 +0200
fsadm: handle fsck return 1 for corrected fs
---
scripts/fsadm.sh | 25 ++++++++++++++++++-------
1 file changed, 18 insertions(+), 7 deletions(-)
diff --git a/scripts/fsadm.sh b/scripts/fsadm.sh
index b84412d92..5ca80b4dd 100755
--- a/scripts/fsadm.sh
+++ b/scripts/fsadm.sh
@@ -1,6 +1,6 @@
#!/bin/bash
#
-# Copyright (C) 2007-2017 Red Hat, Inc. All rights reserved.
+# Copyright (C) 2007-2020 Red Hat, Inc. All rights reserved.
#
# This file is part of LVM2.
#
@@ -130,7 +130,15 @@ dry() {
return 0
fi
verbose "Executing" "$@"
- "$@"
+ $@
+}
+
+# Accept as succss also return code 1 with fsck
+accept_0_1() {
+ $@
+ local ret="$?"
+ test "$ret" -eq 1 || return "$ret"
+ # Filesystem was corrected
}
cleanup() {
@@ -455,9 +463,10 @@ resize_ext() {
if test -n "$MOUNTED" ; then
# Forced fsck -f for umounted extX filesystem.
case "$-" in
- *i*) dry "$FSCK" $YES -f "$VOLUME" ;;
- *) dry "$FSCK" -f -p "$VOLUME" ;;
+ *i*) FLAG=$YES ;;
+ *) FLAG="-p" ;;
esac
+ accept_0_1 dry "$FSCK" -f $FLAG "$VOLUME" || error "Failed to fsck $VOLUME"
fi
fi
@@ -742,9 +751,11 @@ check() {
"ext2"|"ext3"|"ext4"|"reiserfs")
# check if executed from interactive shell environment
case "$-" in
- *i*) dry "$FSCK" $YES $FORCE "$VOLUME" ;;
- *) dry "$FSCK" $FORCE -p "$VOLUME" ;;
- esac ;;
+ *i*) FLAG=$YES ;;
+ *) FLAG="-p" ;;
+ esac
+ accept_0_1 dry "$FSCK" $FORCE $FLAG "$VOLUME" || error "Fsck $FSTYPE failed."
+ ;;
"crypto_LUKS")
which "$CRYPTSETUP" >"$NULL" 2>&1 || error "$CRYPTSETUP utility required."
check_luks ;;
3 years, 6 months
master - fsadm: use NULL
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=73ef86ae3fd51c921c3...
Commit: 73ef86ae3fd51c921c3437a8c3da474e2861d217
Parent: 6226512ad2d6fd30a4b55da6a4d4c370fa7fad09
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sat Oct 24 00:40:34 2020 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Sat Oct 24 01:42:16 2020 +0200
fsadm: use NULL
Use consistently $NULL as in other places.
---
scripts/fsadm.sh | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/scripts/fsadm.sh b/scripts/fsadm.sh
index 28ca6709f..b84412d92 100755
--- a/scripts/fsadm.sh
+++ b/scripts/fsadm.sh
@@ -233,8 +233,8 @@ validate_mounted_major_minor() {
test "$1" = "$MAJORMINOR" || {
local REFNAME
local CURNAME
- REFNAME=$(dmsetup info -c -j "${1%%:*}" -m "${1##*:}" -o name --noheadings 2>/dev/null)
- CURNAME=$(dmsetup info -c -j "$MAJOR" -m "$MINOR" -o name --noheadings 2>/dev/null)
+ REFNAME=$(dmsetup info -c -j "${1%%:*}" -m "${1##*:}" -o name --noheadings 2>"$NULL")
+ CURNAME=$(dmsetup info -c -j "$MAJOR" -m "$MINOR" -o name --noheadings 2>"$NULL")
error "Cannot ${CHECK+CHECK}${RESIZE+RESIZE} device \"$VOLUME\" without umounting filesystem $MOUNTED first." \
"Mounted filesystem is using device $CURNAME, but referenced device is $REFNAME." \
"Filesystem utilities currently do not support renamed devices."
@@ -279,7 +279,7 @@ check_valid_mounted_device() {
detect_mounted_with_proc_self_mountinfo() {
# Check self mountinfo
# grab major:minor mounted_device mount_point
- MOUNTED=$("$GREP" "^[0-9]* [0-9]* $MAJORMINOR " "$PROCSELFMOUNTINFO" 2>/dev/null | head -1)
+ MOUNTED=$("$GREP" "^[0-9]* [0-9]* $MAJORMINOR " "$PROCSELFMOUNTINFO" 2>"$NULL" | head -1)
# If device is opened and not yet found as self mounted
# check all other mountinfos (since it can be mounted in cgroups)
@@ -287,7 +287,7 @@ detect_mounted_with_proc_self_mountinfo() {
# only 1st. line is needed
test -z "$MOUNTED" &&
test "$(dmsetup info -c --noheading -o open -j "$MAJOR" -m "$MINOR")" -gt 0 &&
- MOUNTED=$(find "$PROCDIR" -maxdepth 2 -name mountinfo -print0 | xargs -0 "$GREP" "^[0-9]* [0-9]* $MAJORMINOR " 2>/dev/null | head -1 2>/dev/null)
+ MOUNTED=$(find "$PROCDIR" -maxdepth 2 -name mountinfo -print0 | xargs -0 "$GREP" "^[0-9]* [0-9]* $MAJORMINOR " 2>"$NULL" | head -1 2>"$NULL")
# TODO: for performance compare with sed and stop with 1st. match:
# sed -n "/$MAJORMINOR/ {;p;q;}"
@@ -532,7 +532,7 @@ detect_luks_device() {
CRYPT_NAME=""
CRYPT_DATA_OFFSET=""
- _LUKS_VERSION=$("$CRYPTSETUP" luksDump "$VOLUME" 2> /dev/null | "$GREP" "Version:")
+ _LUKS_VERSION=$("$CRYPTSETUP" luksDump "$VOLUME" 2>"$NULL" | "$GREP" "Version:")
if [ -z "$_LUKS_VERSION" ]; then
verbose "Failed to parse LUKS version on volume \"$VOLUME\""
@@ -541,7 +541,7 @@ detect_luks_device() {
_LUKS_VERSION=${_LUKS_VERSION//[Version:[:space:]]/}
- _LUKS_UUID=$("$CRYPTSETUP" luksDump "$VOLUME" 2> /dev/null | "$GREP" "UUID:")
+ _LUKS_UUID=$("$CRYPTSETUP" luksDump "$VOLUME" 2>"$NULL" | "$GREP" "UUID:")
if [ -z "$_LUKS_UUID" ]; then
verbose "Failed to parse LUKS UUID on volume \"$VOLUME\""
@@ -612,9 +612,9 @@ detect_crypt_device() {
local L_NEWSIZE
local TMP
- which "$CRYPTSETUP" > /dev/null 2>&1 || error "$CRYPTSETUP utility required to resize crypt device"
+ which "$CRYPTSETUP" >"$NULL" 2>&1 || error "$CRYPTSETUP utility required to resize crypt device"
- CRYPT_TYPE=$("$CRYPTSETUP" status "$1" 2> /dev/null | "$GREP" "type:")
+ CRYPT_TYPE=$("$CRYPTSETUP" status "$1" 2>"$NULL" | "$GREP" "type:")
test -n "$CRYPT_TYPE" || error "$CRYPTSETUP failed to detect device type on $1."
@@ -674,7 +674,7 @@ resize() {
"reiserfs") resize_reiser $NEWSIZE ;;
"xfs") resize_xfs $NEWSIZE ;;
"crypto_LUKS")
- which "$CRYPTSETUP" > /dev/null 2>&1 || error "$CRYPTSETUP utility required to resize LUKS volume"
+ which "$CRYPTSETUP" >"$NULL" 2>&1 || error "$CRYPTSETUP utility required to resize LUKS volume"
resize_luks $NEWSIZE ;;
*) error "Filesystem \"$FSTYPE\" on device \"$VOLUME\" is not supported by this tool." ;;
esac || error "Resize $FSTYPE failed."
@@ -746,7 +746,7 @@ check() {
*) dry "$FSCK" $FORCE -p "$VOLUME" ;;
esac ;;
"crypto_LUKS")
- which "$CRYPTSETUP" > /dev/null 2>&1 || error "$CRYPTSETUP utility required."
+ which "$CRYPTSETUP" >"$NULL" 2>&1 || error "$CRYPTSETUP utility required."
check_luks ;;
*)
error "Filesystem \"$FSTYPE\" on device \"$VOLUME\" is not supported by this tool." ;;
3 years, 6 months
stable-2.02 - WHATS_NEW: update
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=f5a2607bb194933caea...
Commit: f5a2607bb194933caea62a88bd7fcc766efcd5cd
Parent: 67dc22b95e7edfc3c0a96d96af313e7384908546
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sat Oct 24 01:37:10 2020 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Sat Oct 24 01:37:10 2020 +0200
WHATS_NEW: update
---
WHATS_NEW | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 73167aca6..2a745dbdd 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,6 +1,8 @@
Version 2.02.188 -
==================================
- Dmevend lvm plugin ignores higher reserved_stack lvm.conf values.
+ Enhance error handling for fsadm and hanled correct fsck result.
+ Stop logging rename errors from persintent filter.
+ Dmeventd lvm plugin ignores higher reserved_stack lvm.conf values.
Support using BLKZEROOUT for clearing devices.
Support interruption when wipping LVs.
Add configure --enable-editline support as an alternative to readline.
3 years, 6 months
stable-2.02 - tests: fsadm test continue after fs repair
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=67dc22b95e7edfc3c0a...
Commit: 67dc22b95e7edfc3c0a96d96af313e7384908546
Parent: 9a2a59c0ed4320324e908be60693bac7ed507824
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sat Oct 24 00:29:45 2020 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Sat Oct 24 01:33:39 2020 +0200
tests: fsadm test continue after fs repair
Test case where filesystem has been corrected via fsck.
In such case fsck returns '1' as success and should be
handled in a same way as '0' since fs is correct.
---
test/shell/fsadm.sh | 27 ++++++++++++++++++++++++++-
1 file changed, 26 insertions(+), 1 deletion(-)
diff --git a/test/shell/fsadm.sh b/test/shell/fsadm.sh
index 8141da42c..3e7f9083c 100644
--- a/test/shell/fsadm.sh
+++ b/test/shell/fsadm.sh
@@ -61,7 +61,8 @@ cleanup_mounted_and_teardown()
fscheck_ext3()
{
- fsck.ext3 -p -F -f "$dev_vg_lv"
+ # fsck with result code '1' is success
+ fsck.ext3 -p -F -f "$dev_vg_lv" || test "$?" -eq 1
}
fscheck_xfs()
@@ -113,6 +114,30 @@ if check_missing ext2; then
fscheck_ext3
lvresize -f -L20M $vg_lv
+
+ if which debugfs ; then
+ mkfs.ext2 -b4096 -j "$dev_vg_lv"
+ mount "$dev_vg_lv" "$mount_dir"
+ touch "$mount_dir/file"
+ umount "$mount_dir"
+ # generate a 'repariable' corruption
+ # so fsck returns code 1 (fs repaired)
+ debugfs -R "clri file" -w "$dev_vg_lv"
+
+ fsadm -v -f check "$dev_vg_lv"
+
+ # corrupting again
+ mount "$dev_vg_lv" "$mount_dir"
+ touch "$mount_dir/file"
+ umount "$mount_dir"
+ debugfs -R "clri file" -w "$dev_vg_lv"
+
+ mount "$dev_vg_lv" "$mount_dir"
+ fsadm -v -y --lvresize resize $vg_lv 10M
+ lvresize -L+10M -y -r -n $vg_lv
+ umount "$mount_dir" 2>/dev/null || true
+ fscheck_ext3
+ fi
fi
if check_missing ext3; then
3 years, 6 months
stable-2.02 - fsadm: enhance error handling
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=9a2a59c0ed4320324e9...
Commit: 9a2a59c0ed4320324e908be60693bac7ed507824
Parent: ab99382d7a614c299e765ea4d1f02fe7282502a1
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sat Oct 24 01:13:42 2020 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Sat Oct 24 01:33:39 2020 +0200
fsadm: enhance error handling
Set more secure bash failure mode for pipilines.
Avoid using unset variables.
Enhnace error reporting for failing command.
Avoid using error via 'case..esac || error'.
---
scripts/fsadm.sh | 47 ++++++++++++++++++++++++++++-------------------
1 file changed, 28 insertions(+), 19 deletions(-)
diff --git a/scripts/fsadm.sh b/scripts/fsadm.sh
index 5ca80b4dd..5bba5ff40 100755
--- a/scripts/fsadm.sh
+++ b/scripts/fsadm.sh
@@ -29,6 +29,8 @@
# 2 break detected
# 3 unsupported online filesystem check for given mounted fs
+set -euE -o pipefail
+
TOOL=fsadm
_SAVEPATH=$PATH
@@ -61,7 +63,7 @@ CRYPTSETUP=cryptsetup
# user may override lvm location by setting LVM_BINARY
LVM=${LVM_BINARY:-lvm}
-YES=${_FSADM_YES}
+YES="${_FSADM_YES-}"
DRY=0
VERB=
FORCE=
@@ -206,7 +208,7 @@ decode_major_minor() {
# detect filesystem on the given device
# dereference device name if it is symbolic link
detect_fs() {
- test -n "$VOLUME_ORIG" || VOLUME_ORIG=$1
+ test -n "${VOLUME_ORIG-}" || VOLUME_ORIG=$1
VOLUME=${1/#"${DM_DEV_DIR}/"/}
VOLUME=$("$READLINK" $READLINK_E "$DM_DEV_DIR/$VOLUME")
test -n "$VOLUME" || error "Cannot get readlink \"$1\"."
@@ -257,11 +259,11 @@ check_valid_mounted_device() {
local MOUNTEDMAJORMINOR
local VOL
local CURNAME
- local SUGGEST="Possibly device \"$1\" has been renamed to \"$CURNAME\"?"
VOL=$("$READLINK" $READLINK_E "$1")
CURNAME=$(dmsetup info -c -j "$MAJOR" -m "$MINOR" -o name --noheadings)
# more confused, device is not DM....
+ local SUGGEST="Possibly device \"$1\" has been renamed to \"$CURNAME\"?"
test -n "$CURNAME" || SUGGEST="Mounted volume is not a device mapper device???"
test -n "$VOL" ||
@@ -270,7 +272,7 @@ check_valid_mounted_device() {
"Filesystem utilities currently do not support renamed devices."
case "$VOL" in
- # hardcoded /dev since udev does not create these entries elsewhere
+ # hardcoded /dev since kernel does not create these entries elsewhere
/dev/dm-[0-9]*)
read -r <"/sys/block/${VOL#/dev/}/dev" MOUNTEDMAJORMINOR 2>&1 || error "Cannot get major:minor for \"$VOLUME\"."
;;
@@ -674,20 +676,23 @@ resize() {
# if the size parameter is missing use device size
#if [ -n "$NEWSIZE" -a $NEWSIZE <
test -z "$NEWSIZE" && NEWSIZE=${DEVSIZE}b
- test -n "$NEWSIZE_ORIG" || NEWSIZE_ORIG=$NEWSIZE
+ NEWSIZE_ORIG=${NEWSIZE_ORIG:-$NEWSIZE}
IFS=$NL
- test -z "$DO_CRYPTRESIZE" || detect_crypt_device "$VOLUME_ORIG" "$NEWSIZE_ORIG"
- test -z "$CRYPT_GROW" || resize_crypt "$VOLUME_ORIG"
+ test -z "${DO_CRYPTRESIZE-}" || detect_crypt_device "$VOLUME_ORIG" "$NEWSIZE_ORIG"
+ test -z "${CRYPT_GROW-}" || resize_crypt "$VOLUME_ORIG"
+
case "$FSTYPE" in
- "ext3"|"ext2"|"ext4") resize_ext $NEWSIZE ;;
- "reiserfs") resize_reiser $NEWSIZE ;;
- "xfs") resize_xfs $NEWSIZE ;;
+ ext[234]) CMD=resize_ext ;;
+ "reiserfs") CMD=resize_reiser ;;
+ "xfs") CMD=resize_xfs ;;
"crypto_LUKS")
which "$CRYPTSETUP" >"$NULL" 2>&1 || error "$CRYPTSETUP utility required to resize LUKS volume"
- resize_luks $NEWSIZE ;;
+ CMD=resize_luks ;;
*) error "Filesystem \"$FSTYPE\" on device \"$VOLUME\" is not supported by this tool." ;;
- esac || error "Resize $FSTYPE failed."
- test -z "$CRYPT_SHRINK" || resize_crypt "$VOLUME_ORIG"
+ esac
+
+ $CMD $NEWSIZE || error "$FSTYPE resize failed."
+ test -z "${CRYPT_SHRINK-}" || resize_crypt "$VOLUME_ORIG"
}
####################################
@@ -716,7 +721,7 @@ check() {
fi
case "$FSTYPE" in
- "ext2"|"ext3"|"ext4")
+ ext[234])
IFS_CHECK=$IFS
IFS=$NL
for i in $(LC_ALL=C "$TUNE_EXT" -l "$VOLUME"); do
@@ -740,15 +745,15 @@ check() {
case "$FSTYPE" in
"xfs") if which "$XFS_CHECK" >"$NULL" 2>&1 ; then
- dry "$XFS_CHECK" "$VOLUME"
+ dry "$XFS_CHECK" "$VOLUME" || error "Xfs check failed."
else
# Replacement for outdated xfs_check
# FIXME: for small devices we need to force_geometry,
# since we run in '-n' mode, it shouldn't be problem.
# Think about better way....
- dry "$XFS_REPAIR" -n -o force_geometry "$VOLUME"
+ dry "$XFS_REPAIR" -n -o force_geometry "$VOLUME" || error "Xfs repair failed."
fi ;;
- "ext2"|"ext3"|"ext4"|"reiserfs")
+ ext[234]|"reiserfs")
# check if executed from interactive shell environment
case "$-" in
*i*) FLAG=$YES ;;
@@ -758,7 +763,8 @@ check() {
;;
"crypto_LUKS")
which "$CRYPTSETUP" >"$NULL" 2>&1 || error "$CRYPTSETUP utility required."
- check_luks ;;
+ check_luks || error "Crypto luks check failed."
+ ;;
*)
error "Filesystem \"$FSTYPE\" on device \"$VOLUME\" is not supported by this tool." ;;
esac
@@ -771,7 +777,7 @@ check() {
trap "cleanup 2" 2
# test if we are not invoked recursively
-test -n "$FSADM_RUNNING" && exit 0
+test -n "${FSADM_RUNNING-}" && exit 0
# test some prerequisities
for i in "$TUNE_EXT" "$RESIZE_EXT" "$TUNE_REISER" "$RESIZE_REISER" \
@@ -793,6 +799,9 @@ if [ "$#" -eq 0 ] ; then
tool_usage
fi
+CHECK=""
+RESIZE=""
+
while [ "$#" -ne 0 ]
do
case "$1" in
3 years, 6 months
stable-2.02 - fsadm: handle fsck return 1 for corrected fs
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=ab99382d7a614c299e7...
Commit: ab99382d7a614c299e765ea4d1f02fe7282502a1
Parent: ee2c80133cad75275be3d19f8c7dd6ad3b1ebd30
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sat Oct 24 00:42:31 2020 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Sat Oct 24 01:33:39 2020 +0200
fsadm: handle fsck return 1 for corrected fs
---
scripts/fsadm.sh | 25 ++++++++++++++++++-------
1 file changed, 18 insertions(+), 7 deletions(-)
diff --git a/scripts/fsadm.sh b/scripts/fsadm.sh
index b84412d92..5ca80b4dd 100755
--- a/scripts/fsadm.sh
+++ b/scripts/fsadm.sh
@@ -1,6 +1,6 @@
#!/bin/bash
#
-# Copyright (C) 2007-2017 Red Hat, Inc. All rights reserved.
+# Copyright (C) 2007-2020 Red Hat, Inc. All rights reserved.
#
# This file is part of LVM2.
#
@@ -130,7 +130,15 @@ dry() {
return 0
fi
verbose "Executing" "$@"
- "$@"
+ $@
+}
+
+# Accept as succss also return code 1 with fsck
+accept_0_1() {
+ $@
+ local ret="$?"
+ test "$ret" -eq 1 || return "$ret"
+ # Filesystem was corrected
}
cleanup() {
@@ -455,9 +463,10 @@ resize_ext() {
if test -n "$MOUNTED" ; then
# Forced fsck -f for umounted extX filesystem.
case "$-" in
- *i*) dry "$FSCK" $YES -f "$VOLUME" ;;
- *) dry "$FSCK" -f -p "$VOLUME" ;;
+ *i*) FLAG=$YES ;;
+ *) FLAG="-p" ;;
esac
+ accept_0_1 dry "$FSCK" -f $FLAG "$VOLUME" || error "Failed to fsck $VOLUME"
fi
fi
@@ -742,9 +751,11 @@ check() {
"ext2"|"ext3"|"ext4"|"reiserfs")
# check if executed from interactive shell environment
case "$-" in
- *i*) dry "$FSCK" $YES $FORCE "$VOLUME" ;;
- *) dry "$FSCK" $FORCE -p "$VOLUME" ;;
- esac ;;
+ *i*) FLAG=$YES ;;
+ *) FLAG="-p" ;;
+ esac
+ accept_0_1 dry "$FSCK" $FORCE $FLAG "$VOLUME" || error "Fsck $FSTYPE failed."
+ ;;
"crypto_LUKS")
which "$CRYPTSETUP" >"$NULL" 2>&1 || error "$CRYPTSETUP utility required."
check_luks ;;
3 years, 6 months
stable-2.02 - fsadm: use NULL
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=ee2c80133cad75275be...
Commit: ee2c80133cad75275be3d19f8c7dd6ad3b1ebd30
Parent: e478ef2f59da65ebf47ca7a1534f112669858d5a
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sat Oct 24 00:40:34 2020 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Sat Oct 24 01:33:39 2020 +0200
fsadm: use NULL
Use consistently $NULL as in other places.
---
scripts/fsadm.sh | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/scripts/fsadm.sh b/scripts/fsadm.sh
index 28ca6709f..b84412d92 100755
--- a/scripts/fsadm.sh
+++ b/scripts/fsadm.sh
@@ -233,8 +233,8 @@ validate_mounted_major_minor() {
test "$1" = "$MAJORMINOR" || {
local REFNAME
local CURNAME
- REFNAME=$(dmsetup info -c -j "${1%%:*}" -m "${1##*:}" -o name --noheadings 2>/dev/null)
- CURNAME=$(dmsetup info -c -j "$MAJOR" -m "$MINOR" -o name --noheadings 2>/dev/null)
+ REFNAME=$(dmsetup info -c -j "${1%%:*}" -m "${1##*:}" -o name --noheadings 2>"$NULL")
+ CURNAME=$(dmsetup info -c -j "$MAJOR" -m "$MINOR" -o name --noheadings 2>"$NULL")
error "Cannot ${CHECK+CHECK}${RESIZE+RESIZE} device \"$VOLUME\" without umounting filesystem $MOUNTED first." \
"Mounted filesystem is using device $CURNAME, but referenced device is $REFNAME." \
"Filesystem utilities currently do not support renamed devices."
@@ -279,7 +279,7 @@ check_valid_mounted_device() {
detect_mounted_with_proc_self_mountinfo() {
# Check self mountinfo
# grab major:minor mounted_device mount_point
- MOUNTED=$("$GREP" "^[0-9]* [0-9]* $MAJORMINOR " "$PROCSELFMOUNTINFO" 2>/dev/null | head -1)
+ MOUNTED=$("$GREP" "^[0-9]* [0-9]* $MAJORMINOR " "$PROCSELFMOUNTINFO" 2>"$NULL" | head -1)
# If device is opened and not yet found as self mounted
# check all other mountinfos (since it can be mounted in cgroups)
@@ -287,7 +287,7 @@ detect_mounted_with_proc_self_mountinfo() {
# only 1st. line is needed
test -z "$MOUNTED" &&
test "$(dmsetup info -c --noheading -o open -j "$MAJOR" -m "$MINOR")" -gt 0 &&
- MOUNTED=$(find "$PROCDIR" -maxdepth 2 -name mountinfo -print0 | xargs -0 "$GREP" "^[0-9]* [0-9]* $MAJORMINOR " 2>/dev/null | head -1 2>/dev/null)
+ MOUNTED=$(find "$PROCDIR" -maxdepth 2 -name mountinfo -print0 | xargs -0 "$GREP" "^[0-9]* [0-9]* $MAJORMINOR " 2>"$NULL" | head -1 2>"$NULL")
# TODO: for performance compare with sed and stop with 1st. match:
# sed -n "/$MAJORMINOR/ {;p;q;}"
@@ -532,7 +532,7 @@ detect_luks_device() {
CRYPT_NAME=""
CRYPT_DATA_OFFSET=""
- _LUKS_VERSION=$("$CRYPTSETUP" luksDump "$VOLUME" 2> /dev/null | "$GREP" "Version:")
+ _LUKS_VERSION=$("$CRYPTSETUP" luksDump "$VOLUME" 2>"$NULL" | "$GREP" "Version:")
if [ -z "$_LUKS_VERSION" ]; then
verbose "Failed to parse LUKS version on volume \"$VOLUME\""
@@ -541,7 +541,7 @@ detect_luks_device() {
_LUKS_VERSION=${_LUKS_VERSION//[Version:[:space:]]/}
- _LUKS_UUID=$("$CRYPTSETUP" luksDump "$VOLUME" 2> /dev/null | "$GREP" "UUID:")
+ _LUKS_UUID=$("$CRYPTSETUP" luksDump "$VOLUME" 2>"$NULL" | "$GREP" "UUID:")
if [ -z "$_LUKS_UUID" ]; then
verbose "Failed to parse LUKS UUID on volume \"$VOLUME\""
@@ -612,9 +612,9 @@ detect_crypt_device() {
local L_NEWSIZE
local TMP
- which "$CRYPTSETUP" > /dev/null 2>&1 || error "$CRYPTSETUP utility required to resize crypt device"
+ which "$CRYPTSETUP" >"$NULL" 2>&1 || error "$CRYPTSETUP utility required to resize crypt device"
- CRYPT_TYPE=$("$CRYPTSETUP" status "$1" 2> /dev/null | "$GREP" "type:")
+ CRYPT_TYPE=$("$CRYPTSETUP" status "$1" 2>"$NULL" | "$GREP" "type:")
test -n "$CRYPT_TYPE" || error "$CRYPTSETUP failed to detect device type on $1."
@@ -674,7 +674,7 @@ resize() {
"reiserfs") resize_reiser $NEWSIZE ;;
"xfs") resize_xfs $NEWSIZE ;;
"crypto_LUKS")
- which "$CRYPTSETUP" > /dev/null 2>&1 || error "$CRYPTSETUP utility required to resize LUKS volume"
+ which "$CRYPTSETUP" >"$NULL" 2>&1 || error "$CRYPTSETUP utility required to resize LUKS volume"
resize_luks $NEWSIZE ;;
*) error "Filesystem \"$FSTYPE\" on device \"$VOLUME\" is not supported by this tool." ;;
esac || error "Resize $FSTYPE failed."
@@ -746,7 +746,7 @@ check() {
*) dry "$FSCK" $FORCE -p "$VOLUME" ;;
esac ;;
"crypto_LUKS")
- which "$CRYPTSETUP" > /dev/null 2>&1 || error "$CRYPTSETUP utility required."
+ which "$CRYPTSETUP" >"$NULL" 2>&1 || error "$CRYPTSETUP utility required."
check_luks ;;
*)
error "Filesystem \"$FSTYPE\" on device \"$VOLUME\" is not supported by this tool." ;;
3 years, 6 months