[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 26/63] vhost-user: factor out "vhost_user_write_sync"
From: |
Michael S. Tsirkin |
Subject: |
[PULL 26/63] vhost-user: factor out "vhost_user_write_sync" |
Date: |
Wed, 4 Oct 2023 04:44:29 -0400 |
From: Laszlo Ersek <lersek@redhat.com>
The tails of the "vhost_user_set_vring_addr" and "vhost_user_set_u64"
functions are now byte-for-byte identical. Factor the common tail out to a
new function called "vhost_user_write_sync".
This is purely refactoring -- no observable change.
Cc: "Michael S. Tsirkin" <mst@redhat.com> (supporter:vhost)
Cc: Eugenio Perez Martin <eperezma@redhat.com>
Cc: German Maglione <gmaglione@redhat.com>
Cc: Liu Jiang <gerry@linux.alibaba.com>
Cc: Sergio Lopez Pascual <slp@redhat.com>
Cc: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Message-Id: <20230830134055.106812-4-lersek@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Eugenio Pérez <eperezma@redhat.com>
---
hw/virtio/vhost-user.c | 66 ++++++++++++++++++------------------------
1 file changed, 28 insertions(+), 38 deletions(-)
diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index dae16d3b33..06d6df3a98 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -1299,10 +1299,35 @@ static int enforce_reply(struct vhost_dev *dev,
return vhost_user_get_features(dev, &dummy);
}
+/* Note: "msg->hdr.flags" may be modified. */
+static int vhost_user_write_sync(struct vhost_dev *dev, VhostUserMsg *msg,
+ bool wait_for_reply)
+{
+ int ret;
+
+ if (wait_for_reply) {
+ bool reply_supported = virtio_has_feature(dev->protocol_features,
+ VHOST_USER_PROTOCOL_F_REPLY_ACK);
+ if (reply_supported) {
+ msg->hdr.flags |= VHOST_USER_NEED_REPLY_MASK;
+ }
+ }
+
+ ret = vhost_user_write(dev, msg, NULL, 0);
+ if (ret < 0) {
+ return ret;
+ }
+
+ if (wait_for_reply) {
+ return enforce_reply(dev, msg);
+ }
+
+ return 0;
+}
+
static int vhost_user_set_vring_addr(struct vhost_dev *dev,
struct vhost_vring_addr *addr)
{
- int ret;
VhostUserMsg msg = {
.hdr.request = VHOST_USER_SET_VRING_ADDR,
.hdr.flags = VHOST_USER_VERSION,
@@ -1316,24 +1341,7 @@ static int vhost_user_set_vring_addr(struct vhost_dev
*dev,
*/
bool wait_for_reply = addr->flags & (1 << VHOST_VRING_F_LOG);
- if (wait_for_reply) {
- bool reply_supported = virtio_has_feature(dev->protocol_features,
- VHOST_USER_PROTOCOL_F_REPLY_ACK);
- if (reply_supported) {
- msg.hdr.flags |= VHOST_USER_NEED_REPLY_MASK;
- }
- }
-
- ret = vhost_user_write(dev, &msg, NULL, 0);
- if (ret < 0) {
- return ret;
- }
-
- if (wait_for_reply) {
- return enforce_reply(dev, &msg);
- }
-
- return 0;
+ return vhost_user_write_sync(dev, &msg, wait_for_reply);
}
static int vhost_user_set_u64(struct vhost_dev *dev, int request, uint64_t u64,
@@ -1345,26 +1353,8 @@ static int vhost_user_set_u64(struct vhost_dev *dev, int
request, uint64_t u64,
.payload.u64 = u64,
.hdr.size = sizeof(msg.payload.u64),
};
- int ret;
- if (wait_for_reply) {
- bool reply_supported = virtio_has_feature(dev->protocol_features,
- VHOST_USER_PROTOCOL_F_REPLY_ACK);
- if (reply_supported) {
- msg.hdr.flags |= VHOST_USER_NEED_REPLY_MASK;
- }
- }
-
- ret = vhost_user_write(dev, &msg, NULL, 0);
- if (ret < 0) {
- return ret;
- }
-
- if (wait_for_reply) {
- return enforce_reply(dev, &msg);
- }
-
- return 0;
+ return vhost_user_write_sync(dev, &msg, wait_for_reply);
}
static int vhost_user_set_status(struct vhost_dev *dev, uint8_t status)
--
MST
- [PULL 13/63] vdpa: Allow VIRTIO_NET_F_CTRL_VLAN in SVQ, (continued)
- [PULL 13/63] vdpa: Allow VIRTIO_NET_F_CTRL_VLAN in SVQ, Michael S. Tsirkin, 2023/10/04
- [PULL 10/63] virtio-net: do not reset vlan filtering at set_features, Michael S. Tsirkin, 2023/10/04
- [PULL 15/63] vdpa: use first queue SVQ state for CVQ default, Michael S. Tsirkin, 2023/10/04
- [PULL 17/63] vdpa: rename vhost_vdpa_net_load to vhost_vdpa_net_cvq_load, Michael S. Tsirkin, 2023/10/04
- [PULL 19/63] vdpa: remove net cvq migration blocker, Michael S. Tsirkin, 2023/10/04
- [PULL 12/63] vdpa: Restore vlan filtering state, Michael S. Tsirkin, 2023/10/04
- [PULL 16/63] vdpa: export vhost_vdpa_set_vring_ready, Michael S. Tsirkin, 2023/10/04
- [PULL 20/63] vhost: Add count argument to vhost_svq_poll(), Michael S. Tsirkin, 2023/10/04
- [PULL 22/63] qmp: update virtio feature maps, vhost-user-gpio introspection, Michael S. Tsirkin, 2023/10/04
- [PULL 24/63] vhost-user: strip superfluous whitespace, Michael S. Tsirkin, 2023/10/04
- [PULL 26/63] vhost-user: factor out "vhost_user_write_sync",
Michael S. Tsirkin <=
- [PULL 25/63] vhost-user: tighten "reply_supported" scope in "set_vring_addr", Michael S. Tsirkin, 2023/10/04
- [PULL 18/63] vdpa: move vhost_vdpa_set_vring_ready to the caller, Michael S. Tsirkin, 2023/10/04
- [PULL 23/63] vhost-user: move VhostUserProtocolFeature definition to header file, Michael S. Tsirkin, 2023/10/04
- [PULL 27/63] vhost-user: flatten "enforce_reply" into "vhost_user_write_sync", Michael S. Tsirkin, 2023/10/04
- [PULL 21/63] qmp: remove virtio_list, search QOM tree instead, Michael S. Tsirkin, 2023/10/04
- [PULL 28/63] vhost-user: hoist "write_sync", "get_features", "get_u64", Michael S. Tsirkin, 2023/10/04
- [PULL 30/63] vhost-user: call VHOST_USER_SET_VRING_ENABLE synchronously, Michael S. Tsirkin, 2023/10/04