summaryrefslogtreecommitdiff
path: root/lbup
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2023-10-08 18:24:43 +0200
committerAnton Khirnov <anton@khirnov.net>2023-10-08 18:24:43 +0200
commit6945dbec12d43f15dfe9a9050c845d38bde3c8e4 (patch)
tree11c0315ecfbd8362bad8690c8f4d804921f675ec /lbup
parenta7fead47c8ba3d1e0c0455fb61f60292d0261bc7 (diff)
targets: move _resolve_mntdev() out of TargetSSHLVM
Make it a standalone function, it does not need anything from the class.
Diffstat (limited to 'lbup')
-rw-r--r--lbup/targets.py73
1 files changed, 37 insertions, 36 deletions
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')