Commit 1094e682 authored by James Smart's avatar James Smart Committed by James Bottomley

[PATCH] suspending I/Os to a device

Add a device blocked state and API to the mid-layer

Use the new device blocked API in the fc transport class to invoke a
user settable delay on cable pulls.
Signed-off-by: default avatarJames Bottomley <James.Bottomley@SteelEye.com>
parent 4c86d5a7
......@@ -48,6 +48,8 @@ static int zfcp_task_management_function(struct zfcp_unit *, u8);
static struct zfcp_unit *zfcp_unit_lookup(struct zfcp_adapter *, int, scsi_id_t,
scsi_lun_t);
static struct zfcp_port * zfcp_port_lookup(struct zfcp_adapter *, int,
scsi_id_t);
static struct device_attribute *zfcp_sysfs_sdev_attrs[];
......@@ -398,6 +400,26 @@ zfcp_unit_lookup(struct zfcp_adapter *adapter, int channel, scsi_id_t id,
out:
return retval;
}
/*
* function: zfcp_unit_tgt_lookup
*
* purpose:
*
* returns:
*
* context:
*/
static struct zfcp_port *
zfcp_port_lookup(struct zfcp_adapter *adapter, int channel, scsi_id_t id)
{
struct zfcp_port *port;
list_for_each_entry(port, &adapter->port_list_head, list) {
if (id == port->scsi_id)
return port;
}
return (zfcp_port *)NULL;
}
/*
* function: zfcp_scsi_eh_abort_handler
......@@ -839,39 +861,63 @@ zfcp_fsf_start_scsi_er_timer(struct zfcp_adapter *adapter)
* Support functions for FC transport class
*/
static void
zfcp_get_port_id(struct scsi_device *sdev)
zfcp_get_port_id(struct scsi_target *starget)
{
struct zfcp_unit *unit;
struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
struct zfcp_adapter *adapter = (struct zfcp_adapter *)shost->hostdata[0];
struct zfcp_port *port;
unsigned long flags;
unit = (struct zfcp_unit *) sdev->hostdata;
fc_port_id(sdev) = unit->port->d_id;
read_lock_irqsave(&zfcp_data.config_lock, flags);
port = zfcp_port_lookup(adapter, starget->channel, starget->id);
if (port)
fc_starget_port_id(starget) = port->d_id;
else
fc_starget_port_id(starget) = -1;
read_unlock_irqrestore(&zfcp_data.config_lock, flags);
}
static void
zfcp_get_port_name(struct scsi_device *sdev)
zfcp_get_port_name(struct scsi_target *starget)
{
struct zfcp_unit *unit;
struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
struct zfcp_adapter *adapter = (struct zfcp_adapter *)shost->hostdata[0];
struct zfcp_port *port;
unsigned long flags;
unit = (struct zfcp_unit *) sdev->hostdata;
fc_port_name(sdev) = unit->port->wwpn;
read_lock_irqsave(&zfcp_data.config_lock, flags);
port = zfcp_port_lookup(adapter, starget->channel, starget->id);
if (port)
fc_starget_port_name(starget) = port->wwpn;
else
fc_starget_port_name(starget) = -1;
read_unlock_irqrestore(&zfcp_data.config_lock, flags);
}
static void
zfcp_get_node_name(struct scsi_device *sdev)
zfcp_get_node_name(struct scsi_target *starget)
{
struct zfcp_unit *unit;
struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
struct zfcp_adapter *adapter = (struct zfcp_adapter *)shost->hostdata[0];
struct zfcp_port *port;
unsigned long flags;
unit = (struct zfcp_unit *) sdev->hostdata;
fc_node_name(sdev) = unit->port->wwnn;
read_lock_irqsave(&zfcp_data.config_lock, flags);
port = zfcp_port_lookup(adapter, starget->channel, starget->id);
if (port)
fc_starget_node_name(starget) = port->wwnn;
else
fc_starget_node_name(starget) = -1;
read_unlock_irqrestore(&zfcp_data.config_lock, flags);
}
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,
.get_starget_port_id = zfcp_get_port_id,
.get_starget_port_name = zfcp_get_port_name,
.get_starget_node_name = zfcp_get_node_name,
.show_starget_port_id = 1,
.show_starget_port_name = 1,
.show_starget_node_name = 1,
};
/**
......
......@@ -4453,61 +4453,64 @@ qla2x00_down_timeout(struct semaphore *sema, unsigned long timeout)
}
static void
qla2xxx_get_port_id(struct scsi_device *sdev)
qla2xxx_get_port_id(struct scsi_target *starget)
{
scsi_qla_host_t *ha = to_qla_host(sdev->host);
struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
scsi_qla_host_t *ha = to_qla_host(shost);
struct fc_port *fc;
list_for_each_entry(fc, &ha->fcports, list) {
if (fc->os_target_id == sdev->id) {
fc_port_id(sdev) = fc->d_id.b.domain << 16 |
if (fc->os_target_id == starget->id) {
fc_starget_port_id(starget) = fc->d_id.b.domain << 16 |
fc->d_id.b.area << 8 |
fc->d_id.b.al_pa;
return;
}
}
fc_port_id(sdev) = -1;
fc_starget_port_id(starget) = -1;
}
static void
qla2xxx_get_port_name(struct scsi_device *sdev)
qla2xxx_get_port_name(struct scsi_target *starget)
{
scsi_qla_host_t *ha = to_qla_host(sdev->host);
struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
scsi_qla_host_t *ha = to_qla_host(shost);
struct fc_port *fc;
list_for_each_entry(fc, &ha->fcports, list) {
if (fc->os_target_id == sdev->id) {
fc_port_name(sdev) =
if (fc->os_target_id == starget->id) {
fc_starget_port_name(starget) =
__be64_to_cpu(*(uint64_t *)fc->port_name);
return;
}
}
fc_port_name(sdev) = -1;
fc_starget_port_name(starget) = -1;
}
static void
qla2xxx_get_node_name(struct scsi_device *sdev)
qla2xxx_get_node_name(struct scsi_target *starget)
{
scsi_qla_host_t *ha = to_qla_host(sdev->host);
struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
scsi_qla_host_t *ha = to_qla_host(shost);
struct fc_port *fc;
list_for_each_entry(fc, &ha->fcports, list) {
if (fc->os_target_id == sdev->id) {
fc_node_name(sdev) =
if (fc->os_target_id == starget->id) {
fc_starget_node_name(starget) =
__be64_to_cpu(*(uint64_t *)fc->node_name);
return;
}
}
fc_node_name(sdev) = -1;
fc_starget_node_name(starget) = -1;
}
static struct fc_function_template qla2xxx_transport_functions = {
.get_port_id = qla2xxx_get_port_id,
.show_port_id = 1,
.get_port_name = qla2xxx_get_port_name,
.show_port_name = 1,
.get_node_name = qla2xxx_get_node_name,
.show_node_name = 1,
.get_starget_port_id = qla2xxx_get_port_id,
.show_starget_port_id = 1,
.get_starget_port_name = qla2xxx_get_port_name,
.show_starget_port_name = 1,
.get_starget_node_name = qla2xxx_get_node_name,
.show_starget_node_name = 1,
};
/**
......
......@@ -518,6 +518,26 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
/* return 0 (because the command has been processed) */
goto out;
}
/* Check to see if the scsi lld put this device into state SDEV_BLOCK. */
if (unlikely(cmd->device->sdev_state == SDEV_BLOCK)) {
/*
* in SDEV_BLOCK, the command is just put back on the device
* queue. The suspend state has already blocked the queue so
* future requests should not occur until the device
* transitions out of the suspend state.
*/
scsi_queue_insert(cmd, SCSI_MLQUEUE_DEVICE_BUSY);
SCSI_LOG_MLQUEUE(3, printk("queuecommand : device blocked \n"));
/*
* NOTE: rtn is still zero here because we don't need the
* queue to be plugged on return (it's already stopped)
*/
goto out;
}
/* Assign a unique nonzero serial_number. */
/* XXX(hch): this is racy */
if (++serial_number == 0)
......@@ -1103,8 +1123,8 @@ EXPORT_SYMBOL(scsi_device_lookup);
/**
* scsi_device_cancel - cancel outstanding IO to this device
* @sdev: pointer to struct scsi_device
* @data: pointer to cancel value.
* @sdev: Pointer to struct scsi_device
* @recovery: Boolean instructing function to recover device or not.
*
**/
int scsi_device_cancel(struct scsi_device *sdev, int recovery)
......
......@@ -1642,6 +1642,7 @@ scsi_device_set_state(struct scsi_device *sdev, enum scsi_device_state state)
case SDEV_CREATED:
case SDEV_OFFLINE:
case SDEV_QUIESCE:
case SDEV_BLOCK:
break;
default:
goto illegal;
......@@ -1669,11 +1670,22 @@ scsi_device_set_state(struct scsi_device *sdev, enum scsi_device_state state)
}
break;
case SDEV_BLOCK:
switch (oldstate) {
case SDEV_CREATED:
case SDEV_RUNNING:
break;
default:
goto illegal;
}
break;
case SDEV_CANCEL:
switch (oldstate) {
case SDEV_CREATED:
case SDEV_RUNNING:
case SDEV_OFFLINE:
case SDEV_BLOCK:
break;
default:
goto illegal;
......@@ -1779,3 +1791,84 @@ scsi_target_resume(struct scsi_target *starget)
device_for_each_child(&starget->dev, NULL, device_resume_fn);
}
EXPORT_SYMBOL(scsi_target_resume);
/**
* scsi_internal_device_block - internal function to put a device
* temporarily into the SDEV_BLOCK state
* @sdev: device to block
*
* Block request made by scsi lld's to temporarily stop all
* scsi commands on the specified device. Called from interrupt
* or normal process context.
*
* Returns zero if successful or error if not
*
* Notes:
* This routine transitions the device to the SDEV_BLOCK state
* (which must be a legal transition). When the device is in this
* state, all commands are deferred until the scsi lld reenables
* the device with scsi_device_unblock or device_block_tmo fires.
* This routine assumes the host_lock is held on entry.
**/
int
scsi_internal_device_block(struct scsi_device *sdev)
{
request_queue_t *q = sdev->request_queue;
unsigned long flags;
int err = 0;
err = scsi_device_set_state(sdev, SDEV_BLOCK);
if (err)
return err;
/*
* The device has transitioned to SDEV_BLOCK. Stop the
* block layer from calling the midlayer with this device's
* request queue.
*/
spin_lock_irqsave(q->queue_lock, flags);
blk_stop_queue(q);
spin_unlock_irqrestore(q->queue_lock, flags);
return 0;
}
EXPORT_SYMBOL_GPL(scsi_internal_device_block);
/**
* scsi_internal_device_unblock - resume a device after a block request
* @sdev: device to resume
*
* Called by scsi lld's or the midlayer to restart the device queue
* for the previously suspended scsi device. Called from interrupt or
* normal process context.
*
* Returns zero if successful or error if not.
*
* Notes:
* This routine transitions the device to the SDEV_RUNNING state
* (which must be a legal transition) allowing the midlayer to
* goose the queue for this device. This routine assumes the
* host_lock is held upon entry.
**/
int
scsi_internal_device_unblock(struct scsi_device *sdev)
{
request_queue_t *q = sdev->request_queue;
int err;
unsigned long flags;
/*
* Try to transition the scsi device to SDEV_RUNNING
* and goose the device queue if successful.
*/
err = scsi_device_set_state(sdev, SDEV_RUNNING);
if (err)
return err;
spin_lock_irqsave(q->queue_lock, flags);
blk_start_queue(q);
spin_unlock_irqrestore(q->queue_lock, flags);
return 0;
}
EXPORT_SYMBOL_GPL(scsi_internal_device_unblock);
......@@ -153,4 +153,13 @@ extern struct scsi_transport_template blank_transport_template;
extern struct class sdev_class;
extern struct bus_type scsi_bus_type;
/*
* internal scsi timeout functions: for use by mid-layer and transport
* classes.
*/
#define SCSI_DEVICE_BLOCK_MAX_TIMEOUT (HZ*60)
extern int scsi_internal_device_block(struct scsi_device *sdev);
extern int scsi_internal_device_unblock(struct scsi_device *sdev);
#endif /* _SCSI_PRIV_H */
......@@ -30,6 +30,7 @@ static struct {
{ SDEV_DEL, "deleted" },
{ SDEV_QUIESCE, "quiesce" },
{ SDEV_OFFLINE, "offline" },
{ SDEV_BLOCK, "blocked" },
};
const char *scsi_device_state_name(enum scsi_device_state state)
......
This diff is collapsed.
......@@ -30,6 +30,9 @@ enum scsi_device_state {
* originate in the mid-layer) */
SDEV_OFFLINE, /* Device offlined (by error handling or
* user request */
SDEV_BLOCK, /* Device blocked by scsi lld. No scsi
* commands from user or midlayer should be issued
* to the scsi lld. */
};
struct scsi_device {
......
......@@ -24,33 +24,68 @@
struct scsi_transport_template;
struct fc_transport_attrs {
struct fc_starget_attrs { /* aka fc_target_attrs */
int port_id;
uint64_t node_name;
uint64_t port_name;
uint32_t dev_loss_tmo; /* Remote Port loss timeout in seconds. */
struct timer_list dev_loss_timer;
};
/* accessor functions */
#define fc_port_id(x) (((struct fc_transport_attrs *)&(x)->sdev_data)->port_id)
#define fc_node_name(x) (((struct fc_transport_attrs *)&(x)->sdev_data)->node_name)
#define fc_port_name(x) (((struct fc_transport_attrs *)&(x)->sdev_data)->port_name)
#define fc_starget_port_id(x) \
(((struct fc_starget_attrs *)&(x)->starget_data)->port_id)
#define fc_starget_node_name(x) \
(((struct fc_starget_attrs *)&(x)->starget_data)->node_name)
#define fc_starget_port_name(x) \
(((struct fc_starget_attrs *)&(x)->starget_data)->port_name)
#define fc_starget_dev_loss_tmo(x) \
(((struct fc_starget_attrs *)&(x)->starget_data)->dev_loss_tmo)
#define fc_starget_dev_loss_timer(x) \
(((struct fc_starget_attrs *)&(x)->starget_data)->dev_loss_timer)
struct fc_host_attrs {
uint32_t link_down_tmo; /* Link Down timeout in seconds. */
struct timer_list link_down_timer;
};
#define fc_host_link_down_tmo(x) \
(((struct fc_host_attrs *)&(x)->shost_data)->link_down_tmo)
#define fc_host_link_down_timer(x) \
(((struct fc_host_attrs *)&(x)->shost_data)->link_down_timer)
/* The functions by which the transport class and the driver communicate */
struct fc_function_template {
void (*get_port_id)(struct scsi_device *);
void (*get_node_name)(struct scsi_device *);
void (*get_port_name)(struct scsi_device *);
/* The driver sets these to tell the transport class it
void (*get_starget_port_id)(struct scsi_target *);
void (*get_starget_node_name)(struct scsi_target *);
void (*get_starget_port_name)(struct scsi_target *);
void (*get_starget_dev_loss_tmo)(struct scsi_target *);
void (*set_starget_dev_loss_tmo)(struct scsi_target *, uint32_t);
void (*get_host_link_down_tmo)(struct Scsi_Host *);
void (*set_host_link_down_tmo)(struct Scsi_Host *, uint32_t);
/*
* The driver sets these to tell the transport class it
* wants the attributes displayed in sysfs. If the show_ flag
* is not set, the attribute will be private to the transport
* class */
unsigned long show_port_id:1;
unsigned long show_node_name:1;
unsigned long show_port_name:1;
* class
*/
unsigned long show_starget_port_id:1;
unsigned long show_starget_node_name:1;
unsigned long show_starget_port_name:1;
unsigned long show_starget_dev_loss_tmo:1;
unsigned long show_host_link_down_tmo:1;
/* Private Attributes */
};
struct scsi_transport_template *fc_attach_transport(struct fc_function_template *);
void fc_release_transport(struct scsi_transport_template *);
int fc_target_block(struct scsi_target *starget);
void fc_target_unblock(struct scsi_target *starget);
int fc_host_block(struct Scsi_Host *shost);
void fc_host_unblock(struct Scsi_Host *shost);
#endif /* SCSI_TRANSPORT_FC_H */
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