-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Refactor device enumeration for unprivileged containers #11900
Conversation
Hi @ciandonovan Thanks for the PR. |
Is there anything I can do on my end to help fix that failing check? Unfortunately the link still isn't working so can't see exactly what's wrong. |
Hi, Please allow some time, once we can make it we will review this PR, thanks! |
hi @ciandonovan |
Hi @dmipx Will I rebase onto the head of the |
58fcce8
to
0a3fc8d
Compare
Removed the part affecting the MIPI handling and squashed the remaining commits |
I changed all the appropriate I now also always explicitly check the return code of |
54cd8c5
to
1e7963f
Compare
Commits squashed and ready for review |
Fixed the get_devname_from_video_path() to return false when no devices are found |
fac526c
to
92c0691
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@ciandonovan Thanks again for this PR. |
@ciandonovan |
…major and minor devices numbers rathers than video4linux sysfs directory names
4824e52
to
b52eaed
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Verified.
Close & reopened to trigger CI, last run had a failure, let's see it it's persistent. |
|
Yes, this is an internal CI, I will update once I get the results |
There are currently two solutions I'm aware of to run librealsense in a Podman/Docker OCI container.
The first is to run the container with the
--privileged
flag, giving it access to all the host's devices. But this also disables beneficial security features, and weakens the sandbox boundary.The second is to use the
--device-cgroup-rule "c 81:* rmw"
flag to allow access to the USB, but this is still far from ideal as the all USB devices are exposed.#3849
IntelRealSense/realsense-ros#1104
https://github.com/IntelRealSense/librealsense/blob/master/scripts/Docker/readme.md
https://www.matrix-vision.com/manuals/mvBlueFOX3/UseCases_section_mvBF3_in_docker.html
Ideally it would be possible to pass through to the container only the devices we need with the
--device
flag, in this case a subset of the/dev/video*
devices. This is especially useful for systems with multiple RealSense cameras attached, where one container is setup to handle each camera, and each camera is passed through to each container individually.However, this doesn't work currently, because in enumerating devices, librealsense naively assumes that the sysfs entries
/sys/class/video4linux/video*
map directly to their corresponding/dev/video*
devices. In most cases this is the correct assumption, but this doesn't hold for unprivileged rootless containers. In these containers, devices passed through must be named explicitly on container creation, and don't necessarily match the same name as on the host. Depending on how many cameras are plugged into the host, a particular device's video node numbers will be different, but they'll still have the same fixed number in the container.librealsense simply lobs off the
/sys/class/video4linux/
part of the path and replaces it with the string/dev/
, leading to it trying to access a device not present in the container's mount namespace and failing to discover the camera that's attached.My pull request modifies this behaviour, introducing a new function
std::string get_devname_from_video_path(const std::string& video_path)
to perform the task of correctly matching video4linux sysfs entries with their corresponding devfs devices.This is done by first parsing the sysfs
uevent
file and extracting the device major and minor number, then searching each file in/dev
to see if there's a match. If so, the string of the device name is returned, if not, and empty string is returned and that sysfs entry is ignored.I've confirmed that this works with and without udev and with the official .
I have not tested with any other Intel RealSense products as I don't have access to any, especially MIPI based ones, would appreciate if someone could test that too.
I also haven't covered any
iio:device
devices, but from a brief reading ofsrc/linux/backend-hid.cpp
it looks like they're accessed exclusively through the devfs and so simply passing them through to the container with the--device
flag should suffice. If someone has a test application that makes use of them, or theHID-SENSOR-2000e1.5.auto
, I can test to ensure they still work too.