scsi: simplify scsi_log_(send|completion)
authorHannes Reinecke <hare@suse.de>
Fri, 24 Oct 2014 12:27:01 +0000 (14:27 +0200)
committerChristoph Hellwig <hch@lst.de>
Wed, 12 Nov 2014 10:16:05 +0000 (11:16 +0100)
Simplify scsi_log_(send|completion) by externalizing
scsi_mlreturn_string() and always print the command address.

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
drivers/scsi/scsi.c
drivers/scsi/scsi_lib.c
drivers/scsi/scsi_logging.h
include/scsi/scsi_dbg.h

index 2893464129b5ca7219b5cdb12c041e9a68d8e742..0cf43f6e464b19e9148b4d69699ba8c83b79b773 100644 (file)
@@ -1440,19 +1440,54 @@ const char *scsi_driverbyte_string(int result)
 }
 EXPORT_SYMBOL(scsi_driverbyte_string);
 
-void scsi_print_result(struct scsi_cmnd *cmd)
+#ifdef CONFIG_SCSI_CONSTANTS
+#define scsi_mlreturn_name(result)     { result, #result }
+static const struct value_name_pair scsi_mlreturn_arr[] = {
+       scsi_mlreturn_name(NEEDS_RETRY),
+       scsi_mlreturn_name(SUCCESS),
+       scsi_mlreturn_name(FAILED),
+       scsi_mlreturn_name(QUEUED),
+       scsi_mlreturn_name(SOFT_ERROR),
+       scsi_mlreturn_name(ADD_TO_MLQUEUE),
+       scsi_mlreturn_name(TIMEOUT_ERROR),
+       scsi_mlreturn_name(SCSI_RETURN_NOT_HANDLED),
+       scsi_mlreturn_name(FAST_IO_FAIL)
+};
+#endif
+
+const char *scsi_mlreturn_string(int result)
+{
+#ifdef CONFIG_SCSI_CONSTANTS
+       const struct value_name_pair *arr = scsi_mlreturn_arr;
+       int k;
+
+       for (k = 0; k < ARRAY_SIZE(scsi_mlreturn_arr); ++k, ++arr) {
+               if (result == arr->value)
+                       return arr->name;
+       }
+#endif
+       return NULL;
+}
+EXPORT_SYMBOL(scsi_mlreturn_string);
+
+void scsi_print_result(struct scsi_cmnd *cmd, const char *msg, int disposition)
 {
+       const char *mlret_string = scsi_mlreturn_string(disposition);
        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",
+                           "%s%s Result: hostbyte=%s driverbyte=%s",
+                           msg ? msg : "",
+                           mlret_string ? mlret_string : "UNKNOWN",
                            hb_string ? hb_string : "invalid",
                            db_string ? db_string : "invalid");
        else
                scmd_printk(KERN_INFO, cmd,
-                           "Result: hostbyte=0x%02x driverbyte=0x%02x",
+                           "%s%s Result: hostbyte=0x%02x driverbyte=0x%02x",
+                           msg ? msg : "",
+                           mlret_string ? mlret_string : "UNKNOWN",
                            host_byte(cmd->result), driver_byte(cmd->result));
 }
 EXPORT_SYMBOL(scsi_print_result);
index 32eaac03cf4e4fcf4d08506069c3e9a0e9eebb99..bc52bbd973813c6cd73da0f7d7d5f3457d8d3715 100644 (file)
@@ -527,9 +527,9 @@ void scsi_log_send(struct scsi_cmnd *cmd)
         *
         * 1: nothing (match completion)
         *
-        * 2: log opcode + command of all commands
+        * 2: log opcode + command of all commands + cmd address
         *
-        * 3: same as 2 plus dump cmd address
+        * 3: same as 2
         *
         * 4: same as 3 plus dump extra junk
         */
@@ -537,10 +537,8 @@ void scsi_log_send(struct scsi_cmnd *cmd)
                level = SCSI_LOG_LEVEL(SCSI_LOG_MLQUEUE_SHIFT,
                                       SCSI_LOG_MLQUEUE_BITS);
                if (level > 1) {
-                       scmd_printk(KERN_INFO, cmd, "Send: ");
-                       if (level > 2)
-                               printk("0x%p ", cmd);
-                       printk("\n");
+                       scmd_printk(KERN_INFO, cmd,
+                                   "Send: scmd 0x%p\n", cmd);
                        scsi_print_command(cmd);
                        if (level > 3) {
                                printk(KERN_INFO "buffer = 0x%p, bufflen = %d,"
@@ -565,7 +563,7 @@ void scsi_log_completion(struct scsi_cmnd *cmd, int disposition)
         *
         * 2: same as 1 but for all command completions.
         *
-        * 3: same as 2 plus dump cmd address
+        * 3: same as 2
         *
         * 4: same as 3 plus dump extra junk
         */
@@ -574,36 +572,7 @@ void scsi_log_completion(struct scsi_cmnd *cmd, int disposition)
                                       SCSI_LOG_MLCOMPLETE_BITS);
                if (((level > 0) && (cmd->result || disposition != SUCCESS)) ||
                    (level > 1)) {
-                       scmd_printk(KERN_INFO, cmd, "Done: ");
-                       if (level > 2)
-                               printk("0x%p ", cmd);
-                       /*
-                        * Dump truncated values, so we usually fit within
-                        * 80 chars.
-                        */
-                       switch (disposition) {
-                       case SUCCESS:
-                               printk("SUCCESS\n");
-                               break;
-                       case NEEDS_RETRY:
-                               printk("RETRY\n");
-                               break;
-                       case ADD_TO_MLQUEUE:
-                               printk("MLQUEUE\n");
-                               break;
-                       case FAILED:
-                               printk("FAILED\n");
-                               break;
-                       case TIMEOUT_ERROR:
-                               /* 
-                                * If called via scsi_times_out.
-                                */
-                               printk("TIMEOUT\n");
-                               break;
-                       default:
-                               printk("UNKNOWN\n");
-                       }
-                       scsi_print_result(cmd);
+                       scsi_print_result(cmd, "Done: ", disposition);
                        scsi_print_command(cmd);
                        if (status_byte(cmd->result) & CHECK_CONDITION)
                                scsi_print_sense(cmd);
index 30f51c11a279be7ec614dc857334a693bd7fa2a7..26a57faf885b33f87693bcc9f84e6bed42ce058f 100644 (file)
@@ -832,7 +832,7 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
        int error = 0;
        struct scsi_sense_hdr sshdr;
        bool sense_valid = false;
-       int sense_deferred = 0;
+       int sense_deferred = 0, level = 0;
        enum {ACTION_FAIL, ACTION_REPREP, ACTION_RETRY,
              ACTION_DELAYED_RETRY} action;
        unsigned long wait_for = (cmd->allowed + 1) * req->timeout;
@@ -1038,8 +1038,15 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
        switch (action) {
        case ACTION_FAIL:
                /* Give up and fail the remainder of the request */
-               if (!(req->cmd_flags & REQ_QUIET)) {
-                       scsi_print_result(cmd);
+               if (unlikely(scsi_logging_level))
+                       level = SCSI_LOG_LEVEL(SCSI_LOG_MLQUEUE_SHIFT,
+                                              SCSI_LOG_MLQUEUE_BITS);
+               /*
+                * if logging is enabled the failure will be printed
+                * in scsi_log_completion(), so avoid duplicate messages
+                */
+               if (!level && !(req->cmd_flags & REQ_QUIET)) {
+                       scsi_print_result(cmd, NULL, FAILED);
                        if (driver_byte(result) & DRIVER_SENSE)
                                scsi_print_sense(cmd);
                        scsi_print_command(cmd);
index 1f65139e14f8d3e9dc470c696c1e3aedabf344a8..7fe64a847143132be478030b4fdffd7dde5418ac 100644 (file)
@@ -51,6 +51,7 @@ do {                                                          \
                } while (0);                                    \
 } while (0)
 #else
+#define SCSI_LOG_LEVEL(SHIFT, BITS) 0
 #define SCSI_CHECK_LOGGING(SHIFT, BITS, LEVEL, CMD)
 #endif /* CONFIG_SCSI_LOGGING */
 
index f41a86bc1a8f9b73f556d6dcd5bf639f30586c17..7982795df59592d8219e9ec6c4b5102b0593214d 100644 (file)
@@ -17,9 +17,10 @@ extern void scsi_print_sense(const struct scsi_cmnd *);
 extern void __scsi_print_sense(const struct scsi_device *, const char *name,
                               const unsigned char *sense_buffer,
                               int sense_len);
-extern void scsi_print_result(struct scsi_cmnd *);
+extern void scsi_print_result(struct scsi_cmnd *, const char *, int);
 extern const char *scsi_hostbyte_string(int);
 extern const char *scsi_driverbyte_string(int);
+extern const char *scsi_mlreturn_string(int);
 extern const char *scsi_sense_key_string(unsigned char);
 extern const char *scsi_extd_sense_format(unsigned char, unsigned char,
                                          const char **);