Commit a202a4c0 authored by Dr. David Alan Gilbert's avatar Dr. David Alan Gilbert Committed by Amit Shah
Browse files

migration: size_t'ify some of qemu-file



This is a start on using size_t more in qemu-file and friends;
it fixes up QEMUFilePutBufferFunc and QEMUFileGetBufferFunc
to take size_t lengths and return ssize_t return values (like read(2))
and fixes up all the different implementations of them.

Note that I've not yet followed this deeply into bdrv_ implementations.

Signed-off-by: default avatarDr. David Alan Gilbert <dgilbert@redhat.com>
Message-Id: <1439463094-5394-5-git-send-email-dgilbert@redhat.com>
Reviewed-by: default avatarzhanghailiang <zhang.zhanghailiang@huawei.com>
Reviewed-by: default avatarAmit Shah <amit.shah@redhat.com>
Signed-off-by: default avatarAmit Shah <amit.shah@redhat.com>
parent c50766f5
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -31,15 +31,15 @@
 * The pos argument can be ignored if the file is only being used for
 * streaming.  The handler should try to write all of the data it can.
 */
typedef int (QEMUFilePutBufferFunc)(void *opaque, const uint8_t *buf,
                                    int64_t pos, int size);
typedef ssize_t (QEMUFilePutBufferFunc)(void *opaque, const uint8_t *buf,
                                        int64_t pos, size_t size);

/* Read a chunk of data from a file at the given position.  The pos argument
 * can be ignored if the file is only be used for streaming.  The number of
 * bytes actually read should be returned.
 */
typedef int (QEMUFileGetBufferFunc)(void *opaque, uint8_t *buf,
                                    int64_t pos, int size);
typedef ssize_t (QEMUFileGetBufferFunc)(void *opaque, uint8_t *buf,
                                        int64_t pos, size_t size);

/* Close a file
 *
+4 −3
Original line number Diff line number Diff line
@@ -372,7 +372,8 @@ typedef struct QEMUBuffer {
    bool qsb_allocated;
} QEMUBuffer;

static int buf_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size)
static ssize_t buf_get_buffer(void *opaque, uint8_t *buf, int64_t pos,
                              size_t size)
{
    QEMUBuffer *s = opaque;
    ssize_t len = qsb_get_length(s->qsb) - pos;
@@ -387,8 +388,8 @@ static int buf_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size)
    return qsb_get_buffer(s->qsb, pos, len, buf);
}

static int buf_put_buffer(void *opaque, const uint8_t *buf,
                          int64_t pos, int size)
static ssize_t buf_put_buffer(void *opaque, const uint8_t *buf,
                              int64_t pos, size_t size)
{
    QEMUBuffer *s = opaque;

+6 −5
Original line number Diff line number Diff line
@@ -37,11 +37,11 @@ static int stdio_get_fd(void *opaque)
    return fileno(s->stdio_file);
}

static int stdio_put_buffer(void *opaque, const uint8_t *buf, int64_t pos,
                            int size)
static ssize_t stdio_put_buffer(void *opaque, const uint8_t *buf, int64_t pos,
                                size_t size)
{
    QEMUFileStdio *s = opaque;
    int res;
    size_t res;

    res = fwrite(buf, 1, size, s->stdio_file);

@@ -51,11 +51,12 @@ static int stdio_put_buffer(void *opaque, const uint8_t *buf, int64_t pos,
    return res;
}

static int stdio_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size)
static ssize_t stdio_get_buffer(void *opaque, uint8_t *buf, int64_t pos,
                                size_t size)
{
    QEMUFileStdio *s = opaque;
    FILE *fp = s->stdio_file;
    int bytes;
    ssize_t bytes;

    for (;;) {
        clearerr(fp);
+4 −2
Original line number Diff line number Diff line
@@ -54,7 +54,8 @@ static int socket_get_fd(void *opaque)
    return s->fd;
}

static int socket_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size)
static ssize_t socket_get_buffer(void *opaque, uint8_t *buf, int64_t pos,
                                 size_t size)
{
    QEMUFileSocket *s = opaque;
    ssize_t len;
@@ -138,7 +139,8 @@ static ssize_t unix_writev_buffer(void *opaque, struct iovec *iov, int iovcnt,
    return total;
}

static int unix_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size)
static ssize_t unix_get_buffer(void *opaque, uint8_t *buf, int64_t pos,
                              size_t size)
{
    QEMUFileSocket *s = opaque;
    ssize_t len;
+7 −6
Original line number Diff line number Diff line
@@ -2519,8 +2519,8 @@ static void *qemu_rdma_data_init(const char *host_port, Error **errp)
 * SEND messages for control only.
 * VM's ram is handled with regular RDMA messages.
 */
static int qemu_rdma_put_buffer(void *opaque, const uint8_t *buf,
                                int64_t pos, int size)
static ssize_t qemu_rdma_put_buffer(void *opaque, const uint8_t *buf,
                                    int64_t pos, size_t size)
{
    QEMUFileRDMA *r = opaque;
    QEMUFile *f = r->file;
@@ -2547,7 +2547,8 @@ static int qemu_rdma_put_buffer(void *opaque, const uint8_t *buf,
        r->len = MIN(remaining, RDMA_SEND_INCREMENT);
        remaining -= r->len;

        head.len = r->len;
        /* Guaranteed to fit due to RDMA_SEND_INCREMENT MIN above */
        head.len = (uint32_t)r->len;
        head.type = RDMA_CONTROL_QEMU_FILE;

        ret = qemu_rdma_exchange_send(rdma, &head, data, NULL, NULL, NULL);
@@ -2564,7 +2565,7 @@ static int qemu_rdma_put_buffer(void *opaque, const uint8_t *buf,
}

static size_t qemu_rdma_fill(RDMAContext *rdma, uint8_t *buf,
                             int size, int idx)
                             size_t size, int idx)
{
    size_t len = 0;

@@ -2585,8 +2586,8 @@ static size_t qemu_rdma_fill(RDMAContext *rdma, uint8_t *buf,
 * RDMA links don't use bytestreams, so we have to
 * return bytes to QEMUFile opportunistically.
 */
static int qemu_rdma_get_buffer(void *opaque, uint8_t *buf,
                                int64_t pos, int size)
static ssize_t qemu_rdma_get_buffer(void *opaque, uint8_t *buf,
                                    int64_t pos, size_t size)
{
    QEMUFileRDMA *r = opaque;
    RDMAContext *rdma = r->rdma;
Loading