mirror of
https://gitlab.com/qemu-project/qemu
synced 2024-09-06 18:05:37 +00:00
monitor: Drop monitor_fdset_dup_fd_find/_remove()
Those functions are not needed, one remove function should already work. Clean it up. Here the code doesn't really care about whether we need to keep that dupfd around if close() failed: when that happens something got very wrong, keeping the dup_fd around the fdsets may not help that situation so far. Cc: Dr. David Alan Gilbert <dave@treblig.org> Cc: Markus Armbruster <armbru@redhat.com> Cc: Philippe Mathieu-Daudé <philmd@linaro.org> Cc: Paolo Bonzini <pbonzini@redhat.com> Cc: Daniel P. Berrangé <berrange@redhat.com> Signed-off-by: Peter Xu <peterx@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> [add missing return statement, removal during traversal is not safe] Signed-off-by: Fabiano Rosas <farosas@suse.de>
This commit is contained in:
parent
926554c0bf
commit
1cd93fb0bf
|
@ -53,7 +53,6 @@ AddfdInfo *monitor_fdset_add_fd(int fd, bool has_fdset_id, int64_t fdset_id,
|
||||||
const char *opaque, Error **errp);
|
const char *opaque, Error **errp);
|
||||||
int monitor_fdset_dup_fd_add(int64_t fdset_id, int flags);
|
int monitor_fdset_dup_fd_add(int64_t fdset_id, int flags);
|
||||||
void monitor_fdset_dup_fd_remove(int dup_fd);
|
void monitor_fdset_dup_fd_remove(int dup_fd);
|
||||||
int64_t monitor_fdset_dup_fd_find(int dup_fd);
|
|
||||||
|
|
||||||
void monitor_register_hmp(const char *name, bool info,
|
void monitor_register_hmp(const char *name, bool info,
|
||||||
void (*cmd)(Monitor *mon, const QDict *qdict));
|
void (*cmd)(Monitor *mon, const QDict *qdict));
|
||||||
|
|
|
@ -458,7 +458,7 @@ int monitor_fdset_dup_fd_add(int64_t fdset_id, int flags)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static int64_t monitor_fdset_dup_fd_find_remove(int dup_fd, bool remove)
|
void monitor_fdset_dup_fd_remove(int dup_fd)
|
||||||
{
|
{
|
||||||
MonFdset *mon_fdset;
|
MonFdset *mon_fdset;
|
||||||
MonFdsetFd *mon_fdset_fd_dup;
|
MonFdsetFd *mon_fdset_fd_dup;
|
||||||
|
@ -467,31 +467,15 @@ static int64_t monitor_fdset_dup_fd_find_remove(int dup_fd, bool remove)
|
||||||
QLIST_FOREACH(mon_fdset, &mon_fdsets, next) {
|
QLIST_FOREACH(mon_fdset, &mon_fdsets, next) {
|
||||||
QLIST_FOREACH(mon_fdset_fd_dup, &mon_fdset->dup_fds, next) {
|
QLIST_FOREACH(mon_fdset_fd_dup, &mon_fdset->dup_fds, next) {
|
||||||
if (mon_fdset_fd_dup->fd == dup_fd) {
|
if (mon_fdset_fd_dup->fd == dup_fd) {
|
||||||
if (remove) {
|
QLIST_REMOVE(mon_fdset_fd_dup, next);
|
||||||
QLIST_REMOVE(mon_fdset_fd_dup, next);
|
g_free(mon_fdset_fd_dup);
|
||||||
g_free(mon_fdset_fd_dup);
|
if (QLIST_EMPTY(&mon_fdset->dup_fds)) {
|
||||||
if (QLIST_EMPTY(&mon_fdset->dup_fds)) {
|
monitor_fdset_cleanup(mon_fdset);
|
||||||
monitor_fdset_cleanup(mon_fdset);
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
} else {
|
|
||||||
return mon_fdset->id;
|
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int64_t monitor_fdset_dup_fd_find(int dup_fd)
|
|
||||||
{
|
|
||||||
return monitor_fdset_dup_fd_find_remove(dup_fd, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void monitor_fdset_dup_fd_remove(int dup_fd)
|
|
||||||
{
|
|
||||||
monitor_fdset_dup_fd_find_remove(dup_fd, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int monitor_fd_param(Monitor *mon, const char *fdname, Error **errp)
|
int monitor_fd_param(Monitor *mon, const char *fdname, Error **errp)
|
||||||
|
|
|
@ -9,11 +9,6 @@ int monitor_fdset_dup_fd_add(int64_t fdset_id, int flags)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t monitor_fdset_dup_fd_find(int dup_fd)
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void monitor_fdset_dup_fd_remove(int dupfd)
|
void monitor_fdset_dup_fd_remove(int dupfd)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
15
util/osdep.c
15
util/osdep.c
|
@ -398,21 +398,8 @@ int qemu_open_old(const char *name, int flags, ...)
|
||||||
|
|
||||||
int qemu_close(int fd)
|
int qemu_close(int fd)
|
||||||
{
|
{
|
||||||
int64_t fdset_id;
|
|
||||||
|
|
||||||
/* Close fd that was dup'd from an fdset */
|
/* Close fd that was dup'd from an fdset */
|
||||||
fdset_id = monitor_fdset_dup_fd_find(fd);
|
monitor_fdset_dup_fd_remove(fd);
|
||||||
if (fdset_id != -1) {
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
ret = close(fd);
|
|
||||||
if (ret == 0) {
|
|
||||||
monitor_fdset_dup_fd_remove(fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
return close(fd);
|
return close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue