kexec-tools package for debian includes a patch that adds a more 
descriptive error message when someone tries to laod a crash kernel 
and didn't remember to boot up with crashkernel= parameter. This 
patch would be of general interest. This patch was originally written 
by Alastair McKinstry.

Please apply.

Signed-off-by: Khalid Aziz <[email protected]>
---
 kexec/arch/i386/crashdump-x86.c |   10 ++++++----
 kexec/kexec.c                   |   18 ++++++++++++++----
 kexec/kexec.h                   |    6 ++++++
 3 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/kexec/arch/i386/crashdump-x86.c b/kexec/arch/i386/crashdump-x86.c
index 590c883..2af090c 100644
--- a/kexec/arch/i386/crashdump-x86.c
+++ b/kexec/arch/i386/crashdump-x86.c
@@ -776,7 +776,9 @@ int load_crashdump_segments(struct kexec_info *info, char* 
mod_cmdline,
        memset(memmap_p, 0, sz);
        add_memmap(memmap_p, info->backup_src_start, info->backup_src_size);
        sz = crash_reserved_mem.end - crash_reserved_mem.start +1;
-       add_memmap(memmap_p, crash_reserved_mem.start, sz);
+       if (add_memmap(memmap_p, crash_reserved_mem.start, sz) < 0) {
+               return ENOCRASHKERNEL;
+       }
 
        /* Create a backup region segment to store backup data*/
        if (!(info->kexec_flags & KEXEC_PRESERVE_CONTEXT)) {
@@ -788,7 +790,7 @@ int load_crashdump_segments(struct kexec_info *info, char* 
mod_cmdline,
                dbgprintf("Created backup segment at 0x%lx\n",
                          info->backup_start);
                if (delete_memmap(memmap_p, info->backup_start, sz) < 0)
-                       return -1;
+                       return EFAILED;
        }
 
        /* Create elf header segment and store crash image data. */
@@ -797,14 +799,14 @@ int load_crashdump_segments(struct kexec_info *info, 
char* mod_cmdline,
                                               crash_memory_range, nr_ranges,
                                               &tmp, &bufsz,
                                               ELF_CORE_HEADER_ALIGN) < 0)
-                       return -1;
+                       return EFAILED;
        }
        else {
                if (crash_create_elf32_headers(info, &elf_info,
                                               crash_memory_range, nr_ranges,
                                               &tmp, &bufsz,
                                               ELF_CORE_HEADER_ALIGN) < 0)
-                       return -1;
+                       return EFAILED;
        }
        /* the size of the elf headers allocated is returned in 'bufsz' */
 
diff --git a/kexec/kexec.c b/kexec/kexec.c
index 19133fa..84dab70 100644
--- a/kexec/kexec.c
+++ b/kexec/kexec.c
@@ -718,10 +718,20 @@ static int my_load(const char *type, int fileind, int 
argc, char **argv,
        }
        info.kexec_flags |= native_arch;
 
-       if (file_type[i].load(argc, argv, kernel_buf,
-                             kernel_size, &info) < 0) {
-               fprintf(stderr, "Cannot load %s\n", kernel);
-               return -1;
+       result = file_type[i].load(argc, argv, kernel_buf, kernel_size, &info);
+       if (result < 0) {
+               switch (result) {
+               case ENOCRASHKERNEL:
+                       fprintf(stderr,
+                               "No crash kernel segment found in /proc/iomem\n"
+                               "Please check the crashkernel= boot 
parameter.\n");
+                       break;
+               case EFAILED:
+               default:
+                       fprintf(stderr, "Cannot load %s\n", kernel);
+                       break;
+               }
+               return result;
        }
        /* If we are not in native mode setup an appropriate trampoline */
        if (arch_compat_trampoline(&info) < 0) {
diff --git a/kexec/kexec.h b/kexec/kexec.h
index dfd3630..279dfdf 100644
--- a/kexec/kexec.h
+++ b/kexec/kexec.h
@@ -57,6 +57,12 @@
 #error unknwon BYTE_ORDER
 #endif
 
+/*
+ * Document some of the reasons why crashdump may fail, so we can give
+ * better error messages
+ */
+#define EFAILED                -1      /* default error code */
+#define ENOCRASHKERNEL -2      /* no memory reserved for crashkernel */
 
 /*
  * This function doesn't actually exist.  The idea is that when someone
-- 
1.7.8.3


====================================================================
Khalid Aziz                                         Unix Systems Lab
(970)898-9214                                        Hewlett-Packard
[email protected]                                  Fort Collins, CO

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

Reply via email to