Fix handling of MODE SENSE commands in scst_pre_dev_done()

Report the "write protect" flag correctly for read-only devices.

Reported-by: Krzysztof Rusek <rusek@9livesdata.com>


git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@9043 d57e44dd-8a1f-0410-8b47-8ef2f437770f
This commit is contained in:
Bart Van Assche
2020-07-08 14:15:20 +00:00
parent 4b5d66239e
commit fd059b135f
5 changed files with 12 additions and 10 deletions
+1 -1
View File
@@ -5106,7 +5106,7 @@ static inline int scst_get_out_buf_count(struct scst_cmd *cmd)
return (cmd->out_sg_cnt == 0) ? 1 : cmd->out_sg_cnt;
}
int scst_get_buf_full(struct scst_cmd *cmd, uint8_t **buf);
int scst_get_buf_full(struct scst_cmd *cmd, uint8_t **buf, bool always_copy);
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);
+1 -1
View File
@@ -2352,7 +2352,7 @@ static void scst_cm_init_inq_finish(struct scst_cmd *cmd)
goto out;
}
length = scst_get_buf_full(cmd, &buf);
length = scst_get_buf_full(cmd, &buf, false);
TRACE_DBG("length %d", length);
if (unlikely(length <= 0)) {
if (length < 0)
+8 -6
View File
@@ -5953,7 +5953,7 @@ static void scst_complete_request_sense(struct scst_cmd *req_cmd)
sBUG_ON(orig_cmd == NULL);
len = scst_get_buf_full(req_cmd, &buf);
len = scst_get_buf_full(req_cmd, &buf, false);
if (scsi_status_is_good(req_cmd->status) && (len > 0) &&
scst_sense_valid(buf)) {
@@ -9113,12 +9113,13 @@ EXPORT_SYMBOL_GPL(scst_copy_sg);
* scst_get_buf_full - return linear buffer for command
* @cmd: scst command
* @buf: pointer on the resulting pointer
* @always_copy: copy the data buffer even for commands that read data
*
* If the command's buffer >single page, it vmalloc() the needed area
* and copies the buffer there. Returns length of the buffer or negative
* error code otherwise.
*/
int scst_get_buf_full(struct scst_cmd *cmd, uint8_t **buf)
int scst_get_buf_full(struct scst_cmd *cmd, uint8_t **buf, bool always_copy)
{
int res = 0;
@@ -9153,7 +9154,8 @@ int scst_get_buf_full(struct scst_cmd *cmd, uint8_t **buf)
}
cmd->sg_buff_vmallocated = 1;
if (scst_cmd_get_data_direction(cmd) == SCST_DATA_WRITE) {
if (scst_cmd_get_data_direction(cmd) == SCST_DATA_WRITE ||
always_copy) {
uint8_t *buf_ptr;
buf_ptr = *buf;
@@ -9191,7 +9193,7 @@ int scst_get_buf_full_sense(struct scst_cmd *cmd, uint8_t **buf)
TRACE_ENTRY();
res = scst_get_buf_full(cmd, buf);
res = scst_get_buf_full(cmd, buf, false);
if (unlikely(res < 0)) {
PRINT_ERROR("scst_get_buf_full() failed: %d", res);
if (res == -ENOMEM)
@@ -12573,7 +12575,7 @@ int scst_block_generic_dev_done(struct scst_cmd *cmd,
int buffer_size, sector_size, sh;
uint8_t *buffer;
buffer_size = scst_get_buf_full(cmd, &buffer);
buffer_size = scst_get_buf_full(cmd, &buffer, false);
sect_sz_off = opcode == READ_CAPACITY ? 4 : 8;
if (buffer_size < sect_sz_off + 4) {
scst_put_buf_full(cmd, buffer);
@@ -12619,7 +12621,7 @@ int scst_tape_generic_dev_done(struct scst_cmd *cmd,
switch (opcode) {
case MODE_SENSE:
case MODE_SELECT:
buffer_size = scst_get_buf_full(cmd, &buffer);
buffer_size = scst_get_buf_full(cmd, &buffer, false);
if (unlikely(buffer_size <= 0)) {
if (buffer_size < 0) {
PRINT_ERROR("%s: Unable to get the buffer (%d)",
+1 -1
View File
@@ -3299,7 +3299,7 @@ next:
uint8_t *address;
bool err = false;
length = scst_get_buf_full(cmd, &address);
length = scst_get_buf_full(cmd, &address, true);
if (length < 0) {
PRINT_ERROR("%s", "Unable to get "
"MODE_SENSE buffer");
+1 -1
View File
@@ -1839,7 +1839,7 @@ int scst_tg_set_group_info(struct scst_cmd *cmd)
TRACE_ENTRY();
len = scst_get_buf_full(cmd, &buf);
len = scst_get_buf_full(cmd, &buf, false);
if (len < 0) {
PRINT_ERROR("scst_get_buf_full() failed: %d", len);
res = len;