From 115f3fdb7f8ca9470dffb886b4250272e81a394f Mon Sep 17 00:00:00 2001 From: svalouch Date: Fri, 7 Aug 2020 13:36:21 +0200 Subject: [PATCH] Improve handling of mountpoint, support pe_helper mounting --- src/simplezfs/pe_helper.py | 14 +++++++++++--- src/simplezfs/zfs_cli.py | 14 ++++++++++++-- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/simplezfs/pe_helper.py b/src/simplezfs/pe_helper.py index 2bdaf74..c4ada23 100644 --- a/src/simplezfs/pe_helper.py +++ b/src/simplezfs/pe_helper.py @@ -20,10 +20,10 @@ class PEHelperBase: def __repr__(self) -> str: return '' - def zfs_mount(self, fileset: str, mountpoint: Optional[str] = None) -> None: + def zfs_mount(self, fileset: str) -> None: ''' - Tries to mount ``fileset``. An optional ``mountpoint`` can be given, otherwise it relies on inheritance to set - the mountpoint. Note that some implementations may need an explicit mountpoint. + Tries to mount ``fileset`` to the location its ``mountpoint`` property points to. It does **not** check if the + fileset has a valid mountpoint property. :raises ValidationError: If parameters do not validate. :raises PEHelperException: If errors are encountered when running the helper. @@ -157,6 +157,14 @@ class SudoPEHelper(PEHelperBase): raise PEHelperException(f'Error running command {" ".join(args)}: {proc.stderr}') self.log.debug(f'pe helper command successful. stout: {proc.stdout}') + def zfs_mount(self, fileset: str) -> None: + if '/' in fileset: + validate_dataset_path(fileset) + else: + validate_pool_name(fileset) + + self._execute_cmd(['zfs', 'mount', fileset]) + def zfs_set_mountpoint(self, fileset: str, mountpoint: str) -> None: if '/' in fileset: validate_dataset_path(fileset) diff --git a/src/simplezfs/zfs_cli.py b/src/simplezfs/zfs_cli.py index 7b2452f..29780c3 100644 --- a/src/simplezfs/zfs_cli.py +++ b/src/simplezfs/zfs_cli.py @@ -267,8 +267,18 @@ class ZFSCli(ZFS): if properties and 'mountpoint' in properties: mp = properties['mountpoint'] if self.pe_helper is not None: - log.info(f'Fileset {name} was created, using pe_helper to set the mountpoint') - self.pe_helper.zfs_set_mountpoint(name, mp) + test_prop = self.get_property(dataset=name, key='mountpoint', metadata=False) + if test_prop.value == mp: + log.info(f'Fileset {name} was created with mountpoint set') + else: + log.info(f'Fileset {name} was created, using pe_helper to set the mountpoint') + self.pe_helper.zfs_set_mountpoint(name, mp) + test_prop = self.get_property(dataset=name, key='mounted', metadata=False) + if test_prop.value == 'yes': + log.info(f'Fileset {name} is mounted') + else: + log.info(f'Using pe_helper to mount fileset {name}') + self.pe_helper.zfs_mount(name) log.info(f'Fileset {name} created successfully (using pe_helper)') return self.get_dataset_info(name) else: