Home
Install
$ cd virtio
$ make && kldload ./virtio.ko
$ cd blk
$ make && kldload ./virtio-blk.ko
Architecture/Implementation
The virtio infrastructure and blk driver is a port of NetBSD’s virtio drivers originally written by Minoura Makoto. To expedite development, we tried to keep the same architecture and as much of the common code as possible. In virtio, each device shows up as a pci device. For example, here is lspci from a network and two block devices on the guest:
00:04.0 Ethernet controller: Qumranet, Inc. Virtio network device
Subsystem: Qumranet, Inc. Device 0001
Flags: fast devsel, IRQ 11
I/O ports at c200
Memory at e2021000 (32-bit, non-prefetchable)
Capabilities: [40] MSI-X: Enable- Count=3 Masked-
00:05.0 SCSI storage controller: Qumranet, Inc. Virtio block device
Subsystem: Qumranet, Inc. Device 0002
Flags: fast devsel, IRQ 10
I/O ports at c240
Memory at e2022000 (32-bit, non-prefetchable)
Capabilities: [40] MSI-X: Enable- Count=2 Masked-
00:06.0 SCSI storage controller: Qumranet, Inc. Virtio block device
Subsystem: Qumranet, Inc. Device 0002
Flags: fast devsel, IRQ 10
I/O ports at c280
Memory at e2023000 (32-bit, non-prefetchable)
Capabilities: [40] MSI-X: Enable- Count=2 Masked-
In virtio’s attach function, we do several things:
– allocate resources for the interrupt
– set up the irq
– initialize the backend state
– create the base parent tag
– add a child device
We add a child device because the virtio driver has consumed the pci device and this enables probe to be called when we load the child driver. Note, that the only real reason we did it this way is because this is how NetBSD implemented the drivers.
In virtio-blk’s attach, we do two things: register with the backend, and setup a Dfly disk:
– negotiate the features we want want regarding the device
– allocate the virtioqueue
– setup the interrupt callback functions
– create and attach the disk, and add devstat entry

