[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 04/11] io: add pwritev support to QIOChannelFile
From: |
Nikolay Borisov |
Subject: |
[PATCH v2 04/11] io: add pwritev support to QIOChannelFile |
Date: |
Mon, 10 Oct 2022 16:34:01 +0300 |
The upcoming 'fixed-ram' feature would require qemu to write data at
specific offsets of the file. This is currently missing so this patch
adds it. I've chosen to implement it as a type-specific function rather
than plumb it through the generic channel interface as it relies on
being able to do seeks.
Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
include/io/channel-file.h | 5 +++++
io/channel-file.c | 24 ++++++++++++++++++++++++
2 files changed, 29 insertions(+)
diff --git a/include/io/channel-file.h b/include/io/channel-file.h
index 50e8eb113868..0a5d54f5e58e 100644
--- a/include/io/channel-file.h
+++ b/include/io/channel-file.h
@@ -89,4 +89,9 @@ qio_channel_file_new_path(const char *path,
mode_t mode,
Error **errp);
+ssize_t qio_channel_file_pwritev(QIOChannel *ioc,
+ const struct iovec *iov,
+ size_t niov,
+ off_t offset,
+ Error **errp);
#endif /* QIO_CHANNEL_FILE_H */
diff --git a/io/channel-file.c b/io/channel-file.c
index b67687c2aa64..da17d0a11ba7 100644
--- a/io/channel-file.c
+++ b/io/channel-file.c
@@ -136,6 +136,30 @@ static ssize_t qio_channel_file_writev(QIOChannel *ioc,
return ret;
}
+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;
+}
+
static int qio_channel_file_set_blocking(QIOChannel *ioc,
bool enabled,
Error **errp)
--
2.34.1
[PATCH v2 09/11] migration: Refactor precopy ram loading code, Nikolay Borisov, 2022/10/10
[PATCH v2 11/11] analyze-migration.py: add initial support for fixed ram streams, Nikolay Borisov, 2022/10/10
[PATCH v2 02/11] migration: Add support for 'file:' uri for incoming migration, Nikolay Borisov, 2022/10/10