[PATCH] Use blivet's getFreeSpace for limitting automatic swap size
Vratislav Podzimek
vpodzime at redhat.com
Fri Aug 1 12:41:56 UTC 2014
We should limit swap size to 10 % of available free space not overall disk
space. Blivet's getFreeSpace can help us a lot with this.
Resolves: rhbz#1053462
Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
---
pyanaconda/kickstart.py | 35 ++++++++++++++++++++++-------------
pyanaconda/ui/gui/spokes/custom.py | 2 ++
pyanaconda/ui/gui/spokes/storage.py | 12 +++---------
3 files changed, 27 insertions(+), 22 deletions(-)
diff --git a/pyanaconda/kickstart.py b/pyanaconda/kickstart.py
index fcbfa72..95c2807 100644
--- a/pyanaconda/kickstart.py
+++ b/pyanaconda/kickstart.py
@@ -22,7 +22,7 @@ from pyanaconda.errors import ScriptError, errorHandler
from blivet.deviceaction import ActionCreateFormat, ActionDestroyFormat, ActionResizeDevice, ActionResizeFormat
from blivet.devices import LUKSDevice
from blivet.devicelibs.lvm import getPossiblePhysicalExtents, LVM_PE_SIZE
-from blivet.devicelibs import swap
+from blivet.devicelibs import swap as swap_lib
from blivet.formats import getFormat
from blivet.partitioning import doPartitioning
from blivet.partitioning import growLVM
@@ -207,22 +207,31 @@ def removeExistingFormat(device, storage):
def getAvailableDiskSpace(storage):
"""
- Get overall disk space available on disks we may use (not free space on the
- disks, but overall space on the disks).
+ Get overall disk space available on disks we may use.
:param storage: blivet.Blivet instance
- :return: overall disk space available in MB
- :rtype: int
+ :return: overall disk space available
+ :rtype: :class:`blivet.size.Size`
"""
- disk_space = 0
- for disk in storage.disks:
- if not storage.config.clearPartDisks or \
- disk.name in storage.config.clearPartDisks:
- disk_space += disk.size
+ free_space = storage.getFreeSpace()
+ return sum(disk_free for disk_free, fs_free in free_space.values())
- return disk_space
+def refreshAutoSwapSize(storage):
+ """
+ Refresh size of the auto partitioning request for swap device according to
+ the current state of the storage configuration.
+
+ :param storage: blivet.Blivet instance
+
+ """
+
+ for request in storage.autoPartitionRequests:
+ if request.fstype == "swap":
+ disk_space = getAvailableDiskSpace(storage)
+ request.size = swap_lib.swapSuggestion(disk_space=disk_space)
+ break
###
### SUBCLASSES OF PYKICKSTART COMMAND HANDLERS
@@ -770,7 +779,7 @@ class LogVolData(commands.logvol.F20_LogVolData):
self.mountpoint = ""
if self.recommended or self.hibernation:
disk_space = getAvailableDiskSpace(storage)
- size = swap.swapSuggestion(hibernation=self.hibernation, disk_space=disk_space)
+ size = swap_lib.swapSuggestion(hibernation=self.hibernation, disk_space=disk_space)
self.grow = False
else:
if self.fstype != "":
@@ -1031,7 +1040,7 @@ class PartitionData(commands.partition.F18_PartData):
self.mountpoint = ""
if self.recommended or self.hibernation:
disk_space = getAvailableDiskSpace(storage)
- size = swap.swapSuggestion(hibernation=self.hibernation, disk_space=disk_space)
+ size = swap_lib.swapSuggestion(hibernation=self.hibernation, disk_space=disk_space)
self.grow = False
# if people want to specify no mountpoint for some reason, let them
# this is really needed for pSeries boot partitions :(
diff --git a/pyanaconda/ui/gui/spokes/custom.py b/pyanaconda/ui/gui/spokes/custom.py
index d9ab155..e0240ac 100644
--- a/pyanaconda/ui/gui/spokes/custom.py
+++ b/pyanaconda/ui/gui/spokes/custom.py
@@ -37,6 +37,7 @@ from pyanaconda.threads import AnacondaThread, threadMgr
from pyanaconda.constants import THREAD_EXECUTE_STORAGE, THREAD_STORAGE, THREAD_CUSTOM_STORAGE_INIT
from pyanaconda.iutil import lowerASCII
from pyanaconda.bootloader import BootLoaderError
+from pyanaconda.kickstart import refreshAutoSwapSize
from pyanaconda import isys
from blivet import devicefactory
@@ -2180,6 +2181,7 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
# doAutoPartitions needs stage1_disk setup so it will reuse existing partitions
self._storage_playground.setUpBootLoader(early=True)
+ refreshAutoSwapSize(self._storage_playground)
doAutoPartition(self._storage_playground, self.data)
except NoDisksError as e:
# No handling should be required for this.
diff --git a/pyanaconda/ui/gui/spokes/storage.py b/pyanaconda/ui/gui/spokes/storage.py
index 479537b..add4783 100644
--- a/pyanaconda/ui/gui/spokes/storage.py
+++ b/pyanaconda/ui/gui/spokes/storage.py
@@ -54,13 +54,12 @@ from pyanaconda.ui.categories.system import SystemCategory
from pyanaconda.ui.gui.utils import escape_markup, gtk_action_nowait, ignoreEscape
from pyanaconda.ui.helpers import StorageChecker
-from pyanaconda.kickstart import doKickstartStorage, getAvailableDiskSpace
+from pyanaconda.kickstart import doKickstartStorage, refreshAutoSwapSize
from blivet import storageInitialize, arch
from blivet.size import Size
from blivet.devices import MultipathDevice
from blivet.errors import StorageError, DasdFormatError
from blivet.platform import platform
-from blivet.devicelibs import swap as swap_lib
from blivet.devicelibs.dasd import make_unformatted_dasd_list, format_dasd
from pyanaconda.threads import threadMgr, AnacondaThread
from pyanaconda.product import productName
@@ -295,13 +294,6 @@ class StorageSpoke(NormalSpoke, StorageChecker):
# user may have set up before now.
self.storage.config.clearNonExistent = self.data.autopart.autopart
- # refresh the autopart swap size suggestion with currently selected disks
- for request in self.storage.autoPartitionRequests:
- if request.fstype == "swap":
- disk_space = getAvailableDiskSpace(self.storage)
- request.size = swap_lib.swapSuggestion(disk_space=disk_space)
- break
-
@gtk_action_nowait
def execute(self):
# Spawn storage execution as a separate thread so there's no big delay
@@ -867,6 +859,8 @@ class StorageSpoke(NormalSpoke, StorageChecker):
# catch-all. Just stay on this spoke.
return
+ if self.autopart:
+ refreshAutoSwapSize(self.storage)
self.applyOnSkip = True
NormalSpoke.on_back_clicked(self, button)
--
1.9.3
More information about the anaconda-patches
mailing list