vhost/compat: implement SET/GET_CONFIG

rte_vhost has rejected a patch with this feature, so
we implement it using the external rte_vhost msg handling
hooks directly in SPDK.

Change-Id: Ib072fc19b921fe0fa01c7f4892e60430232e3a1c
Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/447025
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Darek Stojaczyk 2019-03-04 22:34:44 +01:00 committed by Jim Harris
parent aa5f129f57
commit b9b1c9592e
4 changed files with 50 additions and 0 deletions

View File

@ -110,6 +110,35 @@ spdk_extern_vhost_pre_msg_handler(int vid, void *_msg)
vsession->needs_restart = true;
}
break;
case VHOST_USER_GET_CONFIG: {
struct vhost_user_config *cfg = &msg->payload.cfg;
int rc = 0;
spdk_vhost_lock();
if (vsession->vdev->backend->vhost_get_config) {
rc = vsession->vdev->backend->vhost_get_config(vsession->vdev,
cfg->region, cfg->size);
if (rc != 0) {
msg->size = 0;
}
}
spdk_vhost_unlock();
return RTE_VHOST_MSG_RESULT_REPLY;
}
case VHOST_USER_SET_CONFIG: {
struct vhost_user_config *cfg = &msg->payload.cfg;
int rc = 0;
spdk_vhost_lock();
if (vsession->vdev->backend->vhost_set_config) {
rc = vsession->vdev->backend->vhost_set_config(vsession->vdev,
cfg->region, cfg->offset, cfg->size, cfg->flags);
}
spdk_vhost_unlock();
return rc == 0 ? RTE_VHOST_MSG_RESULT_OK : RTE_VHOST_MSG_RESULT_ERR;
}
default:
break;
}
@ -187,10 +216,26 @@ spdk_vhost_session_install_rte_compat_hooks(struct spdk_vhost_session *vsession)
}
}
void
spdk_vhost_dev_install_rte_compat_hooks(struct spdk_vhost_dev *vdev)
{
uint64_t protocol_features = 0;
rte_vhost_driver_get_protocol_features(vdev->path, &protocol_features);
protocol_features |= (1ULL << VHOST_USER_PROTOCOL_F_CONFIG);
rte_vhost_driver_set_protocol_features(vdev->path, protocol_features);
}
#else /* SPDK_CONFIG_VHOST_INTERNAL_LIB */
void
spdk_vhost_session_install_rte_compat_hooks(struct spdk_vhost_session *vsession)
{
/* nothing to do. all the changes are already incorporated into rte_vhost */
}
void
spdk_vhost_dev_install_rte_compat_hooks(struct spdk_vhost_dev *vdev)
{
/* nothing to do */
}
#endif

View File

@ -763,6 +763,8 @@ spdk_vhost_dev_register(struct spdk_vhost_dev *vdev, const char *name, const cha
spdk_vhost_set_coalescing(vdev, SPDK_VHOST_COALESCING_DELAY_BASE_US,
SPDK_VHOST_VQ_IOPS_COALESCING_THRESHOLD);
spdk_vhost_dev_install_rte_compat_hooks(vdev);
/* The following might start a POSIX thread that polls for incoming
* socket connections and calls backend->start/stop_device. These backend
* callbacks are also protected by the global SPDK vhost mutex, so we're

View File

@ -350,6 +350,7 @@ void spdk_vhost_session_event_done(void *event_ctx, int response);
struct spdk_vhost_session *spdk_vhost_session_find_by_vid(int vid);
void spdk_vhost_session_install_rte_compat_hooks(struct spdk_vhost_session *vsession);
void spdk_vhost_dev_install_rte_compat_hooks(struct spdk_vhost_dev *vdev);
void spdk_vhost_free_reactor(uint32_t lcore);
uint32_t spdk_vhost_allocate_reactor(struct spdk_cpuset *cpumask);

View File

@ -48,6 +48,8 @@ DEFINE_STUB(rte_vhost_get_vring_base, int, (int vid, uint16_t queue_id,
uint16_t *last_avail_idx, uint16_t *last_used_idx), 0);
DEFINE_STUB_V(spdk_vhost_session_install_rte_compat_hooks,
(struct spdk_vhost_session *vsession));
DEFINE_STUB_V(spdk_vhost_dev_install_rte_compat_hooks,
(struct spdk_vhost_dev *vdev));
DEFINE_STUB(rte_vhost_driver_unregister, int, (const char *path), 0);
DEFINE_STUB(spdk_event_allocate, struct spdk_event *,
(uint32_t lcore, spdk_event_fn fn, void *arg1, void *arg2), NULL);