Introduce scst_get_buf_full_sense() instead of open coded scst_get_buf_full() + setting sense on errors

git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@4409 d57e44dd-8a1f-0410-8b47-8ef2f437770f
This commit is contained in:
Vladislav Bolkhovitin
2012-07-19 02:36:32 +00:00
parent 955113f493
commit a3c5648b29
4 changed files with 65 additions and 97 deletions

View File

@@ -3934,6 +3934,7 @@ static inline int scst_get_out_buf_count(struct scst_cmd *cmd)
}
int scst_get_buf_full(struct scst_cmd *cmd, uint8_t **buf);
int scst_get_buf_full_sense(struct scst_cmd *cmd, uint8_t **buf);
void scst_put_buf_full(struct scst_cmd *cmd, uint8_t *buf);
static inline gfp_t scst_cmd_get_gfp_flags(struct scst_cmd *cmd)

View File

@@ -2129,16 +2129,10 @@ static enum compl_status_e vdisk_exec_inquiry(struct vdisk_cmd_params *p)
goto out;
}
length = scst_get_buf_full(cmd, &address);
length = scst_get_buf_full_sense(cmd, &address);
TRACE_DBG("length %d", length);
if (unlikely(length <= 0)) {
if (length < 0) {
PRINT_ERROR("scst_get_buf_full() failed: %d", length);
scst_set_cmd_error(cmd,
SCST_LOAD_SENSE(scst_sense_hardw_error));
}
if (unlikely(length <= 0))
goto out_free;
}
if (cmd->cdb[1] & CMDDT) {
TRACE_DBG("%s", "INQUIRY: CMDDT is unsupported");
@@ -2465,14 +2459,10 @@ static enum compl_status_e vdisk_exec_request_sense(struct vdisk_cmd_params *p)
sl = scst_set_sense(b, sizeof(b), cmd->dev->d_sense,
SCST_LOAD_SENSE(scst_sense_no_sense));
length = scst_get_buf_full(cmd, &address);
length = scst_get_buf_full_sense(cmd, &address);
TRACE_DBG("length %d", length);
if (length < 0) {
PRINT_ERROR("scst_get_buf_full() failed: %d)", length);
scst_set_cmd_error(cmd,
SCST_LOAD_SENSE(scst_sense_hardw_error));
if (length <= 0)
goto out;
}
length = min(sl, length);
memcpy(address, b, length);
@@ -2658,15 +2648,9 @@ static enum compl_status_e vdisk_exec_mode_sense(struct vdisk_cmd_params *p)
if (type != TYPE_ROM)
dev_spec |= DPOFUA;
length = scst_get_buf_full(cmd, &address);
if (unlikely(length <= 0)) {
if (length < 0) {
PRINT_ERROR("scst_get_buf_full() failed: %d", length);
scst_set_cmd_error(cmd,
SCST_LOAD_SENSE(scst_sense_hardw_error));
}
length = scst_get_buf_full_sense(cmd, &address);
if (unlikely(length <= 0))
goto out_free;
}
if (0x3 == pcontrol) {
TRACE_DBG("%s", "MODE SENSE: Saving values not supported");
@@ -2867,15 +2851,9 @@ static enum compl_status_e vdisk_exec_mode_select(struct vdisk_cmd_params *p)
mselect_6 = (MODE_SELECT == cmd->cdb[0]);
type = cmd->dev->type;
length = scst_get_buf_full(cmd, &address);
if (unlikely(length <= 0)) {
if (length < 0) {
PRINT_ERROR("scst_get_buf_full() failed: %d", length);
scst_set_cmd_error(cmd,
SCST_LOAD_SENSE(scst_sense_hardw_error));
}
length = scst_get_buf_full_sense(cmd, &address);
if (unlikely(length <= 0))
goto out;
}
if (!(cmd->cdb[1] & PF) || (cmd->cdb[1] & SP)) {
TRACE(TRACE_MINOR|TRACE_SCSI, "MODE SELECT: Unsupported "
@@ -3002,15 +2980,9 @@ static enum compl_status_e vdisk_exec_read_capacity(struct vdisk_cmd_params *p)
put_unaligned_be32(blocksize, &buffer[4]);
length = scst_get_buf_full(cmd, &address);
if (unlikely(length <= 0)) {
if (length < 0) {
PRINT_ERROR("scst_get_buf_full() failed: %d", length);
scst_set_cmd_error(cmd,
SCST_LOAD_SENSE(scst_sense_hardw_error));
}
length = scst_get_buf_full_sense(cmd, &address);
if (unlikely(length <= 0))
goto out;
}
length = min_t(int, length, sizeof(buffer));
@@ -3085,15 +3057,9 @@ static enum compl_status_e vdisk_exec_read_capacity16(struct vdisk_cmd_params *p
#endif
}
length = scst_get_buf_full(cmd, &address);
if (unlikely(length <= 0)) {
if (length < 0) {
PRINT_ERROR("scst_get_buf_full() failed: %d", length);
scst_set_cmd_error(cmd,
SCST_LOAD_SENSE(scst_sense_hardw_error));
}
length = scst_get_buf_full_sense(cmd, &address);
if (unlikely(length <= 0))
goto out;
}
length = min_t(int, length, sizeof(buffer));
@@ -3128,13 +3094,9 @@ static enum compl_status_e vdisk_exec_report_tpgs(struct vdisk_cmd_params *p)
TRACE_ENTRY();
buf_len = scst_get_buf_full(cmd, &address);
if (buf_len < 0) {
PRINT_ERROR("scst_get_buf_full() failed: %d", buf_len);
scst_set_cmd_error(cmd,
SCST_LOAD_SENSE(scst_sense_hardw_error));
buf_len = scst_get_buf_full_sense(cmd, &address);
if (buf_len <= 0)
goto out;
}
dev = cmd->dev;
data_format = cmd->cdb[1] >> 5;
@@ -3197,15 +3159,9 @@ static enum compl_status_e vdisk_exec_read_toc(struct vdisk_cmd_params *p)
goto out;
}
length = scst_get_buf_full(cmd, &address);
if (unlikely(length <= 0)) {
if (length < 0) {
PRINT_ERROR("scst_get_buf_full() failed: %d", length);
scst_set_cmd_error(cmd,
SCST_LOAD_SENSE(scst_sense_hardw_error));
}
length = scst_get_buf_full_sense(cmd, &address);
if (unlikely(length <= 0))
goto out;
}
virt_dev = cmd->dev->dh_priv;
/* ToDo when you have > 8TB ROM device. */

View File

@@ -6065,13 +6065,44 @@ out:
}
EXPORT_SYMBOL(scst_get_buf_full);
/**
* scst_get_buf_full_sense - return linear buffer for command
* @cmd: scst command
* @buf: pointer on the resulting pointer
*
* Does the same as scst_get_buf_full(), but in case of error
* additionally sets in cmd status code and sense.
*/
int scst_get_buf_full_sense(struct scst_cmd *cmd, uint8_t **buf)
{
int res = 0;
TRACE_ENTRY();
res = scst_get_buf_full(cmd, buf);
if (unlikely(res < 0)) {
PRINT_ERROR("scst_get_buf_full() failed: %d", res);
if (res == -ENOMEM)
scst_set_busy(cmd);
else
scst_set_cmd_error(cmd,
SCST_LOAD_SENSE(scst_sense_hardw_error));
goto out;
}
out:
TRACE_EXIT_RES(res);
return res;
}
EXPORT_SYMBOL(scst_get_buf_full_sense);
/**
* scst_put_buf_full - unmaps linear buffer for command
* @cmd: scst command
* @buf: pointer on the buffer to unmap
*
* Reverse operation for scst_get_buf_full. If the buffer was vmalloced(),
* it vfree() the buffer.
* Reverse operation for scst_get_buf_full()/scst_get_buf_full_sense().
* If the buffer was vmalloced(), it vfree() the buffer.
*/
void scst_put_buf_full(struct scst_cmd *cmd, uint8_t *buf)
{
@@ -7178,8 +7209,9 @@ int scst_block_generic_dev_done(struct scst_cmd *cmd,
buffer_size = scst_get_buf_full(cmd, &buffer);
if (unlikely(buffer_size <= 0)) {
if (buffer_size < 0) {
PRINT_ERROR("%s: Unable to get the"
" buffer (%d)", __func__, buffer_size);
PRINT_ERROR("%s: Unable to get cmd "
"buffer (%d)", __func__,
buffer_size);
}
goto out;
}
@@ -8533,16 +8565,12 @@ static bool scst_parse_unmap_descriptors(struct scst_cmd *cmd)
EXTRACHECKS_BUG_ON(cmd->cmd_data_descriptors != NULL);
length = scst_get_buf_full(cmd, &address);
length = scst_get_buf_full_sense(cmd, &address);
if (unlikely(length <= 0)) {
if (length == 0)
goto out_put;
else if (length == -ENOMEM)
scst_set_busy(cmd);
else
scst_set_cmd_error(cmd,
SCST_LOAD_SENSE(scst_sense_hardw_error));
goto out_abn;
goto out_abn;
}
total_len = get_unaligned_be16(&cmd->cdb[7]);

View File

@@ -1730,11 +1730,9 @@ static int scst_report_luns_local(struct scst_cmd *cmd)
goto out_err;
}
buffer_size = scst_get_buf_full(cmd, &buffer);
if (unlikely(buffer_size == 0))
buffer_size = scst_get_buf_full_sense(cmd, &buffer);
if (unlikely(buffer_size <= 0))
goto out_compl;
else if (unlikely(buffer_size < 0))
goto out_hw_err;
if (buffer_size < 16)
goto out_put_err;
@@ -1820,10 +1818,6 @@ out_err:
scst_set_cmd_error(cmd,
SCST_LOAD_SENSE(scst_sense_invalid_field_in_cdb));
goto out_compl;
out_hw_err:
scst_set_cmd_error(cmd, SCST_LOAD_SENSE(scst_sense_hardw_error));
goto out_compl;
}
static int scst_request_sense_local(struct scst_cmd *cmd)
@@ -1840,11 +1834,9 @@ static int scst_request_sense_local(struct scst_cmd *cmd)
cmd->host_status = DID_OK;
cmd->driver_status = 0;
buffer_size = scst_get_buf_full(cmd, &buffer);
if (unlikely(buffer_size == 0))
buffer_size = scst_get_buf_full_sense(cmd, &buffer);
if (unlikely(buffer_size <= 0))
goto out_compl;
else if (unlikely(buffer_size < 0))
goto out_hw_err;
memset(buffer, 0, buffer_size);
@@ -1943,10 +1935,6 @@ out:
TRACE_EXIT_RES(res);
return res;
out_hw_err:
scst_set_cmd_error(cmd, SCST_LOAD_SENSE(scst_sense_hardw_error));
goto out_compl;
out_put_busy:
scst_put_buf_full(cmd, buffer);
scst_set_busy(cmd);
@@ -2146,12 +2134,9 @@ static int scst_persistent_reserve_in_local(struct scst_cmd *cmd)
goto out_done;
}
buffer_size = scst_get_buf_full(cmd, &buffer);
if (unlikely(buffer_size <= 0)) {
if (buffer_size < 0)
scst_set_busy(cmd);
buffer_size = scst_get_buf_full_sense(cmd, &buffer);
if (unlikely(buffer_size <= 0))
goto out_done;
}
scst_pr_write_lock(dev);
@@ -2260,12 +2245,9 @@ static int scst_persistent_reserve_out_local(struct scst_cmd *cmd)
goto out_done;
}
buffer_size = scst_get_buf_full(cmd, &buffer);
if (unlikely(buffer_size <= 0)) {
if (buffer_size < 0)
scst_set_busy(cmd);
buffer_size = scst_get_buf_full_sense(cmd, &buffer);
if (unlikely(buffer_size <= 0))
goto out_done;
}
/* Check scope */
if ((action != PR_REGISTER) && (action != PR_REGISTER_AND_IGNORE) &&
@@ -3143,10 +3125,11 @@ static int scst_pre_dev_done(struct scst_cmd *cmd)
address[2] |= 0x80; /* Write Protect*/
else if (length > 3 && cmd->cdb[0] == MODE_SENSE_10)
address[3] |= 0x80; /* Write Protect*/
scst_put_buf_full(cmd, address);
if (err)
goto out;
else
scst_put_buf_full(cmd, address);
}
/*