Repository navigation
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
|
@ciandonovan Thanks again for this PR. |
|
@ciandonovan |
…major and minor devices numbers rathers than video4linux sysfs directory names
4824e52 to
b52eaed
Compare
|
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
--privilegedflag, 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
realsenseai/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
--deviceflag, 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
ueventfile and extracting the device major and minor number, then searching each file in/devto 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:devicedevices, but from a brief reading ofsrc/linux/backend-hid.cppit looks like they're accessed exclusively through the devfs and so simply passing them through to the container with the--deviceflag 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.