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.


Fix to direct host network bridge
[palacios-OLD.git] / palacios / src / devices / nvram.c
index e08d5d3..6fc974f 100644 (file)
@@ -743,7 +743,11 @@ static int nvram_write_data_port(struct guest_info * core, ushort_t port,
 
 
 
-static int nvram_free(struct vm_device * dev) {
+static int nvram_free(struct nvram_internal * nvram_state) {
+
+    // unregister host events
+
+    V3_Free(nvram_state);
     return 0;
 }
 
@@ -752,7 +756,7 @@ static int nvram_free(struct vm_device * dev) {
 
 
 static struct v3_device_ops dev_ops = {  
-    .free = nvram_free,
+    .free = (int (*)(void *))nvram_free,
 };
 
 
@@ -763,6 +767,7 @@ static int nvram_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) {
     struct nvram_internal * nvram_state = NULL;
     struct vm_device * ide = v3_find_dev(vm, v3_cfg_val(cfg, "storage"));
     char * dev_id = v3_cfg_val(cfg, "ID");
+    int ret = 0;
 
     if (!ide) {
        PrintError("Could not find IDE device\n");
@@ -777,20 +782,26 @@ static int nvram_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) {
     nvram_state->ide = ide;
     nvram_state->vm = vm;
 
-    struct vm_device * dev = v3_allocate_device(dev_id, &dev_ops, nvram_state);
-
+    struct vm_device * dev = v3_add_device(vm, dev_id, &dev_ops, nvram_state);
 
-    if (v3_attach_device(vm, dev) == -1) {
+    if (dev == NULL) {
        PrintError("Could not attach device %s\n", dev_id);
+       V3_Free(nvram_state);
        return -1;
     }
 
     init_nvram_state(vm, nvram_state);
 
     // hook ports
-    v3_dev_hook_io(dev, NVRAM_REG_PORT, NULL, &nvram_write_reg_port);
-    v3_dev_hook_io(dev, NVRAM_DATA_PORT, &nvram_read_data_port, &nvram_write_data_port);
+    ret |= v3_dev_hook_io(dev, NVRAM_REG_PORT, NULL, &nvram_write_reg_port);
+    ret |= v3_dev_hook_io(dev, NVRAM_DATA_PORT, &nvram_read_data_port, &nvram_write_data_port);
   
+    if (ret != 0) {
+       PrintError("Error hooking NVRAM IO ports\n");
+       v3_remove_device(dev);
+       return -1;
+    }
+
     v3_hook_host_event(vm, HOST_TIMER_EVT, V3_HOST_EVENT_HANDLER(handle_timer_event), nvram_state);
 
     return 0;