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.


deallocation of devices
[palacios.git] / palacios / src / devices / tmpdisk.c
index 1a917ab..0be279f 100644 (file)
@@ -73,8 +73,11 @@ static int blk_write(uint8_t * buf,  uint64_t lba, uint64_t num_bytes, void * pr
 }
 
 
-static int blk_free(struct vm_device * dev) {
-    return -1;
+static int blk_free(struct blk_state * blk) {
+    V3_FreePages((void *)blk->blk_base_addr, blk->capacity / 4096);
+
+    V3_Free(blk);
+    return 0;
 }
 
 
@@ -87,10 +90,8 @@ static struct v3_dev_blk_ops blk_ops = {
 
 
 static struct v3_device_ops dev_ops = {
-    .free = blk_free,
-    .reset = NULL,
-    .start = NULL,
-    .stop = NULL,
+    .free = (int (*)(void *))blk_free,
+
 };
 
 
@@ -99,7 +100,7 @@ static struct v3_device_ops dev_ops = {
 static int blk_init(struct v3_vm_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");
+    char * dev_id = v3_cfg_val(cfg, "ID");
     uint64_t capacity = atoi(v3_cfg_val(cfg, "size")) * 1024 * 1024;
     
     if (!frontend_cfg) {
@@ -119,17 +120,19 @@ static int blk_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) {
     memset(blk->blk_space, 0, capacity);
 
 
-    struct vm_device * dev = v3_allocate_device(name, &dev_ops, blk);
+    struct vm_device * dev = v3_add_device(vm, dev_id, &dev_ops, blk);
 
-    if (v3_attach_device(vm, dev) == -1) {
-       PrintError("Could not attach device %s\n", name);
+    if (dev == NULL) {
+       PrintError("Could not attach device %s\n", dev_id);
+       V3_Free(blk);
        return -1;
     }
 
     if (v3_dev_connect_blk(vm, v3_cfg_val(frontend_cfg, "tag"), 
                           &blk_ops, frontend_cfg, blk) == -1) {
        PrintError("Could not connect %s to frontend %s\n", 
-                  name, v3_cfg_val(frontend_cfg, "tag"));
+                  dev_id, v3_cfg_val(frontend_cfg, "tag"));
+       v3_remove_device(dev);
        return -1;
     }