Skip to content

Commit

Permalink
overlaygen: cap max sparse file size
Browse files Browse the repository at this point in the history
If the source system has a very large disk attached, leapp would attempt
to create similarly large sparse file, possibly hitting the max file
size limits of the filesystem where these images are created. This
patch caps the maximum size of any of the created sparse files to 1TB,
preventing such issues.

Jira ref: RHEL-57064
  • Loading branch information
Michal Hecko committed Sep 5, 2024
1 parent 41e32e3 commit 3bbd3e8
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ test_no_lint:
cd repos/system_upgrade/el7toel8/; \
snactor workflow sanity-check ipu && \
cd - && \
$(_PYTHON_VENV) -m pytest $(REPORT_ARG) $(TEST_PATHS) $(LIBRARY_PATH) $(PYTEST_ARGS)
$(_PYTHON_VENV) -m pytest $(REPORT_ARG) $(LIBRARY_PATH) $(PYTEST_ARGS)
test: lint test_no_lint
Expand Down
22 changes: 22 additions & 0 deletions repos/system_upgrade/common/libraries/overlaygen.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,21 @@
this constant.
"""

_MAX_DISK_IMAGE_SIZE_MB = 1024**2 # 1*TB
"""
Maximum size of the created (sparse) images.
Defaults to 1TB. If a disk with capacity larger than _MAX_DISK_IMAGE_SIZE_MB
is mounted on the system, the corresponding image used to store overlay
modifications will be capped to _MAX_DISK_IMAGE_SIZE_MB.
Engineering rationale:
This constant was introduced to prevent leapp from creating files that are
virtually larger than the maximum file size supported by the file system.
E.g. if the source system hosts /var/lib/leapp on EXT4, then we cannot
create a file larger than 16TB.
"""


MountPoints = namedtuple('MountPoints', ['fs_file', 'fs_vfstype'])

Expand Down Expand Up @@ -287,6 +302,13 @@ def _prepare_required_mounts(scratch_dir, mounts_dir, storage_info, scratch_rese
disk_size = _get_fspace(mountpoint, convert_to_mibs=True, coefficient=0.95)
if mountpoint == scratch_mp:
disk_size = scratch_disk_size

if disk_size > _MAX_DISK_IMAGE_SIZE_MB:
msg = ('Image for overlayfs corresponding to the disk mounted at %s would ideally have %d MB, '
'but we truncate it to %d MB to avoid bumping to max file limits.')
api.current_logger().info(msg, mountpoint, disk_size, _MAX_DISK_IMAGE_SIZE_MB)
disk_size = _MAX_DISK_IMAGE_SIZE_MB

image = _create_mount_disk_image(disk_images_directory, mountpoint, disk_size)
result[mountpoint] = mounting.LoopMount(
source=image,
Expand Down
37 changes: 37 additions & 0 deletions repos/system_upgrade/common/libraries/tests/test_overlaygen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from collections import namedtuple

from leapp.libraries.common import overlaygen


class RunMocked(object):
def __init__(self):
self.invocations = []

def __call__(self, *args, **kwargs):
self.invocations.append((args, kwargs))


def test_prepare_required_mounts_image_size_capping(monkeypatch):
""" Test whether having a very large disk will not create very large image. """
MountPoint = namedtuple('MountPoint', 'fs_file')
mount_points = [MountPoint(fs_file='/big_disk')]
monkeypatch.setattr(overlaygen, '_get_mountpoints', lambda storage_info: mount_points)
monkeypatch.setattr(overlaygen, '_get_scratch_mountpoint', lambda *args: '/scratch')
monkeypatch.setattr(overlaygen, '_create_diskimages_dir', lambda *args: None)
monkeypatch.setattr(overlaygen, '_ensure_enough_diskimage_space', lambda *args: None)

mountpoint_sizes = {
'/big_disk': 20*(1024**2), # 20TB
'/scratch': 20 # Arbitrary, irrelevant for this test
}
monkeypatch.setattr(overlaygen, '_get_fspace', lambda mount, *args, **kwargs: mountpoint_sizes[mount])
monkeypatch.setattr(overlaygen, 'run', RunMocked())

def create_disk_image_mock(disk_images_dir, mountpoint, disk_size):
assert mountpoint == '/big_disk'
assert disk_size == overlaygen._MAX_DISK_IMAGE_SIZE_MB

monkeypatch.setattr(overlaygen, '_create_mount_disk_image', create_disk_image_mock)

storage_info = None # Should not be used in the code due to how we mocked overlaygen functions
overlaygen._prepare_required_mounts('/scratch', '/mounts', storage_info, 100)

0 comments on commit 3bbd3e8

Please sign in to comment.