NFSD: Add nfsd4_encode_nfsace4()
authorChuck Lever <chuck.lever@oracle.com>
Mon, 18 Sep 2023 13:58:30 +0000 (09:58 -0400)
committerChuck Lever <chuck.lever@oracle.com>
Mon, 16 Oct 2023 16:44:16 +0000 (12:44 -0400)
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>
fs/nfsd/nfs4xdr.c
fs/nfsd/xdr4.h

index f7c5c05752371163ad8e91907bedb7e129323cc3..2ecdd11521259d364f624c6df407be8682f20933 100644 (file)
@@ -2783,16 +2783,29 @@ static __be32 nfsd4_encode_fs_locations(struct xdr_stream *xdr,
        return 0;
 }
 
-static inline __be32
-nfsd4_encode_aclname(struct xdr_stream *xdr, struct svc_rqst *rqstp,
-                    struct nfs4_ace *ace)
+static __be32 nfsd4_encode_nfsace4(struct xdr_stream *xdr, struct svc_rqst *rqstp,
+                                  struct nfs4_ace *ace)
 {
+       __be32 status;
+
+       /* type */
+       status = nfsd4_encode_acetype4(xdr, ace->type);
+       if (status != nfs_ok)
+               return nfserr_resource;
+       /* flag */
+       status = nfsd4_encode_aceflag4(xdr, ace->flag);
+       if (status != nfs_ok)
+               return nfserr_resource;
+       /* access mask */
+       status = nfsd4_encode_acemask4(xdr, ace->access_mask & NFS4_ACE_MASK_ALL);
+       if (status != nfs_ok)
+               return nfserr_resource;
+       /* who */
        if (ace->whotype != NFS4_ACL_WHO_NAMED)
                return nfs4_acl_write_who(xdr, ace->whotype);
-       else if (ace->flag & NFS4_ACE_IDENTIFIER_GROUP)
+       if (ace->flag & NFS4_ACE_IDENTIFIER_GROUP)
                return nfsd4_encode_group(xdr, rqstp, ace->who_gid);
-       else
-               return nfsd4_encode_user(xdr, rqstp, ace->who_uid);
+       return nfsd4_encode_user(xdr, rqstp, ace->who_uid);
 }
 
 static inline __be32
@@ -3294,15 +3307,8 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
                *p++ = cpu_to_be32(args.acl->naces);
 
                for (ace = args.acl->aces; ace < args.acl->aces + args.acl->naces; ace++) {
-                       p = xdr_reserve_space(xdr, 4*3);
-                       if (!p)
-                               goto out_resource;
-                       *p++ = cpu_to_be32(ace->type);
-                       *p++ = cpu_to_be32(ace->flag);
-                       *p++ = cpu_to_be32(ace->access_mask &
-                                                       NFS4_ACE_MASK_ALL);
-                       status = nfsd4_encode_aclname(xdr, rqstp, ace);
-                       if (status)
+                       status = nfsd4_encode_nfsace4(xdr, args.rqstp, ace);
+                       if (status != nfs_ok)
                                goto out;
                }
        }
index 488ecdacc4c63d2fdd38bc4bcba5de1a63fefad3..f0866a55fd91412fc7290a1f1ce4bea3ec53a4aa 100644 (file)
@@ -90,6 +90,9 @@ nfsd4_encode_uint32_t(struct xdr_stream *xdr, u32 val)
        return nfs_ok;
 }
 
+#define nfsd4_encode_aceflag4(x, v)    nfsd4_encode_uint32_t(x, v)
+#define nfsd4_encode_acemask4(x, v)    nfsd4_encode_uint32_t(x, v)
+#define nfsd4_encode_acetype4(x, v)    nfsd4_encode_uint32_t(x, v)
 #define nfsd4_encode_nfs_lease4(x, v)  nfsd4_encode_uint32_t(x, v)
 
 /**