static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)

{

    CharDriverState *chr = dev->opaque;

    uint8_t *p = (uint8_t *) msg;

    int r, size = VHOST_USER_HDR_SIZE;



    r = qemu_chr_fe_read_all(chr, p, size);

    if (r != size) {

        error_report("Failed to read msg header. Read %d instead of %d.", r,

                size);

        goto fail;

    }



    /* validate received flags */

    if (msg->flags != (VHOST_USER_REPLY_MASK | VHOST_USER_VERSION)) {

        error_report("Failed to read msg header."

                " Flags 0x%x instead of 0x%x.", msg->flags,

                VHOST_USER_REPLY_MASK | VHOST_USER_VERSION);

        goto fail;

    }



    /* validate message size is sane */

    if (msg->size > VHOST_USER_PAYLOAD_SIZE) {

        error_report("Failed to read msg header."

                " Size %d exceeds the maximum %zu.", msg->size,

                VHOST_USER_PAYLOAD_SIZE);

        goto fail;

    }



    if (msg->size) {

        p += VHOST_USER_HDR_SIZE;

        size = msg->size;

        r = qemu_chr_fe_read_all(chr, p, size);

        if (r != size) {

            error_report("Failed to read msg payload."

                         " Read %d instead of %d.", r, msg->size);

            goto fail;

        }

    }



    return 0;



fail:

    return -1;

}

static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)

{

    CharDriverState *chr = dev->opaque;

    uint8_t *p = (uint8_t *) msg;

    int r, size = VHOST_USER_HDR_SIZE;



    r = qemu_chr_fe_read_all(chr, p, size);

    if (r != size) {

        error_report("Failed to read msg header. Read %d instead of %d.", r,

                size);

        goto fail;

    }



    

    if (msg->flags != (VHOST_USER_REPLY_MASK | VHOST_USER_VERSION)) {

        error_report("Failed to read msg header."

                " Flags 0x%x instead of 0x%x.", msg->flags,

                VHOST_USER_REPLY_MASK | VHOST_USER_VERSION);

        goto fail;

    }



    

    if (msg->size > VHOST_USER_PAYLOAD_SIZE) {

        error_report("Failed to read msg header."

                " Size %d exceeds the maximum %zu.", msg->size,

                VHOST_USER_PAYLOAD_SIZE);

        goto fail;

    }



    if (msg->size) {

        p += VHOST_USER_HDR_SIZE;

        size = msg->size;

        r = qemu_chr_fe_read_all(chr, p, size);

        if (r != size) {

            error_report("Failed to read msg payload."

                         " Read %d instead of %d.", r, msg->size);

            goto fail;

        }

    }



    return 0;



fail:

    return -1;

}

        error_report("Failed to read msg header. Read %d instead of %d.", r,                 size);
static int FUNC_0(struct vhost_dev *VAR_0, VhostUserMsg *VAR_1)

{

    CharDriverState *chr = VAR_0->opaque;

    uint8_t *p = (uint8_t *) VAR_1;

    int VAR_2, VAR_3 = VHOST_USER_HDR_SIZE;



    VAR_2 = qemu_chr_fe_read_all(chr, p, VAR_3);

    if (VAR_2 != VAR_3) {

        error_report("Failed to read VAR_1 header. Read %d instead of %d.", VAR_2,

                VAR_3);

        goto fail;

    }



    

    if (VAR_1->flags != (VHOST_USER_REPLY_MASK | VHOST_USER_VERSION)) {

        error_report("Failed to read VAR_1 header."

                " Flags 0x%x instead of 0x%x.", VAR_1->flags,

                VHOST_USER_REPLY_MASK | VHOST_USER_VERSION);

        goto fail;

    }



    

    if (VAR_1->VAR_3 > VHOST_USER_PAYLOAD_SIZE) {

        error_report("Failed to read VAR_1 header."

                " Size %d exceeds the maximum %zu.", VAR_1->VAR_3,

                VHOST_USER_PAYLOAD_SIZE);

        goto fail;

    }



    if (VAR_1->VAR_3) {

        p += VHOST_USER_HDR_SIZE;

        VAR_3 = VAR_1->VAR_3;

        VAR_2 = qemu_chr_fe_read_all(chr, p, VAR_3);

        if (VAR_2 != VAR_3) {

            error_report("Failed to read VAR_1 payload."

                         " Read %d instead of %d.", VAR_2, VAR_1->VAR_3);

            goto fail;

        }

    }



    return 0;



fail:

    return -1;

}

static int FUNC_0(struct vhost_dev *VAR_0, VhostUserMsg *VAR_1)
{ CharDriverState *chr = VAR_0->opaque; uint8_t *p = (uint8_t *) VAR_1; int VAR_2, VAR_3 = VHOST_USER_HDR_SIZE; VAR_2 = qemu_chr_fe_read_all(chr, p, VAR_3); if (VAR_2 != VAR_3) { error_report("Failed to read VAR_1 header. Read %d instead of %d.", VAR_2,
VAR_3); goto fail; } if (VAR_1->flags != (VHOST_USER_REPLY_MASK | VHOST_USER_VERSION)) { error_report("Failed to read VAR_1 header."
" Flags 0x%x instead of 0x%x.", VAR_1->flags,
VHOST_USER_REPLY_MASK | VHOST_USER_VERSION); goto fail; } if (VAR_1->VAR_3 > VHOST_USER_PAYLOAD_SIZE) { error_report("Failed to read VAR_1 header."
" Size %d exceeds the maximum %zu.", VAR_1->VAR_3,
VHOST_USER_PAYLOAD_SIZE); goto fail; } if (VAR_1->VAR_3) { p += VHOST_USER_HDR_SIZE; VAR_3 = VAR_1->VAR_3; VAR_2 = qemu_chr_fe_read_all(chr, p, VAR_3); if (VAR_2 != VAR_3) { error_report("Failed to read VAR_1 payload."
" Read %d instead of %d.", VAR_2, VAR_1->VAR_3); goto fail; } } return 0; fail:
return -1; }