Message ID | 599c6eb3f07b3ef16f29ad8fda005ddecc038566.1602784930.git.jag.raman@oracle.com |
---|---|
State | New |
Headers | show |
Series | Initial support for multi-process Qemu | expand |
On 10/15/20 8:04 PM, Jagannathan Raman wrote: > From: Elena Ufimtseva <elena.ufimtseva@oracle.com> > > The entire array of the memory regions and file handlers. I don't understand the description... Did you forgot the verb? > Will be used in the next patch. > > Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com> > Signed-off-by: John G Johnson <john.g.johnson@oracle.com> > Signed-off-by: Jagannathan Raman <jag.raman@oracle.com> > Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> > --- > include/io/channel.h | 24 ++++++++++++++++++++++++ > io/channel.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 69 insertions(+)
On Thu, Oct 15, 2020 at 10:05 PM Jagannathan Raman <jag.raman@oracle.com> wrote: > From: Elena Ufimtseva <elena.ufimtseva@oracle.com> > > The entire array of the memory regions and file handlers. > Will be used in the next patch. > > Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com> > Signed-off-by: John G Johnson <john.g.johnson@oracle.com> > Signed-off-by: Jagannathan Raman <jag.raman@oracle.com> > Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> > --- > include/io/channel.h | 24 ++++++++++++++++++++++++ > io/channel.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 69 insertions(+) > > diff --git a/include/io/channel.h b/include/io/channel.h > index 3c04f0e..6807506 100644 > --- a/include/io/channel.h > +++ b/include/io/channel.h > @@ -773,5 +773,29 @@ void qio_channel_set_aio_fd_handler(QIOChannel *ioc, > IOHandler *io_read, > IOHandler *io_write, > void *opaque); > +/** > + * qio_channel_writev_full_all: > + * @ioc: the channel object > + * @iov: the array of memory regions to write data from > + * @niov: the length of the @iov array > + * @fds: an array of file handles to send > + * @nfds: number of file handles in @fds > + * @errp: pointer to a NULL-initialized error object > + * > + * > + * Behaves like qio_channel_writev_full but will attempt > + * to send all data passed (file handles and memory regions). > + * The function will wait for all requested data > + * to be written, yielding from the current coroutine > + * if required. > + * > + * Returns: 0 if all bytes were written, or -1 on error > + */ > + > +int qio_channel_writev_full_all(QIOChannel *ioc, > + const struct iovec *iov, > + size_t niov, > + int *fds, size_t nfds, > + Error **errp); > > #endif /* QIO_CHANNEL_H */ > diff --git a/io/channel.c b/io/channel.c > index e4376eb..22c10c5 100644 > --- a/io/channel.c > +++ b/io/channel.c > @@ -190,6 +190,51 @@ int qio_channel_writev_all(QIOChannel *ioc, > return ret; > } > > +int qio_channel_writev_full_all(QIOChannel *ioc, > + const struct iovec *iov, > + size_t niov, > + int *fds, size_t nfds, > + Error **errp) > +{ > Please make qio_channel_writev_all() call qio_channel_writev_full_all() to avoid logic duplication. thanks + int ret = -1; > + struct iovec *local_iov = g_new(struct iovec, niov); > + struct iovec *local_iov_head = local_iov; > + unsigned int nlocal_iov = niov; > + > + nlocal_iov = iov_copy(local_iov, nlocal_iov, > + iov, niov, > + 0, iov_size(iov, niov)); > + > + while (nlocal_iov > 0) { > + ssize_t len; > + len = qio_channel_writev_full(ioc, local_iov, nlocal_iov, fds, > + nfds, errp); > + if (len == QIO_CHANNEL_ERR_BLOCK) { > + if (qemu_in_coroutine()) { > + qio_channel_yield(ioc, G_IO_OUT); > + } else { > + qio_channel_wait(ioc, G_IO_OUT); > + } > + continue; > + } > + if (len < 0) { > + goto cleanup; > + } > + > + iov_discard_front(&local_iov, &nlocal_iov, len); > + > + if (len > 0) { > + fds = NULL; > + nfds = 0; > + } > + } > + > + ret = 0; > + cleanup: > + g_free(local_iov_head); > + return ret; > +} > + > ssize_t qio_channel_readv(QIOChannel *ioc, > const struct iovec *iov, > size_t niov, > -- > 1.8.3.1 > > -- Marc-André Lureau <div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Oct 15, 2020 at 10:05 PM Jagannathan Raman <<a href="mailto:jag.raman@oracle.com">jag.raman@oracle.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">From: Elena Ufimtseva <<a href="mailto:elena.ufimtseva@oracle.com" target="_blank">elena.ufimtseva@oracle.com</a>><br> <br> The entire array of the memory regions and file handlers.<br> Will be used in the next patch.<br> <br> Signed-off-by: Elena Ufimtseva <<a href="mailto:elena.ufimtseva@oracle.com" target="_blank">elena.ufimtseva@oracle.com</a>><br> Signed-off-by: John G Johnson <<a href="mailto:john.g.johnson@oracle.com" target="_blank">john.g.johnson@oracle.com</a>><br> Signed-off-by: Jagannathan Raman <<a href="mailto:jag.raman@oracle.com" target="_blank">jag.raman@oracle.com</a>><br> Reviewed-by: Stefan Hajnoczi <<a href="mailto:stefanha@redhat.com" target="_blank">stefanha@redhat.com</a>><br> ---<br> include/io/channel.h | 24 ++++++++++++++++++++++++<br> io/channel.c | 45 +++++++++++++++++++++++++++++++++++++++++++++<br> 2 files changed, 69 insertions(+)<br> <br> diff --git a/include/io/channel.h b/include/io/channel.h<br> index 3c04f0e..6807506 100644<br> --- a/include/io/channel.h<br> +++ b/include/io/channel.h<br> @@ -773,5 +773,29 @@ void qio_channel_set_aio_fd_handler(QIOChannel *ioc,<br> IOHandler *io_read,<br> IOHandler *io_write,<br> void *opaque);<br> +/**<br> + * qio_channel_writev_full_all:<br> + * @ioc: the channel object<br> + * @iov: the array of memory regions to write data from<br> + * @niov: the length of the @iov array<br> + * @fds: an array of file handles to send<br> + * @nfds: number of file handles in @fds<br> + * @errp: pointer to a NULL-initialized error object<br> + *<br> + *<br> + * Behaves like qio_channel_writev_full but will attempt<br> + * to send all data passed (file handles and memory regions).<br> + * The function will wait for all requested data<br> + * to be written, yielding from the current coroutine<br> + * if required.<br> + *<br> + * Returns: 0 if all bytes were written, or -1 on error<br> + */<br> +<br> +int qio_channel_writev_full_all(QIOChannel *ioc,<br> + const struct iovec *iov,<br> + size_t niov,<br> + int *fds, size_t nfds,<br> + Error **errp);<br> <br> #endif /* QIO_CHANNEL_H */<br> diff --git a/io/channel.c b/io/channel.c<br> index e4376eb..22c10c5 100644<br> --- a/io/channel.c<br> +++ b/io/channel.c<br> @@ -190,6 +190,51 @@ int qio_channel_writev_all(QIOChannel *ioc,<br> return ret;<br> }<br> <br> +int qio_channel_writev_full_all(QIOChannel *ioc,<br> + const struct iovec *iov,<br> + size_t niov,<br> + int *fds, size_t nfds,<br> + Error **errp)<br> +{<br></blockquote><div><br></div><div>Please make qio_channel_writev_all() call qio_channel_writev_full_all() to avoid logic duplication.</div><div><br></div><div>thanks</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> + int ret = -1;<br> + struct iovec *local_iov = g_new(struct iovec, niov);<br> + struct iovec *local_iov_head = local_iov;<br> + unsigned int nlocal_iov = niov;<br> +<br> + nlocal_iov = iov_copy(local_iov, nlocal_iov,<br> + iov, niov,<br> + 0, iov_size(iov, niov));<br> +<br> + while (nlocal_iov > 0) {<br> + ssize_t len;<br> + len = qio_channel_writev_full(ioc, local_iov, nlocal_iov, fds,<br> + nfds, errp);<br> + if (len == QIO_CHANNEL_ERR_BLOCK) {<br> + if (qemu_in_coroutine()) {<br> + qio_channel_yield(ioc, G_IO_OUT);<br> + } else {<br> + qio_channel_wait(ioc, G_IO_OUT);<br> + }<br> + continue;<br> + }<br> + if (len < 0) {<br> + goto cleanup;<br> + }<br> +<br> + iov_discard_front(&local_iov, &nlocal_iov, len);<br> +<br> + if (len > 0) {<br> + fds = NULL;<br> + nfds = 0;<br> + }<br> + }<br> +<br> + ret = 0;<br> + cleanup:<br> + g_free(local_iov_head);<br> + return ret;<br> +}<br> +<br> ssize_t qio_channel_readv(QIOChannel *ioc,<br> const struct iovec *iov,<br> size_t niov,<br> -- <br> 1.8.3.1<br> <br> </blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature">Marc-André Lureau<br></div></div>
diff --git a/include/io/channel.h b/include/io/channel.h index 3c04f0e..6807506 100644 --- a/include/io/channel.h +++ b/include/io/channel.h @@ -773,5 +773,29 @@ void qio_channel_set_aio_fd_handler(QIOChannel *ioc, IOHandler *io_read, IOHandler *io_write, void *opaque); +/** + * qio_channel_writev_full_all: + * @ioc: the channel object + * @iov: the array of memory regions to write data from + * @niov: the length of the @iov array + * @fds: an array of file handles to send + * @nfds: number of file handles in @fds + * @errp: pointer to a NULL-initialized error object + * + * + * Behaves like qio_channel_writev_full but will attempt + * to send all data passed (file handles and memory regions). + * The function will wait for all requested data + * to be written, yielding from the current coroutine + * if required. + * + * Returns: 0 if all bytes were written, or -1 on error + */ + +int qio_channel_writev_full_all(QIOChannel *ioc, + const struct iovec *iov, + size_t niov, + int *fds, size_t nfds, + Error **errp); #endif /* QIO_CHANNEL_H */ diff --git a/io/channel.c b/io/channel.c index e4376eb..22c10c5 100644 --- a/io/channel.c +++ b/io/channel.c @@ -190,6 +190,51 @@ int qio_channel_writev_all(QIOChannel *ioc, return ret; } +int qio_channel_writev_full_all(QIOChannel *ioc, + const struct iovec *iov, + size_t niov, + int *fds, size_t nfds, + Error **errp) +{ + int ret = -1; + struct iovec *local_iov = g_new(struct iovec, niov); + struct iovec *local_iov_head = local_iov; + unsigned int nlocal_iov = niov; + + nlocal_iov = iov_copy(local_iov, nlocal_iov, + iov, niov, + 0, iov_size(iov, niov)); + + while (nlocal_iov > 0) { + ssize_t len; + len = qio_channel_writev_full(ioc, local_iov, nlocal_iov, fds, + nfds, errp); + if (len == QIO_CHANNEL_ERR_BLOCK) { + if (qemu_in_coroutine()) { + qio_channel_yield(ioc, G_IO_OUT); + } else { + qio_channel_wait(ioc, G_IO_OUT); + } + continue; + } + if (len < 0) { + goto cleanup; + } + + iov_discard_front(&local_iov, &nlocal_iov, len); + + if (len > 0) { + fds = NULL; + nfds = 0; + } + } + + ret = 0; + cleanup: + g_free(local_iov_head); + return ret; +} + ssize_t qio_channel_readv(QIOChannel *ioc, const struct iovec *iov, size_t niov,