<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel.git/fs/nfsd/filecache.c, branch linux-6.3.y</title>
<subtitle>Hosts the 0x221E linux distro kernel.
</subtitle>
<id>https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-6.3.y</id>
<link rel='self' href='https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-6.3.y'/>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/'/>
<updated>2023-02-20T14:20:59Z</updated>
<entry>
<title>nfsd: don't fsync nfsd_files on last close</title>
<updated>2023-02-20T14:20:59Z</updated>
<author>
<name>Jeff Layton</name>
</author>
<published>2023-02-07T17:02:46Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=4c475eee02375ade6e864f1db16976ba0d96a0a2'/>
<id>urn:sha1:4c475eee02375ade6e864f1db16976ba0d96a0a2</id>
<content type='text'>
Most of the time, NFSv4 clients issue a COMMIT before the final CLOSE of
an open stateid, so with NFSv4, the fsync in the nfsd_file_free path is
usually a no-op and doesn't block.

We have a customer running knfsd over very slow storage (XFS over Ceph
RBD). They were using the "async" export option because performance was
more important than data integrity for this application. That export
option turns NFSv4 COMMIT calls into no-ops. Due to the fsync in this
codepath however, their final CLOSE calls would still stall (since a
CLOSE effectively became a COMMIT).

I think this fsync is not strictly necessary. We only use that result to
reset the write verifier. Instead of fsync'ing all of the data when we
free an nfsd_file, we can just check for writeback errors when one is
acquired and when it is freed.

If the client never comes back, then it'll never see the error anyway
and there is no point in resetting it. If an error occurs after the
nfsd_file is removed from the cache but before the inode is evicted,
then it will reset the write verifier on the next nfsd_file_acquire,
(since there will be an unseen error).

The only exception here is if something else opens and fsyncs the file
during that window. Given that local applications work with this
limitation today, I don't see that as an issue.

Link: https://bugzilla.redhat.com/show_bug.cgi?id=2166658
Fixes: ac3a2585f018 ("nfsd: rework refcounting in filecache")
Reported-and-tested-by: Pierguido Lambri &lt;plambri@redhat.com&gt;
Signed-off-by: Jeff Layton &lt;jlayton@kernel.org&gt;
Signed-off-by: Chuck Lever &lt;chuck.lever@oracle.com&gt;
</content>
</entry>
<entry>
<title>nfsd: allow nfsd_file_get to sanely handle a NULL pointer</title>
<updated>2023-02-20T14:20:21Z</updated>
<author>
<name>Jeff Layton</name>
</author>
<published>2023-01-06T15:33:47Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=70f62231cdfd52357836733dd31db787e0412ab2'/>
<id>urn:sha1:70f62231cdfd52357836733dd31db787e0412ab2</id>
<content type='text'>
...and remove some now-useless NULL pointer checks in its callers.

Suggested-by: NeilBrown &lt;neilb@suse.de&gt;
Signed-off-by: Jeff Layton &lt;jlayton@kernel.org&gt;
Signed-off-by: Chuck Lever &lt;chuck.lever@oracle.com&gt;
</content>
</entry>
<entry>
<title>nfsd: don't free files unconditionally in __nfsd_file_cache_purge</title>
<updated>2023-01-23T14:51:17Z</updated>
<author>
<name>Jeff Layton</name>
</author>
<published>2023-01-20T19:52:14Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=4bdbba54e9b1c769da8ded9abd209d765715e1d6'/>
<id>urn:sha1:4bdbba54e9b1c769da8ded9abd209d765715e1d6</id>
<content type='text'>
nfsd_file_cache_purge is called when the server is shutting down, in
which case, tearing things down is generally fine, but it also gets
called when the exports cache is flushed.

Instead of walking the cache and freeing everything unconditionally,
handle it the same as when we have a notification of conflicting access.

Fixes: ac3a2585f018 ("nfsd: rework refcounting in filecache")
Reported-by: Ruben Vestergaard &lt;rubenv@drcmr.dk&gt;
Reported-by: Torkil Svensgaard &lt;torkil@drcmr.dk&gt;
Reported-by: Shachar Kagan &lt;skagan@nvidia.com&gt;
Signed-off-by: Jeff Layton &lt;jlayton@kernel.org&gt;
Tested-by: Shachar Kagan &lt;skagan@nvidia.com&gt;
Signed-off-by: Chuck Lever &lt;chuck.lever@oracle.com&gt;
</content>
</entry>
<entry>
<title>nfsd: fix handling of cached open files in nfsd4_open codepath</title>
<updated>2023-01-06T18:17:06Z</updated>
<author>
<name>Jeff Layton</name>
</author>
<published>2023-01-05T19:55:56Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=0b3a551fa58b4da941efeb209b3770868e2eddd7'/>
<id>urn:sha1:0b3a551fa58b4da941efeb209b3770868e2eddd7</id>
<content type='text'>
Commit fb70bf124b05 ("NFSD: Instantiate a struct file when creating a
regular NFSv4 file") added the ability to cache an open fd over a
compound. There are a couple of problems with the way this currently
works:

It's racy, as a newly-created nfsd_file can end up with its PENDING bit
cleared while the nf is hashed, and the nf_file pointer is still zeroed
out. Other tasks can find it in this state and they expect to see a
valid nf_file, and can oops if nf_file is NULL.

Also, there is no guarantee that we'll end up creating a new nfsd_file
if one is already in the hash. If an extant entry is in the hash with a
valid nf_file, nfs4_get_vfs_file will clobber its nf_file pointer with
the value of op_file and the old nf_file will leak.

Fix both issues by making a new nfsd_file_acquirei_opened variant that
takes an optional file pointer. If one is present when this is called,
we'll take a new reference to it instead of trying to open the file. If
the nfsd_file already has a valid nf_file, we'll just ignore the
optional file and pass the nfsd_file back as-is.

Also rework the tracepoints a bit to allow for an "opened" variant and
don't try to avoid counting acquisitions in the case where we already
have a cached open file.

Fixes: fb70bf124b05 ("NFSD: Instantiate a struct file when creating a regular NFSv4 file")
Cc: Trond Myklebust &lt;trondmy@hammerspace.com&gt;
Reported-by: Stanislav Saner &lt;ssaner@redhat.com&gt;
Reported-and-Tested-by: Ruben Vestergaard &lt;rubenv@drcmr.dk&gt;
Reported-and-Tested-by: Torkil Svensgaard &lt;torkil@drcmr.dk&gt;
Signed-off-by: Jeff Layton &lt;jlayton@kernel.org&gt;
Signed-off-by: Chuck Lever &lt;chuck.lever@oracle.com&gt;
</content>
</entry>
<entry>
<title>nfsd: rework refcounting in filecache</title>
<updated>2022-12-11T16:03:09Z</updated>
<author>
<name>Jeff Layton</name>
</author>
<published>2022-12-11T11:19:33Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=ac3a2585f018f10039b4a856dcb122da88c1c1c9'/>
<id>urn:sha1:ac3a2585f018f10039b4a856dcb122da88c1c1c9</id>
<content type='text'>
The filecache refcounting is a bit non-standard for something searchable
by RCU, in that we maintain a sentinel reference while it's hashed. This
in turn requires that we have to do things differently in the "put"
depending on whether its hashed, which we believe to have led to races.

There are other problems in here too. nfsd_file_close_inode_sync can end
up freeing an nfsd_file while there are still outstanding references to
it, and there are a number of subtle ToC/ToU races.

Rework the code so that the refcount is what drives the lifecycle. When
the refcount goes to zero, then unhash and rcu free the object. A task
searching for a nfsd_file is allowed to bump its refcount, but only if
it's not already 0. Ensure that we don't make any other changes to it
until a reference is held.

With this change, the LRU carries a reference. Take special care to deal
with it when removing an entry from the list, and ensure that we only
repurpose the nf_lru list_head when the refcount is 0 to ensure
exclusive access to it.

Signed-off-by: Jeff Layton &lt;jlayton@kernel.org&gt;
Signed-off-by: Chuck Lever &lt;chuck.lever@oracle.com&gt;
</content>
</entry>
<entry>
<title>NFSD: Add an nfsd_file_fsync tracepoint</title>
<updated>2022-12-10T16:00:04Z</updated>
<author>
<name>Chuck Lever</name>
</author>
<published>2022-11-03T20:22:48Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=d7064eaf688cfe454c50db9f59298463d80d403c'/>
<id>urn:sha1:d7064eaf688cfe454c50db9f59298463d80d403c</id>
<content type='text'>
Add a tracepoint to capture the number of filecache-triggered fsync
calls and which files needed it. Also, record when an fsync triggers
a write verifier reset.

Examples:

&lt;...&gt;-97    [007]   262.505611: nfsd_file_free:       inode=0xffff888171e08140 ref=0 flags=GC may=WRITE nf_file=0xffff8881373d2400
&lt;...&gt;-97    [007]   262.505612: nfsd_file_fsync:      inode=0xffff888171e08140 ref=0 flags=GC may=WRITE nf_file=0xffff8881373d2400 ret=0
&lt;...&gt;-97    [007]   262.505623: nfsd_file_free:       inode=0xffff888171e08dc0 ref=0 flags=GC may=WRITE nf_file=0xffff8881373d1e00
&lt;...&gt;-97    [007]   262.505624: nfsd_file_fsync:      inode=0xffff888171e08dc0 ref=0 flags=GC may=WRITE nf_file=0xffff8881373d1e00 ret=0

Signed-off-by: Chuck Lever &lt;chuck.lever@oracle.com&gt;
Reviewed-by: Jeff Layton &lt;jlayton@kernel.org&gt;
</content>
</entry>
<entry>
<title>nfsd: fix up the filecache laundrette scheduling</title>
<updated>2022-12-10T15:59:20Z</updated>
<author>
<name>Jeff Layton</name>
</author>
<published>2022-11-02T18:44:50Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=22ae4c114f77b55a4c5036e8f70409a0799a08f8'/>
<id>urn:sha1:22ae4c114f77b55a4c5036e8f70409a0799a08f8</id>
<content type='text'>
We don't really care whether there are hashed entries when it comes to
scheduling the laundrette. They might all be non-gc entries, after all.
We only want to schedule it if there are entries on the LRU.

Switch to using list_lru_count, and move the check into
nfsd_file_gc_worker. The other callsite in nfsd_file_put doesn't need to
count entries, since it only schedules the laundrette after adding an
entry to the LRU.

Signed-off-by: Jeff Layton &lt;jlayton@kernel.org&gt;
Signed-off-by: Chuck Lever &lt;chuck.lever@oracle.com&gt;
</content>
</entry>
<entry>
<title>nfsd: reorganize filecache.c</title>
<updated>2022-11-28T17:54:48Z</updated>
<author>
<name>Jeff Layton</name>
</author>
<published>2022-11-02T18:44:48Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=8214118589881b2d390284410c5ff275e7a5e03c'/>
<id>urn:sha1:8214118589881b2d390284410c5ff275e7a5e03c</id>
<content type='text'>
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 &lt;jlayton@kernel.org&gt;
Reviewed-by: NeilBrown &lt;neilb@suse.de&gt;
Signed-off-by: Chuck Lever &lt;chuck.lever@oracle.com&gt;
</content>
</entry>
<entry>
<title>nfsd: remove the pages_flushed statistic from filecache</title>
<updated>2022-11-28T17:54:47Z</updated>
<author>
<name>Jeff Layton</name>
</author>
<published>2022-11-02T18:44:47Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=1f696e230ea5198e393368b319eb55651828d687'/>
<id>urn:sha1:1f696e230ea5198e393368b319eb55651828d687</id>
<content type='text'>
We're counting mapping-&gt;nrpages, but not all of those are necessarily
dirty. We don't really have a simple way to count just the dirty pages,
so just remove this stat since it's not accurate.

Signed-off-by: Jeff Layton &lt;jlayton@kernel.org&gt;
Signed-off-by: Chuck Lever &lt;chuck.lever@oracle.com&gt;
</content>
</entry>
<entry>
<title>NFSD: Fix licensing header in filecache.c</title>
<updated>2022-11-28T17:54:47Z</updated>
<author>
<name>Chuck Lever</name>
</author>
<published>2022-10-31T13:53:26Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=3f054211b29c0fa06dfdcab402c795fd7e906be1'/>
<id>urn:sha1:3f054211b29c0fa06dfdcab402c795fd7e906be1</id>
<content type='text'>
Add a missing SPDX header.

Signed-off-by: Chuck Lever &lt;chuck.lever@oracle.com&gt;
Reviewed-by: Jeff Layton &lt;jlayton@kernel.org&gt;
</content>
</entry>
</feed>
