mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 18:50:05 +01:00
[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>
This commit is contained in:
1 parent
0072510b97
commit
0296f1839a
4 files changed
+73
-59
No files matched your search
@@ -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;
|
||||
|
||||
@@ -430,9 +430,10 @@ xc_domain_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
|
||||
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 @@ xc_domain_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
|
||||
|
||||
}
|
||||
|
||||
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 @@ xc_domain_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
|
||||
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);
|
||||
|
||||
@@ -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
|
||||
@@ -59,6 +60,59 @@ xc_get_max_pages(int xc_handle, uint32_t domid)
|
||||
? -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;
|
||||
}
|
||||
|
||||
/*
|
||||
* XXX from xen/include/asm-ia64/linux-xen/asm/pgtable.h
|
||||
* Should PTRS_PER_PTE be exported by arch-ia64.h?
|
||||
|
||||
@@ -175,12 +175,8 @@ xc_core_arch_memory_map_get(int xc_handle,
|
||||
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 @@ xc_core_arch_memory_map_get(int xc_handle,
|
||||
}
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
|
||||