On Tue, 2012-11-06 at 16:06 -0800, Nicholas A. Bellinger wrote: > On Tue, 2012-10-30 at 11:07 -0400, Christoph Hellwig wrote: > > Pass the sense reason as an explicit return value from the I/O submission > > path instead of storing it in struct se_cmd and using negative return > > values. This cleans up a lot of the code pathes, and with the sparse > > annotations for the new sense_reason_t type allows for much better > > error checking. > > > > Signed-off-by: Christoph Hellwig <hch@xxxxxx> > > > > Hey Christoph, > > Just getting back to this for-3.8 code.. Comments below. <SNIP> > > > > -static int spc_emulate_modesense(struct se_cmd *cmd) > > +static sense_reason_t > > +spc_emulate_modesense(struct se_cmd *cmd) > > { > > struct se_device *dev = cmd->se_dev; > > char *cdb = cmd->t_task_cdb; > > @@ -798,8 +809,7 @@ static int spc_emulate_modesense(struct > > default: > > pr_err("MODE SENSE: unimplemented page/subpage: 0x%02x/0x%02x\n", > > cdb[2] & 0x3f, cdb[3]); > > - cmd->scsi_sense_reason = TCM_UNKNOWN_MODE_PAGE; > > - return -EINVAL; > > + return TCM_UNKNOWN_MODE_PAGE; > > } > > offset += length; > > > > @@ -833,16 +843,18 @@ static int spc_emulate_modesense(struct > > } > > > > rbuf = transport_kmap_data_sg(cmd); > > - if (rbuf) { > > - memcpy(rbuf, buf, min(offset, cmd->data_length)); > > - transport_kunmap_data_sg(cmd); > > - } > > + if (!rbuf) > > + return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; > > + > > + memcpy(rbuf, buf, min(offset, cmd->data_length)); > > + transport_kunmap_data_sg(cmd); > > > > target_complete_cmd(cmd, GOOD); > > return 0; > > } > > > > Ok, this part conflicts with Roland's for-3.8 patch: > > commit 717e44956bc230bca54a4e044ec4b1a4a8438e09 > Author: Roland Dreier <roland@xxxxxxxxxxxxxxx> > Date: Wed Oct 31 09:16:50 2012 -0700 > > target: Add emulation for MODE SELECT > > Fixing up the minor breakage here, and folding into your original patch. > Btw, here's the patch that is being folded into the original to work with Roland's MODE SELECT emulation changes. Thanks, --nab diff --git a/drivers/target/target_core_spc.c b/drivers/target/target_core_spc.c index e43e558..40d9631 100644 --- a/drivers/target/target_core_spc.c +++ b/drivers/target/target_core_spc.c @@ -859,7 +859,8 @@ static sense_reason_t spc_emulate_modesense(struct se_cmd *cmd) int i; map_buf = transport_kmap_data_sg(cmd); - + if (!map_buf) + return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; /* * If SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC is not set, then we * know we actually allocated a full page. Otherwise, if the @@ -928,6 +929,7 @@ static sense_reason_t spc_emulate_modesense(struct se_cmd *cmd) if (page == 0x3f) { if (subpage != 0x00 && subpage != 0xff) { pr_warn("MODE_SENSE: Invalid subpage code: 0x%02x\n", subpage); + kfree(buf); transport_kunmap_data_sg(cmd); return TCM_INVALID_CDB_FIELD; } @@ -974,7 +976,6 @@ set_length: else buf[0] = length - 1; -out: if (buf != map_buf) { memcpy(map_buf, buf, cmd->data_length); kfree(buf); @@ -985,7 +986,7 @@ out: return 0; } -static int spc_emulate_modeselect(struct se_cmd *cmd) +static sense_reason_t spc_emulate_modeselect(struct se_cmd *cmd) { struct se_device *dev = cmd->se_dev; char *cdb = cmd->t_task_cdb; @@ -1000,10 +1001,11 @@ static int spc_emulate_modeselect(struct se_cmd *cmd) int i; buf = transport_kmap_data_sg(cmd); + if (!buf) + return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; if (!pf) { - cmd->scsi_sense_reason = TCM_INVALID_CDB_FIELD; - ret = -EINVAL; + ret = TCM_INVALID_CDB_FIELD; goto out; } @@ -1018,15 +1020,12 @@ static int spc_emulate_modeselect(struct se_cmd *cmd) goto check_contents; } - cmd->scsi_sense_reason = TCM_UNKNOWN_MODE_PAGE; - ret = -EINVAL; + ret = TCM_UNKNOWN_MODE_PAGE; goto out; check_contents: - if (memcmp(buf + off, tbuf, length)) { - cmd->scsi_sense_reason = TCM_INVALID_PARAMETER_LIST; - ret = -EINVAL; - } + if (memcmp(buf + off, tbuf, length)) + ret = TCM_INVALID_PARAMETER_LIST; out: transport_kunmap_data_sg(cmd); @@ -1036,7 +1035,7 @@ out: return ret; } -static int spc_emulate_request_sense(struct se_cmd *cmd) +static sense_reason_t spc_emulate_request_sense(struct se_cmd *cmd) { unsigned char *cdb = cmd->t_task_cdb; unsigned char *rbuf; -- To unsubscribe from this list: send the line "unsubscribe target-devel" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html