diff options
author | NeilBrown <neilb@suse.de> | 2006-03-27 04:15:09 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-03-27 11:44:43 -0500 |
commit | baab935ff3bdac20c558809da0d8e8f761840219 (patch) | |
tree | a22c3189505fe8e7ab3820c988ffd771c0b64fa6 /net/sunrpc | |
parent | ebd0cb1af3be2729cc1f574681dfba01fcf458d9 (diff) |
[PATCH] knfsd: Convert sunrpc_cache to use krefs
.. it makes some of the code nicer.
Signed-off-by: Neil Brown <neilb@suse.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'net/sunrpc')
-rw-r--r-- | net/sunrpc/auth_gss/svcauth_gss.c | 28 | ||||
-rw-r--r-- | net/sunrpc/cache.c | 20 | ||||
-rw-r--r-- | net/sunrpc/svcauth_unix.c | 20 |
3 files changed, 32 insertions, 36 deletions
diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c index 380152603d1e..4d7eb9e704da 100644 --- a/net/sunrpc/auth_gss/svcauth_gss.c +++ b/net/sunrpc/auth_gss/svcauth_gss.c | |||
@@ -89,13 +89,11 @@ static void rsi_free(struct rsi *rsii) | |||
89 | kfree(rsii->out_token.data); | 89 | kfree(rsii->out_token.data); |
90 | } | 90 | } |
91 | 91 | ||
92 | static void rsi_put(struct cache_head *item, struct cache_detail *cd) | 92 | static void rsi_put(struct kref *ref) |
93 | { | 93 | { |
94 | struct rsi *rsii = container_of(item, struct rsi, h); | 94 | struct rsi *rsii = container_of(ref, struct rsi, h.ref); |
95 | if (cache_put(item, cd)) { | 95 | rsi_free(rsii); |
96 | rsi_free(rsii); | 96 | kfree(rsii); |
97 | kfree(rsii); | ||
98 | } | ||
99 | } | 97 | } |
100 | 98 | ||
101 | static inline int rsi_hash(struct rsi *item) | 99 | static inline int rsi_hash(struct rsi *item) |
@@ -267,7 +265,7 @@ static int rsi_parse(struct cache_detail *cd, | |||
267 | out: | 265 | out: |
268 | rsi_free(&rsii); | 266 | rsi_free(&rsii); |
269 | if (rsip) | 267 | if (rsip) |
270 | rsi_put(&rsip->h, &rsi_cache); | 268 | cache_put(&rsip->h, &rsi_cache); |
271 | else | 269 | else |
272 | status = -ENOMEM; | 270 | status = -ENOMEM; |
273 | return status; | 271 | return status; |
@@ -357,14 +355,12 @@ static void rsc_free(struct rsc *rsci) | |||
357 | put_group_info(rsci->cred.cr_group_info); | 355 | put_group_info(rsci->cred.cr_group_info); |
358 | } | 356 | } |
359 | 357 | ||
360 | static void rsc_put(struct cache_head *item, struct cache_detail *cd) | 358 | static void rsc_put(struct kref *ref) |
361 | { | 359 | { |
362 | struct rsc *rsci = container_of(item, struct rsc, h); | 360 | struct rsc *rsci = container_of(ref, struct rsc, h.ref); |
363 | 361 | ||
364 | if (cache_put(item, cd)) { | 362 | rsc_free(rsci); |
365 | rsc_free(rsci); | 363 | kfree(rsci); |
366 | kfree(rsci); | ||
367 | } | ||
368 | } | 364 | } |
369 | 365 | ||
370 | static inline int | 366 | static inline int |
@@ -509,7 +505,7 @@ static int rsc_parse(struct cache_detail *cd, | |||
509 | out: | 505 | out: |
510 | rsc_free(&rsci); | 506 | rsc_free(&rsci); |
511 | if (rscp) | 507 | if (rscp) |
512 | rsc_put(&rscp->h, &rsc_cache); | 508 | cache_put(&rscp->h, &rsc_cache); |
513 | else | 509 | else |
514 | status = -ENOMEM; | 510 | status = -ENOMEM; |
515 | return status; | 511 | return status; |
@@ -1076,7 +1072,7 @@ drop: | |||
1076 | ret = SVC_DROP; | 1072 | ret = SVC_DROP; |
1077 | out: | 1073 | out: |
1078 | if (rsci) | 1074 | if (rsci) |
1079 | rsc_put(&rsci->h, &rsc_cache); | 1075 | cache_put(&rsci->h, &rsc_cache); |
1080 | return ret; | 1076 | return ret; |
1081 | } | 1077 | } |
1082 | 1078 | ||
@@ -1168,7 +1164,7 @@ out_err: | |||
1168 | put_group_info(rqstp->rq_cred.cr_group_info); | 1164 | put_group_info(rqstp->rq_cred.cr_group_info); |
1169 | rqstp->rq_cred.cr_group_info = NULL; | 1165 | rqstp->rq_cred.cr_group_info = NULL; |
1170 | if (gsd->rsci) | 1166 | if (gsd->rsci) |
1171 | rsc_put(&gsd->rsci->h, &rsc_cache); | 1167 | cache_put(&gsd->rsci->h, &rsc_cache); |
1172 | gsd->rsci = NULL; | 1168 | gsd->rsci = NULL; |
1173 | 1169 | ||
1174 | return stat; | 1170 | return stat; |
diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c index edcda4fd88e8..dd81e5928172 100644 --- a/net/sunrpc/cache.c +++ b/net/sunrpc/cache.c | |||
@@ -42,7 +42,7 @@ void cache_init(struct cache_head *h) | |||
42 | time_t now = get_seconds(); | 42 | time_t now = get_seconds(); |
43 | h->next = NULL; | 43 | h->next = NULL; |
44 | h->flags = 0; | 44 | h->flags = 0; |
45 | atomic_set(&h->refcnt, 1); | 45 | kref_init(&h->ref); |
46 | h->expiry_time = now + CACHE_NEW_EXPIRY; | 46 | h->expiry_time = now + CACHE_NEW_EXPIRY; |
47 | h->last_refresh = now; | 47 | h->last_refresh = now; |
48 | } | 48 | } |
@@ -81,7 +81,7 @@ struct cache_head *sunrpc_cache_lookup(struct cache_detail *detail, | |||
81 | if (detail->match(tmp, key)) { | 81 | if (detail->match(tmp, key)) { |
82 | cache_get(tmp); | 82 | cache_get(tmp); |
83 | write_unlock(&detail->hash_lock); | 83 | write_unlock(&detail->hash_lock); |
84 | detail->cache_put(new, detail); | 84 | cache_put(new, detail); |
85 | return tmp; | 85 | return tmp; |
86 | } | 86 | } |
87 | } | 87 | } |
@@ -145,7 +145,7 @@ struct cache_head *sunrpc_cache_update(struct cache_detail *detail, | |||
145 | /* We need to insert a new entry */ | 145 | /* We need to insert a new entry */ |
146 | tmp = detail->alloc(); | 146 | tmp = detail->alloc(); |
147 | if (!tmp) { | 147 | if (!tmp) { |
148 | detail->cache_put(old, detail); | 148 | cache_put(old, detail); |
149 | return NULL; | 149 | return NULL; |
150 | } | 150 | } |
151 | cache_init(tmp); | 151 | cache_init(tmp); |
@@ -165,7 +165,7 @@ struct cache_head *sunrpc_cache_update(struct cache_detail *detail, | |||
165 | write_unlock(&detail->hash_lock); | 165 | write_unlock(&detail->hash_lock); |
166 | cache_fresh_unlocked(tmp, detail, is_new); | 166 | cache_fresh_unlocked(tmp, detail, is_new); |
167 | cache_fresh_unlocked(old, detail, 0); | 167 | cache_fresh_unlocked(old, detail, 0); |
168 | detail->cache_put(old, detail); | 168 | cache_put(old, detail); |
169 | return tmp; | 169 | return tmp; |
170 | } | 170 | } |
171 | EXPORT_SYMBOL(sunrpc_cache_update); | 171 | EXPORT_SYMBOL(sunrpc_cache_update); |
@@ -234,7 +234,7 @@ int cache_check(struct cache_detail *detail, | |||
234 | cache_defer_req(rqstp, h); | 234 | cache_defer_req(rqstp, h); |
235 | 235 | ||
236 | if (rv) | 236 | if (rv) |
237 | detail->cache_put(h, detail); | 237 | cache_put(h, detail); |
238 | return rv; | 238 | return rv; |
239 | } | 239 | } |
240 | 240 | ||
@@ -431,7 +431,7 @@ static int cache_clean(void) | |||
431 | if (test_and_clear_bit(CACHE_PENDING, &ch->flags)) | 431 | if (test_and_clear_bit(CACHE_PENDING, &ch->flags)) |
432 | queue_loose(current_detail, ch); | 432 | queue_loose(current_detail, ch); |
433 | 433 | ||
434 | if (atomic_read(&ch->refcnt) == 1) | 434 | if (atomic_read(&ch->ref.refcount) == 1) |
435 | break; | 435 | break; |
436 | } | 436 | } |
437 | if (ch) { | 437 | if (ch) { |
@@ -446,7 +446,7 @@ static int cache_clean(void) | |||
446 | current_index ++; | 446 | current_index ++; |
447 | spin_unlock(&cache_list_lock); | 447 | spin_unlock(&cache_list_lock); |
448 | if (ch) | 448 | if (ch) |
449 | d->cache_put(ch, d); | 449 | cache_put(ch, d); |
450 | } else | 450 | } else |
451 | spin_unlock(&cache_list_lock); | 451 | spin_unlock(&cache_list_lock); |
452 | 452 | ||
@@ -723,7 +723,7 @@ cache_read(struct file *filp, char __user *buf, size_t count, loff_t *ppos) | |||
723 | !test_bit(CACHE_PENDING, &rq->item->flags)) { | 723 | !test_bit(CACHE_PENDING, &rq->item->flags)) { |
724 | list_del(&rq->q.list); | 724 | list_del(&rq->q.list); |
725 | spin_unlock(&queue_lock); | 725 | spin_unlock(&queue_lock); |
726 | cd->cache_put(rq->item, cd); | 726 | cache_put(rq->item, cd); |
727 | kfree(rq->buf); | 727 | kfree(rq->buf); |
728 | kfree(rq); | 728 | kfree(rq); |
729 | } else | 729 | } else |
@@ -906,7 +906,7 @@ static void queue_loose(struct cache_detail *detail, struct cache_head *ch) | |||
906 | continue; | 906 | continue; |
907 | list_del(&cr->q.list); | 907 | list_del(&cr->q.list); |
908 | spin_unlock(&queue_lock); | 908 | spin_unlock(&queue_lock); |
909 | detail->cache_put(cr->item, detail); | 909 | cache_put(cr->item, detail); |
910 | kfree(cr->buf); | 910 | kfree(cr->buf); |
911 | kfree(cr); | 911 | kfree(cr); |
912 | return; | 912 | return; |
@@ -1192,7 +1192,7 @@ static int c_show(struct seq_file *m, void *p) | |||
1192 | 1192 | ||
1193 | ifdebug(CACHE) | 1193 | ifdebug(CACHE) |
1194 | seq_printf(m, "# expiry=%ld refcnt=%d flags=%lx\n", | 1194 | seq_printf(m, "# expiry=%ld refcnt=%d flags=%lx\n", |
1195 | cp->expiry_time, atomic_read(&cp->refcnt), cp->flags); | 1195 | cp->expiry_time, atomic_read(&cp->ref.refcount), cp->flags); |
1196 | cache_get(cp); | 1196 | cache_get(cp); |
1197 | if (cache_check(cd, cp, NULL)) | 1197 | if (cache_check(cd, cp, NULL)) |
1198 | /* cache_check does a cache_put on failure */ | 1198 | /* cache_check does a cache_put on failure */ |
diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c index 7e38621a20b7..11020c0b7db5 100644 --- a/net/sunrpc/svcauth_unix.c +++ b/net/sunrpc/svcauth_unix.c | |||
@@ -84,15 +84,15 @@ struct ip_map { | |||
84 | }; | 84 | }; |
85 | static struct cache_head *ip_table[IP_HASHMAX]; | 85 | static struct cache_head *ip_table[IP_HASHMAX]; |
86 | 86 | ||
87 | static void ip_map_put(struct cache_head *item, struct cache_detail *cd) | 87 | static void ip_map_put(struct kref *kref) |
88 | { | 88 | { |
89 | struct cache_head *item = container_of(kref, struct cache_head, ref); | ||
89 | struct ip_map *im = container_of(item, struct ip_map,h); | 90 | struct ip_map *im = container_of(item, struct ip_map,h); |
90 | if (cache_put(item, cd)) { | 91 | |
91 | if (test_bit(CACHE_VALID, &item->flags) && | 92 | if (test_bit(CACHE_VALID, &item->flags) && |
92 | !test_bit(CACHE_NEGATIVE, &item->flags)) | 93 | !test_bit(CACHE_NEGATIVE, &item->flags)) |
93 | auth_domain_put(&im->m_client->h); | 94 | auth_domain_put(&im->m_client->h); |
94 | kfree(im); | 95 | kfree(im); |
95 | } | ||
96 | } | 96 | } |
97 | 97 | ||
98 | #if IP_HASHBITS == 8 | 98 | #if IP_HASHBITS == 8 |
@@ -315,7 +315,7 @@ static int ip_map_update(struct ip_map *ipm, struct unix_domain *udom, time_t ex | |||
315 | hash_ip((unsigned long)ipm->m_addr.s_addr)); | 315 | hash_ip((unsigned long)ipm->m_addr.s_addr)); |
316 | if (!ch) | 316 | if (!ch) |
317 | return -ENOMEM; | 317 | return -ENOMEM; |
318 | ip_map_put(ch, &ip_map_cache); | 318 | cache_put(ch, &ip_map_cache); |
319 | return 0; | 319 | return 0; |
320 | } | 320 | } |
321 | 321 | ||
@@ -369,7 +369,7 @@ struct auth_domain *auth_unix_lookup(struct in_addr addr) | |||
369 | rv = &ipm->m_client->h; | 369 | rv = &ipm->m_client->h; |
370 | kref_get(&rv->ref); | 370 | kref_get(&rv->ref); |
371 | } | 371 | } |
372 | ip_map_put(&ipm->h, &ip_map_cache); | 372 | cache_put(&ipm->h, &ip_map_cache); |
373 | return rv; | 373 | return rv; |
374 | } | 374 | } |
375 | 375 | ||
@@ -403,7 +403,7 @@ svcauth_unix_set_client(struct svc_rqst *rqstp) | |||
403 | case 0: | 403 | case 0: |
404 | rqstp->rq_client = &ipm->m_client->h; | 404 | rqstp->rq_client = &ipm->m_client->h; |
405 | kref_get(&rqstp->rq_client->ref); | 405 | kref_get(&rqstp->rq_client->ref); |
406 | ip_map_put(&ipm->h, &ip_map_cache); | 406 | cache_put(&ipm->h, &ip_map_cache); |
407 | break; | 407 | break; |
408 | } | 408 | } |
409 | return SVC_OK; | 409 | return SVC_OK; |