Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


debugging tweaks and minor fixes
[palacios.git] / palacios / src / devices / sym_swap.c
index dad0419..ab1a589 100644 (file)
@@ -20,6 +20,7 @@
 #include <palacios/vmm.h>
 #include <palacios/vmm_dev_mgr.h>
 #include <palacios/vmm_sym_swap.h>
+#include <palacios/vm_guest.h>
 
 
 #ifdef CONFIG_SYMBIOTIC_SWAP_TELEMETRY
@@ -69,6 +70,8 @@ struct swap_state {
     uint8_t * swap_space;
     addr_t swap_base_addr;
 
+    struct guest_info * vm;
+
     uint8_t usage_map[0]; // This must be the last structure member
 };
 
@@ -109,8 +112,7 @@ static inline uint32_t get_swap_index_from_offset(uint32_t offset) {
 
 
 static inline void * get_swap_entry(uint32_t pg_index, void * private_data) {
-    struct vm_device * dev = (struct vm_device *)private_data;
-    struct swap_state * swap = (struct swap_state *)(dev->private_data);
+    struct swap_state * swap = (struct swap_state *)private_data;
     void * pg_addr = NULL;
     // int ret = 0;
 
@@ -125,8 +127,7 @@ static inline void * get_swap_entry(uint32_t pg_index, void * private_data) {
 
 
 static uint64_t swap_get_capacity(void * private_data) {
-    struct vm_device * dev = (struct vm_device *)private_data;
-    struct swap_state * swap = (struct swap_state *)(dev->private_data);
+    struct swap_state * swap = (struct swap_state *)private_data;
 
     PrintDebug("SymSwap: Getting Capacity %d\n", (uint32_t)(swap->capacity));
 
@@ -141,16 +142,15 @@ static struct v3_swap_ops swap_ops = {
 
 
 static int swap_read(uint8_t * buf, uint64_t lba, uint64_t num_bytes, void * private_data) {
-    struct vm_device * dev = (struct vm_device *)private_data;
-    struct swap_state * swap = (struct swap_state *)(dev->private_data);
+    struct swap_state * swap = (struct swap_state *)private_data;
     uint32_t offset = lba;
     uint32_t length = num_bytes;
 
   
-    /*  
-       PrintDebug("SymSwap: Reading %d bytes to %p from %p\n", length,
-       buf, (void *)(swap->swap_space + offset));
-    */
+      
+    PrintDebug("SymSwap: Reading %d bytes to %p from %p\n", length,
+              buf, (void *)(swap->swap_space + offset));
+       
 
     if (length % 4096) {
        PrintError("Swapping in length that is not a page multiple\n");
@@ -170,7 +170,7 @@ static int swap_read(uint8_t * buf, uint64_t lba, uint64_t num_bytes, void * pri
 
        for (i = 0; i < length; i += 4096) {
            set_index_usage(swap, get_swap_index_from_offset(offset + i), 0);
-           v3_swap_in_notify(dev->vm, get_swap_index_from_offset(offset + i), swap->hdr->info.type);
+           v3_swap_in_notify(swap->vm, get_swap_index_from_offset(offset + i), swap->hdr->info.type);
        }
     }
 
@@ -181,8 +181,7 @@ static int swap_read(uint8_t * buf, uint64_t lba, uint64_t num_bytes, void * pri
 
 
 static int swap_write(uint8_t * buf,  uint64_t lba, uint64_t num_bytes, void * private_data) {
-    struct vm_device * dev = (struct vm_device *)private_data;
-    struct swap_state * swap = (struct swap_state *)(dev->private_data);
+    struct swap_state * swap = (struct swap_state *)private_data;
     uint32_t offset = lba;
     uint32_t length = num_bytes;
 
@@ -207,7 +206,7 @@ static int swap_write(uint8_t * buf,  uint64_t lba, uint64_t num_bytes, void * p
 
        PrintDebug("Swap Type=%d (magic=%s)\n", swap->hdr->info.type, swap->hdr->magic.magic);
 
-       if (v3_register_swap_disk(dev->vm, swap->hdr->info.type, &swap_ops, dev) == -1) {
+       if (v3_register_swap_disk(swap->vm, swap->hdr->info.type, &swap_ops, swap) == -1) {
            PrintError("Error registering symbiotic swap disk\n");
            return -1;
        }
@@ -281,10 +280,12 @@ static int swap_init(struct guest_info * vm, v3_cfg_tree_t * cfg) {
        return -1;
     }
 
-    PrintDebug("Creating Swap Device\n");
+    PrintDebug("Creating Swap Device (size=%dMB)\n", capacity / (1024 * 1024));
 
     swap = (struct swap_state *)V3_Malloc(sizeof(struct swap_state) + ((capacity / 4096) / 8));
 
+    swap->vm = vm;
+
     swap->capacity = capacity;
 
     swap->swapped_pages = 0;
@@ -314,7 +315,7 @@ static int swap_init(struct guest_info * vm, v3_cfg_tree_t * cfg) {
     }
 
 #ifdef CONFIG_SYMBIOTIC_SWAP_TELEMETRY
-    if (vm->enable_telemetry) {
+    if (vm->enable_telemetry == 1) {
        v3_add_telemetry_cb(vm, telemetry_cb, dev);
     }
 #endif