From 4bdb46b9ba223f9a482fe9ea1173a68c6c6d32d6 Mon Sep 17 00:00:00 2001 From: "M. Rehan" Date: Thu, 4 Jul 2024 19:55:28 +0500 Subject: [PATCH] NAS-129230 / 24.10 / Fix progress reporting in formatting disks and it's related usages (#13973) * Fix progress reporting in formatting disks and it's related usages * Remove async lock --- .../middlewared/plugins/pool_/attach_disk.py | 13 ++++++++----- .../middlewared/plugins/pool_/format_disks.py | 12 ++++++++---- src/middlewared/middlewared/plugins/pool_/pool.py | 4 ++-- .../middlewared/plugins/pool_/replace_disk.py | 2 +- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/middlewared/middlewared/plugins/pool_/attach_disk.py b/src/middlewared/middlewared/plugins/pool_/attach_disk.py index f0164cca4a4a1..d3ad0b147e787 100644 --- a/src/middlewared/middlewared/plugins/pool_/attach_disk.py +++ b/src/middlewared/middlewared/plugins/pool_/attach_disk.py @@ -53,22 +53,25 @@ async def attach(self, job, oid, options): ) verrors.check() + job.set_progress(3, 'Completed validation') + guid = vdev['guid'] if vdev['type'] in ['DISK', 'RAIDZ1', 'RAIDZ2', 'RAIDZ3'] else vdev['children'][0]['guid'] disks = {options['new_disk']: {'vdev': []}} - await self.middleware.call('pool.format_disks', job, disks) - + job.set_progress(5, 'Formatting disks') + await self.middleware.call('pool.format_disks', job, disks, 5, 20) + job.set_progress(22, 'Extending pool') devname = disks[options['new_disk']]['vdev'][0] extend_job = await self.middleware.call('zfs.pool.extend', pool['name'], None, [ {'target': guid, 'type': 'DISK', 'path': devname} ]) - await job.wrap(extend_job) + await extend_job.wait(raise_error=True) if vdev['type'] in ('RAIDZ1', 'RAIDZ2', 'RAIDZ3'): while True: expand = await self.middleware.call('zfs.pool.expand_state', pool['name']) if expand['state'] is None: - job.set_progress(0, 'Waiting for expansion to start') + job.set_progress(25, 'Waiting for expansion to start') await asyncio.sleep(1) continue @@ -81,6 +84,6 @@ async def attach(self, job, oid, options): else: message = 'Expanding' - job.set_progress(min(expand['percentage'], 100), message) + job.set_progress(max(min(expand['percentage'], 95), 25), message) await asyncio.sleep(10 if expand['total_secs_left'] > 60 else 1) diff --git a/src/middlewared/middlewared/plugins/pool_/format_disks.py b/src/middlewared/middlewared/plugins/pool_/format_disks.py index 47723136adae8..2a83bce2f67dc 100644 --- a/src/middlewared/middlewared/plugins/pool_/format_disks.py +++ b/src/middlewared/middlewared/plugins/pool_/format_disks.py @@ -5,7 +5,7 @@ class PoolService(Service): @private - async def format_disks(self, job, disks): + async def format_disks(self, job, disks, base_percentage=0, upper_percentage=100): """ Format all disks, putting all ZFS partitions created into their respective vdevs. """ @@ -13,17 +13,21 @@ async def format_disks(self, job, disks): formatted = 0 len_disks = len(disks) + current_percentage = base_percentage + single_disk_percentage = (upper_percentage - base_percentage) / len_disks + async def format_disk(arg): - nonlocal formatted + nonlocal formatted, current_percentage disk, config = arg await self.middleware.call('disk.format', disk) formatted += 1 - job.set_progress(15, f'Formatting disks ({formatted}/{len_disks})') + current_percentage += single_disk_percentage + job.set_progress(current_percentage, f'Formatting disks ({formatted}/{len_disks})') await asyncio_map(format_disk, disks.items(), limit=16) disk_sync_job = await self.middleware.call('disk.sync_all') - await job.wrap(disk_sync_job) + await disk_sync_job.wait(raise_error=True) zfs_part_type = await self.middleware.call('disk.get_zfs_part_type') for disk, config in disks.items(): diff --git a/src/middlewared/middlewared/plugins/pool_/pool.py b/src/middlewared/middlewared/plugins/pool_/pool.py index 0f69d9e8a7f20..7dcf405bf0a28 100644 --- a/src/middlewared/middlewared/plugins/pool_/pool.py +++ b/src/middlewared/middlewared/plugins/pool_/pool.py @@ -566,7 +566,7 @@ async def do_create(self, job, data): # will log errors if there are any so it won't crash here (this matches CORE behavior) await (await self.middleware.call('disk.resize', log_disks, True)).wait() - await self.middleware.call('pool.format_disks', job, disks) + await self.middleware.call('pool.format_disks', job, disks, 0, 30) options = { 'feature@lz4_compress': 'enabled', @@ -713,7 +713,7 @@ async def do_update(self, job, id_, data): disks, vdevs = await self._process_topology('pool_update', data, pool) if disks and vdevs: - await self.middleware.call('pool.format_disks', job, disks) + await self.middleware.call('pool.format_disks', job, disks, 0, 80) job.set_progress(90, 'Extending ZFS Pool') extend_job = await self.middleware.call('zfs.pool.extend', pool['name'], vdevs) diff --git a/src/middlewared/middlewared/plugins/pool_/replace_disk.py b/src/middlewared/middlewared/plugins/pool_/replace_disk.py index c7d26877bb36a..7ce97402e71a2 100644 --- a/src/middlewared/middlewared/plugins/pool_/replace_disk.py +++ b/src/middlewared/middlewared/plugins/pool_/replace_disk.py @@ -69,7 +69,7 @@ async def replace(self, job, oid, options): 'vdev': vdev, 'size': None, # pool.format_disks checks size of disk }, - }) + }, 0, 25) try: job.set_progress(30, 'Replacing disk')