From a209f4615c6853a226e847810b6c607c71b6a046 Mon Sep 17 00:00:00 2001 From: Fam Zheng Date: Tue, 17 Feb 2015 17:55:53 +0800 Subject: virtio-blk: Check return value of blk_aio_ioctl Since commit 1dc936aa84 (virtio-blk: Use blk_aio_ioctl) we silently lose the request if blk_aio_ioctl returns NULL (not implemented). Fix it by directly returning VIRTIO_BLK_S_UNSUPP as we used to do. Signed-off-by: Fam Zheng Reviewed-by: Stefan Hajnoczi [ kwolf: Fixed build error on win32 ] Signed-off-by: Kevin Wolf --- hw/block/virtio-blk.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'hw/block') diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index cb71772f95..3ad5fe44e2 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -201,6 +201,7 @@ static int virtio_blk_handle_scsi_req(VirtIOBlockReq *req) #ifdef __linux__ int i; VirtIOBlockIoctlReq *ioctl_req; + BlockAIOCB *acb; #endif /* @@ -278,8 +279,13 @@ static int virtio_blk_handle_scsi_req(VirtIOBlockReq *req) ioctl_req->hdr.sbp = elem->in_sg[elem->in_num - 3].iov_base; ioctl_req->hdr.mx_sb_len = elem->in_sg[elem->in_num - 3].iov_len; - blk_aio_ioctl(blk->blk, SG_IO, &ioctl_req->hdr, - virtio_blk_ioctl_complete, ioctl_req); + acb = blk_aio_ioctl(blk->blk, SG_IO, &ioctl_req->hdr, + virtio_blk_ioctl_complete, ioctl_req); + if (!acb) { + g_free(ioctl_req); + status = VIRTIO_BLK_S_UNSUPP; + goto fail; + } return -EINPROGRESS; #else abort(); -- cgit v1.2.3 From 0eb28a42284ec32e6f283985d2d638474a05eba4 Mon Sep 17 00:00:00 2001 From: Ekaterina Tumanova Date: Mon, 16 Feb 2015 12:47:58 +0100 Subject: BlockConf: Call backend functions to detect geometry and blocksizes geometry: hd_geometry_guess function autodetects the drive geometry. This patch adds a block backend call, that probes the backing device geometry. If the inner driver method is implemented and succeeds (currently only for DASDs), the blkconf_geometry will pass-through the backing device geometry. Otherwise will fallback to old logic. blocksize: This patch initializes blocksize properties to 0. In order to set the property a blkconf_blocksizes was introduced. If user didn't set physical or logical blocksize, it will retrieve its value from a driver (only succeeds for DASD), otherwise it will set default 512 value. The blkconf_blocksizes call was added to all users of BlkConf. Signed-off-by: Ekaterina Tumanova Reviewed-by: Markus Armbruster Reviewed-by: Stefan Hajnoczi Message-id: 1424087278-49393-6-git-send-email-tumanova@linux.vnet.ibm.com Signed-off-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- hw/block/block.c | 24 ++++++++++++++++++++++++ hw/block/hd-geometry.c | 10 +++++++++- hw/block/nvme.c | 1 + hw/block/virtio-blk.c | 1 + 4 files changed, 35 insertions(+), 1 deletion(-) (limited to 'hw/block') diff --git a/hw/block/block.c b/hw/block/block.c index a625773d44..f7243e5b94 100644 --- a/hw/block/block.c +++ b/hw/block/block.c @@ -25,6 +25,30 @@ void blkconf_serial(BlockConf *conf, char **serial) } } +void blkconf_blocksizes(BlockConf *conf) +{ + BlockBackend *blk = conf->blk; + BlockSizes blocksizes; + int backend_ret; + + backend_ret = blk_probe_blocksizes(blk, &blocksizes); + /* fill in detected values if they are not defined via qemu command line */ + if (!conf->physical_block_size) { + if (!backend_ret) { + conf->physical_block_size = blocksizes.phys; + } else { + conf->physical_block_size = BDRV_SECTOR_SIZE; + } + } + if (!conf->logical_block_size) { + if (!backend_ret) { + conf->logical_block_size = blocksizes.log; + } else { + conf->logical_block_size = BDRV_SECTOR_SIZE; + } + } +} + void blkconf_geometry(BlockConf *conf, int *ptrans, unsigned cyls_max, unsigned heads_max, unsigned secs_max, Error **errp) diff --git a/hw/block/hd-geometry.c b/hw/block/hd-geometry.c index 6fcf74df44..b187878fac 100644 --- a/hw/block/hd-geometry.c +++ b/hw/block/hd-geometry.c @@ -121,8 +121,16 @@ void hd_geometry_guess(BlockBackend *blk, int *ptrans) { int cylinders, heads, secs, translation; + HDGeometry geo; - if (guess_disk_lchs(blk, &cylinders, &heads, &secs) < 0) { + /* Try to probe the backing device geometry, otherwise fallback + to the old logic. (as of 12/2014 probing only succeeds on DASDs) */ + if (blk_probe_geometry(blk, &geo) == 0) { + *pcyls = geo.cylinders; + *psecs = geo.sectors; + *pheads = geo.heads; + translation = BIOS_ATA_TRANSLATION_NONE; + } else if (guess_disk_lchs(blk, &cylinders, &heads, &secs) < 0) { /* no LCHS guess: use a standard physical disk geometry */ guess_chs_for_size(blk, pcyls, pheads, psecs); translation = hd_bios_chs_auto_trans(*pcyls, *pheads, *psecs); diff --git a/hw/block/nvme.c b/hw/block/nvme.c index ce079aefdd..0f3dfb90ea 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -765,6 +765,7 @@ static int nvme_init(PCIDevice *pci_dev) if (!n->serial) { return -1; } + blkconf_blocksizes(&n->conf); pci_conf = pci_dev->config; pci_conf[PCI_INTERRUPT_PIN] = 1; diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 3ad5fe44e2..2acfef87eb 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -893,6 +893,7 @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp) error_propagate(errp, err); return; } + blkconf_blocksizes(&conf->conf); virtio_init(vdev, "virtio-blk", VIRTIO_ID_BLOCK, sizeof(struct virtio_blk_config)); -- cgit v1.2.3 From 4c0542ea60d21b56a9157d3f6331d2df8990d3bb Mon Sep 17 00:00:00 2001 From: Fam Zheng Date: Mon, 16 Feb 2015 12:09:40 +0800 Subject: virtio-blk: Remove the stale FIXME comment By default, we have ioeventfd enabled, so the IO request processing is in IO thread; in the vcpu thread, guest mode is returned to as quickly as possible, and completion is delivered via irqfd. Therefore this comment from the initial implementation is barely relevant. Signed-off-by: Fam Zheng Reviewed-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- hw/block/virtio-blk.c | 6 ------ 1 file changed, 6 deletions(-) (limited to 'hw/block') diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 2acfef87eb..0468297688 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -597,12 +597,6 @@ static void virtio_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq) if (mrb.num_reqs) { virtio_blk_submit_multireq(s->blk, &mrb); } - - /* - * FIXME: Want to check for completions before returning to guest mode, - * so cached reads and writes are reported as quickly as possible. But - * that should be done in the generic block layer. - */ } static void virtio_blk_dma_restart_bh(void *opaque) -- cgit v1.2.3