4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
31 * lustre/mdd/mdd_object.c
33 * Lustre Metadata Server (mdd) routines
35 * Author: Wang Di <wangdi@clusterfs.com>
38 #define DEBUG_SUBSYSTEM S_MDS
40 #include <linux/module.h>
42 #include <obd_class.h>
43 #include <obd_support.h>
44 #include <lprocfs_status.h>
45 /* fid_be_cpu(), fid_cpu_to_be(). */
46 #include <lustre_fid.h>
47 #include <lustre_idmap.h>
48 #include <uapi/linux/lustre/lustre_param.h>
49 #include <lustre_mds.h>
51 #include "mdd_internal.h"
53 static const struct lu_object_operations mdd_lu_obj_ops;
55 struct mdd_object_user {
56 struct list_head mou_list; /**< linked off mod_users */
57 u64 mou_open_flags; /**< open mode by client */
58 __u64 mou_uidgid; /**< uid_gid on client */
59 int mou_opencount; /**< # opened */
60 ktime_t mou_deniednext; /**< time of next access denied
65 static int mdd_xattr_get(const struct lu_env *env,
66 struct md_object *obj, struct lu_buf *buf,
69 static int mdd_changelog_data_store_by_fid(const struct lu_env *env,
70 struct mdd_device *mdd,
71 enum changelog_rec_type type,
72 enum changelog_rec_flags clf_flags,
73 const struct lu_fid *fid,
74 const struct lu_fid *pfid,
75 const char *xattr_name,
76 struct thandle *handle);
78 static inline bool has_prefix(const char *str, const char *prefix);
81 static u32 flags_helper(u64 open_flags)
85 if (open_flags & MDS_FMODE_EXEC) {
86 open_mode = MDS_FMODE_EXEC;
88 if (open_flags & MDS_FMODE_READ)
89 open_mode = MDS_FMODE_READ;
91 (MDS_FMODE_WRITE | MDS_OPEN_TRUNC | MDS_OPEN_APPEND))
92 open_mode |= MDS_FMODE_WRITE;
98 /** Allocate/init a user and its sub-structures.
103 * \retval mou [OUT] success valid structure
106 static struct mdd_object_user *mdd_obj_user_alloc(u64 open_flags,
107 uid_t uid, gid_t gid)
109 struct mdd_object_user *mou;
113 OBD_SLAB_ALLOC_PTR(mou, mdd_object_kmem);
115 RETURN(ERR_PTR(-ENOMEM));
117 mou->mou_open_flags = open_flags;
118 mou->mou_uidgid = ((__u64)uid << 32) | gid;
119 mou->mou_opencount = 0;
120 mou->mou_deniednext = ktime_set(0, 0);
126 * Free a user and its sub-structures.
128 * \param mou [IN] user to be freed.
130 static void mdd_obj_user_free(struct mdd_object_user *mou)
132 OBD_SLAB_FREE_PTR(mou, mdd_object_kmem);
136 * Find if UID/GID already has this file open
138 * Caller should have write-locked \param mdd_obj.
139 * \param mdd_obj [IN] mdd_obj
140 * \param uid [IN] client uid
141 * \param gid [IN] client gid
142 * \retval user pointer or NULL if not found
145 struct mdd_object_user *mdd_obj_user_find(struct mdd_object *mdd_obj,
146 uid_t uid, gid_t gid,
149 struct mdd_object_user *mou;
154 uidgid = ((__u64)uid << 32) | gid;
155 list_for_each_entry(mou, &mdd_obj->mod_users, mou_list) {
156 if (mou->mou_uidgid == uidgid &&
157 flags_helper(mou->mou_open_flags) ==
158 flags_helper(open_flags))
165 * Add a user to the list of openers for this file
167 * Caller should have write-locked \param mdd_obj.
168 * \param mdd_obj [IN] mdd_obj
169 * \param mou [IN] user
171 * \retval -ve failure
173 static int mdd_obj_user_add(struct mdd_object *mdd_obj,
174 struct mdd_object_user *mou,
177 struct mdd_device *mdd = mdd_obj2mdd_dev(mdd_obj);
178 struct mdd_object_user *tmp;
179 __u32 uid = mou->mou_uidgid >> 32;
180 __u32 gid = mou->mou_uidgid & ((1UL << 32) - 1);
183 tmp = mdd_obj_user_find(mdd_obj, uid, gid, mou->mou_open_flags);
187 list_add_tail(&mou->mou_list, &mdd_obj->mod_users);
190 /* next 'access denied' notification cannot happen before
193 mou->mou_deniednext =
194 ktime_add(ktime_get(),
195 ktime_set(mdd->mdd_cl.mc_deniednext, 0));
197 mou->mou_opencount++;
202 * Remove UID from the list
204 * Caller should have write-locked \param mdd_obj.
205 * \param mdd_obj [IN] mdd_obj
206 * \param uid [IN] user
207 * \retval -ve failure
209 static int mdd_obj_user_remove(struct mdd_object *mdd_obj,
210 struct mdd_object_user *mou)
217 list_del_init(&mou->mou_list);
219 mdd_obj_user_free(mou);
223 int mdd_la_get(const struct lu_env *env, struct mdd_object *obj,
228 if (mdd_object_exists(obj) == 0)
231 rc = mdo_attr_get(env, obj, la);
232 if (unlikely(rc != 0)) {
234 obj->mod_flags |= DEAD_OBJ;
238 if (la->la_valid & LA_FLAGS && la->la_flags & LUSTRE_ORPHAN_FL)
239 obj->mod_flags |= ORPHAN_OBJ | DEAD_OBJ;
244 struct mdd_thread_info *mdd_env_info(const struct lu_env *env)
246 return lu_env_info(env, &mdd_thread_key);
249 struct lu_buf *mdd_buf_get(const struct lu_env *env, void *area, ssize_t len)
253 buf = &mdd_env_info(env)->mdi_buf[0];
259 const struct lu_buf *mdd_buf_get_const(const struct lu_env *env,
260 const void *area, ssize_t len)
264 buf = &mdd_env_info(env)->mdi_buf[0];
265 buf->lb_buf = (void *)area;
270 struct lu_object *mdd_object_alloc(const struct lu_env *env,
271 const struct lu_object_header *hdr,
274 struct mdd_device *mdd = lu2mdd_dev(d);
275 struct mdd_object *mdd_obj;
278 OBD_SLAB_ALLOC_PTR_GFP(mdd_obj, mdd_object_kmem, GFP_NOFS);
282 o = mdd2lu_obj(mdd_obj);
283 lu_object_init(o, NULL, d);
284 mdd_obj->mod_obj.mo_ops = &mdd_obj_ops;
285 mdd_obj->mod_obj.mo_dir_ops = &mdd_dir_ops;
286 mdd_obj->mod_count = 0;
287 obd_obt_init(mdd2obd_dev(mdd));
288 o->lo_ops = &mdd_lu_obj_ops;
289 INIT_LIST_HEAD(&mdd_obj->mod_users);
294 static int mdd_object_init(const struct lu_env *env, struct lu_object *o,
295 const struct lu_object_conf *unused)
297 struct mdd_device *d = lu2mdd_dev(o->lo_dev);
298 struct mdd_object *mdd_obj = lu2mdd_obj(o);
299 struct lu_object *below;
300 struct lu_device *under;
303 mdd_obj->mod_cltime = ktime_set(0, 0);
304 under = &d->mdd_child->dd_lu_dev;
305 below = under->ld_ops->ldo_object_alloc(env, o->lo_header, under);
307 RETURN(PTR_ERR(below));
309 lu_object_add(o, below);
314 static int mdd_object_start(const struct lu_env *env, struct lu_object *o)
318 if (lu_object_exists(o)) {
319 struct mdd_object *mdd_obj = lu2mdd_obj(o);
320 struct lu_attr *attr = MDD_ENV_VAR(env, la_for_start);
322 rc = mdd_la_get(env, mdd_obj, attr);
328 static void mdd_object_free(const struct lu_env *env, struct lu_object *o)
330 struct mdd_object *mdd = lu2mdd_obj(o);
331 struct mdd_object_user *mou, *tmp2;
334 list_for_each_entry_safe(mou, tmp2, &mdd->mod_users, mou_list) {
335 list_del(&mou->mou_list);
336 mdd_obj_user_free(mou);
340 /* mdd doesn't contain an lu_object_header, so don't need call_rcu */
341 OBD_SLAB_FREE_PTR(mdd, mdd_object_kmem);
344 static int mdd_object_print(const struct lu_env *env, void *cookie,
345 lu_printer_t p, const struct lu_object *o)
347 struct mdd_object *mdd = lu2mdd_obj((struct lu_object *)o);
349 return (*p)(env, cookie,
350 LUSTRE_MDD_NAME"-object@%p(open_count=%d, valid=%x, cltime=%lldns, flags=%lx)",
351 mdd, mdd->mod_count, mdd->mod_valid,
352 ktime_to_ns(mdd->mod_cltime), mdd->mod_flags);
355 static const struct lu_object_operations mdd_lu_obj_ops = {
356 .loo_object_init = mdd_object_init,
357 .loo_object_start = mdd_object_start,
358 .loo_object_free = mdd_object_free,
359 .loo_object_print = mdd_object_print,
362 struct mdd_object *mdd_object_find(const struct lu_env *env,
363 struct mdd_device *d,
364 const struct lu_fid *f)
366 return md2mdd_obj(md_object_find_slice(env, &d->mdd_md_dev, f));
370 * No permission check is needed.
372 int mdd_attr_get(const struct lu_env *env, struct md_object *obj,
375 struct mdd_object *mdd_obj = md2mdd_obj(obj);
380 rc = mdd_la_get(env, mdd_obj, &ma->ma_attr);
381 if ((ma->ma_need & MA_INODE) != 0 && mdd_is_dead_obj(mdd_obj))
382 ma->ma_attr.la_nlink = 0;
388 * No permission check is needed.
390 static int mdd_xattr_get(const struct lu_env *env,
391 struct md_object *obj, struct lu_buf *buf,
394 struct mdd_object *mdd_obj = md2mdd_obj(obj);
395 struct mdd_device *mdd;
400 if (mdd_object_exists(mdd_obj) == 0) {
401 CERROR("%s: object "DFID" not found: rc = -2\n",
402 mdd_obj_dev_name(mdd_obj),
403 PFID(mdd_object_fid(mdd_obj)));
407 /* If the object has been destroyed, then do not get LMVEA, because
408 * it needs to load stripes from the iteration of the master object,
409 * and it will cause problem if master object has been destroyed, see
411 if (unlikely((mdd_obj->mod_flags & DEAD_OBJ) &&
412 !(mdd_obj->mod_flags & ORPHAN_OBJ) &&
413 strcmp(name, XATTR_NAME_LMV) == 0))
416 /* If the object has been delete from the namespace, then
417 * get linkEA should return -ENOENT as well */
418 if (unlikely((mdd_obj->mod_flags & (DEAD_OBJ | ORPHAN_OBJ)) &&
419 strcmp(name, XATTR_NAME_LINK) == 0))
422 mdd_read_lock(env, mdd_obj, DT_TGT_CHILD);
423 rc = mdo_xattr_get(env, mdd_obj, buf, name);
424 mdd_read_unlock(env, mdd_obj);
428 /* record only getting user xattrs and acls */
429 if (rc >= 0 && buf->lb_buf &&
430 mdd_changelog_enabled(env, mdd, CL_GETXATTR) &&
431 (has_prefix(name, XATTR_USER_PREFIX) ||
432 has_prefix(name, XATTR_NAME_POSIX_ACL_ACCESS) ||
433 has_prefix(name, XATTR_NAME_POSIX_ACL_DEFAULT))) {
434 struct thandle *handle;
437 LASSERT(mdd_object_fid(mdd_obj) != NULL);
439 handle = mdd_trans_create(env, mdd);
441 RETURN(PTR_ERR(handle));
443 rc2 = mdd_declare_changelog_store(env, mdd, CL_GETXATTR, NULL,
448 rc2 = mdd_trans_start(env, mdd, handle);
452 rc2 = mdd_changelog_data_store_by_fid(env, mdd, CL_GETXATTR, 0,
453 mdd_object_fid(mdd_obj),
457 rc2 = mdd_trans_stop(env, mdd, rc2, handle);
466 * Permission check is done when open,
467 * no need check again.
469 int mdd_readlink(const struct lu_env *env, struct md_object *obj,
472 struct mdd_object *mdd_obj = md2mdd_obj(obj);
473 struct dt_object *next;
478 if (mdd_object_exists(mdd_obj) == 0) {
479 CERROR("%s: object "DFID" not found: rc = -2\n",
480 mdd_obj_dev_name(mdd_obj),PFID(mdd_object_fid(mdd_obj)));
484 next = mdd_object_child(mdd_obj);
485 LASSERT(next != NULL);
486 LASSERT(next->do_body_ops != NULL);
487 LASSERT(next->do_body_ops->dbo_read != NULL);
488 mdd_read_lock(env, mdd_obj, DT_TGT_CHILD);
489 rc = dt_read(env, next, buf, &pos);
490 mdd_read_unlock(env, mdd_obj);
495 * No permission check is needed.
497 static int mdd_xattr_list(const struct lu_env *env, struct md_object *obj,
500 struct mdd_object *mdd_obj = md2mdd_obj(obj);
505 mdd_read_lock(env, mdd_obj, DT_TGT_CHILD);
506 rc = mdo_xattr_list(env, mdd_obj, buf);
507 mdd_read_unlock(env, mdd_obj);
509 /* If the buffer is NULL then we are only here to get the
510 * length of the xattr name list. */
511 if (rc < 0 || buf->lb_buf == NULL)
515 * Filter out XATTR_NAME_LINK if this is an orphan object. See
518 if (unlikely(mdd_obj->mod_flags & (DEAD_OBJ | ORPHAN_OBJ))) {
519 char *end = (char *)buf->lb_buf + rc;
520 char *p = buf->lb_buf;
523 char *next = p + strlen(p) + 1;
525 if (strcmp(p, XATTR_NAME_LINK) == 0) {
527 memmove(p, next, end - next);
529 CDEBUG(D_INFO, "Filtered out "XATTR_NAME_LINK
530 " of orphan "DFID"\n",
531 PFID(mdd_object_fid(mdd_obj)));
542 int mdd_invalidate(const struct lu_env *env, struct md_object *obj)
544 return mdo_invalidate(env, md2mdd_obj(obj));
547 int mdd_declare_create_object_internal(const struct lu_env *env,
548 struct mdd_object *p,
549 struct mdd_object *c,
550 struct lu_attr *attr,
551 struct thandle *handle,
552 const struct md_op_spec *spec,
553 struct dt_allocation_hint *hint)
555 struct dt_object_format *dof = &mdd_env_info(env)->mdi_dof;
556 const struct dt_index_features *feat = spec->sp_feat;
560 if (feat != &dt_directory_features && feat != NULL) {
561 dof->dof_type = DFT_INDEX;
562 dof->u.dof_idx.di_feat = feat;
564 dof->dof_type = dt_mode_to_dft(attr->la_mode);
565 if (dof->dof_type == DFT_REGULAR) {
566 dof->u.dof_reg.striped =
567 md_should_create(spec->sp_cr_flags);
568 if (spec->sp_cr_flags & MDS_OPEN_HAS_EA)
569 dof->u.dof_reg.striped = 0;
570 /* is this replay? */
572 dof->u.dof_reg.striped = 0;
576 rc = mdo_declare_create_object(env, c, attr, hint, dof, handle);
581 int mdd_create_object_internal(const struct lu_env *env, struct mdd_object *p,
582 struct mdd_object *c, struct lu_attr *attr,
583 struct thandle *handle,
584 const struct md_op_spec *spec,
585 struct dt_allocation_hint *hint)
587 struct dt_object_format *dof = &mdd_env_info(env)->mdi_dof;
591 LASSERT(!mdd_object_exists(c));
593 rc = mdo_create_object(env, c, attr, hint, dof, handle);
598 int mdd_attr_set_internal(const struct lu_env *env, struct mdd_object *obj,
599 const struct lu_attr *attr, struct thandle *handle,
605 rc = mdo_attr_set(env, obj, attr, handle);
606 #ifdef CONFIG_LUSTRE_FS_POSIX_ACL
607 if (!rc && (attr->la_valid & LA_MODE) && needacl)
608 rc = mdd_acl_chmod(env, obj, attr->la_mode, handle);
613 int mdd_update_time(const struct lu_env *env, struct mdd_object *obj,
614 const struct lu_attr *oattr, struct lu_attr *attr,
615 struct thandle *handle)
620 LASSERT(attr->la_valid & LA_CTIME);
621 LASSERT(oattr != NULL);
623 /* Make sure the ctime is increased only, however, it's not strictly
624 * reliable at here because there is not guarantee to hold lock on
625 * object, so we just bypass some unnecessary cmtime setting first
626 * and OSD has to check it again. */
627 if (attr->la_ctime < oattr->la_ctime)
628 attr->la_valid &= ~(LA_MTIME | LA_CTIME);
629 else if (attr->la_valid == LA_CTIME &&
630 attr->la_ctime == oattr->la_ctime)
631 attr->la_valid &= ~LA_CTIME;
633 if (attr->la_valid != 0)
634 rc = mdd_attr_set_internal(env, obj, attr, handle, 0);
639 static bool is_project_state_change(const struct lu_attr *oattr,
642 if (la->la_valid & LA_PROJID &&
643 oattr->la_projid != la->la_projid)
646 if ((la->la_valid & LA_FLAGS) &&
647 (la->la_flags & LUSTRE_PROJINHERIT_FL) !=
648 (oattr->la_flags & LUSTRE_PROJINHERIT_FL))
655 * This gives the same functionality as the code between
656 * sys_chmod and inode_setattr
657 * chown_common and inode_setattr
658 * utimes and inode_setattr
659 * This API is ported from mds_fix_attr but remove some unnecesssary stuff.
661 * @param[in] oattr Original, current object attributes.
662 * @param[in,out] la New attributes to be evaluated and potentially
663 * modified depending on oattr content and other rules.
664 * @param[in] ma md_attr to be evaluated for that object.
666 static int mdd_fix_attr(const struct lu_env *env, struct mdd_object *obj,
667 const struct lu_attr *oattr, struct lu_attr *la,
668 const struct md_attr *ma)
672 const unsigned long flags = ma->ma_attr_flags;
679 /* Do not permit change file type */
680 if (la->la_valid & LA_TYPE)
683 /* They should not be processed by setattr */
684 if (la->la_valid & (LA_NLINK | LA_RDEV | LA_BLKSIZE))
687 LASSERT(oattr != NULL);
689 uc = lu_ucred_check(env);
693 if (is_project_state_change(oattr, la)) {
694 /* we want rbac roles to have precedence over any other
695 * permission or capability checks
697 if (!uc->uc_rbac_file_perms ||
698 (!cap_raised(uc->uc_cap, CAP_SYS_RESOURCE) &&
699 !lustre_in_group_p(uc, ma->ma_enable_chprojid_gid) &&
700 !(ma->ma_enable_chprojid_gid == -1 &&
701 mdd_permission_internal(env, obj, oattr, MAY_WRITE))))
705 if (la->la_valid == LA_CTIME) {
706 if (!(flags & MDS_PERM_BYPASS))
707 /* This is only for set ctime when rename's source is
709 rc = mdd_may_delete(env, NULL, NULL, obj, oattr, NULL,
711 if (rc == 0 && la->la_ctime <= oattr->la_ctime)
712 la->la_valid &= ~LA_CTIME;
716 if (flags & MDS_CLOSE_UPDATE_TIMES &&
717 la->la_valid & (LA_ATIME | LA_MTIME | LA_CTIME)) {
718 /* This is an atime/mtime/ctime attribute update for
721 if (la->la_valid & LA_ATIME &&
722 la->la_atime <= (oattr->la_atime +
723 mdd_obj2mdd_dev(obj)->mdd_atime_diff))
724 la->la_valid &= ~LA_ATIME;
725 if (la->la_valid & LA_CTIME && la->la_ctime <= oattr->la_ctime)
726 la->la_valid &= ~LA_CTIME;
727 if (la->la_valid & LA_MTIME && la->la_mtime <= oattr->la_mtime)
728 la->la_valid &= ~LA_MTIME;
732 /* Check if flags change. */
733 if (la->la_valid & LA_FLAGS) {
734 unsigned int oldflags = oattr->la_flags &
735 (LUSTRE_IMMUTABLE_FL | LUSTRE_APPEND_FL);
736 unsigned int newflags = la->la_flags &
737 (LUSTRE_IMMUTABLE_FL | LUSTRE_APPEND_FL);
739 if ((uc->uc_fsuid != oattr->la_uid) &&
740 !cap_raised(uc->uc_cap, CAP_FOWNER))
743 /* The IMMUTABLE and APPEND_ONLY flags can
744 * only be changed by the relevant capability. */
745 if ((oldflags ^ newflags) &&
746 !cap_raised(uc->uc_cap, CAP_LINUX_IMMUTABLE))
749 if (!S_ISDIR(oattr->la_mode)) {
750 la->la_flags &= ~(LUSTRE_DIRSYNC_FL | LUSTRE_TOPDIR_FL);
751 } else if (la->la_flags & LUSTRE_ENCRYPT_FL) {
752 /* when trying to add encryption flag on dir,
753 * make sure it is empty
755 rc = mdd_dir_is_empty(env, obj);
762 if (oattr->la_flags & (LUSTRE_IMMUTABLE_FL | LUSTRE_APPEND_FL) &&
763 (la->la_valid & ~LA_FLAGS) &&
764 !(flags & MDS_PERM_BYPASS))
767 /* Check for setting the obj time. */
768 if ((la->la_valid & (LA_MTIME | LA_ATIME | LA_CTIME)) &&
769 !(la->la_valid & ~(LA_MTIME | LA_ATIME | LA_CTIME))) {
770 if ((uc->uc_fsuid != oattr->la_uid) &&
771 !cap_raised(uc->uc_cap, CAP_FOWNER)) {
772 rc = mdd_permission_internal(env, obj, oattr,
779 if (la->la_valid & LA_KILL_SUID) {
780 la->la_valid &= ~LA_KILL_SUID;
781 if ((oattr->la_mode & S_ISUID) &&
782 !(la->la_valid & LA_MODE)) {
783 la->la_mode = oattr->la_mode;
784 la->la_valid |= LA_MODE;
786 la->la_mode &= ~S_ISUID;
789 if (la->la_valid & LA_KILL_SGID) {
790 la->la_valid &= ~LA_KILL_SGID;
791 if (((oattr->la_mode & (S_ISGID | S_IXGRP)) ==
792 (S_ISGID | S_IXGRP)) &&
793 !(la->la_valid & LA_MODE)) {
794 la->la_mode = oattr->la_mode;
795 la->la_valid |= LA_MODE;
797 la->la_mode &= ~S_ISGID;
800 /* Make sure a caller can chmod. */
801 if (la->la_valid & LA_MODE) {
802 /* we want rbac roles to have precedence over any other
803 * permission or capability checks
805 if (!uc->uc_rbac_file_perms ||
806 (!(flags & MDS_PERM_BYPASS) &&
807 (uc->uc_fsuid != oattr->la_uid) &&
808 !cap_raised(uc->uc_cap, CAP_FOWNER)))
811 if (la->la_mode == (umode_t) -1)
812 la->la_mode = oattr->la_mode;
814 la->la_mode = (la->la_mode & S_IALLUGO) |
815 (oattr->la_mode & ~S_IALLUGO);
817 /* Also check the setgid bit! */
818 if (!lustre_in_group_p(uc, (la->la_valid & LA_GID) ?
819 la->la_gid : oattr->la_gid) &&
820 !cap_raised(uc->uc_cap, CAP_FSETID))
821 la->la_mode &= ~S_ISGID;
823 la->la_mode = oattr->la_mode;
826 /* Make sure a caller can chown. */
827 if (la->la_valid & LA_UID) {
828 if (la->la_uid == (uid_t) -1)
829 la->la_uid = oattr->la_uid;
830 /* we want rbac roles to have precedence over any other
831 * permission or capability checks
833 if (!uc->uc_rbac_file_perms ||
834 ((uc->uc_fsuid != oattr->la_uid ||
835 la->la_uid != oattr->la_uid) &&
836 !cap_raised(uc->uc_cap, CAP_CHOWN)))
839 /* If the user or group of a non-directory has been
840 * changed by a non-root user, remove the setuid bit.
841 * 19981026 David C Niemi <niemi@tux.org>
843 * Changed this to apply to all users, including root,
844 * to avoid some races. This is the behavior we had in
845 * 2.0. The check for non-root was definitely wrong
846 * for 2.2 anyway, as it should have been using
847 * CAP_FSETID rather than fsuid -- 19990830 SD. */
848 if (((oattr->la_mode & S_ISUID) == S_ISUID) &&
849 !S_ISDIR(oattr->la_mode)) {
850 la->la_mode &= ~S_ISUID;
851 la->la_valid |= LA_MODE;
855 /* Make sure caller can chgrp. */
856 if (la->la_valid & LA_GID) {
857 if (la->la_gid == (gid_t) -1)
858 la->la_gid = oattr->la_gid;
859 /* we want rbac roles to have precedence over any other
860 * permission or capability checks
862 if (!uc->uc_rbac_file_perms ||
863 ((uc->uc_fsuid != oattr->la_uid ||
864 (la->la_gid != oattr->la_gid &&
865 !lustre_in_group_p(uc, la->la_gid))) &&
866 !cap_raised(uc->uc_cap, CAP_CHOWN)))
869 /* Likewise, if the user or group of a non-directory
870 * has been changed by a non-root user, remove the
871 * setgid bit UNLESS there is no group execute bit
872 * (this would be a file marked for mandatory
873 * locking). 19981026 David C Niemi <niemi@tux.org>
875 * Removed the fsuid check (see the comment above) --
877 if (((oattr->la_mode & (S_ISGID | S_IXGRP)) ==
878 (S_ISGID | S_IXGRP)) && !S_ISDIR(oattr->la_mode)) {
879 la->la_mode &= ~S_ISGID;
880 la->la_valid |= LA_MODE;
884 if (la->la_valid & (LA_SIZE | LA_BLOCKS)) {
885 if (!((flags & MDS_OWNEROVERRIDE) &&
886 (uc->uc_fsuid == oattr->la_uid)) &&
887 !(flags & MDS_PERM_BYPASS)) {
888 rc = mdd_permission_internal(env, obj, oattr,
895 if (la->la_valid & LA_CTIME) {
897 * The pure setattr, it has the priority over what is
898 * already set, do not drop it if ctime is equal.
900 if (la->la_ctime < oattr->la_ctime)
901 la->la_valid &= ~(LA_ATIME | LA_MTIME | LA_CTIME);
907 static int mdd_changelog_data_store_by_fid(const struct lu_env *env,
908 struct mdd_device *mdd,
909 enum changelog_rec_type type,
910 enum changelog_rec_flags clf_flags,
911 const struct lu_fid *fid,
912 const struct lu_fid *pfid,
913 const char *xattr_name,
914 struct thandle *handle)
916 const struct lu_ucred *uc = lu_ucred(env);
917 enum changelog_rec_extra_flags xflags = CLFE_INVALID;
918 struct llog_changelog_rec *rec;
923 clf_flags = (clf_flags & CLF_FLAGMASK) | CLF_VERSION | CLF_EXTRA_FLAGS;
926 if (uc->uc_jobid[0] != '\0')
927 clf_flags |= CLF_JOBID;
928 xflags |= CLFE_UIDGID;
931 if (type == CL_OPEN || type == CL_DN_OPEN)
933 if (type == CL_SETXATTR || type == CL_GETXATTR)
934 xflags |= CLFE_XATTR;
936 reclen = llog_data_len(LLOG_CHANGELOG_HDR_SZ +
937 changelog_rec_offset(clf_flags & CLF_SUPPORTED,
938 xflags & CLFE_SUPPORTED));
939 buf = lu_buf_check_and_alloc(&mdd_env_info(env)->mdi_chlg_buf, reclen);
940 if (buf->lb_buf == NULL)
944 rec->cr_hdr.lrh_len = reclen;
945 rec->cr.cr_flags = clf_flags;
946 rec->cr.cr_type = (__u32)type;
947 rec->cr.cr_tfid = *fid;
949 rec->cr.cr_pfid = *pfid;
950 rec->cr.cr_namelen = 0;
952 if (clf_flags & CLF_JOBID)
953 mdd_changelog_rec_ext_jobid(&rec->cr, uc->uc_jobid);
955 if (clf_flags & CLF_EXTRA_FLAGS) {
956 mdd_changelog_rec_ext_extra_flags(&rec->cr, xflags);
957 if (xflags & CLFE_UIDGID)
958 mdd_changelog_rec_extra_uidgid(&rec->cr,
959 uc->uc_uid, uc->uc_gid);
960 if (xflags & CLFE_NID)
961 mdd_changelog_rec_extra_nid(&rec->cr, uc->uc_nid);
962 if (xflags & CLFE_OPEN)
963 mdd_changelog_rec_extra_omode(&rec->cr, clf_flags);
964 if (xflags & CLFE_XATTR) {
965 if (xattr_name == NULL)
967 mdd_changelog_rec_extra_xattr(&rec->cr, xattr_name);
971 rc = mdd_changelog_store(env, mdd, rec, handle);
976 /** Store a data change changelog record
977 * If this fails, we must fail the whole transaction; we don't
978 * want the change to commit without the log entry.
979 * \param mdd_obj - mdd_object of change
980 * \param handle - transaction handle
981 * \param pfid - parent FID for CL_MTIME changelogs
983 int mdd_changelog_data_store(const struct lu_env *env, struct mdd_device *mdd,
984 enum changelog_rec_type type,
985 enum changelog_rec_flags clf_flags,
986 struct mdd_object *mdd_obj, struct thandle *handle,
987 const struct lu_fid *pfid)
991 LASSERT(mdd_obj != NULL);
992 LASSERT(handle != NULL);
994 if (!mdd_changelog_enabled(env, mdd, type))
997 if (mdd_is_volatile_obj(mdd_obj))
1000 if ((type >= CL_MTIME) && (type <= CL_ATIME) &&
1001 ktime_before(mdd->mdd_cl.mc_starttime, mdd_obj->mod_cltime)) {
1002 /* Don't need multiple updates in this log */
1003 /* Don't check under lock - no big deal if we get an extra
1008 rc = mdd_changelog_data_store_by_fid(env, mdd, type, clf_flags,
1009 mdd_object_fid(mdd_obj), pfid,
1012 mdd_obj->mod_cltime = ktime_get();
1017 int mdd_changelog_data_store_xattr(const struct lu_env *env,
1018 struct mdd_device *mdd,
1019 enum changelog_rec_type type,
1020 enum changelog_rec_flags clf_flags,
1021 struct mdd_object *mdd_obj,
1022 const char *xattr_name,
1023 struct thandle *handle)
1027 LASSERT(mdd_obj != NULL);
1028 LASSERT(handle != NULL);
1030 if (!mdd_changelog_enabled(env, mdd, type))
1033 if (mdd_is_volatile_obj(mdd_obj))
1036 if ((type >= CL_MTIME) && (type <= CL_ATIME) &&
1037 ktime_before(mdd->mdd_cl.mc_starttime, mdd_obj->mod_cltime)) {
1038 /* Don't need multiple updates in this log */
1039 /* Don't check under lock - no big deal if we get an extra
1045 rc = mdd_changelog_data_store_by_fid(env, mdd, type, clf_flags,
1046 mdd_object_fid(mdd_obj), NULL,
1047 xattr_name, handle);
1049 mdd_obj->mod_cltime = ktime_get();
1054 /* Only the bottom CLF_FLAGMASK bits of @flags are stored in the record,
1055 * except for open flags have a dedicated record to store 32 bits of flags.
1057 static int mdd_changelog(const struct lu_env *env, enum changelog_rec_type type,
1058 enum changelog_rec_flags clf_flags,
1059 struct md_device *m, const struct lu_fid *fid)
1061 struct thandle *handle;
1062 struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
1066 LASSERT(fid != NULL);
1068 /* We'll check this again below, but we check now before we
1069 * start a transaction. */
1070 if (!mdd_changelog_enabled(env, mdd, type))
1073 handle = mdd_trans_create(env, mdd);
1075 RETURN(PTR_ERR(handle));
1077 rc = mdd_declare_changelog_store(env, mdd, type, NULL, NULL, handle);
1081 rc = mdd_trans_start(env, mdd, handle);
1085 /* note we only store the low CLF_FLAGMASK bits of la_valid */
1086 rc = mdd_changelog_data_store_by_fid(env, mdd, type,
1087 clf_flags & CLF_FLAGMASK,
1088 fid, NULL, NULL, handle);
1091 rc = mdd_trans_stop(env, mdd, rc, handle);
1097 * Save LMA extended attributes with data from \a ma.
1099 * HSM and Size-On-MDS data will be extracted from \ma if they are valid, if
1100 * not, LMA EA will be first read from disk, modified and write back.
1103 /* Precedence for choosing record type when multiple
1104 * attributes change: setattr > mtime > ctime > atime
1105 * (ctime changes when mtime does, plus chmod/chown.
1106 * atime and ctime are independent.) */
1107 static int mdd_attr_set_changelog(const struct lu_env *env,
1108 struct md_object *obj, struct thandle *handle,
1109 const struct lu_fid *pfid, __u64 valid)
1111 struct mdd_device *mdd = mdo2mdd(obj);
1114 bits = (valid & LA_SIZE) ? BIT(CL_TRUNC) : 0;
1115 bits |= (valid & ~(LA_CTIME|LA_MTIME|LA_ATIME)) ? BIT(CL_SETATTR) : 0;
1116 bits |= (valid & LA_MTIME) ? BIT(CL_MTIME) : 0;
1117 bits |= (valid & LA_CTIME) ? BIT(CL_CTIME) : 0;
1118 bits |= (valid & LA_ATIME) ? BIT(CL_ATIME) : 0;
1119 bits = bits & mdd->mdd_cl.mc_current_mask;
1120 /* This is an implementation limit rather than a protocol limit */
1121 BUILD_BUG_ON(CL_LAST > sizeof(int) * 8);
1125 /* The record type is the lowest non-masked set bit */
1128 /* only the low CLF_FLAGMASK bits of la_valid are stored */
1129 return mdd_changelog_data_store(env, mdd, type, valid & CLF_FLAGMASK,
1130 md2mdd_obj(obj), handle, pfid);
1133 static int mdd_declare_attr_set(const struct lu_env *env,
1134 struct mdd_device *mdd,
1135 struct mdd_object *obj,
1136 const struct lu_attr *attr,
1137 struct thandle *handle)
1141 rc = mdo_declare_attr_set(env, obj, attr, handle);
1145 #ifdef CONFIG_LUSTRE_FS_POSIX_ACL
1146 if (attr->la_valid & LA_MODE) {
1147 mdd_read_lock(env, obj, DT_TGT_CHILD);
1148 rc = mdo_xattr_get(env, obj, &LU_BUF_NULL,
1149 XATTR_NAME_ACL_ACCESS);
1150 mdd_read_unlock(env, obj);
1151 if (rc == -EOPNOTSUPP || rc == -ENODATA)
1157 struct lu_buf *buf = mdd_buf_get(env, NULL, rc);
1158 rc = mdo_declare_xattr_set(env, obj, buf,
1159 XATTR_NAME_ACL_ACCESS, 0,
1167 rc = mdd_declare_changelog_store(env, mdd, CL_SETXATTR, NULL, NULL,
1176 * permission changes may require sync operation, to mitigate performance
1177 * impact, only do this for dir and when permission is reduced.
1179 * For regular files, version is updated with permission change (see VBR), async
1180 * permission won't cause any issue, while missing permission change on
1181 * directory may affect accessibility of other objects after recovery.
1183 static inline bool permission_needs_sync(const struct lu_attr *old,
1184 const struct lu_attr *new)
1186 if (!S_ISDIR(old->la_mode))
1189 if (new->la_valid & LA_UID && old->la_uid != new->la_uid)
1192 if (new->la_valid & LA_GID && old->la_gid != new->la_gid)
1195 if (new->la_valid & LA_MODE) {
1196 /* turned on sticky bit */
1197 if (!(old->la_mode & S_ISVTX) && (new->la_mode & S_ISVTX))
1200 /* set-GID has no impact on what is allowed, not checked */
1202 /* turned off setuid bit, or one of rwx for someone */
1203 if (((new->la_mode & old->la_mode) & (0777 | S_ISUID)) !=
1204 (old->la_mode & (0777 | S_ISUID)))
1211 static inline __u64 mdd_lmm_dom_size(void *buf)
1213 struct lov_mds_md *lmm = buf;
1214 struct lov_comp_md_v1 *comp_v1;
1215 struct lov_mds_md *v1;
1221 if (le32_to_cpu(lmm->lmm_magic) != LOV_MAGIC_COMP_V1)
1224 comp_v1 = (struct lov_comp_md_v1 *)lmm;
1225 off = le32_to_cpu(comp_v1->lcm_entries[0].lcme_offset);
1226 v1 = (struct lov_mds_md *)((char *)comp_v1 + off);
1228 /* DoM entry is the first entry always */
1229 if (lov_pattern(le32_to_cpu(v1->lmm_pattern)) & LOV_PATTERN_MDT)
1230 return le64_to_cpu(comp_v1->lcm_entries[0].lcme_extent.e_end);
1235 /* set attr and LOV EA at once, return updated attr */
1236 int mdd_attr_set(const struct lu_env *env, struct md_object *obj,
1237 const struct md_attr *ma)
1239 struct mdd_object *mdd_obj = md2mdd_obj(obj);
1240 struct mdd_device *mdd = mdo2mdd(obj);
1241 struct thandle *handle = NULL;
1242 struct lu_attr *la_copy = &mdd_env_info(env)->mdi_la_for_fix;
1243 struct lu_attr *attr = MDD_ENV_VAR(env, cattr);
1244 const struct lu_attr *la = &ma->ma_attr;
1245 struct lu_ucred *uc;
1246 struct lquota_id_info qi;
1247 bool quota_reserved = false;
1248 bool chrgrp_by_unprivileged_user = false;
1252 /* we do not use ->attr_set() for LOV/HSM EA any more */
1253 LASSERT((ma->ma_valid & MA_LOV) == 0);
1254 LASSERT((ma->ma_valid & MA_HSM) == 0);
1256 rc = mdd_la_get(env, mdd_obj, attr);
1260 *la_copy = ma->ma_attr;
1261 rc = mdd_fix_attr(env, mdd_obj, attr, la_copy, ma);
1265 /* no need to setattr anymore */
1266 if (la_copy->la_valid == 0) {
1268 "%s: no valid attribute on "DFID", previous was %#llx\n",
1269 mdd_obj_dev_name(mdd_obj),
1270 PFID(mdd_object_fid(mdd_obj)), la->la_valid);
1275 /* If an unprivileged user changes group of some file,
1276 * the setattr operation will be processed synchronously to
1277 * honor the quota limit of the corresponding group. see LU-5152 */
1278 uc = lu_ucred_check(env);
1279 memset(&qi, 0, sizeof(qi));
1280 if (S_ISREG(attr->la_mode) && la->la_valid & LA_GID &&
1281 la->la_gid != attr->la_gid && uc != NULL && uc->uc_fsuid != 0) {
1282 CDEBUG(D_QUOTA, "%s: reserve quota for changing group: gid=%u size=%llu\n",
1283 mdd2obd_dev(mdd)->obd_name, la->la_gid, la->la_size);
1285 if (la->la_valid & LA_BLOCKS)
1286 qi.lqi_space = la->la_blocks << 9;
1287 else if (la->la_valid & LA_SIZE)
1288 qi.lqi_space = la->la_size;
1289 /* use local attr gotten above */
1290 else if (attr->la_valid & LA_BLOCKS)
1291 qi.lqi_space = attr->la_blocks << 9;
1292 else if (attr->la_valid & LA_SIZE)
1293 qi.lqi_space = attr->la_size;
1295 if (qi.lqi_space > 0) {
1296 qi.lqi_id.qid_gid = la->la_gid;
1297 qi.lqi_type = GRPQUOTA;
1298 qi.lqi_space = toqb(qi.lqi_space);
1299 qi.lqi_is_blk = true;
1300 rc = dt_reserve_or_free_quota(env, mdd->mdd_bottom,
1304 CDEBUG(D_QUOTA, "%s: failed to reserve quota for gid %d size %llu\n",
1305 mdd2obd_dev(mdd)->obd_name,
1306 la->la_gid, qi.lqi_space);
1311 quota_reserved = true;
1312 la_copy->la_valid |= LA_FLAGS;
1315 chrgrp_by_unprivileged_user = true;
1317 /* Flush the possible existing client setattr requests to OSTs
1318 * to keep the order with the current setattr operation that
1319 * will be sent directly to OSTs. see LU-5152 */
1320 /* LU-11303 disable sync as this is too heavyweight.
1321 * This should be replaced with a sync only for the object
1322 * being modified here, not the whole filesystem.
1323 rc = dt_sync(env, mdd->mdd_child);
1329 handle = mdd_trans_create(env, mdd);
1330 if (IS_ERR(handle)) {
1331 rc = PTR_ERR(handle);
1337 rc = mdd_declare_attr_set(env, mdd, mdd_obj, la_copy, handle);
1341 rc = mdd_trans_start(env, mdd, handle);
1345 if (!chrgrp_by_unprivileged_user && mdd->mdd_sync_permission &&
1346 permission_needs_sync(attr, la))
1347 handle->th_sync = 1;
1349 if (la->la_valid & (LA_MTIME | LA_CTIME))
1350 CDEBUG(D_INODE, "setting mtime %llu, ctime %llu\n",
1351 la->la_mtime, la->la_ctime);
1353 mdd_write_lock(env, mdd_obj, DT_TGT_CHILD);
1355 /* LU-10509: setattr of LA_SIZE should be skipped case of DOM,
1356 * otherwise following truncate will do nothing and truncated
1357 * data may be read again. This is a quick fix until LU-11033
1360 if (la_copy->la_valid & LA_SIZE) {
1361 struct lu_buf *lov_buf = mdd_buf_get(env, NULL, 0);
1363 rc = mdd_stripe_get(env, mdd_obj, lov_buf, XATTR_NAME_LOV);
1367 if (mdd_lmm_dom_size(lov_buf->lb_buf) > 0)
1368 la_copy->la_valid &= ~LA_SIZE;
1369 lu_buf_free(lov_buf);
1373 if (la_copy->la_valid) {
1374 rc = mdd_attr_set_internal(env, mdd_obj, la_copy, handle, 1);
1376 if (rc == -EDQUOT && la_copy->la_flags & LUSTRE_SET_SYNC_FL) {
1377 /* rollback to the original gid */
1378 la_copy->la_flags &= ~LUSTRE_SET_SYNC_FL;
1379 la_copy->la_gid = attr->la_gid;
1380 mdd_attr_set_internal(env, mdd_obj, la_copy, handle, 1);
1383 mdd_write_unlock(env, mdd_obj);
1387 rc = mdd_attr_set_changelog(env, obj, handle, &ma->ma_pfid,
1390 if (rc == 0 && quota_reserved) {
1391 struct thandle *sub_th;
1393 sub_th = thandle_get_sub_by_dt(env, handle, mdd->mdd_bottom);
1394 if (unlikely(IS_ERR(sub_th))) {
1396 dt_reserve_or_free_quota(env, mdd->mdd_bottom, &qi);
1398 sub_th->th_reserved_quota = qi;
1400 } else if (quota_reserved) {
1402 dt_reserve_or_free_quota(env, mdd->mdd_bottom, &qi);
1406 rc = mdd_trans_stop(env, mdd, rc, handle);
1411 static int mdd_xattr_sanity_check(const struct lu_env *env,
1412 struct mdd_object *obj,
1413 const struct lu_attr *attr,
1416 struct lu_ucred *uc = lu_ucred_assert(env);
1419 if (attr->la_flags & (LUSTRE_IMMUTABLE_FL | LUSTRE_APPEND_FL))
1422 if (strncmp(XATTR_USER_PREFIX, name,
1423 sizeof(XATTR_USER_PREFIX) - 1) == 0) {
1424 /* For sticky directories, only the owner and privileged user
1425 * can write attributes. */
1426 if (S_ISDIR(attr->la_mode) && (attr->la_mode & S_ISVTX) &&
1427 (uc->uc_fsuid != attr->la_uid) &&
1428 !cap_raised(uc->uc_cap, CAP_FOWNER))
1430 } else if (strcmp(name, XATTR_NAME_SOM) != 0 &&
1431 (uc->uc_fsuid != attr->la_uid) &&
1432 !cap_raised(uc->uc_cap, CAP_FOWNER)) {
1440 * Check if a string begins with a given prefix.
1442 * \param str String to check
1443 * \param prefix Substring to check at the beginning of \a str
1444 * \return true/false whether the condition is verified.
1446 static inline bool has_prefix(const char *str, const char *prefix)
1448 return strncmp(prefix, str, strlen(prefix)) == 0;
1452 * Indicate the kind of changelog to store (if any) for a xattr set/del.
1454 * \param[in] xattr_name Full extended attribute name.
1456 * \return type of changelog to use, or CL_NONE if no changelog is to be emitted
1458 static enum changelog_rec_type
1459 mdd_xattr_changelog_type(const struct lu_env *env, struct mdd_device *mdd,
1460 const char *xattr_name)
1462 /* Layout changes systematically recorded */
1463 if (strcmp(XATTR_NAME_LOV, xattr_name) == 0 ||
1464 strcmp(XATTR_LUSTRE_LOV, xattr_name) == 0 ||
1465 allowed_lustre_lov(xattr_name))
1468 /* HSM information changes systematically recorded */
1469 if (strcmp(XATTR_NAME_HSM, xattr_name) == 0)
1472 /* Avoid logging SOM xattr for every file */
1473 if (strcmp(XATTR_NAME_SOM, xattr_name) == 0)
1476 if (has_prefix(xattr_name, XATTR_USER_PREFIX) ||
1477 has_prefix(xattr_name, XATTR_NAME_POSIX_ACL_ACCESS) ||
1478 has_prefix(xattr_name, XATTR_NAME_POSIX_ACL_DEFAULT) ||
1479 has_prefix(xattr_name, XATTR_TRUSTED_PREFIX) ||
1480 has_prefix(xattr_name, XATTR_SECURITY_PREFIX))
1486 static int mdd_declare_xattr_set(const struct lu_env *env,
1487 struct mdd_device *mdd,
1488 struct mdd_object *obj,
1489 const struct lu_buf *buf,
1491 int fl, struct thandle *handle)
1493 enum changelog_rec_type type;
1496 rc = mdo_declare_xattr_set(env, obj, buf, name, fl, handle);
1500 type = mdd_xattr_changelog_type(env, mdd, name);
1502 return 0; /* no changelog to store */
1504 return mdd_declare_changelog_store(env, mdd, type, NULL, NULL, handle);
1508 * Compare current and future data of HSM EA and add a changelog if needed.
1510 * Caller should have write-locked \param obj.
1512 * \param buf - Future HSM EA content.
1513 * \retval 0 if no changelog is needed or changelog was added properly.
1514 * \retval -ve errno if there was a problem
1516 static int mdd_hsm_update_locked(const struct lu_env *env,
1517 struct md_object *obj,
1518 const struct lu_buf *buf,
1519 struct thandle *handle,
1520 enum changelog_rec_flags *clf_flags)
1522 struct mdd_thread_info *info = mdd_env_info(env);
1523 struct mdd_object *mdd_obj = md2mdd_obj(obj);
1524 struct lu_buf *current_buf;
1525 struct md_hsm *current_mh;
1526 struct md_hsm *new_mh;
1530 OBD_ALLOC_PTR(current_mh);
1531 if (current_mh == NULL)
1534 /* Read HSM attrs from disk */
1535 current_buf = lu_buf_check_and_alloc(&info->mdi_xattr_buf,
1537 mdd_obj2mdd_dev(mdd_obj)->mdd_dt_conf.ddp_max_ea_size,
1539 rc = mdo_xattr_get(env, mdd_obj, current_buf, XATTR_NAME_HSM);
1540 rc = lustre_buf2hsm(current_buf->lb_buf, rc, current_mh);
1541 if (rc < 0 && rc != -ENODATA)
1543 else if (rc == -ENODATA)
1544 current_mh->mh_flags = 0;
1546 /* Map future HSM xattr */
1547 OBD_ALLOC_PTR(new_mh);
1549 GOTO(free, rc = -ENOMEM);
1550 lustre_buf2hsm(buf->lb_buf, buf->lb_len, new_mh);
1554 /* Flags differ, set flags for the changelog that will be added */
1555 if (current_mh->mh_flags != new_mh->mh_flags) {
1556 hsm_set_cl_event(clf_flags, HE_STATE);
1557 if (new_mh->mh_flags & HS_DIRTY)
1558 hsm_set_cl_flags(clf_flags, CLF_HSM_DIRTY);
1561 OBD_FREE_PTR(new_mh);
1564 OBD_FREE_PTR(current_mh);
1568 static int mdd_object_pfid_replace(const struct lu_env *env,
1569 struct mdd_object *o)
1571 struct mdd_device *mdd = mdo2mdd(&o->mod_obj);
1572 struct thandle *handle;
1575 handle = mdd_trans_create(env, mdd);
1577 RETURN(PTR_ERR(handle));
1579 handle->th_complex = 1;
1581 /* it doesn't need to track the PFID update via llog, because LFSCK
1582 * will repair it even it goes wrong */
1583 rc = mdd_declare_xattr_set(env, mdd, o, NULL, XATTR_NAME_FID,
1588 rc = mdd_trans_start(env, mdd, handle);
1592 rc = mdo_xattr_set(env, o, NULL, XATTR_NAME_FID, 0, handle);
1597 mdd_trans_stop(env, mdd, rc, handle);
1602 static int mdd_declare_xattr_del(const struct lu_env *env,
1603 struct mdd_device *mdd,
1604 struct mdd_object *obj,
1606 struct thandle *handle);
1608 static int mdd_xattr_del(const struct lu_env *env, struct md_object *obj,
1611 static int mdd_xattr_merge(const struct lu_env *env, struct md_object *md_obj,
1612 struct md_object *md_vic)
1614 struct mdd_device *mdd = mdo2mdd(md_obj);
1615 struct mdd_object *obj = md2mdd_obj(md_obj);
1616 struct mdd_object *vic = md2mdd_obj(md_vic);
1617 struct lu_buf *buf = &mdd_env_info(env)->mdi_buf[0];
1618 struct lu_buf *buf_vic = &mdd_env_info(env)->mdi_buf[1];
1619 struct lov_mds_md *lmm;
1620 struct thandle *handle;
1621 struct lu_attr *cattr = MDD_ENV_VAR(env, cattr);
1622 struct lu_attr *tattr = MDD_ENV_VAR(env, tattr);
1623 bool is_same_projid;
1627 rc = mdd_la_get(env, obj, cattr);
1631 rc = mdd_la_get(env, vic, tattr);
1635 is_same_projid = cattr->la_projid == tattr->la_projid;
1637 lock_order = lu_fid_cmp(mdd_object_fid(obj), mdd_object_fid(vic));
1638 if (lock_order == 0) /* same fid */
1641 handle = mdd_trans_create(env, mdd);
1643 RETURN(PTR_ERR(handle));
1645 if (!is_same_projid) {
1646 rc = mdd_declare_attr_set(env, mdd, vic, cattr, handle);
1651 /* get EA of victim file */
1652 memset(buf_vic, 0, sizeof(*buf_vic));
1653 rc = mdd_stripe_get(env, vic, buf_vic, XATTR_NAME_LOV);
1660 /* parse the layout of victim file */
1661 lmm = buf_vic->lb_buf;
1662 if (le32_to_cpu(lmm->lmm_magic) != LOV_MAGIC_COMP_V1)
1663 GOTO(stop, rc = -EINVAL);
1665 /* save EA of target file for restore */
1666 memset(buf, 0, sizeof(*buf));
1667 rc = mdd_stripe_get(env, obj, buf, XATTR_NAME_LOV);
1671 /* Get rid of the layout from victim object */
1672 rc = mdd_declare_xattr_del(env, mdd, vic, XATTR_NAME_LOV, handle);
1676 rc = mdd_declare_xattr_set(env, mdd, obj, buf_vic, XATTR_NAME_LOV,
1677 LU_XATTR_MERGE, handle);
1681 rc = mdd_trans_start(env, mdd, handle);
1685 if (lock_order > 0) {
1686 mdd_write_lock(env, obj, DT_TGT_CHILD);
1687 mdd_write_lock(env, vic, DT_TGT_CHILD);
1689 mdd_write_lock(env, vic, DT_TGT_CHILD);
1690 mdd_write_lock(env, obj, DT_TGT_CHILD);
1693 if (!is_same_projid) {
1694 cattr->la_valid = LA_PROJID;
1695 rc = mdd_attr_set_internal(env, vic, cattr, handle, 0);
1700 rc = mdo_xattr_set(env, obj, buf_vic, XATTR_NAME_LOV, LU_XATTR_MERGE,
1705 rc = mdo_xattr_del(env, vic, XATTR_NAME_LOV, handle);
1707 GOTO(out_restore, rc);
1709 (void)mdd_changelog_data_store(env, mdd, CL_LAYOUT, 0, obj, handle,
1711 (void)mdd_changelog_data_store(env, mdd, CL_LAYOUT, 0, vic, handle,
1717 int rc2 = mdo_xattr_set(env, obj, buf, XATTR_NAME_LOV,
1718 LU_XATTR_REPLACE, handle);
1720 CERROR("%s: failed rollback of "DFID" layout: file state unknown: rc = %d\n",
1721 mdd_obj_dev_name(obj),
1722 PFID(mdd_object_fid(obj)), rc2);
1726 mdd_write_unlock(env, obj);
1727 mdd_write_unlock(env, vic);
1729 mdd_trans_stop(env, mdd, rc, handle);
1731 lu_buf_free(buf_vic);
1734 (void) mdd_object_pfid_replace(env, obj);
1740 * Extract the mirror with specified mirror id, and store the splitted
1741 * mirror layout to @buf.
1743 * \param[in] comp_v1 mirrored layout
1744 * \param[in] mirror_id the mirror with mirror_id to be extracted
1745 * \param[out] buf store the layout excluding the extracted mirror,
1746 * caller free the buffer we allocated in this function
1747 * \param[out] buf_vic store the extracted layout, caller free the buffer
1748 * we allocated in this function
1750 * \retval 0 on success; < 0 if error happens
1752 static int mdd_split_ea(struct lov_comp_md_v1 *comp_v1, __u16 mirror_id,
1753 struct lu_buf *buf, struct lu_buf *buf_vic)
1755 struct lov_comp_md_v1 *comp_rem;
1756 struct lov_comp_md_v1 *comp_vic;
1757 struct lov_comp_md_entry_v1 *entry;
1758 struct lov_comp_md_entry_v1 *entry_rem;
1759 struct lov_comp_md_entry_v1 *entry_vic;
1761 __u16 comp_cnt, count = 0;
1762 int lmm_size, lmm_size_vic = 0;
1764 int offset, offset_rem, offset_vic;
1766 mirror_cnt = le16_to_cpu(comp_v1->lcm_mirror_count) + 1;
1767 /* comp_v1 should contains more than 1 mirror */
1768 if (mirror_cnt <= 1)
1770 comp_cnt = le16_to_cpu(comp_v1->lcm_entry_count);
1771 lmm_size = le32_to_cpu(comp_v1->lcm_size);
1773 for (i = 0; i < comp_cnt; i++) {
1774 entry = &comp_v1->lcm_entries[i];
1775 if (mirror_id_of(le32_to_cpu(entry->lcme_id)) == mirror_id) {
1777 lmm_size_vic += sizeof(*entry);
1778 lmm_size_vic += le32_to_cpu(entry->lcme_size);
1779 } else if (count > 0) {
1780 /* find the specified mirror */
1788 lu_buf_alloc(buf, lmm_size - lmm_size_vic);
1792 lu_buf_alloc(buf_vic, sizeof(*comp_vic) + lmm_size_vic);
1793 if (!buf_vic->lb_buf) {
1798 comp_rem = (struct lov_comp_md_v1 *)buf->lb_buf;
1799 comp_vic = (struct lov_comp_md_v1 *)buf_vic->lb_buf;
1801 memcpy(comp_rem, comp_v1, sizeof(*comp_v1));
1802 comp_rem->lcm_mirror_count = cpu_to_le16(mirror_cnt - 2);
1803 comp_rem->lcm_entry_count = cpu_to_le32(comp_cnt - count);
1804 comp_rem->lcm_size = cpu_to_le32(lmm_size - lmm_size_vic);
1805 if (!comp_rem->lcm_mirror_count)
1806 comp_rem->lcm_flags = cpu_to_le16(LCM_FL_NONE);
1808 memset(comp_vic, 0, sizeof(*comp_v1));
1809 comp_vic->lcm_magic = cpu_to_le32(LOV_MAGIC_COMP_V1);
1810 comp_vic->lcm_mirror_count = 0;
1811 comp_vic->lcm_entry_count = cpu_to_le32(count);
1812 comp_vic->lcm_size = cpu_to_le32(lmm_size_vic + sizeof(*comp_vic));
1813 comp_vic->lcm_flags = cpu_to_le16(LCM_FL_NONE);
1814 comp_vic->lcm_layout_gen = 0;
1816 offset = sizeof(*comp_v1) + sizeof(*entry) * comp_cnt;
1817 offset_rem = sizeof(*comp_rem) +
1818 sizeof(*entry_rem) * (comp_cnt - count);
1819 offset_vic = sizeof(*comp_vic) + sizeof(*entry_vic) * count;
1820 for (i = j = k = 0; i < comp_cnt; i++) {
1821 struct lov_mds_md *lmm, *lmm_dst;
1824 entry = &comp_v1->lcm_entries[i];
1825 entry_vic = &comp_vic->lcm_entries[j];
1826 entry_rem = &comp_rem->lcm_entries[k];
1828 if (mirror_id_of(le32_to_cpu(entry->lcme_id)) == mirror_id)
1831 /* copy component entry */
1833 memcpy(entry_vic, entry, sizeof(*entry));
1834 entry_vic->lcme_flags &= cpu_to_le32(LCME_FL_INIT);
1835 entry_vic->lcme_offset = cpu_to_le32(offset_vic);
1838 memcpy(entry_rem, entry, sizeof(*entry));
1839 entry_rem->lcme_offset = cpu_to_le32(offset_rem);
1843 lmm = (struct lov_mds_md *)((char *)comp_v1 + offset);
1845 lmm_dst = (struct lov_mds_md *)
1846 ((char *)comp_vic + offset_vic);
1848 lmm_dst = (struct lov_mds_md *)
1849 ((char *)comp_rem + offset_rem);
1851 /* copy component entry blob */
1852 memcpy(lmm_dst, lmm, le32_to_cpu(entry->lcme_size));
1854 /* blob offset advance */
1855 offset += le32_to_cpu(entry->lcme_size);
1857 offset_vic += le32_to_cpu(entry->lcme_size);
1859 offset_rem += le32_to_cpu(entry->lcme_size);
1865 static int mdd_xattr_split(const struct lu_env *env, struct md_object *md_obj,
1866 struct md_rejig_data *mrd)
1868 struct mdd_device *mdd = mdo2mdd(md_obj);
1869 struct mdd_object *obj = md2mdd_obj(md_obj);
1870 struct mdd_object *vic = NULL;
1871 struct lu_buf *buf = &mdd_env_info(env)->mdi_buf[0];
1872 struct lu_buf *buf_save = &mdd_env_info(env)->mdi_buf[1];
1873 struct lu_buf *buf_vic = &mdd_env_info(env)->mdi_buf[2];
1874 struct lov_comp_md_v1 *lcm;
1875 struct thandle *handle;
1877 bool dom_stripe = false;
1882 * NULL @mrd_obj means mirror deleting, and use NULL vic to indicate
1886 vic = md2mdd_obj(mrd->mrd_obj);
1888 handle = mdd_trans_create(env, mdd);
1890 RETURN(PTR_ERR(handle));
1892 /* get EA of mirrored file */
1893 memset(buf_save, 0, sizeof(*buf));
1894 rc = mdd_stripe_get(env, obj, buf_save, XATTR_NAME_LOV);
1898 lcm = buf_save->lb_buf;
1899 if (le32_to_cpu(lcm->lcm_magic) != LOV_MAGIC_COMP_V1)
1900 GOTO(stop, rc = -EINVAL);
1903 * Extract the mirror with specified mirror id, and store the splitted
1904 * mirror layout to the victim buffer.
1906 memset(buf, 0, sizeof(*buf));
1907 memset(buf_vic, 0, sizeof(*buf_vic));
1908 rc = mdd_split_ea(lcm, mrd->mrd_mirror_id, buf, buf_vic);
1912 * @buf stores layout w/o the specified mirror, @buf_vic stores the
1916 dom_stripe = mdd_lmm_dom_size(buf_vic->lb_buf) > 0;
1920 * non delete mirror split
1922 * declare obj set remaining layout in @buf, will set obj's
1925 rc = mdd_declare_xattr_set(env, mdd, obj, buf, XATTR_NAME_LOV,
1926 LU_XATTR_SPLIT, handle);
1930 /* declare vic set splitted layout in @buf_vic */
1931 rc = mdd_declare_xattr_set(env, mdd, vic, buf_vic,
1932 XATTR_NAME_LOV, LU_XATTR_SPLIT,
1938 * declare delete mirror objects in @buf_vic, will change obj's
1941 rc = mdd_declare_xattr_set(env, mdd, obj, buf_vic,
1942 XATTR_NAME_LOV, LU_XATTR_PURGE,
1947 /* declare obj set remaining layout in @buf */
1948 rc = mdd_declare_xattr_set(env, mdd, obj, buf,
1949 XATTR_NAME_LOV, LU_XATTR_SPLIT,
1955 rc = mdd_trans_start(env, mdd, handle);
1960 /* don't use the same file to save the splitted mirror */
1961 rc = lu_fid_cmp(mdd_object_fid(obj), mdd_object_fid(vic));
1963 GOTO(stop, rc = -EPERM);
1966 mdd_write_lock(env, obj, DT_TGT_CHILD);
1967 mdd_write_lock(env, vic, DT_TGT_CHILD);
1969 mdd_write_lock(env, vic, DT_TGT_CHILD);
1970 mdd_write_lock(env, obj, DT_TGT_CHILD);
1973 mdd_write_lock(env, obj, DT_TGT_CHILD);
1976 /* set obj's layout in @buf */
1977 rc = mdo_xattr_set(env, obj, buf, XATTR_NAME_LOV, LU_XATTR_SPLIT,
1983 /* set vic's layout in @buf_vic */
1984 rc = mdo_xattr_set(env, vic, buf_vic, XATTR_NAME_LOV,
1985 LU_XATTR_CREATE, handle);
1987 GOTO(out_restore, rc);
1989 /* delete mirror objects */
1990 rc = mdo_xattr_set(env, obj, buf_vic, XATTR_NAME_LOV,
1991 LU_XATTR_PURGE, handle);
1993 GOTO(out_restore, rc);
1996 rc = mdd_changelog_data_store(env, mdd, CL_LAYOUT, 0, obj, handle,
1999 GOTO(out_restore, rc);
2002 rc = mdd_changelog_data_store(env, mdd, CL_LAYOUT, 0, vic,
2005 GOTO(out_restore, rc);
2010 /* restore obj's in-memory and on-disk layout */
2011 int rc2 = mdo_xattr_set(env, obj, buf_save, XATTR_NAME_LOV,
2012 LU_XATTR_REPLACE, handle);
2014 CERROR("%s: failed rollback "DFID
2015 " layout: file state unknown: rc = %d\n",
2016 mdd_obj_dev_name(obj),
2017 PFID(mdd_object_fid(obj)), rc);
2021 mdd_write_unlock(env, obj);
2023 mdd_write_unlock(env, vic);
2025 rc = mdd_trans_stop(env, mdd, rc, handle);
2027 /* Truncate local DOM data if all went well */
2028 if (!rc && dom_stripe)
2029 mdd_dom_fixup(env, mdd, obj, NULL);
2031 lu_buf_free(buf_save);
2033 lu_buf_free(buf_vic);
2036 (void) mdd_object_pfid_replace(env, obj);
2041 static int mdd_layout_merge_allowed(const struct lu_env *env,
2042 struct md_object *target,
2043 struct md_object *victim)
2045 struct mdd_object *o1 = md2mdd_obj(target);
2047 /* cannot extend directory's LOVEA */
2048 if (S_ISDIR(mdd_object_type(o1))) {
2049 CERROR("%s: Don't extend directory's LOVEA, just set it.\n",
2050 mdd_obj_dev_name(o1));
2058 * The caller should guarantee to update the object ctime
2059 * after xattr_set if needed.
2061 static int mdd_xattr_set(const struct lu_env *env, struct md_object *obj,
2062 const struct lu_buf *buf, const char *name,
2065 struct mdd_object *mdd_obj = md2mdd_obj(obj);
2066 struct lu_attr *attr = MDD_ENV_VAR(env, cattr);
2067 struct mdd_device *mdd = mdo2mdd(obj);
2068 struct thandle *handle;
2069 enum changelog_rec_type cl_type;
2070 enum changelog_rec_flags clf_flags = 0;
2074 rc = mdd_la_get(env, mdd_obj, attr);
2078 rc = mdd_xattr_sanity_check(env, mdd_obj, attr, name);
2082 if (strcmp(name, XATTR_LUSTRE_LOV) == 0 &&
2083 (fl == LU_XATTR_MERGE || fl == LU_XATTR_SPLIT)) {
2084 struct md_rejig_data *mrd = buf->lb_buf;
2085 struct md_object *victim = mrd->mrd_obj;
2087 if (buf->lb_len != sizeof(*mrd))
2091 if (fl == LU_XATTR_MERGE) {
2092 rc = mdd_layout_merge_allowed(env, obj, victim);
2095 /* merge layout of victim as a mirror of obj's. */
2096 rc = mdd_xattr_merge(env, obj, victim);
2098 rc = mdd_xattr_split(env, obj, mrd);
2103 if (strcmp(name, XATTR_NAME_ACL_ACCESS) == 0 ||
2104 strcmp(name, XATTR_NAME_ACL_DEFAULT) == 0) {
2105 struct posix_acl *acl;
2107 /* user may set empty ACL, which should be treated as removing
2109 acl = posix_acl_from_xattr(&init_user_ns, buf->lb_buf,
2112 RETURN(PTR_ERR(acl));
2114 rc = mdd_xattr_del(env, obj, name);
2117 posix_acl_release(acl);
2120 if (!strcmp(name, XATTR_NAME_ACL_ACCESS)) {
2121 rc = mdd_acl_set(env, mdd_obj, attr, buf, fl);
2125 handle = mdd_trans_create(env, mdd);
2127 RETURN(PTR_ERR(handle));
2129 rc = mdd_declare_xattr_set(env, mdd, mdd_obj, buf, name, fl, handle);
2133 rc = mdd_trans_start(env, mdd, handle);
2137 mdd_write_lock(env, mdd_obj, DT_TGT_CHILD);
2139 if (strcmp(XATTR_NAME_HSM, name) == 0) {
2140 rc = mdd_hsm_update_locked(env, obj, buf, handle, &clf_flags);
2142 mdd_write_unlock(env, mdd_obj);
2147 rc = mdo_xattr_set(env, mdd_obj, buf, name, fl, handle);
2148 mdd_write_unlock(env, mdd_obj);
2152 cl_type = mdd_xattr_changelog_type(env, mdd, name);
2156 rc = mdd_changelog_data_store_xattr(env, mdd, cl_type, clf_flags,
2157 mdd_obj, name, handle);
2161 return mdd_trans_stop(env, mdd, rc, handle);
2164 static int mdd_declare_xattr_del(const struct lu_env *env,
2165 struct mdd_device *mdd,
2166 struct mdd_object *obj,
2168 struct thandle *handle)
2170 enum changelog_rec_type type;
2173 rc = mdo_declare_xattr_del(env, obj, name, handle);
2177 type = mdd_xattr_changelog_type(env, mdd, name);
2179 return 0; /* no changelog to store */
2181 return mdd_declare_changelog_store(env, mdd, type, NULL, NULL, handle);
2185 * The caller should guarantee to update the object ctime
2186 * after xattr_set if needed.
2188 static int mdd_xattr_del(const struct lu_env *env, struct md_object *obj,
2191 struct mdd_object *mdd_obj = md2mdd_obj(obj);
2192 struct lu_attr *attr = MDD_ENV_VAR(env, cattr);
2193 struct mdd_device *mdd = mdo2mdd(obj);
2194 struct thandle *handle;
2198 rc = mdd_la_get(env, mdd_obj, attr);
2202 rc = mdd_xattr_sanity_check(env, mdd_obj, attr, name);
2206 handle = mdd_trans_create(env, mdd);
2208 RETURN(PTR_ERR(handle));
2210 rc = mdd_declare_xattr_del(env, mdd, mdd_obj, name, handle);
2214 rc = mdd_trans_start(env, mdd, handle);
2218 mdd_write_lock(env, mdd_obj, DT_TGT_CHILD);
2219 rc = mdo_xattr_del(env, mdd_obj, name, handle);
2220 mdd_write_unlock(env, mdd_obj);
2224 if (mdd_xattr_changelog_type(env, mdd, name) < 0)
2227 rc = mdd_changelog_data_store_xattr(env, mdd, CL_SETXATTR, 0, mdd_obj,
2232 return mdd_trans_stop(env, mdd, rc, handle);
2236 * read lov/lmv EA of an object
2237 * return the lov/lmv EA in an allocated lu_buf
2239 int mdd_stripe_get(const struct lu_env *env, struct mdd_object *obj,
2240 struct lu_buf *lmm_buf, const char *name)
2242 struct lu_buf *buf = &mdd_env_info(env)->mdi_big_buf;
2247 if (buf->lb_buf == NULL) {
2248 buf = lu_buf_check_and_alloc(buf, 4096);
2249 if (buf->lb_buf == NULL)
2254 rc = mdo_xattr_get(env, obj, buf, name);
2255 if (rc == -ERANGE) {
2256 /* mdi_big_buf is allocated but is too small
2257 * we need to increase it */
2258 buf = lu_buf_check_and_alloc(&mdd_env_info(env)->mdi_big_buf,
2260 if (buf->lb_buf == NULL)
2263 } else if (rc < 0) {
2265 } else if (rc == 0) {
2269 lu_buf_alloc(lmm_buf, rc);
2270 if (lmm_buf->lb_buf == NULL)
2274 * we don't use lmm_buf directly, because we don't know xattr size, so
2275 * by using mdi_big_buf we can avoid calling mdo_xattr_get() twice.
2277 memcpy(lmm_buf->lb_buf, buf->lb_buf, rc);
2282 static int mdd_xattr_hsm_replace(const struct lu_env *env,
2283 struct mdd_object *o, struct lu_buf *buf,
2284 struct thandle *handle)
2286 struct hsm_attrs *attrs;
2287 enum hsm_states hsm_flags;
2288 enum changelog_rec_flags clf_flags = 0;
2292 rc = mdo_xattr_set(env, o, buf, XATTR_NAME_HSM, LU_XATTR_REPLACE,
2297 attrs = buf->lb_buf;
2298 hsm_flags = le32_to_cpu(attrs->hsm_flags);
2299 if (!(hsm_flags & HS_RELEASED) || mdd_is_dead_obj(o))
2302 /* Add a changelog record for release. */
2303 hsm_set_cl_event(&clf_flags, HE_RELEASE);
2304 rc = mdd_changelog_data_store(env, mdo2mdd(&o->mod_obj), CL_HSM,
2305 clf_flags, o, handle, NULL);
2310 * check if layout swapping between 2 objects is allowed
2312 * - only normal FIDs or non-system IGIFs
2313 * - same type of objects
2314 * - same owner/group (so quotas are still valid) unless this is from HSM
2317 static int mdd_layout_swap_allowed(const struct lu_env *env,
2318 struct mdd_object *o1,
2319 const struct lu_attr *attr1,
2320 struct mdd_object *o2,
2321 const struct lu_attr *attr2,
2324 const struct lu_fid *fid1, *fid2;
2327 fid1 = mdd_object_fid(o1);
2328 fid2 = mdd_object_fid(o2);
2330 if (!fid_is_norm(fid1) &&
2331 (!fid_is_igif(fid1) || IS_ERR(mdd_links_get(env, o1))))
2334 if (!fid_is_norm(fid2) &&
2335 (!fid_is_igif(fid2) || IS_ERR(mdd_links_get(env, o2))))
2338 if (mdd_object_type(o1) != mdd_object_type(o2)) {
2339 if (S_ISDIR(mdd_object_type(o1)))
2341 if (S_ISREG(mdd_object_type(o1)))
2346 if (flags & SWAP_LAYOUTS_MDS_HSM)
2349 if ((attr1->la_uid != attr2->la_uid) ||
2350 (attr1->la_gid != attr2->la_gid))
2356 /* XXX To set the proper lmm_oi & lmm_layout_gen when swap layouts, we have to
2357 * look into the layout in MDD layer.
2359 static int mdd_lmm_oi(struct lov_mds_md *lmm, struct ost_id *oi, bool get)
2361 struct lov_comp_md_v1 *comp_v1;
2362 struct lov_mds_md *v1;
2366 if (le32_to_cpu(lmm->lmm_magic) == LOV_MAGIC_COMP_V1) {
2367 comp_v1 = (struct lov_comp_md_v1 *)lmm;
2368 ent_count = le16_to_cpu(comp_v1->lcm_entry_count);
2376 off = le32_to_cpu(comp_v1->lcm_entries[i].lcme_offset);
2377 v1 = (struct lov_mds_md *)((char *)comp_v1 + off);
2378 if (le32_to_cpu(v1->lmm_magic) != LOV_MAGIC_FOREIGN) {
2386 comp_v1->lcm_entries[i].lcme_offset);
2387 v1 = (struct lov_mds_md *)((char *)comp_v1 +
2389 if (le32_to_cpu(v1->lmm_magic) ==
2396 for (i = 0; i < le32_to_cpu(ent_count); i++) {
2397 off = le32_to_cpu(comp_v1->lcm_entries[i].
2399 v1 = (struct lov_mds_md *)((char *)comp_v1 +
2401 if (le32_to_cpu(v1->lmm_magic) !=
2406 } else if (le32_to_cpu(lmm->lmm_magic) == LOV_MAGIC_V1 ||
2407 le32_to_cpu(lmm->lmm_magic) == LOV_MAGIC_V3) {
2418 static inline int mdd_get_lmm_oi(struct lov_mds_md *lmm, struct ost_id *oi)
2420 return mdd_lmm_oi(lmm, oi, true);
2423 static inline int mdd_set_lmm_oi(struct lov_mds_md *lmm, struct ost_id *oi)
2425 return mdd_lmm_oi(lmm, oi, false);
2428 static int mdd_lmm_gen(struct lov_mds_md *lmm, __u32 *gen, bool get)
2430 struct lov_comp_md_v1 *comp_v1;
2432 if (le32_to_cpu(lmm->lmm_magic) == LOV_MAGIC_COMP_V1) {
2433 comp_v1 = (struct lov_comp_md_v1 *)lmm;
2435 *gen = le32_to_cpu(comp_v1->lcm_layout_gen);
2437 comp_v1->lcm_layout_gen = cpu_to_le32(*gen);
2438 } else if (le32_to_cpu(lmm->lmm_magic) == LOV_MAGIC_V1 ||
2439 le32_to_cpu(lmm->lmm_magic) == LOV_MAGIC_V3) {
2440 __u16 tmp_gen = *gen;
2442 *gen = le16_to_cpu(lmm->lmm_layout_gen);
2444 lmm->lmm_layout_gen = cpu_to_le16(tmp_gen);
2451 static inline int mdd_get_lmm_gen(struct lov_mds_md *lmm, __u32 *gen)
2453 return mdd_lmm_gen(lmm, gen, true);
2456 static inline int mdd_set_lmm_gen(struct lov_mds_md *lmm, __u32 *gen)
2458 return mdd_lmm_gen(lmm, gen, false);
2461 int mdd_dom_fixup(const struct lu_env *env, struct mdd_device *mdd,
2462 struct mdd_object *mo, struct mdd_object *vo)
2464 struct dt_object *dom, *vlt;
2465 dt_obj_version_t dv = 0;
2472 vlt = dt_object_locate(mdd_object_child(vo), mdd->mdd_bottom);
2474 GOTO(out, rc = -ENOENT);
2475 dv = dt_data_version_get(env, vlt);
2477 GOTO(out, rc = -ENODATA);
2480 dom = dt_object_locate(mdd_object_child(mo), mdd->mdd_bottom);
2482 th = dt_trans_create(env, mdd->mdd_bottom);
2484 GOTO(out, rc = PTR_ERR(th));
2487 rc = dt_declare_data_version_set(env, dom, th);
2491 rc = dt_declare_data_version_del(env, dom, th);
2494 rc = dt_declare_punch(env, dom, 0, OBD_OBJECT_EOF, th);
2499 rc = dt_trans_start_local(env, mdd->mdd_bottom, th);
2504 dt_data_version_set(env, dom, dv, th);
2506 dt_data_version_del(env, dom, th);
2507 rc = dt_punch(env, dom, 0, OBD_OBJECT_EOF, th);
2511 dt_trans_stop(env, mdd->mdd_bottom, th);
2513 /* Ignore failure but report the error */
2515 CERROR("%s: can't manage DOM file "DFID" data: rc = %d\n",
2516 mdd_obj_dev_name(mo), PFID(mdd_object_fid(mo)), rc);
2521 * swap layouts between 2 lustre objects
2523 static int mdd_swap_layouts(const struct lu_env *env, struct md_object *obj1,
2524 struct md_object *obj2, __u64 flags)
2526 struct mdd_thread_info *info = mdd_env_info(env);
2527 struct mdd_object *fst_o = md2mdd_obj(obj1);
2528 struct mdd_object *snd_o = md2mdd_obj(obj2);
2529 struct lu_attr *fst_la = MDD_ENV_VAR(env, cattr);
2530 struct lu_attr *snd_la = MDD_ENV_VAR(env, tattr);
2531 struct mdd_device *mdd = mdo2mdd(obj1);
2532 struct lov_mds_md *fst_lmm, *snd_lmm;
2533 struct lu_buf *fst_buf = &info->mdi_buf[0];
2534 struct lu_buf *snd_buf = &info->mdi_buf[1];
2535 struct lu_buf *fst_hsm_buf = &info->mdi_buf[2];
2536 struct lu_buf *snd_hsm_buf = &info->mdi_buf[3];
2537 struct ost_id *saved_oi = NULL;
2538 struct thandle *handle;
2539 struct mdd_object *dom_o = NULL, *vlt_o = NULL;
2540 __u64 domsize_dom, domsize_vlt;
2541 __u32 fst_gen, snd_gen, saved_gen;
2547 BUILD_BUG_ON(ARRAY_SIZE(info->mdi_buf) < 4);
2548 memset(info->mdi_buf, 0, sizeof(info->mdi_buf));
2550 /* we have to sort the 2 obj, so locking will always
2551 * be in the same order, even in case of 2 concurrent swaps */
2552 rc = lu_fid_cmp(mdd_object_fid(fst_o), mdd_object_fid(snd_o));
2553 if (rc == 0) /* same fid ? */
2559 rc = mdd_la_get(env, fst_o, fst_la);
2563 rc = mdd_la_get(env, snd_o, snd_la);
2567 /* check if layout swapping is allowed */
2568 rc = mdd_layout_swap_allowed(env, fst_o, fst_la, snd_o, snd_la, flags);
2572 handle = mdd_trans_create(env, mdd);
2574 RETURN(PTR_ERR(handle));
2576 rc = mdd_stripe_get(env, fst_o, fst_buf, XATTR_NAME_LOV);
2577 if (rc < 0 && rc != -ENODATA)
2580 rc = mdd_stripe_get(env, snd_o, snd_buf, XATTR_NAME_LOV);
2581 if (rc < 0 && rc != -ENODATA)
2584 /* check if file has DoM. DoM file can be migrated only to another
2585 * DoM layout with the same DoM component size or to an non-DOM
2586 * layout. After migration to OSTs layout, local MDT inode data
2587 * should be truncated.
2588 * Objects are sorted by FIDs, considering that original file's FID
2589 * is always smaller the snd_o is always original file we are migrating
2592 domsize_dom = mdd_lmm_dom_size(snd_buf->lb_buf);
2593 domsize_vlt = mdd_lmm_dom_size(fst_buf->lb_buf);
2595 /* Only migration is supported for DoM files, not 'swap_layouts' so
2596 * target file must be volatile and orphan.
2598 if (fst_o->mod_flags & (ORPHAN_OBJ | VOLATILE_OBJ)) {
2599 vlt_o = domsize_vlt ? fst_o : NULL;
2600 dom_o = domsize_dom ? snd_o : NULL;
2601 } else if (snd_o->mod_flags & (ORPHAN_OBJ | VOLATILE_OBJ)) {
2602 swap(domsize_dom, domsize_vlt);
2603 vlt_o = domsize_vlt ? snd_o : NULL;
2604 dom_o = domsize_dom ? fst_o : NULL;
2605 } else if (domsize_dom > 0 || domsize_vlt > 0) {
2606 /* 'lfs swap_layouts' case, neither file should have DoM */
2608 CDEBUG(D_LAYOUT, "cannot swap layouts with DOM component, "
2609 "use migration instead: rc = %d\n", rc);
2613 if (domsize_vlt > 0 && domsize_dom == 0) {
2616 "%s: cannot swap "DFID" layout: OST to DOM migration not supported: rc = %d\n",
2617 mdd_obj_dev_name(snd_o),
2618 PFID(mdd_object_fid(snd_o)), rc);
2620 } else if (domsize_vlt > 0 && domsize_dom != domsize_vlt) {
2623 "%s: cannot swap "DFID" layout: new layout must have same DoM component size: rc = %d\n",
2624 mdd_obj_dev_name(fst_o),
2625 PFID(mdd_object_fid(fst_o)), rc);
2629 /* swapping 2 non existant layouts is a success */
2630 if (fst_buf->lb_buf == NULL && snd_buf->lb_buf == NULL)
2633 /* to help inode migration between MDT, it is better to
2634 * start by the no layout file (if one), so we order the swap */
2635 if (snd_buf->lb_buf == NULL) {
2637 swap(fst_buf, snd_buf);
2640 fst_gen = snd_gen = 0;
2641 /* lmm and generation layout initialization */
2642 if (fst_buf->lb_buf != NULL) {
2643 fst_lmm = fst_buf->lb_buf;
2644 mdd_get_lmm_gen(fst_lmm, &fst_gen);
2645 fst_fl = LU_XATTR_REPLACE;
2649 fst_fl = LU_XATTR_CREATE;
2652 snd_lmm = snd_buf->lb_buf;
2653 mdd_get_lmm_gen(snd_lmm, &snd_gen);
2655 saved_gen = fst_gen;
2656 /* increase the generation layout numbers */
2661 * XXX The layout generation is used to generate component IDs for
2662 * the composite file, we have to do some special tweaks to make
2663 * sure the layout generation is always adequate for that job.
2666 /* Skip invalid generation number for composite layout */
2667 if ((snd_gen & LCME_ID_MASK) == 0)
2669 if ((fst_gen & LCME_ID_MASK) == 0)
2671 /* Make sure the generation is greater than all the component IDs */
2672 if (fst_gen < snd_gen)
2674 else if (fst_gen > snd_gen)
2677 /* set the file specific informations in lmm */
2678 if (fst_lmm != NULL) {
2679 struct ost_id temp_oi;
2681 saved_oi = &info->mdi_oa.o_oi;
2682 mdd_get_lmm_oi(fst_lmm, saved_oi);
2683 mdd_get_lmm_oi(snd_lmm, &temp_oi);
2684 mdd_set_lmm_gen(fst_lmm, &snd_gen);
2685 mdd_set_lmm_oi(fst_lmm, &temp_oi);
2686 mdd_set_lmm_oi(snd_lmm, saved_oi);
2688 if ((snd_lmm->lmm_magic & cpu_to_le32(LOV_MAGIC_MASK)) ==
2689 cpu_to_le32(LOV_MAGIC_MAGIC))
2690 snd_lmm->lmm_magic |= cpu_to_le32(LOV_MAGIC_DEFINED);
2692 GOTO(stop, rc = -EPROTO);
2694 mdd_set_lmm_gen(snd_lmm, &fst_gen);
2696 /* Prepare HSM attribute if it's required */
2697 if (flags & SWAP_LAYOUTS_MDS_HSM) {
2698 const int buflen = sizeof(struct hsm_attrs);
2700 lu_buf_alloc(fst_hsm_buf, buflen);
2701 lu_buf_alloc(snd_hsm_buf, buflen);
2702 if (fst_hsm_buf->lb_buf == NULL || snd_hsm_buf->lb_buf == NULL)
2703 GOTO(stop, rc = -ENOMEM);
2705 /* Read HSM attribute */
2706 rc = mdo_xattr_get(env, fst_o, fst_hsm_buf, XATTR_NAME_HSM);
2710 rc = mdo_xattr_get(env, snd_o, snd_hsm_buf, XATTR_NAME_HSM);
2714 rc = mdd_declare_xattr_set(env, mdd, fst_o, snd_hsm_buf,
2715 XATTR_NAME_HSM, LU_XATTR_REPLACE,
2720 rc = mdd_declare_xattr_set(env, mdd, snd_o, fst_hsm_buf,
2721 XATTR_NAME_HSM, LU_XATTR_REPLACE,
2727 /* prepare transaction */
2728 rc = mdd_declare_xattr_set(env, mdd, fst_o, snd_buf, XATTR_NAME_LOV,
2733 if (fst_buf->lb_buf != NULL)
2734 rc = mdd_declare_xattr_set(env, mdd, snd_o, fst_buf,
2735 XATTR_NAME_LOV, LU_XATTR_REPLACE,
2738 rc = mdd_declare_xattr_del(env, mdd, snd_o, XATTR_NAME_LOV,
2743 rc = mdd_trans_start(env, mdd, handle);
2747 /* objects are already sorted */
2748 mdd_write_lock(env, fst_o, DT_TGT_CHILD);
2749 mdd_write_lock(env, snd_o, DT_TGT_CHILD);
2751 if (!mdd_object_exists(fst_o))
2752 GOTO(unlock, rc = -ENOENT);
2753 if (!mdd_object_exists(snd_o))
2754 GOTO(unlock, rc = -ENOENT);
2756 if (flags & SWAP_LAYOUTS_MDS_HSM) {
2757 rc = mdd_xattr_hsm_replace(env, fst_o, snd_hsm_buf, handle);
2761 rc = mdd_xattr_hsm_replace(env, snd_o, fst_hsm_buf, handle);
2763 rc2 = mdd_xattr_hsm_replace(env, fst_o, fst_hsm_buf,
2766 CERROR("%s: HSM error restoring "DFID": rc = %d/%d\n",
2767 mdd_obj_dev_name(fst_o),
2768 PFID(mdd_object_fid(fst_o)), rc, rc2);
2773 rc = mdo_xattr_set(env, fst_o, snd_buf, XATTR_NAME_LOV, fst_fl, handle);
2777 if (unlikely(CFS_FAIL_CHECK(OBD_FAIL_MDS_HSM_SWAP_LAYOUTS))) {
2780 if (fst_buf->lb_buf != NULL)
2781 rc = mdo_xattr_set(env, snd_o, fst_buf, XATTR_NAME_LOV,
2782 LU_XATTR_REPLACE, handle);
2784 rc = mdo_xattr_del(env, snd_o, XATTR_NAME_LOV, handle);
2787 GOTO(out_restore, rc);
2789 /* Issue one changelog record per file */
2790 rc = mdd_changelog_data_store(env, mdd, CL_LAYOUT, 0, fst_o, handle,
2795 rc = mdd_changelog_data_store(env, mdd, CL_LAYOUT, 0, snd_o, handle,
2805 /* failure on second file, but first was done, so we have
2806 * to roll back first. */
2807 if (fst_buf->lb_buf != NULL) {
2808 mdd_set_lmm_oi(fst_lmm, saved_oi);
2809 mdd_set_lmm_gen(fst_lmm, &saved_gen);
2810 rc2 = mdo_xattr_set(env, fst_o, fst_buf, XATTR_NAME_LOV,
2811 LU_XATTR_REPLACE, handle);
2813 rc2 = mdo_xattr_del(env, fst_o, XATTR_NAME_LOV, handle);
2818 if (flags & SWAP_LAYOUTS_MDS_HSM) {
2820 rc2 = mdd_xattr_hsm_replace(env, fst_o, fst_hsm_buf,
2826 rc2 = mdd_xattr_hsm_replace(env, snd_o, snd_hsm_buf,
2833 CERROR("%s: unable to roll back layout swap of "DFID" and "DFID", steps: %d: rc = %d/%d\n",
2834 mdd_obj_dev_name(fst_o),
2835 PFID(mdd_object_fid(snd_o)),
2836 PFID(mdd_object_fid(fst_o)),
2838 /* a solution to avoid journal commit is to panic,
2839 * but it has strong consequences so we use LBUG to
2840 * allow sysdamin to choose to panic or not
2847 mdd_write_unlock(env, snd_o);
2848 mdd_write_unlock(env, fst_o);
2851 rc = mdd_trans_stop(env, mdd, rc, handle);
2853 /* Truncate local DOM data if all went well, except migration case
2854 * with the same DOM component size. In that case a local data is
2855 * still in use and shouldn't be deleted.
2858 mdd_dom_fixup(env, mdd, dom_o, vlt_o);
2860 lu_buf_free(fst_buf);
2861 lu_buf_free(snd_buf);
2862 lu_buf_free(fst_hsm_buf);
2863 lu_buf_free(snd_hsm_buf);
2866 (void) mdd_object_pfid_replace(env, fst_o);
2867 (void) mdd_object_pfid_replace(env, snd_o);
2872 static int mdd_declare_layout_change(const struct lu_env *env,
2873 struct mdd_device *mdd,
2874 struct mdd_object *obj,
2875 struct md_layout_change *mlc,
2876 struct thandle *handle)
2880 rc = mdo_declare_layout_change(env, obj, mlc, handle);
2884 return mdd_declare_changelog_store(env, mdd, CL_LAYOUT, NULL, NULL,
2888 /* For PFL, this is used to instantiate necessary component objects. */
2890 mdd_layout_instantiate_component(const struct lu_env *env,
2891 struct mdd_object *obj, struct md_layout_change *mlc,
2892 struct thandle *handle)
2894 struct mdd_device *mdd = mdd_obj2mdd_dev(obj);
2898 if (mlc->mlc_opc != MD_LAYOUT_WRITE)
2901 rc = mdd_declare_layout_change(env, mdd, obj, mlc, handle);
2903 * It's possible that another layout write intent has already
2904 * instantiated our objects, so a -EALREADY returned, and we need to
2908 RETURN(rc == -EALREADY ? 0 : rc);
2910 rc = mdd_trans_start(env, mdd, handle);
2914 mdd_write_lock(env, obj, DT_TGT_CHILD);
2915 rc = mdo_layout_change(env, obj, mlc, handle);
2916 mdd_write_unlock(env, obj);
2920 rc = mdd_changelog_data_store(env, mdd, CL_LAYOUT, 0, obj, handle,
2926 * Change the FLR layout from RDONLY to WRITE_PENDING.
2928 * It picks the primary mirror, and bumps the layout version, and set
2929 * layout version xattr to OST objects in a sync tx. In order to facilitate
2930 * the handling of phantom writers from evicted clients, the clients carry
2931 * layout version of the file with write RPC, so that the OSTs can verify
2932 * if the write RPCs are legitimate, meaning not from evicted clients.
2935 mdd_layout_update_rdonly(const struct lu_env *env, struct mdd_object *obj,
2936 struct md_layout_change *mlc, struct thandle *handle)
2938 struct mdd_device *mdd = mdd_obj2mdd_dev(obj);
2939 struct lu_buf *som_buf = &mdd_env_info(env)->mdi_buf[1];
2940 struct lustre_som_attrs *som = &mlc->mlc_som;
2945 /* Verify acceptable operations */
2946 switch (mlc->mlc_opc) {
2947 case MD_LAYOUT_WRITE:
2948 case MD_LAYOUT_RESYNC:
2949 /* these are legal operations - this represents the case that
2950 * a few mirrors were missed in the last resync. */
2952 case MD_LAYOUT_RESYNC_DONE:
2957 som_buf->lb_buf = som;
2958 som_buf->lb_len = sizeof(*som);
2959 rc = mdo_xattr_get(env, obj, som_buf, XATTR_NAME_SOM);
2960 if (rc < 0 && rc != -ENODATA)
2964 lustre_som_swab(som);
2965 if (som->lsa_valid & SOM_FL_STRICT)
2966 fl = LU_XATTR_REPLACE;
2968 if (mlc->mlc_opc == MD_LAYOUT_WRITE &&
2969 mlc->mlc_intent->lai_extent.e_end > som->lsa_size) {
2970 som->lsa_size = mlc->mlc_intent->lai_extent.e_end + 1;
2971 fl = LU_XATTR_REPLACE;
2975 rc = mdd_declare_layout_change(env, mdd, obj, mlc, handle);
2980 rc = mdd_declare_xattr_set(env, mdd, obj, som_buf,
2981 XATTR_NAME_SOM, fl, handle);
2986 /* record a changelog for data mover to consume */
2987 rc = mdd_declare_changelog_store(env, mdd, CL_FLRW, NULL, NULL, handle);
2991 rc = mdd_trans_start(env, mdd, handle);
2995 /* it needs a sync tx to make FLR to work properly */
2996 handle->th_sync = 1;
2998 mdd_write_lock(env, obj, DT_TGT_CHILD);
2999 rc = mdo_layout_change(env, obj, mlc, handle);
3001 /* SOM state transition from STRICT to STALE */
3002 som->lsa_valid = SOM_FL_STALE;
3003 lustre_som_swab(som);
3004 rc = mdo_xattr_set(env, obj, som_buf, XATTR_NAME_SOM,
3007 mdd_write_unlock(env, obj);
3011 rc = mdd_changelog_data_store(env, mdd, CL_FLRW, 0, obj, handle, NULL);
3022 * Handle mirrored file state transition when it's in WRITE_PENDING.
3024 * Only MD_LAYOUT_RESYNC, which represents start of resync, is allowed when
3025 * the file is in WRITE_PENDING state. If everything goes fine, the file's
3026 * layout version will be increased, and the file's state will be changed to
3030 mdd_layout_update_write_pending(const struct lu_env *env,
3031 struct mdd_object *obj, struct md_layout_change *mlc,
3032 struct thandle *handle)
3034 struct mdd_device *mdd = mdd_obj2mdd_dev(obj);
3035 struct lu_buf *som_buf = &mdd_env_info(env)->mdi_buf[1];
3036 struct lustre_som_attrs *som = &mlc->mlc_som;
3041 switch (mlc->mlc_opc) {
3042 case MD_LAYOUT_RESYNC:
3043 /* Upon receiving the resync request, it should
3044 * instantiate all stale components right away to get ready
3045 * for mirror copy. In order to avoid layout version change,
3046 * client should avoid sending LAYOUT_WRITE request at the
3049 case MD_LAYOUT_WRITE:
3051 * legal race for concurrent write, the file state has been
3052 * changed by another client. Or a jump over file size and
3055 som_buf->lb_buf = som;
3056 som_buf->lb_len = sizeof(*som);
3057 rc = mdo_xattr_get(env, obj, som_buf, XATTR_NAME_SOM);
3058 if (rc < 0 && rc != -ENODATA)
3062 lustre_som_swab(som);
3063 if (mlc->mlc_intent->lai_extent.e_end > som->lsa_size) {
3065 mlc->mlc_intent->lai_extent.e_end + 1;
3066 fl = LU_XATTR_REPLACE;
3074 rc = mdd_declare_layout_change(env, mdd, obj, mlc, handle);
3079 rc = mdd_declare_xattr_set(env, mdd, obj, som_buf,
3080 XATTR_NAME_SOM, fl, handle);
3085 rc = mdd_trans_start(env, mdd, handle);
3089 /* it needs a sync tx to make FLR to work properly */
3090 handle->th_sync = 1;
3092 mdd_write_lock(env, obj, DT_TGT_CHILD);
3093 rc = mdo_layout_change(env, obj, mlc, handle);
3095 som->lsa_valid = SOM_FL_STALE;
3096 lustre_som_swab(som);
3097 rc = mdo_xattr_set(env, obj, som_buf, XATTR_NAME_SOM,
3100 mdd_write_unlock(env, obj);
3111 * Handle the requests when a FLR file's state is in SYNC_PENDING.
3113 * Only concurrent write and sync complete requests are possible when the
3114 * file is in SYNC_PENDING. For the latter request, it will pass in the
3115 * mirrors that have been synchronized, then the stale bit will be cleared
3116 * to make the file's state turn into RDONLY.
3117 * For concurrent write reqeust, it just needs to change the file's state
3118 * to WRITE_PENDING in a sync tx. It doesn't have to change the layout
3119 * version because the version will be increased in the transition to
3120 * SYNC_PENDING later so that it can deny the write request from potential
3121 * evicted SYNC clients. */
3123 mdd_object_update_sync_pending(const struct lu_env *env, struct mdd_object *obj,
3124 struct md_layout_change *mlc, struct thandle *handle)
3126 struct mdd_device *mdd = mdd_obj2mdd_dev(obj);
3127 struct lu_buf *som_buf = &mdd_env_info(env)->mdi_buf[1];
3132 /* operation validation */
3133 switch (mlc->mlc_opc) {
3134 case MD_LAYOUT_RESYNC_DONE:
3135 /* resync complete. */
3136 case MD_LAYOUT_WRITE:
3137 /* concurrent write. */
3139 case MD_LAYOUT_RESYNC:
3140 /* resync again, most likely the previous run failed.
3141 * no-op if it's already in SYNC_PENDING state */
3147 if (mlc->mlc_som.lsa_valid & SOM_FL_STRICT) {
3148 rc = mdo_xattr_get(env, obj, &LU_BUF_NULL, XATTR_NAME_SOM);
3149 if (rc < 0 && rc != -ENODATA)
3152 fl = rc == -ENODATA ? LU_XATTR_CREATE : LU_XATTR_REPLACE;
3153 lustre_som_swab(&mlc->mlc_som);
3154 som_buf->lb_buf = &mlc->mlc_som;
3155 som_buf->lb_len = sizeof(mlc->mlc_som);
3158 rc = mdd_declare_layout_change(env, mdd, obj, mlc, handle);
3162 /* record a changelog for the completion of resync */
3163 rc = mdd_declare_changelog_store(env, mdd, CL_RESYNC, NULL, NULL,
3168 /* RESYNC_DONE has piggybacked size and blocks */
3170 rc = mdd_declare_xattr_set(env, mdd, obj, som_buf,
3171 XATTR_NAME_SOM, fl, handle);
3176 rc = mdd_trans_start(env, mdd, handle);
3180 /* it needs a sync tx to make FLR to work properly */
3181 handle->th_sync = 1;
3183 rc = mdo_layout_change(env, obj, mlc, handle);
3188 rc = mdo_xattr_set(env, obj, som_buf, XATTR_NAME_SOM,
3194 rc = mdd_changelog_data_store(env, mdd, CL_RESYNC, 0, obj, handle,
3204 * Update the layout for PCC-RO.
3207 mdd_layout_update_pccro(const struct lu_env *env, struct md_object *o,
3208 struct md_layout_change *mlc)
3210 struct mdd_object *obj = md2mdd_obj(o);
3211 struct mdd_device *mdd = mdd_obj2mdd_dev(obj);
3212 struct thandle *handle;
3217 handle = mdd_trans_create(env, mdd);
3219 RETURN(PTR_ERR(handle));
3221 /* TODO: Set SOM strict correct when the file is PCC-RO cached. */
3222 rc = mdd_declare_layout_change(env, mdd, obj, mlc, handle);
3224 * It is possible that another layout write intent has already
3225 * set/cleared read-only flag on the object, so as to return
3226 * -EALREADY, and we need to do nothing in this case.
3229 GOTO(out, rc == -EALREADY ? rc = 0 : rc);
3231 rc = mdd_trans_start(env, mdd, handle);
3235 mdd_write_lock(env, obj, DT_TGT_CHILD);
3236 rc = mdo_layout_change(env, obj, mlc, handle);
3237 mdd_write_unlock(env, obj);
3241 rc = mdd_changelog_data_store(env, mdd, CL_LAYOUT, 0, obj, handle,
3244 mdd_trans_stop(env, mdd, rc, handle);
3249 * Layout change callback for object.
3251 * This is only used by FLR and PCC-RO for now. In the future, it can be
3252 * exteneded to handle all layout change.
3255 mdd_layout_change(const struct lu_env *env, struct md_object *o,
3256 struct md_layout_change *mlc)
3258 struct mdd_object *obj = md2mdd_obj(o);
3259 struct mdd_device *mdd = mdd_obj2mdd_dev(obj);
3260 struct lu_buf *buf = mdd_buf_get(env, NULL, 0);
3261 struct lov_comp_md_v1 *lcm;
3262 struct thandle *handle;
3268 if (S_ISDIR(mdd_object_type(obj))) {
3269 switch (mlc->mlc_opc) {
3270 case MD_LAYOUT_SHRINK:
3271 rc = mdd_dir_layout_shrink(env, o, mlc);
3273 case MD_LAYOUT_SPLIT:
3274 rc = mdd_dir_layout_split(env, o, mlc);
3283 /* Verify acceptable operations */
3284 switch (mlc->mlc_opc) {
3285 case MD_LAYOUT_WRITE: {
3286 struct layout_intent *intent = mlc->mlc_intent;
3288 if (intent->lai_opc == LAYOUT_INTENT_PCCRO_SET ||
3289 intent->lai_opc == LAYOUT_INTENT_PCCRO_CLEAR)
3290 RETURN(mdd_layout_update_pccro(env, o, mlc));
3292 case MD_LAYOUT_RESYNC:
3293 case MD_LAYOUT_RESYNC_DONE:
3299 handle = mdd_trans_create(env, mdd);
3301 RETURN(PTR_ERR(handle));
3303 rc = mdd_stripe_get(env, obj, buf, XATTR_NAME_LOV);
3310 /* analyze the layout to make sure it's a FLR file */
3312 if (le32_to_cpu(lcm->lcm_magic) != LOV_MAGIC_COMP_V1)
3313 GOTO(out, rc = -EINVAL);
3315 flr_state = le16_to_cpu(lcm->lcm_flags) & LCM_FL_FLR_MASK;
3317 /* please refer to HLD of FLR for state transition */
3318 switch (flr_state) {
3320 rc = mdd_layout_instantiate_component(env, obj, mlc, handle);
3322 case LCM_FL_WRITE_PENDING:
3323 rc = mdd_layout_update_write_pending(env, obj, mlc, handle);
3326 rc = mdd_layout_update_rdonly(env, obj, mlc, handle);
3328 case LCM_FL_SYNC_PENDING:
3329 rc = mdd_object_update_sync_pending(env, obj, mlc, handle);
3338 mdd_trans_stop(env, mdd, rc, handle);
3343 void mdd_object_make_hint(const struct lu_env *env, struct mdd_object *parent,
3344 struct mdd_object *child, const struct lu_attr *attr,
3345 const struct md_op_spec *spec,
3346 struct dt_allocation_hint *hint)
3348 struct dt_object *np = parent ? mdd_object_child(parent) : NULL;
3349 struct mdd_device *mdd = mdd_obj2mdd_dev(child);
3350 struct dt_object *nc = mdd_object_child(child);
3352 memset(hint, 0, sizeof(*hint));
3354 /* For striped directory, give striping EA to lod_ah_init, which will
3355 * decide the stripe_offset and stripe count by it. */
3356 if (S_ISDIR(attr->la_mode) && spec) {
3357 if (unlikely(spec->sp_cr_flags & MDS_OPEN_HAS_EA)) {
3358 hint->dah_eadata = spec->u.sp_ea.eadata;
3359 hint->dah_eadata_len = spec->u.sp_ea.eadatalen;
3360 if (spec->sp_cr_flags & MDS_OPEN_DEFAULT_LMV)
3361 hint->dah_eadata_is_dmv = 1;
3363 hint->dah_dmv_imp_inherit = spec->sp_dmv_imp_inherit;
3364 } else if (S_ISREG(attr->la_mode) &&
3365 spec->sp_cr_flags & MDS_OPEN_APPEND) {
3366 hint->dah_append_stripe_count = mdd->mdd_append_stripe_count;
3367 hint->dah_append_pool = mdd->mdd_append_pool;
3370 CDEBUG(D_INFO, DFID" eadata %p len %d\n", PFID(mdd_object_fid(child)),
3371 hint->dah_eadata, hint->dah_eadata_len);
3372 /* @hint will be initialized by underlying device. */
3373 nc->do_ops->do_ah_init(env, hint, np, nc, attr->la_mode & S_IFMT);
3376 static int mdd_accmode(const struct lu_env *env, const struct lu_attr *la,
3379 /* Sadly, NFSD reopens a file repeatedly during operation, so the
3380 * "acc_mode = 0" allowance for newly-created files isn't honoured.
3381 * NFSD uses the MDS_OPEN_OWNEROVERRIDE flag to say that a file
3382 * owner can write to a file even if it is marked readonly to hide
3383 * its brokenness. (bug 5781) */
3384 if (open_flags & MDS_OPEN_OWNEROVERRIDE) {
3385 struct lu_ucred *uc = lu_ucred_check(env);
3387 if ((uc == NULL) || (la->la_uid == uc->uc_fsuid))
3391 return mds_accmode(open_flags);
3394 static int mdd_open_sanity_check(const struct lu_env *env,
3395 struct mdd_object *obj,
3396 const struct lu_attr *attr, u64 open_flags,
3399 unsigned int may_mask;
3403 /* EEXIST check, also opening of *open* orphans is allowed so we can
3404 * open-by-handle unlinked files
3406 if (mdd_is_dead_obj(obj) && !is_replay &&
3407 likely(!(mdd_is_orphan_obj(obj) && obj->mod_count > 0)))
3410 if (S_ISLNK(attr->la_mode))
3413 may_mask = mdd_accmode(env, attr, open_flags);
3415 if (S_ISDIR(attr->la_mode) && (may_mask & MAY_WRITE))
3418 if (!(open_flags & MDS_OPEN_CREATED)) {
3419 rc = mdd_permission_internal(env, obj, attr, may_mask);
3424 if (S_ISFIFO(attr->la_mode) || S_ISSOCK(attr->la_mode) ||
3425 S_ISBLK(attr->la_mode) || S_ISCHR(attr->la_mode))
3426 open_flags &= ~MDS_OPEN_TRUNC;
3428 /* For writing append-only file must open it with append mode. */
3429 if (attr->la_flags & LUSTRE_APPEND_FL) {
3430 if ((open_flags & MDS_FMODE_WRITE) &&
3431 !(open_flags & MDS_OPEN_APPEND))
3433 if (open_flags & MDS_OPEN_TRUNC)
3440 static int mdd_open(const struct lu_env *env, struct md_object *obj,
3441 u64 open_flags, struct md_op_spec *spec)
3443 struct mdd_object *mdd_obj = md2mdd_obj(obj);
3444 struct md_device *md_dev = lu2md_dev(mdd2lu_dev(mdo2mdd(obj)));
3445 struct lu_attr *attr = MDD_ENV_VAR(env, cattr);
3446 struct mdd_object_user *mou = NULL;
3447 const struct lu_ucred *uc = lu_ucred(env);
3448 struct mdd_device *mdd = mdo2mdd(obj);
3449 enum changelog_rec_type type = CL_OPEN;
3453 mdd_write_lock(env, mdd_obj, DT_TGT_CHILD);
3455 rc = mdd_la_get(env, mdd_obj, attr);
3459 rc = mdd_open_sanity_check(env, mdd_obj, attr, open_flags,
3461 if ((rc == -EACCES) && (mdd->mdd_cl.mc_current_mask & BIT(CL_DN_OPEN)))
3466 mdd_obj->mod_count++;
3468 if (!mdd_changelog_enabled(env, mdd, type))
3472 /* look for existing opener in list under mdd_write_lock */
3473 mou = mdd_obj_user_find(mdd_obj, uc->uc_uid, uc->uc_gid, open_flags);
3478 /* add user to list */
3479 mou = mdd_obj_user_alloc(open_flags, uc->uc_uid, uc->uc_gid);
3485 rc2 = mdd_obj_user_add(mdd_obj, mou, type == CL_DN_OPEN);
3487 mdd_obj_user_free(mou);
3492 if (type == CL_DN_OPEN) {
3493 if (ktime_before(ktime_get(), mou->mou_deniednext))
3494 /* same user denied again same access within
3495 * time interval: do not record
3499 /* this user already denied, but some time ago:
3500 * update denied time
3502 mou->mou_deniednext =
3503 ktime_add(ktime_get(),
3504 ktime_set(mdd->mdd_cl.mc_deniednext,
3507 mou->mou_opencount++;
3508 /* same user opening file again with same flags:
3515 /* we can't hold object lock over transaction start
3516 * and we don't actually need the object to be locked */
3517 mdd_write_unlock(env, mdd_obj);
3519 /* FYI, only the bottom 32 bits of open_flags are recorded */
3520 /* only the low CLF_FLAGMASK bits of la_valid are stored*/
3521 mdd_changelog(env, type, open_flags & CLF_FLAGMASK, md_dev,
3522 mdd_object_fid(mdd_obj));
3527 mdd_write_unlock(env, mdd_obj);
3532 static int mdd_declare_close(const struct lu_env *env, struct mdd_object *obj,
3533 struct md_attr *ma, struct thandle *handle)
3537 rc = mdd_orphan_declare_delete(env, obj, handle);
3541 return mdo_declare_destroy(env, obj, handle);
3545 * No permission check is needed.
3547 static int mdd_close(const struct lu_env *env, struct md_object *obj,
3548 struct md_attr *ma, u64 open_flags)
3550 struct mdd_object *mdd_obj = md2mdd_obj(obj);
3551 struct mdd_device *mdd = mdo2mdd(obj);
3552 struct thandle *handle = NULL;
3555 bool blocked = false;
3556 bool last_close_by_uid = false;
3557 const struct lu_ucred *uc = lu_ucred(env);
3560 if (ma->ma_valid & MA_FLAGS && ma->ma_attr_flags & MDS_KEEP_ORPHAN) {
3561 mdd_write_lock(env, mdd_obj, DT_TGT_CHILD);
3562 mdd_obj->mod_count--;
3563 mdd_write_unlock(env, mdd_obj);
3565 if (mdd_obj->mod_flags & ORPHAN_OBJ && !mdd_obj->mod_count)
3566 CDEBUG(D_HA, "Object "DFID" is retained in orphan "
3567 "list\n", PFID(mdd_object_fid(mdd_obj)));
3571 /* mdd_finish_unlink() will always set orphan object as DEAD_OBJ, but
3572 * it might fail to add the object to orphan list (w/o ORPHAN_OBJ). */
3573 /* check without any lock */
3574 is_orphan = mdd_obj->mod_count == 1 &&
3575 (mdd_obj->mod_flags & (ORPHAN_OBJ | DEAD_OBJ)) != 0;
3579 /* mdd_trans_create() maybe failed because of barrier_entry(),
3580 * under such case, the orphan MDT-object will be left in the
3581 * orphan list, and when the MDT remount next time, the unused
3582 * orphans will be destroyed automatically.
3584 * One exception: the former mdd_finish_unlink may failed to
3585 * add the orphan MDT-object to the orphan list, then if the
3586 * mdd_trans_create() failed because of barrier_entry(), the
3587 * MDT-object will become real orphan that is neither in the
3588 * namespace nor in the orphan list. Such bad case should be
3589 * very rare and will be handled by e2fsck/lfsck. */
3590 handle = mdd_trans_create(env, mdo2mdd(obj));
3591 if (IS_ERR(handle)) {
3592 rc = PTR_ERR(handle);
3593 if (rc != -EINPROGRESS)
3601 rc = mdd_declare_close(env, mdd_obj, ma, handle);
3605 rc = mdd_declare_changelog_store(env, mdd, CL_CLOSE, NULL, NULL,
3610 rc = mdd_trans_start(env, mdo2mdd(obj), handle);
3616 mdd_write_lock(env, mdd_obj, DT_TGT_CHILD);
3617 rc = mdd_la_get(env, mdd_obj, &ma->ma_attr);
3619 CERROR("%s: failed to get lu_attr of "DFID": rc = %d\n",
3620 lu_dev_name(mdd2lu_dev(mdd)),
3621 PFID(mdd_object_fid(mdd_obj)), rc);
3625 /* check again with lock */
3626 is_orphan = (mdd_obj->mod_count == 1) &&
3627 ((mdd_obj->mod_flags & (ORPHAN_OBJ | DEAD_OBJ)) != 0 ||
3628 ma->ma_attr.la_nlink == 0);
3630 if (is_orphan && !handle && !blocked) {
3631 mdd_write_unlock(env, mdd_obj);
3635 mdd_obj->mod_count--; /*release open count */
3637 /* under mdd write lock */
3638 /* If recording, see if we need to remove UID from list. uc is not
3639 * initialized if the client has been evicted. */
3640 if (mdd_changelog_enabled(env, mdd, CL_OPEN) && uc) {
3641 struct mdd_object_user *mou;
3643 /* look for UID in list */
3644 /* If mou is NULL, it probably means logging was enabled after
3645 * the user had the file open. So the corresponding close
3646 * will not be logged.
3648 mou = mdd_obj_user_find(mdd_obj, uc->uc_uid, uc->uc_gid,
3651 mou->mou_opencount--;
3652 if (mou->mou_opencount == 0) {
3653 mdd_obj_user_remove(mdd_obj, mou);
3654 last_close_by_uid = true;
3659 if (!is_orphan || blocked)
3663 /* NB: Object maybe not in orphan list originally, it is rare case for
3664 * mdd_finish_unlink() failure, in that case, the object doesn't have
3665 * ORPHAN_OBJ flag */
3666 if ((mdd_obj->mod_flags & ORPHAN_OBJ) != 0) {
3667 /* remove link to object from orphan index */
3668 LASSERT(handle != NULL);
3669 rc = mdd_orphan_delete(env, mdd_obj, handle);
3671 CERROR("%s: unable to delete "DFID" from orphan list: "
3672 "rc = %d\n", lu_dev_name(mdd2lu_dev(mdd)),
3673 PFID(mdd_object_fid(mdd_obj)), rc);
3674 /* If object was not deleted from orphan list, do not
3675 * destroy OSS objects, which will be done when next
3680 CDEBUG(D_HA, "Object "DFID" is deleted from orphan "
3681 "list, OSS objects to be destroyed.\n",
3682 PFID(mdd_object_fid(mdd_obj)));
3685 rc = mdo_destroy(env, mdd_obj, handle);
3688 CERROR("%s: unable to delete "DFID" from orphan list: "
3689 "rc = %d\n", lu_dev_name(mdd2lu_dev(mdd)),
3690 PFID(mdd_object_fid(mdd_obj)), rc);
3695 mdd_write_unlock(env, mdd_obj);
3697 if (rc != 0 || blocked ||
3698 !mdd_changelog_enabled(env, mdd, CL_CLOSE))
3701 /* Record CL_CLOSE in changelog only if file was opened in write mode,
3702 * or if CL_OPEN was recorded and it's last close by user.
3703 * Changelogs mask may change between open and close operations, but
3704 * this is not a big deal if we have a CL_CLOSE entry with no matching
3705 * CL_OPEN. Plus Changelogs mask may not change often.
3707 if (((!(mdd->mdd_cl.mc_current_mask & BIT(CL_OPEN)) &&
3708 (open_flags & (MDS_FMODE_WRITE | MDS_OPEN_APPEND |
3709 MDS_OPEN_TRUNC))) ||
3710 ((mdd->mdd_cl.mc_current_mask & BIT(CL_OPEN)) &&
3711 last_close_by_uid)) &&
3712 !(ma->ma_valid & MA_FLAGS && ma->ma_attr_flags & MDS_RECOV_OPEN)) {
3713 if (handle == NULL) {
3714 handle = mdd_trans_create(env, mdo2mdd(obj));
3716 GOTO(stop, rc = PTR_ERR(handle));
3718 rc = mdd_declare_changelog_store(env, mdd, CL_CLOSE,
3719 NULL, NULL, handle);
3723 rc = mdd_trans_start(env, mdo2mdd(obj), handle);
3728 /* FYI, only the bottom 32 bits of open_flags are recorded */
3729 mdd_changelog_data_store(env, mdd, CL_CLOSE, open_flags,
3730 mdd_obj, handle, NULL);
3734 if (handle != NULL && !IS_ERR(handle))
3735 rc = mdd_trans_stop(env, mdd, rc, handle);
3741 * Permission check is done when open,
3742 * no need check again.
3744 static int mdd_readpage_sanity_check(const struct lu_env *env,
3745 struct mdd_object *obj)
3747 if (!dt_try_as_dir(env, mdd_object_child(obj), true))
3753 static int mdd_dir_page_build(const struct lu_env *env, struct dt_object *obj,
3754 union lu_page *lp, size_t bytes,
3755 const struct dt_it_ops *iops,
3756 struct dt_it *it, __u32 attr, void *arg)
3758 struct lu_dirpage *dp = &lp->lp_dir;
3761 struct lu_dirent *ent;
3762 struct lu_dirent *last = NULL;
3767 if (bytes < sizeof(*dp))
3768 GOTO(out_err, result = -EOVERFLOW);
3770 memset(area, 0, sizeof(*dp));
3771 area += sizeof(*dp);
3772 bytes -= sizeof(*dp);
3779 len = iops->key_size(env, it);
3781 /* IAM iterator can return record with zero len. */
3785 hash = iops->store(env, it);
3786 if (unlikely(first)) {
3788 dp->ldp_hash_start = cpu_to_le64(hash);
3791 /* calculate max space required for lu_dirent */
3792 recsize = lu_dirent_calc_size(len, attr);
3794 if (bytes >= recsize &&
3795 !CFS_FAIL_CHECK(OBD_FAIL_MDS_DIR_PAGE_WALK)) {
3796 result = iops->rec(env, it, (struct dt_rec *)ent, attr);
3797 if (result == -ESTALE)
3802 /* OSD might not able to pack all attributes, so
3803 * recheck record length had room to store FID
3805 recsize = le16_to_cpu(ent->lde_reclen);
3807 if (le32_to_cpu(ent->lde_attrs) & LUDA_FID) {
3808 fid_le_to_cpu(&fid, &ent->lde_fid);
3809 if (fid_is_dot_lustre(&fid))
3810 GOTO(next, recsize);
3813 result = (last != NULL) ? 0 : -EBADSLT;
3817 ent = (void *)ent + recsize;
3821 result = iops->next(env, it);
3822 if (result == -ESTALE)
3824 } while (result == 0);
3827 dp->ldp_hash_end = cpu_to_le64(hash);
3829 if (last->lde_hash == dp->ldp_hash_end)
3830 dp->ldp_flags |= cpu_to_le32(LDF_COLLIDE);
3831 last->lde_reclen = 0; /* end mark */
3835 /* end of directory */
3836 dp->ldp_hash_end = cpu_to_le64(MDS_DIR_END_OFF);
3837 else if (result < 0)
3838 CWARN("%s: build page failed for "DFID": rc = %d\n",
3839 lu_dev_name(obj->do_lu.lo_dev),
3840 PFID(lu_object_fid(&obj->do_lu)), result);
3845 int mdd_readpage(const struct lu_env *env, struct md_object *obj,
3846 const struct lu_rdpg *rdpg)
3848 struct mdd_object *mdd_obj = md2mdd_obj(obj);
3852 if (mdd_object_exists(mdd_obj) == 0) {
3853 CERROR("%s: object "DFID" not found: rc = -2\n",
3854 mdd_obj_dev_name(mdd_obj),PFID(mdd_object_fid(mdd_obj)));
3858 mdd_read_lock(env, mdd_obj, DT_TGT_CHILD);
3859 rc = mdd_readpage_sanity_check(env, mdd_obj);
3861 GOTO(out_unlock, rc);
3863 if (mdd_is_dead_obj(mdd_obj)) {
3865 struct lu_dirpage *dp;
3868 * According to POSIX, please do not return any entry to client:
3869 * even dot and dotdot should not be returned.
3871 CDEBUG(D_INODE, "readdir from dead object: "DFID"\n",
3872 PFID(mdd_object_fid(mdd_obj)));
3874 if (rdpg->rp_count <= 0)
3875 GOTO(out_unlock, rc = -EFAULT);
3876 LASSERT(rdpg->rp_pages != NULL);
3878 pg = rdpg->rp_pages[0];
3879 dp = (struct lu_dirpage *)kmap(pg);
3880 memset(dp, 0 , sizeof(struct lu_dirpage));
3881 dp->ldp_hash_start = cpu_to_le64(rdpg->rp_hash);
3882 dp->ldp_hash_end = cpu_to_le64(MDS_DIR_END_OFF);
3883 dp->ldp_flags = cpu_to_le32(LDF_EMPTY);
3885 GOTO(out_unlock, rc = LU_PAGE_SIZE);
3888 rc = dt_index_walk(env, mdd_object_child(mdd_obj), rdpg,
3889 mdd_dir_page_build, NULL);
3891 struct lu_dirpage *dp;
3893 dp = kmap(rdpg->rp_pages[0]);
3894 dp->ldp_hash_start = cpu_to_le64(rdpg->rp_hash);
3897 * No pages were processed, mark this for first page
3900 dp->ldp_hash_end = cpu_to_le64(MDS_DIR_END_OFF);
3901 dp->ldp_flags = cpu_to_le32(LDF_EMPTY);
3902 rc = min_t(unsigned int, LU_PAGE_SIZE, rdpg->rp_count);
3904 kunmap(rdpg->rp_pages[0]);
3907 GOTO(out_unlock, rc);
3909 mdd_read_unlock(env, mdd_obj);
3913 static int mdd_object_sync(const struct lu_env *env, struct md_object *obj)
3915 struct mdd_object *mdd_obj = md2mdd_obj(obj);
3917 if (mdd_object_exists(mdd_obj) == 0) {
3920 CERROR("%s: object "DFID" not found: rc = %d\n",
3921 mdd_obj_dev_name(mdd_obj),
3922 PFID(mdd_object_fid(mdd_obj)), rc);
3925 return dt_object_sync(env, mdd_object_child(mdd_obj),
3929 static int mdd_object_lock(const struct lu_env *env,
3930 struct md_object *obj,
3931 struct lustre_handle *lh,
3932 struct ldlm_enqueue_info *einfo,
3933 union ldlm_policy_data *policy)
3935 struct mdd_object *mdd_obj = md2mdd_obj(obj);
3936 return dt_object_lock(env, mdd_object_child(mdd_obj), lh,
3940 static int mdd_object_unlock(const struct lu_env *env,
3941 struct md_object *obj,
3942 struct ldlm_enqueue_info *einfo,
3943 union ldlm_policy_data *policy)
3945 struct mdd_object *mdd_obj = md2mdd_obj(obj);
3946 return dt_object_unlock(env, mdd_object_child(mdd_obj), einfo, policy);
3949 const struct md_object_operations mdd_obj_ops = {
3950 .moo_permission = mdd_permission,
3951 .moo_attr_get = mdd_attr_get,
3952 .moo_attr_set = mdd_attr_set,
3953 .moo_xattr_get = mdd_xattr_get,
3954 .moo_xattr_set = mdd_xattr_set,
3955 .moo_xattr_list = mdd_xattr_list,
3956 .moo_invalidate = mdd_invalidate,
3957 .moo_xattr_del = mdd_xattr_del,
3958 .moo_swap_layouts = mdd_swap_layouts,
3959 .moo_open = mdd_open,
3960 .moo_close = mdd_close,
3961 .moo_readpage = mdd_readpage,
3962 .moo_readlink = mdd_readlink,
3963 .moo_changelog = mdd_changelog,
3964 .moo_object_sync = mdd_object_sync,
3965 .moo_object_lock = mdd_object_lock,
3966 .moo_object_unlock = mdd_object_unlock,
3967 .moo_layout_change = mdd_layout_change,