mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-18 22:56:31 +00:00
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:
parent
521037e1a6
commit
636bc3e61a
@ -23,9 +23,10 @@ function run_supervisor() {
|
|||||||
--privileged \
|
--privileged \
|
||||||
--security-opt seccomp=unconfined \
|
--security-opt seccomp=unconfined \
|
||||||
--security-opt apparmor:unconfined \
|
--security-opt apparmor:unconfined \
|
||||||
-v /run/docker.sock:/run/docker.sock \
|
-v /run/docker.sock:/run/docker.sock:rw \
|
||||||
-v /run/dbus:/run/dbus \
|
-v /run/dbus:/run/dbus:ro \
|
||||||
-v "/workspaces/test_supervisor":/data \
|
-v /run/udev:/run/udev:ro \
|
||||||
|
-v "/workspaces/test_supervisor":/data:rw \
|
||||||
-v /etc/machine-id:/etc/machine-id:ro \
|
-v /etc/machine-id:/etc/machine-id:ro \
|
||||||
-v /workspaces/supervisor:/usr/src/supervisor \
|
-v /workspaces/supervisor:/usr/src/supervisor \
|
||||||
-e SUPERVISOR_SHARE="/workspaces/test_supervisor" \
|
-e SUPERVISOR_SHARE="/workspaces/test_supervisor" \
|
||||||
@ -55,6 +56,24 @@ function init_dbus() {
|
|||||||
dbus-daemon --system --print-address
|
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"
|
echo "Run Supervisor"
|
||||||
|
|
||||||
start_docker
|
start_docker
|
||||||
@ -65,6 +84,7 @@ if [ "$( docker container inspect -f '{{.State.Status}}' hassio_supervisor )" ==
|
|||||||
echo "Restarting Supervisor"
|
echo "Restarting Supervisor"
|
||||||
docker rm -f hassio_supervisor
|
docker rm -f hassio_supervisor
|
||||||
init_dbus
|
init_dbus
|
||||||
|
init_udev
|
||||||
cleanup_lastboot
|
cleanup_lastboot
|
||||||
run_supervisor
|
run_supervisor
|
||||||
stop_docker
|
stop_docker
|
||||||
@ -76,6 +96,7 @@ else
|
|||||||
cleanup_lastboot
|
cleanup_lastboot
|
||||||
cleanup_docker
|
cleanup_docker
|
||||||
init_dbus
|
init_dbus
|
||||||
|
init_udev
|
||||||
run_supervisor
|
run_supervisor
|
||||||
stop_docker
|
stop_docker
|
||||||
fi
|
fi
|
@ -130,34 +130,51 @@ class DockerAddon(DockerInterface):
|
|||||||
devices = set()
|
devices = set()
|
||||||
map_strict = False
|
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
|
# Static devices
|
||||||
for device_path in self.addon.static_devices:
|
for device_path in self.addon.static_devices:
|
||||||
if not self.sys_hardware.exists_device_node(device_path):
|
if not self.sys_hardware.exists_device_node(device_path):
|
||||||
_LOGGER.debug("Ignore static device path %s", device_path)
|
_LOGGER.debug("Ignore static device path %s", device_path)
|
||||||
continue
|
continue
|
||||||
devices.add(f"{device_path.as_posix()}:{device_path.as_posix()}:rwm")
|
_create_dev(device_path)
|
||||||
|
|
||||||
# Dynamic devices
|
# Dynamic devices
|
||||||
for device in self.addon.devices:
|
for device in self.addon.devices:
|
||||||
map_strict = True
|
map_strict = True
|
||||||
devices.add(f"{device.path.as_posix()}:{device.path.as_posix()}:rwm")
|
_create_dev(device.path)
|
||||||
|
|
||||||
# Auto mapping UART devices / LINKS
|
# Auto mapping UART devices / LINKS
|
||||||
if self.addon.with_uart:
|
if self.addon.with_uart:
|
||||||
for device in self.sys_hardware.filter_devices(
|
for device in self.sys_hardware.filter_devices(
|
||||||
subsystem=UdevSubsystem.SERIAL
|
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:
|
if map_strict or not device.by_id:
|
||||||
continue
|
continue
|
||||||
devices.add(f"{device.by_id.as_posix()}:{device.by_id.as_posix()}:rwm")
|
_create_dev(device.by_id)
|
||||||
|
|
||||||
# Auto mapping GPIO
|
# Auto mapping GPIO
|
||||||
if self.addon.with_gpio:
|
if self.addon.with_gpio:
|
||||||
for device in self.sys_hardware.filter_devices(
|
for subsystem in (
|
||||||
subsystem=UdevSubsystem.SERIAL
|
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
|
# Return None if no devices is present
|
||||||
if devices:
|
if devices:
|
||||||
|
@ -17,6 +17,14 @@ class UdevSubsystem(str, Enum):
|
|||||||
DISK = "block"
|
DISK = "block"
|
||||||
PCI = "pci"
|
PCI = "pci"
|
||||||
AUDIO = "sound"
|
AUDIO = "sound"
|
||||||
|
VIDEO = "video4linux"
|
||||||
|
MEDIA = "media"
|
||||||
|
GPIO = "GPIO"
|
||||||
|
GPIOMEM = "GPIOMEM"
|
||||||
|
VCHIQ = "vchiq"
|
||||||
|
GRAPHICS = "graphics"
|
||||||
|
CEC = "CEC"
|
||||||
|
DRM = "drm"
|
||||||
|
|
||||||
|
|
||||||
class PolicyGroup(str, Enum):
|
class PolicyGroup(str, Enum):
|
||||||
|
@ -11,8 +11,8 @@ _LOGGER: logging.Logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
GROUP_CGROUPS: Dict[PolicyGroup, List[int]] = {
|
GROUP_CGROUPS: Dict[PolicyGroup, List[int]] = {
|
||||||
PolicyGroup.UART: [204, 188, 166, 244],
|
PolicyGroup.UART: [204, 188, 166, 244],
|
||||||
PolicyGroup.GPIO: [254],
|
PolicyGroup.GPIO: [254, 245],
|
||||||
PolicyGroup.VIDEO: [239, 29],
|
PolicyGroup.VIDEO: [239, 29, 81, 251, 242, 226],
|
||||||
PolicyGroup.AUDIO: [116],
|
PolicyGroup.AUDIO: [116],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,4 +26,8 @@ def test_policy_group(coresys):
|
|||||||
assert coresys.hardware.policy.get_cgroups_rules(PolicyGroup.VIDEO) == [
|
assert coresys.hardware.policy.get_cgroups_rules(PolicyGroup.VIDEO) == [
|
||||||
"c 239:* rwm",
|
"c 239:* rwm",
|
||||||
"c 29:* rwm",
|
"c 29:* rwm",
|
||||||
|
"c 81:* rwm",
|
||||||
|
"c 251:* rwm",
|
||||||
|
"c 242:* rwm",
|
||||||
|
"c 226:* rwm",
|
||||||
]
|
]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user