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.


added disk model something or other
Jack Lange [Tue, 12 Jan 2010 20:39:02 +0000 (14:39 -0600)]
palacios/src/devices/disk_model.c [new file with mode: 0644]

diff --git a/palacios/src/devices/disk_model.c b/palacios/src/devices/disk_model.c
new file mode 100644 (file)
index 0000000..75f4526
--- /dev/null
@@ -0,0 +1,131 @@
+/* 
+ * This file is part of the Palacios Virtual Machine Monitor developed
+ * by the V3VEE Project with funding from the United States National 
+ * Science Foundation and the Department of Energy.  
+ *
+ * The V3VEE Project is a joint project between Northwestern University
+ * and the University of New Mexico.  You can find out more at 
+ * http://www.v3vee.org
+ *
+ * Copyright (c) 2008, Jack Lange <jarusl@cs.northwestern.edu>
+ * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org> 
+ * All rights reserved.
+ *
+ * Author: Jack Lange <jarusl@cs.northwestern.edu>
+ *
+ * This is free software.  You are permitted to use,
+ * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
+ */
+
+#include <palacios/vmm.h>
+#include <palacios/vmm_dev_mgr.h>
+#include <palacios/vmm_sym_swap.h>
+#include <palacios/vm_guest.h>
+
+
+
+void __udelay(unsigned long usecs);
+
+
+struct disk_state {
+    struct v3_dev_blk_ops * ops;
+    uint32_t seek_usecs;
+
+    void * private_data;
+};
+
+
+static int model_write(uint8_t * buf,  uint64_t lba, uint64_t num_bytes, void * private_data) {
+    struct disk_state * model = (struct disk_state *)private_data;
+    
+    __udelay(model->seek_usecs);
+
+    return model->ops->write(buf, lba, num_bytes, model->private_data);
+
+}
+
+static int model_read(uint8_t * buf,  uint64_t lba, uint64_t num_bytes, void * private_data) {
+    struct disk_state * model = (struct disk_state *)private_data;
+    
+    __udelay(model->seek_usecs);
+
+    return model->ops->read(buf, lba, num_bytes, model->private_data);
+
+}
+
+static uint64_t model_get_capacity(void * private_data) {
+    struct disk_state * model = (struct disk_state *)private_data;
+
+    return model->ops->get_capacity(model->private_data);
+}
+
+static int model_free(struct vm_device * dev) {
+    return -1;
+}
+
+
+
+static struct v3_dev_blk_ops blk_ops = {
+    .read = model_read, 
+    .write = model_write, 
+    .get_capacity = model_get_capacity,
+};
+
+
+
+static struct v3_device_ops dev_ops = {
+    .free = model_free,
+    .reset = NULL,
+    .start = NULL,
+    .stop = NULL,
+};
+
+
+static int connect_fn(struct guest_info * info, 
+                     void * frontend_data, 
+                     struct v3_dev_blk_ops * ops, 
+                     v3_cfg_tree_t * cfg, 
+                     void * private_data) {
+
+  v3_cfg_tree_t * frontend_cfg = v3_cfg_subtree(cfg, "frontend");
+  uint32_t seek_time = atoi(v3_cfg_val(cfg, "seek_us"));
+  struct disk_state * model = (struct disk_state *)V3_Malloc(sizeof(struct disk_state));
+
+
+  model->ops = ops;
+  model->seek_usecs = seek_time;
+  model->private_data = private_data;
+
+  if (v3_dev_connect_blk(info, v3_cfg_val(frontend_cfg, "tag"), 
+                        &blk_ops, frontend_cfg, model) == -1) {
+      PrintError("Could not connect  to frontend %s\n", 
+                 v3_cfg_val(frontend_cfg, "tag"));
+      return -1;
+  }
+
+  return 0;
+}
+
+static int model_init(struct guest_info * vm, v3_cfg_tree_t * cfg) {
+
+    char * name = v3_cfg_val(cfg, "name");
+
+    struct vm_device * dev = v3_allocate_device(name, &dev_ops, NULL);
+
+    if (v3_attach_device(vm, dev) == -1) {
+       PrintError("Could not attach device %s\n", name);
+       return -1;
+    }
+
+    if (v3_dev_add_blk_frontend(vm, name, connect_fn, NULL) == -1) {
+       PrintError("Could not register %s as block frontend\n", name);
+       return -1;
+    }
+
+
+    return 0;
+}
+
+
+
+device_register("DISK_MODEL", model_init)