diff mbox series

[2/3] scsi: Convert SCSI errors to PR_STS errors

Message ID 20221109031106.201324-3-michael.christie@oracle.com
State New
Headers show
Series block/scsi/nvme: Add error codes for PR ops | expand

Commit Message

Mike Christie Nov. 9, 2022, 3:11 a.m. UTC
This converts the SCSI errors we commonly see during PR handling to PT_STS
errors, so pr_ops callers can handle scsi and nvme errors without knowing
the device types.

Signed-off-by: Mike Christie <michael.christie@oracle.com>
---
 drivers/scsi/sd.c | 43 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 42 insertions(+), 1 deletion(-)

Comments

Christoph Hellwig Nov. 9, 2022, 6:52 a.m. UTC | #1
On Tue, Nov 08, 2022 at 09:11:05PM -0600, Mike Christie wrote:
> This converts the SCSI errors we commonly see during PR handling to PT_STS
> errors, so pr_ops callers can handle scsi and nvme errors without knowing
> the device types.

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>
kernel test robot Nov. 10, 2022, 6:59 p.m. UTC | #2
Hi Mike,

I love your patch! Yet something to improve:

[auto build test ERROR on mkp-scsi/for-next]
[also build test ERROR on jejb-scsi/for-next axboe-block/for-next linus/master v6.1-rc4 next-20221110]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Mike-Christie/block-scsi-nvme-Add-error-codes-for-PR-ops/20221109-111514
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next
patch link:    https://lore.kernel.org/r/20221109031106.201324-3-michael.christie%40oracle.com
patch subject: [PATCH 2/3] scsi: Convert SCSI errors to PR_STS errors
config: m68k-randconfig-r021-20221110
compiler: m68k-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/7eba651dd021b92ec4cd153c54b7d92833c327b9
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Mike-Christie/block-scsi-nvme-Add-error-codes-for-PR-ops/20221109-111514
        git checkout 7eba651dd021b92ec4cd153c54b7d92833c327b9
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=m68k SHELL=/bin/bash drivers/ fs//

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   drivers/scsi/sd.c: In function 'sd_scsi_to_block_pr_err':
>> drivers/scsi/sd.c:1723:17: error: implicit declaration of function '__get_status_byte'; did you mean 'get_status_byte'? [-Werror=implicit-function-declaration]
    1723 |         switch (__get_status_byte(result)) {
         |                 ^~~~~~~~~~~~~~~~~
         |                 get_status_byte
   cc1: some warnings being treated as errors


vim +1723 drivers/scsi/sd.c

  1703	
  1704	static enum pr_status sd_scsi_to_block_pr_err(struct scsi_sense_hdr *sshdr,
  1705						      int result)
  1706	{
  1707		enum pr_status sts = PR_STS_IOERR;
  1708	
  1709		switch host_byte(result) {
  1710		case DID_TRANSPORT_MARGINAL:
  1711		case DID_TRANSPORT_DISRUPTED:
  1712		case DID_BUS_BUSY:
  1713			sts = PR_STS_RETRY_PATH_FAILURE;
  1714			goto done;
  1715		case DID_NO_CONNECT:
  1716			sts = PR_STS_PATH_FAILED;
  1717			goto done;
  1718		case DID_TRANSPORT_FAILFAST:
  1719			sts = PR_STS_PATH_FAST_FAILED;
  1720			goto done;
  1721		}
  1722	
> 1723		switch (__get_status_byte(result)) {
  1724		case SAM_STAT_RESERVATION_CONFLICT:
  1725			sts = PR_STS_RESERVATION_CONFLICT;
  1726			goto done;
  1727		case SAM_STAT_CHECK_CONDITION:
  1728			if (!scsi_sense_valid(sshdr))
  1729				goto done;
  1730	
  1731			if (sshdr->sense_key == ILLEGAL_REQUEST &&
  1732			    (sshdr->asc == 0x26 || sshdr->asc == 0x24)) {
  1733				sts = PR_STS_OP_INVALID;
  1734				goto done;
  1735			}
  1736		}
  1737	
  1738	done:
  1739		return sts;
  1740	}
  1741
kernel test robot Nov. 10, 2022, 7:29 p.m. UTC | #3
Hi Mike,

I love your patch! Yet something to improve:

[auto build test ERROR on mkp-scsi/for-next]
[also build test ERROR on jejb-scsi/for-next axboe-block/for-next linus/master v6.1-rc4 next-20221110]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Mike-Christie/block-scsi-nvme-Add-error-codes-for-PR-ops/20221109-111514
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next
patch link:    https://lore.kernel.org/r/20221109031106.201324-3-michael.christie%40oracle.com
patch subject: [PATCH 2/3] scsi: Convert SCSI errors to PR_STS errors
config: x86_64-rhel-8.3-syz
compiler: gcc-11 (Debian 11.3.0-8) 11.3.0
reproduce (this is a W=1 build):
        # https://github.com/intel-lab-lkp/linux/commit/7eba651dd021b92ec4cd153c54b7d92833c327b9
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Mike-Christie/block-scsi-nvme-Add-error-codes-for-PR-ops/20221109-111514
        git checkout 7eba651dd021b92ec4cd153c54b7d92833c327b9
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   drivers/scsi/sd.c: In function 'sd_scsi_to_block_pr_err':
>> drivers/scsi/sd.c:1723:17: error: implicit declaration of function '__get_status_byte'; did you mean 'get_status_byte'? [-Werror=implicit-function-declaration]
    1723 |         switch (__get_status_byte(result)) {
         |                 ^~~~~~~~~~~~~~~~~
         |                 get_status_byte
   cc1: some warnings being treated as errors


vim +1723 drivers/scsi/sd.c

  1703	
  1704	static enum pr_status sd_scsi_to_block_pr_err(struct scsi_sense_hdr *sshdr,
  1705						      int result)
  1706	{
  1707		enum pr_status sts = PR_STS_IOERR;
  1708	
  1709		switch host_byte(result) {
  1710		case DID_TRANSPORT_MARGINAL:
  1711		case DID_TRANSPORT_DISRUPTED:
  1712		case DID_BUS_BUSY:
  1713			sts = PR_STS_RETRY_PATH_FAILURE;
  1714			goto done;
  1715		case DID_NO_CONNECT:
  1716			sts = PR_STS_PATH_FAILED;
  1717			goto done;
  1718		case DID_TRANSPORT_FAILFAST:
  1719			sts = PR_STS_PATH_FAST_FAILED;
  1720			goto done;
  1721		}
  1722	
> 1723		switch (__get_status_byte(result)) {
  1724		case SAM_STAT_RESERVATION_CONFLICT:
  1725			sts = PR_STS_RESERVATION_CONFLICT;
  1726			goto done;
  1727		case SAM_STAT_CHECK_CONDITION:
  1728			if (!scsi_sense_valid(sshdr))
  1729				goto done;
  1730	
  1731			if (sshdr->sense_key == ILLEGAL_REQUEST &&
  1732			    (sshdr->asc == 0x26 || sshdr->asc == 0x24)) {
  1733				sts = PR_STS_OP_INVALID;
  1734				goto done;
  1735			}
  1736		}
  1737	
  1738	done:
  1739		return sts;
  1740	}
  1741
diff mbox series

Patch

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index eb76ba055021..667477d1e4b7 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -1701,6 +1701,44 @@  static char sd_pr_type(enum pr_type type)
 	}
 };
 
+static enum pr_status sd_scsi_to_block_pr_err(struct scsi_sense_hdr *sshdr,
+					      int result)
+{
+	enum pr_status sts = PR_STS_IOERR;
+
+	switch host_byte(result) {
+	case DID_TRANSPORT_MARGINAL:
+	case DID_TRANSPORT_DISRUPTED:
+	case DID_BUS_BUSY:
+		sts = PR_STS_RETRY_PATH_FAILURE;
+		goto done;
+	case DID_NO_CONNECT:
+		sts = PR_STS_PATH_FAILED;
+		goto done;
+	case DID_TRANSPORT_FAILFAST:
+		sts = PR_STS_PATH_FAST_FAILED;
+		goto done;
+	}
+
+	switch (__get_status_byte(result)) {
+	case SAM_STAT_RESERVATION_CONFLICT:
+		sts = PR_STS_RESERVATION_CONFLICT;
+		goto done;
+	case SAM_STAT_CHECK_CONDITION:
+		if (!scsi_sense_valid(sshdr))
+			goto done;
+
+		if (sshdr->sense_key == ILLEGAL_REQUEST &&
+		    (sshdr->asc == 0x26 || sshdr->asc == 0x24)) {
+			sts = PR_STS_OP_INVALID;
+			goto done;
+		}
+	}
+
+done:
+	return sts;
+}
+
 static int sd_pr_command(struct block_device *bdev, u8 sa,
 		u64 key, u64 sa_key, u8 type, u8 flags)
 {
@@ -1729,7 +1767,10 @@  static int sd_pr_command(struct block_device *bdev, u8 sa,
 		scsi_print_sense_hdr(sdev, NULL, &sshdr);
 	}
 
-	return result;
+	if (result <= 0)
+		return result;
+
+	return sd_scsi_to_block_pr_err(&sshdr, result);
 }
 
 static int sd_pr_register(struct block_device *bdev, u64 old_key, u64 new_key,