[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 26/27] tests/virtio-blk: add test for WRITE_ZEROES co
From: |
Stefan Hajnoczi |
Subject: |
[Qemu-block] [PULL 26/27] tests/virtio-blk: add test for WRITE_ZEROES command |
Date: |
Fri, 22 Feb 2019 14:07:55 +0000 |
From: Stefano Garzarella <address@hidden>
If the WRITE_ZEROES feature is enabled, we check this command
in the test_basic().
Reviewed-by: Michael S. Tsirkin <address@hidden>
Reviewed-by: Stefan Hajnoczi <address@hidden>
Acked-by: Thomas Huth <address@hidden>
Signed-off-by: Stefano Garzarella <address@hidden>
Message-id: address@hidden
Message-Id: <address@hidden>
Signed-off-by: Stefan Hajnoczi <address@hidden>
---
tests/virtio-blk-test.c | 62 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 62 insertions(+)
diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c
index 85b6b99adc..f43d971099 100644
--- a/tests/virtio-blk-test.c
+++ b/tests/virtio-blk-test.c
@@ -255,6 +255,68 @@ static void test_basic(QVirtioDevice *dev, QGuestAllocator
*alloc,
guest_free(alloc, req_addr);
+ if (features & (1u << VIRTIO_BLK_F_WRITE_ZEROES)) {
+ struct virtio_blk_discard_write_zeroes dwz_hdr;
+ void *expected;
+
+ /*
+ * WRITE_ZEROES request on the same sector of previous test where
+ * we wrote "TEST".
+ */
+ req.type = VIRTIO_BLK_T_WRITE_ZEROES;
+ req.data = (char *) &dwz_hdr;
+ dwz_hdr.sector = 0;
+ 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(vq, req_addr, 16, false, true);
+ qvirtqueue_add(vq, req_addr + 16, sizeof(dwz_hdr), false, true);
+ qvirtqueue_add(vq, req_addr + 16 + sizeof(dwz_hdr), 1, true, false);
+
+ qvirtqueue_kick(dev, vq, free_head);
+
+ qvirtio_wait_used_elem(dev, vq, free_head, NULL,
+ QVIRTIO_BLK_TIMEOUT_US);
+ status = readb(req_addr + 16 + sizeof(dwz_hdr));
+ g_assert_cmpint(status, ==, 0);
+
+ guest_free(alloc, req_addr);
+
+ /* Read request to check if the sector contains all zeroes */
+ req.type = VIRTIO_BLK_T_IN;
+ req.ioprio = 1;
+ req.sector = 0;
+ req.data = g_malloc0(512);
+
+ req_addr = virtio_blk_request(alloc, dev, &req, 512);
+
+ g_free(req.data);
+
+ free_head = qvirtqueue_add(vq, req_addr, 16, false, true);
+ qvirtqueue_add(vq, req_addr + 16, 512, true, true);
+ qvirtqueue_add(vq, req_addr + 528, 1, true, false);
+
+ qvirtqueue_kick(dev, vq, free_head);
+
+ qvirtio_wait_used_elem(dev, vq, free_head, NULL,
+ QVIRTIO_BLK_TIMEOUT_US);
+ status = readb(req_addr + 528);
+ g_assert_cmpint(status, ==, 0);
+
+ data = g_malloc(512);
+ expected = g_malloc0(512);
+ memread(req_addr + 16, data, 512);
+ g_assert_cmpmem(data, 512, expected, 512);
+ g_free(expected);
+ g_free(data);
+
+ guest_free(alloc, req_addr);
+ }
+
if (features & (1u << VIRTIO_F_ANY_LAYOUT)) {
/* Write and read with 2 descriptor layout */
/* Write request */
--
2.20.1
- [Qemu-block] [PULL 13/27] migration/block: use qemu_iovec_init_buf, (continued)
- [Qemu-block] [PULL 13/27] migration/block: use qemu_iovec_init_buf, Stefan Hajnoczi, 2019/02/22
- [Qemu-block] [PULL 10/27] block/qed: use qemu_iovec_init_buf, Stefan Hajnoczi, 2019/02/22
- [Qemu-block] [PULL 14/27] tests/test-bdrv-drain: use QEMU_IOVEC_INIT_BUF, Stefan Hajnoczi, 2019/02/22
- [Qemu-block] [PULL 15/27] hw/ide: drop iov field from IDEState, Stefan Hajnoczi, 2019/02/22
- [Qemu-block] [PULL 12/27] qemu-img: use qemu_iovec_init_buf, Stefan Hajnoczi, 2019/02/22
- [Qemu-block] [PULL 22/27] virtio-blk: set config size depending on the features enabled, Stefan Hajnoczi, 2019/02/22
- [Qemu-block] [PULL 16/27] hw/ide: drop iov field from IDEBufferedRequest, Stefan Hajnoczi, 2019/02/22
- [Qemu-block] [PULL 18/27] virtio-blk: add acct_failed param to virtio_blk_handle_rw_error(), Stefan Hajnoczi, 2019/02/22
- [Qemu-block] [PULL 17/27] hw/ide: drop iov field from IDEDMA, Stefan Hajnoczi, 2019/02/22
- [Qemu-block] [PULL 25/27] tests/virtio-blk: add virtio_blk_fix_dwz_hdr() function, Stefan Hajnoczi, 2019/02/22
- [Qemu-block] [PULL 26/27] tests/virtio-blk: add test for WRITE_ZEROES command,
Stefan Hajnoczi <=
- [Qemu-block] [PULL 20/27] virtio-blk: add "discard" and "write-zeroes" properties, Stefan Hajnoczi, 2019/02/22
- [Qemu-block] [PULL 21/27] virtio-net: make VirtIOFeature usable for other virtio devices, Stefan Hajnoczi, 2019/02/22
- [Qemu-block] [PULL 19/27] virtio-blk: add host_features field in VirtIOBlock, Stefan Hajnoczi, 2019/02/22
- [Qemu-block] [PULL 23/27] virtio-blk: add DISCARD and WRITE_ZEROES features, Stefan Hajnoczi, 2019/02/22
- [Qemu-block] [PULL 27/27] tests/virtio-blk: add test for DISCARD command, Stefan Hajnoczi, 2019/02/22
- [Qemu-block] [PULL 24/27] tests/virtio-blk: change assert on data_size in virtio_blk_request(), Stefan Hajnoczi, 2019/02/22
- Re: [Qemu-block] [PULL 00/27] Block patches, Peter Maydell, 2019/02/26