xenpaging: move page_buffer into struct xenpaging
authorOlaf Hering <olaf@aepfle.de>
Mon, 20 Feb 2012 20:18:44 +0000 (21:18 +0100)
committerOlaf Hering <olaf@aepfle.de>
Mon, 20 Feb 2012 20:18:44 +0000 (21:18 +0100)
Signed-off-by: Olaf Hering <olaf@aepfle.de>
Committed-by: Ian Jackson <ian.jackson.citrix.com>
tools/xenpaging/xenpaging.c
tools/xenpaging/xenpaging.h

index 6562ef1084e891edda58ea11ddad5c6c163f09bf..5f943b5ad773bd38e531b34538e5a9c6a9339d70 100644 (file)
@@ -44,7 +44,6 @@ static char *dom_path;
 static char watch_token[16];
 static char *filename;
 static int interrupted;
-static void *paging_buffer = NULL;
 
 static void unlink_pagefile(void)
 {
@@ -441,8 +440,8 @@ static struct xenpaging *xenpaging_init(int argc, char *argv[])
         goto err;
     }
 
-    paging_buffer = init_page();
-    if ( !paging_buffer )
+    paging->paging_buffer = init_page();
+    if ( !paging->paging_buffer )
     {
         PERROR("Creating page aligned load buffer");
         goto err;
@@ -465,6 +464,11 @@ static struct xenpaging *xenpaging_init(int argc, char *argv[])
             xs_close(paging->xs_handle);
         if ( xch )
             xc_interface_close(xch);
+        if ( paging->paging_buffer )
+        {
+            munlock(paging->paging_buffer, PAGE_SIZE);
+            free(paging->paging_buffer);
+        }
         if ( paging->mem_event.shared_page )
         {
             munlock(paging->mem_event.shared_page, PAGE_SIZE);
@@ -687,7 +691,7 @@ static int xenpaging_populate_page(struct xenpaging *paging, unsigned long gfn,
     DPRINTF("populate_page < gfn %lx pageslot %d\n", gfn, i);
 
     /* Read page */
-    ret = read_page(paging->fd, paging_buffer, i);
+    ret = read_page(paging->fd, paging->paging_buffer, i);
     if ( ret != 0 )
     {
         PERROR("Error reading page");
@@ -697,8 +701,7 @@ static int xenpaging_populate_page(struct xenpaging *paging, unsigned long gfn,
     do
     {
         /* Tell Xen to allocate a page for the domain */
-        ret = xc_mem_paging_load(xch, paging->mem_event.domain_id, gfn,
-                                    paging_buffer);
+        ret = xc_mem_paging_load(xch, paging->mem_event.domain_id, gfn, paging->paging_buffer);
         if ( ret < 0 )
         {
             if ( errno == ENOMEM )
index b5f160d8c31a491c44b4a5f598571768758bff9d..746556b1a063326d9d4ec899ea53902d1099c102 100644 (file)
@@ -49,6 +49,8 @@ struct xenpaging {
     unsigned long *slot_to_gfn;
     int *gfn_to_slot;
 
+    void *paging_buffer;
+
     struct mem_event mem_event;
     int fd;
     /* number of pages for which data structures were allocated */