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 /net | |
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 'net')
-rw-r--r-- | net/core/link_watch.c | 6 | ||||
-rw-r--r-- | net/ipv4/inet_timewait_sock.c | 5 | ||||
-rw-r--r-- | net/ipv4/tcp_minisocks.c | 3 | ||||
-rw-r--r-- | net/sunrpc/cache.c | 6 | ||||
-rw-r--r-- | net/sunrpc/rpc_pipe.c | 7 | ||||
-rw-r--r-- | net/sunrpc/sched.c | 8 | ||||
-rw-r--r-- | net/sunrpc/xprt.c | 7 | ||||
-rw-r--r-- | net/sunrpc/xprtsock.c | 18 |
8 files changed, 32 insertions, 28 deletions
diff --git a/net/core/link_watch.c b/net/core/link_watch.c index f2ed09e25dfd..549a2ce951b0 100644 --- a/net/core/link_watch.c +++ b/net/core/link_watch.c | |||
@@ -34,8 +34,8 @@ enum lw_bits { | |||
34 | static unsigned long linkwatch_flags; | 34 | static unsigned long linkwatch_flags; |
35 | static unsigned long linkwatch_nextevent; | 35 | static unsigned long linkwatch_nextevent; |
36 | 36 | ||
37 | static void linkwatch_event(void *dummy); | 37 | static void linkwatch_event(struct work_struct *dummy); |
38 | static DECLARE_DELAYED_WORK(linkwatch_work, linkwatch_event, NULL); | 38 | static DECLARE_DELAYED_WORK(linkwatch_work, linkwatch_event); |
39 | 39 | ||
40 | static LIST_HEAD(lweventlist); | 40 | static LIST_HEAD(lweventlist); |
41 | static DEFINE_SPINLOCK(lweventlist_lock); | 41 | static DEFINE_SPINLOCK(lweventlist_lock); |
@@ -127,7 +127,7 @@ void linkwatch_run_queue(void) | |||
127 | } | 127 | } |
128 | 128 | ||
129 | 129 | ||
130 | static void linkwatch_event(void *dummy) | 130 | static void linkwatch_event(struct work_struct *dummy) |
131 | { | 131 | { |
132 | /* Limit the number of linkwatch events to one | 132 | /* Limit the number of linkwatch events to one |
133 | * per second so that a runaway driver does not | 133 | * per second so that a runaway driver does not |
diff --git a/net/ipv4/inet_timewait_sock.c b/net/ipv4/inet_timewait_sock.c index cdd805344c61..8c74f9168b7d 100644 --- a/net/ipv4/inet_timewait_sock.c +++ b/net/ipv4/inet_timewait_sock.c | |||
@@ -197,9 +197,10 @@ EXPORT_SYMBOL_GPL(inet_twdr_hangman); | |||
197 | 197 | ||
198 | extern void twkill_slots_invalid(void); | 198 | extern void twkill_slots_invalid(void); |
199 | 199 | ||
200 | void inet_twdr_twkill_work(void *data) | 200 | void inet_twdr_twkill_work(struct work_struct *work) |
201 | { | 201 | { |
202 | struct inet_timewait_death_row *twdr = data; | 202 | struct inet_timewait_death_row *twdr = |
203 | container_of(work, struct inet_timewait_death_row, twkill_work); | ||
203 | int i; | 204 | int i; |
204 | 205 | ||
205 | if ((INET_TWDR_TWKILL_SLOTS - 1) > (sizeof(twdr->thread_slots) * 8)) | 206 | if ((INET_TWDR_TWKILL_SLOTS - 1) > (sizeof(twdr->thread_slots) * 8)) |
diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c index 0163d9826907..af7b2c986b1f 100644 --- a/net/ipv4/tcp_minisocks.c +++ b/net/ipv4/tcp_minisocks.c | |||
@@ -45,8 +45,7 @@ struct inet_timewait_death_row tcp_death_row = { | |||
45 | .tw_timer = TIMER_INITIALIZER(inet_twdr_hangman, 0, | 45 | .tw_timer = TIMER_INITIALIZER(inet_twdr_hangman, 0, |
46 | (unsigned long)&tcp_death_row), | 46 | (unsigned long)&tcp_death_row), |
47 | .twkill_work = __WORK_INITIALIZER(tcp_death_row.twkill_work, | 47 | .twkill_work = __WORK_INITIALIZER(tcp_death_row.twkill_work, |
48 | inet_twdr_twkill_work, | 48 | inet_twdr_twkill_work), |
49 | &tcp_death_row), | ||
50 | /* Short-time timewait calendar */ | 49 | /* Short-time timewait calendar */ |
51 | 50 | ||
52 | .twcal_hand = -1, | 51 | .twcal_hand = -1, |
diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c index d5725cb1491e..d96fd466a9a4 100644 --- a/net/sunrpc/cache.c +++ b/net/sunrpc/cache.c | |||
@@ -284,8 +284,8 @@ static struct file_operations cache_file_operations; | |||
284 | static struct file_operations content_file_operations; | 284 | static struct file_operations content_file_operations; |
285 | static struct file_operations cache_flush_operations; | 285 | static struct file_operations cache_flush_operations; |
286 | 286 | ||
287 | static void do_cache_clean(void *data); | 287 | static void do_cache_clean(struct work_struct *work); |
288 | static DECLARE_DELAYED_WORK(cache_cleaner, do_cache_clean, NULL); | 288 | static DECLARE_DELAYED_WORK(cache_cleaner, do_cache_clean); |
289 | 289 | ||
290 | void cache_register(struct cache_detail *cd) | 290 | void cache_register(struct cache_detail *cd) |
291 | { | 291 | { |
@@ -461,7 +461,7 @@ static int cache_clean(void) | |||
461 | /* | 461 | /* |
462 | * We want to regularly clean the cache, so we need to schedule some work ... | 462 | * We want to regularly clean the cache, so we need to schedule some work ... |
463 | */ | 463 | */ |
464 | static void do_cache_clean(void *data) | 464 | static void do_cache_clean(struct work_struct *work) |
465 | { | 465 | { |
466 | int delay = 5; | 466 | int delay = 5; |
467 | if (cache_clean() == -1) | 467 | if (cache_clean() == -1) |
diff --git a/net/sunrpc/rpc_pipe.c b/net/sunrpc/rpc_pipe.c index 97be3f7fed44..49dba5febbbd 100644 --- a/net/sunrpc/rpc_pipe.c +++ b/net/sunrpc/rpc_pipe.c | |||
@@ -54,10 +54,11 @@ static void rpc_purge_list(struct rpc_inode *rpci, struct list_head *head, | |||
54 | } | 54 | } |
55 | 55 | ||
56 | static void | 56 | static void |
57 | rpc_timeout_upcall_queue(void *data) | 57 | rpc_timeout_upcall_queue(struct work_struct *work) |
58 | { | 58 | { |
59 | LIST_HEAD(free_list); | 59 | LIST_HEAD(free_list); |
60 | struct rpc_inode *rpci = (struct rpc_inode *)data; | 60 | struct rpc_inode *rpci = |
61 | container_of(work, struct rpc_inode, queue_timeout.work); | ||
61 | struct inode *inode = &rpci->vfs_inode; | 62 | struct inode *inode = &rpci->vfs_inode; |
62 | void (*destroy_msg)(struct rpc_pipe_msg *); | 63 | void (*destroy_msg)(struct rpc_pipe_msg *); |
63 | 64 | ||
@@ -838,7 +839,7 @@ init_once(void * foo, kmem_cache_t * cachep, unsigned long flags) | |||
838 | rpci->pipelen = 0; | 839 | rpci->pipelen = 0; |
839 | init_waitqueue_head(&rpci->waitq); | 840 | init_waitqueue_head(&rpci->waitq); |
840 | INIT_DELAYED_WORK(&rpci->queue_timeout, | 841 | INIT_DELAYED_WORK(&rpci->queue_timeout, |
841 | rpc_timeout_upcall_queue, rpci); | 842 | rpc_timeout_upcall_queue); |
842 | rpci->ops = NULL; | 843 | rpci->ops = NULL; |
843 | } | 844 | } |
844 | } | 845 | } |
diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c index a1ab4eed41f4..eff44bcdc95a 100644 --- a/net/sunrpc/sched.c +++ b/net/sunrpc/sched.c | |||
@@ -41,7 +41,7 @@ static mempool_t *rpc_buffer_mempool __read_mostly; | |||
41 | 41 | ||
42 | static void __rpc_default_timer(struct rpc_task *task); | 42 | static void __rpc_default_timer(struct rpc_task *task); |
43 | static void rpciod_killall(void); | 43 | static void rpciod_killall(void); |
44 | static void rpc_async_schedule(void *); | 44 | static void rpc_async_schedule(struct work_struct *); |
45 | 45 | ||
46 | /* | 46 | /* |
47 | * RPC tasks sit here while waiting for conditions to improve. | 47 | * RPC tasks sit here while waiting for conditions to improve. |
@@ -305,7 +305,7 @@ static void rpc_make_runnable(struct rpc_task *task) | |||
305 | if (RPC_IS_ASYNC(task)) { | 305 | if (RPC_IS_ASYNC(task)) { |
306 | int status; | 306 | int status; |
307 | 307 | ||
308 | INIT_WORK(&task->u.tk_work, rpc_async_schedule, (void *)task); | 308 | INIT_WORK(&task->u.tk_work, rpc_async_schedule); |
309 | status = queue_work(task->tk_workqueue, &task->u.tk_work); | 309 | status = queue_work(task->tk_workqueue, &task->u.tk_work); |
310 | if (status < 0) { | 310 | if (status < 0) { |
311 | printk(KERN_WARNING "RPC: failed to add task to queue: error: %d!\n", status); | 311 | printk(KERN_WARNING "RPC: failed to add task to queue: error: %d!\n", status); |
@@ -695,9 +695,9 @@ rpc_execute(struct rpc_task *task) | |||
695 | return __rpc_execute(task); | 695 | return __rpc_execute(task); |
696 | } | 696 | } |
697 | 697 | ||
698 | static void rpc_async_schedule(void *arg) | 698 | static void rpc_async_schedule(struct work_struct *work) |
699 | { | 699 | { |
700 | __rpc_execute((struct rpc_task *)arg); | 700 | __rpc_execute(container_of(work, struct rpc_task, u.tk_work)); |
701 | } | 701 | } |
702 | 702 | ||
703 | /** | 703 | /** |
diff --git a/net/sunrpc/xprt.c b/net/sunrpc/xprt.c index 80857470dc11..4f9a5d9791fb 100644 --- a/net/sunrpc/xprt.c +++ b/net/sunrpc/xprt.c | |||
@@ -479,9 +479,10 @@ int xprt_adjust_timeout(struct rpc_rqst *req) | |||
479 | return status; | 479 | return status; |
480 | } | 480 | } |
481 | 481 | ||
482 | static void xprt_autoclose(void *args) | 482 | static void xprt_autoclose(struct work_struct *work) |
483 | { | 483 | { |
484 | struct rpc_xprt *xprt = (struct rpc_xprt *)args; | 484 | struct rpc_xprt *xprt = |
485 | container_of(work, struct rpc_xprt, task_cleanup); | ||
485 | 486 | ||
486 | xprt_disconnect(xprt); | 487 | xprt_disconnect(xprt); |
487 | xprt->ops->close(xprt); | 488 | xprt->ops->close(xprt); |
@@ -932,7 +933,7 @@ struct rpc_xprt *xprt_create_transport(int proto, struct sockaddr *ap, size_t si | |||
932 | 933 | ||
933 | INIT_LIST_HEAD(&xprt->free); | 934 | INIT_LIST_HEAD(&xprt->free); |
934 | INIT_LIST_HEAD(&xprt->recv); | 935 | INIT_LIST_HEAD(&xprt->recv); |
935 | INIT_WORK(&xprt->task_cleanup, xprt_autoclose, xprt); | 936 | INIT_WORK(&xprt->task_cleanup, xprt_autoclose); |
936 | init_timer(&xprt->timer); | 937 | init_timer(&xprt->timer); |
937 | xprt->timer.function = xprt_init_autodisconnect; | 938 | xprt->timer.function = xprt_init_autodisconnect; |
938 | xprt->timer.data = (unsigned long) xprt; | 939 | xprt->timer.data = (unsigned long) xprt; |
diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c index 3c7532cd009e..cfe3c15be948 100644 --- a/net/sunrpc/xprtsock.c +++ b/net/sunrpc/xprtsock.c | |||
@@ -1060,13 +1060,14 @@ static int xs_bindresvport(struct rpc_xprt *xprt, struct socket *sock) | |||
1060 | 1060 | ||
1061 | /** | 1061 | /** |
1062 | * xs_udp_connect_worker - set up a UDP socket | 1062 | * xs_udp_connect_worker - set up a UDP socket |
1063 | * @args: RPC transport to connect | 1063 | * @work: RPC transport to connect |
1064 | * | 1064 | * |
1065 | * Invoked by a work queue tasklet. | 1065 | * Invoked by a work queue tasklet. |
1066 | */ | 1066 | */ |
1067 | static void xs_udp_connect_worker(void *args) | 1067 | static void xs_udp_connect_worker(struct work_struct *work) |
1068 | { | 1068 | { |
1069 | struct rpc_xprt *xprt = (struct rpc_xprt *) args; | 1069 | struct rpc_xprt *xprt = |
1070 | container_of(work, struct rpc_xprt, connect_worker.work); | ||
1070 | struct socket *sock = xprt->sock; | 1071 | struct socket *sock = xprt->sock; |
1071 | int err, status = -EIO; | 1072 | int err, status = -EIO; |
1072 | 1073 | ||
@@ -1144,13 +1145,14 @@ static void xs_tcp_reuse_connection(struct rpc_xprt *xprt) | |||
1144 | 1145 | ||
1145 | /** | 1146 | /** |
1146 | * xs_tcp_connect_worker - connect a TCP socket to a remote endpoint | 1147 | * xs_tcp_connect_worker - connect a TCP socket to a remote endpoint |
1147 | * @args: RPC transport to connect | 1148 | * @work: RPC transport to connect |
1148 | * | 1149 | * |
1149 | * Invoked by a work queue tasklet. | 1150 | * Invoked by a work queue tasklet. |
1150 | */ | 1151 | */ |
1151 | static void xs_tcp_connect_worker(void *args) | 1152 | static void xs_tcp_connect_worker(struct work_struct *work) |
1152 | { | 1153 | { |
1153 | struct rpc_xprt *xprt = (struct rpc_xprt *)args; | 1154 | struct rpc_xprt *xprt = |
1155 | container_of(work, struct rpc_xprt, connect_worker.work); | ||
1154 | struct socket *sock = xprt->sock; | 1156 | struct socket *sock = xprt->sock; |
1155 | int err, status = -EIO; | 1157 | int err, status = -EIO; |
1156 | 1158 | ||
@@ -1375,7 +1377,7 @@ int xs_setup_udp(struct rpc_xprt *xprt, struct rpc_timeout *to) | |||
1375 | /* XXX: header size can vary due to auth type, IPv6, etc. */ | 1377 | /* XXX: header size can vary due to auth type, IPv6, etc. */ |
1376 | xprt->max_payload = (1U << 16) - (MAX_HEADER << 3); | 1378 | xprt->max_payload = (1U << 16) - (MAX_HEADER << 3); |
1377 | 1379 | ||
1378 | INIT_DELAYED_WORK(&xprt->connect_worker, xs_udp_connect_worker, xprt); | 1380 | INIT_DELAYED_WORK(&xprt->connect_worker, xs_udp_connect_worker); |
1379 | xprt->bind_timeout = XS_BIND_TO; | 1381 | xprt->bind_timeout = XS_BIND_TO; |
1380 | xprt->connect_timeout = XS_UDP_CONN_TO; | 1382 | xprt->connect_timeout = XS_UDP_CONN_TO; |
1381 | xprt->reestablish_timeout = XS_UDP_REEST_TO; | 1383 | xprt->reestablish_timeout = XS_UDP_REEST_TO; |
@@ -1420,7 +1422,7 @@ int xs_setup_tcp(struct rpc_xprt *xprt, struct rpc_timeout *to) | |||
1420 | xprt->tsh_size = sizeof(rpc_fraghdr) / sizeof(u32); | 1422 | xprt->tsh_size = sizeof(rpc_fraghdr) / sizeof(u32); |
1421 | xprt->max_payload = RPC_MAX_FRAGMENT_SIZE; | 1423 | xprt->max_payload = RPC_MAX_FRAGMENT_SIZE; |
1422 | 1424 | ||
1423 | INIT_DELAYED_WORK(&xprt->connect_worker, xs_tcp_connect_worker, xprt); | 1425 | INIT_DELAYED_WORK(&xprt->connect_worker, xs_tcp_connect_worker); |
1424 | xprt->bind_timeout = XS_BIND_TO; | 1426 | xprt->bind_timeout = XS_BIND_TO; |
1425 | xprt->connect_timeout = XS_TCP_CONN_TO; | 1427 | xprt->connect_timeout = XS_TCP_CONN_TO; |
1426 | xprt->reestablish_timeout = XS_TCP_INIT_REEST_TO; | 1428 | xprt->reestablish_timeout = XS_TCP_INIT_REEST_TO; |