Skip to content

Commit ffe9386

Browse files
author
J. Bruce Fields
committed
nfsd: move cache proc (un)registration to separate function
Just some minor cleanup. Also I don't see much point in trying to register further proc entries if initial entries fail; so just stop trying in that case. Acked-by: NeilBrown <[email protected]> Signed-off-by: J. Bruce Fields <[email protected]>
1 parent e331f60 commit ffe9386

File tree

1 file changed

+54
-45
lines changed

1 file changed

+54
-45
lines changed

net/sunrpc/cache.c

Lines changed: 54 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -290,44 +290,63 @@ static const struct file_operations cache_flush_operations;
290290
static void do_cache_clean(struct work_struct *work);
291291
static DECLARE_DELAYED_WORK(cache_cleaner, do_cache_clean);
292292

293-
void cache_register(struct cache_detail *cd)
293+
static void remove_cache_proc_entries(struct cache_detail *cd)
294294
{
295-
cd->proc_ent = proc_mkdir(cd->name, proc_net_rpc);
296-
if (cd->proc_ent) {
297-
struct proc_dir_entry *p;
298-
cd->proc_ent->owner = cd->owner;
299-
cd->channel_ent = cd->content_ent = NULL;
295+
if (cd->proc_ent == NULL)
296+
return;
297+
if (cd->flush_ent)
298+
remove_proc_entry("flush", cd->proc_ent);
299+
if (cd->channel_ent)
300+
remove_proc_entry("channel", cd->proc_ent);
301+
if (cd->content_ent)
302+
remove_proc_entry("content", cd->proc_ent);
303+
cd->proc_ent = NULL;
304+
remove_proc_entry(cd->name, proc_net_rpc);
305+
}
300306

301-
p = create_proc_entry("flush", S_IFREG|S_IRUSR|S_IWUSR,
302-
cd->proc_ent);
303-
cd->flush_ent = p;
304-
if (p) {
305-
p->proc_fops = &cache_flush_operations;
306-
p->owner = cd->owner;
307-
p->data = cd;
308-
}
307+
static void create_cache_proc_entries(struct cache_detail *cd)
308+
{
309+
struct proc_dir_entry *p;
309310

310-
if (cd->cache_request || cd->cache_parse) {
311-
p = create_proc_entry("channel", S_IFREG|S_IRUSR|S_IWUSR,
312-
cd->proc_ent);
313-
cd->channel_ent = p;
314-
if (p) {
315-
p->proc_fops = &cache_file_operations;
316-
p->owner = cd->owner;
317-
p->data = cd;
318-
}
319-
}
320-
if (cd->cache_show) {
321-
p = create_proc_entry("content", S_IFREG|S_IRUSR|S_IWUSR,
322-
cd->proc_ent);
323-
cd->content_ent = p;
324-
if (p) {
325-
p->proc_fops = &content_file_operations;
326-
p->owner = cd->owner;
327-
p->data = cd;
328-
}
329-
}
311+
cd->proc_ent = proc_mkdir(cd->name, proc_net_rpc);
312+
if (cd->proc_ent == NULL)
313+
return;
314+
cd->proc_ent->owner = cd->owner;
315+
cd->channel_ent = cd->content_ent = NULL;
316+
317+
p = create_proc_entry("flush", S_IFREG|S_IRUSR|S_IWUSR, cd->proc_ent);
318+
cd->flush_ent = p;
319+
if (p == NULL)
320+
return;
321+
p->proc_fops = &cache_flush_operations;
322+
p->owner = cd->owner;
323+
p->data = cd;
324+
325+
if (cd->cache_request || cd->cache_parse) {
326+
p = create_proc_entry("channel", S_IFREG|S_IRUSR|S_IWUSR,
327+
cd->proc_ent);
328+
cd->channel_ent = p;
329+
if (p == NULL)
330+
return;
331+
p->proc_fops = &cache_file_operations;
332+
p->owner = cd->owner;
333+
p->data = cd;
334+
}
335+
if (cd->cache_show) {
336+
p = create_proc_entry("content", S_IFREG|S_IRUSR|S_IWUSR,
337+
cd->proc_ent);
338+
cd->content_ent = p;
339+
if (p == NULL)
340+
return;
341+
p->proc_fops = &content_file_operations;
342+
p->owner = cd->owner;
343+
p->data = cd;
330344
}
345+
}
346+
347+
void cache_register(struct cache_detail *cd)
348+
{
349+
create_cache_proc_entries(cd);
331350
rwlock_init(&cd->hash_lock);
332351
INIT_LIST_HEAD(&cd->queue);
333352
spin_lock(&cache_list_lock);
@@ -358,17 +377,7 @@ void cache_unregister(struct cache_detail *cd)
358377
list_del_init(&cd->others);
359378
write_unlock(&cd->hash_lock);
360379
spin_unlock(&cache_list_lock);
361-
if (cd->proc_ent) {
362-
if (cd->flush_ent)
363-
remove_proc_entry("flush", cd->proc_ent);
364-
if (cd->channel_ent)
365-
remove_proc_entry("channel", cd->proc_ent);
366-
if (cd->content_ent)
367-
remove_proc_entry("content", cd->proc_ent);
368-
369-
cd->proc_ent = NULL;
370-
remove_proc_entry(cd->name, proc_net_rpc);
371-
}
380+
remove_cache_proc_entries(cd);
372381
if (list_empty(&cache_list)) {
373382
/* module must be being unloaded so its safe to kill the worker */
374383
cancel_delayed_work_sync(&cache_cleaner);

0 commit comments

Comments
 (0)