Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RHEL 7.2 cherry-picks #146

Merged
merged 5 commits into from
Jun 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions blivet/devices/partition.py
Original file line number Diff line number Diff line change
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("256MiB")

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 Expand Up @@ -736,7 +741,10 @@ def _setSize(self, newsize):
raise ValueError("new size must of type Size")

if not self.exists:
raise errors.DeviceError("device does not exist", self.name)
# device does not exist (a partition request), just set basic values
self._size = newsize
self.req_size = newsize
self.req_base_size = newsize

if newsize > self.disk.size:
raise ValueError("partition size would exceed disk size")
Expand Down
33 changes: 25 additions & 8 deletions blivet/partitioning.py
Original file line number Diff line number Diff line change
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 @@ -115,7 +116,7 @@ def _scheduleImplicitPartitions(storage, disks, min_luks_entropy=0):

return devs

def _schedulePartitions(storage, disks, min_luks_entropy=0, requests=None):
def _schedulePartitions(storage, disks, implicit_devices, min_luks_entropy=0, requests=None):
""" Schedule creation of autopart/reqpart partitions.

This only schedules the requests for actual partitions.
Expand All @@ -138,17 +139,17 @@ def _schedulePartitions(storage, disks, min_luks_entropy=0, requests=None):

# basis for requests with requiredSpace is the sum of the sizes of the
# two largest free regions
all_free = getFreeRegions(disks)
all_free.sort(key=lambda f: f.length, reverse=True)
all_free = (Size(reg.getLength(unit="B")) for reg in getFreeRegions(disks))
all_free = sorted(all_free, reverse=True)
if not all_free:
# this should never happen since we've already filtered the disks
# to those with at least 500MiB free
log.error("no free space on disks %s", [d.name for d in disks])
return

free = Size(all_free[0].getLength(unit="B"))
free = all_free[0]
if len(all_free) > 1:
free += Size(all_free[1].getLength(unit="B"))
free += all_free[1]

# The boot disk must be set at this point. See if any platform-specific
# stage1 device we might allocate already exists on the boot disk.
Expand Down Expand Up @@ -204,6 +205,11 @@ def _schedulePartitions(storage, disks, min_luks_entropy=0, requests=None):
log.debug("%s", stage1_device)
continue

if request.size > all_free[0]:
# no big enough free space for the requested partition
raise NotEnoughFreeSpaceError(_("No big enough free space on disks for "
"automatic partitioning"))

if request.encrypted and storage.encryptedAutoPart:
fmt_type = "luks"
fmt_args = {"passphrase": storage.encryptionPassphrase,
Expand Down Expand Up @@ -237,8 +243,19 @@ def _schedulePartitions(storage, disks, min_luks_entropy=0, requests=None):
parents=dev)
storage.createDevice(luks_dev)

# make sure preexisting broken lvm/raid configs get out of the way
return
if storage.autoPartType in (AUTOPART_TYPE_LVM, AUTOPART_TYPE_LVM_THINP,
AUTOPART_TYPE_BTRFS):
# doing LVM/BTRFS -- make sure the newly created partition fits in some
# free space together with one of the implicitly requested partitions
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 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

def _scheduleVolumes(storage, devs):
""" Schedule creation of autopart lvm/btrfs volumes.
Expand Down Expand Up @@ -414,7 +431,7 @@ def doAutoPartition(storage, data, min_luks_entropy=0):
raise NotEnoughFreeSpaceError(_("Not enough free space on disks for "
"automatic partitioning"))

_schedulePartitions(storage, disks, min_luks_entropy=min_luks_entropy)
devs = _schedulePartitions(storage, disks, devs, min_luks_entropy=min_luks_entropy)

# run the autopart function to allocate and grow partitions
doPartitioning(storage)
Expand Down