示例#1
0
    def probe(self):
        if self.mpath == "true" and self.dconf.has_key('SCSIid'):
# When multipathing is enabled, since we don't refcount the multipath maps,
# we should not attempt to do the iscsi.attach/detach when the map is already present,
# as this will remove it (which may well be in use).
            maps = []
            try:
                maps = mpath_cli.list_maps()
            except:
                pass

            if self.dconf['SCSIid'] in maps:
                if (mpp_luncheck.is_RdacLun(self.dconf['SCSIid'])):
                    mpath_cli.remove_map(self.dconf['SCSIid'])
                else:
                    raise xs_errors.XenError('SRInUse')
            else:
                if (mpp_luncheck.is_RdacLun(self.dconf['SCSIid'])):
                    link=glob.glob('/dev/disk/mpInuse/%s-*' % self.dconf['SCSIid'])
                    if (len(link)):
                        raise xs_errors.XenError('SRInUse')

            self.mpathmodule.refresh(self.SCSIid,0)

        try:
            self._pathrefresh(LVHDoHBASR)
            result = LVHDSR.LVHDSR.probe(self)
            if self.mpath == "true":
                self.mpathmodule.reset(self.SCSIid,True)
            return result
        except:
           if self.mpath == "true":
                self.mpathmodule.reset(self.SCSIid,True)
           raise
示例#2
0
    def probe(self):
        if self.mpath == "true" and self.dconf.has_key('SCSIid'):
            # When multipathing is enabled, since we don't refcount the multipath maps,
            # we should not attempt to do the iscsi.attach/detach when the map is already present,
            # as this will remove it (which may well be in use).
            maps = []
            try:
                maps = mpath_cli.list_maps()
            except:
                pass

            if self.dconf['SCSIid'] in maps:
                if (mpp_luncheck.is_RdacLun(self.dconf['SCSIid'])):
                    mpath_cli.remove_map(self.dconf['SCSIid'])
                else:
                    raise xs_errors.XenError('SRInUse')
            else:
                if (mpp_luncheck.is_RdacLun(self.dconf['SCSIid'])):
                    link = glob.glob('/dev/disk/mpInuse/%s-*' %
                                     self.dconf['SCSIid'])
                    if (len(link)):
                        raise xs_errors.XenError('SRInUse')

            self.mpathmodule.refresh(self.SCSIid, 0)

        try:
            self._pathrefresh(LVHDoHBASR)
            result = LVHDSR.LVHDSR.probe(self)
            if self.mpath == "true":
                self.mpathmodule.reset(self.SCSIid, True)
            return result
        except:
            if self.mpath == "true":
                self.mpathmodule.reset(self.SCSIid, True)
            raise
示例#3
0
    def _LUNprint(self, sr_uuid):
        if self.iscsi.attached:
            # Force a rescan on the bus.
            self.iscsi.refresh()


#            time.sleep(5)
# Now call attach (handles the refcounting + session activa)
        self.iscsi.attach(sr_uuid)

        util.SMlog("LUNprint: waiting for path: %s" % self.iscsi.path)
        if util.wait_for_path("%s/LUN*" % self.iscsi.path,
                              ISCSISR.MAX_TIMEOUT):
            try:
                adapter = self.iscsi.adapter[self.iscsi.address]
                util.SMlog("adapter=%s" % adapter)

                # find a scsi device on which to issue a report luns command:
                devs = glob.glob("%s/LUN*" % self.iscsi.path)
                sgdevs = []
                for i in devs:
                    sgdevs.append(int(i.split("LUN")[1]))
                sgdevs.sort()
                sgdev = "%s/LUN%d" % (self.iscsi.path, sgdevs[0])

                # issue a report luns:
                luns = util.pread2(["/usr/bin/sg_luns", "-q",
                                    sgdev]).split('\n')
                nluns = len(
                    luns) - 1  # remove the line relating to the final \n
                # check if the LUNs are MPP-RDAC Luns
                scsi_id = scsiutil.getSCSIid(sgdev)
                mpp_lun = False
                if (mpp_luncheck.is_RdacLun(scsi_id)):
                    mpp_lun = True
                    link = glob.glob('/dev/disk/by-scsibus/%s-*' % scsi_id)
                    mpp_adapter = link[0].split('/')[-1].split('-')[-1].split(
                        ':')[0]

                # make sure we've got that many sg devices present
                for i in range(0, 30):
                    luns = scsiutil._dosgscan()
                    sgdevs = filter(lambda r: r[1] == adapter, luns)
                    if mpp_lun:
                        sgdevs.extend(
                            filter(lambda r: r[1] == mpp_adapter, luns))
                    if len(sgdevs) >= nluns:
                        util.SMlog("Got all %d sg devices" % nluns)
                        break
                    else:
                        util.SMlog("Got %d sg devices - expecting %d" %
                                   (len(sgdevs), nluns))
                        time.sleep(1)

                util.pread2(["/sbin/udevsettle"])
            except:
                pass  # Make sure we don't break the probe...

        self.iscsi.print_LUNs()
        self.iscsi.detach(sr_uuid)
示例#4
0
    def probe(self):
        self.uuid = util.gen_uuid()

        # When multipathing is enabled, since we don't refcount the multipath maps,
        # we should not attempt to do the iscsi.attach/detach when the map is already present,
        # as this will remove it (which may well be in use).
        if self.mpath == 'true' and self.dconf.has_key('SCSIid'):
            maps = []
            mpp_lun = False
            try:
                if (mpp_luncheck.is_RdacLun(self.dconf['SCSIid'])):
                    mpp_lun = True
                    link = glob.glob('/dev/disk/mpInuse/%s-*' %
                                     self.dconf['SCSIid'])
                else:
                    maps = mpath_cli.list_maps()
            except:
                pass

            if (mpp_lun):
                if (len(link)):
                    raise xs_errors.XenError('SRInUse')
            else:
                if self.dconf['SCSIid'] in maps:
                    raise xs_errors.XenError('SRInUse')

        self.iscsi.attach(self.uuid)
        if not self.iscsi._attach_LUN_bySCSIid(self.SCSIid):
            util.SMlog("Unable to detect LUN")
            raise xs_errors.XenError('InvalidDev')
        self._pathrefresh(LVHDoISCSISR)
        out = LVHDSR.LVHDSR.probe(self)
        self.iscsi.detach(self.uuid)
        return out
示例#5
0
    def probe(self):
        self.uuid = util.gen_uuid()

# When multipathing is enabled, since we don't refcount the multipath maps,
# we should not attempt to do the iscsi.attach/detach when the map is already present,
# as this will remove it (which may well be in use).
        if self.mpath == 'true' and self.dconf.has_key('SCSIid'):
            maps = []
            mpp_lun = False
            try:
                if (mpp_luncheck.is_RdacLun(self.dconf['SCSIid'])):
                    mpp_lun = True
                    link=glob.glob('/dev/disk/mpInuse/%s-*' % self.dconf['SCSIid'])
                else:
                    maps = mpath_cli.list_maps()
            except:
                pass

            if (mpp_lun):
                if (len(link)):
                    raise xs_errors.XenError('SRInUse')
            else:
                if self.dconf['SCSIid'] in maps:
                    raise xs_errors.XenError('SRInUse')

        self.iscsi.attach(self.uuid)
        if not self.iscsi._attach_LUN_bySCSIid(self.SCSIid):
            util.SMlog("Unable to detect LUN")
            raise xs_errors.XenError('InvalidDev')
        self._pathrefresh(LVHDoISCSISR)
        out = LVHDSR.LVHDSR.probe(self)
        self.iscsi.detach(self.uuid)
        return out
示例#6
0
文件: mpath_dmp.py 项目: euanh/sm
def deactivate_MPdev(sid):
    if (mpp_luncheck.is_RdacLun(sid)):
        pathlist = glob.glob('/dev/disk/mpInuse/%s-*' % sid)
        path = pathlist[0]
    else:
        path = os.path.join(MP_INUSEDIR, sid)
    if os.path.exists(path):
        os.unlink(path)
示例#7
0
def deactivate_MPdev(sid):
    if (mpp_luncheck.is_RdacLun(sid)):
        pathlist = glob.glob('/dev/disk/mpInuse/%s-*' % sid)
        path = pathlist[0]
    else:
        path = os.path.join(MP_INUSEDIR, sid)
    if os.path.exists(path):
        os.unlink(path)
示例#8
0
    def _LUNprint(self, sr_uuid):
        if self.iscsi.attached:
            # Force a rescan on the bus.
            self.iscsi.refresh()
#            time.sleep(5)
        # Now call attach (handles the refcounting + session activa)
        self.iscsi.attach(sr_uuid)

        util.SMlog("LUNprint: waiting for path: %s" % self.iscsi.path)
        if util.wait_for_path("%s/LUN*" % self.iscsi.path, ISCSISR.MAX_TIMEOUT):
            try:
                adapter=self.iscsi.adapter[self.iscsi.address]
                util.SMlog("adapter=%s" % adapter)

                # find a scsi device on which to issue a report luns command:
                devs=glob.glob("%s/LUN*" % self.iscsi.path)
                sgdevs = []
                for i in devs:
                    sgdevs.append(int(i.split("LUN")[1]))
                sgdevs.sort()
                sgdev = "%s/LUN%d" % (self.iscsi.path,sgdevs[0])                

                # issue a report luns:
                luns=util.pread2(["/usr/bin/sg_luns","-q",sgdev]).split('\n')
                nluns=len(luns)-1 # remove the line relating to the final \n
                # check if the LUNs are MPP-RDAC Luns
                scsi_id = scsiutil.getSCSIid(sgdev)
                mpp_lun = False
                if (mpp_luncheck.is_RdacLun(scsi_id)):
                    mpp_lun = True
                    link=glob.glob('/dev/disk/by-scsibus/%s-*' % scsi_id)
                    mpp_adapter = link[0].split('/')[-1].split('-')[-1].split(':')[0]

                # make sure we've got that many sg devices present
                for i in range(0,30): 
                    luns=scsiutil._dosgscan()
                    sgdevs=filter(lambda r: r[1]==adapter, luns)
                    if mpp_lun:
                        sgdevs.extend(filter(lambda r: r[1]==mpp_adapter, luns))
                    if len(sgdevs)>=nluns:
                        util.SMlog("Got all %d sg devices" % nluns)
                        break
                    else:
                        util.SMlog("Got %d sg devices - expecting %d" % (len(sgdevs),nluns))
                        time.sleep(1)

                if os.path.exists("/sbin/udevsettle"):
                    util.pread2(["/sbin/udevsettle"])
                else:
                    util.pread2(["/sbin/udevadm","settle"])
            except:
                util.SMlog("Generic exception caught. Pass")
                pass # Make sure we don't break the probe...

        self.iscsi.print_LUNs()
        self.iscsi.detach(sr_uuid)        
示例#9
0
def activate_MPdev(sid, dst):
    if not os.path.exists(MP_INUSEDIR):
        os.mkdir(MP_INUSEDIR)
    if (mpp_luncheck.is_RdacLun(sid)):
        suffix = get_TargetID_LunNUM(sid)
        sid_with_suffix = sid + "-" + suffix
        path = os.path.join(MP_INUSEDIR, sid_with_suffix)
    else:
        path = os.path.join(MP_INUSEDIR, sid)
    cmd = ['ln', '-sf', dst, path]
    util.pread2(cmd)
示例#10
0
文件: mpath_dmp.py 项目: euanh/sm
def activate_MPdev(sid, dst):
    if not os.path.exists(MP_INUSEDIR):
        os.mkdir(MP_INUSEDIR)
    if (mpp_luncheck.is_RdacLun(sid)):
        suffix = get_TargetID_LunNUM(sid)
        sid_with_suffix = sid + "-" + suffix
        path = os.path.join(MP_INUSEDIR, sid_with_suffix)
    else:
        path = os.path.join(MP_INUSEDIR, sid)
    cmd = ['ln', '-sf', dst, path]
    util.pread2(cmd)
示例#11
0
文件: mpathcount.py 项目: robhoes/sm
def get_path_count(SCSIid, active=True):
    count = 0
    if mpp_luncheck.is_RdacLun(SCSIid):
        (total_count, active_count) = mpp_mpathutil.get_pathinfo(SCSIid)
        return (total_count, active_count)
    lines = mpath_cli.get_topology(SCSIid)
    for line in filter(match_dmpLUN, lines):
        if not active:
            count += 1
        elif match_pathup(line):
            count += 1
    return count
示例#12
0
文件: mpathcount.py 项目: MrMEEE/sm
def get_path_count(SCSIid, active=True):
    count = 0
    if (mpp_luncheck.is_RdacLun(SCSIid)):
        (total_count, active_count) = mpp_mpathutil.get_pathinfo(SCSIid)
        return (total_count, active_count)
    lines = mpath_cli.get_topology(SCSIid)
    for line in filter(match_dmpLUN,lines):
        if not active:
            count += 1
        elif match_pathup(line):
            count += 1
    return count
示例#13
0
文件: mpath_dmp.py 项目: euanh/sm
def path(SCSIid):
    if _is_mpath_daemon_running():
        if (mpp_luncheck.is_RdacLun(SCSIid)):
            pathlist = glob.glob('/dev/disk/mpInuse/%s-*' % SCSIid)
            util.SMlog("pathlist is:")
            util.SMlog(pathlist)
            if len(pathlist):
                path = pathlist[0]
            else:
                path = os.path.join(MP_INUSEDIR, SCSIid)
        else:
            path = os.path.join(MP_INUSEDIR, SCSIid)
        return path
    else:
        return DEVBYIDPATH + "/scsi-" + SCSIid
示例#14
0
def refresh(sid, npaths):
    # Refresh the multipath status
    util.SMlog("Refreshing LUN %s" % sid)
    if len(sid):
        path = DEVBYIDPATH + "/scsi-" + sid
        if not os.path.exists(path):
            scsiutil.rescan(scsiutil._genHostList(""))
            if not util.wait_for_path(path, 60):
                raise xs_errors.XenError('Device not appeared yet')
        if not (mpp_luncheck.is_RdacLun(sid)):
            _refresh_DMP(sid, npaths)
        else:
            _refresh_MPP(sid, npaths)
    else:
        raise xs_errors.XenError('MPath not written yet')
示例#15
0
def path(SCSIid):
    if _is_mpath_daemon_running():
        if (mpp_luncheck.is_RdacLun(SCSIid)):
            pathlist = glob.glob('/dev/disk/mpInuse/%s-*' % SCSIid)
            util.SMlog("pathlist is:")
            util.SMlog(pathlist)
            if len(pathlist):
                path = pathlist[0]
            else:
                path = os.path.join(MP_INUSEDIR, SCSIid)
        else:
            path = os.path.join(MP_INUSEDIR, SCSIid)
        return path
    else:
        return DEVBYIDPATH + "/scsi-" + SCSIid
示例#16
0
def refresh(sid,npaths):
    # Refresh the multipath status
    util.SMlog("Refreshing LUN %s" % sid)
    if len(sid):
        path = DEVBYIDPATH + "/scsi-" + sid
        if not os.path.exists(path):
            scsiutil.rescan(scsiutil._genHostList(""))
            if not util.wait_for_path(path,60):
                raise xs_errors.XenError('Device not appeared yet')
        if not (mpp_luncheck.is_RdacLun(sid)):
            _refresh_DMP(sid,npaths)
        else:
            _refresh_MPP(sid,npaths)
    else:
        raise xs_errors.XenError('MPath not written yet')
示例#17
0
文件: mpath_dmp.py 项目: thomasmck/sm
def activate_MPdev(sid, dst):
    try:
        os.mkdir(MP_INUSEDIR)
    except OSError as exc:
        if exc.errno == errno.EEXIST:
            pass
        else:
            raise
    if (mpp_luncheck.is_RdacLun(sid)):
        suffix = get_TargetID_LunNUM(sid)
        sid_with_suffix = sid + "-" + suffix
        path = os.path.join(MP_INUSEDIR, sid_with_suffix)
    else:
        path = os.path.join(MP_INUSEDIR, sid)
    cmd = ['ln', '-sf', dst, path]
    util.pread2(cmd)
示例#18
0
文件: mpathcount.py 项目: robhoes/sm
def update_config(key, SCSIid, entry, remove, add, mpp_path_update=False):
    if mpp_path_update:
        remove("multipathed")
        remove(key)
        remove("MPPEnabled")
        add("MPPEnabled", "true")
        add("multipathed", "true")
        add(key, str(entry))
        return

    rdaclun = False
    if mpp_luncheck.is_RdacLun(SCSIid):
        rdaclun = True
        pathlist = glob.glob("/dev/disk/mpInuse/%s-*" % SCSIid)
        path = pathlist[0]
    else:
        path = MP_INUSEDIR + "/" + SCSIid
    util.SMlog("MPATH: Updating entry for [%s], current: %s" % (SCSIid, entry))
    if os.path.exists(path):
        if rdaclun:
            (total, count) = get_path_count(SCSIid)
        else:
            count = get_path_count(SCSIid)
            total = get_path_count(SCSIid, active=False)
        max = 0
        if len(entry) != 0:
            try:
                p = entry.strip("[")
                p = p.strip("]")
                q = p.split(",")
                max = int(q[1])
            except:
                pass
        if total > max:
            max = total
        newentry = [count, max]
        if str(newentry) != entry:
            remove("multipathed")
            remove(key)
            if rdaclun:
                remove("MPPEnabled")
                add("MPPEnabled", "true")
            add("multipathed", "true")
            add(key, str(newentry))
            util.SMlog("MPATH: \tSet val: %s" % str(newentry))
示例#19
0
文件: mpathcount.py 项目: MrMEEE/sm
def update_config(key, SCSIid, entry, remove, add, mpp_path_update = False):
    if mpp_path_update:
        remove('multipathed')
        remove(key)
        remove('MPPEnabled')
        add('MPPEnabled','true')
        add('multipathed','true')
        add(key,str(entry))
        return

    rdaclun = False
    if (mpp_luncheck.is_RdacLun(SCSIid)):
        rdaclun = True
        pathlist = glob.glob('/dev/disk/mpInuse/%s-*' % SCSIid)
        path = pathlist[0]
    else:
        path = MP_INUSEDIR + "/" + SCSIid
    util.SMlog("MPATH: Updating entry for [%s], current: %s" % (SCSIid,entry))
    if os.path.exists(path):
        if rdaclun:
            (total, count) = get_path_count(SCSIid)
        else:
            count = get_path_count(SCSIid)
            total = get_path_count(SCSIid, active=False)
        max = 0
	if len(entry) != 0:
            try:
                p = entry.strip('[')
                p = p.strip(']')
                q = p.split(',')
                max = int(q[1])
            except:
                pass
        if total > max:
            max = total
        newentry = [count, max]
        if str(newentry) != entry:
            remove('multipathed')
            remove(key)
            if rdaclun:
                remove('MPPEnabled')
                add('MPPEnabled','true')
            add('multipathed','true')
            add(key,str(newentry))
            util.SMlog("MPATH: Set val: %s" % str(newentry))
示例#20
0
文件: mpath_dmp.py 项目: euanh/sm
def refresh(sid, npaths):
    # Fix udev bug (?): make sure it updates /dev/disk/by-id
    # Trigger the old way, if possible
    if os.path.exists("/sbin/udevtrigger"):
        util.pread2(["/sbin/udevtrigger"])
    else:
        util.pread2(["/sbin/udevadm", "trigger"])

    # Refresh the multipath status
    util.SMlog("Refreshing LUN %s" % sid)
    if len(sid):
        path = DEVBYIDPATH + "/scsi-" + sid
        if not os.path.exists(path):
            scsiutil.rescan(scsiutil._genHostList(""))
            if not util.wait_for_path(path, 60):
                raise xs_errors.XenError('Device not appeared yet')
        if not (mpp_luncheck.is_RdacLun(sid)):
            _refresh_DMP(sid, npaths)
        else:
            _refresh_MPP(sid, npaths)
    else:
        raise xs_errors.XenError('MPath not written yet')
示例#21
0
文件: mpath_dmp.py 项目: johnelse/sm
def refresh(sid,npaths):
    # Fix udev bug (?): make sure it updates /dev/disk/by-id
    # Trigger the old way, if possible
    if os.path.exists("/sbin/udevtrigger"):
        util.pread2(["/sbin/udevtrigger"]) 
    else:
        util.pread2(["/sbin/udevadm","trigger"])

    # Refresh the multipath status
    util.SMlog("Refreshing LUN %s" % sid)
    if len(sid):
        path = DEVBYIDPATH + "/scsi-" + sid
        if not os.path.exists(path):
            scsiutil.rescan(scsiutil._genHostList(""))
            if not util.wait_for_path(path,60):
                raise xs_errors.XenError('Device not appeared yet')
        if not (mpp_luncheck.is_RdacLun(sid)):
            _refresh_DMP(sid,npaths)
        else:
            _refresh_MPP(sid,npaths)
    else:
        raise xs_errors.XenError('MPath not written yet')
示例#22
0
文件: mpath_dmp.py 项目: euanh/sm
def reset(sid, explicit_unmap=False, delete_nodes=False):
    util.SMlog("Resetting LUN %s" % sid)
    if (mpp_luncheck.is_RdacLun(sid)):
        _resetMPP(sid, explicit_unmap)
    else:
        _resetDMP(sid, explicit_unmap, delete_nodes)
示例#23
0
def UpdatePaths():

    while (True):
        try:
            session = None
            # Garbage collect any memory allocated in the last run of the loop
            DEBUG("The garbage collection routine returned: %d" % gc.collect())

            # Sleep for some time before checking the status again
            time.sleep(MPP_PATH_STATUS_UPDATE_INTERVAL)

            # List the contents of the directory /dev/disk/mpInuse
            fileList = glob.glob(MPP_DEVICES_IN_USE_LOCATION + "/" + "*")
            if not len(fileList):
                continue

        # for each SCSI ID get the cached values of the total paths and active paths
        # and then compare this with the current path status obtained using mpp_mpathutil.py
            for filename in fileList:
                # extract the SCSI ID from the file name.
                scsiid = filename.rsplit("/")[len(filename.rsplit("/")) -
                                              1].split('-')[0]
                if not (mpp_luncheck.is_RdacLun(scsiid)):
                    continue

        # Get the cached value for the total and active paths for this SCSI ID
                try:
                    cacheFile = glob.glob(MPP_PATH_CACHE_LOCATION + "/" +
                                          scsiid + "*")
                    if len(cacheFile) > 1:
                        DEBUG(
                            "More than one cache file found for SCSI ID %s. Please check the cache manually."
                        )
                        raise Exception

                    # This will return only one file name of the form SCSIID:TOTALPATHS:ACTIVEPATHS, so parse accordingly
                    cachedTotalPaths = cacheFile[0].split(":")[1]
                    cachedActivePaths = cacheFile[0].split(":")[2]
                    cacheFileFound = True
                except:
                    DEBUG(
                        "There was an exception getting the cached path status for SCSI ID %s, assuming 0s."
                        % scsiid)
                    cachedTotalPaths = 0
                    cachedActivePaths = 0
                    cacheFileFound = False

                (totalPaths, activePaths) = mpp_mpathutil.get_pathinfo(scsiid)

                DEBUG(
                    "For SCSI ID %s, cached TotalPaths: %s, cached ActivePaths: %s, New Totalpaths: %s New ActivePaths: %s"
                    % (scsiid, cachedTotalPaths, cachedActivePaths, totalPaths,
                       activePaths))

                if cachedTotalPaths != str(
                        totalPaths) or cachedActivePaths != str(activePaths):
                    DEBUG(
                        "Some path status has changed for SCSI ID %s, updating PBD."
                        % scsiid)
                    entry = "[" + str(activePaths) + ", " + str(
                        totalPaths) + "]"
                    DEBUG(entry)
                    cmd = ['/opt/xensource/sm/mpathcount.py', scsiid, entry]
                    util.pread2(cmd)

                    # Now update the cache with this updated path status
                    DEBUG("Checking if cache file was found.")
                    if cacheFileFound == True:
                        DEBUG("Cache file was found, delete it.")
                        os.remove(cacheFile[0])
                    cacheFileName = MPP_PATH_CACHE_LOCATION + "/" + scsiid + ":" + str(
                        totalPaths) + ":" + str(activePaths)
                    DEBUG("Generated new cache file name %s" % cacheFileName)
                    open(cacheFileName, 'w').close()

        except:
            pass
#DEBUG("There was some exception while updating path status for the SCSI ID %s." % scsiid )
        #break

        if session != None:
            session.xenapi.session.logout()

    return
示例#24
0
def UpdatePaths():

    while True:
        try:
            session = None
            # Garbage collect any memory allocated in the last run of the loop
            DEBUG("The garbage collection routine returned: %d" % gc.collect())

            # Sleep for some time before checking the status again
            time.sleep(MPP_PATH_STATUS_UPDATE_INTERVAL)

            # List the contents of the directory /dev/disk/mpInuse
            fileList = glob.glob(MPP_DEVICES_IN_USE_LOCATION + "/" + "*")
            if not len(fileList):
                continue

            # for each SCSI ID get the cached values of the total paths and active paths
            # and then compare this with the current path status obtained using mpp_mpathutil.py
            for filename in fileList:
                # extract the SCSI ID from the file name.
                scsiid = filename.rsplit("/")[len(filename.rsplit("/")) - 1].split("-")[0]
                if not (mpp_luncheck.is_RdacLun(scsiid)):
                    continue

                # Get the cached value for the total and active paths for this SCSI ID
                try:
                    cacheFile = glob.glob(MPP_PATH_CACHE_LOCATION + "/" + scsiid + "*")
                    if len(cacheFile) > 1:
                        DEBUG("More than one cache file found for SCSI ID %s. Please check the cache manually.")
                        raise Exception

                        # This will return only one file name of the form SCSIID:TOTALPATHS:ACTIVEPATHS, so parse accordingly
                    cachedTotalPaths = cacheFile[0].split(":")[1]
                    cachedActivePaths = cacheFile[0].split(":")[2]
                    cacheFileFound = True
                except:
                    DEBUG("There was an exception getting the cached path status for SCSI ID %s, assuming 0s." % scsiid)
                    cachedTotalPaths = 0
                    cachedActivePaths = 0
                    cacheFileFound = False

                (totalPaths, activePaths) = mpp_mpathutil.get_pathinfo(scsiid)

                DEBUG(
                    "For SCSI ID %s, cached TotalPaths: %s, cached ActivePaths: %s, New Totalpaths: %s New ActivePaths: %s"
                    % (scsiid, cachedTotalPaths, cachedActivePaths, totalPaths, activePaths)
                )

                if cachedTotalPaths != str(totalPaths) or cachedActivePaths != str(activePaths):
                    DEBUG("Some path status has changed for SCSI ID %s, updating PBD." % scsiid)
                    entry = "[" + str(activePaths) + ", " + str(totalPaths) + "]"
                    DEBUG(entry)
                    cmd = ["/opt/xensource/sm/mpathcount.py", scsiid, entry]
                    util.pread2(cmd)

                    # Now update the cache with this updated path status
                    DEBUG("Checking if cache file was found.")
                    if cacheFileFound == True:
                        DEBUG("Cache file was found, delete it.")
                        os.remove(cacheFile[0])
                    cacheFileName = (
                        MPP_PATH_CACHE_LOCATION + "/" + scsiid + ":" + str(totalPaths) + ":" + str(activePaths)
                    )
                    DEBUG("Generated new cache file name %s" % cacheFileName)
                    open(cacheFileName, "w").close()

        except:
            pass
        # DEBUG("There was some exception while updating path status for the SCSI ID %s." % scsiid )
        # break

        if session != None:
            session.xenapi.session.logout()

    return
示例#25
0
def reset(sid,explicit_unmap=False,delete_nodes=False):
    util.SMlog("Resetting LUN %s" % sid)
    if (mpp_luncheck.is_RdacLun(sid)):
        _resetMPP(sid,explicit_unmap)
    else:
        _resetDMP(sid,explicit_unmap,delete_nodes)