Skip to content

Commit

Permalink
Enforce sane disk selections.
Browse files Browse the repository at this point in the history
There is no value (and a great deal of trouble) in allowing users to split
up an existing md array, lvm vg, or btrfs volume by selecting a subset of
the disks it uses.
  • Loading branch information
dwlehman committed Mar 31, 2015
1 parent 24e7ca8 commit 86b21c5
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
13 changes: 12 additions & 1 deletion pyanaconda/ui/gui/spokes/storage.py
Expand Up @@ -42,7 +42,7 @@
from gi.repository import Gdk, GLib, AnacondaWidgets

from pyanaconda.ui.communication import hubQ
from pyanaconda.ui.lib.disks import getDisks, isLocalDisk, applyDiskSelection
from pyanaconda.ui.lib.disks import getDisks, isLocalDisk, applyDiskSelection, checkDiskSelection
from pyanaconda.ui.gui import GUIObject
from pyanaconda.ui.gui.spokes import NormalSpoke
from pyanaconda.ui.gui.spokes.lib.cart import SelectedDisksDialog
Expand Down Expand Up @@ -754,6 +754,17 @@ def on_back_clicked(self, button):
partition in self.storage.partitions:
self.storage.recursiveRemove(partition)

# make sure no containers were split up by the user's disk selection
self.clear_info()
self.errors = checkDiskSelection(self.storage,
self.disks, self.selected_disks)
if self.errors:
# The disk selection has to make sense before we can proceed.
self.set_error(_("There was a problem with your disk selection. "
"Click here for details."))
self.back_clicked = False
return

# hide/unhide disks as requested
for disk in self.disks:
if disk.name not in self.selected_disks and \
Expand Down
30 changes: 30 additions & 0 deletions pyanaconda/ui/lib/disks.py
Expand Up @@ -92,3 +92,33 @@ def applyDiskSelection(storage, data, use_names):

data.ignoredisk.onlyuse = onlyuse
data.clearpart.drives = use_names[:]

def getRelatedDisks(storage, disk):
""" Return a list of disks related to disk by way of container devices. """
return set(d for dep in storage.deviceDeps(disk) for d in dep.disks)

def checkDiskSelection(storage, all_disks, selected_disks):
""" Return a list of errors related to a proposed disk selection.
:param :class:`blivet.Blivet` storage: storage data
:param all_disks: all known disks
:type all_disks: list of :class:`blivet.devices.StorageDevice`
:param selected_disks: proposed selected disks
:type selected_disks: list of :class:`blivet.devices.StorageDevice`
:returns: a list of error messages
:rtype: list of str
"""
errors = []
for selected in all_disks:
if selected.name not in selected_disks:
continue

related = getRelatedDisks(storage, selected)
missing = [r.name for r in related if r.name not in selected_disks]
if missing:
errors.append("You selected disk %s, which contains devices that "
"also use disk(s) %s. You must select or de-select "
"these disks as a set." %
(selected.name, ",".join(missing)))

return errors
14 changes: 12 additions & 2 deletions pyanaconda/ui/tui/spokes/storage.py
Expand Up @@ -22,7 +22,7 @@
# which has the same license and authored by David Lehman <dlehman@redhat.com>
#

from pyanaconda.ui.lib.disks import getDisks, applyDiskSelection
from pyanaconda.ui.lib.disks import getDisks, applyDiskSelection, checkDiskSelection
from pyanaconda.ui.categories.system import SystemCategory
from pyanaconda.ui.tui.spokes import NormalTUISpoke
from pyanaconda.ui.tui.simpleline import TextWidget, CheckboxWidget
Expand Down Expand Up @@ -260,7 +260,7 @@ def _format_disk_info(self, disk):

def input(self, args, key):
"""Grab the disk choice and update things"""

self.errors = []
try:
keyid = int(key) - 1
self.selection = keyid
Expand All @@ -281,6 +281,16 @@ def input(self, args, key):
self.run_dasdfmt(to_format)
return None

# make sure no containers were split up by the user's disk
# selection
self.errors.extend(checkDiskSelection(self.storage,
self.disks,
self.selected_disks))
if self.errors:
# The disk selection has to make sense before we can
# proceed.
return None

newspoke = AutoPartSpoke(self.app, self.data, self.storage,
self.payload, self.instclass)
self.app.switch_screen_modal(newspoke)
Expand Down

0 comments on commit 86b21c5

Please sign in to comment.