Skip to contentSkip to conversation

monitor: Prevent removing fd from set during init

PATCH Superseded Corey Bryant 2 participants 3 messages Oct 16, 2012 – Oct 18, 2012

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 3/4 monitor: Prevent removing fd from set during init

If an fd is added to an fd set via the command line, and it is not referenced by another command line option (ie. -drive), then clean it up after QEMU initialization is complete.

---
v3:
- This patch was split into it's own patch in v3 ([email protected], [email protected])

 monitor.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
monitor.c +3 -2
index 5d5de41..0dae7ac 100644
@@ -2105,8 +2105,9 @@ static void monitor_fdset_cleanup(MonFdset *mon_fdset)
     MonFdsetFd *mon_fdset_fd_next;
 
     QLIST_FOREACH_SAFE(mon_fdset_fd, &mon_fdset->fds, next, mon_fdset_fd_next) {
-        if (mon_fdset_fd->removed ||
-                (QLIST_EMPTY(&mon_fdset->dup_fds) && mon_refcount == 0)) {
+        if ((mon_fdset_fd->removed ||
+                (QLIST_EMPTY(&mon_fdset->dup_fds) && mon_refcount == 0)) &&
+                runstate_is_running()) {
             close(mon_fdset_fd->fd);
             g_free(mon_fdset_fd->opaque);
             QLIST_REMOVE(mon_fdset_fd, next);
Signature · 1 line
1.7.11.4
Reviewed-by on v3 3/4
#1 lore raw
Quoted 4 lines · Corey Bryant

If an fd is added to an fd set via the command line, and it is not referenced by another command line option (ie. -drive), then clean it up after QEMU initialization is complete.

Quoted 8 lines

---
v3:
- This patch was split into it's own patch in v3 ([email protected], [email protected])

 monitor.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
Quoted 6 lines
monitor.c +0 -0
index 5d5de41..0dae7ac 100644

monitor.c static void monitor_fdset_cleanup(MonFdset *mon_fdset) · line 2110

Quoted 8 lines
monitor.c +3 -2
@@ -2105,8 +2105,9 @@ static void monitor_fdset_cleanup(MonFdset *mon_fdset)
     MonFdsetFd *mon_fdset_fd_next;
 
     QLIST_FOREACH_SAFE(mon_fdset_fd, &mon_fdset->fds, next, mon_fdset_fd_next) {
-        if (mon_fdset_fd->removed ||
-                (QLIST_EMPTY(&mon_fdset->dup_fds) && mon_refcount == 0)) {
+        if ((mon_fdset_fd->removed ||
+                (QLIST_EMPTY(&mon_fdset->dup_fds) && mon_refcount == 0)) &&
+                runstate_is_running()) {

This condition looks sufficient for command line parsing; however, I have to wonder if there are any long-term ill effects, such as if I pause a guest, then close an fdset, where qemu keeps the fd open until I continue the guest. But thinking a bit more, we never promised that qemu would close fds right away, but only that it wouldn't leak fds by closing them whenever qemu thinks it is convenient.

Quoted 4 lines
monitor.c +0 -0
             close(mon_fdset_fd->fd);
             g_free(mon_fdset_fd->opaque);
             QLIST_REMOVE(mon_fdset_fd, next);
Signature · 2 lines
Eric Blake   [email protected]    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#2 lore raw
Quoted 11 lines · Eric Blake
Quoted 10 lines · Corey Bryant

If an fd is added to an fd set via the command line, and it is not referenced by another command line option (ie. -drive), then clean it up after QEMU initialization is complete.

---
v3:
- This patch was split into it's own patch in v3 ([email protected], [email protected])

Quoted 5 lines
Quoted 2 lines
  monitor.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)

Thanks!

Quoted 8 lines
Quoted 8 lines
monitor.c +0 -0
index 5d5de41..0dae7ac 100644
@@ -2105,8 +2105,9 @@ static void monitor_fdset_cleanup(MonFdset *mon_fdset)
      MonFdsetFd *mon_fdset_fd_next;
 
Quoted 14 lines

monitor.c static void monitor_fdset_cleanup(MonFdset *mon_fdset) · line 2110

Quoted 6 lines
monitor.c +3 -2
      QLIST_FOREACH_SAFE(mon_fdset_fd, &mon_fdset->fds, next, mon_fdset_fd_next) {
-        if (mon_fdset_fd->removed ||
-                (QLIST_EMPTY(&mon_fdset->dup_fds) && mon_refcount == 0)) {
+        if ((mon_fdset_fd->removed ||
+                (QLIST_EMPTY(&mon_fdset->dup_fds) && mon_refcount == 0)) &&
+                runstate_is_running()) {

This condition looks sufficient for command line parsing; however, I have to wonder if there are any long-term ill effects, such as if I pause a guest, then close an fdset, where qemu keeps the fd open until I continue the guest. But thinking a bit more, we never promised that qemu would close fds right away, but only that it wouldn't leak fds by closing them whenever qemu thinks it is convenient.

I can't think of any ill effects. I think you may be able to remove an fd or fd set followed by adding a drive using that fd set, but that is just a difference in behavior compared to when a guest is running.

Quoted 5 lines
Quoted 4 lines
monitor.c +0 -0
              close(mon_fdset_fd->fd);
              g_free(mon_fdset_fd->opaque);
              QLIST_REMOVE(mon_fdset_fd, next);
Signature · 2 lines
Regards,
Corey Bryant