Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) #include <linux/gfp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) #include <linux/nfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include <linux/nfs3.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/nfs_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/posix_acl_xattr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/nfsacl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include "internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include "nfs3_fs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #define NFSDBG_FACILITY	NFSDBG_PROC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  * nfs3_prepare_get_acl, nfs3_complete_get_acl, nfs3_abort_get_acl: Helpers for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  * caching get_acl results in a race-free way.  See fs/posix_acl.c:get_acl()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * for explanations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) static void nfs3_prepare_get_acl(struct posix_acl **p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	struct posix_acl *sentinel = uncached_acl_sentinel(current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	if (cmpxchg(p, ACL_NOT_CACHED, sentinel) != ACL_NOT_CACHED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 		/* Not the first reader or sentinel already in place. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) static void nfs3_complete_get_acl(struct posix_acl **p, struct posix_acl *acl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	struct posix_acl *sentinel = uncached_acl_sentinel(current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	/* Only cache the ACL if our sentinel is still in place. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	posix_acl_dup(acl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	if (cmpxchg(p, sentinel, acl) != sentinel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 		posix_acl_release(acl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) static void nfs3_abort_get_acl(struct posix_acl **p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	struct posix_acl *sentinel = uncached_acl_sentinel(current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	/* Remove our sentinel upon failure. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	cmpxchg(p, sentinel, ACL_NOT_CACHED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) struct posix_acl *nfs3_get_acl(struct inode *inode, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	struct nfs_server *server = NFS_SERVER(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	struct page *pages[NFSACL_MAXPAGES] = { };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	struct nfs3_getaclargs args = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		.fh = NFS_FH(inode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		/* The xdr layer may allocate pages here. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		.pages = pages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	struct nfs3_getaclres res = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	struct rpc_message msg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		.rpc_argp	= &args,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		.rpc_resp	= &res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	int status, count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	if (!nfs_server_capable(inode, NFS_CAP_ACLS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		return ERR_PTR(-EOPNOTSUPP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	status = nfs_revalidate_inode(server, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	if (status < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		return ERR_PTR(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	 * Only get the access acl when explicitly requested: We don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	 * need it for access decisions, and only some applications use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	 * it. Applications which request the access acl first are not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	 * penalized from this optimization.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	if (type == ACL_TYPE_ACCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		args.mask |= NFS_ACLCNT|NFS_ACL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	if (S_ISDIR(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		args.mask |= NFS_DFACLCNT|NFS_DFACL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	if (args.mask == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	dprintk("NFS call getacl\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	msg.rpc_proc = &server->client_acl->cl_procinfo[ACLPROC3_GETACL];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	res.fattr = nfs_alloc_fattr();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	if (res.fattr == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	if (args.mask & NFS_ACL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		nfs3_prepare_get_acl(&inode->i_acl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	if (args.mask & NFS_DFACL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		nfs3_prepare_get_acl(&inode->i_default_acl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	status = rpc_call_sync(server->client_acl, &msg, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	dprintk("NFS reply getacl: %d\n", status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	/* pages may have been allocated at the xdr layer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	for (count = 0; count < NFSACL_MAXPAGES && args.pages[count]; count++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		__free_page(args.pages[count]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	switch (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 			status = nfs_refresh_inode(inode, res.fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		case -EPFNOSUPPORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		case -EPROTONOSUPPORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 			dprintk("NFS_V3_ACL extension not supported; disabling\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 			server->caps &= ~NFS_CAP_ACLS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 			fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		case -ENOTSUPP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 			status = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 			goto getout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	if ((args.mask & res.mask) != args.mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		status = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		goto getout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	if (res.acl_access != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		if ((posix_acl_equiv_mode(res.acl_access, NULL) == 0) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		    res.acl_access->a_count == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 			posix_acl_release(res.acl_access);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 			res.acl_access = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	if (res.mask & NFS_ACL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		nfs3_complete_get_acl(&inode->i_acl, res.acl_access);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		forget_cached_acl(inode, ACL_TYPE_ACCESS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	if (res.mask & NFS_DFACL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		nfs3_complete_get_acl(&inode->i_default_acl, res.acl_default);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		forget_cached_acl(inode, ACL_TYPE_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	nfs_free_fattr(res.fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	if (type == ACL_TYPE_ACCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		posix_acl_release(res.acl_default);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		return res.acl_access;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		posix_acl_release(res.acl_access);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		return res.acl_default;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) getout:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	nfs3_abort_get_acl(&inode->i_acl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	nfs3_abort_get_acl(&inode->i_default_acl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	posix_acl_release(res.acl_access);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	posix_acl_release(res.acl_default);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	nfs_free_fattr(res.fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	return ERR_PTR(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) static int __nfs3_proc_setacls(struct inode *inode, struct posix_acl *acl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		struct posix_acl *dfacl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	struct nfs_server *server = NFS_SERVER(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	struct nfs_fattr *fattr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	struct page *pages[NFSACL_MAXPAGES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	struct nfs3_setaclargs args = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		.inode = inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		.mask = NFS_ACL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		.acl_access = acl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		.pages = pages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	struct rpc_message msg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		.rpc_argp	= &args,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		.rpc_resp	= &fattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	int status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	if (acl == NULL && (!S_ISDIR(inode->i_mode) || dfacl == NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	status = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	if (!nfs_server_capable(inode, NFS_CAP_ACLS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	/* We are doing this here because XDR marshalling does not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	 * return any results, it BUGs. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	status = -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	if (acl != NULL && acl->a_count > NFS_ACL_MAX_ENTRIES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	if (dfacl != NULL && dfacl->a_count > NFS_ACL_MAX_ENTRIES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	if (S_ISDIR(inode->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		args.mask |= NFS_DFACL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		args.acl_default = dfacl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		args.len = nfsacl_size(acl, dfacl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		args.len = nfsacl_size(acl, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	if (args.len > NFS_ACL_INLINE_BUFSIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		unsigned int npages = 1 + ((args.len - 1) >> PAGE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		status = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 			args.pages[args.npages] = alloc_page(GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 			if (args.pages[args.npages] == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 				goto out_freepages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 			args.npages++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		} while (args.npages < npages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	dprintk("NFS call setacl\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	status = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	fattr = nfs_alloc_fattr();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	if (fattr == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		goto out_freepages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	msg.rpc_proc = &server->client_acl->cl_procinfo[ACLPROC3_SETACL];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	msg.rpc_resp = fattr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	status = rpc_call_sync(server->client_acl, &msg, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	nfs_access_zap_cache(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	nfs_zap_acl_cache(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	dprintk("NFS reply setacl: %d\n", status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	switch (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 			status = nfs_refresh_inode(inode, fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		case -EPFNOSUPPORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		case -EPROTONOSUPPORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 			dprintk("NFS_V3_ACL SETACL RPC not supported"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 					"(will not retry)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 			server->caps &= ~NFS_CAP_ACLS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 			fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		case -ENOTSUPP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 			status = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	nfs_free_fattr(fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) out_freepages:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	while (args.npages != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		args.npages--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		__free_page(args.pages[args.npages]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) int nfs3_proc_setacls(struct inode *inode, struct posix_acl *acl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		struct posix_acl *dfacl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	ret = __nfs3_proc_setacls(inode, acl, dfacl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	return (ret == -EOPNOTSUPP) ? 0 : ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) int nfs3_set_acl(struct inode *inode, struct posix_acl *acl, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	struct posix_acl *orig = acl, *dfacl = NULL, *alloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	if (S_ISDIR(inode->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		switch(type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		case ACL_TYPE_ACCESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 			alloc = get_acl(inode, ACL_TYPE_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 			if (IS_ERR(alloc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 				goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 			dfacl = alloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		case ACL_TYPE_DEFAULT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 			alloc = get_acl(inode, ACL_TYPE_ACCESS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 			if (IS_ERR(alloc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 				goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 			dfacl = acl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 			acl = alloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	if (acl == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		alloc = posix_acl_from_mode(inode->i_mode, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		if (IS_ERR(alloc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 			goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		acl = alloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	status = __nfs3_proc_setacls(inode, acl, dfacl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	if (acl != orig)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		posix_acl_release(acl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	if (dfacl != orig)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 		posix_acl_release(dfacl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	status = PTR_ERR(alloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) const struct xattr_handler *nfs3_xattr_handlers[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	&posix_acl_access_xattr_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	&posix_acl_default_xattr_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) nfs3_list_one_acl(struct inode *inode, int type, const char *name, void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		size_t size, ssize_t *result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	struct posix_acl *acl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	char *p = data + *result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	acl = get_acl(inode, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	if (IS_ERR_OR_NULL(acl))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	posix_acl_release(acl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	*result += strlen(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	*result += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	if (!size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	if (*result > size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 		return -ERANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	strcpy(p, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) nfs3_listxattr(struct dentry *dentry, char *data, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	struct inode *inode = d_inode(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	ssize_t result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	error = nfs3_list_one_acl(inode, ACL_TYPE_ACCESS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 			XATTR_NAME_POSIX_ACL_ACCESS, data, size, &result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	error = nfs3_list_one_acl(inode, ACL_TYPE_DEFAULT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 			XATTR_NAME_POSIX_ACL_DEFAULT, data, size, &result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) }