From 6945dbec12d43f15dfe9a9050c845d38bde3c8e4 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sun, 8 Oct 2023 18:24:43 +0200 Subject: targets: move _resolve_mntdev() out of TargetSSHLVM Make it a standalone function, it does not need anything from the class. --- lbup/targets.py | 73 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 37 insertions(+), 36 deletions(-) (limited to 'lbup') diff --git a/lbup/targets.py b/lbup/targets.py index c6d7df8..877f3d7 100644 --- a/lbup/targets.py +++ b/lbup/targets.py @@ -35,6 +35,42 @@ def _parse_name(name): return SSHRemote(host, port, username) +def _resolve_mntdev(mntinfo, dirs): + """ + Find the device on which dirs to back up are located. + + This also checks that all the dirs are on the same mount and no non-trivial + topologies (like bind mounts) are involved, + otherwise a BackupException is raised. + + Return a tuple of (devnum, mountpoint, fstype) + """ + devnum = None + mountpoint = None + fstype = None + for d in dirs: + mp = mntinfo.mountpoint_for_path(d) + e = list(mntinfo.entries_for_mountpoint(mp)) + + if len(e) != 1: + raise BackupException('Expected exactly one mountpoint for dir', d, str(e)) + if e[0].root != ROOT: + raise BackupException('Mountpoint is a bind mount, which is not supported', str(e[0])) + dn = e[0].devnum + + if devnum is None: + devnum = dn + mountpoint = mp + fstype = e[0].fstype + continue + + if dn != devnum or mp != mountpoint: + raise BackupException('Mismatching device numbers/mountpoints', + dn, devnum, mp, mountpoint) + + return (devnum, mountpoint, fstype) + + class Target(ABC): name = None dirs = None @@ -235,41 +271,6 @@ class TargetSSHLVM(TargetSSH): """ return 1 - def _resolve_mntdev(self, mntinfo, dirs): - """ - Find out which LV to snapshot. - - This also checks that all the dirs are on the same LV and no non-trivial - topologies (like bind mounts) are involved, - otherwise a BackupException is raised. - - Return a tuple of (devnum, mountpoint) - """ - devnum = None - mountpoint = None - fstype = None - for d in dirs: - mp = mntinfo.mountpoint_for_path(d) - e = list(mntinfo.entries_for_mountpoint(mp)) - - if len(e) != 1: - raise BackupException('Expected exactly one mountpoint for dir', d, str(e)) - if e[0].root != ROOT: - raise BackupException('Mountpoint is a bind mount, which is not supported', str(e[0])) - dn = e[0].devnum - - if devnum is None: - devnum = dn - mountpoint = mp - fstype = e[0].fstype - continue - - if dn != devnum or mp != mountpoint: - raise BackupException('Mismatching device numbers/mountpoints', - dn, devnum, mp, mountpoint) - - return (devnum, mountpoint, fstype) - def _resolve_lv(self, ssh, devnum): """ Find the logical volume for the given device number. @@ -364,7 +365,7 @@ class TargetSSHLVM(TargetSSH): self._paramiko_exec_cmd(conn_root, 'cat /proc/%d/mountinfo' % self._mntns_pid, decode = False)) - devnum, mountpoint, fstype = self._resolve_mntdev(mntinfo, dirs) + devnum, mountpoint, fstype = _resolve_mntdev(mntinfo, dirs) # make sure we have a valid fstype fstype = fstype.decode('ascii') -- cgit v1.2.3