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

[Xen-changelog] [xen-unstable] [IA64] libxc clean up.



# HG changeset patch
# User Isaku Yamahata <yamahata@xxxxxxxxxxxxx>
# Date 1222936077 -32400
# Node ID c8511a5e9a570c5086b96251fb97653ca6de5e88
# Parent  6208fcb4082ffbf457ffde198f3f01ca2a9f64e3
[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>
---
 tools/libxc/ia64/xc_ia64.h            |    5 +++
 tools/libxc/ia64/xc_ia64_linux_save.c |   38 ++++++++---------------
 tools/libxc/ia64/xc_ia64_stubs.c      |   54 ++++++++++++++++++++++++++++++++++
 tools/libxc/xc_core_ia64.c            |   41 +------------------------
 4 files changed, 76 insertions(+), 62 deletions(-)

diff -r 6208fcb4082f -r c8511a5e9a57 tools/libxc/ia64/xc_ia64.h
--- a/tools/libxc/ia64/xc_ia64.h        Thu Oct 02 17:27:57 2008 +0900
+++ b/tools/libxc/ia64/xc_ia64.h        Thu Oct 02 17:27:57 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 6208fcb4082f -r c8511a5e9a57 tools/libxc/ia64/xc_ia64_linux_save.c
--- a/tools/libxc/ia64/xc_ia64_linux_save.c     Thu Oct 02 17:27:57 2008 +0900
+++ b/tools/libxc/ia64/xc_ia64_linux_save.c     Thu Oct 02 17:27:57 2008 +0900
@@ -430,9 +430,10 @@ xc_domain_save(int xc_handle, int io_fd,
     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,
 
     }
 
-    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.");
-        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;
-    
+    /* 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_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,
     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 6208fcb4082f -r c8511a5e9a57 tools/libxc/ia64/xc_ia64_stubs.c
--- a/tools/libxc/ia64/xc_ia64_stubs.c  Thu Oct 02 17:27:57 2008 +0900
+++ b/tools/libxc/ia64/xc_ia64_stubs.c  Thu Oct 02 17:27:57 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
@@ -59,6 +60,59 @@ xc_get_max_pages(int xc_handle, uint32_t
             ? -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?
diff -r 6208fcb4082f -r c8511a5e9a57 tools/libxc/xc_core_ia64.c
--- a/tools/libxc/xc_core_ia64.c        Thu Oct 02 17:27:57 2008 +0900
+++ b/tools/libxc/xc_core_ia64.c        Thu Oct 02 17:27:57 2008 +0900
@@ -175,12 +175,8 @@ xc_core_arch_memory_map_get(int xc_handl
                             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_handl
     }
 
     /* 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;
     }
 

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.