Commit 9ef3e4a4 authored by James Smart's avatar James Smart Committed by James Bottomley

[SCSI] fc_transport: fix sysfs deadlock on vport delete

When the vport attribute "delete" is used to delete the vport, sysfs
deadlocks waiting for the write to complete, which is waiting for the
sysfs teardown to complete. Moved this effort to a work_q element.

Took the opportunity to make some other cosmetic changes:
 - removed tabs in Doc file - replaced with expanded spaces
 - minor copyright text and author text updates
 - removed a bunch of trailing whitespace
Signed-off-by: default avatarJames Smart <James.Smart@emulex.com>
Signed-off-by: default avatarJames Bottomley <James.Bottomley@SteelEye.com>
parent bee4fe8e
This diff is collapsed.
/* /*
* FiberChannel transport specific attributes exported to sysfs. * FiberChannel transport specific attributes exported to sysfs.
* *
* Copyright (c) 2003 Silicon Graphics, Inc. All rights reserved. * Copyright (c) 2003 Silicon Graphics, Inc. All rights reserved.
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
* Copyright (C) 2004-2007 James Smart, Emulex Corporation * Copyright (C) 2004-2007 James Smart, Emulex Corporation
* Rewrite for host, target, device, and remote port attributes, * Rewrite for host, target, device, and remote port attributes,
* statistics, and service functions... * statistics, and service functions...
* Add vports, etc
* *
*/ */
#include <linux/module.h> #include <linux/module.h>
...@@ -37,6 +38,7 @@ ...@@ -37,6 +38,7 @@
#include "scsi_priv.h" #include "scsi_priv.h"
static int fc_queue_work(struct Scsi_Host *, struct work_struct *); static int fc_queue_work(struct Scsi_Host *, struct work_struct *);
static void fc_vport_sched_delete(struct work_struct *work);
/* /*
* This is a temporary carrier for creating a vport. It will eventually * This is a temporary carrier for creating a vport. It will eventually
...@@ -377,7 +379,7 @@ static int fc_host_setup(struct transport_container *tc, struct device *dev, ...@@ -377,7 +379,7 @@ static int fc_host_setup(struct transport_container *tc, struct device *dev,
struct Scsi_Host *shost = dev_to_shost(dev); struct Scsi_Host *shost = dev_to_shost(dev);
struct fc_host_attrs *fc_host = shost_to_fc_host(shost); struct fc_host_attrs *fc_host = shost_to_fc_host(shost);
/* /*
* Set default values easily detected by the midlayer as * Set default values easily detected by the midlayer as
* failure cases. The scsi lldd is responsible for initializing * failure cases. The scsi lldd is responsible for initializing
* all transport attributes to valid values per host. * all transport attributes to valid values per host.
...@@ -1198,12 +1200,9 @@ store_fc_vport_delete(struct class_device *cdev, const char *buf, ...@@ -1198,12 +1200,9 @@ store_fc_vport_delete(struct class_device *cdev, const char *buf,
size_t count) size_t count)
{ {
struct fc_vport *vport = transport_class_to_vport(cdev); struct fc_vport *vport = transport_class_to_vport(cdev);
int stat; struct Scsi_Host *shost = vport_to_shost(vport);
stat = fc_vport_terminate(vport);
if (stat)
return stat;
fc_queue_work(shost, &vport->vport_delete_work);
return count; return count;
} }
static FC_CLASS_DEVICE_ATTR(vport, vport_delete, S_IWUSR, static FC_CLASS_DEVICE_ATTR(vport, vport_delete, S_IWUSR,
...@@ -1996,7 +1995,7 @@ fc_attach_transport(struct fc_function_template *ft) ...@@ -1996,7 +1995,7 @@ fc_attach_transport(struct fc_function_template *ft)
i->t.eh_timed_out = fc_timed_out; i->t.eh_timed_out = fc_timed_out;
i->t.user_scan = fc_user_scan; i->t.user_scan = fc_user_scan;
/* /*
* Setup SCSI Target Attributes. * Setup SCSI Target Attributes.
*/ */
...@@ -2215,23 +2214,12 @@ fc_remove_host(struct Scsi_Host *shost) ...@@ -2215,23 +2214,12 @@ fc_remove_host(struct Scsi_Host *shost)
struct workqueue_struct *work_q; struct workqueue_struct *work_q;
struct fc_host_attrs *fc_host = shost_to_fc_host(shost); struct fc_host_attrs *fc_host = shost_to_fc_host(shost);
unsigned long flags; unsigned long flags;
int stat;
spin_lock_irqsave(shost->host_lock, flags); spin_lock_irqsave(shost->host_lock, flags);
/* Remove any vports */ /* Remove any vports */
list_for_each_entry_safe(vport, next_vport, &fc_host->vports, peers) { list_for_each_entry_safe(vport, next_vport, &fc_host->vports, peers)
spin_unlock_irqrestore(shost->host_lock, flags); fc_queue_work(shost, &vport->vport_delete_work);
/* this must be called synchronously */
stat = fc_vport_terminate(vport);
spin_lock_irqsave(shost->host_lock, flags);
if (stat)
dev_printk(KERN_ERR, vport->dev.parent,
"%s: %s could not be deleted created via "
"shost%d channel %d\n", __FUNCTION__,
vport->dev.bus_id, vport->shost->host_no,
vport->channel);
}
/* Remove any remote ports */ /* Remove any remote ports */
list_for_each_entry_safe(rport, next_rport, list_for_each_entry_safe(rport, next_rport,
...@@ -2308,7 +2296,7 @@ fc_rport_final_delete(struct work_struct *work) ...@@ -2308,7 +2296,7 @@ fc_rport_final_delete(struct work_struct *work)
unsigned long flags; unsigned long flags;
/* /*
* if a scan is pending, flush the SCSI Host work_q so that * if a scan is pending, flush the SCSI Host work_q so that
* that we can reclaim the rport scan work element. * that we can reclaim the rport scan work element.
*/ */
if (rport->flags & FC_RPORT_SCAN_PENDING) if (rport->flags & FC_RPORT_SCAN_PENDING)
...@@ -2858,7 +2846,7 @@ EXPORT_SYMBOL(fc_remote_port_rolechg); ...@@ -2858,7 +2846,7 @@ EXPORT_SYMBOL(fc_remote_port_rolechg);
* fc_timeout_deleted_rport - Timeout handler for a deleted remote port, * fc_timeout_deleted_rport - Timeout handler for a deleted remote port,
* which we blocked, and has now failed to return * which we blocked, and has now failed to return
* in the allotted time. * in the allotted time.
* *
* @work: rport target that failed to reappear in the allotted time. * @work: rport target that failed to reappear in the allotted time.
**/ **/
static void static void
...@@ -3061,6 +3049,7 @@ fc_vport_create(struct Scsi_Host *shost, int channel, struct device *pdev, ...@@ -3061,6 +3049,7 @@ fc_vport_create(struct Scsi_Host *shost, int channel, struct device *pdev,
vport->shost = shost; vport->shost = shost;
vport->channel = channel; vport->channel = channel;
vport->flags = FC_VPORT_CREATING; vport->flags = FC_VPORT_CREATING;
INIT_WORK(&vport->vport_delete_work, fc_vport_sched_delete);
spin_lock_irqsave(shost->host_lock, flags); spin_lock_irqsave(shost->host_lock, flags);
...@@ -3207,8 +3196,30 @@ fc_vport_terminate(struct fc_vport *vport) ...@@ -3207,8 +3196,30 @@ fc_vport_terminate(struct fc_vport *vport)
} }
EXPORT_SYMBOL(fc_vport_terminate); EXPORT_SYMBOL(fc_vport_terminate);
/**
* fc_vport_sched_delete - workq-based delete request for a vport
*
* @work: vport to be deleted.
**/
static void
fc_vport_sched_delete(struct work_struct *work)
{
struct fc_vport *vport =
container_of(work, struct fc_vport, vport_delete_work);
int stat;
stat = fc_vport_terminate(vport);
if (stat)
dev_printk(KERN_ERR, vport->dev.parent,
"%s: %s could not be deleted created via "
"shost%d channel %d - error %d\n", __FUNCTION__,
vport->dev.bus_id, vport->shost->host_no,
vport->channel, stat);
}
MODULE_AUTHOR("Martin Hicks"); /* Original Author: Martin Hicks */
MODULE_AUTHOR("James Smart");
MODULE_DESCRIPTION("FC Transport Attributes"); MODULE_DESCRIPTION("FC Transport Attributes");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
......
/* /*
* FiberChannel transport specific attributes exported to sysfs. * FiberChannel transport specific attributes exported to sysfs.
* *
* Copyright (c) 2003 Silicon Graphics, Inc. All rights reserved. * Copyright (c) 2003 Silicon Graphics, Inc. All rights reserved.
...@@ -104,7 +104,7 @@ enum fc_vport_state { ...@@ -104,7 +104,7 @@ enum fc_vport_state {
/* /*
* FC Classes of Service * FC Classes of Service
* Note: values are not enumerated, as they can be "or'd" together * Note: values are not enumerated, as they can be "or'd" together
* for reporting (e.g. report supported_classes). If you alter this list, * for reporting (e.g. report supported_classes). If you alter this list,
...@@ -117,7 +117,7 @@ enum fc_vport_state { ...@@ -117,7 +117,7 @@ enum fc_vport_state {
#define FC_COS_CLASS4 0x10 #define FC_COS_CLASS4 0x10
#define FC_COS_CLASS6 0x40 #define FC_COS_CLASS6 0x40
/* /*
* FC Port Speeds * FC Port Speeds
* Note: values are not enumerated, as they can be "or'd" together * Note: values are not enumerated, as they can be "or'd" together
* for reporting (e.g. report supported_speeds). If you alter this list, * for reporting (e.g. report supported_speeds). If you alter this list,
...@@ -223,6 +223,7 @@ struct fc_vport { ...@@ -223,6 +223,7 @@ struct fc_vport {
u8 flags; u8 flags;
struct list_head peers; struct list_head peers;
struct device dev; struct device dev;
struct work_struct vport_delete_work;
} __attribute__((aligned(sizeof(unsigned long)))); } __attribute__((aligned(sizeof(unsigned long))));
/* bit field values for struct fc_vport "flags" field: */ /* bit field values for struct fc_vport "flags" field: */
...@@ -397,7 +398,7 @@ struct fc_host_statistics { ...@@ -397,7 +398,7 @@ struct fc_host_statistics {
u64 prim_seq_protocol_err_count; u64 prim_seq_protocol_err_count;
u64 invalid_tx_word_count; u64 invalid_tx_word_count;
u64 invalid_crc_count; u64 invalid_crc_count;
/* fc4 statistics (only FCP supported currently) */ /* fc4 statistics (only FCP supported currently) */
u64 fcp_input_requests; u64 fcp_input_requests;
u64 fcp_output_requests; u64 fcp_output_requests;
...@@ -592,11 +593,11 @@ struct fc_function_template { ...@@ -592,11 +593,11 @@ struct fc_function_template {
u32 dd_fcrport_size; u32 dd_fcrport_size;
u32 dd_fcvport_size; u32 dd_fcvport_size;
/* /*
* The driver sets these to tell the transport class it * The driver sets these to tell the transport class it
* wants the attributes displayed in sysfs. If the show_ flag * wants the attributes displayed in sysfs. If the show_ flag
* is not set, the attribute will be private to the transport * is not set, the attribute will be private to the transport
* class * class
*/ */
/* remote port fixed attributes */ /* remote port fixed attributes */
......
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