def getMetaDataMapping(cls, vgName, oldMapping={}): firstDev, firstExtent = lvm.getFirstExt(vgName, sd.METADATA) firstExtent = int(firstExtent) if firstExtent != 0: cls.log.error("INTERNAL: metadata ext is not 0") raise se.MetaDataMappingError("vg %s: metadata extent is not the " "first extent" % vgName) pvlist = list(lvm.listPVNames(vgName)) pvlist.remove(firstDev) pvlist.insert(0, firstDev) cls.log.info("Create: SORT MAPPING: %s" % pvlist) mapping = {} devNum = len(oldMapping) for dev in pvlist: knownDev = False for pvID, oldInfo in oldMapping.iteritems(): if os.path.basename(dev) == oldInfo["guid"]: mapping[pvID] = oldInfo knownDev = True break if knownDev: continue pv = lvm.getPV(dev) pvInfo = {} pvInfo["guid"] = os.path.basename(pv.name) pvInfo["uuid"] = pv.uuid # this is another trick, it's not the # the pestart value you expect, it's just # 0, always pvInfo["pestart"] = 0 pvInfo["pecount"] = pv.pe_count if devNum == 0: mapOffset = 0 else: prevDevNum = devNum - 1 try: prevInfo = mapping["PV%d" % (prevDevNum,)] except KeyError: prevInfo = oldMapping["PV%d" % (prevDevNum,)] mapOffset = int(prevInfo["mapoffset"]) + \ int(prevInfo["pecount"]) pvInfo["mapoffset"] = mapOffset mapping["PV%d" % devNum] = pvInfo devNum += 1 return mapping
def getVolumeMetadataOffsetFromPvMapping(self, vol_name): dev, ext = lvm.getFirstExt(self.sdUUID, vol_name) self.log.debug("vol %s dev %s ext %s" % (vol_name, dev, ext)) for pv in self.readMetadataMapping().values(): self.log.debug("MAPOFFSET: pv %s -- dev %s ext %s" % (pv, dev, ext)) pestart = int(pv["pestart"]) pecount = int(pv["pecount"]) if (os.path.basename(dev) == pv["guid"] and int(ext) in range(pestart, pestart + pecount)): offs = int(ext) + int(pv["mapoffset"]) if offs < SD_METADATA_SIZE/sd.METASIZE: raise se.MetaDataMappingError("domain %s: vol %s MD offset %s is bad - will overwrite SD's MD" % (self.sdUUID, vol_name, offs)) return offs raise se.MetaDataMappingError("domain %s: can't map PV %s ext %s" % (self.sdUUID, dev, ext))
def getVolumeMetadataOffsetFromPvMapping(self, vol_name): dev, ext = lvm.getFirstExt(self.sdUUID, vol_name) self.log.debug("vol %s dev %s ext %s" % (vol_name, dev, ext)) for pv in self.readMetadataMapping().values(): self.log.debug("MAPOFFSET: pv %s -- dev %s ext %s" % (pv, dev, ext)) pestart = int(pv["pestart"]) pecount = int(pv["pecount"]) if (os.path.basename(dev) == pv["guid"] and int(ext) in range(pestart, pestart + pecount)): offs = int(ext) + int(pv["mapoffset"]) if offs < SD_METADATA_SIZE / sd.METASIZE: raise se.MetaDataMappingError( "domain %s: vol %s MD offset %s is bad - will " "overwrite SD's MD" % (self.sdUUID, vol_name, offs)) return offs raise se.MetaDataMappingError("domain %s: can't map PV %s ext %s" % (self.sdUUID, dev, ext))