Removed subvolume logic from MapperDev().mount() as a mapperdev isn't a BtrfsSubvolume(), instead we need to create a BtrfsSubvolume().mount() that handles this.

This commit is contained in:
Anton Hvornum 2022-02-09 12:54:34 +01:00
parent 2319267a46
commit f1333eb77c
No known key found for this signature in database
GPG Key ID: F1234C5BA67C59DF
3 changed files with 40 additions and 11 deletions

View File

@ -25,6 +25,13 @@ GIGA = 2 ** 30
def convert_size_to_gb(size :Union[int, float]) -> float:
return round(size / GIGA,1)
def get_mount_fs_type(fs :str) -> str:
if fs == 'ntfs':
return 'ntfs3' # Needed to use the Paragon R/W NTFS driver
elif fs == 'fat32':
return 'vfat' # This is the actual type used for fat32 mounting
return fs
def sort_block_devices_based_on_performance(block_devices :List[BlockDevice]) -> Dict[BlockDevice, int]:
result = {device: 0 for device in block_devices}

View File

@ -87,4 +87,28 @@ class MapperDev:
def format(self, filesystem :str, options :List[str] = []) -> bool:
# TODO: Create a format() helper function rather than relying on a dummy Partition().format() call:
self.partition.format(filesystem=filesystem, options=options, path=self.path)
self.partition.format(filesystem=filesystem, options=options, path=self.path)
def mount(self, target :str, fs :Optional[str] = None, options :str = '') -> bool:
from .helpers import get_mount_fs_type
log(f'Mounting {self} to {target}', level=logging.INFO)
if not fs:
if not (fs := self.filesystem):
raise DiskError(f'Need to format (or define) the filesystem on {self} before mounting.')
fs_type = get_mount_fs_type(fs)
pathlib.Path(target).mkdir(parents=True, exist_ok=True)
try:
if options:
mnt_handle = SysCommand(f"/usr/bin/mount -t {fs_type} -o {options} {self.path} {target}")
else:
mnt_handle = SysCommand(f"/usr/bin/mount -t {fs_type} {self.path} {target}")
except SysCallError as err:
raise DiskError(f"Could not mount {self.path} to {target} using options {options}: {err}")
return True

View File

@ -8,7 +8,13 @@ import hashlib
from typing import Optional, Dict, Any, List, Union, Iterator
from .blockdevice import BlockDevice
from .helpers import find_mountpoint, get_filesystem_type, convert_size_to_gb, split_bind_name
from .helpers import (
find_mountpoint,
get_filesystem_type,
convert_size_to_gb,
split_bind_name,
get_mount_fs_type
)
from ..storage import storage
from ..exceptions import DiskError, SysCallError, UnknownFilesystemFormat
from ..output import log
@ -470,12 +476,4 @@ class Partition:
pass # We supported it, but /dev/null is not formattable as expected so the mkfs call exited with an error code
except UnknownFilesystemFormat as err:
raise err
return True
def get_mount_fs_type(fs :str) -> str:
if fs == 'ntfs':
return 'ntfs3' # Needed to use the Paragon R/W NTFS driver
elif fs == 'fat32':
return 'vfat' # This is the actual type used for fat32 mounting
return fs
return True