qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jason Wang <jasowang@redhat.com>
To: Anthony Liguori <aliguori@us.ibm.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] net: provide a friendly message when a user passes a bad -net tap, fd=X (v2)
Date: Tue, 12 Oct 2010 02:41:49 -0400 (EDT)	[thread overview]
Message-ID: <858043178.170041286865709512.JavaMail.root@zmail05.collab.prod.int.phx2.redhat.com> (raw)
In-Reply-To: <1784739024.170001286865606278.JavaMail.root@zmail05.collab.prod.int.phx2.redhat.com>


----- "Anthony Liguori" <aliguori@us.ibm.com> wrote:

> A lot of people copy libvirt's command line from ps -ef and then
> wonder why the
> VM isn't working correctly.  Let's be kind and tell them what they
> should do
> instead.
> 
> Without this patch, if you run with an invalid -net tap,fd=X, the
> guest still
> runs and we poll 100% on a bad file descriptor.  With this patch, you
> get:
> 
>  qemu: -net tap,fd=42: invalid fd= for tap network device.  If you're
> copying
>  from libvirt, use `virsh dom2xml-to-native' instead
>  qemu: -net tap,fd=42: Device 'tap' could not be initialized
> 
> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
> ---
> v1 -> v2
>  - Remove garbage from unclean commit (spotted by Alex Graf)
> 
> diff --git a/net/tap.c b/net/tap.c
> index 0147dab..45b1fb6 100644
> --- a/net/tap.c
> +++ b/net/tap.c
> @@ -405,6 +405,8 @@ int net_init_tap(QemuOpts *opts, Monitor *mon,
> const char *name, VLANState *vlan
>      int fd, vnet_hdr = 0;
>  
>      if (qemu_opt_get(opts, "fd")) {
> +        int flags;
> +
>          if (qemu_opt_get(opts, "ifname") ||
>              qemu_opt_get(opts, "script") ||
>              qemu_opt_get(opts, "downscript") ||
> @@ -418,6 +420,11 @@ int net_init_tap(QemuOpts *opts, Monitor *mon,
> const char *name, VLANState *vlan
>              return -1;
>          }
>  
> +        if (fcntl(fd, F_GETFL, &flags) == -1) {
> +            error_report("invalid fd= for tap network device.  If
> you're copying from libvirt, use `virsh dom2xml-to-native' instead");
> +            return -1;
> +        }
> +

Maybe we can use TUNGETFEATURES here to verify whether fd is a tap here?

>          fcntl(fd, F_SETFL, O_NONBLOCK);
>  
>          vnet_hdr = tap_probe_vnet_hdr(fd);
> -- 
> 1.7.0.4

       reply	other threads:[~2010-10-12  6:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1784739024.170001286865606278.JavaMail.root@zmail05.collab.prod.int.phx2.redhat.com>
2010-10-12  6:41 ` Jason Wang [this message]
2010-10-08 23:38 [Qemu-devel] [PATCH] net: provide a friendly message when a user passes a bad -net tap, fd=X (v2) Anthony Liguori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=858043178.170041286865709512.JavaMail.root@zmail05.collab.prod.int.phx2.redhat.com \
    --to=jasowang@redhat.com \
    --cc=aliguori@us.ibm.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).