scsi_error.c
来自「Linux Kernel 2.6.9 for OMAP1710」· C语言 代码 · 共 1,846 行 · 第 1/4 页
C
1,846 行
scmd->owner = SCSI_OWNER_LOWLEVEL; if (scmd->device->scsi_level <= SCSI_2) scmd->cmnd[1] = (scmd->cmnd[1] & 0x1f) | (scmd->device->lun << 5 & 0xe0); scsi_add_timer(scmd, timeout, scsi_eh_times_out); /* * set up the semaphore so we wait for the command to complete. */ scmd->device->host->eh_action = &sem; scmd->request->rq_status = RQ_SCSI_BUSY; spin_lock_irqsave(scmd->device->host->host_lock, flags); scsi_log_send(scmd); host->hostt->queuecommand(scmd, scsi_eh_done); spin_unlock_irqrestore(scmd->device->host->host_lock, flags); down(&sem); scsi_log_completion(scmd, SUCCESS); scmd->device->host->eh_action = NULL; /* * see if timeout. if so, tell the host to forget about it. * in other words, we don't want a callback any more. */ if (scsi_eh_eflags_chk(scmd, SCSI_EH_REC_TIMEOUT)) { scsi_eh_eflags_clr(scmd, SCSI_EH_REC_TIMEOUT); scmd->owner = SCSI_OWNER_LOWLEVEL; /* * as far as the low level driver is * concerned, this command is still active, so * we must give the low level driver a chance * to abort it. (db) * * FIXME(eric) - we are not tracking whether we could * abort a timed out command or not. not sure how * we should treat them differently anyways. */ spin_lock_irqsave(scmd->device->host->host_lock, flags); if (scmd->device->host->hostt->eh_abort_handler) scmd->device->host->hostt->eh_abort_handler(scmd); spin_unlock_irqrestore(scmd->device->host->host_lock, flags); scmd->request->rq_status = RQ_SCSI_DONE; scmd->owner = SCSI_OWNER_ERROR_HANDLER; rtn = FAILED; } SCSI_LOG_ERROR_RECOVERY(3, printk("%s: scmd: %p, rtn:%x\n", __FUNCTION__, scmd, rtn)); /* * now examine the actual status codes to see whether the command * actually did complete normally. */ if (rtn == SUCCESS) { rtn = scsi_eh_completed_normally(scmd); SCSI_LOG_ERROR_RECOVERY(3, printk("%s: scsi_eh_completed_normally %x\n", __FUNCTION__, rtn)); switch (rtn) { case SUCCESS: case NEEDS_RETRY: case FAILED: break; default: rtn = FAILED; break; } } return rtn;}/** * scsi_request_sense - Request sense data from a particular target. * @scmd: SCSI cmd for request sense. * * Notes: * Some hosts automatically obtain this information, others require * that we obtain it on our own. This function will *not* return until * the command either times out, or it completes. **/static int scsi_request_sense(struct scsi_cmnd *scmd){ static unsigned char generic_sense[6] = {REQUEST_SENSE, 0, 0, 0, 252, 0}; unsigned char *scsi_result; int saved_result; int rtn; memcpy(scmd->cmnd, generic_sense, sizeof(generic_sense)); scsi_result = kmalloc(252, GFP_ATOMIC | (scmd->device->host->hostt->unchecked_isa_dma) ? __GFP_DMA : 0); if (unlikely(!scsi_result)) { printk(KERN_ERR "%s: cannot allocate scsi_result.\n", __FUNCTION__); return FAILED; } /* * zero the sense buffer. some host adapters automatically always * request sense, so it is not a good idea that * scmd->request_buffer and scmd->sense_buffer point to the same * address (db). 0 is not a valid sense code. */ memset(scmd->sense_buffer, 0, sizeof(scmd->sense_buffer)); memset(scsi_result, 0, 252); saved_result = scmd->result; scmd->request_buffer = scsi_result; scmd->request_bufflen = 252; scmd->use_sg = 0; scmd->cmd_len = COMMAND_SIZE(scmd->cmnd[0]); scmd->sc_data_direction = DMA_FROM_DEVICE; scmd->underflow = 0; rtn = scsi_send_eh_cmnd(scmd, SENSE_TIMEOUT); /* last chance to have valid sense data */ if(!SCSI_SENSE_VALID(scmd)) { memcpy(scmd->sense_buffer, scmd->request_buffer, sizeof(scmd->sense_buffer)); } kfree(scsi_result); /* * when we eventually call scsi_finish, we really wish to complete * the original request, so let's restore the original data. (db) */ scsi_setup_cmd_retry(scmd); scmd->result = saved_result; return rtn;}/** * scsi_eh_finish_cmd - Handle a cmd that eh is finished with. * @scmd: Original SCSI cmd that eh has finished. * @done_q: Queue for processed commands. * * Notes: * We don't want to use the normal command completion while we are are * still handling errors - it may cause other commands to be queued, * and that would disturb what we are doing. thus we really want to * keep a list of pending commands for final completion, and once we * are ready to leave error handling we handle completion for real. **/static void scsi_eh_finish_cmd(struct scsi_cmnd *scmd, struct list_head *done_q){ scmd->device->host->host_failed--; scmd->state = SCSI_STATE_BHQUEUE; scsi_eh_eflags_clr_all(scmd); /* * set this back so that the upper level can correctly free up * things. */ scsi_setup_cmd_retry(scmd); list_move_tail(&scmd->eh_entry, done_q);}/** * scsi_eh_get_sense - Get device sense data. * @work_q: Queue of commands to process. * @done_q: Queue of proccessed commands.. * * Description: * See if we need to request sense information. if so, then get it * now, so we have a better idea of what to do. * * Notes: * This has the unfortunate side effect that if a shost adapter does * not automatically request sense information, that we end up shutting * it down before we request it. * * All drivers should request sense information internally these days, * so for now all I have to say is tough noogies if you end up in here. * * XXX: Long term this code should go away, but that needs an audit of * all LLDDs first. **/static int scsi_eh_get_sense(struct list_head *work_q, struct list_head *done_q){ struct list_head *lh, *lh_sf; struct scsi_cmnd *scmd; int rtn; list_for_each_safe(lh, lh_sf, work_q) { scmd = list_entry(lh, struct scsi_cmnd, eh_entry); if (scsi_eh_eflags_chk(scmd, SCSI_EH_CANCEL_CMD) || SCSI_SENSE_VALID(scmd)) continue; SCSI_LOG_ERROR_RECOVERY(2, printk("%s: requesting sense" " for id: %d\n", current->comm, scmd->device->id)); rtn = scsi_request_sense(scmd); if (rtn != SUCCESS) continue; SCSI_LOG_ERROR_RECOVERY(3, printk("sense requested for %p" " result %x\n", scmd, scmd->result)); SCSI_LOG_ERROR_RECOVERY(3, scsi_print_sense("bh", scmd)); rtn = scsi_decide_disposition(scmd); /* * if the result was normal, then just pass it along to the * upper level. */ if (rtn == SUCCESS) /* we don't want this command reissued, just * finished with the sense data, so set * retries to the max allowed to ensure it * won't get reissued */ scmd->retries = scmd->allowed; else if (rtn != NEEDS_RETRY) continue; scsi_eh_finish_cmd(scmd, done_q); } return list_empty(work_q);}/** * scsi_try_to_abort_cmd - Ask host to abort a running command. * @scmd: SCSI cmd to abort from Lower Level. * * Notes: * This function will not return until the user's completion function * has been called. there is no timeout on this operation. if the * author of the low-level driver wishes this operation to be timed, * they can provide this facility themselves. helper functions in * scsi_error.c can be supplied to make this easier to do. **/static int scsi_try_to_abort_cmd(struct scsi_cmnd *scmd){ unsigned long flags; int rtn = FAILED; if (!scmd->device->host->hostt->eh_abort_handler) return rtn; /* * scsi_done was called just after the command timed out and before * we had a chance to process it. (db) */ if (scmd->serial_number == 0) return SUCCESS; scmd->owner = SCSI_OWNER_LOWLEVEL; spin_lock_irqsave(scmd->device->host->host_lock, flags); rtn = scmd->device->host->hostt->eh_abort_handler(scmd); spin_unlock_irqrestore(scmd->device->host->host_lock, flags); return rtn;}/** * scsi_eh_tur - Send TUR to device. * @scmd: Scsi cmd to send TUR * * Return value: * 0 - Device is ready. 1 - Device NOT ready. **/static int scsi_eh_tur(struct scsi_cmnd *scmd){ static unsigned char tur_command[6] = {TEST_UNIT_READY, 0, 0, 0, 0, 0}; int retry_cnt = 1, rtn;retry_tur: memcpy(scmd->cmnd, tur_command, sizeof(tur_command)); /* * zero the sense buffer. the scsi spec mandates that any * untransferred sense data should be interpreted as being zero. */ memset(scmd->sense_buffer, 0, sizeof(scmd->sense_buffer)); scmd->request_buffer = NULL; scmd->request_bufflen = 0; scmd->use_sg = 0; scmd->cmd_len = COMMAND_SIZE(scmd->cmnd[0]); scmd->underflow = 0; scmd->sc_data_direction = DMA_NONE; rtn = scsi_send_eh_cmnd(scmd, SENSE_TIMEOUT); /* * when we eventually call scsi_finish, we really wish to complete * the original request, so let's restore the original data. (db) */ scsi_setup_cmd_retry(scmd); /* * hey, we are done. let's look to see what happened. */ SCSI_LOG_ERROR_RECOVERY(3, printk("%s: scmd %p rtn %x\n", __FUNCTION__, scmd, rtn)); if (rtn == SUCCESS) return 0; else if (rtn == NEEDS_RETRY) if (retry_cnt--) goto retry_tur; return 1;}/** * scsi_eh_abort_cmds - abort canceled commands. * @shost: scsi host being recovered. * @eh_done_q: list_head for processed commands. * * Decription: * Try and see whether or not it makes sense to try and abort the * running command. this only works out to be the case if we have one * command that has timed out. if the command simply failed, it makes * no sense to try and abort the command, since as far as the shost * adapter is concerned, it isn't running. **/static int scsi_eh_abort_cmds(struct list_head *work_q, struct list_head *done_q){ struct list_head *lh, *lh_sf; struct scsi_cmnd *scmd; int rtn; list_for_each_safe(lh, lh_sf, work_q) { scmd = list_entry(lh, struct scsi_cmnd, eh_entry); if (!scsi_eh_eflags_chk(scmd, SCSI_EH_CANCEL_CMD)) continue; SCSI_LOG_ERROR_RECOVERY(3, printk("%s: aborting cmd:" "0x%p\n", current->comm, scmd)); rtn = scsi_try_to_abort_cmd(scmd); if (rtn == SUCCESS) { scsi_eh_eflags_clr(scmd, SCSI_EH_CANCEL_CMD); if (!scsi_device_online(scmd->device) || !scsi_eh_tur(scmd)) { scsi_eh_finish_cmd(scmd, done_q); } } else SCSI_LOG_ERROR_RECOVERY(3, printk("%s: aborting" " cmd failed:" "0x%p\n", current->comm, scmd)); } return list_empty(work_q);}/** * scsi_try_bus_device_reset - Ask host to perform a BDR on a dev * @scmd: SCSI cmd used to send BDR * * Notes: * There is no timeout for this operation. if this operation is * unreliable for a given host, then the host itself needs to put a * timer on it, and set the host back to a consistent state prior to * returning. **/static int scsi_try_bus_device_reset(struct scsi_cmnd *scmd){ unsigned long flags; int rtn = FAILED; if (!scmd->device->host->hostt->eh_device_reset_handler) return rtn; scmd->owner = SCSI_OWNER_LOWLEVEL; spin_lock_irqsave(scmd->device->host->host_lock, flags); rtn = scmd->device->host->hostt->eh_device_reset_handler(scmd); spin_unlock_irqrestore(scmd->device->host->host_lock, flags); if (rtn == SUCCESS) { scmd->device->was_reset = 1; scmd->device->expecting_cc_ua = 1; } return rtn;}/** * scsi_eh_try_stu - Send START_UNIT to device. * @scmd: Scsi cmd to send START_UNIT * * Return value: * 0 - Device is ready. 1 - Device NOT ready. **/static int scsi_eh_try_stu(struct scsi_cmnd *scmd){ static unsigned char stu_command[6] = {START_STOP, 0, 0, 0, 1, 0}; int rtn; if (!scmd->device->allow_restart) return 1; memcpy(scmd->cmnd, stu_command, sizeof(stu_command)); /* * zero the sense buffer. the scsi spec mandates that any * untransferred sense data should be interpreted as being zero. */ memset(scmd->sense_buffer, 0, sizeof(scmd->sense_buffer)); scmd->request_buffer = NULL; scmd->request_bufflen = 0; scmd->use_sg = 0; scmd->cmd_len = COMMAND_SIZE(scmd->cmnd[0]); scmd->underflow = 0; scmd->sc_data_direction = DMA_NONE; rtn = scsi_send_eh_cmnd(scmd, START_UNIT_TIMEOUT); /* * when we eventually call scsi_finish, we really wish to complete * the original request, so let's restore the original data. (db) */ scsi_setup_cmd_retry(scmd); /* * hey, we are done. let's look to see what happened. */ SCSI_LOG_ERROR_RECOVERY(3, printk("%s: scmd %p rtn %x\n", __FUNCTION__, scmd, rtn)); if (rtn == SUCCESS) return 0; return 1;} /** * scsi_eh_stu - send START_UNIT if needed * @shost: scsi host being recovered. * @eh_done_q: list_head for processed commands. * * Notes: * If commands are failing due to not ready, initializing command required, * try revalidating the device, which will end up sending a start unit. **/static int scsi_eh_stu(struct Scsi_Host *shost, struct list_head *work_q, struct list_head *done_q){ struct list_head *lh, *lh_sf; struct scsi_cmnd *scmd, *stu_scmd;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?