概述
使用ovs+dpdk模式的kvm虚机,在ovs上会创建一个vhostuser类型的口,vhostuser通过unix socket方式与qemu建立前后端通信机制,其中vhostuser分为server类型和clinet类型,当vhostuser为clinet时,vhotuser主动跟qemu建立连接,因此当ovs重启的时候,可保证虚机自动重连。本文主要描述dpdk侧vhostuser与qemu之间unix socket连接建立过程。
rte_vhost_driver_register
当ovs添加一个vhostuser口时,会进入该register流程,在register流程里,首先根据传递下来的unxi socket文件路径创建socket信息,然后保存到unix socket本地数据里;
int
rte_vhost_driver_register(const char *path, uint64_t flags)
{
int ret = -1;
struct vhost_user_socket *vsocket;
if (!path)
return -1;
pthread_mutex_lock(&vhost_user.mutex);
if (vhost_user.vsocket_cnt == MAX_VHOST_SOCKET) {
RTE_LOG(ERR, VHOST_CONFIG,
"error: the number of vhost sockets reaches maximum\n");
goto out;
}
vsocket = malloc(sizeof(struct vhost_user_socket));
if (!vsocket)
goto out;
memset(vsocket, 0, sizeof(struct vhost_user_socket));
//对vsocket的path信息赋值
vsocket->path = strdup(path);
if (vsocket->path == NULL) {
RTE_LOG(ERR, VHOST_CONFIG,
"error: failed to copy socket path string\n");
vhost_user_socket_mem_free(vsocket);
goto out;
}
TAILQ_INIT(&vsocket->conn_list);
ret = pthread_mutex_init(&vsocket->conn_mutex, NULL);
if (ret) {
RTE_LOG(ERR, VHOST_CONFIG,
"error: failed to init connection mutex\n");
goto out_free;
}
vsocket->dequeue_zero_copy = flags & RTE_VHOST_USER_DEQUEUE_ZERO_COPY;
/*
* Set the supported features correctly for the builtin vhost-user
* net driver.
*
* Applications know nothing about features the builtin virtio net
* driver (virtio_net.c) supports, thus it's not possible for them
* to invoke rte_vhost_driver_set_features(). To workaround it, here
* we set it unconditionally. If the application want to implement
* another vhost-user driver (say SCSI), it should call the
* rte_vhost_driver_set_features(), which will overwrite following
* two values.
*/
vsocket->use_builtin_virtio_net = true;
vsocket->supported_features = VIRTIO_NET_SUPPORTED_FEATURES;
vsocket->features = VIRTIO_NET_SUPPORTED_FEATURES;
vsocket->protocol_features = VHOST_USER_PROTOCOL_FEATURES;
/*
* Dequeue zero copy can't assure descriptors returned in order.
* Also, it requires that the guest memory is populated, which is
* not compatible with

本文详细解析了DPDK环境下,使用vhostuser接口与KVM虚拟机(qemu)通过unixsocket进行通信的机制。在ovs启动时,会创建vhostuser类型的接口,并注册到vhost驱动,创建相应的unixsocket。当vhostuser作为客户端时,会尝试与qemu建立连接,若连接失败则启动重连线程。一旦连接建立,vhost-user接口会通过vhost_event线程监听socket的读写事件,进行数据交换。
2699

被折叠的 条评论
为什么被折叠?



