Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <neilb@suse.de>
Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>

+56 -47
+56 -47
net/sunrpc/cache.c
··· 290 290 static void do_cache_clean(struct work_struct *work); 291 291 static DECLARE_DELAYED_WORK(cache_cleaner, do_cache_clean); 292 292 293 + static void remove_cache_proc_entries(struct cache_detail *cd) 294 + { 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 + } 306 + 307 + static void create_cache_proc_entries(struct cache_detail *cd) 308 + { 309 + struct proc_dir_entry *p; 310 + 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; 344 + } 345 + } 346 + 293 347 void cache_register(struct cache_detail *cd) 294 348 { 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; 300 - 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 - } 309 - 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 - } 330 - } 349 + create_cache_proc_entries(cd); 331 350 rwlock_init(&cd->hash_lock); 332 351 INIT_LIST_HEAD(&cd->queue); 333 352 spin_lock(&cache_list_lock); ··· 377 358 list_del_init(&cd->others); 378 359 write_unlock(&cd->hash_lock); 379 360 spin_unlock(&cache_list_lock); 380 - if (cd->proc_ent) { 381 - if (cd->flush_ent) 382 - remove_proc_entry("flush", cd->proc_ent); 383 - if (cd->channel_ent) 384 - remove_proc_entry("channel", cd->proc_ent); 385 - if (cd->content_ent) 386 - remove_proc_entry("content", cd->proc_ent); 387 - 388 - cd->proc_ent = NULL; 389 - remove_proc_entry(cd->name, proc_net_rpc); 390 - } 361 + remove_cache_proc_entries(cd); 391 362 if (list_empty(&cache_list)) { 392 363 /* module must be being unloaded so its safe to kill the worker */ 393 364 cancel_delayed_work_sync(&cache_cleaner);