Commit 066f4d82a67f621ddd547bfa4b9c94631d8457b0
Committed by
Rusty Russell
1 parent
e962fa660d
Exists in
master
and in
7 other branches
virtio_blk: check for hardsector size from host
Currently virtio_blk assumes a 512 byte hard sector size. This can cause trouble / performance issues if the backing has a different block size (like a file on an ext3 file system formatted with 4k block size or a dasd). Lets add a feature flag that tells the guest to use a different hard sector size than 512 byte. Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Showing 2 changed files with 12 additions and 1 deletions Side-by-side Diff
drivers/block/virtio_blk.c
... | ... | @@ -196,6 +196,7 @@ |
196 | 196 | int err; |
197 | 197 | u64 cap; |
198 | 198 | u32 v; |
199 | + u32 blk_size; | |
199 | 200 | |
200 | 201 | if (index_to_minor(index) >= 1 << MINORBITS) |
201 | 202 | return -ENOSPC; |
... | ... | @@ -290,6 +291,13 @@ |
290 | 291 | if (!err) |
291 | 292 | blk_queue_max_hw_segments(vblk->disk->queue, v); |
292 | 293 | |
294 | + /* Host can optionally specify the block size of the device */ | |
295 | + err = virtio_config_val(vdev, VIRTIO_BLK_F_BLK_SIZE, | |
296 | + offsetof(struct virtio_blk_config, blk_size), | |
297 | + &blk_size); | |
298 | + if (!err) | |
299 | + blk_queue_hardsect_size(vblk->disk->queue, blk_size); | |
300 | + | |
293 | 301 | add_disk(vblk->disk); |
294 | 302 | return 0; |
295 | 303 | |
... | ... | @@ -330,7 +338,7 @@ |
330 | 338 | |
331 | 339 | static unsigned int features[] = { |
332 | 340 | VIRTIO_BLK_F_BARRIER, VIRTIO_BLK_F_SEG_MAX, VIRTIO_BLK_F_SIZE_MAX, |
333 | - VIRTIO_BLK_F_GEOMETRY, VIRTIO_BLK_F_RO, | |
341 | + VIRTIO_BLK_F_GEOMETRY, VIRTIO_BLK_F_RO, VIRTIO_BLK_F_BLK_SIZE, | |
334 | 342 | }; |
335 | 343 | |
336 | 344 | static struct virtio_driver virtio_blk = { |
include/linux/virtio_blk.h
... | ... | @@ -13,6 +13,7 @@ |
13 | 13 | #define VIRTIO_BLK_F_SEG_MAX 2 /* Indicates maximum # of segments */ |
14 | 14 | #define VIRTIO_BLK_F_GEOMETRY 4 /* Legacy geometry available */ |
15 | 15 | #define VIRTIO_BLK_F_RO 5 /* Disk is read-only */ |
16 | +#define VIRTIO_BLK_F_BLK_SIZE 6 /* Block size of disk is available*/ | |
16 | 17 | |
17 | 18 | struct virtio_blk_config |
18 | 19 | { |
... | ... | @@ -28,6 +29,8 @@ |
28 | 29 | __u8 heads; |
29 | 30 | __u8 sectors; |
30 | 31 | } geometry; |
32 | + /* block size of device (if VIRTIO_BLK_F_BLK_SIZE) */ | |
33 | + __u32 blk_size; | |
31 | 34 | } __attribute__((packed)); |
32 | 35 | |
33 | 36 | /* These two define direction. */ |