Revision 8cfacf07
b/block_int.h | ||
---|---|---|
209 | 209 |
typedef struct BlockConf { |
210 | 210 |
struct DriveInfo *dinfo; |
211 | 211 |
uint16_t physical_block_size; |
212 |
uint16_t logical_block_size; |
|
212 | 213 |
uint16_t min_io_size; |
213 | 214 |
uint32_t opt_io_size; |
214 | 215 |
} BlockConf; |
... | ... | |
226 | 227 |
|
227 | 228 |
#define DEFINE_BLOCK_PROPERTIES(_state, _conf) \ |
228 | 229 |
DEFINE_PROP_DRIVE("drive", _state, _conf.dinfo), \ |
230 |
DEFINE_PROP_UINT16("logical_block_size", _state, \ |
|
231 |
_conf.logical_block_size, 512), \ |
|
229 | 232 |
DEFINE_PROP_UINT16("physical_block_size", _state, \ |
230 | 233 |
_conf.physical_block_size, 512), \ |
231 | 234 |
DEFINE_PROP_UINT16("min_io_size", _state, _conf.min_io_size, 512), \ |
b/hw/scsi-disk.c | ||
---|---|---|
396 | 396 |
} |
397 | 397 |
case 0xb0: /* block device characteristics */ |
398 | 398 |
{ |
399 |
unsigned int min_io_size = s->qdev.conf.min_io_size >> 9; |
|
400 |
unsigned int opt_io_size = s->qdev.conf.opt_io_size >> 9; |
|
399 |
unsigned int min_io_size = |
|
400 |
s->qdev.conf.min_io_size / s->qdev.blocksize; |
|
401 |
unsigned int opt_io_size = |
|
402 |
s->qdev.conf.opt_io_size / s->qdev.blocksize; |
|
401 | 403 |
|
402 | 404 |
/* required VPD size with unmap support */ |
403 | 405 |
outbuf[3] = buflen = 0x3c; |
... | ... | |
1036 | 1038 |
} |
1037 | 1039 |
|
1038 | 1040 |
if (bdrv_get_type_hint(s->bs) == BDRV_TYPE_CDROM) { |
1039 |
s->cluster_size = 4;
|
|
1041 |
s->qdev.blocksize = 2048;
|
|
1040 | 1042 |
} else { |
1041 |
s->cluster_size = 1;
|
|
1043 |
s->qdev.blocksize = s->qdev.conf.logical_block_size;
|
|
1042 | 1044 |
} |
1043 |
s->qdev.blocksize = 512 * s->cluster_size; |
|
1045 |
s->cluster_size = s->qdev.blocksize / 512; |
|
1046 |
|
|
1044 | 1047 |
s->qdev.type = TYPE_DISK; |
1045 | 1048 |
bdrv_get_geometry(s->bs, &nb_sectors); |
1046 | 1049 |
nb_sectors /= s->cluster_size; |
b/hw/virtio-blk.c | ||
---|---|---|
27 | 27 |
void *rq; |
28 | 28 |
QEMUBH *bh; |
29 | 29 |
BlockConf *conf; |
30 |
unsigned short sector_mask; |
|
30 | 31 |
} VirtIOBlock; |
31 | 32 |
|
32 | 33 |
static VirtIOBlock *to_virtio_blk(VirtIODevice *vdev) |
... | ... | |
250 | 251 |
static void virtio_blk_handle_write(BlockRequest *blkreq, int *num_writes, |
251 | 252 |
VirtIOBlockReq *req, BlockDriverState **old_bs) |
252 | 253 |
{ |
254 |
if (req->out->sector & req->dev->sector_mask) { |
|
255 |
virtio_blk_rw_complete(req, -EIO); |
|
256 |
return; |
|
257 |
} |
|
258 |
|
|
253 | 259 |
if (req->dev->bs != *old_bs || *num_writes == 32) { |
254 | 260 |
if (*old_bs != NULL) { |
255 | 261 |
do_multiwrite(*old_bs, blkreq, *num_writes); |
... | ... | |
272 | 278 |
{ |
273 | 279 |
BlockDriverAIOCB *acb; |
274 | 280 |
|
281 |
if (req->out->sector & req->dev->sector_mask) { |
|
282 |
virtio_blk_rw_complete(req, -EIO); |
|
283 |
return; |
|
284 |
} |
|
285 |
|
|
275 | 286 |
acb = bdrv_aio_readv(req->dev->bs, req->out->sector, &req->qiov, |
276 | 287 |
req->qiov.size / 512, virtio_blk_rw_complete, req); |
277 | 288 |
if (!acb) { |
... | ... | |
404 | 415 |
stl_raw(&blkcfg.seg_max, 128 - 2); |
405 | 416 |
stw_raw(&blkcfg.cylinders, cylinders); |
406 | 417 |
blkcfg.heads = heads; |
407 |
blkcfg.sectors = secs; |
|
418 |
blkcfg.sectors = secs & ~s->sector_mask; |
|
419 |
blkcfg.blk_size = s->conf->logical_block_size; |
|
408 | 420 |
blkcfg.size_max = 0; |
409 | 421 |
blkcfg.physical_block_exp = get_physical_block_exp(s->conf); |
410 | 422 |
blkcfg.alignment_offset = 0; |
411 |
blkcfg.min_io_size = s->conf->min_io_size / 512;
|
|
412 |
blkcfg.opt_io_size = s->conf->opt_io_size / 512;
|
|
423 |
blkcfg.min_io_size = s->conf->min_io_size / blkcfg.blk_size;
|
|
424 |
blkcfg.opt_io_size = s->conf->opt_io_size / blkcfg.blk_size;
|
|
413 | 425 |
memcpy(config, &blkcfg, sizeof(struct virtio_blk_config)); |
414 | 426 |
} |
415 | 427 |
|
... | ... | |
420 | 432 |
features |= (1 << VIRTIO_BLK_F_SEG_MAX); |
421 | 433 |
features |= (1 << VIRTIO_BLK_F_GEOMETRY); |
422 | 434 |
features |= (1 << VIRTIO_BLK_F_TOPOLOGY); |
435 |
features |= (1 << VIRTIO_BLK_F_BLK_SIZE); |
|
423 | 436 |
|
424 | 437 |
if (bdrv_enable_write_cache(s->bs)) |
425 | 438 |
features |= (1 << VIRTIO_BLK_F_WCACHE); |
... | ... | |
479 | 492 |
s->bs = conf->dinfo->bdrv; |
480 | 493 |
s->conf = conf; |
481 | 494 |
s->rq = NULL; |
495 |
s->sector_mask = (s->conf->logical_block_size / 512) - 1; |
|
482 | 496 |
bdrv_guess_geometry(s->bs, &cylinders, &heads, &secs); |
483 | 497 |
bdrv_set_geometry_hint(s->bs, cylinders, heads, secs); |
484 | 498 |
|
b/hw/virtio-blk.h | ||
---|---|---|
42 | 42 |
uint16_t cylinders; |
43 | 43 |
uint8_t heads; |
44 | 44 |
uint8_t sectors; |
45 |
uint32_t _blk_size; /* structure pad, currently unused */
|
|
45 |
uint32_t blk_size;
|
|
46 | 46 |
uint8_t physical_block_exp; |
47 | 47 |
uint8_t alignment_offset; |
48 | 48 |
uint16_t min_io_size; |
Also available in: Unified diff