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.

Related: rhbz#1202877
Signed-off-by: Vratislav Podzimek <vpodzime@redhat.com>
(cherry picked from commit 77c5f24)

Conflicts:
	blivet/devices.py
  • Loading branch information
vpodzime committed Jun 3, 2015
1 parent 023164e commit 4fd7491
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
7 changes: 6 additions & 1 deletion blivet/devices/partition.py
Expand Up @@ -42,6 +42,11 @@
from .dm import DMDevice
from .lib import devicePathToName, deviceNameToDiskByPath

DEFAULT_PART_SIZE = Size("500MiB")

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

class PartitionDevice(StorageDevice):
""" A disk partition.
Expand All @@ -54,7 +59,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
19 changes: 5 additions & 14 deletions blivet/partitioning.py
Expand Up @@ -29,6 +29,7 @@
from .errors import DeviceError, NoDisksError, NotEnoughFreeSpaceError, PartitioningError
from .flags import flags
from .devices import PartitionDevice, LUKSDevice, devicePathToName
from .devices.partition import FALLBACK_DEFAULT_PART_SIZE
from .formats import getFormat
from .devicelibs.lvm import get_pool_padding
from .size import Size
Expand Down Expand Up @@ -249,20 +250,10 @@ def _schedulePartitions(storage, disks, implicit_devices, min_luks_entropy=0, re
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 4fd7491

Please sign in to comment.