From cf9e1c96fd63d8893f4ddd58501123235c2d2728 Mon Sep 17 00:00:00 2001 From: OpenGnSys Support Team Date: Tue, 1 Oct 2024 16:58:02 +0200 Subject: live: fix EBUSY error in newer kernels with mkfs python-libfdisk does not close file descriptor to /dev/sda after completing partitioning. This results EBUSY errors when formatting partitions with mkfs in newer kernels. Encapsulate code to partition in method so python garbage collection knows ctx objects can be release then close file descritor to /dev/sda. ogRest is not accessible from _partition(), remove check to ogRest.terminated, actually no need to terminate inmediately when formatting is ongoing, better leave things in consistent state when stop command is received. --- src/live/ogOperations.py | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) (limited to 'src/live/ogOperations.py') diff --git a/src/live/ogOperations.py b/src/live/ogOperations.py index 4b3ec13..2451c9b 100644 --- a/src/live/ogOperations.py +++ b/src/live/ogOperations.py @@ -454,23 +454,7 @@ class OgLiveOperations: logging.info('Successful hardware inventory command execution') return result - def setup(self, request, ogRest): - table_type = request.getType() - disk = int(request.getDisk()) - cache = request.getCache() - cache_size = request.getCacheSize() - partlist = request.getPartitionSetup() - - self._ogbrowser_clear_logs() - self._restartBrowser(self._url_log) - - umount_all() - umount_cache() - - if disk < 0 or disk > len(get_disks()): - raise OgError(f'Invalid disk number {disk}, {len(get_disks())} disks available.') - - diskname = get_disks()[disk-1] + def _partition(self, diskname, table_type, partlist): cxt = fdisk.Context(f'/dev/{diskname}', details=True) @@ -487,8 +471,6 @@ class OgLiveOperations: logging.info(f'Creating partition {part["partition"]} with {part["code"]} of {int(part["size"])//1024} MiB') if part["code"] == 'EMPTY': continue - if ogRest.terminated: - break pa = fdisk.Partition(start_follow_default=True, end_follow_default=False, @@ -503,6 +485,26 @@ class OgLiveOperations: cxt.write_disklabel() os.sync() + + def setup(self, request, ogRest): + table_type = request.getType() + disk = int(request.getDisk()) + cache = request.getCache() + cache_size = request.getCacheSize() + partlist = request.getPartitionSetup() + + self._ogbrowser_clear_logs() + self._restartBrowser(self._url_log) + + umount_all() + umount_cache() + + if disk < 0 or disk > len(get_disks()): + raise OgError(f'Invalid disk number {disk}, {len(get_disks())} disks available.') + + diskname = get_disks()[disk-1] + self._partition(diskname, table_type, partlist) + ret = subprocess.run(['partprobe', f'/dev/{diskname}']) logging.info(f'first partprobe /dev/{diskname} reports {ret.returncode}') -- cgit v1.2.3-18-g5258