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/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lustre/mdd/mdd_dir.c
34 * Lustre Metadata Server (mdd) routines
36 * Author: Wang Di <wangdi@intel.com>
39 #define DEBUG_SUBSYSTEM S_MDS
41 #include <obd_class.h>
42 #include <obd_support.h>
43 #include <lustre_mds.h>
44 #include <lustre_fid.h>
45 #include <lustre_lmv.h>
47 #include "mdd_internal.h"
49 static const char dot[] = ".";
50 static const char dotdot[] = "..";
52 static struct lu_name lname_dotdot = {
53 .ln_name = (char *) dotdot,
54 .ln_namelen = sizeof(dotdot) - 1,
58 mdd_name_check(struct mdd_device *m, const struct lu_name *ln)
60 if (!lu_name_is_valid(ln))
62 else if (ln->ln_namelen > m->mdd_dt_conf.ddp_max_name_len)
68 /* Get FID from name and parent */
70 __mdd_lookup(const struct lu_env *env, struct md_object *pobj,
71 const struct lu_attr *pattr, const struct lu_name *lname,
72 struct lu_fid* fid, int mask)
74 const char *name = lname->ln_name;
75 const struct dt_key *key = (const struct dt_key *)name;
76 struct mdd_object *mdd_obj = md2mdd_obj(pobj);
77 struct mdd_device *m = mdo2mdd(pobj);
78 struct dt_object *dir = mdd_object_child(mdd_obj);
82 if (unlikely(mdd_is_dead_obj(mdd_obj)))
85 if (!mdd_object_exists(mdd_obj))
88 if (mdd_object_remote(mdd_obj)) {
89 CDEBUG(D_INFO, "%s: Object "DFID" locates on remote server\n",
90 mdd2obd_dev(m)->obd_name, PFID(mdo2fid(mdd_obj)));
93 rc = mdd_permission_internal_locked(env, mdd_obj, pattr, mask,
98 if (likely(S_ISDIR(mdd_object_type(mdd_obj)) &&
99 dt_try_as_dir(env, dir)))
100 rc = dt_lookup(env, dir, (struct dt_rec *)fid, key);
107 int mdd_lookup(const struct lu_env *env,
108 struct md_object *pobj, const struct lu_name *lname,
109 struct lu_fid *fid, struct md_op_spec *spec)
111 struct lu_attr *pattr = MDD_ENV_VAR(env, pattr);
115 rc = mdd_la_get(env, md2mdd_obj(pobj), pattr);
119 rc = __mdd_lookup(env, pobj, pattr, lname, fid,
120 (spec != NULL && spec->sp_permitted) ? 0 : MAY_EXEC);
124 /** Read the link EA into a temp buffer.
125 * Uses the mdd_thread_info::mti_big_buf since it is generally large.
126 * A pointer to the buffer is stored in \a ldata::ld_buf.
130 static int __mdd_links_read(const struct lu_env *env,
131 struct mdd_object *mdd_obj,
132 struct linkea_data *ldata)
136 if (!mdd_object_exists(mdd_obj))
139 /* First try a small buf */
140 LASSERT(env != NULL);
141 ldata->ld_buf = lu_buf_check_and_alloc(&mdd_env_info(env)->mti_link_buf,
143 if (ldata->ld_buf->lb_buf == NULL)
146 rc = mdo_xattr_get(env, mdd_obj, ldata->ld_buf, XATTR_NAME_LINK);
148 /* Buf was too small, figure out what we need. */
149 lu_buf_free(ldata->ld_buf);
150 rc = mdo_xattr_get(env, mdd_obj, ldata->ld_buf,
154 ldata->ld_buf = lu_buf_check_and_alloc(ldata->ld_buf, rc);
155 if (ldata->ld_buf->lb_buf == NULL)
157 rc = mdo_xattr_get(env, mdd_obj, ldata->ld_buf,
161 lu_buf_free(ldata->ld_buf);
162 ldata->ld_buf = NULL;
166 return linkea_init(ldata);
169 static int mdd_links_read(const struct lu_env *env,
170 struct mdd_object *mdd_obj,
171 struct linkea_data *ldata)
175 rc = __mdd_links_read(env, mdd_obj, ldata);
177 rc = linkea_init(ldata);
182 static int mdd_links_read_with_rec(const struct lu_env *env,
183 struct mdd_object *mdd_obj,
184 struct linkea_data *ldata)
188 rc = __mdd_links_read(env, mdd_obj, ldata);
190 rc = linkea_init_with_rec(ldata);
196 * Get parent FID of the directory
198 * Read parent FID from linkEA, if that fails, then do lookup
199 * dotdot to get the parent FID.
201 * \param[in] env execution environment
202 * \param[in] obj object from which to find the parent FID
203 * \param[in] attr attribute of the object
204 * \param[out] fid fid to get the parent FID
206 * \retval 0 if getting the parent FID succeeds.
207 * \retval negative errno if getting the parent FID fails.
209 static inline int mdd_parent_fid(const struct lu_env *env,
210 struct mdd_object *obj,
211 const struct lu_attr *attr,
214 struct mdd_thread_info *info = mdd_env_info(env);
215 struct linkea_data ldata = { NULL };
216 struct lu_buf *buf = &info->mti_link_buf;
217 struct lu_name lname;
222 LASSERTF(S_ISDIR(mdd_object_type(obj)),
223 "%s: FID "DFID" is not a directory type = %o\n",
224 mdd_obj_dev_name(obj), PFID(mdd_object_fid(obj)),
225 mdd_object_type(obj));
227 buf = lu_buf_check_and_alloc(buf, PATH_MAX);
228 if (buf->lb_buf == NULL)
229 GOTO(lookup, rc = 0);
232 rc = mdd_links_read_with_rec(env, obj, &ldata);
236 LASSERT(ldata.ld_leh != NULL);
237 /* Directory should only have 1 parent */
238 if (ldata.ld_leh->leh_reccount > 1)
241 ldata.ld_lee = (struct link_ea_entry *)(ldata.ld_leh + 1);
243 linkea_entry_unpack(ldata.ld_lee, &ldata.ld_reclen, &lname, fid);
244 if (likely(fid_is_sane(fid)))
247 rc = __mdd_lookup(env, &obj->mod_obj, attr, &lname_dotdot, fid, 0);
252 * For root fid use special function, which does not compare version component
253 * of fid. Version component is different for root fids on all MDTs.
255 int mdd_is_root(struct mdd_device *mdd, const struct lu_fid *fid)
257 return fid_seq(&mdd->mdd_root_fid) == fid_seq(fid) &&
258 fid_oid(&mdd->mdd_root_fid) == fid_oid(fid);
262 * return 1: if \a tfid is the fid of the ancestor of \a mo;
264 * otherwise: values < 0, errors.
266 static int mdd_is_parent(const struct lu_env *env,
267 struct mdd_device *mdd,
268 struct mdd_object *mo,
269 const struct lu_attr *attr,
270 const struct lu_fid *tfid)
272 struct mdd_object *mp;
276 LASSERT(!lu_fid_eq(mdo2fid(mo), tfid));
277 pfid = &mdd_env_info(env)->mti_fid;
279 if (mdd_is_root(mdd, mdo2fid(mo)))
282 if (mdd_is_root(mdd, tfid))
285 rc = mdd_parent_fid(env, mo, attr, pfid);
290 if (lu_fid_eq(pfid, tfid))
293 if (mdd_is_root(mdd, pfid))
296 mp = mdd_object_find(env, mdd, pfid);
300 if (!mdd_object_exists(mp)) {
301 mdd_object_put(env, mp);
305 rc = mdd_parent_fid(env, mp, attr, pfid);
306 mdd_object_put(env, mp);
315 * No permission check is needed.
317 * returns 1: if fid is ancestor of @mo;
318 * returns 0: if fid is not an ancestor of @mo;
319 * returns < 0: if error
321 int mdd_is_subdir(const struct lu_env *env, struct md_object *mo,
322 const struct lu_fid *fid)
324 struct mdd_device *mdd = mdo2mdd(mo);
325 struct lu_attr *attr = MDD_ENV_VAR(env, cattr);
329 if (!mdd_object_exists(md2mdd_obj(mo)))
332 if (!S_ISDIR(mdd_object_type(md2mdd_obj(mo))))
335 rc = mdd_la_get(env, md2mdd_obj(mo), attr);
339 rc = mdd_is_parent(env, mdd, md2mdd_obj(mo), attr, fid);
344 * Check that @dir contains no entries except (possibly) dot and dotdot.
349 * -ENOTDIR not a directory object
350 * -ENOTEMPTY not empty
354 static int mdd_dir_is_empty(const struct lu_env *env,
355 struct mdd_object *dir)
358 struct dt_object *obj;
359 const struct dt_it_ops *iops;
363 obj = mdd_object_child(dir);
364 if (!dt_try_as_dir(env, obj))
367 iops = &obj->do_index_ops->dio_it;
368 it = iops->init(env, obj, LUDA_64BITHASH);
370 result = iops->get(env, it, (const struct dt_key *)"");
373 for (result = 0, i = 0; result == 0 && i < 3; ++i)
374 result = iops->next(env, it);
377 else if (result == 1)
379 } else if (result == 0)
381 * Huh? Index contains no zero key?
388 result = PTR_ERR(it);
393 * Determine if the target object can be hard linked, and right now it only
394 * checks if the link count reach the maximum limit. Note: for ldiskfs, the
395 * directory nlink count might exceed the maximum link count(see
396 * osd_object_ref_add), so it only check nlink for non-directories.
398 * \param[in] env thread environment
399 * \param[in] obj object being linked to
400 * \param[in] la attributes of \a obj
402 * \retval 0 if \a obj can be hard linked
403 * \retval negative error if \a obj is a directory or has too
406 static int __mdd_may_link(const struct lu_env *env, struct mdd_object *obj,
407 const struct lu_attr *la)
409 struct mdd_device *m = mdd_obj2mdd_dev(obj);
414 /* Subdir count limitation can be broken through
415 * (see osd_object_ref_add), so only check non-directory here. */
416 if (!S_ISDIR(la->la_mode) &&
417 la->la_nlink >= m->mdd_dt_conf.ddp_max_nlink)
424 * Check whether it may create the cobj under the pobj.
426 * \param[in] env execution environment
427 * \param[in] pobj the parent directory
428 * \param[in] pattr the attribute of the parent directory
429 * \param[in] cobj the child to be created
430 * \param[in] check_perm if check WRITE|EXEC permission for parent
432 * \retval = 0 create the child under this dir is allowed
433 * \retval negative errno create the child under this dir is
436 int mdd_may_create(const struct lu_env *env, struct mdd_object *pobj,
437 const struct lu_attr *pattr, struct mdd_object *cobj,
443 if (cobj && mdd_object_exists(cobj))
446 if (mdd_is_dead_obj(pobj))
450 rc = mdd_permission_internal_locked(env, pobj, pattr,
451 MAY_WRITE | MAY_EXEC,
457 * Check whether can unlink from the pobj in the case of "cobj == NULL".
459 int mdd_may_unlink(const struct lu_env *env, struct mdd_object *pobj,
460 const struct lu_attr *pattr, const struct lu_attr *attr)
465 if (mdd_is_dead_obj(pobj))
468 if (attr->la_flags & (LUSTRE_APPEND_FL | LUSTRE_IMMUTABLE_FL))
471 rc = mdd_permission_internal_locked(env, pobj, pattr,
472 MAY_WRITE | MAY_EXEC,
477 if (pattr->la_flags & LUSTRE_APPEND_FL)
484 * pobj == NULL is remote ops case, under such case, pobj's
485 * VTX feature has been checked already, no need check again.
487 static inline int mdd_is_sticky(const struct lu_env *env,
488 struct mdd_object *pobj,
489 const struct lu_attr *pattr,
490 struct mdd_object *cobj,
491 const struct lu_attr *cattr)
493 struct lu_ucred *uc = lu_ucred_assert(env);
496 LASSERT(pattr != NULL);
497 if (!(pattr->la_mode & S_ISVTX) ||
498 (pattr->la_uid == uc->uc_fsuid))
502 LASSERT(cattr != NULL);
503 if (cattr->la_uid == uc->uc_fsuid)
506 return !md_capable(uc, CFS_CAP_FOWNER);
509 static int mdd_may_delete_entry(const struct lu_env *env,
510 struct mdd_object *pobj,
511 const struct lu_attr *pattr,
516 LASSERT(pobj != NULL);
517 if (!mdd_object_exists(pobj))
520 if (mdd_is_dead_obj(pobj))
525 rc = mdd_permission_internal_locked(env, pobj, pattr,
526 MAY_WRITE | MAY_EXEC,
532 if (pattr->la_flags & LUSTRE_APPEND_FL)
539 * Check whether it may delete the cobj from the pobj.
542 int mdd_may_delete(const struct lu_env *env, struct mdd_object *tpobj,
543 const struct lu_attr *tpattr, struct mdd_object *tobj,
544 const struct lu_attr *tattr, const struct lu_attr *cattr,
545 int check_perm, int check_empty)
551 LASSERT(tpattr != NULL);
552 rc = mdd_may_delete_entry(env, tpobj, tpattr, check_perm);
560 if (!mdd_object_exists(tobj))
563 if (mdd_is_dead_obj(tobj))
566 if (mdd_is_sticky(env, tpobj, tpattr, tobj, tattr))
569 if (tattr->la_flags & (LUSTRE_APPEND_FL | LUSTRE_IMMUTABLE_FL))
572 /* additional check the rename case */
574 if (S_ISDIR(cattr->la_mode)) {
575 struct mdd_device *mdd = mdo2mdd(&tobj->mod_obj);
577 if (!S_ISDIR(tattr->la_mode))
580 if (lu_fid_eq(mdo2fid(tobj), &mdd->mdd_root_fid))
582 } else if (S_ISDIR(tattr->la_mode))
586 if (S_ISDIR(tattr->la_mode) && check_empty)
587 rc = mdd_dir_is_empty(env, tobj);
593 * Check whether it can create the link file(linked to @src_obj) under
594 * the target directory(@tgt_obj), and src_obj has been locked by
597 * \param[in] env execution environment
598 * \param[in] tgt_obj the target directory
599 * \param[in] tattr attributes of target directory
600 * \param[in] lname the link name
601 * \param[in] src_obj source object for link
602 * \param[in] cattr attributes for source object
604 * \retval = 0 it is allowed to create the link file under tgt_obj
605 * \retval negative error not allowed to create the link file
607 static int mdd_link_sanity_check(const struct lu_env *env,
608 struct mdd_object *tgt_obj,
609 const struct lu_attr *tattr,
610 const struct lu_name *lname,
611 struct mdd_object *src_obj,
612 const struct lu_attr *cattr)
614 struct mdd_device *m = mdd_obj2mdd_dev(src_obj);
618 if (!mdd_object_exists(src_obj))
621 if (mdd_is_dead_obj(src_obj))
624 /* Local ops, no lookup before link, check filename length here. */
625 rc = mdd_name_check(m, lname);
629 if (cattr->la_flags & (LUSTRE_IMMUTABLE_FL | LUSTRE_APPEND_FL))
632 if (S_ISDIR(mdd_object_type(src_obj)))
635 LASSERT(src_obj != tgt_obj);
636 rc = mdd_may_create(env, tgt_obj, tattr, NULL, true);
640 rc = __mdd_may_link(env, src_obj, cattr);
645 static int __mdd_index_delete_only(const struct lu_env *env, struct mdd_object *pobj,
646 const char *name, struct thandle *handle)
648 struct dt_object *next = mdd_object_child(pobj);
652 if (dt_try_as_dir(env, next))
653 rc = dt_delete(env, next, (struct dt_key *)name, handle);
660 static int __mdd_index_insert_only(const struct lu_env *env,
661 struct mdd_object *pobj,
662 const struct lu_fid *lf, __u32 type,
664 struct thandle *handle)
666 struct dt_object *next = mdd_object_child(pobj);
670 if (dt_try_as_dir(env, next)) {
671 struct dt_insert_rec *rec = &mdd_env_info(env)->mti_dt_rec;
674 rec->rec_type = type;
675 rc = dt_insert(env, next, (const struct dt_rec *)rec,
676 (const struct dt_key *)name, handle);
683 /* insert named index, add reference if isdir */
684 static int __mdd_index_insert(const struct lu_env *env, struct mdd_object *pobj,
685 const struct lu_fid *lf, __u32 type,
686 const char *name, struct thandle *handle)
691 rc = __mdd_index_insert_only(env, pobj, lf, type, name, handle);
692 if (rc == 0 && S_ISDIR(type)) {
693 mdd_write_lock(env, pobj, MOR_TGT_PARENT);
694 mdo_ref_add(env, pobj, handle);
695 mdd_write_unlock(env, pobj);
701 /* delete named index, drop reference if isdir */
702 static int __mdd_index_delete(const struct lu_env *env, struct mdd_object *pobj,
703 const char *name, int is_dir,
704 struct thandle *handle)
709 rc = __mdd_index_delete_only(env, pobj, name, handle);
710 if (rc == 0 && is_dir) {
711 mdd_write_lock(env, pobj, MOR_TGT_PARENT);
712 mdo_ref_del(env, pobj, handle);
713 mdd_write_unlock(env, pobj);
719 static int mdd_llog_record_calc_size(const struct lu_env *env,
720 const struct lu_name *tname,
721 const struct lu_name *sname)
723 const struct lu_ucred *uc = lu_ucred(env);
724 enum changelog_rec_flags clf_flags = CLF_EXTRA_FLAGS;
725 enum changelog_rec_extra_flags crfe = CLFE_UIDGID | CLFE_NID;
728 clf_flags |= CLF_RENAME;
730 if (uc != NULL && uc->uc_jobid[0] != '\0')
731 clf_flags |= CLF_JOBID;
733 return llog_data_len(LLOG_CHANGELOG_HDR_SZ +
734 changelog_rec_offset(clf_flags, crfe) +
735 (tname != NULL ? tname->ln_namelen : 0) +
736 (sname != NULL ? 1 + sname->ln_namelen : 0));
739 int mdd_declare_changelog_store(const struct lu_env *env,
740 struct mdd_device *mdd,
741 enum changelog_rec_type type,
742 const struct lu_name *tname,
743 const struct lu_name *sname,
744 struct thandle *handle)
746 struct obd_device *obd = mdd2obd_dev(mdd);
747 struct llog_ctxt *ctxt;
748 struct llog_changelog_rec *rec;
750 struct thandle *llog_th;
754 if (!mdd_changelog_enabled(env, mdd, type))
757 reclen = mdd_llog_record_calc_size(env, tname, sname);
758 buf = lu_buf_check_and_alloc(&mdd_env_info(env)->mti_big_buf, reclen);
759 if (buf->lb_buf == NULL)
763 rec->cr_hdr.lrh_len = reclen;
764 rec->cr_hdr.lrh_type = CHANGELOG_REC;
766 ctxt = llog_get_context(obd, LLOG_CHANGELOG_ORIG_CTXT);
770 llog_th = thandle_get_sub(env, handle, ctxt->loc_handle->lgh_obj);
772 GOTO(out_put, rc = PTR_ERR(llog_th));
774 rc = llog_declare_add(env, ctxt->loc_handle, &rec->cr_hdr, llog_th);
782 /** Add a changelog entry \a rec to the changelog llog
785 * \param handle - currently ignored since llogs start their own transaction;
786 * this will hopefully be fixed in llog rewrite
789 int mdd_changelog_store(const struct lu_env *env, struct mdd_device *mdd,
790 struct llog_changelog_rec *rec, struct thandle *th)
792 struct obd_device *obd = mdd2obd_dev(mdd);
793 struct llog_ctxt *ctxt;
794 struct thandle *llog_th;
797 rec->cr_hdr.lrh_len = llog_data_len(sizeof(*rec) +
798 changelog_rec_varsize(&rec->cr));
800 /* llog_lvfs_write_rec sets the llog tail len */
801 rec->cr_hdr.lrh_type = CHANGELOG_REC;
802 rec->cr.cr_time = cl_time();
804 spin_lock(&mdd->mdd_cl.mc_lock);
805 /* NB: I suppose it's possible llog_add adds out of order wrt cr_index,
806 * but as long as the MDD transactions are ordered correctly for e.g.
807 * rename conflicts, I don't think this should matter. */
808 rec->cr.cr_index = ++mdd->mdd_cl.mc_index;
809 spin_unlock(&mdd->mdd_cl.mc_lock);
811 ctxt = llog_get_context(obd, LLOG_CHANGELOG_ORIG_CTXT);
815 llog_th = thandle_get_sub(env, th, ctxt->loc_handle->lgh_obj);
817 GOTO(out_put, rc = PTR_ERR(llog_th));
819 /* nested journal transaction */
820 rc = llog_add(env, ctxt->loc_handle, &rec->cr_hdr, NULL, llog_th);
822 /* time to recover some space ?? */
823 if (likely(!mdd->mdd_changelog_gc ||
824 mdd->mdd_cl.mc_gc_task != MDD_CHLG_GC_NONE ||
825 mdd->mdd_changelog_min_gc_interval >=
826 ktime_get_real_seconds() - mdd->mdd_cl.mc_gc_time))
827 /* save a spin_lock trip */
829 spin_lock(&mdd->mdd_cl.mc_lock);
830 if (likely(mdd->mdd_changelog_gc &&
831 mdd->mdd_cl.mc_gc_task == MDD_CHLG_GC_NONE &&
832 ktime_get_real_seconds() - mdd->mdd_cl.mc_gc_time >
833 mdd->mdd_changelog_min_gc_interval)) {
834 if (unlikely(llog_cat_free_space(ctxt->loc_handle) <=
835 mdd->mdd_changelog_min_free_cat_entries ||
836 OBD_FAIL_CHECK(OBD_FAIL_FORCE_GC_THREAD))) {
837 CWARN("%s:%s low on changelog_catalog free entries, "
838 "starting ChangeLog garbage collection thread\n",
840 OBD_FAIL_CHECK(OBD_FAIL_FORCE_GC_THREAD) ?
843 /* indicate further kthread run will occur outside
844 * right after current journal transaction filling has
847 mdd->mdd_cl.mc_gc_task = MDD_CHLG_GC_NEED;
849 /* next check in mdd_changelog_min_gc_interval anyway
851 mdd->mdd_cl.mc_gc_time = ktime_get_real_seconds();
853 spin_unlock(&mdd->mdd_cl.mc_lock);
861 static void mdd_changelog_rec_ext_rename(struct changelog_rec *rec,
862 const struct lu_fid *sfid,
863 const struct lu_fid *spfid,
864 const struct lu_name *sname)
866 struct changelog_ext_rename *rnm = changelog_rec_rename(rec);
869 LASSERT(sfid != NULL);
870 LASSERT(spfid != NULL);
871 LASSERT(sname != NULL);
873 extsize = sname->ln_namelen + 1;
875 rnm->cr_sfid = *sfid;
876 rnm->cr_spfid = *spfid;
878 changelog_rec_name(rec)[rec->cr_namelen] = '\0';
879 strlcpy(changelog_rec_sname(rec), sname->ln_name, extsize);
880 rec->cr_namelen += extsize;
883 void mdd_changelog_rec_ext_jobid(struct changelog_rec *rec, const char *jobid)
885 struct changelog_ext_jobid *jid = changelog_rec_jobid(rec);
887 if (jobid == NULL || jobid[0] == '\0')
890 strlcpy(jid->cr_jobid, jobid, sizeof(jid->cr_jobid));
893 void mdd_changelog_rec_ext_extra_flags(struct changelog_rec *rec, __u64 eflags)
895 struct changelog_ext_extra_flags *ef = changelog_rec_extra_flags(rec);
897 ef->cr_extra_flags = eflags;
900 void mdd_changelog_rec_extra_uidgid(struct changelog_rec *rec,
901 __u64 uid, __u64 gid)
903 struct changelog_ext_uidgid *uidgid = changelog_rec_uidgid(rec);
905 uidgid->cr_uid = uid;
906 uidgid->cr_gid = gid;
909 void mdd_changelog_rec_extra_nid(struct changelog_rec *rec,
912 struct changelog_ext_nid *clnid = changelog_rec_nid(rec);
917 void mdd_changelog_rec_extra_omode(struct changelog_rec *rec, u32 flags)
919 struct changelog_ext_openmode *omd = changelog_rec_openmode(rec);
921 omd->cr_openflags = flags;
924 void mdd_changelog_rec_extra_xattr(struct changelog_rec *rec,
925 const char *xattr_name)
927 struct changelog_ext_xattr *xattr = changelog_rec_xattr(rec);
929 strlcpy(xattr->cr_xattr, xattr_name, sizeof(xattr->cr_xattr));
932 /** Store a namespace change changelog record
933 * If this fails, we must fail the whole transaction; we don't
934 * want the change to commit without the log entry.
935 * \param target - mdd_object of change
936 * \param tpfid - target parent dir/object fid
937 * \param sfid - source object fid
938 * \param spfid - source parent fid
939 * \param tname - target name string
940 * \param sname - source name string
941 * \param handle - transaction handle
943 int mdd_changelog_ns_store(const struct lu_env *env,
944 struct mdd_device *mdd,
945 enum changelog_rec_type type,
946 enum changelog_rec_flags clf_flags,
947 struct mdd_object *target,
948 const struct lu_fid *tpfid,
949 const struct lu_fid *sfid,
950 const struct lu_fid *spfid,
951 const struct lu_name *tname,
952 const struct lu_name *sname,
953 struct thandle *handle)
955 const struct lu_ucred *uc = lu_ucred(env);
956 struct llog_changelog_rec *rec;
959 __u64 xflags = CLFE_INVALID;
963 if (!mdd_changelog_enabled(env, mdd, type))
966 LASSERT(tpfid != NULL);
967 LASSERT(tname != NULL);
968 LASSERT(handle != NULL);
970 reclen = mdd_llog_record_calc_size(env, tname, sname);
971 buf = lu_buf_check_and_alloc(&mdd_env_info(env)->mti_big_buf, reclen);
972 if (buf->lb_buf == NULL)
976 clf_flags &= CLF_FLAGMASK;
977 clf_flags |= CLF_EXTRA_FLAGS;
980 if (uc->uc_jobid[0] != '\0')
981 clf_flags |= CLF_JOBID;
982 xflags |= CLFE_UIDGID;
987 clf_flags |= CLF_RENAME;
989 clf_flags |= CLF_VERSION;
991 rec->cr.cr_flags = clf_flags;
993 if (clf_flags & CLF_EXTRA_FLAGS) {
994 mdd_changelog_rec_ext_extra_flags(&rec->cr, xflags);
995 if (xflags & CLFE_UIDGID)
996 mdd_changelog_rec_extra_uidgid(&rec->cr,
997 uc->uc_uid, uc->uc_gid);
998 if (xflags & CLFE_NID)
999 mdd_changelog_rec_extra_nid(&rec->cr, uc->uc_nid);
1002 rec->cr.cr_type = (__u32)type;
1003 rec->cr.cr_pfid = *tpfid;
1004 rec->cr.cr_namelen = tname->ln_namelen;
1005 memcpy(changelog_rec_name(&rec->cr), tname->ln_name, tname->ln_namelen);
1007 if (clf_flags & CLF_RENAME)
1008 mdd_changelog_rec_ext_rename(&rec->cr, sfid, spfid, sname);
1010 if (clf_flags & CLF_JOBID)
1011 mdd_changelog_rec_ext_jobid(&rec->cr, uc->uc_jobid);
1013 if (likely(target != NULL)) {
1014 rec->cr.cr_tfid = *mdo2fid(target);
1015 target->mod_cltime = ktime_get();
1017 fid_zero(&rec->cr.cr_tfid);
1020 rc = mdd_changelog_store(env, mdd, rec, handle);
1022 CERROR("%s: cannot store changelog record: type = %d, "
1023 "name = '%s', t = "DFID", p = "DFID": rc = %d\n",
1024 mdd2obd_dev(mdd)->obd_name, type, tname->ln_name,
1025 PFID(&rec->cr.cr_tfid), PFID(&rec->cr.cr_pfid), rc);
1032 static int __mdd_links_add(const struct lu_env *env,
1033 struct mdd_object *mdd_obj,
1034 struct linkea_data *ldata,
1035 const struct lu_name *lname,
1036 const struct lu_fid *pfid,
1037 int first, int check)
1041 if (ldata->ld_leh == NULL) {
1042 rc = first ? -ENODATA : mdd_links_read(env, mdd_obj, ldata);
1046 rc = linkea_data_new(ldata,
1047 &mdd_env_info(env)->mti_link_buf);
1054 rc = linkea_links_find(ldata, lname, pfid);
1055 if (rc && rc != -ENOENT)
1061 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LINKEA_MORE)) {
1062 struct lu_fid *tfid = &mdd_env_info(env)->mti_fid2;
1066 linkea_add_buf(ldata, lname, tfid);
1069 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LINKEA_MORE2))
1070 linkea_add_buf(ldata, lname, pfid);
1072 return linkea_add_buf(ldata, lname, pfid);
1075 static int __mdd_links_del(const struct lu_env *env,
1076 struct mdd_object *mdd_obj,
1077 struct linkea_data *ldata,
1078 const struct lu_name *lname,
1079 const struct lu_fid *pfid)
1083 if (ldata->ld_leh == NULL) {
1084 rc = mdd_links_read(env, mdd_obj, ldata);
1089 rc = linkea_links_find(ldata, lname, pfid);
1093 linkea_del_buf(ldata, lname);
1097 static int mdd_linkea_prepare(const struct lu_env *env,
1098 struct mdd_object *mdd_obj,
1099 const struct lu_fid *oldpfid,
1100 const struct lu_name *oldlname,
1101 const struct lu_fid *newpfid,
1102 const struct lu_name *newlname,
1103 int first, int check,
1104 struct linkea_data *ldata)
1109 if (OBD_FAIL_CHECK(OBD_FAIL_FID_IGIF))
1112 LASSERT(oldpfid != NULL || newpfid != NULL);
1114 if (mdd_obj->mod_flags & DEAD_OBJ)
1115 /* Unnecessary to update linkEA for dead object. */
1118 if (oldpfid != NULL) {
1119 rc = __mdd_links_del(env, mdd_obj, ldata, oldlname, oldpfid);
1121 if ((check == 1) || (rc != -ENODATA && rc != -ENOENT))
1124 /* No changes done. */
1129 /* If renaming, add the new record */
1130 if (newpfid != NULL)
1131 rc = __mdd_links_add(env, mdd_obj, ldata, newlname, newpfid,
1137 int mdd_links_rename(const struct lu_env *env,
1138 struct mdd_object *mdd_obj,
1139 const struct lu_fid *oldpfid,
1140 const struct lu_name *oldlname,
1141 const struct lu_fid *newpfid,
1142 const struct lu_name *newlname,
1143 struct thandle *handle,
1144 struct linkea_data *ldata,
1145 int first, int check)
1150 if (ldata == NULL) {
1151 ldata = &mdd_env_info(env)->mti_link_data;
1152 memset(ldata, 0, sizeof(*ldata));
1153 rc = mdd_linkea_prepare(env, mdd_obj, oldpfid, oldlname,
1154 newpfid, newlname, first, check, ldata);
1159 if (!(mdd_obj->mod_flags & DEAD_OBJ))
1160 rc = mdd_links_write(env, mdd_obj, ldata, handle);
1166 if (newlname == NULL)
1167 CERROR("link_ea add failed %d "DFID"\n",
1168 rc, PFID(mdd_object_fid(mdd_obj)));
1169 else if (oldpfid == NULL)
1170 CERROR("link_ea add '%.*s' failed %d "DFID"\n",
1171 newlname->ln_namelen, newlname->ln_name, rc,
1172 PFID(mdd_object_fid(mdd_obj)));
1173 else if (newpfid == NULL)
1174 CERROR("link_ea del '%.*s' failed %d "DFID"\n",
1175 oldlname->ln_namelen, oldlname->ln_name, rc,
1176 PFID(mdd_object_fid(mdd_obj)));
1178 CERROR("link_ea rename '%.*s'->'%.*s' failed %d "DFID
1179 "\n", oldlname->ln_namelen, oldlname->ln_name,
1180 newlname->ln_namelen, newlname->ln_name, rc,
1181 PFID(mdd_object_fid(mdd_obj)));
1184 if (is_vmalloc_addr(ldata->ld_buf))
1185 /* if we vmalloced a large buffer drop it */
1186 lu_buf_free(ldata->ld_buf);
1191 static inline int mdd_links_add(const struct lu_env *env,
1192 struct mdd_object *mdd_obj,
1193 const struct lu_fid *pfid,
1194 const struct lu_name *lname,
1195 struct thandle *handle,
1196 struct linkea_data *ldata, int first)
1198 return mdd_links_rename(env, mdd_obj, NULL, NULL,
1199 pfid, lname, handle, ldata, first, 0);
1202 static inline int mdd_links_del(const struct lu_env *env,
1203 struct mdd_object *mdd_obj,
1204 const struct lu_fid *pfid,
1205 const struct lu_name *lname,
1206 struct thandle *handle)
1208 return mdd_links_rename(env, mdd_obj, pfid, lname,
1209 NULL, NULL, handle, NULL, 0, 0);
1212 /** Read the link EA into a temp buffer.
1213 * Uses the name_buf since it is generally large.
1214 * \retval IS_ERR err
1215 * \retval ptr to \a lu_buf (always \a mti_big_buf)
1217 struct lu_buf *mdd_links_get(const struct lu_env *env,
1218 struct mdd_object *mdd_obj)
1220 struct linkea_data ldata = { NULL };
1223 rc = mdd_links_read(env, mdd_obj, &ldata);
1224 return rc ? ERR_PTR(rc) : ldata.ld_buf;
1227 int mdd_links_write(const struct lu_env *env, struct mdd_object *mdd_obj,
1228 struct linkea_data *ldata, struct thandle *handle)
1230 const struct lu_buf *buf;
1233 if (ldata == NULL || ldata->ld_buf == NULL ||
1234 ldata->ld_leh == NULL)
1237 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_NO_LINKEA))
1241 buf = mdd_buf_get_const(env, ldata->ld_buf->lb_buf,
1242 ldata->ld_leh->leh_len);
1243 rc = mdo_xattr_set(env, mdd_obj, buf, XATTR_NAME_LINK, 0, handle);
1244 if (unlikely(rc == -ENOSPC)) {
1245 rc = linkea_overflow_shrink(ldata);
1253 static int mdd_declare_links_add(const struct lu_env *env,
1254 struct mdd_object *mdd_obj,
1255 struct thandle *handle,
1256 struct linkea_data *ldata)
1262 if (ldata != NULL && ldata->ld_leh != NULL) {
1263 ea_len = ldata->ld_leh->leh_len;
1264 linkea = ldata->ld_buf->lb_buf;
1266 ea_len = MAX_LINKEA_SIZE;
1270 rc = mdo_declare_xattr_set(env, mdd_obj,
1271 mdd_buf_get_const(env, linkea, ea_len),
1272 XATTR_NAME_LINK, 0, handle);
1277 static inline int mdd_declare_links_del(const struct lu_env *env,
1278 struct mdd_object *c,
1279 struct thandle *handle)
1283 /* For directory, the linkEA will be removed together
1284 * with the object. */
1285 if (!S_ISDIR(mdd_object_type(c)))
1286 rc = mdd_declare_links_add(env, c, handle, NULL);
1291 static int mdd_declare_link(const struct lu_env *env,
1292 struct mdd_device *mdd,
1293 struct mdd_object *p,
1294 struct mdd_object *c,
1295 const struct lu_name *name,
1296 struct thandle *handle,
1298 struct linkea_data *data)
1300 struct lu_fid tfid = *mdo2fid(c);
1303 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_DANGLING3))
1304 tfid.f_oid = cfs_fail_val;
1306 rc = mdo_declare_index_insert(env, p, &tfid, mdd_object_type(c),
1307 name->ln_name, handle);
1311 rc = mdo_declare_ref_add(env, c, handle);
1315 la->la_valid = LA_CTIME | LA_MTIME;
1316 rc = mdo_declare_attr_set(env, p, la, handle);
1320 la->la_valid = LA_CTIME;
1321 rc = mdo_declare_attr_set(env, c, la, handle);
1325 rc = mdd_declare_links_add(env, c, handle, data);
1329 rc = mdd_declare_changelog_store(env, mdd, CL_HARDLINK, name, NULL,
1335 static int mdd_link(const struct lu_env *env, struct md_object *tgt_obj,
1336 struct md_object *src_obj, const struct lu_name *lname,
1339 const char *name = lname->ln_name;
1340 struct lu_attr *la = &mdd_env_info(env)->mti_la_for_fix;
1341 struct mdd_object *mdd_tobj = md2mdd_obj(tgt_obj);
1342 struct mdd_object *mdd_sobj = md2mdd_obj(src_obj);
1343 struct lu_attr *cattr = MDD_ENV_VAR(env, cattr);
1344 struct lu_attr *tattr = MDD_ENV_VAR(env, tattr);
1345 struct mdd_device *mdd = mdo2mdd(src_obj);
1346 struct thandle *handle;
1347 struct lu_fid *tfid = &mdd_env_info(env)->mti_fid2;
1348 struct linkea_data *ldata = &mdd_env_info(env)->mti_link_data;
1352 rc = mdd_la_get(env, mdd_sobj, cattr);
1356 rc = mdd_la_get(env, mdd_tobj, tattr);
1361 * If we are using project inheritance, we only allow hard link
1362 * creation in our tree when the project IDs are the same;
1363 * otherwise the tree quota mechanism could be circumvented.
1365 if ((tattr->la_flags & LUSTRE_PROJINHERIT_FL) &&
1366 (tattr->la_projid != cattr->la_projid))
1369 handle = mdd_trans_create(env, mdd);
1371 GOTO(out_pending, rc = PTR_ERR(handle));
1373 memset(ldata, 0, sizeof(*ldata));
1375 LASSERT(ma->ma_attr.la_valid & LA_CTIME);
1376 la->la_ctime = la->la_mtime = ma->ma_attr.la_ctime;
1378 /* Note: even this function will change ldata, but it comes from
1379 * thread_info, which is completely temporary and only seen in
1380 * this function, so we do not need reset ldata once it fails.*/
1381 rc = mdd_linkea_prepare(env, mdd_sobj, NULL, NULL, mdo2fid(mdd_tobj),
1382 lname, 0, 0, ldata);
1386 rc = mdd_declare_link(env, mdd, mdd_tobj, mdd_sobj, lname, handle,
1391 rc = mdd_trans_start(env, mdd, handle);
1395 mdd_write_lock(env, mdd_sobj, MOR_TGT_CHILD);
1396 rc = mdd_link_sanity_check(env, mdd_tobj, tattr, lname, mdd_sobj,
1399 GOTO(out_unlock, rc);
1401 if (!OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LESS_NLINK)) {
1402 rc = mdo_ref_add(env, mdd_sobj, handle);
1404 GOTO(out_unlock, rc);
1407 *tfid = *mdo2fid(mdd_sobj);
1408 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_DANGLING3))
1409 tfid->f_oid = cfs_fail_val;
1411 rc = __mdd_index_insert_only(env, mdd_tobj, tfid,
1412 mdd_object_type(mdd_sobj), name, handle);
1414 mdo_ref_del(env, mdd_sobj, handle);
1415 GOTO(out_unlock, rc);
1418 la->la_valid = LA_CTIME | LA_MTIME;
1419 rc = mdd_update_time(env, mdd_tobj, tattr, la, handle);
1421 GOTO(out_unlock, rc);
1423 la->la_valid = LA_CTIME;
1424 rc = mdd_update_time(env, mdd_sobj, cattr, la, handle);
1426 /* Note: The failure of links_add should not cause the
1427 * link failure, so do not check return value. */
1428 mdd_links_add(env, mdd_sobj, mdo2fid(mdd_tobj),
1429 lname, handle, ldata, 0);
1433 mdd_write_unlock(env, mdd_sobj);
1435 rc = mdd_changelog_ns_store(env, mdd, CL_HARDLINK, 0, mdd_sobj,
1436 mdo2fid(mdd_tobj), NULL, NULL,
1437 lname, NULL, handle);
1439 rc = mdd_trans_stop(env, mdd, rc, handle);
1440 if (is_vmalloc_addr(ldata->ld_buf))
1441 /* if we vmalloced a large buffer drop it */
1442 lu_buf_free(ldata->ld_buf);
1447 static int mdd_mark_orphan_object(const struct lu_env *env,
1448 struct mdd_object *obj, struct thandle *handle,
1451 struct lu_attr *attr = MDD_ENV_VAR(env, la_for_start);
1454 if (!S_ISDIR(mdd_object_type(obj)))
1457 attr->la_valid = LA_FLAGS;
1458 attr->la_flags = LUSTRE_ORPHAN_FL;
1461 rc = mdo_declare_attr_set(env, obj, attr, handle);
1463 rc = mdo_attr_set(env, obj, attr, handle);
1468 static int mdd_declare_finish_unlink(const struct lu_env *env,
1469 struct mdd_object *obj,
1470 struct thandle *handle)
1474 /* Sigh, we do not know if the unlink object will become orphan in
1475 * declare phase, but fortunately the flags here does not matter
1476 * in current declare implementation */
1477 rc = mdd_mark_orphan_object(env, obj, handle, true);
1481 rc = mdo_declare_destroy(env, obj, handle);
1485 rc = mdd_orphan_declare_insert(env, obj, mdd_object_type(obj), handle);
1489 return mdd_declare_links_del(env, obj, handle);
1492 /* caller should take a lock before calling */
1493 int mdd_finish_unlink(const struct lu_env *env,
1494 struct mdd_object *obj, struct md_attr *ma,
1495 const struct mdd_object *pobj,
1496 const struct lu_name *lname,
1500 int is_dir = S_ISDIR(ma->ma_attr.la_mode);
1503 LASSERT(mdd_write_locked(env, obj) != 0);
1505 if (ma->ma_attr.la_nlink == 0 || is_dir) {
1506 /* add new orphan and the object
1507 * will be deleted during mdd_close() */
1508 obj->mod_flags |= DEAD_OBJ;
1509 if (obj->mod_count) {
1510 rc = mdd_orphan_insert(env, obj, th);
1512 CDEBUG(D_HA, "Object "DFID" is inserted into "
1513 "orphan list, open count = %d\n",
1514 PFID(mdd_object_fid(obj)),
1517 CERROR("Object "DFID" fail to be an orphan, "
1518 "open count = %d, maybe cause failed "
1520 PFID(mdd_object_fid(obj)),
1523 /* mark object as an orphan here, not
1524 * before mdd_orphan_insert() as racing
1525 * mdd_la_get() may propagate ORPHAN_OBJ
1526 * causing the asserition */
1527 rc = mdd_mark_orphan_object(env, obj, th, false);
1529 rc = mdo_destroy(env, obj, th);
1531 } else if (!is_dir) {
1532 /* old files may not have link ea; ignore errors */
1533 mdd_links_del(env, obj, mdo2fid(pobj), lname, th);
1541 * has mdd_write_lock on cobj already, but not on pobj yet
1543 int mdd_unlink_sanity_check(const struct lu_env *env, struct mdd_object *pobj,
1544 const struct lu_attr *pattr,
1545 struct mdd_object *cobj,
1546 const struct lu_attr *cattr)
1551 rc = mdd_may_delete(env, pobj, pattr, cobj, cattr, NULL, 1, 1);
1556 static int mdd_declare_unlink(const struct lu_env *env, struct mdd_device *mdd,
1557 struct mdd_object *p, struct mdd_object *c,
1558 const struct lu_name *name, struct md_attr *ma,
1559 struct thandle *handle, int no_name, int is_dir)
1561 struct lu_attr *la = &mdd_env_info(env)->mti_la_for_fix;
1564 if (!OBD_FAIL_CHECK(OBD_FAIL_LFSCK_DANGLING2)) {
1565 if (likely(no_name == 0)) {
1566 rc = mdo_declare_index_delete(env, p, name->ln_name,
1573 rc = mdo_declare_ref_del(env, p, handle);
1579 LASSERT(ma->ma_attr.la_valid & LA_CTIME);
1580 la->la_ctime = la->la_mtime = ma->ma_attr.la_ctime;
1581 la->la_valid = LA_CTIME | LA_MTIME;
1582 rc = mdo_declare_attr_set(env, p, la, handle);
1587 rc = mdo_declare_ref_del(env, c, handle);
1591 rc = mdo_declare_ref_del(env, c, handle);
1595 la->la_valid = LA_CTIME;
1596 rc = mdo_declare_attr_set(env, c, la, handle);
1600 rc = mdd_declare_finish_unlink(env, c, handle);
1604 /* FIXME: need changelog for remove entry */
1605 rc = mdd_declare_changelog_store(env, mdd, CL_UNLINK, name,
1613 * test if a file has an HSM archive
1614 * if HSM attributes are not found in ma update them from
1617 static bool mdd_hsm_archive_exists(const struct lu_env *env,
1618 struct mdd_object *obj,
1623 if (!(ma->ma_valid & MA_HSM)) {
1624 /* no HSM MD provided, read xattr */
1625 struct lu_buf *hsm_buf;
1626 const size_t buflen = sizeof(struct hsm_attrs);
1629 hsm_buf = mdd_buf_get(env, NULL, 0);
1630 lu_buf_alloc(hsm_buf, buflen);
1631 rc = mdo_xattr_get(env, obj, hsm_buf, XATTR_NAME_HSM);
1632 rc = lustre_buf2hsm(hsm_buf->lb_buf, rc, &ma->ma_hsm);
1633 lu_buf_free(hsm_buf);
1637 ma->ma_valid |= MA_HSM;
1639 if (ma->ma_hsm.mh_flags & HS_EXISTS)
1645 * Delete name entry and the object.
1646 * Note: no_name == 1 means it only destory the object, i.e. name_entry
1647 * does not exist for this object, and it could only happen during resending
1648 * of remote unlink. see the comments in mdt_reint_unlink. Unfortunately, lname
1649 * is also needed in this case(needed by changelog), so we have to add another
1650 * parameter(no_name)here. XXX: this is only needed in DNE phase I, on Phase II,
1651 * the ENOENT failure should be able to be fixed by redo mechanism.
1653 static int mdd_unlink(const struct lu_env *env, struct md_object *pobj,
1654 struct md_object *cobj, const struct lu_name *lname,
1655 struct md_attr *ma, int no_name)
1657 const char *name = lname->ln_name;
1658 struct lu_attr *pattr = MDD_ENV_VAR(env, pattr);
1659 struct lu_attr *cattr = MDD_ENV_VAR(env, cattr);
1660 struct lu_attr *la = &mdd_env_info(env)->mti_la_for_fix;
1661 struct mdd_object *mdd_pobj = md2mdd_obj(pobj);
1662 struct mdd_object *mdd_cobj = NULL;
1663 struct mdd_device *mdd = mdo2mdd(pobj);
1664 struct thandle *handle;
1665 int rc, is_dir = 0, cl_flags = 0;
1668 /* let shutdown to start */
1669 CFS_FAIL_TIMEOUT(OBD_FAIL_TGT_REPLY_DATA_RACE, 1);
1671 /* cobj == NULL means only delete name entry */
1672 if (likely(cobj != NULL)) {
1673 mdd_cobj = md2mdd_obj(cobj);
1674 if (mdd_object_exists(mdd_cobj) == 0)
1678 rc = mdd_la_get(env, mdd_pobj, pattr);
1682 if (likely(mdd_cobj != NULL)) {
1684 rc = mdd_la_get(env, mdd_cobj, cattr);
1688 is_dir = S_ISDIR(cattr->la_mode);
1689 /* search for an existing archive.
1690 * we should check ahead as the object
1691 * can be destroyed in this transaction */
1692 if (mdd_hsm_archive_exists(env, mdd_cobj, ma))
1693 cl_flags |= CLF_UNLINK_HSM_EXISTS;
1696 rc = mdd_unlink_sanity_check(env, mdd_pobj, pattr, mdd_cobj, cattr);
1700 handle = mdd_trans_create(env, mdd);
1702 RETURN(PTR_ERR(handle));
1704 rc = mdd_declare_unlink(env, mdd, mdd_pobj, mdd_cobj,
1705 lname, ma, handle, no_name, is_dir);
1709 rc = mdd_trans_start(env, mdd, handle);
1713 if (likely(mdd_cobj != NULL))
1714 mdd_write_lock(env, mdd_cobj, MOR_TGT_CHILD);
1716 if (likely(no_name == 0) && !OBD_FAIL_CHECK(OBD_FAIL_LFSCK_DANGLING2)) {
1717 rc = __mdd_index_delete(env, mdd_pobj, name, is_dir, handle);
1722 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_MUL_REF) ||
1723 OBD_FAIL_CHECK(OBD_FAIL_LFSCK_NO_NAMEENTRY))
1724 GOTO(cleanup, rc = 0);
1726 if (likely(mdd_cobj != NULL)) {
1727 rc = mdo_ref_del(env, mdd_cobj, handle);
1729 __mdd_index_insert_only(env, mdd_pobj,
1731 mdd_object_type(mdd_cobj),
1738 mdo_ref_del(env, mdd_cobj, handle);
1740 /* fetch updated nlink */
1741 rc = mdd_la_get(env, mdd_cobj, cattr);
1746 LASSERT(ma->ma_attr.la_valid & LA_CTIME);
1747 la->la_ctime = la->la_mtime = ma->ma_attr.la_ctime;
1749 la->la_valid = LA_CTIME | LA_MTIME;
1750 rc = mdd_update_time(env, mdd_pobj, pattr, la, handle);
1754 /* Enough for only unlink the entry */
1755 if (unlikely(mdd_cobj == NULL))
1758 if (cattr->la_nlink > 0 || mdd_cobj->mod_count > 0) {
1759 /* update ctime of an unlinked file only if it is still
1760 * opened or a link still exists */
1761 la->la_valid = LA_CTIME;
1762 rc = mdd_update_time(env, mdd_cobj, cattr, la, handle);
1767 /* XXX: this transfer to ma will be removed with LOD/OSP */
1768 ma->ma_attr = *cattr;
1769 ma->ma_valid |= MA_INODE;
1770 rc = mdd_finish_unlink(env, mdd_cobj, ma, mdd_pobj, lname, handle);
1774 /* fetch updated nlink */
1775 rc = mdd_la_get(env, mdd_cobj, cattr);
1776 /* if object is removed then we can't get its attrs,
1778 if (rc == -ENOENT) {
1779 cattr->la_nlink = 0;
1783 if (cattr->la_nlink == 0) {
1784 ma->ma_attr = *cattr;
1785 ma->ma_valid |= MA_INODE;
1790 if (likely(mdd_cobj != NULL))
1791 mdd_write_unlock(env, mdd_cobj);
1794 if (cattr->la_nlink == 0)
1795 cl_flags |= CLF_UNLINK_LAST;
1797 cl_flags &= ~CLF_UNLINK_HSM_EXISTS;
1799 rc = mdd_changelog_ns_store(env, mdd,
1800 is_dir ? CL_RMDIR : CL_UNLINK, cl_flags,
1801 mdd_cobj, mdo2fid(mdd_pobj), NULL, NULL, lname, NULL,
1806 rc = mdd_trans_stop(env, mdd, rc, handle);
1812 * The permission has been checked when obj created, no need check again.
1814 static int mdd_cd_sanity_check(const struct lu_env *env,
1815 struct mdd_object *obj)
1820 if (!obj || mdd_is_dead_obj(obj))
1826 static int mdd_create_data(const struct lu_env *env,
1827 struct md_object *pobj,
1828 struct md_object *cobj,
1829 const struct md_op_spec *spec,
1832 struct mdd_device *mdd = mdo2mdd(cobj);
1833 struct mdd_object *mdd_pobj = md2mdd_obj(pobj);
1834 struct mdd_object *son = md2mdd_obj(cobj);
1835 struct thandle *handle;
1836 const struct lu_buf *buf;
1837 struct lu_attr *attr = MDD_ENV_VAR(env, cattr);
1838 struct dt_allocation_hint *hint = &mdd_env_info(env)->mti_hint;
1842 rc = mdd_cd_sanity_check(env, son);
1846 if (!md_should_create(spec->sp_cr_flags))
1850 * there are following use cases for this function:
1851 * 1) late striping - file was created with MDS_OPEN_DELAY_CREATE
1852 * striping can be specified or not
1855 rc = mdd_la_get(env, son, attr);
1859 /* calling ->ah_make_hint() is used to transfer information from parent */
1860 mdd_object_make_hint(env, mdd_pobj, son, attr, spec, hint);
1862 handle = mdd_trans_create(env, mdd);
1864 GOTO(out_free, rc = PTR_ERR(handle));
1867 * XXX: Setting the lov ea is not locked but setting the attr is locked?
1868 * Should this be fixed?
1870 CDEBUG(D_OTHER, "ea %p/%u, cr_flags %#llo, no_create %u\n",
1871 spec->u.sp_ea.eadata, spec->u.sp_ea.eadatalen,
1872 spec->sp_cr_flags, spec->no_create);
1874 if (spec->no_create || (spec->sp_cr_flags & MDS_OPEN_HAS_EA)) {
1875 buf = mdd_buf_get_const(env, spec->u.sp_ea.eadata,
1876 spec->u.sp_ea.eadatalen);
1881 rc = dt_declare_xattr_set(env, mdd_object_child(son), buf,
1882 XATTR_NAME_LOV, 0, handle);
1886 rc = mdd_declare_changelog_store(env, mdd, CL_LAYOUT, NULL, NULL,
1891 rc = mdd_trans_start(env, mdd, handle);
1895 rc = dt_xattr_set(env, mdd_object_child(son), buf, XATTR_NAME_LOV,
1901 rc = mdd_changelog_data_store(env, mdd, CL_LAYOUT, 0, son, handle);
1904 rc = mdd_trans_stop(env, mdd, rc, handle);
1910 static int mdd_declare_object_initialize(const struct lu_env *env,
1911 struct mdd_object *parent,
1912 struct mdd_object *child,
1913 const struct lu_attr *attr,
1914 struct thandle *handle)
1919 LASSERT(attr->la_valid & (LA_MODE | LA_TYPE));
1920 if (!S_ISDIR(attr->la_mode))
1923 rc = mdo_declare_index_insert(env, child, mdo2fid(child), S_IFDIR,
1928 rc = mdo_declare_ref_add(env, child, handle);
1932 rc = mdo_declare_index_insert(env, child, mdo2fid(parent), S_IFDIR,
1938 static int mdd_object_initialize(const struct lu_env *env,
1939 const struct lu_fid *pfid,
1940 struct mdd_object *child,
1941 struct lu_attr *attr,
1942 struct thandle *handle)
1947 if (S_ISDIR(attr->la_mode)) {
1948 /* Add "." and ".." for newly created dir */
1949 mdo_ref_add(env, child, handle);
1950 rc = __mdd_index_insert_only(env, child, mdo2fid(child),
1951 S_IFDIR, dot, handle);
1953 rc = __mdd_index_insert_only(env, child, pfid, S_IFDIR,
1956 mdo_ref_del(env, child, handle);
1963 * This function checks whether it can create a file/dir under the
1964 * directory(@pobj). The directory(@pobj) is not being locked by
1967 * \param[in] env execution environment
1968 * \param[in] pobj the directory to create files
1969 * \param[in] pattr the attributes of the directory
1970 * \param[in] lname the name of the created file/dir
1971 * \param[in] cattr the attributes of the file/dir
1972 * \param[in] spec create specification
1974 * \retval = 0 it is allowed to create file/dir under
1976 * \retval negative error not allowed to create file/dir
1977 * under the directory
1979 static int mdd_create_sanity_check(const struct lu_env *env,
1980 struct md_object *pobj,
1981 const struct lu_attr *pattr,
1982 const struct lu_name *lname,
1983 struct lu_attr *cattr,
1984 struct md_op_spec *spec)
1986 struct mdd_thread_info *info = mdd_env_info(env);
1987 struct lu_fid *fid = &info->mti_fid;
1988 struct mdd_object *obj = md2mdd_obj(pobj);
1989 struct mdd_device *m = mdo2mdd(pobj);
1990 bool check_perm = true;
1995 if (mdd_is_dead_obj(obj))
1999 * In some cases this lookup is not needed - we know before if name
2000 * exists or not because MDT performs lookup for it.
2001 * name length check is done in lookup.
2003 if (spec->sp_cr_lookup) {
2005 * Check if the name already exist, though it will be checked in
2006 * _index_insert also, for avoiding rolling back if exists
2009 rc = __mdd_lookup(env, pobj, pattr, lname, fid,
2010 MAY_WRITE | MAY_EXEC);
2012 RETURN(rc ? : -EEXIST);
2014 /* Permission is already being checked in mdd_lookup */
2018 if (S_ISDIR(cattr->la_mode) &&
2019 unlikely(spec != NULL && spec->sp_cr_flags & MDS_OPEN_HAS_EA) &&
2020 spec->u.sp_ea.eadata != NULL && spec->u.sp_ea.eadatalen > 0) {
2021 const struct lmv_user_md *lum = spec->u.sp_ea.eadata;
2023 if (!lmv_magic_supported(le32_to_cpu(lum->lum_magic)) &&
2024 le32_to_cpu(lum->lum_magic) != LMV_USER_MAGIC_V0) {
2026 CERROR("%s: invalid lmv_user_md: magic = %x, "
2027 "stripe_offset = %d, stripe_count = %u: "
2028 "rc = %d\n", mdd2obd_dev(m)->obd_name,
2029 le32_to_cpu(lum->lum_magic),
2030 (int)le32_to_cpu(lum->lum_stripe_offset),
2031 le32_to_cpu(lum->lum_stripe_count), rc);
2036 rc = mdd_may_create(env, obj, pattr, NULL, check_perm);
2041 if (pattr->la_mode & S_ISGID) {
2042 cattr->la_gid = pattr->la_gid;
2043 if (S_ISDIR(cattr->la_mode)) {
2044 cattr->la_mode |= S_ISGID;
2045 cattr->la_valid |= LA_MODE;
2049 /* Inherit project ID from parent directory */
2050 if (pattr->la_flags & LUSTRE_PROJINHERIT_FL) {
2051 cattr->la_projid = pattr->la_projid;
2052 if (S_ISDIR(cattr->la_mode)) {
2053 cattr->la_flags |= LUSTRE_PROJINHERIT_FL;
2054 cattr->la_valid |= LA_FLAGS;
2056 cattr->la_valid |= LA_PROJID;
2059 rc = mdd_name_check(m, lname);
2063 switch (cattr->la_mode & S_IFMT) {
2065 unsigned int symlen = strlen(spec->u.sp_symname) + 1;
2067 if (symlen > m->mdd_dt_conf.ddp_symlink_max)
2068 RETURN(-ENAMETOOLONG);
2087 static int mdd_declare_create_object(const struct lu_env *env,
2088 struct mdd_device *mdd,
2089 struct mdd_object *p, struct mdd_object *c,
2090 struct lu_attr *attr,
2091 struct thandle *handle,
2092 const struct md_op_spec *spec,
2093 struct lu_buf *def_acl_buf,
2094 struct lu_buf *acl_buf,
2095 struct dt_allocation_hint *hint)
2097 const struct lu_buf *buf;
2100 rc = mdd_declare_create_object_internal(env, p, c, attr, handle, spec,
2105 #ifdef CONFIG_FS_POSIX_ACL
2106 if (def_acl_buf && def_acl_buf->lb_len > 0 && S_ISDIR(attr->la_mode)) {
2107 /* if dir, then can inherit default ACl */
2108 rc = mdo_declare_xattr_set(env, c, def_acl_buf,
2109 XATTR_NAME_ACL_DEFAULT,
2115 if (acl_buf && acl_buf->lb_len > 0) {
2116 rc = mdo_declare_attr_set(env, c, attr, handle);
2120 rc = mdo_declare_xattr_set(env, c, acl_buf,
2121 XATTR_NAME_ACL_ACCESS, 0, handle);
2126 rc = mdd_declare_object_initialize(env, p, c, attr, handle);
2130 /* replay case, create LOV EA from client data */
2131 if ((!(spec->sp_cr_flags & MDS_OPEN_DELAY_CREATE) && spec->no_create) ||
2132 (spec->sp_cr_flags & MDS_OPEN_HAS_EA && S_ISREG(attr->la_mode))) {
2133 buf = mdd_buf_get_const(env, spec->u.sp_ea.eadata,
2134 spec->u.sp_ea.eadatalen);
2135 rc = mdo_declare_xattr_set(env, c, buf,
2136 S_ISDIR(attr->la_mode) ?
2137 XATTR_NAME_LMV : XATTR_NAME_LOV,
2143 if (S_ISLNK(attr->la_mode)) {
2144 const char *target_name = spec->u.sp_symname;
2145 int sym_len = strlen(target_name);
2146 const struct lu_buf *buf;
2148 buf = mdd_buf_get_const(env, target_name, sym_len);
2149 rc = dt_declare_record_write(env, mdd_object_child(c),
2155 if (spec->sp_cr_file_secctx_name != NULL) {
2156 buf = mdd_buf_get_const(env, spec->sp_cr_file_secctx,
2157 spec->sp_cr_file_secctx_size);
2158 rc = mdo_declare_xattr_set(env, c, buf,
2159 spec->sp_cr_file_secctx_name, 0,
2168 static int mdd_declare_create(const struct lu_env *env, struct mdd_device *mdd,
2169 struct mdd_object *p, struct mdd_object *c,
2170 const struct lu_name *name,
2171 struct lu_attr *attr,
2172 struct thandle *handle,
2173 const struct md_op_spec *spec,
2174 struct linkea_data *ldata,
2175 struct lu_buf *def_acl_buf,
2176 struct lu_buf *acl_buf,
2177 struct dt_allocation_hint *hint)
2181 rc = mdd_declare_create_object(env, mdd, p, c, attr, handle, spec,
2182 def_acl_buf, acl_buf, hint);
2186 if (S_ISDIR(attr->la_mode)) {
2187 rc = mdo_declare_ref_add(env, p, handle);
2192 if (unlikely(spec->sp_cr_flags & MDS_OPEN_VOLATILE)) {
2193 rc = mdd_orphan_declare_insert(env, c, attr->la_mode, handle);
2197 struct lu_attr *la = &mdd_env_info(env)->mti_la_for_fix;
2198 enum changelog_rec_type type;
2200 rc = mdo_declare_index_insert(env, p, mdo2fid(c), attr->la_mode,
2201 name->ln_name, handle);
2205 rc = mdd_declare_links_add(env, c, handle, ldata);
2210 la->la_valid = LA_CTIME | LA_MTIME;
2211 rc = mdo_declare_attr_set(env, p, la, handle);
2215 type = S_ISDIR(attr->la_mode) ? CL_MKDIR :
2216 S_ISREG(attr->la_mode) ? CL_CREATE :
2217 S_ISLNK(attr->la_mode) ? CL_SOFTLINK : CL_MKNOD;
2219 rc = mdd_declare_changelog_store(env, mdd, type, name, NULL,
2228 static int mdd_acl_init(const struct lu_env *env, struct mdd_object *pobj,
2229 struct lu_attr *la, struct lu_buf *def_acl_buf,
2230 struct lu_buf *acl_buf)
2235 if (S_ISLNK(la->la_mode)) {
2236 acl_buf->lb_len = 0;
2237 def_acl_buf->lb_len = 0;
2241 mdd_read_lock(env, pobj, MOR_TGT_PARENT);
2242 rc = mdo_xattr_get(env, pobj, def_acl_buf,
2243 XATTR_NAME_ACL_DEFAULT);
2244 mdd_read_unlock(env, pobj);
2246 /* If there are default ACL, fix mode/ACL by default ACL */
2247 def_acl_buf->lb_len = rc;
2248 LASSERT(def_acl_buf->lb_len <= acl_buf->lb_len);
2249 memcpy(acl_buf->lb_buf, def_acl_buf->lb_buf, rc);
2250 acl_buf->lb_len = rc;
2251 rc = __mdd_fix_mode_acl(env, acl_buf, &la->la_mode);
2254 } else if (rc == -ENODATA || rc == -EOPNOTSUPP) {
2255 /* If there are no default ACL, fix mode by mask */
2256 struct lu_ucred *uc = lu_ucred(env);
2258 /* The create triggered by MDT internal events, such as
2259 * LFSCK reset, will not contain valid "uc". */
2260 if (unlikely(uc != NULL))
2261 la->la_mode &= ~uc->uc_umask;
2263 acl_buf->lb_len = 0;
2264 def_acl_buf->lb_len = 0;
2271 * Create a metadata object and initialize it, set acl, xattr.
2273 static int mdd_create_object(const struct lu_env *env, struct mdd_object *pobj,
2274 struct mdd_object *son, struct lu_attr *attr,
2275 struct md_op_spec *spec, struct lu_buf *acl_buf,
2276 struct lu_buf *def_acl_buf,
2277 struct dt_allocation_hint *hint,
2278 struct thandle *handle)
2280 const struct lu_buf *buf;
2283 mdd_write_lock(env, son, MOR_TGT_CHILD);
2284 rc = mdd_create_object_internal(env, NULL, son, attr, handle, spec,
2289 /* Note: In DNE phase I, for striped dir, though sub-stripes will be
2290 * created in declare phase, they also needs to be added to master
2291 * object as sub-directory entry. So it has to initialize the master
2292 * object, then set dir striped EA.(in mdo_xattr_set) */
2293 rc = mdd_object_initialize(env, mdo2fid(pobj), son, attr, handle);
2295 GOTO(err_destroy, rc);
2298 * in case of replay we just set LOVEA provided by the client
2299 * XXX: I think it would be interesting to try "old" way where
2300 * MDT calls this xattr_set(LOV) in a different transaction.
2301 * probably this way we code can be made better.
2304 /* During creation, there are only a few cases we need do xattr_set to
2306 * 1. regular file: see comments above.
2307 * 2. dir: inherit default striping or pool settings from parent.
2308 * 3. create striped directory with provided stripeEA.
2309 * 4. create striped directory because inherit default layout from the
2312 if (spec->no_create ||
2313 (S_ISREG(attr->la_mode) && spec->sp_cr_flags & MDS_OPEN_HAS_EA) ||
2314 S_ISDIR(attr->la_mode)) {
2315 buf = mdd_buf_get_const(env, spec->u.sp_ea.eadata,
2316 spec->u.sp_ea.eadatalen);
2317 rc = mdo_xattr_set(env, son, buf,
2318 S_ISDIR(attr->la_mode) ? XATTR_NAME_LMV :
2322 GOTO(err_destroy, rc);
2325 #ifdef CONFIG_FS_POSIX_ACL
2326 if (def_acl_buf != NULL && def_acl_buf->lb_len > 0 &&
2327 S_ISDIR(attr->la_mode)) {
2328 /* set default acl */
2329 rc = mdo_xattr_set(env, son, def_acl_buf,
2330 XATTR_NAME_ACL_DEFAULT, 0,
2333 GOTO(err_destroy, rc);
2335 /* set its own acl */
2336 if (acl_buf != NULL && acl_buf->lb_len > 0) {
2337 rc = mdo_xattr_set(env, son, acl_buf,
2338 XATTR_NAME_ACL_ACCESS,
2341 GOTO(err_destroy, rc);
2345 if (S_ISLNK(attr->la_mode)) {
2346 struct dt_object *dt = mdd_object_child(son);
2347 const char *target_name = spec->u.sp_symname;
2348 int sym_len = strlen(target_name);
2351 buf = mdd_buf_get_const(env, target_name, sym_len);
2352 rc = dt->do_body_ops->dbo_write(env, dt, buf, &pos, handle);
2356 GOTO(err_initlized, rc = -EFAULT);
2359 if (spec->sp_cr_file_secctx_name != NULL) {
2360 buf = mdd_buf_get_const(env, spec->sp_cr_file_secctx,
2361 spec->sp_cr_file_secctx_size);
2362 rc = mdo_xattr_set(env, son, buf, spec->sp_cr_file_secctx_name,
2365 GOTO(err_initlized, rc);
2369 if (unlikely(rc != 0)) {
2371 if (S_ISDIR(attr->la_mode)) {
2372 /* Drop the reference, no need to delete "."/"..",
2373 * because the object to be destroied directly. */
2374 rc2 = mdo_ref_del(env, son, handle);
2378 rc2 = mdo_ref_del(env, son, handle);
2382 mdo_destroy(env, son, handle);
2385 mdd_write_unlock(env, son);
2389 static int mdd_index_delete(const struct lu_env *env,
2390 struct mdd_object *mdd_pobj,
2391 struct lu_attr *cattr,
2392 const struct lu_name *lname)
2394 struct mdd_device *mdd = mdo2mdd(&mdd_pobj->mod_obj);
2395 struct thandle *handle;
2399 handle = mdd_trans_create(env, mdd);
2401 RETURN(PTR_ERR(handle));
2403 rc = mdo_declare_index_delete(env, mdd_pobj, lname->ln_name,
2408 if (S_ISDIR(cattr->la_mode)) {
2409 rc = mdo_declare_ref_del(env, mdd_pobj, handle);
2414 /* Since this will only be used in the error handler path,
2415 * Let's set the thandle to be local and not mess the transno */
2416 handle->th_local = 1;
2417 rc = mdd_trans_start(env, mdd, handle);
2421 rc = __mdd_index_delete(env, mdd_pobj, lname->ln_name,
2422 S_ISDIR(cattr->la_mode), handle);
2426 rc = mdd_trans_stop(env, mdd, rc, handle);
2432 * Create object and insert it into namespace.
2434 * Two operations have to be performed:
2436 * - an allocation of a new object (->do_create()), and
2437 * - an insertion into a parent index (->dio_insert()).
2439 * Due to locking, operation order is not important, when both are
2440 * successful, *but* error handling cases are quite different:
2442 * - if insertion is done first, and following object creation fails,
2443 * insertion has to be rolled back, but this operation might fail
2444 * also leaving us with dangling index entry.
2446 * - if creation is done first, is has to be undone if insertion fails,
2447 * leaving us with leaked space, which is not good but not fatal.
2449 * It seems that creation-first is simplest solution, but it is sub-optimal
2455 * case, because second mkdir is bound to create object, only to
2456 * destroy it immediately.
2458 * To avoid this follow local file systems that do double lookup:
2460 * 0. lookup -> -EEXIST (mdd_create_sanity_check())
2461 * 1. create (mdd_create_object_internal())
2462 * 2. insert (__mdd_index_insert(), lookup again)
2464 * \param[in] pobj parent object
2465 * \param[in] lname name of child being created
2466 * \param[in,out] child child object being created
2467 * \param[in] spec additional create parameters
2468 * \param[in] ma attributes for new child object
2470 * \retval 0 on success
2471 * \retval negative errno on failure
2473 static int mdd_create(const struct lu_env *env, struct md_object *pobj,
2474 const struct lu_name *lname, struct md_object *child,
2475 struct md_op_spec *spec, struct md_attr *ma)
2477 struct mdd_thread_info *info = mdd_env_info(env);
2478 struct lu_attr *la = &info->mti_la_for_fix;
2479 struct mdd_object *mdd_pobj = md2mdd_obj(pobj);
2480 struct mdd_object *son = md2mdd_obj(child);
2481 struct mdd_device *mdd = mdo2mdd(pobj);
2482 struct lu_attr *attr = &ma->ma_attr;
2483 struct thandle *handle;
2484 struct lu_attr *pattr = &info->mti_pattr;
2485 struct lu_buf acl_buf;
2486 struct lu_buf def_acl_buf;
2487 struct linkea_data *ldata = &info->mti_link_data;
2488 const char *name = lname->ln_name;
2489 struct dt_allocation_hint *hint = &mdd_env_info(env)->mti_hint;
2494 rc = mdd_la_get(env, mdd_pobj, pattr);
2498 /* Sanity checks before big job. */
2499 rc = mdd_create_sanity_check(env, pobj, pattr, lname, attr, spec);
2503 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_DQACQ_NET))
2504 GOTO(out_free, rc = -EINPROGRESS);
2506 handle = mdd_trans_create(env, mdd);
2508 GOTO(out_free, rc = PTR_ERR(handle));
2510 lu_buf_check_and_alloc(&info->mti_xattr_buf,
2511 MIN(mdd->mdd_dt_conf.ddp_max_ea_size, XATTR_SIZE_MAX));
2512 acl_buf = info->mti_xattr_buf;
2513 def_acl_buf.lb_buf = info->mti_key;
2514 def_acl_buf.lb_len = sizeof(info->mti_key);
2515 rc = mdd_acl_init(env, mdd_pobj, attr, &def_acl_buf, &acl_buf);
2519 if (S_ISDIR(attr->la_mode)) {
2520 struct lmv_user_md *lmu = spec->u.sp_ea.eadata;
2523 * migrate may create 1-stripe directory, so lod_ah_init()
2524 * doesn't adjust stripe count from lmu.
2526 if (lmu && lmu->lum_stripe_count == cpu_to_le32(1)) {
2527 info->mti_lmu = *lmu;
2528 info->mti_lmu.lum_stripe_count = 0;
2529 spec->u.sp_ea.eadata = &info->mti_lmu;
2533 mdd_object_make_hint(env, mdd_pobj, son, attr, spec, hint);
2535 memset(ldata, 0, sizeof(*ldata));
2536 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_PARENT)) {
2537 struct lu_fid tfid = *mdd_object_fid(mdd_pobj);
2540 rc = mdd_linkea_prepare(env, son, NULL, NULL,
2541 &tfid, lname, 1, 0, ldata);
2543 rc = mdd_linkea_prepare(env, son, NULL, NULL,
2544 mdd_object_fid(mdd_pobj),
2545 lname, 1, 0, ldata);
2548 rc = mdd_declare_create(env, mdd, mdd_pobj, son, lname, attr,
2549 handle, spec, ldata, &def_acl_buf, &acl_buf,
2554 rc = mdd_trans_start(env, mdd, handle);
2558 rc = mdd_create_object(env, mdd_pobj, son, attr, spec, &acl_buf,
2559 &def_acl_buf, hint, handle);
2563 if (unlikely(spec->sp_cr_flags & MDS_OPEN_VOLATILE)) {
2564 mdd_write_lock(env, son, MOR_TGT_CHILD);
2565 son->mod_flags |= VOLATILE_OBJ;
2566 rc = mdd_orphan_insert(env, son, handle);
2567 GOTO(out_volatile, rc);
2569 rc = __mdd_index_insert(env, mdd_pobj, mdo2fid(son),
2570 attr->la_mode, name, handle);
2572 GOTO(err_created, rc);
2574 mdd_links_add(env, son, mdo2fid(mdd_pobj), lname, handle,
2577 /* update parent directory mtime/ctime */
2579 la->la_valid = LA_CTIME | LA_MTIME;
2580 rc = mdd_update_time(env, mdd_pobj, pattr, la, handle);
2582 GOTO(err_insert, rc);
2588 if (spec->sp_cr_flags & MDS_OPEN_VOLATILE)
2589 rc2 = mdd_orphan_delete(env, son, handle);
2591 rc2 = __mdd_index_delete(env, mdd_pobj, name,
2592 S_ISDIR(attr->la_mode),
2598 mdd_write_lock(env, son, MOR_TGT_CHILD);
2599 if (S_ISDIR(attr->la_mode)) {
2600 /* Drop the reference, no need to delete "."/"..",
2601 * because the object is to be destroyed directly. */
2602 rc2 = mdo_ref_del(env, son, handle);
2604 mdd_write_unlock(env, son);
2609 /* For volatile files drop one link immediately, since there is
2610 * no filename in the namespace, and save any error returned. */
2611 rc2 = mdo_ref_del(env, son, handle);
2613 mdd_write_unlock(env, son);
2614 if (unlikely(rc == 0))
2619 /* Don't destroy the volatile object on success */
2620 if (likely(rc != 0))
2621 mdo_destroy(env, son, handle);
2622 mdd_write_unlock(env, son);
2625 if (rc == 0 && fid_is_namespace_visible(mdo2fid(son)) &&
2626 likely((spec->sp_cr_flags & MDS_OPEN_VOLATILE) == 0))
2627 rc = mdd_changelog_ns_store(env, mdd,
2628 S_ISDIR(attr->la_mode) ? CL_MKDIR :
2629 S_ISREG(attr->la_mode) ? CL_CREATE :
2630 S_ISLNK(attr->la_mode) ? CL_SOFTLINK : CL_MKNOD,
2631 0, son, mdo2fid(mdd_pobj), NULL, NULL, lname,
2634 rc2 = mdd_trans_stop(env, mdd, rc, handle);
2636 /* If creation fails, it is most likely due to the remote update
2637 * failure, because local transaction will mostly succeed at
2638 * this stage. There is no easy way to rollback all of previous
2639 * updates, so let's remove the object from namespace, and
2640 * LFSCK should handle the orphan object. */
2641 if (rc2 < 0 && !mdd_object_remote(mdd_pobj))
2642 mdd_index_delete(env, mdd_pobj, attr, lname);
2646 if (is_vmalloc_addr(ldata->ld_buf))
2647 /* if we vmalloced a large buffer drop it */
2648 lu_buf_free(ldata->ld_buf);
2650 /* The child object shouldn't be cached anymore */
2652 set_bit(LU_OBJECT_HEARD_BANSHEE,
2653 &child->mo_lu.lo_header->loh_flags);
2658 * Get locks on parents in proper order
2659 * RETURN: < 0 - error, rename_order if successful
2667 static int mdd_rename_order(const struct lu_env *env,
2668 struct mdd_device *mdd,
2669 struct mdd_object *src_pobj,
2670 const struct lu_attr *pattr,
2671 struct mdd_object *tgt_pobj)
2673 /* order of locking, 1 - tgt-src, 0 - src-tgt*/
2677 if (src_pobj == tgt_pobj)
2678 RETURN(MDD_RN_SAME);
2680 /* compared the parent child relationship of src_p&tgt_p */
2681 if (lu_fid_eq(&mdd->mdd_root_fid, mdo2fid(src_pobj))){
2683 } else if (lu_fid_eq(&mdd->mdd_root_fid, mdo2fid(tgt_pobj))) {
2686 rc = mdd_is_parent(env, mdd, src_pobj, pattr,
2700 /* has not mdd_write{read}_lock on any obj yet. */
2701 static int mdd_rename_sanity_check(const struct lu_env *env,
2702 struct mdd_object *src_pobj,
2703 const struct lu_attr *pattr,
2704 struct mdd_object *tgt_pobj,
2705 const struct lu_attr *tpattr,
2706 struct mdd_object *sobj,
2707 const struct lu_attr *cattr,
2708 struct mdd_object *tobj,
2709 const struct lu_attr *tattr)
2714 /* XXX: when get here, sobj must NOT be NULL,
2715 * the other case has been processed in cld_rename
2716 * before mdd_rename and enable MDS_PERM_BYPASS. */
2720 * If we are using project inheritance, we only allow renames
2721 * into our tree when the project IDs are the same; otherwise
2722 * tree quota mechanism would be circumvented.
2724 if (((tpattr->la_flags & LUSTRE_PROJINHERIT_FL) &&
2725 tpattr->la_projid != cattr->la_projid) ||
2726 ((pattr->la_flags & LUSTRE_PROJINHERIT_FL) &&
2727 (pattr->la_projid != tpattr->la_projid)))
2730 rc = mdd_may_delete(env, src_pobj, pattr, sobj, cattr, NULL, 1, 0);
2734 /* XXX: when get here, "tobj == NULL" means tobj must
2735 * NOT exist (neither on remote MDS, such case has been
2736 * processed in cld_rename before mdd_rename and enable
2738 * So check may_create, but not check may_unlink. */
2740 rc = mdd_may_create(env, tgt_pobj, tpattr, NULL,
2741 (src_pobj != tgt_pobj));
2743 rc = mdd_may_delete(env, tgt_pobj, tpattr, tobj, tattr, cattr,
2744 (src_pobj != tgt_pobj), 1);
2746 if (!rc && !tobj && (src_pobj != tgt_pobj) && S_ISDIR(cattr->la_mode))
2747 rc = __mdd_may_link(env, tgt_pobj, tpattr);
2752 static int mdd_declare_rename(const struct lu_env *env,
2753 struct mdd_device *mdd,
2754 struct mdd_object *mdd_spobj,
2755 struct mdd_object *mdd_tpobj,
2756 struct mdd_object *mdd_sobj,
2757 struct mdd_object *mdd_tobj,
2758 const struct lu_name *sname,
2759 const struct lu_name *tname,
2761 struct linkea_data *ldata,
2762 struct thandle *handle)
2764 struct lu_attr *la = &mdd_env_info(env)->mti_la_for_fix;
2767 LASSERT(ma->ma_attr.la_valid & LA_CTIME);
2768 la->la_ctime = la->la_mtime = ma->ma_attr.la_ctime;
2774 /* name from source dir */
2775 rc = mdo_declare_index_delete(env, mdd_spobj, sname->ln_name, handle);
2779 /* .. from source child */
2780 if (S_ISDIR(mdd_object_type(mdd_sobj))) {
2781 /* source child can be directory,
2782 * counted by source dir's nlink */
2783 rc = mdo_declare_ref_del(env, mdd_spobj, handle);
2786 if (mdd_spobj != mdd_tpobj) {
2787 rc = mdo_declare_index_delete(env, mdd_sobj, dotdot,
2792 rc = mdo_declare_index_insert(env, mdd_sobj,
2794 S_IFDIR, dotdot, handle);
2799 /* new target child can be directory,
2800 * counted by target dir's nlink */
2801 rc = mdo_declare_ref_add(env, mdd_tpobj, handle);
2806 la->la_valid = LA_CTIME | LA_MTIME;
2807 rc = mdo_declare_attr_set(env, mdd_spobj, la, handle);
2811 rc = mdo_declare_attr_set(env, mdd_tpobj, la, handle);
2815 la->la_valid = LA_CTIME;
2816 rc = mdo_declare_attr_set(env, mdd_sobj, la, handle);
2820 rc = mdd_declare_links_add(env, mdd_sobj, handle, ldata);
2825 rc = mdo_declare_index_insert(env, mdd_tpobj, mdo2fid(mdd_sobj),
2826 mdd_object_type(mdd_sobj),
2827 tname->ln_name, handle);
2831 if (mdd_tobj && mdd_object_exists(mdd_tobj)) {
2832 /* delete target child in target parent directory */
2833 rc = mdo_declare_index_delete(env, mdd_tpobj, tname->ln_name,
2838 rc = mdo_declare_ref_del(env, mdd_tobj, handle);
2842 if (S_ISDIR(mdd_object_type(mdd_tobj))) {
2843 /* target child can be directory,
2844 * delete "." reference in target child directory */
2845 rc = mdo_declare_ref_del(env, mdd_tobj, handle);
2849 /* delete ".." reference in target parent directory */
2850 rc = mdo_declare_ref_del(env, mdd_tpobj, handle);
2855 la->la_valid = LA_CTIME;
2856 rc = mdo_declare_attr_set(env, mdd_tobj, la, handle);
2860 rc = mdd_declare_finish_unlink(env, mdd_tobj, handle);
2865 rc = mdd_declare_changelog_store(env, mdd, CL_RENAME, tname, sname,
2873 /* src object can be remote that is why we use only fid and type of object */
2874 static int mdd_rename(const struct lu_env *env,
2875 struct md_object *src_pobj, struct md_object *tgt_pobj,
2876 const struct lu_fid *lf, const struct lu_name *lsname,
2877 struct md_object *tobj, const struct lu_name *ltname,
2880 const char *sname = lsname->ln_name;
2881 const char *tname = ltname->ln_name;
2882 struct lu_attr *la = &mdd_env_info(env)->mti_la_for_fix;
2883 struct mdd_object *mdd_spobj = md2mdd_obj(src_pobj); /* source parent */
2884 struct mdd_object *mdd_tpobj = md2mdd_obj(tgt_pobj);
2885 struct mdd_device *mdd = mdo2mdd(src_pobj);
2886 struct mdd_object *mdd_sobj = NULL; /* source object */
2887 struct mdd_object *mdd_tobj = NULL;
2888 struct lu_attr *cattr = MDD_ENV_VAR(env, cattr);
2889 struct lu_attr *pattr = MDD_ENV_VAR(env, pattr);
2890 struct lu_attr *tattr = MDD_ENV_VAR(env, tattr);
2891 struct lu_attr *tpattr = MDD_ENV_VAR(env, tpattr);
2892 struct thandle *handle;
2893 struct linkea_data *ldata = &mdd_env_info(env)->mti_link_data;
2894 const struct lu_fid *tpobj_fid = mdo2fid(mdd_tpobj);
2895 const struct lu_fid *spobj_fid = mdo2fid(mdd_spobj);
2898 bool tobj_locked = 0;
2899 unsigned cl_flags = 0;
2903 /* let unlink to complete and commit */
2904 CFS_FAIL_TIMEOUT(OBD_FAIL_TGT_REPLY_DATA_RACE, 2 + cfs_fail_val);
2907 mdd_tobj = md2mdd_obj(tobj);
2909 mdd_sobj = mdd_object_find(env, mdd, lf);
2910 if (IS_ERR(mdd_sobj))
2911 RETURN(PTR_ERR(mdd_sobj));
2913 rc = mdd_la_get(env, mdd_sobj, cattr);
2915 GOTO(out_pending, rc);
2917 rc = mdd_la_get(env, mdd_spobj, pattr);
2919 GOTO(out_pending, rc);
2922 rc = mdd_la_get(env, mdd_tobj, tattr);
2924 GOTO(out_pending, rc);
2925 /* search for an existing archive.
2926 * we should check ahead as the object
2927 * can be destroyed in this transaction */
2928 if (mdd_hsm_archive_exists(env, mdd_tobj, ma))
2929 cl_flags |= CLF_RENAME_LAST_EXISTS;
2932 rc = mdd_la_get(env, mdd_tpobj, tpattr);
2934 GOTO(out_pending, rc);
2936 rc = mdd_rename_sanity_check(env, mdd_spobj, pattr, mdd_tpobj, tpattr,
2937 mdd_sobj, cattr, mdd_tobj, tattr);
2939 GOTO(out_pending, rc);
2941 rc = mdd_name_check(mdd, ltname);
2943 GOTO(out_pending, rc);
2945 /* FIXME: Should consider tobj and sobj too in rename_lock. */
2946 rc = mdd_rename_order(env, mdd, mdd_spobj, pattr, mdd_tpobj);
2948 GOTO(out_pending, rc);
2950 handle = mdd_trans_create(env, mdd);
2952 GOTO(out_pending, rc = PTR_ERR(handle));
2954 memset(ldata, 0, sizeof(*ldata));
2955 rc = mdd_linkea_prepare(env, mdd_sobj, mdd_object_fid(mdd_spobj),
2956 lsname, mdd_object_fid(mdd_tpobj), ltname,
2961 rc = mdd_declare_rename(env, mdd, mdd_spobj, mdd_tpobj, mdd_sobj,
2962 mdd_tobj, lsname, ltname, ma, ldata, handle);
2966 rc = mdd_trans_start(env, mdd, handle);
2970 is_dir = S_ISDIR(cattr->la_mode);
2972 /* Remove source name from source directory */
2973 rc = __mdd_index_delete(env, mdd_spobj, sname, is_dir, handle);
2977 /* "mv dir1 dir2" needs "dir1/.." link update */
2978 if (is_dir && !lu_fid_eq(spobj_fid, tpobj_fid)) {
2979 rc = __mdd_index_delete_only(env, mdd_sobj, dotdot, handle);
2981 GOTO(fixup_spobj2, rc);
2983 rc = __mdd_index_insert_only(env, mdd_sobj, tpobj_fid, S_IFDIR,
2986 GOTO(fixup_spobj, rc);
2989 if (mdd_tobj != NULL && mdd_object_exists(mdd_tobj)) {
2990 rc = __mdd_index_delete(env, mdd_tpobj, tname, is_dir, handle);
2992 /* tname might been renamed to something else */
2993 GOTO(fixup_spobj, rc);
2996 /* Insert new fid with target name into target dir */
2997 rc = __mdd_index_insert(env, mdd_tpobj, lf, cattr->la_mode,
3000 GOTO(fixup_tpobj, rc);
3002 LASSERT(ma->ma_attr.la_valid & LA_CTIME);
3003 la->la_ctime = la->la_mtime = ma->ma_attr.la_ctime;
3005 /* XXX: mdd_sobj must be local one if it is NOT NULL. */
3006 la->la_valid = LA_CTIME;
3007 rc = mdd_update_time(env, mdd_sobj, cattr, la, handle);
3009 GOTO(fixup_tpobj, rc);
3011 /* Update the linkEA for the source object */
3012 mdd_write_lock(env, mdd_sobj, MOR_SRC_CHILD);
3013 rc = mdd_links_rename(env, mdd_sobj, mdo2fid(mdd_spobj), lsname,
3014 mdo2fid(mdd_tpobj), ltname, handle, ldata,
3017 /* Old files might not have EA entry */
3018 mdd_links_add(env, mdd_sobj, mdo2fid(mdd_spobj),
3019 lsname, handle, NULL, 0);
3020 mdd_write_unlock(env, mdd_sobj);
3021 /* We don't fail the transaction if the link ea can't be
3022 updated -- fid2path will use alternate lookup method. */
3025 /* Remove old target object
3026 * For tobj is remote case cmm layer has processed
3027 * and set tobj to NULL then. So when tobj is NOT NULL,
3028 * it must be local one.
3030 if (tobj && mdd_object_exists(mdd_tobj)) {
3031 mdd_write_lock(env, mdd_tobj, MOR_TGT_CHILD);
3033 if (mdd_is_dead_obj(mdd_tobj)) {
3034 /* shld not be dead, something is wrong */
3035 CERROR("tobj is dead, something is wrong\n");
3039 mdo_ref_del(env, mdd_tobj, handle);
3041 /* Remove dot reference. */
3042 if (S_ISDIR(tattr->la_mode))
3043 mdo_ref_del(env, mdd_tobj, handle);
3046 /* fetch updated nlink */
3047 rc = mdd_la_get(env, mdd_tobj, tattr);
3049 CERROR("%s: Failed to get nlink for tobj "
3051 mdd2obd_dev(mdd)->obd_name,
3052 PFID(tpobj_fid), rc);
3053 GOTO(fixup_tpobj, rc);
3056 la->la_valid = LA_CTIME;
3057 rc = mdd_update_time(env, mdd_tobj, tattr, la, handle);
3059 CERROR("%s: Failed to set ctime for tobj "
3061 mdd2obd_dev(mdd)->obd_name,
3062 PFID(tpobj_fid), rc);
3063 GOTO(fixup_tpobj, rc);
3066 /* XXX: this transfer to ma will be removed with LOD/OSP */
3067 ma->ma_attr = *tattr;
3068 ma->ma_valid |= MA_INODE;
3069 rc = mdd_finish_unlink(env, mdd_tobj, ma, mdd_tpobj, ltname,
3072 CERROR("%s: Failed to unlink tobj "
3074 mdd2obd_dev(mdd)->obd_name,
3075 PFID(tpobj_fid), rc);
3076 GOTO(fixup_tpobj, rc);
3079 /* fetch updated nlink */
3080 rc = mdd_la_get(env, mdd_tobj, tattr);
3081 if (rc == -ENOENT) {
3082 /* the object got removed, let's
3083 * return the latest known attributes */
3084 tattr->la_nlink = 0;
3086 } else if (rc != 0) {
3087 CERROR("%s: Failed to get nlink for tobj "
3089 mdd2obd_dev(mdd)->obd_name,
3090 PFID(tpobj_fid), rc);
3091 GOTO(fixup_tpobj, rc);
3093 /* XXX: this transfer to ma will be removed with LOD/OSP */
3094 ma->ma_attr = *tattr;
3095 ma->ma_valid |= MA_INODE;
3097 if (tattr->la_nlink == 0)
3098 cl_flags |= CLF_RENAME_LAST;
3100 cl_flags &= ~CLF_RENAME_LAST_EXISTS;
3103 la->la_valid = LA_CTIME | LA_MTIME;
3104 rc = mdd_update_time(env, mdd_spobj, pattr, la, handle);
3106 GOTO(fixup_tpobj, rc);
3108 if (mdd_spobj != mdd_tpobj) {
3109 la->la_valid = LA_CTIME | LA_MTIME;
3110 rc = mdd_update_time(env, mdd_tpobj, tpattr, la, handle);
3112 GOTO(fixup_tpobj, rc);
3119 rc2 = __mdd_index_delete(env, mdd_tpobj, tname, is_dir, handle);
3121 CWARN("tp obj fix error %d\n",rc2);
3123 if (mdd_tobj && mdd_object_exists(mdd_tobj) &&
3124 !mdd_is_dead_obj(mdd_tobj)) {
3126 mdo_ref_add(env, mdd_tobj, handle);
3128 mdo_ref_add(env, mdd_tobj, handle);
3131 rc2 = __mdd_index_insert(env, mdd_tpobj,
3133 mdd_object_type(mdd_tobj),
3136 CWARN("tp obj fix error: rc = %d\n", rc2);
3141 if (rc && is_dir && mdd_sobj && mdd_spobj != mdd_tpobj) {
3142 rc2 = __mdd_index_delete_only(env, mdd_sobj, dotdot, handle);
3144 CWARN("%s: sp obj dotdot delete error: rc = %d\n",
3145 mdd2obd_dev(mdd)->obd_name, rc2);
3148 rc2 = __mdd_index_insert_only(env, mdd_sobj, spobj_fid, S_IFDIR,
3151 CWARN("%s: sp obj dotdot insert error: rc = %d\n",
3152 mdd2obd_dev(mdd)->obd_name, rc2);
3157 rc2 = __mdd_index_insert(env, mdd_spobj, lf,
3158 mdd_object_type(mdd_sobj), sname,
3161 CWARN("sp obj fix error: rc = %d\n", rc2);
3166 mdd_write_unlock(env, mdd_tobj);
3169 rc = mdd_changelog_ns_store(env, mdd, CL_RENAME, cl_flags,
3170 mdd_tobj, tpobj_fid, lf, spobj_fid,
3171 ltname, lsname, handle);
3174 rc = mdd_trans_stop(env, mdd, rc, handle);
3177 mdd_object_put(env, mdd_sobj);
3182 * Check whether we should migrate the file/dir
3184 * < 0 permission check failed or other error.
3185 * = 0 the file can be migrated.
3187 static int mdd_migrate_sanity_check(const struct lu_env *env,
3188 struct mdd_device *mdd,
3189 struct mdd_object *spobj,
3190 struct mdd_object *tpobj,
3191 struct mdd_object *sobj,
3192 struct mdd_object *tobj,
3193 const struct lu_attr *spattr,
3194 const struct lu_attr *tpattr,
3195 const struct lu_attr *attr)
3201 if (!mdd_object_remote(sobj)) {
3202 mdd_read_lock(env, sobj, MOR_SRC_CHILD);
3203 if (sobj->mod_count > 0) {
3204 CDEBUG(D_INFO, "%s: "DFID" is opened, count %d\n",
3205 mdd2obd_dev(mdd)->obd_name, PFID(mdo2fid(sobj)),
3207 mdd_read_unlock(env, sobj);
3210 mdd_read_unlock(env, sobj);
3213 if (mdd_object_exists(tobj))
3216 rc = mdd_rename_sanity_check(env, spobj, spattr, tpobj, tpattr, sobj,
3221 typedef int (*mdd_dir_stripe_cb)(const struct lu_env *env,
3222 struct mdd_object *obj,
3223 struct mdd_object *stripe,
3224 const struct lu_buf *lmv_buf,
3225 const struct lu_buf *lmu_buf,
3227 struct thandle *handle);
3229 static int mdd_dir_declare_delete_stripe(const struct lu_env *env,
3230 struct mdd_object *obj,
3231 struct mdd_object *stripe,
3232 const struct lu_buf *lmv_buf,
3233 const struct lu_buf *lmu_buf,
3235 struct thandle *handle)
3237 struct mdd_thread_info *info = mdd_env_info(env);
3238 char *stripe_name = info->mti_name;
3239 struct lmv_user_md *lmu = lmu_buf->lb_buf;
3242 if (index < le32_to_cpu(lmu->lum_stripe_count))
3245 rc = mdo_declare_index_delete(env, stripe, dotdot, handle);
3249 snprintf(stripe_name, sizeof(info->mti_name), DFID":%d",
3250 PFID(mdd_object_fid(stripe)), index);
3252 rc = mdo_declare_index_delete(env, obj, stripe_name, handle);
3256 rc = mdo_declare_ref_del(env, obj, handle);
3261 /* delete stripe from its master object namespace */
3262 static int mdd_dir_delete_stripe(const struct lu_env *env,
3263 struct mdd_object *obj,
3264 struct mdd_object *stripe,
3265 const struct lu_buf *lmv_buf,
3266 const struct lu_buf *lmu_buf,
3268 struct thandle *handle)
3270 struct mdd_thread_info *info = mdd_env_info(env);
3271 char *stripe_name = info->mti_name;
3272 struct lmv_mds_md_v1 *lmv = lmv_buf->lb_buf;
3273 struct lmv_user_md *lmu = lmu_buf->lb_buf;
3274 __u32 del_offset = le32_to_cpu(lmu->lum_stripe_count);
3279 /* local dir will delete via LOD */
3280 LASSERT(mdd_object_remote(obj));
3281 LASSERT(del_offset < le32_to_cpu(lmv->lmv_stripe_count));
3283 if (index < del_offset)
3286 mdd_write_lock(env, stripe, MOR_SRC_CHILD);
3287 rc = __mdd_index_delete_only(env, stripe, dotdot, handle);
3291 snprintf(stripe_name, sizeof(info->mti_name), DFID":%d",
3292 PFID(mdd_object_fid(stripe)), index);
3294 rc = __mdd_index_delete_only(env, obj, stripe_name, handle);
3298 rc = mdo_ref_del(env, obj, handle);
3301 mdd_write_unlock(env, stripe);
3306 static int mdd_dir_declare_destroy_stripe(const struct lu_env *env,
3307 struct mdd_object *obj,
3308 struct mdd_object *stripe,
3309 const struct lu_buf *lmv_buf,
3310 const struct lu_buf *lmu_buf,
3312 struct thandle *handle)
3314 struct lmv_user_md *lmu = lmu_buf->lb_buf;
3315 __u32 shrink_offset = le32_to_cpu(lmu->lum_stripe_count);
3318 if (index < shrink_offset) {
3319 if (shrink_offset < 2)
3321 return mdo_declare_xattr_set(env, stripe, lmv_buf,
3322 XATTR_NAME_LMV".set", 0, handle);
3325 rc = mdo_declare_ref_del(env, stripe, handle);
3329 rc = mdo_declare_destroy(env, stripe, handle);
3334 static int mdd_dir_destroy_stripe(const struct lu_env *env,
3335 struct mdd_object *obj,
3336 struct mdd_object *stripe,
3337 const struct lu_buf *lmv_buf,
3338 const struct lu_buf *lmu_buf,
3340 struct thandle *handle)
3342 struct mdd_thread_info *info = mdd_env_info(env);
3343 struct lmv_mds_md_v1 *lmv = lmv_buf->lb_buf;
3344 struct lmv_user_md *lmu = lmu_buf->lb_buf;
3345 __u32 shrink_offset = le32_to_cpu(lmu->lum_stripe_count);
3350 /* update remaining stripes' LMV */
3351 if (index < shrink_offset) {
3352 struct lmv_mds_md_v1 *slave_lmv;
3353 struct lu_buf slave_buf = {
3354 .lb_buf = &info->mti_lmv.lmv_md_v1,
3355 .lb_len = sizeof(*slave_lmv)
3357 __u32 version = le32_to_cpu(lmv->lmv_layout_version);
3359 /* if dir will be shrunk to 1-stripe, don't update */
3360 if (shrink_offset < 2)
3363 slave_lmv = slave_buf.lb_buf;
3364 memset(slave_lmv, 0, sizeof(*slave_lmv));
3365 slave_lmv->lmv_magic = cpu_to_le32(LMV_MAGIC_STRIPE);
3366 slave_lmv->lmv_stripe_count = lmu->lum_stripe_count;
3367 slave_lmv->lmv_master_mdt_index = cpu_to_le32(index);
3368 slave_lmv->lmv_hash_type = lmv->lmv_hash_type &
3369 cpu_to_le32(LMV_HASH_TYPE_MASK);
3370 slave_lmv->lmv_layout_version = cpu_to_le32(++version);
3372 rc = mdo_xattr_set(env, stripe, &slave_buf,
3373 XATTR_NAME_LMV".set", 0, handle);
3377 mdd_write_lock(env, stripe, MOR_SRC_CHILD);
3378 rc = mdo_ref_del(env, stripe, handle);
3380 rc = mdo_destroy(env, stripe, handle);
3381 mdd_write_unlock(env, stripe);
3386 static int mdd_shrink_stripe_is_empty(const struct lu_env *env,
3387 struct mdd_object *obj,
3388 struct mdd_object *stripe,
3389 const struct lu_buf *lmv_buf,
3390 const struct lu_buf *lmu_buf,
3392 struct thandle *handle)
3394 struct lmv_user_md *lmu = lmu_buf->lb_buf;
3395 __u32 shrink_offset = le32_to_cpu(lmu->lum_stripe_count);
3397 /* the default value is 0, but it means 1 */
3401 if (index < shrink_offset)
3404 return mdd_dir_is_empty(env, stripe);
3408 * iterate stripes of striped directory on remote MDT, local striped directory
3409 * is accessed via LOD.
3411 static int mdd_dir_iterate_stripes(const struct lu_env *env,
3412 struct mdd_object *obj,
3413 const struct lu_buf *lmv_buf,
3414 const struct lu_buf *lmu_buf,
3415 struct thandle *handle,
3416 mdd_dir_stripe_cb cb)
3418 struct mdd_device *mdd = mdo2mdd(&obj->mod_obj);
3419 struct lu_fid *fid = &mdd_env_info(env)->mti_fid2;
3420 struct lmv_mds_md_v1 *lmv = lmv_buf->lb_buf;
3421 struct mdd_object *stripe;
3429 for (i = 0; i < le32_to_cpu(lmv->lmv_stripe_count); i++) {
3430 fid_le_to_cpu(fid, &lmv->lmv_stripe_fids[i]);
3431 stripe = mdd_object_find(env, mdd, fid);
3433 RETURN(PTR_ERR(stripe));
3435 rc = cb(env, obj, stripe, lmv_buf, lmu_buf, i, handle);
3436 mdd_object_put(env, stripe);
3444 typedef int (*mdd_xattr_cb)(const struct lu_env *env,
3445 struct mdd_object *obj,
3446 const struct lu_buf *buf,
3448 int fl, struct thandle *handle);
3450 /* iterate xattrs, but ignore LMA, LMV, and LINKEA if 'skip_linkea' is set. */
3451 static int mdd_iterate_xattrs(const struct lu_env *env,
3452 struct mdd_object *sobj,
3453 struct mdd_object *tobj,
3455 struct thandle *handle,
3458 struct mdd_thread_info *info = mdd_env_info(env);
3460 struct lu_buf list_xbuf;
3461 struct lu_buf xbuf = { NULL };
3470 /* retrieve xattr list from the old object */
3471 list_xsize = mdo_xattr_list(env, sobj, &LU_BUF_NULL);
3472 if (list_xsize == -ENODATA)
3478 lu_buf_check_and_alloc(&info->mti_big_buf, list_xsize);
3479 if (info->mti_big_buf.lb_buf == NULL)
3482 list_xbuf.lb_buf = info->mti_big_buf.lb_buf;
3483 list_xbuf.lb_len = list_xsize;
3484 rc = mdo_xattr_list(env, sobj, &list_xbuf);
3490 xname = list_xbuf.lb_buf;
3492 xlen = strnlen(xname, rem - 1) + 1;
3493 if (strcmp(XATTR_NAME_LMA, xname) == 0 ||
3494 strcmp(XATTR_NAME_LMV, xname) == 0)
3498 strcmp(XATTR_NAME_LINK, xname) == 0)
3501 xsize = mdo_xattr_get(env, sobj, &LU_BUF_NULL, xname);
3502 if (xsize == -ENODATA)
3505 GOTO(out, rc = xsize);
3507 lu_buf_check_and_alloc(&xbuf, xsize);
3508 if (xbuf.lb_buf == NULL)
3509 GOTO(out, rc = -ENOMEM);
3511 rc = mdo_xattr_get(env, sobj, &xbuf, xname);
3518 rc = cb(env, tobj, &xbuf, xname, 0, handle);
3519 if (unlikely(rc == -ENOSPC &&
3520 strcmp(xname, XATTR_NAME_LINK) == 0)) {
3521 rc = linkea_overflow_shrink(
3522 (struct linkea_data *)(xbuf.lb_buf));
3523 if (likely(rc > 0)) {
3541 typedef int (*mdd_linkea_cb)(const struct lu_env *env,
3542 struct mdd_object *sobj,
3543 struct mdd_object *tobj,
3544 const struct lu_name *sname,
3545 const struct lu_fid *sfid,
3546 const struct lu_name *lname,
3547 const struct lu_fid *fid,
3549 struct thandle *handle);
3551 static int mdd_declare_update_link(const struct lu_env *env,
3552 struct mdd_object *sobj,
3553 struct mdd_object *tobj,
3554 const struct lu_name *tname,
3555 const struct lu_fid *tpfid,
3556 const struct lu_name *lname,
3557 const struct lu_fid *fid,
3559 struct thandle *handle)
3561 struct mdd_device *mdd = mdo2mdd(&sobj->mod_obj);
3562 struct mdd_object *pobj;
3566 if (lu_fid_eq(tpfid, fid) && tname->ln_namelen == lname->ln_namelen &&
3567 !strcmp(tname->ln_name, lname->ln_name))
3570 pobj = mdd_object_find(env, mdd, fid);
3572 return PTR_ERR(pobj);
3575 rc = mdo_declare_index_delete(env, pobj, lname->ln_name, handle);
3577 rc = mdo_declare_index_insert(env, pobj, mdo2fid(tobj),
3578 mdd_object_type(sobj),
3579 lname->ln_name, handle);
3580 mdd_object_put(env, pobj);
3584 rc = mdo_declare_ref_add(env, tobj, handle);
3588 rc = mdo_declare_ref_del(env, sobj, handle);
3592 static int mdd_update_link(const struct lu_env *env,
3593 struct mdd_object *sobj,
3594 struct mdd_object *tobj,
3595 const struct lu_name *tname,
3596 const struct lu_fid *tpfid,
3597 const struct lu_name *lname,
3598 const struct lu_fid *fid,
3600 struct thandle *handle)
3602 struct mdd_device *mdd = mdo2mdd(&sobj->mod_obj);
3603 struct mdd_object *pobj;
3608 LASSERT(lu_name_is_valid(lname));
3611 if (lu_fid_eq(tpfid, fid) && tname->ln_namelen == lname->ln_namelen &&
3612 !strncmp(tname->ln_name, lname->ln_name, lname->ln_namelen))
3615 CDEBUG(D_INFO, "update "DFID"/"DNAME":"DFID"\n",
3616 PFID(fid), PNAME(lname), PFID(mdo2fid(tobj)));
3618 pobj = mdd_object_find(env, mdd, fid);
3620 CWARN("%s: cannot find obj "DFID": %ld\n",
3621 mdd2obd_dev(mdd)->obd_name, PFID(fid), PTR_ERR(pobj));
3622 RETURN(PTR_ERR(pobj));
3625 if (!mdd_object_exists(pobj)) {
3626 CDEBUG(D_INFO, DFID" doesn't exist\n", PFID(fid));
3627 mdd_object_put(env, pobj);
3631 mdd_write_lock(env, pobj, MOR_TGT_PARENT);
3632 rc = __mdd_index_delete_only(env, pobj, lname->ln_name, handle);
3634 rc = __mdd_index_insert_only(env, pobj, mdo2fid(tobj),
3635 mdd_object_type(sobj),
3636 lname->ln_name, handle);
3637 mdd_write_unlock(env, pobj);
3638 mdd_object_put(env, pobj);
3642 mdd_write_lock(env, tobj, MOR_TGT_CHILD);
3643 rc = mdo_ref_add(env, tobj, handle);
3644 mdd_write_unlock(env, tobj);
3648 mdd_write_lock(env, sobj, MOR_SRC_CHILD);
3649 rc = mdo_ref_del(env, sobj, handle);
3650 mdd_write_unlock(env, sobj);
3655 static inline int mdd_fld_lookup(const struct lu_env *env,
3656 struct mdd_device *mdd,
3657 const struct lu_fid *fid,
3660 struct lu_seq_range *range = &mdd_env_info(env)->mti_range;
3661 struct seq_server_site *ss;
3664 ss = mdd->mdd_md_dev.md_lu_dev.ld_site->ld_seq_site;
3666 range->lsr_flags = LU_SEQ_RANGE_MDT;
3667 rc = fld_server_lookup(env, ss->ss_server_fld, fid->f_seq, range);
3671 *mdt_index = range->lsr_index;
3676 static int mdd_is_link_on_source_mdt(const struct lu_env *env,
3677 struct mdd_object *sobj,
3678 struct mdd_object *tobj,
3679 const struct lu_name *tname,
3680 const struct lu_fid *tpfid,
3681 const struct lu_name *lname,
3682 const struct lu_fid *fid,
3684 struct thandle *handle)
3686 struct mdd_device *mdd = mdo2mdd(&sobj->mod_obj);
3687 __u32 source_mdt_index = *(__u32 *)opaque;
3688 __u32 link_mdt_index;
3694 if (lu_fid_eq(tpfid, fid) && tname->ln_namelen == lname->ln_namelen &&
3695 !strcmp(tname->ln_name, lname->ln_name))
3698 rc = mdd_fld_lookup(env, mdd, fid, &link_mdt_index);
3702 RETURN(link_mdt_index == source_mdt_index);
3705 static int mdd_iterate_linkea(const struct lu_env *env,
3706 struct mdd_object *sobj,
3707 struct mdd_object *tobj,
3708 const struct lu_name *tname,
3709 const struct lu_fid *tpfid,
3710 struct linkea_data *ldata,
3712 struct thandle *handle,
3715 struct mdd_thread_info *info = mdd_env_info(env);
3716 char *filename = info->mti_name;
3717 struct lu_name lname;
3724 for (linkea_first_entry(ldata); ldata->ld_lee && !rc;
3725 linkea_next_entry(ldata)) {
3726 linkea_entry_unpack(ldata->ld_lee, &ldata->ld_reclen, &lname,
3729 /* Note: lname might miss \0 at the end */
3730 snprintf(filename, sizeof(info->mti_name), "%.*s",
3731 lname.ln_namelen, lname.ln_name);
3732 lname.ln_name = filename;
3734 CDEBUG(D_INFO, DFID"/"DNAME"\n", PFID(&fid), PNAME(&lname));
3736 rc = cb(env, sobj, tobj, tname, tpfid, &lname, &fid, opaque,
3744 * Prepare linkea, and check whether file needs migrate: if source still has
3745 * link on source MDT, no need to migrate, just update namespace on source and
3748 * \retval 0 do migrate
3749 * \retval 1 don't migrate
3750 * \retval -errno on failure
3752 static int migrate_linkea_prepare(const struct lu_env *env,
3753 struct mdd_device *mdd,
3754 struct mdd_object *spobj,
3755 struct mdd_object *tpobj,
3756 struct mdd_object *sobj,
3757 const struct lu_name *lname,
3758 const struct lu_attr *attr,
3759 struct linkea_data *ldata)
3761 __u32 source_mdt_index;
3766 memset(ldata, 0, sizeof(*ldata));
3767 rc = mdd_linkea_prepare(env, sobj, mdo2fid(spobj), lname,
3768 mdo2fid(tpobj), lname, 1, 0, ldata);
3773 * Then it will check if the file should be migrated. If the file has
3774 * mulitple links, we only need migrate the file if all of its entries
3775 * has been migrated to the remote MDT.
3777 if (S_ISDIR(attr->la_mode) || attr->la_nlink < 2)
3780 /* If there are still links locally, don't migrate this file */
3781 LASSERT(ldata->ld_leh != NULL);
3784 * If linkEA is overflow, it means there are some unknown name entries
3785 * under unknown parents, which will prevent the migration.
3787 if (unlikely(ldata->ld_leh->leh_overflow_time))
3790 rc = mdd_fld_lookup(env, mdd, mdo2fid(sobj), &source_mdt_index);
3794 rc = mdd_iterate_linkea(env, sobj, NULL, lname, mdo2fid(tpobj), ldata,
3795 &source_mdt_index, NULL,
3796 mdd_is_link_on_source_mdt);
3800 static int mdd_dir_declare_layout_delete(const struct lu_env *env,
3801 struct mdd_object *obj,
3802 const struct lu_buf *lmv_buf,
3803 const struct lu_buf *lmu_buf,
3804 struct thandle *handle)
3808 if (!lmv_buf->lb_buf)
3809 rc = mdo_declare_index_delete(env, obj, dotdot, handle);
3810 else if (mdd_object_remote(obj))
3811 rc = mdd_dir_iterate_stripes(env, obj, lmv_buf, lmu_buf, handle,
3812 mdd_dir_declare_delete_stripe);
3814 rc = mdo_declare_xattr_set(env, obj, lmu_buf,
3815 XATTR_NAME_LMV".del", 0, handle);
3820 static int mdd_dir_layout_delete(const struct lu_env *env,
3821 struct mdd_object *obj,
3822 const struct lu_buf *lmv_buf,
3823 const struct lu_buf *lmu_buf,
3824 struct thandle *handle)
3830 mdd_write_lock(env, obj, MOR_SRC_PARENT);
3831 if (!lmv_buf->lb_buf)
3833 rc = __mdd_index_delete_only(env, obj, dotdot, handle);
3834 else if (mdd_object_remote(obj))
3835 /* striped, but remote */
3836 rc = mdd_dir_iterate_stripes(env, obj, lmv_buf, lmu_buf, handle,
3837 mdd_dir_delete_stripe);
3839 rc = mdo_xattr_set(env, obj, lmu_buf, XATTR_NAME_LMV".del", 0,
3841 mdd_write_unlock(env, obj);
3846 static int mdd_declare_migrate_create(const struct lu_env *env,
3847 struct mdd_object *tpobj,
3848 struct mdd_object *sobj,
3849 struct mdd_object *tobj,
3850 const struct lu_name *lname,
3851 struct lu_attr *attr,
3852 struct lu_buf *sbuf,
3853 struct linkea_data *ldata,
3854 struct md_op_spec *spec,
3855 struct dt_allocation_hint *hint,
3856 struct thandle *handle)
3858 struct mdd_thread_info *info = mdd_env_info(env);
3859 struct lmv_mds_md_v1 *lmv = sbuf->lb_buf;
3862 if (S_ISDIR(attr->la_mode)) {
3863 struct lu_buf lmu_buf = { NULL };
3866 struct lmv_user_md *lmu = &info->mti_lmv.lmv_user_md;
3868 lmu->lum_stripe_count = 0;
3869 lmu_buf.lb_buf = lmu;
3870 lmu_buf.lb_len = sizeof(*lmu);
3873 rc = mdd_dir_declare_layout_delete(env, sobj, sbuf, &lmu_buf,
3879 rc = mdo_declare_xattr_del(env, sobj, XATTR_NAME_LMV,
3886 rc = mdd_declare_create(env, mdo2mdd(&tpobj->mod_obj), tpobj, tobj,
3887 lname, attr, handle, spec, ldata, NULL, NULL,
3892 if (S_ISDIR(attr->la_mode) && mdd_dir_is_empty(env, sobj) != 0) {
3895 * if sobj is not striped, fake a 1-stripe LMV, which
3896 * will be used to generate a compound LMV for tobj.
3898 LASSERT(sizeof(info->mti_key) >
3899 lmv_mds_md_size(1, LMV_MAGIC_V1));
3900 lmv = (typeof(lmv))info->mti_key;
3901 memset(lmv, 0, sizeof(*lmv));
3902 lmv->lmv_magic = cpu_to_le32(LMV_MAGIC_V1);
3903 lmv->lmv_stripe_count = cpu_to_le32(1);
3904 fid_le_to_cpu(&lmv->lmv_stripe_fids[0], mdo2fid(sobj));
3906 sbuf->lb_len = lmv_mds_md_size(1, LMV_MAGIC_V1);
3908 rc = mdo_declare_xattr_set(env, tobj, sbuf,
3909 XATTR_NAME_LMV".add", 0,
3911 sbuf->lb_buf = NULL;
3914 rc = mdo_declare_xattr_set(env, tobj, sbuf,
3915 XATTR_NAME_LMV".add", 0,
3923 * tobj mode will be used in lod_declare_xattr_set(), but it's not
3924 * createb yet, copy from sobj.
3926 tobj->mod_obj.mo_lu.lo_header->loh_attr &= ~S_IFMT;
3927 tobj->mod_obj.mo_lu.lo_header->loh_attr |=
3928 sobj->mod_obj.mo_lu.lo_header->loh_attr & S_IFMT;
3930 rc = mdd_iterate_xattrs(env, sobj, tobj, true, handle,
3931 mdo_declare_xattr_set);
3935 if (S_ISREG(attr->la_mode)) {
3936 struct lu_buf fid_buf;
3938 handle->th_complex = 1;
3940 /* target may be remote, update PFID via sobj. */
3941 fid_buf.lb_buf = (void *)mdo2fid(tobj);
3942 fid_buf.lb_len = sizeof(struct lu_fid);
3943 rc = mdo_declare_xattr_set(env, sobj, &fid_buf, XATTR_NAME_FID,
3948 rc = mdo_declare_xattr_del(env, sobj, XATTR_NAME_LOV, handle);
3953 if (!S_ISDIR(attr->la_mode)) {
3954 rc = mdd_iterate_linkea(env, sobj, tobj, lname, mdo2fid(tpobj),
3955 ldata, NULL, handle,
3956 mdd_declare_update_link);
3961 rc = mdo_declare_xattr_del(env, sobj, XATTR_NAME_LMV,
3972 * Create target, migrate xattrs and update links.
3974 * Create target according to \a spec, and then migrate xattrs, if it's
3975 * directory, migrate source stripes to target, else update fid to target
3978 * \param[in] env execution environment
3979 * \param[in] tpobj target parent object
3980 * \param[in] sobj source object
3981 * \param[in] tobj target object
3982 * \param[in] lname file name
3983 * \param[in] attr source attributes
3984 * \param[in] sbuf source LMV buf
3985 * \param[in] ldata source linkea
3986 * \param[in] spec migrate create spec
3987 * \param[in] hint target creation hint
3988 * \param[in] handle tranasction handle
3990 * \retval 0 on success
3991 * \retval -errno on failure
3993 static int mdd_migrate_create(const struct lu_env *env,
3994 struct mdd_object *tpobj,
3995 struct mdd_object *sobj,
3996 struct mdd_object *tobj,
3997 const struct lu_name *lname,
3998 struct lu_attr *attr,
3999 const struct lu_buf *sbuf,
4000 struct linkea_data *ldata,
4001 struct md_op_spec *spec,
4002 struct dt_allocation_hint *hint,
4003 struct thandle *handle)
4010 * directory will migrate sobj stripes to tobj:
4011 * 1. delete stripes from sobj.
4012 * 2. add stripes to tobj, see lod_dir_declare_layout_add().
4013 * 3. create/attach stripes for tobj, see lod_xattr_set_lmv().
4015 if (S_ISDIR(attr->la_mode)) {
4016 struct lu_buf lmu_buf = { NULL };
4019 struct mdd_thread_info *info = mdd_env_info(env);
4020 struct lmv_user_md *lmu = &info->mti_lmv.lmv_user_md;
4022 lmu->lum_stripe_count = 0;
4023 lmu_buf.lb_buf = lmu;
4024 lmu_buf.lb_len = sizeof(*lmu);
4027 rc = mdd_dir_layout_delete(env, sobj, sbuf, &lmu_buf, handle);
4032 * delete LMV so that later when destroying sobj it won't delete
4036 mdd_write_lock(env, sobj, MOR_SRC_CHILD);
4037 rc = mdo_xattr_del(env, sobj, XATTR_NAME_LMV, handle);
4038 mdd_write_unlock(env, sobj);
4044 /* don't set nlink from sobj */
4045 attr->la_valid &= ~LA_NLINK;
4047 rc = mdd_create_object(env, tpobj, tobj, attr, spec, NULL, NULL, hint,
4052 mdd_write_lock(env, tobj, MOR_TGT_CHILD);
4053 rc = mdd_iterate_xattrs(env, sobj, tobj, true, handle, mdo_xattr_set);
4054 mdd_write_unlock(env, tobj);
4058 /* for regular file, update OST objects XATTR_NAME_FID */
4059 if (S_ISREG(attr->la_mode)) {
4060 struct lu_buf fid_buf;
4062 /* target may be remote, update PFID via sobj. */
4063 fid_buf.lb_buf = (void *)mdo2fid(tobj);
4064 fid_buf.lb_len = sizeof(struct lu_fid);
4065 rc = mdo_xattr_set(env, sobj, &fid_buf, XATTR_NAME_FID, 0,
4070 /* delete LOV to avoid deleting OST objs when destroying sobj */
4071 mdd_write_lock(env, sobj, MOR_SRC_CHILD);
4072 rc = mdo_xattr_del(env, sobj, XATTR_NAME_LOV, handle);
4073 mdd_write_unlock(env, sobj);
4078 if (!S_ISDIR(attr->la_mode))
4079 rc = mdd_iterate_linkea(env, sobj, tobj, lname, mdo2fid(tpobj),
4080 ldata, NULL, handle, mdd_update_link);
4085 static int mdd_declare_migrate_update(const struct lu_env *env,
4086 struct mdd_object *spobj,
4087 struct mdd_object *tpobj,
4088 struct mdd_object *sobj,
4089 struct mdd_object *tobj,
4090 const struct lu_name *lname,
4091 struct lu_attr *attr,
4092 struct lu_attr *spattr,
4093 struct lu_attr *tpattr,
4094 struct linkea_data *ldata,
4098 struct thandle *handle)
4100 struct mdd_thread_info *info = mdd_env_info(env);
4101 const struct lu_fid *fid = mdo2fid(do_create ? tobj : sobj);
4102 struct lu_attr *la = &info->mti_la_for_fix;
4105 rc = mdo_declare_index_delete(env, spobj, lname->ln_name, handle);
4109 if (S_ISDIR(attr->la_mode)) {
4110 rc = mdo_declare_ref_del(env, spobj, handle);
4115 rc = mdo_declare_index_insert(env, tpobj, fid, mdd_object_type(sobj),
4116 lname->ln_name, handle);
4120 rc = mdd_declare_links_add(env, do_create ? tobj : sobj, handle, ldata);
4124 if (S_ISDIR(attr->la_mode)) {
4125 rc = mdo_declare_ref_add(env, tpobj, handle);
4130 la->la_valid = LA_CTIME | LA_MTIME;
4131 rc = mdo_declare_attr_set(env, spobj, la, handle);
4135 if (tpobj != spobj) {
4136 rc = mdo_declare_attr_set(env, tpobj, la, handle);
4141 if (do_create && do_destroy) {
4142 rc = mdo_declare_ref_del(env, sobj, handle);
4146 rc = mdo_declare_destroy(env, sobj, handle);
4155 * migrate dirent from \a spobj to \a tpobj, and destroy \a sobj
4157 static int mdd_migrate_update(const struct lu_env *env,
4158 struct mdd_object *spobj,
4159 struct mdd_object *tpobj,
4160 struct mdd_object *sobj,
4161 struct mdd_object *tobj,
4162 const struct lu_name *lname,
4163 struct lu_attr *attr,
4164 struct lu_attr *spattr,
4165 struct lu_attr *tpattr,
4166 struct linkea_data *ldata,
4170 struct thandle *handle)
4172 struct mdd_thread_info *info = mdd_env_info(env);
4173 const struct lu_fid *fid = mdo2fid(do_create ? tobj : sobj);
4174 struct lu_attr *la = &info->mti_la_for_fix;
4179 CDEBUG(D_INFO, "update %s "DFID"/"DFID" to "DFID"/"DFID"\n",
4180 lname->ln_name, PFID(mdo2fid(spobj)),
4181 PFID(mdo2fid(sobj)), PFID(mdo2fid(tpobj)),
4184 rc = __mdd_index_delete(env, spobj, lname->ln_name,
4185 S_ISDIR(attr->la_mode), handle);
4189 rc = __mdd_index_insert(env, tpobj, fid, mdd_object_type(sobj),
4190 lname->ln_name, handle);
4194 rc = mdd_links_write(env, do_create ? tobj : sobj, ldata, handle);
4198 la->la_ctime = la->la_mtime = ma->ma_attr.la_ctime;
4199 la->la_valid = LA_CTIME | LA_MTIME;
4200 mdd_write_lock(env, spobj, MOR_SRC_PARENT);
4201 rc = mdd_update_time(env, spobj, spattr, la, handle);
4202 mdd_write_unlock(env, spobj);
4206 if (tpobj != spobj) {
4207 la->la_valid = LA_CTIME | LA_MTIME;
4208 mdd_write_lock(env, tpobj, MOR_TGT_PARENT);
4209 rc = mdd_update_time(env, tpobj, tpattr, la, handle);
4210 mdd_write_unlock(env, tpobj);
4216 * there are three situations we shouldn't destroy source:
4217 * 1. if source is not dir, and it happens to be located on the same MDT
4219 * 2. if source is not dir, and has link on the same MDT where source is
4221 * 3. if source is dir, and it's a normal, non-empty dir.
4223 * the first two situations equals to !do_create, and the 3rd equals to
4224 * !do_destroy, so the below condition is actually
4225 * !(!do_create || !do_destroy).
4227 * NB, if user has opened source dir before migration, he will get
4228 * -ENOENT error when close it later, because source is likely to be
4229 * remote, which can't be moved to orphan list, but except this error
4230 * message, this won't cause any inconsistency or trouble.
4232 if (do_create && do_destroy) {
4233 mdd_write_lock(env, sobj, MOR_SRC_CHILD);
4234 mdo_ref_del(env, sobj, handle);
4235 rc = mdo_destroy(env, sobj, handle);
4236 mdd_write_unlock(env, sobj);
4243 * Migrate directory or file.
4245 * migrate source to target in following steps:
4246 * 1. create target, append source stripes after target's if it's directory,
4247 * migrate xattrs and update fid of source links.
4248 * 2. update namespace: migrate dirent from source parent to target parent,
4249 * update file linkea, and destroy source if it's not needed any more.
4251 * \param[in] env execution environment
4252 * \param[in] md_pobj parent master object
4253 * \param[in] md_sobj source object
4254 * \param[in] lname file name
4255 * \param[in] md_tobj target object
4256 * \param[in] spec target creation spec
4257 * \param[in] ma used to update \a pobj mtime and ctime
4259 * \retval 0 on success
4260 * \retval -errno on failure
4262 static int mdd_migrate(const struct lu_env *env, struct md_object *md_pobj,
4263 struct md_object *md_sobj, const struct lu_name *lname,
4264 struct md_object *md_tobj, struct md_op_spec *spec,
4267 struct mdd_device *mdd = mdo2mdd(md_pobj);
4268 struct mdd_thread_info *info = mdd_env_info(env);
4269 struct mdd_object *pobj = md2mdd_obj(md_pobj);
4270 struct mdd_object *sobj = md2mdd_obj(md_sobj);
4271 struct mdd_object *tobj = md2mdd_obj(md_tobj);
4272 struct mdd_object *spobj = NULL;
4273 struct mdd_object *tpobj = NULL;
4274 struct lu_attr *spattr = &info->mti_pattr;
4275 struct lu_attr *tpattr = &info->mti_tpattr;
4276 struct lu_attr *attr = &info->mti_cattr;
4277 struct linkea_data *ldata = &info->mti_link_data;
4278 struct dt_allocation_hint *hint = &info->mti_hint;
4279 struct lu_fid *fid = &info->mti_fid2;
4280 struct lu_buf pbuf = { NULL };
4281 struct lu_buf sbuf = { NULL };
4282 struct lmv_mds_md_v1 *plmv;
4283 struct thandle *handle;
4284 bool do_create = true;
4285 bool do_destroy = true;
4289 rc = mdd_la_get(env, sobj, attr);
4293 /* locate source and target stripe on pobj, which are the real parent */
4294 rc = mdd_stripe_get(env, pobj, &pbuf, XATTR_NAME_LMV);
4295 if (rc < 0 && rc != -ENODATA)
4300 __u32 hash_type = le32_to_cpu(plmv->lmv_hash_type);
4301 __u32 count = le32_to_cpu(plmv->lmv_stripe_count);
4304 /* locate target parent stripe */
4305 if (hash_type & LMV_HASH_FLAG_MIGRATION) {
4307 * fail check here to make sure top dir migration
4310 if (OBD_FAIL_CHECK_RESET(OBD_FAIL_MIGRATE_ENTRIES, 0))
4311 GOTO(out, rc = -EIO);
4312 hash_type &= ~LMV_HASH_FLAG_MIGRATION;
4313 count = le32_to_cpu(plmv->lmv_migrate_offset);
4315 index = lmv_name_to_stripe_index(hash_type, count,
4319 GOTO(out, rc = index);
4321 fid_le_to_cpu(fid, &plmv->lmv_stripe_fids[index]);
4322 tpobj = mdd_object_find(env, mdd, fid);
4324 GOTO(out, rc = PTR_ERR(tpobj));
4326 /* locate source parent stripe */
4327 if (le32_to_cpu(plmv->lmv_hash_type) &
4328 LMV_HASH_FLAG_MIGRATION) {
4329 hash_type = le32_to_cpu(plmv->lmv_migrate_hash);
4330 count = le32_to_cpu(plmv->lmv_stripe_count) -
4331 le32_to_cpu(plmv->lmv_migrate_offset);
4333 index = lmv_name_to_stripe_index(hash_type, count,
4337 mdd_object_put(env, tpobj);
4338 GOTO(out, rc = index);
4341 index += le32_to_cpu(plmv->lmv_migrate_offset);
4342 fid_le_to_cpu(fid, &plmv->lmv_stripe_fids[index]);
4343 spobj = mdd_object_find(env, mdd, fid);
4344 if (IS_ERR(spobj)) {
4345 mdd_object_put(env, tpobj);
4346 GOTO(out, rc = PTR_ERR(spobj));
4350 mdd_object_get(spobj);
4355 mdd_object_get(tpobj);
4356 mdd_object_get(spobj);
4359 rc = mdd_la_get(env, spobj, spattr);
4363 rc = mdd_la_get(env, tpobj, tpattr);
4367 if (S_ISDIR(attr->la_mode)) {
4368 struct lmv_user_md_v1 *lmu = spec->u.sp_ea.eadata;
4373 * if user use default value '0' for stripe_count, we need to
4374 * adjust it to '1' to create a 1-stripe directory.
4376 if (lmu->lum_stripe_count == 0) {
4377 /* eadata is from request, don't alter it */
4378 info->mti_lmu = *lmu;
4379 info->mti_lmu.lum_stripe_count = cpu_to_le32(1);
4380 spec->u.sp_ea.eadata = &info->mti_lmu;
4381 lmu = spec->u.sp_ea.eadata;
4384 rc = mdd_stripe_get(env, sobj, &sbuf, XATTR_NAME_LMV);
4385 if (rc == -ENODATA) {
4386 if (mdd_dir_is_empty(env, sobj) == 0) {
4388 * if sobj is empty, and target is not striped,
4389 * create target as a normal directory.
4391 if (le32_to_cpu(lmu->lum_stripe_count) == 1) {
4392 info->mti_lmu = *lmu;
4393 info->mti_lmu.lum_stripe_count = 0;
4394 spec->u.sp_ea.eadata = &info->mti_lmu;
4395 lmu = spec->u.sp_ea.eadata;
4399 * sobj is not striped dir, if it's not empty,
4400 * it will be migrated to be a stripe of target,
4401 * don't destroy it after migration.
4408 struct lmv_mds_md_v1 *lmv = sbuf.lb_buf;
4410 if (le32_to_cpu(lmv->lmv_hash_type) &
4411 LMV_HASH_FLAG_MIGRATION) {
4412 __u32 lum_stripe_count = lmu->lum_stripe_count;
4413 __u32 lmv_hash_type = lmv->lmv_hash_type &
4414 cpu_to_le32(LMV_HASH_TYPE_MASK);
4416 if (!lum_stripe_count)
4417 lum_stripe_count = cpu_to_le32(1);
4419 /* TODO: check specific MDTs */
4420 if (lmv->lmv_migrate_offset !=
4422 lmv->lmv_master_mdt_index !=
4423 lmu->lum_stripe_offset ||
4424 (lmv_hash_type != 0 &&
4425 lmv_hash_type != lmu->lum_hash_type)) {
4426 CERROR("%s: \'"DNAME"\' migration was "
4427 "interrupted, run \'lfs migrate "
4428 "-m %d -c %d -H %d "DNAME"\' to "
4429 "finish migration.\n",
4430 mdd2obd_dev(mdd)->obd_name,
4433 lmv->lmv_master_mdt_index),
4435 lmv->lmv_migrate_offset),
4436 le32_to_cpu(lmv_hash_type),
4438 GOTO(out, rc = -EPERM);
4440 GOTO(out, rc = -EALREADY);
4443 } else if (!mdd_object_remote(tpobj)) {
4445 * if source is already on MDT where target parent is located,
4446 * no need to create, just update namespace.
4449 } else if (S_ISLNK(attr->la_mode)) {
4450 lu_buf_check_and_alloc(&sbuf, attr->la_size + 1);
4452 GOTO(out, rc = -ENOMEM);
4453 rc = mdd_readlink(env, &sobj->mod_obj, &sbuf);
4456 CERROR("%s: "DFID" readlink failed: rc = %d\n",
4457 mdd2obd_dev(mdd)->obd_name,
4458 PFID(mdo2fid(sobj)), rc);
4461 spec->u.sp_symname = sbuf.lb_buf;
4462 } else if (S_ISREG(attr->la_mode)) {
4463 spec->sp_cr_flags |= MDS_OPEN_DELAY_CREATE;
4464 spec->sp_cr_flags &= ~MDS_OPEN_HAS_EA;
4468 * if sobj has link on the same MDT, no need to create, just update
4469 * namespace, and it will be a remote file on target parent, which is
4470 * similar to rename.
4472 rc = migrate_linkea_prepare(env, mdd, spobj, tpobj, sobj, lname, attr,
4479 rc = mdd_migrate_sanity_check(env, mdd, spobj, tpobj, sobj, tobj,
4480 spattr, tpattr, attr);
4484 mdd_object_make_hint(env, NULL, tobj, attr, spec, hint);
4486 handle = mdd_trans_create(env, mdd);
4488 GOTO(out, rc = PTR_ERR(handle));
4491 rc = mdd_declare_migrate_create(env, tpobj, sobj, tobj, lname,
4492 attr, &sbuf, ldata, spec, hint,
4495 GOTO(stop_trans, rc);
4498 rc = mdd_declare_migrate_update(env, spobj, tpobj, sobj, tobj, lname,
4499 attr, spattr, tpattr, ldata, do_create,
4500 do_destroy, ma, handle);
4502 GOTO(stop_trans, rc);
4504 rc = mdd_declare_changelog_store(env, mdd, CL_MIGRATE, lname, NULL,
4507 GOTO(stop_trans, rc);
4509 rc = mdd_trans_start(env, mdd, handle);
4511 GOTO(stop_trans, rc);
4514 rc = mdd_migrate_create(env, tpobj, sobj, tobj, lname, attr,
4515 &sbuf, ldata, spec, hint, handle);
4517 GOTO(stop_trans, rc);
4520 rc = mdd_migrate_update(env, spobj, tpobj, sobj, tobj, lname, attr,
4521 spattr, tpattr, ldata, do_create, do_destroy,
4524 GOTO(stop_trans, rc);
4526 rc = mdd_changelog_ns_store(env, mdd, CL_MIGRATE, 0, tobj,
4527 mdo2fid(spobj), mdo2fid(sobj),
4528 mdo2fid(tpobj), lname, lname, handle);
4530 GOTO(stop_trans, rc);
4534 rc = mdd_trans_stop(env, mdd, rc, handle);
4536 if (spobj && !IS_ERR(spobj))
4537 mdd_object_put(env, spobj);
4538 if (tpobj && !IS_ERR(tpobj))
4539 mdd_object_put(env, tpobj);
4545 static int __mdd_dir_declare_layout_shrink(const struct lu_env *env,
4546 struct mdd_object *pobj,
4547 struct mdd_object *obj,
4548 struct mdd_object *stripe,
4549 struct lu_attr *attr,
4550 struct lu_buf *lmv_buf,
4551 const struct lu_buf *lmu_buf,
4552 struct lu_name *lname,
4553 struct thandle *handle)
4555 struct mdd_thread_info *info = mdd_env_info(env);
4556 struct lmv_mds_md_v1 *lmv = lmv_buf->lb_buf;
4557 struct lmv_user_md *lmu = (typeof(lmu))info->mti_key;
4558 struct lu_buf shrink_buf = { .lb_buf = lmu,
4559 .lb_len = sizeof(*lmu) };
4564 memcpy(lmu, lmu_buf->lb_buf, sizeof(*lmu));
4566 if (le32_to_cpu(lmu->lum_stripe_count) < 2)
4567 lmu->lum_stripe_count = 0;
4569 rc = mdd_dir_declare_layout_delete(env, obj, lmv_buf, &shrink_buf,
4574 if (lmu->lum_stripe_count == 0) {
4575 lmu->lum_stripe_count = cpu_to_le32(1);
4577 rc = mdo_declare_xattr_del(env, obj, XATTR_NAME_LMV, handle);
4582 rc = mdd_dir_iterate_stripes(env, obj, lmv_buf, &shrink_buf, handle,
4583 mdd_dir_declare_destroy_stripe);
4587 if (le32_to_cpu(lmu->lum_stripe_count) > 1)
4588 return mdo_declare_xattr_set(env, obj, lmv_buf,
4589 XATTR_NAME_LMV".set", 0, handle);
4591 rc = mdo_declare_index_insert(env, stripe, mdo2fid(pobj), S_IFDIR,
4596 rc = mdd_iterate_xattrs(env, obj, stripe, false, handle,
4597 mdo_declare_xattr_set);
4601 rc = mdo_declare_xattr_del(env, stripe, XATTR_NAME_LMV, handle);
4605 rc = mdo_declare_attr_set(env, stripe, attr, handle);
4609 rc = mdo_declare_index_delete(env, pobj, lname->ln_name, handle);
4613 rc = mdo_declare_index_insert(env, pobj, mdo2fid(stripe), attr->la_mode,
4614 lname->ln_name, handle);
4618 rc = mdo_declare_ref_del(env, obj, handle);
4622 rc = mdo_declare_ref_del(env, obj, handle);
4626 rc = mdo_declare_destroy(env, obj, handle);
4635 * after files under \a obj were migrated, shrink old stripes from \a obj,
4636 * furthermore, if it becomes a 1-stripe directory, convert it to a normal one.
4638 static int __mdd_dir_layout_shrink(const struct lu_env *env,
4639 struct mdd_object *pobj,
4640 struct mdd_object *obj,
4641 struct mdd_object *stripe,
4642 struct lu_attr *attr,
4643 struct lu_buf *lmv_buf,
4644 const struct lu_buf *lmu_buf,
4645 struct lu_name *lname,
4646 struct thandle *handle)
4648 struct mdd_thread_info *info = mdd_env_info(env);
4649 struct lmv_mds_md_v1 *lmv = lmv_buf->lb_buf;
4650 struct lmv_user_md *lmu = (typeof(lmu))info->mti_key;
4651 struct lu_buf shrink_buf = { .lb_buf = lmu,
4652 .lb_len = sizeof(*lmu) };
4653 int len = lmv_buf->lb_len;
4654 __u32 version = le32_to_cpu(lmv->lmv_layout_version);
4659 /* lmu needs to be altered, but lmu_buf is const */
4660 memcpy(lmu, lmu_buf->lb_buf, sizeof(*lmu));
4663 * if dir will be shrunk to 1-stripe, delete all stripes, because it
4664 * will be converted to normal dir.
4666 if (le32_to_cpu(lmu->lum_stripe_count) == 1)
4667 lmu->lum_stripe_count = 0;
4669 /* delete stripes after lmu_stripe_count */
4670 rc = mdd_dir_layout_delete(env, obj, lmv_buf, &shrink_buf, handle);
4674 if (lmu->lum_stripe_count == 0) {
4675 lmu->lum_stripe_count = cpu_to_le32(1);
4677 /* delete LMV to avoid deleting stripes again upon destroy */
4678 mdd_write_lock(env, obj, MOR_SRC_CHILD);
4679 rc = mdo_xattr_del(env, obj, XATTR_NAME_LMV, handle);
4680 mdd_write_unlock(env, obj);
4685 /* destroy stripes after lmu_stripe_count */
4686 mdd_write_lock(env, obj, MOR_SRC_PARENT);
4687 rc = mdd_dir_iterate_stripes(env, obj, lmv_buf, &shrink_buf, handle,
4688 mdd_dir_destroy_stripe);
4689 mdd_write_unlock(env, obj);
4691 if (le32_to_cpu(lmu->lum_stripe_count) > 1) {
4692 /* update dir LMV, that's all if it's still striped. */
4693 lmv->lmv_stripe_count = lmu->lum_stripe_count;
4694 lmv->lmv_hash_type &= ~cpu_to_le32(LMV_HASH_FLAG_MIGRATION);
4695 lmv->lmv_migrate_offset = 0;
4696 lmv->lmv_migrate_hash = 0;
4697 lmv->lmv_layout_version = cpu_to_le32(++version);
4699 lmv_buf->lb_len = sizeof(*lmv);
4700 rc = mdo_xattr_set(env, obj, lmv_buf, XATTR_NAME_LMV".set", 0,
4702 lmv_buf->lb_len = len;
4706 /* replace directory with its remaining stripe */
4710 mdd_write_lock(env, pobj, MOR_SRC_PARENT);
4711 mdd_write_lock(env, obj, MOR_SRC_CHILD);
4713 /* insert dotdot to stripe which points to parent */
4714 rc = __mdd_index_insert_only(env, stripe, mdo2fid(pobj), S_IFDIR,
4719 /* copy xattrs including linkea */
4720 rc = mdd_iterate_xattrs(env, obj, stripe, false, handle, mdo_xattr_set);
4725 rc = mdo_xattr_del(env, stripe, XATTR_NAME_LMV, handle);
4729 /* don't set nlink from parent */
4730 attr->la_valid &= ~LA_NLINK;
4732 rc = mdo_attr_set(env, stripe, attr, handle);
4736 /* delete dir name from parent */
4737 rc = __mdd_index_delete_only(env, pobj, lname->ln_name, handle);
4741 /* insert stripe to parent with dir name */
4742 rc = __mdd_index_insert_only(env, pobj, mdo2fid(stripe), attr->la_mode,
4743 lname->ln_name, handle);
4747 /* destroy dir obj */
4748 rc = mdo_ref_del(env, obj, handle);
4752 rc = mdo_ref_del(env, obj, handle);
4756 rc = mdo_destroy(env, obj, handle);
4762 mdd_write_unlock(env, obj);
4763 mdd_write_unlock(env, pobj);
4769 * shrink directory stripes to lum_stripe_count specified by lum_mds_md.
4771 int mdd_dir_layout_shrink(const struct lu_env *env,
4772 struct md_object *md_obj,
4773 const struct lu_buf *lmu_buf)
4775 struct mdd_device *mdd = mdo2mdd(md_obj);
4776 struct mdd_thread_info *info = mdd_env_info(env);
4777 struct mdd_object *obj = md2mdd_obj(md_obj);
4778 struct mdd_object *pobj = NULL;
4779 struct mdd_object *stripe = NULL;
4780 struct lu_attr *attr = &info->mti_pattr;
4781 struct lu_fid *fid = &info->mti_fid2;
4782 struct lu_name lname = { NULL };
4783 struct lu_buf lmv_buf = { NULL };
4784 struct lmv_mds_md_v1 *lmv;
4785 struct lmv_user_md *lmu;
4786 struct thandle *handle;
4791 rc = mdd_la_get(env, obj, attr);
4795 if (!S_ISDIR(attr->la_mode))
4798 rc = mdd_stripe_get(env, obj, &lmv_buf, XATTR_NAME_LMV);
4802 lmv = lmv_buf.lb_buf;
4803 lmu = lmu_buf->lb_buf;
4805 /* this was checked in MDT */
4806 LASSERT(le32_to_cpu(lmu->lum_stripe_count) <
4807 le32_to_cpu(lmv->lmv_stripe_count));
4809 rc = mdd_dir_iterate_stripes(env, obj, &lmv_buf, lmu_buf, NULL,
4810 mdd_shrink_stripe_is_empty);
4814 GOTO(out, rc = -ENOTEMPTY);
4817 * if obj stripe count will be shrunk to 1, we need to convert it to a
4818 * normal dir, which will change its fid and update parent namespace,
4819 * get obj name and parent fid from linkea.
4821 if (le32_to_cpu(lmu->lum_stripe_count) < 2) {
4822 struct linkea_data *ldata = &info->mti_link_data;
4823 char *filename = info->mti_name;
4825 rc = mdd_links_read(env, obj, ldata);
4829 if (ldata->ld_leh->leh_reccount > 1)
4830 GOTO(out, rc = -EINVAL);
4832 linkea_first_entry(ldata);
4834 GOTO(out, rc = -ENODATA);
4836 linkea_entry_unpack(ldata->ld_lee, &ldata->ld_reclen, &lname,
4839 /* Note: lname might miss \0 at the end */
4840 snprintf(filename, sizeof(info->mti_name), "%.*s",
4841 lname.ln_namelen, lname.ln_name);
4842 lname.ln_name = filename;
4844 pobj = mdd_object_find(env, mdd, fid);
4851 fid_le_to_cpu(fid, &lmv->lmv_stripe_fids[0]);
4853 stripe = mdd_object_find(env, mdd, fid);
4854 if (IS_ERR(stripe)) {
4855 mdd_object_put(env, pobj);
4857 GOTO(out, rc = PTR_ERR(stripe));
4861 handle = mdd_trans_create(env, mdd);
4863 GOTO(out, rc = PTR_ERR(handle));
4865 rc = __mdd_dir_declare_layout_shrink(env, pobj, obj, stripe, attr,
4866 &lmv_buf, lmu_buf, &lname, handle);
4868 GOTO(stop_trans, rc);
4870 rc = mdd_declare_changelog_store(env, mdd, CL_LAYOUT, NULL, NULL,
4873 GOTO(stop_trans, rc);
4875 rc = mdd_trans_start(env, mdd, handle);
4877 GOTO(stop_trans, rc);
4879 rc = __mdd_dir_layout_shrink(env, pobj, obj, stripe, attr, &lmv_buf,
4880 lmu_buf, &lname, handle);
4882 GOTO(stop_trans, rc);
4884 rc = mdd_changelog_data_store_xattr(env, mdd, CL_LAYOUT, 0, obj,
4885 XATTR_NAME_LMV, handle);
4886 GOTO(stop_trans, rc);
4889 rc = mdd_trans_stop(env, mdd, rc, handle);
4892 mdd_object_put(env, stripe);
4893 mdd_object_put(env, pobj);
4895 lu_buf_free(&lmv_buf);
4899 const struct md_dir_operations mdd_dir_ops = {
4900 .mdo_is_subdir = mdd_is_subdir,
4901 .mdo_lookup = mdd_lookup,
4902 .mdo_create = mdd_create,
4903 .mdo_rename = mdd_rename,
4904 .mdo_link = mdd_link,
4905 .mdo_unlink = mdd_unlink,
4906 .mdo_create_data = mdd_create_data,
4907 .mdo_migrate = mdd_migrate,