summaryrefslogtreecommitdiff
path: root/kexec/crashdump-xen.c
diff options
context:
space:
mode:
Diffstat (limited to 'kexec/crashdump-xen.c')
-rw-r--r--kexec/crashdump-xen.c126
1 files changed, 93 insertions, 33 deletions
diff --git a/kexec/crashdump-xen.c b/kexec/crashdump-xen.c
index d8bd0f4..60594f6 100644
--- a/kexec/crashdump-xen.c
+++ b/kexec/crashdump-xen.c
@@ -131,30 +131,18 @@ unsigned long xen_architecture(struct crash_elf_info *elf_info)
#ifdef HAVE_LIBXENCTRL
int rc;
xen_capabilities_info_t capabilities;
-#ifdef XENCTRL_HAS_XC_INTERFACE
xc_interface *xc;
-#else
- int xc;
-#endif
if (!xen_present())
goto out;
memset(capabilities, '0', XEN_CAPABILITIES_INFO_LEN);
-#ifdef XENCTRL_HAS_XC_INTERFACE
xc = xc_interface_open(NULL, NULL, 0);
if ( !xc ) {
fprintf(stderr, "failed to open xen control interface.\n");
goto out;
}
-#else
- xc = xc_interface_open();
- if ( xc == -1 ) {
- fprintf(stderr, "failed to open xen control interface.\n");
- goto out;
- }
-#endif
rc = xc_version(xc, XENVER_capabilities, &capabilities[0]);
if ( rc == -1 ) {
@@ -175,42 +163,80 @@ unsigned long xen_architecture(struct crash_elf_info *elf_info)
return machine;
}
-static int xen_crash_note_callback(void *UNUSED(data), int nr,
- char *UNUSED(str),
- unsigned long base,
- unsigned long length)
+#ifdef HAVE_LIBXENCTRL
+int get_xen_vmcoreinfo(uint64_t *addr, uint64_t *len)
{
- struct crash_note_info *note = xen_phys_notes + nr;
+ xc_interface *xc;
+ int ret = 0;
+
+ xc = xc_interface_open(NULL, NULL, 0);
+ if (!xc) {
+ fprintf(stderr, "failed to open xen control interface.\n");
+ return -1;
+ }
- note->base = base;
- note->length = length;
+ ret = xc_kexec_get_range(xc, KEXEC_RANGE_MA_VMCOREINFO, 0, len, addr);
+ xc_interface_close(xc);
+
+ if (ret < 0)
+ return -1;
return 0;
}
int xen_get_nr_phys_cpus(void)
{
- char *match = "Crash note\n";
- int cpus, n;
+ xc_interface *xc;
+ int max_cpus;
+ int cpu = -1;
if (xen_phys_cpus)
return xen_phys_cpus;
- if ((cpus = kexec_iomem_for_each_line(match, NULL, NULL))) {
- n = sizeof(struct crash_note_info) * cpus;
- xen_phys_notes = malloc(n);
- if (!xen_phys_notes) {
- fprintf(stderr, "failed to allocate xen_phys_notes.\n");
- return -1;
- }
- memset(xen_phys_notes, 0, n);
- kexec_iomem_for_each_line(match,
- xen_crash_note_callback, NULL);
- xen_phys_cpus = cpus;
+ xc = xc_interface_open(NULL, NULL, 0);
+ if (!xc) {
+ fprintf(stderr, "failed to open xen control interface.\n");
+ return -1;
+ }
+
+ max_cpus = xc_get_max_cpus(xc);
+ if (max_cpus <= 0)
+ goto out;
+
+ xen_phys_notes = calloc(max_cpus, sizeof(*xen_phys_notes));
+ if (xen_phys_notes == NULL)
+ goto out;
+
+ for (cpu = 0; cpu < max_cpus; cpu++) {
+ uint64_t size, start;
+ int ret;
+
+ ret = xc_kexec_get_range(xc, KEXEC_RANGE_MA_CPU, cpu, &size, &start);
+ if (ret < 0)
+ break;
+
+ xen_phys_notes[cpu].base = start;
+ xen_phys_notes[cpu].length = size;
}
- return cpus;
+ xen_phys_cpus = cpu;
+
+out:
+ xc_interface_close(xc);
+ return cpu;
+}
+#else
+int get_xen_vmcoreinfo(uint64_t *addr, uint64_t *len)
+{
+ return -1;
+}
+
+int xen_get_nr_phys_cpus(void)
+{
+ return -1;
}
+#endif
+
int xen_get_note(int cpu, uint64_t *addr, uint64_t *len)
{
@@ -226,3 +252,37 @@ int xen_get_note(int cpu, uint64_t *addr, uint64_t *len)
return 0;
}
+
+#ifdef HAVE_LIBXENCTRL
+int xen_get_crashkernel_region(uint64_t *start, uint64_t *end)
+{
+ uint64_t size;
+ xc_interface *xc;
+ int rc = -1;
+
+ xc = xc_interface_open(NULL, NULL, 0);
+ if (!xc) {
+ fprintf(stderr, "failed to open xen control interface.\n");
+ goto out;
+ }
+
+ rc = xc_kexec_get_range(xc, KEXEC_RANGE_MA_CRASH, 0, &size, start);
+ if (rc < 0) {
+ fprintf(stderr, "failed to get crash region from hypervisor.\n");
+ goto out_close;
+ }
+
+ *end = *start + size - 1;
+
+out_close:
+ xc_interface_close(xc);
+
+out:
+ return rc;
+}
+#else
+int xen_get_crashkernel_region(uint64_t *start, uint64_t *end)
+{
+ return -1;
+}
+#endif