[PATCH] module-setup: Fix improper dns setup in kdump_setup_dns()
by Xunlei Pang
Current implementation of kdump_setup_dns() get the dns
from interface's ifcfg file first, then parse those in
"/etc/resolv.conf". For example, DNS1 in ifcfg file along
with dhcp, the final dns(/etc/resolv.conf) in 1st system
will be like(dhcp first, then ifcfg file appending end):
dhcp dns1
dhcp dns2
dhcp dns3
DNS1 in ifcfg
After parsing, the dns(/etc/cmdline.d/42dns.conf) in kdump
system will be like:
DNS1 in ifcfg
dhcp dns1
dhcp dns2
dhcp dns3
DNS1 in ifcfg
There are two issues by doing this:
1) The dns sequence is different from that in 1st system.
2) There are some duplicated items.
NOTE: kdump_setup_dns() meant to avoid the duplication,
but the original shell command is actually disfunctional:
"[ ! $(cat $_dnsfile | grep -q $_dns) ]" (always true)
Fix the issues by firstly parsing "/etc/resolv.conf", then
parsing ifcfg file, finally delete the duplicated items.
Signed-off-by: Xunlei Pang <xlpang(a)redhat.com>
---
dracut-module-setup.sh | 27 ++++++++++++++++-----------
1 file changed, 16 insertions(+), 11 deletions(-)
diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh
index 350864e..b7763f7 100755
--- a/dracut-module-setup.sh
+++ b/dracut-module-setup.sh
@@ -68,14 +68,6 @@ kdump_setup_dns() {
local _dnsfile=${initdir}/etc/cmdline.d/42dns.conf
local ifcfg_file
- ifcfg_file=$(get_ifcfg_filename $1)
- if [ -f "${ifcfg_file}" ]; then
- . ${ifcfg_file}
- fi
-
- [ -n "$DNS1" ] && echo "nameserver=$DNS1" > "$_dnsfile"
- [ -n "$DNS2" ] && echo "nameserver=$DNS2" >> "$_dnsfile"
-
while read content;
do
_nameserver=$(echo $content | grep ^nameserver)
@@ -84,10 +76,23 @@ kdump_setup_dns() {
_dns=$(echo $_nameserver | cut -d' ' -f2)
[ -z "$_dns" ] && continue
- if [ ! -f $_dnsfile ] || [ ! $(cat $_dnsfile | grep -q $_dns) ]; then
- echo "nameserver=$_dns" >> "$_dnsfile"
- fi
+ echo "nameserver=$_dns" >> "$_dnsfile"
done < "/etc/resolv.conf"
+
+ unset DNS1 DNS2
+ ifcfg_file=$(get_ifcfg_filename $1)
+ if [ -f "${ifcfg_file}" ]; then
+ . ${ifcfg_file}
+ fi
+
+ [ -n "$DNS1" ] && echo "nameserver=$DNS1" >> "$_dnsfile"
+ [ -n "$DNS2" ] && echo "nameserver=$DNS2" >> "$_dnsfile"
+
+ # Delete duplicated lines
+ if [ -f "$_dnsfile" ]; then
+ awk '!a[$0]++' $_dnsfile > $_dnsfile.tmp
+ mv -f $_dnsfile.tmp $_dnsfile
+ fi
}
#$1: netdev name
--
1.8.3.1
7 years, 11 months
[PATCH v3 1/2] kdump-lib: Add get_ifcfg_filename() to get the proper ifcfg file
by Xunlei Pang
Previously, we assumed the ifcfg file of a network "interface" is
"/etc/sysconfig/network-scripts/ifcfg-<interface>", but actually
it is not the case.
For example, for network interface "enp0s25", we are able to
generate like "/etc/sysconfig/network-scripts/ifcfg-enp0s25-test"
for it via network-manger.
The "suffix" in "ifcfg-<suffix>" is actually a "configuration"
name not "interface" name, though normally we use the "interface"
name as its "configuration" name. You can refer to "man ifup"
for some detail.
So, this patch adds some assistant helpers to acquire the right
ifcfg file for an interface. Borrow some logic from script below:
"/etc/sysconfig/network-scripts/network-functions"
Signed-off-by: Xunlei Pang <xlpang(a)redhat.com>
---
kdump-lib.sh | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 89 insertions(+)
diff --git a/kdump-lib.sh b/kdump-lib.sh
index 4d34206..20ec525 100755
--- a/kdump-lib.sh
+++ b/kdump-lib.sh
@@ -230,3 +230,92 @@ is_hostname()
fi
echo $1 | grep -q "[a-zA-Z]"
}
+
+get_hwaddr()
+{
+ if [ -f "/sys/class/net/${1}/address" ]; then
+ awk '{ print toupper($0) }' < /sys/class/net/${1}/address
+ elif [ -d "/sys/class/net/${1}" ]; then
+ ip -o link show ${1} 2>/dev/null | \
+ awk '{ print toupper(gensub(/.*link\/[^ ]* ([[:alnum:]:]*).*/,
+ "\\1", 1)); }'
+ fi
+}
+
+get_ifcfg_by_device()
+{
+ grep -E -i -l "^[[:space:]]*DEVICE=\"*${1}\"*[[:space:]]*$" \
+ /etc/sysconfig/network-scripts/ifcfg-* 2>/dev/null | head -1
+}
+
+get_ifcfg_by_hwaddr()
+{
+ grep -E -i -l "^[[:space:]]*HWADDR=\"*${1}\"*[[:space:]]*$" 2>/dev/null \
+ /etc/sysconfig/network-scripts/ifcfg-* | head -1
+}
+
+get_ifcfg_by_name()
+{
+ grep -E -i -l "^[[:space:]]*NAME=\"*${1}\"*[[:space:]]*$" 2>/dev/null \
+ /etc/sysconfig/network-scripts/ifcfg-* | head -1
+}
+
+is_nm_running()
+{
+ [ "$(LANG=C nmcli -t --fields running general status 2>/dev/null)" = "running" ]
+}
+
+# $1: netdev name
+get_ifcfg_nmcli()
+{
+ local nm_name
+ local ifcfg_file
+
+ # Get the active nmcli config name of $1
+ if [[ is_nm_running ]]; then
+ # The configuration name generated by nm is wrote to the ifcfg file
+ # as "NAME=<nm_name>".
+ nm_name=$(nmcli d show $1 2>/dev/null |grep GENERAL.CONNECTION \
+ |sed -e 's/GENERAL.CONNECTION: *//')
+ if [[ "${nm_name}" && "${nm_name}" != "--" ]]; then
+ ifcfg_file=$(get_ifcfg_by_name ${nm_name})
+ fi
+ fi
+
+ echo -n ${ifcfg_file}
+}
+
+# $1: netdev name
+get_ifcfg_legacy()
+{
+ local ifcfg_file
+
+ ifcfg_file="/etc/sysconfig/network-scripts/ifcfg-${1}"
+ [ -f "${ifcfg_file}" ] && echo -n "${ifcfg_file}" && return
+
+ ifcfg_file=$(get_ifcfg_by_name "${1}")
+ [ -f "${ifcfg_file}" ] && echo -n "${ifcfg_file}" && return
+
+ local hwaddr=$(get_hwaddr ${1})
+ if [ -n "$hwaddr" ]; then
+ ifcfg_file=$(get_ifcfg_by_hwaddr ${hwaddr})
+ [ -f "${ifcfg_file}" ] && echo -n "${ifcfg_file}" && return
+ fi
+
+ ifcfg_file=$(get_ifcfg_by_device ${1})
+
+ echo -n "${ifcfg_file}"
+}
+
+# $1: netdev name
+# Return the ifcfg file whole name(including the path) of $1 if any.
+get_ifcfg_filename() {
+ local ifcfg_file
+
+ ifcfg_file=$(get_ifcfg_nmcli $1)
+ if [ -z "${ifcfg_file}" ]; then
+ ifcfg_file=$(get_ifcfg_legacy $1)
+ fi
+
+ echo -n "${ifcfg_file}"
+}
--
1.8.3.1
7 years, 11 months
[PATCH V3 0/4] kdumpctl: force rebuild when dump target is modified
by Pratyush Anand
When dump target is re-formatted then its UUID changes. These patches add
support to recognize such changes and then force initramfs rebuild, if
dracut argument has an UUID based root location.
Changes since v2:
-- now is_system_modified returns 2 in case of invalid modification, 1 in
case of valid modification and 0 in case of no modification.
-- file modification check has been moved to is_system_modified now
-- variables have been put under "" in if condition check
Changes since v1:
-- Local variable is defined in shell function now
-- raw target does not take persistent names "by-uuid" now
-- dracut arguments grep is more robust
-- When no UUID then warn and return
Pratyush Anand (4):
mkdumprd: do not lookup in by-uuid dirs for raw device's persistent
name
kdumpctl: force rebuild in case of dynamic system modification
kdumpctl: Move file modification check logic in is_system_modified()
kdumpctl: force rebuild in case of dump target modification
kdumpctl | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++------------
mkdumprd | 14 +++++---
2 files changed, 110 insertions(+), 27 deletions(-)
--
2.5.0
7 years, 11 months
[PATCH] kdumpctl: Do not rebuild initramfs when $KDUMP_BOOTDIR is read only
by Pratyush Anand
When $KDUMP_BOOTDIR is RO then kexec-tools should not try rebuild initramfs
even when conditions for rebuild is met.
Signed-off-by: Pratyush Anand <panand(a)redhat.com>
---
kdumpctl | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/kdumpctl b/kdumpctl
index 5c1d6a421d79..794a891d2c5c 100755
--- a/kdumpctl
+++ b/kdumpctl
@@ -489,6 +489,11 @@ check_rebuild()
return 0
fi
+ if [[ ! -w "$KDUMP_BOOTDIR" ]];then
+ echo "$KDUMP_BOOTDIR does not have write permission. Can not rebuild $TARGET_INITRD"
+ return 1
+ fi
+
echo "Rebuilding $TARGET_INITRD"
rebuild_initrd
return $?
--
2.5.0
7 years, 11 months
[PATCH V2 0/3] kdumpctl: force rebuild when dump target is modified
by Pratyush Anand
When dump target is re-formatted then its UUID changes. These patches add
support to recognize such changes and then force initramfs rebuild, if
dracut argument has an UUID based root location.
Changes since v1:
-- Local variable is defined in shell function now
-- raw target does not take persistent names "by-uuid" now
-- dracut arguments grep is more robust
-- When no UUID then warn and return
Pratyush Anand (3):
mkdumprd: do not lookup in by-uuid dirs for raw device's persistent
name
kdumpctl: force rebuild in case of dynamic system modification
kdumpctl: force rebuild in case of dump target modification
kdumpctl | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
mkdumprd | 14 ++++++++++----
2 files changed, 60 insertions(+), 4 deletions(-)
--
2.5.0
7 years, 11 months
[PATCH v2 1/2] kdump-lib: Add get_ifcfg_filename() to get the proper ifcfg file
by Xunlei Pang
Previously, we assumed the ifcfg of a network "interface" is
"/etc/sysconfig/network-scripts/ifcfg-<interface>", but actually
it is not the case.
For example, for network interface "enp0s25", we are able to
generate like "/etc/sysconfig/network-scripts/ifcfg-enp0s25-test"
for it via network-manger.
The "suffix" in "ifcfg-<suffix>" is actually a "configuration"
name not a "interface" name, though normally we use "interface"
name as its "configuration" name. You can refer to "man ifup"
for the detail.
So, this patch adds some assistant functions to acquire the right
ifcfg file for an interface. Get some help from the following script:
"/etc/sysconfig/network-scripts/network-functions"
Signed-off-by: Xunlei Pang <xlpang(a)redhat.com>
---
kdump-lib.sh | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 93 insertions(+)
diff --git a/kdump-lib.sh b/kdump-lib.sh
index 4d34206..5277966 100755
--- a/kdump-lib.sh
+++ b/kdump-lib.sh
@@ -230,3 +230,96 @@ is_hostname()
fi
echo $1 | grep -q "[a-zA-Z]"
}
+
+get_hwaddr()
+{
+ if [ -f /sys/class/net/${1}/address ]; then
+ awk '{ print toupper($0) }' < /sys/class/net/${1}/address
+ elif [ -d "/sys/class/net/${1}" ]; then
+ ip -o link show ${1} 2>/dev/null | \
+ awk '{ print toupper(gensub(/.*link\/[^ ]* ([[:alnum:]:]*).*/,
+ "\\1", 1)); }'
+ fi
+}
+
+get_config_by_device()
+{
+ grep -E -i -l "^[[:space:]]*DEVICE=${1}" \
+ /etc/sysconfig/network-scripts/ifcfg-* | head -1
+}
+
+get_config_by_hwaddr()
+{
+ grep -E -i -l "^[[:space:]]*HWADDR=${1}" \
+ /etc/sysconfig/network-scripts/ifcfg-* | head -1
+}
+
+get_config_by_name()
+{
+ grep -E -i -l "^[[:space:]]*NAME=${1}" \
+ /etc/sysconfig/network-scripts/ifcfg-* | head -1
+}
+
+is_nm_running ()
+{
+ [ "$(LANG=C nmcli -t --fields running general status 2>/dev/null)" = "running" ]
+}
+
+# $1: netdev name
+get_ifcfg_nmcli()
+{
+ local nm_name
+ local ifcfg_file
+
+ # Get the active nmcli config name of $1
+ if [[ -x /usr/bin/nmcli && is_nm_running ]]; then
+ # The configuration name generated by nm is wrote to the ifcfg file
+ # as "NAME=<nm_name>", if <nm_name> contains whitespaces, a pair of
+ # quote will also be added(i.e. NAME="My Test").
+ nm_name=$(nmcli d show $1 2>/dev/null |grep GENERAL.CONNECTION \
+ |sed -e 's/GENERAL.CONNECTION: *//')
+ if [[ ${nm_name} && ${nm_name} != "--" ]]; then
+ # Add quota for nm name that contains any whitespace
+ $(echo $"${nm_name}" | grep -q " ") && nm_name="\"${nm_name}\""
+ ifcfg_file=$(get_config_by_name ${nm_name})
+ fi
+ fi
+
+ echo -n ${ifcfg_file}
+}
+
+# $1: netdev name
+get_ifcfg_legacy()
+{
+ local ifcfg_file
+
+ ifcfg_file="/etc/sysconfig/network-scripts/ifcfg-${1}"
+ [ -f "${ifcfg_file}" ] && echo -n "${ifcfg_file}" && return
+
+ ifcfg_file=$(get_config_by_name "${1}")
+ [ -f "${ifcfg_file}" ] && echo -n "${ifcfg_file}" && return
+
+ local hwaddr=$(get_hwaddr ${1})
+ if [ -n "$hwaddr" ]; then
+ ifcfg_file=$(get_config_by_hwaddr ${hwaddr})
+ [ -f "${ifcfg_file}" ] && echo -n "${ifcfg_file}" && return
+ fi
+
+ ifcfg_file=$(get_config_by_device ${1})
+
+ echo -n "${ifcfg_file}"
+}
+
+# $1: netdev name
+# Return the ifcfg file whole name(including the path) of $1 if any.
+get_ifcfg_filename() {
+ local ifcfg_file
+
+ ifcfg_file=$(get_ifcfg_nmcli $1)
+ if [ -z ${ifcfg_file} ]; then
+ ifcfg_file=$(get_ifcfg_legacy $1)
+ fi
+
+ echo -n "${ifcfg_file}"
+}
+
--
1.8.3.1
7 years, 11 months
[PATCH 0/2] kdumpctl: force rebuild when dump target is modified
by Pratyush Anand
When dump target is re-formatted then its UUID changes. These patches add
support to recognize such changes and then force initramfs rebuild, if
dracut argument has an UUID based root location.
Pratyush Anand (2):
kdumpctl: force rebuild in case of dynamic system modification
kdumpctl: force rebuild in case of dump target modification
kdumpctl | 42 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
--
2.5.0
7 years, 11 months