diff options
author | David Howells <dhowells@redhat.com> | 2006-11-22 09:55:48 -0500 |
---|---|---|
committer | David Howells <dhowells@redhat.com> | 2006-11-22 09:55:48 -0500 |
commit | 65f27f38446e1976cc98fd3004b110fedcddd189 (patch) | |
tree | 68f8be93feae31dfa018c22db392a05546b63ee1 /drivers/ata/libata-core.c | |
parent | 365970a1ea76d81cb1ad2f652acb605f06dae256 (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/libata-core.c')
-rw-r--r-- | drivers/ata/libata-core.c | 20 |
1 files changed, 11 insertions, 9 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 | */ |
932 | void ata_port_queue_task(struct ata_port *ap, void (*fn)(void *), void *data, | 932 | void 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 | ||
4295 | static void ata_pio_task(void *_data) | 4296 | static 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 | ||