コード例 #1
0
ファイル: scsi_device.py プロジェクト: rorychen/python-scsi
    def execute(self, cmd):
        """
        execute a scsi command

        :param cmd: a SCSICommand
        """
        if self._detect_replugged and self._is_replugged():
            try:
                self.close()
            finally:
                self.open()

        _dir = linux_sgio.DXFER_NONE
        if len(cmd.datain) and len(cmd.dataout):
            raise NotImplemented('Indirect IO is not supported')
        elif len(cmd.datain):
            _dir = linux_sgio.DXFER_FROM_DEV
        elif len(cmd.dataout):
            _dir = linux_sgio.DXFER_TO_DEV

        status = linux_sgio.execute(self._fd, _dir, cmd.cdb, cmd.dataout,
                                    cmd.datain, cmd.sense)
        if status == scsi_enum_command.SCSI_STATUS.CHECK_CONDITION:
            raise self.CheckCondition(cmd.sense)
        if status == scsi_enum_command.SCSI_STATUS.SGIO_ERROR:
            raise self.SCSISGIOError
コード例 #2
0
ファイル: scsi_device.py プロジェクト: rosjat/python-scsi
    def execute(self, cmd):
        """
        execute a scsi command

        :param cmd: a SCSICommand
        """
        if self._detect_replugged and self._is_replugged():
            try:
                self.close()
            finally:
                self.open()

        _dir = linux_sgio.DXFER_NONE
        if len(cmd.datain) and len(cmd.dataout):
            raise NotImplemented('Indirect IO is not supported')
        elif len(cmd.datain):
            _dir = linux_sgio.DXFER_FROM_DEV
        elif len(cmd.dataout):
            _dir = linux_sgio.DXFER_TO_DEV

        status = linux_sgio.execute(self._fd,
                                    _dir,
                                    cmd.cdb,
                                    cmd.dataout,
                                    cmd.datain,
                                    cmd.sense)
        if status == scsi_enum_command.SCSI_STATUS.CHECK_CONDITION:
            raise self.CheckCondition(cmd.sense)
        if status == scsi_enum_command.SCSI_STATUS.SGIO_ERROR:
            raise self.SCSISGIOError
コード例 #3
0
ファイル: scsi_device.py プロジェクト: jlutran/python-scsi
    def execute(self, cdb, dataout, datain, sense):
        """
        execute a scsi command
        :param cdb: a byte array representing a command descriptor block
        :param dataout: a byte array to hold received data from the ioctl call
        :param datain: a byte array to hold data passed to the ioctl call
        :param sense: a byte array to hold sense data
        """
        if self.isLibSCSI:
            _dir = libiscsi.SCSI_XFER_NONE
            _xferlen = 0
            if len(datain):
                _dir = libiscsi.SCSI_XFER_READ
                _xferlen = len(datain)
            if len(dataout):
                _dir = libiscsi.SCSI_XFER_WRITE
                _xferlen = len(dataout)
            _task = libiscsi.scsi_create_task(cdb, _dir, _xferlen)
            if len(datain):
                libiscsi.scsi_task_add_data_in_buffer(_task, datain)
            if len(dataout):
                libiscsi.scsi_task_add_data_out_buffer(_task, dataout)

            libiscsi.iscsi_scsi_command_sync(self._iscsi, self._iscsi_url.lun,
                                             _task, None)
            _status = libiscsi.scsi_task_get_status(_task, None)
            if _status == libiscsi.SCSI_STATUS_CHECK_CONDITION:
                raise self.CheckCondition(sense)
            if _status == libiscsi.SCSI_STATUS_GOOD:
                return

            raise self.SCSISGIOError

        elif self.isLinuxSGIO:
            _dir = linux_sgio.DXFER_NONE
            if len(datain) and len(dataout):
                raise NotImplemented('Indirect IO is not supported')
            elif len(datain):
                _dir = linux_sgio.DXFER_FROM_DEV
            elif len(dataout):
                _dir = linux_sgio.DXFER_TO_DEV

            status = linux_sgio.execute(self._fd, _dir, cdb, dataout, datain,
                                        sense)
            if status == scsi_enum_command.SCSI_STATUS.CHECK_CONDITION:
                raise self.CheckCondition(sense)
            if status == scsi_enum_command.SCSI_STATUS.SGIO_ERROR:
                raise self.SCSISGIOError
コード例 #4
0
ファイル: scsi_device.py プロジェクト: sahlberg/python-scsi
    def execute(self, cdb, dataout, datain, sense):
        """
        execute a scsi command
        :param cdb: a byte array representing a command descriptor block
        :param dataout: a byte array to hold received data from the ioctl call
        :param datain: a byte array to hold data passed to the ioctl call
        :param sense: a byte array to hold sense data
        """
        if self.isLibSCSI:
            _dir = libiscsi.SCSI_XFER_NONE
            _xferlen = 0
            if len(datain):
                _dir = libiscsi.SCSI_XFER_READ
                _xferlen = len(datain)
            if len(dataout):
                _dir = libiscsi.SCSI_XFER_WRITE
                _xferlen = len(dataout)
            _task = libiscsi.scsi_create_task(cdb, _dir, _xferlen)
            if len(datain):
                libiscsi.scsi_task_add_data_in_buffer(_task, datain)
            if len(dataout):
                libiscsi.scsi_task_add_data_out_buffer(_task, dataout)

            libiscsi.iscsi_scsi_command_sync(self._iscsi, self._iscsi_url.lun, _task, None)
            _status = libiscsi.scsi_task_get_status(_task, None)
            if _status == libiscsi.SCSI_STATUS_CHECK_CONDITION:
                raise self.CheckCondition(sense)
            if _status == libiscsi.SCSI_STATUS_GOOD:
                return

            raise self.SCSISGIOError

        elif self.isLinuxSGIO:
            _dir = linux_sgio.DXFER_NONE
            if len(datain) and len(dataout):
                raise NotImplemented('Indirect IO is not supported')
            elif len(datain):
                _dir = linux_sgio.DXFER_FROM_DEV
            elif len(dataout):
                _dir = linux_sgio.DXFER_TO_DEV

            status = linux_sgio.execute(self._fd, _dir, cdb, dataout, datain, sense)
            if status == scsi_enum_command.SCSI_STATUS.CHECK_CONDITION:
                raise self.CheckCondition(sense)
            if status == scsi_enum_command.SCSI_STATUS.SGIO_ERROR:
                raise self.SCSISGIOError