Coverage Report - org.jscsi.target.connection.stage.fullfeature.ReportLunsStage
 
Classes in this File Line Coverage Branch Coverage Complexity
ReportLunsStage
0%
0/19
0%
0/6
3.5
ReportLunsStage$1
0%
0/1
N/A
3.5
 
 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  
  * A stage for processing <code>REPORT LUNS</code> SCSI commands.
 23  
  * 
 24  
  * @author Andreas Ergenzinger
 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;// the response PDU
 41  
 
 42  
         // get command details in CDB
 43  0
         final ReportLunsCDB cdb = new ReportLunsCDB(parser.getCDB());
 44  0
         final FieldPointerSenseKeySpecificData[] illegalFieldPointers = cdb.getIllegalFieldPointers();
 45  
 
 46  0
         if (illegalFieldPointers != null) {
 47  
             // an illegal request has been made
 48  0
             responsePdu = createFixedFormatErrorPdu(illegalFieldPointers,// senseKeySpecificData
 49  
                     bhs.getInitiatorTaskTag(),// initiatorTaskTag
 50  
                     parser.getExpectedDataTransferLength());// expectedDataTransferLength
 51  
 
 52  
             // send response
 53  0
             connection.sendPdu(responsePdu);
 54  
 
 55  
         } else {
 56  
             // PDU is okay
 57  
             // carry out command
 58  0
             final SelectReport selectReport = cdb.getSelectReport();
 59  0
             LOGGER.debug("selectReport = " + selectReport);
 60  
 
 61  
             // there are only well known LUNs
 62  
             ReportLunsParameterData reportLunsParameterData;
 63  
 
 64  
             // TODO the switch isn't really needed right now, but maybe in
 65  
             // future implementations
 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  
                      * Unreachable, this case has already been checked in the ReportLunsCDB constructor
 76  
                      */
 77  
             }
 78  
 
 79  
             // send response
 80  0
             sendResponse(bhs.getInitiatorTaskTag(),// initiatorTaskTag
 81  
                     parser.getExpectedDataTransferLength(),// expectedDataTransferLength
 82  
                     reportLunsParameterData);// responseData
 83  
 
 84  
         }
 85  0
     }
 86  
 
 87  
 }