def checkAllVHD(sr_uuid): activated_list = [] vhd_trees = [] VHDs_total = 0 vg_name = lvhdutil.VG_PREFIX + sr_uuid pattern = "%s*" % lvhdutil.LV_PREFIX[vhdutil.VDI_TYPE_VHD] # Do a vhd scan and gets all the VHDs vhds = vhdutil.getAllVHDs(pattern, lvhdutil.extractUuid, vg_name) VHDs_total = len(vhds) # Build VHD chain, that way it will be easier to activate all the VHDs # that belong to one chain, do check on the same and then deactivate for vhd in vhds: if vhds[vhd].parentUuid: parent_VHD_info = vhds.get(vhds[vhd].parentUuid) if not hasattr(parent_VHD_info, 'children'): parent_VHD_info.children = [] parent_VHD_info.children.append(vhds[vhd]) else: vhd_trees.append(vhds[vhd]) # If needed, activate VHDs belonging to each VDI chain, do a check on # all VHDs and then set the state back. for vhd_chain in vhd_trees: activated_list = activateVdiChainAndCheck(vhd_chain, vg_name) #Deactivate the LVs, states are maintained by Refcounter for item in activated_list: deactivateVdi(sr_uuid, item[0], item[1]) print("VHD check passed on %d, failed on %d, not run on %d" % (VHDs_passed, VHDs_failed, VHDs_total - (VHDs_passed + VHDs_failed)))
def _loadvdis(self): if self.vdis: return pattern = os.path.join(self.path, "*%s" % vhdutil.FILE_EXTN_VHD) try: self.vhds = vhdutil.getAllVHDs(pattern, FileVDI.extractUuid) except util.CommandException, inst: raise xs_errors.XenError("SRScan", opterr="error VHD-scanning " "path %s (%s)" % (self.path, inst))
def _loadvdis(self): if self.vdis: return pattern = os.path.join(self.path, "*%s" % vhdutil.FILE_EXTN_VHD) try: self.vhds = vhdutil.getAllVHDs(pattern, FileVDI.extractUuid) except util.CommandException, inst: raise xs_errors.XenError('SRScan', opterr="error VHD-scanning " \ "path %s (%s)" % (self.path, inst))
def _loadvdis(self): if self.vdis: return pattern = os.path.join(self.path, "*.%s" % SR.DEFAULT_TAP) try: self.vhds = vhdutil.getAllVHDs(pattern, FileVDI.extractUuid) except util.CommandException, inst: raise xs_errors.XenError('SRScan', opterr="error VHD-scanning " \ "path %s (%s)" % (self.path, inst))
def getVDIInfo(lvmCache): """Load VDI info (both LV and if the VDI is not raw, VHD info)""" vdis = {} lvs = getLVInfo(lvmCache) haveVHDs = False for uuid, lvInfo in lvs.iteritems(): if lvInfo.vdiType == vhdutil.VDI_TYPE_VHD: haveVHDs = True vdiInfo = VDIInfo(uuid) vdiInfo.vdiType = lvInfo.vdiType vdiInfo.lvName = lvInfo.name vdiInfo.sizeLV = lvInfo.size vdiInfo.sizeVirt = lvInfo.size vdiInfo.lvActive = lvInfo.active vdiInfo.lvOpen = lvInfo.open vdiInfo.lvReadonly = lvInfo.readonly vdiInfo.hidden = lvInfo.hidden vdis[uuid] = vdiInfo if haveVHDs: pattern = "%s*" % LV_PREFIX[vhdutil.VDI_TYPE_VHD] vhds = vhdutil.getAllVHDs(pattern, extractUuid, lvmCache.vgName) uuids = vdis.keys() for uuid in uuids: vdi = vdis[uuid] if vdi.vdiType == vhdutil.VDI_TYPE_VHD: if not vhds.get(uuid): lvmCache.refresh() if lvmCache.checkLV(vdi.lvName): util.SMlog("*** VHD info missing: %s" % uuid) vdis[uuid].scanError = True else: util.SMlog("LV disappeared since last scan: %s" % uuid) del vdis[uuid] elif vhds[uuid].error: util.SMlog("*** vhd-scan error: %s" % uuid) vdis[uuid].scanError = True else: vdis[uuid].sizeVirt = vhds[uuid].sizeVirt vdis[uuid].parentUuid = vhds[uuid].parentUuid vdis[uuid].hidden = vhds[uuid].hidden return vdis
def _loadvdis(self): if self.vdis: return pattern = os.path.join(self.path, "*%s" % vhdutil.FILE_EXTN_VHD) try: self.vhds = vhdutil.getAllVHDs(pattern, FileVDI.extractUuid) except util.CommandException as inst: raise xs_errors.XenError('SRScan', opterr="error VHD-scanning " \ "path %s (%s)" % (self.path, inst)) try: list_vhds = [ FileVDI.extractUuid(v) for v in util.ioretry(lambda: glob.glob(pattern)) ] if len(self.vhds) != len(list_vhds): util.SMlog("VHD scan returns %d VHDs: %s" % (len(self.vhds), sorted(list(self.vhds)))) util.SMlog("VHD list returns %d VHDs: %s" % (len(list_vhds), sorted(list_vhds))) except: pass for uuid in self.vhds.iterkeys(): if self.vhds[uuid].error: raise xs_errors.XenError('SRScan', opterr='uuid=%s' % uuid) self.vdis[uuid] = self.vdi(uuid, True) # Get the key hash of any encrypted VDIs: vhd_path = os.path.join(self.path, self.vhds[uuid].path) key_hash = vhdutil.getKeyHash(vhd_path) self.vdis[uuid].sm_config_override['key_hash'] = key_hash # raw VDIs and CBT log files files = util.ioretry(lambda: util.listdir(self.path)) for fn in files: if fn.endswith(vhdutil.FILE_EXTN_RAW): uuid = fn[:-(len(vhdutil.FILE_EXTN_RAW))] self.vdis[uuid] = self.vdi(uuid, True) elif fn.endswith(CBTLOG_TAG): cbt_uuid = fn.split(".")[0] # If an associated disk exists, update CBT status # else create new VDI of type cbt_metadata if cbt_uuid in self.vdis: self.vdis[cbt_uuid].cbt_enabled = True else: new_vdi = self.vdi(cbt_uuid) new_vdi.ty = "cbt_metadata" new_vdi.cbt_enabled = True self.vdis[cbt_uuid] = new_vdi # Mark parent VDIs as Read-only and generate virtual allocation self.virtual_allocation = 0 for uuid, vdi in self.vdis.iteritems(): if vdi.parent: if vdi.parent in self.vdis: self.vdis[vdi.parent].read_only = True if vdi.parent in geneology: geneology[vdi.parent].append(uuid) else: geneology[vdi.parent] = [uuid] if not vdi.hidden: self.virtual_allocation += (vdi.size) # now remove all hidden leaf nodes from self.vdis so that they are not # introduced into the Agent DB when SR is synchronized. With the # asynchronous GC, a deleted VDI might stay around until the next # SR.scan, so if we don't ignore hidden leaves we would pick up # freshly-deleted VDIs as newly-added VDIs for uuid in self.vdis.keys(): if uuid not in geneology and self.vdis[uuid].hidden: util.SMlog("Scan found hidden leaf (%s), ignoring" % uuid) del self.vdis[uuid]