Ejemplo n.º 1
0
 def _attach_LUN_bylunid(self, lunid):
     if not self.attached:
         raise xs_errors.XenError('SRUnavailable')
     connected = []
     for val in self.adapter:
         if not self.pathdict.has_key(val):
             continue
         rec = self.pathdict[val]
         path = os.path.join(rec['path'],"LUN%s" % lunid)
         util.SMlog("path: %s" % path)
         realpath = os.path.realpath(path)
         util.SMlog("realpath: %s" % realpath)
         host = self.adapter[val]
         if not self.devs.has_key(realpath):
             l = [realpath, host, 0, 0, lunid]
             scsiutil.scsi_dev_ctrl(l,"add")
             if not util.wait_for_path(path, MAX_LUNID_TIMEOUT):
                 util.SMlog("Unable to detect LUN attached to host on path [%s]" % path)
                 continue
         else:
             # Verify that we are not seeing a stale LUN map
             try:
                 real_SCSIid = scsiutil.getSCSIid(realpath)
                 cur_scsibuspath = glob.glob('/dev/disk/by-scsibus/*-%s:0:0:%s' % (host,lunid))
                 cur_SCSIid = os.path.basename(cur_scsibuspath[0]).split("-")[0]
                 assert(cur_SCSIid == real_SCSIid)
             except:
                 scsiutil.rescan([host])
                 if not os.path.exists('/dev/disk/by-scsibus/%s-%s:0:0:%s' % \
                                       (real_SCSIid,host,lunid)):
                     util.SMlog("Unable to detect LUN attached to host after bus re-probe")
                     continue
         connected.append(path)
     return connected
Ejemplo n.º 2
0
 def _detach_LUN_bylunid(self, lunid, SCSIid):
     if not self.attached:
         raise xs_errors.XenError("SRUnavailable")
     if self.mpath == "true" and len(SCSIid):
         self.mpathmodule.reset(SCSIid, True)
         util.remove_mpathcount_field(self.session, self.host_ref, self.sr_ref, SCSIid)
     for val in self.adapter:
         if not self.pathdict.has_key(val):
             continue
         rec = self.pathdict[val]
         path = os.path.join(rec["path"], "LUN%s" % lunid)
         realpath = os.path.realpath(path)
         if self.devs.has_key(realpath):
             util.SMlog("Found key: %s" % realpath)
             scsiutil.scsi_dev_ctrl(self.devs[realpath], "remove")
             # Wait for device to disappear
             if not util.wait_for_nopath(realpath, MAX_LUNID_TIMEOUT):
                 util.SMlog("Device has not disappeared after %d seconds" % MAX_LUNID_TIMEOUT)
             else:
                 util.SMlog("Device [%s,%s] disappeared" % (realpath, path))
Ejemplo n.º 3
0
    def _detach_LUN_bylunid(self, lunid, SCSIid):
        if not self.attached:
            raise xs_errors.XenError('SRUnavailable')
        if self.mpath == 'true' and len(SCSIid):
            self.mpathmodule.reset(SCSIid, True)
            util.remove_mpathcount_field(self.session, self.host_ref, self.sr_ref, SCSIid)
        for val in self.adapter:
            if not self.pathdict.has_key(val):
                continue
            rec = self.pathdict[val]
            path = os.path.join(rec['path'],"LUN%s" % lunid)            
            realpath = os.path.realpath(path)
            if self.devs.has_key(realpath):
		util.SMlog("Found key: %s" % realpath)
                scsiutil.scsi_dev_ctrl(self.devs[realpath], 'remove')
                # Wait for device to disappear
                if not util.wait_for_nopath(realpath, MAX_LUNID_TIMEOUT):
                    util.SMlog("Device has not disappeared after %d seconds" % \
                               MAX_LUNID_TIMEOUT)
                else:
                    util.SMlog("Device [%s,%s] disappeared" % (realpath,path))
Ejemplo n.º 4
0
    def _attach_LUN_bylunid(self, lunid):
        if not self.attached:
            raise xs_errors.XenError('SRUnavailable')
        connected = []
        for val in self.adapter:
            if val not in self.pathdict:
                continue
            rec = self.pathdict[val]
            path = os.path.join(rec['path'], "LUN%s" % lunid)
            realpath = os.path.realpath(path)
            host = self.adapter[val]
            l = [realpath, host, 0, 0, lunid]

            addDevice = True
            if realpath in self.devs:
                # if the device is stale remove it before adding again
                real_SCSIid = None
                try:
                    real_SCSIid = scsiutil.getSCSIid(realpath)
                except:
                    pass

                if real_SCSIid != None:
                    # make sure this is the same scsiid, if not remove the device
                    cur_scsibuspath = glob.glob(
                        '/dev/disk/by-scsibus/*-%s:0:0:%s' % (host, lunid))
                    cur_SCSIid = os.path.basename(
                        cur_scsibuspath[0]).split("-")[0]
                    if cur_SCSIid != real_SCSIid:
                        # looks stale, remove it
                        scsiutil.scsi_dev_ctrl(l, "remove")
                    else:
                        util.SMlog("Not attaching LUNID %s for adapter %s"\
                            " since the device exists and the scsi id %s seems"\
                            " to be valid. " % (lunid, val, real_SCSIid))
                        addDevice = False
                else:
                    # looks stale, remove it
                    scsiutil.scsi_dev_ctrl(l, "remove")

            if addDevice:
                # add the device
                scsiutil.scsi_dev_ctrl(l, "add")
                if not util.wait_for_path(path, MAX_LUNID_TIMEOUT):
                    util.SMlog(
                        "Unable to detect LUN attached to host on path [%s]" %
                        path)
                    continue
            connected.append(path)
        return connected
Ejemplo n.º 5
0
    def _attach_LUN_bylunid(self, lunid):
        if not self.attached:
            raise xs_errors.XenError("SRUnavailable")
        connected = []
        for val in self.adapter:
            if not self.pathdict.has_key(val):
                continue
            rec = self.pathdict[val]
            path = os.path.join(rec["path"], "LUN%s" % lunid)
            realpath = os.path.realpath(path)
            host = self.adapter[val]
            l = [realpath, host, 0, 0, lunid]

            addDevice = True
            if self.devs.has_key(realpath):
                # if the device is stale remove it before adding again
                real_SCSIid = None
                try:
                    real_SCSIid = scsiutil.getSCSIid(realpath)
                except:
                    pass

                if real_SCSIid != None:
                    # make sure this is the same scsiid, if not remove the device
                    cur_scsibuspath = glob.glob("/dev/disk/by-scsibus/*-%s:0:0:%s" % (host, lunid))
                    cur_SCSIid = os.path.basename(cur_scsibuspath[0]).split("-")[0]
                    if cur_SCSIid != real_SCSIid:
                        # looks stale, remove it
                        scsiutil.scsi_dev_ctrl(l, "remove")
                    else:
                        util.SMlog(
                            "Not attaching LUNID %s for adapter %s"
                            " since the device exists and the scsi id %s seems"
                            " to be valid. " % (lunid, val, real_SCSIid)
                        )
                        addDevice = False
                else:
                    # looks stale, remove it
                    scsiutil.scsi_dev_ctrl(l, "remove")

            if addDevice:
                # add the device
                scsiutil.scsi_dev_ctrl(l, "add")
                if not util.wait_for_path(path, MAX_LUNID_TIMEOUT):
                    util.SMlog("Unable to detect LUN attached to host on path [%s]" % path)
                    continue
            connected.append(path)
        return connected