From: Albert Esteve <aesteve@redhat.com>
To: qemu-devel@nongnu.org
Cc: marcandre.lureau@gmail.com, kraxel@redhat.com, cohuck@redhat.com,
Albert Esteve <aesteve@redhat.com>, Fam Zheng <fam@euphon.net>,
"Michael S. Tsirkin" <mst@redhat.com>
Subject: [PATCH v5 4/4] vhost-user: refactor send_resp code
Date: Wed, 2 Aug 2023 11:08:24 +0200 [thread overview]
Message-ID: <20230802090824.91688-5-aesteve@redhat.com> (raw)
In-Reply-To: <20230802090824.91688-1-aesteve@redhat.com>
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 | 36 +++++++++---------------------------
1 file changed, 9 insertions(+), 27 deletions(-)
diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index 104a56a48d..28fa0ace42 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -1632,29 +1632,23 @@ vhost_user_backend_handle_shared_object_remove(VhostUserShared *object)
return virtio_remove_resource(&uuid);
}
-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];
+ struct iovec iov[] = {
+ { .iov_base = hdr, .iov_len = VHOST_USER_HDR_SIZE },
+ { .iov_base = payload, .iov_len = hdr->size },
+ };
- if (hdr->flags & VHOST_USER_NEED_REPLY_MASK) {
- hdr->flags &= ~VHOST_USER_NEED_REPLY_MASK;
- }
+ hdr->flags &= ~VHOST_USER_NEED_REPLY_MASK;
hdr->flags |= VHOST_USER_REPLY_MASK;
- hdr->size = sizeof(payload->u64);
-
- 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;
}
+
return true;
}
@@ -1834,22 +1828,10 @@ static gboolean backend_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
next prev parent reply other threads:[~2023-08-02 9:09 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-02 9:08 [PATCH v5 0/4] Virtio shared dma-buf Albert Esteve
2023-08-02 9:08 ` [PATCH v5 1/4] uuid: add a hash function Albert Esteve
2023-09-06 5:06 ` Philippe Mathieu-Daudé
2023-08-02 9:08 ` [PATCH v5 2/4] virtio-dmabuf: introduce virtio-dmabuf Albert Esteve
2023-09-06 5:56 ` Philippe Mathieu-Daudé
2023-09-06 7:42 ` Albert Esteve
2023-09-06 8:45 ` Albert Esteve
2023-09-06 9:16 ` Philippe Mathieu-Daudé
2023-08-02 9:08 ` [PATCH v5 3/4] vhost-user: add shared_object msg Albert Esteve
2023-09-06 6:04 ` Philippe Mathieu-Daudé
2023-09-06 6:09 ` Philippe Mathieu-Daudé
2023-09-06 6:54 ` Albert Esteve
2023-08-02 9:08 ` Albert Esteve [this message]
2023-09-06 6:11 ` [PATCH v5 4/4] vhost-user: refactor send_resp code Philippe Mathieu-Daudé
2023-08-21 12:37 ` [PATCH v5 0/4] Virtio shared dma-buf Albert Esteve
2023-09-05 20:45 ` Michael S. Tsirkin
2023-09-06 6:13 ` Philippe Mathieu-Daudé
2023-09-06 9:39 ` Albert Esteve
2023-09-06 10:16 ` Philippe Mathieu-Daudé
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=20230802090824.91688-5-aesteve@redhat.com \
--to=aesteve@redhat.com \
--cc=cohuck@redhat.com \
--cc=fam@euphon.net \
--cc=kraxel@redhat.com \
--cc=marcandre.lureau@gmail.com \
--cc=mst@redhat.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).