Unify the initialization of struct xen_kdump_data.
Signed-off-by: Petr Tesarik <ptesarik(a)suse.com>
---
netdump.c | 82 ++++++--------------------------------------------------------
xen_dom0.c | 36 +++++++++++++++++++++++++++
xen_dom0.h | 1 +
3 files changed, 45 insertions(+), 74 deletions(-)
diff --git a/netdump.c b/netdump.c
index 3a2df55..5305e04 100644
--- a/netdump.c
+++ b/netdump.c
@@ -1964,10 +1964,6 @@ dump_Elf32_Nhdr(Elf32_Off offset, int store)
case NT_XEN_KDUMP_CR3:
netdump_print("(NT_XEN_KDUMP_CR3) [obsolete]\n");
- if (store)
- error(WARNING,
- "obsolete Xen n_type: %lx (NT_XEN_KDUMP_CR3)\n\n",
- note->n_type);
/* FALL THROUGH */
case XEN_ELFNOTE_CRASH_INFO:
@@ -1977,39 +1973,10 @@ dump_Elf32_Nhdr(Elf32_Off offset, int store)
if (note->n_type == XEN_ELFNOTE_CRASH_INFO)
netdump_print("(XEN_ELFNOTE_CRASH_INFO)\n");
xen_core = TRUE;
- if (store) {
- struct xen_kdump_data *xkd = get_xen_kdump_data();
- pc->flags |= XEN_CORE;
- xkd->last_mfn_read = UNINITIALIZED;
- xkd->last_pmd_read = UNINITIALIZED;
-
- if ((note->n_type == NT_XEN_KDUMP_CR3) &&
- ((note->n_descsz/sizeof(ulong)) == 1)) {
- xkd->flags |= KDUMP_CR3;
- /*
- * Use the first cr3 found.
- */
- if (!xkd->cr3) {
- uptr = (ulong *)(ptr + note->n_namesz);
- uptr = (ulong *)roundup((ulong)uptr, 4);
- xkd->cr3 = *uptr;
- }
- } else {
- xkd->flags |= KDUMP_MFN_LIST;
- uptr = (ulong *)(ptr + note->n_namesz);
- uptr = (ulong *)roundup((ulong)uptr, 4);
- words = note->n_descsz/sizeof(ulong);
- /*
- * If already set, overridden with --pfm_mfn
- */
- if (!xkd->p2m_mfn)
- xkd->p2m_mfn = *(uptr+(words-1));
- if (words > 9 && !xkd->xen_phys_start)
- xkd->xen_phys_start = *(uptr+(words-2));
- xkd->xen_major_version = *uptr;
- xkd->xen_minor_version = *(uptr+1);
- }
- }
+ if (store)
+ process_xen_note(note->n_type,
+ ptr + roundup(note->n_namesz, 4),
+ note->n_descsz);
break;
case XEN_ELFNOTE_CRASH_REGS:
@@ -2258,10 +2225,6 @@ dump_Elf64_Nhdr(Elf64_Off offset, int store)
case NT_XEN_KDUMP_CR3:
netdump_print("(NT_XEN_KDUMP_CR3) [obsolete]\n");
- if (store)
- error(WARNING,
- "obsolete Xen n_type: %lx (NT_XEN_KDUMP_CR3)\n\n",
- note->n_type);
/* FALL THROUGH */
case XEN_ELFNOTE_CRASH_INFO:
@@ -2271,39 +2234,10 @@ dump_Elf64_Nhdr(Elf64_Off offset, int store)
if (note->n_type == XEN_ELFNOTE_CRASH_INFO)
netdump_print("(XEN_ELFNOTE_CRASH_INFO)\n");
xen_core = TRUE;
- if (store) {
- struct xen_kdump_data *xkd = get_xen_kdump_data();
- pc->flags |= XEN_CORE;
- xkd->last_mfn_read = UNINITIALIZED;
- xkd->last_pmd_read = UNINITIALIZED;
-
- if ((note->n_type == NT_XEN_KDUMP_CR3) &&
- ((note->n_descsz/sizeof(ulong)) == 1)) {
- xkd->flags |= KDUMP_CR3;
- /*
- * Use the first cr3 found.
- */
- if (!xkd->cr3) {
- up = (ulong *)(ptr + note->n_namesz);
- up = (ulong *)roundup((ulong)up, 4);
- xkd->cr3 = *up;
- }
- } else {
- xkd->flags |= KDUMP_MFN_LIST;
- up = (ulong *)(ptr + note->n_namesz);
- up = (ulong *)roundup((ulong)up, 4);
- words = note->n_descsz/sizeof(ulong);
- /*
- * If already set, overridden with --p2m_mfn
- */
- if (!xkd->p2m_mfn)
- xkd->p2m_mfn = *(up+(words-1));
- if (words > 9 && !xkd->xen_phys_start)
- xkd->xen_phys_start = *(up+(words-2));
- xkd->xen_major_version = *up;
- xkd->xen_minor_version = *(up+1);
- }
- }
+ if (store)
+ process_xen_note(note->n_type,
+ ptr + roundup(note->n_namesz, 4),
+ note->n_descsz);
break;
case XEN_ELFNOTE_CRASH_REGS:
diff --git a/xen_dom0.c b/xen_dom0.c
index 7c9c76e..bc88462 100644
--- a/xen_dom0.c
+++ b/xen_dom0.c
@@ -72,6 +72,42 @@ dump_xen_kdump_data(FILE *fp)
if (i) fprintf(fp, "\n");
}
+void
+process_xen_note(ulong type, void *data, size_t sz)
+{
+ ulong *up = (ulong*) data;
+ unsigned words = sz / sizeof(ulong);
+
+ pc->flags |= XEN_CORE;
+ xkd->last_mfn_read = UNINITIALIZED;
+ xkd->last_pmd_read = UNINITIALIZED;
+
+ if (type == NT_XEN_KDUMP_CR3)
+ error(WARNING,
+ "obsolete Xen n_type: %lx (NT_XEN_KDUMP_CR3)\n\n",
+ type);
+
+ if (type == NT_XEN_KDUMP_CR3 && words == 1) {
+ xkd->flags |= KDUMP_CR3;
+ /*
+ * Use the first cr3 found.
+ */
+ if (!xkd->cr3)
+ xkd->cr3 = *up;
+ } else {
+ xkd->flags |= KDUMP_MFN_LIST;
+ /*
+ * If already set, overridden with --pfm_mfn
+ */
+ if (!xkd->p2m_mfn)
+ xkd->p2m_mfn = up[words-1];
+ if (words > 9 && !xkd->xen_phys_start)
+ xkd->xen_phys_start = up[words-2];
+ xkd->xen_major_version = up[0];
+ xkd->xen_minor_version = up[1];
+ }
+}
+
/*
* Override the dom0 p2m mfn in the XEN_ELFNOTE_CRASH_INFO note
* in order to initiate a crash session of a guest kernel.
diff --git a/xen_dom0.h b/xen_dom0.h
index a8a563d..4f0ff53 100644
--- a/xen_dom0.h
+++ b/xen_dom0.h
@@ -71,4 +71,5 @@ struct xen_kdump_data {
void dump_xen_kdump_data(FILE *);
struct xen_kdump_data *get_xen_kdump_data(void);
+void process_xen_note(ulong, void *, size_t);
physaddr_t xen_kdump_p2m(physaddr_t);
--
2.1.4