mirror of
https://github.com/qemu/qemu.git
synced 2026-07-08 17:46:17 +00:00
vhost-user: introduce vhost_user_has_protocol_feature() helper
Make all protocol feature checks in the same way. Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru> Reviewed-by: Daniil Tatianin <d-tatianin@yandex-team.ru> Reviewed-by: Raphael Norwitz <raphael.s.norwitz@gmail.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Tested-by: Lei Yang <leiyang@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Message-Id: <20260420200339.708640-4-vsementsov@yandex-team.ru>
This commit is contained in:
committed by
Michael S. Tsirkin
parent
1ee0bc0c9b
commit
be9ecc9df0
@@ -267,6 +267,12 @@ struct scrub_regions {
|
||||
int fd_idx;
|
||||
};
|
||||
|
||||
static bool vhost_user_has_protocol_feature(struct vhost_dev *dev,
|
||||
uint64_t feature)
|
||||
{
|
||||
return virtio_has_feature(dev->protocol_features, feature);
|
||||
}
|
||||
|
||||
static int vhost_user_read_header(struct vhost_dev *dev, VhostUserMsg *msg)
|
||||
{
|
||||
struct vhost_user *u = dev->opaque;
|
||||
@@ -430,8 +436,8 @@ static int vhost_user_set_log_base(struct vhost_dev *dev, uint64_t base,
|
||||
{
|
||||
int fds[VHOST_USER_MAX_RAM_SLOTS];
|
||||
size_t fd_num = 0;
|
||||
bool shmfd = virtio_has_feature(dev->protocol_features,
|
||||
VHOST_USER_PROTOCOL_F_LOG_SHMFD);
|
||||
bool shmfd =
|
||||
vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_LOG_SHMFD);
|
||||
int ret;
|
||||
VhostUserMsg msg = {
|
||||
.hdr.request = VHOST_USER_SET_LOG_BASE,
|
||||
@@ -1001,11 +1007,11 @@ static int vhost_user_set_mem_table(struct vhost_dev *dev,
|
||||
int fds[VHOST_MEMORY_BASELINE_NREGIONS];
|
||||
size_t fd_num = 0;
|
||||
bool do_postcopy = u->postcopy_listen && u->postcopy_fd.handler;
|
||||
bool reply_supported = virtio_has_feature(dev->protocol_features,
|
||||
VHOST_USER_PROTOCOL_F_REPLY_ACK);
|
||||
bool reply_supported =
|
||||
vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_REPLY_ACK);
|
||||
bool config_mem_slots =
|
||||
virtio_has_feature(dev->protocol_features,
|
||||
VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS);
|
||||
vhost_user_has_protocol_feature(
|
||||
dev, VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS);
|
||||
int ret;
|
||||
|
||||
if (do_postcopy) {
|
||||
@@ -1053,8 +1059,9 @@ static int vhost_user_set_mem_table(struct vhost_dev *dev,
|
||||
static int vhost_user_set_vring_endian(struct vhost_dev *dev,
|
||||
struct vhost_vring_state *ring)
|
||||
{
|
||||
bool cross_endian = virtio_has_feature(dev->protocol_features,
|
||||
VHOST_USER_PROTOCOL_F_CROSS_ENDIAN);
|
||||
bool cross_endian =
|
||||
vhost_user_has_protocol_feature(
|
||||
dev, VHOST_USER_PROTOCOL_F_CROSS_ENDIAN);
|
||||
VhostUserMsg msg = {
|
||||
.hdr.request = VHOST_USER_SET_VRING_ENDIAN,
|
||||
.hdr.flags = VHOST_USER_VERSION,
|
||||
@@ -1124,8 +1131,9 @@ static int vhost_user_write_sync(struct vhost_dev *dev, VhostUserMsg *msg,
|
||||
int ret;
|
||||
|
||||
if (wait_for_reply) {
|
||||
bool reply_supported = virtio_has_feature(dev->protocol_features,
|
||||
VHOST_USER_PROTOCOL_F_REPLY_ACK);
|
||||
bool reply_supported =
|
||||
vhost_user_has_protocol_feature(
|
||||
dev, VHOST_USER_PROTOCOL_F_REPLY_ACK);
|
||||
if (reply_supported) {
|
||||
msg->hdr.flags |= VHOST_USER_NEED_REPLY_MASK;
|
||||
}
|
||||
@@ -1475,8 +1483,7 @@ static int vhost_user_set_features(struct vhost_dev *dev,
|
||||
ret = vhost_user_set_u64(dev, VHOST_USER_SET_FEATURES, features,
|
||||
log_enabled);
|
||||
|
||||
if (virtio_has_feature(dev->protocol_features,
|
||||
VHOST_USER_PROTOCOL_F_STATUS)) {
|
||||
if (vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_STATUS)) {
|
||||
if (!ret) {
|
||||
return vhost_user_add_status(dev, VIRTIO_CONFIG_S_FEATURES_OK);
|
||||
}
|
||||
@@ -1530,8 +1537,8 @@ static int vhost_user_reset_device(struct vhost_dev *dev)
|
||||
* Historically, reset was not implemented so only reset devices
|
||||
* that are expecting it.
|
||||
*/
|
||||
if (!virtio_has_feature(dev->protocol_features,
|
||||
VHOST_USER_PROTOCOL_F_RESET_DEVICE)) {
|
||||
if (!vhost_user_has_protocol_feature(
|
||||
dev, VHOST_USER_PROTOCOL_F_RESET_DEVICE)) {
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
@@ -1588,8 +1595,8 @@ static int vhost_user_backend_handle_vring_host_notifier(struct vhost_dev *dev,
|
||||
void *addr;
|
||||
char *name;
|
||||
|
||||
if (!virtio_has_feature(dev->protocol_features,
|
||||
VHOST_USER_PROTOCOL_F_HOST_NOTIFIER) ||
|
||||
if (!vhost_user_has_protocol_feature(
|
||||
dev, VHOST_USER_PROTOCOL_F_HOST_NOTIFIER) ||
|
||||
vdev == NULL || queue_idx >= virtio_get_num_queues(vdev)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
@@ -1887,13 +1894,13 @@ static int vhost_setup_backend_channel(struct vhost_dev *dev)
|
||||
};
|
||||
struct vhost_user *u = dev->opaque;
|
||||
int sv[2], ret = 0;
|
||||
bool reply_supported = virtio_has_feature(dev->protocol_features,
|
||||
VHOST_USER_PROTOCOL_F_REPLY_ACK);
|
||||
bool reply_supported =
|
||||
vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_REPLY_ACK);
|
||||
Error *local_err = NULL;
|
||||
QIOChannel *ioc;
|
||||
|
||||
if (!virtio_has_feature(dev->protocol_features,
|
||||
VHOST_USER_PROTOCOL_F_BACKEND_REQ)) {
|
||||
if (!vhost_user_has_protocol_feature(
|
||||
dev, VHOST_USER_PROTOCOL_F_BACKEND_REQ)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -2141,8 +2148,8 @@ static int vhost_user_postcopy_notifier(NotifierWithReturn *notifier,
|
||||
|
||||
switch (pnd->reason) {
|
||||
case POSTCOPY_NOTIFY_PROBE:
|
||||
if (!virtio_has_feature(dev->protocol_features,
|
||||
VHOST_USER_PROTOCOL_F_PAGEFAULT)) {
|
||||
if (!vhost_user_has_protocol_feature(
|
||||
dev, VHOST_USER_PROTOCOL_F_PAGEFAULT)) {
|
||||
/* TODO: Get the device name into this error somehow */
|
||||
error_setg(errp,
|
||||
"vhost-user backend not capable of postcopy");
|
||||
@@ -2240,7 +2247,7 @@ static int vhost_user_backend_init(struct vhost_dev *dev, void *opaque,
|
||||
}
|
||||
|
||||
/* query the max queues we support if backend supports Multiple Queue */
|
||||
if (dev->protocol_features & (1ULL << VHOST_USER_PROTOCOL_F_MQ)) {
|
||||
if (vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_MQ)) {
|
||||
err = vhost_user_get_u64(dev, VHOST_USER_GET_QUEUE_NUM,
|
||||
&dev->max_queues);
|
||||
if (err < 0) {
|
||||
@@ -2258,18 +2265,18 @@ static int vhost_user_backend_init(struct vhost_dev *dev, void *opaque,
|
||||
}
|
||||
|
||||
if (virtio_has_feature(features, VIRTIO_F_IOMMU_PLATFORM) &&
|
||||
!(virtio_has_feature(dev->protocol_features,
|
||||
VHOST_USER_PROTOCOL_F_BACKEND_REQ) &&
|
||||
virtio_has_feature(dev->protocol_features,
|
||||
VHOST_USER_PROTOCOL_F_REPLY_ACK))) {
|
||||
!(vhost_user_has_protocol_feature(
|
||||
dev, VHOST_USER_PROTOCOL_F_BACKEND_REQ) &&
|
||||
vhost_user_has_protocol_feature(
|
||||
dev, VHOST_USER_PROTOCOL_F_REPLY_ACK))) {
|
||||
error_setg(errp, "IOMMU support requires reply-ack and "
|
||||
"backend-req protocol features.");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* get max memory regions if backend supports configurable RAM slots */
|
||||
if (!virtio_has_feature(dev->protocol_features,
|
||||
VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS)) {
|
||||
if (!vhost_user_has_protocol_feature(
|
||||
dev, VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS)) {
|
||||
u->user->memory_slots = VHOST_MEMORY_BASELINE_NREGIONS;
|
||||
} else {
|
||||
err = vhost_user_get_max_memslots(dev, &ram_slots);
|
||||
@@ -2293,8 +2300,8 @@ static int vhost_user_backend_init(struct vhost_dev *dev, void *opaque,
|
||||
}
|
||||
|
||||
if (dev->migration_blocker == NULL &&
|
||||
!virtio_has_feature(dev->protocol_features,
|
||||
VHOST_USER_PROTOCOL_F_LOG_SHMFD)) {
|
||||
!vhost_user_has_protocol_feature(
|
||||
dev, VHOST_USER_PROTOCOL_F_LOG_SHMFD)) {
|
||||
error_setg(&dev->migration_blocker,
|
||||
"Migration disabled: vhost-user backend lacks "
|
||||
"VHOST_USER_PROTOCOL_F_LOG_SHMFD feature.");
|
||||
@@ -2363,8 +2370,8 @@ static bool vhost_user_requires_shm_log(struct vhost_dev *dev)
|
||||
{
|
||||
assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_USER);
|
||||
|
||||
return virtio_has_feature(dev->protocol_features,
|
||||
VHOST_USER_PROTOCOL_F_LOG_SHMFD);
|
||||
return vhost_user_has_protocol_feature(
|
||||
dev, VHOST_USER_PROTOCOL_F_LOG_SHMFD);
|
||||
}
|
||||
|
||||
static int vhost_user_migration_done(struct vhost_dev *dev, char* mac_addr)
|
||||
@@ -2379,8 +2386,7 @@ static int vhost_user_migration_done(struct vhost_dev *dev, char* mac_addr)
|
||||
}
|
||||
|
||||
/* if backend supports VHOST_USER_PROTOCOL_F_RARP ask it to send the RARP */
|
||||
if (virtio_has_feature(dev->protocol_features,
|
||||
VHOST_USER_PROTOCOL_F_RARP)) {
|
||||
if (vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_RARP)) {
|
||||
msg.hdr.request = VHOST_USER_SEND_RARP;
|
||||
msg.hdr.flags = VHOST_USER_VERSION;
|
||||
memcpy((char *)&msg.payload.u64, mac_addr, 6);
|
||||
@@ -2394,11 +2400,11 @@ static int vhost_user_migration_done(struct vhost_dev *dev, char* mac_addr)
|
||||
static int vhost_user_net_set_mtu(struct vhost_dev *dev, uint16_t mtu)
|
||||
{
|
||||
VhostUserMsg msg;
|
||||
bool reply_supported = virtio_has_feature(dev->protocol_features,
|
||||
VHOST_USER_PROTOCOL_F_REPLY_ACK);
|
||||
bool reply_supported =
|
||||
vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_REPLY_ACK);
|
||||
int ret;
|
||||
|
||||
if (!(dev->protocol_features & (1ULL << VHOST_USER_PROTOCOL_F_NET_MTU))) {
|
||||
if (!vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_NET_MTU)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -2458,8 +2464,7 @@ static int vhost_user_get_config(struct vhost_dev *dev, uint8_t *config,
|
||||
.hdr.size = VHOST_USER_CONFIG_HDR_SIZE + config_len,
|
||||
};
|
||||
|
||||
if (!virtio_has_feature(dev->protocol_features,
|
||||
VHOST_USER_PROTOCOL_F_CONFIG)) {
|
||||
if (!vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_CONFIG)) {
|
||||
error_setg(errp, "VHOST_USER_PROTOCOL_F_CONFIG not supported");
|
||||
return -EINVAL;
|
||||
}
|
||||
@@ -2502,8 +2507,8 @@ static int vhost_user_set_config(struct vhost_dev *dev, const uint8_t *data,
|
||||
{
|
||||
int ret;
|
||||
uint8_t *p;
|
||||
bool reply_supported = virtio_has_feature(dev->protocol_features,
|
||||
VHOST_USER_PROTOCOL_F_REPLY_ACK);
|
||||
bool reply_supported =
|
||||
vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_REPLY_ACK);
|
||||
|
||||
VhostUserMsg msg = {
|
||||
.hdr.request = VHOST_USER_SET_CONFIG,
|
||||
@@ -2511,8 +2516,7 @@ static int vhost_user_set_config(struct vhost_dev *dev, const uint8_t *data,
|
||||
.hdr.size = VHOST_USER_CONFIG_HDR_SIZE + size,
|
||||
};
|
||||
|
||||
if (!virtio_has_feature(dev->protocol_features,
|
||||
VHOST_USER_PROTOCOL_F_CONFIG)) {
|
||||
if (!vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_CONFIG)) {
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
@@ -2547,8 +2551,9 @@ static int vhost_user_crypto_create_session(struct vhost_dev *dev,
|
||||
uint64_t *session_id)
|
||||
{
|
||||
int ret;
|
||||
bool crypto_session = virtio_has_feature(dev->protocol_features,
|
||||
VHOST_USER_PROTOCOL_F_CRYPTO_SESSION);
|
||||
bool crypto_session =
|
||||
vhost_user_has_protocol_feature(
|
||||
dev, VHOST_USER_PROTOCOL_F_CRYPTO_SESSION);
|
||||
CryptoDevBackendSessionInfo *backend_info = session_info;
|
||||
VhostUserMsg msg = {
|
||||
.hdr.request = VHOST_USER_CREATE_CRYPTO_SESSION,
|
||||
@@ -2649,8 +2654,9 @@ static int
|
||||
vhost_user_crypto_close_session(struct vhost_dev *dev, uint64_t session_id)
|
||||
{
|
||||
int ret;
|
||||
bool crypto_session = virtio_has_feature(dev->protocol_features,
|
||||
VHOST_USER_PROTOCOL_F_CRYPTO_SESSION);
|
||||
bool crypto_session =
|
||||
vhost_user_has_protocol_feature(
|
||||
dev, VHOST_USER_PROTOCOL_F_CRYPTO_SESSION);
|
||||
VhostUserMsg msg = {
|
||||
.hdr.request = VHOST_USER_CLOSE_CRYPTO_SESSION,
|
||||
.hdr.flags = VHOST_USER_VERSION,
|
||||
@@ -2695,8 +2701,8 @@ static int vhost_user_get_inflight_fd(struct vhost_dev *dev,
|
||||
.hdr.size = sizeof(msg.payload.inflight),
|
||||
};
|
||||
|
||||
if (!virtio_has_feature(dev->protocol_features,
|
||||
VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) {
|
||||
if (!vhost_user_has_protocol_feature(
|
||||
dev, VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -2763,8 +2769,8 @@ static int vhost_user_set_inflight_fd(struct vhost_dev *dev,
|
||||
.hdr.size = sizeof(msg.payload.inflight),
|
||||
};
|
||||
|
||||
if (!virtio_has_feature(dev->protocol_features,
|
||||
VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) {
|
||||
if (!vhost_user_has_protocol_feature(
|
||||
dev, VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -2863,8 +2869,7 @@ void vhost_user_async_close(DeviceState *d,
|
||||
|
||||
static int vhost_user_dev_start(struct vhost_dev *dev, bool started)
|
||||
{
|
||||
if (!virtio_has_feature(dev->protocol_features,
|
||||
VHOST_USER_PROTOCOL_F_STATUS)) {
|
||||
if (!vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_STATUS)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -2889,16 +2894,15 @@ static void vhost_user_reset_status(struct vhost_dev *dev)
|
||||
return;
|
||||
}
|
||||
|
||||
if (virtio_has_feature(dev->protocol_features,
|
||||
VHOST_USER_PROTOCOL_F_STATUS)) {
|
||||
if (vhost_user_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_STATUS)) {
|
||||
vhost_user_set_status(dev, 0);
|
||||
}
|
||||
}
|
||||
|
||||
static bool vhost_user_supports_device_state(struct vhost_dev *dev)
|
||||
{
|
||||
return virtio_has_feature(dev->protocol_features,
|
||||
VHOST_USER_PROTOCOL_F_DEVICE_STATE);
|
||||
return vhost_user_has_protocol_feature(
|
||||
dev, VHOST_USER_PROTOCOL_F_DEVICE_STATE);
|
||||
}
|
||||
|
||||
static int vhost_user_set_device_state_fd(struct vhost_dev *dev,
|
||||
|
||||
Reference in New Issue
Block a user