aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ata
diff options
context:
space:
mode:
authorDavid Howells <dhowells@redhat.com>2006-11-22 09:55:48 -0500
committerDavid Howells <dhowells@redhat.com>2006-11-22 09:55:48 -0500
commit65f27f38446e1976cc98fd3004b110fedcddd189 (patch)
tree68f8be93feae31dfa018c22db392a05546b63ee1 /drivers/ata
parent365970a1ea76d81cb1ad2f652acb605f06dae256 (diff)
WorkStruct: Pass the work_struct pointer instead of context data
Pass the work_struct pointer to the work function rather than context data. The work function can use container_of() to work out the data. For the cases where the container of the work_struct may go away the moment the pending bit is cleared, it is made possible to defer the release of the structure by deferring the clearing of the pending bit. To make this work, an extra flag is introduced into the management side of the work_struct. This governs auto-release of the structure upon execution. Ordinarily, the work queue executor would release the work_struct for further scheduling or deallocation by clearing the pending bit prior to jumping to the work function. This means that, unless the driver makes some guarantee itself that the work_struct won't go away, the work function may not access anything else in the work_struct or its container lest they be deallocated.. This is a problem if the auxiliary data is taken away (as done by the last patch). However, if the pending bit is *not* cleared before jumping to the work function, then the work function *may* access the work_struct and its container with no problems. But then the work function must itself release the work_struct by calling work_release(). In most cases, automatic release is fine, so this is the default. Special initiators exist for the non-auto-release case (ending in _NAR). Signed-Off-By: David Howells <dhowells@redhat.com>
Diffstat (limited to 'drivers/ata')
-rw-r--r--drivers/ata/libata-core.c20
-rw-r--r--drivers/ata/libata-scsi.c14
-rw-r--r--drivers/ata/libata.h4
3 files changed, 21 insertions, 17 deletions
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 0bb4b4dced76..b5f2da6ac80e 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -914,7 +914,7 @@ static unsigned int ata_id_xfermask(const u16 *id)
914 * ata_port_queue_task - Queue port_task 914 * ata_port_queue_task - Queue port_task
915 * @ap: The ata_port to queue port_task for 915 * @ap: The ata_port to queue port_task for
916 * @fn: workqueue function to be scheduled 916 * @fn: workqueue function to be scheduled
917 * @data: data value to pass to workqueue function 917 * @data: data for @fn to use
918 * @delay: delay time for workqueue function 918 * @delay: delay time for workqueue function
919 * 919 *
920 * Schedule @fn(@data) for execution after @delay jiffies using 920 * Schedule @fn(@data) for execution after @delay jiffies using
@@ -929,7 +929,7 @@ static unsigned int ata_id_xfermask(const u16 *id)
929 * LOCKING: 929 * LOCKING:
930 * Inherited from caller. 930 * Inherited from caller.
931 */ 931 */
932void ata_port_queue_task(struct ata_port *ap, void (*fn)(void *), void *data, 932void ata_port_queue_task(struct ata_port *ap, work_func_t fn, void *data,
933 unsigned long delay) 933 unsigned long delay)
934{ 934{
935 int rc; 935 int rc;
@@ -937,7 +937,8 @@ void ata_port_queue_task(struct ata_port *ap, void (*fn)(void *), void *data,
937 if (ap->pflags & ATA_PFLAG_FLUSH_PORT_TASK) 937 if (ap->pflags & ATA_PFLAG_FLUSH_PORT_TASK)
938 return; 938 return;
939 939
940 PREPARE_DELAYED_WORK(&ap->port_task, fn, data); 940 PREPARE_DELAYED_WORK(&ap->port_task, fn);
941 ap->port_task_data = data;
941 942
942 rc = queue_delayed_work(ata_wq, &ap->port_task, delay); 943 rc = queue_delayed_work(ata_wq, &ap->port_task, delay);
943 944
@@ -4292,10 +4293,11 @@ fsm_start:
4292 return poll_next; 4293 return poll_next;
4293} 4294}
4294 4295
4295static void ata_pio_task(void *_data) 4296static void ata_pio_task(struct work_struct *work)
4296{ 4297{
4297 struct ata_queued_cmd *qc = _data; 4298 struct ata_port *ap =
4298 struct ata_port *ap = qc->ap; 4299 container_of(work, struct ata_port, port_task.work);
4300 struct ata_queued_cmd *qc = ap->port_task_data;
4299 u8 status; 4301 u8 status;
4300 int poll_next; 4302 int poll_next;
4301 4303
@@ -5317,9 +5319,9 @@ void ata_port_init(struct ata_port *ap, struct ata_host *host,
5317 ap->msg_enable = ATA_MSG_DRV | ATA_MSG_ERR | ATA_MSG_WARN; 5319 ap->msg_enable = ATA_MSG_DRV | ATA_MSG_ERR | ATA_MSG_WARN;
5318#endif 5320#endif
5319 5321
5320 INIT_DELAYED_WORK(&ap->port_task, NULL, NULL); 5322 INIT_DELAYED_WORK(&ap->port_task, NULL);
5321 INIT_DELAYED_WORK(&ap->hotplug_task, ata_scsi_hotplug, ap); 5323 INIT_DELAYED_WORK(&ap->hotplug_task, ata_scsi_hotplug);
5322 INIT_WORK(&ap->scsi_rescan_task, ata_scsi_dev_rescan, ap); 5324 INIT_WORK(&ap->scsi_rescan_task, ata_scsi_dev_rescan);
5323 INIT_LIST_HEAD(&ap->eh_done_q); 5325 INIT_LIST_HEAD(&ap->eh_done_q);
5324 init_waitqueue_head(&ap->eh_wait_q); 5326 init_waitqueue_head(&ap->eh_wait_q);
5325 5327
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 5c1fc467fc7f..c872b324dbd3 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -3079,7 +3079,7 @@ static void ata_scsi_remove_dev(struct ata_device *dev)
3079 3079
3080/** 3080/**
3081 * ata_scsi_hotplug - SCSI part of hotplug 3081 * ata_scsi_hotplug - SCSI part of hotplug
3082 * @data: Pointer to ATA port to perform SCSI hotplug on 3082 * @work: Pointer to ATA port to perform SCSI hotplug on
3083 * 3083 *
3084 * Perform SCSI part of hotplug. It's executed from a separate 3084 * Perform SCSI part of hotplug. It's executed from a separate
3085 * workqueue after EH completes. This is necessary because SCSI 3085 * workqueue after EH completes. This is necessary because SCSI
@@ -3089,9 +3089,10 @@ static void ata_scsi_remove_dev(struct ata_device *dev)
3089 * LOCKING: 3089 * LOCKING:
3090 * Kernel thread context (may sleep). 3090 * Kernel thread context (may sleep).
3091 */ 3091 */
3092void ata_scsi_hotplug(void *data) 3092void ata_scsi_hotplug(struct work_struct *work)
3093{ 3093{
3094 struct ata_port *ap = data; 3094 struct ata_port *ap =
3095 container_of(work, struct ata_port, hotplug_task.work);
3095 int i; 3096 int i;
3096 3097
3097 if (ap->pflags & ATA_PFLAG_UNLOADING) { 3098 if (ap->pflags & ATA_PFLAG_UNLOADING) {
@@ -3190,7 +3191,7 @@ static int ata_scsi_user_scan(struct Scsi_Host *shost, unsigned int channel,
3190 3191
3191/** 3192/**
3192 * ata_scsi_dev_rescan - initiate scsi_rescan_device() 3193 * ata_scsi_dev_rescan - initiate scsi_rescan_device()
3193 * @data: Pointer to ATA port to perform scsi_rescan_device() 3194 * @work: Pointer to ATA port to perform scsi_rescan_device()
3194 * 3195 *
3195 * After ATA pass thru (SAT) commands are executed successfully, 3196 * After ATA pass thru (SAT) commands are executed successfully,
3196 * libata need to propagate the changes to SCSI layer. This 3197 * libata need to propagate the changes to SCSI layer. This
@@ -3200,9 +3201,10 @@ static int ata_scsi_user_scan(struct Scsi_Host *shost, unsigned int channel,
3200 * LOCKING: 3201 * LOCKING:
3201 * Kernel thread context (may sleep). 3202 * Kernel thread context (may sleep).
3202 */ 3203 */
3203void ata_scsi_dev_rescan(void *data) 3204void ata_scsi_dev_rescan(struct work_struct *work)
3204{ 3205{
3205 struct ata_port *ap = data; 3206 struct ata_port *ap =
3207 container_of(work, struct ata_port, scsi_rescan_task);
3206 struct ata_device *dev; 3208 struct ata_device *dev;
3207 unsigned int i; 3209 unsigned int i;
3208 3210
diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
index 0ed263be652a..7e0f3aff873d 100644
--- a/drivers/ata/libata.h
+++ b/drivers/ata/libata.h
@@ -81,7 +81,7 @@ extern struct scsi_transport_template ata_scsi_transport_template;
81 81
82extern void ata_scsi_scan_host(struct ata_port *ap); 82extern void ata_scsi_scan_host(struct ata_port *ap);
83extern int ata_scsi_offline_dev(struct ata_device *dev); 83extern int ata_scsi_offline_dev(struct ata_device *dev);
84extern void ata_scsi_hotplug(void *data); 84extern void ata_scsi_hotplug(struct work_struct *work);
85extern unsigned int ata_scsiop_inq_std(struct ata_scsi_args *args, u8 *rbuf, 85extern unsigned int ata_scsiop_inq_std(struct ata_scsi_args *args, u8 *rbuf,
86 unsigned int buflen); 86 unsigned int buflen);
87 87
@@ -111,7 +111,7 @@ extern void ata_scsi_rbuf_fill(struct ata_scsi_args *args,
111 unsigned int (*actor) (struct ata_scsi_args *args, 111 unsigned int (*actor) (struct ata_scsi_args *args,
112 u8 *rbuf, unsigned int buflen)); 112 u8 *rbuf, unsigned int buflen));
113extern void ata_schedule_scsi_eh(struct Scsi_Host *shost); 113extern void ata_schedule_scsi_eh(struct Scsi_Host *shost);
114extern void ata_scsi_dev_rescan(void *data); 114extern void ata_scsi_dev_rescan(struct work_struct *work);
115extern int ata_bus_probe(struct ata_port *ap); 115extern int ata_bus_probe(struct ata_port *ap);
116 116
117/* libata-eh.c */ 117/* libata-eh.c */