From: Fabiano Rosas <farosas@suse.de>
To: Junjie Cao <junjie.cao@intel.com>, qemu-devel@nongnu.org
Cc: berrange@redhat.com, peterx@redhat.com, junjie.cao@intel.com
Subject: Re: [PATCH v3 2/4] io/channel: introduce qio_channel_pwrite{v, }_all()
Date: Tue, 14 Apr 2026 12:54:06 -0300 [thread overview]
Message-ID: <87eckhzgf5.fsf@suse.de> (raw)
In-Reply-To: <20260413214549.926435-3-junjie.cao@intel.com>
Junjie Cao <junjie.cao@intel.com> writes:
> Add positioned write helpers that retry on short writes, matching
> the pread_all family from the previous patch.
>
> qio_channel_pwritev_all() -- retry loop; returns 0 on success,
> -1 on error.
> qio_channel_pwrite_all() -- single-buffer convenience wrapper.
>
> Signed-off-by: Junjie Cao <junjie.cao@intel.com>
> ---
> include/io/channel.h | 41 +++++++++++++++++++++++++++++++++++++
> io/channel.c | 48 ++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 89 insertions(+)
>
> diff --git a/include/io/channel.h b/include/io/channel.h
> index 47af409ede..287d10cd6f 100644
> --- a/include/io/channel.h
> +++ b/include/io/channel.h
> @@ -598,6 +598,47 @@ ssize_t qio_channel_pwritev(QIOChannel *ioc, const struct iovec *iov,
> ssize_t qio_channel_pwrite(QIOChannel *ioc, void *buf, size_t buflen,
> off_t offset, Error **errp);
>
> +/**
> + * qio_channel_pwritev_all:
> + * @ioc: the channel object
> + * @iov: the array of memory regions to write data from
> + * @niov: the length of the @iov array
> + * @offset: the starting offset in the channel to write to
> + * @errp: pointer to a NULL-initialized error object
> + *
> + * Writes @iov, possibly blocking or (if the channel is non-blocking)
> + * yielding from the current coroutine multiple times until the entire
> + * content is written. Otherwise behaves as qio_channel_pwritev().
> + *
> + * Returns: 0 if all bytes were written, or -1 on error
> + */
> +int coroutine_mixed_fn qio_channel_pwritev_all(QIOChannel *ioc,
> + const struct iovec *iov,
> + size_t niov,
> + off_t offset,
> + Error **errp);
> +
> +/**
> + * qio_channel_pwrite_all:
> + * @ioc: the channel object
> + * @buf: the memory region to write data from
> + * @buflen: the number of bytes to write from @buf
> + * @offset: the starting offset in the channel to write to
> + * @errp: pointer to a NULL-initialized error object
> + *
> + * Writes @buflen bytes from @buf, possibly blocking or (if the
> + * channel is non-blocking) yielding from the current coroutine
> + * multiple times until the entire content is written. Otherwise
> + * behaves as qio_channel_pwrite().
> + *
> + * Returns: 0 if all bytes were written, or -1 on error
> + */
> +int coroutine_mixed_fn qio_channel_pwrite_all(QIOChannel *ioc,
> + const void *buf,
> + size_t buflen,
> + off_t offset,
> + Error **errp);
> +
> /**
> * qio_channel_preadv
> * @ioc: the channel object
> diff --git a/io/channel.c b/io/channel.c
> index 52c1abfcbc..2853dadb68 100644
> --- a/io/channel.c
> +++ b/io/channel.c
> @@ -478,6 +478,54 @@ ssize_t qio_channel_pwrite(QIOChannel *ioc, void *buf, size_t buflen,
> return qio_channel_pwritev(ioc, &iov, 1, offset, errp);
> }
>
> +int coroutine_mixed_fn qio_channel_pwritev_all(QIOChannel *ioc,
> + const struct iovec *iov,
> + size_t niov,
> + off_t offset,
> + 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_pwritev(ioc, local_iov, nlocal_iov, offset, errp);
> +
> + if (len == QIO_CHANNEL_ERR_BLOCK) {
> + qio_channel_wait_cond(ioc, G_IO_OUT);
> + continue;
> + }
> + if (len < 0) {
> + goto cleanup;
> + }
> +
> + offset += len;
> + iov_discard_front(&local_iov, &nlocal_iov, len);
> + }
> +
> + ret = 0;
> + cleanup:
> + g_free(local_iov_head);
> + return ret;
> +}
> +
> +int coroutine_mixed_fn qio_channel_pwrite_all(QIOChannel *ioc,
> + const void *buf,
> + size_t buflen,
> + off_t offset,
> + Error **errp)
> +{
> + struct iovec iov = { .iov_base = (char *)buf, .iov_len = buflen };
> + return qio_channel_pwritev_all(ioc, &iov, 1, offset, errp);
> +}
> +
> ssize_t qio_channel_preadv(QIOChannel *ioc, const struct iovec *iov,
> size_t niov, off_t offset, Error **errp)
> {
Reviewed-by: Fabiano Rosas <farosas@suse.de>
next prev parent reply other threads:[~2026-04-14 15:54 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-13 21:45 [PATCH v3 0/4] io/channel: complete pread/pwrite_all API and fix multifd_file_recv_data Junjie Cao
2026-04-13 21:45 ` [PATCH v3 1/4] io/channel: introduce qio_channel_pread{v, }_all{, _eof}() Junjie Cao
2026-04-14 15:49 ` Fabiano Rosas
2026-04-17 9:45 ` [PATCH v3 1/4] io/channel: introduce qio_channel_pread{v,}_all{,_eof}() Daniel P. Berrangé
2026-04-13 21:45 ` [PATCH v3 2/4] io/channel: introduce qio_channel_pwrite{v,}_all() Junjie Cao
2026-04-14 15:54 ` Fabiano Rosas [this message]
2026-04-17 9:46 ` [PATCH v3 2/4] io/channel: introduce qio_channel_pwrite{v, }_all() Daniel P. Berrangé via qemu development
2026-04-13 21:45 ` [PATCH v3 3/4] migration/file: fix type mismatch and NULL deref in multifd_file_recv_data Junjie Cao
2026-04-14 15:55 ` Fabiano Rosas
2026-04-13 21:45 ` [PATCH v3 4/4] tests/unit: add pread/pwrite _all tests for io channel file Junjie Cao
2026-04-14 16:01 ` Fabiano Rosas
2026-04-17 9:47 ` Daniel P. Berrangé
2026-04-17 16:51 ` [PATCH v3 0/4] io/channel: complete pread/pwrite_all API and fix multifd_file_recv_data Junjie Cao
2026-04-17 9:48 ` Daniel P. Berrangé
2026-04-17 14:04 ` Peter Xu
2026-04-26 8:15 ` Michael Tokarev
2026-04-26 8:21 ` Michael Tokarev
2026-04-29 14:24 ` Fabiano Rosas
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=87eckhzgf5.fsf@suse.de \
--to=farosas@suse.de \
--cc=berrange@redhat.com \
--cc=junjie.cao@intel.com \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.org \
/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.