Handle GPIO / VIDEO map with subystem (#2478)

* Handle GPIO / VIDEO mapping with subystem

* fix tests

* add udev support

* init udev data

* fix
This commit is contained in:
Pascal Vizeli 2021-01-29 11:28:16 +01:00 committed by GitHub
parent 521037e1a6
commit 636bc3e61a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 62 additions and 12 deletions

View File

@ -23,9 +23,10 @@ function run_supervisor() {
--privileged \
--security-opt seccomp=unconfined \
--security-opt apparmor:unconfined \
-v /run/docker.sock:/run/docker.sock \
-v /run/dbus:/run/dbus \
-v "/workspaces/test_supervisor":/data \
-v /run/docker.sock:/run/docker.sock:rw \
-v /run/dbus:/run/dbus:ro \
-v /run/udev:/run/udev:ro \
-v "/workspaces/test_supervisor":/data:rw \
-v /etc/machine-id:/etc/machine-id:ro \
-v /workspaces/supervisor:/usr/src/supervisor \
-e SUPERVISOR_SHARE="/workspaces/test_supervisor" \
@ -55,6 +56,24 @@ function init_dbus() {
dbus-daemon --system --print-address
}
function init_udev() {
if pgrep systemd-udevd; then
echo "udev is running"
return 0
fi
echo "Startup udev"
# cleanups
mkdir -p /run/udev
# run
/lib/systemd/systemd-udevd --daemon
sleep 3
udevadm trigger && udevadm settle
}
echo "Run Supervisor"
start_docker
@ -65,6 +84,7 @@ if [ "$( docker container inspect -f '{{.State.Status}}' hassio_supervisor )" ==
echo "Restarting Supervisor"
docker rm -f hassio_supervisor
init_dbus
init_udev
cleanup_lastboot
run_supervisor
stop_docker
@ -76,6 +96,7 @@ else
cleanup_lastboot
cleanup_docker
init_dbus
init_udev
run_supervisor
stop_docker
fi

View File

@ -130,34 +130,51 @@ class DockerAddon(DockerInterface):
devices = set()
map_strict = False
def _create_dev(device_path: Path) -> str:
"""Add device to list."""
devices.add(f"{device_path.as_posix()}:{device_path.as_posix()}:rwm")
# Static devices
for device_path in self.addon.static_devices:
if not self.sys_hardware.exists_device_node(device_path):
_LOGGER.debug("Ignore static device path %s", device_path)
continue
devices.add(f"{device_path.as_posix()}:{device_path.as_posix()}:rwm")
_create_dev(device_path)
# Dynamic devices
for device in self.addon.devices:
map_strict = True
devices.add(f"{device.path.as_posix()}:{device.path.as_posix()}:rwm")
_create_dev(device.path)
# Auto mapping UART devices / LINKS
if self.addon.with_uart:
for device in self.sys_hardware.filter_devices(
subsystem=UdevSubsystem.SERIAL
):
devices.add(f"{device.path.as_posix()}:{device.path.as_posix()}:rwm")
_create_dev(device.path)
if map_strict or not device.by_id:
continue
devices.add(f"{device.by_id.as_posix()}:{device.by_id.as_posix()}:rwm")
_create_dev(device.by_id)
# Auto mapping GPIO
if self.addon.with_gpio:
for device in self.sys_hardware.filter_devices(
subsystem=UdevSubsystem.SERIAL
for subsystem in (
UdevSubsystem.GPIO,
UdevSubsystem.GPIOMEM,
):
devices.add(f"{device.path.as_posix()}:{device.path.as_posix()}:rwm")
for device in self.sys_hardware.filter_devices(subsystem=subsystem):
_create_dev(device.path)
# Auto mapping Video
if self.addon.with_video:
for subsystem in (
UdevSubsystem.VIDEO,
UdevSubsystem.CEC,
UdevSubsystem.VCHIQ,
UdevSubsystem.MEDIA,
):
for device in self.sys_hardware.filter_devices(subsystem=subsystem):
_create_dev(device.path)
# Return None if no devices is present
if devices:

View File

@ -17,6 +17,14 @@ class UdevSubsystem(str, Enum):
DISK = "block"
PCI = "pci"
AUDIO = "sound"
VIDEO = "video4linux"
MEDIA = "media"
GPIO = "GPIO"
GPIOMEM = "GPIOMEM"
VCHIQ = "vchiq"
GRAPHICS = "graphics"
CEC = "CEC"
DRM = "drm"
class PolicyGroup(str, Enum):

View File

@ -11,8 +11,8 @@ _LOGGER: logging.Logger = logging.getLogger(__name__)
GROUP_CGROUPS: Dict[PolicyGroup, List[int]] = {
PolicyGroup.UART: [204, 188, 166, 244],
PolicyGroup.GPIO: [254],
PolicyGroup.VIDEO: [239, 29],
PolicyGroup.GPIO: [254, 245],
PolicyGroup.VIDEO: [239, 29, 81, 251, 242, 226],
PolicyGroup.AUDIO: [116],
}

View File

@ -26,4 +26,8 @@ def test_policy_group(coresys):
assert coresys.hardware.policy.get_cgroups_rules(PolicyGroup.VIDEO) == [
"c 239:* rwm",
"c 29:* rwm",
"c 81:* rwm",
"c 251:* rwm",
"c 242:* rwm",
"c 226:* rwm",
]