[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 07/27] io: implement io_pwritev/preadv for QIOChannelFile
From: |
peterx |
Subject: |
[PULL 07/27] io: implement io_pwritev/preadv for QIOChannelFile |
Date: |
Mon, 4 Mar 2024 09:26:14 +0800 |
From: Nikolay Borisov <nborisov@suse.com>
The upcoming 'mapped-ram' feature will require qemu to write data to
(and restore from) specific offsets of the migration file.
Add a minimal implementation of pwritev/preadv and expose them via the
io_pwritev and io_preadv interfaces.
Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: "Daniel P. Berrangé" <berrange@redhat.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
Signed-off-by: Fabiano Rosas <farosas@suse.de>
Link: https://lore.kernel.org/r/20240229153017.2221-5-farosas@suse.de
Signed-off-by: Peter Xu <peterx@redhat.com>
---
io/channel-file.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 56 insertions(+)
diff --git a/io/channel-file.c b/io/channel-file.c
index f91bf6db1c..a6ad7770c6 100644
--- a/io/channel-file.c
+++ b/io/channel-file.c
@@ -146,6 +146,58 @@ static ssize_t qio_channel_file_writev(QIOChannel *ioc,
return ret;
}
+#ifdef CONFIG_PREADV
+static ssize_t qio_channel_file_preadv(QIOChannel *ioc,
+ const struct iovec *iov,
+ size_t niov,
+ off_t offset,
+ Error **errp)
+{
+ QIOChannelFile *fioc = QIO_CHANNEL_FILE(ioc);
+ ssize_t ret;
+
+ retry:
+ ret = preadv(fioc->fd, iov, niov, offset);
+ if (ret < 0) {
+ if (errno == EAGAIN) {
+ return QIO_CHANNEL_ERR_BLOCK;
+ }
+ if (errno == EINTR) {
+ goto retry;
+ }
+
+ error_setg_errno(errp, errno, "Unable to read from file");
+ return -1;
+ }
+
+ return ret;
+}
+
+static ssize_t qio_channel_file_pwritev(QIOChannel *ioc,
+ const struct iovec *iov,
+ size_t niov,
+ off_t offset,
+ Error **errp)
+{
+ QIOChannelFile *fioc = QIO_CHANNEL_FILE(ioc);
+ ssize_t ret;
+
+ retry:
+ ret = pwritev(fioc->fd, iov, niov, offset);
+ if (ret <= 0) {
+ if (errno == EAGAIN) {
+ return QIO_CHANNEL_ERR_BLOCK;
+ }
+ if (errno == EINTR) {
+ goto retry;
+ }
+ error_setg_errno(errp, errno, "Unable to write to file");
+ return -1;
+ }
+ return ret;
+}
+#endif /* CONFIG_PREADV */
+
static int qio_channel_file_set_blocking(QIOChannel *ioc,
bool enabled,
Error **errp)
@@ -231,6 +283,10 @@ static void qio_channel_file_class_init(ObjectClass *klass,
ioc_klass->io_writev = qio_channel_file_writev;
ioc_klass->io_readv = qio_channel_file_readv;
ioc_klass->io_set_blocking = qio_channel_file_set_blocking;
+#ifdef CONFIG_PREADV
+ ioc_klass->io_pwritev = qio_channel_file_pwritev;
+ ioc_klass->io_preadv = qio_channel_file_preadv;
+#endif
ioc_klass->io_seek = qio_channel_file_seek;
ioc_klass->io_close = qio_channel_file_close;
ioc_klass->io_create_watch = qio_channel_file_create_watch;
--
2.44.0
- [PULL 00/27] Migration next patches, peterx, 2024/03/03
- [PULL 01/27] migration: massage cpr-reboot documentation, peterx, 2024/03/03
- [PULL 02/27] migration: Properly apply migration compression level parameters, peterx, 2024/03/03
- [PULL 04/27] migration/multifd: Cleanup multifd_recv_sync_main, peterx, 2024/03/03
- [PULL 05/27] io: add and implement QIO_CHANNEL_FEATURE_SEEKABLE for channel file, peterx, 2024/03/03
- [PULL 03/27] tests/migration: Set compression level in migration tests, peterx, 2024/03/03
- [PULL 07/27] io: implement io_pwritev/preadv for QIOChannelFile,
peterx <=
- [PULL 08/27] io: fsync before closing a file channel, peterx, 2024/03/03
- [PULL 06/27] io: Add generic pwritev/preadv interface, peterx, 2024/03/03
- [PULL 10/27] migration/ram: Introduce 'mapped-ram' migration capability, peterx, 2024/03/03
- [PULL 11/27] migration: Add mapped-ram URI compatibility check, peterx, 2024/03/03
- [PULL 09/27] migration/qemu-file: add utility methods for working with seekable channels, peterx, 2024/03/03
- [PULL 12/27] migration/ram: Add outgoing 'mapped-ram' migration, peterx, 2024/03/03
- [PULL 13/27] migration/ram: Add incoming 'mapped-ram' migration, peterx, 2024/03/03
- [PULL 14/27] tests/qtest/migration: Add tests for mapped-ram file-based migration, peterx, 2024/03/03
- [PULL 16/27] migration/multifd: Decouple recv method from pages, peterx, 2024/03/03
- [PULL 15/27] migration/multifd: Rename MultiFDSend|RecvParams::data to compress_data, peterx, 2024/03/03