Commit 30998f9b authored by Vitaliy Mysak's avatar Vitaliy Mysak Committed by Tomasz Zawadzki
Browse files

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: default avatarVitaliy Mysak <vitaliy.mysak@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/471712


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
parent 0e96d724
Loading
Loading
Loading
Loading
+17 −9
Original line number Diff line number Diff line
@@ -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
+2 −2
Original line number Diff line number Diff line
@@ -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)