net/virtio-user: fix return value not checked
[dpdk.git] / drivers / net / virtio / virtio_user / vhost_user.c
index 2b34cac..a159ece 100644 (file)
@@ -235,11 +235,12 @@ static const char * const vhost_msg_strings[] = {
        [VHOST_USER_SET_VRING_ADDR] = "VHOST_USER_SET_VRING_ADDR",
        [VHOST_USER_SET_VRING_KICK] = "VHOST_USER_SET_VRING_KICK",
        [VHOST_USER_SET_MEM_TABLE] = "VHOST_USER_SET_MEM_TABLE",
+       [VHOST_USER_SET_VRING_ENABLE] = "VHOST_USER_SET_VRING_ENABLE",
        NULL,
 };
 
 int
-vhost_user_sock(int vhostfd, uint64_t req, void *arg)
+vhost_user_sock(int vhostfd, enum vhost_user_request req, void *arg)
 {
        struct vhost_user_msg msg;
        struct vhost_vring_file *file = 0;
@@ -287,6 +288,7 @@ vhost_user_sock(int vhostfd, uint64_t req, void *arg)
 
        case VHOST_USER_SET_VRING_NUM:
        case VHOST_USER_SET_VRING_BASE:
+       case VHOST_USER_SET_VRING_ENABLE:
                memcpy(&msg.payload.state, arg, sizeof(msg.payload.state));
                msg.size = sizeof(m.payload.state);
                break;
@@ -390,7 +392,8 @@ vhost_user_setup(const char *path)
        }
 
        flag = fcntl(fd, F_GETFD);
-       fcntl(fd, F_SETFD, flag | FD_CLOEXEC);
+       if (fcntl(fd, F_SETFD, flag | FD_CLOEXEC) < 0)
+               PMD_DRV_LOG(WARNING, "fcntl failed, %s", strerror(errno));
 
        memset(&un, 0, sizeof(un));
        un.sun_family = AF_UNIX;
@@ -403,3 +406,22 @@ vhost_user_setup(const char *path)
 
        return fd;
 }
+
+int
+vhost_user_enable_queue_pair(int vhostfd, uint16_t pair_idx, int enable)
+{
+       int i;
+
+       for (i = 0; i < 2; ++i) {
+               struct vhost_vring_state state = {
+                       .index = pair_idx * 2 + i,
+                       .num   = enable,
+               };
+
+               if (vhost_user_sock(vhostfd,
+                                   VHOST_USER_SET_VRING_ENABLE, &state))
+                       return -1;
+       }
+
+       return 0;
+}