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 create(cls, sdUUID, domainName, domClass, vgUUID, storageType, version): """ Create new storage domain 'sdUUID' - Storage Domain UUID 'domainName' - storage domain name 'domClass' - Data/Iso 'vgUUID' - volume group UUID 'storageType' - NFS_DOMAIN, LOCALFS_DOMAIN, &etc. 'version' - DOMAIN_VERSIONS """ cls.log.info("sdUUID=%s domainName=%s domClass=%s vgUUID=%s " "storageType=%s version=%s", sdUUID, domainName, domClass, vgUUID, storageType, version) if not misc.isAscii(domainName) and not sd.supportsUnicode(version): raise se.UnicodeArgumentException() if len(domainName) > sd.MAX_DOMAIN_DESCRIPTION_SIZE: raise se.StorageDomainDescriptionTooLongError() sd.validateDomainVersion(version) vg = lvm.getVGbyUUID(vgUUID) vgName = vg.name if set((STORAGE_UNREADY_DOMAIN_TAG,)) != set(vg.tags): raise se.VolumeGroupHasDomainTag(vgUUID) try: lvm.getLV(vgName) raise se.StorageDomainNotEmpty(vgUUID) except se.LogicalVolumeDoesNotExistError: pass numOfPVs = len(lvm.listPVNames(vgName)) if version in VERS_METADATA_LV and numOfPVs > MAX_PVS: cls.log.debug("%d > %d", numOfPVs, MAX_PVS) raise se.StorageDomainIsMadeFromTooManyPVs() # Create metadata service volume metasize = cls.metaSize(vgName) lvm.createLV(vgName, sd.METADATA, "%s" % (metasize)) # Create the mapping right now so the index 0 is guaranteed # to belong to the metadata volume. Since the metadata is at # least SDMETADATA/METASIZE units, we know we can use the first # SDMETADATA bytes of the metadata volume for the SD metadata. # pass metadata's dev to ensure it is the first mapping mapping = cls.getMetaDataMapping(vgName) # Create the rest of the BlockSD internal volumes lvm.createLV(vgName, sd.LEASES, sd.LEASES_SIZE) lvm.createLV(vgName, sd.IDS, sd.IDS_SIZE) lvm.createLV(vgName, sd.INBOX, sd.INBOX_SIZE) lvm.createLV(vgName, sd.OUTBOX, sd.OUTBOX_SIZE) lvm.createLV(vgName, MASTERLV, MASTERLV_SIZE) # Create VMS file system _createVMSfs(os.path.join("/dev", vgName, MASTERLV)) lvm.deactivateLVs(vgName, MASTERLV) path = lvm.lvPath(vgName, sd.METADATA) # Zero out the metadata and special volumes before use try: misc.ddCopy("/dev/zero", path, RESERVED_METADATA_SIZE) path = lvm.lvPath(vgName, sd.INBOX) misc.ddCopy("/dev/zero", path, RESERVED_MAILBOX_SIZE) path = lvm.lvPath(vgName, sd.OUTBOX) misc.ddCopy("/dev/zero", path, RESERVED_MAILBOX_SIZE) except utils.ActionStopped: raise except se.StorageException: raise se.VolumesZeroingError(path) if version in VERS_METADATA_LV: md = LvBasedSDMetadata(vgName, sd.METADATA) elif version in VERS_METADATA_TAG: md = TagBasedSDMetadata(vgName) logBlkSize, phyBlkSize = lvm.getVGBlockSizes(vgName) # create domain metadata # FIXME : This is 99% like the metadata in file SD # Do we really need to keep the VGUUID? # no one reads it from here anyway initialMetadata = { sd.DMDK_VERSION: version, sd.DMDK_SDUUID: sdUUID, sd.DMDK_TYPE: storageType, sd.DMDK_CLASS: domClass, sd.DMDK_DESCRIPTION: domainName, sd.DMDK_ROLE: sd.REGULAR_DOMAIN, sd.DMDK_POOLS: [], sd.DMDK_LOCK_POLICY: '', sd.DMDK_LOCK_RENEWAL_INTERVAL_SEC: sd.DEFAULT_LEASE_PARAMS[ sd.DMDK_LOCK_RENEWAL_INTERVAL_SEC], sd.DMDK_LEASE_TIME_SEC: sd.DEFAULT_LEASE_PARAMS[ sd.DMDK_LEASE_TIME_SEC], sd.DMDK_IO_OP_TIMEOUT_SEC: sd.DEFAULT_LEASE_PARAMS[ sd.DMDK_IO_OP_TIMEOUT_SEC], sd.DMDK_LEASE_RETRIES: sd.DEFAULT_LEASE_PARAMS[ sd.DMDK_LEASE_RETRIES], DMDK_VGUUID: vgUUID, DMDK_LOGBLKSIZE: logBlkSize, DMDK_PHYBLKSIZE: phyBlkSize, } initialMetadata.update(mapping) md.update(initialMetadata) # Mark VG with Storage Domain Tag try: lvm.replaceVGTag(vgName, STORAGE_UNREADY_DOMAIN_TAG, STORAGE_DOMAIN_TAG) except se.StorageException: raise se.VolumeGroupUninitialized(vgName) bsd = BlockStorageDomain(sdUUID) bsd.initSPMlease() return bsd
def create(cls, sdUUID, domainName, domClass, vgUUID, storageType, version): """ Create new storage domain 'sdUUID' - Storage Domain UUID 'domainName' - storage domain name 'vgUUID' - volume group UUID 'domClass' - Data/Iso """ cls.log.info("sdUUID=%s domainName=%s domClass=%s vgUUID=%s " "storageType=%s version=%s", sdUUID, domainName, domClass, vgUUID, storageType, version) if len(domainName) > sd.MAX_DOMAIN_DESCRIPTION_SIZE: raise se.StorageDomainDescriptionTooLongError() sd.validateDomainVersion(version) vg = lvm.getVGbyUUID(vgUUID) vgName = vg.name if set((STORAGE_UNREADY_DOMAIN_TAG,)) != set(vg.tags): raise se.VolumeGroupHasDomainTag(vgUUID) try: lvm.getLV(vgName) raise se.StorageDomainNotEmpty(vgUUID) except se.LogicalVolumeDoesNotExistError: pass numOfPVs = len(lvm.listPVNames(vgName)) if version in VERS_METADATA_LV and numOfPVs > MAX_PVS: cls.log.debug("%d > %d" , numOfPVs, MAX_PVS) raise se.StorageDomainIsMadeFromTooManyPVs() # Set the name of the VG to be the same as sdUUID if vgName != sdUUID: lvm.renameVG(vgName, sdUUID) vgName = sdUUID # Create metadata service volume metasize = cls.metaSize(vgName) lvm.createLV(vgName, sd.METADATA, "%s" % (metasize)) # Create the mapping right now so the index 0 is guaranteed # to belong to the metadata volume. Since the metadata is at # least SDMETADATA/METASIZE units, we know we can use the first # SDMETADATA bytes of the metadata volume for the SD metadata. # pass metadata's dev to ensure it is the first mapping mapping = cls.getMetaDataMapping(vgName) # Create the rest of the BlockSD internal volumes lvm.createLV(vgName, sd.LEASES, sd.LEASES_SIZE) lvm.createLV(vgName, sd.IDS, sd.IDS_SIZE) lvm.createLV(vgName, sd.INBOX, sd.INBOX_SIZE) lvm.createLV(vgName, sd.OUTBOX, sd.OUTBOX_SIZE) lvm.createLV(vgName, MASTERLV, MASTERLV_SIZE) # Create VMS file system _createVMSfs(os.path.join("/dev", vgName, MASTERLV)) lvm.deactivateLVs(vgName, MASTERLV) path = lvm.lvPath(vgName, sd.METADATA) # Zero out the metadata and special volumes before use try: misc.ddCopy("/dev/zero", path, RESERVED_METADATA_SIZE) path = lvm.lvPath(vgName, sd.INBOX) misc.ddCopy("/dev/zero", path, RESERVED_MAILBOX_SIZE) path = lvm.lvPath(vgName, sd.OUTBOX) misc.ddCopy("/dev/zero", path, RESERVED_MAILBOX_SIZE) except se.ActionStopped, e: raise e
def create(cls, sdUUID, domainName, domClass, vgUUID, storageType, version): """ Create new storage domain 'sdUUID' - Storage Domain UUID 'domainName' - storage domain name 'domClass' - Data/Iso 'vgUUID' - volume group UUID 'storageType' - NFS_DOMAIN, LOCALFS_DOMAIN, &etc. 'version' - DOMAIN_VERSIONS """ cls.log.info("sdUUID=%s domainName=%s domClass=%s vgUUID=%s " "storageType=%s version=%s", sdUUID, domainName, domClass, vgUUID, storageType, version) if not misc.isAscii(domainName) and not sd.supportsUnicode(version): raise se.UnicodeArgumentException() if len(domainName) > sd.MAX_DOMAIN_DESCRIPTION_SIZE: raise se.StorageDomainDescriptionTooLongError() sd.validateDomainVersion(version) vg = lvm.getVGbyUUID(vgUUID) vgName = vg.name if set((STORAGE_UNREADY_DOMAIN_TAG,)) != set(vg.tags): raise se.VolumeGroupHasDomainTag(vgUUID) try: lvm.getLV(vgName) raise se.StorageDomainNotEmpty(vgUUID) except se.LogicalVolumeDoesNotExistError: pass numOfPVs = len(lvm.listPVNames(vgName)) if version in VERS_METADATA_LV and numOfPVs > MAX_PVS: cls.log.debug("%d > %d", numOfPVs, MAX_PVS) raise se.StorageDomainIsMadeFromTooManyPVs() # Create metadata service volume metasize = cls.metaSize(vgName) lvm.createLV(vgName, sd.METADATA, "%s" % (metasize)) # Create the mapping right now so the index 0 is guaranteed # to belong to the metadata volume. Since the metadata is at # least SDMETADATA/METASIZE units, we know we can use the first # SDMETADATA bytes of the metadata volume for the SD metadata. # pass metadata's dev to ensure it is the first mapping mapping = cls.getMetaDataMapping(vgName) # Create the rest of the BlockSD internal volumes for metaFile, metaSizeMb in sd.SPECIAL_VOLUME_SIZES_MIB.iteritems(): lvm.createLV(vgName, metaFile, metaSizeMb) lvm.createLV(vgName, MASTERLV, MASTERLV_SIZE) # Create VMS file system _createVMSfs(os.path.join("/dev", vgName, MASTERLV)) lvm.deactivateLVs(vgName, MASTERLV) path = lvm.lvPath(vgName, sd.METADATA) # Zero out the metadata and special volumes before use try: misc.ddCopy("/dev/zero", path, RESERVED_METADATA_SIZE) path = lvm.lvPath(vgName, sd.INBOX) misc.ddCopy("/dev/zero", path, RESERVED_MAILBOX_SIZE) path = lvm.lvPath(vgName, sd.OUTBOX) misc.ddCopy("/dev/zero", path, RESERVED_MAILBOX_SIZE) except utils.ActionStopped: raise except se.StorageException: raise se.VolumesZeroingError(path) if version in VERS_METADATA_LV: md = LvBasedSDMetadata(vgName, sd.METADATA) elif version in VERS_METADATA_TAG: md = TagBasedSDMetadata(vgName) logBlkSize, phyBlkSize = lvm.getVGBlockSizes(vgName) # create domain metadata # FIXME : This is 99% like the metadata in file SD # Do we really need to keep the VGUUID? # no one reads it from here anyway initialMetadata = { sd.DMDK_VERSION: version, sd.DMDK_SDUUID: sdUUID, sd.DMDK_TYPE: storageType, sd.DMDK_CLASS: domClass, sd.DMDK_DESCRIPTION: domainName, sd.DMDK_ROLE: sd.REGULAR_DOMAIN, sd.DMDK_POOLS: [], sd.DMDK_LOCK_POLICY: '', sd.DMDK_LOCK_RENEWAL_INTERVAL_SEC: sd.DEFAULT_LEASE_PARAMS[ sd.DMDK_LOCK_RENEWAL_INTERVAL_SEC], sd.DMDK_LEASE_TIME_SEC: sd.DEFAULT_LEASE_PARAMS[ sd.DMDK_LEASE_TIME_SEC], sd.DMDK_IO_OP_TIMEOUT_SEC: sd.DEFAULT_LEASE_PARAMS[ sd.DMDK_IO_OP_TIMEOUT_SEC], sd.DMDK_LEASE_RETRIES: sd.DEFAULT_LEASE_PARAMS[ sd.DMDK_LEASE_RETRIES], DMDK_VGUUID: vgUUID, DMDK_LOGBLKSIZE: logBlkSize, DMDK_PHYBLKSIZE: phyBlkSize, } initialMetadata.update(mapping) md.update(initialMetadata) # Mark VG with Storage Domain Tag try: lvm.replaceVGTag(vgName, STORAGE_UNREADY_DOMAIN_TAG, STORAGE_DOMAIN_TAG) except se.StorageException: raise se.VolumeGroupUninitialized(vgName) bsd = BlockStorageDomain(sdUUID) bsd.initSPMlease() return bsd
def create(cls, sdUUID, domainName, domClass, vgUUID, storageType, version): """ Create new storage domain 'sdUUID' - Storage Domain UUID 'domainName' - storage domain name 'vgUUID' - volume group UUID 'domClass' - Data/Iso """ cls.log.info( "sdUUID=%s domainName=%s domClass=%s vgUUID=%s " "storageType=%s version=%s", sdUUID, domainName, domClass, vgUUID, storageType, version) if len(domainName) > sd.MAX_DOMAIN_DESCRIPTION_SIZE: raise se.StorageDomainDescriptionTooLongError() sd.validateDomainVersion(version) vg = lvm.getVGbyUUID(vgUUID) vgName = vg.name if set((STORAGE_UNREADY_DOMAIN_TAG, )) != set(vg.tags): raise se.VolumeGroupHasDomainTag(vgUUID) try: lvm.getLV(vgName) raise se.StorageDomainNotEmpty(vgUUID) except se.LogicalVolumeDoesNotExistError: pass numOfPVs = len(lvm.listPVNames(vgName)) if version in VERS_METADATA_LV and numOfPVs > MAX_PVS: cls.log.debug("%d > %d", numOfPVs, MAX_PVS) raise se.StorageDomainIsMadeFromTooManyPVs() # Set the name of the VG to be the same as sdUUID if vgName != sdUUID: lvm.renameVG(vgName, sdUUID) vgName = sdUUID # Create metadata service volume metasize = cls.metaSize(vgName) lvm.createLV(vgName, sd.METADATA, "%s" % (metasize)) # Create the mapping right now so the index 0 is guaranteed # to belong to the metadata volume. Since the metadata is at # least SDMETADATA/METASIZE units, we know we can use the first # SDMETADATA bytes of the metadata volume for the SD metadata. # pass metadata's dev to ensure it is the first mapping mapping = cls.getMetaDataMapping(vgName) # Create the rest of the BlockSD internal volumes lvm.createLV(vgName, sd.LEASES, sd.LEASES_SIZE) lvm.createLV(vgName, sd.IDS, sd.IDS_SIZE) lvm.createLV(vgName, sd.INBOX, sd.INBOX_SIZE) lvm.createLV(vgName, sd.OUTBOX, sd.OUTBOX_SIZE) lvm.createLV(vgName, MASTERLV, MASTERLV_SIZE) # Create VMS file system _createVMSfs(os.path.join("/dev", vgName, MASTERLV)) lvm.deactivateLVs(vgName, MASTERLV) path = lvm.lvPath(vgName, sd.METADATA) # Zero out the metadata and special volumes before use try: misc.ddCopy("/dev/zero", path, RESERVED_METADATA_SIZE) path = lvm.lvPath(vgName, sd.INBOX) misc.ddCopy("/dev/zero", path, RESERVED_MAILBOX_SIZE) path = lvm.lvPath(vgName, sd.OUTBOX) misc.ddCopy("/dev/zero", path, RESERVED_MAILBOX_SIZE) except se.ActionStopped, e: raise e