Patchwork [1/2] virtio-blk: add max sectors feature (virtio_blk driver)

login
register
mail settings
Submitter Avishay Traeger1
Date Dec. 23, 2009, 3:21 p.m.
Message ID <OF67D6809E.115A2813-ONC2257695.0053288C-C2257695.00545C2E@il.ibm.com>
Download mbox | patch
Permalink /patch/41674/
State New
Headers show

Comments

Avishay Traeger1 - Dec. 23, 2009, 3:21 p.m.
This is a revised patch that allows the guest and host to negotiate the
maximum number of total sectors in an I/O.  This feature has already been
added by Rusty to the virtio spec.

Please CC me on replies, as I am not subscribed.

Thanks,
Avishay

Signed-off-by: Avishay Traeger <avishay@il.ibm.com>
---

Patch

diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 51042f0..e68ea8a 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -351,8 +351,14 @@  static int __devinit virtblk_probe(struct
virtio_device *vdev)
      /* No need to bounce any requests */
      blk_queue_bounce_limit(vblk->disk->queue, BLK_BOUNCE_ANY);

-	/* No real sector limit. */
-     blk_queue_max_sectors(vblk->disk->queue, -1U);
+	/* Host can optionally specify maximum total sectors in an I/O. */
+     err = virtio_config_val(vdev, VIRTIO_BLK_F_SECTOR_MAX,
+                       offsetof(struct virtio_blk_config, sectors_max),
+                       &v);
+     if (!err)
+           blk_queue_max_sectors(vblk->disk->queue, v);
+     else
+           blk_queue_max_sectors(vblk->disk->queue, -1U);

      /* Host can optionally specify maximum segment size and number of
       * segments. */
@@ -412,7 +418,7 @@  static struct virtio_device_id id_table[] = {
 static unsigned int features[] = {
      VIRTIO_BLK_F_BARRIER, VIRTIO_BLK_F_SEG_MAX, VIRTIO_BLK_F_SIZE_MAX,
      VIRTIO_BLK_F_GEOMETRY, VIRTIO_BLK_F_RO, VIRTIO_BLK_F_BLK_SIZE,
-     VIRTIO_BLK_F_SCSI, VIRTIO_BLK_F_FLUSH
+     VIRTIO_BLK_F_SCSI, VIRTIO_BLK_F_FLUSH, VIRTIO_BLK_F_SECTOR_MAX
 };

 /*
diff --git a/include/linux/virtio_blk.h b/include/linux/virtio_blk.h
index fd294c5..2536d74 100644
--- a/include/linux/virtio_blk.h
+++ b/include/linux/virtio_blk.h
@@ -15,6 +15,7 @@ 
 #define VIRTIO_BLK_F_BLK_SIZE      6	/* Block size of disk is available*/
 #define VIRTIO_BLK_F_SCSI    7	/* Supports scsi command passthru */
 #define VIRTIO_BLK_F_FLUSH   9	/* Cache flush command support */
+#define VIRTIO_BLK_F_SECTOR_MAX    10	/* Maximum total sectors in an I/O */

 struct virtio_blk_config {
      /* The capacity (in 512-byte sectors). */
@@ -31,6 +32,7 @@  struct virtio_blk_config {
      } geometry;
      /* block size of device (if VIRTIO_BLK_F_BLK_SIZE) */
      __u32 blk_size;
+     __u32 sectors_max;
 } __attribute__((packed));

 /*