[PATCH 1/3] kexec-xen: Introduce xen_get_kexec_range to wrap xc_kexec_get_range

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



And convert all callers of xc_kexec_get_range to use this. This allows reusing
sanity checks for other KEXEC_RANGEs that get added in the future.

Signed-off-by: Varad Gautam <vrd@xxxxxxxxx>
CC: David Woodhouse <dwmw@xxxxxxxxxxxx>
---
 kexec/crashdump-xen.c | 38 +++++---------------------------------
 kexec/kexec-xen.c     | 32 ++++++++++++++++++++++++++++++++
 kexec/kexec-xen.h     |  3 +++
 3 files changed, 40 insertions(+), 33 deletions(-)

diff --git a/kexec/crashdump-xen.c b/kexec/crashdump-xen.c
index 2d6b2f9..3f59a0d 100644
--- a/kexec/crashdump-xen.c
+++ b/kexec/crashdump-xen.c
@@ -162,21 +162,15 @@ unsigned long xen_architecture(struct crash_elf_info *elf_info)
 #ifdef HAVE_LIBXENCTRL
 int get_xen_vmcoreinfo(uint64_t *addr, uint64_t *len)
 {
-	xc_interface *xc;
+	uint64_t end;
 	int ret = 0;
 
-	xc = xc_interface_open(NULL, NULL, 0);
-	if (!xc) {
-	        fprintf(stderr, "failed to open xen control interface.\n");
+	ret = xen_get_kexec_range(KEXEC_RANGE_MA_VMCOREINFO, addr, &end);
+	if (ret < 0)
 	        return -1;
-	}
-
-	ret = xc_kexec_get_range(xc, KEXEC_RANGE_MA_VMCOREINFO, 0, len, addr);
 
-	xc_interface_close(xc);
+	*len = end - *addr + 1;
 
-	if (ret < 0)
-	        return -1;
 	return 0;
 }
 
@@ -252,29 +246,7 @@ int xen_get_note(int cpu, uint64_t *addr, uint64_t *len)
 #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;
+	return xen_get_kexec_range(KEXEC_RANGE_MA_CRASH, start, end);
 }
 #else
 int xen_get_crashkernel_region(uint64_t *start, uint64_t *end)
diff --git a/kexec/kexec-xen.c b/kexec/kexec-xen.c
index c326955..afcfc5b 100644
--- a/kexec/kexec-xen.c
+++ b/kexec/kexec-xen.c
@@ -64,6 +64,33 @@ int __xc_interface_close(xc_interface *xch)
 }
 #endif /* CONFIG_LIBXENCTRL_DL */
 
+int xen_get_kexec_range(int range, 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, range, 0, &size, start);
+	if (rc < 0) {
+		fprintf(stderr, "failed to get range=%d from hypervisor.\n", range);
+		goto out_close;
+	}
+
+	*end = *start + size - 1;
+
+out_close:
+	xc_interface_close(xc);
+
+out:
+	return rc;
+}
+
 #define IDENTMAP_1MiB (1024 * 1024)
 
 int xen_kexec_load(struct kexec_info *info)
@@ -226,6 +253,11 @@ void xen_kexec_exec(void)
 
 #else /* ! HAVE_LIBXENCTRL */
 
+int xen_get_kexec_range(int range, uint64_t *start, uint64_t *end)
+{
+	return -1;
+}
+
 int xen_kexec_load(struct kexec_info *UNUSED(info))
 {
 	return -1;
diff --git a/kexec/kexec-xen.h b/kexec/kexec-xen.h
index ae67393..603ac94 100644
--- a/kexec/kexec-xen.h
+++ b/kexec/kexec-xen.h
@@ -63,6 +63,9 @@ extern int __xc_interface_close(xc_interface *xch);
 	__xc_call(void *, xc_hypercall_buffer_array_destroy, args)
 
 #endif /* CONFIG_LIBXENCTRL_DL */
+
+int xen_get_kexec_range(int range, uint64_t *start, uint64_t *end);
+
 #endif /* HAVE_LIBXENCTRL */
 
 #endif /* KEXEC_XEN_H */
-- 
2.7.4




Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879




_______________________________________________
kexec mailing list
kexec@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/kexec



[Index of Archives]     [LM Sensors]     [Linux Sound]     [ALSA Users]     [ALSA Devel]     [Linux Audio Users]     [Linux Media]     [Kernel]     [Gimp]     [Yosemite News]     [Linux Media]

  Powered by Linux