diff mbox series

[v5,10/10] tests/virtio-blk: add test for DISCARD command

Message ID 20190218140301.197408-11-sgarzare@redhat.com (mailing list archive)
State New, archived
Headers show
Series virtio-blk: add DISCARD and WRITE_ZEROES features | expand

Commit Message

Stefano Garzarella Feb. 18, 2019, 2:03 p.m. UTC
If the DISCARD feature is enabled, we try this command in the
test_basic(), checking only the status returned by the request.

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
---
 tests/virtio-blk-test.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

Comments

Stefan Hajnoczi Feb. 20, 2019, 4:11 p.m. UTC | #1
On Mon, Feb 18, 2019 at 03:03:01PM +0100, Stefano Garzarella wrote:
> If the DISCARD feature is enabled, we try this command in the
> test_basic(), checking only the status returned by the request.
> 
> Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
> ---
>  tests/virtio-blk-test.c | 27 +++++++++++++++++++++++++++
>  1 file changed, 27 insertions(+)

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
diff mbox series

Patch

diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c
index cfc560be46..0bdbee32ba 100644
--- a/tests/virtio-blk-test.c
+++ b/tests/virtio-blk-test.c
@@ -317,6 +317,33 @@  static void test_basic(QVirtioDevice *dev, QGuestAllocator *alloc,
         guest_free(alloc, req_addr);
     }
 
+    if (features & (1u << VIRTIO_BLK_F_DISCARD)) {
+        struct virtio_blk_discard_write_zeroes dwz_hdr;
+
+        req.type = VIRTIO_BLK_T_DISCARD;
+        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);
+    }
+
     if (features & (1u << VIRTIO_F_ANY_LAYOUT)) {
         /* Write and read with 2 descriptor layout */
         /* Write request */