Break an import cycle between lib/luks and lib/disk/device_handler (#3438)
This commit is contained in:
parent
4ed6d0da9b
commit
781760a157
|
|
@ -45,6 +45,7 @@ from .utils import (
|
||||||
find_lsblk_info,
|
find_lsblk_info,
|
||||||
get_all_lsblk_info,
|
get_all_lsblk_info,
|
||||||
get_lsblk_info,
|
get_lsblk_info,
|
||||||
|
umount,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -257,7 +258,7 @@ class DeviceHandler:
|
||||||
subvol_infos.append(_BtrfsSubvolumeInfo(name, sub_vol_mountpoint))
|
subvol_infos.append(_BtrfsSubvolumeInfo(name, sub_vol_mountpoint))
|
||||||
|
|
||||||
if not lsblk_info.mountpoint:
|
if not lsblk_info.mountpoint:
|
||||||
self.umount(dev_path)
|
umount(dev_path)
|
||||||
|
|
||||||
return subvol_infos
|
return subvol_infos
|
||||||
|
|
||||||
|
|
@ -635,7 +636,7 @@ class DeviceHandler:
|
||||||
except SysCallError as err:
|
except SysCallError as err:
|
||||||
raise DiskError(f'Could not set compress attribute at {subvol_path}: {err}')
|
raise DiskError(f'Could not set compress attribute at {subvol_path}: {err}')
|
||||||
|
|
||||||
self.umount(path)
|
umount(path)
|
||||||
|
|
||||||
def create_btrfs_volumes(
|
def create_btrfs_volumes(
|
||||||
self,
|
self,
|
||||||
|
|
@ -677,7 +678,7 @@ class DeviceHandler:
|
||||||
|
|
||||||
SysCommand(f"btrfs subvolume create -p {subvol_path}")
|
SysCommand(f"btrfs subvolume create -p {subvol_path}")
|
||||||
|
|
||||||
self.umount(dev_path)
|
umount(dev_path)
|
||||||
|
|
||||||
if luks_handler is not None and luks_handler.mapper_dev is not None:
|
if luks_handler is not None and luks_handler.mapper_dev is not None:
|
||||||
luks_handler.lock()
|
luks_handler.lock()
|
||||||
|
|
@ -710,7 +711,7 @@ class DeviceHandler:
|
||||||
if partition.fs_type == FilesystemType.Crypto_luks:
|
if partition.fs_type == FilesystemType.Crypto_luks:
|
||||||
Luks2(partition.path).lock()
|
Luks2(partition.path).lock()
|
||||||
else:
|
else:
|
||||||
self.umount(partition.path, recursive=True)
|
umount(partition.path, recursive=True)
|
||||||
|
|
||||||
def partition(
|
def partition(
|
||||||
self,
|
self,
|
||||||
|
|
@ -790,23 +791,6 @@ class DeviceHandler:
|
||||||
except SysCallError as err:
|
except SysCallError as err:
|
||||||
raise DiskError(f'Could not mount {dev_path}: {command}\n{err.message}')
|
raise DiskError(f'Could not mount {dev_path}: {command}\n{err.message}')
|
||||||
|
|
||||||
def umount(self, mountpoint: Path, recursive: bool = False) -> None:
|
|
||||||
lsblk_info = get_lsblk_info(mountpoint)
|
|
||||||
|
|
||||||
if not lsblk_info.mountpoints:
|
|
||||||
return
|
|
||||||
|
|
||||||
debug(f'Partition {mountpoint} is currently mounted at: {[str(m) for m in lsblk_info.mountpoints]}')
|
|
||||||
|
|
||||||
cmd = ['umount']
|
|
||||||
|
|
||||||
if recursive:
|
|
||||||
cmd.append('-R')
|
|
||||||
|
|
||||||
for path in lsblk_info.mountpoints:
|
|
||||||
debug(f'Unmounting mountpoint: {path}')
|
|
||||||
SysCommand(cmd + [str(path)])
|
|
||||||
|
|
||||||
def detect_pre_mounted_mods(self, base_mountpoint: Path) -> list[DeviceModification]:
|
def detect_pre_mounted_mods(self, base_mountpoint: Path) -> list[DeviceModification]:
|
||||||
part_mods: dict[Path, list[PartitionModification]] = {}
|
part_mods: dict[Path, list[PartitionModification]] = {}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -108,3 +108,21 @@ def disk_layouts() -> str:
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
return lsblk_output.model_dump_json(indent=4)
|
return lsblk_output.model_dump_json(indent=4)
|
||||||
|
|
||||||
|
|
||||||
|
def umount(mountpoint: Path, recursive: bool = False) -> None:
|
||||||
|
lsblk_info = get_lsblk_info(mountpoint)
|
||||||
|
|
||||||
|
if not lsblk_info.mountpoints:
|
||||||
|
return
|
||||||
|
|
||||||
|
debug(f'Partition {mountpoint} is currently mounted at: {[str(m) for m in lsblk_info.mountpoints]}')
|
||||||
|
|
||||||
|
cmd = ['umount']
|
||||||
|
|
||||||
|
if recursive:
|
||||||
|
cmd.append('-R')
|
||||||
|
|
||||||
|
for path in lsblk_info.mountpoints:
|
||||||
|
debug(f'Unmounting mountpoint: {path}')
|
||||||
|
SysCommand(cmd + [str(path)])
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ from dataclasses import dataclass
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from subprocess import CalledProcessError
|
from subprocess import CalledProcessError
|
||||||
|
|
||||||
from archinstall.lib.disk.utils import get_lsblk_info
|
from archinstall.lib.disk.utils import get_lsblk_info, umount
|
||||||
|
|
||||||
from .exceptions import DiskError, SysCallError
|
from .exceptions import DiskError, SysCallError
|
||||||
from .general import SysCommand, SysCommandWorker, generate_password, run
|
from .general import SysCommand, SysCommandWorker, generate_password, run
|
||||||
|
|
@ -153,8 +153,7 @@ class Luks2:
|
||||||
raise DiskError(f'Failed to open luks2 device: {self.luks_dev_path}')
|
raise DiskError(f'Failed to open luks2 device: {self.luks_dev_path}')
|
||||||
|
|
||||||
def lock(self) -> None:
|
def lock(self) -> None:
|
||||||
from archinstall.lib.disk.device_handler import device_handler
|
umount(self.luks_dev_path)
|
||||||
device_handler.umount(self.luks_dev_path)
|
|
||||||
|
|
||||||
# Get crypt-information about the device by doing a reverse lookup starting with the partition path
|
# Get crypt-information about the device by doing a reverse lookup starting with the partition path
|
||||||
# For instance: /dev/sda
|
# For instance: /dev/sda
|
||||||
|
|
@ -165,7 +164,7 @@ class Luks2:
|
||||||
# Unmount the child location
|
# Unmount the child location
|
||||||
for mountpoint in child.mountpoints:
|
for mountpoint in child.mountpoints:
|
||||||
debug(f'Unmounting {mountpoint}')
|
debug(f'Unmounting {mountpoint}')
|
||||||
device_handler.umount(mountpoint, recursive=True)
|
umount(mountpoint, recursive=True)
|
||||||
|
|
||||||
# And close it if possible.
|
# And close it if possible.
|
||||||
debug(f"Closing crypt device {child.name}")
|
debug(f"Closing crypt device {child.name}")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue