X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fdevices%2Fswapbypass_cache2.c;h=776c34ae72c60430ad710853b39ef8b71c16ebc7;hb=e61e0890e6f13b1362cfffdcd287e90f1d41e443;hp=bc83762db36f1768082f073fae92dc28c3124640;hpb=e5e029575affad90c19ca038a3b780820535d421;p=palacios.git diff --git a/palacios/src/devices/swapbypass_cache2.c b/palacios/src/devices/swapbypass_cache2.c index bc83762..776c34a 100644 --- a/palacios/src/devices/swapbypass_cache2.c +++ b/palacios/src/devices/swapbypass_cache2.c @@ -24,7 +24,7 @@ #include -#ifdef CONFIG_SWAPBYPASS_TELEMETRY +#ifdef V3_CONFIG_SWAPBYPASS_TELEMETRY #include #endif @@ -83,7 +83,7 @@ struct swap_state { struct v3_dev_blk_ops * ops; void * private_data; -#ifdef CONFIG_SWAPBYPASS_TELEMETRY +#ifdef V3_CONFIG_SWAPBYPASS_TELEMETRY uint32_t pages_in; uint32_t pages_out; #endif @@ -235,7 +235,7 @@ static int buf_read(uint8_t * buf, uint64_t lba, uint64_t num_bytes, void * priv swap->unswapped_pages += (length / 4096); -#ifdef CONFIG_SWAPBYPASS_TELEMETRY +#ifdef V3_CONFIG_SWAPBYPASS_TELEMETRY swap->pages_in += length / 4096; #endif @@ -384,7 +384,7 @@ static int buf_write(uint8_t * buf, uint64_t lba, uint64_t num_bytes, void * pr swap->swapped_pages += written_pages; -#ifdef CONFIG_SWAPBYPASS_TELEMETRY +#ifdef V3_CONFIG_SWAPBYPASS_TELEMETRY swap->pages_out += length / 4096; #endif @@ -506,7 +506,7 @@ static struct v3_device_ops dev_ops = { }; -#ifdef CONFIG_SWAPBYPASS_TELEMETRY +#ifdef V3_CONFIG_SWAPBYPASS_TELEMETRY static void telemetry_cb(struct v3_vm_info * vm, void * private_data, char * hdr) { struct swap_state * swap = (struct swap_state *)private_data; @@ -540,6 +540,11 @@ static int connect_fn(struct v3_vm_info * vm, swap = (struct swap_state *)V3_Malloc(sizeof(struct swap_state)); + if (!swap) { + PrintError("Cannot allocate in connect\n"); + return -1; + } + swap->vm = vm; swap->cache_size = cache_size; swap->io_flag = 0; @@ -561,6 +566,12 @@ static int connect_fn(struct v3_vm_info * vm, INIT_LIST_HEAD(&(swap->entry_list)); INIT_LIST_HEAD(&(swap->free_list)); swap->entry_map = (struct cache_entry *)V3_Malloc(sizeof(struct cache_entry) * (cache_size / 4096)); + + if (!swap->entry_map) { + PrintError("Cannot allocate in connect\n"); + return -1; + } + for (i = 0; i < (cache_size / 4096); i++) { list_add(&(swap->entry_map[i].cache_node), &(swap->free_list)); @@ -571,6 +582,14 @@ static int connect_fn(struct v3_vm_info * vm, swap->active = 0; swap->cache_base_addr = (addr_t)V3_AllocPages(swap->cache_size / 4096); + + if (!swap->cache_base_addr) { + PrintError("Cannot allocate cache space\n"); + V3_Free(swap); + return -1; + } + + swap->cache = (uint8_t *)V3_VAddr((void *)(addr_t)(swap->cache_base_addr)); memset(swap->cache, 0, swap->cache_size); } @@ -583,7 +602,7 @@ static int connect_fn(struct v3_vm_info * vm, } -#ifdef CONFIG_SWAPBYPASS_TELEMETRY +#ifdef V3_CONFIG_SWAPBYPASS_TELEMETRY if (vm->enable_telemetry == 1) { v3_add_telemetry_cb(vm, telemetry_cb, swap);