From 3d419435be4b7271277b25420a5a9d148526e320 Mon Sep 17 00:00:00 2001 From: Jeremy Katz Date: Wed, 23 Jan 2002 20:00:43 +0000 Subject: merge in the generic parts of the xfs changes from sgi and in the process take care of some of our multifsification --- fsset.py | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- partitioning.py | 33 +++++++++--------- upgrade.py | 4 +-- 3 files changed, 113 insertions(+), 26 deletions(-) diff --git a/fsset.py b/fsset.py index 5e30374eb..ef4a223d2 100644 --- a/fsset.py +++ b/fsset.py @@ -59,6 +59,19 @@ def fileSystemTypeRegister(klass): def fileSystemTypeGetTypes(): return fileSystemTypes.copy() +def getUsableLinuxFs(): + rc = [] + for fsType in fileSystemTypes.keys(): + if fileSystemTypes[fsType].isMountable() and \ + fileSystemTypes[fsType].isLinuxNativeFS(): + rc.append(fsType) + + # make sure the default is first in the list, kind of ugly + default = fileSystemTypeGetDefault() + if default in rc: + rc = [ default ] + rc.remove(default) + return rc + def mountCompare(a, b): one = a.mountpoint two = b.mountpoint @@ -77,7 +90,7 @@ class LabelFactory: def __init__(self): self.labels = None - def createLabel(self, mountpoint): + def createLabel(self, mountpoint, maxLabelChars): if self.labels == None: self.labels = {} @@ -89,16 +102,16 @@ class LabelFactory: del diskset self.reserveLabels(labels) - if len(mountpoint) > 16: - mountpoint = mountpoint[0:16] + 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)) <= 16: + if (len(mountpoint) + len(s)) <= maxLabelChars: mountpoint = mountpoint + s else: - strip = len(mountpoint) + len(s) - 16 + strip = len(mountpoint) + len(s) - maxLabelChars mountpoint = mountpoint[0:len(mountpoint) - strip] + s self.labels[mountpoint] = 1 @@ -127,6 +140,7 @@ class FileSystemType: self.defaultOptions = "defaults" self.migratetofs = None self.extraFormatArgs = [] + self.maxLabelChars = 16 def mount(self, device, mountpoint, readOnly=0): if not self.isMountable(): @@ -244,6 +258,7 @@ class FileSystemType: else: return 0 + class reiserfsFileSystem(FileSystemType): def __init__(self): FileSystemType.__init__(self) @@ -288,6 +303,47 @@ class reiserfsFileSystem(FileSystemType): fileSystemTypeRegister(reiserfsFileSystem()) +class xfsFileSystem(FileSystemType): + def __init__(self): + FileSystemType.__init__(self) + self.partedFileSystemType = parted.file_system_type_get("xfs") + self.formattable = 1 + self.checked = 1 + self.linuxnativefs = 1 + self.name = "xfs" + self.maxSize = 2 * 1024 * 1024 + self.maxLabelChars = 12 + # we don't even have the module, so it won't be mountable... but + # just in case + self.supported = 0 + + def formatDevice(self, entry, progress, chroot='/'): + devicePath = entry.device.setupDevice(chroot) + + rc = iutil.execWithRedirect("/usr/sbin/mkfs.xfs", + ["mkfs.xfs", "-f", "-l", "internal", + devicePath ], + stdout = "/dev/tty5", + stderr = "/dev/tty5") + + if rc: + raise SystemError + + def labelDevice(self, entry, chroot): + devicePath = entry.device.setupDevice(chroot) + label = labelFactory.createLabel(entry.mountpoint, self.maxLabelChars) + db_cmd = "label " + label + rc = iutil.execWithRedirect("/usr/sbin/xfs_db", + ["xfs_db", "-x", "-c", db_cmd, + devicePath], + stdout = "/dev/tty5", + stderr = "/dev/tty5") + if rc: + raise SystemError + entry.setLabel(label) + +fileSystemTypeRegister(xfsFileSystem()) + class extFileSystem(FileSystemType): def __init__(self): FileSystemType.__init__(self) @@ -299,7 +355,7 @@ class extFileSystem(FileSystemType): def labelDevice(self, entry, chroot): devicePath = entry.device.setupDevice(chroot) - label = labelFactory.createLabel(entry.mountpoint) + label = labelFactory.createLabel(entry.mountpoint, self.maxLabelChars) rc = iutil.execWithRedirect("/usr/sbin/e2label", ["e2label", devicePath, label], stdout = "/dev/tty5", @@ -1467,6 +1523,40 @@ def isValidExt2(device): return 0 +def isValidXFS(device): + file = '/tmp/' + device + isys.makeDevInode(device, file) + try: + fd = os.open(file, os.O_RDONLY) + except: + return 0 + + buf = os.read(fd, 4) + os.close(fd) + + if len(buf) != 4: + return 0 + + if buf == "XFSB": + return 1 + + return 0 + +# this will return a list of types of filesystems which device +# looks like it could be to try mounting as +def getFStoTry(device): + rc = [] + + if isValidXFS(device): + rc.append("xfs") + + if isValidExt2(device): + rc.append("ext2") + rc.append("ext3") + + # XXX check for reiserfs signature, jfs signature, and others ? + return rc + def allocateLoopback(file): found = 1 for i in range(8): diff --git a/partitioning.py b/partitioning.py index 753d4efd9..74bcbecf5 100644 --- a/partitioning.py +++ b/partitioning.py @@ -1280,23 +1280,24 @@ class DiskSet: self.startAllRaid() for dev, devices, level, numActive in self.mdList: - # XXX multifsify. - # XXX NOTE! reiserfs isn't supported on software raid devices. - if not fsset.isValidExt2 (dev): - continue - - try: - isys.mount(dev, mountpoint, readOnly = 1) - except SystemError, (errno, msg): + (errno, msg) = (None, None) + found = 0 + for fs in fsset.getFStoTry(dev): try: - isys.mount(dev, mountpoint, "ext3", readOnly = 1) + isys.mount(dev, mountpoint, fs, readOnly = 1) + found = 1 + break except SystemError, (errno, msg): - intf.messageWindow(_("Error"), - _("Error mounting filesystem " - "on %s: %s") % (dev, msg)) - continue + pass + + if not found: + intf.messageWindow(_("Error"), + _("Error mounting filesystem " + "on %s: %s") % (dev, msg)) + continue + if os.access (mountpoint + '/etc/fstab', os.R_OK): - rootparts.append ((dev, "ext2")) + rootparts.append ((dev, fs)) isys.umount(mountpoint) self.stopAllRaid() @@ -1315,9 +1316,7 @@ class DiskSet: # XXX check for raid superblocks on non-autoraid partitions # (#32562) pass - elif part.fs_type and (part.fs_type.name == "ext2" - or part.fs_type.name == "ext3" - or part.fs_type.name == "reiserfs"): + elif part.fs_type in fsset.getUsableLinuxFs(): node = get_partition_name(part) try: isys.mount(node, mountpoint, part.fs_type.name) diff --git a/upgrade.py b/upgrade.py index e7369a3fd..68f7a337b 100644 --- a/upgrade.py +++ b/upgrade.py @@ -135,9 +135,7 @@ def upgradeSwapSuggestion(dispatch, id, instPath): fsList.append(info) else: for entry in id.fsset.entries: - # XXX multifsify - if (entry.fsystem.getName() == "ext2" - or entry.fsystem.getName() == "ext3"): + if entry.fsystem.getName() in fsset.getUsableLinuxFs(): if flags.setupFilesystems and not entry.isMounted(): continue space = isys.pathSpaceAvailable(instPath + entry.mountpoint) -- cgit