Make all protocol feature checks in the same way. Signed-off-by: Vladimir Sementsov-Ogievskiy <vsement...@yandex-team.ru> --- hw/virtio/vhost-user.c | 102 ++++++++++++++++++----------------------- 1 file changed, 44 insertions(+), 58 deletions(-)
diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index cf6f53801d..6fa5b8a8bd 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -272,6 +272,11 @@ struct scrub_regions { int fd_idx; }; +static bool vhost_user_has_prot(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; @@ -435,8 +440,7 @@ 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_prot(dev, VHOST_USER_PROTOCOL_F_LOG_SHMFD); int ret; VhostUserMsg msg = { .hdr.request = VHOST_USER_SET_LOG_BASE, @@ -1006,11 +1010,10 @@ 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_prot(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_prot(dev, VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS); int ret; if (do_postcopy) { @@ -1058,8 +1061,8 @@ 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_prot(dev, VHOST_USER_PROTOCOL_F_CROSS_ENDIAN); VhostUserMsg msg = { .hdr.request = VHOST_USER_SET_VRING_ENDIAN, .hdr.flags = VHOST_USER_VERSION, @@ -1129,8 +1132,8 @@ 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_prot(dev, VHOST_USER_PROTOCOL_F_REPLY_ACK); if (reply_supported) { msg->hdr.flags |= VHOST_USER_NEED_REPLY_MASK; } @@ -1459,8 +1462,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_prot(dev, VHOST_USER_PROTOCOL_F_STATUS)) { if (!ret) { return vhost_user_add_status(dev, VIRTIO_CONFIG_S_FEATURES_OK); } @@ -1514,8 +1516,7 @@ 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_prot(dev, VHOST_USER_PROTOCOL_F_RESET_DEVICE)) { return -ENOSYS; } @@ -1572,8 +1573,7 @@ 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_prot(dev, VHOST_USER_PROTOCOL_F_HOST_NOTIFIER) || vdev == NULL || queue_idx >= virtio_get_num_queues(vdev)) { return -EINVAL; } @@ -1885,13 +1885,12 @@ 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_prot(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_prot(dev, VHOST_USER_PROTOCOL_F_BACKEND_REQ)) { return 0; } @@ -2136,8 +2135,7 @@ 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_prot(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"); @@ -2228,7 +2226,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_prot(dev, VHOST_USER_PROTOCOL_F_MQ)) { err = vhost_user_get_u64(dev, VHOST_USER_GET_QUEUE_NUM, &dev->max_queues); if (err < 0) { @@ -2246,18 +2244,16 @@ 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_prot(dev, VHOST_USER_PROTOCOL_F_BACKEND_REQ) && + vhost_user_has_prot(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_prot(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); @@ -2279,8 +2275,7 @@ 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_prot(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."); @@ -2349,8 +2344,7 @@ 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_prot(dev, VHOST_USER_PROTOCOL_F_LOG_SHMFD); } static int vhost_user_migration_done(struct vhost_dev *dev, char* mac_addr) @@ -2365,8 +2359,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_prot(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); @@ -2380,11 +2373,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_prot(dev, VHOST_USER_PROTOCOL_F_REPLY_ACK); int ret; - if (!(dev->protocol_features & (1ULL << VHOST_USER_PROTOCOL_F_NET_MTU))) { + if (!vhost_user_has_prot(dev, VHOST_USER_PROTOCOL_F_NET_MTU)) { return 0; } @@ -2444,8 +2437,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_prot(dev, VHOST_USER_PROTOCOL_F_CONFIG)) { error_setg(errp, "VHOST_USER_PROTOCOL_F_CONFIG not supported"); return -EINVAL; } @@ -2488,8 +2480,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_prot(dev, VHOST_USER_PROTOCOL_F_REPLY_ACK); VhostUserMsg msg = { .hdr.request = VHOST_USER_SET_CONFIG, @@ -2497,8 +2489,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_prot(dev, VHOST_USER_PROTOCOL_F_CONFIG)) { return -ENOTSUP; } @@ -2533,8 +2524,8 @@ 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_prot(dev, VHOST_USER_PROTOCOL_F_CRYPTO_SESSION); CryptoDevBackendSessionInfo *backend_info = session_info; VhostUserMsg msg = { .hdr.request = VHOST_USER_CREATE_CRYPTO_SESSION, @@ -2635,8 +2626,8 @@ 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_prot(dev, VHOST_USER_PROTOCOL_F_CRYPTO_SESSION); VhostUserMsg msg = { .hdr.request = VHOST_USER_CLOSE_CRYPTO_SESSION, .hdr.flags = VHOST_USER_VERSION, @@ -2681,8 +2672,7 @@ 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_prot(dev, VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) { return 0; } @@ -2749,8 +2739,7 @@ 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_prot(dev, VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) { return 0; } @@ -2849,8 +2838,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_prot(dev, VHOST_USER_PROTOCOL_F_STATUS)) { return 0; } @@ -2875,16 +2863,14 @@ 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_prot(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_prot(dev, VHOST_USER_PROTOCOL_F_DEVICE_STATE); } static int vhost_user_set_device_state_fd(struct vhost_dev *dev, -- 2.48.1