Re: RFC: Don't label filesystems

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

 



Here's a first pass at a patch which lets us 
a) Check if a given label exists by using libblkid instead of our cache
b) Don't label devices unless something is explicitly passed via
kickstart

Entirely untested and probably has some problems around upgrades, etc
where we expect things to be given by label.  Doing just the second part
might be reasonable for F9.  I don't think that doing the full set of
changes to pull out our label handling code is reasonable for at this
point

Jeremy
diff --git a/fsset.py b/fsset.py
index 04b9222..65693f3 100644
--- a/fsset.py
+++ b/fsset.py
@@ -112,55 +112,22 @@ def devify(device):
 
 class LabelFactory:
     def __init__(self):
-        self.labels = None
+        self.labels = []
 
     def createLabel(self, mountpoint, maxLabelChars, kslabel = None):
-        if self.labels == None:
-
-            self.labels = {}
-            diskset = partedUtils.DiskSet()
-            diskset.openDevices()
-            diskset.stopMdRaid()
-            diskset.startMdRaid()
-            labels = diskset.getLabels()
-            del diskset
-            self.reserveLabels(labels)
-
         # If a label was specified in the kickstart file, return that as
-        # the label - unless it's already in the reserved list.  If that's
-        # the case, make a new one.
-        if kslabel and kslabel not in self.labels:
-           self.labels[kslabel] = 1
-           return kslabel
-
-        if len(mountpoint) > maxLabelChars:
-            mountpoint = mountpoint[0:maxLabelChars]
-        count = 0
-        while self.labels.has_key(mountpoint):
-            count = count + 1
-            s = "%s" % count
-            if (len(mountpoint) + len(s)) <= maxLabelChars:
-                mountpoint = mountpoint + s
-            else:
-                strip = len(mountpoint) + len(s) - maxLabelChars
-                mountpoint = mountpoint[0:len(mountpoint) - strip] + s
-        self.labels[mountpoint] = 1
-
-        return mountpoint
+        # the label - unless it's already in the reserved list.  Otherwise,
+        # we don't label anymore
+        if kslabel and not self.isLabelReserved(kslabel):
+            self.labels.append(kslabel)
+            return kslabel
 
-    def reserveLabels(self, labels):
-        if self.labels == None:
-            self.labels = {}
-        for device, label in labels.items():
-            self.labels[label] = 1
+        return ""
 
     def isLabelReserved(self, label):
-        if self.labels == None:
-            return False
-        elif self.labels.has_key(label):
-            return True
-        else:
+        if isys.getDevByLabel(label) is None and label not in self.labels:
             return False
+        return True
 
 labelFactory = LabelFactory()
 
@@ -2696,10 +2663,6 @@ def readFstab (anaconda):
             log.warning("Duplicate labels for %s, but no intf so trying "
                         "to continue" %(label,))
 
-    # mark these labels found on the system as used so the factory
-    # doesn't give them to another device
-    labelFactory.reserveLabels(labels)
-
     loopIndex = {}
 
     f = open (path, "r")
diff --git a/isys/isys.c b/isys/isys.c
index 431295f..d3972e9 100644
--- a/isys/isys.c
+++ b/isys/isys.c
@@ -136,6 +136,7 @@ static PyObject * doSegvHandler(PyObject *s, PyObject *args);
 static PyObject * doAuditDaemon(PyObject *s);
 static PyObject * doPrefixToNetmask(PyObject *s, PyObject *args);
 static PyObject * doGetBlkidData(PyObject * s, PyObject * args);
+static PyObject * doGetDevByBlkid(PyObject * s, PyObject * args);
 
 static PyMethodDef isysModuleMethods[] = {
     { "ejectcdrom", (PyCFunction) doEjectCdrom, METH_VARARGS, NULL },
@@ -188,6 +189,7 @@ static PyMethodDef isysModuleMethods[] = {
     { "auditdaemon", (PyCFunction) doAuditDaemon, METH_NOARGS, NULL },
     { "prefix2netmask", (PyCFunction) doPrefixToNetmask, METH_VARARGS, NULL },
     { "getblkid", (PyCFunction) doGetBlkidData, METH_VARARGS, NULL },
+    { "getdevbyblkid", (PyCFunction) doGetDevByBlkid, METH_VARARGS, NULL },
     { NULL, NULL, 0, NULL }
 } ;
 
@@ -1219,4 +1221,20 @@ static PyObject * doGetBlkidData(PyObject * s, PyObject * args) {
     return Py_None;
 }
 
+static PyObject * doGetDevByBlkid(PyObject * s, PyObject * args) {
+    blkid_cache cache;
+    char * bdev = NULL;
+    const char * key, *value;
+
+    if (!PyArg_ParseTuple(args, "ss", &key, &value)) return NULL;
+
+    blkid_get_cache(&cache, NULL);
+    bdev = blkid_get_devname(cache, key, value);
+    if (bdev != NULL)
+        return Py_BuildValue("s", bdev);
+
+    Py_INCREF(Py_None);
+    return Py_None;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4: */
diff --git a/isys/isys.py b/isys/isys.py
index 8c20d1e..19ede4e 100755
--- a/isys/isys.py
+++ b/isys/isys.py
@@ -747,6 +747,9 @@ def dhcpNetDevice(device):
 
     return _isys.dhcpnetdevice(devname, v4, v4method, v6, v6method, klass)
 
+def getDevByLabel(label):
+    return _isys.getdevbyblkid("LABEL", label)
+
 def readFSUuid(device):
     if not os.path.exists(device):
         device = "/dev/%s" % device
diff --git a/partitions.py b/partitions.py
index 1e92600..e38b4e5 100644
--- a/partitions.py
+++ b/partitions.py
@@ -288,7 +288,6 @@ class Partitions:
         """Clear the delete list and set self.requests to reflect disk."""
         self.deletes = []
         self.requests = []
-        labels = diskset.getLabels()
         drives = diskset.disks.keys()
         drives.sort()
         for drive in drives:
@@ -331,12 +330,6 @@ class Partitions:
                 spec.device = fsset.PartedPartitionDevice(part).getDevice()
                 spec.maxResizeSize = partedUtils.getMaxAvailPartSizeMB(part)
 
-                # set label if makes sense
-                if ptype and ptype.isMountable():
-                    if spec.device in labels.keys():
-                        if labels[spec.device] and len(labels[spec.device])>0:
-                            spec.fslabel = labels[spec.device]
-
                 self.addRequest(spec)
                 part = disk.next_partition(part)
 
_______________________________________________
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