* [Qemu-devel] [PATCH] hw/usb/bus.c: print device ID when 'info usb' used
@ 2015-08-24 19:13 Programmingkid
2015-08-28 11:50 ` Gerd Hoffmann
0 siblings, 1 reply; 10+ messages in thread
From: Programmingkid @ 2015-08-24 19:13 UTC (permalink / raw)
To: Gerd Hoffmann, qemu-devel qemu-devel
[-- Attachment #1: Type: text/plain, Size: 1586 bytes --]
Print the ID of each device when 'info usb' is used in the monitor.
Signed-off-by: John Arbuckle <programmingkidx@gmail.com>
---
This patch is easier to test when the qdev-monitor.c patch I
also submitted is applied first. It can still be tested without
it. Just run QEMU with the -usb option. Then go to the monitor
and type "device_add usb-mouse,id=mouse-one". You will see the
ID printed with the usb-mouse's info when you type 'info usb'.
The ID is used by device_del to remove a device from QEMU. With
this patch, the user can actually see the ID of the usb device
making it possible to actually pick the right device to remove.
hw/usb/bus.c | 8 +++++---
1 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/hw/usb/bus.c b/hw/usb/bus.c
index 5f39e1e..d2a726c 100644
--- a/hw/usb/bus.c
+++ b/hw/usb/bus.c
@@ -655,9 +655,11 @@ void hmp_info_usb(Monitor *mon, const QDict *qdict)
dev = port->dev;
if (!dev)
continue;
- monitor_printf(mon, " Device %d.%d, Port %s, Speed %s Mb/s, Product %s\n",
- bus->busnr, dev->addr, port->path, usb_speed(dev->speed),
- dev->product_desc);
+ monitor_printf(mon, " Device %d.%d, Port %s, Speed %s Mb/s,"
+ "Product %s, ID %s\n",
+ bus->busnr, dev->addr, port->path,
+ usb_speed(dev->speed),
+ dev->product_desc, dev->qdev.id);
}
}
}
--
1.7.5.4
[-- Attachment #2: Type: text/html, Size: 8092 bytes --]
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] [PATCH] hw/usb/bus.c: print device ID when 'info usb' used
2015-08-24 19:13 [Qemu-devel] [PATCH] hw/usb/bus.c: print device ID when 'info usb' used Programmingkid
@ 2015-08-28 11:50 ` Gerd Hoffmann
2015-08-28 13:08 ` Programmingkid
0 siblings, 1 reply; 10+ messages in thread
From: Gerd Hoffmann @ 2015-08-28 11:50 UTC (permalink / raw)
To: Programmingkid; +Cc: qemu-devel qemu-devel
On Mo, 2015-08-24 at 15:13 -0400, Programmingkid wrote:
> + monitor_printf(mon, " Device %d.%d, Port %s, Speed %s
> Mb/s,"
> + "Product %s, ID %s\n",
> + bus->busnr, dev->addr, port->path,
> + usb_speed(dev->speed),
> + dev->product_desc, dev->qdev.id);
>
dev->qdev.id can be NULL.
cheers,
Gerd
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] [PATCH] hw/usb/bus.c: print device ID when 'info usb' used
2015-08-28 11:50 ` Gerd Hoffmann
@ 2015-08-28 13:08 ` Programmingkid
2015-08-28 13:35 ` Daniel P. Berrange
0 siblings, 1 reply; 10+ messages in thread
From: Programmingkid @ 2015-08-28 13:08 UTC (permalink / raw)
To: Gerd Hoffmann; +Cc: qemu-devel qemu-devel
On Aug 28, 2015, at 7:50 AM, Gerd Hoffmann wrote:
> On Mo, 2015-08-24 at 15:13 -0400, Programmingkid wrote:
>> + monitor_printf(mon, " Device %d.%d, Port %s, Speed %s
>> Mb/s,"
>> + "Product %s, ID %s\n",
>> + bus->busnr, dev->addr, port->path,
>> + usb_speed(dev->speed),
>> + dev->product_desc, dev->qdev.id);
>>
>
> dev->qdev.id can be NULL.
>
> cheers,
> Gerd
That isn't a problem. It will just say "null" when it is printed. No crash or garbage text.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] [PATCH] hw/usb/bus.c: print device ID when 'info usb' used
2015-08-28 13:08 ` Programmingkid
@ 2015-08-28 13:35 ` Daniel P. Berrange
2015-08-28 13:39 ` Programmingkid
0 siblings, 1 reply; 10+ messages in thread
From: Daniel P. Berrange @ 2015-08-28 13:35 UTC (permalink / raw)
To: Programmingkid; +Cc: Gerd Hoffmann, qemu-devel qemu-devel
On Fri, Aug 28, 2015 at 09:08:12AM -0400, Programmingkid wrote:
>
> On Aug 28, 2015, at 7:50 AM, Gerd Hoffmann wrote:
>
> > On Mo, 2015-08-24 at 15:13 -0400, Programmingkid wrote:
> >> + monitor_printf(mon, " Device %d.%d, Port %s, Speed %s
> >> Mb/s,"
> >> + "Product %s, ID %s\n",
> >> + bus->busnr, dev->addr, port->path,
> >> + usb_speed(dev->speed),
> >> + dev->product_desc, dev->qdev.id);
> >>
> >
> > dev->qdev.id can be NULL.
> >
> > cheers,
> > Gerd
>
> That isn't a problem. It will just say "null" when it is printed.
> No crash or garbage text.
Handling of '%s' with NULL is undefined by the standard. Linux
glibc prints the string "null", but other implementations can
crash.
Regards,
Daniel
--
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org -o- http://virt-manager.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] [PATCH] hw/usb/bus.c: print device ID when 'info usb' used
2015-08-28 13:35 ` Daniel P. Berrange
@ 2015-08-28 13:39 ` Programmingkid
2015-08-28 13:50 ` Daniel P. Berrange
2015-08-28 13:50 ` Gerd Hoffmann
0 siblings, 2 replies; 10+ messages in thread
From: Programmingkid @ 2015-08-28 13:39 UTC (permalink / raw)
To: Daniel P. Berrange; +Cc: Gerd Hoffmann, qemu-devel qemu-devel
On Aug 28, 2015, at 9:35 AM, Daniel P. Berrange wrote:
> On Fri, Aug 28, 2015 at 09:08:12AM -0400, Programmingkid wrote:
>>
>> On Aug 28, 2015, at 7:50 AM, Gerd Hoffmann wrote:
>>
>>> On Mo, 2015-08-24 at 15:13 -0400, Programmingkid wrote:
>>>> + monitor_printf(mon, " Device %d.%d, Port %s, Speed %s
>>>> Mb/s,"
>>>> + "Product %s, ID %s\n",
>>>> + bus->busnr, dev->addr, port->path,
>>>> + usb_speed(dev->speed),
>>>> + dev->product_desc, dev->qdev.id);
>>>>
>>>
>>> dev->qdev.id can be NULL.
>>>
>>> cheers,
>>> Gerd
>>
>> That isn't a problem. It will just say "null" when it is printed.
>> No crash or garbage text.
>
> Handling of '%s' with NULL is undefined by the standard. Linux
> glibc prints the string "null", but other implementations can
> crash.
"null" is also printed on Mac OS X.
Do you want dev->qdev.id replaced with this? (dev->qdev.id != NULL) ? dev->qdev.id : "null"
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] [PATCH] hw/usb/bus.c: print device ID when 'info usb' used
2015-08-28 13:39 ` Programmingkid
@ 2015-08-28 13:50 ` Daniel P. Berrange
2015-08-28 13:50 ` Gerd Hoffmann
1 sibling, 0 replies; 10+ messages in thread
From: Daniel P. Berrange @ 2015-08-28 13:50 UTC (permalink / raw)
To: Programmingkid; +Cc: Gerd Hoffmann, qemu-devel qemu-devel
On Fri, Aug 28, 2015 at 09:39:43AM -0400, Programmingkid wrote:
>
> On Aug 28, 2015, at 9:35 AM, Daniel P. Berrange wrote:
>
> > On Fri, Aug 28, 2015 at 09:08:12AM -0400, Programmingkid wrote:
> >>
> >> On Aug 28, 2015, at 7:50 AM, Gerd Hoffmann wrote:
> >>
> >>> On Mo, 2015-08-24 at 15:13 -0400, Programmingkid wrote:
> >>>> + monitor_printf(mon, " Device %d.%d, Port %s, Speed %s
> >>>> Mb/s,"
> >>>> + "Product %s, ID %s\n",
> >>>> + bus->busnr, dev->addr, port->path,
> >>>> + usb_speed(dev->speed),
> >>>> + dev->product_desc, dev->qdev.id);
> >>>>
> >>>
> >>> dev->qdev.id can be NULL.
> >>>
> >>> cheers,
> >>> Gerd
> >>
> >> That isn't a problem. It will just say "null" when it is printed.
> >> No crash or garbage text.
> >
> > Handling of '%s' with NULL is undefined by the standard. Linux
> > glibc prints the string "null", but other implementations can
> > crash.
>
> "null" is also printed on Mac OS X.
I don't know if it is still true in latest versions, but historically
Solaris would crash on NULL.
"The problem is that while you can printf("%s",NULL); in most
Linux distributions, doing the same in Solaris caused the
executable to exit and generate a core."
https://blogs.oracle.com/bnitz/entry/asc_and_sprintf_s_null
> Do you want dev->qdev.id replaced with this? (dev->qdev.id != NULL) ? dev->qdev.id : "null"
It can be a bit shorter if you just leave out the "!= NULL" bit and
rely on implicit conversion of non-null to a boolean true. I'm not
sure if QEMU has a macro wrapper for hiding this possibly.
Regards,
Daniel
--
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org -o- http://virt-manager.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] [PATCH] hw/usb/bus.c: print device ID when 'info usb' used
2015-08-28 13:39 ` Programmingkid
2015-08-28 13:50 ` Daniel P. Berrange
@ 2015-08-28 13:50 ` Gerd Hoffmann
2015-08-28 13:55 ` Programmingkid
1 sibling, 1 reply; 10+ messages in thread
From: Gerd Hoffmann @ 2015-08-28 13:50 UTC (permalink / raw)
To: Programmingkid; +Cc: qemu-devel qemu-devel
On Fr, 2015-08-28 at 09:39 -0400, Programmingkid wrote:
> On Aug 28, 2015, at 9:35 AM, Daniel P. Berrange wrote:
>
> > On Fri, Aug 28, 2015 at 09:08:12AM -0400, Programmingkid wrote:
> >>
> >> On Aug 28, 2015, at 7:50 AM, Gerd Hoffmann wrote:
> >>
> >>> On Mo, 2015-08-24 at 15:13 -0400, Programmingkid wrote:
> >>>> + monitor_printf(mon, " Device %d.%d, Port %s, Speed %s
> >>>> Mb/s,"
> >>>> + "Product %s, ID %s\n",
> >>>> + bus->busnr, dev->addr, port->path,
> >>>> + usb_speed(dev->speed),
> >>>> + dev->product_desc, dev->qdev.id);
> >>>>
> >>>
> >>> dev->qdev.id can be NULL.
> >>>
> >>> cheers,
> >>> Gerd
> >>
> >> That isn't a problem. It will just say "null" when it is printed.
> >> No crash or garbage text.
> >
> > Handling of '%s' with NULL is undefined by the standard. Linux
> > glibc prints the string "null", but other implementations can
> > crash.
>
> "null" is also printed on Mac OS X.
>
> Do you want dev->qdev.id replaced with this? (dev->qdev.id != NULL) ? dev->qdev.id : "null"
Even better: Don't print "ID: ..." in the first place in case it is not
present.
cheers,
Gerd
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] [PATCH] hw/usb/bus.c: print device ID when 'info usb' used
2015-08-28 13:50 ` Gerd Hoffmann
@ 2015-08-28 13:55 ` Programmingkid
2015-08-28 16:07 ` Peter Maydell
0 siblings, 1 reply; 10+ messages in thread
From: Programmingkid @ 2015-08-28 13:55 UTC (permalink / raw)
To: Gerd Hoffmann; +Cc: qemu-devel qemu-devel
On Aug 28, 2015, at 9:50 AM, Gerd Hoffmann wrote:
> On Fr, 2015-08-28 at 09:39 -0400, Programmingkid wrote:
>> On Aug 28, 2015, at 9:35 AM, Daniel P. Berrange wrote:
>>
>>> On Fri, Aug 28, 2015 at 09:08:12AM -0400, Programmingkid wrote:
>>>>
>>>> On Aug 28, 2015, at 7:50 AM, Gerd Hoffmann wrote:
>>>>
>>>>> On Mo, 2015-08-24 at 15:13 -0400, Programmingkid wrote:
>>>>>> + monitor_printf(mon, " Device %d.%d, Port %s, Speed %s
>>>>>> Mb/s,"
>>>>>> + "Product %s, ID %s\n",
>>>>>> + bus->busnr, dev->addr, port->path,
>>>>>> + usb_speed(dev->speed),
>>>>>> + dev->product_desc, dev->qdev.id);
>>>>>>
>>>>>
>>>>> dev->qdev.id can be NULL.
>>>>>
>>>>> cheers,
>>>>> Gerd
>>>>
>>>> That isn't a problem. It will just say "null" when it is printed.
>>>> No crash or garbage text.
>>>
>>> Handling of '%s' with NULL is undefined by the standard. Linux
>>> glibc prints the string "null", but other implementations can
>>> crash.
>>
>> "null" is also printed on Mac OS X.
>>
>> Do you want dev->qdev.id replaced with this? (dev->qdev.id != NULL) ? dev->qdev.id : "null"
>
> Even better: Don't print "ID: ..." in the first place in case it is not
> present.
The ID is printed so if the user needs to remove the device, device_del <id> can be used.
If the ID isn't printed here, where do you want it to be printed? "info device-id"?
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] [PATCH] hw/usb/bus.c: print device ID when 'info usb' used
2015-08-28 13:55 ` Programmingkid
@ 2015-08-28 16:07 ` Peter Maydell
2015-08-28 16:09 ` Programmingkid
0 siblings, 1 reply; 10+ messages in thread
From: Peter Maydell @ 2015-08-28 16:07 UTC (permalink / raw)
To: Programmingkid; +Cc: Gerd Hoffmann, qemu-devel qemu-devel
On 28 August 2015 at 14:55, Programmingkid <programmingkidx@gmail.com> wrote:
> On Aug 28, 2015, at 9:50 AM, Gerd Hoffmann wrote:
>> Even better: Don't print "ID: ..." in the first place in case it is not
>> present.
>
> The ID is printed so if the user needs to remove the device, device_del <id> can be used.
>
> If the ID isn't printed here, where do you want it to be printed? "info device-id"?
Gerd means, "print nothing at all, rather than ', ID null'".
There's no point in printing something which isn't actually
an ID you can use to delete the device.
thanks
-- PMM
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Qemu-devel] [PATCH] hw/usb/bus.c: print device ID when 'info usb' used
2015-08-28 16:07 ` Peter Maydell
@ 2015-08-28 16:09 ` Programmingkid
0 siblings, 0 replies; 10+ messages in thread
From: Programmingkid @ 2015-08-28 16:09 UTC (permalink / raw)
To: Peter Maydell; +Cc: Gerd Hoffmann, qemu-devel qemu-devel
On Aug 28, 2015, at 12:07 PM, Peter Maydell wrote:
> On 28 August 2015 at 14:55, Programmingkid <programmingkidx@gmail.com> wrote:
>> On Aug 28, 2015, at 9:50 AM, Gerd Hoffmann wrote:
>>> Even better: Don't print "ID: ..." in the first place in case it is not
>>> present.
>>
>> The ID is printed so if the user needs to remove the device, device_del <id> can be used.
>>
>> If the ID isn't printed here, where do you want it to be printed? "info device-id"?
>
> Gerd means, "print nothing at all, rather than ', ID null'".
> There's no point in printing something which isn't actually
> an ID you can use to delete the device.
Ok. I can make a patch that does that.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2015-08-28 16:10 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-24 19:13 [Qemu-devel] [PATCH] hw/usb/bus.c: print device ID when 'info usb' used Programmingkid
2015-08-28 11:50 ` Gerd Hoffmann
2015-08-28 13:08 ` Programmingkid
2015-08-28 13:35 ` Daniel P. Berrange
2015-08-28 13:39 ` Programmingkid
2015-08-28 13:50 ` Daniel P. Berrange
2015-08-28 13:50 ` Gerd Hoffmann
2015-08-28 13:55 ` Programmingkid
2015-08-28 16:07 ` Peter Maydell
2015-08-28 16:09 ` Programmingkid
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).