Skip to content

Commit

Permalink
Better is_multipath_path function (issue #2298) plus lsblk output as …
Browse files Browse the repository at this point in the history
…disklayout.conf header plus TODO comments in layout/prepare/default/010_prepare_files.sh
  • Loading branch information
jsmeix committed Dec 11, 2019
1 parent c3886c8 commit 0bdd428
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 29 deletions.
35 changes: 19 additions & 16 deletions usr/share/rear/layout/prepare/default/010_prepare_files.sh
Expand Up @@ -11,37 +11,40 @@ LUN_WWID_MAP="$VAR_DIR/layout/lun_wwid_mapping"

# Touchfiles for layout recreation.
LAYOUT_TOUCHDIR="$TMP_DIR/touch"
if [ -e $LAYOUT_TOUCHDIR ] ; then
rm -rf $LAYOUT_TOUCHDIR
fi
test -e $LAYOUT_TOUCHDIR && rm -rf $LAYOUT_TOUCHDIR
mkdir -p $LAYOUT_TOUCHDIR

if [ -e $LAYOUT_FILE ] ; then
save_original_file $LAYOUT_FILE
fi
test -e $LAYOUT_FILE && save_original_file $LAYOUT_FILE

if [ -e $CONFIG_DIR/disklayout.conf ] ; then
if test -e $CONFIG_DIR/disklayout.conf ; then
cp $CONFIG_DIR/disklayout.conf $LAYOUT_FILE
# Only set MIGRATION_MODE if not already set (could be already specified by the user):
if ! test "$MIGRATION_MODE" ; then
MIGRATION_MODE='true'
LogPrint "Switching to manual disk layout configuration ($CONFIG_DIR/disklayout.conf exists)"
fi

if [ -e $CONFIG_DIR/lun_wwid_mapping.conf ] ; then
# For the LUN WWIDs migration code see finalize/GNU/Linux/250_migrate_lun_wwid.sh
# TODO: Why are LUN WWIDs migrated only if also $CONFIG_DIR/disklayout.conf exists?
# Why are LUN WWIDs not always migrated when only $CONFIG_DIR/lun_wwid_mapping.conf exists?
# That part was added by
# https://github.com/rear/rear/commit/e822ad69a8ce8dec6132741806008db9c6c3b429
# but there is no comment that explains why LUN WWIDs migration happens
# only if also $CONFIG_DIR/disklayout.conf exists.
if test -e $CONFIG_DIR/lun_wwid_mapping.conf ; then
cp $CONFIG_DIR/lun_wwid_mapping.conf $LUN_WWID_MAP
LogPrint "$CONFIG_DIR/lun_wwid_mapping.conf exists, creating lun_wwid_mapping"
LogPrint "Will migrate LUN WWIDs after backup restore ($CONFIG_DIR/lun_wwid_mapping.conf exists)"
fi
fi

if [ ! -e $LAYOUT_FILE ] ; then
Log "Disklayout file does not exist, creating empty file."
if ! test -e $LAYOUT_FILE ; then
# TODO: This script layout/prepare/default/010_prepare_files.sh is only run during "rear recover"
# and I <jsmeix@suse.de> wonder if "rear recover" can work at all without a disklayout.conf file?
LogPrint "$LAYOUT_FILE file does not exist, creating empty file"
: > $LAYOUT_FILE
fi

if [ -e $FS_UUID_MAP ] ; then
rm -f $FS_UUID_MAP # Make sure old data is deleted.
fi

# Make sure old data is deleted:
test -e $FS_UUID_MAP && rm -f $FS_UUID_MAP
: > $LAYOUT_TODO
: > $LAYOUT_DEPS

41 changes: 29 additions & 12 deletions usr/share/rear/layout/save/GNU/Linux/100_create_layout_file.sh
@@ -1,23 +1,39 @@
# Create the layout file

LogPrint "Creating disk layout"
Log "Preparing layout directory."
mkdir -p $v $VAR_DIR/layout >&2
mkdir -p $v $VAR_DIR/recovery >&2
mkdir -p $v $VAR_DIR/layout/config >&2

# We need directory for XFS options only if XFS is in use
if [ -n "$(mount -t xfs)" ]; then
Log "Creating layout directories (when not existing)"
mkdir -p $v $VAR_DIR/layout
mkdir -p $v $VAR_DIR/recovery
mkdir -p $v $VAR_DIR/layout/config

# We need directory for XFS options only if XFS is in use:
if test "$( mount -t xfs )" ; then
LAYOUT_XFS_OPT_DIR="$VAR_DIR/layout/xfs"
mkdir -p $v $LAYOUT_XFS_OPT_DIR >&2
mkdir -p $v $LAYOUT_XFS_OPT_DIR
fi

DISKLAYOUT_FILE=${DISKLAYOUT_FILE:-$VAR_DIR/layout/disklayout.conf}
# Use exiting DISKLAYOUT_FILE value or use the default:
test "$DISKLAYOUT_FILE" || DISKLAYOUT_FILE=$VAR_DIR/layout/disklayout.conf

if [ -e "$DISKLAYOUT_FILE" ] ; then
Log "Removing old layout file."
fi
: > $DISKLAYOUT_FILE
# Inform the user (he may have specified his DISKLAYOUT_FILE value, see above):
test -e "$DISKLAYOUT_FILE" && LogPrint "Overwriting existing disk layout file $DISKLAYOUT_FILE"

# Initialize disklayout.conf:
# See lib/layout-functions.sh how DATE is set: DATE=$( date +%Y%m%d%H%M%S )
echo "Disk layout dated $DATE (YYYYmmddHHMMSS)" >$DISKLAYOUT_FILE
# Have the actual storage layout as header comment in disklayout.conf
# so that it is easier to make sense of the values in the subsequent entries.
# First try the command
# lsblk -ipo NAME,KNAME,PKNAME,TRAN,TYPE,FSTYPE,SIZE,MOUNTPOINT
# but on older systems (like SLES11) that do not support all that lsblk things
# try the simpler command
# lsblk -io NAME,KNAME,FSTYPE,SIZE,MOUNTPOINT
# and as fallback try 'lsblk -i' and finally try plain 'lsblk'.
# When there is no 'lsblk' command there is no output (bad luck, no harm):
{ lsblk -ipo NAME,KNAME,PKNAME,TRAN,TYPE,FSTYPE,SIZE,MOUNTPOINT || lsblk -io NAME,KNAME,FSTYPE,SIZE,MOUNTPOINT || lsblk -i || lsblk ; } >>$DISKLAYOUT_FILE
# Make all lines in disklayout.conf up to now as header comments:
sed -i -e 's/^/# /' $DISKLAYOUT_FILE

LAYOUT_FILE="$DISKLAYOUT_FILE"
LAYOUT_DEPS="$VAR_DIR/layout/diskdeps.conf"
Expand All @@ -30,3 +46,4 @@ LAYOUT_TODO="$VAR_DIR/layout/disktodo.conf"
# $LAYOUT_TODO is a list of:
# [todo|done] <type> <item>
: > $LAYOUT_TODO

11 changes: 10 additions & 1 deletion usr/share/rear/lib/layout-functions.sh
Expand Up @@ -693,7 +693,16 @@ is_disk_a_pv() {
}

function is_multipath_path {
[ "$1" ] && type multipath &>/dev/null && multipath -c /dev/$1 &>/dev/null
# Return 'false' if there is no device as argument:
test "$1" || return 1
# Return 'false' if there is no multipath command:
type multipath &>/dev/null || return 1
# Return 'false' if multipath is not used.
# Because "multipath -l" always returns zero exit code we check if it has real output
# and we do this via "grep -q" so that no "multipath -l" output appears in the log:
multipath -l | grep -q '[[:alnum:]]' || return 1
# Check if a block device should be a path in a multipath device:
multipath -c /dev/$1 &>/dev/null
}

# retry_command () is binded with REAR_SLEEP_DELAY and REAR_MAX_RETRIES.
Expand Down

0 comments on commit 0bdd428

Please sign in to comment.