| 1 | |
package org.jscsi.target.connection.stage.fullfeature; |
| 2 | |
|
| 3 | |
|
| 4 | |
import java.io.IOException; |
| 5 | |
import java.security.DigestException; |
| 6 | |
|
| 7 | |
import org.jscsi.exception.InternetSCSIException; |
| 8 | |
import org.jscsi.parser.BasicHeaderSegment; |
| 9 | |
import org.jscsi.parser.ProtocolDataUnit; |
| 10 | |
import org.jscsi.parser.scsi.SCSICommandParser; |
| 11 | |
import org.jscsi.target.connection.phase.TargetFullFeaturePhase; |
| 12 | |
import org.jscsi.target.scsi.cdb.ReportLunsCDB; |
| 13 | |
import org.jscsi.target.scsi.cdb.SelectReport; |
| 14 | |
import org.jscsi.target.scsi.lun.ReportLunsParameterData; |
| 15 | |
import org.jscsi.target.scsi.sense.senseDataDescriptor.senseKeySpecific.FieldPointerSenseKeySpecificData; |
| 16 | |
import org.jscsi.target.settings.SettingsException; |
| 17 | |
import org.slf4j.Logger; |
| 18 | |
import org.slf4j.LoggerFactory; |
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
public class ReportLunsStage extends TargetFullFeatureStage { |
| 27 | |
|
| 28 | 0 | private static final Logger LOGGER = LoggerFactory.getLogger(ReportLunsStage.class); |
| 29 | |
|
| 30 | |
public ReportLunsStage (TargetFullFeaturePhase targetFullFeaturePhase) { |
| 31 | 0 | super(targetFullFeaturePhase); |
| 32 | 0 | } |
| 33 | |
|
| 34 | |
@Override |
| 35 | |
public void execute (ProtocolDataUnit pdu) throws IOException , InterruptedException , InternetSCSIException , DigestException , SettingsException { |
| 36 | |
|
| 37 | 0 | final BasicHeaderSegment bhs = pdu.getBasicHeaderSegment(); |
| 38 | 0 | final SCSICommandParser parser = (SCSICommandParser) bhs.getParser(); |
| 39 | |
|
| 40 | 0 | ProtocolDataUnit responsePdu = null; |
| 41 | |
|
| 42 | |
|
| 43 | 0 | final ReportLunsCDB cdb = new ReportLunsCDB(parser.getCDB()); |
| 44 | 0 | final FieldPointerSenseKeySpecificData[] illegalFieldPointers = cdb.getIllegalFieldPointers(); |
| 45 | |
|
| 46 | 0 | if (illegalFieldPointers != null) { |
| 47 | |
|
| 48 | 0 | responsePdu = createFixedFormatErrorPdu(illegalFieldPointers, |
| 49 | |
bhs.getInitiatorTaskTag(), |
| 50 | |
parser.getExpectedDataTransferLength()); |
| 51 | |
|
| 52 | |
|
| 53 | 0 | connection.sendPdu(responsePdu); |
| 54 | |
|
| 55 | |
} else { |
| 56 | |
|
| 57 | |
|
| 58 | 0 | final SelectReport selectReport = cdb.getSelectReport(); |
| 59 | 0 | LOGGER.debug("selectReport = " + selectReport); |
| 60 | |
|
| 61 | |
|
| 62 | |
ReportLunsParameterData reportLunsParameterData; |
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | 0 | switch (selectReport) { |
| 67 | |
case SELECTED_ADDRESSING_METHODS : |
| 68 | |
case WELL_KNOWN_LUNS_ONLY : |
| 69 | |
case ALL : |
| 70 | 0 | reportLunsParameterData = new ReportLunsParameterData(session.getTargetServer().getConfig().getLogicalUnitNumber()); |
| 71 | 0 | break; |
| 72 | |
default : |
| 73 | 0 | throw new InternetSCSIException(); |
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | |
} |
| 78 | |
|
| 79 | |
|
| 80 | 0 | sendResponse(bhs.getInitiatorTaskTag(), |
| 81 | |
parser.getExpectedDataTransferLength(), |
| 82 | |
reportLunsParameterData); |
| 83 | |
|
| 84 | |
} |
| 85 | 0 | } |
| 86 | |
|
| 87 | |
} |