Skip to content

Commit 042254e

Browse files
Kdump improvements (#1284)
- Added support for reporting kdump reboot cause to detect and report a kernel crash - Added additional commands to sonic-kdump-config wrapper script to dump Kdump configuration and status information in JSON format - Automatically save Kdump configuration in startup configuration file. This is an added convenience to the user as Kdump configuration changes require a system reboot and user is expected to save the configuration so that they are activated post reboot. - Additional bug fixes and improvements to allow hostcfgd to process Kdump configuration changes in ConfigDB. sonic-kdump-config script will write to ConfigDB. - Moved kdump CLI commands to a dedicated file Signed-off-by: Rajendra Dendukuri <[email protected]>
1 parent 9a17108 commit 042254e

File tree

6 files changed

+320
-89
lines changed

6 files changed

+320
-89
lines changed

config/kdump.py

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import os
2+
import click
3+
import utilities_common.cli as clicommon
4+
from swsssdk import ConfigDBConnector
5+
6+
@click.group(cls=clicommon.AbbreviationGroup, name="kdump")
7+
def kdump():
8+
""" Configure kdump """
9+
if os.geteuid() != 0:
10+
exit("Root privileges are required for this operation")
11+
12+
@kdump.command()
13+
def disable():
14+
"""Disable kdump operation"""
15+
config_db = ConfigDBConnector()
16+
if config_db is not None:
17+
config_db.connect()
18+
config_db.mod_entry("KDUMP", "config", {"enabled": "false"})
19+
20+
@kdump.command()
21+
def enable():
22+
"""Enable kdump operation"""
23+
config_db = ConfigDBConnector()
24+
if config_db is not None:
25+
config_db.connect()
26+
config_db.mod_entry("KDUMP", "config", {"enabled": "true"})
27+
28+
@kdump.command()
29+
@click.argument('kdump_memory', metavar='<kdump_memory>', required=True)
30+
def memory(kdump_memory):
31+
"""Set memory allocated for kdump capture kernel"""
32+
config_db = ConfigDBConnector()
33+
if config_db is not None:
34+
config_db.connect()
35+
config_db.mod_entry("KDUMP", "config", {"memory": kdump_memory})
36+
37+
@kdump.command('num-dumps')
38+
@click.argument('kdump_num_dumps', metavar='<kdump_num_dumps>', required=True, type=int)
39+
def num_dumps(kdump_num_dumps):
40+
"""Set max number of dump files for kdump"""
41+
config_db = ConfigDBConnector()
42+
if config_db is not None:
43+
config_db.connect()
44+
config_db.mod_entry("KDUMP", "config", {"num_dumps": kdump_num_dumps})

config/main.py

+2-44
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from . import chassis_modules
2929
from . import console
3030
from . import feature
31+
from . import kdump
3132
from . import kube
3233
from . import mlnx
3334
from . import muxcable
@@ -878,6 +879,7 @@ def config(ctx):
878879
config.add_command(chassis_modules.chassis_modules)
879880
config.add_command(console.console)
880881
config.add_command(feature.feature)
882+
config.add_command(kdump.kdump)
881883
config.add_command(kube.kubernetes)
882884
config.add_command(muxcable.muxcable)
883885
config.add_command(nat.nat)
@@ -1901,50 +1903,6 @@ def shutdown():
19011903
"""Shut down BGP session(s)"""
19021904
pass
19031905

1904-
@config.group(cls=clicommon.AbbreviationGroup)
1905-
def kdump():
1906-
""" Configure kdump """
1907-
if os.geteuid() != 0:
1908-
exit("Root privileges are required for this operation")
1909-
1910-
@kdump.command()
1911-
def disable():
1912-
"""Disable kdump operation"""
1913-
config_db = ConfigDBConnector()
1914-
if config_db is not None:
1915-
config_db.connect()
1916-
config_db.mod_entry("KDUMP", "config", {"enabled": "false"})
1917-
clicommon.run_command("sonic-kdump-config --disable")
1918-
1919-
@kdump.command()
1920-
def enable():
1921-
"""Enable kdump operation"""
1922-
config_db = ConfigDBConnector()
1923-
if config_db is not None:
1924-
config_db.connect()
1925-
config_db.mod_entry("KDUMP", "config", {"enabled": "true"})
1926-
clicommon.run_command("sonic-kdump-config --enable")
1927-
1928-
@kdump.command()
1929-
@click.argument('kdump_memory', metavar='<kdump_memory>', required=True)
1930-
def memory(kdump_memory):
1931-
"""Set memory allocated for kdump capture kernel"""
1932-
config_db = ConfigDBConnector()
1933-
if config_db is not None:
1934-
config_db.connect()
1935-
config_db.mod_entry("KDUMP", "config", {"memory": kdump_memory})
1936-
clicommon.run_command("sonic-kdump-config --memory %s" % kdump_memory)
1937-
1938-
@kdump.command('num-dumps')
1939-
@click.argument('kdump_num_dumps', metavar='<kdump_num_dumps>', required=True, type=int)
1940-
def num_dumps(kdump_num_dumps):
1941-
"""Set max number of dump files for kdump"""
1942-
config_db = ConfigDBConnector()
1943-
if config_db is not None:
1944-
config_db.connect()
1945-
config_db.mod_entry("KDUMP", "config", {"num_dumps": kdump_num_dumps})
1946-
clicommon.run_command("sonic-kdump-config --num_dumps %d" % kdump_num_dumps)
1947-
19481906
# 'all' subcommand
19491907
@shutdown.command()
19501908
@click.option('-v', '--verbose', is_flag=True, help="Enable verbose output")

scripts/reboot

+15-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
#!/bin/bash
2+
DEVPATH="/usr/share/sonic/device"
3+
PLAT_REBOOT="platform_reboot"
4+
REBOOT_CAUSE_FILE="/host/reboot-cause/reboot-cause.txt"
5+
REBOOT_TIME=$(date)
26

37
# Reboot immediately if we run the kdump capture kernel
48
VMCORE_FILE=/proc/vmcore
59
if [ -e $VMCORE_FILE -a -s $VMCORE_FILE ]; then
6-
echo "We have a /proc/vmcore, then we just kdump'ed"
7-
/sbin/reboot
10+
echo "We have a /proc/vmcore, then we just kdump'ed"
11+
echo "User issued 'kdump' command [User: kdump, Time: ${REBOOT_TIME}]" > ${REBOOT_CAUSE_FILE}
12+
sync
13+
PLATFORM=$(grep -oP 'platform=\K\S+' /proc/cmdline)
14+
if [ ! -z "${PLATFORM}" -a -x ${DEVPATH}/${PLATFORM}/${PLAT_REBOOT} ]; then
15+
exec ${DEVPATH}/${PLATFORM}/${PLAT_REBOOT}
16+
fi
17+
# If no platform-specific reboot tool, just run /sbin/reboot
18+
/sbin/reboot
19+
echo 1 > /proc/sys/kernel/sysrq
20+
echo b > /proc/sysrq-trigger
821
fi
922

1023
REBOOT_USER=$(logname)
11-
REBOOT_TIME=$(date)
1224
PLATFORM=$(sonic-cfggen -H -v DEVICE_METADATA.localhost.platform)
1325
ASIC_TYPE=$(sonic-cfggen -y /etc/sonic/sonic_version.yml -v asic_type)
14-
DEVPATH="/usr/share/sonic/device"
15-
PLAT_REBOOT="platform_reboot"
16-
REBOOT_CAUSE_FILE="/host/reboot-cause/reboot-cause.txt"
1726
VERBOSE=no
1827
EXIT_NEXT_IMAGE_NOT_EXISTS=4
1928
EXIT_SONIC_INSTALLER_VERIFY_REBOOT=21

0 commit comments

Comments
 (0)