[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 01/10] io: Introduce qio_channel_file_new_dupfd
From: |
peterx |
Subject: |
[PULL 01/10] io: Introduce qio_channel_file_new_dupfd |
Date: |
Sun, 17 Mar 2024 16:57:54 -0400 |
From: Fabiano Rosas <farosas@suse.de>
Add a new helper function for creating a QIOChannelFile channel with a
duplicated file descriptor. This saves the calling code from having to
do error checking on the dup() call.
Suggested-by: "Daniel P. Berrangé" <berrange@redhat.com>
Signed-off-by: Fabiano Rosas <farosas@suse.de>
Reviewed-by: "Daniel P. Berrangé" <berrange@redhat.com>
Link: 20240311233335.17299-2-farosas@suse.de">https://lore.kernel.org/r/20240311233335.17299-2-farosas@suse.de
Signed-off-by: Peter Xu <peterx@redhat.com>
---
include/io/channel-file.h | 18 ++++++++++++++++++
io/channel-file.c | 12 ++++++++++++
2 files changed, 30 insertions(+)
diff --git a/include/io/channel-file.h b/include/io/channel-file.h
index 50e8eb1138..d373a4e44d 100644
--- a/include/io/channel-file.h
+++ b/include/io/channel-file.h
@@ -68,6 +68,24 @@ struct QIOChannelFile {
QIOChannelFile *
qio_channel_file_new_fd(int fd);
+/**
+ * qio_channel_file_new_dupfd:
+ * @fd: the file descriptor
+ * @errp: pointer to initialized error object
+ *
+ * Create a new IO channel object for a file represented by the @fd
+ * parameter. Like qio_channel_file_new_fd(), but the @fd is first
+ * duplicated with dup().
+ *
+ * The channel will own the duplicated file descriptor and will take
+ * responsibility for closing it, the original FD is owned by the
+ * caller.
+ *
+ * Returns: the new channel object
+ */
+QIOChannelFile *
+qio_channel_file_new_dupfd(int fd, Error **errp);
+
/**
* qio_channel_file_new_path:
* @path: the file path
diff --git a/io/channel-file.c b/io/channel-file.c
index a6ad7770c6..6436cfb6ae 100644
--- a/io/channel-file.c
+++ b/io/channel-file.c
@@ -45,6 +45,18 @@ qio_channel_file_new_fd(int fd)
return ioc;
}
+QIOChannelFile *
+qio_channel_file_new_dupfd(int fd, Error **errp)
+{
+ int newfd = dup(fd);
+
+ if (newfd < 0) {
+ error_setg_errno(errp, errno, "Could not dup FD %d", fd);
+ return NULL;
+ }
+
+ return qio_channel_file_new_fd(newfd);
+}
QIOChannelFile *
qio_channel_file_new_path(const char *path,
--
2.44.0
- [PULL 00/10] Migration 20240317 patches, peterx, 2024/03/17
- [PULL 01/10] io: Introduce qio_channel_file_new_dupfd,
peterx <=
- [PULL 02/10] migration: Fix error handling after dup in file migration, peterx, 2024/03/17
- [PULL 03/10] physmem: Expose tlb_reset_dirty_range_all(), peterx, 2024/03/17
- [PULL 04/10] physmem: Factor cpu_physical_memory_dirty_bits_cleared() out, peterx, 2024/03/17
- [PULL 05/10] physmem: Fix migration dirty bitmap coherency with TCG memory access, peterx, 2024/03/17
- [PULL 06/10] migration: Skip only empty block devices, peterx, 2024/03/17
- [PULL 07/10] migration: cpr-reboot documentation, peterx, 2024/03/17
- [PULL 09/10] migration/multifd: Ensure we're not given a socket for file migration, peterx, 2024/03/17
- [PULL 08/10] migration: Fix iocs leaks during file and fd migration, peterx, 2024/03/17
- [PULL 10/10] migration/multifd: Duplicate the fd for the outgoing_args, peterx, 2024/03/17
- Re: [PULL 00/10] Migration 20240317 patches, Peter Maydell, 2024/03/19