diff options
author | Sasha Levin <sasha.levin@oracle.com> | 2013-02-27 20:06:00 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-02-27 22:10:24 -0500 |
commit | b67bfe0d42cac56c512dd5da4b1b347a23f4b70a (patch) | |
tree | 3d465aea12b97683f26ffa38eba8744469de9997 /fs/lockd/host.c | |
parent | 1e142b29e210b5dfb2deeb6ce2210b60af16d2a6 (diff) |
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived
list_for_each_entry(pos, head, member)
The hlist ones were greedy and wanted an extra parameter:
hlist_for_each_entry(tpos, pos, head, member)
Why did they need an extra pos parameter? I'm not quite sure. Not only
they don't really need it, it also prevents the iterator from looking
exactly like the list iterator, which is unfortunate.
Besides the semantic patch, there was some manual work required:
- Fix up the actual hlist iterators in linux/list.h
- Fix up the declaration of other iterators based on the hlist ones.
- A very small amount of places were using the 'node' parameter, this
was modified to use 'obj->member' instead.
- Coccinelle didn't handle the hlist_for_each_entry_safe iterator
properly, so those had to be fixed up manually.
The semantic patch which is mostly the work of Peter Senna Tschudin is here:
@@
iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;
type T;
expression a,c,d,e;
identifier b;
statement S;
@@
-T b;
<+... when != b
(
hlist_for_each_entry(a,
- b,
c, d) S
|
hlist_for_each_entry_continue(a,
- b,
c) S
|
hlist_for_each_entry_from(a,
- b,
c) S
|
hlist_for_each_entry_rcu(a,
- b,
c, d) S
|
hlist_for_each_entry_rcu_bh(a,
- b,
c, d) S
|
hlist_for_each_entry_continue_rcu_bh(a,
- b,
c) S
|
for_each_busy_worker(a, c,
- b,
d) S
|
ax25_uid_for_each(a,
- b,
c) S
|
ax25_for_each(a,
- b,
c) S
|
inet_bind_bucket_for_each(a,
- b,
c) S
|
sctp_for_each_hentry(a,
- b,
c) S
|
sk_for_each(a,
- b,
c) S
|
sk_for_each_rcu(a,
- b,
c) S
|
sk_for_each_from
-(a, b)
+(a)
S
+ sk_for_each_from(a) S
|
sk_for_each_safe(a,
- b,
c, d) S
|
sk_for_each_bound(a,
- b,
c) S
|
hlist_for_each_entry_safe(a,
- b,
c, d, e) S
|
hlist_for_each_entry_continue_rcu(a,
- b,
c) S
|
nr_neigh_for_each(a,
- b,
c) S
|
nr_neigh_for_each_safe(a,
- b,
c, d) S
|
nr_node_for_each(a,
- b,
c) S
|
nr_node_for_each_safe(a,
- b,
c, d) S
|
- for_each_gfn_sp(a, c, d, b) S
+ for_each_gfn_sp(a, c, d) S
|
- for_each_gfn_indirect_valid_sp(a, c, d, b) S
+ for_each_gfn_indirect_valid_sp(a, c, d) S
|
for_each_host(a,
- b,
c) S
|
for_each_host_safe(a,
- b,
c, d) S
|
for_each_mesh_entry(a,
- b,
c, d) S
)
...+>
[akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
[akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
[akpm@linux-foundation.org: checkpatch fixes]
[akpm@linux-foundation.org: fix warnings]
[akpm@linux-foudnation.org: redo intrusive kvm changes]
Tested-by: Peter Senna Tschudin <peter.senna@gmail.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/lockd/host.c')
-rw-r--r-- | fs/lockd/host.c | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/fs/lockd/host.c b/fs/lockd/host.c index 0e17090c310f..abdd75d44dd4 100644 --- a/fs/lockd/host.c +++ b/fs/lockd/host.c | |||
@@ -32,15 +32,15 @@ | |||
32 | static struct hlist_head nlm_server_hosts[NLM_HOST_NRHASH]; | 32 | static struct hlist_head nlm_server_hosts[NLM_HOST_NRHASH]; |
33 | static struct hlist_head nlm_client_hosts[NLM_HOST_NRHASH]; | 33 | static struct hlist_head nlm_client_hosts[NLM_HOST_NRHASH]; |
34 | 34 | ||
35 | #define for_each_host(host, pos, chain, table) \ | 35 | #define for_each_host(host, chain, table) \ |
36 | for ((chain) = (table); \ | 36 | for ((chain) = (table); \ |
37 | (chain) < (table) + NLM_HOST_NRHASH; ++(chain)) \ | 37 | (chain) < (table) + NLM_HOST_NRHASH; ++(chain)) \ |
38 | hlist_for_each_entry((host), (pos), (chain), h_hash) | 38 | hlist_for_each_entry((host), (chain), h_hash) |
39 | 39 | ||
40 | #define for_each_host_safe(host, pos, next, chain, table) \ | 40 | #define for_each_host_safe(host, next, chain, table) \ |
41 | for ((chain) = (table); \ | 41 | for ((chain) = (table); \ |
42 | (chain) < (table) + NLM_HOST_NRHASH; ++(chain)) \ | 42 | (chain) < (table) + NLM_HOST_NRHASH; ++(chain)) \ |
43 | hlist_for_each_entry_safe((host), (pos), (next), \ | 43 | hlist_for_each_entry_safe((host), (next), \ |
44 | (chain), h_hash) | 44 | (chain), h_hash) |
45 | 45 | ||
46 | static unsigned long nrhosts; | 46 | static unsigned long nrhosts; |
@@ -225,7 +225,6 @@ struct nlm_host *nlmclnt_lookup_host(const struct sockaddr *sap, | |||
225 | .net = net, | 225 | .net = net, |
226 | }; | 226 | }; |
227 | struct hlist_head *chain; | 227 | struct hlist_head *chain; |
228 | struct hlist_node *pos; | ||
229 | struct nlm_host *host; | 228 | struct nlm_host *host; |
230 | struct nsm_handle *nsm = NULL; | 229 | struct nsm_handle *nsm = NULL; |
231 | struct lockd_net *ln = net_generic(net, lockd_net_id); | 230 | struct lockd_net *ln = net_generic(net, lockd_net_id); |
@@ -237,7 +236,7 @@ struct nlm_host *nlmclnt_lookup_host(const struct sockaddr *sap, | |||
237 | mutex_lock(&nlm_host_mutex); | 236 | mutex_lock(&nlm_host_mutex); |
238 | 237 | ||
239 | chain = &nlm_client_hosts[nlm_hash_address(sap)]; | 238 | chain = &nlm_client_hosts[nlm_hash_address(sap)]; |
240 | hlist_for_each_entry(host, pos, chain, h_hash) { | 239 | hlist_for_each_entry(host, chain, h_hash) { |
241 | if (host->net != net) | 240 | if (host->net != net) |
242 | continue; | 241 | continue; |
243 | if (!rpc_cmp_addr(nlm_addr(host), sap)) | 242 | if (!rpc_cmp_addr(nlm_addr(host), sap)) |
@@ -322,7 +321,6 @@ struct nlm_host *nlmsvc_lookup_host(const struct svc_rqst *rqstp, | |||
322 | const size_t hostname_len) | 321 | const size_t hostname_len) |
323 | { | 322 | { |
324 | struct hlist_head *chain; | 323 | struct hlist_head *chain; |
325 | struct hlist_node *pos; | ||
326 | struct nlm_host *host = NULL; | 324 | struct nlm_host *host = NULL; |
327 | struct nsm_handle *nsm = NULL; | 325 | struct nsm_handle *nsm = NULL; |
328 | struct sockaddr *src_sap = svc_daddr(rqstp); | 326 | struct sockaddr *src_sap = svc_daddr(rqstp); |
@@ -350,7 +348,7 @@ struct nlm_host *nlmsvc_lookup_host(const struct svc_rqst *rqstp, | |||
350 | nlm_gc_hosts(net); | 348 | nlm_gc_hosts(net); |
351 | 349 | ||
352 | chain = &nlm_server_hosts[nlm_hash_address(ni.sap)]; | 350 | chain = &nlm_server_hosts[nlm_hash_address(ni.sap)]; |
353 | hlist_for_each_entry(host, pos, chain, h_hash) { | 351 | hlist_for_each_entry(host, chain, h_hash) { |
354 | if (host->net != net) | 352 | if (host->net != net) |
355 | continue; | 353 | continue; |
356 | if (!rpc_cmp_addr(nlm_addr(host), ni.sap)) | 354 | if (!rpc_cmp_addr(nlm_addr(host), ni.sap)) |
@@ -515,10 +513,9 @@ static struct nlm_host *next_host_state(struct hlist_head *cache, | |||
515 | { | 513 | { |
516 | struct nlm_host *host; | 514 | struct nlm_host *host; |
517 | struct hlist_head *chain; | 515 | struct hlist_head *chain; |
518 | struct hlist_node *pos; | ||
519 | 516 | ||
520 | mutex_lock(&nlm_host_mutex); | 517 | mutex_lock(&nlm_host_mutex); |
521 | for_each_host(host, pos, chain, cache) { | 518 | for_each_host(host, chain, cache) { |
522 | if (host->h_nsmhandle == nsm | 519 | if (host->h_nsmhandle == nsm |
523 | && host->h_nsmstate != info->state) { | 520 | && host->h_nsmstate != info->state) { |
524 | host->h_nsmstate = info->state; | 521 | host->h_nsmstate = info->state; |
@@ -570,7 +567,6 @@ void nlm_host_rebooted(const struct nlm_reboot *info) | |||
570 | static void nlm_complain_hosts(struct net *net) | 567 | static void nlm_complain_hosts(struct net *net) |
571 | { | 568 | { |
572 | struct hlist_head *chain; | 569 | struct hlist_head *chain; |
573 | struct hlist_node *pos; | ||
574 | struct nlm_host *host; | 570 | struct nlm_host *host; |
575 | 571 | ||
576 | if (net) { | 572 | if (net) { |
@@ -587,7 +583,7 @@ static void nlm_complain_hosts(struct net *net) | |||
587 | dprintk("lockd: %lu hosts left:\n", nrhosts); | 583 | dprintk("lockd: %lu hosts left:\n", nrhosts); |
588 | } | 584 | } |
589 | 585 | ||
590 | for_each_host(host, pos, chain, nlm_server_hosts) { | 586 | for_each_host(host, chain, nlm_server_hosts) { |
591 | if (net && host->net != net) | 587 | if (net && host->net != net) |
592 | continue; | 588 | continue; |
593 | dprintk(" %s (cnt %d use %d exp %ld net %p)\n", | 589 | dprintk(" %s (cnt %d use %d exp %ld net %p)\n", |
@@ -600,14 +596,13 @@ void | |||
600 | nlm_shutdown_hosts_net(struct net *net) | 596 | nlm_shutdown_hosts_net(struct net *net) |
601 | { | 597 | { |
602 | struct hlist_head *chain; | 598 | struct hlist_head *chain; |
603 | struct hlist_node *pos; | ||
604 | struct nlm_host *host; | 599 | struct nlm_host *host; |
605 | 600 | ||
606 | mutex_lock(&nlm_host_mutex); | 601 | mutex_lock(&nlm_host_mutex); |
607 | 602 | ||
608 | /* First, make all hosts eligible for gc */ | 603 | /* First, make all hosts eligible for gc */ |
609 | dprintk("lockd: nuking all hosts in net %p...\n", net); | 604 | dprintk("lockd: nuking all hosts in net %p...\n", net); |
610 | for_each_host(host, pos, chain, nlm_server_hosts) { | 605 | for_each_host(host, chain, nlm_server_hosts) { |
611 | if (net && host->net != net) | 606 | if (net && host->net != net) |
612 | continue; | 607 | continue; |
613 | host->h_expires = jiffies - 1; | 608 | host->h_expires = jiffies - 1; |
@@ -644,11 +639,11 @@ static void | |||
644 | nlm_gc_hosts(struct net *net) | 639 | nlm_gc_hosts(struct net *net) |
645 | { | 640 | { |
646 | struct hlist_head *chain; | 641 | struct hlist_head *chain; |
647 | struct hlist_node *pos, *next; | 642 | struct hlist_node *next; |
648 | struct nlm_host *host; | 643 | struct nlm_host *host; |
649 | 644 | ||
650 | dprintk("lockd: host garbage collection for net %p\n", net); | 645 | dprintk("lockd: host garbage collection for net %p\n", net); |
651 | for_each_host(host, pos, chain, nlm_server_hosts) { | 646 | for_each_host(host, chain, nlm_server_hosts) { |
652 | if (net && host->net != net) | 647 | if (net && host->net != net) |
653 | continue; | 648 | continue; |
654 | host->h_inuse = 0; | 649 | host->h_inuse = 0; |
@@ -657,7 +652,7 @@ nlm_gc_hosts(struct net *net) | |||
657 | /* Mark all hosts that hold locks, blocks or shares */ | 652 | /* Mark all hosts that hold locks, blocks or shares */ |
658 | nlmsvc_mark_resources(net); | 653 | nlmsvc_mark_resources(net); |
659 | 654 | ||
660 | for_each_host_safe(host, pos, next, chain, nlm_server_hosts) { | 655 | for_each_host_safe(host, next, chain, nlm_server_hosts) { |
661 | if (net && host->net != net) | 656 | if (net && host->net != net) |
662 | continue; | 657 | continue; |
663 | if (atomic_read(&host->h_count) || host->h_inuse | 658 | if (atomic_read(&host->h_count) || host->h_inuse |