Skip to content

Commit efc36aa

Browse files
neilbrownLinus Torvalds
authored andcommitted
[PATCH] knfsd: Change the store of auth_domains to not be a 'cache'
The 'auth_domain's are simply handles on internal data structures. They do not cache information from user-space, and forcing them into the mold of a 'cache' misrepresents their true nature and causes confusion. Signed-off-by: Neil Brown <neilb@suse.de> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent 3e7b191 commit efc36aa

6 files changed

Lines changed: 81 additions & 145 deletions

File tree

‎fs/nfsd/export.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ static inline int svc_expkey_match (struct svc_expkey *a, struct svc_expkey *b)
242242

243243
static inline void svc_expkey_init(struct svc_expkey *new, struct svc_expkey *item)
244244
{
245-
cache_get(&item->ek_client->h);
245+
kref_get(&item->ek_client->ref);
246246
new->ek_client = item->ek_client;
247247
new->ek_fsidtype = item->ek_fsidtype;
248248
new->ek_fsid[0] = item->ek_fsid[0];
@@ -474,7 +474,7 @@ static inline int svc_export_match(struct svc_export *a, struct svc_export *b)
474474
}
475475
static inline void svc_export_init(struct svc_export *new, struct svc_export *item)
476476
{
477-
cache_get(&item->ex_client->h);
477+
kref_get(&item->ex_client->ref);
478478
new->ex_client = item->ex_client;
479479
new->ex_dentry = dget(item->ex_dentry);
480480
new->ex_mnt = mntget(item->ex_mnt);
@@ -1129,7 +1129,6 @@ exp_delclient(struct nfsctl_client *ncp)
11291129
*/
11301130
if (dom) {
11311131
err = auth_unix_forget_old(dom);
1132-
dom->h.expiry_time = get_seconds();
11331132
auth_domain_put(dom);
11341133
}
11351134

‎include/linux/sunrpc/svcauth.h‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ struct svc_rqst; /* forward decl */
4545
* of ip addresses to the given client.
4646
*/
4747
struct auth_domain {
48-
struct cache_head h;
48+
struct kref ref;
49+
struct hlist_node hash;
4950
char *name;
50-
int flavour;
51+
struct auth_ops *flavour;
5152
};
5253

5354
/*
@@ -86,6 +87,9 @@ struct auth_domain {
8687
*
8788
* domain_release()
8889
* This call releases a domain.
90+
* set_client()
91+
* Givens a pending request (struct svc_rqst), finds and assigns
92+
* an appropriate 'auth_domain' as the client.
8993
*/
9094
struct auth_ops {
9195
char * name;
@@ -117,7 +121,7 @@ extern void svc_auth_unregister(rpc_authflavor_t flavor);
117121
extern struct auth_domain *unix_domain_find(char *name);
118122
extern void auth_domain_put(struct auth_domain *item);
119123
extern int auth_unix_add_addr(struct in_addr addr, struct auth_domain *dom);
120-
extern struct auth_domain *auth_domain_lookup(struct auth_domain *item, int set);
124+
extern struct auth_domain *auth_domain_lookup(char *name, struct auth_domain *new);
121125
extern struct auth_domain *auth_domain_find(char *name);
122126
extern struct auth_domain *auth_unix_lookup(struct in_addr addr);
123127
extern int auth_unix_forget_old(struct auth_domain *dom);
@@ -160,8 +164,6 @@ static inline unsigned long hash_mem(char *buf, int length, int bits)
160164
return hash >> (BITS_PER_LONG - bits);
161165
}
162166

163-
extern struct cache_detail auth_domain_cache, ip_map_cache;
164-
165167
#endif /* __KERNEL__ */
166168

167169
#endif /* _LINUX_SUNRPC_SVCAUTH_H_ */

‎net/sunrpc/auth_gss/svcauth_gss.c‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,8 @@ find_gss_auth_domain(struct gss_ctx *ctx, u32 svc)
645645
return auth_domain_find(name);
646646
}
647647

648+
static struct auth_ops svcauthops_gss;
649+
648650
int
649651
svcauth_gss_register_pseudoflavor(u32 pseudoflavor, char * name)
650652
{
@@ -655,20 +657,18 @@ svcauth_gss_register_pseudoflavor(u32 pseudoflavor, char * name)
655657
new = kmalloc(sizeof(*new), GFP_KERNEL);
656658
if (!new)
657659
goto out;
658-
cache_init(&new->h.h);
660+
kref_init(&new->h.ref);
659661
new->h.name = kmalloc(strlen(name) + 1, GFP_KERNEL);
660662
if (!new->h.name)
661663
goto out_free_dom;
662664
strcpy(new->h.name, name);
663-
new->h.flavour = RPC_AUTH_GSS;
665+
new->h.flavour = &svcauthops_gss;
664666
new->pseudoflavor = pseudoflavor;
665-
new->h.h.expiry_time = NEVER;
666667

667-
test = auth_domain_lookup(&new->h, 1);
668-
if (test == &new->h) {
669-
BUG_ON(atomic_dec_and_test(&new->h.h.refcnt));
670-
} else { /* XXX Duplicate registration? */
668+
test = auth_domain_lookup(name, &new->h);
669+
if (test != &new->h) { /* XXX Duplicate registration? */
671670
auth_domain_put(&new->h);
671+
/* dangling ref-count... */
672672
goto out;
673673
}
674674
return 0;

‎net/sunrpc/sunrpc_syms.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ EXPORT_SYMBOL(nlm_debug);
142142

143143
extern int register_rpc_pipefs(void);
144144
extern void unregister_rpc_pipefs(void);
145+
extern struct cache_detail ip_map_cache;
145146

146147
static int __init
147148
init_sunrpc(void)
@@ -158,7 +159,6 @@ init_sunrpc(void)
158159
#ifdef CONFIG_PROC_FS
159160
rpc_proc_init();
160161
#endif
161-
cache_register(&auth_domain_cache);
162162
cache_register(&ip_map_cache);
163163
out:
164164
return err;
@@ -169,8 +169,6 @@ cleanup_sunrpc(void)
169169
{
170170
unregister_rpc_pipefs();
171171
rpc_destroy_mempool();
172-
if (cache_unregister(&auth_domain_cache))
173-
printk(KERN_ERR "sunrpc: failed to unregister auth_domain cache\n");
174172
if (cache_unregister(&ip_map_cache))
175173
printk(KERN_ERR "sunrpc: failed to unregister ip_map cache\n");
176174
#ifdef RPC_DEBUG

‎net/sunrpc/svcauth.c‎

Lines changed: 33 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -106,112 +106,56 @@ svc_auth_unregister(rpc_authflavor_t flavor)
106106
EXPORT_SYMBOL(svc_auth_unregister);
107107

108108
/**************************************************
109-
* cache for domain name to auth_domain
110-
* Entries are only added by flavours which will normally
111-
* have a structure that 'inherits' from auth_domain.
112-
* e.g. when an IP -> domainname is given to auth_unix,
113-
* and the domain name doesn't exist, it will create a
114-
* auth_unix_domain and add it to this hash table.
115-
* If it finds the name does exist, but isn't AUTH_UNIX,
116-
* it will complain.
109+
* 'auth_domains' are stored in a hash table indexed by name.
110+
* When the last reference to an 'auth_domain' is dropped,
111+
* the object is unhashed and freed.
112+
* If auth_domain_lookup fails to find an entry, it will return
113+
* it's second argument 'new'. If this is non-null, it will
114+
* have been atomically linked into the table.
117115
*/
118116

119-
/*
120-
* Auth auth_domain cache is somewhat different to other caches,
121-
* largely because the entries are possibly of different types:
122-
* each auth flavour has it's own type.
123-
* One consequence of this that DefineCacheLookup cannot
124-
* allocate a new structure as it cannot know the size.
125-
* Notice that the "INIT" code fragment is quite different
126-
* from other caches. When auth_domain_lookup might be
127-
* creating a new domain, the new domain is passed in
128-
* complete and it is used as-is rather than being copied into
129-
* another structure.
130-
*/
131117
#define DN_HASHBITS 6
132118
#define DN_HASHMAX (1<<DN_HASHBITS)
133119
#define DN_HASHMASK (DN_HASHMAX-1)
134120

135-
static struct cache_head *auth_domain_table[DN_HASHMAX];
136-
137-
static void auth_domain_drop(struct cache_head *item, struct cache_detail *cd)
138-
{
139-
struct auth_domain *dom = container_of(item, struct auth_domain, h);
140-
if (cache_put(item,cd))
141-
authtab[dom->flavour]->domain_release(dom);
142-
}
143-
144-
145-
struct cache_detail auth_domain_cache = {
146-
.owner = THIS_MODULE,
147-
.hash_size = DN_HASHMAX,
148-
.hash_table = auth_domain_table,
149-
.name = "auth.domain",
150-
.cache_put = auth_domain_drop,
151-
};
121+
static struct hlist_head auth_domain_table[DN_HASHMAX];
122+
static spinlock_t auth_domain_lock = SPIN_LOCK_UNLOCKED;
152123

153124
void auth_domain_put(struct auth_domain *dom)
154125
{
155-
auth_domain_drop(&dom->h, &auth_domain_cache);
156-
}
157-
158-
static inline int auth_domain_hash(struct auth_domain *item)
159-
{
160-
return hash_str(item->name, DN_HASHBITS);
161-
}
162-
static inline int auth_domain_match(struct auth_domain *tmp, struct auth_domain *item)
163-
{
164-
return strcmp(tmp->name, item->name) == 0;
126+
if (atomic_dec_and_lock(&dom->ref.refcount, &auth_domain_lock)) {
127+
hlist_del(&dom->hash);
128+
dom->flavour->domain_release(dom);
129+
}
165130
}
166131

167132
struct auth_domain *
168-
auth_domain_lookup(struct auth_domain *item, int set)
133+
auth_domain_lookup(char *name, struct auth_domain *new)
169134
{
170-
struct auth_domain *tmp = NULL;
171-
struct cache_head **hp, **head;
172-
head = &auth_domain_cache.hash_table[auth_domain_hash(item)];
173-
174-
if (set)
175-
write_lock(&auth_domain_cache.hash_lock);
176-
else
177-
read_lock(&auth_domain_cache.hash_lock);
178-
for (hp=head; *hp != NULL; hp = &tmp->h.next) {
179-
tmp = container_of(*hp, struct auth_domain, h);
180-
if (!auth_domain_match(tmp, item))
181-
continue;
182-
if (!set) {
183-
cache_get(&tmp->h);
184-
goto out_noset;
135+
struct auth_domain *hp;
136+
struct hlist_head *head;
137+
struct hlist_node *np;
138+
139+
head = &auth_domain_table[hash_str(name, DN_HASHBITS)];
140+
141+
spin_lock(&auth_domain_lock);
142+
143+
hlist_for_each_entry(hp, np, head, hash) {
144+
if (strcmp(hp->name, name)==0) {
145+
kref_get(&hp->ref);
146+
spin_unlock(&auth_domain_lock);
147+
return hp;
185148
}
186-
*hp = tmp->h.next;
187-
tmp->h.next = NULL;
188-
auth_domain_drop(&tmp->h, &auth_domain_cache);
189-
goto out_set;
190149
}
191-
/* Didn't find anything */
192-
if (!set)
193-
goto out_nada;
194-
auth_domain_cache.entries++;
195-
out_set:
196-
item->h.next = *head;
197-
*head = &item->h;
198-
cache_get(&item->h);
199-
write_unlock(&auth_domain_cache.hash_lock);
200-
cache_fresh(&auth_domain_cache, &item->h, item->h.expiry_time);
201-
cache_get(&item->h);
202-
return item;
203-
out_nada:
204-
tmp = NULL;
205-
out_noset:
206-
read_unlock(&auth_domain_cache.hash_lock);
207-
return tmp;
150+
if (new) {
151+
hlist_add_head(&new->hash, head);
152+
kref_get(&new->ref);
153+
}
154+
spin_unlock(&auth_domain_lock);
155+
return new;
208156
}
209157

210158
struct auth_domain *auth_domain_find(char *name)
211159
{
212-
struct auth_domain *rv, ad;
213-
214-
ad.name = name;
215-
rv = auth_domain_lookup(&ad, 0);
216-
return rv;
160+
return auth_domain_lookup(name, NULL);
217161
}

‎net/sunrpc/svcauth_unix.c‎

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -27,41 +27,35 @@ struct unix_domain {
2727
/* other stuff later */
2828
};
2929

30+
extern struct auth_ops svcauth_unix;
31+
3032
struct auth_domain *unix_domain_find(char *name)
3133
{
32-
struct auth_domain *rv, ud;
33-
struct unix_domain *new;
34-
35-
ud.name = name;
36-
37-
rv = auth_domain_lookup(&ud, 0);
38-
39-
foundit:
40-
if (rv && rv->flavour != RPC_AUTH_UNIX) {
41-
auth_domain_put(rv);
42-
return NULL;
43-
}
44-
if (rv)
45-
return rv;
46-
47-
new = kmalloc(sizeof(*new), GFP_KERNEL);
48-
if (new == NULL)
49-
return NULL;
50-
cache_init(&new->h.h);
51-
new->h.name = kstrdup(name, GFP_KERNEL);
52-
new->h.flavour = RPC_AUTH_UNIX;
53-
new->addr_changes = 0;
54-
new->h.h.expiry_time = NEVER;
55-
56-
rv = auth_domain_lookup(&new->h, 2);
57-
if (rv == &new->h) {
58-
if (atomic_dec_and_test(&new->h.h.refcnt)) BUG();
59-
} else {
60-
auth_domain_put(&new->h);
61-
goto foundit;
34+
struct auth_domain *rv;
35+
struct unix_domain *new = NULL;
36+
37+
rv = auth_domain_lookup(name, NULL);
38+
while(1) {
39+
if (rv != &new->h) {
40+
if (new) auth_domain_put(&new->h);
41+
return rv;
42+
}
43+
if (rv && rv->flavour != &svcauth_unix) {
44+
auth_domain_put(rv);
45+
return NULL;
46+
}
47+
if (rv)
48+
return rv;
49+
50+
new = kmalloc(sizeof(*new), GFP_KERNEL);
51+
if (new == NULL)
52+
return NULL;
53+
kref_init(&new->h.ref);
54+
new->h.name = kstrdup(name, GFP_KERNEL);
55+
new->h.flavour = &svcauth_unix;
56+
new->addr_changes = 0;
57+
rv = auth_domain_lookup(name, &new->h);
6258
}
63-
64-
return rv;
6559
}
6660

6761
static void svcauth_unix_domain_release(struct auth_domain *dom)
@@ -130,7 +124,7 @@ static inline void ip_map_init(struct ip_map *new, struct ip_map *item)
130124
}
131125
static inline void ip_map_update(struct ip_map *new, struct ip_map *item)
132126
{
133-
cache_get(&item->m_client->h.h);
127+
kref_get(&item->m_client->h.ref);
134128
new->m_client = item->m_client;
135129
new->m_add_change = item->m_add_change;
136130
}
@@ -272,7 +266,7 @@ int auth_unix_add_addr(struct in_addr addr, struct auth_domain *dom)
272266
struct unix_domain *udom;
273267
struct ip_map ip, *ipmp;
274268

275-
if (dom->flavour != RPC_AUTH_UNIX)
269+
if (dom->flavour != &svcauth_unix)
276270
return -EINVAL;
277271
udom = container_of(dom, struct unix_domain, h);
278272
strcpy(ip.m_class, "nfsd");
@@ -295,7 +289,7 @@ int auth_unix_forget_old(struct auth_domain *dom)
295289
{
296290
struct unix_domain *udom;
297291

298-
if (dom->flavour != RPC_AUTH_UNIX)
292+
if (dom->flavour != &svcauth_unix)
299293
return -EINVAL;
300294
udom = container_of(dom, struct unix_domain, h);
301295
udom->addr_changes++;
@@ -323,7 +317,7 @@ struct auth_domain *auth_unix_lookup(struct in_addr addr)
323317
rv = NULL;
324318
} else {
325319
rv = &ipm->m_client->h;
326-
cache_get(&rv->h);
320+
kref_get(&rv->ref);
327321
}
328322
ip_map_put(&ipm->h, &ip_map_cache);
329323
return rv;
@@ -332,7 +326,6 @@ struct auth_domain *auth_unix_lookup(struct in_addr addr)
332326
void svcauth_unix_purge(void)
333327
{
334328
cache_purge(&ip_map_cache);
335-
cache_purge(&auth_domain_cache);
336329
}
337330

338331
static int
@@ -361,7 +354,7 @@ svcauth_unix_set_client(struct svc_rqst *rqstp)
361354
return SVC_DENIED;
362355
case 0:
363356
rqstp->rq_client = &ipm->m_client->h;
364-
cache_get(&rqstp->rq_client->h);
357+
kref_get(&rqstp->rq_client->ref);
365358
ip_map_put(&ipm->h, &ip_map_cache);
366359
break;
367360
}

0 commit comments

Comments
 (0)