vhost: distinguish master and slave requests

This patch adds an union in VhostUserMsg to distinguish between
master and slave initiated requests, instead of casting slave
requests as master request.

Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
Acked-by: Yuanhan Liu <yliu@fridaylinux.org>
This commit is contained in:
Maxime Coquelin 2017-10-10 14:47:54 +02:00 committed by Yuanhan Liu
parent efba12a78d
commit 3494ed045e
2 changed files with 11 additions and 8 deletions

View File

@ -1142,7 +1142,7 @@ vhost_user_check_and_alloc_queue_pair(struct virtio_net *dev, VhostUserMsg *msg)
{
uint16_t vring_idx;
switch (msg->request) {
switch (msg->request.master) {
case VHOST_USER_SET_VRING_KICK:
case VHOST_USER_SET_VRING_CALL:
case VHOST_USER_SET_VRING_ERR:
@ -1194,7 +1194,7 @@ vhost_user_msg_handler(int vid, int fd)
}
ret = read_vhost_message(fd, &msg);
if (ret <= 0 || msg.request >= VHOST_USER_MAX) {
if (ret <= 0 || msg.request.master >= VHOST_USER_MAX) {
if (ret < 0)
RTE_LOG(ERR, VHOST_CONFIG,
"vhost read message failed\n");
@ -1209,12 +1209,12 @@ vhost_user_msg_handler(int vid, int fd)
}
ret = 0;
if (msg.request != VHOST_USER_IOTLB_MSG)
if (msg.request.master != VHOST_USER_IOTLB_MSG)
RTE_LOG(INFO, VHOST_CONFIG, "read message %s\n",
vhost_message_str[msg.request]);
vhost_message_str[msg.request.master]);
else
RTE_LOG(DEBUG, VHOST_CONFIG, "read message %s\n",
vhost_message_str[msg.request]);
vhost_message_str[msg.request.master]);
ret = vhost_user_check_and_alloc_queue_pair(dev, &msg);
if (ret < 0) {
@ -1223,7 +1223,7 @@ vhost_user_msg_handler(int vid, int fd)
return -1;
}
switch (msg.request) {
switch (msg.request.master) {
case VHOST_USER_GET_FEATURES:
msg.payload.u64 = vhost_user_get_features(dev);
msg.size = sizeof(msg.payload.u64);
@ -1353,7 +1353,7 @@ vhost_user_iotlb_miss(struct virtio_net *dev, uint64_t iova, uint8_t perm)
{
int ret;
struct VhostUserMsg msg = {
.request = (enum VhostUserRequest)VHOST_USER_SLAVE_IOTLB_MSG,
.request.slave = VHOST_USER_SLAVE_IOTLB_MSG,
.flags = VHOST_USER_VERSION,
.size = sizeof(msg.payload.iotlb),
.payload.iotlb = {

View File

@ -109,7 +109,10 @@ typedef struct VhostUserLog {
} VhostUserLog;
typedef struct VhostUserMsg {
VhostUserRequest request;
union {
VhostUserRequest master;
VhostUserSlaveRequest slave;
} request;
#define VHOST_USER_VERSION_MASK 0x3
#define VHOST_USER_REPLY_MASK (0x1 << 2)