Esempio n. 1
0
    def doMigrate(self, intf=None):
        if not self.exists:
            raise FSError("filesystem has not been created")

        if not self.migratable or not self.migrate:
            return

        if not os.path.exists(self.device):
            raise FSError("device does not exist")

        # if journal already exists skip
        if isys.ext2HasJournal(self.device):
            log.info("Skipping migration of %s, has a journal already." %
                     self.device)
            return

        argv = self._defaultMigrateOptions[:]
        argv.append(self.device)
        try:
            rc = iutil.execWithRedirect(self.migratefsProg,
                                        argv,
                                        stdout="/dev/tty5",
                                        stderr="/dev/tty5")
        except Exception as e:
            raise FSMigrateError("filesystem migration failed: %s" % e,
                                 self.device)

        if rc:
            raise FSMigrateError("filesystem migration failed: %s" % rc,
                                 self.device)

        # the other option is to actually replace this instance with an
        # instance of the new filesystem type.
        self._type = self.migrationTarget
Esempio n. 2
0
    def doMigrate(self, intf=None):
        if not self.exists:
            raise FSError("filesystem has not been created")

        if not self.migratable or not self.migrate:
            return

        if not os.path.exists(self.device):
            raise FSError("device does not exist")

        # if journal already exists skip
        if isys.ext2HasJournal(self.device):
            log.info("Skipping migration of %s, has a journal already."
                     % self.device)
            return

        argv = self._defaultMigrateOptions[:]
        argv.append(self.device)
        try:
            rc = iutil.execWithRedirect(self.migratefsProg,
                                        argv,
                                        stdout = "/dev/tty5",
                                        stderr = "/dev/tty5")
        except Exception as e:
            raise FSMigrateError("filesystem migration failed: %s" % e,
                                 self.device)

        if rc:
            raise FSMigrateError("filesystem migration failed: %s" % rc,
                                 self.device)

        # the other option is to actually replace this instance with an
        # instance of the new filesystem type.
        self._type = self.migrationTarget
        self._mountType = self.migrationTarget
Esempio n. 3
0
    def tuneFS(self):
        if not isys.ext2HasJournal(self.device):
            # only do this if there's a journal
            return

        try:
            rc = iutil.execWithRedirect(
                "tune2fs", ["-c0", "-i0", "-ouser_xattr,acl", self.device],
                stdout="/dev/tty5",
                stderr="/dev/tty5")
        except Exception as e:
            log.error("failed to run tune2fs on %s: %s" % (self.device, e))
Esempio n. 4
0
    def tuneFS(self):
        if not isys.ext2HasJournal(self.device):
            # only do this if there's a journal
            return

        try:
            rc = iutil.execWithRedirect("tune2fs",
                                        ["-c0", "-i0",
                                         "-ouser_xattr,acl", self.device],
                                        stdout = "/dev/tty5",
                                        stderr = "/dev/tty5")
        except Exception as e:
            log.error("failed to run tune2fs on %s: %s" % (self.device, e))
Esempio n. 5
0
def sniffFilesystemType(device):
    """Sniff to determine the type of fs on device.  

    device - name of device to sniff.  we try to create it if it doesn't exist.
    """

    if os.access(device, os.O_RDONLY):
        dev = device
    else:
        dev = "/tmp/" + device
        if not os.access(dev, os.O_RDONLY):
            try:
                isys.makeDevInode(device, dev)
            except:
                pass

    pagesize = isys.getpagesize()
    if pagesize > 2048:
        num = pagesize
    else:
        num = 2048
    try:
        fd = os.open(dev, os.O_RDONLY)
        buf = os.read(fd, num)
        os.close(fd)
    except:
        return None

    if len(buf) < pagesize:
	try:
	    log("Tried to read pagesize for %s in sniffFilesystemType and only read %s", dev, len(buf))
	except:
	    pass
	return None

    # ext2 check
    if struct.unpack("<H", buf[1080:1082]) == (0xef53,):
        if isys.ext2HasJournal(dev, makeDevNode = 0):
            return "ext3"
        else:
            return "ext2"

    # physical volumes start with HM (see linux/lvm.h
    # and LVM/ver/tools/lib/pv_copy.c)
    if buf.startswith("HM"):
        return "physical volume (LVM)"
    # xfs signature
    if buf.startswith("XFSB"):
        return "xfs"

    if (buf[pagesize - 10:] == "SWAP-SPACE" or
        buf[pagesize - 10:] == "SWAPSPACE2"):
        return "swap"

    try:
        isys.raidsbFromDevice(dev)
        return "software RAID"
    except:
        pass

    if fsset.isValidReiserFS(dev):
        return "reiserfs"

    if fsset.isValidJFS(dev):
        return "jfs"

    # FIXME:  we don't look for vfat

    return None