Virtual Devices
In the section "Virtual Devices" in Chapter 5, we saw how virtual devices differ from real ones with regard to initialization. As far as registration is concerned, virtual devices need to be registered and enabled just like real ones, to be used. However, there are differences:
Virtual devices sometimes call
register_netdeviceandunregister_netdevicerather than their wrappers, and take care of locking by themselves. They may need to handle locking to keep the lock for a little longer than a real device does. With this approach, the lock could also be misused and hold longer than needed, by making it protect additional pieces of code (besidesregister_netdev) that could be protected in other ways.Real devices cannot be unregistered (i.e., destroyed) with user commands; they can only be disabled. Real devices are unregistered at the time their drivers are unloaded (when loaded as modules, of course). Virtual devices, in contrast, may be created and unregistered with user commands, too. Whether this is possible depends on the virtual device driver's design.
We also saw in the sections "register_netdevice Function" and "Device Unregistration" that virtual devices, unlike most real ones, use dev->init, dev->uninit, and dev->destructor.
Because most virtual devices implement some kind of more or less complex logic on top of
real devices, they use dev->init and dev->uninit to take care of extra initialization and
cleanup. dev->destructor is often initialized to
free_netdev ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access