summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Devaev <[email protected]>2022-04-10 06:00:10 +0300
committerMaxim Devaev <[email protected]>2022-04-10 06:00:10 +0300
commit486f1be9867fcb3220a2918ddd5b0371ece17d5d (patch)
tree22f6297f9a4755631c0aee3397980a8e2dde0d22
parent122242ea472684434989706253bb38ad48a6cbd6 (diff)
get rid of the otg-unlock helper
-rw-r--r--PKGBUILD3
-rw-r--r--configs/os/sudoers/v2-hdmi1
-rw-r--r--configs/os/sudoers/v2-hdmiusb1
-rw-r--r--configs/os/sudoers/v3-hdmi1
-rw-r--r--kvmd/apps/otg/__init__.py7
-rw-r--r--kvmd/apps/otgmsd/__init__.py25
-rw-r--r--kvmd/helpers/unlock/__init__.py58
-rw-r--r--kvmd/helpers/unlock/__main__.py24
-rw-r--r--kvmd/plugins/msd/otg/__init__.py11
-rw-r--r--kvmd/plugins/msd/otg/drive.py5
-rw-r--r--kvmd/plugins/msd/otg/helpers.py10
-rwxr-xr-xsetup.py2
-rw-r--r--testenv/Dockerfile15
-rw-r--r--testenv/fakes/proc/device-tree/model (renamed from testenv/fakes/dt_model)0
-rw-r--r--testenv/fakes/sys/class/thermal/thermal_zone0/temp (renamed from testenv/fakes/cpu_temp)0
l---------testenv/fakes/sys/class/udc/fe980000.usb/device/driver1
-rw-r--r--testenv/fakes/sys/class/udc/fe980000.usb/state1
l---------testenv/fakes/sys/kernel/config/usb_gadget/kvmd/configs/c.1/mass_storage.usb01
-rw-r--r--testenv/fakes/sys/kernel/config/usb_gadget/kvmd/functions/mass_storage.usb0/lun.0/cdrom (renamed from testenv/fakes/msd/cdrom)0
-rw-r--r--testenv/fakes/sys/kernel/config/usb_gadget/kvmd/functions/mass_storage.usb0/lun.0/file (renamed from testenv/fakes/msd/file)0
l---------testenv/fakes/sys/kernel/config/usb_gadget/kvmd/functions/mass_storage.usb0/lun.0/forced_eject1
-rw-r--r--testenv/fakes/sys/kernel/config/usb_gadget/kvmd/functions/mass_storage.usb0/lun.0/ro (renamed from testenv/fakes/msd/ro)0
-rw-r--r--testenv/v2-hdmi-rpi4.override.yaml1
-rw-r--r--testenv/v2-hdmiusb-rpi4.override.yaml1
24 files changed, 18 insertions, 151 deletions
diff --git a/PKGBUILD b/PKGBUILD
index b63cadfe..2a0dcb63 100644
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -185,6 +185,9 @@ for _variant in "${_variants[@]}"; do
pkgdesc=\"PiKVM platform configs - $_platform for $_board\"
depends=(kvmd=$pkgver-$pkgrel)
+ if [ $_board != generic ]; then
+ depends=(\"\${depends[@]}\" \"linux-rpi-pikvm>=5.15.25-15\")
+ fi
backup=(
etc/sysctl.d/99-kvmd.conf
diff --git a/configs/os/sudoers/v2-hdmi b/configs/os/sudoers/v2-hdmi
index f5d7f5b3..673d4033 100644
--- a/configs/os/sudoers/v2-hdmi
+++ b/configs/os/sudoers/v2-hdmi
@@ -1,3 +1,2 @@
-kvmd ALL=(ALL) NOPASSWD: /usr/bin/kvmd-helper-otgmsd-unlock
kvmd ALL=(ALL) NOPASSWD: /usr/bin/kvmd-helper-otgmsd-remount
kvmd-pst ALL=(ALL) NOPASSWD: /usr/bin/kvmd-helper-pst-remount
diff --git a/configs/os/sudoers/v2-hdmiusb b/configs/os/sudoers/v2-hdmiusb
index f5d7f5b3..673d4033 100644
--- a/configs/os/sudoers/v2-hdmiusb
+++ b/configs/os/sudoers/v2-hdmiusb
@@ -1,3 +1,2 @@
-kvmd ALL=(ALL) NOPASSWD: /usr/bin/kvmd-helper-otgmsd-unlock
kvmd ALL=(ALL) NOPASSWD: /usr/bin/kvmd-helper-otgmsd-remount
kvmd-pst ALL=(ALL) NOPASSWD: /usr/bin/kvmd-helper-pst-remount
diff --git a/configs/os/sudoers/v3-hdmi b/configs/os/sudoers/v3-hdmi
index f5d7f5b3..673d4033 100644
--- a/configs/os/sudoers/v3-hdmi
+++ b/configs/os/sudoers/v3-hdmi
@@ -1,3 +1,2 @@
-kvmd ALL=(ALL) NOPASSWD: /usr/bin/kvmd-helper-otgmsd-unlock
kvmd ALL=(ALL) NOPASSWD: /usr/bin/kvmd-helper-otgmsd-remount
kvmd-pst ALL=(ALL) NOPASSWD: /usr/bin/kvmd-helper-pst-remount
diff --git a/kvmd/apps/otg/__init__.py b/kvmd/apps/otg/__init__.py
index 1d33b98e..e84a7f00 100644
--- a/kvmd/apps/otg/__init__.py
+++ b/kvmd/apps/otg/__init__.py
@@ -71,7 +71,7 @@ def _rmdir(path: str) -> None:
def _unlink(path: str, optional: bool=False) -> None:
logger = get_logger()
if optional and not os.access(path, os.F_OK):
- logger.info("SKIP-RM - %s", path)
+ logger.info("RM ------ [SKIPPED] %s", path)
return
logger.info("RM ------ %s", path)
os.unlink(path)
@@ -185,6 +185,7 @@ class _GadgetConfig:
_chown(join(func_path, "lun.0/cdrom"), user)
_chown(join(func_path, "lun.0/ro"), user)
_chown(join(func_path, "lun.0/file"), user)
+ _chown(join(func_path, "lun.0/forced_eject"), user)
_symlink(func_path, join(self.__profile_path, func))
name = ("Mass Storage Drive" if self.__msd_instance == 0 else f"Extra Drive #{self.__msd_instance}")
self.__create_meta(func, name)
@@ -269,8 +270,6 @@ def _cmd_start(config: Section) -> None: # pylint: disable=too-many-statements
logger.info("Enabling the gadget ...")
_write(join(gadget_path, "UDC"), udc)
time.sleep(config.otg.init_delay)
-
- logger.info("Setting up permissions ...")
_chown(join(gadget_path, "UDC"), config.otg.user)
_chown(profile_path, config.otg.user)
@@ -290,7 +289,7 @@ def _cmd_stop(config: Section) -> None:
logger.info("Disabling gadget %r ...", config.otg.gadget)
_write(join(gadget_path, "UDC"), "\n")
- _unlink(join(gadget_path, "os_desc", usb.G_PROFILE_NAME), True)
+ _unlink(join(gadget_path, "os_desc", usb.G_PROFILE_NAME), optional=True)
profile_path = join(gadget_path, usb.G_PROFILE)
for func in os.listdir(profile_path):
diff --git a/kvmd/apps/otgmsd/__init__.py b/kvmd/apps/otgmsd/__init__.py
index 5187a72d..2e109d96 100644
--- a/kvmd/apps/otgmsd/__init__.py
+++ b/kvmd/apps/otgmsd/__init__.py
@@ -21,15 +21,12 @@
import os
-import signal
import errno
import argparse
from typing import List
from typing import Optional
-import psutil
-
from ...validators.basic import valid_bool
from ...validators.basic import valid_int_f0
from ...validators.os import valid_abs_file
@@ -59,21 +56,6 @@ def _set_param(gadget: str, instance: int, param: str, value: str) -> None:
raise
-def _unlock() -> None:
- # https://github.com/torvalds/linux/blob/3039fad/drivers/usb/gadget/function/f_mass_storage.c#L2924
- found = False
- for proc in psutil.process_iter():
- attrs = proc.as_dict(attrs=["name", "exe", "pid"])
- if attrs.get("name") == "file-storage" and not attrs.get("exe"):
- try:
- proc.send_signal(signal.SIGUSR1)
- found = True
- except Exception as err:
- raise SystemExit(f"Can't send SIGUSR1 to MSD kernel thread with pid={attrs['pid']}: {err}")
- if not found:
- raise SystemExit("Can't find MSD kernel thread")
-
-
# =====
def main(argv: Optional[List[str]]=None) -> None:
(parent_parser, argv, config) = init(
@@ -88,8 +70,6 @@ def main(argv: Optional[List[str]]=None) -> None:
)
parser.add_argument("-i", "--instance", default=0, type=valid_int_f0,
metavar="<N>", help="Drive instance (0 for KVMD drive)")
- parser.add_argument("--unlock", action="store_true",
- help="Send SIGUSR1 to MSD kernel thread")
parser.add_argument("--set-cdrom", default=None, type=valid_bool,
metavar="<1|0|yes|no>", help="Set CD-ROM flag")
parser.add_argument("--set-rw", default=None, type=valid_bool,
@@ -107,11 +87,8 @@ def main(argv: Optional[List[str]]=None) -> None:
set_param = (lambda param, value: _set_param(config.otg.gadget, options.instance, param, value))
get_param = (lambda param: _get_param(config.otg.gadget, options.instance, param))
- if options.unlock:
- _unlock()
-
if options.eject:
- set_param("file", "")
+ set_param("forced_eject", "")
if options.set_cdrom is not None:
set_param("cdrom", str(int(options.set_cdrom)))
diff --git a/kvmd/helpers/unlock/__init__.py b/kvmd/helpers/unlock/__init__.py
deleted file mode 100644
index 140e0e7c..00000000
--- a/kvmd/helpers/unlock/__init__.py
+++ /dev/null
@@ -1,58 +0,0 @@
-# ========================================================================== #
-# #
-# KVMD - The main PiKVM daemon. #
-# #
-# Copyright (C) 2018-2022 Maxim Devaev <[email protected]> #
-# #
-# This program is free software: you can redistribute it and/or modify #
-# it under the terms of the GNU General Public License as published by #
-# the Free Software Foundation, either version 3 of the License, or #
-# (at your option) any later version. #
-# #
-# This program is distributed in the hope that it will be useful, #
-# but WITHOUT ANY WARRANTY; without even the implied warranty of #
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
-# GNU General Public License for more details. #
-# #
-# You should have received a copy of the GNU General Public License #
-# along with this program. If not, see <https://www.gnu.org/licenses/>. #
-# #
-# ========================================================================== #
-
-
-import sys
-import signal
-
-import psutil
-
-
-# =====
-_PROCESS_NAME = "file-storage"
-
-
-# =====
-def _log(msg: str) -> None:
- print(msg, file=sys.stderr)
-
-
-def _unlock() -> None:
- # https://github.com/torvalds/linux/blob/3039fad/drivers/usb/gadget/function/f_mass_storage.c#L2924
- found = False
- for proc in psutil.process_iter():
- attrs = proc.as_dict(attrs=["name", "exe", "pid"])
- if attrs.get("name") == _PROCESS_NAME and not attrs.get("exe"):
- _log(f"Sending SIGUSR1 to MSD {_PROCESS_NAME!r} kernel thread with pid={attrs['pid']} ...")
- try:
- proc.send_signal(signal.SIGUSR1)
- found = True
- except Exception as err:
- raise SystemExit(f"Can't send SIGUSR1 to MSD kernel thread with pid={attrs['pid']}: {err}")
- if not found:
- raise SystemExit(f"Can't find MSD kernel thread {_PROCESS_NAME!r}")
-
-
-# =====
-def main() -> None:
- if len(sys.argv) != 2 or sys.argv[1] != "unlock":
- raise SystemExit(f"Usage: {sys.argv[0]} [unlock]")
- _unlock()
diff --git a/kvmd/helpers/unlock/__main__.py b/kvmd/helpers/unlock/__main__.py
deleted file mode 100644
index 3849d1b9..00000000
--- a/kvmd/helpers/unlock/__main__.py
+++ /dev/null
@@ -1,24 +0,0 @@
-# ========================================================================== #
-# #
-# KVMD - The main PiKVM daemon. #
-# #
-# Copyright (C) 2018-2022 Maxim Devaev <[email protected]> #
-# #
-# This program is free software: you can redistribute it and/or modify #
-# it under the terms of the GNU General Public License as published by #
-# the Free Software Foundation, either version 3 of the License, or #
-# (at your option) any later version. #
-# #
-# This program is distributed in the hope that it will be useful, #
-# but WITHOUT ANY WARRANTY; without even the implied warranty of #
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
-# GNU General Public License for more details. #
-# #
-# You should have received a copy of the GNU General Public License #
-# along with this program. If not, see <https://www.gnu.org/licenses/>. #
-# #
-# ========================================================================== #
-
-
-from . import main
-main()
diff --git a/kvmd/plugins/msd/otg/__init__.py b/kvmd/plugins/msd/otg/__init__.py
index 38a09d84..dcf70557 100644
--- a/kvmd/plugins/msd/otg/__init__.py
+++ b/kvmd/plugins/msd/otg/__init__.py
@@ -140,7 +140,6 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
storage_path: str,
remount_cmd: List[str],
- unlock_cmd: List[str],
initial: Dict,
@@ -155,7 +154,6 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
self.__meta_path = os.path.join(self.__storage_path, "meta")
self.__remount_cmd = remount_cmd
- self.__unlock_cmd = unlock_cmd
self.__initial_image: str = initial["image"]
self.__initial_cdrom: bool = initial["cdrom"]
@@ -182,7 +180,6 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
"storage": Option("/var/lib/kvmd/msd", type=valid_abs_dir, unpack_as="storage_path"),
"remount_cmd": Option([*sudo, "/usr/bin/kvmd-helper-otgmsd-remount", "{mode}"], type=valid_command),
- "unlock_cmd": Option([*sudo, "/usr/bin/kvmd-helper-otgmsd-unlock", "unlock"], type=valid_command),
"initial": {
"image": Option("", type=valid_printable_filename, if_empty=""),
@@ -242,7 +239,6 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
async def reset(self) -> None:
async with self.__state.busy(check_online=False):
try:
- await self.__unlock_drive()
self.__drive.set_image_path("")
self.__drive.set_rw_flag(False)
self.__drive.set_cdrom_flag(False)
@@ -292,15 +288,12 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
if not os.path.exists(self.__state.vd.image.path):
raise MsdUnknownImageError()
- await self.__unlock_drive()
self.__drive.set_cdrom_flag(self.__state.vd.cdrom)
self.__drive.set_image_path(self.__state.vd.image.path)
else:
if not (self.__state.vd.connected or self.__drive.get_image_path()):
raise MsdDisconnectedError()
-
- await self.__unlock_drive()
self.__drive.set_image_path("")
self.__state.vd.connected = connected
@@ -479,7 +472,6 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
if os.path.exists(path):
logger.info("Setting up initial image %r ...", self.__initial_image)
try:
- await self.__unlock_drive()
self.__drive.set_cdrom_flag(self.__initial_cdrom)
self.__drive.set_image_path(path)
except Exception:
@@ -547,6 +539,3 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
async def __remount_storage(self, rw: bool) -> None:
await helpers.remount_storage(self.__remount_cmd, rw)
-
- async def __unlock_drive(self) -> None:
- await helpers.unlock_drive(self.__unlock_cmd)
diff --git a/kvmd/plugins/msd/otg/drive.py b/kvmd/plugins/msd/otg/drive.py
index ee54e5e9..11af7f81 100644
--- a/kvmd/plugins/msd/otg/drive.py
+++ b/kvmd/plugins/msd/otg/drive.py
@@ -53,7 +53,10 @@ class Drive:
# =====
def set_image_path(self, path: str) -> None:
- self.__set_param("file", path)
+ if path:
+ self.__set_param("file", path)
+ else:
+ self.__set_param("forced_eject", "")
def get_image_path(self) -> str:
return self.__get_param("file")
diff --git a/kvmd/plugins/msd/otg/helpers.py b/kvmd/plugins/msd/otg/helpers.py
index 19cb0bbb..2d64bd0c 100644
--- a/kvmd/plugins/msd/otg/helpers.py
+++ b/kvmd/plugins/msd/otg/helpers.py
@@ -45,16 +45,6 @@ async def remount_storage(base_cmd: List[str], rw: bool) -> None:
raise
-async def unlock_drive(base_cmd: List[str]) -> None:
- logger = get_logger(0)
- logger.info("Unlocking the drive ...")
- try:
- await _run_helper(base_cmd)
- except Exception:
- logger.error("Can't unlock the drive")
- raise
-
-
# =====
async def _run_helper(cmd: List[str]) -> None:
logger = get_logger(0)
diff --git a/setup.py b/setup.py
index 8e6e49c5..fdfe61fb 100755
--- a/setup.py
+++ b/setup.py
@@ -108,7 +108,6 @@ def main() -> None:
"kvmd.apps.janus",
"kvmd.apps.watchdog",
"kvmd.helpers",
- "kvmd.helpers.unlock",
"kvmd.helpers.remount",
],
@@ -129,7 +128,6 @@ def main() -> None:
"kvmd-vnc = kvmd.apps.vnc:main",
"kvmd-janus = kvmd.apps.janus:main",
"kvmd-watchdog = kvmd.apps.watchdog:main",
- "kvmd-helper-otgmsd-unlock = kvmd.helpers.unlock:main",
"kvmd-helper-otgmsd-remount = kvmd.helpers.remount:main",
"kvmd-helper-pst-remount = kvmd.helpers.remount:main",
],
diff --git a/testenv/Dockerfile b/testenv/Dockerfile
index d03ba61e..46105815 100644
--- a/testenv/Dockerfile
+++ b/testenv/Dockerfile
@@ -95,19 +95,10 @@ RUN git clone https://github.com/pikvm/ustreamer \
RUN mkdir -p \
/etc/kvmd/{nginx,vnc} \
/var/lib/kvmd/msd/{images,meta} \
- /opt/vc/bin \
- /fake_sysfs/sys/kernel/config/usb_gadget/kvmd/configs/c.1 \
- /fake_sysfs/sys/kernel/config/usb_gadget/kvmd/functions/mass_storage.usb0/lun.0 \
- /fake_sysfs/sys/class/thermal/thermal_zone0 \
- /fake_procfs/proc/device-tree \
- /fake_sysfs/sys/class/udc/fe980000.usb/device \
- /fake_sysfs/sys/bus/platform/drivers/dwc2 \
- && echo configured > /fake_sysfs/sys/class/udc/fe980000.usb/state \
- && ln -s /fake_sysfs/sys/bus/platform/drivers/dwc2 /fake_sysfs/sys/class/udc/fe980000.usb/device/driver
+ /opt/vc/bin
COPY testenv/fakes/vcgencmd /opt/vc/bin/
-COPY testenv/fakes/msd/* /fake_sysfs/sys/kernel/config/usb_gadget/kvmd/functions/mass_storage.usb0/lun.0/
-COPY testenv/fakes/cpu_temp /fake_sysfs/sys/class/thermal/thermal_zone0/temp
-COPY testenv/fakes/dt_model /fake_procfs/proc/device-tree/model
+COPY testenv/fakes/sys /fake_sysfs/sys
+COPY testenv/fakes/proc /fake_procfs/proc
CMD /bin/bash
diff --git a/testenv/fakes/dt_model b/testenv/fakes/proc/device-tree/model
index 3afd3566..3afd3566 100644
--- a/testenv/fakes/dt_model
+++ b/testenv/fakes/proc/device-tree/model
diff --git a/testenv/fakes/cpu_temp b/testenv/fakes/sys/class/thermal/thermal_zone0/temp
index 9db0c8a7..9db0c8a7 100644
--- a/testenv/fakes/cpu_temp
+++ b/testenv/fakes/sys/class/thermal/thermal_zone0/temp
diff --git a/testenv/fakes/sys/class/udc/fe980000.usb/device/driver b/testenv/fakes/sys/class/udc/fe980000.usb/device/driver
new file mode 120000
index 00000000..cd14daa3
--- /dev/null
+++ b/testenv/fakes/sys/class/udc/fe980000.usb/device/driver
@@ -0,0 +1 @@
+../../../../bus/platform/drivers/dwc2 \ No newline at end of file
diff --git a/testenv/fakes/sys/class/udc/fe980000.usb/state b/testenv/fakes/sys/class/udc/fe980000.usb/state
new file mode 100644
index 00000000..6ad6460c
--- /dev/null
+++ b/testenv/fakes/sys/class/udc/fe980000.usb/state
@@ -0,0 +1 @@
+configured
diff --git a/testenv/fakes/sys/kernel/config/usb_gadget/kvmd/configs/c.1/mass_storage.usb0 b/testenv/fakes/sys/kernel/config/usb_gadget/kvmd/configs/c.1/mass_storage.usb0
new file mode 120000
index 00000000..b7637404
--- /dev/null
+++ b/testenv/fakes/sys/kernel/config/usb_gadget/kvmd/configs/c.1/mass_storage.usb0
@@ -0,0 +1 @@
+../../functions/mass_storage.usb0 \ No newline at end of file
diff --git a/testenv/fakes/msd/cdrom b/testenv/fakes/sys/kernel/config/usb_gadget/kvmd/functions/mass_storage.usb0/lun.0/cdrom
index d00491fd..d00491fd 100644
--- a/testenv/fakes/msd/cdrom
+++ b/testenv/fakes/sys/kernel/config/usb_gadget/kvmd/functions/mass_storage.usb0/lun.0/cdrom
diff --git a/testenv/fakes/msd/file b/testenv/fakes/sys/kernel/config/usb_gadget/kvmd/functions/mass_storage.usb0/lun.0/file
index e69de29b..e69de29b 100644
--- a/testenv/fakes/msd/file
+++ b/testenv/fakes/sys/kernel/config/usb_gadget/kvmd/functions/mass_storage.usb0/lun.0/file
diff --git a/testenv/fakes/sys/kernel/config/usb_gadget/kvmd/functions/mass_storage.usb0/lun.0/forced_eject b/testenv/fakes/sys/kernel/config/usb_gadget/kvmd/functions/mass_storage.usb0/lun.0/forced_eject
new file mode 120000
index 00000000..1a010b1c
--- /dev/null
+++ b/testenv/fakes/sys/kernel/config/usb_gadget/kvmd/functions/mass_storage.usb0/lun.0/forced_eject
@@ -0,0 +1 @@
+file \ No newline at end of file
diff --git a/testenv/fakes/msd/ro b/testenv/fakes/sys/kernel/config/usb_gadget/kvmd/functions/mass_storage.usb0/lun.0/ro
index d00491fd..d00491fd 100644
--- a/testenv/fakes/msd/ro
+++ b/testenv/fakes/sys/kernel/config/usb_gadget/kvmd/functions/mass_storage.usb0/lun.0/ro
diff --git a/testenv/v2-hdmi-rpi4.override.yaml b/testenv/v2-hdmi-rpi4.override.yaml
index dc63b3a3..2625f081 100644
--- a/testenv/v2-hdmi-rpi4.override.yaml
+++ b/testenv/v2-hdmi-rpi4.override.yaml
@@ -17,7 +17,6 @@ kvmd:
msd:
remount_cmd: /bin/true
- unlock_cmd: /bin/true
streamer:
desired_fps: 30
diff --git a/testenv/v2-hdmiusb-rpi4.override.yaml b/testenv/v2-hdmiusb-rpi4.override.yaml
index 45e857b1..958bfd34 100644
--- a/testenv/v2-hdmiusb-rpi4.override.yaml
+++ b/testenv/v2-hdmiusb-rpi4.override.yaml
@@ -14,7 +14,6 @@ kvmd:
msd:
remount_cmd: /bin/true
- unlock_cmd: /bin/true
streamer:
cmd: