From 0de0c98b8202a55c47accc0d87a5af29911590c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A5=D0=B8=D1=80=D0=B5=D1=86=D0=BA=D0=B8=D0=B9=20=D0=9C?= =?UTF-8?q?=D0=B8=D1=85=D0=B0=D0=B8=D0=BB?= Date: Thu, 1 Apr 2021 12:12:34 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B0=20=D1=83=D1=81=D1=82=D0=B0=D0=BD=D0=BE=D0=B2=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=BD=D0=B0=20btrfs=20=D1=81=20=D1=81=D0=B6=D0=B0=D1=82?= =?UTF-8?q?=D0=B8=D0=B5=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pym/install/distr.py | 28 +++++++--------------------- pym/install/fs_manager.py | 24 ++++++++++++++++++++---- pym/install/variables/disk.py | 4 +++- 3 files changed, 30 insertions(+), 26 deletions(-) diff --git a/pym/install/distr.py b/pym/install/distr.py index 40bb50b..ce5393f 100644 --- a/pym/install/distr.py +++ b/pym/install/distr.py @@ -987,23 +987,6 @@ class FormatBtrfs(FormatProcessGeneric): def param(self): return "-f", self.get_label(), self.dev -class FormatBtrfsCompressed(FormatBtrfs): - - def postaction(self): - try: - if self.purpose != "boot" and self.compression: - Btrfs(self.dev).compression = self.compression - if self.purpose == "root": - # disable btrfs compression for /boot directory in root partition - # and usr/share/grub for unicode.pf2 - for dn in ("boot", "usr/share/grub", "var/calculate/linux"): - Btrfs(self.dev).set_compression(dn, "") - if self.purpose == "calculate": - Btrfs(self.dev).set_compression("linux", "") - - except BtrfsError as e: - raise DistributiveError( - _("Failed to set btrfs compression for {}").format(self.dev)) class PartitionDistributive(Distributive): format_map = { @@ -1020,7 +1003,7 @@ class PartitionDistributive(Distributive): 'ntfs': FormatNtfs, 'uefi': FormatUefi, 'btrfs': FormatBtrfs, - 'btrfs-compress': FormatBtrfsCompressed, + 'btrfs-compress': FormatBtrfs, 'swap': FormatSwap } @@ -1123,13 +1106,16 @@ class PartitionDistributive(Distributive): def convertToDirectory(self): """Convert partition to directory by mounting""" + mapFS = {'btrfs-compress': 'btrfs'} + mapOpts = {'btrfs-compress': ' -o compress=%s' % self.compression} mdirectory = self.mdirectory for child in self.childs: if isinstance(child, DirectoryDistributive) and \ mdirectory in child.directory: return child mdirectory = self._getMntDirectory(mdirectory) - self._mountPartition(self.partition, mdirectory) + self._mountPartition(self.partition, mdirectory, + mapOpts.get(self.fileSystem,"")) dirObj = DirectoryDistributive(mdirectory, parent=self) if self.multipartition: mulipartDataNotBind = filter(lambda x: x[2] != "bind", @@ -1139,10 +1125,10 @@ class PartitionDistributive(Distributive): realMountPoint = None if fileSystem != "swap": realMountPoint = pathJoin(mdirectory, mountPoint) - mapFS = {'btrfs-compress': 'btrfs'} self._mountPartition( dev, realMountPoint, - "-t %s" % mapFS.get(fileSystem,fileSystem)) + "-t %s" % mapFS.get(fileSystem,fileSystem) + + mapOpts.get(fileSystem,"")) partObj = PartitionDistributive(dev, flagRemoveDir=False, fileSystem=fileSystem, isFormat=isFormat, diff --git a/pym/install/fs_manager.py b/pym/install/fs_manager.py index cfb7497..994a1a0 100644 --- a/pym/install/fs_manager.py +++ b/pym/install/fs_manager.py @@ -35,6 +35,7 @@ class FileSystemManager(object): 'label': '-L {labelname}', 'ssd': [], 'msdos': '83', + 'compress': None, 'type': ['hdd', 'usb-hdd']}, 'ext3': {'defaultopt': defaultOpt, 'format': '/sbin/mkfs.ext3', @@ -43,6 +44,7 @@ class FileSystemManager(object): 'label': '-L {labelname}', 'ssd': [], 'msdos': '83', + 'compress': None, 'type': ['hdd', 'usb-hdd']}, 'ext4': {'defaultopt': defaultOpt, 'format': '/sbin/mkfs.ext4', @@ -51,6 +53,7 @@ class FileSystemManager(object): 'label': '-L {labelname}', 'ssd': ['discard'], 'msdos': '83', + 'compress': None, 'type': ['hdd', 'usb-hdd']}, 'reiserfs': {'defaultopt': defaultOpt, 'format': '/sbin/mkfs.reiserfs', @@ -58,6 +61,7 @@ class FileSystemManager(object): 'gpt': '8300', 'label': '-l {labelname}', 'msdos': '83', + 'compress': None, 'ssd': [], 'type': ['hdd', 'usb-hdd']}, 'btrfs': {'defaultopt': defaultOpt, @@ -68,10 +72,12 @@ class FileSystemManager(object): 'msdos': '83', 'ssd': ['ssd', 'discard', 'space_cache'], 'type': ['hdd', 'usb-hdd'], + 'compress': None, 'compatible': ['btrfs-compress']}, 'btrfs-compress': {'defaultopt': defaultOpt, 'format': '/sbin/mkfs.btrfs', 'orig': 'btrfs', + 'compress': "compress=%s", 'formatparam': '{labelparam} -f {device}', 'gpt': '8300', 'label': '-L {labelname}', @@ -86,6 +92,7 @@ class FileSystemManager(object): 'label': '-L {labelname}', 'msdos': '83', 'ssd': ['discard'], + 'compress': None, 'type': ['hdd', 'usb-hdd']}, 'xfs': {'defaultopt': defaultOpt, 'format': '/sbin/mkfs.xfs', @@ -95,6 +102,7 @@ class FileSystemManager(object): 'msdos': '83', 'boot': '-i sparce=0', 'ssd': ['discard'], + 'compress': None, 'type': ['hdd', 'usb-hdd']}, # 'nilfs2': {'defaultopt': defaultOpt, # 'format': '/sbin/mkfs.nilfs2', @@ -111,6 +119,7 @@ class FileSystemManager(object): 'label': '', 'ssd': [], 'auto': False, + 'compress': None, 'msdos': '82'}, 'uefi': {'defaultopt': defaultOpt, 'format': '/usr/sbin/mkfs.vfat', @@ -120,6 +129,7 @@ class FileSystemManager(object): 'msdos': '0b', 'ssd': [], 'auto': False, + 'compress': None, 'type': ['hdd']}, 'vfat': {'defaultopt': defaultOpt, 'format': '/usr/sbin/mkfs.vfat', @@ -129,6 +139,7 @@ class FileSystemManager(object): 'msdos': '0b', 'auto': False, 'ssd': ['discard'], + 'compress': None, 'type': ['flash']}, 'ntfs': {'defaultopt': defaultOpt, 'format': '/usr/sbin/mkfs.ntfs', @@ -138,6 +149,7 @@ class FileSystemManager(object): 'msdos': '7', 'auto': False, 'ssd': [], + 'compress': None, 'compatible': ['ntfs-3g']}, 'ntfs-3g': {'defaultopt': defaultOpt, 'format': '/usr/sbin/mkfs.ntfs', @@ -147,11 +159,13 @@ class FileSystemManager(object): 'ssd': [], 'auto': False, 'msdos': '7', + 'compress': None, 'compatible': ['ntfs']}} default_param = {'defaultopt': defaultOpt, 'gpt': '8300', 'msdos': '83', + 'compress': None, 'ssd': []} @classmethod @@ -179,10 +193,12 @@ class FileSystemManager(object): } @classmethod - def getDefaultOpt(cls, fs, ssd=False): - return ",".join(cls.supportFS.get(fs, cls.default_param)['defaultopt'] + - (cls.supportFS.get(fs, cls.default_param)['ssd'] - if ssd else [])) + def getDefaultOpt(cls, fs, ssd=False, compress=None): + fsopts = cls.supportFS.get(fs, cls.default_param) + return ",".join(fsopts['defaultopt'] + + (fsopts['ssd'] if ssd else []) + + ([fsopts['compress'] % compress] + if fsopts['compress'] and compress else [])) @classmethod def checkFSForTypeMount(cls, fs, roottype, mp): diff --git a/pym/install/variables/disk.py b/pym/install/variables/disk.py index 3533ac5..7d1bb88 100644 --- a/pym/install/variables/disk.py +++ b/pym/install/variables/disk.py @@ -1784,7 +1784,9 @@ class VariableOsInstallDiskOptions(ReadonlyVariable): else: all_ssd = all(x in ssd_devices for x in disk_parent.split(',')) - yield FileSystemManager.getDefaultOpt(disk_format, all_ssd) + compression = self.Get('os_install_btrfs_compression') + yield FileSystemManager.getDefaultOpt(disk_format, all_ssd, + compression) return list(generator())