Commit 059c97d0 authored by Andreas Herrmann's avatar Andreas Herrmann Committed by James Bottomley

[SCSI] zfcp: remove union zfcp_req_data, use unit refcount for FCP commands

o union zfcp_req_data removed
o increment unit refcount when processing FCP commands
 (This fixes a theoretical race: When all scsi commands of a unit
  are aborted and the scsi_device is removed then the unit could be
  removed before all fsf_requests of that unit are completely processed.)
Signed-off-by: default avatarAndreas Herrmann <aherrman@de.ibm.com>
Signed-off-by: default avatarJames Bottomley <James.Bottomley@SteelEye.com>
parent 3734d24b
...@@ -141,7 +141,7 @@ zfcp_cmd_dbf_event_fsf(const char *text, struct zfcp_fsf_req *fsf_req, ...@@ -141,7 +141,7 @@ zfcp_cmd_dbf_event_fsf(const char *text, struct zfcp_fsf_req *fsf_req,
spin_lock_irqsave(&adapter->dbf_lock, flags); spin_lock_irqsave(&adapter->dbf_lock, flags);
if (zfcp_fsf_req_is_scsi_cmnd(fsf_req)) { if (zfcp_fsf_req_is_scsi_cmnd(fsf_req)) {
scsi_cmnd = fsf_req->data.send_fcp_command_task.scsi_cmnd; scsi_cmnd = (struct scsi_cmnd*) fsf_req->data;
debug_text_event(adapter->cmd_dbf, level, "fsferror"); debug_text_event(adapter->cmd_dbf, level, "fsferror");
debug_text_event(adapter->cmd_dbf, level, text); debug_text_event(adapter->cmd_dbf, level, text);
debug_event(adapter->cmd_dbf, level, &fsf_req, debug_event(adapter->cmd_dbf, level, &fsf_req,
...@@ -167,14 +167,12 @@ void ...@@ -167,14 +167,12 @@ void
zfcp_cmd_dbf_event_scsi(const char *text, struct scsi_cmnd *scsi_cmnd) zfcp_cmd_dbf_event_scsi(const char *text, struct scsi_cmnd *scsi_cmnd)
{ {
struct zfcp_adapter *adapter; struct zfcp_adapter *adapter;
union zfcp_req_data *req_data;
struct zfcp_fsf_req *fsf_req; struct zfcp_fsf_req *fsf_req;
int level = ((host_byte(scsi_cmnd->result) != 0) ? 1 : 5); int level = ((host_byte(scsi_cmnd->result) != 0) ? 1 : 5);
unsigned long flags; unsigned long flags;
adapter = (struct zfcp_adapter *) scsi_cmnd->device->host->hostdata[0]; adapter = (struct zfcp_adapter *) scsi_cmnd->device->host->hostdata[0];
req_data = (union zfcp_req_data *) scsi_cmnd->host_scribble; fsf_req = (struct zfcp_fsf_req *) scsi_cmnd->host_scribble;
fsf_req = (req_data ? req_data->send_fcp_command_task.fsf_req : NULL);
spin_lock_irqsave(&adapter->dbf_lock, flags); spin_lock_irqsave(&adapter->dbf_lock, flags);
debug_text_event(adapter->cmd_dbf, level, "hostbyte"); debug_text_event(adapter->cmd_dbf, level, "hostbyte");
debug_text_event(adapter->cmd_dbf, level, text); debug_text_event(adapter->cmd_dbf, level, text);
...@@ -1609,7 +1607,7 @@ zfcp_fsf_incoming_els(struct zfcp_fsf_req *fsf_req) ...@@ -1609,7 +1607,7 @@ zfcp_fsf_incoming_els(struct zfcp_fsf_req *fsf_req)
u32 els_type; u32 els_type;
struct zfcp_adapter *adapter; struct zfcp_adapter *adapter;
status_buffer = fsf_req->data.status_read.buffer; status_buffer = (struct fsf_status_read_buffer *) fsf_req->data;
els_type = *(u32 *) (status_buffer->payload); els_type = *(u32 *) (status_buffer->payload);
adapter = fsf_req->adapter; adapter = fsf_req->adapter;
......
...@@ -635,45 +635,6 @@ struct zfcp_adapter_mempool { ...@@ -635,45 +635,6 @@ struct zfcp_adapter_mempool {
mempool_t *data_gid_pn; mempool_t *data_gid_pn;
}; };
struct zfcp_exchange_config_data{
};
struct zfcp_open_port {
struct zfcp_port *port;
};
struct zfcp_close_port {
struct zfcp_port *port;
};
struct zfcp_open_unit {
struct zfcp_unit *unit;
};
struct zfcp_close_unit {
struct zfcp_unit *unit;
};
struct zfcp_close_physical_port {
struct zfcp_port *port;
};
struct zfcp_send_fcp_command_task {
struct zfcp_fsf_req *fsf_req;
struct zfcp_unit *unit;
struct scsi_cmnd *scsi_cmnd;
unsigned long start_jiffies;
};
struct zfcp_send_fcp_command_task_management {
struct zfcp_unit *unit;
};
struct zfcp_abort_fcp_command {
struct zfcp_fsf_req *fsf_req;
struct zfcp_unit *unit;
};
/* /*
* header for CT_IU * header for CT_IU
*/ */
...@@ -781,33 +742,6 @@ struct zfcp_send_els { ...@@ -781,33 +742,6 @@ struct zfcp_send_els {
int status; int status;
}; };
struct zfcp_status_read {
struct fsf_status_read_buffer *buffer;
};
struct zfcp_fsf_done {
struct completion *complete;
int status;
};
/* request specific data */
union zfcp_req_data {
struct zfcp_exchange_config_data exchange_config_data;
struct zfcp_open_port open_port;
struct zfcp_close_port close_port;
struct zfcp_open_unit open_unit;
struct zfcp_close_unit close_unit;
struct zfcp_close_physical_port close_physical_port;
struct zfcp_send_fcp_command_task send_fcp_command_task;
struct zfcp_send_fcp_command_task_management
send_fcp_command_task_management;
struct zfcp_abort_fcp_command abort_fcp_command;
struct zfcp_send_ct *send_ct;
struct zfcp_send_els *send_els;
struct zfcp_status_read status_read;
struct fsf_qtcb_bottom_port *port_data;
};
struct zfcp_qdio_queue { struct zfcp_qdio_queue {
struct qdio_buffer *buffer[QDIO_MAX_BUFFERS_PER_Q]; /* SBALs */ struct qdio_buffer *buffer[QDIO_MAX_BUFFERS_PER_Q]; /* SBALs */
u8 free_index; /* index of next free bfr u8 free_index; /* index of next free bfr
...@@ -963,11 +897,12 @@ struct zfcp_fsf_req { ...@@ -963,11 +897,12 @@ struct zfcp_fsf_req {
u32 fsf_command; /* FSF Command copy */ u32 fsf_command; /* FSF Command copy */
struct fsf_qtcb *qtcb; /* address of associated QTCB */ struct fsf_qtcb *qtcb; /* address of associated QTCB */
u32 seq_no; /* Sequence number of request */ u32 seq_no; /* Sequence number of request */
union zfcp_req_data data; /* Info fields of request */ unsigned long data; /* private data of request */
struct zfcp_erp_action *erp_action; /* used if this request is struct zfcp_erp_action *erp_action; /* used if this request is
issued on behalf of erp */ issued on behalf of erp */
mempool_t *pool; /* used if request was alloacted mempool_t *pool; /* used if request was alloacted
from emergency pool */ from emergency pool */
struct zfcp_unit *unit;
}; };
typedef void zfcp_fsf_req_handler_t(struct zfcp_fsf_req*); typedef void zfcp_fsf_req_handler_t(struct zfcp_fsf_req*);
......
This diff is collapsed.
...@@ -414,67 +414,37 @@ zfcp_port_lookup(struct zfcp_adapter *adapter, int channel, scsi_id_t id) ...@@ -414,67 +414,37 @@ zfcp_port_lookup(struct zfcp_adapter *adapter, int channel, scsi_id_t id)
return (struct zfcp_port *) NULL; return (struct zfcp_port *) NULL;
} }
/* /**
* function: zfcp_scsi_eh_abort_handler * zfcp_scsi_eh_abort_handler - abort the specified SCSI command
* * @scpnt: pointer to scsi_cmnd to be aborted
* purpose: tries to abort the specified (timed out) SCSI command * Return: SUCCESS - command has been aborted and cleaned up in internal
* * bookkeeping, SCSI stack won't be called for aborted command
* note: We do not need to care for a SCSI command which completes * FAILED - otherwise
* normally but late during this abort routine runs.
* We are allowed to return late commands to the SCSI stack.
* It tracks the state of commands and will handle late commands.
* (Usually, the normal completion of late commands is ignored with
* respect to the running abort operation. Grep for 'done_late'
* in the SCSI stacks sources.)
* *
* returns: SUCCESS - command has been aborted and cleaned up in internal * We do not need to care for a SCSI command which completes normally
* bookkeeping, * but late during this abort routine runs. We are allowed to return
* SCSI stack won't be called for aborted command * late commands to the SCSI stack. It tracks the state of commands and
* FAILED - otherwise * will handle late commands. (Usually, the normal completion of late
* commands is ignored with respect to the running abort operation.)
*/ */
int int
__zfcp_scsi_eh_abort_handler(struct scsi_cmnd *scpnt) zfcp_scsi_eh_abort_handler(struct scsi_cmnd *scpnt)
{ {
struct Scsi_Host *scsi_host;
struct zfcp_adapter *adapter;
struct zfcp_unit *unit;
int retval = SUCCESS; int retval = SUCCESS;
struct zfcp_fsf_req *new_fsf_req, *old_fsf_req; struct zfcp_fsf_req *new_fsf_req, *old_fsf_req;
struct zfcp_adapter *adapter = (struct zfcp_adapter *) scpnt->device->host->hostdata[0];
struct zfcp_unit *unit = (struct zfcp_unit *) scpnt->device->hostdata;
struct zfcp_port *port = unit->port;
struct Scsi_Host *scsi_host = scpnt->device->host;
union zfcp_req_data *req_data = NULL;
unsigned long flags; unsigned long flags;
u32 status = 0;
scsi_host = scpnt->device->host;
/* the components of a abort_dbf record (fixed size record) */ adapter = (struct zfcp_adapter *) scsi_host->hostdata[0];
u64 dbf_scsi_cmnd = (unsigned long) scpnt; unit = (struct zfcp_unit *) scpnt->device->hostdata;
char dbf_opcode[ZFCP_ABORT_DBF_LENGTH];
wwn_t dbf_wwn = port->wwpn;
fcp_lun_t dbf_fcp_lun = unit->fcp_lun;
u64 dbf_retries = scpnt->retries;
u64 dbf_allowed = scpnt->allowed;
u64 dbf_timeout = 0;
u64 dbf_fsf_req = 0;
u64 dbf_fsf_status = 0;
u64 dbf_fsf_qual[2] = { 0, 0 };
char dbf_result[ZFCP_ABORT_DBF_LENGTH] = "##undef";
memset(dbf_opcode, 0, ZFCP_ABORT_DBF_LENGTH);
memcpy(dbf_opcode,
scpnt->cmnd,
min(scpnt->cmd_len, (unsigned char) ZFCP_ABORT_DBF_LENGTH));
ZFCP_LOG_INFO("aborting scsi_cmnd=%p on adapter %s\n", ZFCP_LOG_INFO("aborting scsi_cmnd=%p on adapter %s\n",
scpnt, zfcp_get_busid_by_adapter(adapter)); scpnt, zfcp_get_busid_by_adapter(adapter));
spin_unlock_irq(scsi_host->host_lock); /* avoid race condition between late normal completion and abort */
/*
* 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); write_lock_irqsave(&adapter->abort_lock, flags);
/* /*
...@@ -484,144 +454,48 @@ __zfcp_scsi_eh_abort_handler(struct scsi_cmnd *scpnt) ...@@ -484,144 +454,48 @@ __zfcp_scsi_eh_abort_handler(struct scsi_cmnd *scpnt)
* this routine returns. (scpnt is parameter passed to this routine * this routine returns. (scpnt is parameter passed to this routine
* and must not disappear during abort even on late completion.) * and must not disappear during abort even on late completion.)
*/ */
req_data = (union zfcp_req_data *) scpnt->host_scribble; old_fsf_req = (struct zfcp_fsf_req *) 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) { if (!old_fsf_req) {
write_unlock_irqrestore(&adapter->abort_lock, flags); write_unlock_irqrestore(&adapter->abort_lock, flags);
ZFCP_LOG_NORMAL("bug: no old fsf request found\n"); 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_LOG_NORMAL("scsi_cmnd:\n");
ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL, ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
(char *) scpnt, sizeof (struct scsi_cmnd)); (char *) scpnt, sizeof (struct scsi_cmnd));
retval = FAILED; retval = FAILED;
strncpy(dbf_result, "##bug:r", ZFCP_ABORT_DBF_LENGTH);
goto out; goto out;
} }
old_fsf_req->data.send_fcp_command_task.scsi_cmnd = NULL; old_fsf_req->data = 0;
/* mark old request as being aborted */
old_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTING; 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);
/* /* don't access old_fsf_req after releasing the abort_lock */
* 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); write_unlock_irqrestore(&adapter->abort_lock, flags);
/* call FSF routine which does the abort */ /* call FSF routine which does the abort */
new_fsf_req = zfcp_fsf_abort_fcp_command((unsigned long) old_fsf_req, new_fsf_req = zfcp_fsf_abort_fcp_command((unsigned long) old_fsf_req,
adapter, unit, 0); adapter, unit, 0);
ZFCP_LOG_DEBUG("new_fsf_req=%p\n", new_fsf_req);
if (!new_fsf_req) { if (!new_fsf_req) {
retval = FAILED; retval = FAILED;
ZFCP_LOG_NORMAL("error: initiation of Abort FCP Cmnd " ZFCP_LOG_NORMAL("error: initiation of Abort FCP Cmnd "
"failed\n"); "failed\n");
strncpy(dbf_result, "##nores", ZFCP_ABORT_DBF_LENGTH);
goto out; goto out;
} }
/* wait for completion of abort */ /* 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, __wait_event(new_fsf_req->completion_wq,
new_fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED); 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_free(new_fsf_req); zfcp_fsf_req_free(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 */ /* status should be valid since signals were not permitted */
if (status & ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED) { if (new_fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED) {
retval = SUCCESS; retval = SUCCESS;
strncpy(dbf_result, "##succ", ZFCP_ABORT_DBF_LENGTH); } else if (new_fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED) {
} else if (status & ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED) {
retval = SUCCESS; retval = SUCCESS;
strncpy(dbf_result, "##late2", ZFCP_ABORT_DBF_LENGTH);
} else { } else {
retval = FAILED; retval = FAILED;
strncpy(dbf_result, "##fail", ZFCP_ABORT_DBF_LENGTH);
} }
out: 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; return retval;
} }
int
zfcp_scsi_eh_abort_handler(struct scsi_cmnd *scpnt)
{
int rc;
struct Scsi_Host *scsi_host = scpnt->device->host;
spin_lock_irq(scsi_host->host_lock);
rc = __zfcp_scsi_eh_abort_handler(scpnt);
spin_unlock_irq(scsi_host->host_lock);
return rc;
}
/* /*
* function: zfcp_scsi_eh_device_reset_handler * function: zfcp_scsi_eh_device_reset_handler
* *
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment