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 a 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("changelog failed: rc=%d, op%d %s c"DFID" p"DFID"\n",
855 rc, type, tname->ln_name, PFID(sfid), PFID(tpfid));
862 static int __mdd_links_add(const struct lu_env *env,
863 struct mdd_object *mdd_obj,
864 struct linkea_data *ldata,
865 const struct lu_name *lname,
866 const struct lu_fid *pfid,
867 int first, int check)
871 if (ldata->ld_leh == NULL) {
872 rc = first ? -ENODATA : mdd_links_read(env, mdd_obj, ldata);
876 rc = linkea_data_new(ldata,
877 &mdd_env_info(env)->mti_link_buf);
884 rc = linkea_links_find(ldata, lname, pfid);
885 if (rc && rc != -ENOENT)
891 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LINKEA_MORE)) {
892 struct lu_fid *tfid = &mdd_env_info(env)->mti_fid2;
896 linkea_add_buf(ldata, lname, tfid);
899 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LINKEA_MORE2))
900 linkea_add_buf(ldata, lname, pfid);
902 return linkea_add_buf(ldata, lname, pfid);
905 static int __mdd_links_del(const struct lu_env *env,
906 struct mdd_object *mdd_obj,
907 struct linkea_data *ldata,
908 const struct lu_name *lname,
909 const struct lu_fid *pfid)
913 if (ldata->ld_leh == NULL) {
914 rc = mdd_links_read(env, mdd_obj, ldata);
919 rc = linkea_links_find(ldata, lname, pfid);
923 linkea_del_buf(ldata, lname);
927 static int mdd_linkea_prepare(const struct lu_env *env,
928 struct mdd_object *mdd_obj,
929 const struct lu_fid *oldpfid,
930 const struct lu_name *oldlname,
931 const struct lu_fid *newpfid,
932 const struct lu_name *newlname,
933 int first, int check,
934 struct linkea_data *ldata)
940 if (OBD_FAIL_CHECK(OBD_FAIL_FID_IGIF))
943 LASSERT(oldpfid != NULL || newpfid != NULL);
945 if (mdd_obj->mod_flags & DEAD_OBJ) {
946 /* Prevent linkea to be updated which is NOT necessary. */
947 ldata->ld_reclen = 0;
948 /* No more links, don't bother */
952 if (oldpfid != NULL) {
953 rc = __mdd_links_del(env, mdd_obj, ldata, oldlname, oldpfid);
956 (rc != -ENODATA && rc != -ENOENT))
958 /* No changes done. */
963 /* If renaming, add the new record */
964 if (newpfid != NULL) {
965 /* even if the add fails, we still delete the out-of-date
967 rc2 = __mdd_links_add(env, mdd_obj, ldata, newlname, newpfid,
971 rc = rc != 0 ? rc : rc2;
976 int mdd_links_rename(const struct lu_env *env,
977 struct mdd_object *mdd_obj,
978 const struct lu_fid *oldpfid,
979 const struct lu_name *oldlname,
980 const struct lu_fid *newpfid,
981 const struct lu_name *newlname,
982 struct thandle *handle,
983 struct linkea_data *ldata,
984 int first, int check)
990 ldata = &mdd_env_info(env)->mti_link_data;
991 memset(ldata, 0, sizeof(*ldata));
992 rc = mdd_linkea_prepare(env, mdd_obj, oldpfid, oldlname,
993 newpfid, newlname, first, check,
999 if (ldata->ld_reclen != 0)
1000 rc = mdd_links_write(env, mdd_obj, ldata, handle);
1005 if (rc == -EOVERFLOW || rc == -ENOSPC)
1007 if (oldpfid == NULL)
1008 CDEBUG(error ? D_ERROR : D_OTHER,
1009 "link_ea add '%.*s' failed %d "DFID"\n",
1010 newlname->ln_namelen, newlname->ln_name,
1011 rc, PFID(mdd_object_fid(mdd_obj)));
1012 else if (newpfid == NULL)
1013 CDEBUG(error ? D_ERROR : D_OTHER,
1014 "link_ea del '%.*s' failed %d "DFID"\n",
1015 oldlname->ln_namelen, oldlname->ln_name,
1016 rc, PFID(mdd_object_fid(mdd_obj)));
1018 CDEBUG(error ? D_ERROR : D_OTHER,
1019 "link_ea rename '%.*s'->'%.*s' failed %d "
1021 oldlname->ln_namelen, oldlname->ln_name,
1022 newlname->ln_namelen, newlname->ln_name,
1023 rc, PFID(mdd_object_fid(mdd_obj)));
1026 if (ldata->ld_buf && ldata->ld_buf->lb_len > OBD_ALLOC_BIG)
1027 /* if we vmalloced a large buffer drop it */
1028 lu_buf_free(ldata->ld_buf);
1033 static inline int mdd_links_add(const struct lu_env *env,
1034 struct mdd_object *mdd_obj,
1035 const struct lu_fid *pfid,
1036 const struct lu_name *lname,
1037 struct thandle *handle,
1038 struct linkea_data *ldata, int first)
1040 return mdd_links_rename(env, mdd_obj, NULL, NULL,
1041 pfid, lname, handle, ldata, first, 0);
1044 static inline int mdd_links_del(const struct lu_env *env,
1045 struct mdd_object *mdd_obj,
1046 const struct lu_fid *pfid,
1047 const struct lu_name *lname,
1048 struct thandle *handle)
1050 return mdd_links_rename(env, mdd_obj, pfid, lname,
1051 NULL, NULL, handle, NULL, 0, 0);
1054 /** Read the link EA into a temp buffer.
1055 * Uses the mdd_thread_info::mti_big_buf since it is generally large.
1056 * A pointer to the buffer is stored in \a ldata::ld_buf.
1058 * \retval 0 or error
1060 int mdd_links_read(const struct lu_env *env, struct mdd_object *mdd_obj,
1061 struct linkea_data *ldata)
1065 if (!mdd_object_exists(mdd_obj))
1068 /* First try a small buf */
1069 LASSERT(env != NULL);
1070 ldata->ld_buf = lu_buf_check_and_alloc(&mdd_env_info(env)->mti_link_buf,
1072 if (ldata->ld_buf->lb_buf == NULL)
1075 rc = mdo_xattr_get(env, mdd_obj, ldata->ld_buf, XATTR_NAME_LINK);
1076 if (rc == -ERANGE) {
1077 /* Buf was too small, figure out what we need. */
1078 lu_buf_free(ldata->ld_buf);
1079 rc = mdo_xattr_get(env, mdd_obj, ldata->ld_buf,
1083 ldata->ld_buf = lu_buf_check_and_alloc(ldata->ld_buf, rc);
1084 if (ldata->ld_buf->lb_buf == NULL)
1086 rc = mdo_xattr_get(env, mdd_obj, ldata->ld_buf,
1090 lu_buf_free(ldata->ld_buf);
1091 ldata->ld_buf = NULL;
1095 return linkea_init(ldata);
1098 /** Read the link EA into a temp buffer.
1099 * Uses the name_buf since it is generally large.
1100 * \retval IS_ERR err
1101 * \retval ptr to \a lu_buf (always \a mti_big_buf)
1103 struct lu_buf *mdd_links_get(const struct lu_env *env,
1104 struct mdd_object *mdd_obj)
1106 struct linkea_data ldata = { NULL };
1109 rc = mdd_links_read(env, mdd_obj, &ldata);
1110 return rc ? ERR_PTR(rc) : ldata.ld_buf;
1113 int mdd_links_write(const struct lu_env *env, struct mdd_object *mdd_obj,
1114 struct linkea_data *ldata, struct thandle *handle)
1116 const struct lu_buf *buf = mdd_buf_get_const(env, ldata->ld_buf->lb_buf,
1117 ldata->ld_leh->leh_len);
1120 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_NO_LINKEA))
1123 rc = mdo_xattr_set(env, mdd_obj, buf, XATTR_NAME_LINK, 0, handle);
1124 if (unlikely(rc == -ENOSPC) && S_ISREG(mdd_object_type(mdd_obj)) &&
1125 mdd_object_remote(mdd_obj) == 0) {
1126 struct lfsck_request *lr = &mdd_env_info(env)->mti_lr;
1127 struct thandle *sub_th;
1129 /* XXX: If the linkEA is overflow, then we need to notify the
1130 * namespace LFSCK to skip "nlink" attribute verification
1131 * on this object to avoid the "nlink" to be shrinked by
1132 * wrong. It may be not good an interaction with LFSCK
1133 * like this. We will consider to replace it with other
1134 * mechanism in future. LU-5802. */
1135 lfsck_pack_rfa(lr, mdo2fid(mdd_obj), LE_SKIP_NLINK,
1136 LFSCK_TYPE_NAMESPACE);
1138 sub_th = thandle_get_sub_by_dt(env, handle,
1139 mdo2mdd(&mdd_obj->mod_obj)->mdd_bottom);
1140 lfsck_in_notify(env, mdo2mdd(&mdd_obj->mod_obj)->mdd_bottom,
1147 int mdd_declare_links_add(const struct lu_env *env, struct mdd_object *mdd_obj,
1148 struct thandle *handle, struct linkea_data *ldata,
1149 enum mdd_links_add_overflow overflow)
1155 if (ldata != NULL && ldata->ld_leh != NULL) {
1156 ea_len = ldata->ld_leh->leh_len;
1157 linkea = ldata->ld_buf->lb_buf;
1159 ea_len = DEFAULT_LINKEA_SIZE;
1163 /* XXX: max size? */
1164 rc = mdo_declare_xattr_set(env, mdd_obj,
1165 mdd_buf_get_const(env, linkea, ea_len),
1166 XATTR_NAME_LINK, 0, handle);
1170 if (mdd_object_remote(mdd_obj) == 0 && overflow == MLAO_CHECK) {
1171 struct lfsck_request *lr = &mdd_env_info(env)->mti_lr;
1172 struct thandle *sub_th;
1174 /* XXX: If the linkEA is overflow, then we need to notify the
1175 * namespace LFSCK to skip "nlink" attribute verification
1176 * on this object to avoid the "nlink" to be shrinked by
1177 * wrong. It may be not good an interaction with LFSCK
1178 * like this. We will consider to replace it with other
1179 * mechanism in future. LU-5802. */
1180 lfsck_pack_rfa(lr, mdo2fid(mdd_obj), LE_SKIP_NLINK_DECLARE,
1181 LFSCK_TYPE_NAMESPACE);
1183 sub_th = thandle_get_sub_by_dt(env, handle,
1184 mdo2mdd(&mdd_obj->mod_obj)->mdd_bottom);
1185 rc = lfsck_in_notify(env,
1186 mdo2mdd(&mdd_obj->mod_obj)->mdd_bottom,
1193 static inline int mdd_declare_links_del(const struct lu_env *env,
1194 struct mdd_object *c,
1195 struct thandle *handle)
1199 /* For directory, the linkEA will be removed together
1200 * with the object. */
1201 if (!S_ISDIR(mdd_object_type(c)))
1202 rc = mdd_declare_links_add(env, c, handle, NULL, MLAO_IGNORE);
1207 static int mdd_declare_link(const struct lu_env *env,
1208 struct mdd_device *mdd,
1209 struct mdd_object *p,
1210 struct mdd_object *c,
1211 const struct lu_name *name,
1212 struct thandle *handle,
1214 struct linkea_data *data)
1218 rc = mdo_declare_index_insert(env, p, mdo2fid(c), mdd_object_type(c),
1219 name->ln_name, handle);
1223 rc = mdo_declare_ref_add(env, c, handle);
1227 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_MORE_NLINK)) {
1228 rc = mdo_declare_ref_add(env, c, handle);
1233 la->la_valid = LA_CTIME | LA_MTIME;
1234 rc = mdo_declare_attr_set(env, p, la, handle);
1238 la->la_valid = LA_CTIME;
1239 rc = mdo_declare_attr_set(env, c, la, handle);
1243 rc = mdd_declare_links_add(env, c, handle, data,
1244 S_ISREG(mdd_object_type(c)) ? MLAO_CHECK : MLAO_IGNORE);
1248 rc = mdd_declare_changelog_store(env, mdd, name, NULL, handle);
1253 static int mdd_link(const struct lu_env *env, struct md_object *tgt_obj,
1254 struct md_object *src_obj, const struct lu_name *lname,
1257 const char *name = lname->ln_name;
1258 struct lu_attr *la = &mdd_env_info(env)->mti_la_for_fix;
1259 struct mdd_object *mdd_tobj = md2mdd_obj(tgt_obj);
1260 struct mdd_object *mdd_sobj = md2mdd_obj(src_obj);
1261 struct lu_attr *cattr = MDD_ENV_VAR(env, cattr);
1262 struct lu_attr *tattr = MDD_ENV_VAR(env, tattr);
1263 struct mdd_device *mdd = mdo2mdd(src_obj);
1264 struct thandle *handle;
1265 struct linkea_data *ldata = &mdd_env_info(env)->mti_link_data;
1269 rc = mdd_la_get(env, mdd_sobj, cattr);
1273 rc = mdd_la_get(env, mdd_tobj, tattr);
1277 handle = mdd_trans_create(env, mdd);
1279 GOTO(out_pending, rc = PTR_ERR(handle));
1281 memset(ldata, 0, sizeof(*ldata));
1283 LASSERT(ma->ma_attr.la_valid & LA_CTIME);
1284 la->la_ctime = la->la_mtime = ma->ma_attr.la_ctime;
1286 rc = mdd_declare_link(env, mdd, mdd_tobj, mdd_sobj, lname, handle,
1291 rc = mdd_trans_start(env, mdd, handle);
1295 mdd_write_lock(env, mdd_sobj, MOR_TGT_CHILD);
1296 rc = mdd_link_sanity_check(env, mdd_tobj, tattr, lname, mdd_sobj,
1299 GOTO(out_unlock, rc);
1301 if (!OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LESS_NLINK)) {
1302 rc = mdo_ref_add(env, mdd_sobj, handle);
1304 GOTO(out_unlock, rc);
1307 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_MORE_NLINK)) {
1308 rc = mdo_ref_add(env, mdd_sobj, handle);
1310 GOTO(out_unlock, rc);
1313 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_DANGLING3)) {
1314 struct lu_fid tfid = *mdo2fid(mdd_sobj);
1317 rc = __mdd_index_insert_only(env, mdd_tobj, &tfid,
1318 mdd_object_type(mdd_sobj),
1321 rc = __mdd_index_insert_only(env, mdd_tobj, mdo2fid(mdd_sobj),
1322 mdd_object_type(mdd_sobj),
1327 mdo_ref_del(env, mdd_sobj, handle);
1328 GOTO(out_unlock, rc);
1331 la->la_valid = LA_CTIME | LA_MTIME;
1332 rc = mdd_update_time(env, mdd_tobj, tattr, la, handle);
1334 GOTO(out_unlock, rc);
1336 la->la_valid = LA_CTIME;
1337 rc = mdd_update_time(env, mdd_sobj, cattr, la, handle);
1339 rc = mdd_linkea_prepare(env, mdd_sobj, NULL, NULL,
1340 mdo2fid(mdd_tobj), lname, 0, 0,
1343 mdd_links_add(env, mdd_sobj, mdo2fid(mdd_tobj),
1344 lname, handle, ldata, 0);
1345 /* The failure of links_add should not cause the link
1346 * failure, reset rc here */
1351 mdd_write_unlock(env, mdd_sobj);
1353 rc = mdd_changelog_ns_store(env, mdd, CL_HARDLINK, 0, mdd_sobj,
1354 mdo2fid(mdd_tobj), NULL, NULL,
1355 lname, NULL, handle);
1357 mdd_trans_stop(env, mdd, rc, handle);
1359 if (ldata->ld_buf && ldata->ld_buf->lb_len > OBD_ALLOC_BIG)
1360 /* if we vmalloced a large buffer drop it */
1361 lu_buf_free(ldata->ld_buf);
1366 static int mdd_mark_dead_object(const struct lu_env *env,
1367 struct mdd_object *obj, struct thandle *handle,
1370 struct lu_attr *attr = MDD_ENV_VAR(env, la_for_start);
1374 obj->mod_flags |= DEAD_OBJ;
1376 if (!S_ISDIR(mdd_object_type(obj)))
1379 attr->la_valid = LA_FLAGS;
1380 attr->la_flags = LUSTRE_SLAVE_DEAD_FL;
1383 rc = mdo_declare_attr_set(env, obj, attr, handle);
1385 rc = mdo_attr_set(env, obj, attr, handle);
1390 static int mdd_declare_finish_unlink(const struct lu_env *env,
1391 struct mdd_object *obj,
1392 struct thandle *handle)
1396 rc = mdd_mark_dead_object(env, obj, handle, true);
1400 rc = orph_declare_index_insert(env, obj, mdd_object_type(obj), handle);
1404 rc = mdo_declare_destroy(env, obj, handle);
1408 return mdd_declare_links_del(env, obj, handle);
1411 /* caller should take a lock before calling */
1412 int mdd_finish_unlink(const struct lu_env *env,
1413 struct mdd_object *obj, struct md_attr *ma,
1414 const struct mdd_object *pobj,
1415 const struct lu_name *lname,
1419 int is_dir = S_ISDIR(ma->ma_attr.la_mode);
1422 LASSERT(mdd_write_locked(env, obj) != 0);
1424 if (ma->ma_attr.la_nlink == 0 || is_dir) {
1425 rc = mdd_mark_dead_object(env, obj, th, false);
1429 /* add new orphan and the object
1430 * will be deleted during mdd_close() */
1431 if (obj->mod_count) {
1432 rc = __mdd_orphan_add(env, obj, th);
1434 CDEBUG(D_HA, "Object "DFID" is inserted into "
1435 "orphan list, open count = %d\n",
1436 PFID(mdd_object_fid(obj)),
1439 CERROR("Object "DFID" fail to be an orphan, "
1440 "open count = %d, maybe cause failed "
1442 PFID(mdd_object_fid(obj)),
1445 rc = mdo_destroy(env, obj, th);
1447 } else if (!is_dir) {
1448 /* old files may not have link ea; ignore errors */
1449 mdd_links_del(env, obj, mdo2fid(pobj), lname, th);
1457 * has mdd_write_lock on cobj already, but not on pobj yet
1459 int mdd_unlink_sanity_check(const struct lu_env *env, struct mdd_object *pobj,
1460 const struct lu_attr *pattr,
1461 struct mdd_object *cobj,
1462 const struct lu_attr *cattr)
1467 rc = mdd_may_delete(env, pobj, pattr, cobj, cattr, NULL, 1, 1);
1472 static int mdd_declare_unlink(const struct lu_env *env, struct mdd_device *mdd,
1473 struct mdd_object *p, struct mdd_object *c,
1474 const struct lu_name *name, struct md_attr *ma,
1475 struct thandle *handle, int no_name, int is_dir)
1477 struct lu_attr *la = &mdd_env_info(env)->mti_la_for_fix;
1480 if (!OBD_FAIL_CHECK(OBD_FAIL_LFSCK_DANGLING2)) {
1481 if (likely(no_name == 0)) {
1482 rc = mdo_declare_index_delete(env, p, name->ln_name,
1489 rc = mdo_declare_ref_del(env, p, handle);
1495 LASSERT(ma->ma_attr.la_valid & LA_CTIME);
1496 la->la_ctime = la->la_mtime = ma->ma_attr.la_ctime;
1497 la->la_valid = LA_CTIME | LA_MTIME;
1498 rc = mdo_declare_attr_set(env, p, la, handle);
1503 rc = mdo_declare_ref_del(env, c, handle);
1507 rc = mdo_declare_ref_del(env, c, handle);
1511 la->la_valid = LA_CTIME;
1512 rc = mdo_declare_attr_set(env, c, la, handle);
1516 rc = mdd_declare_finish_unlink(env, c, handle);
1520 /* FIXME: need changelog for remove entry */
1521 rc = mdd_declare_changelog_store(env, mdd, name, NULL, handle);
1528 * test if a file has an HSM archive
1529 * if HSM attributes are not found in ma update them from
1532 static bool mdd_hsm_archive_exists(const struct lu_env *env,
1533 struct mdd_object *obj,
1538 if (!(ma->ma_valid & MA_HSM)) {
1539 /* no HSM MD provided, read xattr */
1540 struct lu_buf *hsm_buf;
1541 const size_t buflen = sizeof(struct hsm_attrs);
1544 hsm_buf = mdd_buf_get(env, NULL, 0);
1545 lu_buf_alloc(hsm_buf, buflen);
1546 rc = mdo_xattr_get(env, obj, hsm_buf, XATTR_NAME_HSM);
1547 rc = lustre_buf2hsm(hsm_buf->lb_buf, rc, &ma->ma_hsm);
1548 lu_buf_free(hsm_buf);
1552 ma->ma_valid = MA_HSM;
1554 if (ma->ma_hsm.mh_flags & HS_EXISTS)
1560 * Delete name entry and the object.
1561 * Note: no_name == 1 means it only destory the object, i.e. name_entry
1562 * does not exist for this object, and it could only happen during resending
1563 * of remote unlink. see the comments in mdt_reint_unlink. Unfortunately, lname
1564 * is also needed in this case(needed by changelog), so we have to add another
1565 * parameter(no_name)here. XXX: this is only needed in DNE phase I, on Phase II,
1566 * the ENOENT failure should be able to be fixed by redo mechanism.
1568 static int mdd_unlink(const struct lu_env *env, struct md_object *pobj,
1569 struct md_object *cobj, const struct lu_name *lname,
1570 struct md_attr *ma, int no_name)
1572 const char *name = lname->ln_name;
1573 struct lu_attr *pattr = MDD_ENV_VAR(env, pattr);
1574 struct lu_attr *cattr = MDD_ENV_VAR(env, cattr);
1575 struct lu_attr *la = &mdd_env_info(env)->mti_la_for_fix;
1576 struct mdd_object *mdd_pobj = md2mdd_obj(pobj);
1577 struct mdd_object *mdd_cobj = NULL;
1578 struct mdd_device *mdd = mdo2mdd(pobj);
1579 struct thandle *handle;
1583 /* cobj == NULL means only delete name entry */
1584 if (likely(cobj != NULL)) {
1585 mdd_cobj = md2mdd_obj(cobj);
1586 if (mdd_object_exists(mdd_cobj) == 0)
1590 rc = mdd_la_get(env, mdd_pobj, pattr);
1594 if (likely(mdd_cobj != NULL)) {
1596 rc = mdd_la_get(env, mdd_cobj, cattr);
1600 is_dir = S_ISDIR(cattr->la_mode);
1603 rc = mdd_unlink_sanity_check(env, mdd_pobj, pattr, mdd_cobj, cattr);
1607 handle = mdd_trans_create(env, mdd);
1609 RETURN(PTR_ERR(handle));
1611 rc = mdd_declare_unlink(env, mdd, mdd_pobj, mdd_cobj,
1612 lname, ma, handle, no_name, is_dir);
1616 rc = mdd_trans_start(env, mdd, handle);
1620 if (likely(mdd_cobj != NULL))
1621 mdd_write_lock(env, mdd_cobj, MOR_TGT_CHILD);
1623 if (likely(no_name == 0) && !OBD_FAIL_CHECK(OBD_FAIL_LFSCK_DANGLING2)) {
1624 rc = __mdd_index_delete(env, mdd_pobj, name, is_dir, handle);
1629 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_MUL_REF) ||
1630 OBD_FAIL_CHECK(OBD_FAIL_LFSCK_NO_NAMEENTRY))
1631 GOTO(cleanup, rc = 0);
1633 if (likely(mdd_cobj != NULL)) {
1634 rc = mdo_ref_del(env, mdd_cobj, handle);
1636 __mdd_index_insert_only(env, mdd_pobj,
1638 mdd_object_type(mdd_cobj),
1645 mdo_ref_del(env, mdd_cobj, handle);
1647 /* fetch updated nlink */
1648 rc = mdd_la_get(env, mdd_cobj, cattr);
1653 LASSERT(ma->ma_attr.la_valid & LA_CTIME);
1654 la->la_ctime = la->la_mtime = ma->ma_attr.la_ctime;
1656 la->la_valid = LA_CTIME | LA_MTIME;
1657 rc = mdd_update_time(env, mdd_pobj, pattr, la, handle);
1661 /* Enough for only unlink the entry */
1662 if (unlikely(mdd_cobj == NULL))
1665 if (cattr->la_nlink > 0 || mdd_cobj->mod_count > 0) {
1666 /* update ctime of an unlinked file only if it is still
1667 * opened or a link still exists */
1668 la->la_valid = LA_CTIME;
1669 rc = mdd_update_time(env, mdd_cobj, cattr, la, handle);
1674 /* XXX: this transfer to ma will be removed with LOD/OSP */
1675 ma->ma_attr = *cattr;
1676 ma->ma_valid |= MA_INODE;
1677 rc = mdd_finish_unlink(env, mdd_cobj, ma, mdd_pobj, lname, handle);
1679 /* fetch updated nlink */
1681 rc = mdd_la_get(env, mdd_cobj, cattr);
1683 /* if object is removed then we can't get its attrs, use last get */
1684 if (cattr->la_nlink == 0) {
1685 ma->ma_attr = *cattr;
1686 ma->ma_valid |= MA_INODE;
1690 if (likely(mdd_cobj != NULL))
1691 mdd_write_unlock(env, mdd_cobj);
1696 if (cattr->la_nlink == 0) {
1697 cl_flags |= CLF_UNLINK_LAST;
1698 /* search for an existing archive */
1699 if (mdd_hsm_archive_exists(env, mdd_cobj, ma))
1700 cl_flags |= CLF_UNLINK_HSM_EXISTS;
1703 rc = mdd_changelog_ns_store(env, mdd,
1704 is_dir ? CL_RMDIR : CL_UNLINK, cl_flags,
1705 mdd_cobj, mdo2fid(mdd_pobj), NULL, NULL, lname, NULL,
1710 mdd_trans_stop(env, mdd, rc, handle);
1716 * The permission has been checked when obj created, no need check again.
1718 static int mdd_cd_sanity_check(const struct lu_env *env,
1719 struct mdd_object *obj)
1724 if (!obj || mdd_is_dead_obj(obj))
1730 static int mdd_create_data(const struct lu_env *env, struct md_object *pobj,
1731 struct md_object *cobj, const struct md_op_spec *spec,
1734 struct mdd_device *mdd = mdo2mdd(cobj);
1735 struct mdd_object *mdd_pobj = md2mdd_obj(pobj);
1736 struct mdd_object *son = md2mdd_obj(cobj);
1737 struct thandle *handle;
1738 const struct lu_buf *buf;
1739 struct lu_attr *attr = MDD_ENV_VAR(env, cattr);
1740 struct dt_allocation_hint *hint = &mdd_env_info(env)->mti_hint;
1744 rc = mdd_cd_sanity_check(env, son);
1748 if (!md_should_create(spec->sp_cr_flags))
1752 * there are following use cases for this function:
1753 * 1) late striping - file was created with MDS_OPEN_DELAY_CREATE
1754 * striping can be specified or not
1757 rc = mdd_la_get(env, son, attr);
1761 /* calling ->ah_make_hint() is used to transfer information from parent */
1762 mdd_object_make_hint(env, mdd_pobj, son, attr, spec, hint);
1764 handle = mdd_trans_create(env, mdd);
1766 GOTO(out_free, rc = PTR_ERR(handle));
1769 * XXX: Setting the lov ea is not locked but setting the attr is locked?
1770 * Should this be fixed?
1772 CDEBUG(D_OTHER, "ea %p/%u, cr_flags "LPO64", no_create %u\n",
1773 spec->u.sp_ea.eadata, spec->u.sp_ea.eadatalen,
1774 spec->sp_cr_flags, spec->no_create);
1776 if (spec->no_create || (spec->sp_cr_flags & MDS_OPEN_HAS_EA)) {
1777 buf = mdd_buf_get_const(env, spec->u.sp_ea.eadata,
1778 spec->u.sp_ea.eadatalen);
1783 rc = dt_declare_xattr_set(env, mdd_object_child(son), buf,
1784 XATTR_NAME_LOV, 0, handle);
1788 rc = mdd_declare_changelog_store(env, mdd, NULL, NULL, handle);
1792 rc = mdd_trans_start(env, mdd, handle);
1796 rc = dt_xattr_set(env, mdd_object_child(son), buf, XATTR_NAME_LOV,
1802 rc = mdd_changelog_data_store(env, mdd, CL_LAYOUT, 0, son, handle);
1805 mdd_trans_stop(env, mdd, rc, handle);
1810 static int mdd_declare_object_initialize(const struct lu_env *env,
1811 struct mdd_object *parent,
1812 struct mdd_object *child,
1813 struct lu_attr *attr,
1814 struct thandle *handle)
1820 * inode mode has been set in creation time, and it's based on umask,
1821 * la_mode and acl, don't set here again! (which will go wrong
1822 * because below function doesn't consider umask).
1823 * I'd suggest set all object attributes in creation time, see above.
1825 LASSERT(attr->la_valid & (LA_MODE | LA_TYPE));
1826 attr->la_valid &= ~(LA_MODE | LA_TYPE);
1827 rc = mdo_declare_attr_set(env, child, attr, handle);
1828 attr->la_valid |= LA_MODE | LA_TYPE;
1829 if (rc != 0 || !S_ISDIR(attr->la_mode))
1832 rc = mdo_declare_index_insert(env, child, mdo2fid(child), S_IFDIR,
1837 rc = mdo_declare_ref_add(env, child, handle);
1841 rc = mdo_declare_index_insert(env, child, mdo2fid(parent), S_IFDIR,
1847 static int mdd_object_initialize(const struct lu_env *env,
1848 const struct lu_fid *pfid,
1849 struct mdd_object *child,
1850 struct lu_attr *attr, struct thandle *handle,
1851 const struct md_op_spec *spec)
1856 if (S_ISDIR(attr->la_mode)) {
1857 /* Add "." and ".." for newly created dir */
1858 mdo_ref_add(env, child, handle);
1859 rc = __mdd_index_insert_only(env, child, mdo2fid(child),
1860 S_IFDIR, dot, handle);
1862 rc = __mdd_index_insert_only(env, child, pfid, S_IFDIR,
1865 mdo_ref_del(env, child, handle);
1872 * This function checks whether it can create a file/dir under the
1873 * directory(@pobj). The directory(@pobj) is not being locked by
1876 * \param[in] env execution environment
1877 * \param[in] pobj the directory to create files
1878 * \param[in] pattr the attributes of the directory
1879 * \param[in] lname the name of the created file/dir
1880 * \param[in] cattr the attributes of the file/dir
1881 * \param[in] spec create specification
1883 * \retval = 0 it is allowed to create file/dir under
1885 * \retval negative error not allowed to create file/dir
1886 * under the directory
1888 static int mdd_create_sanity_check(const struct lu_env *env,
1889 struct md_object *pobj,
1890 const struct lu_attr *pattr,
1891 const struct lu_name *lname,
1892 struct lu_attr *cattr,
1893 struct md_op_spec *spec)
1895 struct mdd_thread_info *info = mdd_env_info(env);
1896 struct lu_fid *fid = &info->mti_fid;
1897 struct mdd_object *obj = md2mdd_obj(pobj);
1898 struct mdd_device *m = mdo2mdd(pobj);
1899 bool check_perm = true;
1904 if (mdd_is_dead_obj(obj))
1908 * In some cases this lookup is not needed - we know before if name
1909 * exists or not because MDT performs lookup for it.
1910 * name length check is done in lookup.
1912 if (spec->sp_cr_lookup) {
1914 * Check if the name already exist, though it will be checked in
1915 * _index_insert also, for avoiding rolling back if exists
1918 rc = __mdd_lookup(env, pobj, pattr, lname, fid,
1919 MAY_WRITE | MAY_EXEC);
1921 RETURN(rc ? : -EEXIST);
1923 /* Permission is already being checked in mdd_lookup */
1927 rc = mdd_may_create(env, obj, pattr, NULL, check_perm);
1932 if (pattr->la_mode & S_ISGID) {
1933 cattr->la_gid = pattr->la_gid;
1934 if (S_ISDIR(cattr->la_mode)) {
1935 cattr->la_mode |= S_ISGID;
1936 cattr->la_valid |= LA_MODE;
1940 rc = mdd_name_check(m, lname);
1944 switch (cattr->la_mode & S_IFMT) {
1946 unsigned int symlen = strlen(spec->u.sp_symname) + 1;
1948 if (symlen > (1 << m->mdd_dt_conf.ddp_block_shift))
1949 RETURN(-ENAMETOOLONG);
1968 static int mdd_declare_object_create(const struct lu_env *env,
1969 struct mdd_device *mdd,
1970 struct mdd_object *p, struct mdd_object *c,
1971 struct lu_attr *attr,
1972 struct thandle *handle,
1973 const struct md_op_spec *spec,
1974 struct lu_buf *def_acl_buf,
1975 struct lu_buf *acl_buf,
1976 struct dt_allocation_hint *hint)
1980 rc = mdd_declare_object_create_internal(env, p, c, attr, handle, spec,
1985 #ifdef CONFIG_FS_POSIX_ACL
1986 if (def_acl_buf->lb_len > 0 && S_ISDIR(attr->la_mode)) {
1987 /* if dir, then can inherit default ACl */
1988 rc = mdo_declare_xattr_set(env, c, def_acl_buf,
1989 XATTR_NAME_ACL_DEFAULT,
1995 if (acl_buf->lb_len > 0) {
1996 rc = mdo_declare_attr_set(env, c, attr, handle);
2000 rc = mdo_declare_xattr_set(env, c, acl_buf,
2001 XATTR_NAME_ACL_ACCESS, 0, handle);
2006 rc = mdd_declare_object_initialize(env, p, c, attr, handle);
2010 /* replay case, create LOV EA from client data */
2011 if (spec->no_create ||
2012 (spec->sp_cr_flags & MDS_OPEN_HAS_EA && S_ISREG(attr->la_mode))) {
2013 const struct lu_buf *buf;
2015 buf = mdd_buf_get_const(env, spec->u.sp_ea.eadata,
2016 spec->u.sp_ea.eadatalen);
2017 rc = mdo_declare_xattr_set(env, c, buf, XATTR_NAME_LOV, 0,
2023 if (S_ISLNK(attr->la_mode)) {
2024 const char *target_name = spec->u.sp_symname;
2025 int sym_len = strlen(target_name);
2026 const struct lu_buf *buf;
2028 buf = mdd_buf_get_const(env, target_name, sym_len);
2029 rc = dt_declare_record_write(env, mdd_object_child(c),
2038 static int mdd_declare_create(const struct lu_env *env, struct mdd_device *mdd,
2039 struct mdd_object *p, struct mdd_object *c,
2040 const struct lu_name *name,
2041 struct lu_attr *attr,
2042 struct thandle *handle,
2043 const struct md_op_spec *spec,
2044 struct linkea_data *ldata,
2045 struct lu_buf *def_acl_buf,
2046 struct lu_buf *acl_buf,
2047 struct dt_allocation_hint *hint)
2051 rc = mdd_declare_object_create(env, mdd, p, c, attr, handle, spec,
2052 def_acl_buf, acl_buf, hint);
2056 if (S_ISDIR(attr->la_mode)) {
2057 rc = mdo_declare_ref_add(env, p, handle);
2062 if (unlikely(spec->sp_cr_flags & MDS_OPEN_VOLATILE)) {
2063 rc = orph_declare_index_insert(env, c, attr->la_mode, handle);
2067 struct lu_attr *la = &mdd_env_info(env)->mti_la_for_fix;
2069 rc = mdo_declare_index_insert(env, p, mdo2fid(c), attr->la_mode,
2070 name->ln_name, handle);
2074 rc = mdd_declare_links_add(env, c, handle, ldata, MLAO_IGNORE);
2079 la->la_valid = LA_CTIME | LA_MTIME;
2080 rc = mdo_declare_attr_set(env, p, la, handle);
2084 rc = mdd_declare_changelog_store(env, mdd, name, NULL, handle);
2092 static int mdd_acl_init(const struct lu_env *env, struct mdd_object *pobj,
2093 struct lu_attr *la, struct lu_buf *def_acl_buf,
2094 struct lu_buf *acl_buf)
2099 if (S_ISLNK(la->la_mode)) {
2100 acl_buf->lb_len = 0;
2101 def_acl_buf->lb_len = 0;
2105 mdd_read_lock(env, pobj, MOR_TGT_PARENT);
2106 rc = mdo_xattr_get(env, pobj, def_acl_buf,
2107 XATTR_NAME_ACL_DEFAULT);
2108 mdd_read_unlock(env, pobj);
2110 /* If there are default ACL, fix mode/ACL by default ACL */
2111 def_acl_buf->lb_len = rc;
2112 LASSERT(def_acl_buf->lb_len <= acl_buf->lb_len);
2113 memcpy(acl_buf->lb_buf, def_acl_buf->lb_buf, rc);
2114 acl_buf->lb_len = rc;
2115 rc = __mdd_fix_mode_acl(env, acl_buf, &la->la_mode);
2118 } else if (rc == -ENODATA || rc == -EOPNOTSUPP) {
2119 /* If there are no default ACL, fix mode by mask */
2120 struct lu_ucred *uc = lu_ucred(env);
2122 /* The create triggered by MDT internal events, such as
2123 * LFSCK reset, will not contain valid "uc". */
2124 if (unlikely(uc != NULL))
2125 la->la_mode &= ~uc->uc_umask;
2127 acl_buf->lb_len = 0;
2128 def_acl_buf->lb_len = 0;
2135 * Create a metadata object and initialize it, set acl, xattr.
2137 static int mdd_object_create(const struct lu_env *env, struct mdd_object *pobj,
2138 struct mdd_object *son, struct lu_attr *attr,
2139 struct md_op_spec *spec, struct lu_buf *acl_buf,
2140 struct lu_buf *def_acl_buf,
2141 struct dt_allocation_hint *hint,
2142 struct thandle *handle)
2146 mdd_write_lock(env, son, MOR_TGT_CHILD);
2147 rc = mdd_object_create_internal(env, NULL, son, attr, handle, spec,
2152 /* Note: In DNE phase I, for striped dir, though sub-stripes will be
2153 * created in declare phase, they also needs to be added to master
2154 * object as sub-directory entry. So it has to initialize the master
2155 * object, then set dir striped EA.(in mdo_xattr_set) */
2156 rc = mdd_object_initialize(env, mdo2fid(pobj), son, attr, handle,
2159 GOTO(err_destroy, rc);
2162 * in case of replay we just set LOVEA provided by the client
2163 * XXX: I think it would be interesting to try "old" way where
2164 * MDT calls this xattr_set(LOV) in a different transaction.
2165 * probably this way we code can be made better.
2168 /* During creation, there are only a few cases we need do xattr_set to
2170 * 1. regular file: see comments above.
2171 * 2. dir: inherit default striping or pool settings from parent.
2172 * 3. create striped directory with provided stripeEA.
2173 * 4. create striped directory because inherit default layout from the
2176 if (spec->no_create ||
2177 (S_ISREG(attr->la_mode) && spec->sp_cr_flags & MDS_OPEN_HAS_EA) ||
2178 S_ISDIR(attr->la_mode)) {
2179 const struct lu_buf *buf;
2181 buf = mdd_buf_get_const(env, spec->u.sp_ea.eadata,
2182 spec->u.sp_ea.eadatalen);
2183 rc = mdo_xattr_set(env, son, buf,
2184 S_ISDIR(attr->la_mode) ? XATTR_NAME_LMV :
2188 GOTO(err_destroy, rc);
2191 #ifdef CONFIG_FS_POSIX_ACL
2192 if (def_acl_buf != NULL && def_acl_buf->lb_len > 0 &&
2193 S_ISDIR(attr->la_mode)) {
2194 /* set default acl */
2195 rc = mdo_xattr_set(env, son, def_acl_buf,
2196 XATTR_NAME_ACL_DEFAULT, 0,
2199 GOTO(err_destroy, rc);
2201 /* set its own acl */
2202 if (acl_buf != NULL && acl_buf->lb_len > 0) {
2203 rc = mdo_xattr_set(env, son, acl_buf,
2204 XATTR_NAME_ACL_ACCESS,
2207 GOTO(err_destroy, rc);
2211 if (S_ISLNK(attr->la_mode)) {
2212 struct lu_ucred *uc = lu_ucred_assert(env);
2213 struct dt_object *dt = mdd_object_child(son);
2214 const char *target_name = spec->u.sp_symname;
2215 int sym_len = strlen(target_name);
2216 const struct lu_buf *buf;
2219 buf = mdd_buf_get_const(env, target_name, sym_len);
2220 rc = dt->do_body_ops->dbo_write(env, dt, buf, &pos, handle,
2222 CFS_CAP_SYS_RESOURCE_MASK);
2227 GOTO(err_initlized, rc = -EFAULT);
2231 if (unlikely(rc != 0)) {
2233 if (S_ISDIR(attr->la_mode)) {
2234 /* Drop the reference, no need to delete "."/"..",
2235 * because the object to be destroied directly. */
2236 rc2 = mdo_ref_del(env, son, handle);
2240 rc2 = mdo_ref_del(env, son, handle);
2244 mdo_destroy(env, son, handle);
2247 mdd_write_unlock(env, son);
2252 * Create object and insert it into namespace.
2254 static int mdd_create(const struct lu_env *env, struct md_object *pobj,
2255 const struct lu_name *lname, struct md_object *child,
2256 struct md_op_spec *spec, struct md_attr* ma)
2258 struct mdd_thread_info *info = mdd_env_info(env);
2259 struct lu_attr *la = &info->mti_la_for_fix;
2260 struct mdd_object *mdd_pobj = md2mdd_obj(pobj);
2261 struct mdd_object *son = md2mdd_obj(child);
2262 struct mdd_device *mdd = mdo2mdd(pobj);
2263 struct lu_attr *attr = &ma->ma_attr;
2264 struct thandle *handle;
2265 struct lu_attr *pattr = &info->mti_pattr;
2266 struct lu_buf acl_buf;
2267 struct lu_buf def_acl_buf;
2268 struct linkea_data *ldata = &info->mti_link_data;
2269 const char *name = lname->ln_name;
2270 struct dt_allocation_hint *hint = &mdd_env_info(env)->mti_hint;
2276 * Two operations have to be performed:
2278 * - an allocation of a new object (->do_create()), and
2280 * - an insertion into a parent index (->dio_insert()).
2282 * Due to locking, operation order is not important, when both are
2283 * successful, *but* error handling cases are quite different:
2285 * - if insertion is done first, and following object creation fails,
2286 * insertion has to be rolled back, but this operation might fail
2287 * also leaving us with dangling index entry.
2289 * - if creation is done first, is has to be undone if insertion
2290 * fails, leaving us with leaked space, which is neither good, nor
2293 * It seems that creation-first is simplest solution, but it is
2294 * sub-optimal in the frequent
2299 * case, because second mkdir is bound to create object, only to
2300 * destroy it immediately.
2302 * To avoid this follow local file systems that do double lookup:
2304 * 0. lookup -> -EEXIST (mdd_create_sanity_check())
2306 * 1. create (mdd_object_create_internal())
2308 * 2. insert (__mdd_index_insert(), lookup again)
2311 rc = mdd_la_get(env, mdd_pobj, pattr);
2315 /* Sanity checks before big job. */
2316 rc = mdd_create_sanity_check(env, pobj, pattr, lname, attr, spec);
2320 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_DQACQ_NET))
2321 GOTO(out_free, rc = -EINPROGRESS);
2323 handle = mdd_trans_create(env, mdd);
2325 GOTO(out_free, rc = PTR_ERR(handle));
2327 acl_buf.lb_buf = info->mti_xattr_buf;
2328 acl_buf.lb_len = sizeof(info->mti_xattr_buf);
2329 def_acl_buf.lb_buf = info->mti_key;
2330 def_acl_buf.lb_len = sizeof(info->mti_key);
2331 rc = mdd_acl_init(env, mdd_pobj, attr, &def_acl_buf, &acl_buf);
2335 mdd_object_make_hint(env, mdd_pobj, son, attr, spec, hint);
2337 memset(ldata, 0, sizeof(*ldata));
2338 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_PARENT)) {
2339 struct lu_fid tfid = *mdd_object_fid(mdd_pobj);
2342 rc = mdd_linkea_prepare(env, son, NULL, NULL,
2343 &tfid, lname, 1, 0, ldata);
2345 rc = mdd_linkea_prepare(env, son, NULL, NULL,
2346 mdd_object_fid(mdd_pobj),
2347 lname, 1, 0, ldata);
2350 rc = mdd_declare_create(env, mdd, mdd_pobj, son, lname, attr,
2351 handle, spec, ldata, &def_acl_buf, &acl_buf,
2356 rc = mdd_trans_start(env, mdd, handle);
2360 rc = mdd_object_create(env, mdd_pobj, son, attr, spec, &acl_buf,
2361 &def_acl_buf, hint, handle);
2365 if (unlikely(spec->sp_cr_flags & MDS_OPEN_VOLATILE)) {
2366 mdd_write_lock(env, son, MOR_TGT_CHILD);
2367 rc = __mdd_orphan_add(env, son, handle);
2368 GOTO(out_volatile, rc);
2370 rc = __mdd_index_insert(env, mdd_pobj, mdo2fid(son),
2371 attr->la_mode, name, handle);
2373 GOTO(err_created, rc);
2375 mdd_links_add(env, son, mdo2fid(mdd_pobj), lname, handle,
2378 /* update parent directory mtime/ctime */
2380 la->la_valid = LA_CTIME | LA_MTIME;
2381 rc = mdd_update_time(env, mdd_pobj, pattr, la, handle);
2383 GOTO(err_insert, rc);
2391 if (spec->sp_cr_flags & MDS_OPEN_VOLATILE)
2392 rc2 = __mdd_orphan_del(env, son, handle);
2394 rc2 = __mdd_index_delete(env, mdd_pobj, name,
2395 S_ISDIR(attr->la_mode),
2401 mdd_write_lock(env, son, MOR_TGT_CHILD);
2402 if (S_ISDIR(attr->la_mode)) {
2403 /* Drop the reference, no need to delete "."/"..",
2404 * because the object is to be destroyed directly. */
2405 rc2 = mdo_ref_del(env, son, handle);
2407 mdd_write_unlock(env, son);
2412 /* For volatile files drop one link immediately, since there is
2413 * no filename in the namespace, and save any error returned. */
2414 rc2 = mdo_ref_del(env, son, handle);
2416 mdd_write_unlock(env, son);
2417 if (unlikely(rc == 0))
2422 /* Don't destroy the volatile object on success */
2423 if (likely(rc != 0))
2424 mdo_destroy(env, son, handle);
2425 mdd_write_unlock(env, son);
2428 if (rc == 0 && fid_is_namespace_visible(mdo2fid(son)) &&
2429 likely((spec->sp_cr_flags & MDS_OPEN_VOLATILE) == 0))
2430 rc = mdd_changelog_ns_store(env, mdd,
2431 S_ISDIR(attr->la_mode) ? CL_MKDIR :
2432 S_ISREG(attr->la_mode) ? CL_CREATE :
2433 S_ISLNK(attr->la_mode) ? CL_SOFTLINK : CL_MKNOD,
2434 0, son, mdo2fid(mdd_pobj), NULL, NULL, lname,
2437 rc2 = mdd_trans_stop(env, mdd, rc, handle);
2441 if (ldata->ld_buf && ldata->ld_buf->lb_len > OBD_ALLOC_BIG)
2442 /* if we vmalloced a large buffer drop it */
2443 lu_buf_free(ldata->ld_buf);
2445 /* The child object shouldn't be cached anymore */
2447 set_bit(LU_OBJECT_HEARD_BANSHEE,
2448 &child->mo_lu.lo_header->loh_flags);
2453 * Get locks on parents in proper order
2454 * RETURN: < 0 - error, rename_order if successful
2462 static int mdd_rename_order(const struct lu_env *env,
2463 struct mdd_device *mdd,
2464 struct mdd_object *src_pobj,
2465 const struct lu_attr *pattr,
2466 struct mdd_object *tgt_pobj)
2468 /* order of locking, 1 - tgt-src, 0 - src-tgt*/
2472 if (src_pobj == tgt_pobj)
2473 RETURN(MDD_RN_SAME);
2475 /* compared the parent child relationship of src_p&tgt_p */
2476 if (lu_fid_eq(&mdd->mdd_root_fid, mdo2fid(src_pobj))){
2478 } else if (lu_fid_eq(&mdd->mdd_root_fid, mdo2fid(tgt_pobj))) {
2481 rc = mdd_is_parent(env, mdd, src_pobj, pattr, mdo2fid(tgt_pobj),
2495 /* has not mdd_write{read}_lock on any obj yet. */
2496 static int mdd_rename_sanity_check(const struct lu_env *env,
2497 struct mdd_object *src_pobj,
2498 const struct lu_attr *pattr,
2499 struct mdd_object *tgt_pobj,
2500 const struct lu_attr *tpattr,
2501 struct mdd_object *sobj,
2502 const struct lu_attr *cattr,
2503 struct mdd_object *tobj,
2504 const struct lu_attr *tattr)
2509 /* XXX: when get here, sobj must NOT be NULL,
2510 * the other case has been processed in cld_rename
2511 * before mdd_rename and enable MDS_PERM_BYPASS. */
2514 rc = mdd_may_delete(env, src_pobj, pattr, sobj, cattr, NULL, 1, 0);
2518 /* XXX: when get here, "tobj == NULL" means tobj must
2519 * NOT exist (neither on remote MDS, such case has been
2520 * processed in cld_rename before mdd_rename and enable
2522 * So check may_create, but not check may_unlink. */
2524 rc = mdd_may_create(env, tgt_pobj, tpattr, NULL,
2525 (src_pobj != tgt_pobj));
2527 rc = mdd_may_delete(env, tgt_pobj, tpattr, tobj, tattr, cattr,
2528 (src_pobj != tgt_pobj), 1);
2530 if (!rc && !tobj && (src_pobj != tgt_pobj) && S_ISDIR(cattr->la_mode))
2531 rc = __mdd_may_link(env, tgt_pobj, tpattr);
2536 static int mdd_declare_rename(const struct lu_env *env,
2537 struct mdd_device *mdd,
2538 struct mdd_object *mdd_spobj,
2539 struct mdd_object *mdd_tpobj,
2540 struct mdd_object *mdd_sobj,
2541 struct mdd_object *mdd_tobj,
2542 const struct lu_name *tname,
2543 const struct lu_name *sname,
2545 struct linkea_data *ldata,
2546 struct thandle *handle)
2548 struct lu_attr *la = &mdd_env_info(env)->mti_la_for_fix;
2551 LASSERT(ma->ma_attr.la_valid & LA_CTIME);
2552 la->la_ctime = la->la_mtime = ma->ma_attr.la_ctime;
2558 /* name from source dir */
2559 rc = mdo_declare_index_delete(env, mdd_spobj, sname->ln_name, handle);
2563 /* .. from source child */
2564 if (S_ISDIR(mdd_object_type(mdd_sobj))) {
2565 /* source child can be directory,
2566 * counted by source dir's nlink */
2567 rc = mdo_declare_ref_del(env, mdd_spobj, handle);
2570 if (mdd_spobj != mdd_tpobj) {
2571 rc = mdo_declare_index_delete(env, mdd_sobj, dotdot,
2576 rc = mdo_declare_index_insert(env, mdd_sobj,
2578 S_IFDIR, dotdot, handle);
2583 /* new target child can be directory,
2584 * counted by target dir's nlink */
2585 rc = mdo_declare_ref_add(env, mdd_tpobj, handle);
2590 la->la_valid = LA_CTIME | LA_MTIME;
2591 rc = mdo_declare_attr_set(env, mdd_spobj, la, handle);
2595 rc = mdo_declare_attr_set(env, mdd_tpobj, la, handle);
2599 la->la_valid = LA_CTIME;
2600 rc = mdo_declare_attr_set(env, mdd_sobj, la, handle);
2604 rc = mdd_declare_links_add(env, mdd_sobj, handle, ldata,
2605 S_ISREG(mdd_object_type(mdd_sobj)) ? MLAO_CHECK : MLAO_IGNORE);
2610 rc = mdo_declare_index_insert(env, mdd_tpobj, mdo2fid(mdd_sobj),
2611 mdd_object_type(mdd_sobj),
2612 tname->ln_name, handle);
2616 /* name from target dir (old name), we declare it unconditionally
2617 * as mdd_rename() calls delete unconditionally as well. so just
2618 * to balance declarations vs calls to change ... */
2619 rc = mdo_declare_index_delete(env, mdd_tpobj, tname->ln_name, handle);
2623 if (mdd_tobj && mdd_object_exists(mdd_tobj)) {
2624 /* delete target child in target parent directory */
2625 rc = mdo_declare_ref_del(env, mdd_tobj, handle);
2629 if (S_ISDIR(mdd_object_type(mdd_tobj))) {
2630 /* target child can be directory,
2631 * delete "." reference in target child directory */
2632 rc = mdo_declare_ref_del(env, mdd_tobj, handle);
2636 /* delete ".." reference in target parent directory */
2637 rc = mdo_declare_ref_del(env, mdd_tpobj, handle);
2642 la->la_valid = LA_CTIME;
2643 rc = mdo_declare_attr_set(env, mdd_tobj, la, handle);
2647 rc = mdd_declare_finish_unlink(env, mdd_tobj, handle);
2652 rc = mdd_declare_changelog_store(env, mdd, tname, sname, handle);
2659 /* src object can be remote that is why we use only fid and type of object */
2660 static int mdd_rename(const struct lu_env *env,
2661 struct md_object *src_pobj, struct md_object *tgt_pobj,
2662 const struct lu_fid *lf, const struct lu_name *lsname,
2663 struct md_object *tobj, const struct lu_name *ltname,
2666 const char *sname = lsname->ln_name;
2667 const char *tname = ltname->ln_name;
2668 struct lu_attr *la = &mdd_env_info(env)->mti_la_for_fix;
2669 struct mdd_object *mdd_spobj = md2mdd_obj(src_pobj); /* source parent */
2670 struct mdd_object *mdd_tpobj = md2mdd_obj(tgt_pobj);
2671 struct mdd_device *mdd = mdo2mdd(src_pobj);
2672 struct mdd_object *mdd_sobj = NULL; /* source object */
2673 struct mdd_object *mdd_tobj = NULL;
2674 struct lu_attr *cattr = MDD_ENV_VAR(env, cattr);
2675 struct lu_attr *pattr = MDD_ENV_VAR(env, pattr);
2676 struct lu_attr *tattr = MDD_ENV_VAR(env, tattr);
2677 struct lu_attr *tpattr = MDD_ENV_VAR(env, tpattr);
2678 struct thandle *handle;
2679 struct linkea_data *ldata = &mdd_env_info(env)->mti_link_data;
2680 const struct lu_fid *tpobj_fid = mdo2fid(mdd_tpobj);
2681 const struct lu_fid *spobj_fid = mdo2fid(mdd_spobj);
2684 bool tobj_locked = 0;
2685 unsigned cl_flags = 0;
2690 mdd_tobj = md2mdd_obj(tobj);
2692 mdd_sobj = mdd_object_find(env, mdd, lf);
2694 rc = mdd_la_get(env, mdd_sobj, cattr);
2696 GOTO(out_pending, rc);
2698 rc = mdd_la_get(env, mdd_spobj, pattr);
2700 GOTO(out_pending, rc);
2703 rc = mdd_la_get(env, mdd_tobj, tattr);
2705 GOTO(out_pending, rc);
2708 rc = mdd_la_get(env, mdd_tpobj, tpattr);
2710 GOTO(out_pending, rc);
2712 rc = mdd_rename_sanity_check(env, mdd_spobj, pattr, mdd_tpobj, tpattr,
2713 mdd_sobj, cattr, mdd_tobj, tattr);
2715 GOTO(out_pending, rc);
2717 rc = mdd_name_check(mdd, ltname);
2719 GOTO(out_pending, rc);
2721 handle = mdd_trans_create(env, mdd);
2723 GOTO(out_pending, rc = PTR_ERR(handle));
2725 memset(ldata, 0, sizeof(*ldata));
2726 mdd_linkea_prepare(env, mdd_sobj, NULL, NULL, mdd_object_fid(mdd_tpobj),
2727 ltname, 1, 0, ldata);
2728 rc = mdd_declare_rename(env, mdd, mdd_spobj, mdd_tpobj, mdd_sobj,
2729 mdd_tobj, lsname, ltname, ma, ldata, handle);
2733 rc = mdd_trans_start(env, mdd, handle);
2737 /* FIXME: Should consider tobj and sobj too in rename_lock. */
2738 rc = mdd_rename_order(env, mdd, mdd_spobj, pattr, mdd_tpobj);
2740 GOTO(cleanup_unlocked, rc);
2742 is_dir = S_ISDIR(cattr->la_mode);
2744 /* Remove source name from source directory */
2745 rc = __mdd_index_delete(env, mdd_spobj, sname, is_dir, handle);
2749 /* "mv dir1 dir2" needs "dir1/.." link update */
2750 if (is_dir && mdd_sobj && !lu_fid_eq(spobj_fid, tpobj_fid)) {
2751 rc = __mdd_index_delete_only(env, mdd_sobj, dotdot, handle);
2753 GOTO(fixup_spobj2, rc);
2755 rc = __mdd_index_insert_only(env, mdd_sobj, tpobj_fid, S_IFDIR,
2758 GOTO(fixup_spobj, rc);
2761 /* Remove target name from target directory
2762 * Here tobj can be remote one, so we do index_delete unconditionally
2763 * and -ENOENT is allowed.
2765 rc = __mdd_index_delete(env, mdd_tpobj, tname, is_dir, handle);
2768 /* tname might been renamed to something else */
2769 GOTO(fixup_spobj, rc);
2772 GOTO(fixup_spobj, rc);
2775 /* Insert new fid with target name into target dir */
2776 rc = __mdd_index_insert(env, mdd_tpobj, lf, cattr->la_mode,
2779 GOTO(fixup_tpobj, rc);
2781 LASSERT(ma->ma_attr.la_valid & LA_CTIME);
2782 la->la_ctime = la->la_mtime = ma->ma_attr.la_ctime;
2784 /* XXX: mdd_sobj must be local one if it is NOT NULL. */
2786 la->la_valid = LA_CTIME;
2787 rc = mdd_update_time(env, mdd_sobj, cattr, la, handle);
2789 GOTO(fixup_tpobj, rc);
2792 /* Remove old target object
2793 * For tobj is remote case cmm layer has processed
2794 * and set tobj to NULL then. So when tobj is NOT NULL,
2795 * it must be local one.
2797 if (tobj && mdd_object_exists(mdd_tobj)) {
2798 mdd_write_lock(env, mdd_tobj, MOR_TGT_CHILD);
2800 if (mdd_is_dead_obj(mdd_tobj)) {
2801 /* shld not be dead, something is wrong */
2802 CERROR("tobj is dead, something is wrong\n");
2806 mdo_ref_del(env, mdd_tobj, handle);
2808 /* Remove dot reference. */
2809 if (S_ISDIR(tattr->la_mode))
2810 mdo_ref_del(env, mdd_tobj, handle);
2813 /* fetch updated nlink */
2814 rc = mdd_la_get(env, mdd_tobj, tattr);
2816 CERROR("%s: Failed to get nlink for tobj "
2818 mdd2obd_dev(mdd)->obd_name,
2819 PFID(tpobj_fid), rc);
2820 GOTO(fixup_tpobj, rc);
2823 la->la_valid = LA_CTIME;
2824 rc = mdd_update_time(env, mdd_tobj, tattr, la, handle);
2826 CERROR("%s: Failed to set ctime for tobj "
2828 mdd2obd_dev(mdd)->obd_name,
2829 PFID(tpobj_fid), rc);
2830 GOTO(fixup_tpobj, rc);
2833 /* XXX: this transfer to ma will be removed with LOD/OSP */
2834 ma->ma_attr = *tattr;
2835 ma->ma_valid |= MA_INODE;
2836 rc = mdd_finish_unlink(env, mdd_tobj, ma, mdd_tpobj, ltname,
2839 CERROR("%s: Failed to unlink tobj "
2841 mdd2obd_dev(mdd)->obd_name,
2842 PFID(tpobj_fid), rc);
2843 GOTO(fixup_tpobj, rc);
2846 /* fetch updated nlink */
2847 rc = mdd_la_get(env, mdd_tobj, tattr);
2849 CERROR("%s: Failed to get nlink for tobj "
2851 mdd2obd_dev(mdd)->obd_name,
2852 PFID(tpobj_fid), rc);
2853 GOTO(fixup_tpobj, rc);
2855 /* XXX: this transfer to ma will be removed with LOD/OSP */
2856 ma->ma_attr = *tattr;
2857 ma->ma_valid |= MA_INODE;
2859 if (tattr->la_nlink == 0) {
2860 cl_flags |= CLF_RENAME_LAST;
2861 if (mdd_hsm_archive_exists(env, mdd_tobj, ma))
2862 cl_flags |= CLF_RENAME_LAST_EXISTS;
2866 la->la_valid = LA_CTIME | LA_MTIME;
2867 rc = mdd_update_time(env, mdd_spobj, pattr, la, handle);
2869 GOTO(fixup_tpobj, rc);
2871 if (mdd_spobj != mdd_tpobj) {
2872 la->la_valid = LA_CTIME | LA_MTIME;
2873 rc = mdd_update_time(env, mdd_tpobj, tpattr, la, handle);
2876 if (rc == 0 && mdd_sobj) {
2877 mdd_write_lock(env, mdd_sobj, MOR_SRC_CHILD);
2878 rc = mdd_links_rename(env, mdd_sobj, mdo2fid(mdd_spobj), lsname,
2879 mdo2fid(mdd_tpobj), ltname, handle, NULL,
2882 /* Old files might not have EA entry */
2883 mdd_links_add(env, mdd_sobj, mdo2fid(mdd_spobj),
2884 lsname, handle, NULL, 0);
2885 mdd_write_unlock(env, mdd_sobj);
2886 /* We don't fail the transaction if the link ea can't be
2887 updated -- fid2path will use alternate lookup method. */
2895 rc2 = __mdd_index_delete(env, mdd_tpobj, tname, is_dir, handle);
2897 CWARN("tp obj fix error %d\n",rc2);
2899 if (mdd_tobj && mdd_object_exists(mdd_tobj) &&
2900 !mdd_is_dead_obj(mdd_tobj)) {
2902 mdo_ref_add(env, mdd_tobj, handle);
2904 mdo_ref_add(env, mdd_tobj, handle);
2907 rc2 = __mdd_index_insert(env, mdd_tpobj,
2909 mdd_object_type(mdd_tobj),
2912 CWARN("tp obj fix error: rc = %d\n", rc2);
2917 if (rc && is_dir && mdd_sobj && mdd_spobj != mdd_tpobj) {
2918 rc2 = __mdd_index_delete_only(env, mdd_sobj, dotdot, handle);
2920 CWARN("%s: sp obj dotdot delete error: rc = %d\n",
2921 mdd2obd_dev(mdd)->obd_name, rc2);
2924 rc2 = __mdd_index_insert_only(env, mdd_sobj, spobj_fid, S_IFDIR,
2927 CWARN("%s: sp obj dotdot insert error: rc = %d\n",
2928 mdd2obd_dev(mdd)->obd_name, rc2);
2933 rc2 = __mdd_index_insert(env, mdd_spobj, lf,
2934 mdd_object_type(mdd_sobj), sname,
2937 CWARN("sp obj fix error: rc = %d\n", rc2);
2942 mdd_write_unlock(env, mdd_tobj);
2946 rc = mdd_changelog_ns_store(env, mdd, CL_RENAME, cl_flags,
2947 mdd_tobj, tpobj_fid, lf, spobj_fid,
2948 ltname, lsname, handle);
2951 mdd_trans_stop(env, mdd, rc, handle);
2954 mdd_object_put(env, mdd_sobj);
2959 * During migration once the parent FID has been changed,
2960 * we need update the parent FID in linkea.
2962 static int mdd_linkea_update_child_internal(const struct lu_env *env,
2963 struct mdd_object *parent,
2964 struct mdd_object *child,
2965 const char *name, int namelen,
2966 struct thandle *handle,
2969 struct mdd_thread_info *info = mdd_env_info(env);
2970 struct linkea_data ldata = { NULL };
2971 struct lu_buf *buf = &info->mti_link_buf;
2977 buf = lu_buf_check_and_alloc(buf, PATH_MAX);
2978 if (buf->lb_buf == NULL)
2982 rc = mdd_links_read(env, child, &ldata);
2984 if (rc == -ENOENT || rc == -ENODATA)
2989 LASSERT(ldata.ld_leh != NULL);
2990 ldata.ld_lee = (struct link_ea_entry *)(ldata.ld_leh + 1);
2991 for (count = 0; count < ldata.ld_leh->leh_reccount; count++) {
2992 struct mdd_device *mdd = mdo2mdd(&child->mod_obj);
2993 struct lu_name lname;
2996 linkea_entry_unpack(ldata.ld_lee, &ldata.ld_reclen,
2999 if (strncmp(lname.ln_name, name, namelen) != 0 ||
3000 lu_fid_eq(&fid, mdd_object_fid(parent))) {
3001 ldata.ld_lee = (struct link_ea_entry *)
3002 ((char *)ldata.ld_lee +
3007 CDEBUG(D_INFO, "%s: update "DFID" with %.*s:"DFID"\n",
3008 mdd2obd_dev(mdd)->obd_name, PFID(mdd_object_fid(child)),
3009 lname.ln_namelen, lname.ln_name,
3010 PFID(mdd_object_fid(parent)));
3011 /* update to the new parent fid */
3012 linkea_entry_pack(ldata.ld_lee, &lname,
3013 mdd_object_fid(parent));
3015 rc = mdd_declare_links_add(env, child, handle, &ldata,
3018 rc = mdd_links_write(env, child, &ldata, handle);
3024 static int mdd_linkea_declare_update_child(const struct lu_env *env,
3025 struct mdd_object *parent,
3026 struct mdd_object *child,
3027 const char *name, int namelen,
3028 struct thandle *handle)
3030 return mdd_linkea_update_child_internal(env, parent, child, name,
3031 namelen, handle, true);
3034 static int mdd_linkea_update_child(const struct lu_env *env,
3035 struct mdd_object *parent,
3036 struct mdd_object *child,
3037 const char *name, int namelen,
3038 struct thandle *handle)
3040 return mdd_linkea_update_child_internal(env, parent, child, name,
3041 namelen, handle, false);
3044 static int mdd_update_linkea_internal(const struct lu_env *env,
3045 struct mdd_object *mdd_pobj,
3046 struct mdd_object *mdd_sobj,
3047 struct mdd_object *mdd_tobj,
3048 const struct lu_name *child_name,
3049 struct thandle *handle,
3052 struct mdd_thread_info *info = mdd_env_info(env);
3053 struct linkea_data *ldata = &info->mti_link_data;
3058 rc = mdd_links_read(env, mdd_sobj, ldata);
3060 if (rc == -ENOENT || rc == -ENODATA)
3065 /* If it is mulitple links file, we need update the name entry for
3067 LASSERT(ldata->ld_leh != NULL);
3068 ldata->ld_lee = (struct link_ea_entry *)(ldata->ld_leh + 1);
3069 for (count = 0; count < ldata->ld_leh->leh_reccount; count++) {
3070 struct mdd_device *mdd = mdo2mdd(&mdd_sobj->mod_obj);
3071 struct mdd_object *pobj;
3072 struct lu_name lname;
3075 linkea_entry_unpack(ldata->ld_lee, &ldata->ld_reclen,
3077 ldata->ld_lee = (struct link_ea_entry *)((char *)ldata->ld_lee +
3079 pobj = mdd_object_find(env, mdd, &fid);
3081 CWARN("%s: cannot find obj "DFID": rc = %ld\n",
3082 mdd2obd_dev(mdd)->obd_name, PFID(&fid),
3087 if (!mdd_object_exists(pobj)) {
3088 CDEBUG(D_INFO, "%s: obj "DFID" does not exist\n",
3089 mdd2obd_dev(mdd)->obd_name, PFID(&fid));
3093 if (pobj == mdd_pobj &&
3094 lname.ln_namelen == child_name->ln_namelen &&
3095 strncmp(lname.ln_name, child_name->ln_name,
3096 lname.ln_namelen) == 0) {
3097 CDEBUG(D_INFO, "%s: skip its own %s: "DFID"\n",
3098 mdd2obd_dev(mdd)->obd_name, child_name->ln_name,
3103 CDEBUG(D_INFO, "%s: update "DFID" with "DNAME":"DFID"\n",
3104 mdd2obd_dev(mdd)->obd_name, PFID(mdd_object_fid(pobj)),
3105 PNAME(&lname), PFID(mdd_object_fid(mdd_tobj)));
3108 /* Remove source name from source directory */
3109 /* Insert new fid with target name into target dir */
3110 rc = mdo_declare_index_delete(env, pobj, lname.ln_name,
3115 rc = mdo_declare_index_insert(env, pobj,
3116 mdd_object_fid(mdd_tobj),
3117 mdd_object_type(mdd_tobj),
3118 lname.ln_name, handle);
3122 rc = mdo_declare_ref_add(env, mdd_tobj, handle);
3126 rc = mdo_declare_ref_del(env, mdd_sobj, handle);
3130 rc = __mdd_index_delete(env, pobj, lname.ln_name,
3135 rc = __mdd_index_insert(env, pobj,
3136 mdd_object_fid(mdd_tobj),
3137 mdd_object_type(mdd_tobj),
3138 lname.ln_name, handle);
3142 mdd_write_lock(env, mdd_tobj, MOR_SRC_CHILD);
3143 rc = mdo_ref_add(env, mdd_tobj, handle);
3144 mdd_write_unlock(env, mdd_tobj);
3148 mdd_write_lock(env, mdd_sobj, MOR_TGT_CHILD);
3149 mdo_ref_del(env, mdd_sobj, handle);
3150 mdd_write_unlock(env, mdd_sobj);
3153 mdd_object_put(env, pobj);
3161 static int mdd_migrate_xattrs(const struct lu_env *env,
3162 struct mdd_object *mdd_sobj,
3163 struct mdd_object *mdd_tobj)
3165 struct mdd_thread_info *info = mdd_env_info(env);
3166 struct mdd_device *mdd = mdo2mdd(&mdd_sobj->mod_obj);
3168 struct thandle *handle;
3174 struct lu_buf list_xbuf;
3177 /* retrieve xattr list from the old object */
3178 list_xsize = mdo_xattr_list(env, mdd_sobj, &LU_BUF_NULL);
3179 if (list_xsize == -ENODATA)
3185 lu_buf_check_and_alloc(&info->mti_big_buf, list_xsize);
3186 if (info->mti_big_buf.lb_buf == NULL)
3189 list_xbuf.lb_buf = info->mti_big_buf.lb_buf;
3190 list_xbuf.lb_len = list_xsize;
3191 rc = mdo_xattr_list(env, mdd_sobj, &list_xbuf);
3196 xname = list_xbuf.lb_buf;
3198 xlen = strnlen(xname, rem - 1) + 1;
3199 if (strcmp(XATTR_NAME_LINK, xname) == 0 ||
3200 strcmp(XATTR_NAME_LMA, xname) == 0 ||
3201 strcmp(XATTR_NAME_LMV, xname) == 0)
3204 /* For directory, if there are default layout, migrate here */
3205 if (strcmp(XATTR_NAME_LOV, xname) == 0 &&
3206 !S_ISDIR(lu_object_attr(&mdd_sobj->mod_obj.mo_lu)))
3209 xsize = mdo_xattr_get(env, mdd_sobj, &LU_BUF_NULL, xname);
3210 if (xsize == -ENODATA)
3215 lu_buf_check_and_alloc(&info->mti_link_buf, xsize);
3216 if (info->mti_link_buf.lb_buf == NULL)
3217 GOTO(out, rc = -ENOMEM);
3219 xbuf.lb_len = xsize;
3220 xbuf.lb_buf = info->mti_link_buf.lb_buf;
3221 rc = mdo_xattr_get(env, mdd_sobj, &xbuf, xname);
3227 handle = mdd_trans_create(env, mdd);
3229 GOTO(out, rc = PTR_ERR(handle));
3231 rc = mdo_declare_xattr_set(env, mdd_tobj, &xbuf, xname, 0,
3234 GOTO(stop_trans, rc);
3235 /* Note: this transaction is part of migration, and it is not
3236 * the last step of migration, so we set th_local = 1 to avoid
3237 * update last rcvd for this transaction */
3238 handle->th_local = 1;
3239 rc = mdd_trans_start(env, mdd, handle);
3241 GOTO(stop_trans, rc);
3243 rc = mdo_xattr_set(env, mdd_tobj, &xbuf, xname, 0, handle);
3245 GOTO(stop_trans, rc = 0);
3248 GOTO(stop_trans, rc);
3250 mdd_trans_stop(env, mdd, rc, handle);
3255 memmove(xname, xname + xlen, rem);
3261 static int mdd_declare_migrate_create(const struct lu_env *env,
3262 struct mdd_object *mdd_pobj,
3263 struct mdd_object *mdd_sobj,
3264 struct mdd_object *mdd_tobj,
3265 struct md_op_spec *spec,
3267 union lmv_mds_md *mgr_ea,
3268 struct linkea_data *ldata,
3269 struct thandle *handle)
3271 struct lu_attr *la_flag = MDD_ENV_VAR(env, la_for_fix);
3272 const struct lu_buf *buf;
3276 rc = mdd_declare_object_create_internal(env, mdd_pobj, mdd_tobj, la,
3277 handle, spec, NULL);
3281 rc = mdd_declare_object_initialize(env, mdd_pobj, mdd_tobj, la,
3286 if (S_ISLNK(la->la_mode)) {
3287 const char *target_name = spec->u.sp_symname;
3288 int sym_len = strlen(target_name);
3289 const struct lu_buf *buf;
3291 buf = mdd_buf_get_const(env, target_name, sym_len);
3292 rc = dt_declare_record_write(env, mdd_object_child(mdd_tobj),
3296 } else if (S_ISDIR(la->la_mode)) {
3297 rc = mdd_declare_links_add(env, mdd_tobj, handle, ldata,
3303 if (spec->u.sp_ea.eadata != NULL && spec->u.sp_ea.eadatalen != 0) {
3304 buf = mdd_buf_get_const(env, spec->u.sp_ea.eadata,
3305 spec->u.sp_ea.eadatalen);
3306 rc = mdo_declare_xattr_set(env, mdd_tobj, buf, XATTR_NAME_LOV,
3312 mgr_easize = lmv_mds_md_size(2, LMV_MAGIC_V1);
3313 buf = mdd_buf_get_const(env, mgr_ea, mgr_easize);
3314 rc = mdo_declare_xattr_set(env, mdd_sobj, buf, XATTR_NAME_LMV,
3319 la_flag->la_valid = LA_FLAGS;
3320 la_flag->la_flags = la->la_flags | LUSTRE_IMMUTABLE_FL;
3321 rc = mdo_declare_attr_set(env, mdd_sobj, la_flag, handle);
3326 static int mdd_migrate_create(const struct lu_env *env,
3327 struct mdd_object *mdd_pobj,
3328 struct mdd_object *mdd_sobj,
3329 struct mdd_object *mdd_tobj,
3330 const struct lu_name *lname,
3333 struct mdd_thread_info *info = mdd_env_info(env);
3334 struct mdd_device *mdd = mdo2mdd(&mdd_sobj->mod_obj);
3335 struct md_op_spec *spec = &info->mti_spec;
3336 struct lu_buf lmm_buf = { NULL };
3337 struct lu_buf link_buf = { NULL };
3338 const struct lu_buf *buf;
3339 struct thandle *handle;
3340 struct lmv_mds_md_v1 *mgr_ea;
3341 struct lu_attr *la_flag = MDD_ENV_VAR(env, la_for_fix);
3342 struct dt_allocation_hint *hint = &mdd_env_info(env)->mti_hint;
3344 struct linkea_data *ldata = &mdd_env_info(env)->mti_link_data;
3348 /* prepare spec for create */
3349 memset(spec, 0, sizeof(*spec));
3350 spec->sp_cr_lookup = 0;
3351 spec->sp_feat = &dt_directory_features;
3352 if (S_ISLNK(la->la_mode)) {
3353 buf = lu_buf_check_and_alloc(
3354 &mdd_env_info(env)->mti_big_buf,
3357 link_buf.lb_len = la->la_size + 1;
3358 memset(link_buf.lb_buf, 0, link_buf.lb_len);
3359 rc = mdd_readlink(env, &mdd_sobj->mod_obj, &link_buf);
3361 rc = rc != 0 ? rc : -EFAULT;
3362 CERROR("%s: "DFID" readlink failed: rc = %d\n",
3363 mdd2obd_dev(mdd)->obd_name,
3364 PFID(mdd_object_fid(mdd_sobj)), rc);
3367 spec->u.sp_symname = link_buf.lb_buf;
3368 } else if S_ISREG(la->la_mode) {
3369 /* retrieve lov of the old object */
3370 rc = mdd_get_lov_ea(env, mdd_sobj, &lmm_buf);
3371 if (rc != 0 && rc != -ENODATA)
3373 if (lmm_buf.lb_buf != NULL && lmm_buf.lb_len != 0) {
3374 spec->u.sp_ea.eadata = lmm_buf.lb_buf;
3375 spec->u.sp_ea.eadatalen = lmm_buf.lb_len;
3376 spec->sp_cr_flags |= MDS_OPEN_HAS_EA;
3378 } else if (S_ISDIR(la->la_mode)) {
3379 rc = mdd_links_read(env, mdd_sobj, ldata);
3380 if (rc < 0 && rc != -ENODATA)
3384 mgr_ea = (struct lmv_mds_md_v1 *)info->mti_xattr_buf;
3385 memset(mgr_ea, 0, sizeof(*mgr_ea));
3386 mgr_ea->lmv_magic = cpu_to_le32(LMV_MAGIC_V1);
3387 mgr_ea->lmv_stripe_count = cpu_to_le32(2);
3388 mgr_ea->lmv_master_mdt_index = mdd_seq_site(mdd)->ss_node_id;
3389 mgr_ea->lmv_hash_type = cpu_to_le32(LMV_HASH_FLAG_MIGRATION);
3390 fid_cpu_to_le(&mgr_ea->lmv_stripe_fids[0], mdd_object_fid(mdd_sobj));
3391 fid_cpu_to_le(&mgr_ea->lmv_stripe_fids[1], mdd_object_fid(mdd_tobj));
3393 mdd_object_make_hint(env, mdd_pobj, mdd_tobj, la, spec, hint);
3395 handle = mdd_trans_create(env, mdd);
3397 GOTO(out_free, rc = PTR_ERR(handle));
3399 /* Note: this transaction is part of migration, and it is not
3400 * the last step of migration, so we set th_local = 1 to avoid
3401 * update last rcvd for this transaction */
3402 handle->th_local = 1;
3403 rc = mdd_declare_migrate_create(env, mdd_pobj, mdd_sobj, mdd_tobj,
3405 (union lmv_mds_md *)info->mti_xattr_buf,
3408 GOTO(stop_trans, rc);
3410 rc = mdd_trans_start(env, mdd, handle);
3412 GOTO(stop_trans, rc);
3414 /* create the target object */
3415 rc = mdd_object_create(env, mdd_pobj, mdd_tobj, la, spec, NULL, NULL,
3418 GOTO(stop_trans, rc);
3420 if (S_ISDIR(la->la_mode)) {
3421 rc = mdd_links_write(env, mdd_tobj, ldata, handle);
3423 GOTO(stop_trans, rc);
3426 /* Set MIGRATE EA on the source inode, so once the migration needs
3427 * to be re-done during failover, the re-do process can locate the
3428 * target object which is already being created. */
3429 mgr_easize = lmv_mds_md_size(2, LMV_MAGIC_V1);
3430 buf = mdd_buf_get_const(env, mgr_ea, mgr_easize);
3431 rc = mdo_xattr_set(env, mdd_sobj, buf, XATTR_NAME_LMV, 0, handle);
3433 GOTO(stop_trans, rc);
3435 /* Set immutable flag, so any modification is disabled until
3436 * the migration is done. Once the migration is interrupted,
3437 * if the resume process find the migrating object has both
3438 * IMMUTALBE flag and MIGRATE EA, it need to clear IMMUTABLE
3439 * flag and approve the migration */
3440 la_flag->la_valid = LA_FLAGS;
3441 la_flag->la_flags = la->la_flags | LUSTRE_IMMUTABLE_FL;
3442 rc = mdo_attr_set(env, mdd_sobj, la_flag, handle);
3445 mdd_trans_stop(env, mdd, rc, handle);
3447 if (lmm_buf.lb_buf != NULL)
3448 OBD_FREE(lmm_buf.lb_buf, lmm_buf.lb_len);
3452 static int mdd_migrate_entries(const struct lu_env *env,
3453 struct mdd_object *mdd_sobj,
3454 struct mdd_object *mdd_tobj)
3456 struct dt_object *next = mdd_object_child(mdd_sobj);
3457 struct mdd_device *mdd = mdo2mdd(&mdd_sobj->mod_obj);
3458 struct dt_object *dt_tobj = mdd_object_child(mdd_tobj);
3459 struct thandle *handle;
3461 const struct dt_it_ops *iops;
3464 struct lu_dirent *ent;
3467 OBD_ALLOC(ent, NAME_MAX + sizeof(*ent) + 1);
3471 if (!dt_try_as_dir(env, next))
3472 GOTO(out_ent, rc = -ENOTDIR);
3474 * iterate directories
3476 iops = &next->do_index_ops->dio_it;
3477 it = iops->init(env, next, LUDA_FID | LUDA_TYPE);
3479 GOTO(out_ent, rc = PTR_ERR(it));
3481 rc = iops->load(env, it, 0);
3483 rc = iops->next(env, it);
3487 * At this point and across for-loop:
3489 * rc == 0 -> ok, proceed.
3490 * rc > 0 -> end of directory.
3494 struct mdd_object *child;
3495 char *name = mdd_env_info(env)->mti_key;
3499 bool target_exist = false;
3501 len = iops->key_size(env, it);
3505 result = iops->rec(env, it, (struct dt_rec *)ent,
3506 LUDA_FID | LUDA_TYPE);
3507 if (result == -ESTALE)
3514 fid_le_to_cpu(&ent->lde_fid, &ent->lde_fid);
3515 recsize = le16_to_cpu(ent->lde_reclen);
3517 /* Insert new fid with target name into target dir */
3518 if ((ent->lde_namelen == 1 && ent->lde_name[0] == '.') ||
3519 (ent->lde_namelen == 2 && ent->lde_name[0] == '.' &&
3520 ent->lde_name[1] == '.'))
3523 child = mdd_object_find(env, mdd, &ent->lde_fid);
3525 GOTO(out, rc = PTR_ERR(child));
3527 is_dir = S_ISDIR(mdd_object_type(child));
3529 snprintf(name, ent->lde_namelen + 1, "%s", ent->lde_name);
3531 /* Check whether the name has been inserted to the target */
3532 if (dt_try_as_dir(env, dt_tobj)) {
3533 struct lu_fid *fid = &mdd_env_info(env)->mti_fid2;
3535 rc = dt_lookup(env, dt_tobj, (struct dt_rec *)fid,
3536 (struct dt_key *)name);
3537 if (unlikely(rc == 0))
3538 target_exist = true;
3541 handle = mdd_trans_create(env, mdd);
3543 GOTO(out, rc = PTR_ERR(handle));
3545 /* Note: this transaction is part of migration, and it is not
3546 * the last step of migration, so we set th_local = 1 to avoid
3547 * updating last rcvd for this transaction */
3548 handle->th_local = 1;
3549 if (likely(!target_exist)) {
3550 rc = mdo_declare_index_insert(env, mdd_tobj,
3552 mdd_object_type(child),
3558 rc = mdo_declare_ref_add(env, mdd_tobj, handle);
3564 rc = mdo_declare_index_delete(env, mdd_sobj, name, handle);
3569 rc = mdo_declare_ref_del(env, mdd_sobj, handle);
3573 /* Update .. for child */
3574 rc = mdo_declare_index_delete(env, child, dotdot,
3579 rc = mdo_declare_index_insert(env, child,
3580 mdd_object_fid(mdd_tobj),
3581 S_IFDIR, dotdot, handle);
3586 rc = mdd_linkea_declare_update_child(env, mdd_tobj,
3593 rc = mdd_trans_start(env, mdd, handle);
3595 CERROR("%s: transaction start failed: rc = %d\n",
3596 mdd2obd_dev(mdd)->obd_name, rc);
3600 if (likely(!target_exist)) {
3601 rc = __mdd_index_insert(env, mdd_tobj, &ent->lde_fid,
3602 mdd_object_type(child),
3608 rc = __mdd_index_delete(env, mdd_sobj, name, is_dir, handle);
3613 rc = __mdd_index_delete_only(env, child, dotdot,
3618 rc = __mdd_index_insert_only(env, child,
3619 mdd_object_fid(mdd_tobj), S_IFDIR,
3625 rc = mdd_linkea_update_child(env, mdd_tobj, child, name,
3626 strlen(name), handle);
3629 mdd_object_put(env, child);
3630 mdd_trans_stop(env, mdd, rc, handle);
3634 result = iops->next(env, it);
3635 if (OBD_FAIL_CHECK(OBD_FAIL_MIGRATE_ENTRIES))
3636 GOTO(out, rc = -EINTR);
3638 if (result == -ESTALE)
3640 } while (result == 0);
3643 iops->fini(env, it);
3645 OBD_FREE(ent, NAME_MAX + sizeof(*ent) + 1);
3649 static int mdd_declare_update_linkea(const struct lu_env *env,
3650 struct mdd_object *mdd_pobj,
3651 struct mdd_object *mdd_sobj,
3652 struct mdd_object *mdd_tobj,
3653 struct thandle *handle,
3654 const struct lu_name *child_name)
3656 return mdd_update_linkea_internal(env, mdd_pobj, mdd_sobj, mdd_tobj,
3657 child_name, handle, 1);
3660 static int mdd_update_linkea(const struct lu_env *env,
3661 struct mdd_object *mdd_pobj,
3662 struct mdd_object *mdd_sobj,
3663 struct mdd_object *mdd_tobj,
3664 struct thandle *handle,
3665 const struct lu_name *child_name)
3667 return mdd_update_linkea_internal(env, mdd_pobj, mdd_sobj, mdd_tobj,
3668 child_name, handle, 0);
3671 static int mdd_declare_migrate_update_name(const struct lu_env *env,
3672 struct mdd_object *mdd_pobj,
3673 struct mdd_object *mdd_sobj,
3674 struct mdd_object *mdd_tobj,
3675 const struct lu_name *lname,
3677 struct lu_attr *parent_la,
3678 struct thandle *handle)
3680 struct lu_attr *la_flag = MDD_ENV_VAR(env, tattr);
3683 /* Revert IMMUTABLE flag */
3684 la_flag->la_valid = LA_FLAGS;
3685 la_flag->la_flags = la->la_flags & ~LUSTRE_IMMUTABLE_FL;
3686 rc = mdo_declare_attr_set(env, mdd_sobj, la_flag, handle);
3690 /* delete entry from source dir */
3691 rc = mdo_declare_index_delete(env, mdd_pobj, lname->ln_name, handle);
3695 rc = mdd_declare_update_linkea(env, mdd_pobj, mdd_sobj,
3696 mdd_tobj, handle, lname);
3700 if (S_ISREG(mdd_object_type(mdd_sobj))) {
3701 rc = mdo_declare_xattr_del(env, mdd_sobj, XATTR_NAME_LOV,
3707 if (S_ISDIR(mdd_object_type(mdd_sobj))) {
3708 rc = mdo_declare_ref_del(env, mdd_pobj, handle);
3714 rc = mdo_declare_index_insert(env, mdd_pobj, mdo2fid(mdd_tobj),
3715 mdd_object_type(mdd_tobj),
3716 lname->ln_name, handle);
3720 rc = mdd_declare_links_add(env, mdd_tobj, handle, NULL, MLAO_IGNORE);
3724 if (S_ISDIR(mdd_object_type(mdd_sobj))) {
3725 rc = mdo_declare_ref_add(env, mdd_pobj, handle);
3730 /* delete old object */
3731 rc = mdo_declare_ref_del(env, mdd_sobj, handle);
3735 if (S_ISDIR(mdd_object_type(mdd_sobj))) {
3736 /* delete old object */
3737 rc = mdo_declare_ref_del(env, mdd_sobj, handle);
3740 /* set nlink to 0 */
3741 rc = mdo_declare_attr_set(env, mdd_sobj, la, handle);
3746 rc = mdd_declare_finish_unlink(env, mdd_sobj, handle);
3750 rc = mdo_declare_attr_set(env, mdd_pobj, parent_la, handle);
3755 static int mdd_migrate_update_name(const struct lu_env *env,
3756 struct mdd_object *mdd_pobj,
3757 struct mdd_object *mdd_sobj,
3758 struct mdd_object *mdd_tobj,
3759 const struct lu_name *lname,
3762 struct lu_attr *p_la = MDD_ENV_VAR(env, la_for_fix);
3763 struct lu_attr *so_attr = MDD_ENV_VAR(env, cattr);
3764 struct lu_attr *la_flag = MDD_ENV_VAR(env, tattr);
3765 struct mdd_device *mdd = mdo2mdd(&mdd_sobj->mod_obj);
3766 struct thandle *handle;
3767 int is_dir = S_ISDIR(mdd_object_type(mdd_sobj));
3768 const char *name = lname->ln_name;
3772 /* update time for parent */
3773 LASSERT(ma->ma_attr.la_valid & LA_CTIME);
3774 p_la->la_ctime = p_la->la_mtime = ma->ma_attr.la_ctime;
3775 p_la->la_valid = LA_CTIME;
3777 rc = mdd_la_get(env, mdd_sobj, so_attr);
3781 handle = mdd_trans_create(env, mdd);
3783 RETURN(PTR_ERR(handle));
3785 rc = mdd_declare_migrate_update_name(env, mdd_pobj, mdd_sobj, mdd_tobj,
3786 lname, so_attr, p_la, handle);
3788 /* If the migration can not be fit in one transaction, just
3789 * leave it in the original MDT */
3791 GOTO(stop_trans, rc = 0);
3793 GOTO(stop_trans, rc);
3796 CDEBUG(D_INFO, "%s: update "DFID"/"DFID" with %s:"DFID"\n",
3797 mdd2obd_dev(mdd)->obd_name, PFID(mdd_object_fid(mdd_pobj)),
3798 PFID(mdd_object_fid(mdd_sobj)), lname->ln_name,
3799 PFID(mdd_object_fid(mdd_tobj)));
3801 rc = mdd_trans_start(env, mdd, handle);
3803 GOTO(stop_trans, rc);
3805 /* Revert IMMUTABLE flag */
3806 la_flag->la_valid = LA_FLAGS;
3807 la_flag->la_flags = so_attr->la_flags & ~LUSTRE_IMMUTABLE_FL;
3808 rc = mdo_attr_set(env, mdd_sobj, la_flag, handle);
3810 GOTO(stop_trans, rc);
3812 /* Remove source name from source directory */
3813 rc = __mdd_index_delete(env, mdd_pobj, name, is_dir, handle);
3815 GOTO(stop_trans, rc);
3817 rc = mdd_update_linkea(env, mdd_pobj, mdd_sobj, mdd_tobj,
3820 GOTO(stop_trans, rc);
3822 if (S_ISREG(so_attr->la_mode)) {
3823 if (so_attr->la_nlink == 1) {
3824 rc = mdo_xattr_del(env, mdd_sobj, XATTR_NAME_LOV,
3826 if (rc != 0 && rc != -ENODATA)
3827 GOTO(stop_trans, rc);
3831 /* Insert new fid with target name into target dir */
3832 rc = __mdd_index_insert(env, mdd_pobj, mdd_object_fid(mdd_tobj),
3833 mdd_object_type(mdd_tobj), name, handle);
3835 GOTO(stop_trans, rc);
3837 rc = mdd_links_add(env, mdd_tobj, mdo2fid(mdd_pobj), lname, handle,
3840 GOTO(stop_trans, rc);
3842 mdd_write_lock(env, mdd_sobj, MOR_SRC_CHILD);
3843 mdo_ref_del(env, mdd_sobj, handle);
3845 mdo_ref_del(env, mdd_sobj, handle);
3847 /* Get the attr again after ref_del */
3848 rc = mdd_la_get(env, mdd_sobj, so_attr);
3850 GOTO(out_unlock, rc);
3852 ma->ma_attr = *so_attr;
3853 ma->ma_valid |= MA_INODE;
3854 rc = mdd_finish_unlink(env, mdd_sobj, ma, mdd_pobj, lname, handle);
3856 GOTO(out_unlock, rc);
3858 rc = mdd_attr_set_internal(env, mdd_pobj, p_la, handle, 0);
3860 GOTO(out_unlock, rc);
3863 mdd_write_unlock(env, mdd_sobj);
3866 mdd_trans_stop(env, mdd, rc, handle);
3872 * Check whether we should migrate the file/dir
3874 * < 0 permission check failed or other error.
3875 * = 0 the file can be migrated.
3876 * > 0 the file does not need to be migrated, mostly
3877 * for multiple link file
3879 static int mdd_migrate_sanity_check(const struct lu_env *env,
3880 struct mdd_object *pobj,
3881 const struct lu_attr *pattr,
3882 struct mdd_object *sobj,
3883 struct lu_attr *sattr)
3885 struct mdd_thread_info *info = mdd_env_info(env);
3886 struct linkea_data *ldata = &info->mti_link_data;
3888 struct lu_buf *mgr_buf;
3894 mgr_easize = lmv_mds_md_size(2, LMV_MAGIC_V1);
3895 mgr_buf = lu_buf_check_and_alloc(&info->mti_big_buf, mgr_easize);
3896 if (mgr_buf->lb_buf == NULL)
3899 rc = mdo_xattr_get(env, sobj, mgr_buf, XATTR_NAME_LMV);
3901 union lmv_mds_md *lmm = mgr_buf->lb_buf;
3903 /* If the object has migrateEA, it means IMMUTE flag
3904 * is being set by previous migration process, so it
3905 * needs to override the IMMUTE flag, otherwise the
3906 * following sanity check will fail */
3907 if (le32_to_cpu(lmm->lmv_md_v1.lmv_hash_type) &
3908 LMV_HASH_FLAG_MIGRATION) {
3909 struct mdd_device *mdd = mdo2mdd(&sobj->mod_obj);
3911 sattr->la_flags &= ~LUSTRE_IMMUTABLE_FL;
3912 CDEBUG(D_HA, "%s: "DFID" override IMMUTE FLAG\n",
3913 mdd2obd_dev(mdd)->obd_name,
3914 PFID(mdd_object_fid(sobj)));
3918 rc = mdd_rename_sanity_check(env, pobj, pattr, pobj, pattr,
3919 sobj, sattr, NULL, NULL);
3923 /* Then it will check if the file should be migrated. If the file
3924 * has mulitple links, we only need migrate the file if all of its
3925 * entries has been migrated to the remote MDT */
3926 if (!S_ISREG(sattr->la_mode) || sattr->la_nlink < 2)
3929 rc = mdd_links_read(env, sobj, ldata);
3931 /* For multiple links files, if there are no linkEA data at all,
3932 * means the file might be created before linkEA is enabled, and
3933 * all all of its links should not be migrated yet, otherwise
3934 * it should have some linkEA there */
3935 if (rc == -ENOENT || rc == -ENODATA)
3940 /* If it is mulitple links file, we need update the name entry for
3942 LASSERT(ldata->ld_leh != NULL);
3943 ldata->ld_lee = (struct link_ea_entry *)(ldata->ld_leh + 1);
3944 for (count = 0; count < ldata->ld_leh->leh_reccount; count++) {
3945 struct mdd_device *mdd = mdo2mdd(&sobj->mod_obj);
3946 struct mdd_object *lpobj;
3947 struct lu_name lname;
3950 linkea_entry_unpack(ldata->ld_lee, &ldata->ld_reclen,
3952 ldata->ld_lee = (struct link_ea_entry *)((char *)ldata->ld_lee +
3954 lpobj = mdd_object_find(env, mdd, &fid);
3955 if (IS_ERR(lpobj)) {
3956 CWARN("%s: cannot find obj "DFID": rc = %ld\n",
3957 mdd2obd_dev(mdd)->obd_name, PFID(&fid),
3962 if (!mdd_object_exists(lpobj) || mdd_object_remote(lpobj)) {
3963 CDEBUG(D_INFO, DFID"%.*s: is on remote MDT.\n",
3964 PFID(&fid), lname.ln_namelen, lname.ln_name);
3965 mdd_object_put(env, lpobj);
3969 CDEBUG(D_INFO, DFID"still has local entry %.*s "DFID"\n",
3970 PFID(mdd_object_fid(sobj)), lname.ln_namelen,
3971 lname.ln_name, PFID(&fid));
3972 mdd_object_put(env, lpobj);
3980 static int mdd_migrate(const struct lu_env *env, struct md_object *pobj,
3981 struct md_object *sobj, const struct lu_name *lname,
3982 struct md_object *tobj, struct md_attr *ma)
3984 struct mdd_object *mdd_pobj = md2mdd_obj(pobj);
3985 struct mdd_device *mdd = mdo2mdd(pobj);
3986 struct mdd_object *mdd_sobj = md2mdd_obj(sobj);
3987 struct mdd_object *mdd_tobj = NULL;
3988 struct lu_attr *so_attr = MDD_ENV_VAR(env, cattr);
3989 struct lu_attr *pattr = MDD_ENV_VAR(env, pattr);
3993 /* If the file will being migrated, it will check whether
3994 * the file is being opened by someone else right now */
3995 mdd_read_lock(env, mdd_sobj, MOR_SRC_CHILD);
3996 if (mdd_sobj->mod_count >= 1) {
3997 CERROR("%s: "DFID"%s is already opened count %d: rc = %d\n",
3998 mdd2obd_dev(mdd)->obd_name,
3999 PFID(mdd_object_fid(mdd_sobj)), lname->ln_name,
4000 mdd_sobj->mod_count, -EBUSY);
4001 mdd_read_unlock(env, mdd_sobj);
4002 GOTO(put, rc = -EBUSY);
4004 mdd_read_unlock(env, mdd_sobj);
4006 rc = mdd_la_get(env, mdd_sobj, so_attr);
4010 rc = mdd_la_get(env, mdd_pobj, pattr);
4014 rc = mdd_migrate_sanity_check(env, mdd_pobj, pattr, mdd_sobj, so_attr);
4021 /* Sigh, it is impossible to finish all of migration in a single
4022 * transaction, for example migrating big directory entries to the
4023 * new MDT, it needs insert all of name entries of children in the
4026 * So migration will be done in multiple steps and transactions.
4028 * 1. create an orphan object on the remote MDT in one transaction.
4029 * 2. migrate extend attributes to the new target file/directory.
4030 * 3. For directory, migrate the entries to the new MDT and update
4031 * linkEA of each children. Because we can not migrate all entries
4032 * in a single transaction, so the migrating directory will become
4033 * a striped directory during migration, so once the process is
4034 * interrupted, the directory is still accessible. (During lookup,
4035 * client will locate the name by searching both original and target
4037 * 4. Finally, update the name/FID to point to the new file/directory
4038 * in a separate transaction.
4041 /* step 1: Check whether the orphan object has been created, and create
4042 * orphan object on the remote MDT if needed */
4043 mdd_tobj = md2mdd_obj(tobj);
4044 if (!mdd_object_exists(mdd_tobj)) {
4045 rc = mdd_migrate_create(env, mdd_pobj, mdd_sobj, mdd_tobj,
4051 /* step 2: migrate xattr */
4052 rc = mdd_migrate_xattrs(env, mdd_sobj, mdd_tobj);
4056 /* step 3: migrate name entries to the orphan object */
4057 if (S_ISDIR(lu_object_attr(&mdd_sobj->mod_obj.mo_lu))) {
4058 rc = mdd_migrate_entries(env, mdd_sobj, mdd_tobj);
4061 if (unlikely(OBD_FAIL_CHECK_RESET(OBD_FAIL_MIGRATE_NET_REP,
4062 OBD_FAIL_MDS_REINT_NET_REP)))
4065 OBD_FAIL_TIMEOUT(OBD_FAIL_MIGRATE_DELAY, cfs_fail_val);
4068 /* step 4: update name entry to the new object */
4069 rc = mdd_migrate_update_name(env, mdd_pobj, mdd_sobj, mdd_tobj, lname,
4077 const struct md_dir_operations mdd_dir_ops = {
4078 .mdo_is_subdir = mdd_is_subdir,
4079 .mdo_lookup = mdd_lookup,
4080 .mdo_create = mdd_create,
4081 .mdo_rename = mdd_rename,
4082 .mdo_link = mdd_link,
4083 .mdo_unlink = mdd_unlink,
4084 .mdo_create_data = mdd_create_data,
4085 .mdo_migrate = mdd_migrate,