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.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2014, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/mdd/mdd_dir.c
38 * Lustre Metadata Server (mdd) routines
40 * Author: Wang Di <wangdi@intel.com>
43 #define DEBUG_SUBSYSTEM S_MDS
45 #include <obd_class.h>
46 #include <obd_support.h>
47 #include <lustre_mds.h>
48 #include <lustre_fid.h>
50 #include "mdd_internal.h"
52 static const char dot[] = ".";
53 static const char dotdot[] = "..";
55 static struct lu_name lname_dotdot = {
61 mdd_name_check(struct mdd_device *m, const struct lu_name *ln)
63 if (!lu_name_is_valid(ln))
65 else if (ln->ln_namelen > m->mdd_dt_conf.ddp_max_name_len)
71 /* Get FID from name and parent */
73 __mdd_lookup(const struct lu_env *env, struct md_object *pobj,
74 const struct lu_attr *pattr, const struct lu_name *lname,
75 struct lu_fid* fid, int mask)
77 const char *name = lname->ln_name;
78 const struct dt_key *key = (const struct dt_key *)name;
79 struct mdd_object *mdd_obj = md2mdd_obj(pobj);
80 struct mdd_device *m = mdo2mdd(pobj);
81 struct dt_object *dir = mdd_object_child(mdd_obj);
85 if (unlikely(mdd_is_dead_obj(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)));
91 } else if (!mdd_object_exists(mdd_obj)) {
95 rc = mdd_permission_internal_locked(env, mdd_obj, pattr, mask,
100 if (likely(S_ISDIR(mdd_object_type(mdd_obj)) &&
101 dt_try_as_dir(env, dir)))
102 rc = dt_lookup(env, dir, (struct dt_rec *)fid, key);
109 int mdd_lookup(const struct lu_env *env,
110 struct md_object *pobj, const struct lu_name *lname,
111 struct lu_fid *fid, struct md_op_spec *spec)
113 struct lu_attr *pattr = MDD_ENV_VAR(env, pattr);
117 rc = mdd_la_get(env, md2mdd_obj(pobj), pattr);
121 rc = __mdd_lookup(env, pobj, pattr, lname, fid,
122 (spec != NULL && spec->sp_permitted) ? 0 : MAY_EXEC);
126 static inline int mdd_parent_fid(const struct lu_env *env,
127 struct mdd_object *obj,
128 const struct lu_attr *attr,
131 return __mdd_lookup(env, &obj->mod_obj, attr, &lname_dotdot, fid, 0);
135 * For root fid use special function, which does not compare version component
136 * of fid. Version component is different for root fids on all MDTs.
138 int mdd_is_root(struct mdd_device *mdd, const struct lu_fid *fid)
140 return fid_seq(&mdd->mdd_root_fid) == fid_seq(fid) &&
141 fid_oid(&mdd->mdd_root_fid) == fid_oid(fid);
145 * return 1: if lf is the fid of the ancestor of p1;
148 * return -EREMOTE: if remote object is found, in this
149 * case fid of remote object is saved to @pf;
151 * otherwise: values < 0, errors.
153 static int mdd_is_parent(const struct lu_env *env,
154 struct mdd_device *mdd,
155 struct mdd_object *p1,
156 const struct lu_attr *attr,
157 const struct lu_fid *lf,
160 struct mdd_object *parent = NULL;
165 LASSERT(!lu_fid_eq(mdo2fid(p1), lf));
166 pfid = &mdd_env_info(env)->mti_fid;
168 /* Check for root first. */
169 if (mdd_is_root(mdd, mdo2fid(p1)))
173 /* this is done recursively */
174 rc = mdd_parent_fid(env, p1, attr, pfid);
177 if (mdd_is_root(mdd, pfid))
179 if (lu_fid_eq(pfid, &mdd->mdd_local_root_fid))
181 if (lu_fid_eq(pfid, lf))
184 mdd_object_put(env, parent);
186 parent = mdd_object_find(env, mdd, pfid);
187 if (IS_ERR(parent)) {
188 GOTO(out, rc = PTR_ERR(parent));
189 } else if (mdd_object_remote(parent)) {
190 /*FIXME: Because of the restriction of rename in Phase I.
191 * If the parent is remote, we just assumed lf is not the
192 * parent of P1 for now */
199 if (parent && !IS_ERR(parent))
200 mdd_object_put(env, parent);
205 * No permission check is needed.
207 * returns 1: if fid is ancestor of @mo;
208 * returns 0: if fid is not an ancestor of @mo;
210 * returns EREMOTE if remote object is found, fid of remote object is saved to
213 * returns < 0: if error
215 int mdd_is_subdir(const struct lu_env *env, struct md_object *mo,
216 const struct lu_fid *fid, struct lu_fid *sfid)
218 struct mdd_device *mdd = mdo2mdd(mo);
219 struct lu_attr *attr = MDD_ENV_VAR(env, cattr);
223 if (!S_ISDIR(mdd_object_type(md2mdd_obj(mo))))
226 rc = mdd_la_get(env, md2mdd_obj(mo), attr);
230 rc = mdd_is_parent(env, mdd, md2mdd_obj(mo), attr, fid, sfid);
234 } else if (rc == 1) {
235 /* found @fid is parent */
243 * Check that @dir contains no entries except (possibly) dot and dotdot.
248 * -ENOTDIR not a directory object
249 * -ENOTEMPTY not empty
253 static int mdd_dir_is_empty(const struct lu_env *env,
254 struct mdd_object *dir)
257 struct dt_object *obj;
258 const struct dt_it_ops *iops;
262 obj = mdd_object_child(dir);
263 if (!dt_try_as_dir(env, obj))
266 iops = &obj->do_index_ops->dio_it;
267 it = iops->init(env, obj, LUDA_64BITHASH);
269 result = iops->get(env, it, (const struct dt_key *)"");
272 for (result = 0, i = 0; result == 0 && i < 3; ++i)
273 result = iops->next(env, it);
276 else if (result == 1)
278 } else if (result == 0)
280 * Huh? Index contains no zero key?
287 result = PTR_ERR(it);
292 * Determine if the target object can be hard linked, and right now it only
293 * checks if the link count reach the maximum limit. Note: for ldiskfs, the
294 * directory nlink count might exceed the maximum link count(see
295 * osd_object_ref_add), so it only check nlink for non-directories.
297 * \param[in] env thread environment
298 * \param[in] obj object being linked to
299 * \param[in] la attributes of \a obj
301 * \retval 0 if \a obj can be hard linked
302 * \retval negative error if \a obj is a directory or has too
305 static int __mdd_may_link(const struct lu_env *env, struct mdd_object *obj,
306 const struct lu_attr *la)
308 struct mdd_device *m = mdd_obj2mdd_dev(obj);
313 /* Subdir count limitation can be broken through
314 * (see osd_object_ref_add), so only check non-directory here. */
315 if (!S_ISDIR(la->la_mode) &&
316 la->la_nlink >= m->mdd_dt_conf.ddp_max_nlink)
323 * Check whether it may create the cobj under the pobj.
325 * \param[in] env execution environment
326 * \param[in] pobj the parent directory
327 * \param[in] pattr the attribute of the parent directory
328 * \param[in] cobj the child to be created
329 * \param[in] check_perm if check WRITE|EXEC permission for parent
331 * \retval = 0 create the child under this dir is allowed
332 * \retval negative errno create the child under this dir is
335 int mdd_may_create(const struct lu_env *env, struct mdd_object *pobj,
336 const struct lu_attr *pattr, struct mdd_object *cobj,
339 struct mdd_thread_info *info = mdd_env_info(env);
344 if (cobj && mdd_object_exists(cobj))
347 if (mdd_is_dead_obj(pobj))
350 /* If the parent is a sub-stripe, check whether it is dead */
351 xbuf = mdd_buf_get(env, info->mti_key, sizeof(info->mti_key));
352 rc = mdo_xattr_get(env, pobj, xbuf, XATTR_NAME_LMV);
353 if (unlikely(rc > 0)) {
354 struct lmv_mds_md_v1 *lmv1 = xbuf->lb_buf;
356 if (le32_to_cpu(lmv1->lmv_magic) == LMV_MAGIC_STRIPE &&
357 le32_to_cpu(lmv1->lmv_hash_type) & LMV_HASH_FLAG_DEAD)
363 rc = mdd_permission_internal_locked(env, pobj, pattr,
364 MAY_WRITE | MAY_EXEC,
370 * Check whether can unlink from the pobj in the case of "cobj == NULL".
372 int mdd_may_unlink(const struct lu_env *env, struct mdd_object *pobj,
373 const struct lu_attr *pattr, const struct lu_attr *attr)
378 if (mdd_is_dead_obj(pobj))
381 if (attr->la_flags & (LUSTRE_APPEND_FL | LUSTRE_IMMUTABLE_FL))
384 rc = mdd_permission_internal_locked(env, pobj, pattr,
385 MAY_WRITE | MAY_EXEC,
390 if (pattr->la_flags & LUSTRE_APPEND_FL)
397 * pobj == NULL is remote ops case, under such case, pobj's
398 * VTX feature has been checked already, no need check again.
400 static inline int mdd_is_sticky(const struct lu_env *env,
401 struct mdd_object *pobj,
402 const struct lu_attr *pattr,
403 struct mdd_object *cobj,
404 const struct lu_attr *cattr)
406 struct lu_ucred *uc = lu_ucred_assert(env);
409 LASSERT(pattr != NULL);
410 if (!(pattr->la_mode & S_ISVTX) ||
411 (pattr->la_uid == uc->uc_fsuid))
415 LASSERT(cattr != NULL);
416 if (cattr->la_uid == uc->uc_fsuid)
419 return !md_capable(uc, CFS_CAP_FOWNER);
422 static int mdd_may_delete_entry(const struct lu_env *env,
423 struct mdd_object *pobj,
424 const struct lu_attr *pattr,
429 LASSERT(pobj != NULL);
430 if (!mdd_object_exists(pobj))
433 if (mdd_is_dead_obj(pobj))
438 rc = mdd_permission_internal_locked(env, pobj, pattr,
439 MAY_WRITE | MAY_EXEC,
445 if (pattr->la_flags & LUSTRE_APPEND_FL)
452 * Check whether it may delete the cobj from the pobj.
455 int mdd_may_delete(const struct lu_env *env, struct mdd_object *tpobj,
456 const struct lu_attr *tpattr, struct mdd_object *tobj,
457 const struct lu_attr *tattr, const struct lu_attr *cattr,
458 int check_perm, int check_empty)
464 LASSERT(tpattr != NULL);
465 rc = mdd_may_delete_entry(env, tpobj, tpattr, check_perm);
473 if (!mdd_object_exists(tobj))
476 if (mdd_is_dead_obj(tobj))
479 if (mdd_is_sticky(env, tpobj, tpattr, tobj, tattr))
482 if (tattr->la_flags & (LUSTRE_APPEND_FL | LUSTRE_IMMUTABLE_FL))
485 /* additional check the rename case */
487 if (S_ISDIR(cattr->la_mode)) {
488 struct mdd_device *mdd = mdo2mdd(&tobj->mod_obj);
490 if (!S_ISDIR(tattr->la_mode))
493 if (lu_fid_eq(mdo2fid(tobj), &mdd->mdd_root_fid))
495 } else if (S_ISDIR(tattr->la_mode))
499 if (S_ISDIR(tattr->la_mode) && check_empty)
500 rc = mdd_dir_is_empty(env, tobj);
506 * Check whether it can create the link file(linked to @src_obj) under
507 * the target directory(@tgt_obj), and src_obj has been locked by
510 * \param[in] env execution environment
511 * \param[in] tgt_obj the target directory
512 * \param[in] tattr attributes of target directory
513 * \param[in] lname the link name
514 * \param[in] src_obj source object for link
515 * \param[in] cattr attributes for source object
517 * \retval = 0 it is allowed to create the link file under tgt_obj
518 * \retval negative error not allowed to create the link file
520 static int mdd_link_sanity_check(const struct lu_env *env,
521 struct mdd_object *tgt_obj,
522 const struct lu_attr *tattr,
523 const struct lu_name *lname,
524 struct mdd_object *src_obj,
525 const struct lu_attr *cattr)
527 struct mdd_device *m = mdd_obj2mdd_dev(src_obj);
531 if (!mdd_object_exists(src_obj))
534 if (mdd_is_dead_obj(src_obj))
537 /* Local ops, no lookup before link, check filename length here. */
538 rc = mdd_name_check(m, lname);
542 if (cattr->la_flags & (LUSTRE_IMMUTABLE_FL | LUSTRE_APPEND_FL))
545 if (S_ISDIR(mdd_object_type(src_obj)))
548 LASSERT(src_obj != tgt_obj);
549 rc = mdd_may_create(env, tgt_obj, tattr, NULL, true);
553 rc = __mdd_may_link(env, src_obj, cattr);
558 static int __mdd_index_delete_only(const struct lu_env *env, struct mdd_object *pobj,
559 const char *name, struct thandle *handle)
561 struct dt_object *next = mdd_object_child(pobj);
565 if (dt_try_as_dir(env, next))
566 rc = dt_delete(env, next, (struct dt_key *)name, handle);
573 static int __mdd_index_insert_only(const struct lu_env *env,
574 struct mdd_object *pobj,
575 const struct lu_fid *lf, __u32 type,
577 struct thandle *handle)
579 struct dt_object *next = mdd_object_child(pobj);
583 if (dt_try_as_dir(env, next)) {
584 struct dt_insert_rec *rec = &mdd_env_info(env)->mti_dt_rec;
585 struct lu_ucred *uc = lu_ucred_check(env);
589 rec->rec_type = type;
590 ignore_quota = uc ? uc->uc_cap & CFS_CAP_SYS_RESOURCE_MASK : 1;
591 rc = dt_insert(env, next, (const struct dt_rec *)rec,
592 (const struct dt_key *)name, handle,
600 /* insert named index, add reference if isdir */
601 static int __mdd_index_insert(const struct lu_env *env, struct mdd_object *pobj,
602 const struct lu_fid *lf, __u32 type,
603 const char *name, struct thandle *handle)
608 rc = __mdd_index_insert_only(env, pobj, lf, type, name, handle);
609 if (rc == 0 && S_ISDIR(type)) {
610 mdd_write_lock(env, pobj, MOR_TGT_PARENT);
611 mdo_ref_add(env, pobj, handle);
612 mdd_write_unlock(env, pobj);
618 /* delete named index, drop reference if isdir */
619 static int __mdd_index_delete(const struct lu_env *env, struct mdd_object *pobj,
620 const char *name, int is_dir,
621 struct thandle *handle)
626 rc = __mdd_index_delete_only(env, pobj, name, handle);
627 if (rc == 0 && is_dir) {
628 mdd_write_lock(env, pobj, MOR_TGT_PARENT);
629 mdo_ref_del(env, pobj, handle);
630 mdd_write_unlock(env, pobj);
636 static int mdd_llog_record_calc_size(const struct lu_env *env,
637 const struct lu_name *tname,
638 const struct lu_name *sname)
640 const struct lu_ucred *uc = lu_ucred(env);
641 enum changelog_rec_flags crf = 0;
642 size_t hdr_size = sizeof(struct llog_changelog_rec) -
643 sizeof(struct changelog_rec);
648 if (uc != NULL && uc->uc_jobid[0] != '\0')
651 return llog_data_len(hdr_size + changelog_rec_offset(crf) +
652 (tname != NULL ? tname->ln_namelen : 0) +
653 (sname != NULL ? 1 + sname->ln_namelen : 0));
656 int mdd_declare_changelog_store(const struct lu_env *env,
657 struct mdd_device *mdd,
658 const struct lu_name *tname,
659 const struct lu_name *sname,
660 struct thandle *handle)
662 struct obd_device *obd = mdd2obd_dev(mdd);
663 struct llog_ctxt *ctxt;
664 struct llog_changelog_rec *rec;
666 struct thandle *llog_th;
671 if (!(mdd->mdd_cl.mc_flags & CLM_ON))
674 reclen = mdd_llog_record_calc_size(env, tname, sname);
675 buf = lu_buf_check_and_alloc(&mdd_env_info(env)->mti_big_buf, reclen);
676 if (buf->lb_buf == NULL)
680 rec->cr_hdr.lrh_len = reclen;
681 rec->cr_hdr.lrh_type = CHANGELOG_REC;
683 ctxt = llog_get_context(obd, LLOG_CHANGELOG_ORIG_CTXT);
687 llog_th = thandle_get_sub(env, handle, ctxt->loc_handle->lgh_obj);
689 GOTO(out_put, rc = PTR_ERR(llog_th));
691 rc = llog_declare_add(env, ctxt->loc_handle, &rec->cr_hdr, llog_th);
699 /** Add a changelog entry \a rec to the changelog llog
702 * \param handle - currently ignored since llogs start their own transaction;
703 * this will hopefully be fixed in llog rewrite
706 int mdd_changelog_store(const struct lu_env *env, struct mdd_device *mdd,
707 struct llog_changelog_rec *rec, struct thandle *th)
709 struct obd_device *obd = mdd2obd_dev(mdd);
710 struct llog_ctxt *ctxt;
711 struct thandle *llog_th;
714 rec->cr_hdr.lrh_len = llog_data_len(sizeof(*rec) +
715 changelog_rec_varsize(&rec->cr));
717 /* llog_lvfs_write_rec sets the llog tail len */
718 rec->cr_hdr.lrh_type = CHANGELOG_REC;
719 rec->cr.cr_time = cl_time();
721 spin_lock(&mdd->mdd_cl.mc_lock);
722 /* NB: I suppose it's possible llog_add adds out of order wrt cr_index,
723 * but as long as the MDD transactions are ordered correctly for e.g.
724 * rename conflicts, I don't think this should matter. */
725 rec->cr.cr_index = ++mdd->mdd_cl.mc_index;
726 spin_unlock(&mdd->mdd_cl.mc_lock);
728 ctxt = llog_get_context(obd, LLOG_CHANGELOG_ORIG_CTXT);
732 llog_th = thandle_get_sub(env, th, ctxt->loc_handle->lgh_obj);
734 GOTO(out_put, rc = PTR_ERR(llog_th));
736 /* nested journal transaction */
737 rc = llog_add(env, ctxt->loc_handle, &rec->cr_hdr, NULL, llog_th);
746 static void mdd_changelog_rec_ext_rename(struct changelog_rec *rec,
747 const struct lu_fid *sfid,
748 const struct lu_fid *spfid,
749 const struct lu_name *sname)
751 struct changelog_ext_rename *rnm = changelog_rec_rename(rec);
752 size_t extsize = sname->ln_namelen + 1;
754 LASSERT(sfid != NULL);
755 LASSERT(spfid != NULL);
756 LASSERT(sname != NULL);
758 rnm->cr_sfid = *sfid;
759 rnm->cr_spfid = *spfid;
761 changelog_rec_name(rec)[rec->cr_namelen] = '\0';
762 strlcpy(changelog_rec_sname(rec), sname->ln_name, extsize);
763 rec->cr_namelen += extsize;
766 void mdd_changelog_rec_ext_jobid(struct changelog_rec *rec, const char *jobid)
768 struct changelog_ext_jobid *jid = changelog_rec_jobid(rec);
770 if (jobid == NULL || jobid[0] == '\0')
773 strlcpy(jid->cr_jobid, jobid, sizeof(jid->cr_jobid));
776 /** Store a namespace change changelog record
777 * If this fails, we must fail the whole transaction; we don't
778 * want the change to commit without the log entry.
779 * \param target - mdd_object of change
780 * \param tpfid - target parent dir/object fid
781 * \param sfid - source object fid
782 * \param spfid - source parent fid
783 * \param tname - target name string
784 * \param sname - source name string
785 * \param handle - transacion handle
787 int mdd_changelog_ns_store(const struct lu_env *env,
788 struct mdd_device *mdd,
789 enum changelog_rec_type type,
790 enum changelog_rec_flags crf,
791 struct mdd_object *target,
792 const struct lu_fid *tpfid,
793 const struct lu_fid *sfid,
794 const struct lu_fid *spfid,
795 const struct lu_name *tname,
796 const struct lu_name *sname,
797 struct thandle *handle)
799 const struct lu_ucred *uc = lu_ucred(env);
800 struct llog_changelog_rec *rec;
807 if (!(mdd->mdd_cl.mc_flags & CLM_ON))
810 if ((mdd->mdd_cl.mc_mask & (1 << type)) == 0)
813 LASSERT(tpfid != NULL);
814 LASSERT(tname != NULL);
815 LASSERT(handle != NULL);
817 reclen = mdd_llog_record_calc_size(env, tname, sname);
818 buf = lu_buf_check_and_alloc(&mdd_env_info(env)->mti_big_buf, reclen);
819 if (buf->lb_buf == NULL)
825 if (uc != NULL && uc->uc_jobid[0] != '\0')
833 rec->cr.cr_flags = crf;
834 rec->cr.cr_type = (__u32)type;
835 rec->cr.cr_pfid = *tpfid;
836 rec->cr.cr_namelen = tname->ln_namelen;
837 memcpy(changelog_rec_name(&rec->cr), tname->ln_name, tname->ln_namelen);
839 if (crf & CLF_RENAME)
840 mdd_changelog_rec_ext_rename(&rec->cr, sfid, spfid, sname);
843 mdd_changelog_rec_ext_jobid(&rec->cr, uc->uc_jobid);
845 if (likely(target != NULL)) {
846 rec->cr.cr_tfid = *mdo2fid(target);
847 target->mod_cltime = cfs_time_current_64();
849 fid_zero(&rec->cr.cr_tfid);
852 rc = mdd_changelog_store(env, mdd, rec, handle);
854 CERROR("%s: cannot store changelog record: type = %d, "
855 "name = '%s', t = "DFID", p = "DFID": rc = %d\n",
856 mdd2obd_dev(mdd)->obd_name, type, tname->ln_name,
857 PFID(&rec->cr.cr_tfid), PFID(&rec->cr.cr_pfid), rc);
864 static int __mdd_links_add(const struct lu_env *env,
865 struct mdd_object *mdd_obj,
866 struct linkea_data *ldata,
867 const struct lu_name *lname,
868 const struct lu_fid *pfid,
869 int first, int check)
873 if (ldata->ld_leh == NULL) {
874 rc = first ? -ENODATA : mdd_links_read(env, mdd_obj, ldata);
878 rc = linkea_data_new(ldata,
879 &mdd_env_info(env)->mti_link_buf);
886 rc = linkea_links_find(ldata, lname, pfid);
887 if (rc && rc != -ENOENT)
893 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LINKEA_MORE)) {
894 struct lu_fid *tfid = &mdd_env_info(env)->mti_fid2;
898 linkea_add_buf(ldata, lname, tfid);
901 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LINKEA_MORE2))
902 linkea_add_buf(ldata, lname, pfid);
904 return linkea_add_buf(ldata, lname, pfid);
907 static int __mdd_links_del(const struct lu_env *env,
908 struct mdd_object *mdd_obj,
909 struct linkea_data *ldata,
910 const struct lu_name *lname,
911 const struct lu_fid *pfid)
915 if (ldata->ld_leh == NULL) {
916 rc = mdd_links_read(env, mdd_obj, ldata);
921 rc = linkea_links_find(ldata, lname, pfid);
925 linkea_del_buf(ldata, lname);
929 static int mdd_linkea_prepare(const struct lu_env *env,
930 struct mdd_object *mdd_obj,
931 const struct lu_fid *oldpfid,
932 const struct lu_name *oldlname,
933 const struct lu_fid *newpfid,
934 const struct lu_name *newlname,
935 int first, int check,
936 struct linkea_data *ldata)
942 if (OBD_FAIL_CHECK(OBD_FAIL_FID_IGIF))
945 LASSERT(oldpfid != NULL || newpfid != NULL);
947 if (mdd_obj->mod_flags & DEAD_OBJ) {
948 /* Prevent linkea to be updated which is NOT necessary. */
949 ldata->ld_reclen = 0;
950 /* No more links, don't bother */
954 if (oldpfid != NULL) {
955 rc = __mdd_links_del(env, mdd_obj, ldata, oldlname, oldpfid);
958 (rc != -ENODATA && rc != -ENOENT))
960 /* No changes done. */
965 /* If renaming, add the new record */
966 if (newpfid != NULL) {
967 /* even if the add fails, we still delete the out-of-date
969 rc2 = __mdd_links_add(env, mdd_obj, ldata, newlname, newpfid,
973 rc = rc != 0 ? rc : rc2;
978 int mdd_links_rename(const struct lu_env *env,
979 struct mdd_object *mdd_obj,
980 const struct lu_fid *oldpfid,
981 const struct lu_name *oldlname,
982 const struct lu_fid *newpfid,
983 const struct lu_name *newlname,
984 struct thandle *handle,
985 struct linkea_data *ldata,
986 int first, int check)
992 ldata = &mdd_env_info(env)->mti_link_data;
993 memset(ldata, 0, sizeof(*ldata));
994 rc = mdd_linkea_prepare(env, mdd_obj, oldpfid, oldlname,
995 newpfid, newlname, first, check,
1001 if (ldata->ld_reclen != 0)
1002 rc = mdd_links_write(env, mdd_obj, ldata, handle);
1007 if (rc == -EOVERFLOW || rc == -ENOSPC)
1009 if (oldpfid == NULL)
1010 CDEBUG(error ? D_ERROR : D_OTHER,
1011 "link_ea add '%.*s' failed %d "DFID"\n",
1012 newlname->ln_namelen, newlname->ln_name,
1013 rc, PFID(mdd_object_fid(mdd_obj)));
1014 else if (newpfid == NULL)
1015 CDEBUG(error ? D_ERROR : D_OTHER,
1016 "link_ea del '%.*s' failed %d "DFID"\n",
1017 oldlname->ln_namelen, oldlname->ln_name,
1018 rc, PFID(mdd_object_fid(mdd_obj)));
1020 CDEBUG(error ? D_ERROR : D_OTHER,
1021 "link_ea rename '%.*s'->'%.*s' failed %d "
1023 oldlname->ln_namelen, oldlname->ln_name,
1024 newlname->ln_namelen, newlname->ln_name,
1025 rc, PFID(mdd_object_fid(mdd_obj)));
1028 if (ldata->ld_buf && ldata->ld_buf->lb_len > OBD_ALLOC_BIG)
1029 /* if we vmalloced a large buffer drop it */
1030 lu_buf_free(ldata->ld_buf);
1035 static inline int mdd_links_add(const struct lu_env *env,
1036 struct mdd_object *mdd_obj,
1037 const struct lu_fid *pfid,
1038 const struct lu_name *lname,
1039 struct thandle *handle,
1040 struct linkea_data *ldata, int first)
1042 return mdd_links_rename(env, mdd_obj, NULL, NULL,
1043 pfid, lname, handle, ldata, first, 0);
1046 static inline int mdd_links_del(const struct lu_env *env,
1047 struct mdd_object *mdd_obj,
1048 const struct lu_fid *pfid,
1049 const struct lu_name *lname,
1050 struct thandle *handle)
1052 return mdd_links_rename(env, mdd_obj, pfid, lname,
1053 NULL, NULL, handle, NULL, 0, 0);
1056 /** Read the link EA into a temp buffer.
1057 * Uses the mdd_thread_info::mti_big_buf since it is generally large.
1058 * A pointer to the buffer is stored in \a ldata::ld_buf.
1060 * \retval 0 or error
1062 int mdd_links_read(const struct lu_env *env, struct mdd_object *mdd_obj,
1063 struct linkea_data *ldata)
1067 if (!mdd_object_exists(mdd_obj))
1070 /* First try a small buf */
1071 LASSERT(env != NULL);
1072 ldata->ld_buf = lu_buf_check_and_alloc(&mdd_env_info(env)->mti_link_buf,
1074 if (ldata->ld_buf->lb_buf == NULL)
1077 rc = mdo_xattr_get(env, mdd_obj, ldata->ld_buf, XATTR_NAME_LINK);
1078 if (rc == -ERANGE) {
1079 /* Buf was too small, figure out what we need. */
1080 lu_buf_free(ldata->ld_buf);
1081 rc = mdo_xattr_get(env, mdd_obj, ldata->ld_buf,
1085 ldata->ld_buf = lu_buf_check_and_alloc(ldata->ld_buf, rc);
1086 if (ldata->ld_buf->lb_buf == NULL)
1088 rc = mdo_xattr_get(env, mdd_obj, ldata->ld_buf,
1092 lu_buf_free(ldata->ld_buf);
1093 ldata->ld_buf = NULL;
1097 return linkea_init(ldata);
1100 /** Read the link EA into a temp buffer.
1101 * Uses the name_buf since it is generally large.
1102 * \retval IS_ERR err
1103 * \retval ptr to \a lu_buf (always \a mti_big_buf)
1105 struct lu_buf *mdd_links_get(const struct lu_env *env,
1106 struct mdd_object *mdd_obj)
1108 struct linkea_data ldata = { NULL };
1111 rc = mdd_links_read(env, mdd_obj, &ldata);
1112 return rc ? ERR_PTR(rc) : ldata.ld_buf;
1115 int mdd_links_write(const struct lu_env *env, struct mdd_object *mdd_obj,
1116 struct linkea_data *ldata, struct thandle *handle)
1118 const struct lu_buf *buf = mdd_buf_get_const(env, ldata->ld_buf->lb_buf,
1119 ldata->ld_leh->leh_len);
1122 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_NO_LINKEA))
1125 rc = mdo_xattr_set(env, mdd_obj, buf, XATTR_NAME_LINK, 0, handle);
1126 if (unlikely(rc == -ENOSPC) && S_ISREG(mdd_object_type(mdd_obj)) &&
1127 mdd_object_remote(mdd_obj) == 0) {
1128 struct lfsck_request *lr = &mdd_env_info(env)->mti_lr;
1129 struct thandle *sub_th;
1131 /* XXX: If the linkEA is overflow, then we need to notify the
1132 * namespace LFSCK to skip "nlink" attribute verification
1133 * on this object to avoid the "nlink" to be shrinked by
1134 * wrong. It may be not good an interaction with LFSCK
1135 * like this. We will consider to replace it with other
1136 * mechanism in future. LU-5802. */
1137 lfsck_pack_rfa(lr, mdo2fid(mdd_obj), LE_SKIP_NLINK,
1138 LFSCK_TYPE_NAMESPACE);
1140 sub_th = thandle_get_sub_by_dt(env, handle,
1141 mdo2mdd(&mdd_obj->mod_obj)->mdd_bottom);
1142 lfsck_in_notify(env, mdo2mdd(&mdd_obj->mod_obj)->mdd_bottom,
1149 int mdd_declare_links_add(const struct lu_env *env, struct mdd_object *mdd_obj,
1150 struct thandle *handle, struct linkea_data *ldata,
1151 enum mdd_links_add_overflow overflow)
1157 if (ldata != NULL && ldata->ld_leh != NULL) {
1158 ea_len = ldata->ld_leh->leh_len;
1159 linkea = ldata->ld_buf->lb_buf;
1161 ea_len = DEFAULT_LINKEA_SIZE;
1165 /* XXX: max size? */
1166 rc = mdo_declare_xattr_set(env, mdd_obj,
1167 mdd_buf_get_const(env, linkea, ea_len),
1168 XATTR_NAME_LINK, 0, handle);
1172 if (mdd_object_remote(mdd_obj) == 0 && overflow == MLAO_CHECK) {
1173 struct lfsck_request *lr = &mdd_env_info(env)->mti_lr;
1174 struct thandle *sub_th;
1176 /* XXX: If the linkEA is overflow, then we need to notify the
1177 * namespace LFSCK to skip "nlink" attribute verification
1178 * on this object to avoid the "nlink" to be shrinked by
1179 * wrong. It may be not good an interaction with LFSCK
1180 * like this. We will consider to replace it with other
1181 * mechanism in future. LU-5802. */
1182 lfsck_pack_rfa(lr, mdo2fid(mdd_obj), LE_SKIP_NLINK_DECLARE,
1183 LFSCK_TYPE_NAMESPACE);
1185 sub_th = thandle_get_sub_by_dt(env, handle,
1186 mdo2mdd(&mdd_obj->mod_obj)->mdd_bottom);
1187 rc = lfsck_in_notify(env,
1188 mdo2mdd(&mdd_obj->mod_obj)->mdd_bottom,
1195 static inline int mdd_declare_links_del(const struct lu_env *env,
1196 struct mdd_object *c,
1197 struct thandle *handle)
1201 /* For directory, the linkEA will be removed together
1202 * with the object. */
1203 if (!S_ISDIR(mdd_object_type(c)))
1204 rc = mdd_declare_links_add(env, c, handle, NULL, MLAO_IGNORE);
1209 static int mdd_declare_link(const struct lu_env *env,
1210 struct mdd_device *mdd,
1211 struct mdd_object *p,
1212 struct mdd_object *c,
1213 const struct lu_name *name,
1214 struct thandle *handle,
1216 struct linkea_data *data)
1220 rc = mdo_declare_index_insert(env, p, mdo2fid(c), mdd_object_type(c),
1221 name->ln_name, handle);
1225 rc = mdo_declare_ref_add(env, c, handle);
1229 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_MORE_NLINK)) {
1230 rc = mdo_declare_ref_add(env, c, handle);
1235 la->la_valid = LA_CTIME | LA_MTIME;
1236 rc = mdo_declare_attr_set(env, p, la, handle);
1240 la->la_valid = LA_CTIME;
1241 rc = mdo_declare_attr_set(env, c, la, handle);
1245 rc = mdd_declare_links_add(env, c, handle, data,
1246 S_ISREG(mdd_object_type(c)) ? MLAO_CHECK : MLAO_IGNORE);
1250 rc = mdd_declare_changelog_store(env, mdd, name, NULL, handle);
1255 static int mdd_link(const struct lu_env *env, struct md_object *tgt_obj,
1256 struct md_object *src_obj, const struct lu_name *lname,
1259 const char *name = lname->ln_name;
1260 struct lu_attr *la = &mdd_env_info(env)->mti_la_for_fix;
1261 struct mdd_object *mdd_tobj = md2mdd_obj(tgt_obj);
1262 struct mdd_object *mdd_sobj = md2mdd_obj(src_obj);
1263 struct lu_attr *cattr = MDD_ENV_VAR(env, cattr);
1264 struct lu_attr *tattr = MDD_ENV_VAR(env, tattr);
1265 struct mdd_device *mdd = mdo2mdd(src_obj);
1266 struct thandle *handle;
1267 struct linkea_data *ldata = &mdd_env_info(env)->mti_link_data;
1271 rc = mdd_la_get(env, mdd_sobj, cattr);
1275 rc = mdd_la_get(env, mdd_tobj, tattr);
1279 handle = mdd_trans_create(env, mdd);
1281 GOTO(out_pending, rc = PTR_ERR(handle));
1283 memset(ldata, 0, sizeof(*ldata));
1285 LASSERT(ma->ma_attr.la_valid & LA_CTIME);
1286 la->la_ctime = la->la_mtime = ma->ma_attr.la_ctime;
1288 rc = mdd_declare_link(env, mdd, mdd_tobj, mdd_sobj, lname, handle,
1293 rc = mdd_trans_start(env, mdd, handle);
1297 mdd_write_lock(env, mdd_sobj, MOR_TGT_CHILD);
1298 rc = mdd_link_sanity_check(env, mdd_tobj, tattr, lname, mdd_sobj,
1301 GOTO(out_unlock, rc);
1303 if (!OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LESS_NLINK)) {
1304 rc = mdo_ref_add(env, mdd_sobj, handle);
1306 GOTO(out_unlock, rc);
1309 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_MORE_NLINK)) {
1310 rc = mdo_ref_add(env, mdd_sobj, handle);
1312 GOTO(out_unlock, rc);
1315 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_DANGLING3)) {
1316 struct lu_fid tfid = *mdo2fid(mdd_sobj);
1319 rc = __mdd_index_insert_only(env, mdd_tobj, &tfid,
1320 mdd_object_type(mdd_sobj),
1323 rc = __mdd_index_insert_only(env, mdd_tobj, mdo2fid(mdd_sobj),
1324 mdd_object_type(mdd_sobj),
1329 mdo_ref_del(env, mdd_sobj, handle);
1330 GOTO(out_unlock, rc);
1333 la->la_valid = LA_CTIME | LA_MTIME;
1334 rc = mdd_update_time(env, mdd_tobj, tattr, la, handle);
1336 GOTO(out_unlock, rc);
1338 la->la_valid = LA_CTIME;
1339 rc = mdd_update_time(env, mdd_sobj, cattr, la, handle);
1341 rc = mdd_linkea_prepare(env, mdd_sobj, NULL, NULL,
1342 mdo2fid(mdd_tobj), lname, 0, 0,
1345 mdd_links_add(env, mdd_sobj, mdo2fid(mdd_tobj),
1346 lname, handle, ldata, 0);
1347 /* The failure of links_add should not cause the link
1348 * failure, reset rc here */
1353 mdd_write_unlock(env, mdd_sobj);
1355 rc = mdd_changelog_ns_store(env, mdd, CL_HARDLINK, 0, mdd_sobj,
1356 mdo2fid(mdd_tobj), NULL, NULL,
1357 lname, NULL, handle);
1359 mdd_trans_stop(env, mdd, rc, handle);
1361 if (ldata->ld_buf && ldata->ld_buf->lb_len > OBD_ALLOC_BIG)
1362 /* if we vmalloced a large buffer drop it */
1363 lu_buf_free(ldata->ld_buf);
1368 static int mdd_mark_dead_object(const struct lu_env *env,
1369 struct mdd_object *obj, struct thandle *handle,
1372 struct lu_attr *attr = MDD_ENV_VAR(env, la_for_start);
1376 obj->mod_flags |= DEAD_OBJ;
1378 if (!S_ISDIR(mdd_object_type(obj)))
1381 attr->la_valid = LA_FLAGS;
1382 attr->la_flags = LUSTRE_SLAVE_DEAD_FL;
1385 rc = mdo_declare_attr_set(env, obj, attr, handle);
1387 rc = mdo_attr_set(env, obj, attr, handle);
1392 static int mdd_declare_finish_unlink(const struct lu_env *env,
1393 struct mdd_object *obj,
1394 struct thandle *handle)
1398 rc = mdd_mark_dead_object(env, obj, handle, true);
1402 rc = orph_declare_index_insert(env, obj, mdd_object_type(obj), handle);
1406 rc = mdo_declare_destroy(env, obj, handle);
1410 return mdd_declare_links_del(env, obj, handle);
1413 /* caller should take a lock before calling */
1414 int mdd_finish_unlink(const struct lu_env *env,
1415 struct mdd_object *obj, struct md_attr *ma,
1416 const struct mdd_object *pobj,
1417 const struct lu_name *lname,
1421 int is_dir = S_ISDIR(ma->ma_attr.la_mode);
1424 LASSERT(mdd_write_locked(env, obj) != 0);
1426 if (ma->ma_attr.la_nlink == 0 || is_dir) {
1427 rc = mdd_mark_dead_object(env, obj, th, false);
1431 /* add new orphan and the object
1432 * will be deleted during mdd_close() */
1433 if (obj->mod_count) {
1434 rc = __mdd_orphan_add(env, obj, th);
1436 CDEBUG(D_HA, "Object "DFID" is inserted into "
1437 "orphan list, open count = %d\n",
1438 PFID(mdd_object_fid(obj)),
1441 CERROR("Object "DFID" fail to be an orphan, "
1442 "open count = %d, maybe cause failed "
1444 PFID(mdd_object_fid(obj)),
1447 rc = mdo_destroy(env, obj, th);
1449 } else if (!is_dir) {
1450 /* old files may not have link ea; ignore errors */
1451 mdd_links_del(env, obj, mdo2fid(pobj), lname, th);
1459 * has mdd_write_lock on cobj already, but not on pobj yet
1461 int mdd_unlink_sanity_check(const struct lu_env *env, struct mdd_object *pobj,
1462 const struct lu_attr *pattr,
1463 struct mdd_object *cobj,
1464 const struct lu_attr *cattr)
1469 rc = mdd_may_delete(env, pobj, pattr, cobj, cattr, NULL, 1, 1);
1474 static int mdd_declare_unlink(const struct lu_env *env, struct mdd_device *mdd,
1475 struct mdd_object *p, struct mdd_object *c,
1476 const struct lu_name *name, struct md_attr *ma,
1477 struct thandle *handle, int no_name, int is_dir)
1479 struct lu_attr *la = &mdd_env_info(env)->mti_la_for_fix;
1482 if (!OBD_FAIL_CHECK(OBD_FAIL_LFSCK_DANGLING2)) {
1483 if (likely(no_name == 0)) {
1484 rc = mdo_declare_index_delete(env, p, name->ln_name,
1491 rc = mdo_declare_ref_del(env, p, handle);
1497 LASSERT(ma->ma_attr.la_valid & LA_CTIME);
1498 la->la_ctime = la->la_mtime = ma->ma_attr.la_ctime;
1499 la->la_valid = LA_CTIME | LA_MTIME;
1500 rc = mdo_declare_attr_set(env, p, la, handle);
1505 rc = mdo_declare_ref_del(env, c, handle);
1509 rc = mdo_declare_ref_del(env, c, handle);
1513 la->la_valid = LA_CTIME;
1514 rc = mdo_declare_attr_set(env, c, la, handle);
1518 rc = mdd_declare_finish_unlink(env, c, handle);
1522 /* FIXME: need changelog for remove entry */
1523 rc = mdd_declare_changelog_store(env, mdd, name, NULL, handle);
1530 * test if a file has an HSM archive
1531 * if HSM attributes are not found in ma update them from
1534 static bool mdd_hsm_archive_exists(const struct lu_env *env,
1535 struct mdd_object *obj,
1540 if (!(ma->ma_valid & MA_HSM)) {
1541 /* no HSM MD provided, read xattr */
1542 struct lu_buf *hsm_buf;
1543 const size_t buflen = sizeof(struct hsm_attrs);
1546 hsm_buf = mdd_buf_get(env, NULL, 0);
1547 lu_buf_alloc(hsm_buf, buflen);
1548 rc = mdo_xattr_get(env, obj, hsm_buf, XATTR_NAME_HSM);
1549 rc = lustre_buf2hsm(hsm_buf->lb_buf, rc, &ma->ma_hsm);
1550 lu_buf_free(hsm_buf);
1554 ma->ma_valid = MA_HSM;
1556 if (ma->ma_hsm.mh_flags & HS_EXISTS)
1562 * Delete name entry and the object.
1563 * Note: no_name == 1 means it only destory the object, i.e. name_entry
1564 * does not exist for this object, and it could only happen during resending
1565 * of remote unlink. see the comments in mdt_reint_unlink. Unfortunately, lname
1566 * is also needed in this case(needed by changelog), so we have to add another
1567 * parameter(no_name)here. XXX: this is only needed in DNE phase I, on Phase II,
1568 * the ENOENT failure should be able to be fixed by redo mechanism.
1570 static int mdd_unlink(const struct lu_env *env, struct md_object *pobj,
1571 struct md_object *cobj, const struct lu_name *lname,
1572 struct md_attr *ma, int no_name)
1574 const char *name = lname->ln_name;
1575 struct lu_attr *pattr = MDD_ENV_VAR(env, pattr);
1576 struct lu_attr *cattr = MDD_ENV_VAR(env, cattr);
1577 struct lu_attr *la = &mdd_env_info(env)->mti_la_for_fix;
1578 struct mdd_object *mdd_pobj = md2mdd_obj(pobj);
1579 struct mdd_object *mdd_cobj = NULL;
1580 struct mdd_device *mdd = mdo2mdd(pobj);
1581 struct thandle *handle;
1585 /* cobj == NULL means only delete name entry */
1586 if (likely(cobj != NULL)) {
1587 mdd_cobj = md2mdd_obj(cobj);
1588 if (mdd_object_exists(mdd_cobj) == 0)
1592 rc = mdd_la_get(env, mdd_pobj, pattr);
1596 if (likely(mdd_cobj != NULL)) {
1598 rc = mdd_la_get(env, mdd_cobj, cattr);
1602 is_dir = S_ISDIR(cattr->la_mode);
1605 rc = mdd_unlink_sanity_check(env, mdd_pobj, pattr, mdd_cobj, cattr);
1609 handle = mdd_trans_create(env, mdd);
1611 RETURN(PTR_ERR(handle));
1613 rc = mdd_declare_unlink(env, mdd, mdd_pobj, mdd_cobj,
1614 lname, ma, handle, no_name, is_dir);
1618 rc = mdd_trans_start(env, mdd, handle);
1622 if (likely(mdd_cobj != NULL))
1623 mdd_write_lock(env, mdd_cobj, MOR_TGT_CHILD);
1625 if (likely(no_name == 0) && !OBD_FAIL_CHECK(OBD_FAIL_LFSCK_DANGLING2)) {
1626 rc = __mdd_index_delete(env, mdd_pobj, name, is_dir, handle);
1631 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_MUL_REF) ||
1632 OBD_FAIL_CHECK(OBD_FAIL_LFSCK_NO_NAMEENTRY))
1633 GOTO(cleanup, rc = 0);
1635 if (likely(mdd_cobj != NULL)) {
1636 rc = mdo_ref_del(env, mdd_cobj, handle);
1638 __mdd_index_insert_only(env, mdd_pobj,
1640 mdd_object_type(mdd_cobj),
1647 mdo_ref_del(env, mdd_cobj, handle);
1649 /* fetch updated nlink */
1650 rc = mdd_la_get(env, mdd_cobj, cattr);
1655 LASSERT(ma->ma_attr.la_valid & LA_CTIME);
1656 la->la_ctime = la->la_mtime = ma->ma_attr.la_ctime;
1658 la->la_valid = LA_CTIME | LA_MTIME;
1659 rc = mdd_update_time(env, mdd_pobj, pattr, la, handle);
1663 /* Enough for only unlink the entry */
1664 if (unlikely(mdd_cobj == NULL))
1667 if (cattr->la_nlink > 0 || mdd_cobj->mod_count > 0) {
1668 /* update ctime of an unlinked file only if it is still
1669 * opened or a link still exists */
1670 la->la_valid = LA_CTIME;
1671 rc = mdd_update_time(env, mdd_cobj, cattr, la, handle);
1676 /* XXX: this transfer to ma will be removed with LOD/OSP */
1677 ma->ma_attr = *cattr;
1678 ma->ma_valid |= MA_INODE;
1679 rc = mdd_finish_unlink(env, mdd_cobj, ma, mdd_pobj, lname, handle);
1681 /* fetch updated nlink */
1683 rc = mdd_la_get(env, mdd_cobj, cattr);
1685 /* if object is removed then we can't get its attrs, use last get */
1686 if (cattr->la_nlink == 0) {
1687 ma->ma_attr = *cattr;
1688 ma->ma_valid |= MA_INODE;
1692 if (likely(mdd_cobj != NULL))
1693 mdd_write_unlock(env, mdd_cobj);
1698 if (cattr->la_nlink == 0) {
1699 cl_flags |= CLF_UNLINK_LAST;
1700 /* search for an existing archive */
1701 if (mdd_hsm_archive_exists(env, mdd_cobj, ma))
1702 cl_flags |= CLF_UNLINK_HSM_EXISTS;
1705 rc = mdd_changelog_ns_store(env, mdd,
1706 is_dir ? CL_RMDIR : CL_UNLINK, cl_flags,
1707 mdd_cobj, mdo2fid(mdd_pobj), NULL, NULL, lname, NULL,
1712 mdd_trans_stop(env, mdd, rc, handle);
1718 * The permission has been checked when obj created, no need check again.
1720 static int mdd_cd_sanity_check(const struct lu_env *env,
1721 struct mdd_object *obj)
1726 if (!obj || mdd_is_dead_obj(obj))
1732 static int mdd_create_data(const struct lu_env *env, struct md_object *pobj,
1733 struct md_object *cobj, const struct md_op_spec *spec,
1736 struct mdd_device *mdd = mdo2mdd(cobj);
1737 struct mdd_object *mdd_pobj = md2mdd_obj(pobj);
1738 struct mdd_object *son = md2mdd_obj(cobj);
1739 struct thandle *handle;
1740 const struct lu_buf *buf;
1741 struct lu_attr *attr = MDD_ENV_VAR(env, cattr);
1742 struct dt_allocation_hint *hint = &mdd_env_info(env)->mti_hint;
1746 rc = mdd_cd_sanity_check(env, son);
1750 if (!md_should_create(spec->sp_cr_flags))
1754 * there are following use cases for this function:
1755 * 1) late striping - file was created with MDS_OPEN_DELAY_CREATE
1756 * striping can be specified or not
1759 rc = mdd_la_get(env, son, attr);
1763 /* calling ->ah_make_hint() is used to transfer information from parent */
1764 mdd_object_make_hint(env, mdd_pobj, son, attr, spec, hint);
1766 handle = mdd_trans_create(env, mdd);
1768 GOTO(out_free, rc = PTR_ERR(handle));
1771 * XXX: Setting the lov ea is not locked but setting the attr is locked?
1772 * Should this be fixed?
1774 CDEBUG(D_OTHER, "ea %p/%u, cr_flags "LPO64", no_create %u\n",
1775 spec->u.sp_ea.eadata, spec->u.sp_ea.eadatalen,
1776 spec->sp_cr_flags, spec->no_create);
1778 if (spec->no_create || (spec->sp_cr_flags & MDS_OPEN_HAS_EA)) {
1779 buf = mdd_buf_get_const(env, spec->u.sp_ea.eadata,
1780 spec->u.sp_ea.eadatalen);
1785 rc = dt_declare_xattr_set(env, mdd_object_child(son), buf,
1786 XATTR_NAME_LOV, 0, handle);
1790 rc = mdd_declare_changelog_store(env, mdd, NULL, NULL, handle);
1794 rc = mdd_trans_start(env, mdd, handle);
1798 rc = dt_xattr_set(env, mdd_object_child(son), buf, XATTR_NAME_LOV,
1804 rc = mdd_changelog_data_store(env, mdd, CL_LAYOUT, 0, son, handle);
1807 mdd_trans_stop(env, mdd, rc, handle);
1812 static int mdd_declare_object_initialize(const struct lu_env *env,
1813 struct mdd_object *parent,
1814 struct mdd_object *child,
1815 struct lu_attr *attr,
1816 struct thandle *handle)
1822 * inode mode has been set in creation time, and it's based on umask,
1823 * la_mode and acl, don't set here again! (which will go wrong
1824 * because below function doesn't consider umask).
1825 * I'd suggest set all object attributes in creation time, see above.
1827 LASSERT(attr->la_valid & (LA_MODE | LA_TYPE));
1828 attr->la_valid &= ~(LA_MODE | LA_TYPE);
1829 rc = mdo_declare_attr_set(env, child, attr, handle);
1830 attr->la_valid |= LA_MODE | LA_TYPE;
1831 if (rc != 0 || !S_ISDIR(attr->la_mode))
1834 rc = mdo_declare_index_insert(env, child, mdo2fid(child), S_IFDIR,
1839 rc = mdo_declare_ref_add(env, child, handle);
1843 rc = mdo_declare_index_insert(env, child, mdo2fid(parent), S_IFDIR,
1849 static int mdd_object_initialize(const struct lu_env *env,
1850 const struct lu_fid *pfid,
1851 struct mdd_object *child,
1852 struct lu_attr *attr, struct thandle *handle,
1853 const struct md_op_spec *spec)
1858 if (S_ISDIR(attr->la_mode)) {
1859 /* Add "." and ".." for newly created dir */
1860 mdo_ref_add(env, child, handle);
1861 rc = __mdd_index_insert_only(env, child, mdo2fid(child),
1862 S_IFDIR, dot, handle);
1864 rc = __mdd_index_insert_only(env, child, pfid, S_IFDIR,
1867 mdo_ref_del(env, child, handle);
1874 * This function checks whether it can create a file/dir under the
1875 * directory(@pobj). The directory(@pobj) is not being locked by
1878 * \param[in] env execution environment
1879 * \param[in] pobj the directory to create files
1880 * \param[in] pattr the attributes of the directory
1881 * \param[in] lname the name of the created file/dir
1882 * \param[in] cattr the attributes of the file/dir
1883 * \param[in] spec create specification
1885 * \retval = 0 it is allowed to create file/dir under
1887 * \retval negative error not allowed to create file/dir
1888 * under the directory
1890 static int mdd_create_sanity_check(const struct lu_env *env,
1891 struct md_object *pobj,
1892 const struct lu_attr *pattr,
1893 const struct lu_name *lname,
1894 struct lu_attr *cattr,
1895 struct md_op_spec *spec)
1897 struct mdd_thread_info *info = mdd_env_info(env);
1898 struct lu_fid *fid = &info->mti_fid;
1899 struct mdd_object *obj = md2mdd_obj(pobj);
1900 struct mdd_device *m = mdo2mdd(pobj);
1901 bool check_perm = true;
1906 if (mdd_is_dead_obj(obj))
1910 * In some cases this lookup is not needed - we know before if name
1911 * exists or not because MDT performs lookup for it.
1912 * name length check is done in lookup.
1914 if (spec->sp_cr_lookup) {
1916 * Check if the name already exist, though it will be checked in
1917 * _index_insert also, for avoiding rolling back if exists
1920 rc = __mdd_lookup(env, pobj, pattr, lname, fid,
1921 MAY_WRITE | MAY_EXEC);
1923 RETURN(rc ? : -EEXIST);
1925 /* Permission is already being checked in mdd_lookup */
1929 rc = mdd_may_create(env, obj, pattr, NULL, check_perm);
1934 if (pattr->la_mode & S_ISGID) {
1935 cattr->la_gid = pattr->la_gid;
1936 if (S_ISDIR(cattr->la_mode)) {
1937 cattr->la_mode |= S_ISGID;
1938 cattr->la_valid |= LA_MODE;
1942 rc = mdd_name_check(m, lname);
1946 switch (cattr->la_mode & S_IFMT) {
1948 unsigned int symlen = strlen(spec->u.sp_symname) + 1;
1950 if (symlen > (1 << m->mdd_dt_conf.ddp_block_shift))
1951 RETURN(-ENAMETOOLONG);
1970 static int mdd_declare_object_create(const struct lu_env *env,
1971 struct mdd_device *mdd,
1972 struct mdd_object *p, struct mdd_object *c,
1973 struct lu_attr *attr,
1974 struct thandle *handle,
1975 const struct md_op_spec *spec,
1976 struct lu_buf *def_acl_buf,
1977 struct lu_buf *acl_buf,
1978 struct dt_allocation_hint *hint)
1982 rc = mdd_declare_object_create_internal(env, p, c, attr, handle, spec,
1987 #ifdef CONFIG_FS_POSIX_ACL
1988 if (def_acl_buf->lb_len > 0 && S_ISDIR(attr->la_mode)) {
1989 /* if dir, then can inherit default ACl */
1990 rc = mdo_declare_xattr_set(env, c, def_acl_buf,
1991 XATTR_NAME_ACL_DEFAULT,
1997 if (acl_buf->lb_len > 0) {
1998 rc = mdo_declare_attr_set(env, c, attr, handle);
2002 rc = mdo_declare_xattr_set(env, c, acl_buf,
2003 XATTR_NAME_ACL_ACCESS, 0, handle);
2008 rc = mdd_declare_object_initialize(env, p, c, attr, handle);
2012 /* replay case, create LOV EA from client data */
2013 if (spec->no_create ||
2014 (spec->sp_cr_flags & MDS_OPEN_HAS_EA && S_ISREG(attr->la_mode))) {
2015 const struct lu_buf *buf;
2017 buf = mdd_buf_get_const(env, spec->u.sp_ea.eadata,
2018 spec->u.sp_ea.eadatalen);
2019 rc = mdo_declare_xattr_set(env, c, buf, XATTR_NAME_LOV, 0,
2025 if (S_ISLNK(attr->la_mode)) {
2026 const char *target_name = spec->u.sp_symname;
2027 int sym_len = strlen(target_name);
2028 const struct lu_buf *buf;
2030 buf = mdd_buf_get_const(env, target_name, sym_len);
2031 rc = dt_declare_record_write(env, mdd_object_child(c),
2040 static int mdd_declare_create(const struct lu_env *env, struct mdd_device *mdd,
2041 struct mdd_object *p, struct mdd_object *c,
2042 const struct lu_name *name,
2043 struct lu_attr *attr,
2044 struct thandle *handle,
2045 const struct md_op_spec *spec,
2046 struct linkea_data *ldata,
2047 struct lu_buf *def_acl_buf,
2048 struct lu_buf *acl_buf,
2049 struct dt_allocation_hint *hint)
2053 rc = mdd_declare_object_create(env, mdd, p, c, attr, handle, spec,
2054 def_acl_buf, acl_buf, hint);
2058 if (S_ISDIR(attr->la_mode)) {
2059 rc = mdo_declare_ref_add(env, p, handle);
2064 if (unlikely(spec->sp_cr_flags & MDS_OPEN_VOLATILE)) {
2065 rc = orph_declare_index_insert(env, c, attr->la_mode, handle);
2069 struct lu_attr *la = &mdd_env_info(env)->mti_la_for_fix;
2071 rc = mdo_declare_index_insert(env, p, mdo2fid(c), attr->la_mode,
2072 name->ln_name, handle);
2076 rc = mdd_declare_links_add(env, c, handle, ldata, MLAO_IGNORE);
2081 la->la_valid = LA_CTIME | LA_MTIME;
2082 rc = mdo_declare_attr_set(env, p, la, handle);
2086 rc = mdd_declare_changelog_store(env, mdd, name, NULL, handle);
2094 static int mdd_acl_init(const struct lu_env *env, struct mdd_object *pobj,
2095 struct lu_attr *la, struct lu_buf *def_acl_buf,
2096 struct lu_buf *acl_buf)
2101 if (S_ISLNK(la->la_mode)) {
2102 acl_buf->lb_len = 0;
2103 def_acl_buf->lb_len = 0;
2107 mdd_read_lock(env, pobj, MOR_TGT_PARENT);
2108 rc = mdo_xattr_get(env, pobj, def_acl_buf,
2109 XATTR_NAME_ACL_DEFAULT);
2110 mdd_read_unlock(env, pobj);
2112 /* If there are default ACL, fix mode/ACL by default ACL */
2113 def_acl_buf->lb_len = rc;
2114 LASSERT(def_acl_buf->lb_len <= acl_buf->lb_len);
2115 memcpy(acl_buf->lb_buf, def_acl_buf->lb_buf, rc);
2116 acl_buf->lb_len = rc;
2117 rc = __mdd_fix_mode_acl(env, acl_buf, &la->la_mode);
2120 } else if (rc == -ENODATA || rc == -EOPNOTSUPP) {
2121 /* If there are no default ACL, fix mode by mask */
2122 struct lu_ucred *uc = lu_ucred(env);
2124 /* The create triggered by MDT internal events, such as
2125 * LFSCK reset, will not contain valid "uc". */
2126 if (unlikely(uc != NULL))
2127 la->la_mode &= ~uc->uc_umask;
2129 acl_buf->lb_len = 0;
2130 def_acl_buf->lb_len = 0;
2137 * Create a metadata object and initialize it, set acl, xattr.
2139 static int mdd_object_create(const struct lu_env *env, struct mdd_object *pobj,
2140 struct mdd_object *son, struct lu_attr *attr,
2141 struct md_op_spec *spec, struct lu_buf *acl_buf,
2142 struct lu_buf *def_acl_buf,
2143 struct dt_allocation_hint *hint,
2144 struct thandle *handle)
2148 mdd_write_lock(env, son, MOR_TGT_CHILD);
2149 rc = mdd_object_create_internal(env, NULL, son, attr, handle, spec,
2154 /* Note: In DNE phase I, for striped dir, though sub-stripes will be
2155 * created in declare phase, they also needs to be added to master
2156 * object as sub-directory entry. So it has to initialize the master
2157 * object, then set dir striped EA.(in mdo_xattr_set) */
2158 rc = mdd_object_initialize(env, mdo2fid(pobj), son, attr, handle,
2161 GOTO(err_destroy, rc);
2164 * in case of replay we just set LOVEA provided by the client
2165 * XXX: I think it would be interesting to try "old" way where
2166 * MDT calls this xattr_set(LOV) in a different transaction.
2167 * probably this way we code can be made better.
2170 /* During creation, there are only a few cases we need do xattr_set to
2172 * 1. regular file: see comments above.
2173 * 2. dir: inherit default striping or pool settings from parent.
2174 * 3. create striped directory with provided stripeEA.
2175 * 4. create striped directory because inherit default layout from the
2178 if (spec->no_create ||
2179 (S_ISREG(attr->la_mode) && spec->sp_cr_flags & MDS_OPEN_HAS_EA) ||
2180 S_ISDIR(attr->la_mode)) {
2181 const struct lu_buf *buf;
2183 buf = mdd_buf_get_const(env, spec->u.sp_ea.eadata,
2184 spec->u.sp_ea.eadatalen);
2185 rc = mdo_xattr_set(env, son, buf,
2186 S_ISDIR(attr->la_mode) ? XATTR_NAME_LMV :
2190 GOTO(err_destroy, rc);
2193 #ifdef CONFIG_FS_POSIX_ACL
2194 if (def_acl_buf != NULL && def_acl_buf->lb_len > 0 &&
2195 S_ISDIR(attr->la_mode)) {
2196 /* set default acl */
2197 rc = mdo_xattr_set(env, son, def_acl_buf,
2198 XATTR_NAME_ACL_DEFAULT, 0,
2201 GOTO(err_destroy, rc);
2203 /* set its own acl */
2204 if (acl_buf != NULL && acl_buf->lb_len > 0) {
2205 rc = mdo_xattr_set(env, son, acl_buf,
2206 XATTR_NAME_ACL_ACCESS,
2209 GOTO(err_destroy, rc);
2213 if (S_ISLNK(attr->la_mode)) {
2214 struct lu_ucred *uc = lu_ucred_assert(env);
2215 struct dt_object *dt = mdd_object_child(son);
2216 const char *target_name = spec->u.sp_symname;
2217 int sym_len = strlen(target_name);
2218 const struct lu_buf *buf;
2221 buf = mdd_buf_get_const(env, target_name, sym_len);
2222 rc = dt->do_body_ops->dbo_write(env, dt, buf, &pos, handle,
2224 CFS_CAP_SYS_RESOURCE_MASK);
2229 GOTO(err_initlized, rc = -EFAULT);
2233 if (unlikely(rc != 0)) {
2235 if (S_ISDIR(attr->la_mode)) {
2236 /* Drop the reference, no need to delete "."/"..",
2237 * because the object to be destroied directly. */
2238 rc2 = mdo_ref_del(env, son, handle);
2242 rc2 = mdo_ref_del(env, son, handle);
2246 mdo_destroy(env, son, handle);
2249 mdd_write_unlock(env, son);
2254 * Create object and insert it into namespace.
2256 static int mdd_create(const struct lu_env *env, struct md_object *pobj,
2257 const struct lu_name *lname, struct md_object *child,
2258 struct md_op_spec *spec, struct md_attr* ma)
2260 struct mdd_thread_info *info = mdd_env_info(env);
2261 struct lu_attr *la = &info->mti_la_for_fix;
2262 struct mdd_object *mdd_pobj = md2mdd_obj(pobj);
2263 struct mdd_object *son = md2mdd_obj(child);
2264 struct mdd_device *mdd = mdo2mdd(pobj);
2265 struct lu_attr *attr = &ma->ma_attr;
2266 struct thandle *handle;
2267 struct lu_attr *pattr = &info->mti_pattr;
2268 struct lu_buf acl_buf;
2269 struct lu_buf def_acl_buf;
2270 struct linkea_data *ldata = &info->mti_link_data;
2271 const char *name = lname->ln_name;
2272 struct dt_allocation_hint *hint = &mdd_env_info(env)->mti_hint;
2278 * Two operations have to be performed:
2280 * - an allocation of a new object (->do_create()), and
2282 * - an insertion into a parent index (->dio_insert()).
2284 * Due to locking, operation order is not important, when both are
2285 * successful, *but* error handling cases are quite different:
2287 * - if insertion is done first, and following object creation fails,
2288 * insertion has to be rolled back, but this operation might fail
2289 * also leaving us with dangling index entry.
2291 * - if creation is done first, is has to be undone if insertion
2292 * fails, leaving us with leaked space, which is neither good, nor
2295 * It seems that creation-first is simplest solution, but it is
2296 * sub-optimal in the frequent
2301 * case, because second mkdir is bound to create object, only to
2302 * destroy it immediately.
2304 * To avoid this follow local file systems that do double lookup:
2306 * 0. lookup -> -EEXIST (mdd_create_sanity_check())
2308 * 1. create (mdd_object_create_internal())
2310 * 2. insert (__mdd_index_insert(), lookup again)
2313 rc = mdd_la_get(env, mdd_pobj, pattr);
2317 /* Sanity checks before big job. */
2318 rc = mdd_create_sanity_check(env, pobj, pattr, lname, attr, spec);
2322 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_DQACQ_NET))
2323 GOTO(out_free, rc = -EINPROGRESS);
2325 handle = mdd_trans_create(env, mdd);
2327 GOTO(out_free, rc = PTR_ERR(handle));
2329 acl_buf.lb_buf = info->mti_xattr_buf;
2330 acl_buf.lb_len = sizeof(info->mti_xattr_buf);
2331 def_acl_buf.lb_buf = info->mti_key;
2332 def_acl_buf.lb_len = sizeof(info->mti_key);
2333 rc = mdd_acl_init(env, mdd_pobj, attr, &def_acl_buf, &acl_buf);
2337 mdd_object_make_hint(env, mdd_pobj, son, attr, spec, hint);
2339 memset(ldata, 0, sizeof(*ldata));
2340 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_PARENT)) {
2341 struct lu_fid tfid = *mdd_object_fid(mdd_pobj);
2344 rc = mdd_linkea_prepare(env, son, NULL, NULL,
2345 &tfid, lname, 1, 0, ldata);
2347 rc = mdd_linkea_prepare(env, son, NULL, NULL,
2348 mdd_object_fid(mdd_pobj),
2349 lname, 1, 0, ldata);
2352 rc = mdd_declare_create(env, mdd, mdd_pobj, son, lname, attr,
2353 handle, spec, ldata, &def_acl_buf, &acl_buf,
2358 rc = mdd_trans_start(env, mdd, handle);
2362 rc = mdd_object_create(env, mdd_pobj, son, attr, spec, &acl_buf,
2363 &def_acl_buf, hint, handle);
2367 if (unlikely(spec->sp_cr_flags & MDS_OPEN_VOLATILE)) {
2368 mdd_write_lock(env, son, MOR_TGT_CHILD);
2369 rc = __mdd_orphan_add(env, son, handle);
2370 GOTO(out_volatile, rc);
2372 rc = __mdd_index_insert(env, mdd_pobj, mdo2fid(son),
2373 attr->la_mode, name, handle);
2375 GOTO(err_created, rc);
2377 mdd_links_add(env, son, mdo2fid(mdd_pobj), lname, handle,
2380 /* update parent directory mtime/ctime */
2382 la->la_valid = LA_CTIME | LA_MTIME;
2383 rc = mdd_update_time(env, mdd_pobj, pattr, la, handle);
2385 GOTO(err_insert, rc);
2393 if (spec->sp_cr_flags & MDS_OPEN_VOLATILE)
2394 rc2 = __mdd_orphan_del(env, son, handle);
2396 rc2 = __mdd_index_delete(env, mdd_pobj, name,
2397 S_ISDIR(attr->la_mode),
2403 mdd_write_lock(env, son, MOR_TGT_CHILD);
2404 if (S_ISDIR(attr->la_mode)) {
2405 /* Drop the reference, no need to delete "."/"..",
2406 * because the object is to be destroyed directly. */
2407 rc2 = mdo_ref_del(env, son, handle);
2409 mdd_write_unlock(env, son);
2414 /* For volatile files drop one link immediately, since there is
2415 * no filename in the namespace, and save any error returned. */
2416 rc2 = mdo_ref_del(env, son, handle);
2418 mdd_write_unlock(env, son);
2419 if (unlikely(rc == 0))
2424 /* Don't destroy the volatile object on success */
2425 if (likely(rc != 0))
2426 mdo_destroy(env, son, handle);
2427 mdd_write_unlock(env, son);
2430 if (rc == 0 && fid_is_namespace_visible(mdo2fid(son)) &&
2431 likely((spec->sp_cr_flags & MDS_OPEN_VOLATILE) == 0))
2432 rc = mdd_changelog_ns_store(env, mdd,
2433 S_ISDIR(attr->la_mode) ? CL_MKDIR :
2434 S_ISREG(attr->la_mode) ? CL_CREATE :
2435 S_ISLNK(attr->la_mode) ? CL_SOFTLINK : CL_MKNOD,
2436 0, son, mdo2fid(mdd_pobj), NULL, NULL, lname,
2439 rc2 = mdd_trans_stop(env, mdd, rc, handle);
2443 if (ldata->ld_buf && ldata->ld_buf->lb_len > OBD_ALLOC_BIG)
2444 /* if we vmalloced a large buffer drop it */
2445 lu_buf_free(ldata->ld_buf);
2447 /* The child object shouldn't be cached anymore */
2449 set_bit(LU_OBJECT_HEARD_BANSHEE,
2450 &child->mo_lu.lo_header->loh_flags);
2455 * Get locks on parents in proper order
2456 * RETURN: < 0 - error, rename_order if successful
2464 static int mdd_rename_order(const struct lu_env *env,
2465 struct mdd_device *mdd,
2466 struct mdd_object *src_pobj,
2467 const struct lu_attr *pattr,
2468 struct mdd_object *tgt_pobj)
2470 /* order of locking, 1 - tgt-src, 0 - src-tgt*/
2474 if (src_pobj == tgt_pobj)
2475 RETURN(MDD_RN_SAME);
2477 /* compared the parent child relationship of src_p&tgt_p */
2478 if (lu_fid_eq(&mdd->mdd_root_fid, mdo2fid(src_pobj))){
2480 } else if (lu_fid_eq(&mdd->mdd_root_fid, mdo2fid(tgt_pobj))) {
2483 rc = mdd_is_parent(env, mdd, src_pobj, pattr, mdo2fid(tgt_pobj),
2497 /* has not mdd_write{read}_lock on any obj yet. */
2498 static int mdd_rename_sanity_check(const struct lu_env *env,
2499 struct mdd_object *src_pobj,
2500 const struct lu_attr *pattr,
2501 struct mdd_object *tgt_pobj,
2502 const struct lu_attr *tpattr,
2503 struct mdd_object *sobj,
2504 const struct lu_attr *cattr,
2505 struct mdd_object *tobj,
2506 const struct lu_attr *tattr)
2511 /* XXX: when get here, sobj must NOT be NULL,
2512 * the other case has been processed in cld_rename
2513 * before mdd_rename and enable MDS_PERM_BYPASS. */
2516 rc = mdd_may_delete(env, src_pobj, pattr, sobj, cattr, NULL, 1, 0);
2520 /* XXX: when get here, "tobj == NULL" means tobj must
2521 * NOT exist (neither on remote MDS, such case has been
2522 * processed in cld_rename before mdd_rename and enable
2524 * So check may_create, but not check may_unlink. */
2526 rc = mdd_may_create(env, tgt_pobj, tpattr, NULL,
2527 (src_pobj != tgt_pobj));
2529 rc = mdd_may_delete(env, tgt_pobj, tpattr, tobj, tattr, cattr,
2530 (src_pobj != tgt_pobj), 1);
2532 if (!rc && !tobj && (src_pobj != tgt_pobj) && S_ISDIR(cattr->la_mode))
2533 rc = __mdd_may_link(env, tgt_pobj, tpattr);
2538 static int mdd_declare_rename(const struct lu_env *env,
2539 struct mdd_device *mdd,
2540 struct mdd_object *mdd_spobj,
2541 struct mdd_object *mdd_tpobj,
2542 struct mdd_object *mdd_sobj,
2543 struct mdd_object *mdd_tobj,
2544 const struct lu_name *tname,
2545 const struct lu_name *sname,
2547 struct linkea_data *ldata,
2548 struct thandle *handle)
2550 struct lu_attr *la = &mdd_env_info(env)->mti_la_for_fix;
2553 LASSERT(ma->ma_attr.la_valid & LA_CTIME);
2554 la->la_ctime = la->la_mtime = ma->ma_attr.la_ctime;
2560 /* name from source dir */
2561 rc = mdo_declare_index_delete(env, mdd_spobj, sname->ln_name, handle);
2565 /* .. from source child */
2566 if (S_ISDIR(mdd_object_type(mdd_sobj))) {
2567 /* source child can be directory,
2568 * counted by source dir's nlink */
2569 rc = mdo_declare_ref_del(env, mdd_spobj, handle);
2572 if (mdd_spobj != mdd_tpobj) {
2573 rc = mdo_declare_index_delete(env, mdd_sobj, dotdot,
2578 rc = mdo_declare_index_insert(env, mdd_sobj,
2580 S_IFDIR, dotdot, handle);
2585 /* new target child can be directory,
2586 * counted by target dir's nlink */
2587 rc = mdo_declare_ref_add(env, mdd_tpobj, handle);
2592 la->la_valid = LA_CTIME | LA_MTIME;
2593 rc = mdo_declare_attr_set(env, mdd_spobj, la, handle);
2597 rc = mdo_declare_attr_set(env, mdd_tpobj, la, handle);
2601 la->la_valid = LA_CTIME;
2602 rc = mdo_declare_attr_set(env, mdd_sobj, la, handle);
2606 rc = mdd_declare_links_add(env, mdd_sobj, handle, ldata,
2607 S_ISREG(mdd_object_type(mdd_sobj)) ? MLAO_CHECK : MLAO_IGNORE);
2612 rc = mdo_declare_index_insert(env, mdd_tpobj, mdo2fid(mdd_sobj),
2613 mdd_object_type(mdd_sobj),
2614 tname->ln_name, handle);
2618 /* name from target dir (old name), we declare it unconditionally
2619 * as mdd_rename() calls delete unconditionally as well. so just
2620 * to balance declarations vs calls to change ... */
2621 rc = mdo_declare_index_delete(env, mdd_tpobj, tname->ln_name, handle);
2625 if (mdd_tobj && mdd_object_exists(mdd_tobj)) {
2626 /* delete target child in target parent directory */
2627 rc = mdo_declare_ref_del(env, mdd_tobj, handle);
2631 if (S_ISDIR(mdd_object_type(mdd_tobj))) {
2632 /* target child can be directory,
2633 * delete "." reference in target child directory */
2634 rc = mdo_declare_ref_del(env, mdd_tobj, handle);
2638 /* delete ".." reference in target parent directory */
2639 rc = mdo_declare_ref_del(env, mdd_tpobj, handle);
2644 la->la_valid = LA_CTIME;
2645 rc = mdo_declare_attr_set(env, mdd_tobj, la, handle);
2649 rc = mdd_declare_finish_unlink(env, mdd_tobj, handle);
2654 rc = mdd_declare_changelog_store(env, mdd, tname, sname, handle);
2661 /* src object can be remote that is why we use only fid and type of object */
2662 static int mdd_rename(const struct lu_env *env,
2663 struct md_object *src_pobj, struct md_object *tgt_pobj,
2664 const struct lu_fid *lf, const struct lu_name *lsname,
2665 struct md_object *tobj, const struct lu_name *ltname,
2668 const char *sname = lsname->ln_name;
2669 const char *tname = ltname->ln_name;
2670 struct lu_attr *la = &mdd_env_info(env)->mti_la_for_fix;
2671 struct mdd_object *mdd_spobj = md2mdd_obj(src_pobj); /* source parent */
2672 struct mdd_object *mdd_tpobj = md2mdd_obj(tgt_pobj);
2673 struct mdd_device *mdd = mdo2mdd(src_pobj);
2674 struct mdd_object *mdd_sobj = NULL; /* source object */
2675 struct mdd_object *mdd_tobj = NULL;
2676 struct lu_attr *cattr = MDD_ENV_VAR(env, cattr);
2677 struct lu_attr *pattr = MDD_ENV_VAR(env, pattr);
2678 struct lu_attr *tattr = MDD_ENV_VAR(env, tattr);
2679 struct lu_attr *tpattr = MDD_ENV_VAR(env, tpattr);
2680 struct thandle *handle;
2681 struct linkea_data *ldata = &mdd_env_info(env)->mti_link_data;
2682 const struct lu_fid *tpobj_fid = mdo2fid(mdd_tpobj);
2683 const struct lu_fid *spobj_fid = mdo2fid(mdd_spobj);
2686 bool tobj_locked = 0;
2687 unsigned cl_flags = 0;
2692 mdd_tobj = md2mdd_obj(tobj);
2694 mdd_sobj = mdd_object_find(env, mdd, lf);
2696 rc = mdd_la_get(env, mdd_sobj, cattr);
2698 GOTO(out_pending, rc);
2700 rc = mdd_la_get(env, mdd_spobj, pattr);
2702 GOTO(out_pending, rc);
2705 rc = mdd_la_get(env, mdd_tobj, tattr);
2707 GOTO(out_pending, rc);
2710 rc = mdd_la_get(env, mdd_tpobj, tpattr);
2712 GOTO(out_pending, rc);
2714 rc = mdd_rename_sanity_check(env, mdd_spobj, pattr, mdd_tpobj, tpattr,
2715 mdd_sobj, cattr, mdd_tobj, tattr);
2717 GOTO(out_pending, rc);
2719 rc = mdd_name_check(mdd, ltname);
2721 GOTO(out_pending, rc);
2723 handle = mdd_trans_create(env, mdd);
2725 GOTO(out_pending, rc = PTR_ERR(handle));
2727 memset(ldata, 0, sizeof(*ldata));
2728 mdd_linkea_prepare(env, mdd_sobj, NULL, NULL, mdd_object_fid(mdd_tpobj),
2729 ltname, 1, 0, ldata);
2730 rc = mdd_declare_rename(env, mdd, mdd_spobj, mdd_tpobj, mdd_sobj,
2731 mdd_tobj, lsname, ltname, ma, ldata, handle);
2735 rc = mdd_trans_start(env, mdd, handle);
2739 /* FIXME: Should consider tobj and sobj too in rename_lock. */
2740 rc = mdd_rename_order(env, mdd, mdd_spobj, pattr, mdd_tpobj);
2742 GOTO(cleanup_unlocked, rc);
2744 is_dir = S_ISDIR(cattr->la_mode);
2746 /* Remove source name from source directory */
2747 rc = __mdd_index_delete(env, mdd_spobj, sname, is_dir, handle);
2751 /* "mv dir1 dir2" needs "dir1/.." link update */
2752 if (is_dir && mdd_sobj && !lu_fid_eq(spobj_fid, tpobj_fid)) {
2753 rc = __mdd_index_delete_only(env, mdd_sobj, dotdot, handle);
2755 GOTO(fixup_spobj2, rc);
2757 rc = __mdd_index_insert_only(env, mdd_sobj, tpobj_fid, S_IFDIR,
2760 GOTO(fixup_spobj, rc);
2763 /* Remove target name from target directory
2764 * Here tobj can be remote one, so we do index_delete unconditionally
2765 * and -ENOENT is allowed.
2767 rc = __mdd_index_delete(env, mdd_tpobj, tname, is_dir, handle);
2770 /* tname might been renamed to something else */
2771 GOTO(fixup_spobj, rc);
2774 GOTO(fixup_spobj, rc);
2777 /* Insert new fid with target name into target dir */
2778 rc = __mdd_index_insert(env, mdd_tpobj, lf, cattr->la_mode,
2781 GOTO(fixup_tpobj, rc);
2783 LASSERT(ma->ma_attr.la_valid & LA_CTIME);
2784 la->la_ctime = la->la_mtime = ma->ma_attr.la_ctime;
2786 /* XXX: mdd_sobj must be local one if it is NOT NULL. */
2788 la->la_valid = LA_CTIME;
2789 rc = mdd_update_time(env, mdd_sobj, cattr, la, handle);
2791 GOTO(fixup_tpobj, rc);
2794 /* Remove old target object
2795 * For tobj is remote case cmm layer has processed
2796 * and set tobj to NULL then. So when tobj is NOT NULL,
2797 * it must be local one.
2799 if (tobj && mdd_object_exists(mdd_tobj)) {
2800 mdd_write_lock(env, mdd_tobj, MOR_TGT_CHILD);
2802 if (mdd_is_dead_obj(mdd_tobj)) {
2803 /* shld not be dead, something is wrong */
2804 CERROR("tobj is dead, something is wrong\n");
2808 mdo_ref_del(env, mdd_tobj, handle);
2810 /* Remove dot reference. */
2811 if (S_ISDIR(tattr->la_mode))
2812 mdo_ref_del(env, mdd_tobj, handle);
2815 /* fetch updated nlink */
2816 rc = mdd_la_get(env, mdd_tobj, tattr);
2818 CERROR("%s: Failed to get nlink for tobj "
2820 mdd2obd_dev(mdd)->obd_name,
2821 PFID(tpobj_fid), rc);
2822 GOTO(fixup_tpobj, rc);
2825 la->la_valid = LA_CTIME;
2826 rc = mdd_update_time(env, mdd_tobj, tattr, la, handle);
2828 CERROR("%s: Failed to set ctime for tobj "
2830 mdd2obd_dev(mdd)->obd_name,
2831 PFID(tpobj_fid), rc);
2832 GOTO(fixup_tpobj, rc);
2835 /* XXX: this transfer to ma will be removed with LOD/OSP */
2836 ma->ma_attr = *tattr;
2837 ma->ma_valid |= MA_INODE;
2838 rc = mdd_finish_unlink(env, mdd_tobj, ma, mdd_tpobj, ltname,
2841 CERROR("%s: Failed to unlink tobj "
2843 mdd2obd_dev(mdd)->obd_name,
2844 PFID(tpobj_fid), rc);
2845 GOTO(fixup_tpobj, rc);
2848 /* fetch updated nlink */
2849 rc = mdd_la_get(env, mdd_tobj, tattr);
2851 CERROR("%s: Failed to get nlink for tobj "
2853 mdd2obd_dev(mdd)->obd_name,
2854 PFID(tpobj_fid), rc);
2855 GOTO(fixup_tpobj, rc);
2857 /* XXX: this transfer to ma will be removed with LOD/OSP */
2858 ma->ma_attr = *tattr;
2859 ma->ma_valid |= MA_INODE;
2861 if (tattr->la_nlink == 0) {
2862 cl_flags |= CLF_RENAME_LAST;
2863 if (mdd_hsm_archive_exists(env, mdd_tobj, ma))
2864 cl_flags |= CLF_RENAME_LAST_EXISTS;
2868 la->la_valid = LA_CTIME | LA_MTIME;
2869 rc = mdd_update_time(env, mdd_spobj, pattr, la, handle);
2871 GOTO(fixup_tpobj, rc);
2873 if (mdd_spobj != mdd_tpobj) {
2874 la->la_valid = LA_CTIME | LA_MTIME;
2875 rc = mdd_update_time(env, mdd_tpobj, tpattr, la, handle);
2878 if (rc == 0 && mdd_sobj) {
2879 mdd_write_lock(env, mdd_sobj, MOR_SRC_CHILD);
2880 rc = mdd_links_rename(env, mdd_sobj, mdo2fid(mdd_spobj), lsname,
2881 mdo2fid(mdd_tpobj), ltname, handle, NULL,
2884 /* Old files might not have EA entry */
2885 mdd_links_add(env, mdd_sobj, mdo2fid(mdd_spobj),
2886 lsname, handle, NULL, 0);
2887 mdd_write_unlock(env, mdd_sobj);
2888 /* We don't fail the transaction if the link ea can't be
2889 updated -- fid2path will use alternate lookup method. */
2897 rc2 = __mdd_index_delete(env, mdd_tpobj, tname, is_dir, handle);
2899 CWARN("tp obj fix error %d\n",rc2);
2901 if (mdd_tobj && mdd_object_exists(mdd_tobj) &&
2902 !mdd_is_dead_obj(mdd_tobj)) {
2904 mdo_ref_add(env, mdd_tobj, handle);
2906 mdo_ref_add(env, mdd_tobj, handle);
2909 rc2 = __mdd_index_insert(env, mdd_tpobj,
2911 mdd_object_type(mdd_tobj),
2914 CWARN("tp obj fix error: rc = %d\n", rc2);
2919 if (rc && is_dir && mdd_sobj && mdd_spobj != mdd_tpobj) {
2920 rc2 = __mdd_index_delete_only(env, mdd_sobj, dotdot, handle);
2922 CWARN("%s: sp obj dotdot delete error: rc = %d\n",
2923 mdd2obd_dev(mdd)->obd_name, rc2);
2926 rc2 = __mdd_index_insert_only(env, mdd_sobj, spobj_fid, S_IFDIR,
2929 CWARN("%s: sp obj dotdot insert error: rc = %d\n",
2930 mdd2obd_dev(mdd)->obd_name, rc2);
2935 rc2 = __mdd_index_insert(env, mdd_spobj, lf,
2936 mdd_object_type(mdd_sobj), sname,
2939 CWARN("sp obj fix error: rc = %d\n", rc2);
2944 mdd_write_unlock(env, mdd_tobj);
2948 rc = mdd_changelog_ns_store(env, mdd, CL_RENAME, cl_flags,
2949 mdd_tobj, tpobj_fid, lf, spobj_fid,
2950 ltname, lsname, handle);
2953 mdd_trans_stop(env, mdd, rc, handle);
2956 mdd_object_put(env, mdd_sobj);
2961 * During migration once the parent FID has been changed,
2962 * we need update the parent FID in linkea.
2964 static int mdd_linkea_update_child_internal(const struct lu_env *env,
2965 struct mdd_object *parent,
2966 struct mdd_object *child,
2967 const char *name, int namelen,
2968 struct thandle *handle,
2971 struct mdd_thread_info *info = mdd_env_info(env);
2972 struct linkea_data ldata = { NULL };
2973 struct lu_buf *buf = &info->mti_link_buf;
2979 buf = lu_buf_check_and_alloc(buf, PATH_MAX);
2980 if (buf->lb_buf == NULL)
2984 rc = mdd_links_read(env, child, &ldata);
2986 if (rc == -ENOENT || rc == -ENODATA)
2991 LASSERT(ldata.ld_leh != NULL);
2992 ldata.ld_lee = (struct link_ea_entry *)(ldata.ld_leh + 1);
2993 for (count = 0; count < ldata.ld_leh->leh_reccount; count++) {
2994 struct mdd_device *mdd = mdo2mdd(&child->mod_obj);
2995 struct lu_name lname;
2998 linkea_entry_unpack(ldata.ld_lee, &ldata.ld_reclen,
3001 if (strncmp(lname.ln_name, name, namelen) != 0 ||
3002 lu_fid_eq(&fid, mdd_object_fid(parent))) {
3003 ldata.ld_lee = (struct link_ea_entry *)
3004 ((char *)ldata.ld_lee +
3009 CDEBUG(D_INFO, "%s: update "DFID" with %.*s:"DFID"\n",
3010 mdd2obd_dev(mdd)->obd_name, PFID(mdd_object_fid(child)),
3011 lname.ln_namelen, lname.ln_name,
3012 PFID(mdd_object_fid(parent)));
3013 /* update to the new parent fid */
3014 linkea_entry_pack(ldata.ld_lee, &lname,
3015 mdd_object_fid(parent));
3017 rc = mdd_declare_links_add(env, child, handle, &ldata,
3020 rc = mdd_links_write(env, child, &ldata, handle);
3026 static int mdd_linkea_declare_update_child(const struct lu_env *env,
3027 struct mdd_object *parent,
3028 struct mdd_object *child,
3029 const char *name, int namelen,
3030 struct thandle *handle)
3032 return mdd_linkea_update_child_internal(env, parent, child, name,
3033 namelen, handle, true);
3036 static int mdd_linkea_update_child(const struct lu_env *env,
3037 struct mdd_object *parent,
3038 struct mdd_object *child,
3039 const char *name, int namelen,
3040 struct thandle *handle)
3042 return mdd_linkea_update_child_internal(env, parent, child, name,
3043 namelen, handle, false);
3046 static int mdd_update_linkea_internal(const struct lu_env *env,
3047 struct mdd_object *mdd_pobj,
3048 struct mdd_object *mdd_sobj,
3049 struct mdd_object *mdd_tobj,
3050 const struct lu_name *child_name,
3051 struct thandle *handle,
3054 struct mdd_thread_info *info = mdd_env_info(env);
3055 struct linkea_data *ldata = &info->mti_link_data;
3060 rc = mdd_links_read(env, mdd_sobj, ldata);
3062 if (rc == -ENOENT || rc == -ENODATA)
3067 /* If it is mulitple links file, we need update the name entry for
3069 LASSERT(ldata->ld_leh != NULL);
3070 ldata->ld_lee = (struct link_ea_entry *)(ldata->ld_leh + 1);
3071 for (count = 0; count < ldata->ld_leh->leh_reccount; count++) {
3072 struct mdd_device *mdd = mdo2mdd(&mdd_sobj->mod_obj);
3073 struct mdd_object *pobj;
3074 struct lu_name lname;
3077 linkea_entry_unpack(ldata->ld_lee, &ldata->ld_reclen,
3079 ldata->ld_lee = (struct link_ea_entry *)((char *)ldata->ld_lee +
3081 pobj = mdd_object_find(env, mdd, &fid);
3083 CWARN("%s: cannot find obj "DFID": rc = %ld\n",
3084 mdd2obd_dev(mdd)->obd_name, PFID(&fid),
3089 if (!mdd_object_exists(pobj)) {
3090 CDEBUG(D_INFO, "%s: obj "DFID" does not exist\n",
3091 mdd2obd_dev(mdd)->obd_name, PFID(&fid));
3095 if (pobj == mdd_pobj &&
3096 lname.ln_namelen == child_name->ln_namelen &&
3097 strncmp(lname.ln_name, child_name->ln_name,
3098 lname.ln_namelen) == 0) {
3099 CDEBUG(D_INFO, "%s: skip its own %s: "DFID"\n",
3100 mdd2obd_dev(mdd)->obd_name, child_name->ln_name,
3105 CDEBUG(D_INFO, "%s: update "DFID" with "DNAME":"DFID"\n",
3106 mdd2obd_dev(mdd)->obd_name, PFID(mdd_object_fid(pobj)),
3107 PNAME(&lname), PFID(mdd_object_fid(mdd_tobj)));
3110 /* Remove source name from source directory */
3111 /* Insert new fid with target name into target dir */
3112 rc = mdo_declare_index_delete(env, pobj, lname.ln_name,
3117 rc = mdo_declare_index_insert(env, pobj,
3118 mdd_object_fid(mdd_tobj),
3119 mdd_object_type(mdd_tobj),
3120 lname.ln_name, handle);
3124 rc = mdo_declare_ref_add(env, mdd_tobj, handle);
3128 rc = mdo_declare_ref_del(env, mdd_sobj, handle);
3132 rc = __mdd_index_delete(env, pobj, lname.ln_name,
3137 rc = __mdd_index_insert(env, pobj,
3138 mdd_object_fid(mdd_tobj),
3139 mdd_object_type(mdd_tobj),
3140 lname.ln_name, handle);
3144 mdd_write_lock(env, mdd_tobj, MOR_SRC_CHILD);
3145 rc = mdo_ref_add(env, mdd_tobj, handle);
3146 mdd_write_unlock(env, mdd_tobj);
3150 mdd_write_lock(env, mdd_sobj, MOR_TGT_CHILD);
3151 mdo_ref_del(env, mdd_sobj, handle);
3152 mdd_write_unlock(env, mdd_sobj);
3155 mdd_object_put(env, pobj);
3163 static int mdd_migrate_xattrs(const struct lu_env *env,
3164 struct mdd_object *mdd_sobj,
3165 struct mdd_object *mdd_tobj)
3167 struct mdd_thread_info *info = mdd_env_info(env);
3168 struct mdd_device *mdd = mdo2mdd(&mdd_sobj->mod_obj);
3170 struct thandle *handle;
3176 struct lu_buf list_xbuf;
3179 /* retrieve xattr list from the old object */
3180 list_xsize = mdo_xattr_list(env, mdd_sobj, &LU_BUF_NULL);
3181 if (list_xsize == -ENODATA)
3187 lu_buf_check_and_alloc(&info->mti_big_buf, list_xsize);
3188 if (info->mti_big_buf.lb_buf == NULL)
3191 list_xbuf.lb_buf = info->mti_big_buf.lb_buf;
3192 list_xbuf.lb_len = list_xsize;
3193 rc = mdo_xattr_list(env, mdd_sobj, &list_xbuf);
3198 xname = list_xbuf.lb_buf;
3200 xlen = strnlen(xname, rem - 1) + 1;
3201 if (strcmp(XATTR_NAME_LINK, xname) == 0 ||
3202 strcmp(XATTR_NAME_LMA, xname) == 0 ||
3203 strcmp(XATTR_NAME_LMV, xname) == 0)
3206 /* For directory, if there are default layout, migrate here */
3207 if (strcmp(XATTR_NAME_LOV, xname) == 0 &&
3208 !S_ISDIR(lu_object_attr(&mdd_sobj->mod_obj.mo_lu)))
3211 xsize = mdo_xattr_get(env, mdd_sobj, &LU_BUF_NULL, xname);
3212 if (xsize == -ENODATA)
3217 lu_buf_check_and_alloc(&info->mti_link_buf, xsize);
3218 if (info->mti_link_buf.lb_buf == NULL)
3219 GOTO(out, rc = -ENOMEM);
3221 xbuf.lb_len = xsize;
3222 xbuf.lb_buf = info->mti_link_buf.lb_buf;
3223 rc = mdo_xattr_get(env, mdd_sobj, &xbuf, xname);
3229 handle = mdd_trans_create(env, mdd);
3231 GOTO(out, rc = PTR_ERR(handle));
3233 rc = mdo_declare_xattr_set(env, mdd_tobj, &xbuf, xname, 0,
3236 GOTO(stop_trans, rc);
3237 /* Note: this transaction is part of migration, and it is not
3238 * the last step of migration, so we set th_local = 1 to avoid
3239 * update last rcvd for this transaction */
3240 handle->th_local = 1;
3241 rc = mdd_trans_start(env, mdd, handle);
3243 GOTO(stop_trans, rc);
3245 rc = mdo_xattr_set(env, mdd_tobj, &xbuf, xname, 0, handle);
3247 GOTO(stop_trans, rc = 0);
3250 GOTO(stop_trans, rc);
3252 mdd_trans_stop(env, mdd, rc, handle);
3257 memmove(xname, xname + xlen, rem);
3263 static int mdd_declare_migrate_create(const struct lu_env *env,
3264 struct mdd_object *mdd_pobj,
3265 struct mdd_object *mdd_sobj,
3266 struct mdd_object *mdd_tobj,
3267 struct md_op_spec *spec,
3269 union lmv_mds_md *mgr_ea,
3270 struct linkea_data *ldata,
3271 struct thandle *handle)
3273 struct lu_attr *la_flag = MDD_ENV_VAR(env, la_for_fix);
3274 const struct lu_buf *buf;
3278 rc = mdd_declare_object_create_internal(env, mdd_pobj, mdd_tobj, la,
3279 handle, spec, NULL);
3283 rc = mdd_declare_object_initialize(env, mdd_pobj, mdd_tobj, la,
3288 if (S_ISLNK(la->la_mode)) {
3289 const char *target_name = spec->u.sp_symname;
3290 int sym_len = strlen(target_name);
3291 const struct lu_buf *buf;
3293 buf = mdd_buf_get_const(env, target_name, sym_len);
3294 rc = dt_declare_record_write(env, mdd_object_child(mdd_tobj),
3298 } else if (S_ISDIR(la->la_mode)) {
3299 rc = mdd_declare_links_add(env, mdd_tobj, handle, ldata,
3305 if (spec->u.sp_ea.eadata != NULL && spec->u.sp_ea.eadatalen != 0) {
3306 buf = mdd_buf_get_const(env, spec->u.sp_ea.eadata,
3307 spec->u.sp_ea.eadatalen);
3308 rc = mdo_declare_xattr_set(env, mdd_tobj, buf, XATTR_NAME_LOV,
3314 mgr_easize = lmv_mds_md_size(2, LMV_MAGIC_V1);
3315 buf = mdd_buf_get_const(env, mgr_ea, mgr_easize);
3316 rc = mdo_declare_xattr_set(env, mdd_sobj, buf, XATTR_NAME_LMV,
3321 la_flag->la_valid = LA_FLAGS;
3322 la_flag->la_flags = la->la_flags | LUSTRE_IMMUTABLE_FL;
3323 rc = mdo_declare_attr_set(env, mdd_sobj, la_flag, handle);
3328 static int mdd_migrate_create(const struct lu_env *env,
3329 struct mdd_object *mdd_pobj,
3330 struct mdd_object *mdd_sobj,
3331 struct mdd_object *mdd_tobj,
3332 const struct lu_name *lname,
3335 struct mdd_thread_info *info = mdd_env_info(env);
3336 struct mdd_device *mdd = mdo2mdd(&mdd_sobj->mod_obj);
3337 struct md_op_spec *spec = &info->mti_spec;
3338 struct lu_buf lmm_buf = { NULL };
3339 struct lu_buf link_buf = { NULL };
3340 const struct lu_buf *buf;
3341 struct thandle *handle;
3342 struct lmv_mds_md_v1 *mgr_ea;
3343 struct lu_attr *la_flag = MDD_ENV_VAR(env, la_for_fix);
3344 struct dt_allocation_hint *hint = &mdd_env_info(env)->mti_hint;
3346 struct linkea_data *ldata = &mdd_env_info(env)->mti_link_data;
3350 /* prepare spec for create */
3351 memset(spec, 0, sizeof(*spec));
3352 spec->sp_cr_lookup = 0;
3353 spec->sp_feat = &dt_directory_features;
3354 if (S_ISLNK(la->la_mode)) {
3355 buf = lu_buf_check_and_alloc(
3356 &mdd_env_info(env)->mti_big_buf,
3359 link_buf.lb_len = la->la_size + 1;
3360 memset(link_buf.lb_buf, 0, link_buf.lb_len);
3361 rc = mdd_readlink(env, &mdd_sobj->mod_obj, &link_buf);
3363 rc = rc != 0 ? rc : -EFAULT;
3364 CERROR("%s: "DFID" readlink failed: rc = %d\n",
3365 mdd2obd_dev(mdd)->obd_name,
3366 PFID(mdd_object_fid(mdd_sobj)), rc);
3369 spec->u.sp_symname = link_buf.lb_buf;
3370 } else if S_ISREG(la->la_mode) {
3371 /* retrieve lov of the old object */
3372 rc = mdd_get_lov_ea(env, mdd_sobj, &lmm_buf);
3373 if (rc != 0 && rc != -ENODATA)
3375 if (lmm_buf.lb_buf != NULL && lmm_buf.lb_len != 0) {
3376 spec->u.sp_ea.eadata = lmm_buf.lb_buf;
3377 spec->u.sp_ea.eadatalen = lmm_buf.lb_len;
3378 spec->sp_cr_flags |= MDS_OPEN_HAS_EA;
3380 } else if (S_ISDIR(la->la_mode)) {
3381 rc = mdd_links_read(env, mdd_sobj, ldata);
3382 if (rc < 0 && rc != -ENODATA)
3386 mgr_ea = (struct lmv_mds_md_v1 *)info->mti_xattr_buf;
3387 memset(mgr_ea, 0, sizeof(*mgr_ea));
3388 mgr_ea->lmv_magic = cpu_to_le32(LMV_MAGIC_V1);
3389 mgr_ea->lmv_stripe_count = cpu_to_le32(2);
3390 mgr_ea->lmv_master_mdt_index = mdd_seq_site(mdd)->ss_node_id;
3391 mgr_ea->lmv_hash_type = cpu_to_le32(LMV_HASH_FLAG_MIGRATION);
3392 fid_cpu_to_le(&mgr_ea->lmv_stripe_fids[0], mdd_object_fid(mdd_sobj));
3393 fid_cpu_to_le(&mgr_ea->lmv_stripe_fids[1], mdd_object_fid(mdd_tobj));
3395 mdd_object_make_hint(env, mdd_pobj, mdd_tobj, la, spec, hint);
3397 handle = mdd_trans_create(env, mdd);
3399 GOTO(out_free, rc = PTR_ERR(handle));
3401 /* Note: this transaction is part of migration, and it is not
3402 * the last step of migration, so we set th_local = 1 to avoid
3403 * update last rcvd for this transaction */
3404 handle->th_local = 1;
3405 rc = mdd_declare_migrate_create(env, mdd_pobj, mdd_sobj, mdd_tobj,
3407 (union lmv_mds_md *)info->mti_xattr_buf,
3410 GOTO(stop_trans, rc);
3412 rc = mdd_trans_start(env, mdd, handle);
3414 GOTO(stop_trans, rc);
3416 /* create the target object */
3417 rc = mdd_object_create(env, mdd_pobj, mdd_tobj, la, spec, NULL, NULL,
3420 GOTO(stop_trans, rc);
3422 if (S_ISDIR(la->la_mode)) {
3423 rc = mdd_links_write(env, mdd_tobj, ldata, handle);
3425 GOTO(stop_trans, rc);
3428 /* Set MIGRATE EA on the source inode, so once the migration needs
3429 * to be re-done during failover, the re-do process can locate the
3430 * target object which is already being created. */
3431 mgr_easize = lmv_mds_md_size(2, LMV_MAGIC_V1);
3432 buf = mdd_buf_get_const(env, mgr_ea, mgr_easize);
3433 rc = mdo_xattr_set(env, mdd_sobj, buf, XATTR_NAME_LMV, 0, handle);
3435 GOTO(stop_trans, rc);
3437 /* Set immutable flag, so any modification is disabled until
3438 * the migration is done. Once the migration is interrupted,
3439 * if the resume process find the migrating object has both
3440 * IMMUTALBE flag and MIGRATE EA, it need to clear IMMUTABLE
3441 * flag and approve the migration */
3442 la_flag->la_valid = LA_FLAGS;
3443 la_flag->la_flags = la->la_flags | LUSTRE_IMMUTABLE_FL;
3444 rc = mdo_attr_set(env, mdd_sobj, la_flag, handle);
3447 mdd_trans_stop(env, mdd, rc, handle);
3449 if (lmm_buf.lb_buf != NULL)
3450 OBD_FREE(lmm_buf.lb_buf, lmm_buf.lb_len);
3454 static int mdd_migrate_entries(const struct lu_env *env,
3455 struct mdd_object *mdd_sobj,
3456 struct mdd_object *mdd_tobj)
3458 struct dt_object *next = mdd_object_child(mdd_sobj);
3459 struct mdd_device *mdd = mdo2mdd(&mdd_sobj->mod_obj);
3460 struct dt_object *dt_tobj = mdd_object_child(mdd_tobj);
3461 struct thandle *handle;
3463 const struct dt_it_ops *iops;
3466 struct lu_dirent *ent;
3469 OBD_ALLOC(ent, NAME_MAX + sizeof(*ent) + 1);
3473 if (!dt_try_as_dir(env, next))
3474 GOTO(out_ent, rc = -ENOTDIR);
3476 * iterate directories
3478 iops = &next->do_index_ops->dio_it;
3479 it = iops->init(env, next, LUDA_FID | LUDA_TYPE);
3481 GOTO(out_ent, rc = PTR_ERR(it));
3483 rc = iops->load(env, it, 0);
3485 rc = iops->next(env, it);
3489 * At this point and across for-loop:
3491 * rc == 0 -> ok, proceed.
3492 * rc > 0 -> end of directory.
3496 struct mdd_object *child;
3497 char *name = mdd_env_info(env)->mti_key;
3501 bool target_exist = false;
3503 len = iops->key_size(env, it);
3507 result = iops->rec(env, it, (struct dt_rec *)ent,
3508 LUDA_FID | LUDA_TYPE);
3509 if (result == -ESTALE)
3516 fid_le_to_cpu(&ent->lde_fid, &ent->lde_fid);
3517 recsize = le16_to_cpu(ent->lde_reclen);
3519 /* Insert new fid with target name into target dir */
3520 if ((ent->lde_namelen == 1 && ent->lde_name[0] == '.') ||
3521 (ent->lde_namelen == 2 && ent->lde_name[0] == '.' &&
3522 ent->lde_name[1] == '.'))
3525 child = mdd_object_find(env, mdd, &ent->lde_fid);
3527 GOTO(out, rc = PTR_ERR(child));
3529 is_dir = S_ISDIR(mdd_object_type(child));
3531 snprintf(name, ent->lde_namelen + 1, "%s", ent->lde_name);
3533 /* Check whether the name has been inserted to the target */
3534 if (dt_try_as_dir(env, dt_tobj)) {
3535 struct lu_fid *fid = &mdd_env_info(env)->mti_fid2;
3537 rc = dt_lookup(env, dt_tobj, (struct dt_rec *)fid,
3538 (struct dt_key *)name);
3539 if (unlikely(rc == 0))
3540 target_exist = true;
3543 handle = mdd_trans_create(env, mdd);
3545 GOTO(out, rc = PTR_ERR(handle));
3547 /* Note: this transaction is part of migration, and it is not
3548 * the last step of migration, so we set th_local = 1 to avoid
3549 * updating last rcvd for this transaction */
3550 handle->th_local = 1;
3551 if (likely(!target_exist)) {
3552 rc = mdo_declare_index_insert(env, mdd_tobj,
3554 mdd_object_type(child),
3560 rc = mdo_declare_ref_add(env, mdd_tobj, handle);
3566 rc = mdo_declare_index_delete(env, mdd_sobj, name, handle);
3571 rc = mdo_declare_ref_del(env, mdd_sobj, handle);
3575 /* Update .. for child */
3576 rc = mdo_declare_index_delete(env, child, dotdot,
3581 rc = mdo_declare_index_insert(env, child,
3582 mdd_object_fid(mdd_tobj),
3583 S_IFDIR, dotdot, handle);
3588 rc = mdd_linkea_declare_update_child(env, mdd_tobj,
3595 rc = mdd_trans_start(env, mdd, handle);
3597 CERROR("%s: transaction start failed: rc = %d\n",
3598 mdd2obd_dev(mdd)->obd_name, rc);
3602 if (likely(!target_exist)) {
3603 rc = __mdd_index_insert(env, mdd_tobj, &ent->lde_fid,
3604 mdd_object_type(child),
3610 rc = __mdd_index_delete(env, mdd_sobj, name, is_dir, handle);
3615 rc = __mdd_index_delete_only(env, child, dotdot,
3620 rc = __mdd_index_insert_only(env, child,
3621 mdd_object_fid(mdd_tobj), S_IFDIR,
3627 rc = mdd_linkea_update_child(env, mdd_tobj, child, name,
3628 strlen(name), handle);
3631 mdd_object_put(env, child);
3632 mdd_trans_stop(env, mdd, rc, handle);
3636 result = iops->next(env, it);
3637 if (OBD_FAIL_CHECK(OBD_FAIL_MIGRATE_ENTRIES))
3638 GOTO(out, rc = -EINTR);
3640 if (result == -ESTALE)
3642 } while (result == 0);
3645 iops->fini(env, it);
3647 OBD_FREE(ent, NAME_MAX + sizeof(*ent) + 1);
3651 static int mdd_declare_update_linkea(const struct lu_env *env,
3652 struct mdd_object *mdd_pobj,
3653 struct mdd_object *mdd_sobj,
3654 struct mdd_object *mdd_tobj,
3655 struct thandle *handle,
3656 const struct lu_name *child_name)
3658 return mdd_update_linkea_internal(env, mdd_pobj, mdd_sobj, mdd_tobj,
3659 child_name, handle, 1);
3662 static int mdd_update_linkea(const struct lu_env *env,
3663 struct mdd_object *mdd_pobj,
3664 struct mdd_object *mdd_sobj,
3665 struct mdd_object *mdd_tobj,
3666 struct thandle *handle,
3667 const struct lu_name *child_name)
3669 return mdd_update_linkea_internal(env, mdd_pobj, mdd_sobj, mdd_tobj,
3670 child_name, handle, 0);
3673 static int mdd_declare_migrate_update_name(const struct lu_env *env,
3674 struct mdd_object *mdd_pobj,
3675 struct mdd_object *mdd_sobj,
3676 struct mdd_object *mdd_tobj,
3677 const struct lu_name *lname,
3679 struct lu_attr *parent_la,
3680 struct thandle *handle)
3682 struct lu_attr *la_flag = MDD_ENV_VAR(env, tattr);
3685 /* Revert IMMUTABLE flag */
3686 la_flag->la_valid = LA_FLAGS;
3687 la_flag->la_flags = la->la_flags & ~LUSTRE_IMMUTABLE_FL;
3688 rc = mdo_declare_attr_set(env, mdd_sobj, la_flag, handle);
3692 /* delete entry from source dir */
3693 rc = mdo_declare_index_delete(env, mdd_pobj, lname->ln_name, handle);
3697 rc = mdd_declare_update_linkea(env, mdd_pobj, mdd_sobj,
3698 mdd_tobj, handle, lname);
3702 if (S_ISREG(mdd_object_type(mdd_sobj))) {
3703 rc = mdo_declare_xattr_del(env, mdd_sobj, XATTR_NAME_LOV,
3709 if (S_ISDIR(mdd_object_type(mdd_sobj))) {
3710 rc = mdo_declare_ref_del(env, mdd_pobj, handle);
3716 rc = mdo_declare_index_insert(env, mdd_pobj, mdo2fid(mdd_tobj),
3717 mdd_object_type(mdd_tobj),
3718 lname->ln_name, handle);
3722 rc = mdd_declare_links_add(env, mdd_tobj, handle, NULL, MLAO_IGNORE);
3726 if (S_ISDIR(mdd_object_type(mdd_sobj))) {
3727 rc = mdo_declare_ref_add(env, mdd_pobj, handle);
3732 /* delete old object */
3733 rc = mdo_declare_ref_del(env, mdd_sobj, handle);
3737 if (S_ISDIR(mdd_object_type(mdd_sobj))) {
3738 /* delete old object */
3739 rc = mdo_declare_ref_del(env, mdd_sobj, handle);
3742 /* set nlink to 0 */
3743 rc = mdo_declare_attr_set(env, mdd_sobj, la, handle);
3748 rc = mdd_declare_finish_unlink(env, mdd_sobj, handle);
3752 rc = mdo_declare_attr_set(env, mdd_pobj, parent_la, handle);
3757 static int mdd_migrate_update_name(const struct lu_env *env,
3758 struct mdd_object *mdd_pobj,
3759 struct mdd_object *mdd_sobj,
3760 struct mdd_object *mdd_tobj,
3761 const struct lu_name *lname,
3764 struct lu_attr *p_la = MDD_ENV_VAR(env, la_for_fix);
3765 struct lu_attr *so_attr = MDD_ENV_VAR(env, cattr);
3766 struct lu_attr *la_flag = MDD_ENV_VAR(env, tattr);
3767 struct mdd_device *mdd = mdo2mdd(&mdd_sobj->mod_obj);
3768 struct thandle *handle;
3769 int is_dir = S_ISDIR(mdd_object_type(mdd_sobj));
3770 const char *name = lname->ln_name;
3774 /* update time for parent */
3775 LASSERT(ma->ma_attr.la_valid & LA_CTIME);
3776 p_la->la_ctime = p_la->la_mtime = ma->ma_attr.la_ctime;
3777 p_la->la_valid = LA_CTIME;
3779 rc = mdd_la_get(env, mdd_sobj, so_attr);
3783 handle = mdd_trans_create(env, mdd);
3785 RETURN(PTR_ERR(handle));
3787 rc = mdd_declare_migrate_update_name(env, mdd_pobj, mdd_sobj, mdd_tobj,
3788 lname, so_attr, p_la, handle);
3790 /* If the migration can not be fit in one transaction, just
3791 * leave it in the original MDT */
3793 GOTO(stop_trans, rc = 0);
3795 GOTO(stop_trans, rc);
3798 CDEBUG(D_INFO, "%s: update "DFID"/"DFID" with %s:"DFID"\n",
3799 mdd2obd_dev(mdd)->obd_name, PFID(mdd_object_fid(mdd_pobj)),
3800 PFID(mdd_object_fid(mdd_sobj)), lname->ln_name,
3801 PFID(mdd_object_fid(mdd_tobj)));
3803 rc = mdd_trans_start(env, mdd, handle);
3805 GOTO(stop_trans, rc);
3807 /* Revert IMMUTABLE flag */
3808 la_flag->la_valid = LA_FLAGS;
3809 la_flag->la_flags = so_attr->la_flags & ~LUSTRE_IMMUTABLE_FL;
3810 rc = mdo_attr_set(env, mdd_sobj, la_flag, handle);
3812 GOTO(stop_trans, rc);
3814 /* Remove source name from source directory */
3815 rc = __mdd_index_delete(env, mdd_pobj, name, is_dir, handle);
3817 GOTO(stop_trans, rc);
3819 rc = mdd_update_linkea(env, mdd_pobj, mdd_sobj, mdd_tobj,
3822 GOTO(stop_trans, rc);
3824 if (S_ISREG(so_attr->la_mode)) {
3825 if (so_attr->la_nlink == 1) {
3826 rc = mdo_xattr_del(env, mdd_sobj, XATTR_NAME_LOV,
3828 if (rc != 0 && rc != -ENODATA)
3829 GOTO(stop_trans, rc);
3833 /* Insert new fid with target name into target dir */
3834 rc = __mdd_index_insert(env, mdd_pobj, mdd_object_fid(mdd_tobj),
3835 mdd_object_type(mdd_tobj), name, handle);
3837 GOTO(stop_trans, rc);
3839 rc = mdd_links_add(env, mdd_tobj, mdo2fid(mdd_pobj), lname, handle,
3842 GOTO(stop_trans, rc);
3844 mdd_write_lock(env, mdd_sobj, MOR_SRC_CHILD);
3845 mdo_ref_del(env, mdd_sobj, handle);
3847 mdo_ref_del(env, mdd_sobj, handle);
3849 /* Get the attr again after ref_del */
3850 rc = mdd_la_get(env, mdd_sobj, so_attr);
3852 GOTO(out_unlock, rc);
3854 ma->ma_attr = *so_attr;
3855 ma->ma_valid |= MA_INODE;
3856 rc = mdd_finish_unlink(env, mdd_sobj, ma, mdd_pobj, lname, handle);
3858 GOTO(out_unlock, rc);
3860 rc = mdd_attr_set_internal(env, mdd_pobj, p_la, handle, 0);
3862 GOTO(out_unlock, rc);
3865 mdd_write_unlock(env, mdd_sobj);
3868 mdd_trans_stop(env, mdd, rc, handle);
3874 * Check whether we should migrate the file/dir
3876 * < 0 permission check failed or other error.
3877 * = 0 the file can be migrated.
3878 * > 0 the file does not need to be migrated, mostly
3879 * for multiple link file
3881 static int mdd_migrate_sanity_check(const struct lu_env *env,
3882 struct mdd_object *pobj,
3883 const struct lu_attr *pattr,
3884 struct mdd_object *sobj,
3885 struct lu_attr *sattr)
3887 struct mdd_thread_info *info = mdd_env_info(env);
3888 struct linkea_data *ldata = &info->mti_link_data;
3890 struct lu_buf *mgr_buf;
3896 mgr_easize = lmv_mds_md_size(2, LMV_MAGIC_V1);
3897 mgr_buf = lu_buf_check_and_alloc(&info->mti_big_buf, mgr_easize);
3898 if (mgr_buf->lb_buf == NULL)
3901 rc = mdo_xattr_get(env, sobj, mgr_buf, XATTR_NAME_LMV);
3903 union lmv_mds_md *lmm = mgr_buf->lb_buf;
3905 /* If the object has migrateEA, it means IMMUTE flag
3906 * is being set by previous migration process, so it
3907 * needs to override the IMMUTE flag, otherwise the
3908 * following sanity check will fail */
3909 if (le32_to_cpu(lmm->lmv_md_v1.lmv_hash_type) &
3910 LMV_HASH_FLAG_MIGRATION) {
3911 struct mdd_device *mdd = mdo2mdd(&sobj->mod_obj);
3913 sattr->la_flags &= ~LUSTRE_IMMUTABLE_FL;
3914 CDEBUG(D_HA, "%s: "DFID" override IMMUTE FLAG\n",
3915 mdd2obd_dev(mdd)->obd_name,
3916 PFID(mdd_object_fid(sobj)));
3920 rc = mdd_rename_sanity_check(env, pobj, pattr, pobj, pattr,
3921 sobj, sattr, NULL, NULL);
3925 /* Then it will check if the file should be migrated. If the file
3926 * has mulitple links, we only need migrate the file if all of its
3927 * entries has been migrated to the remote MDT */
3928 if (!S_ISREG(sattr->la_mode) || sattr->la_nlink < 2)
3931 rc = mdd_links_read(env, sobj, ldata);
3933 /* For multiple links files, if there are no linkEA data at all,
3934 * means the file might be created before linkEA is enabled, and
3935 * all all of its links should not be migrated yet, otherwise
3936 * it should have some linkEA there */
3937 if (rc == -ENOENT || rc == -ENODATA)
3942 /* If it is mulitple links file, we need update the name entry for
3944 LASSERT(ldata->ld_leh != NULL);
3945 ldata->ld_lee = (struct link_ea_entry *)(ldata->ld_leh + 1);
3946 for (count = 0; count < ldata->ld_leh->leh_reccount; count++) {
3947 struct mdd_device *mdd = mdo2mdd(&sobj->mod_obj);
3948 struct mdd_object *lpobj;
3949 struct lu_name lname;
3952 linkea_entry_unpack(ldata->ld_lee, &ldata->ld_reclen,
3954 ldata->ld_lee = (struct link_ea_entry *)((char *)ldata->ld_lee +
3956 lpobj = mdd_object_find(env, mdd, &fid);
3957 if (IS_ERR(lpobj)) {
3958 CWARN("%s: cannot find obj "DFID": rc = %ld\n",
3959 mdd2obd_dev(mdd)->obd_name, PFID(&fid),
3964 if (!mdd_object_exists(lpobj) || mdd_object_remote(lpobj)) {
3965 CDEBUG(D_INFO, DFID"%.*s: is on remote MDT.\n",
3966 PFID(&fid), lname.ln_namelen, lname.ln_name);
3967 mdd_object_put(env, lpobj);
3971 CDEBUG(D_INFO, DFID"still has local entry %.*s "DFID"\n",
3972 PFID(mdd_object_fid(sobj)), lname.ln_namelen,
3973 lname.ln_name, PFID(&fid));
3974 mdd_object_put(env, lpobj);
3982 static int mdd_migrate(const struct lu_env *env, struct md_object *pobj,
3983 struct md_object *sobj, const struct lu_name *lname,
3984 struct md_object *tobj, struct md_attr *ma)
3986 struct mdd_object *mdd_pobj = md2mdd_obj(pobj);
3987 struct mdd_device *mdd = mdo2mdd(pobj);
3988 struct mdd_object *mdd_sobj = md2mdd_obj(sobj);
3989 struct mdd_object *mdd_tobj = NULL;
3990 struct lu_attr *so_attr = MDD_ENV_VAR(env, cattr);
3991 struct lu_attr *pattr = MDD_ENV_VAR(env, pattr);
3995 /* If the file will being migrated, it will check whether
3996 * the file is being opened by someone else right now */
3997 mdd_read_lock(env, mdd_sobj, MOR_SRC_CHILD);
3998 if (mdd_sobj->mod_count >= 1) {
3999 CERROR("%s: "DFID"%s is already opened count %d: rc = %d\n",
4000 mdd2obd_dev(mdd)->obd_name,
4001 PFID(mdd_object_fid(mdd_sobj)), lname->ln_name,
4002 mdd_sobj->mod_count, -EBUSY);
4003 mdd_read_unlock(env, mdd_sobj);
4004 GOTO(put, rc = -EBUSY);
4006 mdd_read_unlock(env, mdd_sobj);
4008 rc = mdd_la_get(env, mdd_sobj, so_attr);
4012 rc = mdd_la_get(env, mdd_pobj, pattr);
4016 rc = mdd_migrate_sanity_check(env, mdd_pobj, pattr, mdd_sobj, so_attr);
4023 /* Sigh, it is impossible to finish all of migration in a single
4024 * transaction, for example migrating big directory entries to the
4025 * new MDT, it needs insert all of name entries of children in the
4028 * So migration will be done in multiple steps and transactions.
4030 * 1. create an orphan object on the remote MDT in one transaction.
4031 * 2. migrate extend attributes to the new target file/directory.
4032 * 3. For directory, migrate the entries to the new MDT and update
4033 * linkEA of each children. Because we can not migrate all entries
4034 * in a single transaction, so the migrating directory will become
4035 * a striped directory during migration, so once the process is
4036 * interrupted, the directory is still accessible. (During lookup,
4037 * client will locate the name by searching both original and target
4039 * 4. Finally, update the name/FID to point to the new file/directory
4040 * in a separate transaction.
4043 /* step 1: Check whether the orphan object has been created, and create
4044 * orphan object on the remote MDT if needed */
4045 mdd_tobj = md2mdd_obj(tobj);
4046 if (!mdd_object_exists(mdd_tobj)) {
4047 rc = mdd_migrate_create(env, mdd_pobj, mdd_sobj, mdd_tobj,
4053 /* step 2: migrate xattr */
4054 rc = mdd_migrate_xattrs(env, mdd_sobj, mdd_tobj);
4058 /* step 3: migrate name entries to the orphan object */
4059 if (S_ISDIR(lu_object_attr(&mdd_sobj->mod_obj.mo_lu))) {
4060 rc = mdd_migrate_entries(env, mdd_sobj, mdd_tobj);
4063 if (unlikely(OBD_FAIL_CHECK_RESET(OBD_FAIL_MIGRATE_NET_REP,
4064 OBD_FAIL_MDS_REINT_NET_REP)))
4067 OBD_FAIL_TIMEOUT(OBD_FAIL_MIGRATE_DELAY, cfs_fail_val);
4070 /* step 4: update name entry to the new object */
4071 rc = mdd_migrate_update_name(env, mdd_pobj, mdd_sobj, mdd_tobj, lname,
4079 const struct md_dir_operations mdd_dir_ops = {
4080 .mdo_is_subdir = mdd_is_subdir,
4081 .mdo_lookup = mdd_lookup,
4082 .mdo_create = mdd_create,
4083 .mdo_rename = mdd_rename,
4084 .mdo_link = mdd_link,
4085 .mdo_unlink = mdd_unlink,
4086 .mdo_create_data = mdd_create_data,
4087 .mdo_migrate = mdd_migrate,