summaryrefslogtreecommitdiff
path: root/kexec/crashdump.c
diff options
context:
space:
mode:
authorVivek Goyal <vivek@in.ibm.com>2005-12-15 11:36:37 +0530
committerEric W. Biederman <ebiederm@xmission.com>2006-07-27 10:40:38 -0600
commit920fca9abfba3f5b86b2f73b54ba6f45148847cf (patch)
tree75f936be5224af9ff3a2ccb9427341eabab6481b /kexec/crashdump.c
parente2a925519d24e1aef1fd8d6e2f0d6f659d128ea7 (diff)
kexec-tools: i386 sys interface changes compatibility
On Wed, Dec 14, 2005 at 02:50:52PM -0600, Milton Miller wrote: [..] > >>(2) why do you stat the files instead of just trying to open them and > >>check for ENOENT? > >> > >>milton > >> > > > >I wanted to differentiate between two cases. One being sysfs not > >mounted > >and other being file not being present (Due to kernel bug or cpu not > >present), hence used stat(). In case of sysfs not being mounted, we > >simply exit after giving an error message. In other case we continue > >to loop through other cpus and ignore cpu, which is not present. > > > > Ok, but try to open the file first. IF you want to do this diagnostic > after the open fails, that is ok. But don't do this check n times (n = > number of cpus) when the file exists. > I have moved the sysfs mounted check in failure condition. > > > > >On Tue, Dec 13, 2005 at 09:36:26AM -0800, Haren Myneni wrote: > >>Vivek, I believe, we should push this func into arch independent code. > >>Otherwise, we have to copy it for every platform. > >> > > > >We have reworked the patch and moved this code to architecture > >independent > >portion. > > > > > Only the x86 code has the fallback the old name, not the genric code. > Only i386 port of kdump was available when crash_notes was exported through /sys/kernel/crash_notes. Rest of the architectures see new arch- independent percpu crash_notes sysfs interface only. Hence thought no point copying backward compatibility code in generic code. > > Also, there are error paths that do not set the address, others that > zero it. > The error paths which do not set address to zero are non return path. They call die() which inturn calls exit(1) after printing appropriate error messasge. > What happens if the base kernel is too old for kexec-panic, where > neiter file will exist? > In that case kexec will fail much earlier. There will be no reserved memory area for loading second kernel (crashkernel=X&Y) hence attempt to load the second kernel will fail and control will not reach this place at all. Modifed patch appended. Thanks Vivek o This patch moves per cpu interface to retrieve crash_notes address to architecture independent section. (As suggested by Haren) o For i386, kernels older than 2.6.15-rc1-mm2 used to export crash_notes through /sys/kernel/crash_notes. This patch also provides backward compatibility with older kernel versions. o Definition of MAX_NOTE_BYTES moved to architecture independent header file as everybody is using same definition. o Definition of MAX_LINE moved to architecture independent header file. Seems to be a better option than defining it in many C files. Signed-off-by: Maneesh Soni <maneesh@in.ibm.com> Signed-off-by: Vivek Goyal <vgoyal@in.ibm.com> Signed-off-by: Maneesh Soni <maneesh@in.ibm.com>
Diffstat (limited to 'kexec/crashdump.c')
-rw-r--r--kexec/crashdump.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/kexec/crashdump.c b/kexec/crashdump.c
new file mode 100644
index 0000000..9e5bf15
--- /dev/null
+++ b/kexec/crashdump.c
@@ -0,0 +1,65 @@
+/*
+ * crashdump.c: Architecture independent code for crashdump support.
+ *
+ * Created by: Vivek Goyal (vgoyal@in.ibm.com)
+ * Copyright (C) IBM Corporation, 2005. All rights reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation (version 2 of the License).
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <limits.h>
+#include <elf.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include "kexec.h"
+#include "crashdump.h"
+
+/* Returns the physical address of start of crash notes buffer for a cpu. */
+int get_crash_notes_per_cpu(int cpu, uint64_t *addr)
+{
+ char crash_notes[PATH_MAX];
+ char line[MAX_LINE];
+ FILE *fp;
+ struct stat cpu_stat;
+ int count;
+ unsigned long long temp;
+
+ sprintf(crash_notes, "/sys/devices/system/cpu/cpu%d/crash_notes", cpu);
+ fp = fopen(crash_notes, "r");
+ if (!fp) {
+ /* Either sysfs is not mounted or CPU is not present*/
+ if (stat("/sys/devices", &cpu_stat))
+ die("Sysfs is not mounted. Try mounting sysfs\n");
+
+ /* CPU is not physically present.*/
+ *addr = 0;
+ return errno;
+ }
+ if (fgets(line, sizeof(line), fp) != 0) {
+ count = sscanf(line, "%Lx", &temp);
+ if (count != 1)
+ die("Cannot parse %s: %s\n", crash_notes,
+ strerror(errno));
+ *addr = (uint64_t) temp;
+ }
+#if 0
+ printf("crash_notes addr = %Lx\n", *addr);
+#endif
+ return 0;
+}