Whamcloud - gitweb
06baab6bef19b5354e769518f5d42220a0821257
[fs/lustre-release.git] / lustre / mdt / mdt_xattr.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2011, 2017, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  * Lustre is a trademark of Sun Microsystems, Inc.
31  *
32  * lustre/mdt/mdt_xattr.c
33  *
34  * Lustre Metadata Target (mdt) extended attributes management.
35  *
36  * Author: Peter Braam <braam@clusterfs.com>
37  * Author: Andreas Dilger <adilger@clusterfs.com>
38  * Author: Phil Schwan <phil@clusterfs.com>
39  * Author: Huang Hua <huanghua@clusterfs.com>
40  */
41
42 #define DEBUG_SUBSYSTEM S_MDS
43
44 #include <linux/xattr.h>
45 #include <obd_class.h>
46 #include <lustre_nodemap.h>
47 #include <lustre_acl.h>
48 #include "mdt_internal.h"
49
50
51 /* return EADATA length to the caller. negative value means error */
52 static int mdt_getxattr_pack_reply(struct mdt_thread_info * info)
53 {
54         struct req_capsule *pill = info->mti_pill;
55         struct ptlrpc_request *req = mdt_info_req(info);
56         const char *xattr_name;
57         u64 valid;
58         static const char user_string[] = "user.";
59         int size;
60         int rc = 0;
61         int rc2;
62         ENTRY;
63
64         valid = info->mti_body->mbo_valid & (OBD_MD_FLXATTR | OBD_MD_FLXATTRLS);
65
66         /* Determine how many bytes we need */
67         if (valid == OBD_MD_FLXATTR) {
68                 xattr_name = req_capsule_client_get(pill, &RMF_NAME);
69                 if (!xattr_name)
70                         RETURN(-EFAULT);
71
72                 if (!(exp_connect_flags(req->rq_export) & OBD_CONNECT_XATTR) &&
73                     !strncmp(xattr_name, user_string, sizeof(user_string) - 1))
74                         RETURN(-EOPNOTSUPP);
75
76                 size = mo_xattr_get(info->mti_env,
77                                     mdt_object_child(info->mti_object),
78                                     &LU_BUF_NULL, xattr_name);
79                 if (size == -ENODATA) {
80                         /* XXX: Some client code will not handle -ENODATA
81                          * for XATTR_NAME_LOV (trusted.lov) properly. */
82                         if (strcmp(xattr_name, XATTR_NAME_LOV) == 0)
83                                 rc = 0;
84                         else
85                                 rc = -ENODATA;
86
87                         size = 0;
88                 }
89         } else if (valid == OBD_MD_FLXATTRLS) {
90                 xattr_name = "list";
91                 size = mo_xattr_list(info->mti_env,
92                                      mdt_object_child(info->mti_object),
93                                      &LU_BUF_NULL);
94         } else if (valid == OBD_MD_FLXATTRALL) {
95                 xattr_name = "all";
96                 /* N.B. eadatasize = 0 is not valid for FLXATTRALL */
97                 /* We could calculate accurate sizes, but this would
98                  * introduce a lot of overhead, let's do it later... */
99                 size = info->mti_body->mbo_eadatasize;
100                 req_capsule_set_size(pill, &RMF_EAVALS, RCL_SERVER, size);
101                 req_capsule_set_size(pill, &RMF_EAVALS_LENS, RCL_SERVER, size);
102         } else {
103                 CDEBUG(D_INFO, "Valid bits: %#llx\n",
104                        info->mti_body->mbo_valid);
105                 RETURN(-EINVAL);
106         }
107
108         if (size < 0) {
109                 if (size != -EOPNOTSUPP && size != -ENOENT)
110                         CERROR("%s: error geting EA size for '%s': rc = %d\n",
111                                mdt_obd_name(info->mti_mdt), xattr_name, size);
112                 RETURN(size);
113         }
114
115         if (req_capsule_has_field(pill, &RMF_ACL, RCL_SERVER))
116                 req_capsule_set_size(pill, &RMF_ACL, RCL_SERVER,
117                                      LUSTRE_POSIX_ACL_MAX_SIZE_OLD);
118
119         req_capsule_set_size(pill, &RMF_EADATA, RCL_SERVER,
120                              info->mti_body->mbo_eadatasize == 0 ? 0 : size);
121
122         rc2 = req_capsule_server_pack(pill);
123         if (rc2 < 0)
124                 RETURN(rc2);
125
126         if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETXATTR_PACK))
127                 RETURN(-ENOMEM);
128
129         RETURN(rc < 0 ? rc : size);
130 }
131
132 static int mdt_nodemap_map_acl(struct mdt_thread_info *info, void *buf,
133                                size_t size, const char *name,
134                                enum nodemap_tree_type tree_type)
135 {
136         struct lu_nodemap      *nodemap;
137         struct obd_export      *exp = info->mti_exp;
138         int                     rc = size;
139
140         ENTRY;
141
142         if (strcmp(name, XATTR_NAME_ACL_ACCESS) == 0 ||
143             strcmp(name, XATTR_NAME_ACL_DEFAULT) == 0) {
144                 if (size > info->mti_mdt->mdt_max_ea_size ||
145                      (!exp_connect_large_acl(exp) &&
146                       size > LUSTRE_POSIX_ACL_MAX_SIZE_OLD))
147                         GOTO(out, rc = -ERANGE);
148
149                 nodemap = nodemap_get_from_exp(exp);
150                 if (IS_ERR(nodemap))
151                         GOTO(out, rc = PTR_ERR(nodemap));
152
153                 rc = nodemap_map_acl(nodemap, buf, size, tree_type);
154                 nodemap_putref(nodemap);
155                 if (rc < 0)
156                         GOTO(out, rc);
157         }
158 out:
159         RETURN(rc);
160 }
161
162 static int mdt_getxattr_all(struct mdt_thread_info *info,
163                             struct mdt_body *reqbody, struct mdt_body *repbody,
164                             struct lu_buf *buf, struct md_object *next)
165 {
166         const struct lu_env *env = info->mti_env;
167         char *v, *b, *eadatahead, *eadatatail;
168         __u32 *sizes;
169         int eadatasize, eavallen = 0, eavallens = 0, rc;
170
171         ENTRY;
172
173         /*
174          * The format of the pill is the following:
175          * EADATA:      attr1\0attr2\0...attrn\0
176          * EAVALS:      val1val2...valn
177          * EAVALS_LENS: 4,4,...4
178          */
179
180         eadatahead = buf->lb_buf;
181
182         /* Fill out EADATA first */
183         rc = mo_xattr_list(env, next, buf);
184         if (rc < 0)
185                 GOTO(out_shrink, rc);
186
187         eadatasize = rc;
188         eadatatail = eadatahead + eadatasize;
189
190         v = req_capsule_server_get(info->mti_pill, &RMF_EAVALS);
191         sizes = req_capsule_server_get(info->mti_pill, &RMF_EAVALS_LENS);
192
193         /* Fill out EAVALS and EAVALS_LENS */
194         for (b = eadatahead; b < eadatatail; b += strlen(b) + 1, v += rc) {
195                 buf->lb_buf = v;
196                 buf->lb_len = reqbody->mbo_eadatasize - eavallen;
197                 rc = mo_xattr_get(env, next, buf, b);
198                 if (rc < 0)
199                         GOTO(out_shrink, rc);
200                 rc = mdt_nodemap_map_acl(info, buf->lb_buf, rc, b,
201                                          NODEMAP_FS_TO_CLIENT);
202                 if (rc < 0)
203                         GOTO(out_shrink, rc);
204                 sizes[eavallens] = rc;
205                 eavallens++;
206                 eavallen += rc;
207         }
208
209 out_shrink:
210         if (rc < 0) {
211                 eadatasize = 0;
212                 eavallens = 0;
213                 eavallen = 0;
214         }
215         repbody->mbo_aclsize = eavallen;
216         repbody->mbo_max_mdsize = eavallens;
217
218         req_capsule_shrink(info->mti_pill, &RMF_EAVALS, eavallen, RCL_SERVER);
219         req_capsule_shrink(info->mti_pill, &RMF_EAVALS_LENS,
220                            eavallens * sizeof(__u32), RCL_SERVER);
221         req_capsule_shrink(info->mti_pill, &RMF_EADATA, eadatasize, RCL_SERVER);
222
223         if (rc >= 0)
224                 RETURN(eadatasize);
225         return rc;
226 }
227
228 int mdt_getxattr(struct mdt_thread_info *info)
229 {
230         struct ptlrpc_request  *req = mdt_info_req(info);
231         struct mdt_body        *reqbody;
232         struct mdt_body        *repbody = NULL;
233         struct md_object       *next;
234         struct lu_buf          *buf;
235         int                     easize, rc;
236         u64                     valid;
237         ENTRY;
238
239         LASSERT(info->mti_object != NULL);
240         LASSERT(lu_object_assert_exists(&info->mti_object->mot_obj));
241
242         CDEBUG(D_INODE, "getxattr "DFID"\n", PFID(&info->mti_body->mbo_fid1));
243
244         rc = req_check_sepol(info->mti_pill);
245         if (rc)
246                 RETURN(err_serious(rc));
247
248         reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
249         if (reqbody == NULL)
250                 RETURN(err_serious(-EFAULT));
251
252         rc = mdt_init_ucred(info, reqbody);
253         if (rc)
254                 RETURN(err_serious(rc));
255
256         next = mdt_object_child(info->mti_object);
257         easize = mdt_getxattr_pack_reply(info);
258         if (easize == -ENODATA)
259                 GOTO(out, rc = easize);
260         else if (easize < 0)
261                 GOTO(out, rc = err_serious(easize));
262
263         repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
264         LASSERT(repbody != NULL);
265
266         /* No need further getxattr. */
267         if (easize == 0 || reqbody->mbo_eadatasize == 0)
268                 GOTO(out, rc = easize);
269
270         buf = &info->mti_buf;
271         buf->lb_buf = req_capsule_server_get(info->mti_pill, &RMF_EADATA);
272         buf->lb_len = easize;
273
274         valid = info->mti_body->mbo_valid & (OBD_MD_FLXATTR | OBD_MD_FLXATTRLS);
275
276         if (valid == OBD_MD_FLXATTR) {
277                 const char *xattr_name = req_capsule_client_get(info->mti_pill,
278                                                                 &RMF_NAME);
279                 rc = mo_xattr_get(info->mti_env, next, buf, xattr_name);
280                 if (rc < 0)
281                         GOTO(out, rc);
282
283                 rc = mdt_nodemap_map_acl(info, buf->lb_buf, rc, xattr_name,
284                                          NODEMAP_FS_TO_CLIENT);
285         } else if (valid == OBD_MD_FLXATTRLS) {
286                 CDEBUG(D_INODE, "listxattr\n");
287
288                 rc = mo_xattr_list(info->mti_env, next, buf);
289                 if (rc < 0)
290                         CDEBUG(D_INFO, "listxattr failed: %d\n", rc);
291         } else if (valid == OBD_MD_FLXATTRALL) {
292                 rc = mdt_getxattr_all(info, reqbody, repbody,
293                                       buf, next);
294         } else
295                 LBUG();
296
297         EXIT;
298 out:
299         if (rc >= 0) {
300                 mdt_counter_incr(req, LPROC_MDT_GETXATTR);
301                 /* LU-11109: Set OBD_MD_FLXATTR on success so that
302                  * newer clients can distinguish between nonexistent
303                  * xattrs and zero length values. */
304                 repbody->mbo_valid |= OBD_MD_FLXATTR;
305                 repbody->mbo_eadatasize = rc;
306                 rc = 0;
307         }
308         mdt_exit_ucred(info);
309         return rc;
310 }
311
312 /* shrink dir layout after migration */
313 static int mdt_dir_layout_shrink(struct mdt_thread_info *info)
314 {
315         const struct lu_env *env = info->mti_env;
316         struct mdt_device *mdt = info->mti_mdt;
317         struct lu_ucred *uc = mdt_ucred(info);
318         struct mdt_reint_record *rr = &info->mti_rr;
319         struct lmv_user_md *lmu = rr->rr_eadata;
320         __u32 lum_stripe_count = lmu->lum_stripe_count;
321         struct lu_buf *buf = &info->mti_buf;
322         struct lmv_mds_md_v1 *lmv;
323         struct md_attr *ma = &info->mti_attr;
324         struct ldlm_enqueue_info *einfo = &info->mti_einfo[0];
325         struct mdt_object *pobj = NULL;
326         struct mdt_object *obj;
327         struct mdt_lock_handle *lhp = NULL;
328         struct mdt_lock_handle *lhc;
329         int rc;
330
331         ENTRY;
332
333         if (!mdt->mdt_enable_dir_migration)
334                 RETURN(-EPERM);
335
336         if (!md_capable(uc, CFS_CAP_SYS_ADMIN) &&
337             uc->uc_gid != mdt->mdt_enable_remote_dir_gid &&
338             mdt->mdt_enable_remote_dir_gid != -1)
339                 RETURN(-EPERM);
340
341         /* mti_big_lmm is used to save LMV, but it may be uninitialized. */
342         if (unlikely(!info->mti_big_lmm)) {
343                 info->mti_big_lmmsize = lmv_mds_md_size(64, LMV_MAGIC);
344                 OBD_ALLOC(info->mti_big_lmm, info->mti_big_lmmsize);
345                 if (!info->mti_big_lmm)
346                         RETURN(-ENOMEM);
347         }
348
349         obj = mdt_object_find(env, mdt, rr->rr_fid1);
350         if (IS_ERR(obj))
351                 RETURN(PTR_ERR(obj));
352
353         /* get parent from PFID */
354         rc = mdt_attr_get_pfid(info, obj, &ma->ma_pfid);
355         if (rc)
356                 GOTO(put_obj, rc);
357
358         pobj = mdt_object_find(env, mdt, &ma->ma_pfid);
359         if (IS_ERR(pobj))
360                 GOTO(put_obj, rc = PTR_ERR(pobj));
361
362         /* revoke object remote LOOKUP lock */
363         if (mdt_object_remote(pobj)) {
364                 rc = mdt_revoke_remote_lookup_lock(info, pobj, obj);
365                 if (rc)
366                         GOTO(put_pobj, rc);
367         }
368
369         /*
370          * lock parent if dir will be shrunk to 1 stripe, because dir will be
371          * converted to normal directory, as will change dir fid and update
372          * namespace of parent.
373          */
374         lhp = &info->mti_lh[MDT_LH_PARENT];
375         mdt_lock_reg_init(lhp, LCK_PW);
376
377         if (le32_to_cpu(lmu->lum_stripe_count) < 2) {
378                 rc = mdt_reint_object_lock(info, pobj, lhp,
379                                            MDS_INODELOCK_UPDATE, true);
380                 if (rc)
381                         GOTO(put_pobj, rc);
382         }
383
384         /* lock object */
385         lhc = &info->mti_lh[MDT_LH_CHILD];
386         mdt_lock_reg_init(lhc, LCK_EX);
387         rc = mdt_reint_striped_lock(info, obj, lhc, MDS_INODELOCK_FULL, einfo,
388                                     true);
389         if (rc)
390                 GOTO(unlock_pobj, rc);
391
392         ma->ma_lmv = info->mti_big_lmm;
393         ma->ma_lmv_size = info->mti_big_lmmsize;
394         ma->ma_valid = 0;
395         rc = mdt_stripe_get(info, obj, ma, XATTR_NAME_LMV);
396         if (rc)
397                 GOTO(unlock_obj, rc);
398
399         /* user may run 'lfs migrate' multiple times, so it's shrunk already */
400         if (!(ma->ma_valid & MA_LMV))
401                 GOTO(unlock_obj, rc = -EALREADY);
402
403         lmv = &ma->ma_lmv->lmv_md_v1;
404
405         /* ditto */
406         if (!(le32_to_cpu(lmv->lmv_hash_type) & LMV_HASH_FLAG_MIGRATION))
407                 GOTO(unlock_obj, rc = -EALREADY);
408
409         lum_stripe_count = lmu->lum_stripe_count;
410         if (!lum_stripe_count)
411                 lum_stripe_count = cpu_to_le32(1);
412
413         if (lmv->lmv_migrate_offset != lum_stripe_count) {
414                 CERROR("%s: "DFID" migrate mdt count mismatch %u != %u\n",
415                         mdt_obd_name(info->mti_mdt), PFID(rr->rr_fid1),
416                         lmv->lmv_migrate_offset, lmu->lum_stripe_count);
417                 GOTO(unlock_obj, rc = -EINVAL);
418         }
419
420         if (lmv->lmv_master_mdt_index != lmu->lum_stripe_offset) {
421                 CERROR("%s: "DFID" migrate mdt index mismatch %u != %u\n",
422                         mdt_obd_name(info->mti_mdt), PFID(rr->rr_fid1),
423                         lmv->lmv_master_mdt_index, lmu->lum_stripe_offset);
424                 GOTO(unlock_obj, rc = -EINVAL);
425         }
426
427         if (lum_stripe_count > 1 &&
428             (lmv->lmv_hash_type & cpu_to_le32(LMV_HASH_TYPE_MASK)) !=
429             lmu->lum_hash_type) {
430                 CERROR("%s: "DFID" migrate mdt hash mismatch %u != %u\n",
431                         mdt_obd_name(info->mti_mdt), PFID(rr->rr_fid1),
432                         lmv->lmv_hash_type, lmu->lum_hash_type);
433                 GOTO(unlock_obj, rc = -EINVAL);
434         }
435
436         buf->lb_buf = rr->rr_eadata;
437         buf->lb_len = rr->rr_eadatalen;
438         rc = mo_xattr_set(env, mdt_object_child(obj), buf, XATTR_NAME_LMV, 0);
439         GOTO(unlock_obj, rc);
440
441 unlock_obj:
442         mdt_reint_striped_unlock(info, obj, lhc, einfo, rc);
443 unlock_pobj:
444         mdt_object_unlock(info, pobj, lhp, rc);
445 put_pobj:
446         mdt_object_put(env, pobj);
447 put_obj:
448         mdt_object_put(env, obj);
449
450         return rc;
451 }
452
453 int mdt_reint_setxattr(struct mdt_thread_info *info,
454                        struct mdt_lock_handle *unused)
455 {
456         struct ptlrpc_request   *req = mdt_info_req(info);
457         struct mdt_lock_handle  *lh;
458         const struct lu_env     *env  = info->mti_env;
459         struct lu_buf           *buf  = &info->mti_buf;
460         struct mdt_reint_record *rr   = &info->mti_rr;
461         struct md_attr          *ma = &info->mti_attr;
462         struct lu_attr          *attr = &info->mti_attr.ma_attr;
463         struct mdt_object       *obj;
464         struct md_object        *child;
465         __u64                    valid = attr->la_valid;
466         const char              *xattr_name = rr->rr_name.ln_name;
467         int                      xattr_len = rr->rr_eadatalen;
468         __u64                    lockpart = MDS_INODELOCK_UPDATE;
469         int                      rc;
470         ENTRY;
471
472         CDEBUG(D_INODE, "setxattr for "DFID": %s %s\n", PFID(rr->rr_fid1),
473                valid & OBD_MD_FLXATTR ? "set" : "remove", xattr_name);
474
475         if (info->mti_dlm_req)
476                 ldlm_request_cancel(req, info->mti_dlm_req, 0, LATF_SKIP);
477
478         if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SETXATTR))
479                 RETURN(err_serious(-ENOMEM));
480
481         rc = mdt_init_ucred_reint(info);
482         if (rc != 0)
483                 RETURN(rc);
484
485         if (strncmp(xattr_name, XATTR_USER_PREFIX,
486                     sizeof(XATTR_USER_PREFIX) - 1) == 0) {
487                 if (!(exp_connect_flags(req->rq_export) & OBD_CONNECT_XATTR))
488                         GOTO(out, rc = -EOPNOTSUPP);
489         } else if (strncmp(xattr_name, XATTR_TRUSTED_PREFIX,
490                     sizeof(XATTR_TRUSTED_PREFIX) - 1) == 0) {
491
492                 /* setxattr(LMV) with lum is used to shrink dir layout */
493                 if (strcmp(xattr_name, XATTR_NAME_LMV) == 0) {
494                         __u32 *magic = rr->rr_eadata;
495
496                         /* we don't let to remove LMV? */
497                         if (!rr->rr_eadata)
498                                 GOTO(out, rc = 0);
499
500                         if (le32_to_cpu(*magic) == LMV_USER_MAGIC ||
501                             le32_to_cpu(*magic) == LMV_USER_MAGIC_SPECIFIC) {
502                                 rc = mdt_dir_layout_shrink(info);
503                                 GOTO(out, rc);
504                         }
505                 }
506
507                 if (!md_capable(mdt_ucred(info), CFS_CAP_SYS_ADMIN))
508                         GOTO(out, rc = -EPERM);
509
510                 if (strcmp(xattr_name, XATTR_NAME_LOV) == 0 ||
511                     strcmp(xattr_name, XATTR_NAME_LMA) == 0 ||
512                     strcmp(xattr_name, XATTR_NAME_LMV) == 0 ||
513                     strcmp(xattr_name, XATTR_NAME_LINK) == 0 ||
514                     strcmp(xattr_name, XATTR_NAME_FID) == 0 ||
515                     strcmp(xattr_name, XATTR_NAME_VERSION) == 0 ||
516                     strcmp(xattr_name, XATTR_NAME_SOM) == 0 ||
517                     strcmp(xattr_name, XATTR_NAME_HSM) == 0 ||
518                     strcmp(xattr_name, XATTR_NAME_LFSCK_NAMESPACE) == 0)
519                         GOTO(out, rc = 0);
520         } else if ((valid & OBD_MD_FLXATTR) &&
521                    (strcmp(xattr_name, XATTR_NAME_ACL_ACCESS) == 0 ||
522                     strcmp(xattr_name, XATTR_NAME_ACL_DEFAULT) == 0)) {
523                 rc = mdt_nodemap_map_acl(info, rr->rr_eadata, xattr_len,
524                                          xattr_name, NODEMAP_CLIENT_TO_FS);
525                 if (rc < 0)
526                         GOTO(out, rc);
527                 /* ACLs were mapped out, return an error so the user knows */
528                 if (rc != xattr_len)
529                         GOTO(out, rc = -EPERM);
530         } else if ((strlen(xattr_name) > strlen(XATTR_LUSTRE_LOV) + 1) &&
531                    strncmp(xattr_name, XATTR_LUSTRE_LOV,
532                            strlen(XATTR_LUSTRE_LOV)) == 0) {
533
534                 if (strncmp(xattr_name, XATTR_LUSTRE_LOV".add",
535                             strlen(XATTR_LUSTRE_LOV".add")) &&
536                     strncmp(xattr_name, XATTR_LUSTRE_LOV".set",
537                             strlen(XATTR_LUSTRE_LOV".set")) &&
538                     strncmp(xattr_name, XATTR_LUSTRE_LOV".del",
539                             strlen(XATTR_LUSTRE_LOV".del"))) {
540                         CERROR("%s: invalid xattr name: %s\n",
541                                mdt_obd_name(info->mti_mdt), xattr_name);
542                         GOTO(out, rc = -EINVAL);
543                 }
544
545                 lockpart |= MDS_INODELOCK_LAYOUT;
546         }
547
548         /* Revoke all clients' lookup lock, since the access
549          * permissions for this inode is changed when ACL_ACCESS is
550          * set. This isn't needed for ACL_DEFAULT, since that does
551          * not change the access permissions of this inode, nor any
552          * other existing inodes. It is setting the ACLs inherited
553          * by new directories/files at create time. */
554         /* We need revoke both LOOKUP|PERM lock here, see mdt_attr_set. */
555         if (!strcmp(xattr_name, XATTR_NAME_ACL_ACCESS))
556                 lockpart |= MDS_INODELOCK_PERM | MDS_INODELOCK_LOOKUP;
557         /* We need to take the lock on behalf of old clients so that newer
558          * clients flush their xattr caches */
559         else
560                 lockpart |= MDS_INODELOCK_XATTR;
561
562         lh = &info->mti_lh[MDT_LH_PARENT];
563         /* ACLs were sent to clients under LCK_CR locks, so taking LCK_EX
564          * to cancel them. */
565         mdt_lock_reg_init(lh, LCK_EX);
566         obj = mdt_object_find_lock(info, rr->rr_fid1, lh, lockpart);
567         if (IS_ERR(obj))
568                 GOTO(out, rc = PTR_ERR(obj));
569
570         tgt_vbr_obj_set(env, mdt_obj2dt(obj));
571         rc = mdt_version_get_check_save(info, obj, 0);
572         if (rc)
573                 GOTO(out_unlock, rc);
574
575         if (unlikely(!(valid & OBD_MD_FLCTIME))) {
576                 /* This isn't strictly an error, but all current clients
577                  * should set OBD_MD_FLCTIME when setting attributes. */
578                 CWARN("%s: client miss to set OBD_MD_FLCTIME when "
579                       "setxattr %s: [object "DFID"] [valid %llu]\n",
580                       mdt_obd_name(info->mti_mdt), xattr_name,
581                       PFID(rr->rr_fid1), valid);
582                 attr->la_ctime = ktime_get_real_seconds();
583         }
584         attr->la_valid = LA_CTIME;
585         child = mdt_object_child(obj);
586         if (valid & OBD_MD_FLXATTR) {
587                 int     flags = 0;
588
589                 if (attr->la_flags & XATTR_REPLACE)
590                         flags |= LU_XATTR_REPLACE;
591
592                 if (attr->la_flags & XATTR_CREATE)
593                         flags |= LU_XATTR_CREATE;
594
595                 mdt_fail_write(env, info->mti_mdt->mdt_bottom,
596                                OBD_FAIL_MDS_SETXATTR_WRITE);
597
598                 buf->lb_buf = rr->rr_eadata;
599                 buf->lb_len = xattr_len;
600                 rc = mo_xattr_set(env, child, buf, xattr_name, flags);
601                 /* update ctime after xattr changed */
602                 if (rc == 0) {
603                         ma->ma_attr_flags |= MDS_PERM_BYPASS;
604                         mo_attr_set(env, child, ma);
605                 }
606         } else if (valid & OBD_MD_FLXATTRRM) {
607                 rc = mo_xattr_del(env, child, xattr_name);
608                 /* update ctime after xattr changed */
609                 if (rc == 0) {
610                         ma->ma_attr_flags |= MDS_PERM_BYPASS;
611                         mo_attr_set(env, child, ma);
612                 }
613         } else {
614                 CDEBUG(D_INFO, "valid bits: %#llx\n", valid);
615                 rc = -EINVAL;
616         }
617
618         if (rc == 0)
619                 mdt_counter_incr(req, LPROC_MDT_SETXATTR);
620
621         EXIT;
622 out_unlock:
623         mdt_object_unlock_put(info, obj, lh, rc);
624 out:
625         mdt_exit_ucred(info);
626         return rc;
627 }