El día 14 de febrero de 2012 19:42, Greg KH <greg@kroah.com> escribió:
On Tue, Feb 14, 2012 at 07:05:48PM -0300, Ezequiel García wrote:
I noticed that after registering a video driver with "video_register_device" the "open" function gets called. The registration is like:
peasycap->video_device.fops = &v4l2_fops; peasycap->video_device.minor = -1; peasycap->video_device.release = (void *)(&videodev_release);
video_set_drvdata(&(peasycap->video_device), (void *)peasycap);
First question: who calls it and why does it open the device?
Userspace probably.
I find hard that userspace is who opens the device in this particular case, because I get the "open" call just by plugging in the usb, right after usb_probe. (unless there is a daemon, or udev opens the device for module insertion or something). I will investigate this further. Thanks, Ezequiel.
On Wed, Feb 15, 2012 at 10:15 AM, Ezequiel García <elezegarcia@gmail.com>wrote:
El día 14 de febrero de 2012 19:42, Greg KH <greg@kroah.com> escribió:
On Tue, Feb 14, 2012 at 07:05:48PM -0300, Ezequiel García wrote:
I noticed that after registering a video driver with "video_register_device" the "open" function gets called. The registration is like:
peasycap->video_device.fops = &v4l2_fops; peasycap->video_device.minor = -1; peasycap->video_device.release = (void *)(&videodev_release);
video_set_drvdata(&(peasycap->video_device), (void *)peasycap);
First question: who calls it and why does it open the device?
Userspace probably.
I find hard that userspace is who opens the device in this particular case, because I get the "open" call just by plugging in the usb, right after usb_probe. (unless there is a daemon, or udev opens the device for module insertion or something).
I will investigate this further.
Although it doesn't easily click, but very simple. Implement open fop and put following print in it: printk("%s: My caller is %s\n", __func__, current->comm); You will get to know the user space daemon name. I have seen a daemon on some linux distributions, called 'hald' (Hardware Abstraction Layer Daemon) doing these sort of activities when it detects hardware changes. Even in case of new mount point, it stats every mounted filesystem. -Rajat
Thanks, Ezequiel.
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Ezequiel García <elezegarcia@gmail.com> writes:
I find hard that userspace is who opens the device in this particular case, because I get the "open" call just by plugging in the usb, right after usb_probe. (unless there is a daemon, or udev opens the device for module insertion or something).
Typical V4L rules have something like this in /lib/udev/rules.d/60-persistent-v4l.rules : IMPORT{program}="v4l_id $tempnode" So yes, looks like udev will open your device when it's plugged. Bjørn
2012/2/15 Bjørn Mork <bjorn@mork.no>:
IMPORT{program}="v4l_id $tempnode"
So yes, looks like udev will open your device when it's plugged.
Thanks! I checked that and you are right. It is also possible to stop udev service and then insert the device. In this case, the device is not opened after plugging it. Looking at easycap_usb_probe() I guess we could just remove this comment (or at least fix it) since it *not* videodev who calls easycap_open(): /* * IT IS ESSENTIAL TO INITIALIZE THE HARDWARE BEFORE, RATHER THAN AFTER, * THE DEVICE IS REGISTERED, BECAUSE SOME VERSIONS OF THE videodev MODULE * CALL easycap_open() IMMEDIATELY AFTER REGISTRATION, CAUSING A CLASH. * BEWARE. */ Another question: when does udev recognizes that this device was plugged? Probably somewhere inside video_register_device(), right? Thanks, Ezequiel.
Ezequiel García <elezegarcia@gmail.com> writes:
Another question: when does udev recognizes that this device was plugged? Probably somewhere inside video_register_device(), right?
Yes, if you look at the extremely long function __video_register_device() in drivers/media/video/v4l2-dev, you'll find this: /* Part 4: register the device with sysfs */ vdev->dev.class = &video_class; vdev->dev.devt = MKDEV(VIDEO_MAJOR, vdev->minor); if (vdev->parent) vdev->dev.parent = vdev->parent; dev_set_name(&vdev->dev, "%s%d", name_base, vdev->num); ret = device_register(&vdev->dev); The device_register() will do a kobject_uevent(&dev->kobj, KOBJ_ADD); among other things. That's what udev sees. Bjørn
participants (3)
-
Bjørn Mork -
Ezequiel García -
Rajat Sharma