zfcp_scsi.c

来自「Linux Kernel 2.6.9 for OMAP1710」· C语言 代码 · 共 911 行 · 第 1/2 页

C
911
字号
	 * Race condition between normal (late) completion and abort has	 * to be avoided.	 * The entirity of all accesses to scsi_req have to be atomic.	 * scsi_req is usually part of the fsf_req and thus we block the	 * release of fsf_req as long as we need to access scsi_req.	 */	write_lock_irqsave(&adapter->abort_lock, flags);	/*	 * Check whether command has just completed and can not be aborted.	 * Even if the command has just been completed late, we can access	 * scpnt since the SCSI stack does not release it at least until	 * this routine returns. (scpnt is parameter passed to this routine	 * and must not disappear during abort even on late completion.)	 */	req_data = (union zfcp_req_data *) scpnt->host_scribble;	/* DEBUG */	ZFCP_LOG_DEBUG("req_data=%p\n", req_data);	if (!req_data) {		ZFCP_LOG_DEBUG("late command completion overtook abort\n");		/*		 * That's it.		 * Do not initiate abort but return SUCCESS.		 */		write_unlock_irqrestore(&adapter->abort_lock, flags);		retval = SUCCESS;		strncpy(dbf_result, "##late1", ZFCP_ABORT_DBF_LENGTH);		goto out;	}	/* Figure out which fsf_req needs to be aborted. */	old_fsf_req = req_data->send_fcp_command_task.fsf_req;	dbf_fsf_req = (unsigned long) old_fsf_req;	dbf_timeout =	    (jiffies - req_data->send_fcp_command_task.start_jiffies) / HZ;	ZFCP_LOG_DEBUG("old_fsf_req=%p\n", old_fsf_req);	if (!old_fsf_req) {		write_unlock_irqrestore(&adapter->abort_lock, flags);		ZFCP_LOG_NORMAL("bug: no old fsf request found\n");		ZFCP_LOG_NORMAL("req_data:\n");		ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,			      (char *) req_data, sizeof (union zfcp_req_data));		ZFCP_LOG_NORMAL("scsi_cmnd:\n");		ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,			      (char *) scpnt, sizeof (struct scsi_cmnd));		retval = FAILED;		strncpy(dbf_result, "##bug:r", ZFCP_ABORT_DBF_LENGTH);		goto out;	}	old_fsf_req->data.send_fcp_command_task.scsi_cmnd = NULL;	/* mark old request as being aborted */	old_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTING;	/*	 * We have to collect all information (e.g. unit) needed by 	 * zfcp_fsf_abort_fcp_command before calling that routine	 * since that routine is not allowed to access	 * fsf_req which it is going to abort.	 * This is because of we need to release fsf_req_list_lock	 * before calling zfcp_fsf_abort_fcp_command.	 * Since this lock will not be held, fsf_req may complete	 * late and may be released meanwhile.	 */	ZFCP_LOG_DEBUG("unit 0x%016Lx (%p)\n", unit->fcp_lun, unit);	/*	 * We block (call schedule)	 * That's why we must release the lock and enable the	 * interrupts before.	 * On the other hand we do not need the lock anymore since	 * all critical accesses to scsi_req are done.	 */	write_unlock_irqrestore(&adapter->abort_lock, flags);	/* call FSF routine which does the abort */	new_fsf_req = zfcp_fsf_abort_fcp_command((unsigned long) old_fsf_req,						 adapter, unit, 0);	ZFCP_LOG_DEBUG("new_fsf_req=%p\n", new_fsf_req);	if (!new_fsf_req) {		retval = FAILED;		ZFCP_LOG_NORMAL("error: initiation of Abort FCP Cmnd "				"failed\n");		strncpy(dbf_result, "##nores", ZFCP_ABORT_DBF_LENGTH);		goto out;	}	/* wait for completion of abort */	ZFCP_LOG_DEBUG("waiting for cleanup...\n");#if 1	/*	 * FIXME:	 * copying zfcp_fsf_req_wait_and_cleanup code is not really nice	 */	__wait_event(new_fsf_req->completion_wq,		     new_fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);	status = new_fsf_req->status;	dbf_fsf_status = new_fsf_req->qtcb->header.fsf_status;	/*	 * Ralphs special debug load provides timestamps in the FSF	 * status qualifier. This might be specified later if being	 * useful for debugging aborts.	 */	dbf_fsf_qual[0] =	    *(u64 *) & new_fsf_req->qtcb->header.fsf_status_qual.word[0];	dbf_fsf_qual[1] =	    *(u64 *) & new_fsf_req->qtcb->header.fsf_status_qual.word[2];	zfcp_fsf_req_cleanup(new_fsf_req);#else	retval = zfcp_fsf_req_wait_and_cleanup(new_fsf_req,					       ZFCP_UNINTERRUPTIBLE, &status);#endif	ZFCP_LOG_DEBUG("Waiting for cleanup complete, status=0x%x\n", status);	/* status should be valid since signals were not permitted */	if (status & ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED) {		retval = SUCCESS;		strncpy(dbf_result, "##succ", ZFCP_ABORT_DBF_LENGTH);	} else if (status & ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED) {		retval = SUCCESS;		strncpy(dbf_result, "##late2", ZFCP_ABORT_DBF_LENGTH);	} else {		retval = FAILED;		strncpy(dbf_result, "##fail", ZFCP_ABORT_DBF_LENGTH);	} out:	debug_event(adapter->abort_dbf, 1, &dbf_scsi_cmnd, sizeof (u64));	debug_event(adapter->abort_dbf, 1, &dbf_opcode, ZFCP_ABORT_DBF_LENGTH);	debug_event(adapter->abort_dbf, 1, &dbf_wwn, sizeof (wwn_t));	debug_event(adapter->abort_dbf, 1, &dbf_fcp_lun, sizeof (fcp_lun_t));	debug_event(adapter->abort_dbf, 1, &dbf_retries, sizeof (u64));	debug_event(adapter->abort_dbf, 1, &dbf_allowed, sizeof (u64));	debug_event(adapter->abort_dbf, 1, &dbf_timeout, sizeof (u64));	debug_event(adapter->abort_dbf, 1, &dbf_fsf_req, sizeof (u64));	debug_event(adapter->abort_dbf, 1, &dbf_fsf_status, sizeof (u64));	debug_event(adapter->abort_dbf, 1, &dbf_fsf_qual[0], sizeof (u64));	debug_event(adapter->abort_dbf, 1, &dbf_fsf_qual[1], sizeof (u64));	debug_text_event(adapter->abort_dbf, 1, dbf_result);	spin_lock_irq(scsi_host->host_lock);	return retval;}/* * function:	zfcp_scsi_eh_device_reset_handler * * purpose: * * returns: */intzfcp_scsi_eh_device_reset_handler(struct scsi_cmnd *scpnt){	int retval;	struct zfcp_unit *unit = (struct zfcp_unit *) scpnt->device->hostdata;	struct Scsi_Host *scsi_host = scpnt->device->host;	spin_unlock_irq(scsi_host->host_lock);	if (!unit) {		ZFCP_LOG_NORMAL("bug: Tried reset for nonexistent unit\n");		retval = SUCCESS;		goto out;	}	ZFCP_LOG_NORMAL("resetting unit 0x%016Lx\n", unit->fcp_lun);	/*	 * If we do not know whether the unit supports 'logical unit reset'	 * then try 'logical unit reset' and proceed with 'target reset'	 * if 'logical unit reset' fails.	 * If the unit is known not to support 'logical unit reset' then	 * skip 'logical unit reset' and try 'target reset' immediately.	 */	if (!atomic_test_mask(ZFCP_STATUS_UNIT_NOTSUPPUNITRESET,			      &unit->status)) {		retval =		    zfcp_task_management_function(unit, LOGICAL_UNIT_RESET);		if (retval) {			ZFCP_LOG_DEBUG("unit reset failed (unit=%p)\n", unit);			if (retval == -ENOTSUPP)				atomic_set_mask				    (ZFCP_STATUS_UNIT_NOTSUPPUNITRESET,				     &unit->status);			/* fall through and try 'target reset' next */		} else {			ZFCP_LOG_DEBUG("unit reset succeeded (unit=%p)\n",				       unit);			/* avoid 'target reset' */			retval = SUCCESS;			goto out;		}	}	retval = zfcp_task_management_function(unit, TARGET_RESET);	if (retval) {		ZFCP_LOG_DEBUG("target reset failed (unit=%p)\n", unit);		retval = FAILED;	} else {		ZFCP_LOG_DEBUG("target reset succeeded (unit=%p)\n", unit);		retval = SUCCESS;	} out:	spin_lock_irq(scsi_host->host_lock);	return retval;}static intzfcp_task_management_function(struct zfcp_unit *unit, u8 tm_flags){	struct zfcp_adapter *adapter = unit->port->adapter;	int retval;	int status;	struct zfcp_fsf_req *fsf_req;	/* issue task management function */	fsf_req = zfcp_fsf_send_fcp_command_task_management		(adapter, unit, tm_flags, 0);	if (!fsf_req) {		ZFCP_LOG_INFO("error: creation of task management request "			      "failed for unit 0x%016Lx on port 0x%016Lx on  "			      "adapter %s\n", unit->fcp_lun, unit->port->wwpn,			      zfcp_get_busid_by_adapter(adapter));		retval = -ENOMEM;		goto out;	}	retval = zfcp_fsf_req_wait_and_cleanup(fsf_req,					       ZFCP_UNINTERRUPTIBLE, &status);	/*	 * check completion status of task management function	 * (status should always be valid since no signals permitted)	 */	if (status & ZFCP_STATUS_FSFREQ_TMFUNCFAILED)		retval = -EIO;	else if (status & ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP)		retval = -ENOTSUPP;	else		retval = 0; out:	return retval;}/* * function:	zfcp_scsi_eh_bus_reset_handler * * purpose: * * returns: */intzfcp_scsi_eh_bus_reset_handler(struct scsi_cmnd *scpnt){	int retval = 0;	struct zfcp_unit *unit;	struct Scsi_Host *scsi_host = scpnt->device->host;	spin_unlock_irq(scsi_host->host_lock);	unit = (struct zfcp_unit *) scpnt->device->hostdata;	ZFCP_LOG_NORMAL("bus reset because of problems with "			"unit 0x%016Lx\n", unit->fcp_lun);	zfcp_erp_adapter_reopen(unit->port->adapter, 0);	zfcp_erp_wait(unit->port->adapter);	retval = SUCCESS;	spin_lock_irq(scsi_host->host_lock);	return retval;}/* * function:	zfcp_scsi_eh_host_reset_handler * * purpose: * * returns: */intzfcp_scsi_eh_host_reset_handler(struct scsi_cmnd *scpnt){	int retval = 0;	struct zfcp_unit *unit;	struct Scsi_Host *scsi_host = scpnt->device->host;	spin_unlock_irq(scsi_host->host_lock);	unit = (struct zfcp_unit *) scpnt->device->hostdata;	ZFCP_LOG_NORMAL("host reset because of problems with "			"unit 0x%016Lx\n", unit->fcp_lun);	zfcp_erp_adapter_reopen(unit->port->adapter, 0);	zfcp_erp_wait(unit->port->adapter);	retval = SUCCESS;	spin_lock_irq(scsi_host->host_lock);	return retval;}/* * function:	 * * purpose:	 * * returns: */intzfcp_adapter_scsi_register(struct zfcp_adapter *adapter){	int retval = 0;	static unsigned int unique_id = 0;	/* register adapter as SCSI host with mid layer of SCSI stack */	adapter->scsi_host = scsi_host_alloc(&zfcp_data.scsi_host_template,					     sizeof (struct zfcp_adapter *));	if (!adapter->scsi_host) {		ZFCP_LOG_NORMAL("error: registration with SCSI stack failed "				"for adapter %s ",				zfcp_get_busid_by_adapter(adapter));		retval = -EIO;		goto out;	}	ZFCP_LOG_DEBUG("host registered, scsi_host=%p\n", adapter->scsi_host);	/* tell the SCSI stack some characteristics of this adapter */	adapter->scsi_host->max_id = 1;	adapter->scsi_host->max_lun = 1;	adapter->scsi_host->max_channel = 0;	adapter->scsi_host->unique_id = unique_id++;	/* FIXME */	adapter->scsi_host->max_cmd_len = ZFCP_MAX_SCSI_CMND_LENGTH;	adapter->scsi_host->transportt = zfcp_transport_template;	/*	 * Reverse mapping of the host number to avoid race condition	 */	adapter->scsi_host_no = adapter->scsi_host->host_no;	/*	 * save a pointer to our own adapter data structure within	 * hostdata field of SCSI host data structure	 */	adapter->scsi_host->hostdata[0] = (unsigned long) adapter;	if (scsi_add_host(adapter->scsi_host, &adapter->ccw_device->dev)) {		scsi_host_put(adapter->scsi_host);		retval = -EIO;		goto out;	}	atomic_set_mask(ZFCP_STATUS_ADAPTER_REGISTERED, &adapter->status); out:	return retval;}/* * function:	 * * purpose:	 * * returns: */voidzfcp_adapter_scsi_unregister(struct zfcp_adapter *adapter){	struct Scsi_Host *shost;	shost = adapter->scsi_host;	if (!shost)		return;	scsi_remove_host(shost);	scsi_host_put(shost);	adapter->scsi_host = NULL;	adapter->scsi_host_no = 0;	atomic_clear_mask(ZFCP_STATUS_ADAPTER_REGISTERED, &adapter->status);	return;}voidzfcp_fsf_start_scsi_er_timer(struct zfcp_adapter *adapter){	adapter->scsi_er_timer.function = zfcp_fsf_scsi_er_timeout_handler;	adapter->scsi_er_timer.data = (unsigned long) adapter;	adapter->scsi_er_timer.expires = jiffies + ZFCP_SCSI_ER_TIMEOUT;	add_timer(&adapter->scsi_er_timer);}/* * Support functions for FC transport class */static voidzfcp_get_port_id(struct scsi_device *sdev){	struct zfcp_unit *unit;	unit = (struct zfcp_unit *) sdev->hostdata;	fc_port_id(sdev) = unit->port->d_id;}static voidzfcp_get_port_name(struct scsi_device *sdev){	struct zfcp_unit *unit;	unit = (struct zfcp_unit *) sdev->hostdata;	fc_port_name(sdev) = unit->port->wwpn;}static voidzfcp_get_node_name(struct scsi_device *sdev){	struct zfcp_unit *unit;	unit = (struct zfcp_unit *) sdev->hostdata;	fc_node_name(sdev) = unit->port->wwnn;}struct fc_function_template zfcp_transport_functions = {	.get_port_id = zfcp_get_port_id,	.get_port_name = zfcp_get_port_name,	.get_node_name = zfcp_get_node_name,	.show_port_id = 1,	.show_port_name = 1,	.show_node_name = 1,};/** * ZFCP_DEFINE_SCSI_ATTR * @_name:   name of show attribute * @_format: format string * @_value:  value to print * * Generates attribute for a unit. */#define ZFCP_DEFINE_SCSI_ATTR(_name, _format, _value)                    \static ssize_t zfcp_sysfs_scsi_##_name##_show(struct device *dev,        \                                              char *buf)                 \{                                                                        \        struct scsi_device *sdev;                                        \        struct zfcp_unit *unit;                                          \                                                                         \        sdev = to_scsi_device(dev);                                      \        unit = sdev->hostdata;                                           \        return sprintf(buf, _format, _value);                            \}                                                                        \                                                                         \static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_scsi_##_name##_show, NULL);ZFCP_DEFINE_SCSI_ATTR(hba_id, "%s\n", zfcp_get_busid_by_unit(unit));ZFCP_DEFINE_SCSI_ATTR(wwpn, "0x%016llx\n", unit->port->wwpn);ZFCP_DEFINE_SCSI_ATTR(fcp_lun, "0x%016llx\n", unit->fcp_lun);static struct device_attribute *zfcp_sysfs_sdev_attrs[] = {	&dev_attr_fcp_lun,	&dev_attr_wwpn,	&dev_attr_hba_id,	NULL};#undef ZFCP_LOG_AREA

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?