diff options
author | Jeremy Katz <katzj@redhat.com> | 2002-05-31 04:22:19 +0000 |
---|---|---|
committer | Jeremy Katz <katzj@redhat.com> | 2002-05-31 04:22:19 +0000 |
commit | 2e58842ca3172343937392a35f41566e34c1755c (patch) | |
tree | 54ebd81c773e6a79cb219dc8be67e3801641f42d | |
parent | 87a722dab1676eb1e1bb37bcfc866d1f6175789f (diff) | |
download | anaconda-2e58842ca3172343937392a35f41566e34c1755c.tar.gz anaconda-2e58842ca3172343937392a35f41566e34c1755c.tar.xz anaconda-2e58842ca3172343937392a35f41566e34c1755c.zip |
clean up getting of request sizes for lvm and raid to be just the same as
for partitions. clean up the ensuing mess. we also need to use proper
sanity checking of requests before doing autopartitioning instead of
the hack that was there before.
-rw-r--r-- | autopart.py | 40 | ||||
-rw-r--r-- | iw/partition_gui.py | 7 | ||||
-rw-r--r-- | partRequests.py | 69 | ||||
-rw-r--r-- | partitioning.py | 79 | ||||
-rw-r--r-- | partitions.py | 10 |
5 files changed, 99 insertions, 106 deletions
diff --git a/autopart.py b/autopart.py index e5224b300..fe772eac7 100644 --- a/autopart.py +++ b/autopart.py @@ -740,10 +740,8 @@ def processPartitioning(diskset, requests, newParts): if request.type == REQUEST_LV and not request.device: request.device = str(request.uniqueID) - if request.type == REQUEST_RAID: - request.size = get_raid_device_size(request, requests, diskset) / 1024 / 1024 - elif request.type == REQUEST_VG: - request.size = get_lvm_volume_group_size(request, requests, diskset) / 1024 / 1024 + if request.type == REQUEST_RAID or request.type == REQUEST_VG: + request.size = request.getActualSize(requests, diskset) if not request.device: # return PARTITION_FAIL raise PartitioningError, "Unsatisfied partition request\n%s" %(request) @@ -945,18 +943,15 @@ def doAutoPartition(dir, diskset, partitions, intf, instClass, dispatch): partitions.addRequest(req) # sanity checks for the auto partitioning requests; mostly only useful - # for kickstart as our installclass defaults SHOULD be sane - (errors, warnings) = partitions.sanityCheckAllRequests(diskset, 1) - if warnings: - for warning in warnings: - log("WARNING: %s" % (warning)) - if errors: - errortxt = string.join(errors, '\n') - intf.messageWindow(_("Partition Request Sanity Check Errors"), - _("The following errors occurred with your " - "partitioning:\n\n%s\n\n" - "Press OK to reboot your system.") % (errortxt)) - sys.exit(0) + # for kickstart as our installclass defaults SHOULD be sane + for req in partitions.requests: + errors = req.sanityCheckRequest(partitions) + if errors: + intf.messageWindow(_("Partition Request Sanity Check Errors"), + _("The following errors occurred with your " + "partitioning:\n\n%s\n\n" + "Press OK to reboot your system.") % + (errors)) try: doPartitioning(diskset, partitions, doRefresh = 0) @@ -984,6 +979,19 @@ def doAutoPartition(dir, diskset, partitions, intf, instClass, dispatch): if isKickstart: sys.exit(0) + # now do a full check of the requests + (errors, warnings) = partitions.sanityCheckAllRequests(diskset) + if warnings: + for warning in warnings: + log("WARNING: %s" % (warning)) + if errors: + errortxt = string.join(errors, '\n') + intf.messageWindow(_("Partition Request Sanity Check Errors"), + _("The following errors occurred with your " + "partitioning:\n\n%s\n\n" + "Press OK to reboot your system.") % (errortxt)) + sys.exit(0) + def autoCreatePartitionRequests(autoreq): """Return a list of requests created with a shorthand notation. diff --git a/iw/partition_gui.py b/iw/partition_gui.py index d146f777f..402215afc 100644 --- a/iw/partition_gui.py +++ b/iw/partition_gui.py @@ -840,7 +840,7 @@ class PartitionWindow(InstallWindow): vgparent = self.tree.append(lvmparent) self.tree[vgparent]['Device'] = _("LVM: %s") % (vgname,) vgrequest = self.partitions.getRequestByVolumeGroupName(vgname) - rsize = requestSize(vgrequest, self.diskset) + rsize = vgrequest.getActualSize(self.partitions, self.diskset) print "volume group %s size is %g" % (vgname, rsize) self.tree[vgparent]['Start'] = "" self.tree[vgparent]['End'] = "" @@ -2128,8 +2128,9 @@ class PartitionWindow(InstallWindow): pv.append(id) part = get_partition_by_name(self.diskset.disks, partname) - availSpaceMB = availSpaceMB + requestSize(pvreq, - self.diskset) + availSpaceMB = (availSpaceMB + + pvreq.getActualSize(self.partitions, + self.diskset)) next = model.iter_next(iter) print "Total size of volume group is %g MB" % (availSpaceMB,) diff --git a/partRequests.py b/partRequests.py index 1a8bd8854..5106c049d 100644 --- a/partRequests.py +++ b/partRequests.py @@ -97,6 +97,13 @@ class RequestSpec: "fstype": fsname, "format": self.format, "bb": self.badblocks, "dev": self.device, "migrate": self.migrate}) return str + + def getActualSize(self, partitions, diskset): + """Return the actual size allocated for the request in megabytes.""" + + sys.stderr.write("WARNING: Abstract RequestSpec.getActualSize() called\n") + import traceback + traceback.print_stack() def getDevice(self, partitions): """Return a device to solidify.""" @@ -174,8 +181,8 @@ class RequestSpec: if partitions and partitions.requests: for request in partitions.requests: if request.mountpoint == mntpt: - if (not self.device - or request.device != self.device): + if (not self.uniqueID or + request.uniqueID != self.uniqueID): return _("The mount point %s is already in use, " "please choose a different mount point." %(mntpt)) @@ -354,6 +361,14 @@ class PartitionSpec(RequestSpec): dev = fsset.PartitionDevice(self.device) return dev + def getActualSize(self, partitions, diskset): + """Return the actual size allocated for the request in megabytes.""" + part = partedUtils.get_partition_by_name(diskset.disks, self.device) + if not part: + # XXX kickstart might still call this before allocating the partitions + raise RuntimeError, "Checking the size of a partition which hasn't been allocated yet" + return partedUtils.getPartSizeMB(part) + def doSizeSanityCheck(self): """Sanity check that the size of the partition is sane.""" if not self.fstype: @@ -492,6 +507,37 @@ class RaidRequestSpec(RequestSpec): spares = self.raidspares) return dev + def getActualSize(self, partitions, diskset): + """Return the actual size allocated for the request in megabytes.""" + + # this seems like a check which should never fail... + if not self.raidmembers or self.raidlevel: + return 0 + nummembers = len(self.raidmembers) - self.raidspares + smallest = None + sum = 0 + for member in self.raidmembers: + req = partitions.getRequestByID(member) + partsize = req.getActualSize(partitions, diskset) + + if raid.isRaid0(self.raidlevel): + sum = sum + partsize + else: + if not smallest: + smallest = partsize + elif partsize < smallest: + smallest = partsize + + if raid.isRaid0(self.raidlevel): + return sum + elif raid.isRaid1(self.raidlevel): + return smallest + elif raid.isRaid5(self.raidlevel): + return (nummembers-1) * smallest + else: + raise ValueError, "Invalid raidlevel in RaidRequest.getActualSize" + + # do RAID specific sanity checks; this is an internal function def sanityCheckRaid(self, partitions): if not self.raidmembers or not self.raidlevel: @@ -567,6 +613,21 @@ class VolumeGroupRequestSpec(RequestSpec): dev = fsset.VolumeGroupDevice(self.volumeGroupName, pvs) return dev + def getActualSize(self, partitions, diskset): + """Return the actual size allocated for the request in megabytes.""" + + # this seems like a bogus check too... + if self.physicalVolumes is None: + return 0 + + totalspace = 0 + for pvid in self.physicalVolumes: + pvreq = partitions.getRequestByID(pvid) + size = pvreq.getActualSize(partitions, diskset) + totalspace = totalspace + size + + return totalspace + class LogicalVolumeRequestSpec(RequestSpec): """Request to represent logical volume devices.""" @@ -611,3 +672,7 @@ class LogicalVolumeRequestSpec(RequestSpec): dev = fsset.LogicalVolumeDevice(vgname, self.size, self.logicalVolumeName) return dev + + def getActualSize(self, partitions, diskset): + """Return the actual size allocated for the request in megabytes.""" + diff --git a/partitioning.py b/partitioning.py index d7144f5a5..ffd2bae22 100644 --- a/partitioning.py +++ b/partitioning.py @@ -38,85 +38,6 @@ import partRequests from rhpl.translate import _ from rhpl.log import log -def get_lvm_volume_group_size(request, requests, diskset): - # got to add up all of physical volumes to get total size - if request.physicalVolumes is None: - return 0 - totalspace = 0 - for physvolid in request.physicalVolumes: - pvreq = requests.getRequestByID(physvolid) - if pvreq.type != REQUEST_RAID: - part = partedUtils.get_partition_by_name(diskset.disks, - pvreq.device) - partsize = part.geom.length * part.geom.disk.dev.sector_size - else: - partsize = get_raid_device_size(pvreq, requests, diskset) - - totalspace = totalspace + partsize - - return totalspace - - -def get_raid_device_size(raidrequest, partitions, diskset): - if not raidrequest.raidmembers or not raidrequest.raidlevel: - return 0 - - raidlevel = raidrequest.raidlevel - nummembers = len(raidrequest.raidmembers) - raidrequest.raidspares - smallest = None - sum = 0 - for member in raidrequest.raidmembers: - req = partitions.getRequestByID(member) - device = req.device - part = partedUtils.get_partition_by_name(diskset.disks, device) - partsize = part.geom.length * part.geom.disk.dev.sector_size - - if raid.isRaid0(raidlevel): - sum = sum + partsize - else: - if not smallest: - smallest = partsize - elif partsize < smallest: - smallest = partsize - - if raid.isRaid0(raidlevel): - return sum - elif raid.isRaid1(raidlevel): - return smallest - elif raid.isRaid5(raidlevel): - return (nummembers-1) * smallest - else: - raise ValueError, "Invalid raidlevel in get_raid_device_size()" - -# return the actual size being used by the request in megabytes -def requestSize(req, diskset): - if req.type == REQUEST_VG: - if req.size != None: - thissize = req.size - else: - thissize = 0 - if req.type == REQUEST_RAID: - # XXX duplicate the hack below. - if req.size != None: - thissize = req.size - else: - thissize = 0 - else: - part = partedUtils.get_partition_by_name(diskset.disks, req.device) - if not part: - # XXX hack for kickstart which ends up calling this - # before allocating the partitions - if req.size: - thissize = req.size - else: - thissize = 0 - else: - thissize = partedUtils.getPartSizeMB(part) - return thissize - - - - def partitionObjectsInitialize(diskset, partitions, dir, intf): if iutil.getArch() == "s390": diff --git a/partitions.py b/partitions.py index 51ada1bd8..71835e742 100644 --- a/partitions.py +++ b/partitions.py @@ -29,8 +29,6 @@ import raid import partedUtils import partRequests -from partitioning import requestSize - from rhpl.translate import _ from rhpl.log import log @@ -505,14 +503,14 @@ class Partitions: "which is required for installation of %s " "to continue.") % (productName,)) - if slash and requestSize(slash, diskset) < 250: + if slash and slash.getActualSize(self, diskset) < 250: warnings.append(_("Your root partition is less than 250 " "megabytes which is usually too small to " "install %s.") % (productName,)) if iutil.getArch() == "ia64": bootreq = self.getRequestByMountPoint("/boot/efi") - if not bootreq or requestSize(bootreq, diskset) < 50: + if not bootreq or bootreq.getActualSize(self, diskset) < 50: errors.append(_("You must create a /boot/efi partition of " "type FAT and a size of 50 megabytes.")) @@ -520,7 +518,7 @@ class Partitions: req = self.getRequestByMountPoint(mount) if not req: continue - if requestSize(req, diskset) < size: + if req.getActualSize(self, diskset) < size: warnings.append(_("Your %s partition is less than %s " "megabytes which is lower than recommended " "for a normal %s install.") @@ -531,7 +529,7 @@ class Partitions: for request in self.requests: if request.fstype and request.fstype.getName() == "swap": foundSwap = foundSwap + 1 - swapSize = swapSize + requestSize(request, diskset) + swapSize = swapSize + request.getActualSize(self, diskset) if baseChecks: rc = request.doSizeSanityCheck() if rc: |