From 60efffa41b34cc299fed65b67e2c2641846d592b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Date: Thu, 27 Aug 2020 13:27:00 +0100 Subject: monitor: simplify functions for getting a dup'd fdset entry MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently code has to call monitor_fdset_get_fd, then dup the return fd, and then add the duplicate FD back into the fdset. This dance is overly verbose for the caller and introduces extra failure modes which can be avoided by folding all the logic into monitor_fdset_dup_fd_add and removing monitor_fdset_get_fd entirely. Signed-off-by: Daniel P. Berrangé --- include/monitor/monitor.h | 3 +-- include/qemu/osdep.h | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h index 1018d75..c017077 100644 --- a/include/monitor/monitor.h +++ b/include/monitor/monitor.h @@ -43,8 +43,7 @@ int monitor_read_password(MonitorHMP *mon, ReadLineFunc *readline_func, AddfdInfo *monitor_fdset_add_fd(int fd, bool has_fdset_id, int64_t fdset_id, bool has_opaque, const char *opaque, Error **errp); -int monitor_fdset_get_fd(int64_t fdset_id, int flags); -int monitor_fdset_dup_fd_add(int64_t fdset_id, int dup_fd); +int monitor_fdset_dup_fd_add(int64_t fdset_id, int flags); void monitor_fdset_dup_fd_remove(int dup_fd); int64_t monitor_fdset_dup_fd_find(int dup_fd); diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index 412962d..66ee5bc 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -501,6 +501,7 @@ int qemu_open(const char *name, int flags, ...); int qemu_close(int fd); int qemu_unlink(const char *name); #ifndef _WIN32 +int qemu_dup_flags(int fd, int flags); int qemu_dup(int fd); #endif int qemu_lock_fd(int fd, int64_t start, int64_t len, bool exclusive); -- cgit v1.1 From 448058aa99aaf30e7b8978508e575284a19fcfc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Date: Tue, 21 Jul 2020 13:25:21 +0100 Subject: util: rename qemu_open() to qemu_open_old() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We want to introduce a new version of qemu_open() that uses an Error object for reporting problems and make this it the preferred interface. Rename the existing method to release the namespace for the new impl. Reviewed-by: Eric Blake Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Markus Armbruster Signed-off-by: Daniel P. Berrangé --- include/qemu/osdep.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index 66ee5bc..ae12341 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -497,7 +497,7 @@ int qemu_madvise(void *addr, size_t len, int advice); int qemu_mprotect_rwx(void *addr, size_t size); int qemu_mprotect_none(void *addr, size_t size); -int qemu_open(const char *name, int flags, ...); +int qemu_open_old(const char *name, int flags, ...); int qemu_close(int fd); int qemu_unlink(const char *name); #ifndef _WIN32 -- cgit v1.1 From c490af57cb451bf39707f4cc73650e81c5797221 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Date: Wed, 1 Jul 2020 16:30:35 +0100 Subject: util: introduce qemu_open and qemu_create with error reporting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit qemu_open_old() works like open(): set errno and return -1 on failure. It has even more failure modes, though. Reporting the error clearly to users is basically impossible for many of them. Our standard cure for "errno is too coarse" is the Error object. Introduce two new helper methods: int qemu_open(const char *name, int flags, Error **errp); int qemu_create(const char *name, int flags, mode_t mode, Error **errp); Note that with this design we no longer require or even accept the O_CREAT flag. Avoiding overloading the two distinct operations means we can avoid variable arguments which would prevent 'errp' from being the last argument. It also gives us a guarantee that the 'mode' is given when creating files, avoiding a latent security bug. Reviewed-by: Markus Armbruster Signed-off-by: Daniel P. Berrangé --- include/qemu/osdep.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'include') diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index ae12341..577d9e8 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -497,7 +497,13 @@ int qemu_madvise(void *addr, size_t len, int advice); int qemu_mprotect_rwx(void *addr, size_t size); int qemu_mprotect_none(void *addr, size_t size); +/* + * Don't introduce new usage of this function, prefer the following + * qemu_open/qemu_create that take an "Error **errp" + */ int qemu_open_old(const char *name, int flags, ...); +int qemu_open(const char *name, int flags, Error **errp); +int qemu_create(const char *name, int flags, mode_t mode, Error **errp); int qemu_close(int fd); int qemu_unlink(const char *name); #ifndef _WIN32 -- cgit v1.1