Esempio n. 1
0
    def run(self):
        if self.dialog is None:
            return []

        while 1:
            rc = self.dialog.exec_()
            operations = []
            raidmembers = []

            if not rc:
                self.destroy()
                return []

            widget = self.dialog.content

            mountpoint = unicode(widget.mountpointMenu.currentText())
            active = widget.mountpointMenu.isEnabled()
            if active and mountpoint:
                msg = sanityCheckMountPoint(mountpoint)
                if msg:
                    self.intf.messageWindow(_("Mount Point Error"),
                                            msg,
                                            type="error")
                    continue

                used = False
                for (mp, dev) in self.storage.mountpoints.iteritems():
                    if mp == mountpoint and \
                       dev.id != self.origrequest.id and \
                       not (self.origrequest.format.type == "luks" and
                            self.origrequest in dev.parents):
                        used = True
                        break

                if used:
                    self.intf.messageWindow(_("Mount point in use"),
                                            _("The mount point \"%s\" is in "
                                              "use. Please pick another.") %
                                            (mountpoint, ),
                                            type="warning")
                    continue

            for index in range(widget.raidMembers.count()):
                if widget.raidMembers.item(index).checkState() == Qt.Checked:
                    raidmembers.append(
                        widget.raidMembers.item(index).partition)

            # The user has to select some devices to be part of the array.
            if not raidmembers:
                raidlevel = int(
                    widget.raidLevels.itemData(
                        widget.raidLevels.currentIndex()))
                self.intf.messageWindow(
                    _("Invalid Raid Members"),
                    _("A RAID%(level)d set requires at least %(min_member)d member"
                      ) % {
                          "level": raidlevel,
                          "min_member": raid.get_raid_min_members(raidlevel)
                      },
                    type="warning")
                continue

            if not self.origrequest.exists:
                formatType = str(widget.filesystemMenu.currentText())
                raidminor = int(
                    widget.raidMinors.itemData(
                        widget.raidMinors.currentIndex()))
                raidlevel = int(
                    widget.raidLevels.itemData(
                        widget.raidLevels.currentIndex()))

                if not raid.isRaid(raid.RAID0, raidlevel):
                    spares = widget.spareSpin.value()
                else:
                    spares = 0

                format = formats.getFormat(formatType, mountpoint=mountpoint)
                members = len(raidmembers) - spares

                try:
                    request = self.storage.newRaidArray(
                        minor=raidminor,
                        level=raidlevel,
                        format=format,
                        parents=raidmembers,
                        totalDevices=len(raidmembers),
                        memberDevices=members)
                except ValueError, msg:
                    self.intf.messageWindow(_("Invalid Raid Members"),
                                            unicode(msg),
                                            type="warning")
                    continue

                if not self.isNew:
                    # This may be handled in devicetree.registerAction,
                    # but not in case when we change minor and thus
                    # device name/path (at least with current md)
                    operations.append(OperationDestroyDevice(self.origrequest))

                operations.append(OperationCreateDevice(request))
                operations.append(OperationCreateFormat(request))

            else:
                format = None
                if widget.formatRadio.isChecked():
                    formatType = str(widget.formatCombo.currentText())
                    format = formats.getFormat(formatType,
                                               mountpoint=mountpoint,
                                               device=self.origrequest.path)
                    operations.append(
                        OperationCreateFormat(self.origrequest, format))
                else:
                    cancel = []
                    cancel.extend(
                        self.storage.devicetree.findOperations(
                            type="destroy",
                            object="format",
                            devid=self.origrequest.id))
                    cancel.extend(
                        self.storage.devicetree.findOperations(
                            type="create",
                            object="format",
                            devid=self.origrequest.id))
                    for operation in cancel:
                        self.storage.devicetree.removeOperation(operation)

                    self.origrequest.format = self.origrequest.originalFormat

                if self.origrequest.format.mountable:
                    self.origrequest.format.mountpoint = mountpoint

                if widget.migrateRadio.isChecked():
                    operations.append(OperationMigrateFormat(self.origrequest))

                if self.origrequest.format.exists and not format and \
                   self.storage.formatByDefault(self.origrequest):
                    if not queryNoFormatPreExisting(self.intf):
                        continue

            # everything ok, fall out of loop
            break
Esempio n. 2
0
    def run(self):
        if self.dialog is None:
            return []

        while 1:
            rc = self.dialog.exec_()
            operations = []
            raidmembers = []

            if not rc:
                self.destroy()
                return []

            widget = self.dialog.content

            mountpoint = unicode(widget.mountpointMenu.currentText())
            active = widget.mountpointMenu.isEnabled()
            if active and mountpoint:
                msg = sanityCheckMountPoint(mountpoint)
                if msg:
                    self.intf.messageWindow(_("Mount Point Error"), msg,
                                            type="error")
                    continue

                used = False
                for (mp, dev) in self.storage.mountpoints.iteritems():
                    if mp == mountpoint and \
                       dev.id != self.origrequest.id and \
                       not (self.origrequest.format.type == "luks" and
                            self.origrequest in dev.parents):
                        used = True
                        break

                if used:
                    self.intf.messageWindow(_("Mount point in use"),
                                            _("The mount point \"%s\" is in "
                                              "use. Please pick another.") %
                                            (mountpoint,),
                                            type="warning")
                    continue

            for index in range(widget.raidMembers.count()):
                if widget.raidMembers.item(index).checkState() == Qt.Checked:
                    raidmembers.append(widget.raidMembers.item(index).partition)

            # The user has to select some devices to be part of the array.
            if not raidmembers:
                raidlevel = int(widget.raidLevels.itemData(widget.raidLevels.currentIndex()))
                self.intf.messageWindow(_("Invalid Raid Members"),
                                        _("A RAID%(level)d set requires at least %(min_member)d member")
                                        % {"level":raidlevel,
                                           "min_member":raid.get_raid_min_members(raidlevel)},
                                        type="warning")
                continue

            if not self.origrequest.exists:
                formatType = str(widget.filesystemMenu.currentText())
                raidminor = int(widget.raidMinors.itemData(widget.raidMinors.currentIndex()))
                raidlevel = int(widget.raidLevels.itemData(widget.raidLevels.currentIndex()))

                if not raid.isRaid(raid.RAID0, raidlevel):
                    spares = widget.spareSpin.value()
                else:
                    spares = 0

                format = formats.getFormat(formatType, mountpoint=mountpoint)
                members = len(raidmembers) - spares

                try:
                    request = self.storage.newRaidArray(minor=raidminor,
                                                        level=raidlevel,
                                                        format=format,
                                                        parents=raidmembers,
                                                        totalDevices=len(raidmembers),
                                                        memberDevices=members)
                except ValueError, msg:
                    self.intf.messageWindow(_("Invalid Raid Members"), unicode(msg),
                                            type="warning")
                    continue

                if not self.isNew:
                    # This may be handled in devicetree.registerAction,
                    # but not in case when we change minor and thus
                    # device name/path (at least with current md)
                    operations.append(OperationDestroyDevice(self.origrequest))

                operations.append(OperationCreateDevice(request))
                operations.append(OperationCreateFormat(request))

            else:
                format = None
                if widget.formatRadio.isChecked():
                    formatType = str(widget.formatCombo.currentText())
                    format = formats.getFormat(formatType, mountpoint=mountpoint, device=self.origrequest.path)
                    operations.append(OperationCreateFormat(self.origrequest, format))
                else:
                    cancel = []
                    cancel.extend(self.storage.devicetree.findOperations(type="destroy",
                                                                         object="format",
                                                                         devid=self.origrequest.id))
                    cancel.extend(self.storage.devicetree.findOperations(type="create",
                                                                         object="format",
                                                                         devid=self.origrequest.id))
                    for operation in cancel:
                        self.storage.devicetree.removeOperation(operation)

                    self.origrequest.format = self.origrequest.originalFormat

                if self.origrequest.format.mountable:
                    self.origrequest.format.mountpoint = mountpoint

                if widget.migrateRadio.isChecked():
                    operations.append(OperationMigrateFormat(self.origrequest))

                if self.origrequest.format.exists and not format and \
                   self.storage.formatByDefault(self.origrequest):
                    if not queryNoFormatPreExisting(self.intf):
                        continue

            # everything ok, fall out of loop
            break
Esempio n. 3
0
    def __init__(self, name, level=None, major=None, minor=None, size=None,
                 memberDevices=None, totalDevices=None,
                 uuid=None, format=None, exists=None,
                 parents=None, sysfsPath=''):
        """ Create a RaidArray instance.

            Arguments:

                name -- the device name (generally a device node's basename)

            Keyword Arguments:

                level -- the device's RAID level (a string, eg: '1' or 'raid1')
                parents -- list of member devices (Device instances)
                size -- the device's size (units/format TBD)
                uuid -- the device's UUID
                minor -- the device minor
                sysfsPath -- sysfs device path
                format -- a DeviceFormat instance
                exists -- indicates whether this is an existing device
        """
        Device.__init__(self, name, format=format, exists=exists,
                               major=major, minor=minor, size=size,
                               parents=parents, sysfsPath=sysfsPath)

        self.level = level
        if level == "container":
            self._type = "mdcontainer"
        elif level is not None:
            self.level = raid.raidLevel(level)

        # For new arrays check if we have enough members
        if (not exists and parents and
                len(parents) < raid.get_raid_min_members(self.level)):
            raise ValueError, _("A RAID%(level)d set requires at least %(min_member)d member") % \
                                {"level":self.level, "min_member":raid.get_raid_min_members(self.level)}

        self.uuid = uuid
        self._totalDevices = numeric_type(totalDevices)
        self._memberDevices = numeric_type(memberDevices)
        self.sysfsPath = "/devices/virtual/block/%s" % name
        self.chunkSize = 512.0 / 1024.0         # chunk size in MB
        self.superBlockSize = 2.0               # superblock size in MB

        self.createMetadataVer = "1.1"
        # bitmaps are not meaningful on raid0 according to mdadm-3.0.3
        self.createBitmap = self.level != 0

        # For container members probe size now, as we cannot determine it
        # when teared down.
        if self.parents and self.parents[0].type == "mdcontainer":
            self._size = self.currentSize
            self._type = "mdbiosraidarray"

        self.formatClass = get_device_format("mdmember")
        if not self.formatClass:
            raise RaidArrayError("cannot find class for 'mdmember'", self.name)

        if self.exists and self.uuid:
            # this is a hack to work around mdadm's insistence on giving
            # really high minors to arrays it has no config entry for
            open("/etc/mdadm.conf", "a").write("ARRAY %s UUID=%s\n"
                                                % (self.path, self.uuid))
Esempio n. 4
0
    def __init__(self,
                 name,
                 level=None,
                 major=None,
                 minor=None,
                 size=None,
                 memberDevices=None,
                 totalDevices=None,
                 uuid=None,
                 format=None,
                 exists=None,
                 parents=None,
                 sysfsPath=''):
        """ Create a RaidArray instance.

            Arguments:

                name -- the device name (generally a device node's basename)

            Keyword Arguments:

                level -- the device's RAID level (a string, eg: '1' or 'raid1')
                parents -- list of member devices (Device instances)
                size -- the device's size (units/format TBD)
                uuid -- the device's UUID
                minor -- the device minor
                sysfsPath -- sysfs device path
                format -- a DeviceFormat instance
                exists -- indicates whether this is an existing device
        """
        Device.__init__(self,
                        name,
                        format=format,
                        exists=exists,
                        major=major,
                        minor=minor,
                        size=size,
                        parents=parents,
                        sysfsPath=sysfsPath)

        self.level = level
        if level == "container":
            self._type = "mdcontainer"
        elif level is not None:
            self.level = raid.raidLevel(level)

        # For new arrays check if we have enough members
        if (not exists and parents
                and len(parents) < raid.get_raid_min_members(self.level)):
            raise ValueError, _("A RAID%(level)d set requires at least %(min_member)d member") % \
                                {"level":self.level, "min_member":raid.get_raid_min_members(self.level)}

        self.uuid = uuid
        self._totalDevices = numeric_type(totalDevices)
        self._memberDevices = numeric_type(memberDevices)
        self.sysfsPath = "/devices/virtual/block/%s" % name
        self.chunkSize = 512.0 / 1024.0  # chunk size in MB
        self.superBlockSize = 2.0  # superblock size in MB

        self.createMetadataVer = "1.1"
        # bitmaps are not meaningful on raid0 according to mdadm-3.0.3
        self.createBitmap = self.level != 0

        # For container members probe size now, as we cannot determine it
        # when teared down.
        if self.parents and self.parents[0].type == "mdcontainer":
            self._size = self.currentSize
            self._type = "mdbiosraidarray"

        self.formatClass = get_device_format("mdmember")
        if not self.formatClass:
            raise RaidArrayError("cannot find class for 'mdmember'", self.name)

        if self.exists and self.uuid:
            # this is a hack to work around mdadm's insistence on giving
            # really high minors to arrays it has no config entry for
            open("/etc/mdadm.conf",
                 "a").write("ARRAY %s UUID=%s\n" % (self.path, self.uuid))