scsi: separate out scsi_(host|driver)byte_string()
authorHannes Reinecke <hare@suse.de>
Fri, 24 Oct 2014 12:26:59 +0000 (14:26 +0200)
committerChristoph Hellwig <hch@lst.de>
Wed, 12 Nov 2014 10:16:04 +0000 (11:16 +0100)
Export functions for later use.

Signed-off-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Robert Elliott <elliott@hp.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
drivers/scsi/constants.c
include/scsi/scsi_dbg.h

index a84ced0de02b3e7b3638c86093e27be530445d88..541a8620929cc696703b46bc06447bdf1463abcb 100644 (file)
@@ -1407,38 +1407,68 @@ static const char * const hostbyte_table[]={
 "DID_PASSTHROUGH", "DID_SOFT_ERROR", "DID_IMM_RETRY", "DID_REQUEUE",
 "DID_TRANSPORT_DISRUPTED", "DID_TRANSPORT_FAILFAST", "DID_TARGET_FAILURE",
 "DID_NEXUS_FAILURE" };
-#define NUM_HOSTBYTE_STRS ARRAY_SIZE(hostbyte_table)
 
 static const char * const driverbyte_table[]={
 "DRIVER_OK", "DRIVER_BUSY", "DRIVER_SOFT",  "DRIVER_MEDIA", "DRIVER_ERROR",
 "DRIVER_INVALID", "DRIVER_TIMEOUT", "DRIVER_HARD", "DRIVER_SENSE"};
-#define NUM_DRIVERBYTE_STRS ARRAY_SIZE(driverbyte_table)
 
-void scsi_show_result(int result)
+#endif
+
+const char *scsi_hostbyte_string(int result)
 {
+       const char *hb_string = NULL;
+#ifdef CONFIG_SCSI_CONSTANTS
        int hb = host_byte(result);
-       int db = driver_byte(result);
 
-       printk("Result: hostbyte=%s driverbyte=%s\n",
-              (hb < NUM_HOSTBYTE_STRS ? hostbyte_table[hb]     : "invalid"),
-              (db < NUM_DRIVERBYTE_STRS ? driverbyte_table[db] : "invalid"));
+       if (hb < ARRAY_SIZE(hostbyte_table))
+               hb_string = hostbyte_table[hb];
+#endif
+       return hb_string;
 }
+EXPORT_SYMBOL(scsi_hostbyte_string);
 
-#else
+const char *scsi_driverbyte_string(int result)
+{
+       const char *db_string = NULL;
+#ifdef CONFIG_SCSI_CONSTANTS
+       int db = driver_byte(result);
+
+       if (db < ARRAY_SIZE(driverbyte_table))
+               db_string = driverbyte_table[db];
+#endif
+       return db_string;
+}
+EXPORT_SYMBOL(scsi_driverbyte_string);
 
 void scsi_show_result(int result)
 {
-       printk("Result: hostbyte=0x%02x driverbyte=0x%02x\n",
-              host_byte(result), driver_byte(result));
-}
+       const char *hb_string = scsi_hostbyte_string(result);
+       const char *db_string = scsi_driverbyte_string(result);
 
-#endif
+       if (hb_string || db_string)
+               printk("Result: hostbyte=%s driverbyte=%s\n",
+                      hb_string ? hb_string : "invalid",
+                      db_string ? db_string : "invalid");
+       else
+               printk("Result: hostbyte=0x%02x driverbyte=0x%02x\n",
+                      host_byte(result), driver_byte(result));
+}
 EXPORT_SYMBOL(scsi_show_result);
 
 
 void scsi_print_result(struct scsi_cmnd *cmd)
 {
-       scmd_printk(KERN_INFO, cmd, " ");
-       scsi_show_result(cmd->result);
+       const char *hb_string = scsi_hostbyte_string(cmd->result);
+       const char *db_string = scsi_driverbyte_string(cmd->result);
+
+       if (hb_string || db_string)
+               scmd_printk(KERN_INFO, cmd,
+                           "Result: hostbyte=%s driverbyte=%s",
+                           hb_string ? hb_string : "invalid",
+                           db_string ? db_string : "invalid");
+       else
+               scmd_printk(KERN_INFO, cmd,
+                           "Result: hostbyte=0x%02x driverbyte=0x%02x",
+                           host_byte(cmd->result), driver_byte(cmd->result));
 }
 EXPORT_SYMBOL(scsi_print_result);
index 81d04182222955cdf0e92ba62e55ed27cb1c5723..50f4d8542eced4438fe374991223f64108152618 100644 (file)
@@ -19,6 +19,8 @@ extern void __scsi_print_sense(const struct scsi_device *, const char *name,
                               int sense_len);
 extern void scsi_show_result(int);
 extern void scsi_print_result(struct scsi_cmnd *);
+extern const char *scsi_hostbyte_string(int);
+extern const char *scsi_driverbyte_string(int);
 extern const char *scsi_sense_key_string(unsigned char);
 extern const char *scsi_extd_sense_format(unsigned char, unsigned char,
                                          const char **);