예제 #1
0
 def _query(self, path, id):
     self.uuid = scsiutil.gen_uuid_from_string(scsiutil.getuniqueserial(path))
     self.location = self.uuid
     self.vendor = scsiutil.getmanufacturer(path)
     self.serial = scsiutil.getserial(path)
     self.LUNid = id
     self.size = scsiutil.getsize(path)
     self.SCSIid = scsiutil.getSCSIid(path)
     self.path = path
     sm_config = util.default(self, "sm_config", lambda: {})
     sm_config['LUNid'] = str(self.LUNid)
     sm_config['SCSIid'] = self.SCSIid
     self.sm_config = sm_config
예제 #2
0
 def _loadvdis(self):
     count = 0
     if not os.path.exists(self.path):
         return 0
     for file in filter(self.match_lun, util.listdir(self.path)):
         vdi_path = os.path.join(self.path,file)
         LUNid = file.replace("LUN","")
         uuid = scsiutil.gen_uuid_from_string(scsiutil.getuniqueserial(vdi_path))
         obj = self.vdi(uuid)
         obj._query(vdi_path, LUNid)
         self.vdis[uuid] = obj
         self.physical_size += obj.size
         count += 1
     return count
예제 #3
0
 def _query(self, path, id):
     self.uuid = scsiutil.gen_uuid_from_string(
         scsiutil.getuniqueserial(path))
     self.location = self.uuid
     self.vendor = scsiutil.getmanufacturer(path)
     self.serial = scsiutil.getserial(path)
     self.LUNid = id
     self.size = scsiutil.getsize(path)
     self.SCSIid = scsiutil.getSCSIid(path)
     self.path = path
     sm_config = util.default(self, "sm_config", lambda: {})
     sm_config['LUNid'] = str(self.LUNid)
     sm_config['SCSIid'] = self.SCSIid
     self.sm_config = sm_config
예제 #4
0
 def _loadvdis(self):
     count = 0
     if not os.path.exists(self.path):
         return 0
     for file in filter(self.match_lun, util.listdir(self.path)):
         vdi_path = os.path.join(self.path,file)
         LUNid = file.replace("LUN","")
         uuid = scsiutil.gen_uuid_from_string(scsiutil.getuniqueserial(vdi_path))
         obj = self.vdi(uuid)
         obj._query(vdi_path, LUNid)
         self.vdis[uuid] = obj
         self.physical_size += obj.size
         count += 1
     return count
예제 #5
0
파일: RawHBASR.py 프로젝트: BobBall/sm
    def _query(self, path, id, uuid=None, scsi_id=None):
        """Overloaded function with mostly duplicated code"""
        if uuid:
            self.uuid = uuid
        else:
            util.SMlog("RawHBA: uuid should not be generated..")
            self.uuid = scsiutil.gen_uuid_from_string(
                scsiutil.getuniqueserial(path)
                )
        if scsi_id:
            self.SCSIid = scsi_id
        else:
            # It is usually unnecessary to calculate it again but scsi_id
            # is used as a flag in this function and we cannot guarantee
            # this info is already available at call time
            self.SCSIid = scsiutil.getSCSIid(path)
        self.location = self.uuid
        self.vendor = scsiutil.getmanufacturer(path)
        self.serial = scsiutil.getserial(path)
        self.LUNid = id

        # Handle resize done at the array size. The resize gets reflected
        # only when the vdi is not in detached state. Do this if we the vdi
        # is known to xapi
        try:
            vdi_ref = self.sr.session.xenapi.VDI.get_by_uuid(self.uuid)
            # Check if the vbd is not in attached state, do a LUN rescan
            # to reflect the array LUN
            dev = [path]
            if scsi_id:
                # We want all the devices with this scsi_id
                dev = scsiutil._genReverseSCSIidmap(scsi_id)
            if self.sr.srcmd.cmd == "vdi_attach":
                scsiutil.refreshdev(dev)
            elif not B_util.is_vdi_attached(self.sr.session, vdi_ref):
                scsiutil.refreshdev(dev)
        except:
            pass

        self.size = scsiutil.getsize(path)
        self.path = path
        sm_config = util.default(self, "sm_config", lambda: {})
        sm_config['LUNid'] = str(self.LUNid)
        sm_config['SCSIid'] = self.SCSIid
        # Make sure to use kernel blkback (not blktap3) for raw LUNs
        sm_config['backend-kind'] = 'vbd'
        self.sm_config = sm_config
예제 #6
0
    def _query(self, path, id, uuid=None, scsi_id=None):
        """Overloaded function with mostly duplicated code"""
        if uuid:
            self.uuid = uuid
        else:
            util.SMlog("RawHBA: uuid should not be generated..")
            self.uuid = scsiutil.gen_uuid_from_string(
                scsiutil.getuniqueserial(path)
                )
        if scsi_id:
            self.SCSIid = scsi_id
        else:
            # It is usually unnecessary to calculate it again but scsi_id
            # is used as a flag in this function and we cannot guarantee
            # this info is already available at call time
            self.SCSIid = scsiutil.getSCSIid(path)
        self.location = self.uuid
        self.vendor = scsiutil.getmanufacturer(path)
        self.serial = scsiutil.getserial(path)
        self.LUNid = id

        # Handle resize done at the array size. The resize gets reflected
        # only when the vdi is not in detached state. Do this if we the vdi
        # is known to xapi
        try:
            vdi_ref = self.sr.session.xenapi.VDI.get_by_uuid(self.uuid)
            # Check if the vbd is not in attached state, do a LUN rescan
            # to reflect the array LUN
            dev = [path]
            if scsi_id:
                # We want all the devices with this scsi_id
                dev = scsiutil._genReverseSCSIidmap(scsi_id)
            if self.sr.srcmd.cmd == "vdi_attach":
                scsiutil.refreshdev(dev)
            elif not B_util.is_vdi_attached(self.sr.session, vdi_ref):
                scsiutil.refreshdev(dev)
        except:
            pass

        self.size = scsiutil.getsize(path)
        self.path = path
        sm_config = util.default(self, "sm_config", lambda: {})
        sm_config['LUNid'] = str(self.LUNid)
        sm_config['SCSIid'] = self.SCSIid
        # Make sure to use kernel blkback (not blktap3) for raw LUNs
        sm_config['backend-kind'] = 'vbd'
        self.sm_config = sm_config
예제 #7
0
    def _loadvdis(self):
        if self.vdis:
            return

        self._init_hbadict()
        count = 0
        for key in self.hbadict.iterkeys():
            vdi_path = os.path.join("/dev",key)
	    if not self.devs.has_key(vdi_path):
		continue
            uuid = scsiutil.gen_uuid_from_string(scsiutil.getuniqueserial(vdi_path))
            obj = self.vdi(uuid)
            path = self.mpathmodule.path(scsiutil.getSCSIid(vdi_path))
	    ids = self.devs[vdi_path]
            obj._query(vdi_path, ids[4])
            self.vdis[uuid] = obj
            self.physical_size += obj.size
            count += 1
        return count
예제 #8
0
    def _loadvdis(self):
        if self.vdis:
            return

        self._init_hbadict()
        count = 0
        for key in self.hbadict.iterkeys():
            vdi_path = os.path.join("/dev",key)
	    if vdi_path not in self.devs:
		continue
            uuid = scsiutil.gen_uuid_from_string(scsiutil.getuniqueserial(vdi_path))
            obj = self.vdi(uuid)
            path = self.mpathmodule.path(scsiutil.getSCSIid(vdi_path))
	    ids = self.devs[vdi_path]
            obj._query(vdi_path, ids[4])
            self.vdis[uuid] = obj
            self.physical_size += obj.size
            count += 1
        return count
예제 #9
0
    def _loadvdis(self):
        if self.cmd not in NEEDS_LOADVDIS:
            return 0
        if self.vdis:
            return

        self._init_hbadict()
        count = 0
        self.physical_size = 0
        root_dev_id = util.getrootdevID()

        xapi_session = self.session.xenapi
        known_scsid = {}  # dict of ids processed within the following loop

        for key in self.hbadict.iterkeys():

            # We need a fresh sm_config everytime because it is modified
            # inside this loop
            sm_config = xapi_session.SR.get_sm_config(self.sr_ref)

            # The way we create vdi_path and the following check are
            # not clear at all
            vdi_path = os.path.join("/dev", key)
            if vdi_path not in self.devs:
                continue

            scsi_id = scsiutil.getSCSIid(vdi_path)
            if scsi_id == root_dev_id:
                util.SMlog("Skipping root device %s" % scsi_id)
                continue

            # Avoid false positives: this SR can already contain this
            # SCSIid during scan.
            scsi_key = "scsi-" + scsi_id
            if scsi_key in sm_config:
                # if we know about this scsid we can skip this specific dev
                if scsi_key in known_scsid:
                    util.SMlog("This SCSI id (%s) is already added" % scsi_id)
                    continue
                else:
                    # marked as known to avoid adding it again to sm_config
                    known_scsid[scsi_key] = ""
            elif util.test_SCSIid(self.session, None, scsi_id):
                util.SMlog("This SCSI id (%s) is used by another SR" % scsi_id)
                continue

            # getuniqueserial invokes again getSCSIid -> Fix!
            uuid = scsiutil.gen_uuid_from_string(
                scsiutil.getuniqueserial(vdi_path))
            # We could have checked the SCSIid but the dictionary has
            # uuid as key.
            # We have already checked known_scsid, though. This block is
            # supposed to be always False
            if uuid in self.vdis:
                util.SMlog("Warning: unexpected code block reached with"
                           " uuid = %s" % scsi_id)
                continue

            obj = self.vdi(uuid)
            path = self.mpathmodule.path(scsi_id)
            ids = self.devs[vdi_path]
            obj._query(vdi_path, ids[4], uuid, scsi_id)
            self.vdis[uuid] = obj
            self.physical_size += obj.size

            count += 1

            # If we know about it no need to add to sm_config
            if scsi_key in known_scsid:
                continue

            # Prepare multipathing and make the other SRs know this SCSIid
            # is reserved.
            # Its counterpart is vdi_delete
            try:
                xapi_session.SR.add_to_sm_config(self.sr_ref, scsi_key, uuid)
                known_scsid[scsi_key] = ""
            except:
                util.SMlog("Warning: add_to_sm_config failed unexpectedly")

        return count
예제 #10
0
파일: RawHBASR.py 프로젝트: BobBall/sm
    def _loadvdis(self):
        if self.cmd not in NEEDS_LOADVDIS:
            return 0
        if self.vdis:
            return

        self._init_hbadict()
        count = 0
        self.physical_size = 0
        root_dev_id = util.getrootdevID()

        xapi_session = self.session.xenapi
        known_scsid = {} # dict of ids processed within the following loop

        for key in self.hbadict.iterkeys():

            # We need a fresh sm_config everytime because it is modified
            # inside this loop
            sm_config = xapi_session.SR.get_sm_config(self.sr_ref)

            # The way we create vdi_path and the following check are
            # not clear at all
            vdi_path = os.path.join("/dev",key)
            if not self.devs.has_key(vdi_path):
                continue

            scsi_id = scsiutil.getSCSIid(vdi_path)
            if scsi_id == root_dev_id:
                util.SMlog("Skipping root device %s" %scsi_id)
                continue

            # Avoid false positives: this SR can already contain this
            # SCSIid during scan.
            scsi_key = "scsi-" + scsi_id
            if sm_config.has_key(scsi_key):
                # if we know about this scsid we can skip this specific dev
                if known_scsid.has_key(scsi_key):
                    util.SMlog("This SCSI id (%s) is already added" %scsi_id)
                    continue
                else:
                    # marked as known to avoid adding it again to sm_config
                    known_scsid[scsi_key] = ""
            elif util.test_SCSIid(self.session, None, scsi_id):
                util.SMlog("This SCSI id (%s) is used by another SR" %scsi_id)
                continue

            # getuniqueserial invokes again getSCSIid -> Fix!
            uuid = scsiutil.gen_uuid_from_string(
                scsiutil.getuniqueserial(vdi_path)
                )
            # We could have checked the SCSIid but the dictionary has
            # uuid as key.
            # We have already checked known_scsid, though. This block is
            # supposed to be always False
            if self.vdis.has_key(uuid):
                util.SMlog("Warning: unexpected code block reached with"
                           " uuid = %s" %scsi_id)
                continue

            obj = self.vdi(uuid)
            path = self.mpathmodule.path(scsi_id)
            ids = self.devs[vdi_path]
            obj._query(vdi_path, ids[4], uuid, scsi_id)
            self.vdis[uuid] = obj
            self.physical_size += obj.size

            count += 1

            # If we know about it no need to add to sm_config
            if known_scsid.has_key(scsi_key):
                continue

            # Prepare multipathing and make the other SRs know this SCSIid
            # is reserved.
            # Its counterpart is vdi_delete
            try:
                xapi_session.SR.add_to_sm_config(self.sr_ref, scsi_key, uuid)
                known_scsid[scsi_key] = ""
            except:
                util.SMlog("Warning: add_to_sm_config failed unexpectedly")

        return count