diff options
author | Anthony Liguori <aliguori@us.ibm.com> | 2012-06-03 07:54:05 +0800 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2012-06-03 07:54:05 +0800 |
commit | 2eb02f28269dc47b38aa3becbaff1cc6300210da (patch) | |
tree | 39c8cd5408ae324d73798710e899c45897fc994d /hw/virtio-blk.c | |
parent | a854972f8cdec0148087789d62777d8f7176933d (diff) | |
parent | 4bb9c939a57103898f5a51aa6a7336eb3320d923 (diff) |
Merge remote-tracking branch 'kwolf/for-anthony' into staging
* kwolf/for-anthony:
ahci: SATA FIS is 20 bytes, not 0x20
virtio-blk: Fix geometry sector calculation
block: prevent snapshot mode $TMPDIR symlink attack
sheepdog: fix return value of do_load_save_vm_state
virtio: Fix compiler warning for non Linux hosts
Diffstat (limited to 'hw/virtio-blk.c')
-rw-r--r-- | hw/virtio-blk.c | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c index f9e1896ea9..fe0774617b 100644 --- a/hw/virtio-blk.c +++ b/hw/virtio-blk.c @@ -147,9 +147,11 @@ static VirtIOBlockReq *virtio_blk_get_request(VirtIOBlock *s) static void virtio_blk_handle_scsi(VirtIOBlockReq *req) { +#ifdef __linux__ int ret; - int status = VIRTIO_BLK_S_OK; int i; +#endif + int status = VIRTIO_BLK_S_OK; /* * We require at least one output segment each for the virtio_blk_outhdr @@ -489,7 +491,22 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config) stw_raw(&blkcfg.min_io_size, s->conf->min_io_size / blk_size); stw_raw(&blkcfg.opt_io_size, s->conf->opt_io_size / blk_size); blkcfg.heads = heads; - blkcfg.sectors = secs & ~s->sector_mask; + /* + * We must ensure that the block device capacity is a multiple of + * the logical block size. If that is not the case, lets use + * sector_mask to adopt the geometry to have a correct picture. + * For those devices where the capacity is ok for the given geometry + * we dont touch the sector value of the geometry, since some devices + * (like s390 dasd) need a specific value. Here the capacity is already + * cyls*heads*secs*blk_size and the sector value is not block size + * divided by 512 - instead it is the amount of blk_size blocks + * per track (cylinder). + */ + if (bdrv_getlength(s->bs) / heads / secs % blk_size) { + blkcfg.sectors = secs & ~s->sector_mask; + } else { + blkcfg.sectors = secs; + } blkcfg.size_max = 0; blkcfg.physical_block_exp = get_physical_block_exp(s->conf); blkcfg.alignment_offset = 0; |