From be91d52cbc3d51498903c57c99e8af44791f8cfe Mon Sep 17 00:00:00 2001 From: Ding Meng Date: Wed, 22 Nov 2023 05:22:39 -0500 Subject: [PATCH] storage: reset storage_bmap_dict after writing and refactor reset storage_bmap_dict after writing refactor is_storage_mounted set Image._is_storage_mounted to False in _umount Signed-off-by: Ding Meng --- mtda/client.py | 1 + mtda/main.py | 2 +- mtda/storage/helpers/image.py | 15 ++++++++++----- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/mtda/client.py b/mtda/client.py index 36ef147f..095838d2 100644 --- a/mtda/client.py +++ b/mtda/client.py @@ -270,6 +270,7 @@ def storage_write_image(self, path, callback=None): finally: # Storage may be closed now self.storage_close() + self._impl.storage_bmap_dict(None, self._session) def parseBmap(self, bmap, bmap_path): try: diff --git a/mtda/main.py b/mtda/main.py index ea8799fd..3e66bfbe 100644 --- a/mtda/main.py +++ b/mtda/main.py @@ -643,7 +643,7 @@ def storage_mount(self, part=None, session=None): self.mtda.debug(3, "main.storage_mount()") self._session_check(session) - if self.storage_controller.static_is_mounted is True: + if self.storage.is_storage_mounted is True: self.mtda.debug(4, "storage_mount(): already mounted") result = True elif self.storage is None: diff --git a/mtda/storage/helpers/image.py b/mtda/storage/helpers/image.py index d8f576dc..c25d5bc5 100644 --- a/mtda/storage/helpers/image.py +++ b/mtda/storage/helpers/image.py @@ -32,7 +32,8 @@ class BmapWriteError(OSError): class Image(StorageController): - static_is_mounted = False + _is_storage_mounted = False + def __init__(self, mtda): self.mtda = mtda self.handle = None @@ -46,6 +47,10 @@ def __init__(self, mtda): self.lock = threading.Lock() atexit.register(self._umount) + @property + def is_storage_mounted(self): + return Image._is_storage_mounted + def _close(self): self.mtda.debug(3, "storage.helpers.image._close()") @@ -123,6 +128,7 @@ def _umount(self): self.isloop = False self.mtda.debug(3, "storage.helpers.image._umount(): %s" % str(result)) + Image._is_storage_mounted = result is False return result def umount(self): @@ -130,8 +136,6 @@ def umount(self): with self.lock: result = self._umount() - if result is True: - static_is_mounted = False self.mtda.debug(3, "storage.helpers.image.umount(): %s" % str(result)) return result @@ -229,7 +233,7 @@ def mount(self, part=None): with self.lock: result = self._mount_impl(part) if result is True: - static_is_mounted = True + Image._is_storage_mounted = True self.mtda.debug(3, "storage.helpers.image.mount(): %s" % str(result)) return result @@ -298,7 +302,8 @@ def setBmap(self, bmapDict): self.crtBlockRange = 0 self.writtenBytes = 0 self.overlap = 0 - self.rangeChkSum = self._get_hasher_by_name() + if bmapDict is not None: + self.rangeChkSum = self._get_hasher_by_name() def supports_hotplug(self): return False