Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blk.vhost blk #317

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 32 additions & 16 deletions drivers/block/virtio_blk.c
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,37 @@ static const struct device_attribute dev_attr_cache_type_rw =
__ATTR(cache_type, S_IRUGO|S_IWUSR,
virtblk_cache_type_show, virtblk_cache_type_store);

static void virtblk_scan(struct virtio_device *vdev)
{
struct virtio_blk *vblk = vdev->priv;
int err;

add_disk(vblk->disk);
err = device_create_file(disk_to_dev(vblk->disk), &dev_attr_serial);
if (err)
goto out_del_disk;

if (virtio_has_feature(vdev, VIRTIO_BLK_F_CONFIG_WCE))
err = device_create_file(disk_to_dev(vblk->disk),
&dev_attr_cache_type_rw);
else
err = device_create_file(disk_to_dev(vblk->disk),
&dev_attr_cache_type_ro);
if (err)
goto out_del_disk;

return;

out_del_disk:
del_gendisk(vblk->disk);
blk_cleanup_queue(vblk->disk->queue);
put_disk(vblk->disk);
mempool_destroy(vblk->pool);
vdev->config->del_vqs(vdev);
kfree(vblk);
ida_simple_remove(&vd_index_ida, vblk->index);
}

static int virtblk_probe(struct virtio_device *vdev)
{
struct virtio_blk *vblk;
Expand Down Expand Up @@ -837,24 +868,8 @@ static int virtblk_probe(struct virtio_device *vdev)
if (!err && opt_io_size)
blk_queue_io_opt(q, blk_size * opt_io_size);

add_disk(vblk->disk);
err = device_create_file(disk_to_dev(vblk->disk), &dev_attr_serial);
if (err)
goto out_del_disk;

if (virtio_has_feature(vdev, VIRTIO_BLK_F_CONFIG_WCE))
err = device_create_file(disk_to_dev(vblk->disk),
&dev_attr_cache_type_rw);
else
err = device_create_file(disk_to_dev(vblk->disk),
&dev_attr_cache_type_ro);
if (err)
goto out_del_disk;
return 0;

out_del_disk:
del_gendisk(vblk->disk);
blk_cleanup_queue(vblk->disk->queue);
out_put_disk:
put_disk(vblk->disk);
out_mempool:
Expand Down Expand Up @@ -957,6 +972,7 @@ static struct virtio_driver virtio_blk = {
.driver.owner = THIS_MODULE,
.id_table = id_table,
.probe = virtblk_probe,
.scan = virtblk_scan,
.remove = virtblk_remove,
.config_changed = virtblk_config_changed,
#ifdef CONFIG_PM
Expand Down
4 changes: 4 additions & 0 deletions drivers/vhost/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ config VHOST_RING
---help---
This option is selected by any driver which needs to access
the host side of a virtio ring.

if STAGING
source "drivers/vhost/Kconfig.blk"
endif
10 changes: 10 additions & 0 deletions drivers/vhost/Kconfig.blk
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
config VHOST_BLK
tristate "Host kernel accelerator for virtio blk"
depends on BLOCK && EVENTFD && m
---help---
This kernel module can be loaded in host kernel to accelerate
guest block with virtio_blk. Not to be confused with virtio_blk
module itself which needs to be loaded in guest kernel.

To compile this driver as a module, choose M here: the module will
be called vhost_blk.
3 changes: 3 additions & 0 deletions drivers/vhost/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ vhost_net-y := vhost.o net.o
obj-$(CONFIG_VHOST_SCSI) += vhost_scsi.o
vhost_scsi-y := scsi.o

obj-$(CONFIG_VHOST_BLK) += vhost_blk.o
vhost_blk-y := blk.o

obj-$(CONFIG_VHOST_RING) += vringh.o
Loading