diff --git a/lvmsnapshot.py b/lvmsnapshot.py index cbb8e0063666c771e2a3f24bd31d2fb5c4e59b94..088b34fac19780a2546d7474b8e738304bc8d7f3 100644 --- a/lvmsnapshot.py +++ b/lvmsnapshot.py @@ -131,10 +131,10 @@ class Snapshot: self.get_name().replace("-", "--")) def get_mount_options(self): - return "-nfstype=xfs,ro,noatime,nouuid,norecovery" + return "ro,noatime,nouuid,norecovery" def get_tab_entry(self): - return "{} {} :{}".format( + return "{} -fstype=xfs,{} :{}".format( self.get_name(), self.get_mount_options(), self.get_mapper_device()) @@ -166,10 +166,21 @@ class Snapshot: "/bin/mount", self.get_mapper_device(), self.get_mountpoint(), - self.get_mount_options() # nouuid is necessary for xfs snapshots + "-o", self.get_mount_options() ] sp.run(mount_command, check=True) + def check_mount(self): + check_command = [ + "/bin/findmnt", + "--source", self.get_mapper_device() + ] + try: + sp.check_call(check_command) + return True + except sp.CalledProcessError: + return False + def remove(self): self.unmount() remove_command = [ @@ -179,11 +190,12 @@ class Snapshot: sp.run(remove_command, check=True) def unmount(self): - unmount_command = [ - "/bin/umount", - self.get_mountpoint() - ] - sp.run(unmount_command, check=True) + if self.check_mount(): + unmount_command = [ + "/bin/umount", + self.get_mountpoint() + ] + sp.run(unmount_command, check=True) deactivate_command = [ "/sbin/lvchange", "--activate", "n",