From: Junjie Cao <junjie.cao@intel.com>
To: qemu-devel@nongnu.org
Cc: peterx@redhat.com, farosas@suse.de, junjie.cao@intel.com
Subject: [PATCH 1/3] migration/qemu-file: switch buffer_at functions to positioned I/O _all helpers
Date: Tue, 21 Apr 2026 04:13:15 +0800 [thread overview]
Message-ID: <20260420201317.30199-2-junjie.cao@intel.com> (raw)
In-Reply-To: <20260420201317.30199-1-junjie.cao@intel.com>
qemu_put_buffer_at() and qemu_get_buffer_at() have the same pattern as
the bug fixed in multifd_file_recv_data(): the ssize_t return value from
the channel layer is stored in a size_t variable, and a short transfer
would be mishandled rather than retried.
Switch to qio_channel_pwrite_all() / qio_channel_pread_all() which
handle short transfers internally and make the code more robust and
consistent with the rest of the positioned I/O call sites.
Fixes: 7f5b50a401 ("migration/qemu-file: add utility methods for working with seekable channels")
Signed-off-by: Junjie Cao <junjie.cao@intel.com>
---
migration/qemu-file.c | 35 +++--------------------------------
1 file changed, 3 insertions(+), 32 deletions(-)
diff --git a/migration/qemu-file.c b/migration/qemu-file.c
index 9cf7dc3bd5..9dfb202203 100644
--- a/migration/qemu-file.c
+++ b/migration/qemu-file.c
@@ -535,28 +535,13 @@ void qemu_put_buffer_at(QEMUFile *f, const uint8_t *buf, size_t buflen,
off_t pos)
{
Error *err = NULL;
- size_t ret;
if (f->last_error) {
return;
}
qemu_fflush(f);
- ret = qio_channel_pwrite(f->ioc, (char *)buf, buflen, pos, &err);
-
- if (err) {
- qemu_file_set_error_obj(f, -EIO, err);
- return;
- }
-
- if ((ssize_t)ret == QIO_CHANNEL_ERR_BLOCK) {
- qemu_file_set_error_obj(f, -EAGAIN, NULL);
- return;
- }
-
- if (ret != buflen) {
- error_setg(&err, "Partial write of size %zu, expected %zu", ret,
- buflen);
+ if (qio_channel_pwrite_all(f->ioc, buf, buflen, pos, &err) < 0) {
qemu_file_set_error_obj(f, -EIO, err);
return;
}
@@ -569,31 +554,17 @@ size_t qemu_get_buffer_at(QEMUFile *f, const uint8_t *buf, size_t buflen,
off_t pos)
{
Error *err = NULL;
- size_t ret;
if (f->last_error) {
return 0;
}
- ret = qio_channel_pread(f->ioc, (char *)buf, buflen, pos, &err);
-
- if ((ssize_t)ret == -1 || err) {
+ if (qio_channel_pread_all(f->ioc, (char *)buf, buflen, pos, &err) < 0) {
qemu_file_set_error_obj(f, -EIO, err);
return 0;
}
- if ((ssize_t)ret == QIO_CHANNEL_ERR_BLOCK) {
- qemu_file_set_error_obj(f, -EAGAIN, NULL);
- return 0;
- }
-
- if (ret != buflen) {
- error_setg(&err, "Partial read of size %zu, expected %zu", ret, buflen);
- qemu_file_set_error_obj(f, -EIO, err);
- return 0;
- }
-
- return ret;
+ return buflen;
}
void qemu_set_offset(QEMUFile *f, off_t off, int whence)
--
2.43.0
next prev parent reply other threads:[~2026-04-20 12:11 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-20 20:13 [PATCH 0/3] migration: switch remaining positioned I/O to _all helpers Junjie Cao
2026-04-20 20:13 ` Junjie Cao [this message]
2026-04-20 20:13 ` [PATCH 2/3] migration/file: switch file_write_ramblock_iov to pwritev_all Junjie Cao
2026-04-20 20:13 ` [PATCH 3/3] migration/qemu-file: drop incorrect const from qemu_get_buffer_at buf Junjie Cao
2026-04-20 17:34 ` Philippe Mathieu-Daudé
2026-04-21 14:20 ` [PATCH 0/3] migration: switch remaining positioned I/O to _all helpers Peter Xu
2026-04-26 8:27 ` Michael Tokarev
2026-04-27 13:16 ` Peter Xu
2026-04-27 22:36 ` Junjie Cao
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=20260420201317.30199-2-junjie.cao@intel.com \
--to=junjie.cao@intel.com \
--cc=farosas@suse.de \
--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.