Message ID | a366c7f80a862b4f32445f8334e2f36767b102a3.1607922214.git.jag.raman@oracle.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Initial support for multi-process Qemu | expand |
Hi On Mon, Dec 14, 2020 at 9:15 AM Jagannathan Raman <jag.raman@oracle.com> wrote: > From: Elena Ufimtseva <elena.ufimtseva@oracle.com> > > Adds QIO channel functions that transmit and receive iovs along with fds. > > 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 | 50 +++++++++++++++++++++++++++++++++++++++++ > io/channel.c | 63 > +++++++++++++++++++++++++++++++++++++++++++++++++++- > 2 files changed, 112 insertions(+), 1 deletion(-) > > diff --git a/include/io/channel.h b/include/io/channel.h > index 4d6fe45..c2d9836 100644 > --- a/include/io/channel.h > +++ b/include/io/channel.h > @@ -774,4 +774,54 @@ void qio_channel_set_aio_fd_handler(QIOChannel *ioc, > IOHandler *io_write, > void *opaque); > > +/** > + * qio_channel_readv_full_all: > + * @ioc: the channel object > + * @iov: the array of memory regions to read data to > + * @niov: the length of the @iov array > + * @fds: an array of file handles to read > + * @nfds: number of file handles in @fds > + * @errp: pointer to a NULL-initialized error object > + * > + * > + * Behaves like qio_channel_readvv_full but will attempt > + * to read all data specified (file handles and memory regions). > + * The function will wait for all requested data > + * to be read, yielding from the current coroutine > + * if required. > + * > + * Returns: 0 if all bytes were read, or -1 on error > + */ > + > +int qio_channel_readv_full_all(QIOChannel *ioc, > + const struct iovec *iov, > + size_t niov, > + int **fds, size_t *nfds, > + Error **errp); > + > +/** > + * 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 93d449d..13b0e7a 100644 > --- a/io/channel.c > +++ b/io/channel.c > @@ -152,15 +152,72 @@ int qio_channel_readv_all(QIOChannel *ioc, > return ret; > } > > +int qio_channel_readv_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; > + int **local_fds = fds; > + size_t *local_nfds = nfds; > + > + 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_readv_full(ioc, local_iov, nlocal_iov, > local_fds, > + local_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) { > + ret = len; > + goto cleanup; > + } > + > + iov_discard_front(&local_iov, &nlocal_iov, len); > + > + local_fds = NULL; > + local_nfds = 0; > + } > + > + ret = 1; > + cleanup: > + g_free(local_iov_head); > + return ret; > +} > + > I suggest to adapt the code so qio_channel_readv_all_eof() calls qio_channel_readv_full_all(). You may want to split this patch in 2 parts: the read and write parts. > int qio_channel_writev_all(QIOChannel *ioc, > const struct iovec *iov, > size_t niov, > Error **errp) > { > + return qio_channel_writev_full_all(ioc, iov, niov, NULL, 0, errp); > +} > + > +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; > + int *local_fds = fds; > + size_t local_nfds = nfds; > > nlocal_iov = iov_copy(local_iov, nlocal_iov, > iov, niov, > @@ -168,7 +225,8 @@ int qio_channel_writev_all(QIOChannel *ioc, > > while (nlocal_iov > 0) { > ssize_t len; > - len = qio_channel_writev(ioc, local_iov, nlocal_iov, errp); > + len = qio_channel_writev_full(ioc, local_iov, nlocal_iov, > local_fds, > + local_nfds, errp); > if (len == QIO_CHANNEL_ERR_BLOCK) { > if (qemu_in_coroutine()) { > qio_channel_yield(ioc, G_IO_OUT); > @@ -182,6 +240,9 @@ int qio_channel_writev_all(QIOChannel *ioc, > } > > iov_discard_front(&local_iov, &nlocal_iov, len); > + > + local_fds = NULL; > + local_nfds = 0; > } > > ret = 0; > -- > 1.8.3.1 > >
On Tue, Dec 15, 2020 at 02:49:22PM +0400, Marc-André Lureau wrote: > Hi > > On Mon, Dec 14, 2020 at 9:15 AM Jagannathan Raman <jag.raman@oracle.com> > wrote: > > > From: Elena Ufimtseva <elena.ufimtseva@oracle.com> > > > > Adds QIO channel functions that transmit and receive iovs along with fds. > > > > 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 | 50 +++++++++++++++++++++++++++++++++++++++++ > > io/channel.c | 63 > > +++++++++++++++++++++++++++++++++++++++++++++++++++- > > 2 files changed, 112 insertions(+), 1 deletion(-) > > > > diff --git a/include/io/channel.h b/include/io/channel.h > > index 4d6fe45..c2d9836 100644 > > --- a/include/io/channel.h > > +++ b/include/io/channel.h > > @@ -774,4 +774,54 @@ void qio_channel_set_aio_fd_handler(QIOChannel *ioc, > > IOHandler *io_write, > > void *opaque); > > > > +/** > > + * qio_channel_readv_full_all: > > + * @ioc: the channel object > > + * @iov: the array of memory regions to read data to > > + * @niov: the length of the @iov array > > + * @fds: an array of file handles to read > > + * @nfds: number of file handles in @fds > > + * @errp: pointer to a NULL-initialized error object > > + * > > + * > > + * Behaves like qio_channel_readvv_full but will attempt > > + * to read all data specified (file handles and memory regions). > > + * The function will wait for all requested data > > + * to be read, yielding from the current coroutine > > + * if required. > > + * > > + * Returns: 0 if all bytes were read, or -1 on error > > + */ > > + > > +int qio_channel_readv_full_all(QIOChannel *ioc, > > + const struct iovec *iov, > > + size_t niov, > > + int **fds, size_t *nfds, > > + Error **errp); > > + > > +/** > > + * 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 93d449d..13b0e7a 100644 > > --- a/io/channel.c > > +++ b/io/channel.c > > @@ -152,15 +152,72 @@ int qio_channel_readv_all(QIOChannel *ioc, > > return ret; > > } > > > > +int qio_channel_readv_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; > > + int **local_fds = fds; > > + size_t *local_nfds = nfds; > > + > > + 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_readv_full(ioc, local_iov, nlocal_iov, > > local_fds, > > + local_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) { > > + ret = len; > > + goto cleanup; > > + } > > + > > + iov_discard_front(&local_iov, &nlocal_iov, len); > > + > > + local_fds = NULL; > > + local_nfds = 0; > > + } > > + > > + ret = 1; > > + cleanup: > > + g_free(local_iov_head); > > + return ret; > > +} > > + > > > > I suggest to adapt the code so qio_channel_readv_all_eof() calls > qio_channel_readv_full_all(). > > You may want to split this patch in 2 parts: the read and write parts. > > Thank you Marc-Andre, will do. Elena > > int qio_channel_writev_all(QIOChannel *ioc, > > const struct iovec *iov, > > size_t niov, > > Error **errp) > > { > > + return qio_channel_writev_full_all(ioc, iov, niov, NULL, 0, errp); > > +} > > + > > +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; > > + int *local_fds = fds; > > + size_t local_nfds = nfds; > > > > nlocal_iov = iov_copy(local_iov, nlocal_iov, > > iov, niov, > > @@ -168,7 +225,8 @@ int qio_channel_writev_all(QIOChannel *ioc, > > > > while (nlocal_iov > 0) { > > ssize_t len; > > - len = qio_channel_writev(ioc, local_iov, nlocal_iov, errp); > > + len = qio_channel_writev_full(ioc, local_iov, nlocal_iov, > > local_fds, > > + local_nfds, errp); > > if (len == QIO_CHANNEL_ERR_BLOCK) { > > if (qemu_in_coroutine()) { > > qio_channel_yield(ioc, G_IO_OUT); > > @@ -182,6 +240,9 @@ int qio_channel_writev_all(QIOChannel *ioc, > > } > > > > iov_discard_front(&local_iov, &nlocal_iov, len); > > + > > + local_fds = NULL; > > + local_nfds = 0; > > } > > > > ret = 0; > > -- > > 1.8.3.1 > > > > > > -- > Marc-André Lureau
On Tue, Dec 15, 2020 at 02:49:22PM +0400, Marc-André Lureau wrote: > Hi > > On Mon, Dec 14, 2020 at 9:15 AM Jagannathan Raman <jag.raman@oracle.com> > wrote: > > > From: Elena Ufimtseva <elena.ufimtseva@oracle.com> > > > > Adds QIO channel functions that transmit and receive iovs along with fds. > > > > 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 | 50 +++++++++++++++++++++++++++++++++++++++++ > > io/channel.c | 63 > > +++++++++++++++++++++++++++++++++++++++++++++++++++- > > 2 files changed, 112 insertions(+), 1 deletion(-) > > > > diff --git a/include/io/channel.h b/include/io/channel.h > > index 4d6fe45..c2d9836 100644 > > --- a/include/io/channel.h > > +++ b/include/io/channel.h > > @@ -774,4 +774,54 @@ void qio_channel_set_aio_fd_handler(QIOChannel *ioc, > > IOHandler *io_write, > > void *opaque); > > > > +/** > > + * qio_channel_readv_full_all: > > + * @ioc: the channel object > > + * @iov: the array of memory regions to read data to > > + * @niov: the length of the @iov array > > + * @fds: an array of file handles to read > > + * @nfds: number of file handles in @fds > > + * @errp: pointer to a NULL-initialized error object > > + * > > + * > > + * Behaves like qio_channel_readvv_full but will attempt > > + * to read all data specified (file handles and memory regions). > > + * The function will wait for all requested data > > + * to be read, yielding from the current coroutine > > + * if required. > > + * > > + * Returns: 0 if all bytes were read, or -1 on error > > + */ > > + > > +int qio_channel_readv_full_all(QIOChannel *ioc, > > + const struct iovec *iov, > > + size_t niov, > > + int **fds, size_t *nfds, > > + Error **errp); > > + > > +/** > > + * 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 93d449d..13b0e7a 100644 > > --- a/io/channel.c > > +++ b/io/channel.c > > @@ -152,15 +152,72 @@ int qio_channel_readv_all(QIOChannel *ioc, > > return ret; > > } > > > > +int qio_channel_readv_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; > > + int **local_fds = fds; > > + size_t *local_nfds = nfds; > > + > > + 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_readv_full(ioc, local_iov, nlocal_iov, > > local_fds, > > + local_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) { > > + ret = len; > > + goto cleanup; > > + } > > + > > + iov_discard_front(&local_iov, &nlocal_iov, len); > > + > > + local_fds = NULL; > > + local_nfds = 0; > > + } > > + > > + ret = 1; > > + cleanup: > > + g_free(local_iov_head); > > + return ret; > > +} > > + > > > > I suggest to adapt the code so qio_channel_readv_all_eof() calls > qio_channel_readv_full_all(). > > You may want to split this patch in 2 parts: the read and write parts. > And should we drop the Reviewed-by: Stefan Hajnoczi then? Thanks! Elena > > > int qio_channel_writev_all(QIOChannel *ioc, > > const struct iovec *iov, > > size_t niov, > > Error **errp) > > { > > + return qio_channel_writev_full_all(ioc, iov, niov, NULL, 0, errp); > > +} > > + > > +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; > > + int *local_fds = fds; > > + size_t local_nfds = nfds; > > > > nlocal_iov = iov_copy(local_iov, nlocal_iov, > > iov, niov, > > @@ -168,7 +225,8 @@ int qio_channel_writev_all(QIOChannel *ioc, > > > > while (nlocal_iov > 0) { > > ssize_t len; > > - len = qio_channel_writev(ioc, local_iov, nlocal_iov, errp); > > + len = qio_channel_writev_full(ioc, local_iov, nlocal_iov, > > local_fds, > > + local_nfds, errp); > > if (len == QIO_CHANNEL_ERR_BLOCK) { > > if (qemu_in_coroutine()) { > > qio_channel_yield(ioc, G_IO_OUT); > > @@ -182,6 +240,9 @@ int qio_channel_writev_all(QIOChannel *ioc, > > } > > > > iov_discard_front(&local_iov, &nlocal_iov, len); > > + > > + local_fds = NULL; > > + local_nfds = 0; > > } > > > > ret = 0; > > -- > > 1.8.3.1 > > > > > > -- > Marc-André Lureau
On Tue, Dec 15, 2020 at 01:22:25PM -0800, Elena Ufimtseva wrote: > On Tue, Dec 15, 2020 at 02:49:22PM +0400, Marc-André Lureau wrote: > > I suggest to adapt the code so qio_channel_readv_all_eof() calls > > qio_channel_readv_full_all(). > > > > You may want to split this patch in 2 parts: the read and write parts. > > > > And should we drop the Reviewed-by: Stefan Hajnoczi then? Yes, please drop my R-b and I'll review again. Stefan
diff --git a/include/io/channel.h b/include/io/channel.h index 4d6fe45..c2d9836 100644 --- a/include/io/channel.h +++ b/include/io/channel.h @@ -774,4 +774,54 @@ void qio_channel_set_aio_fd_handler(QIOChannel *ioc, IOHandler *io_write, void *opaque); +/** + * qio_channel_readv_full_all: + * @ioc: the channel object + * @iov: the array of memory regions to read data to + * @niov: the length of the @iov array + * @fds: an array of file handles to read + * @nfds: number of file handles in @fds + * @errp: pointer to a NULL-initialized error object + * + * + * Behaves like qio_channel_readvv_full but will attempt + * to read all data specified (file handles and memory regions). + * The function will wait for all requested data + * to be read, yielding from the current coroutine + * if required. + * + * Returns: 0 if all bytes were read, or -1 on error + */ + +int qio_channel_readv_full_all(QIOChannel *ioc, + const struct iovec *iov, + size_t niov, + int **fds, size_t *nfds, + Error **errp); + +/** + * 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 93d449d..13b0e7a 100644 --- a/io/channel.c +++ b/io/channel.c @@ -152,15 +152,72 @@ int qio_channel_readv_all(QIOChannel *ioc, return ret; } +int qio_channel_readv_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; + int **local_fds = fds; + size_t *local_nfds = nfds; + + 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_readv_full(ioc, local_iov, nlocal_iov, local_fds, + local_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) { + ret = len; + goto cleanup; + } + + iov_discard_front(&local_iov, &nlocal_iov, len); + + local_fds = NULL; + local_nfds = 0; + } + + ret = 1; + cleanup: + g_free(local_iov_head); + return ret; +} + int qio_channel_writev_all(QIOChannel *ioc, const struct iovec *iov, size_t niov, Error **errp) { + return qio_channel_writev_full_all(ioc, iov, niov, NULL, 0, errp); +} + +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; + int *local_fds = fds; + size_t local_nfds = nfds; nlocal_iov = iov_copy(local_iov, nlocal_iov, iov, niov, @@ -168,7 +225,8 @@ int qio_channel_writev_all(QIOChannel *ioc, while (nlocal_iov > 0) { ssize_t len; - len = qio_channel_writev(ioc, local_iov, nlocal_iov, errp); + len = qio_channel_writev_full(ioc, local_iov, nlocal_iov, local_fds, + local_nfds, errp); if (len == QIO_CHANNEL_ERR_BLOCK) { if (qemu_in_coroutine()) { qio_channel_yield(ioc, G_IO_OUT); @@ -182,6 +240,9 @@ int qio_channel_writev_all(QIOChannel *ioc, } iov_discard_front(&local_iov, &nlocal_iov, len); + + local_fds = NULL; + local_nfds = 0; } ret = 0;