Пример #1
0
    def teardown(self, recursive=None):
        """ Close, or tear down, a device. """
        if not self.exists and not recursive:
            raise RaidArrayError("device has not been created", self.name)

        if self.status:
            if self.originalFormat.exists:
                self.originalFormat.teardown()
            if self.format.exists:
                self.format.teardown()
            udev_settle()

        # Since BIOS RAID sets (containers in raid terminology) never change
        # there is no need to stop them and later restart them. Not stopping
        # (and thus also not starting) them also works around bug 523334
        if self.type == "mdcontainer" or self.type == "mdbiosraidarray":
            return

        # We don't really care what the array's state is. If the device
        # file exists, we want to deactivate it. raid has too many
        # states.
        if self.exists and os.path.exists(self.path):
            raid.mddeactivate(self.path)

        if recursive:
            self.teardownParents(recursive=recursive)
Пример #2
0
    def teardown(self, recursive=None):
        """ Close, or tear down, a device. """
        if not self.exists and not recursive:
            raise RaidArrayError("device has not been created", self.name)

        if self.status:
            if self.originalFormat.exists:
                self.originalFormat.teardown()
            if self.format.exists:
                self.format.teardown()
            udev_settle()

        # Since BIOS RAID sets (containers in raid terminology) never change
        # there is no need to stop them and later restart them. Not stopping
        # (and thus also not starting) them also works around bug 523334
        if self.type == "mdcontainer" or self.type == "mdbiosraidarray":
            return

        # We don't really care what the array's state is. If the device
        # file exists, we want to deactivate it. raid has too many
        # states.
        if self.exists and os.path.exists(self.path):
            raid.mddeactivate(self.path)

        if recursive:
            self.teardownParents(recursive=recursive)
Пример #3
0
    def setup(self, intf=None, orig=False):
        """ Open, or set up, a device. """
        if not self.exists:
            raise RaidArrayError("device has not been created", self.name)

        if self.status:
            return

        disks = []
        for member in self.devices:
            member.setup(orig=orig)
            disks.append(member.path)

        update_super_minor = True
        if self.type == "mdcontainer" or self.type == "mdbiosraidarray":
            update_super_minor = False

        raid.mdactivate(self.path,
                          members=disks,
                          super_minor=self.minor,
                          update_super_minor=update_super_minor,
                          uuid=self.uuid)

        udev_settle()

        # we always probe since the device may not be set up when we want
        # information about it
        self._size = self.currentSize
Пример #4
0
    def create(self):
        """ Create the device. """
        if self.exists:
            raise DeviceError("device already exists", self.name)

        try:
            self.createParents()
            self.setupParents()

            disks = [disk.path for disk in self.devices]
            spares = len(self.devices) - self.memberDevices
            raid.mdcreate(self.path,
                            self.level,
                            disks,
                            spares,
                            metadataVer=self.createMetadataVer,
                            bitmap=self.createBitmap)
        except Exception:
            raise
        else:
            self.exists = True
            # the array is automatically activated upon creation, but...
            self.setup()
            udev_settle()
            self.updateSysfsPath()
            info = udev_get_block_device(self.sysfsPath)
            self.uuid = udev_device_get_md_uuid(info)
            for member in self.devices:
                member.mdUuid = self.uuid
Пример #5
0
    def setup(self, intf=None, orig=False):
        """ Open, or set up, a device. """
        if not self.exists:
            raise RaidArrayError("device has not been created", self.name)

        if self.status:
            return

        disks = []
        for member in self.devices:
            member.setup(orig=orig)
            disks.append(member.path)

        update_super_minor = True
        if self.type == "mdcontainer" or self.type == "mdbiosraidarray":
            update_super_minor = False

        raid.mdactivate(self.path,
                        members=disks,
                        super_minor=self.minor,
                        update_super_minor=update_super_minor,
                        uuid=self.uuid)

        udev_settle()

        # we always probe since the device may not be set up when we want
        # information about it
        self._size = self.currentSize
Пример #6
0
    def resize(self, intf=None):
        # XXX resize format probably, right?
        if not self.exists:
            raise DeviceError("device has not been created", self.name)

        # Setup VG parents (in case they are dmraid partitions for example)
        self.vg.setupParents(orig=True)

        if self.originalFormat.exists:
            self.originalFormat.teardown()
        if self.format.exists:
            self.format.teardown()

        udev_settle()
        lvm.lvresize(self.vg.name, self._name, self.size)
Пример #7
0
    def resize(self, intf=None):
        # XXX resize format probably, right?
        if not self.exists:
            raise LogicalVolumeError("device has not been created", self.name)

        # Setup VG parents (in case they are dmraid partitions for example)
        self.vg.setupParents(orig=True)

        if self.originalFormat.exists:
            self.originalFormat.teardown()
        if self.format.exists:
            self.format.teardown()

        udev_settle()
        lvm.lvresize(self.vg.name, self._name, self.size)
Пример #8
0
    def teardown(self, recursive=None):
        """ Close, or tear down, a device. """
        if not self.exists and not recursive:
            raise DeviceError("device has not been created", self.name)

        if self.status:
            if self.originalFormat.exists:
                self.originalFormat.teardown()
            if self.format.exists:
                self.format.teardown()
            udev_settle()

        if self.status:
            try:
                lvm.lvdeactivate(self.vg.name, self._name)
            except lvm.LVMError, msg:
                ctx.logger.debug("lv %s deactivate failed; continuing" % self._name)
Пример #9
0
    def teardown(self, recursive=None):
        """ Close, or tear down, a device. """
        if not self.exists and not recursive:
            raise LogicalVolumeError("device has not been created", self.name)

        if self.status:
            if self.originalFormat.exists:
                self.originalFormat.teardown()
            if self.format.exists:
                self.format.teardown()
            udev_settle()

        if self.status:
            try:
                lvm.lvdeactivate(self.vg.name, self._name)
            except lvm.LVMError, msg:
                ctx.logger.debug("lv %s deactivate failed; continuing" % self._name)
Пример #10
0
    def _addDevice(self, device):
        """ Add a new member device to the array.

            XXX This is for use when probing devices, not for modification
                of arrays.
        """
        if not self.exists:
            raise RaidArrayError("device has not been created", self.name)

        if not isinstance(device.format, self.formatClass):
            raise ValueError("invalid device format for raid member")

        if self.uuid and device.format.mdUuid != self.uuid:
            raise ValueError("cannot add member with non-matching UUID")

        if device in self.devices:
            raise ValueError("device is already a member of this array")

        # we added it, so now set up the relations
        self.devices.append(device)
        device.addChild()

        device.setup()
        udev_settle()
        try:
            raid.mdadd(device.path)
            # mdadd causes udev events
            udev_settle()
        except raid.RaidError as e:
            ctx.logger.warning("failed to add member %s to md array %s: %s"
                        % (device.path, self.path, e))

        if self.status:
            # we always probe since the device may not be set up when we want
            # information about it
            self._size = self.currentSize
Пример #11
0
    def _addDevice(self, device):
        """ Add a new member device to the array.

            XXX This is for use when probing devices, not for modification
                of arrays.
        """
        if not self.exists:
            raise RaidArrayError("device has not been created", self.name)

        if not isinstance(device.format, self.formatClass):
            raise ValueError("invalid device format for raid member")

        if self.uuid and device.format.mdUuid != self.uuid:
            raise ValueError("cannot add member with non-matching UUID")

        if device in self.devices:
            raise ValueError("device is already a member of this array")

        # we added it, so now set up the relations
        self.devices.append(device)
        device.addChild()

        device.setup()
        udev_settle()
        try:
            raid.mdadd(device.path)
            # mdadd causes udev events
            udev_settle()
        except raid.RaidError as e:
            ctx.logger.warning("failed to add member %s to md array %s: %s" %
                               (device.path, self.path, e))

        if self.status:
            # we always probe since the device may not be set up when we want
            # information about it
            self._size = self.currentSize
Пример #12
0
 def activate(self):
     """ Activate the raid set. """
     # This call already checks if the set is active.
     self._raidSet.activate(mknod=True)
     udev_settle()
Пример #13
0
            disks = [disk.path for disk in self.devices]
            spares = len(self.devices) - self.memberDevices
            raid.mdcreate(self.path,
                            self.level,
                            disks,
                            spares,
                            metadataVer=self.createMetadataVer,
                            bitmap=self.createBitmap)
        except Exception, msg:
            raise RaidArrayError, msg
        else:
            self.exists = True
            # the array is automatically activated upon creation, but...
            self.setup()
            udev_settle()
            self.updateSysfsPath()
            info = udev_get_block_device(self.sysfsPath)
            self.uuid = udev_device_get_md_uuid(info)
            for member in self.devices:
                member.mdUuid = self.uuid
        finally:
            if w:
                w.pop()

    @property
    def formatArgs(self):
        formatArgs = []
        if self.format.type == "ext2":
            if self.level == raid.RAID5:
                formatArgs = ['-R',
Пример #14
0
            disks = [disk.path for disk in self.devices]
            spares = len(self.devices) - self.memberDevices
            raid.mdcreate(self.path,
                          self.level,
                          disks,
                          spares,
                          metadataVer=self.createMetadataVer,
                          bitmap=self.createBitmap)
        except Exception, msg:
            raise RaidArrayError, msg
        else:
            self.exists = True
            # the array is automatically activated upon creation, but...
            self.setup()
            udev_settle()
            self.updateSysfsPath()
            info = udev_get_block_device(self.sysfsPath)
            self.uuid = udev_device_get_md_uuid(info)
            for member in self.devices:
                member.mdUuid = self.uuid
        finally:
            if w:
                w.pop()

    @property
    def formatArgs(self):
        formatArgs = []
        if self.format.type == "ext2":
            if self.level == raid.RAID5:
                formatArgs = [
Пример #15
0
 def activate(self):
     """ Activate the raid set. """
     # This call already checks if the set is active.
     self._raidSet.activate(mknod=True)
     udev_settle()