]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
NFSD: Refactor nfsd4_do_encode_secinfo() again
authorChuck Lever <chuck.lever@oracle.com>
Tue, 31 Dec 2024 00:28:58 +0000 (19:28 -0500)
committerChuck Lever <chuck.lever@oracle.com>
Sat, 11 Jan 2025 04:41:49 +0000 (23:41 -0500)
Extract the code that encodes the secinfo4 union data type to
clarify the logic. The removed warning is pretty well obscured and
thus probably not terribly useful.

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

index 2116a03830c3766e43d478a191fc96b16746577e..5cc365a3ed0df71de7f082e19822d73d1cc814de 100644 (file)
@@ -4613,13 +4613,41 @@ nfsd4_encode_rpcsec_gss_info(struct xdr_stream *xdr,
        return nfs_ok;
 }
 
+static __be32
+nfsd4_encode_secinfo4(struct xdr_stream *xdr, rpc_authflavor_t pf,
+                     u32 *supported)
+{
+       struct rpcsec_gss_info info;
+       __be32 status;
+
+       if (rpcauth_get_gssinfo(pf, &info) == 0) {
+               (*supported)++;
+
+               /* flavor */
+               status = nfsd4_encode_uint32_t(xdr, RPC_AUTH_GSS);
+               if (status != nfs_ok)
+                       return status;
+               /* flavor_info */
+               status = nfsd4_encode_rpcsec_gss_info(xdr, &info);
+               if (status != nfs_ok)
+                       return status;
+       } else if (pf < RPC_AUTH_MAXFLAVOR) {
+               (*supported)++;
+
+               /* flavor */
+               status = nfsd4_encode_uint32_t(xdr, pf);
+               if (status != nfs_ok)
+                       return status;
+       }
+       return nfs_ok;
+}
+
 static __be32
 nfsd4_do_encode_secinfo(struct xdr_stream *xdr, struct svc_export *exp)
 {
        u32 i, nflavs, supported;
        struct exp_flavor_info *flavs;
        struct exp_flavor_info def_flavs[2];
-       static bool report = true;
        __be32 *flavorsp;
        __be32 status;
 
@@ -4643,42 +4671,17 @@ nfsd4_do_encode_secinfo(struct xdr_stream *xdr, struct svc_export *exp)
                }
        }
 
-       supported = 0;
        flavorsp = xdr_reserve_space(xdr, XDR_UNIT);
        if (!flavorsp)
                return nfserr_resource;
 
-       for (i = 0; i < nflavs; i++) {
-               rpc_authflavor_t pf = flavs[i].pseudoflavor;
-               struct rpcsec_gss_info info;
-
-               if (rpcauth_get_gssinfo(pf, &info) == 0) {
-                       supported++;
-
-                       /* flavor */
-                       status = nfsd4_encode_uint32_t(xdr, RPC_AUTH_GSS);
-                       if (status != nfs_ok)
-                               return status;
-                       /* flavor_info */
-                       status = nfsd4_encode_rpcsec_gss_info(xdr, &info);
-                       if (status != nfs_ok)
-                               return status;
-               } else if (pf < RPC_AUTH_MAXFLAVOR) {
-                       supported++;
-
-                       /* flavor */
-                       status = nfsd4_encode_uint32_t(xdr, pf);
-                       if (status != nfs_ok)
-                               return status;
-               } else {
-                       if (report)
-                               pr_warn("NFS: SECINFO: security flavor %u "
-                                       "is not supported\n", pf);
-               }
+       for (i = 0, supported = 0; i < nflavs; i++) {
+               status = nfsd4_encode_secinfo4(xdr, flavs[i].pseudoflavor,
+                                              &supported);
+               if (status != nfs_ok)
+                       return status;
        }
 
-       if (nflavs != supported)
-               report = false;
        *flavorsp = cpu_to_be32(supported);
        return 0;
 }