[IA64] libxc clean up.
remove code duplication between xc_ia64_linux_save.c and xc_core_ia64.c
by introducing xc_ia64_copy_memmap().
Later xc_ia64_copy_memmap() will be enhanced.
Signed-off-by: Isaku Yamahata <yamahata@xxxxxxxxxxxxx>
diff -r 32d38d693280 tools/libxc/ia64/xc_ia64.h
--- a/tools/libxc/ia64/xc_ia64.h Mon Sep 29 21:10:12 2008 +0900
+++ b/tools/libxc/ia64/xc_ia64.h Mon Sep 29 21:11:24 2008 +0900
@@ -21,6 +21,11 @@
#ifndef _XC_IA64_H_
#define _XC_IA64_H_
+int xc_ia64_copy_memmap(int xc_handle, uint32_t domid,
+ shared_info_t *live_shinfo,
+ xen_ia64_memmap_info_t **memmap_info_p,
+ unsigned long *memmap_info_num_pages_p);
+
struct xen_ia64_p2m_table {
unsigned long size;
unsigned long *p2m;
diff -r 32d38d693280 tools/libxc/ia64/xc_ia64_linux_save.c
--- a/tools/libxc/ia64/xc_ia64_linux_save.c Mon Sep 29 21:10:12 2008 +0900
+++ b/tools/libxc/ia64/xc_ia64_linux_save.c Mon Sep 29 21:11:24 2008 +0900
@@ -430,9 +430,10 @@
int qemu_non_active = 1;
/* for foreign p2m exposure */
- unsigned int memmap_info_num_pages;
+ unsigned long memmap_info_num_pages;
+ /* Unsigned int was used before. To keep file format compatibility. */
+ unsigned int memmap_info_num_pages_to_send;
unsigned long memmap_size = 0;
- xen_ia64_memmap_info_t *memmap_info_live = NULL;
xen_ia64_memmap_info_t *memmap_info = NULL;
void *memmap_desc_start;
void *memmap_desc_end;
@@ -566,30 +567,21 @@
}
- memmap_info_num_pages = live_shinfo->arch.memmap_info_num_pages;
- memmap_size = PAGE_SIZE * memmap_info_num_pages;
- memmap_info_live = xc_map_foreign_range(xc_handle, info.domid,
- memmap_size, PROT_READ,
- live_shinfo->arch.memmap_info_pfn);
- if (memmap_info_live == NULL) {
- PERROR("Could not map memmap info.");
+ /* copy before use in case someone updating them */
+ if (xc_ia64_copy_memmap(xc_handle, info.domid, live_shinfo,
+ &memmap_info, &memmap_info_num_pages) != 0) {
+ PERROR("Could not copy memmap");
goto out;
}
- memmap_info = malloc(memmap_size);
- if (memmap_info == NULL) {
- PERROR("Could not allocate memmap info memory");
- goto out;
- }
- memcpy(memmap_info, memmap_info_live, memmap_size);
- munmap(memmap_info_live, memmap_size);
- memmap_info_live = NULL;
-
+ memmap_size = memmap_info_num_pages << PAGE_SHIFT;
+
if (xc_ia64_p2m_map(&p2m_table, xc_handle, dom, memmap_info, 0) < 0) {
PERROR("xc_ia64_p2m_map");
goto out;
}
- if (write_exact(io_fd,
- &memmap_info_num_pages, sizeof(memmap_info_num_pages))) {
+ memmap_info_num_pages_to_send = memmap_info_num_pages;
+ if (write_exact(io_fd, &memmap_info_num_pages_to_send,
+ sizeof(memmap_info_num_pages_to_send))) {
PERROR("write: arch.memmap_info_num_pages");
goto out;
}
@@ -778,8 +770,6 @@
free(to_skip);
if (live_shinfo)
munmap(live_shinfo, PAGE_SIZE);
- if (memmap_info_live)
- munmap(memmap_info_live, memmap_size);
if (memmap_info)
free(memmap_info);
xc_ia64_p2m_unmap(&p2m_table);
diff -r 32d38d693280 tools/libxc/ia64/xc_ia64_stubs.c
--- a/tools/libxc/ia64/xc_ia64_stubs.c Mon Sep 29 21:10:12 2008 +0900
+++ b/tools/libxc/ia64/xc_ia64_stubs.c Mon Sep 29 21:11:24 2008 +0900
@@ -1,4 +1,5 @@
#include "xg_private.h"
+#include "xc_efi.h"
#include "xc_ia64.h"
/* this is a very ugly way of getting FPSR_DEFAULT. struct ia64_fpreg is
@@ -57,6 +58,59 @@
domctl.domain = (domid_t)domid;
return ((do_domctl(xc_handle, &domctl) < 0)
? -1 : domctl.u.getdomaininfo.max_pages);
+}
+
+int
+xc_ia64_copy_memmap(int xc_handle, uint32_t domid, shared_info_t *live_shinfo,
+ xen_ia64_memmap_info_t **memmap_info_p,
+ unsigned long *memmap_info_num_pages_p)
+{
+ unsigned int memmap_info_num_pages;
+ unsigned long memmap_info_pfn;
+ unsigned long memmap_size;
+
+ xen_ia64_memmap_info_t *memmap_info_live;
+ xen_ia64_memmap_info_t *memmap_info;
+
+ /* copy before use in case someone updating them */
+ memmap_info_num_pages = live_shinfo->arch.memmap_info_num_pages;
+ memmap_info_pfn = live_shinfo->arch.memmap_info_pfn;
+ if (memmap_info_num_pages == 0 || memmap_info_pfn == 0) {
+ ERROR("memmap_info_num_pages 0x%x memmap_info_pfn 0x%lx",
+ memmap_info_num_pages, memmap_info_pfn);
+ return -1;
+ }
+
+ memmap_size = memmap_info_num_pages << PAGE_SHIFT;
+ memmap_info_live = xc_map_foreign_range(xc_handle, domid, memmap_size,
+ PROT_READ, memmap_info_pfn);
+ if (memmap_info_live == NULL) {
+ PERROR("Could not map memmap info.");
+ return -1;
+ }
+ memmap_info = malloc(memmap_size);
+ if (memmap_info == NULL) {
+ munmap(memmap_info_live, memmap_size);
+ return -1;
+ }
+ memcpy(memmap_info, memmap_info_live, memmap_size); /* copy before use */
+ munmap(memmap_info_live, memmap_size);
+
+ /* reject unknown memmap */
+ if (memmap_info->efi_memdesc_size != sizeof(efi_memory_desc_t) ||
+ (memmap_info->efi_memmap_size / memmap_info->efi_memdesc_size) == 0 ||
+ memmap_info->efi_memmap_size > memmap_size - sizeof(memmap_info) ||
+ memmap_info->efi_memdesc_version != EFI_MEMORY_DESCRIPTOR_VERSION) {
+ PERROR("unknown memmap header. defaulting to compat mode.");
+ free(memmap_info);
+ return -1;
+ }
+
+ *memmap_info_p = memmap_info;
+ if (memmap_info_num_pages_p != NULL)
+ *memmap_info_num_pages_p = memmap_info_num_pages;
+
+ return 0;
}
/*
diff -r 32d38d693280 tools/libxc/xc_core_ia64.c
--- a/tools/libxc/xc_core_ia64.c Mon Sep 29 21:10:12 2008 +0900
+++ b/tools/libxc/xc_core_ia64.c Mon Sep 29 21:11:24 2008 +0900
@@ -175,12 +175,8 @@
unsigned int *nr_entries)
{
int ret = -1;
- unsigned int memmap_info_num_pages;
- unsigned long memmap_info_pfn;
- xen_ia64_memmap_info_t *memmap_info_live;
xen_ia64_memmap_info_t *memmap_info = NULL;
- unsigned long map_size;
xc_core_memory_map_t *map;
char *start;
char *end;
@@ -194,39 +190,8 @@
}
/* copy before use in case someone updating them */
- memmap_info_num_pages = live_shinfo->arch.memmap_info_num_pages;
- memmap_info_pfn = live_shinfo->arch.memmap_info_pfn;
- if ( memmap_info_num_pages == 0 || memmap_info_pfn == 0 )
- {
- ERROR("memmap_info_num_pages 0x%x memmap_info_pfn 0x%lx",
- memmap_info_num_pages, memmap_info_pfn);
- goto old;
- }
-
- map_size = PAGE_SIZE * memmap_info_num_pages;
- memmap_info_live = xc_map_foreign_range(xc_handle, info->domid,
- map_size, PROT_READ, memmap_info_pfn);
- if ( memmap_info_live == NULL )
- {
- PERROR("Could not map memmap info.");
- return -1;
- }
- memmap_info = malloc(map_size);
- if ( memmap_info == NULL )
- {
- munmap(memmap_info_live, map_size);
- return -1;
- }
- memcpy(memmap_info, memmap_info_live, map_size); /* copy before use */
- munmap(memmap_info_live, map_size);
-
- if ( memmap_info->efi_memdesc_size != sizeof(*md) ||
- (memmap_info->efi_memmap_size / memmap_info->efi_memdesc_size) == 0 ||
- memmap_info->efi_memmap_size > map_size - sizeof(memmap_info) ||
- memmap_info->efi_memdesc_version != EFI_MEMORY_DESCRIPTOR_VERSION )
- {
- PERROR("unknown memmap header. defaulting to compat mode.");
- free(memmap_info);
+ if (xc_ia64_copy_memmap(xc_handle, info->domid, live_shinfo, &memmap_info,
+ NULL)) {
goto old;
}
introduce-xc-ia64-copy-memmap.patch
Description: Text Data
_______________________________________________
Xen-ia64-devel mailing list
Xen-ia64-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-ia64-devel
|