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