[PATCH] Fix editing of raid device (persistence of level choice) (#496159)

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

 



I didn't want to add another 0/'0'/'RAID0' tweaking so I made
mdraid.raid_levels and mdraid deviceclass level attribute to contain
constants for levels defined in mdraid.py.

I have also one more patch for raid dialog burried in the list
(doing similar thing for member selection).
Anyone wants to review it too?
http://www.mailinglistarchive.com/anaconda-devel-list@xxxxxxxxxx/msg04548.html

---
 iw/raid_dialog_gui.py        |   17 ++++++++---------
 kickstart.py                 |    2 +-
 storage/devicelibs/mdraid.py |   32 ++++++++++++++++++++++++--------
 storage/devices.py           |   21 ++++++++++++---------
 4 files changed, 45 insertions(+), 27 deletions(-)

diff --git a/iw/raid_dialog_gui.py b/iw/raid_dialog_gui.py
index 095c3f8..7c93dfc 100644
--- a/iw/raid_dialog_gui.py
+++ b/iw/raid_dialog_gui.py
@@ -75,19 +75,19 @@ class RaidEditor:
     def createRaidLevelMenu(self, levels, reqlevel):
         levelcombo = gtk.combo_box_new_text()
 	defindex = 0
-        if "RAID1" in levels:
-            defindex = levels.index("RAID1")
+        if mdraidlib.RAID1 in levels:
+            defindex = levels.index(mdraidlib.RAID1)
 	i = 0
 	for lev in levels:
-            levelcombo.append_text(lev)
+            levelcombo.append_text("RAID%d" % lev)
 
-	    if reqlevel and lev == reqlevel:
+	    if reqlevel is not None and lev == reqlevel:
 		defindex = i
 	    i = i + 1
 
         levelcombo.set_active(defindex)
 
-	if reqlevel and reqlevel == "RAID0":
+	if reqlevel is not None and reqlevel == mdraidlib.RAID0:
 	    self.sparesb.set_sensitive(0)
 
         if self.sparesb:
@@ -115,7 +115,7 @@ class RaidEditor:
 	numparts = sparesb.get_data("numparts")
 	maxspares = mdraidlib.get_raid_max_spares(raidlevel, numparts)
 
-	if maxspares > 0 and raidlevel != "raid0":
+	if maxspares > 0 and not mdraidlib.isRaid(mdraidlib.RAID0, raidlevel):
 	    adj = sparesb.get_adjustment() 
 	    value = adj.value 
 	    if adj.value > maxspares: 
@@ -169,7 +169,7 @@ class RaidEditor:
                 model = self.levelcombo.get_model()
                 raidlevel = model[self.levelcombo.get_active()][0]
 
-                if raidlevel != "RAID0":
+                if not mdraidlib.isRaid(mdraidlib.RAID0, raidlevel):
                     self.sparesb.update()
                     spares = self.sparesb.get_value_as_int()
                 else:
@@ -177,10 +177,9 @@ class RaidEditor:
 
                 format = fmt_class(mountpoint=mountpoint)
                 members = len(raidmembers) - spares
-                level = int(raidlevel.lower().replace("raid", ""))
 
                 request = self.storage.newMDArray(minor=raidminor,
-                                                  level=level,
+                                                  level=raidlevel,
                                                   format=format,
                                                   parents=raidmembers,
                                                   totalDevices=len(raidmembers),
diff --git a/kickstart.py b/kickstart.py
index 87f81f9..de01017 100644
--- a/kickstart.py
+++ b/kickstart.py
@@ -750,7 +750,7 @@ class Raid(commands.raid.F9_Raid):
             raise KickstartValueError, formatErrorMsg(self.lineno, msg="The \"%s\" filesystem type is not supported." % type)
 
         kwargs["name"] = devicename
-        kwargs["level"] = rd.level.lower()
+        kwargs["level"] = rd.level
         kwargs["parents"] = raidmems
         kwargs["memberDevices"] = len(raidmems)
         kwargs["totalDevices"] = kwargs["memberDevices"]+rd.spares
diff --git a/storage/devicelibs/mdraid.py b/storage/devicelibs/mdraid.py
index d079359..cd704ee 100644
--- a/storage/devicelibs/mdraid.py
+++ b/storage/devicelibs/mdraid.py
@@ -39,6 +39,13 @@ RAID1 = 1
 RAID0 = 0
 
 def getRaidLevels():
+    mdstat_descriptors = {
+        RAID10: ("[RAID10]", "[raid10]"),
+        RAID6: ("[RAID6]", "[raid6]"),
+        RAID5: ("[RAID5]", "[raid5]"),
+        RAID1: ("[RAID1]", "[raid1]"),
+        RAID0: ("[RAID0]", "[raid0]"),
+    }
     avail = []
     try:
         f = open("/proc/mdstat", "r")
@@ -51,9 +58,11 @@ def getRaidLevels():
 
             lst = l.split()
 
-            for lev in ["RAID0", "RAID1", "RAID5", "RAID6", "RAID10"]:
-                if "[" + lev + "]" in lst or "[" + lev.lower() + "]" in lst:
-                    avail.append(lev)
+            for level in mdstat_descriptors:
+                for d in mdstat_descriptors[level]:
+                    if d in lst:
+                        avail.append(level)
+                        break
 
         f.close()
 
@@ -62,13 +71,20 @@ def getRaidLevels():
 
 raid_levels = getRaidLevels()
 
+def raidLevel(descriptor):
+    for level in raid_levels:
+        if isRaid(level, descriptor):
+            return level
+    else:
+        raise ValueError, "invalid raid level descriptor %s" % descriptor
+
 def isRaid(raid, raidlevel):
     """Return whether raidlevel is a valid descriptor of raid"""
-    raid_descriptors = {RAID10: ("RAID10", "10", 10),
-                        RAID6: ("RAID6", "6", 6),
-                        RAID5: ("RAID5", "5", 5),
-                        RAID1: ("mirror", "RAID1", "1", 1),
-                        RAID0: ("stripe", "RAID0", "0", 0)}
+    raid_descriptors = {RAID10: ("RAID10", "raid10", "10", 10),
+                        RAID6: ("RAID6", "raid6", "6", 6),
+                        RAID5: ("RAID5", "raid5", "5", 5),
+                        RAID1: ("mirror", "RAID1", "raid1", "1", 1),
+                        RAID0: ("stripe", "RAID0", "raid0", "0", 0)}
 
     if raid in raid_descriptors:
         return raidlevel in raid_descriptors[raid]
diff --git a/storage/devices.py b/storage/devices.py
index 91fa40c..976c238 100644
--- a/storage/devices.py
+++ b/storage/devices.py
@@ -2098,7 +2098,10 @@ class MDRaidArrayDevice(StorageDevice):
         StorageDevice.__init__(self, name, format=format, exists=exists,
                                minor=minor, size=size,
                                parents=parents, sysfsPath=sysfsPath)
-        self.level = level
+        if level is not None:
+            self.level = mdraid.raidLevel(level)
+        else:
+            self.level = level
         self.uuid = uuid
         self._totalDevices = numeric_type(totalDevices)
         self._memberDevices = numeric_type(memberDevices)
@@ -2137,18 +2140,18 @@ class MDRaidArrayDevice(StorageDevice):
         size = 0
         smallestMemberSize = self.smallestMember.size - self.superBlockSize
         if not self.exists or not self.partedDevice:
-            if self.level == 0:
+            if self.level == mdraid.RAID0:
                 size = self.memberDevices * smallestMemberSize
                 size -= size % self.chunkSize
-            elif self.level == 1:
+            elif self.level == mdraid.RAID1:
                 size = smallestMemberSize
-            elif self.level == 5:
+            elif self.level == mdraid.RAID5:
                 size = (self.memberDevices - 1) * smallestMemberSize
                 size -= size % self.chunkSize
-            elif self.level == 6:
+            elif self.level == mdraid.RAID6:
                 size = (self.memberDevices - 2) * smallestMemberSize
                 size -= size % self.chunkSize
-            elif self.level == 10:
+            elif self.level == mdraid.RAID10:
                 size = (self.memberDevices / 2.0) * smallestMemberSize
                 size -= size % self.chunkSize
         else:
@@ -2230,7 +2233,7 @@ class MDRaidArrayDevice(StorageDevice):
 
         info = mdraid.mdexamine(self.devices[0].path)
         if self.level is None:
-            self.level = info['level']
+            self.level = mdraid.raidLevel(info['level'])
         if self.memberDevices is None:
             self.memberDevices = info['nrDisks']
         if self.totalDevices is None:
@@ -2417,10 +2420,10 @@ class MDRaidArrayDevice(StorageDevice):
     def formatArgs(self):
         formatArgs = []
         if self.format.type == "ext2":
-            if self.level == 5:
+            if self.level == mdraid.RAID5:
                 formatArgs = ['-R',
                               'stride=%d' % ((self.memberDevices - 1) * 16)]
-            elif self.level == 0:
+            elif self.level == mdraid.RAID0:
                 formatArgs = ['-R',
                               'stride=%d' % (self.memberDevices * 16)]
 
-- 
1.5.4.3

_______________________________________________
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