From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:44954) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1USD8N-0001E7-89 for qemu-devel@nongnu.org; Tue, 16 Apr 2013 17:09:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1USD8L-00030d-UY for qemu-devel@nongnu.org; Tue, 16 Apr 2013 17:09:47 -0400 Received: from mail-qe0-f42.google.com ([209.85.128.42]:61003) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1USD8L-00030F-Q9 for qemu-devel@nongnu.org; Tue, 16 Apr 2013 17:09:45 -0400 Received: by mail-qe0-f42.google.com with SMTP id cz11so552152qeb.15 for ; Tue, 16 Apr 2013 14:09:45 -0700 (PDT) From: Anthony Liguori In-Reply-To: <1364402192-18169-7-git-send-email-pbonzini@redhat.com> References: <1364402192-18169-1-git-send-email-pbonzini@redhat.com> <1364402192-18169-7-git-send-email-pbonzini@redhat.com> Date: Tue, 16 Apr 2013 16:09:41 -0500 Message-ID: <87bo9e5giy.fsf@codemonkey.ws> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 6/6] qemu-file: do not use stdio for qemu_fdopen List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini , qemu-devel@nongnu.org Cc: owasserm@redhat.com, quintela@redhat.com Paolo Bonzini 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 Needs rebasing: CC i386-softmmu/savevm.o /home/aliguori/git/qemu/savevm.c:439:5: error: initialization from incompat= ible pointer type [-Werror] /home/aliguori/git/qemu/savevm.c:439:5: error: (near initialization for =E2= =80=98unix_write_ops.writev_buffer=E2=80=99) [-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 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 =3D { > .close =3D stdio_fclose > }; >=20=20 > +static ssize_t unix_writev_buffer(void *opaque, struct iovec *iov, int i= ovcnt) > +{ > + QEMUFileSocket *s =3D opaque; > + ssize_t len, offset; > + ssize_t size =3D iov_size(iov, iovcnt); > + ssize_t total =3D 0; > + > + assert(iovcnt > 0); > + offset =3D 0; > + while (size > 0) { > + /* Find the next start position; skip all full-sized vector elem= ents */ > + while (offset >=3D iov[0].iov_len) { > + offset -=3D 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 +=3D offset; > + iov[0].iov_len -=3D offset; > + > + do { > + len =3D writev(s->fd, iov, iovcnt); > + } while (len =3D=3D -1 && errno =3D=3D EINTR); > + if (len =3D=3D -1) { > + return -errno; > + } > + > + /* Undo the changes above */ > + iov[0].iov_base -=3D offset; > + iov[0].iov_len +=3D offset; > + > + /* Prepare for the next iteration */ > + offset +=3D len; > + total +=3D len; > + size -=3D len; > + } > + > + return total; > +} > + > +static int unix_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int = size) > +{ > + QEMUFileSocket *s =3D opaque; > + ssize_t len; > + > + for (;;) { > + len =3D read(s->fd, buf, size); > + if (len !=3D -1) { > + break; > + } > + if (errno =3D=3D EAGAIN) { > + yield_until_fd_readable(s->fd); > + } else if (errno !=3D EINTR) { > + break; > + } > + } > + > + if (len =3D=3D -1) { > + len =3D -errno; > + } > + return len; > +} > + > +static int unix_close(void *opaque) > +{ > + QEMUFileSocket *s =3D opaque; > + close(s->fd); > + g_free(s); > + return 0; > +} > + > +static const QEMUFileOps unix_read_ops =3D { > + .get_fd =3D socket_get_fd, > + .get_buffer =3D unix_get_buffer, > + .close =3D unix_close > +}; > + > +static const QEMUFileOps unix_write_ops =3D { > + .get_fd =3D socket_get_fd, > + .writev_buffer =3D unix_writev_buffer, > + .close =3D unix_close > +}; > + > QEMUFile *qemu_fdopen(int fd, const char *mode) > { > - QEMUFileStdio *s; > + QEMUFileSocket *s; >=20=20 > if (mode =3D=3D NULL || > (mode[0] !=3D 'r' && mode[0] !=3D 'w') || > @@ -367,21 +451,15 @@ QEMUFile *qemu_fdopen(int fd, const char *mode) > return NULL; > } >=20=20 > - s =3D g_malloc0(sizeof(QEMUFileStdio)); > - s->stdio_file =3D fdopen(fd, mode); > - if (!s->stdio_file) > - goto fail; > + s =3D g_malloc0(sizeof(QEMUFileSocket)); > + s->fd =3D fd; >=20=20 > if(mode[0] =3D=3D 'r') { > - s->file =3D qemu_fopen_ops(s, &stdio_file_read_ops); > + s->file =3D qemu_fopen_ops(s, &unix_read_ops); > } else { > - s->file =3D qemu_fopen_ops(s, &stdio_file_write_ops); > + s->file =3D qemu_fopen_ops(s, &unix_write_ops); > } > return s->file; > - > -fail: > - g_free(s); > - return NULL; > } >=20=20 > static const QEMUFileOps socket_read_ops =3D { > --=20 > 1.8.1.4