All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: Alberto Faria <afaria@redhat.com>
Cc: qemu-devel@nongnu.org, "Stefano Garzarella" <sgarzare@redhat.com>,
	"Kevin Wolf" <kwolf@redhat.com>,
	"Xie Yongji" <xieyongji@bytedance.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Raphael Norwitz" <raphael@enfabrica.net>,
	"Cornelia Huck" <cohuck@redhat.com>,
	"Eduardo Habkost" <eduardo@habkost.net>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Hanna Reitz" <hreitz@redhat.com>,
	qemu-block@nongnu.org, "Paolo Bonzini" <pbonzini@redhat.com>,
	"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
	"Laurent Vivier" <lvivier@redhat.com>,
	"Zhao Liu" <zhao1.liu@intel.com>, "Coiby Xu" <Coiby.Xu@gmail.com>,
	"Fabiano Rosas" <farosas@suse.de>,
	"Yanan Wang" <wangyanan55@huawei.com>
Subject: Re: [RFC v2 3/4] vhost-user-blk: Add VIRTIO_BLK_T_OUT_FUA command support
Date: Mon, 12 May 2025 15:43:12 -0400	[thread overview]
Message-ID: <20250512194312.GM141177@fedora> (raw)
In-Reply-To: <20250508162044.857655-4-afaria@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 7224 bytes --]

On Thu, May 08, 2025 at 05:20:43PM +0100, Alberto Faria wrote:
> Signed-off-by: Alberto Faria <afaria@redhat.com>
> ---
>  block/export/vhost-user-blk-server.c    |  1 +
>  contrib/vhost-user-blk/vhost-user-blk.c | 16 +++++--
>  hw/block/vhost-user-blk.c               |  3 ++
>  hw/core/machine.c                       |  1 +
>  tests/qtest/vhost-user-blk-test.c       | 56 +++++++++++++++++++++++++
>  5 files changed, 74 insertions(+), 3 deletions(-)
> 
> diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user-blk-server.c
> index d9d2014d9b7..fad9560b219 100644
> --- a/block/export/vhost-user-blk-server.c
> +++ b/block/export/vhost-user-blk-server.c
> @@ -125,6 +125,7 @@ static uint64_t vu_blk_get_features(VuDev *dev)
>                 1ull << VIRTIO_BLK_F_FLUSH |
>                 1ull << VIRTIO_BLK_F_DISCARD |
>                 1ull << VIRTIO_BLK_F_WRITE_ZEROES |
> +               1ull << VIRTIO_BLK_F_OUT_FUA |
>                 1ull << VIRTIO_BLK_F_CONFIG_WCE |
>                 1ull << VIRTIO_BLK_F_MQ |
>                 1ull << VIRTIO_F_VERSION_1 |
> diff --git a/contrib/vhost-user-blk/vhost-user-blk.c b/contrib/vhost-user-blk/vhost-user-blk.c
> index 6cc18a1c04f..8d732bbe468 100644
> --- a/contrib/vhost-user-blk/vhost-user-blk.c
> +++ b/contrib/vhost-user-blk/vhost-user-blk.c
> @@ -154,7 +154,7 @@ vub_readv(VubReq *req, struct iovec *iov, uint32_t iovcnt)
>  }
>  
>  static ssize_t
> -vub_writev(VubReq *req, struct iovec *iov, uint32_t iovcnt)
> +vub_writev(VubReq *req, struct iovec *iov, uint32_t iovcnt, int flags)
>  {
>      VubDev *vdev_blk = req->vdev_blk;
>      ssize_t rc;

Where is flags used?

> @@ -271,12 +271,19 @@ static int vub_virtio_process_req(VubDev *vdev_blk,
>      type = le32_to_cpu(req->out->type);
>      switch (type & ~VIRTIO_BLK_T_BARRIER) {
>      case VIRTIO_BLK_T_IN:
> -    case VIRTIO_BLK_T_OUT: {
> +    case VIRTIO_BLK_T_OUT:
> +    case VIRTIO_BLK_T_OUT_FUA: {
>          ssize_t ret = 0;
>          bool is_write = type & VIRTIO_BLK_T_OUT;
> +        int flags = 0;
>          req->sector_num = le64_to_cpu(req->out->sector);
>          if (is_write) {
> -            ret  = vub_writev(req, &elem->out_sg[1], out_num);
> +            #ifdef RWF_SYNC
> +            if (type == VIRTIO_BLK_T_OUT_FUA) {
> +                flags |= RWF_SYNC;
> +            }
> +            #endif
> +            ret  = vub_writev(req, &elem->out_sg[1], out_num, flags);
>          } else {
>              ret = vub_readv(req, &elem->in_sg[0], in_num);
>          }
> @@ -379,6 +386,9 @@ vub_get_features(VuDev *dev)
>                 1ull << VIRTIO_BLK_F_DISCARD |
>                 1ull << VIRTIO_BLK_F_WRITE_ZEROES |
>                 #endif
> +               #ifdef RWF_SYNC
> +               1ull << VIRTIO_BLK_F_OUT_FUA |
> +               #endif
>                 1ull << VIRTIO_BLK_F_CONFIG_WCE;
>  
>      if (vdev_blk->enable_ro) {
> diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c
> index 4bb5ed299e7..988be625969 100644
> --- a/hw/block/vhost-user-blk.c
> +++ b/hw/block/vhost-user-blk.c
> @@ -44,6 +44,7 @@ static const int user_feature_bits[] = {
>      VIRTIO_BLK_F_CONFIG_WCE,
>      VIRTIO_BLK_F_DISCARD,
>      VIRTIO_BLK_F_WRITE_ZEROES,
> +    VIRTIO_BLK_F_OUT_FUA,
>      VIRTIO_F_VERSION_1,
>      VIRTIO_RING_F_INDIRECT_DESC,
>      VIRTIO_RING_F_EVENT_IDX,
> @@ -581,6 +582,8 @@ static const Property vhost_user_blk_properties[] = {
>                        VIRTIO_BLK_F_DISCARD, true),
>      DEFINE_PROP_BIT64("write-zeroes", VHostUserBlk, parent_obj.host_features,
>                        VIRTIO_BLK_F_WRITE_ZEROES, true),
> +    DEFINE_PROP_BIT64("fua-write", VHostUserBlk, parent_obj.host_features,
> +                      VIRTIO_BLK_F_OUT_FUA, true),
>  };
>  
>  static void vhost_user_blk_class_init(ObjectClass *klass, const void *data)
> diff --git a/hw/core/machine.c b/hw/core/machine.c
> index 8439b094904..bcf4f3423cb 100644
> --- a/hw/core/machine.c
> +++ b/hw/core/machine.c
> @@ -39,6 +39,7 @@
>  
>  GlobalProperty hw_compat_10_0[] = {
>      { "virtio-blk-device", "fua-write", "false" },
> +    { "vhost-user-blk", "fua-write", "false" },
>  };
>  const size_t hw_compat_10_0_len = G_N_ELEMENTS(hw_compat_10_0);
>  
> diff --git a/tests/qtest/vhost-user-blk-test.c b/tests/qtest/vhost-user-blk-test.c
> index ea90d41232e..4c68702e0b0 100644
> --- a/tests/qtest/vhost-user-blk-test.c
> +++ b/tests/qtest/vhost-user-blk-test.c
> @@ -72,6 +72,7 @@ static uint64_t virtio_blk_request(QGuestAllocator *alloc, QVirtioDevice *d,
>      switch (req->type) {
>      case VIRTIO_BLK_T_IN:
>      case VIRTIO_BLK_T_OUT:
> +    case VIRTIO_BLK_T_OUT_FUA:
>          g_assert_cmpuint(data_size % 512, ==, 0);
>          break;
>      case VIRTIO_BLK_T_DISCARD:
> @@ -389,6 +390,61 @@ static QVirtQueue *test_basic(QVirtioDevice *dev, QGuestAllocator *alloc)
>                                            VIRTIO_BLK_T_DISCARD);
>      }
>  
> +    if (features & (1u << VIRTIO_BLK_F_OUT_FUA)) {
> +        /* FUA write and read with 3 descriptor layout */
> +        /* FUA write request */
> +        req.type = VIRTIO_BLK_T_OUT_FUA;
> +        req.ioprio = 1;
> +        req.sector = 0;
> +        req.data = g_malloc0(512);
> +        strcpy(req.data, "test");
> +
> +        req_addr = virtio_blk_request(alloc, dev, &req, 512);
> +
> +        g_free(req.data);
> +
> +        free_head = qvirtqueue_add(qts, vq, req_addr, 16, false, true);
> +        qvirtqueue_add(qts, vq, req_addr + 16, 512, false, true);
> +        qvirtqueue_add(qts, vq, req_addr + 528, 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 + 528);
> +        g_assert_cmpint(status, ==, 0);
> +
> +        guest_free(alloc, req_addr);
> +
> +        /* Read request */
> +        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(qts, vq, req_addr, 16, false, true);
> +        qvirtqueue_add(qts, vq, req_addr + 16, 512, true, true);
> +        qvirtqueue_add(qts, vq, req_addr + 528, 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 + 528);
> +        g_assert_cmpint(status, ==, 0);
> +
> +        data = g_malloc0(512);
> +        qtest_memread(qts, req_addr + 16, data, 512);
> +        g_assert_cmpstr(data, ==, "test");
> +        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.49.0
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2025-05-12 19:43 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-08 16:20 [RFC v2 0/4] virtio-blk: Add support for FUA write requests Alberto Faria
2025-05-08 16:20 ` [RFC v2 1/4] include: Add tentative virtio-blk FUA write definitions Alberto Faria
2025-05-12 19:12   ` Stefan Hajnoczi
2025-05-08 16:20 ` [RFC v2 2/4] virtio-blk: Add VIRTIO_BLK_T_OUT_FUA command support Alberto Faria
2025-05-12 19:32   ` Stefan Hajnoczi
2025-05-08 16:20 ` [RFC v2 3/4] vhost-user-blk: " Alberto Faria
2025-05-12 19:43   ` Stefan Hajnoczi [this message]
2025-05-08 16:20 ` [RFC v2 4/4] vduse-blk: " Alberto Faria
2025-05-12 19:52   ` Stefan Hajnoczi
2025-05-12 19:52   ` Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250512194312.GM141177@fedora \
    --to=stefanha@redhat.com \
    --cc=Coiby.Xu@gmail.com \
    --cc=afaria@redhat.com \
    --cc=cohuck@redhat.com \
    --cc=eduardo@habkost.net \
    --cc=farosas@suse.de \
    --cc=hreitz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=lvivier@redhat.com \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=raphael@enfabrica.net \
    --cc=sgarzare@redhat.com \
    --cc=wangyanan55@huawei.com \
    --cc=xieyongji@bytedance.com \
    --cc=zhao1.liu@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.