4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2015, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/mdt/mdt_reint.c
38 * Lustre Metadata Target (mdt) reintegration routines
40 * Author: Peter Braam <braam@clusterfs.com>
41 * Author: Andreas Dilger <adilger@clusterfs.com>
42 * Author: Phil Schwan <phil@clusterfs.com>
43 * Author: Huang Hua <huanghua@clusterfs.com>
44 * Author: Yury Umanets <umka@clusterfs.com>
47 #define DEBUG_SUBSYSTEM S_MDS
49 #include <lprocfs_status.h>
50 #include "mdt_internal.h"
51 #include <lustre_lmv.h>
53 static inline void mdt_reint_init_ma(struct mdt_thread_info *info,
56 ma->ma_need = MA_INODE;
61 * Get version of object by fid.
63 * Return real version or ENOENT_VERSION if object doesn't exist
65 static void mdt_obj_version_get(struct mdt_thread_info *info,
66 struct mdt_object *o, __u64 *version)
69 if (mdt_object_exists(o) && !mdt_object_remote(o) &&
70 !fid_is_obf(mdt_object_fid(o)))
71 *version = dt_version_get(info->mti_env, mdt_obj2dt(o));
73 *version = ENOENT_VERSION;
74 CDEBUG(D_INODE, "FID "DFID" version is "LPX64"\n",
75 PFID(mdt_object_fid(o)), *version);
79 * Check version is correct.
81 * Should be called only during replay.
83 static int mdt_version_check(struct ptlrpc_request *req,
84 __u64 version, int idx)
86 __u64 *pre_ver = lustre_msg_get_versions(req->rq_reqmsg);
89 if (!exp_connect_vbr(req->rq_export))
92 LASSERT(req_is_replay(req));
93 /** VBR: version is checked always because costs nothing */
94 LASSERT(idx < PTLRPC_NUM_VERSIONS);
95 /** Sanity check for malformed buffers */
96 if (pre_ver == NULL) {
97 CERROR("No versions in request buffer\n");
98 spin_lock(&req->rq_export->exp_lock);
99 req->rq_export->exp_vbr_failed = 1;
100 spin_unlock(&req->rq_export->exp_lock);
102 } else if (pre_ver[idx] != version) {
103 CDEBUG(D_INODE, "Version mismatch "LPX64" != "LPX64"\n",
104 pre_ver[idx], version);
105 spin_lock(&req->rq_export->exp_lock);
106 req->rq_export->exp_vbr_failed = 1;
107 spin_unlock(&req->rq_export->exp_lock);
114 * Save pre-versions in reply.
116 static void mdt_version_save(struct ptlrpc_request *req, __u64 version,
121 if (!exp_connect_vbr(req->rq_export))
124 LASSERT(!req_is_replay(req));
125 LASSERT(req->rq_repmsg != NULL);
126 reply_ver = lustre_msg_get_versions(req->rq_repmsg);
128 reply_ver[idx] = version;
132 * Save enoent version, it is needed when it is obvious that object doesn't
133 * exist, e.g. child during create.
135 static void mdt_enoent_version_save(struct mdt_thread_info *info, int idx)
137 /* save version of file name for replay, it must be ENOENT here */
138 if (!req_is_replay(mdt_info_req(info))) {
139 info->mti_ver[idx] = ENOENT_VERSION;
140 mdt_version_save(mdt_info_req(info), info->mti_ver[idx], idx);
145 * Get version from disk and save in reply buffer.
147 * Versions are saved in reply only during normal operations not replays.
149 void mdt_version_get_save(struct mdt_thread_info *info,
150 struct mdt_object *mto, int idx)
152 /* don't save versions during replay */
153 if (!req_is_replay(mdt_info_req(info))) {
154 mdt_obj_version_get(info, mto, &info->mti_ver[idx]);
155 mdt_version_save(mdt_info_req(info), info->mti_ver[idx], idx);
160 * Get version from disk and check it, no save in reply.
162 int mdt_version_get_check(struct mdt_thread_info *info,
163 struct mdt_object *mto, int idx)
165 /* only check versions during replay */
166 if (!req_is_replay(mdt_info_req(info)))
169 mdt_obj_version_get(info, mto, &info->mti_ver[idx]);
170 return mdt_version_check(mdt_info_req(info), info->mti_ver[idx], idx);
174 * Get version from disk and check if recovery or just save.
176 int mdt_version_get_check_save(struct mdt_thread_info *info,
177 struct mdt_object *mto, int idx)
181 mdt_obj_version_get(info, mto, &info->mti_ver[idx]);
182 if (req_is_replay(mdt_info_req(info)))
183 rc = mdt_version_check(mdt_info_req(info), info->mti_ver[idx],
186 mdt_version_save(mdt_info_req(info), info->mti_ver[idx], idx);
191 * Lookup with version checking.
193 * This checks version of 'name'. Many reint functions uses 'name' for child not
194 * FID, therefore we need to get object by name and check its version.
196 static int mdt_lookup_version_check(struct mdt_thread_info *info,
197 struct mdt_object *p,
198 const struct lu_name *lname,
199 struct lu_fid *fid, int idx)
203 rc = mdo_lookup(info->mti_env, mdt_object_child(p), lname, fid,
205 /* Check version only during replay */
206 if (!req_is_replay(mdt_info_req(info)))
209 info->mti_ver[idx] = ENOENT_VERSION;
211 struct mdt_object *child;
212 child = mdt_object_find(info->mti_env, info->mti_mdt, fid);
213 if (likely(!IS_ERR(child))) {
214 mdt_obj_version_get(info, child, &info->mti_ver[idx]);
215 mdt_object_put(info->mti_env, child);
218 vbrc = mdt_version_check(mdt_info_req(info), info->mti_ver[idx], idx);
219 return vbrc ? vbrc : rc;
223 static inline int mdt_remote_permission_check(struct mdt_thread_info *info)
225 struct lu_ucred *uc = mdt_ucred(info);
226 struct mdt_device *mdt = info->mti_mdt;
228 if (!md_capable(uc, CFS_CAP_SYS_ADMIN)) {
229 if (uc->uc_gid != mdt->mdt_enable_remote_dir_gid &&
230 mdt->mdt_enable_remote_dir_gid != -1)
238 * mdt_remote_permission: Check whether the remote operation is permitted,
240 * Only sysadmin can create remote directory / striped directory,
241 * migrate directory and set default stripedEA on directory, unless
243 * lctl set_param mdt.*.enable_remote_dir_gid=allow_gid.
245 * param[in] info: mdt_thread_info.
247 * retval = 0 remote operation is allowed.
248 * < 0 remote operation is denied.
250 static int mdt_remote_permission(struct mdt_thread_info *info)
252 struct md_op_spec *spec = &info->mti_spec;
253 struct lu_attr *attr = &info->mti_attr.ma_attr;
254 struct obd_export *exp = mdt_info_req(info)->rq_export;
257 if (info->mti_rr.rr_opcode == REINT_MIGRATE) {
258 rc = mdt_remote_permission_check(info);
263 if (info->mti_rr.rr_opcode == REINT_CREATE &&
264 (S_ISDIR(attr->la_mode) && spec->u.sp_ea.eadata != NULL &&
265 spec->u.sp_ea.eadatalen != 0)) {
266 const struct lmv_user_md *lum = spec->u.sp_ea.eadata;
268 /* Only new clients can create remote dir( >= 2.4) and
269 * striped dir(>= 2.6), old client will return -ENOTSUPP */
270 if (!mdt_is_dne_client(exp))
273 if (le32_to_cpu(lum->lum_stripe_count) > 1 &&
274 !mdt_is_striped_client(exp))
277 rc = mdt_remote_permission_check(info);
282 if (info->mti_rr.rr_opcode == REINT_SETATTR) {
283 struct md_attr *ma = &info->mti_attr;
285 if ((ma->ma_valid & MA_LMV)) {
286 rc = mdt_remote_permission_check(info);
296 * VBR: we save three versions in reply:
297 * 0 - parent. Check that parent version is the same during replay.
298 * 1 - name. Version of 'name' if file exists with the same name or
299 * ENOENT_VERSION, it is needed because file may appear due to missed replays.
300 * 2 - child. Version of child by FID. Must be ENOENT. It is mostly sanity
303 static int mdt_md_create(struct mdt_thread_info *info)
305 struct mdt_device *mdt = info->mti_mdt;
306 struct mdt_object *parent;
307 struct mdt_object *child;
308 struct mdt_lock_handle *lh;
309 struct mdt_body *repbody;
310 struct md_attr *ma = &info->mti_attr;
311 struct mdt_reint_record *rr = &info->mti_rr;
315 DEBUG_REQ(D_INODE, mdt_info_req(info), "Create ("DNAME"->"DFID") "
317 PNAME(&rr->rr_name), PFID(rr->rr_fid2), PFID(rr->rr_fid1));
319 if (!fid_is_md_operative(rr->rr_fid1))
322 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
324 parent = mdt_object_find(info->mti_env, info->mti_mdt, rr->rr_fid1);
326 RETURN(PTR_ERR(parent));
328 if (!mdt_object_exists(parent))
329 GOTO(put_parent, rc = -ENOENT);
331 lh = &info->mti_lh[MDT_LH_PARENT];
332 mdt_lock_pdo_init(lh, LCK_PW, &rr->rr_name);
333 rc = mdt_object_lock(info, parent, lh, MDS_INODELOCK_UPDATE);
335 GOTO(put_parent, rc);
337 if (!mdt_object_remote(parent)) {
338 rc = mdt_version_get_check_save(info, parent, 0);
340 GOTO(unlock_parent, rc);
344 * Check child name version during replay.
345 * During create replay a file may exist with same name.
347 rc = mdt_lookup_version_check(info, parent, &rr->rr_name,
348 &info->mti_tmp_fid1, 1);
350 GOTO(unlock_parent, rc = -EEXIST);
352 /* -ENOENT is expected here */
354 GOTO(unlock_parent, rc);
356 /* save version of file name for replay, it must be ENOENT here */
357 mdt_enoent_version_save(info, 1);
359 child = mdt_object_new(info->mti_env, mdt, rr->rr_fid2);
360 if (likely(!IS_ERR(child))) {
361 struct md_object *next = mdt_object_child(parent);
363 rc = mdt_remote_permission(info);
365 GOTO(out_put_child, rc);
367 ma->ma_need = MA_INODE;
370 mdt_fail_write(info->mti_env, info->mti_mdt->mdt_bottom,
371 OBD_FAIL_MDS_REINT_CREATE_WRITE);
373 /* Version of child will be updated on disk. */
374 tgt_vbr_obj_set(info->mti_env, mdt_obj2dt(child));
375 rc = mdt_version_get_check_save(info, child, 2);
377 GOTO(out_put_child, rc);
379 /* Let lower layer know current lock mode. */
380 info->mti_spec.sp_cr_mode =
381 mdt_dlm_mode2mdl_mode(lh->mlh_pdo_mode);
384 * Do not perform lookup sanity check. We know that name does
387 info->mti_spec.sp_cr_lookup = 0;
388 info->mti_spec.sp_feat = &dt_directory_features;
390 rc = mdo_create(info->mti_env, next, &rr->rr_name,
391 mdt_object_child(child), &info->mti_spec, ma);
393 rc = mdt_attr_get_complex(info, child, ma);
396 /* Return fid & attr to client. */
397 if (ma->ma_valid & MA_INODE)
398 mdt_pack_attr2body(info, repbody, &ma->ma_attr,
399 mdt_object_fid(child));
402 mdt_object_put(info->mti_env, child);
407 mdt_object_unlock(info, parent, lh, rc);
409 mdt_object_put(info->mti_env, parent);
413 static int mdt_unlock_slaves(struct mdt_thread_info *mti,
414 struct mdt_object *obj, __u64 ibits,
415 struct mdt_lock_handle *s0_lh,
416 struct mdt_object *s0_obj,
417 struct ldlm_enqueue_info *einfo)
419 union ldlm_policy_data *policy = &mti->mti_policy;
423 if (!S_ISDIR(obj->mot_header.loh_attr))
426 /* Unlock stripe 0 */
427 if (s0_lh != NULL && lustre_handle_is_used(&s0_lh->mlh_reg_lh)) {
428 LASSERT(s0_obj != NULL);
429 mdt_object_unlock_put(mti, s0_obj, s0_lh, 1);
432 memset(policy, 0, sizeof(*policy));
433 policy->l_inodebits.bits = ibits;
435 rc = mo_object_unlock(mti->mti_env, mdt_object_child(obj), einfo,
441 * Lock slave stripes if necessary, the lock handles of slave stripes
442 * will be stored in einfo->ei_cbdata.
444 static int mdt_lock_slaves(struct mdt_thread_info *mti, struct mdt_object *obj,
445 enum ldlm_mode mode, __u64 ibits,
446 struct mdt_lock_handle *s0_lh,
447 struct mdt_object **s0_objp,
448 struct ldlm_enqueue_info *einfo)
450 union ldlm_policy_data *policy = &mti->mti_policy;
451 struct lu_buf *buf = &mti->mti_buf;
452 struct lmv_mds_md_v1 *lmv;
453 struct lu_fid *fid = &mti->mti_tmp_fid1;
457 if (!S_ISDIR(obj->mot_header.loh_attr))
460 buf->lb_buf = mti->mti_xattr_buf;
461 buf->lb_len = sizeof(mti->mti_xattr_buf);
462 rc = mo_xattr_get(mti->mti_env, mdt_object_child(obj), buf,
465 rc = mdt_big_xattr_get(mti, obj, XATTR_NAME_LMV);
467 buf->lb_buf = mti->mti_big_lmm;
468 buf->lb_len = mti->mti_big_lmmsize;
472 if (rc == -ENODATA || rc == -ENOENT)
479 if (le32_to_cpu(lmv->lmv_magic) != LMV_MAGIC_V1)
482 fid_le_to_cpu(fid, &lmv->lmv_stripe_fids[0]);
483 if (!lu_fid_eq(fid, mdt_object_fid(obj))) {
484 /* Except migrating object, whose 0_stripe and master
485 * object are the same object, 0_stripe and master
486 * object are different, though they are in the same
487 * MDT, to avoid adding osd_object_lock here, so we
488 * will enqueue the stripe0 lock in MDT0 for now */
489 *s0_objp = mdt_object_find_lock(mti, fid, s0_lh, ibits);
490 if (IS_ERR(*s0_objp))
491 RETURN(PTR_ERR(*s0_objp));
494 memset(einfo, 0, sizeof(*einfo));
495 einfo->ei_type = LDLM_IBITS;
496 einfo->ei_mode = mode;
497 einfo->ei_cb_bl = mdt_remote_blocking_ast;
498 einfo->ei_cb_local_bl = mdt_blocking_ast;
499 einfo->ei_cb_cp = ldlm_completion_ast;
500 einfo->ei_enq_slave = 1;
501 einfo->ei_namespace = mti->mti_mdt->mdt_namespace;
502 memset(policy, 0, sizeof(*policy));
503 policy->l_inodebits.bits = ibits;
505 rc = mo_object_lock(mti->mti_env, mdt_object_child(obj), NULL, einfo,
510 static int mdt_attr_set(struct mdt_thread_info *info, struct mdt_object *mo,
513 struct mdt_lock_handle *lh;
514 int do_vbr = ma->ma_attr.la_valid & (LA_MODE|LA_UID|LA_GID|LA_FLAGS);
515 __u64 lockpart = MDS_INODELOCK_UPDATE;
516 struct ldlm_enqueue_info *einfo = &info->mti_einfo;
517 struct mdt_lock_handle *s0_lh;
518 struct mdt_object *s0_obj = NULL;
522 lh = &info->mti_lh[MDT_LH_PARENT];
523 mdt_lock_reg_init(lh, LCK_PW);
525 /* Even though the new MDT will grant PERM lock to the old
526 * client, but the old client will almost ignore that during
527 * So it needs to revoke both LOOKUP and PERM lock here, so
528 * both new and old client can cancel the dcache */
529 if (ma->ma_attr.la_valid & (LA_MODE|LA_UID|LA_GID))
530 lockpart |= MDS_INODELOCK_LOOKUP | MDS_INODELOCK_PERM;
532 rc = mdt_object_lock(info, mo, lh, lockpart);
536 s0_lh = &info->mti_lh[MDT_LH_LOCAL];
537 mdt_lock_reg_init(s0_lh, LCK_PW);
538 rc = mdt_lock_slaves(info, mo, LCK_PW, lockpart, s0_lh, &s0_obj, einfo);
540 GOTO(out_unlock, rc);
542 /* all attrs are packed into mti_attr in unpack_setattr */
543 mdt_fail_write(info->mti_env, info->mti_mdt->mdt_bottom,
544 OBD_FAIL_MDS_REINT_SETATTR_WRITE);
546 /* This is only for set ctime when rename's source is on remote MDS. */
547 if (unlikely(ma->ma_attr.la_valid == LA_CTIME))
548 ma->ma_attr_flags |= MDS_VTX_BYPASS;
550 /* VBR: update version if attr changed are important for recovery */
552 /* update on-disk version of changed object */
553 tgt_vbr_obj_set(info->mti_env, mdt_obj2dt(mo));
554 rc = mdt_version_get_check_save(info, mo, 0);
556 GOTO(out_unlock, rc);
559 /* Ensure constant striping during chown(). See LU-2789. */
560 if (ma->ma_attr.la_valid & (LA_UID|LA_GID))
561 mutex_lock(&mo->mot_lov_mutex);
563 /* all attrs are packed into mti_attr in unpack_setattr */
564 rc = mo_attr_set(info->mti_env, mdt_object_child(mo), ma);
566 if (ma->ma_attr.la_valid & (LA_UID|LA_GID))
567 mutex_unlock(&mo->mot_lov_mutex);
570 GOTO(out_unlock, rc);
574 mdt_unlock_slaves(info, mo, lockpart, s0_lh, s0_obj, einfo);
575 mdt_object_unlock(info, mo, lh, rc);
580 * Check HSM flags and add HS_DIRTY flag if relevant.
582 * A file could be set dirty only if it has a copy in the backend (HS_EXISTS)
583 * and is not RELEASED.
585 int mdt_add_dirty_flag(struct mdt_thread_info *info, struct mdt_object *mo,
591 /* If the file was modified, add the dirty flag */
592 ma->ma_need = MA_HSM;
593 rc = mdt_attr_get_complex(info, mo, ma);
595 CERROR("file attribute read error for "DFID": %d.\n",
596 PFID(mdt_object_fid(mo)), rc);
600 /* If an up2date copy exists in the backend, add dirty flag */
601 if ((ma->ma_valid & MA_HSM) && (ma->ma_hsm.mh_flags & HS_EXISTS)
602 && !(ma->ma_hsm.mh_flags & (HS_DIRTY|HS_RELEASED))) {
603 struct mdt_lock_handle *lh = &info->mti_lh[MDT_LH_CHILD];
605 ma->ma_hsm.mh_flags |= HS_DIRTY;
607 mdt_lock_reg_init(lh, LCK_PW);
608 rc = mdt_object_lock(info, mo, lh, MDS_INODELOCK_XATTR);
612 rc = mdt_hsm_attr_set(info, mo, &ma->ma_hsm);
614 CERROR("file attribute change error for "DFID": %d\n",
615 PFID(mdt_object_fid(mo)), rc);
616 mdt_object_unlock(info, mo, lh, rc);
622 static int mdt_reint_setattr(struct mdt_thread_info *info,
623 struct mdt_lock_handle *lhc)
625 struct md_attr *ma = &info->mti_attr;
626 struct mdt_reint_record *rr = &info->mti_rr;
627 struct ptlrpc_request *req = mdt_info_req(info);
628 struct mdt_object *mo;
629 struct mdt_body *repbody;
633 DEBUG_REQ(D_INODE, req, "setattr "DFID" %x", PFID(rr->rr_fid1),
634 (unsigned int)ma->ma_attr.la_valid);
636 if (info->mti_dlm_req)
637 ldlm_request_cancel(req, info->mti_dlm_req, 0, LATF_SKIP);
639 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
640 mo = mdt_object_find(info->mti_env, info->mti_mdt, rr->rr_fid1);
642 GOTO(out, rc = PTR_ERR(mo));
644 if (!mdt_object_exists(mo))
645 GOTO(out_put, rc = -ENOENT);
647 if (mdt_object_remote(mo))
648 GOTO(out_put, rc = -EREMOTE);
650 if ((ma->ma_attr.la_valid & LA_SIZE) ||
651 (rr->rr_flags & MRF_OPEN_TRUNC)) {
652 /* Check write access for the O_TRUNC case */
653 if (mdt_write_read(mo) < 0)
654 GOTO(out_put, rc = -ETXTBSY);
657 if ((ma->ma_valid & MA_INODE) && ma->ma_attr.la_valid) {
658 if (ma->ma_valid & MA_LOV)
659 GOTO(out_put, rc = -EPROTO);
661 rc = mdt_attr_set(info, mo, ma);
664 } else if ((ma->ma_valid & MA_LOV) && (ma->ma_valid & MA_INODE)) {
665 struct lu_buf *buf = &info->mti_buf;
667 if (ma->ma_attr.la_valid != 0)
668 GOTO(out_put, rc = -EPROTO);
670 buf->lb_buf = ma->ma_lmm;
671 buf->lb_len = ma->ma_lmm_size;
672 rc = mo_xattr_set(info->mti_env, mdt_object_child(mo),
673 buf, XATTR_NAME_LOV, 0);
676 } else if ((ma->ma_valid & MA_LMV) && (ma->ma_valid & MA_INODE)) {
677 struct lu_buf *buf = &info->mti_buf;
678 struct mdt_lock_handle *lh;
680 rc = mdt_remote_permission(info);
684 if (ma->ma_attr.la_valid != 0)
685 GOTO(out_put, rc = -EPROTO);
687 lh = &info->mti_lh[MDT_LH_PARENT];
688 mdt_lock_reg_init(lh, LCK_PW);
690 rc = mdt_object_lock(info, mo, lh,
691 MDS_INODELOCK_XATTR);
695 buf->lb_buf = ma->ma_lmv;
696 buf->lb_len = ma->ma_lmv_size;
697 rc = mo_xattr_set(info->mti_env, mdt_object_child(mo),
698 buf, XATTR_NAME_DEFAULT_LMV, 0);
700 mdt_object_unlock(info, mo, lh, rc);
704 GOTO(out_put, rc = -EPROTO);
707 /* If file data is modified, add the dirty flag */
708 if (ma->ma_attr_flags & MDS_DATA_MODIFIED)
709 rc = mdt_add_dirty_flag(info, mo, ma);
711 ma->ma_need = MA_INODE;
713 rc = mdt_attr_get_complex(info, mo, ma);
717 mdt_pack_attr2body(info, repbody, &ma->ma_attr, mdt_object_fid(mo));
721 mdt_object_put(info->mti_env, mo);
724 mdt_counter_incr(req, LPROC_MDT_SETATTR);
726 mdt_client_compatibility(info);
727 rc2 = mdt_fix_reply(info);
733 static int mdt_reint_create(struct mdt_thread_info *info,
734 struct mdt_lock_handle *lhc)
736 struct ptlrpc_request *req = mdt_info_req(info);
740 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_CREATE))
741 RETURN(err_serious(-ESTALE));
743 if (info->mti_dlm_req)
744 ldlm_request_cancel(mdt_info_req(info),
745 info->mti_dlm_req, 0, LATF_SKIP);
747 if (!lu_name_is_valid(&info->mti_rr.rr_name))
750 switch (info->mti_attr.ma_attr.la_mode & S_IFMT) {
752 mdt_counter_incr(req, LPROC_MDT_MKDIR);
760 /* Special file should stay on the same node as parent. */
761 mdt_counter_incr(req, LPROC_MDT_MKNOD);
764 CERROR("%s: Unsupported mode %o\n",
765 mdt_obd_name(info->mti_mdt),
766 info->mti_attr.ma_attr.la_mode);
767 RETURN(err_serious(-EOPNOTSUPP));
770 rc = mdt_md_create(info);
775 * VBR: save parent version in reply and child version getting by its name.
776 * Version of child is getting and checking during its lookup. If
778 static int mdt_reint_unlink(struct mdt_thread_info *info,
779 struct mdt_lock_handle *lhc)
781 struct mdt_reint_record *rr = &info->mti_rr;
782 struct ptlrpc_request *req = mdt_info_req(info);
783 struct md_attr *ma = &info->mti_attr;
784 struct lu_fid *child_fid = &info->mti_tmp_fid1;
785 struct mdt_object *mp;
786 struct mdt_object *mc;
787 struct mdt_lock_handle *parent_lh;
788 struct mdt_lock_handle *child_lh;
789 struct ldlm_enqueue_info *einfo = &info->mti_einfo;
790 struct mdt_lock_handle *s0_lh = NULL;
791 struct mdt_object *s0_obj = NULL;
797 DEBUG_REQ(D_INODE, req, "unlink "DFID"/"DNAME"", PFID(rr->rr_fid1),
798 PNAME(&rr->rr_name));
800 if (info->mti_dlm_req)
801 ldlm_request_cancel(req, info->mti_dlm_req, 0, LATF_SKIP);
803 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_UNLINK))
804 RETURN(err_serious(-ENOENT));
806 if (!fid_is_md_operative(rr->rr_fid1))
810 * step 1: Found the parent.
812 mp = mdt_object_find(info->mti_env, info->mti_mdt, rr->rr_fid1);
818 parent_lh = &info->mti_lh[MDT_LH_PARENT];
819 mdt_lock_pdo_init(parent_lh, LCK_PW, &rr->rr_name);
820 rc = mdt_object_lock(info, mp, parent_lh, MDS_INODELOCK_UPDATE);
822 GOTO(put_parent, rc);
824 if (!mdt_object_remote(mp)) {
825 rc = mdt_version_get_check_save(info, mp, 0);
827 GOTO(unlock_parent, rc);
830 /* step 2: find & lock the child */
831 /* lookup child object along with version checking */
833 rc = mdt_lookup_version_check(info, mp, &rr->rr_name, child_fid, 1);
835 /* Name might not be able to find during resend of
836 * remote unlink, considering following case.
837 * dir_A is a remote directory, the name entry of
838 * dir_A is on MDT0, the directory is on MDT1,
840 * 1. client sends unlink req to MDT1.
841 * 2. MDT1 sends name delete update to MDT0.
842 * 3. name entry is being deleted in MDT0 synchronously.
843 * 4. MDT1 is restarted.
844 * 5. client resends unlink req to MDT1. So it can not
845 * find the name entry on MDT0 anymore.
846 * In this case, MDT1 only needs to destory the local
849 if (mdt_object_remote(mp) && rc == -ENOENT &&
850 !fid_is_zero(rr->rr_fid2) &&
851 lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT) {
853 *child_fid = *rr->rr_fid2;
855 GOTO(unlock_parent, rc);
859 if (!fid_is_md_operative(child_fid))
860 GOTO(unlock_parent, rc = -EPERM);
862 /* We will lock the child regardless it is local or remote. No harm. */
863 mc = mdt_object_find(info->mti_env, info->mti_mdt, child_fid);
865 GOTO(unlock_parent, rc = PTR_ERR(mc));
867 child_lh = &info->mti_lh[MDT_LH_CHILD];
868 mdt_lock_reg_init(child_lh, LCK_EX);
869 if (info->mti_spec.sp_rm_entry) {
870 struct lu_ucred *uc = mdt_ucred(info);
872 if (!mdt_is_dne_client(req->rq_export))
873 /* Return -ENOTSUPP for old client */
874 GOTO(put_child, rc = -ENOTSUPP);
876 if (!md_capable(uc, CFS_CAP_SYS_ADMIN))
877 GOTO(put_child, rc = -EPERM);
879 ma->ma_need = MA_INODE;
881 rc = mdo_unlink(info->mti_env, mdt_object_child(mp),
882 NULL, &rr->rr_name, ma, no_name);
886 if (mdt_object_remote(mc)) {
887 struct mdt_body *repbody;
889 if (!fid_is_zero(rr->rr_fid2)) {
890 CDEBUG(D_INFO, "%s: name "DNAME" cannot find "DFID"\n",
891 mdt_obd_name(info->mti_mdt),
892 PNAME(&rr->rr_name), PFID(mdt_object_fid(mc)));
893 GOTO(put_child, rc = -ENOENT);
895 CDEBUG(D_INFO, "%s: name "DNAME": "DFID" is on another MDT\n",
896 mdt_obd_name(info->mti_mdt),
897 PNAME(&rr->rr_name), PFID(mdt_object_fid(mc)));
899 if (!mdt_is_dne_client(req->rq_export))
900 /* Return -ENOTSUPP for old client */
901 GOTO(put_child, rc = -ENOTSUPP);
903 /* Revoke the LOOKUP lock of the remote object granted by
904 * this MDT. Since the unlink will happen on another MDT,
905 * it will release the LOOKUP lock right away. Then What
906 * would happen if another client try to grab the LOOKUP
907 * lock at the same time with unlink XXX */
908 mdt_object_lock(info, mc, child_lh, MDS_INODELOCK_LOOKUP);
909 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
910 LASSERT(repbody != NULL);
911 repbody->mbo_fid1 = *mdt_object_fid(mc);
912 repbody->mbo_valid |= (OBD_MD_FLID | OBD_MD_MDS);
913 GOTO(unlock_child, rc = -EREMOTE);
915 /* We used to acquire MDS_INODELOCK_FULL here but we can't do
916 * this now because a running HSM restore on the child (unlink
917 * victim) will hold the layout lock. See LU-4002. */
918 lock_ibits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE;
919 if (mdt_object_remote(mp)) {
920 /* Enqueue lookup lock from parent MDT */
921 rc = mdt_remote_object_lock(info, mp, mdt_object_fid(mc),
922 &child_lh->mlh_rreg_lh,
923 child_lh->mlh_rreg_mode,
924 MDS_INODELOCK_LOOKUP, false);
928 lock_ibits &= ~MDS_INODELOCK_LOOKUP;
931 rc = mdt_object_lock(info, mc, child_lh, lock_ibits);
935 * Now we can only make sure we need MA_INODE, in mdd layer, will check
936 * whether need MA_LOV and MA_COOKIE.
938 ma->ma_need = MA_INODE;
941 s0_lh = &info->mti_lh[MDT_LH_LOCAL];
942 mdt_lock_reg_init(s0_lh, LCK_EX);
943 rc = mdt_lock_slaves(info, mc, LCK_EX, MDS_INODELOCK_UPDATE, s0_lh,
946 GOTO(unlock_child, rc);
948 mdt_fail_write(info->mti_env, info->mti_mdt->mdt_bottom,
949 OBD_FAIL_MDS_REINT_UNLINK_WRITE);
950 /* save version when object is locked */
951 mdt_version_get_save(info, mc, 1);
953 mutex_lock(&mc->mot_lov_mutex);
955 rc = mdo_unlink(info->mti_env, mdt_object_child(mp),
956 mdt_object_child(mc), &rr->rr_name, ma, no_name);
958 mutex_unlock(&mc->mot_lov_mutex);
960 if (rc == 0 && !lu_object_is_dying(&mc->mot_header))
961 rc = mdt_attr_get_complex(info, mc, ma);
963 mdt_handle_last_unlink(info, mc, ma);
965 if (ma->ma_valid & MA_INODE) {
966 switch (ma->ma_attr.la_mode & S_IFMT) {
968 mdt_counter_incr(req, LPROC_MDT_RMDIR);
976 mdt_counter_incr(req, LPROC_MDT_UNLINK);
979 LASSERTF(0, "bad file type %o unlinking\n",
980 ma->ma_attr.la_mode);
987 mdt_unlock_slaves(info, mc, MDS_INODELOCK_UPDATE, s0_lh, s0_obj, einfo);
988 mdt_object_unlock(info, mc, child_lh, rc);
990 mdt_object_put(info->mti_env, mc);
992 mdt_object_unlock(info, mp, parent_lh, rc);
994 mdt_object_put(info->mti_env, mp);
1000 * VBR: save versions in reply: 0 - parent; 1 - child by fid; 2 - target by
1003 static int mdt_reint_link(struct mdt_thread_info *info,
1004 struct mdt_lock_handle *lhc)
1006 struct mdt_reint_record *rr = &info->mti_rr;
1007 struct ptlrpc_request *req = mdt_info_req(info);
1008 struct md_attr *ma = &info->mti_attr;
1009 struct mdt_object *ms;
1010 struct mdt_object *mp;
1011 struct mdt_lock_handle *lhs;
1012 struct mdt_lock_handle *lhp;
1016 DEBUG_REQ(D_INODE, req, "link "DFID" to "DFID"/"DNAME,
1017 PFID(rr->rr_fid1), PFID(rr->rr_fid2), PNAME(&rr->rr_name));
1019 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_LINK))
1020 RETURN(err_serious(-ENOENT));
1022 if (info->mti_dlm_req)
1023 ldlm_request_cancel(req, info->mti_dlm_req, 0, LATF_SKIP);
1025 /* Invalid case so return error immediately instead of
1027 if (lu_fid_eq(rr->rr_fid1, rr->rr_fid2))
1030 if (!fid_is_md_operative(rr->rr_fid1) ||
1031 !fid_is_md_operative(rr->rr_fid2))
1034 /* step 1: find & lock the target parent dir */
1035 lhp = &info->mti_lh[MDT_LH_PARENT];
1036 mdt_lock_pdo_init(lhp, LCK_PW, &rr->rr_name);
1037 mp = mdt_object_find_lock(info, rr->rr_fid2, lhp,
1038 MDS_INODELOCK_UPDATE);
1040 RETURN(PTR_ERR(mp));
1042 rc = mdt_version_get_check_save(info, mp, 0);
1044 GOTO(out_unlock_parent, rc);
1046 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RENAME3, 5);
1048 /* step 2: find & lock the source */
1049 lhs = &info->mti_lh[MDT_LH_CHILD];
1050 mdt_lock_reg_init(lhs, LCK_EX);
1052 ms = mdt_object_find(info->mti_env, info->mti_mdt, rr->rr_fid1);
1054 GOTO(out_unlock_parent, rc = PTR_ERR(ms));
1056 if (!mdt_object_exists(ms)) {
1057 mdt_object_put(info->mti_env, ms);
1058 CDEBUG(D_INFO, "%s: "DFID" does not exist.\n",
1059 mdt_obd_name(info->mti_mdt), PFID(rr->rr_fid1));
1060 GOTO(out_unlock_parent, rc = -ENOENT);
1063 rc = mdt_object_lock(info, ms, lhs, MDS_INODELOCK_UPDATE |
1064 MDS_INODELOCK_XATTR);
1066 mdt_object_put(info->mti_env, ms);
1067 GOTO(out_unlock_parent, rc);
1070 /* step 3: link it */
1071 mdt_fail_write(info->mti_env, info->mti_mdt->mdt_bottom,
1072 OBD_FAIL_MDS_REINT_LINK_WRITE);
1074 tgt_vbr_obj_set(info->mti_env, mdt_obj2dt(ms));
1075 rc = mdt_version_get_check_save(info, ms, 1);
1077 GOTO(out_unlock_child, rc);
1079 /** check target version by name during replay */
1080 rc = mdt_lookup_version_check(info, mp, &rr->rr_name,
1081 &info->mti_tmp_fid1, 2);
1082 if (rc != 0 && rc != -ENOENT)
1083 GOTO(out_unlock_child, rc);
1084 /* save version of file name for replay, it must be ENOENT here */
1085 if (!req_is_replay(mdt_info_req(info))) {
1086 if (rc != -ENOENT) {
1087 CDEBUG(D_INFO, "link target "DNAME" existed!\n",
1088 PNAME(&rr->rr_name));
1089 GOTO(out_unlock_child, rc = -EEXIST);
1091 info->mti_ver[2] = ENOENT_VERSION;
1092 mdt_version_save(mdt_info_req(info), info->mti_ver[2], 2);
1095 rc = mdo_link(info->mti_env, mdt_object_child(mp),
1096 mdt_object_child(ms), &rr->rr_name, ma);
1099 mdt_counter_incr(req, LPROC_MDT_LINK);
1103 mdt_object_unlock_put(info, ms, lhs, rc);
1105 mdt_object_unlock_put(info, mp, lhp, rc);
1109 * lock the part of the directory according to the hash of the name
1110 * (lh->mlh_pdo_hash) in parallel directory lock.
1112 static int mdt_pdir_hash_lock(struct mdt_thread_info *info,
1113 struct mdt_lock_handle *lh,
1114 struct mdt_object *obj, __u64 ibits)
1116 struct ldlm_res_id *res = &info->mti_res_id;
1117 struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
1118 union ldlm_policy_data *policy = &info->mti_policy;
1122 * Finish res_id initializing by name hash marking part of
1123 * directory which is taking modification.
1125 LASSERT(lh->mlh_pdo_hash != 0);
1126 fid_build_pdo_res_name(mdt_object_fid(obj), lh->mlh_pdo_hash, res);
1127 memset(policy, 0, sizeof(*policy));
1128 policy->l_inodebits.bits = ibits;
1130 * Use LDLM_FL_LOCAL_ONLY for this lock. We do not know yet if it is
1131 * going to be sent to client. If it is - mdt_intent_policy() path will
1132 * fix it up and turn FL_LOCAL flag off.
1134 rc = mdt_fid_lock(ns, &lh->mlh_reg_lh, lh->mlh_reg_mode, policy,
1135 res, LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB,
1136 &info->mti_exp->exp_handle.h_cookie);
1141 * Get BFL lock for rename or migrate process.
1143 static int mdt_rename_lock(struct mdt_thread_info *info,
1144 struct lustre_handle *lh)
1149 if (mdt_seq_site(info->mti_mdt)->ss_node_id != 0) {
1150 struct lu_fid *fid = &info->mti_tmp_fid1;
1151 struct mdt_object *obj;
1153 /* XXX, right now, it has to use object API to
1154 * enqueue lock cross MDT, so it will enqueue
1155 * rename lock(with LUSTRE_BFL_FID) by root object */
1157 obj = mdt_object_find(info->mti_env, info->mti_mdt, fid);
1159 RETURN(PTR_ERR(obj));
1161 rc = mdt_remote_object_lock(info, obj,
1162 &LUSTRE_BFL_FID, lh,
1164 MDS_INODELOCK_UPDATE, false);
1165 mdt_object_put(info->mti_env, obj);
1167 struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
1168 union ldlm_policy_data *policy = &info->mti_policy;
1169 struct ldlm_res_id *res_id = &info->mti_res_id;
1172 fid_build_reg_res_name(&LUSTRE_BFL_FID, res_id);
1173 memset(policy, 0, sizeof *policy);
1174 policy->l_inodebits.bits = MDS_INODELOCK_UPDATE;
1175 flags = LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB;
1176 rc = ldlm_cli_enqueue_local(ns, res_id, LDLM_IBITS, policy,
1177 LCK_EX, &flags, ldlm_blocking_ast,
1178 ldlm_completion_ast, NULL, NULL, 0,
1180 &info->mti_exp->exp_handle.h_cookie,
1187 static void mdt_rename_unlock(struct lustre_handle *lh)
1190 LASSERT(lustre_handle_is_used(lh));
1191 /* Cancel the single rename lock right away */
1192 ldlm_lock_decref_and_cancel(lh, LCK_EX);
1197 * This is is_subdir() variant, it is CMD if cmm forwards it to correct
1198 * target. Source should not be ancestor of target dir. May be other rename
1199 * checks can be moved here later.
1201 static int mdt_is_subdir(struct mdt_thread_info *info,
1202 struct mdt_object *dir,
1203 const struct lu_fid *fid)
1205 struct lu_fid dir_fid = dir->mot_header.loh_fid;
1209 /* If the source and target are in the same directory, they can not
1210 * be parent/child relationship, so subdir check is not needed */
1211 if (lu_fid_eq(&dir_fid, fid))
1214 if (!mdt_object_exists(dir))
1217 rc = mdo_is_subdir(info->mti_env, mdt_object_child(dir),
1220 CERROR("%s: failed subdir check in "DFID" for "DFID
1221 ": rc = %d\n", mdt_obd_name(info->mti_mdt),
1222 PFID(&dir_fid), PFID(fid), rc);
1223 /* Return EINVAL only if a parent is the @fid */
1227 /* check the found fid */
1228 if (lu_fid_eq(&dir_fid, fid))
1235 /* Update object linkEA */
1236 struct mdt_lock_list {
1237 struct mdt_object *mll_obj;
1238 struct mdt_lock_handle mll_lh;
1239 struct list_head mll_list;
1242 static void mdt_unlock_list(struct mdt_thread_info *info,
1243 struct list_head *list, int rc)
1245 struct mdt_lock_list *mll;
1246 struct mdt_lock_list *mll2;
1248 list_for_each_entry_safe(mll, mll2, list, mll_list) {
1249 mdt_object_unlock_put(info, mll->mll_obj, &mll->mll_lh, rc);
1250 list_del(&mll->mll_list);
1255 static int mdt_lock_objects_in_linkea(struct mdt_thread_info *info,
1256 struct mdt_object *obj,
1257 struct mdt_object *pobj,
1258 struct list_head *lock_list)
1260 struct lu_buf *buf = &info->mti_big_buf;
1261 struct linkea_data ldata = { NULL };
1267 if (S_ISDIR(lu_object_attr(&obj->mot_obj)))
1270 buf = lu_buf_check_and_alloc(buf, PATH_MAX);
1271 if (buf->lb_buf == NULL)
1275 rc = mdt_links_read(info, obj, &ldata);
1277 if (rc == -ENOENT || rc == -ENODATA)
1282 /* ignore the migrating parent(@pobj) */
1283 retry_count = ldata.ld_leh->leh_reccount - 1;
1286 LASSERT(ldata.ld_leh != NULL);
1287 ldata.ld_lee = (struct link_ea_entry *)(ldata.ld_leh + 1);
1288 for (count = 0; count < ldata.ld_leh->leh_reccount; count++) {
1289 struct mdt_device *mdt = info->mti_mdt;
1290 struct mdt_object *mdt_pobj;
1291 struct mdt_lock_list *mll;
1292 struct lu_name name;
1295 linkea_entry_unpack(ldata.ld_lee, &ldata.ld_reclen,
1297 mdt_pobj = mdt_object_find(info->mti_env, mdt, &fid);
1298 if (IS_ERR(mdt_pobj)) {
1299 CWARN("%s: cannot find obj "DFID": rc = %ld\n",
1300 mdt_obd_name(mdt), PFID(&fid), PTR_ERR(mdt_pobj));
1304 if (!mdt_object_exists(mdt_pobj)) {
1305 CDEBUG(D_INFO, "%s: obj "DFID" does not exist\n",
1306 mdt_obd_name(mdt), PFID(&fid));
1307 mdt_object_put(info->mti_env, mdt_pobj);
1311 /* Check if the object already exists in the list */
1312 list_for_each_entry(mll, lock_list, mll_list) {
1313 if (mll->mll_obj == mdt_pobj) {
1314 mdt_object_put(info->mti_env, mdt_pobj);
1319 if (mdt_pobj == pobj) {
1320 CDEBUG(D_INFO, "%s: skipping parent obj "DFID"\n",
1321 mdt_obd_name(mdt), PFID(&fid));
1322 mdt_object_put(info->mti_env, mdt_pobj);
1328 mdt_object_put(info->mti_env, mdt_pobj);
1329 GOTO(out, rc = -ENOMEM);
1332 /* Since this needs to lock all of objects in linkea, to avoid
1333 * deadlocks, because it does not follow parent-child order as
1334 * other MDT operation, let's use try_lock here and if the lock
1335 * cannot be gotten because of conflicting locks, then drop all
1336 * current locks, send an AST to the client, and start again. */
1337 mdt_lock_pdo_init(&mll->mll_lh, LCK_PW, &name);
1338 rc = mdt_object_lock_try(info, mdt_pobj, &mll->mll_lh,
1339 MDS_INODELOCK_UPDATE);
1341 mdt_unlock_list(info, lock_list, rc);
1343 CDEBUG(D_INFO, "%s: busy lock on "DFID".\n",
1344 mdt_obd_name(mdt), PFID(&fid));
1346 if (retry_count == 0) {
1347 mdt_object_put(info->mti_env, mdt_pobj);
1349 GOTO(out, rc = -EBUSY);
1352 rc = mdt_object_lock(info, mdt_pobj, &mll->mll_lh,
1353 MDS_INODELOCK_UPDATE);
1355 mdt_object_put(info->mti_env, mdt_pobj);
1360 if (mdt_object_remote(mdt_pobj)) {
1361 struct ldlm_lock *lock;
1363 /* For remote object, Set lock to cb_atomic,
1364 * so lock can be released in blocking_ast()
1365 * immediately, then the next try_lock will
1366 * have better chance to succeds */
1368 ldlm_handle2lock(&mll->mll_lh.mlh_rreg_lh);
1369 LASSERT(lock != NULL);
1370 lock_res_and_lock(lock);
1371 ldlm_set_atomic_cb(lock);
1372 unlock_res_and_lock(lock);
1373 LDLM_LOCK_PUT(lock);
1375 mdt_object_unlock_put(info, mdt_pobj, &mll->mll_lh, rc);
1381 INIT_LIST_HEAD(&mll->mll_list);
1382 mll->mll_obj = mdt_pobj;
1383 list_add_tail(&mll->mll_list, lock_list);
1385 ldata.ld_lee = (struct link_ea_entry *)((char *)ldata.ld_lee +
1390 mdt_unlock_list(info, lock_list, rc);
1394 /* migrate files from one MDT to another MDT */
1395 static int mdt_reint_migrate_internal(struct mdt_thread_info *info,
1396 struct mdt_lock_handle *lhc)
1398 struct mdt_reint_record *rr = &info->mti_rr;
1399 struct md_attr *ma = &info->mti_attr;
1400 struct mdt_object *msrcdir;
1401 struct mdt_object *mold;
1402 struct mdt_object *mnew = NULL;
1403 struct mdt_lock_handle *lh_dirp;
1404 struct mdt_lock_handle *lh_childp;
1405 struct mdt_lock_handle *lh_tgtp = NULL;
1406 struct lu_fid *old_fid = &info->mti_tmp_fid1;
1407 struct list_head lock_list;
1409 struct ldlm_lock *lease = NULL;
1410 bool lock_open_sem = false;
1414 CDEBUG(D_INODE, "migrate "DFID"/"DNAME" to "DFID"\n", PFID(rr->rr_fid1),
1415 PNAME(&rr->rr_name), PFID(rr->rr_fid2));
1417 /* 1: lock the source dir. */
1418 msrcdir = mdt_object_find(info->mti_env, info->mti_mdt, rr->rr_fid1);
1419 if (IS_ERR(msrcdir)) {
1420 CERROR("%s: cannot find source dir "DFID" : rc = %d\n",
1421 mdt_obd_name(info->mti_mdt), PFID(rr->rr_fid1),
1422 (int)PTR_ERR(msrcdir));
1423 RETURN(PTR_ERR(msrcdir));
1426 lh_dirp = &info->mti_lh[MDT_LH_PARENT];
1427 mdt_lock_pdo_init(lh_dirp, LCK_PW, &rr->rr_name);
1428 rc = mdt_object_lock(info, msrcdir, lh_dirp,
1429 MDS_INODELOCK_UPDATE);
1431 GOTO(out_put_parent, rc);
1433 if (!mdt_object_remote(msrcdir)) {
1434 rc = mdt_version_get_check_save(info, msrcdir, 0);
1436 GOTO(out_unlock_parent, rc);
1439 /* 2: sanity check and find the object to be migrated. */
1441 rc = mdt_lookup_version_check(info, msrcdir, &rr->rr_name, old_fid, 2);
1443 GOTO(out_unlock_parent, rc);
1445 if (lu_fid_eq(old_fid, rr->rr_fid1) || lu_fid_eq(old_fid, rr->rr_fid2))
1446 GOTO(out_unlock_parent, rc = -EINVAL);
1448 if (!fid_is_md_operative(old_fid))
1449 GOTO(out_unlock_parent, rc = -EPERM);
1451 mold = mdt_object_find(info->mti_env, info->mti_mdt, old_fid);
1453 GOTO(out_unlock_parent, rc = PTR_ERR(mold));
1455 if (mdt_object_remote(mold)) {
1456 CERROR("%s: source "DFID" is on the remote MDT\n",
1457 mdt_obd_name(info->mti_mdt), PFID(old_fid));
1458 GOTO(out_put_child, rc = -EREMOTE);
1461 if (S_ISREG(lu_object_attr(&mold->mot_obj)) &&
1462 !mdt_object_remote(msrcdir)) {
1463 CERROR("%s: parent "DFID" is still on the same"
1464 " MDT, which should be migrated first:"
1465 " rc = %d\n", mdt_obd_name(info->mti_mdt),
1466 PFID(mdt_object_fid(msrcdir)), -EPERM);
1467 GOTO(out_put_child, rc = -EPERM);
1470 rc = mdt_remote_permission(info);
1472 GOTO(out_put_child, rc);
1474 /* 3: iterate the linkea of the object and lock all of the objects */
1475 INIT_LIST_HEAD(&lock_list);
1476 rc = mdt_lock_objects_in_linkea(info, mold, msrcdir, &lock_list);
1478 GOTO(out_put_child, rc);
1480 if (info->mti_spec.sp_migrate_close) {
1481 struct close_data *data;
1482 struct mdt_body *repbody;
1483 bool lease_broken = false;
1485 if (!req_capsule_field_present(info->mti_pill, &RMF_MDT_EPOCH,
1487 !req_capsule_field_present(info->mti_pill, &RMF_CLOSE_DATA,
1489 GOTO(out_lease, rc = -EPROTO);
1491 data = req_capsule_client_get(info->mti_pill, &RMF_CLOSE_DATA);
1493 GOTO(out_lease, rc = -EPROTO);
1495 lease = ldlm_handle2lock(&data->cd_handle);
1497 GOTO(out_lease, rc = -ESTALE);
1499 /* try to hold open_sem so that nobody else can open the file */
1500 if (!down_write_trylock(&mold->mot_open_sem)) {
1501 ldlm_lock_cancel(lease);
1502 GOTO(out_lease, rc = -EBUSY);
1505 lock_open_sem = true;
1506 /* Check if the lease open lease has already canceled */
1507 lock_res_and_lock(lease);
1508 lease_broken = ldlm_is_cancel(lease);
1509 unlock_res_and_lock(lease);
1511 LDLM_DEBUG(lease, DFID " lease broken? %d\n",
1512 PFID(mdt_object_fid(mold)), lease_broken);
1514 /* Cancel server side lease. Client side counterpart should
1515 * have been cancelled. It's okay to cancel it now as we've
1516 * held mot_open_sem. */
1517 ldlm_lock_cancel(lease);
1520 GOTO(out_lease, rc = -EAGAIN);
1522 rc = mdt_close_internal(info, mdt_info_req(info), NULL);
1523 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1524 repbody->mbo_valid |= OBD_MD_CLOSE_INTENT_EXECED;
1526 GOTO(out_unlock_list, rc);
1529 /* 4: lock of the object migrated object */
1530 lh_childp = &info->mti_lh[MDT_LH_OLD];
1531 mdt_lock_reg_init(lh_childp, LCK_EX);
1532 lock_ibits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE |
1533 MDS_INODELOCK_LAYOUT;
1534 if (mdt_object_remote(msrcdir)) {
1535 /* Enqueue lookup lock from the parent MDT */
1536 rc = mdt_remote_object_lock(info, msrcdir, mdt_object_fid(mold),
1537 &lh_childp->mlh_rreg_lh,
1538 lh_childp->mlh_rreg_mode,
1539 MDS_INODELOCK_LOOKUP, false);
1541 GOTO(out_unlock_list, rc);
1543 lock_ibits &= ~MDS_INODELOCK_LOOKUP;
1546 rc = mdt_object_lock(info, mold, lh_childp, lock_ibits);
1548 GOTO(out_unlock_child, rc);
1550 /* Migration is incompatible with HSM. */
1551 ma->ma_need = MA_HSM;
1553 rc = mdt_attr_get_complex(info, mold, ma);
1555 GOTO(out_unlock_child, rc);
1557 if ((ma->ma_valid & MA_HSM) && ma->ma_hsm.mh_flags != 0) {
1559 CERROR("%s: cannot migrate HSM archived file "DFID": rc = %d\n",
1560 mdt_obd_name(info->mti_mdt), PFID(old_fid), rc);
1561 GOTO(out_unlock_child, rc);
1564 ma->ma_need = MA_LMV;
1566 ma->ma_lmv = (union lmv_mds_md *)info->mti_xattr_buf;
1567 ma->ma_lmv_size = sizeof(info->mti_xattr_buf);
1568 rc = mdt_stripe_get(info, mold, ma, XATTR_NAME_LMV);
1570 GOTO(out_unlock_child, rc);
1572 if ((ma->ma_valid & MA_LMV)) {
1573 struct lmv_mds_md_v1 *lmm1;
1575 lmv_le_to_cpu(ma->ma_lmv, ma->ma_lmv);
1576 lmm1 = &ma->ma_lmv->lmv_md_v1;
1577 if (!(lmm1->lmv_hash_type & LMV_HASH_FLAG_MIGRATION)) {
1578 CERROR("%s: can not migrate striped dir "DFID
1579 ": rc = %d\n", mdt_obd_name(info->mti_mdt),
1580 PFID(mdt_object_fid(mold)), -EPERM);
1581 GOTO(out_unlock_child, rc = -EPERM);
1584 if (!fid_is_sane(&lmm1->lmv_stripe_fids[1]))
1585 GOTO(out_unlock_child, rc = -EINVAL);
1587 mnew = mdt_object_find(info->mti_env, info->mti_mdt,
1588 &lmm1->lmv_stripe_fids[1]);
1590 GOTO(out_unlock_child, rc = PTR_ERR(mnew));
1592 if (!mdt_object_remote(mnew)) {
1593 CERROR("%s: "DFID" being migrated is on this MDT:"
1594 " rc = %d\n", mdt_obd_name(info->mti_mdt),
1595 PFID(rr->rr_fid2), -EPERM);
1596 GOTO(out_put_new, rc = -EPERM);
1599 lh_tgtp = &info->mti_lh[MDT_LH_CHILD];
1600 mdt_lock_reg_init(lh_tgtp, LCK_EX);
1601 rc = mdt_remote_object_lock(info, mnew,
1602 mdt_object_fid(mnew),
1603 &lh_tgtp->mlh_rreg_lh,
1604 lh_tgtp->mlh_rreg_mode,
1605 MDS_INODELOCK_UPDATE, false);
1608 GOTO(out_put_new, rc);
1611 mnew = mdt_object_find(info->mti_env, info->mti_mdt,
1614 GOTO(out_unlock_child, rc = PTR_ERR(mnew));
1615 if (!mdt_object_remote(mnew)) {
1616 CERROR("%s: Migration "DFID" is on this MDT:"
1617 " rc = %d\n", mdt_obd_name(info->mti_mdt),
1618 PFID(rr->rr_fid2), -EXDEV);
1619 GOTO(out_put_new, rc = -EXDEV);
1624 mdt_reint_init_ma(info, ma);
1626 mdt_fail_write(info->mti_env, info->mti_mdt->mdt_bottom,
1627 OBD_FAIL_MDS_REINT_RENAME_WRITE);
1629 rc = mdo_migrate(info->mti_env, mdt_object_child(msrcdir),
1630 mdt_object_child(mold), &rr->rr_name,
1631 mdt_object_child(mnew), ma);
1633 GOTO(out_unlock_new, rc);
1636 if (lh_tgtp != NULL)
1637 mdt_object_unlock(info, mnew, lh_tgtp, rc);
1640 mdt_object_put(info->mti_env, mnew);
1642 mdt_object_unlock(info, mold, lh_childp, rc);
1644 mdt_unlock_list(info, &lock_list, rc);
1645 if (lease != NULL) {
1646 ldlm_reprocess_all(lease->l_resource);
1647 LDLM_LOCK_PUT(lease);
1651 up_write(&mold->mot_open_sem);
1653 mdt_object_put(info->mti_env, mold);
1655 mdt_object_unlock(info, msrcdir, lh_dirp, rc);
1657 mdt_object_put(info->mti_env, msrcdir);
1662 static struct mdt_object *mdt_object_find_check(struct mdt_thread_info *info,
1663 const struct lu_fid *fid,
1666 struct mdt_object *dir;
1670 dir = mdt_object_find(info->mti_env, info->mti_mdt, fid);
1674 /* check early, the real version will be saved after locking */
1675 rc = mdt_version_get_check(info, dir, idx);
1681 mdt_object_put(info->mti_env, dir);
1685 static int mdt_object_lock_save(struct mdt_thread_info *info,
1686 struct mdt_object *dir,
1687 struct mdt_lock_handle *lh,
1692 /* we lock the target dir if it is local */
1693 rc = mdt_object_lock(info, dir, lh, MDS_INODELOCK_UPDATE);
1697 /* get and save correct version after locking */
1698 mdt_version_get_save(info, dir, idx);
1703 static int mdt_rename_parents_lock(struct mdt_thread_info *info,
1704 struct mdt_object **srcp,
1705 struct mdt_object **tgtp)
1707 struct mdt_reint_record *rr = &info->mti_rr;
1708 const struct lu_fid *fid_src = rr->rr_fid1;
1709 const struct lu_fid *fid_tgt = rr->rr_fid2;
1710 struct mdt_lock_handle *lh_src = &info->mti_lh[MDT_LH_PARENT];
1711 struct mdt_lock_handle *lh_tgt = &info->mti_lh[MDT_LH_CHILD];
1712 struct mdt_object *src;
1713 struct mdt_object *tgt;
1718 /* find both parents. */
1719 src = mdt_object_find_check(info, fid_src, 0);
1721 RETURN(PTR_ERR(src));
1723 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RENAME3, 5);
1725 if (lu_fid_eq(fid_src, fid_tgt)) {
1727 mdt_object_get(info->mti_env, tgt);
1729 /* Check if the @src is not a child of the @tgt, otherwise a
1730 * reverse locking must take place. */
1731 rc = mdt_is_subdir(info, src, fid_tgt);
1735 GOTO(err_src_put, rc);
1737 tgt = mdt_object_find_check(info, fid_tgt, 1);
1739 GOTO(err_src_put, rc = PTR_ERR(tgt));
1742 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RENAME4, 5);
1744 /* lock parents in the proper order. */
1746 rc = mdt_object_lock_save(info, tgt, lh_tgt, 1);
1748 GOTO(err_tgt_put, rc);
1750 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RENAME, 5);
1752 rc = mdt_object_lock_save(info, src, lh_src, 0);
1754 rc = mdt_object_lock_save(info, src, lh_src, 0);
1756 GOTO(err_tgt_put, rc);
1758 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RENAME, 5);
1761 rc = mdt_object_lock_save(info, tgt, lh_tgt, 1);
1762 else if (lh_src->mlh_pdo_hash != lh_tgt->mlh_pdo_hash) {
1763 rc = mdt_pdir_hash_lock(info, lh_tgt, tgt,
1764 MDS_INODELOCK_UPDATE);
1765 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_PDO_LOCK2, 10);
1769 GOTO(err_unlock, rc);
1771 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RENAME4, 5);
1778 /* The order does not matter as the handle is checked inside,
1779 * as well as not used handle. */
1780 mdt_object_unlock(info, src, lh_src, rc);
1781 mdt_object_unlock(info, tgt, lh_tgt, rc);
1783 mdt_object_put(info->mti_env, tgt);
1785 mdt_object_put(info->mti_env, src);
1790 * VBR: rename versions in reply: 0 - src parent; 1 - tgt parent;
1791 * 2 - src child; 3 - tgt child.
1792 * Update on disk version of src child.
1795 * For DNE phase I, only these renames are allowed
1796 * mv src_p/src_c tgt_p/tgt_c
1797 * 1. src_p/src_c/tgt_p/tgt_c are in the same MDT.
1798 * 2. src_p and tgt_p are same directory, and tgt_c does not
1799 * exists. In this case, all of modification will happen
1800 * in the MDT where ithesource parent is, only one remote
1801 * update is needed, i.e. set c_time/m_time on the child.
1802 * And tgt_c will be still in the same MDT as the original
1805 static int mdt_reint_rename_internal(struct mdt_thread_info *info,
1806 struct mdt_lock_handle *lhc)
1808 struct mdt_reint_record *rr = &info->mti_rr;
1809 struct md_attr *ma = &info->mti_attr;
1810 struct ptlrpc_request *req = mdt_info_req(info);
1811 struct mdt_object *msrcdir = NULL;
1812 struct mdt_object *mtgtdir = NULL;
1813 struct mdt_object *mold;
1814 struct mdt_object *mnew = NULL;
1815 struct mdt_lock_handle *lh_srcdirp;
1816 struct mdt_lock_handle *lh_tgtdirp;
1817 struct mdt_lock_handle *lh_oldp = NULL;
1818 struct mdt_lock_handle *lh_newp = NULL;
1819 struct lu_fid *old_fid = &info->mti_tmp_fid1;
1820 struct lu_fid *new_fid = &info->mti_tmp_fid2;
1825 DEBUG_REQ(D_INODE, req, "rename "DFID"/"DNAME" to "DFID"/"DNAME,
1826 PFID(rr->rr_fid1), PNAME(&rr->rr_name),
1827 PFID(rr->rr_fid2), PNAME(&rr->rr_tgt_name));
1829 lh_srcdirp = &info->mti_lh[MDT_LH_PARENT];
1830 mdt_lock_pdo_init(lh_srcdirp, LCK_PW, &rr->rr_name);
1831 lh_tgtdirp = &info->mti_lh[MDT_LH_CHILD];
1832 mdt_lock_pdo_init(lh_tgtdirp, LCK_PW, &rr->rr_tgt_name);
1834 /* step 1&2: lock the source and target dirs. */
1835 rc = mdt_rename_parents_lock(info, &msrcdir, &mtgtdir);
1839 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RENAME2, 5);
1841 /* step 3: find & lock the old object. */
1843 rc = mdt_lookup_version_check(info, msrcdir, &rr->rr_name, old_fid, 2);
1845 GOTO(out_unlock_parents, rc);
1847 if (lu_fid_eq(old_fid, rr->rr_fid1) || lu_fid_eq(old_fid, rr->rr_fid2))
1848 GOTO(out_unlock_parents, rc = -EINVAL);
1850 if (!fid_is_md_operative(old_fid))
1851 GOTO(out_unlock_parents, rc = -EPERM);
1853 mold = mdt_object_find(info->mti_env, info->mti_mdt, old_fid);
1855 GOTO(out_unlock_parents, rc = PTR_ERR(mold));
1857 /* Check if @mtgtdir is subdir of @mold, before locking child
1858 * to avoid reverse locking. */
1859 rc = mdt_is_subdir(info, mtgtdir, old_fid);
1861 GOTO(out_put_old, rc);
1863 tgt_vbr_obj_set(info->mti_env, mdt_obj2dt(mold));
1864 /* save version after locking */
1865 mdt_version_get_save(info, mold, 2);
1867 /* step 4: find & lock the new object. */
1868 /* new target object may not exist now */
1869 /* lookup with version checking */
1871 rc = mdt_lookup_version_check(info, mtgtdir, &rr->rr_tgt_name, new_fid,
1874 /* the new_fid should have been filled at this moment */
1875 if (lu_fid_eq(old_fid, new_fid))
1876 GOTO(out_put_old, rc);
1878 if (lu_fid_eq(new_fid, rr->rr_fid1) ||
1879 lu_fid_eq(new_fid, rr->rr_fid2))
1880 GOTO(out_put_old, rc = -EINVAL);
1882 if (!fid_is_md_operative(new_fid))
1883 GOTO(out_put_old, rc = -EPERM);
1885 mnew = mdt_object_find(info->mti_env, info->mti_mdt, new_fid);
1887 GOTO(out_put_old, rc = PTR_ERR(mnew));
1889 if (mdt_object_remote(mnew)) {
1890 struct mdt_body *repbody;
1892 /* Always send rename req to the target child MDT */
1893 repbody = req_capsule_server_get(info->mti_pill,
1895 LASSERT(repbody != NULL);
1896 repbody->mbo_fid1 = *new_fid;
1897 repbody->mbo_valid |= (OBD_MD_FLID | OBD_MD_MDS);
1898 GOTO(out_put_new, rc = -EXDEV);
1900 /* Before locking the target dir, check we do not replace
1901 * a dir with a non-dir, otherwise it may deadlock with
1902 * link op which tries to create a link in this dir
1903 * back to this non-dir. */
1904 if (S_ISDIR(lu_object_attr(&mnew->mot_obj)) &&
1905 !S_ISDIR(lu_object_attr(&mold->mot_obj)))
1906 GOTO(out_put_new, rc = -EISDIR);
1908 lh_oldp = &info->mti_lh[MDT_LH_OLD];
1909 mdt_lock_reg_init(lh_oldp, LCK_EX);
1911 lock_ibits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_XATTR;
1912 if (mdt_object_remote(msrcdir)) {
1913 /* Enqueue lookup lock from the parent MDT */
1914 rc = mdt_remote_object_lock(info, msrcdir,
1915 mdt_object_fid(mold),
1916 &lh_oldp->mlh_rreg_lh,
1917 lh_oldp->mlh_rreg_mode,
1918 MDS_INODELOCK_LOOKUP,
1921 GOTO(out_put_new, rc);
1923 lock_ibits &= ~MDS_INODELOCK_LOOKUP;
1926 rc = mdt_object_lock(info, mold, lh_oldp, lock_ibits);
1928 GOTO(out_unlock_old, rc);
1930 /* Check if @msrcdir is subdir of @mnew, before locking child
1931 * to avoid reverse locking. */
1932 rc = mdt_is_subdir(info, msrcdir, new_fid);
1934 GOTO(out_unlock_old, rc);
1936 /* We used to acquire MDS_INODELOCK_FULL here but we
1937 * can't do this now because a running HSM restore on
1938 * the rename onto victim will hold the layout
1939 * lock. See LU-4002. */
1941 lh_newp = &info->mti_lh[MDT_LH_NEW];
1942 mdt_lock_reg_init(lh_newp, LCK_EX);
1943 rc = mdt_object_lock(info, mnew, lh_newp,
1944 MDS_INODELOCK_LOOKUP |
1945 MDS_INODELOCK_UPDATE);
1947 GOTO(out_unlock_old, rc);
1949 /* get and save version after locking */
1950 mdt_version_get_save(info, mnew, 3);
1951 } else if (rc != -EREMOTE && rc != -ENOENT) {
1952 GOTO(out_put_old, rc);
1954 lh_oldp = &info->mti_lh[MDT_LH_OLD];
1955 mdt_lock_reg_init(lh_oldp, LCK_EX);
1957 lock_ibits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_XATTR;
1958 if (mdt_object_remote(msrcdir)) {
1959 /* Enqueue lookup lock from the parent MDT */
1960 rc = mdt_remote_object_lock(info, msrcdir,
1961 mdt_object_fid(mold),
1962 &lh_oldp->mlh_rreg_lh,
1963 lh_oldp->mlh_rreg_mode,
1964 MDS_INODELOCK_LOOKUP,
1967 GOTO(out_put_new, rc);
1969 lock_ibits &= ~MDS_INODELOCK_LOOKUP;
1972 rc = mdt_object_lock(info, mold, lh_oldp, lock_ibits);
1974 GOTO(out_put_old, rc);
1976 mdt_enoent_version_save(info, 3);
1979 /* step 5: rename it */
1980 mdt_reint_init_ma(info, ma);
1982 mdt_fail_write(info->mti_env, info->mti_mdt->mdt_bottom,
1983 OBD_FAIL_MDS_REINT_RENAME_WRITE);
1986 mutex_lock(&mnew->mot_lov_mutex);
1988 rc = mdo_rename(info->mti_env, mdt_object_child(msrcdir),
1989 mdt_object_child(mtgtdir), old_fid, &rr->rr_name,
1990 mnew != NULL ? mdt_object_child(mnew) : NULL,
1991 &rr->rr_tgt_name, ma);
1994 mutex_unlock(&mnew->mot_lov_mutex);
1996 /* handle last link of tgt object */
1998 mdt_counter_incr(req, LPROC_MDT_RENAME);
2000 mdt_handle_last_unlink(info, mnew, ma);
2002 mdt_rename_counter_tally(info, info->mti_mdt, req,
2008 mdt_object_unlock(info, mnew, lh_newp, rc);
2010 mdt_object_unlock(info, mold, lh_oldp, rc);
2013 mdt_object_put(info->mti_env, mnew);
2015 mdt_object_put(info->mti_env, mold);
2017 mdt_object_unlock_put(info, mtgtdir, lh_tgtdirp, rc);
2018 mdt_object_unlock_put(info, msrcdir, lh_srcdirp, rc);
2022 static int mdt_reint_rename_or_migrate(struct mdt_thread_info *info,
2023 struct mdt_lock_handle *lhc, bool rename)
2025 struct mdt_reint_record *rr = &info->mti_rr;
2026 struct ptlrpc_request *req = mdt_info_req(info);
2027 struct lustre_handle rename_lh = { 0 };
2031 if (info->mti_dlm_req)
2032 ldlm_request_cancel(req, info->mti_dlm_req, 0, LATF_SKIP);
2034 if (!fid_is_md_operative(rr->rr_fid1) ||
2035 !fid_is_md_operative(rr->rr_fid2))
2038 /* Note: do not enqueue rename lock for replay request, because
2039 * if other MDT holds rename lock, but being blocked to wait for
2040 * this MDT to finish its recovery, and the failover MDT can not
2041 * get rename lock, which will cause deadlock. */
2042 if (!req_is_replay(req)) {
2043 rc = mdt_rename_lock(info, &rename_lh);
2045 CERROR("%s: can't lock FS for rename: rc = %d\n",
2046 mdt_obd_name(info->mti_mdt), rc);
2052 rc = mdt_reint_rename_internal(info, lhc);
2054 rc = mdt_reint_migrate_internal(info, lhc);
2056 if (lustre_handle_is_used(&rename_lh))
2057 mdt_rename_unlock(&rename_lh);
2062 static int mdt_reint_rename(struct mdt_thread_info *info,
2063 struct mdt_lock_handle *lhc)
2065 return mdt_reint_rename_or_migrate(info, lhc, true);
2068 static int mdt_reint_migrate(struct mdt_thread_info *info,
2069 struct mdt_lock_handle *lhc)
2071 return mdt_reint_rename_or_migrate(info, lhc, false);
2074 struct mdt_reinter {
2075 int (*mr_handler)(struct mdt_thread_info *, struct mdt_lock_handle *);
2076 enum lprocfs_extra_opc mr_extra_opc;
2079 static const struct mdt_reinter mdt_reinters[] = {
2081 .mr_handler = &mdt_reint_setattr,
2082 .mr_extra_opc = MDS_REINT_SETATTR,
2085 .mr_handler = &mdt_reint_create,
2086 .mr_extra_opc = MDS_REINT_CREATE,
2089 .mr_handler = &mdt_reint_link,
2090 .mr_extra_opc = MDS_REINT_LINK,
2093 .mr_handler = &mdt_reint_unlink,
2094 .mr_extra_opc = MDS_REINT_UNLINK,
2097 .mr_handler = &mdt_reint_rename,
2098 .mr_extra_opc = MDS_REINT_RENAME,
2101 .mr_handler = &mdt_reint_open,
2102 .mr_extra_opc = MDS_REINT_OPEN,
2104 [REINT_SETXATTR] = {
2105 .mr_handler = &mdt_reint_setxattr,
2106 .mr_extra_opc = MDS_REINT_SETXATTR,
2109 .mr_handler = &mdt_reint_unlink,
2110 .mr_extra_opc = MDS_REINT_UNLINK,
2113 .mr_handler = &mdt_reint_migrate,
2114 .mr_extra_opc = MDS_REINT_RENAME,
2118 int mdt_reint_rec(struct mdt_thread_info *info,
2119 struct mdt_lock_handle *lhc)
2121 const struct mdt_reinter *mr;
2125 if (!(info->mti_rr.rr_opcode < ARRAY_SIZE(mdt_reinters)))
2128 mr = &mdt_reinters[info->mti_rr.rr_opcode];
2129 if (mr->mr_handler == NULL)
2132 rc = (*mr->mr_handler)(info, lhc);
2134 lprocfs_counter_incr(ptlrpc_req2svc(mdt_info_req(info))->srv_stats,
2135 PTLRPC_LAST_CNTR + mr->mr_extra_opc);