#endif
+#define SECTOR_SIZE 512
+
#define BLK_CAPACITY_PORT 20
#define BLK_MAX_SIZE_PORT 28
#define BLK_MAX_SEG_PORT 32
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;
}
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;
}
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;
}
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
};
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;
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));
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;
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);
}
}
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;
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;
}
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;
struct blk_state {
uint64_t capacity;
- uint8_t * blk_space;
addr_t blk_base_addr;
+ uint8_t * blk_space;
};
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;
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;
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);