Let's return error on not block size aligned writes

git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@4532 d57e44dd-8a1f-0410-8b47-8ef2f437770f
This commit is contained in:
Vladislav Bolkhovitin
2012-09-28 21:04:56 +00:00
parent 7110f25138
commit 560383df22
2 changed files with 17 additions and 2 deletions

View File

@@ -303,6 +303,7 @@ static inline int scst_sense_response_code(const uint8_t *sense)
#define scst_sense_saving_params_unsup ILLEGAL_REQUEST, 0x39, 0
#define scst_sense_invalid_message ILLEGAL_REQUEST, 0x49, 0
#define scst_sense_parameter_list_length_invalid ILLEGAL_REQUEST, 0x1A, 0
#define scst_sense_invalid_field_in_command_information_unit ILLEGAL_REQUEST, 0xE, 0x3
/* UNIT_ATTENTION is 6 */
#define scst_sense_medium_changed_UA UNIT_ATTENTION, 0x28, 0

View File

@@ -1545,8 +1545,22 @@ static int scst_tgt_pre_exec(struct scst_cmd *cmd)
do_zero = true;
}
if (do_zero) {
scst_check_restore_sg_buff(cmd);
scst_zero_write_rest(cmd);
if ((cmd->write_len & ((1 << cmd->dev->block_shift) - 1)) == 0) {
scst_check_restore_sg_buff(cmd);
scst_zero_write_rest(cmd);
} else {
/*
* Looks like it's safer in this case to
* return error instead of zeroing
* the rest to prevent initiators lost
* in 4K and 512 bytes blocks, i.e.
* sending commands on 4K blocks devices
* thinking that they have 512 bytes
* blocks, from corrupting data.
*/
scst_set_cmd_error(cmd,
SCST_LOAD_SENSE(scst_sense_invalid_field_in_command_information_unit));
}
}
}
}