Skip to content

Commit 66c4db8

Browse files
pirat89MichalHe
authored andcommitted
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..). Co-authored-by: Michal Hečko <[email protected]> (cherry picked from commit a81ebb0)
1 parent 903f005 commit 66c4db8

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

repos/system_upgrade/common/libraries/overlaygen.py

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

376379

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

395401

@@ -406,15 +412,43 @@ def _create_mount_disk_image(disk_images_directory, path, disk_size):
406412
and it's supposed to be used for write directories of an overlayfs built
407413
above it.
408414
415+
If the disk_size is lower than 130 MiBs, the disk size is automatically
416+
set to 130 MiBs to be able to format it correctly.
417+
409418
The disk image is formatted with Ext4 if (envar) `LEAPP_OVL_IMG_FS_EXT4=1`.
410419
411420
:param disk_images_directory: Path to the directory where disk images should be stored.
412421
:type disk_images_directory: str
413422
:param path: Path to the mountpoint of the original (host/source) partition/volume
414423
:type path: str
424+
:param disk_size: Apparent size of the disk img in MiBs
425+
:type disk_size: int
415426
:return: Path to the created disk image
416427
:rtype: str
417428
"""
429+
if disk_size < 130:
430+
# NOTE(pstodulk): SEATBELT
431+
# min. required size for current params to format a disk img with a FS:
432+
# XFS -> 130 MiB
433+
# EXT4 -> 70 MiB
434+
# so let's stick to 130 always. This is expected to happen when:
435+
# * the free space on a system mountpoint is really super small, but if
436+
# such a mounpoint contains a content installed by packages, most
437+
# likely the msg about not enough free space is raised
438+
# * the mountpoint is actually no important at all, could be possibly
439+
# read only (e.g. ISO), or it's an FS type that should be covered by
440+
# OVERLAY_DO_NOT_MOUNT
441+
# * most common case important for us here could be /boot, but that's
442+
# covered already in different actors/checks, so it should not be
443+
# problem either
444+
# NOTE(pstodulk): In case the formatting params are modified,
445+
# the minimal required size could be different
446+
api.current_logger().warning(
447+
'The apparent size for the disk image representing {path}'
448+
' is too small ({disk_size} MiBs) for a formatting. Setting 130 MiBs instead.'
449+
.format(path=path, disk_size=disk_size)
450+
)
451+
disk_size = 130
418452
diskimage_path = os.path.join(disk_images_directory, _mount_name(path))
419453
cmd = [
420454
'/bin/dd',
@@ -647,7 +681,7 @@ def _create_mount_disk_image_old(disk_images_directory, path):
647681
try:
648682
utils.call_with_oserror_handled(cmd=['/sbin/mkfs.ext4', '-F', diskimage_path])
649683
except CalledProcessError as e:
650-
api.current_logger().error('Failed to create ext4 filesystem %s', exc_info=True)
684+
api.current_logger().error('Failed to create ext4 filesystem in %s', exc_info=True)
651685
raise StopActorExecutionError(
652686
message=str(e)
653687
)

0 commit comments

Comments
 (0)