4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lustre/mdd/mdd_dir.c
34 * Lustre Metadata Server (mdd) routines
36 * Author: Wang Di <wangdi@intel.com>
39 #define DEBUG_SUBSYSTEM S_MDS
41 #include <obd_class.h>
42 #include <obd_support.h>
43 #include <lustre_mds.h>
44 #include <lustre_fid.h>
45 #include <lustre_lmv.h>
47 #include "mdd_internal.h"
49 static const char dot[] = ".";
50 static const char dotdot[] = "..";
52 static struct lu_name lname_dotdot = {
53 .ln_name = (char *) dotdot,
54 .ln_namelen = sizeof(dotdot) - 1,
58 mdd_name_check(struct mdd_device *m, const struct lu_name *ln)
60 if (!lu_name_is_valid(ln))
62 else if (ln->ln_namelen > m->mdd_dt_conf.ddp_max_name_len)
68 /* Get FID from name and parent */
70 __mdd_lookup(const struct lu_env *env, struct md_object *pobj,
71 const struct lu_attr *pattr, const struct lu_name *lname,
72 struct lu_fid* fid, int mask)
74 const char *name = lname->ln_name;
75 const struct dt_key *key = (const struct dt_key *)name;
76 struct mdd_object *mdd_obj = md2mdd_obj(pobj);
77 struct mdd_device *m = mdo2mdd(pobj);
78 struct dt_object *dir = mdd_object_child(mdd_obj);
82 if (unlikely(mdd_is_dead_obj(mdd_obj)))
85 if (!mdd_object_exists(mdd_obj))
88 if (mdd_object_remote(mdd_obj)) {
89 CDEBUG(D_INFO, "%s: Object "DFID" locates on remote server\n",
90 mdd2obd_dev(m)->obd_name, PFID(mdo2fid(mdd_obj)));
93 rc = mdd_permission_internal_locked(env, mdd_obj, pattr, mask,
98 if (likely(S_ISDIR(mdd_object_type(mdd_obj)) &&
99 dt_try_as_dir(env, dir)))
100 rc = dt_lookup(env, dir, (struct dt_rec *)fid, key);
107 int mdd_lookup(const struct lu_env *env,
108 struct md_object *pobj, const struct lu_name *lname,
109 struct lu_fid *fid, struct md_op_spec *spec)
111 struct lu_attr *pattr = MDD_ENV_VAR(env, pattr);
115 rc = mdd_la_get(env, md2mdd_obj(pobj), pattr);
119 rc = __mdd_lookup(env, pobj, pattr, lname, fid,
120 (spec != NULL && spec->sp_permitted) ? 0 : MAY_EXEC);
124 /** Read the link EA into a temp buffer.
125 * Uses the mdd_thread_info::mti_big_buf since it is generally large.
126 * A pointer to the buffer is stored in \a ldata::ld_buf.
130 static int __mdd_links_read(const struct lu_env *env,
131 struct mdd_object *mdd_obj,
132 struct linkea_data *ldata)
136 if (!mdd_object_exists(mdd_obj))
139 /* First try a small buf */
140 LASSERT(env != NULL);
141 ldata->ld_buf = lu_buf_check_and_alloc(&mdd_env_info(env)->mti_link_buf,
143 if (ldata->ld_buf->lb_buf == NULL)
146 rc = mdo_xattr_get(env, mdd_obj, ldata->ld_buf, XATTR_NAME_LINK);
148 /* Buf was too small, figure out what we need. */
149 lu_buf_free(ldata->ld_buf);
150 rc = mdo_xattr_get(env, mdd_obj, ldata->ld_buf,
154 ldata->ld_buf = lu_buf_check_and_alloc(ldata->ld_buf, rc);
155 if (ldata->ld_buf->lb_buf == NULL)
157 rc = mdo_xattr_get(env, mdd_obj, ldata->ld_buf,
161 lu_buf_free(ldata->ld_buf);
162 ldata->ld_buf = NULL;
166 return linkea_init(ldata);
169 static int mdd_links_read(const struct lu_env *env,
170 struct mdd_object *mdd_obj,
171 struct linkea_data *ldata)
175 rc = __mdd_links_read(env, mdd_obj, ldata);
177 rc = linkea_init(ldata);
182 static int mdd_links_read_with_rec(const struct lu_env *env,
183 struct mdd_object *mdd_obj,
184 struct linkea_data *ldata)
188 rc = __mdd_links_read(env, mdd_obj, ldata);
190 rc = linkea_init_with_rec(ldata);
196 * Get parent FID of the directory
198 * Read parent FID from linkEA, if that fails, then do lookup
199 * dotdot to get the parent FID.
201 * \param[in] env execution environment
202 * \param[in] obj object from which to find the parent FID
203 * \param[in] attr attribute of the object
204 * \param[out] fid fid to get the parent FID
206 * \retval 0 if getting the parent FID succeeds.
207 * \retval negative errno if getting the parent FID fails.
209 static inline int mdd_parent_fid(const struct lu_env *env,
210 struct mdd_object *obj,
211 const struct lu_attr *attr,
214 struct mdd_thread_info *info = mdd_env_info(env);
215 struct linkea_data ldata = { NULL };
216 struct lu_buf *buf = &info->mti_link_buf;
217 struct lu_name lname;
222 LASSERT(S_ISDIR(mdd_object_type(obj)));
224 buf = lu_buf_check_and_alloc(buf, PATH_MAX);
225 if (buf->lb_buf == NULL)
226 GOTO(lookup, rc = 0);
229 rc = mdd_links_read_with_rec(env, obj, &ldata);
233 LASSERT(ldata.ld_leh != NULL);
234 /* Directory should only have 1 parent */
235 if (ldata.ld_leh->leh_reccount > 1)
238 ldata.ld_lee = (struct link_ea_entry *)(ldata.ld_leh + 1);
240 linkea_entry_unpack(ldata.ld_lee, &ldata.ld_reclen, &lname, fid);
241 if (likely(fid_is_sane(fid)))
244 rc = __mdd_lookup(env, &obj->mod_obj, attr, &lname_dotdot, fid, 0);
249 * For root fid use special function, which does not compare version component
250 * of fid. Version component is different for root fids on all MDTs.
252 int mdd_is_root(struct mdd_device *mdd, const struct lu_fid *fid)
254 return fid_seq(&mdd->mdd_root_fid) == fid_seq(fid) &&
255 fid_oid(&mdd->mdd_root_fid) == fid_oid(fid);
259 * return 1: if \a tfid is the fid of the ancestor of \a mo;
261 * otherwise: values < 0, errors.
263 static int mdd_is_parent(const struct lu_env *env,
264 struct mdd_device *mdd,
265 struct mdd_object *mo,
266 const struct lu_attr *attr,
267 const struct lu_fid *tfid)
269 struct mdd_object *mp;
273 LASSERT(!lu_fid_eq(mdo2fid(mo), tfid));
274 pfid = &mdd_env_info(env)->mti_fid;
276 if (mdd_is_root(mdd, mdo2fid(mo)))
279 if (mdd_is_root(mdd, tfid))
282 rc = mdd_parent_fid(env, mo, attr, pfid);
287 if (lu_fid_eq(pfid, tfid))
290 if (mdd_is_root(mdd, pfid))
293 mp = mdd_object_find(env, mdd, pfid);
297 if (!mdd_object_exists(mp)) {
298 mdd_object_put(env, mp);
302 rc = mdd_parent_fid(env, mp, attr, pfid);
303 mdd_object_put(env, mp);
312 * No permission check is needed.
314 * returns 1: if fid is ancestor of @mo;
315 * returns 0: if fid is not an ancestor of @mo;
316 * returns < 0: if error
318 int mdd_is_subdir(const struct lu_env *env, struct md_object *mo,
319 const struct lu_fid *fid)
321 struct mdd_device *mdd = mdo2mdd(mo);
322 struct lu_attr *attr = MDD_ENV_VAR(env, cattr);
326 if (!mdd_object_exists(md2mdd_obj(mo)))
329 if (!S_ISDIR(mdd_object_type(md2mdd_obj(mo))))
332 rc = mdd_la_get(env, md2mdd_obj(mo), attr);
336 rc = mdd_is_parent(env, mdd, md2mdd_obj(mo), attr, fid);
341 * Check that @dir contains no entries except (possibly) dot and dotdot.
346 * -ENOTDIR not a directory object
347 * -ENOTEMPTY not empty
351 static int mdd_dir_is_empty(const struct lu_env *env,
352 struct mdd_object *dir)
355 struct dt_object *obj;
356 const struct dt_it_ops *iops;
360 obj = mdd_object_child(dir);
361 if (!dt_try_as_dir(env, obj))
364 iops = &obj->do_index_ops->dio_it;
365 it = iops->init(env, obj, LUDA_64BITHASH);
367 result = iops->get(env, it, (const struct dt_key *)"");
370 for (result = 0, i = 0; result == 0 && i < 3; ++i)
371 result = iops->next(env, it);
374 else if (result == 1)
376 } else if (result == 0)
378 * Huh? Index contains no zero key?
385 result = PTR_ERR(it);
390 * Determine if the target object can be hard linked, and right now it only
391 * checks if the link count reach the maximum limit. Note: for ldiskfs, the
392 * directory nlink count might exceed the maximum link count(see
393 * osd_object_ref_add), so it only check nlink for non-directories.
395 * \param[in] env thread environment
396 * \param[in] obj object being linked to
397 * \param[in] la attributes of \a obj
399 * \retval 0 if \a obj can be hard linked
400 * \retval negative error if \a obj is a directory or has too
403 static int __mdd_may_link(const struct lu_env *env, struct mdd_object *obj,
404 const struct lu_attr *la)
406 struct mdd_device *m = mdd_obj2mdd_dev(obj);
411 /* Subdir count limitation can be broken through
412 * (see osd_object_ref_add), so only check non-directory here. */
413 if (!S_ISDIR(la->la_mode) &&
414 la->la_nlink >= m->mdd_dt_conf.ddp_max_nlink)
421 * Check whether it may create the cobj under the pobj.
423 * \param[in] env execution environment
424 * \param[in] pobj the parent directory
425 * \param[in] pattr the attribute of the parent directory
426 * \param[in] cobj the child to be created
427 * \param[in] check_perm if check WRITE|EXEC permission for parent
429 * \retval = 0 create the child under this dir is allowed
430 * \retval negative errno create the child under this dir is
433 int mdd_may_create(const struct lu_env *env, struct mdd_object *pobj,
434 const struct lu_attr *pattr, struct mdd_object *cobj,
440 if (cobj && mdd_object_exists(cobj))
443 if (mdd_is_dead_obj(pobj))
447 rc = mdd_permission_internal_locked(env, pobj, pattr,
448 MAY_WRITE | MAY_EXEC,
454 * Check whether can unlink from the pobj in the case of "cobj == NULL".
456 int mdd_may_unlink(const struct lu_env *env, struct mdd_object *pobj,
457 const struct lu_attr *pattr, const struct lu_attr *attr)
462 if (mdd_is_dead_obj(pobj))
465 if (attr->la_flags & (LUSTRE_APPEND_FL | LUSTRE_IMMUTABLE_FL))
468 rc = mdd_permission_internal_locked(env, pobj, pattr,
469 MAY_WRITE | MAY_EXEC,
474 if (pattr->la_flags & LUSTRE_APPEND_FL)
481 * pobj == NULL is remote ops case, under such case, pobj's
482 * VTX feature has been checked already, no need check again.
484 static inline int mdd_is_sticky(const struct lu_env *env,
485 struct mdd_object *pobj,
486 const struct lu_attr *pattr,
487 struct mdd_object *cobj,
488 const struct lu_attr *cattr)
490 struct lu_ucred *uc = lu_ucred_assert(env);
493 LASSERT(pattr != NULL);
494 if (!(pattr->la_mode & S_ISVTX) ||
495 (pattr->la_uid == uc->uc_fsuid))
499 LASSERT(cattr != NULL);
500 if (cattr->la_uid == uc->uc_fsuid)
503 return !md_capable(uc, CFS_CAP_FOWNER);
506 static int mdd_may_delete_entry(const struct lu_env *env,
507 struct mdd_object *pobj,
508 const struct lu_attr *pattr,
513 LASSERT(pobj != NULL);
514 if (!mdd_object_exists(pobj))
517 if (mdd_is_dead_obj(pobj))
522 rc = mdd_permission_internal_locked(env, pobj, pattr,
523 MAY_WRITE | MAY_EXEC,
529 if (pattr->la_flags & LUSTRE_APPEND_FL)
536 * Check whether it may delete the cobj from the pobj.
539 int mdd_may_delete(const struct lu_env *env, struct mdd_object *tpobj,
540 const struct lu_attr *tpattr, struct mdd_object *tobj,
541 const struct lu_attr *tattr, const struct lu_attr *cattr,
542 int check_perm, int check_empty)
548 LASSERT(tpattr != NULL);
549 rc = mdd_may_delete_entry(env, tpobj, tpattr, check_perm);
557 if (!mdd_object_exists(tobj))
560 if (mdd_is_dead_obj(tobj))
563 if (mdd_is_sticky(env, tpobj, tpattr, tobj, tattr))
566 if (tattr->la_flags & (LUSTRE_APPEND_FL | LUSTRE_IMMUTABLE_FL))
569 /* additional check the rename case */
571 if (S_ISDIR(cattr->la_mode)) {
572 struct mdd_device *mdd = mdo2mdd(&tobj->mod_obj);
574 if (!S_ISDIR(tattr->la_mode))
577 if (lu_fid_eq(mdo2fid(tobj), &mdd->mdd_root_fid))
579 } else if (S_ISDIR(tattr->la_mode))
583 if (S_ISDIR(tattr->la_mode) && check_empty)
584 rc = mdd_dir_is_empty(env, tobj);
590 * Check whether it can create the link file(linked to @src_obj) under
591 * the target directory(@tgt_obj), and src_obj has been locked by
594 * \param[in] env execution environment
595 * \param[in] tgt_obj the target directory
596 * \param[in] tattr attributes of target directory
597 * \param[in] lname the link name
598 * \param[in] src_obj source object for link
599 * \param[in] cattr attributes for source object
601 * \retval = 0 it is allowed to create the link file under tgt_obj
602 * \retval negative error not allowed to create the link file
604 static int mdd_link_sanity_check(const struct lu_env *env,
605 struct mdd_object *tgt_obj,
606 const struct lu_attr *tattr,
607 const struct lu_name *lname,
608 struct mdd_object *src_obj,
609 const struct lu_attr *cattr)
611 struct mdd_device *m = mdd_obj2mdd_dev(src_obj);
615 if (!mdd_object_exists(src_obj))
618 if (mdd_is_dead_obj(src_obj))
621 /* Local ops, no lookup before link, check filename length here. */
622 rc = mdd_name_check(m, lname);
626 if (cattr->la_flags & (LUSTRE_IMMUTABLE_FL | LUSTRE_APPEND_FL))
629 if (S_ISDIR(mdd_object_type(src_obj)))
632 LASSERT(src_obj != tgt_obj);
633 rc = mdd_may_create(env, tgt_obj, tattr, NULL, true);
637 rc = __mdd_may_link(env, src_obj, cattr);
642 static int __mdd_index_delete_only(const struct lu_env *env, struct mdd_object *pobj,
643 const char *name, struct thandle *handle)
645 struct dt_object *next = mdd_object_child(pobj);
649 if (dt_try_as_dir(env, next))
650 rc = dt_delete(env, next, (struct dt_key *)name, handle);
657 static int __mdd_index_insert_only(const struct lu_env *env,
658 struct mdd_object *pobj,
659 const struct lu_fid *lf, __u32 type,
661 struct thandle *handle)
663 struct dt_object *next = mdd_object_child(pobj);
667 if (dt_try_as_dir(env, next)) {
668 struct dt_insert_rec *rec = &mdd_env_info(env)->mti_dt_rec;
671 rec->rec_type = type;
672 rc = dt_insert(env, next, (const struct dt_rec *)rec,
673 (const struct dt_key *)name, handle);
680 /* insert named index, add reference if isdir */
681 static int __mdd_index_insert(const struct lu_env *env, struct mdd_object *pobj,
682 const struct lu_fid *lf, __u32 type,
683 const char *name, struct thandle *handle)
688 rc = __mdd_index_insert_only(env, pobj, lf, type, name, handle);
689 if (rc == 0 && S_ISDIR(type)) {
690 mdd_write_lock(env, pobj, MOR_TGT_PARENT);
691 mdo_ref_add(env, pobj, handle);
692 mdd_write_unlock(env, pobj);
698 /* delete named index, drop reference if isdir */
699 static int __mdd_index_delete(const struct lu_env *env, struct mdd_object *pobj,
700 const char *name, int is_dir,
701 struct thandle *handle)
706 rc = __mdd_index_delete_only(env, pobj, name, handle);
707 if (rc == 0 && is_dir) {
708 mdd_write_lock(env, pobj, MOR_TGT_PARENT);
709 mdo_ref_del(env, pobj, handle);
710 mdd_write_unlock(env, pobj);
716 static int mdd_llog_record_calc_size(const struct lu_env *env,
717 const struct lu_name *tname,
718 const struct lu_name *sname)
720 const struct lu_ucred *uc = lu_ucred(env);
721 enum changelog_rec_flags crf = CLF_EXTRA_FLAGS;
722 enum changelog_rec_extra_flags crfe = CLFE_UIDGID | CLFE_NID;
727 if (uc != NULL && uc->uc_jobid[0] != '\0')
730 return llog_data_len(LLOG_CHANGELOG_HDR_SZ +
731 changelog_rec_offset(crf, crfe) +
732 (tname != NULL ? tname->ln_namelen : 0) +
733 (sname != NULL ? 1 + sname->ln_namelen : 0));
736 int mdd_declare_changelog_store(const struct lu_env *env,
737 struct mdd_device *mdd,
738 enum changelog_rec_type type,
739 const struct lu_name *tname,
740 const struct lu_name *sname,
741 struct thandle *handle)
743 struct obd_device *obd = mdd2obd_dev(mdd);
744 struct llog_ctxt *ctxt;
745 struct llog_changelog_rec *rec;
747 struct thandle *llog_th;
751 if (!mdd_changelog_enabled(env, mdd, type))
754 reclen = mdd_llog_record_calc_size(env, tname, sname);
755 buf = lu_buf_check_and_alloc(&mdd_env_info(env)->mti_big_buf, reclen);
756 if (buf->lb_buf == NULL)
760 rec->cr_hdr.lrh_len = reclen;
761 rec->cr_hdr.lrh_type = CHANGELOG_REC;
763 ctxt = llog_get_context(obd, LLOG_CHANGELOG_ORIG_CTXT);
767 llog_th = thandle_get_sub(env, handle, ctxt->loc_handle->lgh_obj);
769 GOTO(out_put, rc = PTR_ERR(llog_th));
771 rc = llog_declare_add(env, ctxt->loc_handle, &rec->cr_hdr, llog_th);
779 /** Add a changelog entry \a rec to the changelog llog
782 * \param handle - currently ignored since llogs start their own transaction;
783 * this will hopefully be fixed in llog rewrite
786 int mdd_changelog_store(const struct lu_env *env, struct mdd_device *mdd,
787 struct llog_changelog_rec *rec, struct thandle *th)
789 struct obd_device *obd = mdd2obd_dev(mdd);
790 struct llog_ctxt *ctxt;
791 struct thandle *llog_th;
794 rec->cr_hdr.lrh_len = llog_data_len(sizeof(*rec) +
795 changelog_rec_varsize(&rec->cr));
797 /* llog_lvfs_write_rec sets the llog tail len */
798 rec->cr_hdr.lrh_type = CHANGELOG_REC;
799 rec->cr.cr_time = cl_time();
801 spin_lock(&mdd->mdd_cl.mc_lock);
802 /* NB: I suppose it's possible llog_add adds out of order wrt cr_index,
803 * but as long as the MDD transactions are ordered correctly for e.g.
804 * rename conflicts, I don't think this should matter. */
805 rec->cr.cr_index = ++mdd->mdd_cl.mc_index;
806 spin_unlock(&mdd->mdd_cl.mc_lock);
808 ctxt = llog_get_context(obd, LLOG_CHANGELOG_ORIG_CTXT);
812 llog_th = thandle_get_sub(env, th, ctxt->loc_handle->lgh_obj);
814 GOTO(out_put, rc = PTR_ERR(llog_th));
816 /* nested journal transaction */
817 rc = llog_add(env, ctxt->loc_handle, &rec->cr_hdr, NULL, llog_th);
819 /* time to recover some space ?? */
820 if (likely(!mdd->mdd_changelog_gc ||
821 mdd->mdd_cl.mc_gc_task != MDD_CHLG_GC_NONE ||
822 mdd->mdd_changelog_min_gc_interval >=
823 ktime_get_real_seconds() - mdd->mdd_cl.mc_gc_time))
824 /* save a spin_lock trip */
826 spin_lock(&mdd->mdd_cl.mc_lock);
827 if (likely(mdd->mdd_changelog_gc &&
828 mdd->mdd_cl.mc_gc_task == MDD_CHLG_GC_NONE &&
829 ktime_get_real_seconds() - mdd->mdd_cl.mc_gc_time >
830 mdd->mdd_changelog_min_gc_interval)) {
831 if (unlikely(llog_cat_free_space(ctxt->loc_handle) <=
832 mdd->mdd_changelog_min_free_cat_entries ||
833 OBD_FAIL_CHECK(OBD_FAIL_FORCE_GC_THREAD))) {
834 CWARN("%s:%s low on changelog_catalog free entries, "
835 "starting ChangeLog garbage collection thread\n",
837 OBD_FAIL_CHECK(OBD_FAIL_FORCE_GC_THREAD) ?
840 /* indicate further kthread run will occur outside
841 * right after current journal transaction filling has
844 mdd->mdd_cl.mc_gc_task = MDD_CHLG_GC_NEED;
846 /* next check in mdd_changelog_min_gc_interval anyway
848 mdd->mdd_cl.mc_gc_time = ktime_get_real_seconds();
850 spin_unlock(&mdd->mdd_cl.mc_lock);
858 static void mdd_changelog_rec_ext_rename(struct changelog_rec *rec,
859 const struct lu_fid *sfid,
860 const struct lu_fid *spfid,
861 const struct lu_name *sname)
863 struct changelog_ext_rename *rnm = changelog_rec_rename(rec);
866 LASSERT(sfid != NULL);
867 LASSERT(spfid != NULL);
868 LASSERT(sname != NULL);
870 extsize = sname->ln_namelen + 1;
872 rnm->cr_sfid = *sfid;
873 rnm->cr_spfid = *spfid;
875 changelog_rec_name(rec)[rec->cr_namelen] = '\0';
876 strlcpy(changelog_rec_sname(rec), sname->ln_name, extsize);
877 rec->cr_namelen += extsize;
880 void mdd_changelog_rec_ext_jobid(struct changelog_rec *rec, const char *jobid)
882 struct changelog_ext_jobid *jid = changelog_rec_jobid(rec);
884 if (jobid == NULL || jobid[0] == '\0')
887 strlcpy(jid->cr_jobid, jobid, sizeof(jid->cr_jobid));
890 void mdd_changelog_rec_ext_extra_flags(struct changelog_rec *rec, __u64 eflags)
892 struct changelog_ext_extra_flags *ef = changelog_rec_extra_flags(rec);
894 ef->cr_extra_flags = eflags;
897 void mdd_changelog_rec_extra_uidgid(struct changelog_rec *rec,
898 __u64 uid, __u64 gid)
900 struct changelog_ext_uidgid *uidgid = changelog_rec_uidgid(rec);
902 uidgid->cr_uid = uid;
903 uidgid->cr_gid = gid;
906 void mdd_changelog_rec_extra_nid(struct changelog_rec *rec,
909 struct changelog_ext_nid *clnid = changelog_rec_nid(rec);
914 void mdd_changelog_rec_extra_omode(struct changelog_rec *rec, int flags)
916 struct changelog_ext_openmode *omd = changelog_rec_openmode(rec);
918 omd->cr_openflags = (__u32)flags;
921 void mdd_changelog_rec_extra_xattr(struct changelog_rec *rec,
922 const char *xattr_name)
924 struct changelog_ext_xattr *xattr = changelog_rec_xattr(rec);
926 strlcpy(xattr->cr_xattr, xattr_name, sizeof(xattr->cr_xattr));
929 /** Store a namespace change changelog record
930 * If this fails, we must fail the whole transaction; we don't
931 * want the change to commit without the log entry.
932 * \param target - mdd_object of change
933 * \param tpfid - target parent dir/object fid
934 * \param sfid - source object fid
935 * \param spfid - source parent fid
936 * \param tname - target name string
937 * \param sname - source name string
938 * \param handle - transaction handle
940 int mdd_changelog_ns_store(const struct lu_env *env,
941 struct mdd_device *mdd,
942 enum changelog_rec_type type,
943 enum changelog_rec_flags crf,
944 struct mdd_object *target,
945 const struct lu_fid *tpfid,
946 const struct lu_fid *sfid,
947 const struct lu_fid *spfid,
948 const struct lu_name *tname,
949 const struct lu_name *sname,
950 struct thandle *handle)
952 const struct lu_ucred *uc = lu_ucred(env);
953 struct llog_changelog_rec *rec;
956 __u64 xflags = CLFE_INVALID;
960 if (!mdd_changelog_enabled(env, mdd, type))
963 LASSERT(tpfid != NULL);
964 LASSERT(tname != NULL);
965 LASSERT(handle != NULL);
967 reclen = mdd_llog_record_calc_size(env, tname, sname);
968 buf = lu_buf_check_and_alloc(&mdd_env_info(env)->mti_big_buf, reclen);
969 if (buf->lb_buf == NULL)
974 crf |= CLF_EXTRA_FLAGS;
977 if (uc->uc_jobid[0] != '\0')
979 xflags |= CLFE_UIDGID;
988 rec->cr.cr_flags = crf;
990 if (crf & CLF_EXTRA_FLAGS) {
991 mdd_changelog_rec_ext_extra_flags(&rec->cr, xflags);
992 if (xflags & CLFE_UIDGID)
993 mdd_changelog_rec_extra_uidgid(&rec->cr,
994 uc->uc_uid, uc->uc_gid);
995 if (xflags & CLFE_NID)
996 mdd_changelog_rec_extra_nid(&rec->cr, uc->uc_nid);
999 rec->cr.cr_type = (__u32)type;
1000 rec->cr.cr_pfid = *tpfid;
1001 rec->cr.cr_namelen = tname->ln_namelen;
1002 memcpy(changelog_rec_name(&rec->cr), tname->ln_name, tname->ln_namelen);
1004 if (crf & CLF_RENAME)
1005 mdd_changelog_rec_ext_rename(&rec->cr, sfid, spfid, sname);
1007 if (crf & CLF_JOBID)
1008 mdd_changelog_rec_ext_jobid(&rec->cr, uc->uc_jobid);
1010 if (likely(target != NULL)) {
1011 rec->cr.cr_tfid = *mdo2fid(target);
1012 target->mod_cltime = ktime_get();
1014 fid_zero(&rec->cr.cr_tfid);
1017 rc = mdd_changelog_store(env, mdd, rec, handle);
1019 CERROR("%s: cannot store changelog record: type = %d, "
1020 "name = '%s', t = "DFID", p = "DFID": rc = %d\n",
1021 mdd2obd_dev(mdd)->obd_name, type, tname->ln_name,
1022 PFID(&rec->cr.cr_tfid), PFID(&rec->cr.cr_pfid), rc);
1029 static int __mdd_links_add(const struct lu_env *env,
1030 struct mdd_object *mdd_obj,
1031 struct linkea_data *ldata,
1032 const struct lu_name *lname,
1033 const struct lu_fid *pfid,
1034 int first, int check)
1038 if (ldata->ld_leh == NULL) {
1039 rc = first ? -ENODATA : mdd_links_read(env, mdd_obj, ldata);
1043 rc = linkea_data_new(ldata,
1044 &mdd_env_info(env)->mti_link_buf);
1051 rc = linkea_links_find(ldata, lname, pfid);
1052 if (rc && rc != -ENOENT)
1058 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LINKEA_MORE)) {
1059 struct lu_fid *tfid = &mdd_env_info(env)->mti_fid2;
1063 linkea_add_buf(ldata, lname, tfid);
1066 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LINKEA_MORE2))
1067 linkea_add_buf(ldata, lname, pfid);
1069 return linkea_add_buf(ldata, lname, pfid);
1072 static int __mdd_links_del(const struct lu_env *env,
1073 struct mdd_object *mdd_obj,
1074 struct linkea_data *ldata,
1075 const struct lu_name *lname,
1076 const struct lu_fid *pfid)
1080 if (ldata->ld_leh == NULL) {
1081 rc = mdd_links_read(env, mdd_obj, ldata);
1086 rc = linkea_links_find(ldata, lname, pfid);
1090 linkea_del_buf(ldata, lname);
1094 static int mdd_linkea_prepare(const struct lu_env *env,
1095 struct mdd_object *mdd_obj,
1096 const struct lu_fid *oldpfid,
1097 const struct lu_name *oldlname,
1098 const struct lu_fid *newpfid,
1099 const struct lu_name *newlname,
1100 int first, int check,
1101 struct linkea_data *ldata)
1106 if (OBD_FAIL_CHECK(OBD_FAIL_FID_IGIF))
1109 LASSERT(oldpfid != NULL || newpfid != NULL);
1111 if (mdd_obj->mod_flags & DEAD_OBJ)
1112 /* Unnecessary to update linkEA for dead object. */
1115 if (oldpfid != NULL) {
1116 rc = __mdd_links_del(env, mdd_obj, ldata, oldlname, oldpfid);
1118 if ((check == 1) || (rc != -ENODATA && rc != -ENOENT))
1121 /* No changes done. */
1126 /* If renaming, add the new record */
1127 if (newpfid != NULL)
1128 rc = __mdd_links_add(env, mdd_obj, ldata, newlname, newpfid,
1134 int mdd_links_rename(const struct lu_env *env,
1135 struct mdd_object *mdd_obj,
1136 const struct lu_fid *oldpfid,
1137 const struct lu_name *oldlname,
1138 const struct lu_fid *newpfid,
1139 const struct lu_name *newlname,
1140 struct thandle *handle,
1141 struct linkea_data *ldata,
1142 int first, int check)
1147 if (ldata == NULL) {
1148 ldata = &mdd_env_info(env)->mti_link_data;
1149 memset(ldata, 0, sizeof(*ldata));
1150 rc = mdd_linkea_prepare(env, mdd_obj, oldpfid, oldlname,
1151 newpfid, newlname, first, check, ldata);
1156 if (!(mdd_obj->mod_flags & DEAD_OBJ))
1157 rc = mdd_links_write(env, mdd_obj, ldata, handle);
1163 if (newlname == NULL)
1164 CERROR("link_ea add failed %d "DFID"\n",
1165 rc, PFID(mdd_object_fid(mdd_obj)));
1166 else if (oldpfid == NULL)
1167 CERROR("link_ea add '%.*s' failed %d "DFID"\n",
1168 newlname->ln_namelen, newlname->ln_name, rc,
1169 PFID(mdd_object_fid(mdd_obj)));
1170 else if (newpfid == NULL)
1171 CERROR("link_ea del '%.*s' failed %d "DFID"\n",
1172 oldlname->ln_namelen, oldlname->ln_name, rc,
1173 PFID(mdd_object_fid(mdd_obj)));
1175 CERROR("link_ea rename '%.*s'->'%.*s' failed %d "DFID
1176 "\n", oldlname->ln_namelen, oldlname->ln_name,
1177 newlname->ln_namelen, newlname->ln_name, rc,
1178 PFID(mdd_object_fid(mdd_obj)));
1181 if (is_vmalloc_addr(ldata->ld_buf))
1182 /* if we vmalloced a large buffer drop it */
1183 lu_buf_free(ldata->ld_buf);
1188 static inline int mdd_links_add(const struct lu_env *env,
1189 struct mdd_object *mdd_obj,
1190 const struct lu_fid *pfid,
1191 const struct lu_name *lname,
1192 struct thandle *handle,
1193 struct linkea_data *ldata, int first)
1195 return mdd_links_rename(env, mdd_obj, NULL, NULL,
1196 pfid, lname, handle, ldata, first, 0);
1199 static inline int mdd_links_del(const struct lu_env *env,
1200 struct mdd_object *mdd_obj,
1201 const struct lu_fid *pfid,
1202 const struct lu_name *lname,
1203 struct thandle *handle)
1205 return mdd_links_rename(env, mdd_obj, pfid, lname,
1206 NULL, NULL, handle, NULL, 0, 0);
1209 /** Read the link EA into a temp buffer.
1210 * Uses the name_buf since it is generally large.
1211 * \retval IS_ERR err
1212 * \retval ptr to \a lu_buf (always \a mti_big_buf)
1214 struct lu_buf *mdd_links_get(const struct lu_env *env,
1215 struct mdd_object *mdd_obj)
1217 struct linkea_data ldata = { NULL };
1220 rc = mdd_links_read(env, mdd_obj, &ldata);
1221 return rc ? ERR_PTR(rc) : ldata.ld_buf;
1224 int mdd_links_write(const struct lu_env *env, struct mdd_object *mdd_obj,
1225 struct linkea_data *ldata, struct thandle *handle)
1227 const struct lu_buf *buf;
1230 if (ldata == NULL || ldata->ld_buf == NULL ||
1231 ldata->ld_leh == NULL)
1234 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_NO_LINKEA))
1238 buf = mdd_buf_get_const(env, ldata->ld_buf->lb_buf,
1239 ldata->ld_leh->leh_len);
1240 rc = mdo_xattr_set(env, mdd_obj, buf, XATTR_NAME_LINK, 0, handle);
1241 if (unlikely(rc == -ENOSPC)) {
1242 rc = linkea_overflow_shrink(ldata);
1250 static int mdd_declare_links_add(const struct lu_env *env,
1251 struct mdd_object *mdd_obj,
1252 struct thandle *handle,
1253 struct linkea_data *ldata)
1259 if (ldata != NULL && ldata->ld_leh != NULL) {
1260 ea_len = ldata->ld_leh->leh_len;
1261 linkea = ldata->ld_buf->lb_buf;
1263 ea_len = MAX_LINKEA_SIZE;
1267 rc = mdo_declare_xattr_set(env, mdd_obj,
1268 mdd_buf_get_const(env, linkea, ea_len),
1269 XATTR_NAME_LINK, 0, handle);
1274 static inline int mdd_declare_links_del(const struct lu_env *env,
1275 struct mdd_object *c,
1276 struct thandle *handle)
1280 /* For directory, the linkEA will be removed together
1281 * with the object. */
1282 if (!S_ISDIR(mdd_object_type(c)))
1283 rc = mdd_declare_links_add(env, c, handle, NULL);
1288 static int mdd_declare_link(const struct lu_env *env,
1289 struct mdd_device *mdd,
1290 struct mdd_object *p,
1291 struct mdd_object *c,
1292 const struct lu_name *name,
1293 struct thandle *handle,
1295 struct linkea_data *data)
1297 struct lu_fid tfid = *mdo2fid(c);
1300 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_DANGLING3))
1301 tfid.f_oid = cfs_fail_val;
1303 rc = mdo_declare_index_insert(env, p, &tfid, mdd_object_type(c),
1304 name->ln_name, handle);
1308 rc = mdo_declare_ref_add(env, c, handle);
1312 la->la_valid = LA_CTIME | LA_MTIME;
1313 rc = mdo_declare_attr_set(env, p, la, handle);
1317 la->la_valid = LA_CTIME;
1318 rc = mdo_declare_attr_set(env, c, la, handle);
1322 rc = mdd_declare_links_add(env, c, handle, data);
1326 rc = mdd_declare_changelog_store(env, mdd, CL_HARDLINK, name, NULL,
1332 static int mdd_link(const struct lu_env *env, struct md_object *tgt_obj,
1333 struct md_object *src_obj, const struct lu_name *lname,
1336 const char *name = lname->ln_name;
1337 struct lu_attr *la = &mdd_env_info(env)->mti_la_for_fix;
1338 struct mdd_object *mdd_tobj = md2mdd_obj(tgt_obj);
1339 struct mdd_object *mdd_sobj = md2mdd_obj(src_obj);
1340 struct lu_attr *cattr = MDD_ENV_VAR(env, cattr);
1341 struct lu_attr *tattr = MDD_ENV_VAR(env, tattr);
1342 struct mdd_device *mdd = mdo2mdd(src_obj);
1343 struct thandle *handle;
1344 struct lu_fid *tfid = &mdd_env_info(env)->mti_fid2;
1345 struct linkea_data *ldata = &mdd_env_info(env)->mti_link_data;
1349 rc = mdd_la_get(env, mdd_sobj, cattr);
1353 rc = mdd_la_get(env, mdd_tobj, tattr);
1358 * If we are using project inheritance, we only allow hard link
1359 * creation in our tree when the project IDs are the same;
1360 * otherwise the tree quota mechanism could be circumvented.
1362 if ((tattr->la_flags & LUSTRE_PROJINHERIT_FL) &&
1363 (tattr->la_projid != cattr->la_projid))
1366 handle = mdd_trans_create(env, mdd);
1368 GOTO(out_pending, rc = PTR_ERR(handle));
1370 memset(ldata, 0, sizeof(*ldata));
1372 LASSERT(ma->ma_attr.la_valid & LA_CTIME);
1373 la->la_ctime = la->la_mtime = ma->ma_attr.la_ctime;
1375 /* Note: even this function will change ldata, but it comes from
1376 * thread_info, which is completely temporary and only seen in
1377 * this function, so we do not need reset ldata once it fails.*/
1378 rc = mdd_linkea_prepare(env, mdd_sobj, NULL, NULL, mdo2fid(mdd_tobj),
1379 lname, 0, 0, ldata);
1383 rc = mdd_declare_link(env, mdd, mdd_tobj, mdd_sobj, lname, handle,
1388 rc = mdd_trans_start(env, mdd, handle);
1392 mdd_write_lock(env, mdd_sobj, MOR_TGT_CHILD);
1393 rc = mdd_link_sanity_check(env, mdd_tobj, tattr, lname, mdd_sobj,
1396 GOTO(out_unlock, rc);
1398 if (!OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LESS_NLINK)) {
1399 rc = mdo_ref_add(env, mdd_sobj, handle);
1401 GOTO(out_unlock, rc);
1404 *tfid = *mdo2fid(mdd_sobj);
1405 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_DANGLING3))
1406 tfid->f_oid = cfs_fail_val;
1408 rc = __mdd_index_insert_only(env, mdd_tobj, tfid,
1409 mdd_object_type(mdd_sobj), name, handle);
1411 mdo_ref_del(env, mdd_sobj, handle);
1412 GOTO(out_unlock, rc);
1415 la->la_valid = LA_CTIME | LA_MTIME;
1416 rc = mdd_update_time(env, mdd_tobj, tattr, la, handle);
1418 GOTO(out_unlock, rc);
1420 la->la_valid = LA_CTIME;
1421 rc = mdd_update_time(env, mdd_sobj, cattr, la, handle);
1423 /* Note: The failure of links_add should not cause the
1424 * link failure, so do not check return value. */
1425 mdd_links_add(env, mdd_sobj, mdo2fid(mdd_tobj),
1426 lname, handle, ldata, 0);
1430 mdd_write_unlock(env, mdd_sobj);
1432 rc = mdd_changelog_ns_store(env, mdd, CL_HARDLINK, 0, mdd_sobj,
1433 mdo2fid(mdd_tobj), NULL, NULL,
1434 lname, NULL, handle);
1436 rc = mdd_trans_stop(env, mdd, rc, handle);
1437 if (is_vmalloc_addr(ldata->ld_buf))
1438 /* if we vmalloced a large buffer drop it */
1439 lu_buf_free(ldata->ld_buf);
1444 static int mdd_mark_orphan_object(const struct lu_env *env,
1445 struct mdd_object *obj, struct thandle *handle,
1448 struct lu_attr *attr = MDD_ENV_VAR(env, la_for_start);
1451 if (!S_ISDIR(mdd_object_type(obj)))
1454 attr->la_valid = LA_FLAGS;
1455 attr->la_flags = LUSTRE_ORPHAN_FL;
1458 rc = mdo_declare_attr_set(env, obj, attr, handle);
1460 rc = mdo_attr_set(env, obj, attr, handle);
1465 static int mdd_declare_finish_unlink(const struct lu_env *env,
1466 struct mdd_object *obj,
1467 struct thandle *handle)
1471 /* Sigh, we do not know if the unlink object will become orphan in
1472 * declare phase, but fortunately the flags here does not matter
1473 * in current declare implementation */
1474 rc = mdd_mark_orphan_object(env, obj, handle, true);
1478 rc = mdo_declare_destroy(env, obj, handle);
1482 rc = mdd_orphan_declare_insert(env, obj, mdd_object_type(obj), handle);
1486 return mdd_declare_links_del(env, obj, handle);
1489 /* caller should take a lock before calling */
1490 int mdd_finish_unlink(const struct lu_env *env,
1491 struct mdd_object *obj, struct md_attr *ma,
1492 const struct mdd_object *pobj,
1493 const struct lu_name *lname,
1497 int is_dir = S_ISDIR(ma->ma_attr.la_mode);
1500 LASSERT(mdd_write_locked(env, obj) != 0);
1502 if (ma->ma_attr.la_nlink == 0 || is_dir) {
1503 /* add new orphan and the object
1504 * will be deleted during mdd_close() */
1505 obj->mod_flags |= DEAD_OBJ;
1506 if (obj->mod_count) {
1507 rc = mdd_orphan_insert(env, obj, th);
1509 CDEBUG(D_HA, "Object "DFID" is inserted into "
1510 "orphan list, open count = %d\n",
1511 PFID(mdd_object_fid(obj)),
1514 CERROR("Object "DFID" fail to be an orphan, "
1515 "open count = %d, maybe cause failed "
1517 PFID(mdd_object_fid(obj)),
1520 /* mark object as an orphan here, not
1521 * before mdd_orphan_insert() as racing
1522 * mdd_la_get() may propagate ORPHAN_OBJ
1523 * causing the asserition */
1524 rc = mdd_mark_orphan_object(env, obj, th, false);
1526 rc = mdo_destroy(env, obj, th);
1528 } else if (!is_dir) {
1529 /* old files may not have link ea; ignore errors */
1530 mdd_links_del(env, obj, mdo2fid(pobj), lname, th);
1538 * has mdd_write_lock on cobj already, but not on pobj yet
1540 int mdd_unlink_sanity_check(const struct lu_env *env, struct mdd_object *pobj,
1541 const struct lu_attr *pattr,
1542 struct mdd_object *cobj,
1543 const struct lu_attr *cattr)
1548 rc = mdd_may_delete(env, pobj, pattr, cobj, cattr, NULL, 1, 1);
1553 static int mdd_declare_unlink(const struct lu_env *env, struct mdd_device *mdd,
1554 struct mdd_object *p, struct mdd_object *c,
1555 const struct lu_name *name, struct md_attr *ma,
1556 struct thandle *handle, int no_name, int is_dir)
1558 struct lu_attr *la = &mdd_env_info(env)->mti_la_for_fix;
1561 if (!OBD_FAIL_CHECK(OBD_FAIL_LFSCK_DANGLING2)) {
1562 if (likely(no_name == 0)) {
1563 rc = mdo_declare_index_delete(env, p, name->ln_name,
1570 rc = mdo_declare_ref_del(env, p, handle);
1576 LASSERT(ma->ma_attr.la_valid & LA_CTIME);
1577 la->la_ctime = la->la_mtime = ma->ma_attr.la_ctime;
1578 la->la_valid = LA_CTIME | LA_MTIME;
1579 rc = mdo_declare_attr_set(env, p, la, handle);
1584 rc = mdo_declare_ref_del(env, c, handle);
1588 rc = mdo_declare_ref_del(env, c, handle);
1592 la->la_valid = LA_CTIME;
1593 rc = mdo_declare_attr_set(env, c, la, handle);
1597 rc = mdd_declare_finish_unlink(env, c, handle);
1601 /* FIXME: need changelog for remove entry */
1602 rc = mdd_declare_changelog_store(env, mdd, CL_UNLINK, name,
1610 * test if a file has an HSM archive
1611 * if HSM attributes are not found in ma update them from
1614 static bool mdd_hsm_archive_exists(const struct lu_env *env,
1615 struct mdd_object *obj,
1620 if (!(ma->ma_valid & MA_HSM)) {
1621 /* no HSM MD provided, read xattr */
1622 struct lu_buf *hsm_buf;
1623 const size_t buflen = sizeof(struct hsm_attrs);
1626 hsm_buf = mdd_buf_get(env, NULL, 0);
1627 lu_buf_alloc(hsm_buf, buflen);
1628 rc = mdo_xattr_get(env, obj, hsm_buf, XATTR_NAME_HSM);
1629 rc = lustre_buf2hsm(hsm_buf->lb_buf, rc, &ma->ma_hsm);
1630 lu_buf_free(hsm_buf);
1634 ma->ma_valid |= MA_HSM;
1636 if (ma->ma_hsm.mh_flags & HS_EXISTS)
1642 * Delete name entry and the object.
1643 * Note: no_name == 1 means it only destory the object, i.e. name_entry
1644 * does not exist for this object, and it could only happen during resending
1645 * of remote unlink. see the comments in mdt_reint_unlink. Unfortunately, lname
1646 * is also needed in this case(needed by changelog), so we have to add another
1647 * parameter(no_name)here. XXX: this is only needed in DNE phase I, on Phase II,
1648 * the ENOENT failure should be able to be fixed by redo mechanism.
1650 static int mdd_unlink(const struct lu_env *env, struct md_object *pobj,
1651 struct md_object *cobj, const struct lu_name *lname,
1652 struct md_attr *ma, int no_name)
1654 const char *name = lname->ln_name;
1655 struct lu_attr *pattr = MDD_ENV_VAR(env, pattr);
1656 struct lu_attr *cattr = MDD_ENV_VAR(env, cattr);
1657 struct lu_attr *la = &mdd_env_info(env)->mti_la_for_fix;
1658 struct mdd_object *mdd_pobj = md2mdd_obj(pobj);
1659 struct mdd_object *mdd_cobj = NULL;
1660 struct mdd_device *mdd = mdo2mdd(pobj);
1661 struct thandle *handle;
1662 int rc, is_dir = 0, cl_flags = 0;
1665 /* let shutdown to start */
1666 CFS_FAIL_TIMEOUT(OBD_FAIL_TGT_REPLY_DATA_RACE, 1);
1668 /* cobj == NULL means only delete name entry */
1669 if (likely(cobj != NULL)) {
1670 mdd_cobj = md2mdd_obj(cobj);
1671 if (mdd_object_exists(mdd_cobj) == 0)
1675 rc = mdd_la_get(env, mdd_pobj, pattr);
1679 if (likely(mdd_cobj != NULL)) {
1681 rc = mdd_la_get(env, mdd_cobj, cattr);
1685 is_dir = S_ISDIR(cattr->la_mode);
1686 /* search for an existing archive.
1687 * we should check ahead as the object
1688 * can be destroyed in this transaction */
1689 if (mdd_hsm_archive_exists(env, mdd_cobj, ma))
1690 cl_flags |= CLF_UNLINK_HSM_EXISTS;
1693 rc = mdd_unlink_sanity_check(env, mdd_pobj, pattr, mdd_cobj, cattr);
1697 handle = mdd_trans_create(env, mdd);
1699 RETURN(PTR_ERR(handle));
1701 rc = mdd_declare_unlink(env, mdd, mdd_pobj, mdd_cobj,
1702 lname, ma, handle, no_name, is_dir);
1706 rc = mdd_trans_start(env, mdd, handle);
1710 if (likely(mdd_cobj != NULL))
1711 mdd_write_lock(env, mdd_cobj, MOR_TGT_CHILD);
1713 if (likely(no_name == 0) && !OBD_FAIL_CHECK(OBD_FAIL_LFSCK_DANGLING2)) {
1714 rc = __mdd_index_delete(env, mdd_pobj, name, is_dir, handle);
1719 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_MUL_REF) ||
1720 OBD_FAIL_CHECK(OBD_FAIL_LFSCK_NO_NAMEENTRY))
1721 GOTO(cleanup, rc = 0);
1723 if (likely(mdd_cobj != NULL)) {
1724 rc = mdo_ref_del(env, mdd_cobj, handle);
1726 __mdd_index_insert_only(env, mdd_pobj,
1728 mdd_object_type(mdd_cobj),
1735 mdo_ref_del(env, mdd_cobj, handle);
1737 /* fetch updated nlink */
1738 rc = mdd_la_get(env, mdd_cobj, cattr);
1743 LASSERT(ma->ma_attr.la_valid & LA_CTIME);
1744 la->la_ctime = la->la_mtime = ma->ma_attr.la_ctime;
1746 la->la_valid = LA_CTIME | LA_MTIME;
1747 rc = mdd_update_time(env, mdd_pobj, pattr, la, handle);
1751 /* Enough for only unlink the entry */
1752 if (unlikely(mdd_cobj == NULL))
1755 if (cattr->la_nlink > 0 || mdd_cobj->mod_count > 0) {
1756 /* update ctime of an unlinked file only if it is still
1757 * opened or a link still exists */
1758 la->la_valid = LA_CTIME;
1759 rc = mdd_update_time(env, mdd_cobj, cattr, la, handle);
1764 /* XXX: this transfer to ma will be removed with LOD/OSP */
1765 ma->ma_attr = *cattr;
1766 ma->ma_valid |= MA_INODE;
1767 rc = mdd_finish_unlink(env, mdd_cobj, ma, mdd_pobj, lname, handle);
1771 /* fetch updated nlink */
1772 rc = mdd_la_get(env, mdd_cobj, cattr);
1773 /* if object is removed then we can't get its attrs,
1775 if (rc == -ENOENT) {
1776 cattr->la_nlink = 0;
1780 if (cattr->la_nlink == 0) {
1781 ma->ma_attr = *cattr;
1782 ma->ma_valid |= MA_INODE;
1787 if (likely(mdd_cobj != NULL))
1788 mdd_write_unlock(env, mdd_cobj);
1791 if (cattr->la_nlink == 0)
1792 cl_flags |= CLF_UNLINK_LAST;
1794 cl_flags &= ~CLF_UNLINK_HSM_EXISTS;
1796 rc = mdd_changelog_ns_store(env, mdd,
1797 is_dir ? CL_RMDIR : CL_UNLINK, cl_flags,
1798 mdd_cobj, mdo2fid(mdd_pobj), NULL, NULL, lname, NULL,
1803 rc = mdd_trans_stop(env, mdd, rc, handle);
1809 * The permission has been checked when obj created, no need check again.
1811 static int mdd_cd_sanity_check(const struct lu_env *env,
1812 struct mdd_object *obj)
1817 if (!obj || mdd_is_dead_obj(obj))
1823 static int mdd_create_data(const struct lu_env *env,
1824 struct md_object *pobj,
1825 struct md_object *cobj,
1826 const struct md_op_spec *spec,
1829 struct mdd_device *mdd = mdo2mdd(cobj);
1830 struct mdd_object *mdd_pobj = md2mdd_obj(pobj);
1831 struct mdd_object *son = md2mdd_obj(cobj);
1832 struct thandle *handle;
1833 const struct lu_buf *buf;
1834 struct lu_attr *attr = MDD_ENV_VAR(env, cattr);
1835 struct dt_allocation_hint *hint = &mdd_env_info(env)->mti_hint;
1839 rc = mdd_cd_sanity_check(env, son);
1843 if (!md_should_create(spec->sp_cr_flags))
1847 * there are following use cases for this function:
1848 * 1) late striping - file was created with MDS_OPEN_DELAY_CREATE
1849 * striping can be specified or not
1852 rc = mdd_la_get(env, son, attr);
1856 /* calling ->ah_make_hint() is used to transfer information from parent */
1857 mdd_object_make_hint(env, mdd_pobj, son, attr, spec, hint);
1859 handle = mdd_trans_create(env, mdd);
1861 GOTO(out_free, rc = PTR_ERR(handle));
1864 * XXX: Setting the lov ea is not locked but setting the attr is locked?
1865 * Should this be fixed?
1867 CDEBUG(D_OTHER, "ea %p/%u, cr_flags %#llo, no_create %u\n",
1868 spec->u.sp_ea.eadata, spec->u.sp_ea.eadatalen,
1869 spec->sp_cr_flags, spec->no_create);
1871 if (spec->no_create || (spec->sp_cr_flags & MDS_OPEN_HAS_EA)) {
1872 buf = mdd_buf_get_const(env, spec->u.sp_ea.eadata,
1873 spec->u.sp_ea.eadatalen);
1878 rc = dt_declare_xattr_set(env, mdd_object_child(son), buf,
1879 XATTR_NAME_LOV, 0, handle);
1883 rc = mdd_declare_changelog_store(env, mdd, CL_LAYOUT, NULL, NULL,
1888 rc = mdd_trans_start(env, mdd, handle);
1892 rc = dt_xattr_set(env, mdd_object_child(son), buf, XATTR_NAME_LOV,
1898 rc = mdd_changelog_data_store(env, mdd, CL_LAYOUT, 0, son, handle);
1901 rc = mdd_trans_stop(env, mdd, rc, handle);
1907 static int mdd_declare_object_initialize(const struct lu_env *env,
1908 struct mdd_object *parent,
1909 struct mdd_object *child,
1910 const struct lu_attr *attr,
1911 struct thandle *handle)
1916 LASSERT(attr->la_valid & (LA_MODE | LA_TYPE));
1917 if (!S_ISDIR(attr->la_mode))
1920 rc = mdo_declare_index_insert(env, child, mdo2fid(child), S_IFDIR,
1925 rc = mdo_declare_ref_add(env, child, handle);
1929 rc = mdo_declare_index_insert(env, child, mdo2fid(parent), S_IFDIR,
1935 static int mdd_object_initialize(const struct lu_env *env,
1936 const struct lu_fid *pfid,
1937 struct mdd_object *child,
1938 struct lu_attr *attr,
1939 struct thandle *handle)
1944 if (S_ISDIR(attr->la_mode)) {
1945 /* Add "." and ".." for newly created dir */
1946 mdo_ref_add(env, child, handle);
1947 rc = __mdd_index_insert_only(env, child, mdo2fid(child),
1948 S_IFDIR, dot, handle);
1950 rc = __mdd_index_insert_only(env, child, pfid, S_IFDIR,
1953 mdo_ref_del(env, child, handle);
1960 * This function checks whether it can create a file/dir under the
1961 * directory(@pobj). The directory(@pobj) is not being locked by
1964 * \param[in] env execution environment
1965 * \param[in] pobj the directory to create files
1966 * \param[in] pattr the attributes of the directory
1967 * \param[in] lname the name of the created file/dir
1968 * \param[in] cattr the attributes of the file/dir
1969 * \param[in] spec create specification
1971 * \retval = 0 it is allowed to create file/dir under
1973 * \retval negative error not allowed to create file/dir
1974 * under the directory
1976 static int mdd_create_sanity_check(const struct lu_env *env,
1977 struct md_object *pobj,
1978 const struct lu_attr *pattr,
1979 const struct lu_name *lname,
1980 struct lu_attr *cattr,
1981 struct md_op_spec *spec)
1983 struct mdd_thread_info *info = mdd_env_info(env);
1984 struct lu_fid *fid = &info->mti_fid;
1985 struct mdd_object *obj = md2mdd_obj(pobj);
1986 struct mdd_device *m = mdo2mdd(pobj);
1987 bool check_perm = true;
1992 if (mdd_is_dead_obj(obj))
1996 * In some cases this lookup is not needed - we know before if name
1997 * exists or not because MDT performs lookup for it.
1998 * name length check is done in lookup.
2000 if (spec->sp_cr_lookup) {
2002 * Check if the name already exist, though it will be checked in
2003 * _index_insert also, for avoiding rolling back if exists
2006 rc = __mdd_lookup(env, pobj, pattr, lname, fid,
2007 MAY_WRITE | MAY_EXEC);
2009 RETURN(rc ? : -EEXIST);
2011 /* Permission is already being checked in mdd_lookup */
2015 if (S_ISDIR(cattr->la_mode) &&
2016 unlikely(spec != NULL && spec->sp_cr_flags & MDS_OPEN_HAS_EA) &&
2017 spec->u.sp_ea.eadata != NULL && spec->u.sp_ea.eadatalen > 0) {
2018 const struct lmv_user_md *lum = spec->u.sp_ea.eadata;
2020 if (le32_to_cpu(lum->lum_magic) != LMV_USER_MAGIC &&
2021 le32_to_cpu(lum->lum_magic) != LMV_USER_MAGIC_SPECIFIC &&
2022 le32_to_cpu(lum->lum_magic) != LMV_USER_MAGIC_V0) {
2024 CERROR("%s: invalid lmv_user_md: magic = %x, "
2025 "stripe_offset = %d, stripe_count = %u: "
2026 "rc = %d\n", mdd2obd_dev(m)->obd_name,
2027 le32_to_cpu(lum->lum_magic),
2028 (int)le32_to_cpu(lum->lum_stripe_offset),
2029 le32_to_cpu(lum->lum_stripe_count), rc);
2034 rc = mdd_may_create(env, obj, pattr, NULL, check_perm);
2039 if (pattr->la_mode & S_ISGID) {
2040 cattr->la_gid = pattr->la_gid;
2041 if (S_ISDIR(cattr->la_mode)) {
2042 cattr->la_mode |= S_ISGID;
2043 cattr->la_valid |= LA_MODE;
2047 /* Inherit project ID from parent directory */
2048 if (pattr->la_flags & LUSTRE_PROJINHERIT_FL) {
2049 cattr->la_projid = pattr->la_projid;
2050 if (S_ISDIR(cattr->la_mode)) {
2051 cattr->la_flags |= LUSTRE_PROJINHERIT_FL;
2052 cattr->la_valid |= LA_FLAGS;
2054 cattr->la_valid |= LA_PROJID;
2057 rc = mdd_name_check(m, lname);
2061 switch (cattr->la_mode & S_IFMT) {
2063 unsigned int symlen = strlen(spec->u.sp_symname) + 1;
2065 if (symlen > m->mdd_dt_conf.ddp_symlink_max)
2066 RETURN(-ENAMETOOLONG);
2085 static int mdd_declare_create_object(const struct lu_env *env,
2086 struct mdd_device *mdd,
2087 struct mdd_object *p, struct mdd_object *c,
2088 struct lu_attr *attr,
2089 struct thandle *handle,
2090 const struct md_op_spec *spec,
2091 struct lu_buf *def_acl_buf,
2092 struct lu_buf *acl_buf,
2093 struct dt_allocation_hint *hint)
2095 const struct lu_buf *buf;
2098 rc = mdd_declare_create_object_internal(env, p, c, attr, handle, spec,
2103 #ifdef CONFIG_FS_POSIX_ACL
2104 if (def_acl_buf && def_acl_buf->lb_len > 0 && S_ISDIR(attr->la_mode)) {
2105 /* if dir, then can inherit default ACl */
2106 rc = mdo_declare_xattr_set(env, c, def_acl_buf,
2107 XATTR_NAME_ACL_DEFAULT,
2113 if (acl_buf && acl_buf->lb_len > 0) {
2114 rc = mdo_declare_attr_set(env, c, attr, handle);
2118 rc = mdo_declare_xattr_set(env, c, acl_buf,
2119 XATTR_NAME_ACL_ACCESS, 0, handle);
2124 rc = mdd_declare_object_initialize(env, p, c, attr, handle);
2128 /* replay case, create LOV EA from client data */
2129 if ((!(spec->sp_cr_flags & MDS_OPEN_DELAY_CREATE) && spec->no_create) ||
2130 (spec->sp_cr_flags & MDS_OPEN_HAS_EA && S_ISREG(attr->la_mode))) {
2131 buf = mdd_buf_get_const(env, spec->u.sp_ea.eadata,
2132 spec->u.sp_ea.eadatalen);
2133 rc = mdo_declare_xattr_set(env, c, buf,
2134 S_ISDIR(attr->la_mode) ?
2135 XATTR_NAME_LMV : XATTR_NAME_LOV,
2141 if (S_ISLNK(attr->la_mode)) {
2142 const char *target_name = spec->u.sp_symname;
2143 int sym_len = strlen(target_name);
2144 const struct lu_buf *buf;
2146 buf = mdd_buf_get_const(env, target_name, sym_len);
2147 rc = dt_declare_record_write(env, mdd_object_child(c),
2153 if (spec->sp_cr_file_secctx_name != NULL) {
2154 buf = mdd_buf_get_const(env, spec->sp_cr_file_secctx,
2155 spec->sp_cr_file_secctx_size);
2156 rc = mdo_declare_xattr_set(env, c, buf,
2157 spec->sp_cr_file_secctx_name, 0,
2166 static int mdd_declare_create(const struct lu_env *env, struct mdd_device *mdd,
2167 struct mdd_object *p, struct mdd_object *c,
2168 const struct lu_name *name,
2169 struct lu_attr *attr,
2170 struct thandle *handle,
2171 const struct md_op_spec *spec,
2172 struct linkea_data *ldata,
2173 struct lu_buf *def_acl_buf,
2174 struct lu_buf *acl_buf,
2175 struct dt_allocation_hint *hint)
2179 rc = mdd_declare_create_object(env, mdd, p, c, attr, handle, spec,
2180 def_acl_buf, acl_buf, hint);
2184 if (S_ISDIR(attr->la_mode)) {
2185 rc = mdo_declare_ref_add(env, p, handle);
2190 if (unlikely(spec->sp_cr_flags & MDS_OPEN_VOLATILE)) {
2191 rc = mdd_orphan_declare_insert(env, c, attr->la_mode, handle);
2195 struct lu_attr *la = &mdd_env_info(env)->mti_la_for_fix;
2196 enum changelog_rec_type type;
2198 rc = mdo_declare_index_insert(env, p, mdo2fid(c), attr->la_mode,
2199 name->ln_name, handle);
2203 rc = mdd_declare_links_add(env, c, handle, ldata);
2208 la->la_valid = LA_CTIME | LA_MTIME;
2209 rc = mdo_declare_attr_set(env, p, la, handle);
2213 type = S_ISDIR(attr->la_mode) ? CL_MKDIR :
2214 S_ISREG(attr->la_mode) ? CL_CREATE :
2215 S_ISLNK(attr->la_mode) ? CL_SOFTLINK : CL_MKNOD;
2217 rc = mdd_declare_changelog_store(env, mdd, type, name, NULL,
2226 static int mdd_acl_init(const struct lu_env *env, struct mdd_object *pobj,
2227 struct lu_attr *la, struct lu_buf *def_acl_buf,
2228 struct lu_buf *acl_buf)
2233 if (S_ISLNK(la->la_mode)) {
2234 acl_buf->lb_len = 0;
2235 def_acl_buf->lb_len = 0;
2239 mdd_read_lock(env, pobj, MOR_TGT_PARENT);
2240 rc = mdo_xattr_get(env, pobj, def_acl_buf,
2241 XATTR_NAME_ACL_DEFAULT);
2242 mdd_read_unlock(env, pobj);
2244 /* If there are default ACL, fix mode/ACL by default ACL */
2245 def_acl_buf->lb_len = rc;
2246 LASSERT(def_acl_buf->lb_len <= acl_buf->lb_len);
2247 memcpy(acl_buf->lb_buf, def_acl_buf->lb_buf, rc);
2248 acl_buf->lb_len = rc;
2249 rc = __mdd_fix_mode_acl(env, acl_buf, &la->la_mode);
2252 } else if (rc == -ENODATA || rc == -EOPNOTSUPP) {
2253 /* If there are no default ACL, fix mode by mask */
2254 struct lu_ucred *uc = lu_ucred(env);
2256 /* The create triggered by MDT internal events, such as
2257 * LFSCK reset, will not contain valid "uc". */
2258 if (unlikely(uc != NULL))
2259 la->la_mode &= ~uc->uc_umask;
2261 acl_buf->lb_len = 0;
2262 def_acl_buf->lb_len = 0;
2269 * Create a metadata object and initialize it, set acl, xattr.
2271 static int mdd_create_object(const struct lu_env *env, struct mdd_object *pobj,
2272 struct mdd_object *son, struct lu_attr *attr,
2273 struct md_op_spec *spec, struct lu_buf *acl_buf,
2274 struct lu_buf *def_acl_buf,
2275 struct dt_allocation_hint *hint,
2276 struct thandle *handle)
2278 const struct lu_buf *buf;
2281 mdd_write_lock(env, son, MOR_TGT_CHILD);
2282 rc = mdd_create_object_internal(env, NULL, son, attr, handle, spec,
2287 /* Note: In DNE phase I, for striped dir, though sub-stripes will be
2288 * created in declare phase, they also needs to be added to master
2289 * object as sub-directory entry. So it has to initialize the master
2290 * object, then set dir striped EA.(in mdo_xattr_set) */
2291 rc = mdd_object_initialize(env, mdo2fid(pobj), son, attr, handle);
2293 GOTO(err_destroy, rc);
2296 * in case of replay we just set LOVEA provided by the client
2297 * XXX: I think it would be interesting to try "old" way where
2298 * MDT calls this xattr_set(LOV) in a different transaction.
2299 * probably this way we code can be made better.
2302 /* During creation, there are only a few cases we need do xattr_set to
2304 * 1. regular file: see comments above.
2305 * 2. dir: inherit default striping or pool settings from parent.
2306 * 3. create striped directory with provided stripeEA.
2307 * 4. create striped directory because inherit default layout from the
2310 if (spec->no_create ||
2311 (S_ISREG(attr->la_mode) && spec->sp_cr_flags & MDS_OPEN_HAS_EA) ||
2312 S_ISDIR(attr->la_mode)) {
2313 buf = mdd_buf_get_const(env, spec->u.sp_ea.eadata,
2314 spec->u.sp_ea.eadatalen);
2315 rc = mdo_xattr_set(env, son, buf,
2316 S_ISDIR(attr->la_mode) ? XATTR_NAME_LMV :
2320 GOTO(err_destroy, rc);
2323 #ifdef CONFIG_FS_POSIX_ACL
2324 if (def_acl_buf != NULL && def_acl_buf->lb_len > 0 &&
2325 S_ISDIR(attr->la_mode)) {
2326 /* set default acl */
2327 rc = mdo_xattr_set(env, son, def_acl_buf,
2328 XATTR_NAME_ACL_DEFAULT, 0,
2331 GOTO(err_destroy, rc);
2333 /* set its own acl */
2334 if (acl_buf != NULL && acl_buf->lb_len > 0) {
2335 rc = mdo_xattr_set(env, son, acl_buf,
2336 XATTR_NAME_ACL_ACCESS,
2339 GOTO(err_destroy, rc);
2343 if (S_ISLNK(attr->la_mode)) {
2344 struct dt_object *dt = mdd_object_child(son);
2345 const char *target_name = spec->u.sp_symname;
2346 int sym_len = strlen(target_name);
2349 buf = mdd_buf_get_const(env, target_name, sym_len);
2350 rc = dt->do_body_ops->dbo_write(env, dt, buf, &pos, handle);
2354 GOTO(err_initlized, rc = -EFAULT);
2357 if (spec->sp_cr_file_secctx_name != NULL) {
2358 buf = mdd_buf_get_const(env, spec->sp_cr_file_secctx,
2359 spec->sp_cr_file_secctx_size);
2360 rc = mdo_xattr_set(env, son, buf, spec->sp_cr_file_secctx_name,
2363 GOTO(err_initlized, rc);
2367 if (unlikely(rc != 0)) {
2369 if (S_ISDIR(attr->la_mode)) {
2370 /* Drop the reference, no need to delete "."/"..",
2371 * because the object to be destroied directly. */
2372 rc2 = mdo_ref_del(env, son, handle);
2376 rc2 = mdo_ref_del(env, son, handle);
2380 mdo_destroy(env, son, handle);
2383 mdd_write_unlock(env, son);
2387 static int mdd_index_delete(const struct lu_env *env,
2388 struct mdd_object *mdd_pobj,
2389 struct lu_attr *cattr,
2390 const struct lu_name *lname)
2392 struct mdd_device *mdd = mdo2mdd(&mdd_pobj->mod_obj);
2393 struct thandle *handle;
2397 handle = mdd_trans_create(env, mdd);
2399 RETURN(PTR_ERR(handle));
2401 rc = mdo_declare_index_delete(env, mdd_pobj, lname->ln_name,
2406 if (S_ISDIR(cattr->la_mode)) {
2407 rc = mdo_declare_ref_del(env, mdd_pobj, handle);
2412 /* Since this will only be used in the error handler path,
2413 * Let's set the thandle to be local and not mess the transno */
2414 handle->th_local = 1;
2415 rc = mdd_trans_start(env, mdd, handle);
2419 rc = __mdd_index_delete(env, mdd_pobj, lname->ln_name,
2420 S_ISDIR(cattr->la_mode), handle);
2424 rc = mdd_trans_stop(env, mdd, rc, handle);
2430 * Create object and insert it into namespace.
2432 * Two operations have to be performed:
2434 * - an allocation of a new object (->do_create()), and
2435 * - an insertion into a parent index (->dio_insert()).
2437 * Due to locking, operation order is not important, when both are
2438 * successful, *but* error handling cases are quite different:
2440 * - if insertion is done first, and following object creation fails,
2441 * insertion has to be rolled back, but this operation might fail
2442 * also leaving us with dangling index entry.
2444 * - if creation is done first, is has to be undone if insertion fails,
2445 * leaving us with leaked space, which is not good but not fatal.
2447 * It seems that creation-first is simplest solution, but it is sub-optimal
2453 * case, because second mkdir is bound to create object, only to
2454 * destroy it immediately.
2456 * To avoid this follow local file systems that do double lookup:
2458 * 0. lookup -> -EEXIST (mdd_create_sanity_check())
2459 * 1. create (mdd_create_object_internal())
2460 * 2. insert (__mdd_index_insert(), lookup again)
2462 * \param[in] pobj parent object
2463 * \param[in] lname name of child being created
2464 * \param[in,out] child child object being created
2465 * \param[in] spec additional create parameters
2466 * \param[in] ma attributes for new child object
2468 * \retval 0 on success
2469 * \retval negative errno on failure
2471 static int mdd_create(const struct lu_env *env, struct md_object *pobj,
2472 const struct lu_name *lname, struct md_object *child,
2473 struct md_op_spec *spec, struct md_attr *ma)
2475 struct mdd_thread_info *info = mdd_env_info(env);
2476 struct lu_attr *la = &info->mti_la_for_fix;
2477 struct mdd_object *mdd_pobj = md2mdd_obj(pobj);
2478 struct mdd_object *son = md2mdd_obj(child);
2479 struct mdd_device *mdd = mdo2mdd(pobj);
2480 struct lu_attr *attr = &ma->ma_attr;
2481 struct thandle *handle;
2482 struct lu_attr *pattr = &info->mti_pattr;
2483 struct lu_buf acl_buf;
2484 struct lu_buf def_acl_buf;
2485 struct linkea_data *ldata = &info->mti_link_data;
2486 const char *name = lname->ln_name;
2487 struct dt_allocation_hint *hint = &mdd_env_info(env)->mti_hint;
2492 rc = mdd_la_get(env, mdd_pobj, pattr);
2496 /* Sanity checks before big job. */
2497 rc = mdd_create_sanity_check(env, pobj, pattr, lname, attr, spec);
2501 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_DQACQ_NET))
2502 GOTO(out_free, rc = -EINPROGRESS);
2504 handle = mdd_trans_create(env, mdd);
2506 GOTO(out_free, rc = PTR_ERR(handle));
2508 lu_buf_check_and_alloc(&info->mti_xattr_buf,
2509 mdd->mdd_dt_conf.ddp_max_ea_size);
2510 acl_buf = info->mti_xattr_buf;
2511 def_acl_buf.lb_buf = info->mti_key;
2512 def_acl_buf.lb_len = sizeof(info->mti_key);
2513 rc = mdd_acl_init(env, mdd_pobj, attr, &def_acl_buf, &acl_buf);
2517 if (S_ISDIR(attr->la_mode)) {
2518 struct lmv_user_md *lmu = spec->u.sp_ea.eadata;
2521 * migrate may create 1-stripe directory, so lod_ah_init()
2522 * doesn't adjust stripe count from lmu.
2524 if (lmu && lmu->lum_stripe_count == cpu_to_le32(1)) {
2525 info->mti_lmu = *lmu;
2526 info->mti_lmu.lum_stripe_count = 0;
2527 spec->u.sp_ea.eadata = &info->mti_lmu;
2531 mdd_object_make_hint(env, mdd_pobj, son, attr, spec, hint);
2533 memset(ldata, 0, sizeof(*ldata));
2534 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_PARENT)) {
2535 struct lu_fid tfid = *mdd_object_fid(mdd_pobj);
2538 rc = mdd_linkea_prepare(env, son, NULL, NULL,
2539 &tfid, lname, 1, 0, ldata);
2541 rc = mdd_linkea_prepare(env, son, NULL, NULL,
2542 mdd_object_fid(mdd_pobj),
2543 lname, 1, 0, ldata);
2546 rc = mdd_declare_create(env, mdd, mdd_pobj, son, lname, attr,
2547 handle, spec, ldata, &def_acl_buf, &acl_buf,
2552 rc = mdd_trans_start(env, mdd, handle);
2556 rc = mdd_create_object(env, mdd_pobj, son, attr, spec, &acl_buf,
2557 &def_acl_buf, hint, handle);
2561 if (unlikely(spec->sp_cr_flags & MDS_OPEN_VOLATILE)) {
2562 mdd_write_lock(env, son, MOR_TGT_CHILD);
2563 son->mod_flags |= VOLATILE_OBJ;
2564 rc = mdd_orphan_insert(env, son, handle);
2565 GOTO(out_volatile, rc);
2567 rc = __mdd_index_insert(env, mdd_pobj, mdo2fid(son),
2568 attr->la_mode, name, handle);
2570 GOTO(err_created, rc);
2572 mdd_links_add(env, son, mdo2fid(mdd_pobj), lname, handle,
2575 /* update parent directory mtime/ctime */
2577 la->la_valid = LA_CTIME | LA_MTIME;
2578 rc = mdd_update_time(env, mdd_pobj, pattr, la, handle);
2580 GOTO(err_insert, rc);
2586 if (spec->sp_cr_flags & MDS_OPEN_VOLATILE)
2587 rc2 = mdd_orphan_delete(env, son, handle);
2589 rc2 = __mdd_index_delete(env, mdd_pobj, name,
2590 S_ISDIR(attr->la_mode),
2596 mdd_write_lock(env, son, MOR_TGT_CHILD);
2597 if (S_ISDIR(attr->la_mode)) {
2598 /* Drop the reference, no need to delete "."/"..",
2599 * because the object is to be destroyed directly. */
2600 rc2 = mdo_ref_del(env, son, handle);
2602 mdd_write_unlock(env, son);
2607 /* For volatile files drop one link immediately, since there is
2608 * no filename in the namespace, and save any error returned. */
2609 rc2 = mdo_ref_del(env, son, handle);
2611 mdd_write_unlock(env, son);
2612 if (unlikely(rc == 0))
2617 /* Don't destroy the volatile object on success */
2618 if (likely(rc != 0))
2619 mdo_destroy(env, son, handle);
2620 mdd_write_unlock(env, son);
2623 if (rc == 0 && fid_is_namespace_visible(mdo2fid(son)) &&
2624 likely((spec->sp_cr_flags & MDS_OPEN_VOLATILE) == 0))
2625 rc = mdd_changelog_ns_store(env, mdd,
2626 S_ISDIR(attr->la_mode) ? CL_MKDIR :
2627 S_ISREG(attr->la_mode) ? CL_CREATE :
2628 S_ISLNK(attr->la_mode) ? CL_SOFTLINK : CL_MKNOD,
2629 0, son, mdo2fid(mdd_pobj), NULL, NULL, lname,
2632 rc2 = mdd_trans_stop(env, mdd, rc, handle);
2634 /* If creation fails, it is most likely due to the remote update
2635 * failure, because local transaction will mostly succeed at
2636 * this stage. There is no easy way to rollback all of previous
2637 * updates, so let's remove the object from namespace, and
2638 * LFSCK should handle the orphan object. */
2639 if (rc2 < 0 && !mdd_object_remote(mdd_pobj))
2640 mdd_index_delete(env, mdd_pobj, attr, lname);
2644 if (is_vmalloc_addr(ldata->ld_buf))
2645 /* if we vmalloced a large buffer drop it */
2646 lu_buf_free(ldata->ld_buf);
2648 /* The child object shouldn't be cached anymore */
2650 set_bit(LU_OBJECT_HEARD_BANSHEE,
2651 &child->mo_lu.lo_header->loh_flags);
2656 * Get locks on parents in proper order
2657 * RETURN: < 0 - error, rename_order if successful
2665 static int mdd_rename_order(const struct lu_env *env,
2666 struct mdd_device *mdd,
2667 struct mdd_object *src_pobj,
2668 const struct lu_attr *pattr,
2669 struct mdd_object *tgt_pobj)
2671 /* order of locking, 1 - tgt-src, 0 - src-tgt*/
2675 if (src_pobj == tgt_pobj)
2676 RETURN(MDD_RN_SAME);
2678 /* compared the parent child relationship of src_p&tgt_p */
2679 if (lu_fid_eq(&mdd->mdd_root_fid, mdo2fid(src_pobj))){
2681 } else if (lu_fid_eq(&mdd->mdd_root_fid, mdo2fid(tgt_pobj))) {
2684 rc = mdd_is_parent(env, mdd, src_pobj, pattr,
2698 /* has not mdd_write{read}_lock on any obj yet. */
2699 static int mdd_rename_sanity_check(const struct lu_env *env,
2700 struct mdd_object *src_pobj,
2701 const struct lu_attr *pattr,
2702 struct mdd_object *tgt_pobj,
2703 const struct lu_attr *tpattr,
2704 struct mdd_object *sobj,
2705 const struct lu_attr *cattr,
2706 struct mdd_object *tobj,
2707 const struct lu_attr *tattr)
2712 /* XXX: when get here, sobj must NOT be NULL,
2713 * the other case has been processed in cld_rename
2714 * before mdd_rename and enable MDS_PERM_BYPASS. */
2718 * If we are using project inheritance, we only allow renames
2719 * into our tree when the project IDs are the same; otherwise
2720 * tree quota mechanism would be circumvented.
2722 if (((tpattr->la_flags & LUSTRE_PROJINHERIT_FL) &&
2723 tpattr->la_projid != cattr->la_projid) ||
2724 ((pattr->la_flags & LUSTRE_PROJINHERIT_FL) &&
2725 (pattr->la_projid != tpattr->la_projid)))
2728 rc = mdd_may_delete(env, src_pobj, pattr, sobj, cattr, NULL, 1, 0);
2732 /* XXX: when get here, "tobj == NULL" means tobj must
2733 * NOT exist (neither on remote MDS, such case has been
2734 * processed in cld_rename before mdd_rename and enable
2736 * So check may_create, but not check may_unlink. */
2738 rc = mdd_may_create(env, tgt_pobj, tpattr, NULL,
2739 (src_pobj != tgt_pobj));
2741 rc = mdd_may_delete(env, tgt_pobj, tpattr, tobj, tattr, cattr,
2742 (src_pobj != tgt_pobj), 1);
2744 if (!rc && !tobj && (src_pobj != tgt_pobj) && S_ISDIR(cattr->la_mode))
2745 rc = __mdd_may_link(env, tgt_pobj, tpattr);
2750 static int mdd_declare_rename(const struct lu_env *env,
2751 struct mdd_device *mdd,
2752 struct mdd_object *mdd_spobj,
2753 struct mdd_object *mdd_tpobj,
2754 struct mdd_object *mdd_sobj,
2755 struct mdd_object *mdd_tobj,
2756 const struct lu_name *sname,
2757 const struct lu_name *tname,
2759 struct linkea_data *ldata,
2760 struct thandle *handle)
2762 struct lu_attr *la = &mdd_env_info(env)->mti_la_for_fix;
2765 LASSERT(ma->ma_attr.la_valid & LA_CTIME);
2766 la->la_ctime = la->la_mtime = ma->ma_attr.la_ctime;
2772 /* name from source dir */
2773 rc = mdo_declare_index_delete(env, mdd_spobj, sname->ln_name, handle);
2777 /* .. from source child */
2778 if (S_ISDIR(mdd_object_type(mdd_sobj))) {
2779 /* source child can be directory,
2780 * counted by source dir's nlink */
2781 rc = mdo_declare_ref_del(env, mdd_spobj, handle);
2784 if (mdd_spobj != mdd_tpobj) {
2785 rc = mdo_declare_index_delete(env, mdd_sobj, dotdot,
2790 rc = mdo_declare_index_insert(env, mdd_sobj,
2792 S_IFDIR, dotdot, handle);
2797 /* new target child can be directory,
2798 * counted by target dir's nlink */
2799 rc = mdo_declare_ref_add(env, mdd_tpobj, handle);
2804 la->la_valid = LA_CTIME | LA_MTIME;
2805 rc = mdo_declare_attr_set(env, mdd_spobj, la, handle);
2809 rc = mdo_declare_attr_set(env, mdd_tpobj, la, handle);
2813 la->la_valid = LA_CTIME;
2814 rc = mdo_declare_attr_set(env, mdd_sobj, la, handle);
2818 rc = mdd_declare_links_add(env, mdd_sobj, handle, ldata);
2823 rc = mdo_declare_index_insert(env, mdd_tpobj, mdo2fid(mdd_sobj),
2824 mdd_object_type(mdd_sobj),
2825 tname->ln_name, handle);
2829 if (mdd_tobj && mdd_object_exists(mdd_tobj)) {
2830 /* delete target child in target parent directory */
2831 rc = mdo_declare_index_delete(env, mdd_tpobj, tname->ln_name,
2836 rc = mdo_declare_ref_del(env, mdd_tobj, handle);
2840 if (S_ISDIR(mdd_object_type(mdd_tobj))) {
2841 /* target child can be directory,
2842 * delete "." reference in target child directory */
2843 rc = mdo_declare_ref_del(env, mdd_tobj, handle);
2847 /* delete ".." reference in target parent directory */
2848 rc = mdo_declare_ref_del(env, mdd_tpobj, handle);
2853 la->la_valid = LA_CTIME;
2854 rc = mdo_declare_attr_set(env, mdd_tobj, la, handle);
2858 rc = mdd_declare_finish_unlink(env, mdd_tobj, handle);
2863 rc = mdd_declare_changelog_store(env, mdd, CL_RENAME, tname, sname,
2871 /* src object can be remote that is why we use only fid and type of object */
2872 static int mdd_rename(const struct lu_env *env,
2873 struct md_object *src_pobj, struct md_object *tgt_pobj,
2874 const struct lu_fid *lf, const struct lu_name *lsname,
2875 struct md_object *tobj, const struct lu_name *ltname,
2878 const char *sname = lsname->ln_name;
2879 const char *tname = ltname->ln_name;
2880 struct lu_attr *la = &mdd_env_info(env)->mti_la_for_fix;
2881 struct mdd_object *mdd_spobj = md2mdd_obj(src_pobj); /* source parent */
2882 struct mdd_object *mdd_tpobj = md2mdd_obj(tgt_pobj);
2883 struct mdd_device *mdd = mdo2mdd(src_pobj);
2884 struct mdd_object *mdd_sobj = NULL; /* source object */
2885 struct mdd_object *mdd_tobj = NULL;
2886 struct lu_attr *cattr = MDD_ENV_VAR(env, cattr);
2887 struct lu_attr *pattr = MDD_ENV_VAR(env, pattr);
2888 struct lu_attr *tattr = MDD_ENV_VAR(env, tattr);
2889 struct lu_attr *tpattr = MDD_ENV_VAR(env, tpattr);
2890 struct thandle *handle;
2891 struct linkea_data *ldata = &mdd_env_info(env)->mti_link_data;
2892 const struct lu_fid *tpobj_fid = mdo2fid(mdd_tpobj);
2893 const struct lu_fid *spobj_fid = mdo2fid(mdd_spobj);
2896 bool tobj_locked = 0;
2897 unsigned cl_flags = 0;
2901 /* let unlink to complete and commit */
2902 CFS_FAIL_TIMEOUT(OBD_FAIL_TGT_REPLY_DATA_RACE, 2 + cfs_fail_val);
2905 mdd_tobj = md2mdd_obj(tobj);
2907 mdd_sobj = mdd_object_find(env, mdd, lf);
2908 if (IS_ERR(mdd_sobj))
2909 RETURN(PTR_ERR(mdd_sobj));
2911 rc = mdd_la_get(env, mdd_sobj, cattr);
2913 GOTO(out_pending, rc);
2915 rc = mdd_la_get(env, mdd_spobj, pattr);
2917 GOTO(out_pending, rc);
2920 rc = mdd_la_get(env, mdd_tobj, tattr);
2922 GOTO(out_pending, rc);
2923 /* search for an existing archive.
2924 * we should check ahead as the object
2925 * can be destroyed in this transaction */
2926 if (mdd_hsm_archive_exists(env, mdd_tobj, ma))
2927 cl_flags |= CLF_RENAME_LAST_EXISTS;
2930 rc = mdd_la_get(env, mdd_tpobj, tpattr);
2932 GOTO(out_pending, rc);
2934 rc = mdd_rename_sanity_check(env, mdd_spobj, pattr, mdd_tpobj, tpattr,
2935 mdd_sobj, cattr, mdd_tobj, tattr);
2937 GOTO(out_pending, rc);
2939 rc = mdd_name_check(mdd, ltname);
2941 GOTO(out_pending, rc);
2943 /* FIXME: Should consider tobj and sobj too in rename_lock. */
2944 rc = mdd_rename_order(env, mdd, mdd_spobj, pattr, mdd_tpobj);
2946 GOTO(out_pending, rc);
2948 handle = mdd_trans_create(env, mdd);
2950 GOTO(out_pending, rc = PTR_ERR(handle));
2952 memset(ldata, 0, sizeof(*ldata));
2953 rc = mdd_linkea_prepare(env, mdd_sobj, mdd_object_fid(mdd_spobj),
2954 lsname, mdd_object_fid(mdd_tpobj), ltname,
2959 rc = mdd_declare_rename(env, mdd, mdd_spobj, mdd_tpobj, mdd_sobj,
2960 mdd_tobj, lsname, ltname, ma, ldata, handle);
2964 rc = mdd_trans_start(env, mdd, handle);
2968 is_dir = S_ISDIR(cattr->la_mode);
2970 /* Remove source name from source directory */
2971 rc = __mdd_index_delete(env, mdd_spobj, sname, is_dir, handle);
2975 /* "mv dir1 dir2" needs "dir1/.." link update */
2976 if (is_dir && !lu_fid_eq(spobj_fid, tpobj_fid)) {
2977 rc = __mdd_index_delete_only(env, mdd_sobj, dotdot, handle);
2979 GOTO(fixup_spobj2, rc);
2981 rc = __mdd_index_insert_only(env, mdd_sobj, tpobj_fid, S_IFDIR,
2984 GOTO(fixup_spobj, rc);
2987 if (mdd_tobj != NULL && mdd_object_exists(mdd_tobj)) {
2988 rc = __mdd_index_delete(env, mdd_tpobj, tname, is_dir, handle);
2990 /* tname might been renamed to something else */
2991 GOTO(fixup_spobj, rc);
2994 /* Insert new fid with target name into target dir */
2995 rc = __mdd_index_insert(env, mdd_tpobj, lf, cattr->la_mode,
2998 GOTO(fixup_tpobj, rc);
3000 LASSERT(ma->ma_attr.la_valid & LA_CTIME);
3001 la->la_ctime = la->la_mtime = ma->ma_attr.la_ctime;
3003 /* XXX: mdd_sobj must be local one if it is NOT NULL. */
3004 la->la_valid = LA_CTIME;
3005 rc = mdd_update_time(env, mdd_sobj, cattr, la, handle);
3007 GOTO(fixup_tpobj, rc);
3009 /* Update the linkEA for the source object */
3010 mdd_write_lock(env, mdd_sobj, MOR_SRC_CHILD);
3011 rc = mdd_links_rename(env, mdd_sobj, mdo2fid(mdd_spobj), lsname,
3012 mdo2fid(mdd_tpobj), ltname, handle, ldata,
3015 /* Old files might not have EA entry */
3016 mdd_links_add(env, mdd_sobj, mdo2fid(mdd_spobj),
3017 lsname, handle, NULL, 0);
3018 mdd_write_unlock(env, mdd_sobj);
3019 /* We don't fail the transaction if the link ea can't be
3020 updated -- fid2path will use alternate lookup method. */
3023 /* Remove old target object
3024 * For tobj is remote case cmm layer has processed
3025 * and set tobj to NULL then. So when tobj is NOT NULL,
3026 * it must be local one.
3028 if (tobj && mdd_object_exists(mdd_tobj)) {
3029 mdd_write_lock(env, mdd_tobj, MOR_TGT_CHILD);
3031 if (mdd_is_dead_obj(mdd_tobj)) {
3032 /* shld not be dead, something is wrong */
3033 CERROR("tobj is dead, something is wrong\n");
3037 mdo_ref_del(env, mdd_tobj, handle);
3039 /* Remove dot reference. */
3040 if (S_ISDIR(tattr->la_mode))
3041 mdo_ref_del(env, mdd_tobj, handle);
3044 /* fetch updated nlink */
3045 rc = mdd_la_get(env, mdd_tobj, tattr);
3047 CERROR("%s: Failed to get nlink for tobj "
3049 mdd2obd_dev(mdd)->obd_name,
3050 PFID(tpobj_fid), rc);
3051 GOTO(fixup_tpobj, rc);
3054 la->la_valid = LA_CTIME;
3055 rc = mdd_update_time(env, mdd_tobj, tattr, la, handle);
3057 CERROR("%s: Failed to set ctime for tobj "
3059 mdd2obd_dev(mdd)->obd_name,
3060 PFID(tpobj_fid), rc);
3061 GOTO(fixup_tpobj, rc);
3064 /* XXX: this transfer to ma will be removed with LOD/OSP */
3065 ma->ma_attr = *tattr;
3066 ma->ma_valid |= MA_INODE;
3067 rc = mdd_finish_unlink(env, mdd_tobj, ma, mdd_tpobj, ltname,
3070 CERROR("%s: Failed to unlink tobj "
3072 mdd2obd_dev(mdd)->obd_name,
3073 PFID(tpobj_fid), rc);
3074 GOTO(fixup_tpobj, rc);
3077 /* fetch updated nlink */
3078 rc = mdd_la_get(env, mdd_tobj, tattr);
3079 if (rc == -ENOENT) {
3080 /* the object got removed, let's
3081 * return the latest known attributes */
3082 tattr->la_nlink = 0;
3084 } else if (rc != 0) {
3085 CERROR("%s: Failed to get nlink for tobj "
3087 mdd2obd_dev(mdd)->obd_name,
3088 PFID(tpobj_fid), rc);
3089 GOTO(fixup_tpobj, rc);
3091 /* XXX: this transfer to ma will be removed with LOD/OSP */
3092 ma->ma_attr = *tattr;
3093 ma->ma_valid |= MA_INODE;
3095 if (tattr->la_nlink == 0)
3096 cl_flags |= CLF_RENAME_LAST;
3098 cl_flags &= ~CLF_RENAME_LAST_EXISTS;
3101 la->la_valid = LA_CTIME | LA_MTIME;
3102 rc = mdd_update_time(env, mdd_spobj, pattr, la, handle);
3104 GOTO(fixup_tpobj, rc);
3106 if (mdd_spobj != mdd_tpobj) {
3107 la->la_valid = LA_CTIME | LA_MTIME;
3108 rc = mdd_update_time(env, mdd_tpobj, tpattr, la, handle);
3110 GOTO(fixup_tpobj, rc);
3117 rc2 = __mdd_index_delete(env, mdd_tpobj, tname, is_dir, handle);
3119 CWARN("tp obj fix error %d\n",rc2);
3121 if (mdd_tobj && mdd_object_exists(mdd_tobj) &&
3122 !mdd_is_dead_obj(mdd_tobj)) {
3124 mdo_ref_add(env, mdd_tobj, handle);
3126 mdo_ref_add(env, mdd_tobj, handle);
3129 rc2 = __mdd_index_insert(env, mdd_tpobj,
3131 mdd_object_type(mdd_tobj),
3134 CWARN("tp obj fix error: rc = %d\n", rc2);
3139 if (rc && is_dir && mdd_sobj && mdd_spobj != mdd_tpobj) {
3140 rc2 = __mdd_index_delete_only(env, mdd_sobj, dotdot, handle);
3142 CWARN("%s: sp obj dotdot delete error: rc = %d\n",
3143 mdd2obd_dev(mdd)->obd_name, rc2);
3146 rc2 = __mdd_index_insert_only(env, mdd_sobj, spobj_fid, S_IFDIR,
3149 CWARN("%s: sp obj dotdot insert error: rc = %d\n",
3150 mdd2obd_dev(mdd)->obd_name, rc2);
3155 rc2 = __mdd_index_insert(env, mdd_spobj, lf,
3156 mdd_object_type(mdd_sobj), sname,
3159 CWARN("sp obj fix error: rc = %d\n", rc2);
3164 mdd_write_unlock(env, mdd_tobj);
3167 rc = mdd_changelog_ns_store(env, mdd, CL_RENAME, cl_flags,
3168 mdd_tobj, tpobj_fid, lf, spobj_fid,
3169 ltname, lsname, handle);
3172 rc = mdd_trans_stop(env, mdd, rc, handle);
3175 mdd_object_put(env, mdd_sobj);
3180 * Check whether we should migrate the file/dir
3182 * < 0 permission check failed or other error.
3183 * = 0 the file can be migrated.
3185 static int mdd_migrate_sanity_check(const struct lu_env *env,
3186 struct mdd_device *mdd,
3187 struct mdd_object *spobj,
3188 struct mdd_object *tpobj,
3189 struct mdd_object *sobj,
3190 struct mdd_object *tobj,
3191 const struct lu_attr *spattr,
3192 const struct lu_attr *tpattr,
3193 const struct lu_attr *attr)
3199 if (!mdd_object_remote(sobj)) {
3200 mdd_read_lock(env, sobj, MOR_SRC_CHILD);
3201 if (sobj->mod_count > 0) {
3202 CDEBUG(D_INFO, "%s: "DFID" is opened, count %d\n",
3203 mdd2obd_dev(mdd)->obd_name, PFID(mdo2fid(sobj)),
3205 mdd_read_unlock(env, sobj);
3208 mdd_read_unlock(env, sobj);
3211 if (mdd_object_exists(tobj))
3214 rc = mdd_rename_sanity_check(env, spobj, spattr, tpobj, tpattr, sobj,
3219 typedef int (*mdd_dir_stripe_cb)(const struct lu_env *env,
3220 struct mdd_object *obj,
3221 struct mdd_object *stripe,
3222 const struct lu_buf *lmv_buf,
3223 const struct lu_buf *lmu_buf,
3225 struct thandle *handle);
3227 static int mdd_dir_declare_delete_stripe(const struct lu_env *env,
3228 struct mdd_object *obj,
3229 struct mdd_object *stripe,
3230 const struct lu_buf *lmv_buf,
3231 const struct lu_buf *lmu_buf,
3233 struct thandle *handle)
3235 struct mdd_thread_info *info = mdd_env_info(env);
3236 char *stripe_name = info->mti_name;
3237 struct lmv_user_md *lmu = lmu_buf->lb_buf;
3240 if (index < le32_to_cpu(lmu->lum_stripe_count))
3243 rc = mdo_declare_index_delete(env, stripe, dotdot, handle);
3247 snprintf(stripe_name, sizeof(info->mti_name), DFID":%d",
3248 PFID(mdd_object_fid(stripe)), index);
3250 rc = mdo_declare_index_delete(env, obj, stripe_name, handle);
3254 rc = mdo_declare_ref_del(env, obj, handle);
3259 /* delete stripe from its master object namespace */
3260 static int mdd_dir_delete_stripe(const struct lu_env *env,
3261 struct mdd_object *obj,
3262 struct mdd_object *stripe,
3263 const struct lu_buf *lmv_buf,
3264 const struct lu_buf *lmu_buf,
3266 struct thandle *handle)
3268 struct mdd_thread_info *info = mdd_env_info(env);
3269 char *stripe_name = info->mti_name;
3270 struct lmv_mds_md_v1 *lmv = lmv_buf->lb_buf;
3271 struct lmv_user_md *lmu = lmu_buf->lb_buf;
3272 __u32 del_offset = le32_to_cpu(lmu->lum_stripe_count);
3277 /* local dir will delete via LOD */
3278 LASSERT(mdd_object_remote(obj));
3279 LASSERT(del_offset < le32_to_cpu(lmv->lmv_stripe_count));
3281 if (index < del_offset)
3284 mdd_write_lock(env, stripe, MOR_SRC_CHILD);
3285 rc = __mdd_index_delete_only(env, stripe, dotdot, handle);
3289 snprintf(stripe_name, sizeof(info->mti_name), DFID":%d",
3290 PFID(mdd_object_fid(stripe)), index);
3292 rc = __mdd_index_delete_only(env, obj, stripe_name, handle);
3296 rc = mdo_ref_del(env, obj, handle);
3299 mdd_write_unlock(env, stripe);
3304 static int mdd_dir_declare_destroy_stripe(const struct lu_env *env,
3305 struct mdd_object *obj,
3306 struct mdd_object *stripe,
3307 const struct lu_buf *lmv_buf,
3308 const struct lu_buf *lmu_buf,
3310 struct thandle *handle)
3312 struct lmv_user_md *lmu = lmu_buf->lb_buf;
3313 __u32 shrink_offset = le32_to_cpu(lmu->lum_stripe_count);
3316 if (index < shrink_offset) {
3317 if (shrink_offset < 2)
3319 return mdo_declare_xattr_set(env, stripe, lmv_buf,
3320 XATTR_NAME_LMV".set", 0, handle);
3323 rc = mdo_declare_ref_del(env, stripe, handle);
3327 rc = mdo_declare_destroy(env, stripe, handle);
3332 static int mdd_dir_destroy_stripe(const struct lu_env *env,
3333 struct mdd_object *obj,
3334 struct mdd_object *stripe,
3335 const struct lu_buf *lmv_buf,
3336 const struct lu_buf *lmu_buf,
3338 struct thandle *handle)
3340 struct mdd_thread_info *info = mdd_env_info(env);
3341 struct lmv_mds_md_v1 *lmv = lmv_buf->lb_buf;
3342 struct lmv_user_md *lmu = lmu_buf->lb_buf;
3343 __u32 shrink_offset = le32_to_cpu(lmu->lum_stripe_count);
3348 /* update remaining stripes' LMV */
3349 if (index < shrink_offset) {
3350 struct lmv_mds_md_v1 *slave_lmv;
3351 struct lu_buf slave_buf = {
3352 .lb_buf = &info->mti_lmv.lmv_md_v1,
3353 .lb_len = sizeof(*slave_lmv)
3355 __u32 version = le32_to_cpu(lmv->lmv_layout_version);
3357 /* if dir will be shrunk to 1-stripe, don't update */
3358 if (shrink_offset < 2)
3361 slave_lmv = slave_buf.lb_buf;
3362 memset(slave_lmv, 0, sizeof(*slave_lmv));
3363 slave_lmv->lmv_magic = cpu_to_le32(LMV_MAGIC_STRIPE);
3364 slave_lmv->lmv_stripe_count = lmu->lum_stripe_count;
3365 slave_lmv->lmv_master_mdt_index = cpu_to_le32(index);
3366 slave_lmv->lmv_hash_type = lmv->lmv_hash_type &
3367 cpu_to_le32(LMV_HASH_TYPE_MASK);
3368 slave_lmv->lmv_layout_version = cpu_to_le32(++version);
3370 rc = mdo_xattr_set(env, stripe, &slave_buf,
3371 XATTR_NAME_LMV".set", 0, handle);
3375 mdd_write_lock(env, stripe, MOR_SRC_CHILD);
3376 rc = mdo_ref_del(env, stripe, handle);
3378 rc = mdo_destroy(env, stripe, handle);
3379 mdd_write_unlock(env, stripe);
3384 static int mdd_shrink_stripe_is_empty(const struct lu_env *env,
3385 struct mdd_object *obj,
3386 struct mdd_object *stripe,
3387 const struct lu_buf *lmv_buf,
3388 const struct lu_buf *lmu_buf,
3390 struct thandle *handle)
3392 struct lmv_user_md *lmu = lmu_buf->lb_buf;
3393 __u32 shrink_offset = le32_to_cpu(lmu->lum_stripe_count);
3395 /* the default value is 0, but it means 1 */
3399 if (index < shrink_offset)
3402 return mdd_dir_is_empty(env, stripe);
3406 * iterate stripes of striped directory on remote MDT, local striped directory
3407 * is accessed via LOD.
3409 static int mdd_dir_iterate_stripes(const struct lu_env *env,
3410 struct mdd_object *obj,
3411 const struct lu_buf *lmv_buf,
3412 const struct lu_buf *lmu_buf,
3413 struct thandle *handle,
3414 mdd_dir_stripe_cb cb)
3416 struct mdd_device *mdd = mdo2mdd(&obj->mod_obj);
3417 struct lu_fid *fid = &mdd_env_info(env)->mti_fid2;
3418 struct lmv_mds_md_v1 *lmv = lmv_buf->lb_buf;
3419 struct mdd_object *stripe;
3427 for (i = 0; i < le32_to_cpu(lmv->lmv_stripe_count); i++) {
3428 fid_le_to_cpu(fid, &lmv->lmv_stripe_fids[i]);
3429 stripe = mdd_object_find(env, mdd, fid);
3431 RETURN(PTR_ERR(stripe));
3433 rc = cb(env, obj, stripe, lmv_buf, lmu_buf, i, handle);
3434 mdd_object_put(env, stripe);
3442 typedef int (*mdd_xattr_cb)(const struct lu_env *env,
3443 struct mdd_object *obj,
3444 const struct lu_buf *buf,
3446 int fl, struct thandle *handle);
3448 /* iterate xattrs, but ignore LMA, LMV, and LINKEA if 'skip_linkea' is set. */
3449 static int mdd_iterate_xattrs(const struct lu_env *env,
3450 struct mdd_object *sobj,
3451 struct mdd_object *tobj,
3453 struct thandle *handle,
3456 struct mdd_thread_info *info = mdd_env_info(env);
3458 struct lu_buf list_xbuf;
3459 struct lu_buf xbuf = { NULL };
3468 /* retrieve xattr list from the old object */
3469 list_xsize = mdo_xattr_list(env, sobj, &LU_BUF_NULL);
3470 if (list_xsize == -ENODATA)
3476 lu_buf_check_and_alloc(&info->mti_big_buf, list_xsize);
3477 if (info->mti_big_buf.lb_buf == NULL)
3480 list_xbuf.lb_buf = info->mti_big_buf.lb_buf;
3481 list_xbuf.lb_len = list_xsize;
3482 rc = mdo_xattr_list(env, sobj, &list_xbuf);
3488 xname = list_xbuf.lb_buf;
3490 xlen = strnlen(xname, rem - 1) + 1;
3491 if (strcmp(XATTR_NAME_LMA, xname) == 0 ||
3492 strcmp(XATTR_NAME_LMV, xname) == 0)
3496 strcmp(XATTR_NAME_LINK, xname) == 0)
3499 xsize = mdo_xattr_get(env, sobj, &LU_BUF_NULL, xname);
3500 if (xsize == -ENODATA)
3503 GOTO(out, rc = xsize);
3505 lu_buf_check_and_alloc(&xbuf, xsize);
3506 if (xbuf.lb_buf == NULL)
3507 GOTO(out, rc = -ENOMEM);
3509 rc = mdo_xattr_get(env, sobj, &xbuf, xname);
3516 rc = cb(env, tobj, &xbuf, xname, 0, handle);
3517 if (unlikely(rc == -ENOSPC &&
3518 strcmp(xname, XATTR_NAME_LINK) == 0)) {
3519 rc = linkea_overflow_shrink(
3520 (struct linkea_data *)(xbuf.lb_buf));
3521 if (likely(rc > 0)) {
3539 typedef int (*mdd_linkea_cb)(const struct lu_env *env,
3540 struct mdd_object *sobj,
3541 struct mdd_object *tobj,
3542 const struct lu_name *sname,
3543 const struct lu_fid *sfid,
3544 const struct lu_name *lname,
3545 const struct lu_fid *fid,
3547 struct thandle *handle);
3549 static int mdd_declare_update_link(const struct lu_env *env,
3550 struct mdd_object *sobj,
3551 struct mdd_object *tobj,
3552 const struct lu_name *tname,
3553 const struct lu_fid *tpfid,
3554 const struct lu_name *lname,
3555 const struct lu_fid *fid,
3557 struct thandle *handle)
3559 struct mdd_device *mdd = mdo2mdd(&sobj->mod_obj);
3560 struct mdd_object *pobj;
3564 if (lu_fid_eq(tpfid, fid) && tname->ln_namelen == lname->ln_namelen &&
3565 !strcmp(tname->ln_name, lname->ln_name))
3568 pobj = mdd_object_find(env, mdd, fid);
3570 return PTR_ERR(pobj);
3573 rc = mdo_declare_index_delete(env, pobj, lname->ln_name, handle);
3575 rc = mdo_declare_index_insert(env, pobj, mdo2fid(tobj),
3576 mdd_object_type(sobj),
3577 lname->ln_name, handle);
3578 mdd_object_put(env, pobj);
3582 rc = mdo_declare_ref_add(env, tobj, handle);
3586 rc = mdo_declare_ref_del(env, sobj, handle);
3590 static int mdd_update_link(const struct lu_env *env,
3591 struct mdd_object *sobj,
3592 struct mdd_object *tobj,
3593 const struct lu_name *tname,
3594 const struct lu_fid *tpfid,
3595 const struct lu_name *lname,
3596 const struct lu_fid *fid,
3598 struct thandle *handle)
3600 struct mdd_device *mdd = mdo2mdd(&sobj->mod_obj);
3601 struct mdd_object *pobj;
3606 LASSERT(lu_name_is_valid(lname));
3609 if (lu_fid_eq(tpfid, fid) && tname->ln_namelen == lname->ln_namelen &&
3610 !strncmp(tname->ln_name, lname->ln_name, lname->ln_namelen))
3613 CDEBUG(D_INFO, "update "DFID"/"DNAME":"DFID"\n",
3614 PFID(fid), PNAME(lname), PFID(mdo2fid(tobj)));
3616 pobj = mdd_object_find(env, mdd, fid);
3618 CWARN("%s: cannot find obj "DFID": %ld\n",
3619 mdd2obd_dev(mdd)->obd_name, PFID(fid), PTR_ERR(pobj));
3620 RETURN(PTR_ERR(pobj));
3623 if (!mdd_object_exists(pobj)) {
3624 CDEBUG(D_INFO, DFID" doesn't exist\n", PFID(fid));
3625 mdd_object_put(env, pobj);
3629 mdd_write_lock(env, pobj, MOR_TGT_PARENT);
3630 rc = __mdd_index_delete_only(env, pobj, lname->ln_name, handle);
3632 rc = __mdd_index_insert_only(env, pobj, mdo2fid(tobj),
3633 mdd_object_type(sobj),
3634 lname->ln_name, handle);
3635 mdd_write_unlock(env, pobj);
3636 mdd_object_put(env, pobj);
3640 mdd_write_lock(env, tobj, MOR_TGT_CHILD);
3641 rc = mdo_ref_add(env, tobj, handle);
3642 mdd_write_unlock(env, tobj);
3646 mdd_write_lock(env, sobj, MOR_SRC_CHILD);
3647 rc = mdo_ref_del(env, sobj, handle);
3648 mdd_write_unlock(env, sobj);
3653 static inline int mdd_fld_lookup(const struct lu_env *env,
3654 struct mdd_device *mdd,
3655 const struct lu_fid *fid,
3658 struct lu_seq_range *range = &mdd_env_info(env)->mti_range;
3659 struct seq_server_site *ss;
3662 ss = mdd->mdd_md_dev.md_lu_dev.ld_site->ld_seq_site;
3664 range->lsr_flags = LU_SEQ_RANGE_MDT;
3665 rc = fld_server_lookup(env, ss->ss_server_fld, fid->f_seq, range);
3669 *mdt_index = range->lsr_index;
3674 static int mdd_is_link_on_source_mdt(const struct lu_env *env,
3675 struct mdd_object *sobj,
3676 struct mdd_object *tobj,
3677 const struct lu_name *tname,
3678 const struct lu_fid *tpfid,
3679 const struct lu_name *lname,
3680 const struct lu_fid *fid,
3682 struct thandle *handle)
3684 struct mdd_device *mdd = mdo2mdd(&sobj->mod_obj);
3685 __u32 source_mdt_index = *(__u32 *)opaque;
3686 __u32 link_mdt_index;
3692 if (lu_fid_eq(tpfid, fid) && tname->ln_namelen == lname->ln_namelen &&
3693 !strcmp(tname->ln_name, lname->ln_name))
3696 rc = mdd_fld_lookup(env, mdd, fid, &link_mdt_index);
3700 RETURN(link_mdt_index == source_mdt_index);
3703 static int mdd_iterate_linkea(const struct lu_env *env,
3704 struct mdd_object *sobj,
3705 struct mdd_object *tobj,
3706 const struct lu_name *tname,
3707 const struct lu_fid *tpfid,
3708 struct linkea_data *ldata,
3710 struct thandle *handle,
3713 struct mdd_thread_info *info = mdd_env_info(env);
3714 char *filename = info->mti_name;
3715 struct lu_name lname;
3722 for (linkea_first_entry(ldata); ldata->ld_lee && !rc;
3723 linkea_next_entry(ldata)) {
3724 linkea_entry_unpack(ldata->ld_lee, &ldata->ld_reclen, &lname,
3727 /* Note: lname might miss \0 at the end */
3728 snprintf(filename, sizeof(info->mti_name), "%.*s",
3729 lname.ln_namelen, lname.ln_name);
3730 lname.ln_name = filename;
3732 CDEBUG(D_INFO, DFID"/"DNAME"\n", PFID(&fid), PNAME(&lname));
3734 rc = cb(env, sobj, tobj, tname, tpfid, &lname, &fid, opaque,
3742 * Prepare linkea, and check whether file needs migrate: if source still has
3743 * link on source MDT, no need to migrate, just update namespace on source and
3746 * \retval 0 do migrate
3747 * \retval 1 don't migrate
3748 * \retval -errno on failure
3750 static int migrate_linkea_prepare(const struct lu_env *env,
3751 struct mdd_device *mdd,
3752 struct mdd_object *spobj,
3753 struct mdd_object *tpobj,
3754 struct mdd_object *sobj,
3755 const struct lu_name *lname,
3756 const struct lu_attr *attr,
3757 struct linkea_data *ldata)
3759 __u32 source_mdt_index;
3764 memset(ldata, 0, sizeof(*ldata));
3765 rc = mdd_linkea_prepare(env, sobj, mdo2fid(spobj), lname,
3766 mdo2fid(tpobj), lname, 1, 0, ldata);
3771 * Then it will check if the file should be migrated. If the file has
3772 * mulitple links, we only need migrate the file if all of its entries
3773 * has been migrated to the remote MDT.
3775 if (S_ISDIR(attr->la_mode) || attr->la_nlink < 2)
3778 /* If there are still links locally, don't migrate this file */
3779 LASSERT(ldata->ld_leh != NULL);
3782 * If linkEA is overflow, it means there are some unknown name entries
3783 * under unknown parents, which will prevent the migration.
3785 if (unlikely(ldata->ld_leh->leh_overflow_time))
3788 rc = mdd_fld_lookup(env, mdd, mdo2fid(sobj), &source_mdt_index);
3792 rc = mdd_iterate_linkea(env, sobj, NULL, lname, mdo2fid(tpobj), ldata,
3793 &source_mdt_index, NULL,
3794 mdd_is_link_on_source_mdt);
3798 static int mdd_dir_declare_layout_delete(const struct lu_env *env,
3799 struct mdd_object *obj,
3800 const struct lu_buf *lmv_buf,
3801 const struct lu_buf *lmu_buf,
3802 struct thandle *handle)
3806 if (!lmv_buf->lb_buf)
3807 rc = mdo_declare_index_delete(env, obj, dotdot, handle);
3808 else if (mdd_object_remote(obj))
3809 rc = mdd_dir_iterate_stripes(env, obj, lmv_buf, lmu_buf, handle,
3810 mdd_dir_declare_delete_stripe);
3812 rc = mdo_declare_xattr_set(env, obj, lmu_buf,
3813 XATTR_NAME_LMV".del", 0, handle);
3818 static int mdd_dir_layout_delete(const struct lu_env *env,
3819 struct mdd_object *obj,
3820 const struct lu_buf *lmv_buf,
3821 const struct lu_buf *lmu_buf,
3822 struct thandle *handle)
3828 mdd_write_lock(env, obj, MOR_SRC_PARENT);
3829 if (!lmv_buf->lb_buf)
3831 rc = __mdd_index_delete_only(env, obj, dotdot, handle);
3832 else if (mdd_object_remote(obj))
3833 /* striped, but remote */
3834 rc = mdd_dir_iterate_stripes(env, obj, lmv_buf, lmu_buf, handle,
3835 mdd_dir_delete_stripe);
3837 rc = mdo_xattr_set(env, obj, lmu_buf, XATTR_NAME_LMV".del", 0,
3839 mdd_write_unlock(env, obj);
3844 static int mdd_declare_migrate_create(const struct lu_env *env,
3845 struct mdd_object *tpobj,
3846 struct mdd_object *sobj,
3847 struct mdd_object *tobj,
3848 const struct lu_name *lname,
3849 struct lu_attr *attr,
3850 struct lu_buf *sbuf,
3851 struct linkea_data *ldata,
3852 struct md_op_spec *spec,
3853 struct dt_allocation_hint *hint,
3854 struct thandle *handle)
3856 struct mdd_thread_info *info = mdd_env_info(env);
3857 struct lmv_mds_md_v1 *lmv = sbuf->lb_buf;
3860 if (S_ISDIR(attr->la_mode)) {
3861 struct lu_buf lmu_buf = { NULL };
3864 struct lmv_user_md *lmu = &info->mti_lmv.lmv_user_md;
3866 lmu->lum_stripe_count = 0;
3867 lmu_buf.lb_buf = lmu;
3868 lmu_buf.lb_len = sizeof(*lmu);
3871 rc = mdd_dir_declare_layout_delete(env, sobj, sbuf, &lmu_buf,
3877 rc = mdo_declare_xattr_del(env, sobj, XATTR_NAME_LMV,
3884 rc = mdd_declare_create(env, mdo2mdd(&tpobj->mod_obj), tpobj, tobj,
3885 lname, attr, handle, spec, ldata, NULL, NULL,
3890 if (S_ISDIR(attr->la_mode) && mdd_dir_is_empty(env, sobj) != 0) {
3893 * if sobj is not striped, fake a 1-stripe LMV, which
3894 * will be used to generate a compound LMV for tobj.
3896 LASSERT(sizeof(info->mti_key) >
3897 lmv_mds_md_size(1, LMV_MAGIC_V1));
3898 lmv = (typeof(lmv))info->mti_key;
3899 memset(lmv, 0, sizeof(*lmv));
3900 lmv->lmv_magic = cpu_to_le32(LMV_MAGIC_V1);
3901 lmv->lmv_stripe_count = cpu_to_le32(1);
3902 fid_le_to_cpu(&lmv->lmv_stripe_fids[0], mdo2fid(sobj));
3904 sbuf->lb_len = lmv_mds_md_size(1, LMV_MAGIC_V1);
3906 rc = mdo_declare_xattr_set(env, tobj, sbuf,
3907 XATTR_NAME_LMV".add", 0,
3909 sbuf->lb_buf = NULL;
3912 rc = mdo_declare_xattr_set(env, tobj, sbuf,
3913 XATTR_NAME_LMV".add", 0,
3921 * tobj mode will be used in lod_declare_xattr_set(), but it's not
3922 * createb yet, copy from sobj.
3924 tobj->mod_obj.mo_lu.lo_header->loh_attr &= ~S_IFMT;
3925 tobj->mod_obj.mo_lu.lo_header->loh_attr |=
3926 sobj->mod_obj.mo_lu.lo_header->loh_attr & S_IFMT;
3928 rc = mdd_iterate_xattrs(env, sobj, tobj, true, handle,
3929 mdo_declare_xattr_set);
3933 if (S_ISREG(attr->la_mode)) {
3934 handle->th_complex = 1;
3936 rc = mdo_declare_xattr_del(env, sobj, XATTR_NAME_LOV, handle);
3941 * target is not initalized because its LOV is copied from
3942 * source in mdd_migrate_create(), declare via sobj.
3944 rc = mdo_declare_xattr_set(env, sobj, NULL, XATTR_NAME_FID, 0,
3950 if (!S_ISDIR(attr->la_mode)) {
3951 rc = mdd_iterate_linkea(env, sobj, tobj, lname, mdo2fid(tpobj),
3952 ldata, NULL, handle,
3953 mdd_declare_update_link);
3958 rc = mdo_declare_xattr_del(env, sobj, XATTR_NAME_LMV,
3969 * Create target, migrate xattrs and update links.
3971 * Create target according to \a spec, and then migrate xattrs, if it's
3972 * directory, migrate source stripes to target, else update fid to target
3975 * \param[in] env execution environment
3976 * \param[in] tpobj target parent object
3977 * \param[in] sobj source object
3978 * \param[in] tobj target object
3979 * \param[in] lname file name
3980 * \param[in] attr source attributes
3981 * \param[in] sbuf source LMV buf
3982 * \param[in] ldata source linkea
3983 * \param[in] spec migrate create spec
3984 * \param[in] hint target creation hint
3985 * \param[in] handle tranasction handle
3987 * \retval 0 on success
3988 * \retval -errno on failure
3990 static int mdd_migrate_create(const struct lu_env *env,
3991 struct mdd_object *tpobj,
3992 struct mdd_object *sobj,
3993 struct mdd_object *tobj,
3994 const struct lu_name *lname,
3995 struct lu_attr *attr,
3996 const struct lu_buf *sbuf,
3997 struct linkea_data *ldata,
3998 struct md_op_spec *spec,
3999 struct dt_allocation_hint *hint,
4000 struct thandle *handle)
4007 * directory will migrate sobj stripes to tobj:
4008 * 1. delete stripes from sobj.
4009 * 2. add stripes to tobj, see lod_dir_declare_layout_add().
4010 * 3. create/attach stripes for tobj, see lod_xattr_set_lmv().
4012 if (S_ISDIR(attr->la_mode)) {
4013 struct lu_buf lmu_buf = { NULL };
4016 struct mdd_thread_info *info = mdd_env_info(env);
4017 struct lmv_user_md *lmu = &info->mti_lmv.lmv_user_md;
4019 lmu->lum_stripe_count = 0;
4020 lmu_buf.lb_buf = lmu;
4021 lmu_buf.lb_len = sizeof(*lmu);
4024 rc = mdd_dir_layout_delete(env, sobj, sbuf, &lmu_buf, handle);
4029 * delete LMV so that later when destroying sobj it won't delete
4033 mdd_write_lock(env, sobj, MOR_SRC_CHILD);
4034 rc = mdo_xattr_del(env, sobj, XATTR_NAME_LMV, handle);
4035 mdd_write_unlock(env, sobj);
4041 /* don't set nlink from sobj */
4042 attr->la_valid &= ~LA_NLINK;
4044 rc = mdd_create_object(env, tpobj, tobj, attr, spec, NULL, NULL, hint,
4049 mdd_write_lock(env, tobj, MOR_TGT_CHILD);
4050 rc = mdd_iterate_xattrs(env, sobj, tobj, true, handle, mdo_xattr_set);
4051 mdd_write_unlock(env, tobj);
4055 if (S_ISREG(attr->la_mode)) {
4056 /* delete LOV to avoid deleting OST objs when destroying sobj */
4057 mdd_write_lock(env, sobj, MOR_SRC_CHILD);
4058 rc = mdo_xattr_del(env, sobj, XATTR_NAME_LOV, handle);
4059 mdd_write_unlock(env, sobj);
4063 /* for regular file, update OST objects XATTR_NAME_FID */
4064 rc = mdo_xattr_set(env, tobj, NULL, XATTR_NAME_FID, 0, handle);
4069 if (!S_ISDIR(attr->la_mode))
4070 rc = mdd_iterate_linkea(env, sobj, tobj, lname, mdo2fid(tpobj),
4071 ldata, NULL, handle, mdd_update_link);
4076 static int mdd_declare_migrate_update(const struct lu_env *env,
4077 struct mdd_object *spobj,
4078 struct mdd_object *tpobj,
4079 struct mdd_object *sobj,
4080 struct mdd_object *tobj,
4081 const struct lu_name *lname,
4082 struct lu_attr *attr,
4083 struct lu_attr *spattr,
4084 struct lu_attr *tpattr,
4085 struct linkea_data *ldata,
4089 struct thandle *handle)
4091 struct mdd_thread_info *info = mdd_env_info(env);
4092 const struct lu_fid *fid = mdo2fid(do_create ? tobj : sobj);
4093 struct lu_attr *la = &info->mti_la_for_fix;
4096 rc = mdo_declare_index_delete(env, spobj, lname->ln_name, handle);
4100 if (S_ISDIR(attr->la_mode)) {
4101 rc = mdo_declare_ref_del(env, spobj, handle);
4106 rc = mdo_declare_index_insert(env, tpobj, fid, mdd_object_type(sobj),
4107 lname->ln_name, handle);
4111 rc = mdd_declare_links_add(env, do_create ? tobj : sobj, handle, ldata);
4115 if (S_ISDIR(attr->la_mode)) {
4116 rc = mdo_declare_ref_add(env, tpobj, handle);
4121 la->la_valid = LA_CTIME | LA_MTIME;
4122 rc = mdo_declare_attr_set(env, spobj, la, handle);
4126 if (tpobj != spobj) {
4127 rc = mdo_declare_attr_set(env, tpobj, la, handle);
4132 if (do_create && do_destroy) {
4133 rc = mdo_declare_ref_del(env, sobj, handle);
4137 rc = mdo_declare_destroy(env, sobj, handle);
4146 * migrate dirent from \a spobj to \a tpobj, and destroy \a sobj
4148 static int mdd_migrate_update(const struct lu_env *env,
4149 struct mdd_object *spobj,
4150 struct mdd_object *tpobj,
4151 struct mdd_object *sobj,
4152 struct mdd_object *tobj,
4153 const struct lu_name *lname,
4154 struct lu_attr *attr,
4155 struct lu_attr *spattr,
4156 struct lu_attr *tpattr,
4157 struct linkea_data *ldata,
4161 struct thandle *handle)
4163 struct mdd_thread_info *info = mdd_env_info(env);
4164 const struct lu_fid *fid = mdo2fid(do_create ? tobj : sobj);
4165 struct lu_attr *la = &info->mti_la_for_fix;
4170 CDEBUG(D_INFO, "update %s "DFID"/"DFID" to "DFID"/"DFID"\n",
4171 lname->ln_name, PFID(mdo2fid(spobj)),
4172 PFID(mdo2fid(sobj)), PFID(mdo2fid(tpobj)),
4175 rc = __mdd_index_delete(env, spobj, lname->ln_name,
4176 S_ISDIR(attr->la_mode), handle);
4180 rc = __mdd_index_insert(env, tpobj, fid, mdd_object_type(sobj),
4181 lname->ln_name, handle);
4185 rc = mdd_links_write(env, do_create ? tobj : sobj, ldata, handle);
4189 la->la_ctime = la->la_mtime = ma->ma_attr.la_ctime;
4190 la->la_valid = LA_CTIME | LA_MTIME;
4191 mdd_write_lock(env, spobj, MOR_SRC_PARENT);
4192 rc = mdd_update_time(env, spobj, spattr, la, handle);
4193 mdd_write_unlock(env, spobj);
4197 if (tpobj != spobj) {
4198 la->la_valid = LA_CTIME | LA_MTIME;
4199 mdd_write_lock(env, tpobj, MOR_TGT_PARENT);
4200 rc = mdd_update_time(env, tpobj, tpattr, la, handle);
4201 mdd_write_unlock(env, tpobj);
4207 * there are three situations we shouldn't destroy source:
4208 * 1. if source is not dir, and it happens to be located on the same MDT
4210 * 2. if source is not dir, and has link on the same MDT where source is
4212 * 3. if source is dir, and it's a normal, non-empty dir.
4214 * the first two situations equals to !do_create, and the 3rd equals to
4215 * !do_destroy, so the below condition is actually
4216 * !(!do_create || !do_destroy).
4218 * NB, if user has opened source dir before migration, he will get
4219 * -ENOENT error when close it later, because source is likely to be
4220 * remote, which can't be moved to orphan list, but except this error
4221 * message, this won't cause any inconsistency or trouble.
4223 if (do_create && do_destroy) {
4224 mdd_write_lock(env, sobj, MOR_SRC_CHILD);
4225 mdo_ref_del(env, sobj, handle);
4226 rc = mdo_destroy(env, sobj, handle);
4227 mdd_write_unlock(env, sobj);
4234 * Migrate directory or file.
4236 * migrate source to target in following steps:
4237 * 1. create target, append source stripes after target's if it's directory,
4238 * migrate xattrs and update fid of source links.
4239 * 2. update namespace: migrate dirent from source parent to target parent,
4240 * update file linkea, and destroy source if it's not needed any more.
4242 * \param[in] env execution environment
4243 * \param[in] md_pobj parent master object
4244 * \param[in] md_sobj source object
4245 * \param[in] lname file name
4246 * \param[in] md_tobj target object
4247 * \param[in] spec target creation spec
4248 * \param[in] ma used to update \a pobj mtime and ctime
4250 * \retval 0 on success
4251 * \retval -errno on failure
4253 static int mdd_migrate(const struct lu_env *env, struct md_object *md_pobj,
4254 struct md_object *md_sobj, const struct lu_name *lname,
4255 struct md_object *md_tobj, struct md_op_spec *spec,
4258 struct mdd_device *mdd = mdo2mdd(md_pobj);
4259 struct mdd_thread_info *info = mdd_env_info(env);
4260 struct mdd_object *pobj = md2mdd_obj(md_pobj);
4261 struct mdd_object *sobj = md2mdd_obj(md_sobj);
4262 struct mdd_object *tobj = md2mdd_obj(md_tobj);
4263 struct mdd_object *spobj = NULL;
4264 struct mdd_object *tpobj = NULL;
4265 struct lu_attr *spattr = &info->mti_pattr;
4266 struct lu_attr *tpattr = &info->mti_tpattr;
4267 struct lu_attr *attr = &info->mti_cattr;
4268 struct linkea_data *ldata = &info->mti_link_data;
4269 struct dt_allocation_hint *hint = &info->mti_hint;
4270 struct lu_fid *fid = &info->mti_fid2;
4271 struct lu_buf pbuf = { NULL };
4272 struct lu_buf sbuf = { NULL };
4273 struct lmv_mds_md_v1 *plmv;
4274 struct thandle *handle;
4275 bool do_create = true;
4276 bool do_destroy = true;
4280 rc = mdd_la_get(env, sobj, attr);
4284 /* locate source and target stripe on pobj, which are the real parent */
4285 rc = mdd_stripe_get(env, pobj, &pbuf, XATTR_NAME_LMV);
4286 if (rc < 0 && rc != -ENODATA)
4291 __u32 hash_type = le32_to_cpu(plmv->lmv_hash_type);
4292 __u32 count = le32_to_cpu(plmv->lmv_stripe_count);
4295 /* locate target parent stripe */
4296 if (hash_type & LMV_HASH_FLAG_MIGRATION) {
4298 * fail check here to make sure top dir migration
4301 if (OBD_FAIL_CHECK_RESET(OBD_FAIL_MIGRATE_ENTRIES, 0))
4302 GOTO(out, rc = -EIO);
4303 hash_type &= ~LMV_HASH_FLAG_MIGRATION;
4304 count = le32_to_cpu(plmv->lmv_migrate_offset);
4306 index = lmv_name_to_stripe_index(hash_type, count,
4310 GOTO(out, rc = index);
4312 fid_le_to_cpu(fid, &plmv->lmv_stripe_fids[index]);
4313 tpobj = mdd_object_find(env, mdd, fid);
4315 GOTO(out, rc = PTR_ERR(tpobj));
4317 /* locate source parent stripe */
4318 if (le32_to_cpu(plmv->lmv_hash_type) &
4319 LMV_HASH_FLAG_MIGRATION) {
4320 hash_type = le32_to_cpu(plmv->lmv_migrate_hash);
4321 count = le32_to_cpu(plmv->lmv_stripe_count) -
4322 le32_to_cpu(plmv->lmv_migrate_offset);
4324 index = lmv_name_to_stripe_index(hash_type, count,
4328 mdd_object_put(env, tpobj);
4329 GOTO(out, rc = index);
4332 index += le32_to_cpu(plmv->lmv_migrate_offset);
4333 fid_le_to_cpu(fid, &plmv->lmv_stripe_fids[index]);
4334 spobj = mdd_object_find(env, mdd, fid);
4335 if (IS_ERR(spobj)) {
4336 mdd_object_put(env, tpobj);
4337 GOTO(out, rc = PTR_ERR(spobj));
4341 mdd_object_get(spobj);
4346 mdd_object_get(tpobj);
4347 mdd_object_get(spobj);
4350 rc = mdd_la_get(env, spobj, spattr);
4354 rc = mdd_la_get(env, tpobj, tpattr);
4358 if (S_ISDIR(attr->la_mode)) {
4359 struct lmv_user_md_v1 *lmu = spec->u.sp_ea.eadata;
4364 * if user use default value '0' for stripe_count, we need to
4365 * adjust it to '1' to create a 1-stripe directory.
4367 if (lmu->lum_stripe_count == 0) {
4368 /* eadata is from request, don't alter it */
4369 info->mti_lmu = *lmu;
4370 info->mti_lmu.lum_stripe_count = cpu_to_le32(1);
4371 spec->u.sp_ea.eadata = &info->mti_lmu;
4372 lmu = spec->u.sp_ea.eadata;
4375 rc = mdd_stripe_get(env, sobj, &sbuf, XATTR_NAME_LMV);
4376 if (rc == -ENODATA) {
4377 if (mdd_dir_is_empty(env, sobj) == 0) {
4379 * if sobj is empty, and target is not striped,
4380 * create target as a normal directory.
4382 if (le32_to_cpu(lmu->lum_stripe_count) == 1) {
4383 info->mti_lmu = *lmu;
4384 info->mti_lmu.lum_stripe_count = 0;
4385 spec->u.sp_ea.eadata = &info->mti_lmu;
4386 lmu = spec->u.sp_ea.eadata;
4390 * sobj is not striped dir, if it's not empty,
4391 * it will be migrated to be a stripe of target,
4392 * don't destroy it after migration.
4399 struct lmv_mds_md_v1 *lmv = sbuf.lb_buf;
4401 if (le32_to_cpu(lmv->lmv_hash_type) &
4402 LMV_HASH_FLAG_MIGRATION) {
4403 __u32 lum_stripe_count = lmu->lum_stripe_count;
4404 __u32 lmv_hash_type = lmv->lmv_hash_type &
4405 cpu_to_le32(LMV_HASH_TYPE_MASK);
4407 if (!lum_stripe_count)
4408 lum_stripe_count = cpu_to_le32(1);
4410 /* TODO: check specific MDTs */
4411 if (lmv->lmv_migrate_offset !=
4413 lmv->lmv_master_mdt_index !=
4414 lmu->lum_stripe_offset ||
4415 (lmv_hash_type != 0 &&
4416 lmv_hash_type != lmu->lum_hash_type)) {
4417 CERROR("%s: \'"DNAME"\' migration was "
4418 "interrupted, run \'lfs migrate "
4419 "-m %d -c %d -H %d "DNAME"\' to "
4420 "finish migration.\n",
4421 mdd2obd_dev(mdd)->obd_name,
4424 lmv->lmv_master_mdt_index),
4426 lmv->lmv_migrate_offset),
4427 le32_to_cpu(lmv_hash_type),
4429 GOTO(out, rc = -EPERM);
4431 GOTO(out, rc = -EALREADY);
4434 } else if (!mdd_object_remote(tpobj)) {
4436 * if source is already on MDT where target parent is located,
4437 * no need to create, just update namespace.
4440 } else if (S_ISLNK(attr->la_mode)) {
4441 lu_buf_check_and_alloc(&sbuf, attr->la_size + 1);
4443 GOTO(out, rc = -ENOMEM);
4444 rc = mdd_readlink(env, &sobj->mod_obj, &sbuf);
4447 CERROR("%s: "DFID" readlink failed: rc = %d\n",
4448 mdd2obd_dev(mdd)->obd_name,
4449 PFID(mdo2fid(sobj)), rc);
4452 spec->u.sp_symname = sbuf.lb_buf;
4453 } else if (S_ISREG(attr->la_mode)) {
4454 spec->sp_cr_flags |= MDS_OPEN_DELAY_CREATE;
4455 spec->sp_cr_flags &= ~MDS_OPEN_HAS_EA;
4459 * if sobj has link on the same MDT, no need to create, just update
4460 * namespace, and it will be a remote file on target parent, which is
4461 * similar to rename.
4463 rc = migrate_linkea_prepare(env, mdd, spobj, tpobj, sobj, lname, attr,
4470 rc = mdd_migrate_sanity_check(env, mdd, spobj, tpobj, sobj, tobj,
4471 spattr, tpattr, attr);
4475 mdd_object_make_hint(env, NULL, tobj, attr, spec, hint);
4477 handle = mdd_trans_create(env, mdd);
4479 GOTO(out, rc = PTR_ERR(handle));
4482 rc = mdd_declare_migrate_create(env, tpobj, sobj, tobj, lname,
4483 attr, &sbuf, ldata, spec, hint,
4486 GOTO(stop_trans, rc);
4489 rc = mdd_declare_migrate_update(env, spobj, tpobj, sobj, tobj, lname,
4490 attr, spattr, tpattr, ldata, do_create,
4491 do_destroy, ma, handle);
4493 GOTO(stop_trans, rc);
4495 rc = mdd_declare_changelog_store(env, mdd, CL_MIGRATE, lname, NULL,
4498 GOTO(stop_trans, rc);
4500 rc = mdd_trans_start(env, mdd, handle);
4502 GOTO(stop_trans, rc);
4505 rc = mdd_migrate_create(env, tpobj, sobj, tobj, lname, attr,
4506 &sbuf, ldata, spec, hint, handle);
4508 GOTO(stop_trans, rc);
4511 rc = mdd_migrate_update(env, spobj, tpobj, sobj, tobj, lname, attr,
4512 spattr, tpattr, ldata, do_create, do_destroy,
4515 GOTO(stop_trans, rc);
4517 rc = mdd_changelog_ns_store(env, mdd, CL_MIGRATE, 0, tobj,
4518 mdo2fid(spobj), mdo2fid(sobj),
4519 mdo2fid(tpobj), lname, lname, handle);
4521 GOTO(stop_trans, rc);
4525 rc = mdd_trans_stop(env, mdd, rc, handle);
4527 if (spobj && !IS_ERR(spobj))
4528 mdd_object_put(env, spobj);
4529 if (tpobj && !IS_ERR(tpobj))
4530 mdd_object_put(env, tpobj);
4536 static int __mdd_dir_declare_layout_shrink(const struct lu_env *env,
4537 struct mdd_object *pobj,
4538 struct mdd_object *obj,
4539 struct mdd_object *stripe,
4540 struct lu_attr *attr,
4541 struct lu_buf *lmv_buf,
4542 const struct lu_buf *lmu_buf,
4543 struct lu_name *lname,
4544 struct thandle *handle)
4546 struct mdd_thread_info *info = mdd_env_info(env);
4547 struct lmv_mds_md_v1 *lmv = lmv_buf->lb_buf;
4548 struct lmv_user_md *lmu = (typeof(lmu))info->mti_key;
4549 struct lu_buf shrink_buf = { .lb_buf = lmu,
4550 .lb_len = sizeof(*lmu) };
4555 memcpy(lmu, lmu_buf->lb_buf, sizeof(*lmu));
4557 if (le32_to_cpu(lmu->lum_stripe_count) < 2)
4558 lmu->lum_stripe_count = 0;
4560 rc = mdd_dir_declare_layout_delete(env, obj, lmv_buf, &shrink_buf,
4565 if (lmu->lum_stripe_count == 0) {
4566 lmu->lum_stripe_count = cpu_to_le32(1);
4568 rc = mdo_declare_xattr_del(env, obj, XATTR_NAME_LMV, handle);
4573 rc = mdd_dir_iterate_stripes(env, obj, lmv_buf, &shrink_buf, handle,
4574 mdd_dir_declare_destroy_stripe);
4578 if (le32_to_cpu(lmu->lum_stripe_count) > 1)
4579 return mdo_declare_xattr_set(env, obj, lmv_buf,
4580 XATTR_NAME_LMV".set", 0, handle);
4582 rc = mdo_declare_index_insert(env, stripe, mdo2fid(pobj), S_IFDIR,
4587 rc = mdd_iterate_xattrs(env, obj, stripe, false, handle,
4588 mdo_declare_xattr_set);
4592 rc = mdo_declare_xattr_del(env, stripe, XATTR_NAME_LMV, handle);
4596 rc = mdo_declare_attr_set(env, stripe, attr, handle);
4600 rc = mdo_declare_index_delete(env, pobj, lname->ln_name, handle);
4604 rc = mdo_declare_index_insert(env, pobj, mdo2fid(stripe), attr->la_mode,
4605 lname->ln_name, handle);
4609 rc = mdo_declare_ref_del(env, obj, handle);
4613 rc = mdo_declare_ref_del(env, obj, handle);
4617 rc = mdo_declare_destroy(env, obj, handle);
4626 * after files under \a obj were migrated, shrink old stripes from \a obj,
4627 * furthermore, if it becomes a 1-stripe directory, convert it to a normal one.
4629 static int __mdd_dir_layout_shrink(const struct lu_env *env,
4630 struct mdd_object *pobj,
4631 struct mdd_object *obj,
4632 struct mdd_object *stripe,
4633 struct lu_attr *attr,
4634 struct lu_buf *lmv_buf,
4635 const struct lu_buf *lmu_buf,
4636 struct lu_name *lname,
4637 struct thandle *handle)
4639 struct mdd_thread_info *info = mdd_env_info(env);
4640 struct lmv_mds_md_v1 *lmv = lmv_buf->lb_buf;
4641 struct lmv_user_md *lmu = (typeof(lmu))info->mti_key;
4642 struct lu_buf shrink_buf = { .lb_buf = lmu,
4643 .lb_len = sizeof(*lmu) };
4644 int len = lmv_buf->lb_len;
4645 __u32 version = le32_to_cpu(lmv->lmv_layout_version);
4650 /* lmu needs to be altered, but lmu_buf is const */
4651 memcpy(lmu, lmu_buf->lb_buf, sizeof(*lmu));
4654 * if dir will be shrunk to 1-stripe, delete all stripes, because it
4655 * will be converted to normal dir.
4657 if (le32_to_cpu(lmu->lum_stripe_count) == 1)
4658 lmu->lum_stripe_count = 0;
4660 /* delete stripes after lmu_stripe_count */
4661 rc = mdd_dir_layout_delete(env, obj, lmv_buf, &shrink_buf, handle);
4665 if (lmu->lum_stripe_count == 0) {
4666 lmu->lum_stripe_count = cpu_to_le32(1);
4668 /* delete LMV to avoid deleting stripes again upon destroy */
4669 mdd_write_lock(env, obj, MOR_SRC_CHILD);
4670 rc = mdo_xattr_del(env, obj, XATTR_NAME_LMV, handle);
4671 mdd_write_unlock(env, obj);
4676 /* destroy stripes after lmu_stripe_count */
4677 mdd_write_lock(env, obj, MOR_SRC_PARENT);
4678 rc = mdd_dir_iterate_stripes(env, obj, lmv_buf, &shrink_buf, handle,
4679 mdd_dir_destroy_stripe);
4680 mdd_write_unlock(env, obj);
4682 if (le32_to_cpu(lmu->lum_stripe_count) > 1) {
4683 /* update dir LMV, that's all if it's still striped. */
4684 lmv->lmv_stripe_count = lmu->lum_stripe_count;
4685 lmv->lmv_hash_type &= ~cpu_to_le32(LMV_HASH_FLAG_MIGRATION);
4686 lmv->lmv_migrate_offset = 0;
4687 lmv->lmv_migrate_hash = 0;
4688 lmv->lmv_layout_version = cpu_to_le32(++version);
4690 lmv_buf->lb_len = sizeof(*lmv);
4691 rc = mdo_xattr_set(env, obj, lmv_buf, XATTR_NAME_LMV".set", 0,
4693 lmv_buf->lb_len = len;
4697 /* replace directory with its remaining stripe */
4701 mdd_write_lock(env, pobj, MOR_SRC_PARENT);
4702 mdd_write_lock(env, obj, MOR_SRC_CHILD);
4704 /* insert dotdot to stripe which points to parent */
4705 rc = __mdd_index_insert_only(env, stripe, mdo2fid(pobj), S_IFDIR,
4710 /* copy xattrs including linkea */
4711 rc = mdd_iterate_xattrs(env, obj, stripe, false, handle, mdo_xattr_set);
4716 rc = mdo_xattr_del(env, stripe, XATTR_NAME_LMV, handle);
4720 /* don't set nlink from parent */
4721 attr->la_valid &= ~LA_NLINK;
4723 rc = mdo_attr_set(env, stripe, attr, handle);
4727 /* delete dir name from parent */
4728 rc = __mdd_index_delete_only(env, pobj, lname->ln_name, handle);
4732 /* insert stripe to parent with dir name */
4733 rc = __mdd_index_insert_only(env, pobj, mdo2fid(stripe), attr->la_mode,
4734 lname->ln_name, handle);
4738 /* destroy dir obj */
4739 rc = mdo_ref_del(env, obj, handle);
4743 rc = mdo_ref_del(env, obj, handle);
4747 rc = mdo_destroy(env, obj, handle);
4753 mdd_write_unlock(env, obj);
4754 mdd_write_unlock(env, pobj);
4760 * shrink directory stripes to lum_stripe_count specified by lum_mds_md.
4762 int mdd_dir_layout_shrink(const struct lu_env *env,
4763 struct md_object *md_obj,
4764 const struct lu_buf *lmu_buf)
4766 struct mdd_device *mdd = mdo2mdd(md_obj);
4767 struct mdd_thread_info *info = mdd_env_info(env);
4768 struct mdd_object *obj = md2mdd_obj(md_obj);
4769 struct mdd_object *pobj = NULL;
4770 struct mdd_object *stripe = NULL;
4771 struct lu_attr *attr = &info->mti_pattr;
4772 struct lu_fid *fid = &info->mti_fid2;
4773 struct lu_name lname = { NULL };
4774 struct lu_buf lmv_buf = { NULL };
4775 struct lmv_mds_md_v1 *lmv;
4776 struct lmv_user_md *lmu;
4777 struct thandle *handle;
4782 rc = mdd_la_get(env, obj, attr);
4786 if (!S_ISDIR(attr->la_mode))
4789 rc = mdd_stripe_get(env, obj, &lmv_buf, XATTR_NAME_LMV);
4793 lmv = lmv_buf.lb_buf;
4794 lmu = lmu_buf->lb_buf;
4796 /* this was checked in MDT */
4797 LASSERT(le32_to_cpu(lmu->lum_stripe_count) <
4798 le32_to_cpu(lmv->lmv_stripe_count));
4800 rc = mdd_dir_iterate_stripes(env, obj, &lmv_buf, lmu_buf, NULL,
4801 mdd_shrink_stripe_is_empty);
4805 GOTO(out, rc = -ENOTEMPTY);
4808 * if obj stripe count will be shrunk to 1, we need to convert it to a
4809 * normal dir, which will change its fid and update parent namespace,
4810 * get obj name and parent fid from linkea.
4812 if (le32_to_cpu(lmu->lum_stripe_count) < 2) {
4813 struct linkea_data *ldata = &info->mti_link_data;
4814 char *filename = info->mti_name;
4816 rc = mdd_links_read(env, obj, ldata);
4820 if (ldata->ld_leh->leh_reccount > 1)
4821 GOTO(out, rc = -EINVAL);
4823 linkea_first_entry(ldata);
4825 GOTO(out, rc = -ENODATA);
4827 linkea_entry_unpack(ldata->ld_lee, &ldata->ld_reclen, &lname,
4830 /* Note: lname might miss \0 at the end */
4831 snprintf(filename, sizeof(info->mti_name), "%.*s",
4832 lname.ln_namelen, lname.ln_name);
4833 lname.ln_name = filename;
4835 pobj = mdd_object_find(env, mdd, fid);
4842 fid_le_to_cpu(fid, &lmv->lmv_stripe_fids[0]);
4844 stripe = mdd_object_find(env, mdd, fid);
4845 if (IS_ERR(stripe)) {
4846 mdd_object_put(env, pobj);
4848 GOTO(out, rc = PTR_ERR(stripe));
4852 handle = mdd_trans_create(env, mdd);
4854 GOTO(out, rc = PTR_ERR(handle));
4856 rc = __mdd_dir_declare_layout_shrink(env, pobj, obj, stripe, attr,
4857 &lmv_buf, lmu_buf, &lname, handle);
4859 GOTO(stop_trans, rc);
4861 rc = mdd_declare_changelog_store(env, mdd, CL_LAYOUT, NULL, NULL,
4864 GOTO(stop_trans, rc);
4866 rc = mdd_trans_start(env, mdd, handle);
4868 GOTO(stop_trans, rc);
4870 rc = __mdd_dir_layout_shrink(env, pobj, obj, stripe, attr, &lmv_buf,
4871 lmu_buf, &lname, handle);
4873 GOTO(stop_trans, rc);
4875 rc = mdd_changelog_data_store_xattr(env, mdd, CL_LAYOUT, 0, obj,
4876 XATTR_NAME_LMV, handle);
4877 GOTO(stop_trans, rc);
4880 rc = mdd_trans_stop(env, mdd, rc, handle);
4883 mdd_object_put(env, stripe);
4884 mdd_object_put(env, pobj);
4886 lu_buf_free(&lmv_buf);
4890 const struct md_dir_operations mdd_dir_ops = {
4891 .mdo_is_subdir = mdd_is_subdir,
4892 .mdo_lookup = mdd_lookup,
4893 .mdo_create = mdd_create,
4894 .mdo_rename = mdd_rename,
4895 .mdo_link = mdd_link,
4896 .mdo_unlink = mdd_unlink,
4897 .mdo_create_data = mdd_create_data,
4898 .mdo_migrate = mdd_migrate,