Since get_persistent_dev is called in dracut-module-setup.sh and
mkdumprd, we move this lib from mkdumprd to kdump-lib.sh. Thus
dracut-module-setup.sh can use this lib, not the function in dracut.sh.
Copy the function get_persistent_dev from dracut to make the function
consistent.
Signed-off-by: Minfei Huang <mhuang(a)redhat.com>
---
dracut-module-setup.sh | 2 +-
kdump-lib.sh | 43 +++++++++++++++++++++++++++++++++++++++++++
mkdumprd | 25 ++-----------------------
3 files changed, 46 insertions(+), 24 deletions(-)
diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh
index eeb348c..efafc16 100755
--- a/dracut-module-setup.sh
+++ b/dracut-module-setup.sh
@@ -43,7 +43,7 @@ kdump_to_udev_name() {
dev=`blkid -L "${dev#LABEL=}"`
;;
esac
- echo $(get_persistent_dev "$dev")
+ echo $(get_persistent_devce "$dev")
}
kdump_is_bridge() {
diff --git a/kdump-lib.sh b/kdump-lib.sh
index e62b4e2..35aa533 100755
--- a/kdump-lib.sh
+++ b/kdump-lib.sh
@@ -86,6 +86,49 @@ get_root_fs_device()
return
}
+# get_maj_min <device>
+# Prints the major and minor of a device node.
+# Example:
+# $ get_maj_min /dev/sda2
+# 8:2
+get_maj_min() {
+ local _maj _min _majmin
+ _majmin="$(stat -L -c '%t:%T' "$1" 2>/dev/null)"
+ printf "%s" "$((0x${_majmin%:*})):$((0x${_majmin#*:}))"
+}
+
+get_persistent_devce() {
+ local i _tmp _dev
+
+ _dev=$(get_maj_min "$1")
+ [ -z "$_dev" ] && {
+ perror_exit "Kernel dev name of $1 is not found."
+ }
+
+ for i in \
+ /dev/mapper/* \
+ /dev/disk/${persistent_policy:-by-uuid}/* \
+ /dev/disk/by-uuid/* \
+ /dev/disk/by-label/* \
+ /dev/disk/by-partuuid/* \
+ /dev/disk/by-partlabel/* \
+ /dev/disk/by-id/* \
+ /dev/disk/by-path/* \
+ ; do
+ [[ -e "$i" ]] || continue
+ [[ $i == /dev/mapper/control ]] && continue
+ [[ $i == /dev/mapper/mpath* ]] && continue
+ _tmp=$(get_maj_min "$i")
+ if [ "$_tmp" = "$_dev" ]; then
+ echo $i
+ return
+ fi
+ done
+
+ perror "WARNING: Persistent device name of $1 not found. Using $1 as dump target name"
+ echo $1
+}
+
# findmnt uses the option "-v, --nofsroot" to exclusive the [/dir]
# in the SOURCE column for bind-mounts, then if $_mntpoint equals to
# $_mntpoint_nofsroot, the mountpoint is not bind mounted directory.
diff --git a/mkdumprd b/mkdumprd
index 28ecdd7..ac8a63a 100644
--- a/mkdumprd
+++ b/mkdumprd
@@ -29,26 +29,6 @@ perror() {
echo $@ >&2
}
-get_persistent_dev() {
- local i _tmp _dev
-
- _dev=$(udevadm info --query=name --name="$1" 2>/dev/null)
- [ -z "$_dev" ] && {
- perror_exit "Kernel dev name of $1 is not found."
- }
-
- for i in /dev/mapper/* /dev/disk/by-uuid/* /dev/disk/by-id/*; do
- _tmp=$(udevadm info --query=name --name="$i" 2>/dev/null)
- if [ "$_tmp" = "$_dev" ]; then
- echo $i
- return
- fi
- done
-
- perror "WARNING: Persistent device name of $1 not found. Using $1 as dump target name"
- echo $1
-}
-
add_dracut_arg() {
local arg qarg is_quoted=0
while [ $# -gt 0 ];
@@ -138,11 +118,10 @@ to_mount() {
_mntopts="$_target $_fstype $_options"
#for non-nfs _dev converting to use udev persistent name
if [ -b "$_source" ]; then
- _pdev="$(get_persistent_dev $_source)"
+ _pdev="$(get_persistent_devce $_source)"
if [ $? -ne 0 ]; then
return 1
fi
-
else
_pdev=$_dev
fi
@@ -565,7 +544,7 @@ do
dd if=$config_val count=1 of=/dev/null > /dev/null 2>&1 || {
perror_exit "Bad raw disk $config_val"
}
- _praw=$(get_persistent_dev $config_val)
+ _praw=$(get_persistent_devce $config_val)
if [ $? -ne 0 ]; then
exit 1
fi
--
2.1.0