[RFC PATCH 2/3] added way to determine kernel version that vmcore is from

Alexander Kamensky alexander.kamensky42 at gmail.com
Sun Nov 22 23:37:57 EST 2020


In some cases reading kernel dump require knowledge of the kernel version
that created the kernel dump file. Introduce release_kernel_version field
in struct DumpInfo, and fill it by parsing OSRELEASE value during
vmcoreinfo note read.

Signed-off-by: Alexander Kamensky <alexander.kamensky42 at gmail.com>
---
 makedumpfile.c | 27 +++++++++++++++++++++++++++
 makedumpfile.h |  1 +
 2 files changed, 28 insertions(+)

diff --git a/makedumpfile.c b/makedumpfile.c
index a955912..e2b0bc2 100644
--- a/makedumpfile.c
+++ b/makedumpfile.c
@@ -2380,6 +2380,32 @@ generate_vmcoreinfo(void)
 	return TRUE;
 }
 
+static void
+update_release_kernel_version(void)
+{
+	char *endp, *curp;
+	unsigned int kver_maj, kver_min, kver_rel;
+
+	curp = info->release;
+	kver_maj = strtoul(curp, &endp, 10);
+	if ((curp != endp) && (endp[0] == '.')) {
+		curp = endp + 1;
+		kver_min = strtoul(curp, &endp, 10);
+		if ((curp != endp) && (endp[0] == '.')) {
+			curp = endp + 1;
+			kver_rel =  strtoul(curp, &endp, 10);
+			if (curp != endp) {
+				info->release_kernel_version = KERNEL_VERSION(kver_maj,
+									      kver_min,
+									      kver_rel);
+				return;
+			}
+		}
+	}
+	ERRMSG("Cannot extract kernel version from %s%s\n", STR_OSRELEASE,
+	       info->release);
+}
+
 int
 read_vmcoreinfo_basic_info(void)
 {
@@ -2409,6 +2435,7 @@ read_vmcoreinfo_basic_info(void)
 			if (strlen(info->release))
 				continue;
 			strcpy(info->release, buf + strlen(STR_OSRELEASE));
+			update_release_kernel_version();
 		}
 		if (strncmp(buf, STR_PAGESIZE, strlen(STR_PAGESIZE)) == 0) {
 			page_size = strtol(buf+strlen(STR_PAGESIZE),&endp,10);
diff --git a/makedumpfile.h b/makedumpfile.h
index b95c7b6..b36766a 100644
--- a/makedumpfile.h
+++ b/makedumpfile.h
@@ -1440,6 +1440,7 @@ struct DumpInfo {
 	FILE			*file_vmcoreinfo;
 	char			*name_vmcoreinfo;	     /* vmcoreinfo file */
 	char			release[STRLEN_OSRELEASE];
+	int32_t			release_kernel_version; /* extracted from release */
 	int			read_text_vmcoreinfo;
 
 	/*
-- 
2.26.2




More information about the kexec mailing list