vhost-user-blk-test: add tests for the vhost-user-blk server
cover vhost-user-blk-test: add tests for the vhost-user-blk server
These patches add a qtest for the vhost-user-blk server. CI found several issues that caused these patches to be dropped from Michael Tsirkin and Kevin Wolf's pull requests in the past. Hopefully they will go in smoothly this time!
Coiby Xu (1):
test: new qTest case to test the vhost-user-blk-server
Stefan Hajnoczi (2):
tests/qtest: add multi-queue test case to vhost-user-blk-test
vhost-user-blk-test: test discard/write zeroes invalid inputs
MAINTAINERS | 2 + tests/qtest/libqos/vhost-user-blk.h | 48 ++ tests/qtest/libqos/vhost-user-blk.c | 130 ++++ tests/qtest/vhost-user-blk-test.c | 989 ++++++++++++++++++++++++++++ tests/qtest/libqos/meson.build | 1 + tests/qtest/meson.build | 4 + 6 files changed, 1174 insertions(+) create mode 100644 tests/qtest/libqos/vhost-user-blk.h create mode 100644 tests/qtest/libqos/vhost-user-blk.c create mode 100644 tests/qtest/vhost-user-blk-test.c
Signature · 1 line
2.30.2
PATCH 1/3 test: new qTest case to test the vhost-user-blk-server
From: Coiby Xu <[email protected]>
This test case has the same tests as tests/virtio-blk-test.c except for tests have block_resize. Since the vhost-user-blk export only serves one client one time, two exports are started by qemu-storage-daemon for the hotplug test.
Message-Id: <[email protected]>
--- MAINTAINERS | 2 + tests/qtest/libqos/vhost-user-blk.h | 48 ++ tests/qtest/libqos/vhost-user-blk.c | 130 +++++ tests/qtest/vhost-user-blk-test.c | 794 ++++++++++++++++++++++++++++ tests/qtest/libqos/meson.build | 1 + tests/qtest/meson.build | 4 + 6 files changed, 979 insertions(+) create mode 100644 tests/qtest/libqos/vhost-user-blk.h create mode 100644 tests/qtest/libqos/vhost-user-blk.c create mode 100644 tests/qtest/vhost-user-blk-test.c
MAINTAINERS +2 -0
@@ -3251,6 +3251,8 @@ F: block/export/vhost-user-blk-server.c F: block/export/vhost-user-blk-server.h F: include/qemu/vhost-user-server.h F: tests/qtest/libqos/vhost-user-blk.c +F: tests/qtest/libqos/vhost-user-blk.h +F: tests/qtest/vhost-user-blk-test.c F: util/vhost-user-server.c FUSE block device exports
tests/qtest/libqos/vhost-user-blk.h new file +48 -0
48 lines not on this page · raw message
tests/qtest/libqos/vhost-user-blk.c new file +130 -0
130 lines not on this page · raw message
tests/qtest/vhost-user-blk-test.c new file +794 -0
794 lines not on this page · raw message
tests/qtest/libqos/meson.build +1 -0
@@ -32,6 +32,7 @@ libqos_srcs = files('../libqtest.c', 'virtio-9p.c', 'virtio-balloon.c', 'virtio-blk.c', + 'vhost-user-blk.c', 'virtio-mmio.c', 'virtio-net.c', 'virtio-pci.c',
tests/qtest/meson.build +4 -0
@@ -231,6 +231,9 @@ if have_virtfs qos_test_ss.add(files('virtio-9p-test.c')) endif qos_test_ss.add(when: 'CONFIG_VHOST_USER', if_true: files('vhost-user-test.c')) +if have_vhost_user_blk_server + qos_test_ss.add(files('vhost-user-blk-test.c')) +endif tpmemu_files = ['tpm-emu.c', 'tpm-util.c', 'tpm-tests.c']
@@ -269,6 +272,7 @@ foreach dir : target_dirs endif qtest_env.set('G_TEST_DBUS_DAEMON', meson.source_root() / 'tests/dbus-vmstate-daemon.sh') qtest_env.set('QTEST_QEMU_BINARY', './qemu-system-' + target_base) + qtest_env.set('QTEST_QEMU_STORAGE_DAEMON_BINARY', './storage-daemon/qemu-storage-daemon') foreach test : target_qtests # Executables are shared across targets, declare them only the first time we
Signature · 1 line
2.30.2
PATCH 2/3 tests/qtest: add multi-queue test case to vhost-user-blk-test
In reply to Stefan HajnocziMessage-Id: <[email protected]>
--- tests/qtest/vhost-user-blk-test.c | 81 +++++++++++++++++++++++++++++-- 1 file changed, 76 insertions(+), 5 deletions(-)
tests/qtest/vhost-user-blk-test.c +76 -5
@@ -569,6 +569,67 @@ static void pci_hotplug(void *obj, void *data, QGuestAllocator *t_alloc)qpci_unplug_acpi_device_test (qts,"drv1" ,PCI_SLOT_HP ); } +static void multiqueue (void *obj,void *data,QGuestAllocator *t_alloc) +{ +QVirtioPCIDevice *pdev1 = obj; +QVirtioDevice *dev1 = &pdev1->vdev; +QVirtioPCIDevice *pdev8; +QVirtioDevice *dev8; +QTestState *qts = pdev1->pdev->bus->qts; +uint64_t features; +uint16_t num_queues; + +/* +* The primary device has 1 queue and VIRTIO_BLK_F_MQ is not enabled. The +* VIRTIO specification allows VIRTIO_BLK_F_MQ to be enabled when there is +* only 1 virtqueue, but --device vhost-user-blk-pci doesn't do this (which +* is also spec-compliant). +*/ + features =qvirtio_get_features (dev1); + g_assert_cmpint(features & (1u << VIRTIO_BLK_F_MQ), ==, 0); + features = features & ~(QVIRTIO_F_BAD_FEATURE | + (1u <<VIRTIO_RING_F_INDIRECT_DESC ) | + (1u <<VIRTIO_F_NOTIFY_ON_EMPTY ) | + (1u <<VIRTIO_BLK_F_SCSI )); +qvirtio_set_features (dev1, features); + +/* Hotplug a secondary device with 8 queues */ +qtest_qmp_device_add (qts,"vhost-user-blk-pci" ,"drv1" , +"{'addr': %s, 'chardev': 'char2', 'num-queues': 8}" , + stringify(PCI_SLOT_HP) ".0"); + + pdev8 =virtio_pci_new (pdev1->pdev->bus, + &(QPCIAddress ) { + .devfn =QPCI_DEVFN (PCI_SLOT_HP ,0 ) + }); +g_assert_nonnull (pdev8); + g_assert_cmpint(pdev8->vdev.device_type, ==, VIRTIO_ID_BLOCK); + +qos_object_start_hw (&pdev8->obj); + + dev8 = &pdev8->vdev; + features =qvirtio_get_features (dev8); +g_assert_cmpint (features & (1u <<VIRTIO_BLK_F_MQ ), + ==, + (1u <<VIRTIO_BLK_F_MQ )); + features = features & ~(QVIRTIO_F_BAD_FEATURE | + (1u <<VIRTIO_RING_F_INDIRECT_DESC ) | + (1u <<VIRTIO_F_NOTIFY_ON_EMPTY ) | + (1u <<VIRTIO_BLK_F_SCSI ) | + (1u <<VIRTIO_BLK_F_MQ )); +qvirtio_set_features (dev8, features); + + num_queues =qvirtio_config_readw (dev8, + offsetof(struct virtio_blk_config , num_queues)); + g_assert_cmpint(num_queues, ==, 8); + +qvirtio_pci_device_disable (pdev8); +qos_object_destroy (&pdev8->obj); + +/* unplug secondary disk */ +qpci_unplug_acpi_device_test (qts,"drv1" ,PCI_SLOT_HP ); +} +/* * Check that setting the vring addr on a non-existent virtqueue does * not crash.
@@ -688,7 +749,8 @@ static void quit_storage_daemon(void *data)g_free (data); } -static void start_vhost_user_blk (GString *cmd_line,int vus_instances) +static void start_vhost_user_blk (GString *cmd_line,int vus_instances, +int num_queues) {const char *vhost_user_blk_bin =qtest_qemu_storage_daemon_binary ();int i;
@@ -713,8 +775,8 @@ static void start_vhost_user_blk(GString *cmd_line, int vus_instances)g_string_append_printf (storage_daemon_command,"--blockdev driver=file,node-name=disk%d,filename=%s " "--export type=vhost-user-blk,id=disk%d,addr.type=unix,addr.path=%s," -"node-name=disk%i,writable=on " , - i, img_path, i, sock_path, i); +"node-name=disk%i,writable=on,num-queues=%d " , + i, img_path, i, sock_path, i, num_queues);g_string_append_printf (cmd_line,"-chardev socket,id=char%d,path=%s " , i +1 , sock_path);
@@ -748,7 +810,7 @@ static void start_vhost_user_blk(GString *cmd_line, int vus_instances)static void *vhost_user_blk_test_setup (GString *cmd_line,void *arg) { -start_vhost_user_blk (cmd_line,1 ); +start_vhost_user_blk (cmd_line,1 ,1 );return arg; }
@@ -762,7 +824,13 @@ static void *vhost_user_blk_test_setup(GString *cmd_line, void *arg)static void *vhost_user_blk_hotplug_test_setup (GString *cmd_line,void *arg) {/* "-chardev socket,id=char2" is used for pci_hotplug*/ -start_vhost_user_blk (cmd_line,2 ); +start_vhost_user_blk (cmd_line,2 ,1 ); +return arg; +} + +static void *vhost_user_blk_multiqueue_test_setup (GString *cmd_line,void *arg) +{ +start_vhost_user_blk (cmd_line,2 ,8 );return arg; }
@@ -789,6 +857,9 @@ static void register_vhost_user_blk_test(void) opts.before = vhost_user_blk_hotplug_test_setup;qos_add_test ("hotplug" ,"vhost-user-blk-pci" , pci_hotplug, &opts); + + opts.before = vhost_user_blk_multiqueue_test_setup; +qos_add_test ("multiqueue" ,"vhost-user-blk-pci" , multiqueue, &opts); }libqos_init (register_vhost_user_blk_test);
Signature · 1 line
2.30.2
PATCH 3/3 vhost-user-blk-test: test discard/write zeroes invalid inputs
In reply to Stefan HajnocziExercise input validation code paths inblock/export/vhost-user-blk-server.c.
Message-Id: <[email protected]>
--- tests/qtest/vhost-user-blk-test.c | 124 ++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+)
tests/qtest/vhost-user-blk-test.c +124 -0
@@ -94,6 +94,124 @@ static uint64_t virtio_blk_request(QGuestAllocator *alloc, QVirtioDevice *d,return addr; } +static void test_invalid_discard_write_zeroes (QVirtioDevice *dev, +QGuestAllocator *alloc, +QTestState *qts, +QVirtQueue *vq, +uint32_t type) +{ +QVirtioBlkReq req; +struct virtio_blk_discard_write_zeroes dwz_hdr; +struct virtio_blk_discard_write_zeroes dwz_hdr2[2 ]; +uint64_t req_addr; +uint32_t free_head; +uint8_t status; + +/* More than one dwz is not supported */ + req.type = type; + req.data = (char *) dwz_hdr2; + dwz_hdr2[0 ].sector =0 ; + dwz_hdr2[0 ].num_sectors =1 ; + dwz_hdr2[0 ].flags =0 ; + dwz_hdr2[1 ].sector =1 ; + dwz_hdr2[1 ].num_sectors =1 ; + dwz_hdr2[1 ].flags =0 ; + +virtio_blk_fix_dwz_hdr (dev, &dwz_hdr2[0 ]); +virtio_blk_fix_dwz_hdr (dev, &dwz_hdr2[1 ]); + + req_addr =virtio_blk_request (alloc, dev, &req,sizeof (dwz_hdr2)); + + free_head =qvirtqueue_add (qts, vq, req_addr,16 , false, true); +qvirtqueue_add (qts, vq, req_addr +16 ,sizeof (dwz_hdr2), false, true); +qvirtqueue_add (qts, vq, req_addr +16 +sizeof (dwz_hdr2),1 , true, + false); + +qvirtqueue_kick (qts, dev, vq, free_head); + +qvirtio_wait_used_elem (qts, dev, vq, free_head,NULL , +QVIRTIO_BLK_TIMEOUT_US ); + status =readb (req_addr +16 +sizeof (dwz_hdr2)); + g_assert_cmpint(status, ==, VIRTIO_BLK_S_UNSUPP); + +guest_free (alloc, req_addr); + +/* num_sectors must be less than config->max_write_zeroes_sectors */ + req.type = type; + req.data = (char *) &dwz_hdr; + dwz_hdr.sector =0 ; + dwz_hdr.num_sectors =0xffffffff ; + dwz_hdr.flags =0 ; + +virtio_blk_fix_dwz_hdr (dev, &dwz_hdr); + + req_addr =virtio_blk_request (alloc, dev, &req,sizeof (dwz_hdr)); + + free_head =qvirtqueue_add (qts, vq, req_addr,16 , false, true); +qvirtqueue_add (qts, vq, req_addr +16 ,sizeof (dwz_hdr), false, true); +qvirtqueue_add (qts, vq, req_addr +16 +sizeof (dwz_hdr),1 , true, + false); + +qvirtqueue_kick (qts, dev, vq, free_head); + +qvirtio_wait_used_elem (qts, dev, vq, free_head,NULL , +QVIRTIO_BLK_TIMEOUT_US ); + status =readb (req_addr +16 +sizeof (dwz_hdr)); + g_assert_cmpint(status, ==, VIRTIO_BLK_S_IOERR); + +guest_free (alloc, req_addr); + +/* sector must be less than the device capacity */ + req.type = type; + req.data = (char *) &dwz_hdr; + dwz_hdr.sector =TEST_IMAGE_SIZE /512 +1 ; + dwz_hdr.num_sectors =1 ; + dwz_hdr.flags =0 ; + +virtio_blk_fix_dwz_hdr (dev, &dwz_hdr); + + req_addr =virtio_blk_request (alloc, dev, &req,sizeof (dwz_hdr)); + + free_head =qvirtqueue_add (qts, vq, req_addr,16 , false, true); +qvirtqueue_add (qts, vq, req_addr +16 ,sizeof (dwz_hdr), false, true); +qvirtqueue_add (qts, vq, req_addr +16 +sizeof (dwz_hdr),1 , true, + false); + +qvirtqueue_kick (qts, dev, vq, free_head); + +qvirtio_wait_used_elem (qts, dev, vq, free_head,NULL , +QVIRTIO_BLK_TIMEOUT_US ); + status =readb (req_addr +16 +sizeof (dwz_hdr)); + g_assert_cmpint(status, ==, VIRTIO_BLK_S_IOERR); + +guest_free (alloc, req_addr); + +/* reserved flag bits must be zero */ + req.type = type; + req.data = (char *) &dwz_hdr; + dwz_hdr.sector =0 ; + dwz_hdr.num_sectors =1 ; + dwz_hdr.flags = ~VIRTIO_BLK_WRITE_ZEROES_FLAG_UNMAP ; + +virtio_blk_fix_dwz_hdr (dev, &dwz_hdr); + + req_addr =virtio_blk_request (alloc, dev, &req,sizeof (dwz_hdr)); + + free_head =qvirtqueue_add (qts, vq, req_addr,16 , false, true); +qvirtqueue_add (qts, vq, req_addr +16 ,sizeof (dwz_hdr), false, true); +qvirtqueue_add (qts, vq, req_addr +16 +sizeof (dwz_hdr),1 , true, + false); + +qvirtqueue_kick (qts, dev, vq, free_head); + +qvirtio_wait_used_elem (qts, dev, vq, free_head,NULL , +QVIRTIO_BLK_TIMEOUT_US ); + status =readb (req_addr +16 +sizeof (dwz_hdr)); + g_assert_cmpint(status, ==, VIRTIO_BLK_S_UNSUPP); + +guest_free (alloc, req_addr); +} +/* Returns the request virtqueue so the caller can perform further tests */ static QVirtQueue *test_basic (QVirtioDevice *dev,QGuestAllocator *alloc) {
@@ -235,6 +353,9 @@ static QVirtQueue *test_basic(QVirtioDevice *dev, QGuestAllocator *alloc)g_free (data);guest_free (alloc, req_addr); + +test_invalid_discard_write_zeroes (dev, alloc, qts, vq, +VIRTIO_BLK_T_WRITE_ZEROES ); }if (features & (1u <<VIRTIO_BLK_F_DISCARD )) {
@@ -263,6 +384,9 @@ static QVirtQueue *test_basic(QVirtioDevice *dev, QGuestAllocator *alloc) g_assert_cmpint(status, ==, 0);guest_free (alloc, req_addr); + +test_invalid_discard_write_zeroes (dev, alloc, qts, vq, +VIRTIO_BLK_T_DISCARD ); }if (features & (1u <<VIRTIO_F_ANY_LAYOUT )) {
Signature · 1 line
2.30.2
Quoted 11 lines · Stefan Hajnoczi
These patches add a qtest for the vhost-user-blk server. CI found several issues that caused these patches to be dropped from Michael Tsirkin and Kevin Wolf's pull requests in the past. Hopefully they will go in smoothly this time!
Coiby Xu (1):
test: new qTest case to test the vhost-user-blk-serverStefan Hajnoczi (2):
tests/qtest: add multi-queue test case to vhost-user-blk-test
vhost-user-blk-test: test discard/write zeroes invalid inputs
Quoted 10 lines
MAINTAINERS | 2 + tests/qtest/libqos/vhost-user-blk.h | 48 ++ tests/qtest/libqos/vhost-user-blk.c | 130 ++++ tests/qtest/vhost-user-blk-test.c | 989 ++++++++++++++++++++++++++++ tests/qtest/libqos/meson.build | 1 + tests/qtest/meson.build | 4 + 6 files changed, 1174 insertions(+) create mode 100644 tests/qtest/libqos/vhost-user-blk.h create mode 100644 tests/qtest/libqos/vhost-user-blk.c create mode 100644 tests/qtest/vhost-user-blk-test.c
Ping for QEMU 6.1
Stefan
Kevin Wolf
AppliedAm 11.05.2021 um 10:23 hat Stefan Hajnoczi geschrieben:
Quoted 23 lines · Stefan Hajnoczi
Quoted 11 lines
These patches add a qtest for the vhost-user-blk server. CI found several issues that caused these patches to be dropped from Michael Tsirkin and Kevin Wolf's pull requests in the past. Hopefully they will go in smoothly this time!
Coiby Xu (1):
test: new qTest case to test the vhost-user-blk-serverStefan Hajnoczi (2):
tests/qtest: add multi-queue test case to vhost-user-blk-test
vhost-user-blk-test: test discard/write zeroes invalid inputsQuoted 10 lines
MAINTAINERS | 2 + tests/qtest/libqos/vhost-user-blk.h | 48 ++ tests/qtest/libqos/vhost-user-blk.c | 130 ++++ tests/qtest/vhost-user-blk-test.c | 989 ++++++++++++++++++++++++++++ tests/qtest/libqos/meson.build | 1 + tests/qtest/meson.build | 4 + 6 files changed, 1174 insertions(+) create mode 100644 tests/qtest/libqos/vhost-user-blk.h create mode 100644 tests/qtest/libqos/vhost-user-blk.c create mode 100644 tests/qtest/vhost-user-blk-test.c
Quoted 1 line
Ping for QEMU 6.1
Thanks, applied to the block branch.
Kevin