Skip to contentSkip to conversation

net: clean up network at qemu process termination

PATCH Superseded Amos Kong 3 participants 5 messages Dec 11, 2012 – Dec 18, 2012

lore
Share & tools
lore

Amos Kong

author
#0 lore raw

PATCH 1/1 net: clean up network at qemu process termination

We don't clean up network if fails to parse "-device" parameters without calling net_cleanup(). I touch a problem, the tap device which is created by qemu-ifup script could not be removed by qemu-ifdown script. Some similar problems also exist in vl.c

In this patch, if network initialization successes, a cleanup function will be registered to be called at qemu process termination.

---
 vl.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
vl.c +3 -1
index a3ab384..842f987 100644
@@ -3749,6 +3749,9 @@ int main(int argc, char **argv, char **envp)
         exit(1);
     }
 
+    /* clean up network at qemu process termination */
+    atexit(&net_cleanup);
+
     /* init the bluetooth world */
     if (foreach_device_config(DEV_BT, bt_parse))
         exit(1);
@@ -3999,7 +4002,6 @@ int main(int argc, char **argv, char **envp)
     main_loop();
     bdrv_close_all();
     pause_all_vcpus();
-    net_cleanup();
     res_free();
 
     return 0;
Signature · 1 line
1.7.1
#1 lore raw
Quoted 9 lines · Amos Kong

We don't clean up network if fails to parse "-device" parameters without calling net_cleanup(). I touch a problem, the tap device which is created by qemu-ifup script could not be removed by qemu-ifdown script. Some similar problems also exist in vl.c

In this patch, if network initialization successes, a cleanup function will be registered to be called at qemu process termination.

If there are multiple net clients, this still leaves the problem where one client is initialized, the second one fails, and we exit without ifdown.

I think registering before net_init_clients will fix this case but please do test.

Quoted 28 lines
---
 vl.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
vl.c +3 -1
index a3ab384..842f987 100644
@@ -3749,6 +3749,9 @@ int main(int argc, char **argv, char **envp)
         exit(1);
     }
 
+    /* clean up network at qemu process termination */
+    atexit(&net_cleanup);
+
     /* init the bluetooth world */
     if (foreach_device_config(DEV_BT, bt_parse))
         exit(1);
@@ -3999,7 +4002,6 @@ int main(int argc, char **argv, char **envp)
     main_loop();
     bdrv_close_all();
     pause_all_vcpus();
-    net_cleanup();
     res_free();
 
     return 0;
Signature · 1 line
1.7.1
author
#2 lore raw

PATCH v2 1/1 net: clean up network at qemu process termination

In reply to Amos Kong

We don't clean up network if fails to parse "-device" parameters without calling net_cleanup(). I touch a problem, the tap device which is created by qemu-ifup script could not be removed by qemu-ifdown script. Some similar problems also exist in vl.c

In this patch, if network initialization successes, a cleanup function will be registered to be called at qemu process termination.

---
v2: register cleanup function before network initialization

---
 vl.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
vl.c +3 -1
index a3ab384..3bd773e 100644
@@ -3745,6 +3745,9 @@ int main(int argc, char **argv, char **envp)
     }
     configure_icount(icount_option);
 
+    /* clean up network at qemu process termination */
+    atexit(&net_cleanup);
+
     if (net_init_clients() < 0) {
         exit(1);
     }
@@ -3999,7 +4002,6 @@ int main(int argc, char **argv, char **envp)
     main_loop();
     bdrv_close_all();
     pause_all_vcpus();
-    net_cleanup();
     res_free();
 
     return 0;
Signature · 1 line
1.7.1
Acked-by on v2 1/1
#3 lore raw
Quoted 9 lines · Amos Kong

We don't clean up network if fails to parse "-device" parameters without calling net_cleanup(). I touch a problem, the tap device which is created by qemu-ifup script could not be removed by qemu-ifdown script. Some similar problems also exist in vl.c

In this patch, if network initialization successes, a cleanup function will be registered to be called at qemu process termination.

Quoted 30 lines

---
v2: register cleanup function before network initialization

---
 vl.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
vl.c +3 -1
index a3ab384..3bd773e 100644
@@ -3745,6 +3745,9 @@ int main(int argc, char **argv, char **envp)
     }
     configure_icount(icount_option);
 
+    /* clean up network at qemu process termination */
+    atexit(&net_cleanup);
+
     if (net_init_clients() < 0) {
         exit(1);
     }
@@ -3999,7 +4002,6 @@ int main(int argc, char **argv, char **envp)
     main_loop();
     bdrv_close_all();
     pause_all_vcpus();
-    net_cleanup();
     res_free();
 
     return 0;
Signature · 1 line
1.7.1
#4 lore raw
In reply to Amos Kong
Quoted 8 lines · Amos Kong

We don't clean up network if fails to parse "-device" parameters without calling net_cleanup(). I touch a problem, the tap device which is created by qemu-ifup script could not be removed by qemu-ifdown script. Some similar problems also exist in vl.c

In this patch, if network initialization successes, a cleanup function will be registered to be called at qemu process termination.

Quoted 6 lines

---
v2: register cleanup function before network initialization

---
 vl.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

Thanks, applied to the net tree:
https://github.com/stefanha/qemu/commits/net

Stefan