Re: [PATCH 3/4] aacraid: use blk_mq_rq_busy_iter() for traversing outstanding commands

Bart Van Assche
2019-11-01T15:34:45Z

On 11/1/19 4:18 AM, Hannes Reinecke wrote:
> +static bool synchronize_busy_iter(struct request *req, void *data, bool reserved)
> +{
> + struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(req);
> + struct synchronize_busy_data *busy_data = data;
> +
> + if (busy_data->sdev == cmd->device &&
> + cmd->SCp.phase == AAC_OWNER_FIRMWARE) {
> + u64 cmnd_lba;
> + u32 cmnd_count;
> +
> + if (cmd->cmnd[0] == WRITE_6) {
> + cmnd_lba = ((cmd->cmnd[1] & 0x1F) << 16) |
> + (cmd->cmnd[2] << 8) |
> + cmd->cmnd[3];
> + cmnd_count = cmd->cmnd[4];
> + if (cmnd_count == 0)
> + cmnd_count = 256;
> + } else if (cmd->cmnd[0] == WRITE_16) {
> + cmnd_lba = ((u64)cmd->cmnd[2] << 56) |
> + ((u64)cmd->cmnd[3] << 48) |
> + ((u64)cmd->cmnd[4] << 40) |
> + ((u64)cmd->cmnd[5] << 32) |
> + ((u64)cmd->cmnd[6] << 24) |
> + (cmd->cmnd[7] << 16) |
> + (cmd->cmnd[8] << 8) |
> + cmd->cmnd[9];
> + cmnd_count = (cmd->cmnd[10] << 24) |
> + (cmd->cmnd[11] << 16) |
> + (cmd->cmnd[12] << 8) |
> + cmd->cmnd[13];
> + } else if (cmd->cmnd[0] == WRITE_12) {
> + cmnd_lba = ((u64)cmd->cmnd[2] << 24) |
> + (cmd->cmnd[3] << 16) |
> + (cmd->cmnd[4] << 8) |
> + cmd->cmnd[5];
> + cmnd_count = (cmd->cmnd[6] << 24) |
> + (cmd->cmnd[7] << 16) |
> + (cmd->cmnd[8] << 8) |
> + cmd->cmnd[9];
> + } else if (cmd->cmnd[0] == WRITE_10) {
> + cmnd_lba = ((u64)cmd->cmnd[2] << 24) |
> + (cmd->cmnd[3] << 16) |
> + (cmd->cmnd[4] << 8) |
> + cmd->cmnd[5];
> + cmnd_count = (cmd->cmnd[7] << 8) |
> + cmd->cmnd[8];
> + } else
> + return true;

The above code looks very similar to the code in scsi_trace.c. Although
SCSI LLDs shouldn't parse CDBs, there are a few SCSI LLDs that do this.
Would it be worth it to introduce a function in the SCSI core that
extracts the most important fields from a CDB (LBA, data buffer size, ...)?

Bart.