Example #1
0
    def unmount(self, allow_lazy=False):
        """Unmounts the given volume."""
        super().unmount(allow_lazy=allow_lazy)

        if self.mountpoint is not None:
            _util.clean_unmount(['umount'], self.mountpoint)
            self.mountpoint = None
Example #2
0
    def unmount(self, remove_rw=False):
        """Removes all ties of this disk to the filesystem, so the image can be unmounted successfully.

        :raises SubsystemError: when one of the underlying commands fails. Some are swallowed.
        :raises CleanupError: when actual cleanup fails. Some are swallowed.
        """

        for m in list(
                sorted(self.volumes,
                       key=lambda v: v.mountpoint or "",
                       reverse=True)):
            try:
                m.unmount()
            except ImageMounterError:
                logger.warning("Error unmounting volume {0}".format(
                    m.mountpoint))

        if self.mountpoint:
            _util.clean_unmount(['fusermount', '-u'], self.mountpoint)

        if self._paths.get('avfs'):
            _util.clean_unmount(['fusermount', '-u'], self._paths['avfs'])

        if self.rw_active() and remove_rw:
            os.remove(self.rwpath)

        self.is_mounted = False
Example #3
0
    def unmount_base_images(self):
        """Unmounts all mounts identified by :func:`find_base_images`"""

        for mountpoint in self.find_base_images():
            try:
                _util.clean_unmount(['fusermount', '-u'], mountpoint)
            except SubsystemError:
                _util.clean_unmount(['fusermount', '-uz'], mountpoint)
Example #4
0
    def unmount(self):
        """Unounts the volume from the filesystem."""

        for volume in self.volumes:
            volume.unmount()

        if self.loopback and self.volume_group:
            try:
                _util.check_call_(['vgchange', '-a', 'n', self.volume_group], stdout=subprocess.PIPE)
            except Exception:
                return False

            self.volume_group = ""

        if self.loopback and self.luks_path:
            try:
                _util.check_call_(['cryptsetup', 'luksClose', self.luks_path], stdout=subprocess.PIPE)
            except Exception:
                return False

            self.luks_path = ""

        if self.loopback:
            try:
                _util.check_call_(['losetup', '-d', self.loopback])
            except Exception:
                return False

            self.loopback = ""

        if self.bindmountpoint:
            if not _util.clean_unmount(['umount'], self.bindmountpoint, rmdir=False):
                return False

            self.bindmountpoint = ""

        if self.mountpoint:
            if not _util.clean_unmount(['umount'], self.mountpoint):
                return False

            self.mountpoint = ""

        if self.carvepoint:
            try:
                shutil.rmtree(self.carvepoint)
            except OSError:
                return False
            else:
                self.carvepoint = ""

        return True
Example #5
0
    def unmount(self, remove_rw=False):
        """Removes all ties of this disk to the filesystem, so the image can be unmounted successfully. Warning: this
        method will destruct the entire RAID array in which this disk takes part.
        """

        for m in list(sorted(self.volumes, key=lambda v: v.mountpoint or "", reverse=True)):
            if not m.unmount():
                logger.warning("Error unmounting volume {0}".format(m.mountpoint))

        # TODO: remove specific device from raid array
        if self.md_device:
            # Removes the RAID device first. Actually, we should be able to remove the devices from the array separately,
            # but whatever.
            try:
                _util.check_call_(['mdadm', '-S', self.md_device], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
                self.md_device = None
            except Exception as e:
                logger.warning("Failed unmounting MD device {0}".format(self.md_device), exc_info=True)

        if self.loopback:
            # noinspection PyBroadException
            try:
                _util.check_call_(['losetup', '-d', self.loopback])
                self.loopback = None
            except Exception:
                logger.warning("Failed deleting loopback device {0}".format(self.loopback), exc_info=True)

        if self.mountpoint and not _util.clean_unmount(['fusermount', '-u'], self.mountpoint):
            logger.error("Error unmounting base {0}".format(self.mountpoint))
            return False

        if self.avfs_mountpoint and not _util.clean_unmount(['fusermount', '-u'], self.avfs_mountpoint):
            logger.error("Error unmounting AVFS mountpoint {0}".format(self.avfs_mountpoint))
            return False

        if self.rw_active() and remove_rw:
            os.remove(self.rwpath)

        return True
Example #6
0
    def unmount(self, remove_rw=False):
        """Removes all ties of this disk to the filesystem, so the image can be unmounted successfully.

        :raises SubsystemError: when one of the underlying commands fails. Some are swallowed.
        :raises CleanupError: when actual cleanup fails. Some are swallowed.
        """

        for m in list(sorted(self.volumes, key=lambda v: v.mountpoint or "", reverse=True)):
            try:
                m.unmount()
            except ImageMounterError:
                logger.warning("Error unmounting volume {0}".format(m.mountpoint))

        if self.mountpoint:
            _util.clean_unmount(["fusermount", "-u"], self.mountpoint)

        if self._paths.get("avfs"):
            _util.clean_unmount(["fusermount", "-u"], self._paths["avfs"])

        if self.rw_active() and remove_rw:
            os.remove(self.rwpath)

        self.is_mounted = False
Example #7
0
    def unmount(self, remove_rw=False, allow_lazy=False):
        """Removes all ties of this disk to the filesystem, so the image can be unmounted successfully.

        :raises SubsystemError: when one of the underlying commands fails. Some are swallowed.
        :raises CleanupError: when actual cleanup fails. Some are swallowed.
        """

        for m in list(sorted(self.volumes, key=lambda v: v.mountpoint or "", reverse=True)):
            try:
                m.unmount(allow_lazy=allow_lazy)
            except ImageMounterError:
                logger.warning("Error unmounting volume {0}".format(m.mountpoint))

        if self._paths.get('nbd'):
            _util.clean_unmount(['qemu-nbd', '-d'], self._paths['nbd'], rmdir=False)

        if self.mountpoint:
            try:
                _util.clean_unmount(['fusermount', '-u'], self.mountpoint)
            except SubsystemError:
                if not allow_lazy:
                    raise
                _util.clean_unmount(['fusermount', '-uz'], self.mountpoint)

        if self._paths.get('avfs'):
            try:
                _util.clean_unmount(['fusermount', '-u'], self._paths['avfs'])
            except SubsystemError:
                if not allow_lazy:
                    raise
                _util.clean_unmount(['fusermount', '-uz'], self._paths['avfs'])

        if self.rw_active() and remove_rw:
            os.remove(self.rwpath)

        self.is_mounted = False
Example #8
0
    def unmount(self, allow_lazy=False):
        """Unounts the volume from the filesystem.

        :raises SubsystemError: if one of the underlying processes fails
        :raises CleanupError: if the cleanup fails
        """

        for volume in self.volumes:
            try:
                volume.unmount(allow_lazy=allow_lazy)
            except ImageMounterError:
                pass

        if self.is_mounted:
            logger.info("Unmounting volume %s", self)

        if self._paths.get('vss'):
            try:
                _util.clean_unmount(['fusermount', '-u'], self._paths['vss'])
            except SubsystemError:
                if not allow_lazy:
                    raise
                _util.clean_unmount(['fusermount', '-uz'], self._paths['vss'])
            del self._paths['vss']

        if self._paths.get('bindmounts'):
            for mp in self._paths['bindmounts']:
                _util.clean_unmount(['umount'], mp, rmdir=False)
            del self._paths['bindmounts']

        if self._paths.get('carve'):
            try:
                shutil.rmtree(self._paths['carve'])
            except OSError as e:
                raise SubsystemError(e)
            else:
                del self._paths['carve']

        self.filesystem.unmount(allow_lazy=allow_lazy)

        self.is_mounted = False
Example #9
0
    def unmount_base_images(self):
        """Unmounts all mounts identified by :func:`find_base_images`"""

        for mountpoint in self.find_base_images():
            _util.clean_unmount(['fusermount', '-u'], mountpoint)
Example #10
0
    def unmount_mounts(self):
        """Unmounts all mounts identified by :func:`find_mounts`"""

        for mountpoint in self.find_mounts():
            _util.clean_unmount(['umount'], mountpoint)
Example #11
0
    def unmount_bindmounts(self):
        """Unmounts all bind mounts identified by :func:`find_bindmounts`"""

        for mountpoint in self.find_bindmounts():
            _util.clean_unmount(['umount'], mountpoint, rmdir=False)
Example #12
0
    def unmount(self, allow_lazy=False):
        """Unounts the volume from the filesystem.

        :raises SubsystemError: if one of the underlying processes fails
        :raises CleanupError: if the cleanup fails
        """

        for volume in self.volumes:
            try:
                volume.unmount(allow_lazy=allow_lazy)
            except ImageMounterError:
                pass

        if self.is_mounted:
            logger.info("Unmounting volume %s", self)

        if self.loopback and self.info.get('volume_group'):
            _util.check_call_(
                ["lvm", 'vgchange', '-a', 'n', self.info['volume_group']],
                wrap_error=True,
                stdout=subprocess.PIPE)
            self.info['volume_group'] = ""

        if self.loopback and self._paths.get('luks'):
            _util.check_call_(['cryptsetup', 'luksClose', self._paths['luks']],
                              wrap_error=True,
                              stdout=subprocess.PIPE)
            del self._paths['luks']

        if self._paths.get('bde'):
            try:
                _util.clean_unmount(['fusermount', '-u'], self._paths['bde'])
            except SubsystemError:
                if not allow_lazy:
                    raise
                _util.clean_unmount(['fusermount', '-uz'], self._paths['bde'])
            del self._paths['bde']

        if self._paths.get('md'):
            md_path = self._paths['md']
            del self._paths[
                'md']  # removing it here to ensure we do not enter an infinite loop, will add it back later

            # MD arrays are a bit complicated, we also check all other volumes that are part of this array and
            # unmount them as well.
            logger.debug(
                "All other volumes that use %s as well will also be unmounted",
                md_path)
            for v in self.disk.get_volumes():
                if v != self and v._paths.get('md') == md_path:
                    v.unmount(allow_lazy=allow_lazy)

            try:
                _util.check_output_(["mdadm", '--stop', md_path],
                                    stderr=subprocess.STDOUT)
            except Exception as e:
                self._paths['md'] = md_path
                raise SubsystemError(e)

        if self._paths.get('vss'):
            try:
                _util.clean_unmount(['fusermount', '-u'], self._paths['vss'])
            except SubsystemError:
                if not allow_lazy:
                    raise
                _util.clean_unmount(['fusermount', '-uz'], self._paths['vss'])
            del self._paths['vss']

        if self.loopback:
            _util.check_call_(['losetup', '-d', self.loopback],
                              wrap_error=True)
            self.loopback = ""

        if self._paths.get('bindmounts'):
            for mp in self._paths['bindmounts']:
                _util.clean_unmount(['umount'], mp, rmdir=False)
            del self._paths['bindmounts']

        if self.mountpoint:
            _util.clean_unmount(['umount'], self.mountpoint)
            self.mountpoint = ""

        if self._paths.get('carve'):
            try:
                shutil.rmtree(self._paths['carve'])
            except OSError as e:
                raise SubsystemError(e)
            else:
                del self._paths['carve']

        self.is_mounted = False
Example #13
0
    def unmount_base_images(self):
        """Unmounts all mounts identified by :func:`find_base_images`"""

        for mountpoint in self.find_base_images():
            _util.clean_unmount(['fusermount', '-u'], mountpoint)
Example #14
0
    def unmount_mounts(self):
        """Unmounts all mounts identified by :func:`find_mounts`"""

        for mountpoint in self.find_mounts():
            _util.clean_unmount(['umount'], mountpoint)
Example #15
0
    def unmount_bindmounts(self):
        """Unmounts all bind mounts identified by :func:`find_bindmounts`"""

        for mountpoint in self.find_bindmounts():
            _util.clean_unmount(['umount'], mountpoint, rmdir=False)
Example #16
0
    def unmount(self):
        """Unounts the volume from the filesystem.

        :raises SubsystemError: if one of the underlying processes fails
        :raises CleanupError: if the cleanup fails
        """

        for volume in self.volumes:
            try:
                volume.unmount()
            except ImageMounterError:
                pass

        if self.is_mounted:
            logger.info("Unmounting volume %s", self)

        if self.loopback and self.info.get('volume_group'):
            _util.check_call_(["lvm", 'vgchange', '-a', 'n', self.info['volume_group']],
                              wrap_error=True, stdout=subprocess.PIPE)
            self.info['volume_group'] = ""

        if self.loopback and self._paths.get('luks'):
            _util.check_call_(['cryptsetup', 'luksClose', self._paths['luks']], wrap_error=True, stdout=subprocess.PIPE)
            del self._paths['luks']

        if self._paths.get('bde'):
            _util.clean_unmount(['fusermount', '-u'], self._paths['bde'])
            del self._paths['bde']

        if self._paths.get('md'):
            md_path = self._paths['md']
            del self._paths['md']  # removing it here to ensure we do not enter an infinite loop, will add it back later

            # MD arrays are a bit complicated, we also check all other volumes that are part of this array and
            # unmount them as well.
            logger.debug("All other volumes that use %s as well will also be unmounted", md_path)
            for v in self.disk.get_volumes():
                if v != self and v._paths.get('md') == md_path:
                    v.unmount()

            try:
                _util.check_output_(["mdadm", '--stop', md_path], stderr=subprocess.STDOUT)
            except Exception as e:
                self._paths['md'] = md_path
                raise SubsystemError(e)

        if self._paths.get('vss'):
            _util.clean_unmount(['fusermount', '-u'], self._paths['vss'])
            del self._paths['vss']

        if self.loopback:
            _util.check_call_(['losetup', '-d', self.loopback], wrap_error=True)
            self.loopback = ""

        if self._paths.get('bindmounts'):
            for mp in self._paths['bindmounts']:
                _util.clean_unmount(['umount'], mp, rmdir=False)
            del self._paths['bindmounts']

        if self.mountpoint:
            _util.clean_unmount(['umount'], self.mountpoint)
            self.mountpoint = ""

        if self._paths.get('carve'):
            try:
                shutil.rmtree(self._paths['carve'])
            except OSError as e:
                raise SubsystemError(e)
            else:
                del self._paths['carve']

        self.is_mounted = False