qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] Network isn't clean when qemu exits
@ 2012-12-11  5:57 Amos Kong
  2012-12-11  8:38 ` Stefan Hajnoczi
  0 siblings, 1 reply; 3+ messages in thread
From: Amos Kong @ 2012-12-11  5:57 UTC (permalink / raw)
  To: Qemu Devel Mail List, Stefan Hajnoczi; +Cc: mst

In vl.c:main(), tap device would be created when net_init_clients() is called.
"device" option is parsed after calling net_init_clients() by:
# "qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL, 1)

Qemu will exit 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.

I did a quick fix, the tap device should be removed.

But there are many "exit(1)" after calling net_init_clients() in vl.c,
it's ugly to call net_cleanup() before each exit. Not sure if we have
other exit(1) in other sub-functions, which is also called after calling
net_init_clients().

Any comments?

=====
@@ -3882,8 +3889,11 @@ int main(int argc, char **argv, char **envp)
     }

     /* init generic devices */
-    if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func,
     NULL, 1) != 0)
+    if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func,
+                          NULL, 1) != 0) {
+        net_cleanup();
         exit(1);
+    }

-- 
		Amos.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] Network isn't clean when qemu exits
  2012-12-11  5:57 [Qemu-devel] Network isn't clean when qemu exits Amos Kong
@ 2012-12-11  8:38 ` Stefan Hajnoczi
  2012-12-11 13:02   ` Michael S. Tsirkin
  0 siblings, 1 reply; 3+ messages in thread
From: Stefan Hajnoczi @ 2012-12-11  8:38 UTC (permalink / raw)
  To: Amos Kong; +Cc: Qemu Devel Mail List, mst

On Tue, Dec 11, 2012 at 01:57:04PM +0800, Amos Kong wrote:
> In vl.c:main(), tap device would be created when net_init_clients() is called.
> "device" option is parsed after calling net_init_clients() by:
> # "qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL, 1)
> 
> Qemu will exit 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.
> 
> I did a quick fix, the tap device should be removed.
> 
> But there are many "exit(1)" after calling net_init_clients() in vl.c,
> it's ugly to call net_cleanup() before each exit. Not sure if we have
> other exit(1) in other sub-functions, which is also called after calling
> net_init_clients().
> 
> Any comments?
> 
> =====
> @@ -3882,8 +3889,11 @@ int main(int argc, char **argv, char **envp)
>      }
> 
>      /* init generic devices */
> -    if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func,
>      NULL, 1) != 0)
> +    if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func,
> +                          NULL, 1) != 0) {
> +        net_cleanup();
>          exit(1);
> +    }

How about qemu_add_exit_notifier() or atexit(3)?  Several other places
in QEMU use this to clean up.

Then you can also remove net_cleanup() from the end of vl.c:main() since
it gets called implicitly.

Stefan

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] Network isn't clean when qemu exits
  2012-12-11  8:38 ` Stefan Hajnoczi
@ 2012-12-11 13:02   ` Michael S. Tsirkin
  0 siblings, 0 replies; 3+ messages in thread
From: Michael S. Tsirkin @ 2012-12-11 13:02 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: Amos Kong, Qemu Devel Mail List

On Tue, Dec 11, 2012 at 09:38:43AM +0100, Stefan Hajnoczi wrote:
> On Tue, Dec 11, 2012 at 01:57:04PM +0800, Amos Kong wrote:
> > In vl.c:main(), tap device would be created when net_init_clients() is called.
> > "device" option is parsed after calling net_init_clients() by:
> > # "qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL, 1)
> > 
> > Qemu will exit 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.
> > 
> > I did a quick fix, the tap device should be removed.
> > 
> > But there are many "exit(1)" after calling net_init_clients() in vl.c,
> > it's ugly to call net_cleanup() before each exit. Not sure if we have
> > other exit(1) in other sub-functions, which is also called after calling
> > net_init_clients().
> > 
> > Any comments?
> > 
> > =====
> > @@ -3882,8 +3889,11 @@ int main(int argc, char **argv, char **envp)
> >      }
> > 
> >      /* init generic devices */
> > -    if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func,
> >      NULL, 1) != 0)
> > +    if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func,
> > +                          NULL, 1) != 0) {
> > +        net_cleanup();
> >          exit(1);
> > +    }
> 
> How about qemu_add_exit_notifier() or atexit(3)?  Several other places
> in QEMU use this to clean up.
> 
> Then you can also remove net_cleanup() from the end of vl.c:main() since
> it gets called implicitly.
> 
> Stefan

Good idea, thanks a lot.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-12-11 12:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-11  5:57 [Qemu-devel] Network isn't clean when qemu exits Amos Kong
2012-12-11  8:38 ` Stefan Hajnoczi
2012-12-11 13:02   ` Michael S. Tsirkin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).