From fb62608fb98e670e18a6aa790eb41ea17d4d3314 Mon Sep 17 00:00:00 2001
From: David Lehman <dlehman@redhat.com>
Date: Tue, 8 Jan 2013 18:15:31 -0600
Subject: [PATCH 01/10] Remove filesystem migration code.

---
 pyanaconda/errors.py                   |  7 ---
 pyanaconda/storage/__init__.py         | 24 ---------
 pyanaconda/storage/deviceaction.py     | 36 +------------
 pyanaconda/storage/devicetree.py       |  2 +-
 pyanaconda/storage/errors.py           |  3 --
 pyanaconda/storage/formats/__init__.py | 11 ----
 pyanaconda/storage/formats/fs.py       | 93 +---------------------------------
 7 files changed, 3 insertions(+), 173 deletions(-)

diff --git a/pyanaconda/errors.py b/pyanaconda/errors.py
index 3ae9178..5011683 100644
--- a/pyanaconda/errors.py
+++ b/pyanaconda/errors.py
@@ -106,12 +106,6 @@ class ErrorHandler(object):
         self.ui.showError(message)
         return ERROR_RAISE
 
-    def _fsMigrateHandler(self, *args, **kwargs):
-        message = _("An error occurred while migrating the filesystem on device %s.") % args[0]
-        message += "\n\n%s" % args[1]
-        self.ui.showError(message)
-        return ERROR_RAISE
-
     def _noDisksHandler(self, *args, **kwargs):
         message = _("An error has occurred - no valid devices were found on "
                     "which to create new file systems.  Please check your "
@@ -256,7 +250,6 @@ class ErrorHandler(object):
         _map = {"KickstartError": self._kickstartErrorHandler,
                 "PartitioningError": self._partitionErrorHandler,
                 "FSResizeError": self._fsResizeHandler,
-                "FSMigrateError": self._fsMigrateHandler,
                 "NoDisksError": self._noDisksHandler,
                 "DirtyFSError": self._dirtyFSHandler,
                 "FSTabTypeMismatchError": self._fstabTypeMismatchHandler,
diff --git a/pyanaconda/storage/__init__.py b/pyanaconda/storage/__init__.py
index 5aeb45a..3dde12d 100644
--- a/pyanaconda/storage/__init__.py
+++ b/pyanaconda/storage/__init__.py
@@ -164,12 +164,6 @@ def turnOnFilesystems(storage):
                                    stdout = "/dev/tty5", stderr="/dev/tty5")
         storage.devicetree.teardownAll()
 
-    upgrade_migrate = False
-    if upgrade:
-        for d in storage.migratableDevices:
-            if d.format.migrate:
-                upgrade_migrate = True
-
     try:
         storage.doIt()
     except FSResizeError as e:
@@ -180,9 +174,6 @@ def turnOnFilesystems(storage):
 
         if errorHandler.cb(e, e.args[0], details=details) == ERROR_RAISE:
             raise
-    except FSMigrateError as e:
-        if errorHandler.cb(e, e.args[0], e.args[1]) == ERROR_RAISE:
-            raise
     except Exception as e:
         raise
 
@@ -1747,10 +1738,6 @@ class Storage(object):
         return self.fsset.mountpoints
 
     @property
-    def migratableDevices(self):
-        return self.fsset.migratableDevices
-
-    @property
     def rootDevice(self):
         return self.fsset.rootDevice
 
@@ -2712,7 +2699,6 @@ class FSSet(object):
         if fstype != "auto" and ftype != dtype:
             log.info("fstab says %s at %s is %s" % (dtype, mountpoint, ftype))
             if fmt.testMount():
-                # XXX we should probably disallow migration for this fs
                 device.format = fmt
             else:
                 device.teardown()
@@ -2964,16 +2950,6 @@ class FSSet(object):
                 if mountpoint == path:
                     return device
 
-    @property
-    def migratableDevices(self):
-        """ List of devices whose filesystems can be migrated. """
-        migratable = []
-        for device in self.devices:
-            if device.format.migratable and device.format.exists:
-                migratable.append(device)
-
-        return migratable
-
     def write(self):
         """ write out all config files based on the set of filesystems """
         # /etc/fstab
diff --git a/pyanaconda/storage/deviceaction.py b/pyanaconda/storage/deviceaction.py
index f13740c..7cb17c4 100644
--- a/pyanaconda/storage/deviceaction.py
+++ b/pyanaconda/storage/deviceaction.py
@@ -43,13 +43,11 @@ log = logging.getLogger("storage")
 ACTION_TYPE_NONE = 0
 ACTION_TYPE_DESTROY = 1000
 ACTION_TYPE_RESIZE = 500
-ACTION_TYPE_MIGRATE = 250
 ACTION_TYPE_CREATE = 100
 
 action_strings = {ACTION_TYPE_NONE: "None",
                   ACTION_TYPE_DESTROY: "Destroy",
                   ACTION_TYPE_RESIZE: "Resize",
-                  ACTION_TYPE_MIGRATE: "Migrate",
                   ACTION_TYPE_CREATE: "Create"}
 
 ACTION_OBJECT_NONE = 0
@@ -168,10 +166,6 @@ class DeviceAction(object):
         return self.type == ACTION_TYPE_CREATE
 
     @property
-    def isMigrate(self):
-        return self.type == ACTION_TYPE_MIGRATE
-
-    @property
     def isResize(self):
         return self.type == ACTION_TYPE_RESIZE
 
@@ -201,10 +195,7 @@ class DeviceAction(object):
         if self.isResize:
             s += " (%s)" % resize_strings[self.dir]
         if self.isFormat:
-            s += " %s" % self.format.desc
-            if self.isMigrate:
-                s += " to %s" % self.format.migrationTarget
-            s += " on"
+            s += " %s on" % self.format.desc
         s += " %s %s (id %d)" % (self.device.type, self.device.name,
                                  self.device.id)
         return s
@@ -588,28 +579,3 @@ class ActionResizeFormat(DeviceAction):
                 retval = True
 
         return retval
-
-
-class ActionMigrateFormat(DeviceAction):
-    """ An action representing the migration of an existing filesystem. """
-    type = ACTION_TYPE_MIGRATE
-    obj = ACTION_OBJECT_FORMAT
-
-    def __init__(self, device):
-        if not device.format.migratable or not device.format.exists:
-            raise ValueError("device format is not migratable")
-
-        DeviceAction.__init__(self, device)
-        self.device.format.migrate = True
-
-    def execute(self):
-        from pyanaconda.progress import progress_report
-
-        msg = _("Migrating filesystem on %(device)s") % {"device": self.device.path}
-        with progress_report(msg):
-            self.device.setup(orig=True)
-            self.device.format.doMigrate()
-
-    def cancel(self):
-        self.device.format.migrate = False
-
diff --git a/pyanaconda/storage/devicetree.py b/pyanaconda/storage/devicetree.py
index 9d902aa..14f2594 100644
--- a/pyanaconda/storage/devicetree.py
+++ b/pyanaconda/storage/devicetree.py
@@ -450,7 +450,7 @@ class DeviceTree(object):
             # add the device back into the tree
             self._addDevice(action.device)
         elif action.isFormat and \
-             (action.isCreate or action.isMigrate or action.isResize):
+             (action.isCreate or action.isResize):
             action.cancel()
 
         self._actions.remove(action)
diff --git a/pyanaconda/storage/errors.py b/pyanaconda/storage/errors.py
index 85465ed..aad1d00 100644
--- a/pyanaconda/storage/errors.py
+++ b/pyanaconda/storage/errors.py
@@ -81,9 +81,6 @@ class FSError(DeviceFormatError):
 class FSResizeError(FSError):
     pass
 
-class FSMigrateError(FSError):
-    pass
-
 class DirtyFSError(FSError):
     pass
 
diff --git a/pyanaconda/storage/formats/__init__.py b/pyanaconda/storage/formats/__init__.py
index 838ad26..e1c8e14 100644
--- a/pyanaconda/storage/formats/__init__.py
+++ b/pyanaconda/storage/formats/__init__.py
@@ -147,7 +147,6 @@ class DeviceFormat(object):
     _packages = []                      # required packages
     _services = []                      # required services
     _resizable = False                  # can be resized
-    _migratable = False                 # can be migrated
     _maxSize = 0                        # maximum size in MB
     _minSize = 0                        # minimum size in MB
     _dump = False
@@ -169,7 +168,6 @@ class DeviceFormat(object):
         self.exists = kwargs.get("exists")
         self.options = kwargs.get("options")
         self._majorminor = None
-        self._migrate = False
 
         # don't worry about existence if this is a DeviceFormat instance
         #if self.__class__ is DeviceFormat:
@@ -379,15 +377,6 @@ class DeviceFormat(object):
         return self._resizable and self.exists
 
     @property
-    def migratable(self):
-        """ Can formats of this type be migrated? """
-        return self._migratable
-
-    @property
-    def migrate(self):
-        return self._migrate
-
-    @property
     def linuxNative(self):
         """ Is this format type native to linux? """
         return self._linuxNative
diff --git a/pyanaconda/storage/formats/fs.py b/pyanaconda/storage/formats/fs.py
index 70a52a4..e1b1315 100644
--- a/pyanaconda/storage/formats/fs.py
+++ b/pyanaconda/storage/formats/fs.py
@@ -117,15 +117,12 @@ class FS(DeviceFormat):
     _labelfs = ""                        # labeling utility
     _fsck = ""                           # fs check utility
     _fsckErrors = {}                     # fs check command error codes & msgs
-    _migratefs = ""                      # fs migration utility
     _infofs = ""                         # fs info utility
     _defaultFormatOptions = []           # default options passed to mkfs
     _defaultMountOptions = ["defaults"]  # default options passed to mount
     _defaultLabelOptions = []
     _defaultCheckOptions = []
-    _defaultMigrateOptions = []
     _defaultInfoOptions = []
-    _migrationTarget = None
     _existingSizeFields = []
     _fsProfileSpecifier = None           # mkfs option specifying fsprofile
 
@@ -187,8 +184,7 @@ class FS(DeviceFormat):
         d = super(FS, self).dict
         d.update({"mountpoint": self.mountpoint, "size": self._size,
                   "label": self.label, "targetSize": self.targetSize,
-                  "mountable": self.mountable,
-                  "migratable": self.migratable})
+                  "mountable": self.mountable})
         return d
 
     def _setTargetSize(self, newsize):
@@ -384,36 +380,6 @@ class FS(DeviceFormat):
         if self.label:
             self.writeLabel(self.label)
 
-    def doMigrate(self):
-        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")
-
-        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
-
     @property
     def resizeArgs(self):
         argv = [self.device, "%d" % (self.targetSize,)]
@@ -702,20 +668,11 @@ class FS(DeviceFormat):
         return self._labelfs
 
     @property
-    def migratefsProg(self):
-        """ Program used to migrate filesystems of this type. """
-        return self._migratefs
-
-    @property
     def infofsProg(self):
         """ Program used to get information for this filesystem type. """
         return self._infofs
 
     @property
-    def migrationTarget(self):
-        return self._migrationTarget
-
-    @property
     def utilsAvailable(self):
         # we aren't checking for fsck because we shouldn't need it
         for prog in [self.mkfsProg, self.resizefsProg, self.labelfsProg,
@@ -789,34 +746,6 @@ class FS(DeviceFormat):
 
     options = property(_getOptions, _setOptions)
 
-    def _isMigratable(self):
-        """ Can filesystems of this type be migrated? """
-        return bool(self._migratable and self.migratefsProg and
-                    iutil.find_program_in_path(self.migratefsProg) and
-                    self.migrationTarget)
-
-    migratable = property(_isMigratable)
-
-    def _setMigrate(self, migrate):
-        if not migrate:
-            self._migrate = migrate
-            return
-
-        if self.migratable and self.exists:
-            self._migrate = migrate
-        else:
-            raise ValueError("cannot set migrate on non-migratable filesystem")
-
-    migrate = property(lambda f: f._migrate, lambda f,m: f._setMigrate(m))
-
-    @property
-    def type(self):
-        _type = self._type
-        if self.migrate:
-            _type = self.migrationTarget
-
-        return _type
-
     @property
     def mountType(self):
         if not self._mountType:
@@ -881,10 +810,6 @@ class Ext2FS(FS):
     _defaultCheckOptions = ["-f", "-p", "-C", "0"]
     _dump = True
     _check = True
-    _migratable = True
-    _migrationTarget = "ext3"
-    _migratefs = "tune2fs"
-    _defaultMigrateOptions = ["-j"]
     _infofs = "dumpe2fs"
     _defaultInfoOptions = ["-h"]
     _existingSizeFields = ["Block count:", "Block size:"]
@@ -906,18 +831,6 @@ class Ext2FS(FS):
 
         return msg.strip()
 
-    def doMigrate(self):
-        # if journal already exists skip
-        if isys.ext2HasJournal(self.device):
-            log.info("Skipping migration of %s, has a journal already."
-                     % self.device)
-            return
-
-        FS.doMigrate(self)
-
-    def doFormat(self, *args, **kwargs):
-        FS.doFormat(self, *args, **kwargs)
-
     def writeRandomUUID(self):
         if not self.exists:
             raise FSError("filesystem does not exist")
@@ -1011,9 +924,7 @@ class Ext3FS(Ext2FS):
     """ ext3 filesystem. """
     _type = "ext3"
     _defaultFormatOptions = ["-t", "ext3"]
-    _migratable = False
     _modules = ["ext3"]
-    _defaultMigrateOptions = ["-O", "extents"]
     partedSystem = fileSystemType["ext3"]
 
     # It is possible for a user to specify an fsprofile that defines a blocksize
@@ -1029,7 +940,6 @@ class Ext4FS(Ext3FS):
     """ ext4 filesystem. """
     _type = "ext4"
     _defaultFormatOptions = ["-t", "ext4"]
-    _migratable = False
     _modules = ["ext4"]
     partedSystem = fileSystemType["ext4"]
 
@@ -1460,7 +1370,6 @@ class Iso9660FS(FS):
     _linuxNative = False
     _dump = False
     _check = False
-    _migratable = False
     _defaultMountOptions = ["ro"]
 
 register_device_format(Iso9660FS)
-- 
1.7.11.7

