linux-2.6-microblaze.git
11 months agoNFSD: Clean up nfsd4_encode_access()
Chuck Lever [Mon, 9 Oct 2023 18:29:43 +0000 (14:29 -0400)]
NFSD: Clean up nfsd4_encode_access()

Convert nfsd4_encode_access() to use modern XDR utility functions.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Clean up nfsd4_encode_readdir()
Chuck Lever [Wed, 4 Oct 2023 13:42:10 +0000 (09:42 -0400)]
NFSD: Clean up nfsd4_encode_readdir()

Untangle nfsd4_encode_readdir() so it is more clear what XDR data
item is being encoded by which piece of code.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Clean up nfsd4_encode_entry4()
Chuck Lever [Wed, 4 Oct 2023 13:42:03 +0000 (09:42 -0400)]
NFSD: Clean up nfsd4_encode_entry4()

Reshape nfsd4_encode_entry4() to be more like the legacy dirent
encoders, which were recently rewritten to use xdr_stream.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add an nfsd4_encode_nfs_cookie4() helper
Chuck Lever [Wed, 4 Oct 2023 13:41:57 +0000 (09:41 -0400)]
NFSD: Add an nfsd4_encode_nfs_cookie4() helper

De-duplicate the entry4 cookie encoder, similar to the arrangement
for the NFSv2 and NFSv3 directory entry encoders.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Clean up nfsd4_encode_rdattr_error()
Chuck Lever [Wed, 4 Oct 2023 13:41:51 +0000 (09:41 -0400)]
NFSD: Clean up nfsd4_encode_rdattr_error()

No need for specialized code here, as this function is invoked only
rarely. Convert it to encode to xdr_stream using conventional XDR
helpers.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Rename nfsd4_encode_dirent()
Chuck Lever [Wed, 4 Oct 2023 13:41:44 +0000 (09:41 -0400)]
NFSD: Rename nfsd4_encode_dirent()

Rename nfsd4_encode_dirent() to match the naming convention already
used in the NFSv2 and NFSv3 readdir paths. The new name reflects the
name of the spec-defined XDR data type for an NFSv4 directory entry.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Clean up nfsd4_encode_sequence()
Chuck Lever [Mon, 2 Oct 2023 14:51:37 +0000 (10:51 -0400)]
NFSD: Clean up nfsd4_encode_sequence()

De-duplicate open-coded encoding of the sessionid, and convert the
rest of the function to use conventional XDR utility functions.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Restructure nfsd4_encode_create_session()
Chuck Lever [Mon, 2 Oct 2023 14:51:30 +0000 (10:51 -0400)]
NFSD: Restructure nfsd4_encode_create_session()

Convert nfsd4_encode_create_session() to use the conventional XDR
encoding utilities.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_channel_attr4()
Chuck Lever [Mon, 2 Oct 2023 14:51:24 +0000 (10:51 -0400)]
NFSD: Add nfsd4_encode_channel_attr4()

De-duplicate the encoding of the fore channel and backchannel
attributes.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add a utility function for encoding sessionid4 objects
Chuck Lever [Mon, 2 Oct 2023 14:51:17 +0000 (10:51 -0400)]
NFSD: Add a utility function for encoding sessionid4 objects

There is more than one NFSv4 operation that needs to encode a
sessionid4, so extract that data type into a separate helper.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Clean up nfsd4_encode_open()
Chuck Lever [Fri, 29 Sep 2023 13:59:31 +0000 (09:59 -0400)]
NFSD: Clean up nfsd4_encode_open()

Finish cleaning up nfsd4_encode_open().

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_open_delegation4()
Chuck Lever [Fri, 29 Sep 2023 13:59:24 +0000 (09:59 -0400)]
NFSD: Add nfsd4_encode_open_delegation4()

To better align our implementation with the XDR specification,
refactor the part of nfsd4_encode_open() that encodes delegation
metadata.

As part of that refactor, remove an unnecessary BUG() call site and
a comment that appears to be stale.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_open_none_delegation4()
Chuck Lever [Fri, 29 Sep 2023 13:59:18 +0000 (09:59 -0400)]
NFSD: Add nfsd4_encode_open_none_delegation4()

To better align our implementation with the XDR specification,
refactor the part of nfsd4_encode_open() that encodes the
open_none_delegation4 type.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_open_write_delegation4()
Chuck Lever [Fri, 29 Sep 2023 13:59:12 +0000 (09:59 -0400)]
NFSD: Add nfsd4_encode_open_write_delegation4()

Make it easier to adjust the XDR encoder to handle new features
related to write delegations.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_open_read_delegation4()
Chuck Lever [Fri, 29 Sep 2023 13:59:05 +0000 (09:59 -0400)]
NFSD: Add nfsd4_encode_open_read_delegation4()

Refactor nfsd4_encode_open() so the open_read_delegation4 type is
encoded in a separate function. This makes it more straightforward
to later add support for returning an nfsace4 in OPEN responses that
offer a delegation.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Refactor nfsd4_encode_lock_denied()
Chuck Lever [Fri, 29 Sep 2023 13:58:59 +0000 (09:58 -0400)]
NFSD: Refactor nfsd4_encode_lock_denied()

Use the modern XDR utility functions.

The LOCK and LOCKT encoder functions need to return nfserr_denied
when a lock is denied, but nfsd4_encode_lock4denied() should return
a status code that is consistent with other XDR encoders.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_lock_owner4()
Chuck Lever [Fri, 29 Sep 2023 13:58:53 +0000 (09:58 -0400)]
NFSD: Add nfsd4_encode_lock_owner4()

To improve readability and better align the LOCK encoders with the
XDR specification, add an explicit encoder named for the lock_owner4
type.

In particular, to avoid code duplication, use
nfsd4_encode_clientid4() to encode the clientid in the lock owner
rather than open-coding it.

It looks to me like nfs4_set_lock_denied() already clears the
clientid if it won't return an owner (cf: the nevermind: label). The
code in the XDR encoder appears to be redundant and can safely be
removed.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Remove a layering violation when encoding lock_denied
Chuck Lever [Thu, 12 Oct 2023 17:46:39 +0000 (13:46 -0400)]
NFSD: Remove a layering violation when encoding lock_denied

An XDR encoder is responsible for marshaling results, not releasing
memory that was allocated by the upper layer. We have .op_release
for that purpose.

Move the release of the ld_owner.data string to op_release functions
for LOCK and LOCKT.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Clean up nfsd4_encode_getdeviceinfo()
Chuck Lever [Mon, 25 Sep 2023 13:28:23 +0000 (09:28 -0400)]
NFSD: Clean up nfsd4_encode_getdeviceinfo()

Adopt the conventional XDR utility functions. Also, restructure to
make the function align more closely with the spec -- there doesn't
seem to be a performance need for speciality code, so prioritize
readability.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Make @gdev parameter of ->encode_getdeviceinfo a const pointer
Chuck Lever [Mon, 25 Sep 2023 13:28:17 +0000 (09:28 -0400)]
NFSD: Make @gdev parameter of ->encode_getdeviceinfo a const pointer

This enables callers to be passed const pointer parameters.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Clean up nfsd4_encode_layoutreturn()
Chuck Lever [Mon, 25 Sep 2023 13:28:10 +0000 (09:28 -0400)]
NFSD: Clean up nfsd4_encode_layoutreturn()

Adopt the use of conventional XDR utility functions. Restructure
the encoder to better align with the XDR definition of the result.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Clean up nfsd4_encode_layoutcommit()
Chuck Lever [Mon, 25 Sep 2023 13:28:04 +0000 (09:28 -0400)]
NFSD: Clean up nfsd4_encode_layoutcommit()

Adopt the use of conventional XDR utility functions. Restructure
the encoder to better align with the XDR definition of the result.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Clean up nfsd4_encode_layoutget()
Chuck Lever [Mon, 25 Sep 2023 13:27:58 +0000 (09:27 -0400)]
NFSD: Clean up nfsd4_encode_layoutget()

De-duplicate the open-coded stateid4 encoder. Adopt the use of the
conventional current XDR encoding helpers. Refactor the encoder to
align with the XDR specification.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Make @lgp parameter of ->encode_layoutget a const pointer
Chuck Lever [Mon, 25 Sep 2023 13:27:51 +0000 (09:27 -0400)]
NFSD: Make @lgp parameter of ->encode_layoutget a const pointer

This enables callers to be passed const pointer parameters.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Clean up nfsd4_encode_stateid()
Chuck Lever [Mon, 25 Sep 2023 13:27:45 +0000 (09:27 -0400)]
NFSD: Clean up nfsd4_encode_stateid()

Update the encoder function name to match the type name, as is the
convention with other such encoder utility functions, and with
nfsd4_decode_stateid4().

Make the @stateid argument a const so that callers of
nfsd4_encode_stateid4() in the future can be passed const pointers
to structures.

Since the compiler is allowed to add padding to structs, use the
wire (spec-defined) size when reserving buffer space.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_count4()
Chuck Lever [Mon, 25 Sep 2023 13:27:38 +0000 (09:27 -0400)]
NFSD: Add nfsd4_encode_count4()

This is a synonym for nfsd4_encode_uint32_t() that matches the
name of the XDR type. It will get at least one more use in a
subsequent patch.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Rename nfsd4_encode_fattr()
Chuck Lever [Mon, 18 Sep 2023 14:02:18 +0000 (10:02 -0400)]
NFSD: Rename nfsd4_encode_fattr()

For better alignment with the specification, NFSD's encoder function
name should match the name of the XDR data type.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Use a bitmask loop to encode FATTR4 results
Chuck Lever [Mon, 18 Sep 2023 14:02:12 +0000 (10:02 -0400)]
NFSD: Use a bitmask loop to encode FATTR4 results

The fattr4 encoder is now structured like the COMPOUND op encoder:
one function for each individual attribute, called by bit number.
Benefits include:

- The individual attributes are now guaranteed to be encoded in
  bitmask order into the send buffer

- There can be no unwanted side effects between attribute encoders

- The code now clearly documents which attributes are /not/
  implemented on this server

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Copy FATTR4 bit number definitions from RFCs
Chuck Lever [Mon, 18 Sep 2023 14:02:06 +0000 (10:02 -0400)]
NFSD: Copy FATTR4 bit number definitions from RFCs

I'd like to convert nfsd4_encode_fattr() to rotate through the
attrmask using for_each_bit() instead of explicitly testing the
bitmask for each bit value. This means I need the bit numbers, as
defined in the specs, instead of our internal bitmask constants.

As a clean up, use the new spec-derived values to define the WORD#
bitmask constants.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_fattr4_xattr_support()
Chuck Lever [Mon, 18 Sep 2023 14:01:59 +0000 (10:01 -0400)]
NFSD: Add nfsd4_encode_fattr4_xattr_support()

Refactor the encoder for FATTR4_XATTR_SUPPORT into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_fattr4_sec_label()
Chuck Lever [Mon, 18 Sep 2023 14:01:53 +0000 (10:01 -0400)]
NFSD: Add nfsd4_encode_fattr4_sec_label()

Refactor the encoder for FATTR4_SEC_LABEL into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_fattr4_suppattr_exclcreat()
Chuck Lever [Mon, 18 Sep 2023 14:01:47 +0000 (10:01 -0400)]
NFSD: Add nfsd4_encode_fattr4_suppattr_exclcreat()

Refactor the encoder for FATTR4_SUPPATTR_EXCLCREAT into a helper. In
a subsequent patch, this helper will be called from a bitmask loop.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_fattr4_layout_blksize()
Chuck Lever [Mon, 18 Sep 2023 14:01:40 +0000 (10:01 -0400)]
NFSD: Add nfsd4_encode_fattr4_layout_blksize()

Refactor the encoder for FATTR4_LAYOUT_BLKSIZE into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_fattr4_layout_types()
Chuck Lever [Mon, 18 Sep 2023 14:01:34 +0000 (10:01 -0400)]
NFSD: Add nfsd4_encode_fattr4_layout_types()

Refactor the encoder for FATTR4_LAYOUT_TYPES into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_fattr4_fs_layout_types()
Chuck Lever [Mon, 18 Sep 2023 14:01:28 +0000 (10:01 -0400)]
NFSD: Add nfsd4_encode_fattr4_fs_layout_types()

Refactor the encoder for FATTR4_FS_LAYOUT_TYPES into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_fattr4_mounted_on_fileid()
Chuck Lever [Mon, 18 Sep 2023 14:01:21 +0000 (10:01 -0400)]
NFSD: Add nfsd4_encode_fattr4_mounted_on_fileid()

Refactor the encoder for FATTR4_MOUNTED_ON_FILEID into a helper. In
a subsequent patch, this helper will be called from a bitmask loop.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_fattr4_time_modify()
Chuck Lever [Mon, 18 Sep 2023 14:01:15 +0000 (10:01 -0400)]
NFSD: Add nfsd4_encode_fattr4_time_modify()

Refactor the encoder for FATTR4_TIME_MODIFY into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_fattr4_time_metadata()
Chuck Lever [Mon, 18 Sep 2023 14:01:09 +0000 (10:01 -0400)]
NFSD: Add nfsd4_encode_fattr4_time_metadata()

Refactor the encoder for FATTR4_TIME_METADATA into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_fattr4_time_delta()
Chuck Lever [Mon, 18 Sep 2023 14:01:02 +0000 (10:01 -0400)]
NFSD: Add nfsd4_encode_fattr4_time_delta()

Refactor the encoder for FATTR4_TIME_DELTA into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

fattr4_time_delta is specified as an nfstime4, so de-duplicate this
encoder.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_fattr4_time_create()
Chuck Lever [Mon, 18 Sep 2023 14:00:56 +0000 (10:00 -0400)]
NFSD: Add nfsd4_encode_fattr4_time_create()

Refactor the encoder for FATTR4_TIME_CREATE into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_fattr4_time_access()
Chuck Lever [Mon, 18 Sep 2023 14:00:50 +0000 (10:00 -0400)]
NFSD: Add nfsd4_encode_fattr4_time_access()

Refactor the encoder for FATTR4_TIME_ACCESS into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_fattr4_space_used()
Chuck Lever [Mon, 18 Sep 2023 14:00:43 +0000 (10:00 -0400)]
NFSD: Add nfsd4_encode_fattr4_space_used()

Refactor the encoder for FATTR4_SPACE_USED into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_fattr4_space_total()
Chuck Lever [Mon, 18 Sep 2023 14:00:37 +0000 (10:00 -0400)]
NFSD: Add nfsd4_encode_fattr4_space_total()

Refactor the encoder for FATTR4_SPACE_TOTAL into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_fattr4_space_free()
Chuck Lever [Mon, 18 Sep 2023 14:00:30 +0000 (10:00 -0400)]
NFSD: Add nfsd4_encode_fattr4_space_free()

Refactor the encoder for FATTR4_SPACE_FREE into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_fattr4_space_avail()
Chuck Lever [Mon, 18 Sep 2023 14:00:24 +0000 (10:00 -0400)]
NFSD: Add nfsd4_encode_fattr4_space_avail()

Refactor the encoder for FATTR4_SPACE_AVAIL into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_fattr4_rawdev()
Chuck Lever [Mon, 18 Sep 2023 14:00:18 +0000 (10:00 -0400)]
NFSD: Add nfsd4_encode_fattr4_rawdev()

Refactor the encoder for FATTR4_RAWDEV into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_fattr4_owner_group()
Chuck Lever [Mon, 18 Sep 2023 14:00:11 +0000 (10:00 -0400)]
NFSD: Add nfsd4_encode_fattr4_owner_group()

Refactor the encoder for FATTR4_OWNER_GROUP into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_fattr4_owner()
Chuck Lever [Mon, 18 Sep 2023 14:00:05 +0000 (10:00 -0400)]
NFSD: Add nfsd4_encode_fattr4_owner()

Refactor the encoder for FATTR4_OWNER into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_fattr4_numlinks()
Chuck Lever [Mon, 18 Sep 2023 13:59:59 +0000 (09:59 -0400)]
NFSD: Add nfsd4_encode_fattr4_numlinks()

Refactor the encoder for FATTR4_NUMLINKS into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_fattr4_mode()
Chuck Lever [Mon, 18 Sep 2023 13:59:52 +0000 (09:59 -0400)]
NFSD: Add nfsd4_encode_fattr4_mode()

Refactor the encoder for FATTR4_MODE into a helper. In a subsequent
patch, this helper will be called from a bitmask loop.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_fattr4_maxwrite()
Chuck Lever [Mon, 18 Sep 2023 13:59:46 +0000 (09:59 -0400)]
NFSD: Add nfsd4_encode_fattr4_maxwrite()

Refactor the encoder for FATTR4_MAXWRITE into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_fattr4_maxread()
Chuck Lever [Mon, 18 Sep 2023 13:59:39 +0000 (09:59 -0400)]
NFSD: Add nfsd4_encode_fattr4_maxread()

Refactor the encoder for FATTR4_MAXREAD into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_fattr4_maxname()
Chuck Lever [Mon, 18 Sep 2023 13:59:33 +0000 (09:59 -0400)]
NFSD: Add nfsd4_encode_fattr4_maxname()

Refactor the encoder for FATTR4_MAXNAME into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_fattr4_maxlink()
Chuck Lever [Mon, 18 Sep 2023 13:59:27 +0000 (09:59 -0400)]
NFSD: Add nfsd4_encode_fattr4_maxlink()

Refactor the encoder for FATTR4_MAXLINK into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_fattr4_maxfilesize()
Chuck Lever [Mon, 18 Sep 2023 13:59:20 +0000 (09:59 -0400)]
NFSD: Add nfsd4_encode_fattr4_maxfilesize()

Refactor the encoder for FATTR4_MAXFILESIZE into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_fattr4_fs_locations()
Chuck Lever [Mon, 18 Sep 2023 13:59:14 +0000 (09:59 -0400)]
NFSD: Add nfsd4_encode_fattr4_fs_locations()

Refactor the encoder for FATTR4_FS_LOCATIONS into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_fattr4_files_total()
Chuck Lever [Mon, 18 Sep 2023 13:59:08 +0000 (09:59 -0400)]
NFSD: Add nfsd4_encode_fattr4_files_total()

Refactor the encoder for FATTR4_FILES_TOTAL into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_fattr4_files_free()
Chuck Lever [Mon, 18 Sep 2023 13:59:01 +0000 (09:59 -0400)]
NFSD: Add nfsd4_encode_fattr4_files_free()

Refactor the encoder for FATTR4_FILES_FREE into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_fattr4_files_avail()
Chuck Lever [Mon, 18 Sep 2023 13:58:55 +0000 (09:58 -0400)]
NFSD: Add nfsd4_encode_fattr4_files_avail()

Refactor the encoder for FATTR4_FILES_AVAIL into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_fattr4_fileid()
Chuck Lever [Mon, 18 Sep 2023 13:58:49 +0000 (09:58 -0400)]
NFSD: Add nfsd4_encode_fattr4_fileid()

Refactor the encoder for FATTR4_FILEID into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_fattr4_filehandle()
Chuck Lever [Mon, 18 Sep 2023 13:58:42 +0000 (09:58 -0400)]
NFSD: Add nfsd4_encode_fattr4_filehandle()

Refactor the encoder for FATTR4_FILEHANDLE into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

We can de-duplicate the other filehandle encoder (in GETFH) using
our new helper.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_fattr4_acl()
Chuck Lever [Mon, 18 Sep 2023 13:58:36 +0000 (09:58 -0400)]
NFSD: Add nfsd4_encode_fattr4_acl()

Refactor the encoder for FATTR4_ACL into a helper. In a subsequent
patch, this helper will be called from a bitmask loop.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_nfsace4()
Chuck Lever [Mon, 18 Sep 2023 13:58:30 +0000 (09:58 -0400)]
NFSD: Add nfsd4_encode_nfsace4()

Refactor the ACE encoding helper so that it can eventually be reused
for encoding OPEN results that contain delegation ACEs.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_fattr4_aclsupport()
Chuck Lever [Mon, 18 Sep 2023 13:58:23 +0000 (09:58 -0400)]
NFSD: Add nfsd4_encode_fattr4_aclsupport()

Refactor the encoder for FATTR4_ACLSUPPORT into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_fattr4_rdattr_error()
Chuck Lever [Mon, 18 Sep 2023 13:58:17 +0000 (09:58 -0400)]
NFSD: Add nfsd4_encode_fattr4_rdattr_error()

Refactor the encoder for FATTR4_RDATTR_ERROR into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_fattr4_lease_time()
Chuck Lever [Mon, 18 Sep 2023 13:58:10 +0000 (09:58 -0400)]
NFSD: Add nfsd4_encode_fattr4_lease_time()

Refactor the encoder for FATTR4_LEASE_TIME into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_fattr4_fsid()
Chuck Lever [Mon, 18 Sep 2023 13:58:04 +0000 (09:58 -0400)]
NFSD: Add nfsd4_encode_fattr4_fsid()

Refactor the encoder for FATTR4_FSID into a helper. In a subsequent
patch, this helper will be called from a bitmask loop.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_fattr4_size()
Chuck Lever [Mon, 18 Sep 2023 13:57:58 +0000 (09:57 -0400)]
NFSD: Add nfsd4_encode_fattr4_size()

Refactor the encoder for FATTR4_SIZE into a helper. In a subsequent
patch, this helper will be called from a bitmask loop.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_fattr4_change()
Chuck Lever [Mon, 18 Sep 2023 13:57:51 +0000 (09:57 -0400)]
NFSD: Add nfsd4_encode_fattr4_change()

Refactor the encoder for FATTR4_CHANGE into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

The code is restructured a bit to use the modern xdr_stream flow,
and the encoded cinfo value is made const so that callers of the
encoders can be passed a const cinfo.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_fattr4_fh_expire_type()
Chuck Lever [Mon, 18 Sep 2023 13:57:45 +0000 (09:57 -0400)]
NFSD: Add nfsd4_encode_fattr4_fh_expire_type()

Refactor the encoder for FATTR4_FH_EXPIRE_TYPE into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_fattr4_type()
Chuck Lever [Mon, 18 Sep 2023 13:57:39 +0000 (09:57 -0400)]
NFSD: Add nfsd4_encode_fattr4_type()

Refactor the encoder for FATTR4_TYPE into a helper. In a subsequent
patch, this helper will be called from a bitmask loop.

In addition, restructure the code so that byte-swapping is done on
constant values rather than at run time. Run-time swapping can be
costly on some platforms, and "type" is a frequently-requested
attribute.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_fattr4_supported_attrs()
Chuck Lever [Mon, 18 Sep 2023 13:57:32 +0000 (09:57 -0400)]
NFSD: Add nfsd4_encode_fattr4_supported_attrs()

Refactor the encoder for FATTR4_SUPPORTED_ATTRS into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_fattr4__false()
Chuck Lever [Mon, 18 Sep 2023 13:57:26 +0000 (09:57 -0400)]
NFSD: Add nfsd4_encode_fattr4__false()

Add an encoding helper that encodes a single boolean "false" value.
Attributes that always return "false" can use this helper.

In a subsequent patch, this helper will be called from a bitmask
loop, so it is given a standardized synopsis.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add nfsd4_encode_fattr4__true()
Chuck Lever [Mon, 18 Sep 2023 13:57:19 +0000 (09:57 -0400)]
NFSD: Add nfsd4_encode_fattr4__true()

Add an encoding helper that encodes a single boolean "true" value.
Attributes that always return "true" can use this helper.

In a subsequent patch, this helper will be called from a bitmask
loop, so it is given a standardized synopsis.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add struct nfsd4_fattr_args
Chuck Lever [Mon, 18 Sep 2023 13:57:13 +0000 (09:57 -0400)]
NFSD: Add struct nfsd4_fattr_args

I'm about to split nfsd4_encode_fattr() into a number of smaller
functions. Instead of passing a large number of arguments to each of
the smaller functions, create a struct that can gather the common
argument variables into something with a convenient handle on it.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Clean up nfsd4_encode_setattr()
Chuck Lever [Mon, 18 Sep 2023 13:57:07 +0000 (09:57 -0400)]
NFSD: Clean up nfsd4_encode_setattr()

De-duplicate the encoding of bitmap4 results in
nfsd4_encode_setattr().

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Rename nfsd4_encode_bitmap()
Chuck Lever [Mon, 18 Sep 2023 13:57:00 +0000 (09:57 -0400)]
NFSD: Rename nfsd4_encode_bitmap()

For alignment with the specification, the name of NFSD's encoder
function should match the name of the XDR type.

I've also replaced a few "naked integers" with symbolic constants
that better reflect the usage of these values.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: Add simple u32, u64, and bool encoders
Chuck Lever [Mon, 18 Sep 2023 13:56:54 +0000 (09:56 -0400)]
NFSD: Add simple u32, u64, and bool encoders

The generic XDR encoders return a length or a negative errno. NFSv4
encoders want to know simply whether the encode ran out of stream
buffer space. The return values for server-side encoding are either
nfs_ok or nfserr_resource.

So far I've found it adds a lot of duplicate code to try to use the
generic XDR encoder utilities when encoding the simple data types in
the NFSv4 operation encoders.

Add a set of NFSv4-specific utilities that handle the basic XDR data
types. These are added in xdr4.h so they might eventually be used by
the callback server and pNFS driver encoders too.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoSUNRPC: Remove BUG_ON call sites
Chuck Lever [Tue, 19 Sep 2023 15:35:15 +0000 (11:35 -0400)]
SUNRPC: Remove BUG_ON call sites

There is no need to take down the whole system for these assertions.

I'd rather not attempt a heroic save here, as some bug has occurred
that has left the transport data structures in an unknown state.
Just warn and then leak the left-over resources.

Acked-by: Christian Brauner <brauner@kernel.org>
Reviewed-by: NeilBrown <neilb@suse.de>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agonfs: fix the typo of rfc number about xattr in NFSv4
Kinglong Mee [Mon, 18 Sep 2023 06:59:06 +0000 (14:59 +0800)]
nfs: fix the typo of rfc number about xattr in NFSv4

Signed-off-by: Kinglong Mee <kinglongmee@gmail.com>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agotools: ynl: Add source files for nfsd netlink protocol
Chuck Lever [Thu, 5 Oct 2023 12:41:20 +0000 (08:41 -0400)]
tools: ynl: Add source files for nfsd netlink protocol

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: add rpc_status netlink support
Lorenzo Bianconi [Mon, 11 Sep 2023 12:49:46 +0000 (14:49 +0200)]
NFSD: add rpc_status netlink support

Introduce rpc_status netlink support for NFSD in order to dump pending
RPC requests debugging information from userspace.

Closes: https://bugzilla.linux-nfs.org/show_bug.cgi?id=366
Tested-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: introduce netlink stubs
Lorenzo Bianconi [Mon, 11 Sep 2023 12:49:44 +0000 (14:49 +0200)]
NFSD: introduce netlink stubs

Generate stubs and uAPI for nfsd netlink protocol. For the moment,
the new protocol has one operation: rpc_status.

The generated header and source files are created by running:

  tools/net/ynl/ynl-regen.sh

Tested-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Acked-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: handle GETATTR conflict with write delegation
Dai Ngo [Wed, 13 Sep 2023 23:38:21 +0000 (16:38 -0700)]
NFSD: handle GETATTR conflict with write delegation

If the GETATTR request on a file that has write delegation in effect
and the request attributes include the change info and size attribute
then the request is handled as below:

Server sends CB_GETATTR to client to get the latest change info and file
size. If these values are the same as the server's cached values then
the GETATTR proceeds as normal.

If either the change info or file size is different from the server's
cached values, or the file was already marked as modified, then:

    . update time_modify and time_metadata into file's metadata
      with current time

    . encode GETATTR as normal except the file size is encoded with
      the value returned from CB_GETATTR

    . mark the file as modified

If the CB_GETATTR fails for any reasons, the delegation is recalled
and NFS4ERR_DELAY is returned for the GETATTR.

Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoNFSD: add support for CB_GETATTR callback
Dai Ngo [Wed, 13 Sep 2023 23:38:20 +0000 (16:38 -0700)]
NFSD: add support for CB_GETATTR callback

Includes:
   . CB_GETATTR proc for nfs4_cb_procedures[]
   . XDR encoding and decoding function for CB_GETATTR request/reply
   . add nfs4_cb_fattr to nfs4_delegation for sending CB_GETATTR
     and store file attributes from client's reply.

Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoSUNRPC: change the back-channel queue to lwq
NeilBrown [Mon, 11 Sep 2023 14:40:22 +0000 (10:40 -0400)]
SUNRPC: change the back-channel queue to lwq

This removes the need to store and update back-links in the list.
It also remove the need for the _bh version of spin_lock().

Signed-off-by: NeilBrown <neilb@suse.de>
Cc: Trond Myklebust <trond.myklebust@hammerspace.com>
Cc: Anna Schumaker <Anna.Schumaker@Netapp.com>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoSUNRPC: discard sp_lock
NeilBrown [Mon, 11 Sep 2023 14:40:15 +0000 (10:40 -0400)]
SUNRPC: discard sp_lock

sp_lock is now only used to protect sp_all_threads.  This isn't needed
as sp_all_threads is only manipulated through svc_set_num_threads(),
which is already serialized.  Read-acccess only requires rcu_read_lock().
So no more locking is needed.

Signed-off-by: NeilBrown <neilb@suse.de>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoSUNRPC: change sp_nrthreads to atomic_t
NeilBrown [Mon, 11 Sep 2023 14:40:09 +0000 (10:40 -0400)]
SUNRPC: change sp_nrthreads to atomic_t

Using an atomic_t avoids the need to take a spinlock (which can soon be
removed).

Choosing a thread to kill needs to be careful as we cannot set the "die
now" bit atomically with the test on the count.  Instead we temporarily
increase the count.

Signed-off-by: NeilBrown <neilb@suse.de>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoSUNRPC: use lwq for sp_sockets - renamed to sp_xprts
NeilBrown [Mon, 11 Sep 2023 14:40:02 +0000 (10:40 -0400)]
SUNRPC: use lwq for sp_sockets - renamed to sp_xprts

lwq avoids using back pointers in lists, and uses less locking.
This introduces a new spinlock, but the other one will be removed in a
future patch.

For svc_clean_up_xprts(), we now dequeue the entire queue, walk it to
remove and process the xprts that need cleaning up, then re-enqueue the
remaining queue.

Signed-off-by: NeilBrown <neilb@suse.de>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoSUNRPC: only have one thread waking up at a time
NeilBrown [Mon, 11 Sep 2023 14:39:56 +0000 (10:39 -0400)]
SUNRPC: only have one thread waking up at a time

Currently if several items of work become available in quick succession,
that number of threads (if available) will be woken.  By the time some
of them wake up another thread that was already cache-warm might have
come along and completed the work.  Anecdotal evidence suggests as many
as 15% of wakes find nothing to do once they get to the point of
looking.

This patch changes svc_pool_wake_idle_thread() to wake the first thread
on the queue but NOT remove it.  Subsequent calls will wake the same
thread.  Once that thread starts it will dequeue itself and after
dequeueing some work to do, it will wake the next thread if there is more
work ready.  This results in a more orderly increase in the number of
busy threads.

As a bonus, this allows us to reduce locking around the idle queue.
svc_pool_wake_idle_thread() no longer needs to take a lock (beyond
rcu_read_lock()) as it doesn't manipulate the queue, it just looks at
the first item.

The thread itself can avoid locking by using the new
llist_del_first_this() interface.  This will safely remove the thread
itself if it is the head.  If it isn't the head, it will do nothing.
If multiple threads call this concurrently only one will succeed.  The
others will do nothing, so no corruption can result.

If a thread wakes up and finds that it cannot dequeue itself that means
either
- that it wasn't woken because it was the head of the queue.  Maybe the
  freezer woke it.  In that case it can go back to sleep (after trying
  to freeze of course).
- some other thread found there was nothing to do very recently, and
  placed itself on the head of the queue in front of this thread.
  It must check again after placing itself there, so it can be deemed to
  be responsible for any pending work, and this thread can go back to
  sleep until woken.

No code ever tests for busy threads any more.  Only each thread itself
cares if it is busy.  So svc_thread_busy() is no longer needed.

Signed-off-by: NeilBrown <neilb@suse.de>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoSUNRPC: rename some functions from rqst_ to svc_thread_
NeilBrown [Mon, 11 Sep 2023 14:39:50 +0000 (10:39 -0400)]
SUNRPC: rename some functions from rqst_ to svc_thread_

Functions which directly manipulate a 'struct rqst', such as
svc_rqst_alloc() or svc_rqst_release_pages(), can reasonably
have "rqst" in there name.
However functions that act on the running thread, such as
XX_should_sleep() or XX_wait_for_work() should seem more
natural with a "svc_thread_" prefix.

So make those changes.

Signed-off-by: NeilBrown <neilb@suse.de>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agolib: add light-weight queuing mechanism.
NeilBrown [Mon, 11 Sep 2023 14:39:43 +0000 (10:39 -0400)]
lib: add light-weight queuing mechanism.

lwq is a FIFO single-linked queue that only requires a spinlock
for dequeueing, which happens in process context.  Enqueueing is atomic
with no spinlock and can happen in any context.

This is particularly useful when work items are queued from BH or IRQ
context, and when they are handled one at a time by dedicated threads.

Avoiding any locking when enqueueing means there is no need to disable
BH or interrupts, which is generally best avoided (particularly when
there are any RT tasks on the machine).

This solution is superior to using "list_head" links because we need
half as many pointers in the data structures, and because list_head
lists would need locking to add items to the queue.

This solution is superior to a bespoke solution as all locking and
container_of casting is integrated, so the interface is simple.

Despite the similar name, this solution meets a distinctly different
need to kfifo.  kfifo provides a fixed sized circular buffer to which
data can be added at one end and removed at the other, and does not
provide any locking.  lwq does not have any size limit and works with
data structures (objects?) rather than data (bytes).

A unit test for basic functionality, which runs at boot time, is included.

Signed-off-by: NeilBrown <neilb@suse.de>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: "Liam R. Howlett" <Liam.Howlett@oracle.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: David Gow <davidgow@google.com>
Cc: linux-kernel@vger.kernel.org
Message-Id: <20230911111333.4d1a872330e924a00acb905b@linux-foundation.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agollist: add llist_del_first_this()
NeilBrown [Mon, 11 Sep 2023 14:39:37 +0000 (10:39 -0400)]
llist: add llist_del_first_this()

llist_del_first_this() deletes a specific entry from an llist, providing
it is at the head of the list.  Multiple threads can call this
concurrently providing they each offer a different entry.

This can be uses for a set of worker threads which are on the llist when
they are idle.  The head can always be woken, and when it is woken it
can remove itself, and possibly wake the next if there is an excess of
work to do.

Signed-off-by: NeilBrown <neilb@suse.de>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoSUNRPC: change service idle list to be an llist
NeilBrown [Mon, 11 Sep 2023 14:39:30 +0000 (10:39 -0400)]
SUNRPC: change service idle list to be an llist

With an llist we don't need to take a lock to add a thread to the list,
though we still need a lock to remove it.  That will go in the next
patch.

Unlike double-linked lists, a thread cannot reliably remove itself from
the list.  Only the first thread can be removed, and that can change
asynchronously.  So some care is needed.

We already check if there is pending work to do, so we are unlikely to
add ourselves to the idle list and then want to remove ourselves again.

If we DO find something needs to be done after adding ourselves to the
list, we simply wake up the first thread on the list.  If that was us,
we successfully removed ourselves and can continue.  If it was some
other thread, they will do the work that needs to be done.  We can
safely sleep until woken.

We also remove the test on freezing() from rqst_should_sleep().  Instead
we set TASK_FREEZABLE before scheduling.  This makes is safe to
schedule() when a freeze is pending.  As we now loop waiting to be
removed from the idle queue, this is a cleaner way to handle freezing.

Signed-off-by: NeilBrown <neilb@suse.de>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agollist: add interface to check if a node is on a list.
NeilBrown [Mon, 11 Sep 2023 14:39:24 +0000 (10:39 -0400)]
llist: add interface to check if a node is on a list.

With list.h lists, it is easy to test if a node is on a list, providing
it was initialised and that it is removed with list_del_init().

This patch provides similar functionality for llist.h lists.

 init_llist_node()
marks a node as being not-on-any-list be setting the ->next pointer to
the node itself.
 llist_on_list()
tests if the node is on any list.
 llist_del_first_init()
remove the first element from a llist, and marks it as being off-list.

Signed-off-by: NeilBrown <neilb@suse.de>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoSUNRPC: discard SP_CONGESTED
NeilBrown [Mon, 11 Sep 2023 14:39:17 +0000 (10:39 -0400)]
SUNRPC: discard SP_CONGESTED

We can tell if a pool is congested by checking if the idle list is
empty.  We don't need a separate flag.

Signed-off-by: NeilBrown <neilb@suse.de>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoSUNRPC: add list of idle threads
NeilBrown [Mon, 11 Sep 2023 14:39:11 +0000 (10:39 -0400)]
SUNRPC: add list of idle threads

Rather than searching a list of threads to find an idle one, having a
list of idle threads allows an idle thread to be found immediately.

This adds some spin_lock calls which is not ideal, but as the hold-time
is tiny it is still faster than searching a list.  A future patch will
remove them using llist.h.  This involves some subtlety and so is left
to a separate patch.

This removes the need for the RQ_BUSY flag.  The rqst is "busy"
precisely when it is not on the "idle" list.

Signed-off-by: NeilBrown <neilb@suse.de>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoSUNRPC: change how svc threads are asked to exit.
NeilBrown [Mon, 11 Sep 2023 14:39:04 +0000 (10:39 -0400)]
SUNRPC: change how svc threads are asked to exit.

svc threads are currently stopped using kthread_stop().  This requires
identifying a specific thread.  However we don't care which thread
stops, just as long as one does.

So instead, set a flag in the svc_pool to say that a thread needs to
die, and have each thread check this flag instead of calling
kthread_should_stop().  The first thread to find and clear this flag
then moves towards exiting.

This removes an explicit dependency on sp_all_threads which will make a
future patch simpler.

Signed-off-by: NeilBrown <neilb@suse.de>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agolockd: hold a reference to nlmsvc_serv while stopping the thread.
NeilBrown [Tue, 10 Oct 2023 22:31:22 +0000 (09:31 +1100)]
lockd: hold a reference to nlmsvc_serv while stopping the thread.

Both nfsd and nfsv4-callback take a temporary reference to the svc_serv
while calling svc_set_num_threads() to stop the last thread.  lockd does
not.

This extra reference prevents the scv_serv from being freed when the
last thread drops its reference count.  This is not currently needed
for lockd as the svc_serv is not accessed after the last thread is told
to exit.

However a future patch will require svc_exit_thread() to access the
svc_serv after the svc_put() so it will need the code that calls
svc_set_num_threads() to keep a reference and keep the svc_serv active.

So copy the pattern from nfsd and nfsv4-cb to lockd, and take a
reference around svc_set_num_threads(.., 0)

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Tested-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: NeilBrown <neilb@suse.de>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
11 months agoSUNRPC: integrate back-channel processing with svc_recv()
NeilBrown [Mon, 11 Sep 2023 14:38:58 +0000 (10:38 -0400)]
SUNRPC: integrate back-channel processing with svc_recv()

Using svc_recv() for (NFSv4.1) back-channel handling means we have just
one mechanism for waking threads.

Also change kthread_freezable_should_stop() in nfs4_callback_svc() to
kthread_should_stop() as used elsewhere.
kthread_freezable_should_stop() effectively adds a try_to_freeze() call,
and svc_recv() already contains that at an appropriate place.

Signed-off-by: NeilBrown <neilb@suse.de>
Cc: Trond Myklebust <trond.myklebust@hammerspace.com>
Cc: Anna Schumaker <Anna.Schumaker@Netapp.com>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>