Commit dde62137 authored by Dariusz Stojaczyk's avatar Dariusz Stojaczyk Committed by Jim Harris
Browse files

rte_vhost: added user callbacks for socket open/close



Added new callbacks to notify about socket connection status.
As destroy_device is used for virtqueue processing *pause* as well as
connection close, the user has no distinction between those.

Consider the following scenario:
rte_vhost: received SET_VRING_BASE message,
           calling destroy_device() as usual

user:  end-user asks to remove the device (together with socket file),
       OK, device is not *in use* - that's NOT the behavior we want
       calling rte_vhost_driver_unregister() etc.

Instead of changing new_device/destroy_device callbacks and breaking
the ABI, a set of new functions new_connection/destroy_connection
has been added.

Change-Id: I50a8ca4035045892d6c658da7df58c0c97025ec3
Signed-off-by: default avatarDariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/372074


Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarPawel Wodkowski <pawelx.wodkowski@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent 3e084a34
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -104,7 +104,10 @@ struct vhost_device_ops {
	 */
	int (*features_changed)(int vid, uint64_t features);

	void *reserved[4]; /**< Reserved for future extension */
	int (*new_connection)(int vid);
	void (*destroy_connection)(int vid);

	void *reserved[2]; /**< Reserved for future extension */
};

/**
+24 −6
Original line number Diff line number Diff line
@@ -222,9 +222,7 @@ vhost_user_add_connection(int fd, struct vhost_user_socket *vsocket)

	vid = vhost_new_device();
	if (vid == -1) {
		close(fd);
		free(conn);
		return;
		goto err;
	}

	size = strnlen(vsocket->path, PATH_MAX);
@@ -235,23 +233,40 @@ vhost_user_add_connection(int fd, struct vhost_user_socket *vsocket)

	RTE_LOG(INFO, VHOST_CONFIG, "new device, handle is %d\n", vid);

	if (vsocket->notify_ops->new_connection) {
		ret = vsocket->notify_ops->new_connection(vid);
		if (ret < 0) {
			RTE_LOG(ERR, VHOST_CONFIG,
				"failed to add vhost user connection with fd %d\n",
				fd);
			goto err;
		}
	}

	conn->connfd = fd;
	conn->vsocket = vsocket;
	conn->vid = vid;
	ret = fdset_add(&vhost_user.fdset, fd, vhost_user_read_cb,
			NULL, conn);
	if (ret < 0) {
		conn->connfd = -1;
		free(conn);
		close(fd);
		RTE_LOG(ERR, VHOST_CONFIG,
			"failed to add fd %d into vhost server fdset\n",
			fd);

		if (vsocket->notify_ops->destroy_connection)
			vsocket->notify_ops->destroy_connection(conn->vid);

		goto err;
	}

	pthread_mutex_lock(&vsocket->conn_mutex);
	TAILQ_INSERT_TAIL(&vsocket->conn_list, conn, next);
	pthread_mutex_unlock(&vsocket->conn_mutex);
	return;

err:
	free(conn);
	close(fd);
}

/* call back when there is new vhost-user connection from client  */
@@ -281,6 +296,9 @@ vhost_user_read_cb(int connfd, void *dat, int *remove)
		*remove = 1;
		vhost_destroy_device(conn->vid);

		if (vsocket->notify_ops->destroy_connection)
			vsocket->notify_ops->destroy_connection(conn->vid);

		pthread_mutex_lock(&vsocket->conn_mutex);
		TAILQ_REMOVE(&vsocket->conn_list, conn, next);
		pthread_mutex_unlock(&vsocket->conn_mutex);