Skip to content

Commit

Permalink
Make implicit partitions smaller if real requests don't fit anywhere
Browse files Browse the repository at this point in the history
In case of BTRFS/LVM autopartitioning we schedule one parition on every disk
used for the installation to be part of the new BTRFS/LVM setup. But in case
some other partition needs to be allocated (e.g. swap in case of BTRFS) we need
to fit this partition to some disk together with one of the implicitly scheduled
ones. In case we find out the implicitly scheduled partitions are too big to
make this possible we need to make them smaller so that autopartitioning works.

Resolves: rhbz#1171116
Signed-off-by: Vratislav Podzimek <vpodzime@redhat.com>
  • Loading branch information
vpodzime authored and dwlehman committed Jan 27, 2015
1 parent 468bb92 commit 77c5f24
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
7 changes: 6 additions & 1 deletion blivet/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@
import logging
log = logging.getLogger("blivet")

DEFAULT_PART_SIZE = Size("500MiB")

# in case the default partition size doesn't fit
FALLBACK_DEFAULT_PART_SIZE = Size("10MiB")

def get_device_majors():
majors = {}
for line in open("/proc/devices").readlines():
Expand Down Expand Up @@ -1368,7 +1373,7 @@ class PartitionDevice(StorageDevice):
"""
_type = "partition"
_resizable = True
defaultSize = Size("500MiB")
defaultSize = DEFAULT_PART_SIZE

def __init__(self, name, fmt=None,
size=None, grow=False, maxsize=None, start=None, end=None,
Expand Down
20 changes: 5 additions & 15 deletions blivet/partitioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

from .errors import DeviceError, NoDisksError, NotEnoughFreeSpaceError, PartitioningError, SanityError, SanityWarning
from .flags import flags
from .devices import PartitionDevice, LUKSDevice, devicePathToName
from .devices import PartitionDevice, LUKSDevice, devicePathToName, FALLBACK_DEFAULT_PART_SIZE
from .formats import getFormat
from .devicelibs.lvm import get_pool_padding
from .size import Size
Expand Down Expand Up @@ -243,20 +243,10 @@ def _schedulePartitions(storage, disks, implicit_devices, min_luks_entropy=0):
smallest_implicit = sorted(implicit_devices, key=lambda d: d.size)[0]
if (request.size + smallest_implicit.size) > all_free[0]:
# not enough space to allocate the smallest implicit partition
# and the request, make the implicit partition smaller with
# fixed size in order to make space for the request
new_size = all_free[0] - request.size

# subtract the size from the biggest free region and reorder the
# list
all_free[0] -= request.size
all_free.sort(reverse=True)

if new_size > Size(0):
smallest_implicit.size = new_size
else:
implicit_devices.remove(smallest_implicit)
storage.destroyDevice(smallest_implicit)
# and the request, make the implicit partitions smaller in
# attempt to make space for the request
for implicit_req in implicit_devices:
implicit_req.size = FALLBACK_DEFAULT_PART_SIZE

return implicit_devices

Expand Down

0 comments on commit 77c5f24

Please sign in to comment.