We maintained kdump specific get persistent dev function, it is ready to drop it. Dracut upstream splitted dracut init stuff from dracut-functions.sh so that we can source it.
OTOH, dracut now has a persistent_policy feature, for kdump when we dump to raw disks we do not care the filesystem uuid and labels so we prefer to search disk id instead. For raw disk set the persistent_policy before calling get_persistent_dev ensure kdump logic still work.
Tested filesystem and raw dump in kvm guests.
[Xunlei: Also drop get_maj_min, dracut-functions.sh also has such a function.]
Signed-off-by: Dave Young dyoung@redhat.com --- kdump-lib.sh | 26 -------------------------- kdumpctl | 8 +++++++- mkdumprd | 22 ++++++---------------- 3 files changed, 13 insertions(+), 43 deletions(-)
--- kexec-tools.orig/kdump-lib.sh +++ kexec-tools/kdump-lib.sh @@ -88,32 +88,6 @@ to_dev_name() { echo $dev }
-kdump_get_persistent_dev() { - local i _tmp _dev _lookup_dirs - - _dev=$(udevadm info --query=name --name="$1" 2>/dev/null) - [ -z "$_dev" ] && { - perror_exit "Kernel dev name of $1 is not found." - } - - if [[ $2 = "raw" ]];then - _lookup_dirs="/dev/mapper/* /dev/disk/by-id/*" - else - _lookup_dirs="/dev/mapper/* /dev/disk/by-uuid/* /dev/disk/by-id/*" - fi - - for i in $_lookup_dirs; 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 -} - get_user_configured_dump_disk() { local _target --- kexec-tools.orig/kdumpctl +++ kexec-tools/kdumpctl @@ -19,6 +19,8 @@ FADUMP_REGISTER_SYS_NODE="/sys/kernel/fa DEFAULT_DUMP_MODE="kdump" image_time=0
+[[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut +. $dracutbasedir/dracut-functions.sh . /lib/kdump/kdump-lib.sh
standard_kexec_args="-p" @@ -432,7 +434,11 @@ check_dump_fs_modified() if [[ $(expr substr $_new_fstype 1 3) = "nfs" ]];then _new_dev=$_target else - _new_dev=$(kdump_get_persistent_dev $_target $_new_fstype) + _new_dev=$(get_persistent_dev $_target) + if [ -z "$_new_dev" ]; then + echo "Get persistent device name failed" + return 2 + fi fi
if ! findmnt $_target >/dev/null; then --- kexec-tools.orig/mkdumprd +++ kexec-tools/mkdumprd @@ -6,6 +6,8 @@ # Written by Cong Wang amwang@redhat.com #
+[[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut +. $dracutbasedir/dracut-functions.sh . /lib/kdump/kdump-lib.sh export IN_KDUMP=1
@@ -127,8 +129,8 @@ to_mount() { _mntopts="$_target $_fstype $_options" #for non-nfs _dev converting to use udev persistent name if [ -b "$_source" ]; then - _pdev="$(kdump_get_persistent_dev $_source $_fstype)" - if [ $? -ne 0 ]; then + _pdev="$(get_persistent_dev $_source)" + if [ -z "$_pdev" ]; then return 1 fi
@@ -257,18 +259,6 @@ add_mount() { fi }
-# 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 _dev - _dev=$(stat -L -c '$((0x%t)):$((0x%T))' "$1" 2>/dev/null) - _dev=$(eval "echo $_dev") - echo $_dev -} - # ugly workaround for the lvm design # There is no volume group device, # so, there are no slave devices for volume groups. @@ -532,8 +522,8 @@ do dd if=$config_val count=1 of=/dev/null > /dev/null 2>&1 || { perror_exit "Bad raw disk $config_val" } - _praw=$(kdump_get_persistent_dev $config_val "raw") - if [ $? -ne 0 ]; then + _praw=$(persistent_policy="by-id" get_persistent_dev $config_val) + if [ -z "$_praw" ]; then exit 1 fi add_dracut_arg "--device" "$_praw"
On 2016/11/14 at 13:12, Dave Young wrote:
We maintained kdump specific get persistent dev function, it is ready to drop it. Dracut upstream splitted dracut init stuff from dracut-functions.sh so that we can source it.
OTOH, dracut now has a persistent_policy feature, for kdump when we dump to raw disks we do not care the filesystem uuid and labels so we prefer to search disk id instead. For raw disk set the persistent_policy before calling get_persistent_dev ensure kdump logic still work.
Tested filesystem and raw dump in kvm guests.
[Xunlei: Also drop get_maj_min, dracut-functions.sh also has such a function.]
Signed-off-by: Dave Young dyoung@redhat.com
kdump-lib.sh | 26 -------------------------- kdumpctl | 8 +++++++- mkdumprd | 22 ++++++---------------- 3 files changed, 13 insertions(+), 43 deletions(-)
--- kexec-tools.orig/kdump-lib.sh +++ kexec-tools/kdump-lib.sh @@ -88,32 +88,6 @@ to_dev_name() { echo $dev }
-kdump_get_persistent_dev() {
- local i _tmp _dev _lookup_dirs
- _dev=$(udevadm info --query=name --name="$1" 2>/dev/null)
- [ -z "$_dev" ] && {
perror_exit "Kernel dev name of $1 is not found."
- }
- if [[ $2 = "raw" ]];then
- _lookup_dirs="/dev/mapper/* /dev/disk/by-id/*"
- else
- _lookup_dirs="/dev/mapper/* /dev/disk/by-uuid/* /dev/disk/by-id/*"
- fi
- for i in $_lookup_dirs; 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
-}
get_user_configured_dump_disk() { local _target --- kexec-tools.orig/kdumpctl +++ kexec-tools/kdumpctl @@ -19,6 +19,8 @@ FADUMP_REGISTER_SYS_NODE="/sys/kernel/fa DEFAULT_DUMP_MODE="kdump" image_time=0
+[[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut +. $dracutbasedir/dracut-functions.sh . /lib/kdump/kdump-lib.sh
standard_kexec_args="-p" @@ -432,7 +434,11 @@ check_dump_fs_modified() if [[ $(expr substr $_new_fstype 1 3) = "nfs" ]];then _new_dev=$_target else
_new_dev=$(kdump_get_persistent_dev $_target $_new_fstype)
_new_dev=$(get_persistent_dev $_target)
if [ -z "$_new_dev" ]; then
Hi Dave,
I did some quick tests, although I didn't see any problem caused for kexec-tools, seems that get_maj_min() doesn't return empty value: get_maj_min() { local _maj _min _majmin _majmin="$(stat -L -c '%t:%T' "$1" 2>/dev/null)" printf "%s" "$((0x${_majmin%:*})):$((0x${_majmin#*:}))" }
We can see that, it always returns "0:0" in case of non-existent device, and get_persistent_dev() will return the non-existent device name input.
Regards, Xunlei
echo "Get persistent device name failed"
return 2
fi
fi
if ! findmnt $_target >/dev/null; then
--- kexec-tools.orig/mkdumprd +++ kexec-tools/mkdumprd @@ -6,6 +6,8 @@ # Written by Cong Wang amwang@redhat.com #
+[[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut +. $dracutbasedir/dracut-functions.sh . /lib/kdump/kdump-lib.sh export IN_KDUMP=1
@@ -127,8 +129,8 @@ to_mount() { _mntopts="$_target $_fstype $_options" #for non-nfs _dev converting to use udev persistent name if [ -b "$_source" ]; then
_pdev="$(kdump_get_persistent_dev $_source $_fstype)"
if [ $? -ne 0 ]; then
_pdev="$(get_persistent_dev $_source)"
if [ -z "$_pdev" ]; then return 1 fi
@@ -257,18 +259,6 @@ add_mount() { fi }
-# 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 _dev
- _dev=$(stat -L -c '$((0x%t)):$((0x%T))' "$1" 2>/dev/null)
- _dev=$(eval "echo $_dev")
- echo $_dev
-}
# ugly workaround for the lvm design # There is no volume group device, # so, there are no slave devices for volume groups. @@ -532,8 +522,8 @@ do dd if=$config_val count=1 of=/dev/null > /dev/null 2>&1 || { perror_exit "Bad raw disk $config_val" }
_praw=$(kdump_get_persistent_dev $config_val "raw")
if [ $? -ne 0 ]; then
_praw=$(persistent_policy="by-id" get_persistent_dev $config_val)
if [ -z "$_praw" ]; then exit 1 fi add_dracut_arg "--device" "$_praw"
On 11/14/16 at 02:46pm, Xunlei Pang wrote:
On 2016/11/14 at 13:12, Dave Young wrote:
We maintained kdump specific get persistent dev function, it is ready to drop it. Dracut upstream splitted dracut init stuff from dracut-functions.sh so that we can source it.
OTOH, dracut now has a persistent_policy feature, for kdump when we dump to raw disks we do not care the filesystem uuid and labels so we prefer to search disk id instead. For raw disk set the persistent_policy before calling get_persistent_dev ensure kdump logic still work.
Tested filesystem and raw dump in kvm guests.
[Xunlei: Also drop get_maj_min, dracut-functions.sh also has such a function.]
Signed-off-by: Dave Young dyoung@redhat.com
kdump-lib.sh | 26 -------------------------- kdumpctl | 8 +++++++- mkdumprd | 22 ++++++---------------- 3 files changed, 13 insertions(+), 43 deletions(-)
--- kexec-tools.orig/kdump-lib.sh +++ kexec-tools/kdump-lib.sh @@ -88,32 +88,6 @@ to_dev_name() { echo $dev }
-kdump_get_persistent_dev() {
- local i _tmp _dev _lookup_dirs
- _dev=$(udevadm info --query=name --name="$1" 2>/dev/null)
- [ -z "$_dev" ] && {
perror_exit "Kernel dev name of $1 is not found."
- }
- if [[ $2 = "raw" ]];then
- _lookup_dirs="/dev/mapper/* /dev/disk/by-id/*"
- else
- _lookup_dirs="/dev/mapper/* /dev/disk/by-uuid/* /dev/disk/by-id/*"
- fi
- for i in $_lookup_dirs; 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
-}
get_user_configured_dump_disk() { local _target --- kexec-tools.orig/kdumpctl +++ kexec-tools/kdumpctl @@ -19,6 +19,8 @@ FADUMP_REGISTER_SYS_NODE="/sys/kernel/fa DEFAULT_DUMP_MODE="kdump" image_time=0
+[[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut +. $dracutbasedir/dracut-functions.sh . /lib/kdump/kdump-lib.sh
standard_kexec_args="-p" @@ -432,7 +434,11 @@ check_dump_fs_modified() if [[ $(expr substr $_new_fstype 1 3) = "nfs" ]];then _new_dev=$_target else
_new_dev=$(kdump_get_persistent_dev $_target $_new_fstype)
_new_dev=$(get_persistent_dev $_target)
if [ -z "$_new_dev" ]; then
Hi Dave,
I did some quick tests, although I didn't see any problem caused for kexec-tools, seems that get_maj_min() doesn't return empty value: get_maj_min() { local _maj _min _majmin _majmin="$(stat -L -c '%t:%T' "$1" 2>/dev/null)" printf "%s" "$((0x${_majmin%:*})):$((0x${_majmin#*:}))" }
We can see that, it always returns "0:0" in case of non-existent device, and get_persistent_dev() will return the non-existent device name input.
We do not check the return value, just leave the caller to handle it later. Since the caller are copied from dracut so it should be fine.
Regards, Xunlei
echo "Get persistent device name failed"
return 2
fi
fi
if ! findmnt $_target >/dev/null; then
--- kexec-tools.orig/mkdumprd +++ kexec-tools/mkdumprd @@ -6,6 +6,8 @@ # Written by Cong Wang amwang@redhat.com #
+[[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut +. $dracutbasedir/dracut-functions.sh . /lib/kdump/kdump-lib.sh export IN_KDUMP=1
@@ -127,8 +129,8 @@ to_mount() { _mntopts="$_target $_fstype $_options" #for non-nfs _dev converting to use udev persistent name if [ -b "$_source" ]; then
_pdev="$(kdump_get_persistent_dev $_source $_fstype)"
if [ $? -ne 0 ]; then
_pdev="$(get_persistent_dev $_source)"
if [ -z "$_pdev" ]; then return 1 fi
@@ -257,18 +259,6 @@ add_mount() { fi }
-# 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 _dev
- _dev=$(stat -L -c '$((0x%t)):$((0x%T))' "$1" 2>/dev/null)
- _dev=$(eval "echo $_dev")
- echo $_dev
-}
# ugly workaround for the lvm design # There is no volume group device, # so, there are no slave devices for volume groups. @@ -532,8 +522,8 @@ do dd if=$config_val count=1 of=/dev/null > /dev/null 2>&1 || { perror_exit "Bad raw disk $config_val" }
_praw=$(kdump_get_persistent_dev $config_val "raw")
if [ $? -ne 0 ]; then
_praw=$(persistent_policy="by-id" get_persistent_dev $config_val)
if [ -z "$_praw" ]; then exit 1 fi add_dracut_arg "--device" "$_praw"