All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anthony Liguori <anthony@codemonkey.ws>
To: Paolo Bonzini <pbonzini@redhat.com>, qemu-devel@nongnu.org
Cc: owasserm@redhat.com, quintela@redhat.com
Subject: Re: [Qemu-devel] [PATCH 6/6] qemu-file: do not use stdio for qemu_fdopen
Date: Tue, 16 Apr 2013 16:09:41 -0500	[thread overview]
Message-ID: <87bo9e5giy.fsf@codemonkey.ws> (raw)
In-Reply-To: <1364402192-18169-7-git-send-email-pbonzini@redhat.com>

Paolo Bonzini <pbonzini@redhat.com> writes:

> This uses system calls directly for Unix file descriptors, so that the
> efficient writev_buffer can be used.  Pay attention to the possibility
> of partial writes in writev.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Needs rebasing:

  CC    i386-softmmu/savevm.o
/home/aliguori/git/qemu/savevm.c:439:5: error: initialization from incompatible pointer type [-Werror]
/home/aliguori/git/qemu/savevm.c:439:5: error: (near initialization for ‘unix_write_ops.writev_buffer’) [-Werror]
cc1: all warnings being treated as errors
make[1]: *** [savevm.o] Error 1
make: *** [subdir-i386-softmmu] Error 2
d13ed415c0ab9f7cf29226022f8c24d1b8dc794d is the first bad commit
commit d13ed415c0ab9f7cf29226022f8c24d1b8dc794d
Author: Paolo Bonzini <pbonzini@redhat.com>
Date:   Wed Mar 27 17:36:32 2013 +0100

    qemu-file: do not use stdio for qemu_fdopen

Regards,

Anthony Liguori

> ---
>  savevm.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------
>  1 file changed, 89 insertions(+), 11 deletions(-)
>
> diff --git a/savevm.c b/savevm.c
> index 0415830..8eb5aab 100644
> --- a/savevm.c
> +++ b/savevm.c
> @@ -356,9 +356,93 @@ static const QEMUFileOps stdio_file_write_ops = {
>      .close =      stdio_fclose
>  };
>  
> +static ssize_t unix_writev_buffer(void *opaque, struct iovec *iov, int iovcnt)
> +{
> +    QEMUFileSocket *s = opaque;
> +    ssize_t len, offset;
> +    ssize_t size = iov_size(iov, iovcnt);
> +    ssize_t total = 0;
> +
> +    assert(iovcnt > 0);
> +    offset = 0;
> +    while (size > 0) {
> +        /* Find the next start position; skip all full-sized vector elements  */
> +        while (offset >= iov[0].iov_len) {
> +            offset -= iov[0].iov_len;
> +            iov++, iovcnt--;
> +        }
> +
> +        /* skip `offset' bytes from the (now) first element, undo it on exit */
> +        assert(iovcnt > 0);
> +        iov[0].iov_base += offset;
> +        iov[0].iov_len -= offset;
> +
> +        do {
> +            len = writev(s->fd, iov, iovcnt);
> +        } while (len == -1 && errno == EINTR);
> +        if (len == -1) {
> +            return -errno;
> +        }
> +
> +        /* Undo the changes above */
> +        iov[0].iov_base -= offset;
> +        iov[0].iov_len += offset;
> +
> +        /* Prepare for the next iteration */
> +        offset += len;
> +        total += len;
> +        size -= len;
> +    }
> +
> +    return total;
> +}
> +
> +static int unix_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size)
> +{
> +    QEMUFileSocket *s = opaque;
> +    ssize_t len;
> +
> +    for (;;) {
> +        len = read(s->fd, buf, size);
> +        if (len != -1) {
> +            break;
> +        }
> +        if (errno == EAGAIN) {
> +            yield_until_fd_readable(s->fd);
> +        } else if (errno != EINTR) {
> +            break;
> +        }
> +    }
> +
> +    if (len == -1) {
> +        len = -errno;
> +    }
> +    return len;
> +}
> +
> +static int unix_close(void *opaque)
> +{
> +    QEMUFileSocket *s = opaque;
> +    close(s->fd);
> +    g_free(s);
> +    return 0;
> +}
> +
> +static const QEMUFileOps unix_read_ops = {
> +    .get_fd =     socket_get_fd,
> +    .get_buffer = unix_get_buffer,
> +    .close =      unix_close
> +};
> +
> +static const QEMUFileOps unix_write_ops = {
> +    .get_fd =     socket_get_fd,
> +    .writev_buffer = unix_writev_buffer,
> +    .close =      unix_close
> +};
> +
>  QEMUFile *qemu_fdopen(int fd, const char *mode)
>  {
> -    QEMUFileStdio *s;
> +    QEMUFileSocket *s;
>  
>      if (mode == NULL ||
>  	(mode[0] != 'r' && mode[0] != 'w') ||
> @@ -367,21 +451,15 @@ QEMUFile *qemu_fdopen(int fd, const char *mode)
>          return NULL;
>      }
>  
> -    s = g_malloc0(sizeof(QEMUFileStdio));
> -    s->stdio_file = fdopen(fd, mode);
> -    if (!s->stdio_file)
> -        goto fail;
> +    s = g_malloc0(sizeof(QEMUFileSocket));
> +    s->fd = fd;
>  
>      if(mode[0] == 'r') {
> -        s->file = qemu_fopen_ops(s, &stdio_file_read_ops);
> +        s->file = qemu_fopen_ops(s, &unix_read_ops);
>      } else {
> -        s->file = qemu_fopen_ops(s, &stdio_file_write_ops);
> +        s->file = qemu_fopen_ops(s, &unix_write_ops);
>      }
>      return s->file;
> -
> -fail:
> -    g_free(s);
> -    return NULL;
>  }
>  
>  static const QEMUFileOps socket_read_ops = {
> -- 
> 1.8.1.4

  parent reply	other threads:[~2013-04-16 21:09 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-27 16:36 [Qemu-devel] [PATCH 0/6] migration: followups for writev patches Paolo Bonzini
2013-03-27 16:36 ` [Qemu-devel] [PATCH 1/6] qemu-file: drop socket_put_buffer Paolo Bonzini
2013-04-09 13:20   ` Juan Quintela
2013-03-27 16:36 ` [Qemu-devel] [PATCH 2/6] iov: reorganize iov_send_recv, part 1 Paolo Bonzini
2013-04-09 13:18   ` Juan Quintela
2013-03-27 16:36 ` [Qemu-devel] [PATCH 3/6] iov: reorganize iov_send_recv, part 2 Paolo Bonzini
2013-04-09 13:23   ` Juan Quintela
2013-03-27 16:36 ` [Qemu-devel] [PATCH 4/6] iov: reorganize iov_send_recv, part 3 Paolo Bonzini
2013-04-09 13:24   ` Juan Quintela
2013-03-27 16:36 ` [Qemu-devel] [PATCH 5/6] iov: handle partial writes from sendmsg and recvmsg Paolo Bonzini
2013-04-09 13:27   ` Juan Quintela
2013-03-27 16:36 ` [Qemu-devel] [PATCH 6/6] qemu-file: do not use stdio for qemu_fdopen Paolo Bonzini
2013-04-09 13:30   ` Juan Quintela
2013-04-16 21:09   ` Anthony Liguori [this message]
2013-04-03  8:08 ` [Qemu-devel] [PATCH 0/6] migration: followups for writev patches Orit Wasserman
2013-04-16 15:41   ` Anthony Liguori
  -- strict thread matches above, loose matches on Subject: below --
2013-04-17  9:46 [Qemu-devel] [PULL (rebased) " Paolo Bonzini
2013-04-17  9:46 ` [Qemu-devel] [PATCH 6/6] qemu-file: do not use stdio for qemu_fdopen Paolo Bonzini
2013-04-20 18:53   ` Blue Swirl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87bo9e5giy.fsf@codemonkey.ws \
    --to=anthony@codemonkey.ws \
    --cc=owasserm@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.