[SCSI] zfcp: fix logging during device reset

Avoid access to old fsf_requests if device reset is logged.

Signed-off-by: Maxim Shchetynin <maxim@de.ibm.com>
Signed-off-by: Andreas Herrmann <aherrman@de.ibm.com>
Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>

authored by Maxim Shchetynin and committed by ed829ad6 2f8f3ed5

+47 -61
+30 -46
drivers/s390/scsi/zfcp_dbf.c
··· 710 710 _zfcp_scsi_dbf_event_common(const char *tag, const char *tag2, int level, 711 711 struct zfcp_adapter *adapter, 712 712 struct scsi_cmnd *scsi_cmnd, 713 - struct zfcp_fsf_req *new_fsf_req) 713 + struct zfcp_fsf_req *fsf_req, 714 + struct zfcp_fsf_req *old_fsf_req) 714 715 { 715 - struct zfcp_fsf_req *fsf_req = 716 - (struct zfcp_fsf_req *)scsi_cmnd->host_scribble; 717 716 struct zfcp_scsi_dbf_record *rec = &adapter->scsi_dbf_buf; 718 717 struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)rec; 719 718 unsigned long flags; ··· 726 727 if (offset == 0) { 727 728 strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE); 728 729 strncpy(rec->tag2, tag2, ZFCP_DBF_TAG_SIZE); 729 - if (scsi_cmnd->device) { 730 - rec->scsi_id = scsi_cmnd->device->id; 731 - rec->scsi_lun = scsi_cmnd->device->lun; 730 + if (scsi_cmnd != NULL) { 731 + if (scsi_cmnd->device) { 732 + rec->scsi_id = scsi_cmnd->device->id; 733 + rec->scsi_lun = scsi_cmnd->device->lun; 734 + } 735 + rec->scsi_result = scsi_cmnd->result; 736 + rec->scsi_cmnd = (unsigned long)scsi_cmnd; 737 + rec->scsi_serial = scsi_cmnd->serial_number; 738 + memcpy(rec->scsi_opcode, &scsi_cmnd->cmnd, 739 + min((int)scsi_cmnd->cmd_len, 740 + ZFCP_DBF_SCSI_OPCODE)); 741 + rec->scsi_retries = scsi_cmnd->retries; 742 + rec->scsi_allowed = scsi_cmnd->allowed; 732 743 } 733 - rec->scsi_result = scsi_cmnd->result; 734 - rec->scsi_cmnd = (unsigned long)scsi_cmnd; 735 - rec->scsi_serial = scsi_cmnd->serial_number; 736 - memcpy(rec->scsi_opcode, 737 - &scsi_cmnd->cmnd, 738 - min((int)scsi_cmnd->cmd_len, 739 - ZFCP_DBF_SCSI_OPCODE)); 740 - rec->scsi_retries = scsi_cmnd->retries; 741 - rec->scsi_allowed = scsi_cmnd->allowed; 742 744 if (fsf_req != NULL) { 743 745 fcp_rsp = (struct fcp_rsp_iu *) 744 746 &(fsf_req->qtcb->bottom.io.fcp_rsp); ··· 772 772 rec->fsf_seqno = fsf_req->seq_no; 773 773 rec->fsf_issued = fsf_req->issued; 774 774 } 775 - if (new_fsf_req != NULL) { 776 - rec->type.new_fsf_req.fsf_reqid = 777 - (unsigned long) 778 - new_fsf_req; 779 - rec->type.new_fsf_req.fsf_seqno = 780 - new_fsf_req->seq_no; 781 - rec->type.new_fsf_req.fsf_issued = 782 - new_fsf_req->issued; 783 - } 775 + rec->type.old_fsf_reqid = 776 + (unsigned long) old_fsf_req; 784 777 } else { 785 778 strncpy(dump->tag, "dump", ZFCP_DBF_TAG_SIZE); 786 779 dump->total_size = buflen; ··· 794 801 inline void 795 802 zfcp_scsi_dbf_event_result(const char *tag, int level, 796 803 struct zfcp_adapter *adapter, 797 - struct scsi_cmnd *scsi_cmnd) 804 + struct scsi_cmnd *scsi_cmnd, 805 + struct zfcp_fsf_req *fsf_req) 798 806 { 799 - _zfcp_scsi_dbf_event_common("rslt", 800 - tag, level, adapter, scsi_cmnd, NULL); 807 + _zfcp_scsi_dbf_event_common("rslt", tag, level, 808 + adapter, scsi_cmnd, fsf_req, NULL); 801 809 } 802 810 803 811 inline void 804 812 zfcp_scsi_dbf_event_abort(const char *tag, struct zfcp_adapter *adapter, 805 813 struct scsi_cmnd *scsi_cmnd, 806 - struct zfcp_fsf_req *new_fsf_req) 814 + struct zfcp_fsf_req *new_fsf_req, 815 + struct zfcp_fsf_req *old_fsf_req) 807 816 { 808 - _zfcp_scsi_dbf_event_common("abrt", 809 - tag, 1, adapter, scsi_cmnd, new_fsf_req); 817 + _zfcp_scsi_dbf_event_common("abrt", tag, 1, 818 + adapter, scsi_cmnd, new_fsf_req, old_fsf_req); 810 819 } 811 820 812 821 inline void ··· 818 823 struct zfcp_adapter *adapter = unit->port->adapter; 819 824 820 825 _zfcp_scsi_dbf_event_common(flag == FCP_TARGET_RESET ? "trst" : "lrst", 821 - tag, 1, adapter, scsi_cmnd, NULL); 826 + tag, 1, adapter, scsi_cmnd, NULL, NULL); 822 827 } 823 828 824 829 static int ··· 851 856 rec->scsi_retries); 852 857 len += zfcp_dbf_view(out_buf + len, "scsi_allowed", "0x%02x", 853 858 rec->scsi_allowed); 859 + if (strncmp(rec->tag, "abrt", ZFCP_DBF_TAG_SIZE) == 0) { 860 + len += zfcp_dbf_view(out_buf + len, "old_fsf_reqid", "0x%0Lx", 861 + rec->type.old_fsf_reqid); 862 + } 854 863 len += zfcp_dbf_view(out_buf + len, "fsf_reqid", "0x%0Lx", 855 864 rec->fsf_reqid); 856 865 len += zfcp_dbf_view(out_buf + len, "fsf_seqno", "0x%08x", ··· 882 883 min((int)rec->type.fcp.sns_info_len, 883 884 ZFCP_DBF_SCSI_FCP_SNS_INFO), 0, 884 885 rec->type.fcp.sns_info_len); 885 - } else if (strncmp(rec->tag, "abrt", ZFCP_DBF_TAG_SIZE) == 0) { 886 - len += zfcp_dbf_view(out_buf + len, "fsf_reqid_abort", "0x%0Lx", 887 - rec->type.new_fsf_req.fsf_reqid); 888 - len += zfcp_dbf_view(out_buf + len, "fsf_seqno_abort", "0x%08x", 889 - rec->type.new_fsf_req.fsf_seqno); 890 - len += zfcp_dbf_stck(out_buf + len, "fsf_issued", 891 - rec->type.new_fsf_req.fsf_issued); 892 - } else if ((strncmp(rec->tag, "trst", ZFCP_DBF_TAG_SIZE) == 0) || 893 - (strncmp(rec->tag, "lrst", ZFCP_DBF_TAG_SIZE) == 0)) { 894 - len += zfcp_dbf_view(out_buf + len, "fsf_reqid_reset", "0x%0Lx", 895 - rec->type.new_fsf_req.fsf_reqid); 896 - len += zfcp_dbf_view(out_buf + len, "fsf_seqno_reset", "0x%08x", 897 - rec->type.new_fsf_req.fsf_seqno); 898 - len += zfcp_dbf_stck(out_buf + len, "fsf_issued", 899 - rec->type.new_fsf_req.fsf_issued); 900 886 } 901 887 902 888 len += sprintf(out_buf + len, "\n");
+1 -5
drivers/s390/scsi/zfcp_def.h
··· 424 424 u32 fsf_seqno; 425 425 u64 fsf_issued; 426 426 union { 427 - struct { 428 - u64 fsf_reqid; 429 - u32 fsf_seqno; 430 - u64 fsf_issued; 431 - } new_fsf_req; 427 + u64 old_fsf_reqid; 432 428 struct { 433 429 u8 rsp_validity; 434 430 u8 rsp_scsi_status;
+3 -2
drivers/s390/scsi/zfcp_ext.h
··· 194 194 extern void zfcp_san_dbf_event_incoming_els(struct zfcp_fsf_req *); 195 195 196 196 extern void zfcp_scsi_dbf_event_result(const char *, int, struct zfcp_adapter *, 197 - struct scsi_cmnd *); 197 + struct scsi_cmnd *, 198 + struct zfcp_fsf_req *); 198 199 extern void zfcp_scsi_dbf_event_abort(const char *, struct zfcp_adapter *, 199 - struct scsi_cmnd *, 200 + struct scsi_cmnd *, struct zfcp_fsf_req *, 200 201 struct zfcp_fsf_req *); 201 202 extern void zfcp_scsi_dbf_event_devreset(const char *, u8, struct zfcp_unit *, 202 203 struct scsi_cmnd *);
+3 -3
drivers/s390/scsi/zfcp_fsf.c
··· 4211 4211 ZFCP_LOG_DEBUG("scpnt->result =0x%x\n", scpnt->result); 4212 4212 4213 4213 if (scpnt->result != 0) 4214 - zfcp_scsi_dbf_event_result("erro", 3, fsf_req->adapter, scpnt); 4214 + zfcp_scsi_dbf_event_result("erro", 3, fsf_req->adapter, scpnt, fsf_req); 4215 4215 else if (scpnt->retries > 0) 4216 - zfcp_scsi_dbf_event_result("retr", 4, fsf_req->adapter, scpnt); 4216 + zfcp_scsi_dbf_event_result("retr", 4, fsf_req->adapter, scpnt, fsf_req); 4217 4217 else 4218 - zfcp_scsi_dbf_event_result("norm", 6, fsf_req->adapter, scpnt); 4218 + zfcp_scsi_dbf_event_result("norm", 6, fsf_req->adapter, scpnt, fsf_req); 4219 4219 4220 4220 /* cleanup pointer (need this especially for abort) */ 4221 4221 scpnt->host_scribble = NULL;
+10 -5
drivers/s390/scsi/zfcp_scsi.c
··· 242 242 if ((scpnt->device != NULL) && (scpnt->device->host != NULL)) 243 243 zfcp_scsi_dbf_event_result("fail", 4, 244 244 (struct zfcp_adapter*) scpnt->device->host->hostdata[0], 245 - scpnt); 245 + scpnt, NULL); 246 246 /* return directly */ 247 247 scpnt->scsi_done(scpnt); 248 248 } ··· 446 446 old_fsf_req = (struct zfcp_fsf_req *) scpnt->host_scribble; 447 447 if (!old_fsf_req) { 448 448 write_unlock_irqrestore(&adapter->abort_lock, flags); 449 - zfcp_scsi_dbf_event_abort("lte1", adapter, scpnt, new_fsf_req); 449 + zfcp_scsi_dbf_event_abort("lte1", adapter, scpnt, NULL, NULL); 450 450 retval = SUCCESS; 451 451 goto out; 452 452 } ··· 460 460 adapter, unit, 0); 461 461 if (!new_fsf_req) { 462 462 ZFCP_LOG_INFO("error: initiation of Abort FCP Cmnd failed\n"); 463 + zfcp_scsi_dbf_event_abort("nres", adapter, scpnt, NULL, 464 + old_fsf_req); 463 465 retval = FAILED; 464 466 goto out; 465 467 } ··· 472 470 473 471 /* status should be valid since signals were not permitted */ 474 472 if (new_fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED) { 475 - zfcp_scsi_dbf_event_abort("okay", adapter, scpnt, new_fsf_req); 473 + zfcp_scsi_dbf_event_abort("okay", adapter, scpnt, new_fsf_req, 474 + NULL); 476 475 retval = SUCCESS; 477 476 } else if (new_fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED) { 478 - zfcp_scsi_dbf_event_abort("lte2", adapter, scpnt, new_fsf_req); 477 + zfcp_scsi_dbf_event_abort("lte2", adapter, scpnt, new_fsf_req, 478 + NULL); 479 479 retval = SUCCESS; 480 480 } else { 481 - zfcp_scsi_dbf_event_abort("fail", adapter, scpnt, new_fsf_req); 481 + zfcp_scsi_dbf_event_abort("fail", adapter, scpnt, new_fsf_req, 482 + NULL); 482 483 retval = FAILED; 483 484 } 484 485 zfcp_fsf_req_free(new_fsf_req);