ia64/xen-unstable
changeset 18571:c8511a5e9a57
[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@valinux.co.jp>
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@valinux.co.jp>
author | Isaku Yamahata <yamahata@valinux.co.jp> |
---|---|
date | Thu Oct 02 17:27:57 2008 +0900 (2008-10-02) |
parents | 6208fcb4082f |
children | 591734b38585 |
files | tools/libxc/ia64/xc_ia64.h tools/libxc/ia64/xc_ia64_linux_save.c tools/libxc/ia64/xc_ia64_stubs.c tools/libxc/xc_core_ia64.c |
line diff
1.1 --- a/tools/libxc/ia64/xc_ia64.h Thu Oct 02 17:27:57 2008 +0900 1.2 +++ b/tools/libxc/ia64/xc_ia64.h Thu Oct 02 17:27:57 2008 +0900 1.3 @@ -21,6 +21,11 @@ 1.4 #ifndef _XC_IA64_H_ 1.5 #define _XC_IA64_H_ 1.6 1.7 +int xc_ia64_copy_memmap(int xc_handle, uint32_t domid, 1.8 + shared_info_t *live_shinfo, 1.9 + xen_ia64_memmap_info_t **memmap_info_p, 1.10 + unsigned long *memmap_info_num_pages_p); 1.11 + 1.12 struct xen_ia64_p2m_table { 1.13 unsigned long size; 1.14 unsigned long *p2m;
2.1 --- a/tools/libxc/ia64/xc_ia64_linux_save.c Thu Oct 02 17:27:57 2008 +0900 2.2 +++ b/tools/libxc/ia64/xc_ia64_linux_save.c Thu Oct 02 17:27:57 2008 +0900 2.3 @@ -430,9 +430,10 @@ xc_domain_save(int xc_handle, int io_fd, 2.4 int qemu_non_active = 1; 2.5 2.6 /* for foreign p2m exposure */ 2.7 - unsigned int memmap_info_num_pages; 2.8 + unsigned long memmap_info_num_pages; 2.9 + /* Unsigned int was used before. To keep file format compatibility. */ 2.10 + unsigned int memmap_info_num_pages_to_send; 2.11 unsigned long memmap_size = 0; 2.12 - xen_ia64_memmap_info_t *memmap_info_live = NULL; 2.13 xen_ia64_memmap_info_t *memmap_info = NULL; 2.14 void *memmap_desc_start; 2.15 void *memmap_desc_end; 2.16 @@ -566,30 +567,21 @@ xc_domain_save(int xc_handle, int io_fd, 2.17 2.18 } 2.19 2.20 - memmap_info_num_pages = live_shinfo->arch.memmap_info_num_pages; 2.21 - memmap_size = PAGE_SIZE * memmap_info_num_pages; 2.22 - memmap_info_live = xc_map_foreign_range(xc_handle, info.domid, 2.23 - memmap_size, PROT_READ, 2.24 - live_shinfo->arch.memmap_info_pfn); 2.25 - if (memmap_info_live == NULL) { 2.26 - PERROR("Could not map memmap info."); 2.27 + /* copy before use in case someone updating them */ 2.28 + if (xc_ia64_copy_memmap(xc_handle, info.domid, live_shinfo, 2.29 + &memmap_info, &memmap_info_num_pages) != 0) { 2.30 + PERROR("Could not copy memmap"); 2.31 goto out; 2.32 } 2.33 - memmap_info = malloc(memmap_size); 2.34 - if (memmap_info == NULL) { 2.35 - PERROR("Could not allocate memmap info memory"); 2.36 - goto out; 2.37 - } 2.38 - memcpy(memmap_info, memmap_info_live, memmap_size); 2.39 - munmap(memmap_info_live, memmap_size); 2.40 - memmap_info_live = NULL; 2.41 - 2.42 + memmap_size = memmap_info_num_pages << PAGE_SHIFT; 2.43 + 2.44 if (xc_ia64_p2m_map(&p2m_table, xc_handle, dom, memmap_info, 0) < 0) { 2.45 PERROR("xc_ia64_p2m_map"); 2.46 goto out; 2.47 } 2.48 - if (write_exact(io_fd, 2.49 - &memmap_info_num_pages, sizeof(memmap_info_num_pages))) { 2.50 + memmap_info_num_pages_to_send = memmap_info_num_pages; 2.51 + if (write_exact(io_fd, &memmap_info_num_pages_to_send, 2.52 + sizeof(memmap_info_num_pages_to_send))) { 2.53 PERROR("write: arch.memmap_info_num_pages"); 2.54 goto out; 2.55 } 2.56 @@ -778,8 +770,6 @@ xc_domain_save(int xc_handle, int io_fd, 2.57 free(to_skip); 2.58 if (live_shinfo) 2.59 munmap(live_shinfo, PAGE_SIZE); 2.60 - if (memmap_info_live) 2.61 - munmap(memmap_info_live, memmap_size); 2.62 if (memmap_info) 2.63 free(memmap_info); 2.64 xc_ia64_p2m_unmap(&p2m_table);
3.1 --- a/tools/libxc/ia64/xc_ia64_stubs.c Thu Oct 02 17:27:57 2008 +0900 3.2 +++ b/tools/libxc/ia64/xc_ia64_stubs.c Thu Oct 02 17:27:57 2008 +0900 3.3 @@ -1,4 +1,5 @@ 3.4 #include "xg_private.h" 3.5 +#include "xc_efi.h" 3.6 #include "xc_ia64.h" 3.7 3.8 /* this is a very ugly way of getting FPSR_DEFAULT. struct ia64_fpreg is 3.9 @@ -59,6 +60,59 @@ xc_get_max_pages(int xc_handle, uint32_t 3.10 ? -1 : domctl.u.getdomaininfo.max_pages); 3.11 } 3.12 3.13 +int 3.14 +xc_ia64_copy_memmap(int xc_handle, uint32_t domid, shared_info_t *live_shinfo, 3.15 + xen_ia64_memmap_info_t **memmap_info_p, 3.16 + unsigned long *memmap_info_num_pages_p) 3.17 +{ 3.18 + unsigned int memmap_info_num_pages; 3.19 + unsigned long memmap_info_pfn; 3.20 + unsigned long memmap_size; 3.21 + 3.22 + xen_ia64_memmap_info_t *memmap_info_live; 3.23 + xen_ia64_memmap_info_t *memmap_info; 3.24 + 3.25 + /* copy before use in case someone updating them */ 3.26 + memmap_info_num_pages = live_shinfo->arch.memmap_info_num_pages; 3.27 + memmap_info_pfn = live_shinfo->arch.memmap_info_pfn; 3.28 + if (memmap_info_num_pages == 0 || memmap_info_pfn == 0) { 3.29 + ERROR("memmap_info_num_pages 0x%x memmap_info_pfn 0x%lx", 3.30 + memmap_info_num_pages, memmap_info_pfn); 3.31 + return -1; 3.32 + } 3.33 + 3.34 + memmap_size = memmap_info_num_pages << PAGE_SHIFT; 3.35 + memmap_info_live = xc_map_foreign_range(xc_handle, domid, memmap_size, 3.36 + PROT_READ, memmap_info_pfn); 3.37 + if (memmap_info_live == NULL) { 3.38 + PERROR("Could not map memmap info."); 3.39 + return -1; 3.40 + } 3.41 + memmap_info = malloc(memmap_size); 3.42 + if (memmap_info == NULL) { 3.43 + munmap(memmap_info_live, memmap_size); 3.44 + return -1; 3.45 + } 3.46 + memcpy(memmap_info, memmap_info_live, memmap_size); /* copy before use */ 3.47 + munmap(memmap_info_live, memmap_size); 3.48 + 3.49 + /* reject unknown memmap */ 3.50 + if (memmap_info->efi_memdesc_size != sizeof(efi_memory_desc_t) || 3.51 + (memmap_info->efi_memmap_size / memmap_info->efi_memdesc_size) == 0 || 3.52 + memmap_info->efi_memmap_size > memmap_size - sizeof(memmap_info) || 3.53 + memmap_info->efi_memdesc_version != EFI_MEMORY_DESCRIPTOR_VERSION) { 3.54 + PERROR("unknown memmap header. defaulting to compat mode."); 3.55 + free(memmap_info); 3.56 + return -1; 3.57 + } 3.58 + 3.59 + *memmap_info_p = memmap_info; 3.60 + if (memmap_info_num_pages_p != NULL) 3.61 + *memmap_info_num_pages_p = memmap_info_num_pages; 3.62 + 3.63 + return 0; 3.64 +} 3.65 + 3.66 /* 3.67 * XXX from xen/include/asm-ia64/linux-xen/asm/pgtable.h 3.68 * Should PTRS_PER_PTE be exported by arch-ia64.h?
4.1 --- a/tools/libxc/xc_core_ia64.c Thu Oct 02 17:27:57 2008 +0900 4.2 +++ b/tools/libxc/xc_core_ia64.c Thu Oct 02 17:27:57 2008 +0900 4.3 @@ -175,12 +175,8 @@ xc_core_arch_memory_map_get(int xc_handl 4.4 unsigned int *nr_entries) 4.5 { 4.6 int ret = -1; 4.7 - unsigned int memmap_info_num_pages; 4.8 - unsigned long memmap_info_pfn; 4.9 4.10 - xen_ia64_memmap_info_t *memmap_info_live; 4.11 xen_ia64_memmap_info_t *memmap_info = NULL; 4.12 - unsigned long map_size; 4.13 xc_core_memory_map_t *map; 4.14 char *start; 4.15 char *end; 4.16 @@ -194,39 +190,8 @@ xc_core_arch_memory_map_get(int xc_handl 4.17 } 4.18 4.19 /* copy before use in case someone updating them */ 4.20 - memmap_info_num_pages = live_shinfo->arch.memmap_info_num_pages; 4.21 - memmap_info_pfn = live_shinfo->arch.memmap_info_pfn; 4.22 - if ( memmap_info_num_pages == 0 || memmap_info_pfn == 0 ) 4.23 - { 4.24 - ERROR("memmap_info_num_pages 0x%x memmap_info_pfn 0x%lx", 4.25 - memmap_info_num_pages, memmap_info_pfn); 4.26 - goto old; 4.27 - } 4.28 - 4.29 - map_size = PAGE_SIZE * memmap_info_num_pages; 4.30 - memmap_info_live = xc_map_foreign_range(xc_handle, info->domid, 4.31 - map_size, PROT_READ, memmap_info_pfn); 4.32 - if ( memmap_info_live == NULL ) 4.33 - { 4.34 - PERROR("Could not map memmap info."); 4.35 - return -1; 4.36 - } 4.37 - memmap_info = malloc(map_size); 4.38 - if ( memmap_info == NULL ) 4.39 - { 4.40 - munmap(memmap_info_live, map_size); 4.41 - return -1; 4.42 - } 4.43 - memcpy(memmap_info, memmap_info_live, map_size); /* copy before use */ 4.44 - munmap(memmap_info_live, map_size); 4.45 - 4.46 - if ( memmap_info->efi_memdesc_size != sizeof(*md) || 4.47 - (memmap_info->efi_memmap_size / memmap_info->efi_memdesc_size) == 0 || 4.48 - memmap_info->efi_memmap_size > map_size - sizeof(memmap_info) || 4.49 - memmap_info->efi_memdesc_version != EFI_MEMORY_DESCRIPTOR_VERSION ) 4.50 - { 4.51 - PERROR("unknown memmap header. defaulting to compat mode."); 4.52 - free(memmap_info); 4.53 + if (xc_ia64_copy_memmap(xc_handle, info->domid, live_shinfo, &memmap_info, 4.54 + NULL)) { 4.55 goto old; 4.56 } 4.57