From: Albert Esteve <aesteve@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
Albert Esteve <aesteve@redhat.com>
Subject: [PATCH 3/4] vhost-user: refactor send_resp code
Date: Wed, 3 May 2023 10:19:10 +0200 [thread overview]
Message-ID: <20230503081911.119168-4-aesteve@redhat.com> (raw)
In-Reply-To: <20230503081911.119168-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 | 52 +++++++++++++++++++-----------------------
1 file changed, 24 insertions(+), 28 deletions(-)
diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index d0b889282a..3e5affa67e 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -1628,28 +1628,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];
- 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;
}
@@ -1726,22 +1734,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
next prev parent reply other threads:[~2023-05-03 8:21 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-03 8:19 [PATCH 0/4] Virtio shared dma-buf Albert Esteve
2023-05-03 8:19 ` [PATCH 1/4] virtio-dmabuf: introduce virtio-dmabuf Albert Esteve
2023-05-08 13:12 ` Cornelia Huck
2023-05-09 7:21 ` Albert Esteve
2023-05-09 10:52 ` Marc-André Lureau
2023-05-09 12:52 ` Albert Esteve
2023-05-09 12:57 ` Marc-André Lureau
2023-05-17 15:10 ` Albert Esteve
2023-05-03 8:19 ` [PATCH 2/4] vhost-user: add shared_object msg Albert Esteve
2023-05-03 8:19 ` Albert Esteve [this message]
2023-05-03 8:19 ` [PATCH 4/4] libvhost-user: add write_msg cb to dev struct Albert Esteve
2023-05-09 10:11 ` Marc-André Lureau
2023-05-09 11:17 ` Albert Esteve
2023-05-09 12:53 ` Marc-André Lureau
2023-05-10 12:30 ` Albert Esteve
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=20230503081911.119168-4-aesteve@redhat.com \
--to=aesteve@redhat.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).