New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Kernel+SystemServer+DeviceMapper: Add propagation mechanism for hotplug events between userspace programs #24210
Open
supercomputer7
wants to merge
13
commits into
SerenityOS:master
Choose a base branch
from
supercomputer7:devicemapper-hotplug-events
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Kernel+SystemServer+DeviceMapper: Add propagation mechanism for hotplug events between userspace programs #24210
supercomputer7
wants to merge
13
commits into
SerenityOS:master
from
supercomputer7:devicemapper-hotplug-events
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
github-actions
bot
added
👀 pr-needs-review
PR needs review from a maintainer or community member
and removed
👀 pr-needs-review
PR needs review from a maintainer or community member
labels
May 4, 2024
supercomputer7
force-pushed
the
devicemapper-hotplug-events
branch
from
May 4, 2024 18:13
50945fe
to
e49d4c0
Compare
Here's a video demo to show the I booted with PS/2 mouse being disabled, and added a USB mouse during the SerenityOS VM runtime. :) |
supercomputer7
force-pushed
the
devicemapper-hotplug-events
branch
3 times, most recently
from
May 4, 2024 18:57
bfa07f7
to
13007b2
Compare
spholz
reviewed
May 4, 2024
supercomputer7
force-pushed
the
devicemapper-hotplug-events
branch
2 times, most recently
from
May 7, 2024 19:12
a30f537
to
b0799ac
Compare
supercomputer7
force-pushed
the
devicemapper-hotplug-events
branch
from
May 10, 2024 05:22
b0799ac
to
e6eab66
Compare
github-actions
bot
added
the
👀 pr-needs-review
PR needs review from a maintainer or community member
label
May 10, 2024
supercomputer7
force-pushed
the
devicemapper-hotplug-events
branch
from
May 10, 2024 15:48
e6eab66
to
a964903
Compare
I rebased this and force-pushed to see if the CI flakiness is resolved. |
supercomputer7
commented
May 11, 2024
supercomputer7
force-pushed
the
devicemapper-hotplug-events
branch
from
May 14, 2024 07:15
a964903
to
aabd05d
Compare
supercomputer7
force-pushed
the
devicemapper-hotplug-events
branch
2 times, most recently
from
May 16, 2024 18:29
9e7c561
to
c0fe27d
Compare
I accidentally marked them as char devices, so they're not usable on their own when trying to mount with them.
There is simply no advantage with putting both virtual console devices and serial TTY devices on the same major number. Putting them on separate major numbers greatly simplifies the allocation mechanism on the DeviceMapper code, because it no longer needs to calculate offsets of minor numbers, and should start from number 0 to theoretically infinite amount of device nodes.
Instead of putting everything in one hash map, let's distinguish between the devices based on their type. This change makes the devices semantically separated, and is considered a preparation before we could expose a comprehensive list of allocations per major numbers and their purpose.
Having a separate enum is pointless, and opens the possibility of having duplicates elsewhere. Therefore, just unify everything under one known enum.
We used to allocate major numbers quite randomly, with no common place to look them up if needed. This commit is changing that by placing all major number allocations under a new C++ namespace, in the Devices/MajorNumberAllocation.h file. We also add the foundations of what is needed before we can publish this information (allocated numbers for block and char devices) to userspace.
After the previous commit, we are able to create a comprehensive list of all devices' major number allocations. To help userspace to distinguish between character and block devices, we expose 2 sysfs nodes so userspace can decide which list it needs to open in order to iterate on it.
Contributors that want to add new types of character or block devices must follow these guidelines in order to keep everything intact.
The new mechanism is basically adding or removing symbolic links to device nodes in /dev. These symbolic links are located in the directory of /tmp/system/devicemap/nodes/{block,char} which contain subdirectories for major number allocation, which then hold these symbolic links. An interested userspace program could then open an inode watcher on the subdirectories which hold the symbolic link for added or removed links to indicate hotplug events of insertion or removal of a device.
This utility lists all devices' major number allocations, for character and block devices. It can help the user to figure out the DeviceMapper service manages spawning of device nodes in /dev and other associated files under the /tmp/system/devicemap directory.
Add inode watchers on the /tmp/system/devicemap/family/{mouse,keyboard}/ directories. Then instruct those watchers to dispatch a refresh call to the vectors which hold references to these devices.
We are going to remove this device from the kernel in the next commit, so prepare for that by not creating a device node.
This device was a short-lived solution to allow userspace (WindowServer) to easily support hotplugging mouse devices with presumably very small modifications on userspace side. Now that we have a proper mechanism to propagate hotplug events from the DeviceMapper program to any program that needs to get such events, we no longer need this device, so let's remove it.
supercomputer7
force-pushed
the
devicemapper-hotplug-events
branch
from
May 18, 2024 14:57
c0fe27d
to
7aae9cc
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Relies on #24203.
The idea is very simple - we could utilize the
inode_watcher
facility to inform user programs which are interested to get hotplug events, on removal or insertion of device nodes.I still need to implement the actual usage of this in a mainService
, which I thinkWindowServer
would be an excellent option to start with.The first userspace program to use this mechanism is
WindowServer
, to support hotplug events of keyboard and mouse devices.cc @Hendiadyoin1 @spholz