diff --git a/autotest.sh b/autotest.sh index 391b7b8f7..8687c173c 100755 --- a/autotest.sh +++ b/autotest.sh @@ -137,9 +137,9 @@ if [ $SPDK_TEST_VHOST -eq 1 ]; then timing_exit negative if [ $RUN_NIGHTLY -eq 1 ]; then -# timing_enter integrity_blk -# run_test ./test/vhost/spdk_vhost.sh --integrity-blk -# timing_exit integrity_blk + timing_enter integrity_blk + run_test ./test/vhost/spdk_vhost.sh --integrity-blk + timing_exit integrity_blk timing_enter integrity run_test ./test/vhost/spdk_vhost.sh --integrity @@ -170,9 +170,9 @@ if [ $SPDK_TEST_VHOST -eq 1 ]; then run_test ./test/vhost/spdk_vhost.sh --integrity-lvol-scsi timing_exit integrity_lvol_scsi -# timing_enter integrity_lvol_blk -# run_test ./test/vhost/spdk_vhost.sh --integrity-lvol-blk -# timing_exit integrity_lvol_blk + timing_enter integrity_lvol_blk + run_test ./test/vhost/spdk_vhost.sh --integrity-lvol-blk + timing_exit integrity_lvol_blk timing_exit vhost fi diff --git a/doc/vhost.md b/doc/vhost.md index 541c2a3c4..c631e17b7 100644 --- a/doc/vhost.md +++ b/doc/vhost.md @@ -72,19 +72,8 @@ the following command to confirm your QEMU supports userspace vhost-scsi. qemu-system-x86_64 -device vhost-user-scsi-pci,help ~~~ -Userspace vhost-blk target support is not yet upstream in QEMU, but patches -are available in SPDK's QEMU repository: - -~~~{.sh} -git clone -b spdk https://github.com/spdk/qemu -cd qemu -mkdir build -cd build -../configure -make -~~~ - -Run the following command to confirm your QEMU supports userspace vhost-blk. +Userspace vhost-blk target support was added to upstream QEMU in v2.12.0. Run +the following command to confirm your QEMU supports userspace vhost-blk. ~~~{.sh} qemu-system-x86_64 -device vhost-user-blk-pci,help @@ -221,7 +210,7 @@ Finally, specify the SPDK vhost devices: ~~~{.sh} -chardev socket,id=char1,path=/var/tmp/vhost.1 --device vhost-user-blk-pci,id=blk0,chardev=char1,logical_block_size=512,size=64M +-device vhost-user-blk-pci,id=blk0,chardev=char1 ~~~ ## Example output {#vhost_example} @@ -297,7 +286,7 @@ host:~# taskset -c 2,3 qemu-system-x86_64 \ -chardev socket,id=spdk_vhost_scsi0,path=/var/tmp/vhost.0 \ -device vhost-user-scsi-pci,id=scsi0,chardev=spdk_vhost_scsi0,num_queues=4 \ -chardev socket,id=spdk_vhost_blk0,path=/var/tmp/vhost.1 \ - -device vhost-user-blk-pci,logical_block_size=512,size=64M,chardev=spdk_vhost_blk0,num_queues=4 + -device vhost-user-blk-pci,chardev=spdk_vhost_blk0,num-queues=4 ~~~ Please note the following two commands are run on the guest VM. @@ -392,3 +381,7 @@ The Windows `viostor` driver before version 0.1.130-1 is buggy and does not correctly support vhost-blk devices with non-512-byte block size. See the [bug report](https://bugzilla.redhat.com/show_bug.cgi?id=1411092) for more information. + +## QEMU vhost-user-blk +QEMU [vhost-user-blk](https://git.qemu.org/?p=qemu.git;a=commit;h=00343e4b54ba) is +supported from version 2.12. diff --git a/lib/vhost/vhost_blk.c b/lib/vhost/vhost_blk.c index 1cd887109..1d06690ca 100644 --- a/lib/vhost/vhost_blk.c +++ b/lib/vhost/vhost_blk.c @@ -615,6 +615,45 @@ spdk_vhost_blk_dump_config_json(struct spdk_vhost_dev *vdev, struct spdk_json_wr static int spdk_vhost_blk_destroy(struct spdk_vhost_dev *dev); +static int +spdk_vhost_blk_get_config(struct spdk_vhost_dev *vdev, uint8_t *config, + uint32_t len) +{ + struct virtio_blk_config *blkcfg = (struct virtio_blk_config *)config; + struct spdk_vhost_blk_dev *bvdev; + struct spdk_bdev *bdev; + uint32_t blk_size; + uint64_t blkcnt; + + bvdev = to_blk_dev(vdev); + if (bvdev == NULL) { + SPDK_ERRLOG("Trying to get virito_blk configuration failed\n"); + return -1; + } + + if (len < sizeof(*blkcfg)) { + return -1; + } + + bdev = bvdev->bdev; + blk_size = spdk_bdev_get_block_size(bdev); + blkcnt = spdk_bdev_get_num_blocks(bdev); + + memset(blkcfg, 0, sizeof(*blkcfg)); + blkcfg->blk_size = blk_size; + /* minimum I/O size in blocks */ + blkcfg->min_io_size = 1; + /* expressed in 512 Bytes sectors */ + blkcfg->capacity = (blkcnt * blk_size) / 512; + blkcfg->size_max = 131072; + /* -2 for REQ and RESP and -1 for region boundary splitting */ + blkcfg->seg_max = SPDK_VHOST_IOVS_MAX - 2 - 1; + /* QEMU can overwrite this value when started */ + blkcfg->num_queues = 1; + + return 0; +} + static const struct spdk_vhost_dev_backend vhost_blk_device_backend = { .virtio_features = SPDK_VHOST_FEATURES | (1ULL << VIRTIO_BLK_F_SIZE_MAX) | (1ULL << VIRTIO_BLK_F_SEG_MAX) | @@ -628,6 +667,7 @@ static const struct spdk_vhost_dev_backend vhost_blk_device_backend = { (1ULL << VIRTIO_BLK_F_BARRIER) | (1ULL << VIRTIO_BLK_F_SCSI), .start_device = spdk_vhost_blk_start, .stop_device = spdk_vhost_blk_stop, + .vhost_get_config = spdk_vhost_blk_get_config, .dump_config_json = spdk_vhost_blk_dump_config_json, .remove_device = spdk_vhost_blk_destroy, }; diff --git a/test/unit/lib/vhost/vhost_blk.c/vhost_blk_ut.c b/test/unit/lib/vhost/vhost_blk.c/vhost_blk_ut.c index 65d5f2950..5f3d0e1c3 100644 --- a/test/unit/lib/vhost/vhost_blk.c/vhost_blk_ut.c +++ b/test/unit/lib/vhost/vhost_blk.c/vhost_blk_ut.c @@ -61,6 +61,24 @@ DEFINE_STUB_V(spdk_bdev_close, (struct spdk_bdev_desc *desc)); DEFINE_STUB(rte_vhost_driver_enable_features, int, (const char *path, uint64_t features), 0); DEFINE_STUB_P(spdk_bdev_get_io_channel, struct spdk_io_channel, (struct spdk_bdev_desc *desc), {0}); +uint32_t +spdk_bdev_get_block_size(const struct spdk_bdev *bdev) +{ + return 512; +} + +uint64_t +spdk_bdev_get_num_blocks(const struct spdk_bdev *bdev) +{ + return 0x1; +} + +bool +spdk_bdev_has_write_cache(const struct spdk_bdev *bdev) +{ + return false; +} + static void vhost_blk_controller_construct_test(void) { diff --git a/test/vhost/common/common.sh b/test/vhost/common/common.sh index 2d6be2b52..fccd025fd 100644 --- a/test/vhost/common/common.sh +++ b/test/vhost/common/common.sh @@ -629,8 +629,7 @@ function vm_setup() disk=${disk%%_*} notice "using socket $SPDK_VHOST_SCSI_TEST_DIR/naa.$disk.$vm_num" cmd+="-chardev socket,id=char_$disk,path=$SPDK_VHOST_SCSI_TEST_DIR/naa.$disk.$vm_num ${eol}" - cmd+="-device vhost-user-blk-pci,num_queues=$queue_number,chardev=char_$disk," - cmd+="logical_block_size=4096,size=$size ${eol}" + cmd+="-device vhost-user-blk-pci,num-queues=$queue_number,chardev=char_$disk ${eol}" ;; kernel_vhost) if [[ -z $disk ]]; then diff --git a/test/vhost/fiotest/autotest.sh b/test/vhost/fiotest/autotest.sh index 5aeb5fd0a..51fd18f4c 100755 --- a/test/vhost/fiotest/autotest.sh +++ b/test/vhost/fiotest/autotest.sh @@ -39,8 +39,6 @@ function usage() echo " NUM - VM number (mandatory)" echo " OS - VM os disk path (optional)" echo " DISKS - VM os test disks/devices path (virtio - optional, kernel_vhost - mandatory)" - echo " If test-type=spdk_vhost_blk then each disk can have additional size parameter, e.g." - echo " --vm=X,os.qcow,DISK_size_35G; unit can be M or G; default - 20G" exit 0 } diff --git a/test/vhost/hotplug/common.sh b/test/vhost/hotplug/common.sh index ec9d7cada..9f324d025 100644 --- a/test/vhost/hotplug/common.sh +++ b/test/vhost/hotplug/common.sh @@ -34,8 +34,6 @@ function usage() { echo " NUM - VM number (mandatory)" echo " OS - VM os disk path (optional)" echo " DISKS - VM os test disks/devices path (virtio - optional, kernel_vhost - mandatory)" - echo " If test-type=spdk_vhost_blk then each disk can have additional size parameter, e.g." - echo " --vm=X,os.qcow,DISK_size_35G; unit can be M or G; default - 20G" exit 0 } diff --git a/test/vhost/integrity/integrity_start.sh b/test/vhost/integrity/integrity_start.sh index fec79da74..49831693e 100755 --- a/test/vhost/integrity/integrity_start.sh +++ b/test/vhost/integrity/integrity_start.sh @@ -113,7 +113,7 @@ sed -i "s@@$VM_NET_NAME@g" $basedir/vnet_conf.xml if [[ "$VHOST_MODE" == "scsi" ]]; then sed -i "s@vhost_dev_args@vhost-user-scsi-pci,id=scsi0@g" $basedir/vm_conf.xml else - sed -i "s@vhost_dev_args@vhost-user-blk-pci,size=30G,logical_block_size=4096@g" $basedir/vm_conf.xml + sed -i "s@vhost_dev_args@vhost-user-blk-pci@g" $basedir/vm_conf.xml fi trap "cleanup_virsh; killprocess $pid; exit 1" SIGINT SIGTERM EXIT