Whamcloud - gitweb
LU-14138 ptlrpc: move more members in PTLRPC request into pill
[fs/lustre-release.git] / lustre / mdc / mdc_acl.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * GPL HEADER START
4  *
5  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 only,
9  * as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * General Public License version 2 for more details (a copy is included
15  * in the LICENSE file that accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License
18  * version 2 along with this program; If not, see
19  * http://www.gnu.org/licenses/gpl-2.0.html
20  *
21  * GPL HEADER END
22  */
23 #include <lustre_acl.h>
24
25 #include "mdc_internal.h"
26
27 int mdc_unpack_acl(struct req_capsule *pill, struct lustre_md *md)
28 {
29         struct mdt_body *body = md->body;
30         struct posix_acl *acl;
31         void *buf;
32         int rc;
33
34         /* for ACL, it's possible that FLACL is set but aclsize is zero.
35          * only when aclsize != 0 there's an actual segment for ACL
36          * in reply buffer.
37          */
38         if (!body->mbo_aclsize) {
39                 md->posix_acl = NULL;
40                 return 0;
41         }
42
43         buf = req_capsule_server_sized_get(pill, &RMF_ACL, body->mbo_aclsize);
44         if (!buf)
45                 return -EPROTO;
46
47         acl = posix_acl_from_xattr(&init_user_ns, buf, body->mbo_aclsize);
48         if (IS_ERR_OR_NULL(acl)) {
49                 rc = acl ? PTR_ERR(acl) : 0;
50                 CERROR("convert xattr to acl: %d\n", rc);
51                 return rc;
52         }
53
54         rc = posix_acl_valid(&init_user_ns, acl);
55         if (rc) {
56                 CERROR("validate acl: %d\n", rc);
57                 posix_acl_release(acl);
58                 return rc;
59         }
60
61         md->posix_acl = acl;
62         return 0;
63 }