* [Qemu-devel] [PATCH] net: provide a friendly message when a user passes a bad -net tap, fd=X
@ 2010-10-08 22:04 Anthony Liguori
2010-10-08 23:28 ` Alexander Graf
2010-10-11 9:45 ` [Qemu-devel] " Daniel P. Berrange
0 siblings, 2 replies; 4+ messages in thread
From: Anthony Liguori @ 2010-10-08 22:04 UTC (permalink / raw)
To: qemu-devel; +Cc: Anthony Liguori
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>
diff --git a/hw/usb-uhci.c b/hw/usb-uhci.c
index 1d83400..5f9f749 100644
--- a/hw/usb-uhci.c
+++ b/hw/usb-uhci.c
@@ -64,7 +64,7 @@
#define UHCI_PORT_CSC (1 << 1)
#define UHCI_PORT_CCS (1 << 0)
-#define FRAME_TIMER_FREQ 1000
+#define FRAME_TIMER_FREQ 500
#define FRAME_MAX_LOOPS 100
@@ -1054,7 +1054,7 @@ static void uhci_frame_timer(void *opaque)
UHCIState *s = opaque;
/* prepare the timer for the next frame */
- s->expire_time += (get_ticks_per_sec() / FRAME_TIMER_FREQ);
+ s->expire_time = qemu_get_clock(vm_clock) + (get_ticks_per_sec() / FRAME_TIMER_FREQ);
if (!(s->cmd & UHCI_CMD_RS)) {
/* Full stop */
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;
+ }
+
fcntl(fd, F_SETFL, O_NONBLOCK);
vnet_hdr = tap_probe_vnet_hdr(fd);
--
1.7.0.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] net: provide a friendly message when a user passes a bad -net tap, fd=X
2010-10-08 22:04 [Qemu-devel] [PATCH] net: provide a friendly message when a user passes a bad -net tap, fd=X Anthony Liguori
@ 2010-10-08 23:28 ` Alexander Graf
2010-10-08 23:36 ` Anthony Liguori
2010-10-11 9:45 ` [Qemu-devel] " Daniel P. Berrange
1 sibling, 1 reply; 4+ messages in thread
From: Alexander Graf @ 2010-10-08 23:28 UTC (permalink / raw)
To: Anthony Liguori; +Cc: qemu-devel
On 09.10.2010, at 00:04, Anthony Liguori 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>
>
> diff --git a/hw/usb-uhci.c b/hw/usb-uhci.c
> index 1d83400..5f9f749 100644
> --- a/hw/usb-uhci.c
> +++ b/hw/usb-uhci.c
> @@ -64,7 +64,7 @@
> #define UHCI_PORT_CSC (1 << 1)
> #define UHCI_PORT_CCS (1 << 0)
>
> -#define FRAME_TIMER_FREQ 1000
> +#define FRAME_TIMER_FREQ 500
>
> #define FRAME_MAX_LOOPS 100
>
> @@ -1054,7 +1054,7 @@ static void uhci_frame_timer(void *opaque)
> UHCIState *s = opaque;
>
> /* prepare the timer for the next frame */
> - s->expire_time += (get_ticks_per_sec() / FRAME_TIMER_FREQ);
> + s->expire_time = qemu_get_clock(vm_clock) + (get_ticks_per_sec() / FRAME_TIMER_FREQ);
How exactly is this related?
Alex
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] net: provide a friendly message when a user passes a bad -net tap, fd=X
2010-10-08 23:28 ` Alexander Graf
@ 2010-10-08 23:36 ` Anthony Liguori
0 siblings, 0 replies; 4+ messages in thread
From: Anthony Liguori @ 2010-10-08 23:36 UTC (permalink / raw)
To: Alexander Graf; +Cc: qemu-devel
On 10/08/2010 06:28 PM, Alexander Graf wrote:
> On 09.10.2010, at 00:04, Anthony Liguori 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>
>>
>> diff --git a/hw/usb-uhci.c b/hw/usb-uhci.c
>> index 1d83400..5f9f749 100644
>> --- a/hw/usb-uhci.c
>> +++ b/hw/usb-uhci.c
>> @@ -64,7 +64,7 @@
>> #define UHCI_PORT_CSC (1<< 1)
>> #define UHCI_PORT_CCS (1<< 0)
>>
>> -#define FRAME_TIMER_FREQ 1000
>> +#define FRAME_TIMER_FREQ 500
>>
>> #define FRAME_MAX_LOOPS 100
>>
>> @@ -1054,7 +1054,7 @@ static void uhci_frame_timer(void *opaque)
>> UHCIState *s = opaque;
>>
>> /* prepare the timer for the next frame */
>> - s->expire_time += (get_ticks_per_sec() / FRAME_TIMER_FREQ);
>> + s->expire_time = qemu_get_clock(vm_clock) + (get_ticks_per_sec() / FRAME_TIMER_FREQ);
>>
> How exactly is this related?
>
So, didn't have a clean working directory.
Regards,
Anthony Liguori
> Alex
>
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Qemu-devel] Re: [PATCH] net: provide a friendly message when a user passes a bad -net tap, fd=X
2010-10-08 22:04 [Qemu-devel] [PATCH] net: provide a friendly message when a user passes a bad -net tap, fd=X Anthony Liguori
2010-10-08 23:28 ` Alexander Graf
@ 2010-10-11 9:45 ` Daniel P. Berrange
1 sibling, 0 replies; 4+ messages in thread
From: Daniel P. Berrange @ 2010-10-11 9:45 UTC (permalink / raw)
To: Anthony Liguori; +Cc: qemu-devel
On Fri, Oct 08, 2010 at 05:04:56PM -0500, Anthony Liguori 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>
>
> diff --git a/hw/usb-uhci.c b/hw/usb-uhci.c
> index 1d83400..5f9f749 100644
> --- a/hw/usb-uhci.c
> +++ b/hw/usb-uhci.c
> @@ -64,7 +64,7 @@
> #define UHCI_PORT_CSC (1 << 1)
> #define UHCI_PORT_CCS (1 << 0)
>
> -#define FRAME_TIMER_FREQ 1000
> +#define FRAME_TIMER_FREQ 500
>
> #define FRAME_MAX_LOOPS 100
>
> @@ -1054,7 +1054,7 @@ static void uhci_frame_timer(void *opaque)
> UHCIState *s = opaque;
>
> /* prepare the timer for the next frame */
> - s->expire_time += (get_ticks_per_sec() / FRAME_TIMER_FREQ);
> + s->expire_time = qemu_get_clock(vm_clock) + (get_ticks_per_sec() / FRAME_TIMER_FREQ);
>
> if (!(s->cmd & UHCI_CMD_RS)) {
> /* Full stop */
> 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");
It is just 'domxml-to-native' - no '2' in there.
Should it check for EBADF explicitly ? I guess this is the only errno that
can really happen here, but I always prefer strict checks myself.
Regards,
Daniel
--
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-10-11 9:45 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-08 22:04 [Qemu-devel] [PATCH] net: provide a friendly message when a user passes a bad -net tap, fd=X Anthony Liguori
2010-10-08 23:28 ` Alexander Graf
2010-10-08 23:36 ` Anthony Liguori
2010-10-11 9:45 ` [Qemu-devel] " Daniel P. Berrange
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).