[PATCH 2/2] Ask about LVM inconsistencies only in storageinit step.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The patch does essentially the same thing as commit for disk initialization
question. The difference is that when user chooses LVM reinitialization, it is
done immediately (not as planned action as with disk initialization) so the
user wouldn't be asked again anyway without the patch (he would be asked if he
chose to ignore).

I also made one function more readable in the patch.
---
 cmdline.py            |   10 ++++++++
 gui.py                |   45 +++++++++++++++++++++++++++++++++++++++
 storage/__init__.py   |    1 +
 storage/devicetree.py |   56 ++++++++++++------------------------------------
 text.py               |   45 +++++++++++++++++++++++++++++++++++++++
 5 files changed, 115 insertions(+), 42 deletions(-)

diff --git a/cmdline.py b/cmdline.py
index 24485f7..700e741 100644
--- a/cmdline.py
+++ b/cmdline.py
@@ -144,6 +144,16 @@ class InstallInterface:
         while 1:
             time.sleep(5)
 
+    def resetReinitInconsistentLVMQuestion(self):
+        pass
+
+    def questionReinitInconsistentLVM(self, pv_names=None, lv_name=None, vg_name=None):
+        print(_("Can't have a question in command line mode!"))
+        print("(questionReinitInconsistentLVM)")
+        # don't exit
+        while 1:
+            time.sleep(5)
+
     def mainExceptionWindow(self, shortText, longTextFile):
         print(shortText)
 
diff --git a/gui.py b/gui.py
index 2f9f925..ea83c08 100755
--- a/gui.py
+++ b/gui.py
@@ -988,6 +988,7 @@ class InstallInterface:
         cursor = gtk.gdk.Cursor(gtk.gdk.LEFT_PTR)
         root.set_cursor(cursor)
         self._initLabelAnswers = {}
+        self._inconsistentLVMAnswers = {}
 
     def __del__ (self):
         pass
@@ -1160,6 +1161,50 @@ class InstallInterface:
         self._initLabelAnswers[path] = retVal
         return retVal
 
+    def resetReinitInconsistentLVMQuestion(self):
+        self._inconsistentLVMAnswers = {}
+
+    def questionReinitInconsistentLVM(self, pv_names=None, lv_name=None, vg_name=None):
+
+        retVal = False # The less destructive default
+
+        if not pv_names or (lv_name is None and vg_name is None):
+            return retVal
+
+        # We are caching answers so that we don't ask for ignoring
+        # in each storage.reset() again (note that reinitialization is
+        # done right after confirmation in dialog, not as a planned
+        # action).
+        key = frozenset(pv_names)
+        if key in self._inconsistentLVMAnswers:
+            log.info("UI not asking about disk initialization, "
+                     "using cached answer: %s" % self._inconsistentLVMAnswers[key])
+            return self._inconsistentLVMAnswers[key]
+
+        if vg_name is not None:
+            message = "Volume Group %s" % vg_name
+        elif lv_name is not None:
+            message = "Logical Volume %s" % lv_name
+
+        na = {'msg': message, 'pvs': ", ".join(pv_names)}
+        rc = self.messageWindow(_("Warning"),
+                  _("Error processing LVM.\n"
+                    "There is inconsistent LVM data on %(msg)s.  You can "
+                    "reinitialize all related PVs (%(pvs)s) which will erase "
+                    "the LVM metadata, or ignore which will preserve the "
+                    "contents.") % na,
+                type="custom",
+                custom_buttons = [ _("_Ignore"),
+                                   _("_Re-initialize") ],
+                custom_icon="question")
+        if rc == 0:
+            pass
+        else:
+            retVal = True # this means clobber.
+
+        self._inconsistentLVMAnswers[key] = retVal
+        return retVal
+
     def beep(self):
         gtk.gdk.beep()
 
diff --git a/storage/__init__.py b/storage/__init__.py
index c748362..eb4d69f 100644
--- a/storage/__init__.py
+++ b/storage/__init__.py
@@ -80,6 +80,7 @@ def storageInitialize(anaconda):
 
 
     anaconda.intf.resetInitializeDiskQuestion()
+    anaconda.intf.resetReinitInconsistentLVMQuestion()
 
     # Set up the protected partitions list now.
     if os.path.exists("/dev/live") and \
diff --git a/storage/devicetree.py b/storage/devicetree.py
index f93e44f..b376771 100644
--- a/storage/devicetree.py
+++ b/storage/devicetree.py
@@ -127,34 +127,6 @@ def getLUKSPassphrase(intf, device, globalPassphrase):
     return (passphrase, isglobal)
 
 
-def questionReinitILVM(intf=None, pv_names=None, lv_name=None, vg_name=None):
-    retVal = False # The less destructive default
-    if not intf or not pv_names or (lv_name is None and vg_name is None):
-        pass
-    else:
-        if vg_name is not None:
-            message = "Volume Group %s" % vg_name
-        elif lv_name is not None:
-            message = "Logical Volume %s" % lv_name
-
-        na = {'msg': message, 'pvs': ", ".join(pv_names)}
-        rc = intf.messageWindow(_("Warning"),
-                  _("Error processing LVM.\n"
-                    "There is inconsistent LVM data on %(msg)s.  You can "
-                    "reinitialize all related PVs (%(pvs)s) which will erase "
-                    "the LVM metadata, or ignore which will preserve the "
-                    "contents.") % na,
-                type="custom",
-                custom_buttons = [ _("_Ignore"),
-                                   _("_Re-initialize") ],
-                custom_icon="question")
-        if rc == 0:
-            pass
-        else:
-            retVal = True # thie means clobber.
-
-    return retVal
-
 class DeviceTree(object):
     """ A quasi-tree that represents the devices in the system.
 
@@ -1806,17 +1778,19 @@ class DeviceTree(object):
 
         def leafInconsistencies(device):
             if device.type == "lvmvg":
+                if device.complete:
+                    return
+
                 paths = []
                 for parent in device.parents:
                     paths.append(parent.path)
 
-                # when zeroMbr is true he wont ask.
-                if not device.complete and (self.zeroMbr or \
-                        questionReinitILVM(intf=self.intf, \
-                            vg_name=device.name, pv_names=paths)):
+                # if zeroMbr is true don't ask.
+                if (self.zeroMbr or
+                    self.intf.questionReinitInconsistentLVM(pv_names=paths,
+                                                            vg_name=device.name)):
                     reinitializeVG(device)
-
-                elif not device.complete:
+                else:
                     # The user chose not to reinitialize.
                     # hopefully this will ignore the vg components too.
                     self._removeDevice(device)
@@ -1831,21 +1805,21 @@ class DeviceTree(object):
                             self.addIgnoredDisk(parent.name)
                         lvm.lvm_cc_addFilterRejectRegexp(parent.name)
 
-                return
-
             elif device.type == "lvmlv":
                 # we might have already fixed this.
                 if device not in self._devices or \
                         device.name in self._ignoredDisks:
                     return
+                if device.complete:
+                    return
 
                 paths = []
                 for parent in device.vg.parents:
                     paths.append(parent.path)
 
-                if not device.complete and (self.zeroMbr or \
-                    questionReinitILVM(intf=self.intf, \
-                        lv_name=device.name, pv_names=paths)):
+                if (self.zeroMbr or
+                    self.intf.questionReinitInconsistentLVM(pv_names=paths,
+                                                            lv_name=device.name)):
 
                     # destroy all lvs.
                     for lv in device.vg.lvs:
@@ -1860,8 +1834,7 @@ class DeviceTree(object):
                         self._removeDevice(lv)
 
                     reinitializeVG(device.vg)
-
-                elif not device.complete:
+                else:
                     # ignore all the lvs.
                     for lv in device.vg.lvs:
                         self._removeDevice(lv)
@@ -1879,7 +1852,6 @@ class DeviceTree(object):
                             self._removeDevice(parent, moddisk=False)
                             self.addIgnoredDisk(parent.name)
                         lvm.lvm_cc_addFilterRejectRegexp(parent.name)
-                return
 
         # Address the inconsistencies present in the tree leaves.
         for leaf in self.leaves:
diff --git a/text.py b/text.py
index 6972417..c4602cd 100644
--- a/text.py
+++ b/text.py
@@ -438,6 +438,7 @@ class InstallInterface:
 	signal.signal(signal.SIGTSTP, signal.SIG_IGN)
 	self.screen = SnackScreen()
         self._initLabelAnswers = {}
+        self._inconsistentLVMAnswers = {}
 
     def __del__(self):
 	if self.screen:
@@ -490,6 +491,50 @@ class InstallInterface:
         self._initLabelAnswers[path] = retVal
         return retVal
 
+    def resetReinitInconsistentLVMQuestion(self):
+        self._inconsistentLVMAnswers = {}
+
+    def questionReinitInconsistentLVM(self, pv_names=None, lv_name=None, vg_name=None):
+
+        retVal = False # The less destructive default
+
+        if not pv_names or (lv_name is None and vg_name is None):
+            return retVal
+
+        # We are caching answers so that we don't ask for ignoring
+        # in each storage.reset() again (note that reinitialization is
+        # done right after confirmation in dialog, not as a planned
+        # action).
+        key = frozenset(pv_names)
+        if key in self._inconsistentLVMAnswers:
+            log.info("UI not asking about disk initialization, "
+                     "using cached answer: %s" % self._inconsistentLVMAnswers[key])
+            return self._inconsistentLVMAnswers[key]
+
+        if vg_name is not None:
+            message = "Volume Group %s" % vg_name
+        elif lv_name is not None:
+            message = "Logical Volume %s" % lv_name
+
+        na = {'msg': message, 'pvs': ", ".join(pv_names)}
+        rc = self.messageWindow(_("Warning"),
+                  _("Error processing LVM.\n"
+                    "There is inconsistent LVM data on %(msg)s.  You can "
+                    "reinitialize all related PVs (%(pvs)s) which will erase "
+                    "the LVM metadata, or ignore which will preserve the "
+                    "contents.") % na,
+                type="custom",
+                custom_buttons = [ _("_Ignore"),
+                                   _("_Re-initialize") ],
+                custom_icon="question")
+        if rc == 0:
+            pass
+        else:
+            retVal = True # this means clobber.
+
+        self._inconsistentLVMAnswers[key] = retVal
+        return retVal
+
     def run(self, anaconda):
         self.anaconda = anaconda
         instLang = anaconda.id.instLanguage
-- 
1.6.0.6

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux