Skip to content

Commit 4cb3b72

Browse files
authored
[Show] Update the subcommands of Kdump. (sonic-net#1682)
Signed-off-by: Yong Zhao [email protected] What I did This PR fixed the following issues: Initially we need add prefix sudo when ran the show command of Kdump. This is unnecessary. I re-organized the logic of implementing show command and also update the script sonic-kdump-config. How I did it Since the script sonic-kdump-config can only be executed by root user, I moved some functions from this file to the kdump.py such that we do not need run the show command with sudo. How to verify it I verified this change on the DuT str-msn2700-03.
1 parent c03342f commit 4cb3b72

File tree

3 files changed

+290
-169
lines changed

3 files changed

+290
-169
lines changed

doc/Command-Reference.md

+116
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@
7171
* [Kubernetes](#Kubernetes)
7272
* [Kubernetes show commands](#Kubernetes-show-commands)
7373
* [Kubernetes config commands](#Kubernetes-config-commands)
74+
* [Linux Kernel Dump](#kdump)
75+
* [Linux Kernel Dump show commands](#kdump-show-commands)
76+
* [Linux Kernel Dump config commands](#kdump-config-commands)
7477
* [LLDP](#lldp)
7578
* [LLDP show commands](#lldp-show-commands)
7679
* [Loading, Reloading And Saving Configuration](#loading-reloading-and-saving-configuration)
@@ -4538,6 +4541,119 @@ This command displays the kubernetes server status.
45384541
----------- ------ ----------- -------------------
45394542
10.3.157.24 6443 true 2020-11-15 18:25:05
45404543
```
4544+
Go Back To [Beginning of the document](#) or [Beginning of this section](#Kubernetes)
4545+
4546+
## Linux Kernel Dump
4547+
4548+
This section demonstrates the show commands and configuration commands of Linux kernel dump mechanism in SONiC.
4549+
4550+
### Linux Kernel Dump show commands
4551+
4552+
**show kdump config**
4553+
4554+
This command shows the configuration of Linux kernel dump.
4555+
4556+
- Usage:
4557+
```
4558+
show kdump config
4559+
```
4560+
4561+
- Example:
4562+
```
4563+
admin@sonic:$ show kdump config
4564+
Kdump administrative mode: Disabled
4565+
Kdump operational mode: Unready
4566+
Kdump memory researvation: 0M-2G:256M,2G-4G:320M,4G-8G:384M,8G-:448M
4567+
Maximum number of Kdump files: 3
4568+
```
4569+
4570+
**show kdump files**
4571+
4572+
This command shows the Linux kernel core dump files and dmesg files which are
4573+
generated by kernel dump tool.
4574+
4575+
- Usage:
4576+
```
4577+
show kdump files
4578+
```
4579+
4580+
- Example:
4581+
```
4582+
admin@sonic:~$ show kdump files
4583+
Kernel core dump files Kernel dmesg files
4584+
------------------------------------------ ------------------------------------------
4585+
/var/crash/202106242344/kdump.202106242344 /var/crash/202106242344/dmesg.202106242344
4586+
/var/crash/202106242337/kdump.202106242337 /var/crash/202106242337/dmesg.202106242337
4587+
```
4588+
4589+
**show kdump logging <file_name> <num_of_lines>**
4590+
4591+
By default, this command will show the last 10 lines of latest dmesg file.
4592+
This command can also accept a specific file name and number of lines as arguments.
4593+
4594+
- Usage:
4595+
```
4596+
show kdump logging
4597+
```
4598+
4599+
- Example:
4600+
```
4601+
admin@sonic:~$ show kdump logging
4602+
[ 157.642053] RSP: 002b:00007fff1beee708 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
4603+
[ 157.732635] RAX: ffffffffffffffda RBX: 0000000000000002 RCX: 00007fc3887d4504
4604+
[ 157.818015] RDX: 0000000000000002 RSI: 000055d388eceb40 RDI: 0000000000000001
4605+
[ 157.903401] RBP: 000055d388eceb40 R08: 000000000000000a R09: 00007fc3888255f0
4606+
[ 157.988784] R10: 000000000000000a R11: 0000000000000246 R12: 00007fc3888a6760
4607+
[ 158.074166] R13: 0000000000000002 R14: 00007fc3888a1760 R15: 0000000000000002
4608+
[ 158.159553] Modules linked in: nft_chain_route_ipv6(E) nft_chain_route_ipv4(E) xt_TCPMSS(E) dummy(E) team_mode_loadbalance(E) team(E) sx_bfd(OE) sx_netdev(OE) psample(E) sx_core(OE) 8021q(E) garp(E) mrp(E) mst_pciconf(OE) mst_pci(OE) xt_hl(E) xt_tcpudp(E) ip6_tables(E) nft_compat(E) nft_chain_nat_ipv4(E) nf_nat_ipv4(E) nft_counter(E) xt_conntrack(E) nf_nat(E) jc42(E) nf_conntrack_netlink(E) nf_conntrack(E) nf_defrag_ipv6(E) nf_defrag_ipv4(E) libcrc32c(E) xfrm_user(E) xfrm_algo(E) mlxsw_minimal(E) mlxsw_i2c(E) i2c_mux_reg(E) i2c_mux(E) i2c_mlxcpld(E) leds_mlxreg(E) mlxreg_io(E) mlxreg_hotplug(E) mei_wdt(E) evdev(E) intel_rapl(E) x86_pkg_temp_thermal(E) intel_powerclamp(E) kvm_intel(E) mlx_platform(E) kvm(E) irqbypass(E) crct10dif_pclmul(E) crc32_pclmul(E) ghash_clmulni_intel(E) intel_cstate(E) intel_uncore(E)
4609+
[ 159.016731] intel_rapl_perf(E) pcspkr(E) sg(E) iTCO_wdt(E) iTCO_vendor_support(E) mei_me(E) mei(E) bonding(E) pcc_cpufreq(E) video(E) button(E) ebt_vlan(E) ebtable_broute(E) bridge(E) stp(E) llc(E) ebtable_nat(E) ebtable_filter(E) ebtables(E) nf_tables(E) nfnetlink(E) xdpe12284(E) at24(E) ledtrig_timer(E) tmp102(E) lm75(E) drm(E) coretemp(E) max1363(E) industrialio_triggered_buffer(E) kfifo_buf(E) industrialio(E) tps53679(E) fuse(E) pmbus(E) pmbus_core(E) i2c_dev(E) configfs(E) ip_tables(E) x_tables(E) autofs4(E) loop(E) ext4(E) crc16(E) mbcache(E) jbd2(E) crc32c_generic(E) fscrypto(E) ecb(E) crypto_simd(E) cryptd(E) glue_helper(E) aes_x86_64(E) nvme(E) nvme_core(E) nls_utf8(E) nls_cp437(E) nls_ascii(E) vfat(E) fat(E) overlay(E) squashfs(E) zstd_decompress(E) xxhash(E) sd_mod(E) gpio_ich(E) ahci(E)
4610+
[ 159.864532] libahci(E) mlxsw_core(E) devlink(E) ehci_pci(E) ehci_hcd(E) crc32c_intel(E) libata(E) i2c_i801(E) scsi_mod(E) usbcore(E) usb_common(E) lpc_ich(E) mfd_core(E) e1000e(E) fan(E) thermal(E)
4611+
[ 160.075846] CR2: 0000000000000000
4612+
```
4613+
You can specify a file name in order to show its
4614+
last 10 lines.
4615+
4616+
- Example:
4617+
```
4618+
admin@sonic:~$ show kdump logging dmesg.202106242337
4619+
[ 654.120195] RSP: 002b:00007ffe697690f8 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
4620+
[ 654.210778] RAX: ffffffffffffffda RBX: 0000000000000002 RCX: 00007fcfca27b504
4621+
[ 654.296157] RDX: 0000000000000002 RSI: 000055a6e4d1b3f0 RDI: 0000000000000001
4622+
[ 654.381543] RBP: 000055a6e4d1b3f0 R08: 000000000000000a R09: 00007fcfca2cc5f0
4623+
[ 654.466925] R10: 000000000000000a R11: 0000000000000246 R12: 00007fcfca34d760
4624+
[ 654.552310] R13: 0000000000000002 R14: 00007fcfca348760 R15: 0000000000000002
4625+
[ 654.637694] Modules linked in: binfmt_misc(E) nft_chain_route_ipv6(E) nft_chain_route_ipv4(E) xt_TCPMSS(E) dummy(E) team_mode_loadbalance(E) team(E) sx_bfd(OE) sx_netdev(OE) psample(E) sx_core(OE) 8021q(E) garp(E) mrp(E) mst_pciconf(OE) mst_pci(OE) xt_hl(E) xt_tcpudp(E) ip6_tables(E) nft_chain_nat_ipv4(E) nf_nat_ipv4(E) nft_compat(E) nft_counter(E) xt_conntrack(E) nf_nat(E) jc42(E) nf_conntrack_netlink(E) nf_conntrack(E) nf_defrag_ipv6(E) nf_defrag_ipv4(E) libcrc32c(E) xfrm_user(E) xfrm_algo(E) mlxsw_minimal(E) mlxsw_i2c(E) i2c_mux_reg(E) i2c_mux(E) mlxreg_hotplug(E) mlxreg_io(E) i2c_mlxcpld(E) leds_mlxreg(E) mei_wdt(E) evdev(E) intel_rapl(E) x86_pkg_temp_thermal(E) intel_powerclamp(E) kvm_intel(E) kvm(E) mlx_platform(E) irqbypass(E) crct10dif_pclmul(E) crc32_pclmul(E) ghash_clmulni_intel(E) intel_cstate(E)
4626+
[ 655.493833] intel_uncore(E) intel_rapl_perf(E) pcspkr(E) sg(E) iTCO_wdt(E) iTCO_vendor_support(E) mei_me(E) mei(E) bonding(E) video(E) button(E) pcc_cpufreq(E) ebt_vlan(E) ebtable_broute(E) bridge(E) stp(E) llc(E) ebtable_nat(E) ebtable_filter(E) ebtables(E) nf_tables(E) nfnetlink(E) xdpe12284(E) at24(E) ledtrig_timer(E) tmp102(E) drm(E) lm75(E) coretemp(E) max1363(E) industrialio_triggered_buffer(E) kfifo_buf(E) industrialio(E) fuse(E) tps53679(E) pmbus(E) pmbus_core(E) i2c_dev(E) configfs(E) ip_tables(E) x_tables(E) autofs4(E) loop(E) ext4(E) crc16(E) mbcache(E) jbd2(E) crc32c_generic(E) fscrypto(E) ecb(E) crypto_simd(E) cryptd(E) glue_helper(E) aes_x86_64(E) nvme(E) nvme_core(E) nls_utf8(E) nls_cp437(E) nls_ascii(E) vfat(E) fat(E) overlay(E) squashfs(E) zstd_decompress(E) xxhash(E) sd_mod(E)
4627+
[ 656.337476] gpio_ich(E) ahci(E) mlxsw_core(E) libahci(E) devlink(E) crc32c_intel(E) libata(E) i2c_i801(E) scsi_mod(E) lpc_ich(E) mfd_core(E) ehci_pci(E) ehci_hcd(E) usbcore(E) e1000e(E) usb_common(E) fan(E) thermal(E)
4628+
[ 656.569590] CR2: 0000000000000000
4629+
```
4630+
You can also specify a file name and number of lines in order to show the
4631+
last number of lines.
4632+
4633+
- Example:
4634+
```
4635+
admin@sonic:~$ show kdump logging dmesg.202106242337 -l 20
4636+
[ 653.525427] __handle_sysrq.cold.9+0x45/0xf2
4637+
[ 653.576487] write_sysrq_trigger+0x2b/0x30
4638+
[ 653.625472] proc_reg_write+0x39/0x60
4639+
[ 653.669252] vfs_write+0xa5/0x1a0
4640+
[ 653.708881] ksys_write+0x57/0xd0
4641+
[ 653.748501] do_syscall_64+0x53/0x110
4642+
[ 653.792287] entry_SYSCALL_64_after_hwframe+0x44/0xa9
4643+
[ 653.852707] RIP: 0033:0x7fcfca27b504
4644+
[ 653.895452] Code: 00 f7 d8 64 89 02 48 c7 c0 ff ff ff ff eb b3 0f 1f 80 00 00 00 00 48 8d 05 f9 61 0d 00 8b 00 85 c0 75 13 b8 01 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 54 c3 0f 1f 00 41 54 49 89 d4 55 48 89 f5 53
4645+
[ 654.120195] RSP: 002b:00007ffe697690f8 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
4646+
[ 654.210778] RAX: ffffffffffffffda RBX: 0000000000000002 RCX: 00007fcfca27b504
4647+
[ 654.296157] RDX: 0000000000000002 RSI: 000055a6e4d1b3f0 RDI: 0000000000000001
4648+
[ 654.381543] RBP: 000055a6e4d1b3f0 R08: 000000000000000a R09: 00007fcfca2cc5f0
4649+
[ 654.466925] R10: 000000000000000a R11: 0000000000000246 R12: 00007fcfca34d760
4650+
[ 654.552310] R13: 0000000000000002 R14: 00007fcfca348760 R15: 0000000000000002
4651+
[ 654.637694] Modules linked in: binfmt_misc(E) nft_chain_route_ipv6(E) nft_chain_route_ipv4(E) xt_TCPMSS(E) dummy(E) team_mode_loadbalance(E) team(E) sx_bfd(OE) sx_netdev(OE) psample(E) sx_core(OE) 8021q(E) garp(E) mrp(E) mst_pciconf(OE) mst_pci(OE) xt_hl(E) xt_tcpudp(E) ip6_tables(E) nft_chain_nat_ipv4(E) nf_nat_ipv4(E) nft_compat(E) nft_counter(E) xt_conntrack(E) nf_nat(E) jc42(E) nf_conntrack_netlink(E) nf_conntrack(E) nf_defrag_ipv6(E) nf_defrag_ipv4(E) libcrc32c(E) xfrm_user(E) xfrm_algo(E) mlxsw_minimal(E) mlxsw_i2c(E) i2c_mux_reg(E) i2c_mux(E) mlxreg_hotplug(E) mlxreg_io(E) i2c_mlxcpld(E) leds_mlxreg(E) mei_wdt(E) evdev(E) intel_rapl(E) x86_pkg_temp_thermal(E) intel_powerclamp(E) kvm_intel(E) kvm(E) mlx_platform(E) irqbypass(E) crct10dif_pclmul(E) crc32_pclmul(E) ghash_clmulni_intel(E) intel_cstate(E)
4652+
[ 655.493833] intel_uncore(E) intel_rapl_perf(E) pcspkr(E) sg(E) iTCO_wdt(E) iTCO_vendor_support(E) mei_me(E) mei(E) bonding(E) video(E) button(E) pcc_cpufreq(E) ebt_vlan(E) ebtable_broute(E) bridge(E) stp(E) llc(E) ebtable_nat(E) ebtable_filter(E) ebtables(E) nf_tables(E) nfnetlink(E) xdpe12284(E) at24(E) ledtrig_timer(E) tmp102(E) drm(E) lm75(E) coretemp(E) max1363(E) industrialio_triggered_buffer(E) kfifo_buf(E) industrialio(E) fuse(E) tps53679(E) pmbus(E) pmbus_core(E) i2c_dev(E) configfs(E) ip_tables(E) x_tables(E) autofs4(E) loop(E) ext4(E) crc16(E) mbcache(E) jbd2(E) crc32c_generic(E) fscrypto(E) ecb(E) crypto_simd(E) cryptd(E) glue_helper(E) aes_x86_64(E) nvme(E) nvme_core(E) nls_utf8(E) nls_cp437(E) nls_ascii(E) vfat(E) fat(E) overlay(E) squashfs(E) zstd_decompress(E) xxhash(E) sd_mod(E)
4653+
[ 656.337476] gpio_ich(E) ahci(E) mlxsw_core(E) libahci(E) devlink(E) crc32c_intel(E) libata(E) i2c_i801(E) scsi_mod(E) lpc_ich(E) mfd_core(E) ehci_pci(E) ehci_hcd(E) usbcore(E) e1000e(E) usb_common(E) fan(E) thermal(E)
4654+
[ 656.569590] CR2: 0000000000000000
4655+
```
4656+
Go Back To [Beginning of the document](#) or [Beginning of this section](#kdump)
45414657
45424658
## LLDP
45434659

scripts/sonic-kdump-config

-99
Original file line numberDiff line numberDiff line change
@@ -607,86 +607,6 @@ def cmd_kdump_num_dumps(verbose, num_dumps):
607607
kdump_memory = get_kdump_memory()
608608
save_config(kdump_enabled, kdump_memory, num_dumps)
609609

610-
## Command: Display kdump status
611-
def cmd_kdump_status():
612-
print('Kdump Administrative Mode: ', end='')
613-
kdump_enabled = get_kdump_administrative_mode()
614-
if kdump_enabled:
615-
print('Enabled')
616-
else:
617-
print('Disabled')
618-
619-
print('Kdump Operational State: ', end='')
620-
(rc, lines, err_str) = run_command("/usr/sbin/kdump-config status", use_shell=False);
621-
if len(lines) >= 1 and ": ready to kdump" in lines[0]:
622-
use_kdump_in_cfg = read_use_kdump()
623-
if use_kdump_in_cfg:
624-
print('Ready')
625-
else:
626-
print('Not Ready')
627-
elif not kdump_enabled:
628-
print('Disabled')
629-
else:
630-
print('Ready after Reboot')
631-
632-
## Get the current number of kernel dump files stored
633-
#
634-
# @param The number of kdump files stored in /var/crash
635-
def get_nb_dumps_in_var_crash():
636-
(rc, lines, err_str) = run_command("find /var/crash/ -name 'kdump.*'", use_shell=False);
637-
if rc == 0:
638-
return len(lines)
639-
return 0
640-
641-
## Command: Display kdump files
642-
def cmd_kdump_files():
643-
nb_dumps = get_nb_dumps_in_var_crash()
644-
if nb_dumps == 0:
645-
print("No kernel core dump files")
646-
else:
647-
(rc1, lines1, err_str) = run_command("find /var/crash/ -name 'dmesg.*'", use_shell=False);
648-
lines1.sort(reverse=True)
649-
(rc2, lines2, err_str) = run_command("find /var/crash/ -name 'kdump.*'", use_shell=False);
650-
lines2.sort(reverse=True)
651-
print("Record Key Filename")
652-
print("-------------------------------------------------------------")
653-
for n in range(len(lines1)):
654-
print("%6d %s %s\n %s" % (n+1, lines1[n][11:23], lines1[n], lines2[n]))
655-
656-
## Command: Display kdump file (kernel log)
657-
#
658-
# @param num_lines Number of last lines displayed
659-
# @param filename Name or index of the kernel log file (dmesg)
660-
def cmd_kdump_file(num_lines, filename):
661-
fname = None
662-
nb_dumps = get_nb_dumps_in_var_crash()
663-
if nb_dumps == 0:
664-
print("Kernel crash log not found")
665-
else:
666-
(rc, lines, err_str) = run_command("find /var/crash/ -name 'dmesg.*'", use_shell=False);
667-
if rc == 0 and nb_dumps == len(lines):
668-
if filename.isdigit() and len(filename) <= 2:
669-
num = int(filename)
670-
if num < 1 or num > nb_dumps:
671-
if nb_dumps == 1:
672-
print("Invalid record number - Should be 1")
673-
else:
674-
print("Invalid record number - Should be between 1 and %d" % nb_dumps)
675-
sys.exit(1)
676-
fname = sorted(lines, reverse=True)[num-1]
677-
else:
678-
lines.sort(reverse=True)
679-
for x in lines:
680-
if x.find(filename) != -1:
681-
fname = x
682-
break
683-
if fname is None:
684-
print("Invalid key")
685-
sys.exit(1)
686-
(rc, lines, err_str) = run_command("/usr/bin/tail -n %d %s" % (num_lines, fname), use_shell=False);
687-
if rc == 0:
688-
print('File: %s' % fname)
689-
print('\n'.join(lines))
690610

691611
def main():
692612

@@ -714,10 +634,6 @@ def main():
714634
parser.add_argument('--disable', action='store_true',
715635
help='Disable kdump')
716636

717-
# kdump status on Current Image
718-
parser.add_argument('--status', action='store_true',
719-
help='Show kdump status')
720-
721637
# kdump status on Current Image
722638
parser.add_argument('--status-json', action='store_true',
723639
help='Show kdump status in json format')
@@ -726,7 +642,6 @@ def main():
726642
parser.add_argument('--kdump-records-json', action='store_true',
727643
help='Show kdump records in json format')
728644

729-
# kdump config on Current Image
730645
# kdump config on Current Image
731646
parser.add_argument('--config-json', action='store_true',
732647
help='Show kdump config in json format')
@@ -739,14 +654,6 @@ def main():
739654
parser.add_argument('--memory', nargs='?', type=str, action='store', default=False,
740655
help='Amount of memory reserved for the capture kernel')
741656

742-
# Capture kernel files
743-
parser.add_argument('--files', action='store_true',
744-
help='Show stored capture kernel files')
745-
746-
# Capture kernel file
747-
parser.add_argument('--file', nargs=1, type=str,
748-
help='Show stored capture kernel file')
749-
750657
# Show more information (used for sonic-kdump-config status)
751658
parser.add_argument("-v", "--verbose", action='store_true',
752659
help='displays detailed kdump status information. Used with status command.')
@@ -776,12 +683,6 @@ def main():
776683
cmd_kdump_memory(options.verbose, options.memory)
777684
elif options.num_dumps != False:
778685
cmd_kdump_num_dumps(options.verbose, options.num_dumps)
779-
elif options.status:
780-
cmd_kdump_status()
781-
elif options.files != False:
782-
cmd_kdump_files()
783-
elif options.file:
784-
cmd_kdump_file(options.lines, options.file[0])
785686
elif options.dump_db:
786687
cmd_dump_db()
787688
elif options.status_json:

0 commit comments

Comments
 (0)