def computeVGSize(self, pvlist, curpe): availSpaceMB = 0L if self.origvgrequest.preexist and self.origvgrequest.preexist_size: availSpaceMB = lvm.clampPVSize(self.origvgrequest.preexist_size, curpe) else: for id in pvlist: pvreq = self.partitions.getRequestByID(id) pvsize = pvreq.getActualSize(self.partitions, self.diskset) # have to clamp pvsize to multiple of PE clampedSize = lvm.clampPVSize(pvsize, curpe) if long(pvsize) == clampedSize: # If clamping reserves only less than 1MB for lvm metadata, # reserve one more PE. clampedSize = clampedSize - (curpe / 1024) availSpaceMB = availSpaceMB + clampedSize log.debug("computeVGSize: vgsize is %s" % (availSpaceMB,)) return availSpaceMB
def getActualSize(self, partitions, diskset): """Return the actual size allocated for the request in megabytes.""" # if we have a preexisting size, use it if self.preexist and self.preexist_size: totalspace = lvm.clampPVSize(self.preexist_size, self.pesize) log.debug("using preexisting size of %s for volume group %s" % (self.preexist_size, self.volumeGroupName)) else: totalspace = 0 log.debug("no preexisting size for volume group %s" % (self.volumeGroupName)) for pvid in self.physicalVolumes: pvreq = partitions.getRequestByID(pvid) size = pvreq.getActualSize(partitions, diskset) clamped = lvm.clampPVSize(size, self.pesize) if long(size) == clamped: # If clamping reserves only less than 1MB for lvm metadata, # reserve one more PE. clamped = clamped - (self.pesize / 1024) log.debug(" got pv.size of %s, clamped to %s" % (size,clamped)) totalspace = totalspace + clamped log.debug(" total space: %s" % (totalspace,)) return totalspace
def getSmallestPVSize(self): """ finds the smallest PV and returns its size in MB """ first = 1 pvlist = self.getSelectedPhysicalVolumes(self.lvmlist.get_model()) for id in pvlist: try: pesize = int(self.peCombo.get_active_value()) except: pesize = 32768 pvreq = self.partitions.getRequestByID(id) pvsize = pvreq.getActualSize(self.partitions, self.diskset) pvsize = lvm.clampPVSize(pvsize, pesize) - (pesize / 1024) if first: minpvsize = pvsize first = 0 else: minpvsize = min(pvsize, minpvsize) return minpvsize
def getSmallestPVSize(self): """ finds the smallest PV and returns its size in MB """ first = 1 pvlist = self.getSelectedPhysicalVolumes(self.lvmlist.get_model()) for id in pvlist: try: pesize = int(self.peCombo.get_active_value()) except: pesize = 32768 pvreq = self.partitions.getRequestByID(id) pvsize = pvreq.getActualSize(self.partitions, self.diskset) pvsize = lvm.clampPVSize(pvsize, pesize) - (pesize/1024) if first: minpvsize = pvsize first = 0 else: minpvsize = min(pvsize, minpvsize) return minpvsize
def createAllowedLvmPartitionsList(self, alllvmparts, reqlvmpart, partitions, preexist=0): store = gtk.TreeStore(gobject.TYPE_BOOLEAN, gobject.TYPE_STRING, gobject.TYPE_STRING) partlist = WideCheckList(2, store, self.clickCB) sw = gtk.ScrolledWindow() sw.add(partlist) sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) sw.set_shadow_type(gtk.SHADOW_IN) for part in alllvmparts: uid = part[0] request = partitions.getRequestByID(uid) if request.type != REQUEST_RAID: partname = "%s" % (request.device, ) else: partname = "md%d" % (request.raidminor, ) size = request.getActualSize(partitions, self.diskset) used = part[2] # clip size to current PE pesize = int(self.peCombo.get_active_value()) size = lvm.clampPVSize(size, pesize) partsize = "%10.2f MB" % size if used or not reqlvmpart: selected = 1 else: selected = 0 if preexist == 0 or selected == 1: partlist.append_row((partname, partsize), selected) return (partlist, sw)
def updateAllowedLvmPartitionsList(self, alllvmparts, partitions, partlist): """ update sizes in pv list alllvmparts - list of pv from partitions.getAvailLVMPartitions partitions - object holding all partition requests partlist - the checklist containing pv list """ row = 0 for part in alllvmparts: uid = part[0] request = partitions.getRequestByID(uid) size = request.getActualSize(partitions, self.diskset) # clip size to current PE pesize = int(self.peCombo.get_active_value()) size = lvm.clampPVSize(size, pesize) partsize = "%10.2f MB" % size iter = partlist.store.get_iter((int(row),)) partlist.store.set_value(iter, 2, partsize) row = row + 1
def updateAllowedLvmPartitionsList(self, alllvmparts, partitions, partlist): """ update sizes in pv list alllvmparts - list of pv from partitions.getAvailLVMPartitions partitions - object holding all partition requests partlist - the checklist containing pv list """ row = 0 for part in alllvmparts: uid = part[0] request = partitions.getRequestByID(uid) size = request.getActualSize(partitions, self.diskset) # clip size to current PE pesize = int(self.peCombo.get_active_value()) size = lvm.clampPVSize(size, pesize) partsize = "%10.2f MB" % size iter = partlist.store.get_iter((int(row), )) partlist.store.set_value(iter, 2, partsize) row = row + 1
def createAllowedLvmPartitionsList(self, alllvmparts, reqlvmpart, partitions, preexist = 0): store = gtk.TreeStore(gobject.TYPE_BOOLEAN, gobject.TYPE_STRING, gobject.TYPE_STRING) partlist = WideCheckList(2, store, self.clickCB) sw = gtk.ScrolledWindow() sw.add(partlist) sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) sw.set_shadow_type(gtk.SHADOW_IN) for part in alllvmparts: uid = part[0] request = partitions.getRequestByID(uid) if request.type != REQUEST_RAID: partname = "%s" % (request.device,) else: partname = "md%d" % (request.raidminor,) size = request.getActualSize (partitions, self.diskset) used = part[2] # clip size to current PE pesize = int(self.peCombo.get_active_value()) size = lvm.clampPVSize(size, pesize) partsize = "%10.2f MB" % size if used or not reqlvmpart: selected = 1 else: selected = 0 if preexist == 0 or selected == 1: partlist.append_row((partname, partsize), selected) return (partlist, sw)
def peChangeCB(self, widget, peOption): """ handle changes in the Physical Extent option menu widget - menu item which was activated peOption - the Option menu containing the items. The data value for "lastval" is the previous PE value. """ curval = widget.get_data("value") lastval = peOption.get_data("lastpe") lastidx = peOption.get_data("lastidx") # see if PE is too large compared to smallest PV # remember PE is in KB, PV size is in MB maxpvsize = self.getSmallestPVSize() if curval > maxpvsize * 1024: self.intf.messageWindow( _("Not enough space"), _("The physical extent size cannot be " "changed because the value selected " "(%10.2f MB) is larger than the smallest " "physical volume (%10.2f MB) in the " "volume group.") % (curval / 1024.0, maxpvsize), custom_icon="error") peOption.set_history(lastidx) return 0 # see if new PE will make any PV useless due to overhead if lvm.clampPVSize(maxpvsize, curval) * 1024 < curval: self.intf.messageWindow(_("Not enough space"), _("The physical extent size cannot be " "changed because the value selected " "(%10.2f MB) is too large compared " "to the size of the " "smallest physical volume " "(%10.2f MB) in the " "volume group.") % (curval / 1024.0, maxpvsize), custom_icon="error") peOption.set_history(lastidx) return 0 if self.getPVWastedRatio(curval) > 0.10: rc = self.intf.messageWindow( _("Too small"), _("This change in the value of the " "physical extent will waste " "substantial space on one or more " "of the physical volumes in the " "volume group."), type="custom", custom_icon="error", custom_buttons=["gtk-cancel", _("C_ontinue")]) if not rc: peOption.set_history(lastidx) return 0 # now see if we need to fixup effect PV and LV sizes based on PE if curval > lastval: rc = self.reclampLV(curval) if not rc: peOption.set_history(lastidx) return 0 else: self.updateLogVolStore() else: maxlv = lvm.getMaxLVSize(curval) for lv in self.logvolreqs: lvsize = lv.getActualSize(self.partitions, self.diskset) if lvsize > maxlv: self.intf.messageWindow(_("Not enough space"), _("The physical extent size " "cannot be changed because the " "resulting maximum logical " "volume size (%10.2f MB) is " "smaller " "than one or more of the " "currently defined logical " "volumes.") % (maxlv, ), custom_icon="error") peOption.set_history(lastidx) return 0 peOption.set_data("lastpe", curval) peOption.set_data("lastidx", peOption.get_history()) self.updateAllowedLvmPartitionsList(self.availlvmparts, self.partitions, self.lvmlist) self.updateVGSpaceLabels()
def peChangeCB(self, widget, *args): """ handle changes in the Physical Extent option menu widget - menu item which was activated peOption - the Option menu containing the items. The data value for "lastval" is the previous PE value. """ curval = int(widget.get_active_value()) lastval = widget.get_data("lastpe") lastidx = widget.get_data("lastidx") # see if PE is too large compared to smallest PV # remember PE is in KB, PV size is in MB maxpvsize = self.getSmallestPVSize() if curval > maxpvsize * 1024: self.intf.messageWindow(_("Not enough space"), _("The physical extent size cannot be " "changed because the value selected " "(%10.2f MB) is larger than the smallest " "physical volume (%10.2f MB) in the " "volume group.") % (curval/1024.0, maxpvsize), custom_icon="error") widget.set_active(lastidx) return 0 # see if new PE will make any PV useless due to overhead if lvm.clampPVSize(maxpvsize, curval) * 1024 < curval: self.intf.messageWindow(_("Not enough space"), _("The physical extent size cannot be " "changed because the value selected " "(%10.2f MB) is too large compared " "to the size of the " "smallest physical volume " "(%10.2f MB) in the " "volume group.") % (curval/1024.0, maxpvsize), custom_icon="error") widget.set_active(lastidx) return 0 if self.getPVWastedRatio(curval) > 0.10: rc = self.intf.messageWindow(_("Too small"), _("This change in the value of the " "physical extent will waste " "substantial space on one or more " "of the physical volumes in the " "volume group."), type="custom", custom_icon="error", custom_buttons=["gtk-cancel", _("C_ontinue")]) if not rc: widget.set_active(lastidx) return 0 # now see if we need to fixup effect PV and LV sizes based on PE if curval > lastval: rc = self.reclampLV(lastval, curval) if not rc: widget.set_active(lastidx) return 0 else: self.updateLogVolStore() else: maxlv = lvm.getMaxLVSize(curval) for lv in self.logvolreqs: lvsize = lv.getActualSize(self.partitions, self.diskset, pesize=lastval) if lvsize > maxlv: self.intf.messageWindow(_("Not enough space"), _("The physical extent size " "cannot be changed because the " "resulting maximum logical " "volume size (%10.2f MB) is " "smaller " "than one or more of the " "currently defined logical " "volumes.") % (maxlv,), custom_icon="error") widget.set_active(lastidx) return 0 widget.set_data("lastpe", curval) widget.set_data("lastidx", widget.get_active()) self.updateAllowedLvmPartitionsList(self.availlvmparts, self.partitions, self.lvmlist) self.updateVGSpaceLabels()