virtio-blk: fix minimum number of S/G elements
Subsystems (3)
PATCH 1/1 virtio-blk: fix minimum number of S/G elements
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.
drivers/block/virtio_blk.c +4 -2
@@ -287,7 +287,7 @@ static int __devinit virtblk_probe(strucstruct request_queue *q;int err;u64 cap; -u32 v, blk_size, sg_elems, opt_io_size; +u32 v, blk_size, sg_elems =0 , opt_io_size;u16 min_io_size;u8 physical_block_exp, alignment_offset;
@@ -298,7 +298,9 @@ static int __devinit virtblk_probe(struc 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 */ +if (!sg_elems) sg_elems =1 ;/* We need an extra sg elements at head and tail. */
Quoted 6 lines · Christoph Hellwig
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_elementsof 0 under some circumstances.Signed-off-by Christoph Hellwig <[email protected]>
Seems reasonable: we might as well ignore it if device is obviously talking crap.
However, the result is awkward (we assign err then don't use it), and assumes that sg_elems isn't touched on error (true at the moment).
Prefer this:
Subject: virtio-blk: fix minimum number of S/G elements
Date: Tue, 25 May 2010 14:17:54 +0200
From: Christoph Hellwig <[email protected]>
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.
drivers/block/virtio_blk.c +3 -1
@@ -298,7 +298,9 @@ static int __devinit virtblk_probe(struc 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. */