def print_LUNs(self): self.LUNs = {} if os.path.exists(self.path): dom0_disks = util.dom0_disks() for file in util.listdir(self.path): if file.find("LUN") != -1 and file.find("_") == -1: vdi_path = os.path.join(self.path, file) if os.path.realpath(vdi_path) in dom0_disks: util.SMlog("Hide dom0 boot disk LUN") else: LUNid = file.replace("LUN", "") obj = self.vdi(self.uuid) obj._query(vdi_path, LUNid) self.LUNs[obj.uuid] = obj
def print_LUNs(self): self.LUNs = {} if os.path.exists(self.path): dom0_disks = util.dom0_disks() for file in util.listdir(self.path): if file.find("LUN") != -1 and file.find("_") == -1: vdi_path = os.path.join(self.path,file) if os.path.realpath(vdi_path) in dom0_disks: util.SMlog("Hide dom0 boot disk LUN") else: LUNid = file.replace("LUN","") obj = self.vdi(self.uuid) obj._query(vdi_path, LUNid) self.LUNs[obj.uuid] = obj
def block_setscheduler(self, dev): try: realdev = os.path.realpath(dev) disk = util.diskFromPartition(realdev) # the normal case: the sr default scheduler (typically noop), # potentially overridden by SR.other_config:scheduler other_config = self.session.xenapi.SR.get_other_config(self.sr_ref) sched = other_config.get('scheduler') if not sched: sched = self.sched # special case: CFQ if the underlying disk holds dom0's file systems. if disk in util.dom0_disks(): sched = 'cfq' util.SMlog("Block scheduler: %s (%s) wants %s" % (dev, disk, sched)) util.set_scheduler(realdev[5:], sched) except Exception, e: util.SMlog("Failed to set block scheduler on %s: %s" % (dev, e))
def refresh_scsi_channel(channel): DEV_WAIT = 5 util.SMlog("Refreshing channel %s" % channel) util.wait_for_path('/dev/disk/by-scsibus/*-%s*' % channel, DEV_WAIT) LUNs = glob.glob('/dev/disk/by-scsibus/*-%s*' % channel) try: rootdevs = util.dom0_disks() except: util.SMlog("Failed to query root disk, failing operation") return False # a) Find a LUN to issue a Query LUNs command li = [] Query = False for lun in LUNs: try: hbtl = lun.split('-')[-1] h = hbtl.split(':') l=util.pread2(["/usr/bin/sg_luns","-q",lun]).split('\n') li = [] for i in l: if len(i): li.append(int(i[0:4], 16)) util.SMlog("sg_luns query returned %s" % li) Query = True break except: pass if not Query: util.SMlog("Failed to detect or query LUN on Channel %s" % channel) return False # b) Remove stale LUNs current = glob.glob('/dev/disk/by-scsibus/*-%s:%s:%s*' % (h[0],h[1],h[2])) for cur in current: lunID = int(cur.split(':')[-1]) newhbtl = ['',h[0],h[1],h[2],str(lunID)] if os.path.realpath(cur) in rootdevs: # Don't touch the rootdev if lunID in li: li.remove(lunID) continue # Check if LUN is stale, and remove it if not lunID in li: util.SMlog("Stale LUN detected. Removing HBTL: %s" % newhbtl) scsi_dev_ctrl(newhbtl,"remove") util.wait_for_nopath(cur, DEV_WAIT) continue else: li.remove(lunID) # Query SCSIid, check it matches, if not, re-probe cur_SCSIid = os.path.basename(cur).split("-%s:%s:%s" % (h[0],h[1],h[2]))[0] real_SCSIid = getSCSIid(cur) if cur_SCSIid != real_SCSIid: util.SMlog("HBTL %s does not match, re-probing" % newhbtl) scsi_dev_ctrl(newhbtl,"remove") util.wait_for_nopath(cur, DEV_WAIT) scsi_dev_ctrl(newhbtl,"add") util.wait_for_path('/dev/disk/by-scsibus/%s-%s' % (real_SCSIid,hbtl), DEV_WAIT) pass # c) Probe for any LUNs that are not present in the system for l in li: newhbtl = ['',h[0],h[1],h[2],str(l)] util.SMlog("Probing new HBTL: %s" % newhbtl) scsi_dev_ctrl(newhbtl,"add") util.wait_for_path('/dev/disk/by-scsibus/*-%s' % hbtl, DEV_WAIT) return True
def refresh_scsi_channel(channel): DEV_WAIT = 5 util.SMlog("Refreshing channel %s" % channel) util.wait_for_path('/dev/disk/by-scsibus/*-%s*' % channel, DEV_WAIT) LUNs = glob.glob('/dev/disk/by-scsibus/*-%s*' % channel) try: rootdevs = util.dom0_disks() except: util.SMlog("Failed to query root disk, failing operation") return False # a) Find a LUN to issue a Query LUNs command li = [] Query = False for lun in LUNs: try: hbtl = lun.split('-')[-1] h = hbtl.split(':') l = util.pread2(["/usr/bin/sg_luns", "-q", lun]).split('\n') li = [] for i in l: if len(i): li.append(int(i[0:4], 16)) util.SMlog("sg_luns query returned %s" % li) Query = True break except: pass if not Query: util.SMlog("Failed to detect or query LUN on Channel %s" % channel) return False # b) Remove stale LUNs current = glob.glob('/dev/disk/by-scsibus/*-%s:%s:%s*' % (h[0], h[1], h[2])) for cur in current: lunID = int(cur.split(':')[-1]) newhbtl = ['', h[0], h[1], h[2], str(lunID)] if os.path.realpath(cur) in rootdevs: # Don't touch the rootdev if lunID in li: li.remove(lunID) continue # Check if LUN is stale, and remove it if not lunID in li: util.SMlog("Stale LUN detected. Removing HBTL: %s" % newhbtl) scsi_dev_ctrl(newhbtl, "remove") util.wait_for_nopath(cur, DEV_WAIT) continue else: li.remove(lunID) # Check if the device is still present if not os.path.exists(cur): continue # Query SCSIid, check it matches, if not, re-probe cur_SCSIid = os.path.basename(cur).split("-%s:%s:%s" % (h[0], h[1], h[2]))[0] real_SCSIid = getSCSIid(cur) if cur_SCSIid != real_SCSIid: util.SMlog("HBTL %s does not match, re-probing" % newhbtl) scsi_dev_ctrl(newhbtl, "remove") util.wait_for_nopath(cur, DEV_WAIT) scsi_dev_ctrl(newhbtl, "add") util.wait_for_path( '/dev/disk/by-scsibus/%s-%s' % (real_SCSIid, hbtl), DEV_WAIT) pass # c) Probe for any LUNs that are not present in the system for l in li: newhbtl = ['', h[0], h[1], h[2], str(l)] newhbtlstr = "%s:%s:%s:%s" % (h[0], h[1], h[2], str(l)) util.SMlog("Probing new HBTL: %s" % newhbtl) scsi_dev_ctrl(newhbtl, "add") util.wait_for_path('/dev/disk/by-scsibus/*-%s' % newhbtlstr, DEV_WAIT) return True