summaryrefslogtreecommitdiff
path: root/kvmd
diff options
context:
space:
mode:
authorMaxim Devaev <[email protected]>2022-03-31 11:54:31 +0300
committerMaxim Devaev <[email protected]>2022-03-31 11:54:31 +0300
commit6828a0e6aaa2ab0e95ac9f84980aa17805c3f3ba (patch)
treeb60a8a2c15c0829f8a05e29ad31c476da6612260 /kvmd
parent03a4c13291c4a876a519fa545842404ad1d88b1c (diff)
otg msd: handle functions switching
Diffstat (limited to 'kvmd')
-rw-r--r--kvmd/plugins/msd/otg/__init__.py5
-rw-r--r--kvmd/plugins/msd/otg/drive.py21
2 files changed, 19 insertions, 7 deletions
diff --git a/kvmd/plugins/msd/otg/__init__.py b/kvmd/plugins/msd/otg/__init__.py
index 6a01f1a3..f6a68b86 100644
--- a/kvmd/plugins/msd/otg/__init__.py
+++ b/kvmd/plugins/msd/otg/__init__.py
@@ -216,7 +216,7 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
return {
"enabled": True,
- "online": bool(self.__state.vd),
+ "online": (bool(self.__state.vd) and self.__drive.is_enabled()),
"busy": self.__state.is_busy(),
"storage": storage,
"drive": vd,
@@ -405,7 +405,8 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
with Inotify() as inotify:
inotify.watch(self.__images_path, InotifyMask.ALL_MODIFY_EVENTS)
inotify.watch(self.__meta_path, InotifyMask.ALL_MODIFY_EVENTS)
- inotify.watch(self.__drive.get_sysfs_path(), InotifyMask.ALL_MODIFY_EVENTS)
+ for path in self.__drive.get_watchable_paths():
+ inotify.watch(path, InotifyMask.ALL_MODIFY_EVENTS)
# После установки вотчеров еще раз проверяем стейт, чтобы ничего не потерять
await self.__reload_state()
diff --git a/kvmd/plugins/msd/otg/drive.py b/kvmd/plugins/msd/otg/drive.py
index 66ea2de4..1bbb2558 100644
--- a/kvmd/plugins/msd/otg/drive.py
+++ b/kvmd/plugins/msd/otg/drive.py
@@ -23,6 +23,8 @@
import os
import errno
+from typing import List
+
from .... import env
from .. import MsdOperationError
@@ -37,14 +39,23 @@ class MsdDriveLockedError(MsdOperationError):
# =====
class Drive:
def __init__(self, gadget: str, instance: int, lun: int) -> None:
- self.__path = os.path.join(
+ self.__lun_path = os.path.join(
f"{env.SYSFS_PREFIX}/sys/kernel/config/usb_gadget",
gadget,
f"functions/mass_storage.usb{instance}/lun.{lun}",
)
+ self.__configs_root_path = os.path.join(
+ f"{env.SYSFS_PREFIX}/sys/kernel/config/usb_gadget",
+ gadget,
+ "configs/c.1",
+ )
+ self.__func_path = os.path.join(self.__configs_root_path, f"mass_storage.usb{instance}")
+
+ def is_enabled(self) -> bool:
+ return os.path.exists(self.__func_path)
- def get_sysfs_path(self) -> str:
- return self.__path
+ def get_watchable_paths(self) -> List[str]:
+ return [self.__lun_path, self.__configs_root_path]
# =====
@@ -69,12 +80,12 @@ class Drive:
# =====
def __get_param(self, param: str) -> str:
- with open(os.path.join(self.__path, param)) as param_file:
+ with open(os.path.join(self.__lun_path, param)) as param_file:
return param_file.read().strip()
def __set_param(self, param: str, value: str) -> None:
try:
- with open(os.path.join(self.__path, param), "w") as param_file:
+ with open(os.path.join(self.__lun_path, param), "w") as param_file:
param_file.write(value + "\n")
except OSError as err:
if err.errno == errno.EBUSY: