qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Albert Esteve <aesteve@redhat.com>
Cc: qemu-devel@nongnu.org, kraxel@redhat.com,
	marcandre.lureau@gmail.com, cohuck@redhat.com,
	Fam Zheng <fam@euphon.net>
Subject: Re: [PATCH v3 4/4] vhost-user: refactor send_resp code
Date: Fri, 23 Jun 2023 02:48:01 -0400	[thread overview]
Message-ID: <20230623024530-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20230524091333.201767-5-aesteve@redhat.com>

On Wed, May 24, 2023 at 11:13:33AM +0200, Albert Esteve wrote:
> Refactor code to send response message so that
> all common parts both for the common REPLY_ACK
> case, and other data responses, can call it and
> avoid code repetition.
> 
> Signed-off-by: Albert Esteve <aesteve@redhat.com>
> ---
>  hw/virtio/vhost-user.c | 52 +++++++++++++++++++-----------------------
>  1 file changed, 24 insertions(+), 28 deletions(-)
> 
> diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
> index 5ac5f0eafd..b888f2c177 100644
> --- a/hw/virtio/vhost-user.c
> +++ b/hw/virtio/vhost-user.c
> @@ -1619,28 +1619,36 @@ static int vhost_user_backend_handle_shared_object(VhostUserShared *object)
>      return 0;
>  }
>  
> -static bool
> -vhost_user_backend_send_dmabuf_fd(QIOChannel *ioc, VhostUserHeader *hdr,
> -                                  VhostUserPayload *payload)
> +static bool vhost_user_send_resp(QIOChannel *ioc, VhostUserHeader *hdr,
> +                                 VhostUserPayload *payload)
>  {
>      Error *local_err = NULL;
>      struct iovec iov[2];


As long as you are refactoring, please add an empty line here
after variable declaration.

Also, can't we initialize it here?
	struct iovec iov[] = {
		{ .iov_base = hdr ....},
		{ .iov_base = payload }
	};

will also avoid the need for explicit size.


> -    if (hdr->flags & VHOST_USER_NEED_REPLY_MASK) {
> -        hdr->flags &= ~VHOST_USER_NEED_REPLY_MASK;
> -        hdr->flags |= VHOST_USER_REPLY_MASK;
> +    hdr->flags &= ~VHOST_USER_NEED_REPLY_MASK;
> +    hdr->flags |= VHOST_USER_REPLY_MASK;
>  
> -        hdr->size = sizeof(payload->object);
> +    iov[0].iov_base = hdr;
> +    iov[0].iov_len = VHOST_USER_HDR_SIZE;
> +    iov[1].iov_base = payload;
> +    iov[1].iov_len = hdr->size;
> +
> +    if (qio_channel_writev_all(ioc, iov, ARRAY_SIZE(iov), &local_err)) {
> +        error_report_err(local_err);
> +        return false;
> +    }
>  
> -        iov[0].iov_base = hdr;
> -        iov[0].iov_len = VHOST_USER_HDR_SIZE;
> -        iov[1].iov_base = payload;
> -        iov[1].iov_len = hdr->size;
> +    return true;
> +}
>  
> -        if (qio_channel_writev_all(ioc, iov, ARRAY_SIZE(iov), &local_err)) {
> -            error_report_err(local_err);
> -            return false;
> -        }
> +static bool
> +vhost_user_backend_send_dmabuf_fd(QIOChannel *ioc, VhostUserHeader *hdr,
> +                                  VhostUserPayload *payload)
> +{
> +    if (hdr->flags & VHOST_USER_NEED_REPLY_MASK) {
> +        hdr->size = sizeof(payload->object);
> +        return vhost_user_send_resp(ioc, hdr, payload);
>      }
> +
>      return true;
>  }
>  
> @@ -1717,22 +1725,10 @@ static gboolean slave_read(QIOChannel *ioc, GIOCondition condition,
>       * directly in their request handlers.
>       */
>      if (hdr.flags & VHOST_USER_NEED_REPLY_MASK) {
> -        struct iovec iovec[2];
> -
> -
> -        hdr.flags &= ~VHOST_USER_NEED_REPLY_MASK;
> -        hdr.flags |= VHOST_USER_REPLY_MASK;
> -
>          payload.u64 = !!ret;
>          hdr.size = sizeof(payload.u64);
>  
> -        iovec[0].iov_base = &hdr;
> -        iovec[0].iov_len = VHOST_USER_HDR_SIZE;
> -        iovec[1].iov_base = &payload;
> -        iovec[1].iov_len = hdr.size;
> -
> -        if (qio_channel_writev_all(ioc, iovec, ARRAY_SIZE(iovec), &local_err)) {
> -            error_report_err(local_err);
> +        if (!vhost_user_send_resp(ioc, &hdr, &payload)) {
>              goto err;
>          }
>      }
> -- 
> 2.40.0



  reply	other threads:[~2023-06-23  6:48 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-24  9:13 [PATCH v3 0/4] Virtio shared dma-buf Albert Esteve
2023-05-24  9:13 ` [PATCH v3 1/4] uuid: add hash_func and equal_func Albert Esteve
2023-05-24  9:13 ` [PATCH v3 2/4] virtio-dmabuf: introduce virtio-dmabuf Albert Esteve
2023-05-24  9:13 ` [PATCH v3 3/4] vhost-user: add shared_object msg Albert Esteve
2023-06-22 19:57   ` Michael S. Tsirkin
2023-06-22 20:18   ` Marc-André Lureau
2023-06-23  7:45     ` Albert Esteve
2023-06-23  6:45   ` Michael S. Tsirkin
2023-06-23  7:19     ` Albert Esteve
2023-06-23  7:32       ` Michael S. Tsirkin
2023-06-23 13:46     ` Albert Esteve
2023-06-23  8:14   ` Michael S. Tsirkin
2023-06-23 12:08     ` Albert Esteve
2023-05-24  9:13 ` [PATCH v3 4/4] vhost-user: refactor send_resp code Albert Esteve
2023-06-23  6:48   ` Michael S. Tsirkin [this message]
2023-06-21  8:20 ` [PATCH v3 0/4] Virtio shared dma-buf Albert Esteve
2023-06-21 20:25   ` Michael S. Tsirkin
2023-06-22 19:53   ` Michael S. Tsirkin
2023-06-23  6:49 ` Michael S. Tsirkin

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=20230623024530-mutt-send-email-mst@kernel.org \
    --to=mst@redhat.com \
    --cc=aesteve@redhat.com \
    --cc=cohuck@redhat.com \
    --cc=fam@euphon.net \
    --cc=kraxel@redhat.com \
    --cc=marcandre.lureau@gmail.com \
    --cc=qemu-devel@nongnu.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).