Commit 82141185 authored by Jeff Layton's avatar Jeff Layton Committed by Chuck Lever

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: default avatarJeff Layton <jlayton@kernel.org>
Reviewed-by: default avatarNeilBrown <neilb@suse.de>
Signed-off-by: default avatarChuck Lever <chuck.lever@oracle.com>
parent 1f696e23
...@@ -335,16 +335,59 @@ nfsd_file_alloc(struct nfsd_file_lookup_key *key, unsigned int may) ...@@ -335,16 +335,59 @@ nfsd_file_alloc(struct nfsd_file_lookup_key *key, unsigned int may)
return nf; return nf;
} }
static void
nfsd_file_fsync(struct nfsd_file *nf)
{
struct file *file = nf->nf_file;
if (!file || !(file->f_mode & FMODE_WRITE))
return;
if (vfs_fsync(file, 1) != 0)
nfsd_reset_write_verifier(net_generic(nf->nf_net, nfsd_net_id));
}
static int
nfsd_file_check_write_error(struct nfsd_file *nf)
{
struct file *file = nf->nf_file;
if (!file || !(file->f_mode & FMODE_WRITE))
return 0;
return filemap_check_wb_err(file->f_mapping, READ_ONCE(file->f_wb_err));
}
static void
nfsd_file_hash_remove(struct nfsd_file *nf)
{
trace_nfsd_file_unhash(nf);
if (nfsd_file_check_write_error(nf))
nfsd_reset_write_verifier(net_generic(nf->nf_net, nfsd_net_id));
rhashtable_remove_fast(&nfsd_file_rhash_tbl, &nf->nf_rhash,
nfsd_file_rhash_params);
}
static bool
nfsd_file_unhash(struct nfsd_file *nf)
{
if (test_and_clear_bit(NFSD_FILE_HASHED, &nf->nf_flags)) {
nfsd_file_hash_remove(nf);
return true;
}
return false;
}
static bool static bool
nfsd_file_free(struct nfsd_file *nf) nfsd_file_free(struct nfsd_file *nf)
{ {
s64 age = ktime_to_ms(ktime_sub(ktime_get(), nf->nf_birthtime)); s64 age = ktime_to_ms(ktime_sub(ktime_get(), nf->nf_birthtime));
bool flush = false; bool flush = false;
trace_nfsd_file_free(nf);
this_cpu_inc(nfsd_file_releases); this_cpu_inc(nfsd_file_releases);
this_cpu_add(nfsd_file_total_age, age); this_cpu_add(nfsd_file_total_age, age);
trace_nfsd_file_put_final(nf);
if (nf->nf_mark) if (nf->nf_mark)
nfsd_file_mark_put(nf->nf_mark); nfsd_file_mark_put(nf->nf_mark);
if (nf->nf_file) { if (nf->nf_file) {
...@@ -378,27 +421,6 @@ nfsd_file_check_writeback(struct nfsd_file *nf) ...@@ -378,27 +421,6 @@ nfsd_file_check_writeback(struct nfsd_file *nf)
mapping_tagged(mapping, PAGECACHE_TAG_WRITEBACK); mapping_tagged(mapping, PAGECACHE_TAG_WRITEBACK);
} }
static int
nfsd_file_check_write_error(struct nfsd_file *nf)
{
struct file *file = nf->nf_file;
if (!file || !(file->f_mode & FMODE_WRITE))
return 0;
return filemap_check_wb_err(file->f_mapping, READ_ONCE(file->f_wb_err));
}
static void
nfsd_file_flush(struct nfsd_file *nf)
{
struct file *file = nf->nf_file;
if (!file || !(file->f_mode & FMODE_WRITE))
return;
if (vfs_fsync(file, 1) != 0)
nfsd_reset_write_verifier(net_generic(nf->nf_net, nfsd_net_id));
}
static void nfsd_file_lru_add(struct nfsd_file *nf) static void nfsd_file_lru_add(struct nfsd_file *nf)
{ {
set_bit(NFSD_FILE_REFERENCED, &nf->nf_flags); set_bit(NFSD_FILE_REFERENCED, &nf->nf_flags);
...@@ -412,31 +434,18 @@ static void nfsd_file_lru_remove(struct nfsd_file *nf) ...@@ -412,31 +434,18 @@ static void nfsd_file_lru_remove(struct nfsd_file *nf)
trace_nfsd_file_lru_del(nf); trace_nfsd_file_lru_del(nf);
} }
static void struct nfsd_file *
nfsd_file_hash_remove(struct nfsd_file *nf) nfsd_file_get(struct nfsd_file *nf)
{
trace_nfsd_file_unhash(nf);
if (nfsd_file_check_write_error(nf))
nfsd_reset_write_verifier(net_generic(nf->nf_net, nfsd_net_id));
rhashtable_remove_fast(&nfsd_file_rhash_tbl, &nf->nf_rhash,
nfsd_file_rhash_params);
}
static bool
nfsd_file_unhash(struct nfsd_file *nf)
{ {
if (test_and_clear_bit(NFSD_FILE_HASHED, &nf->nf_flags)) { if (likely(refcount_inc_not_zero(&nf->nf_ref)))
nfsd_file_hash_remove(nf); return nf;
return true; return NULL;
}
return false;
} }
static void static void
nfsd_file_unhash_and_dispose(struct nfsd_file *nf, struct list_head *dispose) nfsd_file_unhash_and_queue(struct nfsd_file *nf, struct list_head *dispose)
{ {
trace_nfsd_file_unhash_and_dispose(nf); trace_nfsd_file_unhash_and_queue(nf);
if (nfsd_file_unhash(nf)) { if (nfsd_file_unhash(nf)) {
/* caller must call nfsd_file_dispose_list() later */ /* caller must call nfsd_file_dispose_list() later */
nfsd_file_lru_remove(nf); nfsd_file_lru_remove(nf);
...@@ -474,7 +483,7 @@ nfsd_file_put(struct nfsd_file *nf) ...@@ -474,7 +483,7 @@ nfsd_file_put(struct nfsd_file *nf)
nfsd_file_unhash_and_put(nf); nfsd_file_unhash_and_put(nf);
if (!test_bit(NFSD_FILE_HASHED, &nf->nf_flags)) { if (!test_bit(NFSD_FILE_HASHED, &nf->nf_flags)) {
nfsd_file_flush(nf); nfsd_file_fsync(nf);
nfsd_file_put_noref(nf); nfsd_file_put_noref(nf);
} else if (nf->nf_file && test_bit(NFSD_FILE_GC, &nf->nf_flags)) { } else if (nf->nf_file && test_bit(NFSD_FILE_GC, &nf->nf_flags)) {
nfsd_file_put_noref(nf); nfsd_file_put_noref(nf);
...@@ -483,14 +492,6 @@ nfsd_file_put(struct nfsd_file *nf) ...@@ -483,14 +492,6 @@ nfsd_file_put(struct nfsd_file *nf)
nfsd_file_put_noref(nf); nfsd_file_put_noref(nf);
} }
struct nfsd_file *
nfsd_file_get(struct nfsd_file *nf)
{
if (likely(refcount_inc_not_zero(&nf->nf_ref)))
return nf;
return NULL;
}
static void static void
nfsd_file_dispose_list(struct list_head *dispose) nfsd_file_dispose_list(struct list_head *dispose)
{ {
...@@ -499,7 +500,7 @@ nfsd_file_dispose_list(struct list_head *dispose) ...@@ -499,7 +500,7 @@ nfsd_file_dispose_list(struct list_head *dispose)
while(!list_empty(dispose)) { while(!list_empty(dispose)) {
nf = list_first_entry(dispose, struct nfsd_file, nf_lru); nf = list_first_entry(dispose, struct nfsd_file, nf_lru);
list_del_init(&nf->nf_lru); list_del_init(&nf->nf_lru);
nfsd_file_flush(nf); nfsd_file_fsync(nf);
nfsd_file_put_noref(nf); nfsd_file_put_noref(nf);
} }
} }
...@@ -513,7 +514,7 @@ nfsd_file_dispose_list_sync(struct list_head *dispose) ...@@ -513,7 +514,7 @@ nfsd_file_dispose_list_sync(struct list_head *dispose)
while(!list_empty(dispose)) { while(!list_empty(dispose)) {
nf = list_first_entry(dispose, struct nfsd_file, nf_lru); nf = list_first_entry(dispose, struct nfsd_file, nf_lru);
list_del_init(&nf->nf_lru); list_del_init(&nf->nf_lru);
nfsd_file_flush(nf); nfsd_file_fsync(nf);
if (!refcount_dec_and_test(&nf->nf_ref)) if (!refcount_dec_and_test(&nf->nf_ref))
continue; continue;
if (nfsd_file_free(nf)) if (nfsd_file_free(nf))
...@@ -713,7 +714,7 @@ __nfsd_file_close_inode(struct inode *inode, struct list_head *dispose) ...@@ -713,7 +714,7 @@ __nfsd_file_close_inode(struct inode *inode, struct list_head *dispose)
nfsd_file_rhash_params); nfsd_file_rhash_params);
if (!nf) if (!nf)
break; break;
nfsd_file_unhash_and_dispose(nf, dispose); nfsd_file_unhash_and_queue(nf, dispose);
count++; count++;
} while (1); } while (1);
rcu_read_unlock(); rcu_read_unlock();
...@@ -915,7 +916,7 @@ __nfsd_file_cache_purge(struct net *net) ...@@ -915,7 +916,7 @@ __nfsd_file_cache_purge(struct net *net)
nf = rhashtable_walk_next(&iter); nf = rhashtable_walk_next(&iter);
while (!IS_ERR_OR_NULL(nf)) { while (!IS_ERR_OR_NULL(nf)) {
if (!net || nf->nf_net == net) if (!net || nf->nf_net == net)
nfsd_file_unhash_and_dispose(nf, &dispose); nfsd_file_unhash_and_queue(nf, &dispose);
nf = rhashtable_walk_next(&iter); nf = rhashtable_walk_next(&iter);
} }
......
...@@ -906,10 +906,10 @@ DEFINE_EVENT(nfsd_file_class, name, \ ...@@ -906,10 +906,10 @@ DEFINE_EVENT(nfsd_file_class, name, \
TP_PROTO(struct nfsd_file *nf), \ TP_PROTO(struct nfsd_file *nf), \
TP_ARGS(nf)) TP_ARGS(nf))
DEFINE_NFSD_FILE_EVENT(nfsd_file_put_final); DEFINE_NFSD_FILE_EVENT(nfsd_file_free);
DEFINE_NFSD_FILE_EVENT(nfsd_file_unhash); DEFINE_NFSD_FILE_EVENT(nfsd_file_unhash);
DEFINE_NFSD_FILE_EVENT(nfsd_file_put); DEFINE_NFSD_FILE_EVENT(nfsd_file_put);
DEFINE_NFSD_FILE_EVENT(nfsd_file_unhash_and_dispose); DEFINE_NFSD_FILE_EVENT(nfsd_file_unhash_and_queue);
TRACE_EVENT(nfsd_file_alloc, TRACE_EVENT(nfsd_file_alloc,
TP_PROTO( TP_PROTO(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment