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

Configure Feed

Select the types of activity you want to include in your feed.

nfsd: reorganize filecache.c

In a coming patch, we're going to rework how the filecache refcounting
works. Move some code around in the function to reduce the churn in the
later patches, and rename some of the functions with (hopefully) clearer
names: nfsd_file_flush becomes nfsd_file_fsync, and
nfsd_file_unhash_and_dispose is renamed to nfsd_file_unhash_and_queue.

Also, the nfsd_file_put_final tracepoint is renamed to nfsd_file_free,
to better match the name of the function from which it's called.

Signed-off-by: Jeff Layton <jlayton@kernel.org>
Reviewed-by: NeilBrown <neilb@suse.de>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>

authored by

Jeff Layton and committed by
Chuck Lever
82141185 1f696e23

+58 -57
+56 -55
fs/nfsd/filecache.c
··· 335 335 return nf; 336 336 } 337 337 338 + static void 339 + nfsd_file_fsync(struct nfsd_file *nf) 340 + { 341 + struct file *file = nf->nf_file; 342 + 343 + if (!file || !(file->f_mode & FMODE_WRITE)) 344 + return; 345 + if (vfs_fsync(file, 1) != 0) 346 + nfsd_reset_write_verifier(net_generic(nf->nf_net, nfsd_net_id)); 347 + } 348 + 349 + static int 350 + nfsd_file_check_write_error(struct nfsd_file *nf) 351 + { 352 + struct file *file = nf->nf_file; 353 + 354 + if (!file || !(file->f_mode & FMODE_WRITE)) 355 + return 0; 356 + return filemap_check_wb_err(file->f_mapping, READ_ONCE(file->f_wb_err)); 357 + } 358 + 359 + static void 360 + nfsd_file_hash_remove(struct nfsd_file *nf) 361 + { 362 + trace_nfsd_file_unhash(nf); 363 + 364 + if (nfsd_file_check_write_error(nf)) 365 + nfsd_reset_write_verifier(net_generic(nf->nf_net, nfsd_net_id)); 366 + rhashtable_remove_fast(&nfsd_file_rhash_tbl, &nf->nf_rhash, 367 + nfsd_file_rhash_params); 368 + } 369 + 370 + static bool 371 + nfsd_file_unhash(struct nfsd_file *nf) 372 + { 373 + if (test_and_clear_bit(NFSD_FILE_HASHED, &nf->nf_flags)) { 374 + nfsd_file_hash_remove(nf); 375 + return true; 376 + } 377 + return false; 378 + } 379 + 338 380 static bool 339 381 nfsd_file_free(struct nfsd_file *nf) 340 382 { 341 383 s64 age = ktime_to_ms(ktime_sub(ktime_get(), nf->nf_birthtime)); 342 384 bool flush = false; 343 385 386 + trace_nfsd_file_free(nf); 387 + 344 388 this_cpu_inc(nfsd_file_releases); 345 389 this_cpu_add(nfsd_file_total_age, age); 346 390 347 - trace_nfsd_file_put_final(nf); 348 391 if (nf->nf_mark) 349 392 nfsd_file_mark_put(nf->nf_mark); 350 393 if (nf->nf_file) { ··· 421 378 mapping_tagged(mapping, PAGECACHE_TAG_WRITEBACK); 422 379 } 423 380 424 - static int 425 - nfsd_file_check_write_error(struct nfsd_file *nf) 426 - { 427 - struct file *file = nf->nf_file; 428 - 429 - if (!file || !(file->f_mode & FMODE_WRITE)) 430 - return 0; 431 - return filemap_check_wb_err(file->f_mapping, READ_ONCE(file->f_wb_err)); 432 - } 433 - 434 - static void 435 - nfsd_file_flush(struct nfsd_file *nf) 436 - { 437 - struct file *file = nf->nf_file; 438 - 439 - if (!file || !(file->f_mode & FMODE_WRITE)) 440 - return; 441 - if (vfs_fsync(file, 1) != 0) 442 - nfsd_reset_write_verifier(net_generic(nf->nf_net, nfsd_net_id)); 443 - } 444 - 445 381 static void nfsd_file_lru_add(struct nfsd_file *nf) 446 382 { 447 383 set_bit(NFSD_FILE_REFERENCED, &nf->nf_flags); ··· 434 412 trace_nfsd_file_lru_del(nf); 435 413 } 436 414 437 - static void 438 - nfsd_file_hash_remove(struct nfsd_file *nf) 415 + struct nfsd_file * 416 + nfsd_file_get(struct nfsd_file *nf) 439 417 { 440 - trace_nfsd_file_unhash(nf); 441 - 442 - if (nfsd_file_check_write_error(nf)) 443 - nfsd_reset_write_verifier(net_generic(nf->nf_net, nfsd_net_id)); 444 - rhashtable_remove_fast(&nfsd_file_rhash_tbl, &nf->nf_rhash, 445 - nfsd_file_rhash_params); 446 - } 447 - 448 - static bool 449 - nfsd_file_unhash(struct nfsd_file *nf) 450 - { 451 - if (test_and_clear_bit(NFSD_FILE_HASHED, &nf->nf_flags)) { 452 - nfsd_file_hash_remove(nf); 453 - return true; 454 - } 455 - return false; 418 + if (likely(refcount_inc_not_zero(&nf->nf_ref))) 419 + return nf; 420 + return NULL; 456 421 } 457 422 458 423 static void 459 - nfsd_file_unhash_and_dispose(struct nfsd_file *nf, struct list_head *dispose) 424 + nfsd_file_unhash_and_queue(struct nfsd_file *nf, struct list_head *dispose) 460 425 { 461 - trace_nfsd_file_unhash_and_dispose(nf); 426 + trace_nfsd_file_unhash_and_queue(nf); 462 427 if (nfsd_file_unhash(nf)) { 463 428 /* caller must call nfsd_file_dispose_list() later */ 464 429 nfsd_file_lru_remove(nf); ··· 483 474 nfsd_file_unhash_and_put(nf); 484 475 485 476 if (!test_bit(NFSD_FILE_HASHED, &nf->nf_flags)) { 486 - nfsd_file_flush(nf); 477 + nfsd_file_fsync(nf); 487 478 nfsd_file_put_noref(nf); 488 479 } else if (nf->nf_file && test_bit(NFSD_FILE_GC, &nf->nf_flags)) { 489 480 nfsd_file_put_noref(nf); 490 481 nfsd_file_schedule_laundrette(); 491 482 } else 492 483 nfsd_file_put_noref(nf); 493 - } 494 - 495 - struct nfsd_file * 496 - nfsd_file_get(struct nfsd_file *nf) 497 - { 498 - if (likely(refcount_inc_not_zero(&nf->nf_ref))) 499 - return nf; 500 - return NULL; 501 484 } 502 485 503 486 static void ··· 500 499 while(!list_empty(dispose)) { 501 500 nf = list_first_entry(dispose, struct nfsd_file, nf_lru); 502 501 list_del_init(&nf->nf_lru); 503 - nfsd_file_flush(nf); 502 + nfsd_file_fsync(nf); 504 503 nfsd_file_put_noref(nf); 505 504 } 506 505 } ··· 514 513 while(!list_empty(dispose)) { 515 514 nf = list_first_entry(dispose, struct nfsd_file, nf_lru); 516 515 list_del_init(&nf->nf_lru); 517 - nfsd_file_flush(nf); 516 + nfsd_file_fsync(nf); 518 517 if (!refcount_dec_and_test(&nf->nf_ref)) 519 518 continue; 520 519 if (nfsd_file_free(nf)) ··· 714 713 nfsd_file_rhash_params); 715 714 if (!nf) 716 715 break; 717 - nfsd_file_unhash_and_dispose(nf, dispose); 716 + nfsd_file_unhash_and_queue(nf, dispose); 718 717 count++; 719 718 } while (1); 720 719 rcu_read_unlock(); ··· 916 915 nf = rhashtable_walk_next(&iter); 917 916 while (!IS_ERR_OR_NULL(nf)) { 918 917 if (!net || nf->nf_net == net) 919 - nfsd_file_unhash_and_dispose(nf, &dispose); 918 + nfsd_file_unhash_and_queue(nf, &dispose); 920 919 nf = rhashtable_walk_next(&iter); 921 920 } 922 921
+2 -2
fs/nfsd/trace.h
··· 906 906 TP_PROTO(struct nfsd_file *nf), \ 907 907 TP_ARGS(nf)) 908 908 909 - DEFINE_NFSD_FILE_EVENT(nfsd_file_put_final); 909 + DEFINE_NFSD_FILE_EVENT(nfsd_file_free); 910 910 DEFINE_NFSD_FILE_EVENT(nfsd_file_unhash); 911 911 DEFINE_NFSD_FILE_EVENT(nfsd_file_put); 912 - DEFINE_NFSD_FILE_EVENT(nfsd_file_unhash_and_dispose); 912 + DEFINE_NFSD_FILE_EVENT(nfsd_file_unhash_and_queue); 913 913 914 914 TRACE_EVENT(nfsd_file_alloc, 915 915 TP_PROTO(