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.


updated virtio block device to partially handle non-aligned IO requests
[palacios.git] / palacios / src / devices / lnx_virtio_blk.c
index bb29d9a..fd9ec61 100644 (file)
@@ -26,7 +26,7 @@
 
 
 
-#ifndef CONFIG_DEBUG_VIRTIO_BLK
+#ifndef V3_CONFIG_DEBUG_VIRTIO_BLK
 #undef PrintDebug
 #define PrintDebug(fmt, args...)
 #endif
@@ -104,9 +104,7 @@ struct virtio_blk_state {
 };
 
 
-static int virtio_free(struct vm_device * dev) {
-    return -1;
-}
+
 
 static int blk_reset(struct virtio_blk_state * virtio) {
 
@@ -409,38 +407,44 @@ static int virtio_io_read(struct guest_info * core, uint16_t port, void * dst, u
     PrintDebug("VIRTIO BLOCK Read  for port %d (index =%d), length=%d\n", 
               port, port_idx, length);
 
+
     switch (port_idx) {
        case HOST_FEATURES_PORT:
-           if (length != 4) {
-               PrintError("Illegal read length for host features\n");
+       case HOST_FEATURES_PORT + 1:
+       case HOST_FEATURES_PORT + 2:
+       case HOST_FEATURES_PORT + 3:
+           if (port_idx + length > HOST_FEATURES_PORT + 4) {
+               PrintError("Illegal read length for host features (len=%d)\n", length);
                return -1;
            }
 
-           *(uint32_t *)dst = blk_state->virtio_cfg.host_features;
-       
+           memcpy(dst, &(blk_state->virtio_cfg.host_features), length);
            break;
        case VRING_PG_NUM_PORT:
-           if (length != 4) {
-               PrintError("Illegal read length for page frame number\n");
+       case VRING_PG_NUM_PORT + 1:
+       case VRING_PG_NUM_PORT + 2:
+       case VRING_PG_NUM_PORT + 3:
+           if (port_idx + length > VRING_PG_NUM_PORT + 4) {
+               PrintError("Illegal read length for vring pg num (len=%d)\n", length);
                return -1;
            }
 
-           *(uint32_t *)dst = blk_state->queue.pfn;
-
+           memcpy(dst, &(blk_state->queue.pfn), length);
            break;
        case VRING_SIZE_PORT:
-           if (length != 2) {
-               PrintError("Illegal read length for vring size\n");
+       case VRING_SIZE_PORT + 1:
+           if (length > 2) {
+               PrintError("Illegal read length for vring size (len=%d)\n", length);
                return -1;
            }
-               
-           *(uint16_t *)dst = blk_state->queue.queue_size;
+           
+           memcpy(dst, &(blk_state->queue.queue_size), length);
 
            break;
 
        case VIRTIO_STATUS_PORT:
            if (length != 1) {
-               PrintError("Illegal read length for status\n");
+               PrintError("Illegal read length for status (len=%d)\n", length);
                return -1;
            }
 
@@ -473,10 +477,28 @@ static int virtio_io_read(struct guest_info * core, uint16_t port, void * dst, u
 }
 
 
+static int virtio_free(struct virtio_dev_state * virtio) {
+    struct virtio_blk_state * blk_state = NULL;
+    struct virtio_blk_state * tmp = NULL;
+
+    list_for_each_entry_safe(blk_state, tmp, &(virtio->dev_list), dev_link) {
+
+       // unregister from PCI
+
+       list_del(&(blk_state->dev_link));
+       V3_Free(blk_state);
+    }
+    
+
+    V3_Free(virtio);
+
+    return 0;
+}
+
 
 
 static struct v3_device_ops dev_ops = {
-    .free = virtio_free,
+    .free = (int (*)(void *))virtio_free,
 
 };
 
@@ -550,6 +572,10 @@ static int register_dev(struct virtio_dev_state * virtio, struct virtio_blk_stat
     
     
     blk_state->pci_dev = pci_dev;
+
+
+    /* Add backend to list of devices */
+    list_add(&(blk_state->dev_link), &(virtio->dev_list));
     
     /* Block configuration */
     blk_state->virtio_cfg.host_features = VIRTIO_SEG_MAX;