Skip to content

Commit ed140e2

Browse files
committed
overlay lib: Secure the creation of the disk image when size is < 130
In case the filesystem for which the disk img is going to be created has very small amount of free space (under 130 MiBs), it cannot be formatted by XFS with current params. This could be hit in several cases: * the system partition/volume - in this case, most likely an issue will be hit anyway later by DNF speaking about small amount of free space if a content is installed inside by RPMs as such a small amount of free space is really not expected to see at all * it's a data mount point (e.g. iso) or a filesystem type that should by part of the OVERLAY_DO_NOT_MOUNT set, so enlarging the value to 130 MiBs should not affect anything negatively at all * in case of /boot, the problem with the free space is covered already in a different actor prior we try to create any disk img, so we are safe here Based on arguments above, I am considering setting the 130 MiBs as minimal value safe for in-place upgrades. Also it will allow to skip possible problems with specific file systems (like tmpfs, ...) in case we are still missing some in the OVERLAY_DO_NOT_MOUNT - and kind of read only storage (such as iso9660, etc..).
1 parent 1b471b2 commit ed140e2

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

repos/system_upgrade/common/libraries/overlaygen.py

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,12 @@ def _format_disk_image_ext4(diskimage_path):
367367
utils.call_with_oserror_handled(cmd=cmd)
368368
except CalledProcessError as e:
369369
# FIXME(pstodulk): taken from original, but %s seems to me invalid here
370-
api.current_logger().error('Failed to create ext4 filesystem %s', diskimage_path, exc_info=True)
370+
api.current_logger().error('Failed to create ext4 filesystem in %s', diskimage_path, exc_info=True)
371371
raise StopActorExecutionError(
372-
message=str(e)
372+
message='Cannot create Ext4 filesystem in{}'.format(diskimage_path),
373+
details={
374+
'error message': str(e),
375+
}
373376
)
374377

375378

@@ -388,7 +391,10 @@ def _format_disk_image_xfs(diskimage_path):
388391
# FIXME(pstodulk): taken from original, but %s seems to me invalid here
389392
api.current_logger().error('Failed to create XFS filesystem %s', diskimage_path, exc_info=True)
390393
raise StopActorExecutionError(
391-
message=str(e)
394+
message='Cannot create XFS filesystem in{}'.format(diskimage_path),
395+
details={
396+
'error message': str(e),
397+
}
392398
)
393399

394400

@@ -405,15 +411,42 @@ def _create_mount_disk_image(disk_images_directory, path, disk_size):
405411
and it's supposed to be used for write directories of an overlayfs built
406412
above it.
407413
414+
If the disk_size is lower than 130 MiBs, the disk size is automatically
415+
set to 130 MiBs to be able to format it correctly.
416+
408417
The disk image is formatted with Ext4 if (envar) `LEAPP_OVL_IMG_FS_EXT4=1`.
409418
410419
:param disk_images_directory: Path to the directory where disk images should be stored.
411420
:type disk_images_directory: str
412421
:param path: Path to the mountpoint of the original (host/source) partition/volume
413422
:type path: str
423+
:param disk_size: Apparent size of the disk img in MiBs
424+
:type disk_size: int
414425
:return: Path to the created disk image
415426
:rtype: str
416427
"""
428+
if disk_size < 130:
429+
# NOTE(pstodulk): SEATBELT
430+
# min. required size for current params to format a disk img with a FS:
431+
# XFS -> 130 MiB
432+
# EXT4 -> 70 MiB
433+
# so let's stick to 130 always. This is expected to happen when:
434+
# * the free space on a system mountpoint is really super small, but if
435+
# such a mounpoint contains a content installed by packages, most
436+
# likely the msg about not enough free space is raised
437+
# * the mountpoint is actually no important at all, could be possibly
438+
# read only (e.g. ISO), or it's an FS type that should be covered by
439+
# OVERLAY_DO_NOT_MOUNT
440+
# * most common case important for us here could be /boot, but that's
441+
# covered already in different actors/checks, so it should not be
442+
# problem either
443+
# NOTE(pstodulk): In case the formatting params are modified,
444+
# the minimal required size could be different
445+
api.current_logger().warning(
446+
'The apparent size for the disk image representing {path}'
447+
' is too small ({} MiBs) for a formatting. Setting 130 MiBs instead.'
448+
)
449+
disk_size = 130
417450
diskimage_path = os.path.join(disk_images_directory, _mount_name(path))
418451
cmd = [
419452
'/bin/dd',

0 commit comments

Comments
 (0)