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

index 2ecdd11521259d364f624c6df407be8682f20933..07a2e65da7d7ff9bdd91cc8ce246bf2ee3840388 100644 (file)
@@ -3102,6 +3102,29 @@ static __be32 nfsd4_encode_fattr4_aclsupport(struct xdr_stream *xdr,
        return nfsd4_encode_uint32_t(xdr, mask);
 }
 
+static __be32 nfsd4_encode_fattr4_acl(struct xdr_stream *xdr,
+                                     const struct nfsd4_fattr_args *args)
+{
+       struct nfs4_acl *acl = args->acl;
+       struct nfs4_ace *ace;
+       __be32 status;
+
+       /* nfsace4<> */
+       if (!acl) {
+               if (xdr_stream_encode_u32(xdr, 0) != XDR_UNIT)
+                       return nfserr_resource;
+       } else {
+               if (xdr_stream_encode_u32(xdr, acl->naces) != XDR_UNIT)
+                       return nfserr_resource;
+               for (ace = acl->aces; ace < acl->aces + acl->naces; ace++) {
+                       status = nfsd4_encode_nfsace4(xdr, args->rqstp, ace);
+                       if (status != nfs_ok)
+                               return status;
+               }
+       }
+       return nfs_ok;
+}
+
 /*
  * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  * ourselves.
@@ -3291,28 +3314,10 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
                        goto out;
        }
        if (bmval0 & FATTR4_WORD0_ACL) {
-               struct nfs4_ace *ace;
-
-               if (args.acl == NULL) {
-                       p = xdr_reserve_space(xdr, 4);
-                       if (!p)
-                               goto out_resource;
-
-                       *p++ = cpu_to_be32(0);
-                       goto out_acl;
-               }
-               p = xdr_reserve_space(xdr, 4);
-               if (!p)
-                       goto out_resource;
-               *p++ = cpu_to_be32(args.acl->naces);
-
-               for (ace = args.acl->aces; ace < args.acl->aces + args.acl->naces; ace++) {
-                       status = nfsd4_encode_nfsace4(xdr, args.rqstp, ace);
-                       if (status != nfs_ok)
-                               goto out;
-               }
+               status = nfsd4_encode_fattr4_acl(xdr, &args);
+               if (status)
+                       goto out;
        }
-out_acl:
        if (bmval0 & FATTR4_WORD0_ACLSUPPORT) {
                status = nfsd4_encode_fattr4_aclsupport(xdr, &args);
                if (status != nfs_ok)