Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix some tricky bugs by setting flags at the proper timing and place #371

Merged
merged 3 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_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
12 changes: 10 additions & 2 deletions mtda/storage/helpers/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class BmapWriteError(OSError):


class Image(StorageController):
_is_storage_mounted = False

def __init__(self, mtda):
self.mtda = mtda
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,14 +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()

self.mtda.debug(3, "storage.helpers.image.umount(): %s" % str(result))
return result

Expand Down Expand Up @@ -227,6 +232,8 @@ def mount(self, part=None):
self.mtda.debug(3, "storage.helpers.image.mount()")
with self.lock:
result = self._mount_impl(part)
if result is True:
Image._is_storage_mounted = True
self.mtda.debug(3, "storage.helpers.image.mount(): %s" % str(result))
return result

Expand Down Expand Up @@ -295,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
10 changes: 6 additions & 4 deletions mtda/storage/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ def put(self, chunk, block=True, timeout=None):
self.mtda.debug(1, "storage.writer.put(): no storage!")
raise IOError("no storage!")
result = super().put(chunk, block, timeout)

# if thread is started and put data is not empty
if len(chunk) > 0 and self._exiting is False:
self._writing = True
self.mtda.debug(3, "storage.writer.put(): %s" % str(result))
return result

Expand Down Expand Up @@ -120,17 +122,17 @@ def worker(self):
self._failed = False
self._written = 0
while self._exiting is False:
if self.empty():
self._writing = False
chunk = self.get()
if self._exiting is False:
self._writing = True
try:
self._write(chunk)
except Exception as e:
self.mtda.debug(1, "storage.writer.worker(): {}".format(e))
self._failed = True
pass
finally:
self._writing = False
pass
self.task_done()
if self._failed is True:
self.mtda.debug(1, "storage.writer.worker(): "
Expand Down