Skip to content

Commit

Permalink
storage: reset storage_bmap_dict after writing and refactor
Browse files Browse the repository at this point in the history
  reset storage_bmap_dict after writing
  refactor is_storage_mounted
  set Image._is_storage_mounted to False in _umount

Signed-off-by: Ding Meng <[email protected]>
  • Loading branch information
DingMeng-Siemens committed Nov 22, 2023
1 parent 2125eaf commit be91d52
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions mtda/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion mtda/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 10 additions & 5 deletions mtda/storage/helpers/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()")

Expand Down Expand Up @@ -123,15 +128,14 @@ 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):
self.mtda.debug(3, "storage.helpers.image.umount()")

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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit be91d52

Please sign in to comment.