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.


device fixes for bugs introduced with new configuration system
Jack Lange [Mon, 7 Dec 2009 23:13:55 +0000 (17:13 -0600)]
palacios/src/devices/lnx_virtio_blk.c
palacios/src/devices/sym_swap.c
palacios/src/devices/tmpdisk.c

index 7bc41a6..a129c7f 100644 (file)
@@ -32,6 +32,8 @@
 #endif
 
 
+#define SECTOR_SIZE 512
+
 #define BLK_CAPACITY_PORT     20
 #define BLK_MAX_SIZE_PORT     28
 #define BLK_MAX_SEG_PORT      32
@@ -136,8 +138,8 @@ static int handle_read_op(struct virtio_blk_state * blk_state, uint8_t * buf, ui
     int ret = -1;
 
     PrintDebug("Reading Disk\n");
-    ret = blk_state->ops->read(buf, *sector, len, (void *)(blk_state->backend_data));
-    *sector += len;
+    ret = blk_state->ops->read(buf, (*sector) * SECTOR_SIZE, len, (void *)(blk_state->backend_data));
+    *sector += (len / SECTOR_SIZE);
 
     return ret;
 }
@@ -147,8 +149,8 @@ static int handle_write_op(struct virtio_blk_state * blk_state, uint8_t * buf, u
     int ret = -1;
 
     PrintDebug("Writing Disk\n");
-    ret = blk_state->ops->write(buf, *sector, len, (void *)(blk_state->backend_data));
-    *sector += len;
+    ret = blk_state->ops->write(buf, (*sector) * SECTOR_SIZE, len, (void *)(blk_state->backend_data));
+    *sector += (len / SECTOR_SIZE);
 
     return ret;
 }
@@ -593,10 +595,10 @@ static int connect_fn(struct guest_info * info,
     blk_state->ops = ops;
     blk_state->backend_data = private_data;
 
-    blk_state->block_cfg.capacity = ops->get_capacity(private_data);
+    blk_state->block_cfg.capacity = ops->get_capacity(private_data) / SECTOR_SIZE;
 
-    PrintDebug("Virtio Capacity = %d -- 0x%p\n", (int)(virtio->block_cfg.capacity), 
-              (void *)(addr_t)(virtio->block_cfg.capacity));
+    PrintDebug("Virtio Capacity = %d -- 0x%p\n", (int)(blk_state->block_cfg.capacity), 
+              (void *)(addr_t)(blk_state->block_cfg.capacity));
 
     return 0;
 }
index dad0419..49b0f32 100644 (file)
@@ -69,6 +69,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 +111,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 +126,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,8 +141,7 @@ 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;
 
@@ -170,7 +169,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 +180,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 +205,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 +279,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;
index a40aa55..fde3cf3 100644 (file)
@@ -23,8 +23,8 @@
 
 struct blk_state {
     uint64_t capacity;
-    uint8_t * blk_space;
     addr_t blk_base_addr;
+    uint8_t * blk_space;
 };
 
 
@@ -42,6 +42,11 @@ static uint64_t blk_get_capacity(void * private_data) {
 static int blk_read(uint8_t * buf, uint64_t lba, uint64_t num_bytes, void * private_data) {
     struct blk_state * blk = (struct blk_state *)private_data;
 
+    if (lba + num_bytes > blk->capacity) {
+       PrintError("TMPDISK Read past end of disk\n");
+       return -1;
+    }
+
     memcpy(buf, blk->blk_space + lba, num_bytes);
 
     return 0;
@@ -53,6 +58,11 @@ static int blk_read(uint8_t * buf, uint64_t lba, uint64_t num_bytes, void * priv
 static int blk_write(uint8_t * buf,  uint64_t lba, uint64_t num_bytes, void * private_data) {
     struct blk_state * blk = (struct blk_state *)private_data;
 
+    if (lba + num_bytes > blk->capacity) {
+       PrintError("TMPDISK Write past end of disk\n");
+       return -1;
+    }
+
     memcpy(blk->blk_space + lba, buf, num_bytes);
 
     return 0;
@@ -86,21 +96,21 @@ static int blk_init(struct guest_info * vm, v3_cfg_tree_t * cfg) {
     struct blk_state * blk = NULL;
     v3_cfg_tree_t * frontend_cfg = v3_cfg_subtree(cfg, "frontend");
     char * name = v3_cfg_val(cfg, "name");
-    uint64_t capacity = atoi(v3_cfg_val(cfg, "size"));
+    uint64_t capacity = atoi(v3_cfg_val(cfg, "size")) * 1024 * 1024;
     
     if (!frontend_cfg) {
        PrintError("Frontend Configuration not present\n");
        return -1;
     }
 
-    PrintDebug("Creating Blk Device\n");
+    PrintDebug("Intializing TMPDISK (capacity=%d)\n", (uint32_t)capacity);
 
 
-    blk = (struct blk_state *)V3_Malloc(sizeof(struct blk_state) + ((capacity / 4096) / 8));
+    blk = (struct blk_state *)V3_Malloc(sizeof(struct blk_state));
 
     blk->capacity = capacity;
-
-    blk->blk_base_addr = (addr_t)V3_AllocPages(capacity / 4096);
+    
+    blk->blk_base_addr = (addr_t)V3_AllocPages(blk->capacity / 4096);
     blk->blk_space = (uint8_t *)V3_VAddr((void *)(blk->blk_base_addr));
     memset(blk->blk_space, 0, capacity);