return bytes# of read on success or negative val on failure. */
| 2875 | |
| 2876 | /* return bytes# of read on success or negative val on failure. */ |
| 2877 | static int |
| 2878 | read_vhost_message(struct virtio_net *dev, int sockfd, struct vhu_msg_context *ctx) |
| 2879 | { |
| 2880 | int ret; |
| 2881 | |
| 2882 | ret = read_fd_message(dev->ifname, sockfd, (char *)&ctx->msg, VHOST_USER_HDR_SIZE, |
| 2883 | ctx->fds, VHOST_MEMORY_MAX_NREGIONS, &ctx->fd_num); |
| 2884 | if (ret <= 0) |
| 2885 | goto out; |
| 2886 | |
| 2887 | if (ret != VHOST_USER_HDR_SIZE) { |
| 2888 | VHOST_LOG_CONFIG(dev->ifname, ERR, "Unexpected header size read\n"); |
| 2889 | ret = -1; |
| 2890 | goto out; |
| 2891 | } |
| 2892 | |
| 2893 | if (ctx->msg.size) { |
| 2894 | if (ctx->msg.size > sizeof(ctx->msg.payload)) { |
| 2895 | VHOST_LOG_CONFIG(dev->ifname, ERR, "invalid msg size: %d\n", |
| 2896 | ctx->msg.size); |
| 2897 | ret = -1; |
| 2898 | goto out; |
| 2899 | } |
| 2900 | ret = read(sockfd, &ctx->msg.payload, ctx->msg.size); |
| 2901 | if (ret <= 0) |
| 2902 | goto out; |
| 2903 | if (ret != (int)ctx->msg.size) { |
| 2904 | VHOST_LOG_CONFIG(dev->ifname, ERR, "read control message failed\n"); |
| 2905 | ret = -1; |
| 2906 | goto out; |
| 2907 | } |
| 2908 | } |
| 2909 | |
| 2910 | out: |
| 2911 | if (ret <= 0) |
| 2912 | close_msg_fds(ctx); |
| 2913 | |
| 2914 | return ret; |
| 2915 | } |
| 2916 | |
| 2917 | static int |
| 2918 | send_vhost_message(struct virtio_net *dev, int sockfd, struct vhu_msg_context *ctx) |
no test coverage detected