mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-01-29 00:51:53 +08:00
msd: reread device info while writing
This commit is contained in:
@@ -61,8 +61,8 @@ class DeviceInfo(NamedTuple):
|
|||||||
_DISK_META_SIZE = 4096
|
_DISK_META_SIZE = 4096
|
||||||
_DISK_META_MAGIC_SIZE = 16
|
_DISK_META_MAGIC_SIZE = 16
|
||||||
_DISK_META_IMAGE_NAME_SIZE = 256
|
_DISK_META_IMAGE_NAME_SIZE = 256
|
||||||
_DISK_META_PADS_SIZE = _DISK_META_SIZE - _DISK_META_IMAGE_NAME_SIZE - _DISK_META_MAGIC_SIZE * 8 * 2
|
_DISK_META_PADS_SIZE = _DISK_META_SIZE - _DISK_META_IMAGE_NAME_SIZE - _DISK_META_MAGIC_SIZE * 8
|
||||||
_DISK_META_FORMAT = "%dL%dc%dx%dL" % (
|
_DISK_META_FORMAT = ">%dL%dc%dx%dL" % (
|
||||||
_DISK_META_MAGIC_SIZE,
|
_DISK_META_MAGIC_SIZE,
|
||||||
_DISK_META_IMAGE_NAME_SIZE,
|
_DISK_META_IMAGE_NAME_SIZE,
|
||||||
_DISK_META_PADS_SIZE,
|
_DISK_META_PADS_SIZE,
|
||||||
@@ -185,10 +185,7 @@ class MassStorageDevice: # pylint: disable=too-many-instance-attributes
|
|||||||
# TODO: disable gpio
|
# TODO: disable gpio
|
||||||
if not no_delay:
|
if not no_delay:
|
||||||
await asyncio.sleep(self.__init_delay)
|
await asyncio.sleep(self.__init_delay)
|
||||||
path = await self.__loop.run_in_executor(None, locate_by_bind, self._bind)
|
await self.__reread_device_info()
|
||||||
if not path:
|
|
||||||
raise MassStorageError("Can't locate device by bind %r" % (self._bind))
|
|
||||||
self.__device_info = await self.__loop.run_in_executor(None, explore_device, path)
|
|
||||||
get_logger().info("Mass-storage device switched to KVM: %s", self.__device_info)
|
get_logger().info("Mass-storage device switched to KVM: %s", self.__device_info)
|
||||||
|
|
||||||
@_operated_and_locked
|
@_operated_and_locked
|
||||||
@@ -231,6 +228,7 @@ class MassStorageDevice: # pylint: disable=too-many-instance-attributes
|
|||||||
await self._device_file.flush()
|
await self._device_file.flush()
|
||||||
await self.__loop.run_in_executor(None, os.fsync, self._device_file.fileno())
|
await self.__loop.run_in_executor(None, os.fsync, self._device_file.fileno())
|
||||||
await self._device_file.seek(0)
|
await self._device_file.seek(0)
|
||||||
|
await self.__reread_device_info()
|
||||||
|
|
||||||
async def write_image_chunk(self, chunk: bytes) -> int:
|
async def write_image_chunk(self, chunk: bytes) -> int:
|
||||||
async with self._lock:
|
async with self._lock:
|
||||||
@@ -251,6 +249,12 @@ class MassStorageDevice: # pylint: disable=too-many-instance-attributes
|
|||||||
async with self._lock:
|
async with self._lock:
|
||||||
await self.__close_device_file()
|
await self.__close_device_file()
|
||||||
|
|
||||||
|
async def __reread_device_info(self) -> None:
|
||||||
|
path = await self.__loop.run_in_executor(None, locate_by_bind, self._bind)
|
||||||
|
if not path:
|
||||||
|
raise MassStorageError("Can't locate device by bind %r" % (self._bind))
|
||||||
|
self.__device_info = await self.__loop.run_in_executor(None, explore_device, path)
|
||||||
|
|
||||||
async def __close_device_file(self) -> None:
|
async def __close_device_file(self) -> None:
|
||||||
try:
|
try:
|
||||||
if self._device_file:
|
if self._device_file:
|
||||||
|
|||||||
Reference in New Issue
Block a user