From 8c345b32a662cc44a9dd88bb6cf2cfcbfd8c773e Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sun, 20 Feb 2022 21:47:54 +0100 Subject: zfssnap: async snapshots --- modules/zfssnap/zfssnap.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'modules/zfssnap') diff --git a/modules/zfssnap/zfssnap.py b/modules/zfssnap/zfssnap.py index a8ad231c..b53c6b17 100644 --- a/modules/zfssnap/zfssnap.py +++ b/modules/zfssnap/zfssnap.py @@ -25,6 +25,8 @@ from functools import cache from math import floor +import asyncio + @cache def _now(): @@ -234,7 +236,7 @@ def autosnap(): pass all_snap_names = set() - def do_snapshot(*snap_items, recursive=False): + async def do_snapshot(*snap_items, recursive=False): nonlocal items, all_snap_names snap_names = {_snap_name(item) for item in snap_items} if recursive: @@ -251,12 +253,16 @@ def autosnap(): _log_cmd(*args) subprocess.run(args, check=True) + tasks = [] if single: - do_snapshot(*single) + tasks.append(asyncio.create_task(do_snapshot(*single))) if recursive: - do_snapshot(*recursive, recursive=True) - if not single and not recursive: + tasks.append(asyncio.create_task(do_snapshot(*recursive, recursive=True))) + if not tasks: logger.warning('No snapshots to create') + else: + for task in tasks: + await task for snap in all_snap_names: logger.info(f'Created ‘{snap}’') if all_snap_names: -- cgit v1.2.3