virtio-blk: fix minimum number of S/G elements
authorChristoph Hellwig <hch@lst.de>
Tue, 25 May 2010 12:17:54 +0000 (14:17 +0200)
committerRusty Russell <rusty@rustcorp.com.au>
Thu, 3 Jun 2010 13:09:18 +0000 (22:39 +0930)
We need at least one S/G element to operate properly, as does the block
layer which increments it to one anyway.  We hit this due to a qemu
bug which advertises a sg_elements of 0 under some circumstances.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (tweaked logic)
drivers/block/virtio_blk.c

index 83fa09a836ca8574a3696c888d7574a833b35447..258bc2ae2885625a1650cebcabb4b9eb975092bb 100644 (file)
@@ -298,7 +298,9 @@ static int __devinit virtblk_probe(struct virtio_device *vdev)
        err = virtio_config_val(vdev, VIRTIO_BLK_F_SEG_MAX,
                                offsetof(struct virtio_blk_config, seg_max),
                                &sg_elems);
-       if (err)
+
+       /* We need at least one SG element, whatever they say. */
+       if (err || !sg_elems)
                sg_elems = 1;
 
        /* We need an extra sg elements at head and tail. */