Skip to contentSkip to conversation

userspace virtio

PATCH In review Dor Laor 1 participant 1 message Dec 21, 2007 KVM

lore
Share & tools
lore

Dor Laor

author
#0 lore raw

PATCH 3/7 userspace virtio

From 4780a4792ca7776268107e200ae77003c36d55c9 Mon Sep 17 00:00:00 2001
From: Dor Laor <dor.laor-atKUWr5tajBWk0Htik3J/[email protected]>
Date: Wed, 19 Dec 2007 23:52:43 +0200
Subject: [PATCH] virtio block device

This patch implements the backend support for the virtio block device. It's designed to support in-order queueing of a virtually unlimited size so it will
be able to perform better than SCSI. Besides performance, the virtio block interface passes through guest SCSI commands so it can be used to expose any type of block device (although only normal disks are supported in this patch).

Cc Rusty Russell <rusty-8n+1lVoiYb80n/[email protected]>
Cc Avi Kivity <avi-atKUWr5tajBWk0Htik3J/[email protected]>
Cc Dor Laor <dor.laor-atKUWr5tajBWk0Htik3J/[email protected]>
---
 qemu/Makefile.target |    2 +-
 qemu/hw/pc.c         |   12 ++++
 qemu/hw/pc.h         |    4 +
 qemu/hw/virtio-blk.c |  163 
++++++++++++++++++++++++++++++++++++++++++++++++++
 qemu/sysemu.h        |    2 +-
 qemu/vl.c            |    4 +
 6 files changed, 185 insertions(+), 2 deletions(-)
 create mode 100644 qemu/hw/virtio-blk.c
qemu/Makefile.target +1 -1
index 17ff6f2..535f4f5 100644
@@ -464,7 +464,7 @@ VL_OBJS += rtl8139.o
 VL_OBJS+= hypercall.o
 
 # virtio devices
-VL_OBJS += virtio.o virtio-net.o
+VL_OBJS += virtio.o virtio-net.o virtio-blk.o
 
 ifeq ($(TARGET_BASE_ARCH), i386)
 # Hardware support
qemu/hw/pc.c +0 -0
index dde40c3..003d15d 100644
@@ -1103,6 +1103,18 @@ static void pc_init1(ram_addr_t ram_size, int 

vga_ram_size,

         }
         }
     }
+
+    /* Add virtio block devices */
+    if (pci_enabled) {
+    int index;
+    int unit_id = 0;

+
+ while ((index = drive_get_index(IF_VIRTIO, 0, unit_id)) != -1) {
+ virtio_blk_init(pci_bus, 0x5002, 0x2258,
+ drives_table[index].bdrv);
+ unit_id++;
+ }
+ }
}

static void pc_init_pci(ram_addr_t ram_size, int vga_ram_size,

qemu/hw/pc.h +0 -0
index ce1a1f3..95471f3 100644
@@ -147,4 +147,8 @@ void isa_ne2000_init(int base, qemu_irq irq, NICInfo 

*nd);
void *virtio_net_init(PCIBus *bus, NICInfo *nd, int devfn);

+/* virtio-blk.h */
+void *virtio_blk_init(PCIBus *bus, uint16_t vendor, uint16_t device,
+ BlockDriverState *bs);
+
#endif

qemu/hw/virtio-blk.c new file +163 -0

163 lines not on this page · raw message

qemu/sysemu.h +1 -1
index 1f5b093..e20159d 100644
@@ -117,7 +117,7 @@ extern unsigned int nb_prom_envs;
 #endif
 
 typedef enum {
-    IF_IDE, IF_SCSI, IF_FLOPPY, IF_PFLASH, IF_MTD, IF_SD
+    IF_IDE, IF_SCSI, IF_FLOPPY, IF_PFLASH, IF_MTD, IF_SD, IF_VIRTIO
 } BlockInterfaceType;
 
 typedef struct DriveInfo {
qemu/vl.c +0 -0
index 28c5df4..26055a4 100644
@@ -4970,6 +4970,9 @@ static int drive_init(const char *str, int 

snapshot, QEMUMachine *machine)

     } else if (!strcmp(buf, "sd")) {
         interface = IF_SD;
             max_devs = 0;

+ } else if (!strcmp(buf, "virtio")) {
+ interface = IF_VIRTIO;
+ max_devs = 0;
} else {
fprintf(stderr, "qemu: '%s' unsupported bus type '%s'\n",

str, buf);
             return -1;
@@ -5143,6 +5146,7 @@ static int drive_init(const char *str, int 
snapshot, QEMUMachine *machine)
         break;
     case IF_PFLASH:
     case IF_MTD:
+    case IF_VIRTIO:
         break;
     }
     if (!file[0])
Signature · 7 lines
1.5.3.3


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/