Commit 9af84c02 authored by Marc-André Lureau's avatar Marc-André Lureau Committed by Michael S. Tsirkin
Browse files

vhost-user: split vhost_user_read()



Split vhost_user_read(), so only header can be read with
vhost_user_read_header().

Signed-off-by: default avatarMarc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: default avatarDaniel P. Berrangé <berrange@redhat.com>
Message-Id: <20190308140454.32437-8-marcandre.lureau@redhat.com>
Reviewed-by: default avatarMichael S. Tsirkin <mst@redhat.com>
Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
parent 917d7dd7
Loading
Loading
Loading
Loading
+19 −8
Original line number Diff line number Diff line
@@ -214,7 +214,7 @@ static bool ioeventfd_enabled(void)
    return !kvm_enabled() || kvm_eventfds_enabled();
}

static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)
static int vhost_user_read_header(struct vhost_dev *dev, VhostUserMsg *msg)
{
    struct vhost_user *u = dev->opaque;
    CharBackend *chr = u->user->chr;
@@ -225,7 +225,7 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)
    if (r != size) {
        error_report("Failed to read msg header. Read %d instead of %d."
                     " Original request %d.", r, size, msg->hdr.request);
        goto fail;
        return -1;
    }

    /* validate received flags */
@@ -233,7 +233,21 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)
        error_report("Failed to read msg header."
                " Flags 0x%x instead of 0x%x.", msg->hdr.flags,
                VHOST_USER_REPLY_MASK | VHOST_USER_VERSION);
        goto fail;
        return -1;
    }

    return 0;
}

static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)
{
    struct vhost_user *u = dev->opaque;
    CharBackend *chr = u->user->chr;
    uint8_t *p = (uint8_t *) msg;
    int r, size;

    if (vhost_user_read_header(dev, msg) < 0) {
        return -1;
    }

    /* validate message size is sane */
@@ -241,7 +255,7 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)
        error_report("Failed to read msg header."
                " Size %d exceeds the maximum %zu.", msg->hdr.size,
                VHOST_USER_PAYLOAD_SIZE);
        goto fail;
        return -1;
    }

    if (msg->hdr.size) {
@@ -251,14 +265,11 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)
        if (r != size) {
            error_report("Failed to read msg payload."
                         " Read %d instead of %d.", r, msg->hdr.size);
            goto fail;
            return -1;
        }
    }

    return 0;

fail:
    return -1;
}

static int process_message_reply(struct vhost_dev *dev,