vhost: return error codes for all session callbacks

Change type of `vhost_stop_device_cb()` and `vhost_destroy_connection_cb()`
to return response code instead of "void".

While DPDK callbacks `stop_device()` and `destroy_connection()`
do not have response code, it does make sense to have them in
our VHOST wrappers because those actions can fail.

Practical benefit we get by adopting this change is that we can
now use high level `vhost_stop_device_cb()` and `vhost_destroy_connection_cb()`
in unittests and check if they succeeded or not.

Change-Id: I2cd1886728b1edce7946e87db7ca0ac435e83a41
Signed-off-by: Vitaliy Mysak <vitaliy.mysak@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/471712
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>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
Vitaliy Mysak 2019-10-14 12:01:41 +02:00 committed by Tomasz Zawadzki
parent 0e96d724d8
commit 30998f9b1f
2 changed files with 19 additions and 11 deletions

View File

@ -1032,7 +1032,7 @@ vhost_dev_foreach_session(struct spdk_vhost_dev *vdev,
foreach_session_continue(ev_ctx, vsession);
}
static void
static int
_stop_session(struct spdk_vhost_session *vsession)
{
struct spdk_vhost_dev *vdev = vsession->vdev;
@ -1044,7 +1044,7 @@ _stop_session(struct spdk_vhost_session *vsession)
if (rc != 0) {
SPDK_ERRLOG("Couldn't stop device with vid %d.\n", vsession->vid);
pthread_mutex_unlock(&g_vhost_mutex);
return;
return rc;
}
for (i = 0; i < vsession->max_queues; i++) {
@ -1057,29 +1057,34 @@ _stop_session(struct spdk_vhost_session *vsession)
vhost_session_mem_unregister(vsession);
free(vsession->mem);
return 0;
}
void
int
vhost_stop_device_cb(int vid)
{
struct spdk_vhost_session *vsession;
int rc;
pthread_mutex_lock(&g_vhost_mutex);
vsession = vhost_session_find_by_vid(vid);
if (vsession == NULL) {
SPDK_ERRLOG("Couldn't find session with vid %d.\n", vid);
pthread_mutex_unlock(&g_vhost_mutex);
return;
return -EINVAL;
}
if (!vsession->started) {
/* already stopped, nothing to do */
pthread_mutex_unlock(&g_vhost_mutex);
return;
return -EALREADY;
}
_stop_session(vsession);
rc = _stop_session(vsession);
pthread_mutex_unlock(&g_vhost_mutex);
return rc;
}
int
@ -1319,27 +1324,30 @@ vhost_new_connection_cb(int vid, const char *ifname)
return 0;
}
void
int
vhost_destroy_connection_cb(int vid)
{
struct spdk_vhost_session *vsession;
int rc = 0;
pthread_mutex_lock(&g_vhost_mutex);
vsession = vhost_session_find_by_vid(vid);
if (vsession == NULL) {
SPDK_ERRLOG("Couldn't find session with vid %d.\n", vid);
pthread_mutex_unlock(&g_vhost_mutex);
return;
return -EINVAL;
}
if (vsession->started) {
_stop_session(vsession);
rc = _stop_session(vsession);
}
TAILQ_REMOVE(&vsession->vdev->vsessions, vsession, tailq);
free(vsession->name);
free(vsession);
pthread_mutex_unlock(&g_vhost_mutex);
return rc;
}
void

View File

@ -321,8 +321,8 @@ void vhost_dump_info_json(struct spdk_vhost_dev *vdev, struct spdk_json_write_ct
int vhost_new_connection_cb(int vid, const char *ifname);
int vhost_start_device_cb(int vid);
void vhost_stop_device_cb(int vid);
void vhost_destroy_connection_cb(int vid);
int vhost_stop_device_cb(int vid);
int vhost_destroy_connection_cb(int vid);
#ifdef SPDK_CONFIG_VHOST_INTERNAL_LIB
int vhost_get_config_cb(int vid, uint8_t *config, uint32_t len)