From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IzhYN-0000R1-Tz for qemu-devel@nongnu.org; Tue, 04 Dec 2007 18:51:52 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IzhYL-0000NX-0l for qemu-devel@nongnu.org; Tue, 04 Dec 2007 18:51:51 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IzhYK-0000NM-OM for qemu-devel@nongnu.org; Tue, 04 Dec 2007 18:51:48 -0500 Received: from ug-out-1314.google.com ([66.249.92.171]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1IzhYJ-0000EA-SK for qemu-devel@nongnu.org; Tue, 04 Dec 2007 18:51:48 -0500 Received: by ug-out-1314.google.com with SMTP id m2so228614uge for ; Tue, 04 Dec 2007 15:51:46 -0800 (PST) Message-ID: <4755E810.4000106@qumranet.com> Date: Wed, 05 Dec 2007 01:51:44 +0200 MIME-Version: 1.0 References: <4755CCAD.7010403@us.ibm.com> In-Reply-To: <4755CCAD.7010403@us.ibm.com> Content-Type: multipart/alternative; boundary="------------020902040100080302030706" From: Dor Laor Subject: [Qemu-devel] Re: [PATCH 3/3] virtio block device Reply-To: dor.laor@qumranet.com, qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: Rusty Russell , qemu-devel@nongnu.org This is a multi-part message in MIME format. --------------020902040100080302030706 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Anthony Liguori wrote: Subject: [PATCH 3/3] virtio block device + +static void virtio_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq) +{ + VirtIOBlock *s = to_virtio_blk(vdev); + VirtQueueElement elem; + unsigned int count; + + while ((count = virtqueue_pop(vq, &elem)) != 0) { + struct virtio_blk_inhdr *in; + struct virtio_blk_outhdr *out; + unsigned int wlen; + off_t off; + int i; + + out = (void *)elem.out_sg[0].iov_base; + in = (void *)elem.in_sg[elem.in_num - 1].iov_base; + off = out->sector; + + if (out->type & VIRTIO_BLK_T_SCSI_CMD) { + wlen = sizeof(*in); + in->status = VIRTIO_BLK_S_UNSUPP; + } else if (out->type & VIRTIO_BLK_T_OUT) { + wlen = sizeof(*in); + + for (i = 1; i < elem.out_num; i++) { + bdrv_write(s->bs, off, + elem.out_sg[i].iov_base, + elem.out_sg[i].iov_len / 512); + off += elem.out_sg[i].iov_len / 512; + } + + in->status = VIRTIO_BLK_S_OK; + } else { + wlen = sizeof(*in); + + for (i = 0; i < elem.in_num - 1; i++) { + bdrv_read(s->bs, off, + elem.in_sg[i].iov_base, + elem.in_sg[i].iov_len / 512); + off += elem.in_sg[i].iov_len / 512; + wlen += elem.in_sg[i].iov_len; + } + + in->status = VIRTIO_BLK_S_OK; + } + + virtqueue_push(vq, &elem, wlen); + virtio_notify(vdev, vq); + } The notify here should also be outside the while loop. =================================================================== --- qemu.orig/sysemu.h 2007-12-04 13:51:49.000000000 -0600 +++ qemu/sysemu.h 2007-12-04 14:18:57.000000000 -0600 @@ -117,7 +117,7 @@ #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 { Index: qemu/hw/pc.c =================================================================== --- qemu.orig/hw/pc.c 2007-12-04 13:51:49.000000000 -0600 +++ qemu/hw/pc.c 2007-12-04 14:18:57.000000000 -0600 @@ -1008,6 +1008,18 @@ } } } + + /* 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, The pci vendor id should be identical to the network (0x6900) regards, Dor. --------------020902040100080302030706 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Anthony Liguori wrote:

Subject: [PATCH 3/3] virtio block device
+
+static void virtio_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq)
+{
+    VirtIOBlock *s = to_virtio_blk(vdev);
+    VirtQueueElement elem;
+    unsigned int count;
+
+    while ((count = virtqueue_pop(vq, &elem)) != 0) {
+	struct virtio_blk_inhdr *in;
+	struct virtio_blk_outhdr *out;
+	unsigned int wlen;
+	off_t off;
+	int i;
+
+	out = (void *)elem.out_sg[0].iov_base;
+	in = (void *)elem.in_sg[elem.in_num - 1].iov_base;
+	off = out->sector;
+
+	if (out->type & VIRTIO_BLK_T_SCSI_CMD) {
+	    wlen = sizeof(*in);
+	    in->status = VIRTIO_BLK_S_UNSUPP;
+	} else if (out->type & VIRTIO_BLK_T_OUT) {
+	    wlen = sizeof(*in);
+
+	    for (i = 1; i < elem.out_num; i++) {
+		bdrv_write(s->bs, off,
+			   elem.out_sg[i].iov_base,
+			   elem.out_sg[i].iov_len / 512);
+		off += elem.out_sg[i].iov_len / 512;
+	    }
+
+	    in->status = VIRTIO_BLK_S_OK;
+	} else {
+	    wlen = sizeof(*in);
+
+	    for (i = 0; i < elem.in_num - 1; i++) {
+		bdrv_read(s->bs, off,
+			  elem.in_sg[i].iov_base,
+			  elem.in_sg[i].iov_len / 512);
+		off += elem.in_sg[i].iov_len / 512;
+		wlen += elem.in_sg[i].iov_len;
+	    }
+
+	    in->status = VIRTIO_BLK_S_OK;
+	}
+
+	virtqueue_push(vq, &elem, wlen);
+	virtio_notify(vdev, vq);
+    }



The notify here should also be outside the while loop.


===================================================================
--- qemu.orig/sysemu.h	2007-12-04 13:51:49.000000000 -0600
+++ qemu/sysemu.h	2007-12-04 14:18:57.000000000 -0600
@@ -117,7 +117,7 @@
 #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 {
Index: qemu/hw/pc.c
===================================================================
--- qemu.orig/hw/pc.c	2007-12-04 13:51:49.000000000 -0600
+++ qemu/hw/pc.c	2007-12-04 14:18:57.000000000 -0600
@@ -1008,6 +1008,18 @@
 	    }
         }
     }
+
+    /* 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,




The pci vendor id should be identical to the network (0x6900)
regards,
Dor.

--------------020902040100080302030706--