Enhance dev command to analyze and extract hardware specific
device dumps in KDUMP vmcore.
Signed-off-by: Surendra Mobiya <surendra(a)chelsio.com>
Signed-off-by: Rahul Lakkireddy <rahul.lakkireddy(a)chelsio.com>
---
rfc:
- Moved logic to extract device dumps from "devdump" to "dev"
command.
defs.h | 2 ++
dev.c | 8 ++++++--
diskdump.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 54 insertions(+), 2 deletions(-)
diff --git a/defs.h b/defs.h
index a6a0d8a..b025eae 100644
--- a/defs.h
+++ b/defs.h
@@ -6450,6 +6450,8 @@ void process_elf64_notes(void *, ulong);
void dump_registers_for_compressed_kdump(void);
int diskdump_kaslr_check(void);
QEMUCPUState *diskdump_get_qemucpustate(int);
+void diskdump_device_dump_info(FILE *);
+void diskdump_device_dump_extract(int, char *, FILE *);
/*
* makedumpfile.c
diff --git a/dev.c b/dev.c
index 08bb010..498c90f 100644
--- a/dev.c
+++ b/dev.c
@@ -142,8 +142,10 @@ cmd_dev(void)
case 'V':
if (KDUMP_DUMPFILE())
kdump_device_dump_info(fp);
+ else if (DISKDUMP_DUMPFILE())
+ diskdump_device_dump_info(fp);
else
- error(WARNING, "KDUMP flag not found");
+ error(WARNING, "KDUMP/DISKDUMP flag not found");
return;
case 'v':
@@ -166,8 +168,10 @@ cmd_dev(void)
if (index >= 0) {
if (KDUMP_DUMPFILE())
kdump_device_dump_extract(index, outputfile, fp);
+ else if (DISKDUMP_DUMPFILE())
+ diskdump_device_dump_extract(index, outputfile, fp);
else
- error(WARNING, "KDUMP flag not found");
+ error(WARNING, "KDUMP/DISKDUMP flag not found");
return;
}
diff --git a/diskdump.c b/diskdump.c
index 6b7a91b..645bdf1 100644
--- a/diskdump.c
+++ b/diskdump.c
@@ -2538,3 +2538,49 @@ diskdump_get_qemucpustate(int cpu)
return (QEMUCPUState *)dd->nt_qemucs_percpu[cpu];
}
#endif
+
+/*
+ * extract hardware specific device dumps from coredump.
+ */
+void
+diskdump_device_dump_extract(int index, char *outfile, FILE *ofp)
+{
+ ulonglong offset;
+
+ if (index >= dd->num_vmcoredd_notes) {
+ error(WARNING, "No device dump found at index: %d", index);
+ return;
+ }
+
+ offset = dd->sub_header_kdump->offset_note +
+ ((unsigned char *)dd->nt_vmcoredd_array[index] -
+ dd->notes_buf);
+
+ devdump_extract(dd->nt_vmcoredd_array[index], offset, outfile, ofp);
+}
+
+/*
+ * list all hardware specific device dumps present in coredump.
+ */
+void
+diskdump_device_dump_info(FILE *ofp)
+{
+ ulonglong offset;
+ char buf[BUFSIZE];
+ ulong i;
+
+ fprintf(fp, "%s ", mkstring(buf, INT_PRLEN, LJUST, "INDEX"));
+ fprintf(fp, "%s ", mkstring(buf, LONG_LONG_PRLEN, LJUST,
"OFFSET"));
+ fprintf(fp, " %s ", mkstring(buf, LONG_PRLEN, LJUST, "SIZE"));
+ fprintf(fp, "%s\n", mkstring(buf, VMCOREDD_MAX_NAME_BYTES, LJUST,
+ "NAME"));
+
+ for (i = 0; i < dd->num_vmcoredd_notes; i++) {
+ fprintf(fp, "%s ", mkstring(buf, INT_PRLEN, LJUST | INT_DEC,
+ MKSTR(i)));
+ offset = dd->sub_header_kdump->offset_note +
+ ((unsigned char *)dd->nt_vmcoredd_array[i] -
+ dd->notes_buf);
+ devdump_info(dd->nt_vmcoredd_array[i], offset, ofp);
+ }
+}
--
2.21.0