@@ -106,112 +106,56 @@ svc_auth_unregister(rpc_authflavor_t flavor)
106106EXPORT_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
153124void 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
167132struct 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
210158struct 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}
0 commit comments