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, 2013, 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;
60 static int mdt_create_pack_capa(struct mdt_thread_info *info, int rc,
61 struct mdt_object *object,
62 struct mdt_body *repbody)
66 /* for cross-ref mkdir, mds capa has been fetched from remote obj, then
67 * we won't go to below*/
68 if (repbody->mbo_valid & OBD_MD_FLMDSCAPA)
71 if (rc == 0 && info->mti_mdt->mdt_lut.lut_mds_capa &&
72 exp_connect_flags(info->mti_exp) & OBD_CONNECT_MDS_CAPA) {
73 struct lustre_capa *capa;
75 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA1);
77 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
78 rc = mo_capa_get(info->mti_env, mdt_object_child(object), capa,
81 repbody->mbo_valid |= OBD_MD_FLMDSCAPA;
88 * Get version of object by fid.
90 * Return real version or ENOENT_VERSION if object doesn't exist
92 static void mdt_obj_version_get(struct mdt_thread_info *info,
93 struct mdt_object *o, __u64 *version)
96 if (mdt_object_exists(o) && !mdt_object_remote(o) &&
97 !fid_is_obf(mdt_object_fid(o)))
98 *version = dt_version_get(info->mti_env, mdt_obj2dt(o));
100 *version = ENOENT_VERSION;
101 CDEBUG(D_INODE, "FID "DFID" version is "LPX64"\n",
102 PFID(mdt_object_fid(o)), *version);
106 * Check version is correct.
108 * Should be called only during replay.
110 static int mdt_version_check(struct ptlrpc_request *req,
111 __u64 version, int idx)
113 __u64 *pre_ver = lustre_msg_get_versions(req->rq_reqmsg);
116 if (!exp_connect_vbr(req->rq_export))
119 LASSERT(req_is_replay(req));
120 /** VBR: version is checked always because costs nothing */
121 LASSERT(idx < PTLRPC_NUM_VERSIONS);
122 /** Sanity check for malformed buffers */
123 if (pre_ver == NULL) {
124 CERROR("No versions in request buffer\n");
125 spin_lock(&req->rq_export->exp_lock);
126 req->rq_export->exp_vbr_failed = 1;
127 spin_unlock(&req->rq_export->exp_lock);
129 } else if (pre_ver[idx] != version) {
130 CDEBUG(D_INODE, "Version mismatch "LPX64" != "LPX64"\n",
131 pre_ver[idx], version);
132 spin_lock(&req->rq_export->exp_lock);
133 req->rq_export->exp_vbr_failed = 1;
134 spin_unlock(&req->rq_export->exp_lock);
141 * Save pre-versions in reply.
143 static void mdt_version_save(struct ptlrpc_request *req, __u64 version,
148 if (!exp_connect_vbr(req->rq_export))
151 LASSERT(!req_is_replay(req));
152 LASSERT(req->rq_repmsg != NULL);
153 reply_ver = lustre_msg_get_versions(req->rq_repmsg);
155 reply_ver[idx] = version;
159 * Save enoent version, it is needed when it is obvious that object doesn't
160 * exist, e.g. child during create.
162 static void mdt_enoent_version_save(struct mdt_thread_info *info, int idx)
164 /* save version of file name for replay, it must be ENOENT here */
165 if (!req_is_replay(mdt_info_req(info))) {
166 info->mti_ver[idx] = ENOENT_VERSION;
167 mdt_version_save(mdt_info_req(info), info->mti_ver[idx], idx);
172 * Get version from disk and save in reply buffer.
174 * Versions are saved in reply only during normal operations not replays.
176 void mdt_version_get_save(struct mdt_thread_info *info,
177 struct mdt_object *mto, int idx)
179 /* don't save versions during replay */
180 if (!req_is_replay(mdt_info_req(info))) {
181 mdt_obj_version_get(info, mto, &info->mti_ver[idx]);
182 mdt_version_save(mdt_info_req(info), info->mti_ver[idx], idx);
187 * Get version from disk and check it, no save in reply.
189 int mdt_version_get_check(struct mdt_thread_info *info,
190 struct mdt_object *mto, int idx)
192 /* only check versions during replay */
193 if (!req_is_replay(mdt_info_req(info)))
196 mdt_obj_version_get(info, mto, &info->mti_ver[idx]);
197 return mdt_version_check(mdt_info_req(info), info->mti_ver[idx], idx);
201 * Get version from disk and check if recovery or just save.
203 int mdt_version_get_check_save(struct mdt_thread_info *info,
204 struct mdt_object *mto, int idx)
208 mdt_obj_version_get(info, mto, &info->mti_ver[idx]);
209 if (req_is_replay(mdt_info_req(info)))
210 rc = mdt_version_check(mdt_info_req(info), info->mti_ver[idx],
213 mdt_version_save(mdt_info_req(info), info->mti_ver[idx], idx);
218 * Lookup with version checking.
220 * This checks version of 'name'. Many reint functions uses 'name' for child not
221 * FID, therefore we need to get object by name and check its version.
223 int mdt_lookup_version_check(struct mdt_thread_info *info,
224 struct mdt_object *p, const struct lu_name *lname,
225 struct lu_fid *fid, int idx)
229 rc = mdo_lookup(info->mti_env, mdt_object_child(p), lname, fid,
231 /* Check version only during replay */
232 if (!req_is_replay(mdt_info_req(info)))
235 info->mti_ver[idx] = ENOENT_VERSION;
237 struct mdt_object *child;
238 child = mdt_object_find(info->mti_env, info->mti_mdt, fid);
239 if (likely(!IS_ERR(child))) {
240 mdt_obj_version_get(info, child, &info->mti_ver[idx]);
241 mdt_object_put(info->mti_env, child);
244 vbrc = mdt_version_check(mdt_info_req(info), info->mti_ver[idx], idx);
245 return vbrc ? vbrc : rc;
250 * mdt_remote_permission: Check whether the remote operation is permitted,
252 * Before we implement async cross-MDT updates (DNE phase 2). There are a few
255 * 1.Only sysadmin can create remote directory and striped directory and
256 * migrate directory now, unless
257 * lctl set_param mdt.*.enable_remote_dir_gid=allow_gid.
258 * 2.Remote directory can only be created on MDT0, unless
259 * lctl set_param mdt.*.enable_remote_dir = 1
260 * 3.Only new clients can access remote dir( >= 2.4) and striped dir(>= 2.6),
261 * old client will return -ENOTSUPP.
263 * XXX these check are only needed for remote synchronization, once async
264 * update is supported, these check will be removed.
266 * param[in]info: execution environment.
267 * param[in]parent: the directory of this operation.
268 * param[in]child: the child of this operation.
270 * retval = 0 remote operation is allowed.
271 * < 0 remote operation is denied.
273 static int mdt_remote_permission(struct mdt_thread_info *info,
274 struct mdt_object *parent,
275 struct mdt_object *child)
277 struct mdt_device *mdt = info->mti_mdt;
278 struct lu_ucred *uc = mdt_ucred(info);
279 struct md_op_spec *spec = &info->mti_spec;
280 struct lu_attr *attr = &info->mti_attr.ma_attr;
281 struct obd_export *exp = mdt_info_req(info)->rq_export;
283 /* Only check create remote directory, striped directory and
285 if (mdt_object_remote(parent) == 0 && mdt_object_remote(child) == 0 &&
286 !(S_ISDIR(attr->la_mode) && spec->u.sp_ea.eadata != NULL &&
287 spec->u.sp_ea.eadatalen != 0) &&
288 info->mti_rr.rr_opcode != REINT_MIGRATE)
291 if (!md_capable(uc, CFS_CAP_SYS_ADMIN)) {
292 if (uc->uc_gid != mdt->mdt_enable_remote_dir_gid &&
293 mdt->mdt_enable_remote_dir_gid != -1)
297 if (mdt->mdt_enable_remote_dir == 0) {
298 struct seq_server_site *ss = mdt_seq_site(mdt);
299 struct lu_seq_range range = { 0 };
302 fld_range_set_type(&range, LU_SEQ_RANGE_MDT);
303 rc = fld_server_lookup(info->mti_env, ss->ss_server_fld,
304 fid_seq(mdt_object_fid(parent)), &range);
308 if (range.lsr_index != 0)
312 if (!mdt_is_dne_client(exp))
315 if (S_ISDIR(attr->la_mode) && spec->u.sp_ea.eadata != NULL &&
316 spec->u.sp_ea.eadatalen != 0 && !mdt_is_striped_client(exp))
323 * VBR: we save three versions in reply:
324 * 0 - parent. Check that parent version is the same during replay.
325 * 1 - name. Version of 'name' if file exists with the same name or
326 * ENOENT_VERSION, it is needed because file may appear due to missed replays.
327 * 2 - child. Version of child by FID. Must be ENOENT. It is mostly sanity
330 static int mdt_md_create(struct mdt_thread_info *info)
332 struct mdt_device *mdt = info->mti_mdt;
333 struct mdt_object *parent;
334 struct mdt_object *child;
335 struct mdt_lock_handle *lh;
336 struct mdt_body *repbody;
337 struct md_attr *ma = &info->mti_attr;
338 struct mdt_reint_record *rr = &info->mti_rr;
342 DEBUG_REQ(D_INODE, mdt_info_req(info), "Create ("DNAME"->"DFID") "
344 PNAME(&rr->rr_name), PFID(rr->rr_fid2), PFID(rr->rr_fid1));
346 if (!fid_is_md_operative(rr->rr_fid1))
349 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
351 parent = mdt_object_find(info->mti_env, info->mti_mdt, rr->rr_fid1);
353 RETURN(PTR_ERR(parent));
355 if (!mdt_object_exists(parent))
356 GOTO(put_parent, rc = -ENOENT);
358 lh = &info->mti_lh[MDT_LH_PARENT];
359 mdt_lock_pdo_init(lh, LCK_PW, &rr->rr_name);
360 rc = mdt_object_lock(info, parent, lh, MDS_INODELOCK_UPDATE,
363 GOTO(put_parent, rc);
365 if (!mdt_object_remote(parent)) {
366 rc = mdt_version_get_check_save(info, parent, 0);
368 GOTO(unlock_parent, rc);
372 * Check child name version during replay.
373 * During create replay a file may exist with same name.
375 rc = mdt_lookup_version_check(info, parent, &rr->rr_name,
376 &info->mti_tmp_fid1, 1);
378 GOTO(unlock_parent, rc = -EEXIST);
380 /* -ENOENT is expected here */
382 GOTO(unlock_parent, rc);
384 /* save version of file name for replay, it must be ENOENT here */
385 mdt_enoent_version_save(info, 1);
387 child = mdt_object_new(info->mti_env, mdt, rr->rr_fid2);
388 if (likely(!IS_ERR(child))) {
389 struct md_object *next = mdt_object_child(parent);
391 rc = mdt_remote_permission(info, parent, child);
393 GOTO(out_put_child, rc);
395 ma->ma_need = MA_INODE;
397 /* capa for cross-ref will be stored here */
398 ma->ma_capa = req_capsule_server_get(info->mti_pill,
400 LASSERT(ma->ma_capa);
402 mdt_fail_write(info->mti_env, info->mti_mdt->mdt_bottom,
403 OBD_FAIL_MDS_REINT_CREATE_WRITE);
405 /* Version of child will be updated on disk. */
406 tgt_vbr_obj_set(info->mti_env, mdt_obj2dt(child));
407 rc = mdt_version_get_check_save(info, child, 2);
409 GOTO(out_put_child, rc);
411 /* Let lower layer know current lock mode. */
412 info->mti_spec.sp_cr_mode =
413 mdt_dlm_mode2mdl_mode(lh->mlh_pdo_mode);
416 * Do not perform lookup sanity check. We know that name does
419 info->mti_spec.sp_cr_lookup = 0;
420 info->mti_spec.sp_feat = &dt_directory_features;
422 rc = mdo_create(info->mti_env, next, &rr->rr_name,
423 mdt_object_child(child), &info->mti_spec, ma);
425 rc = mdt_attr_get_complex(info, child, ma);
428 /* Return fid & attr to client. */
429 if (ma->ma_valid & MA_INODE)
430 mdt_pack_attr2body(info, repbody, &ma->ma_attr,
431 mdt_object_fid(child));
434 mdt_create_pack_capa(info, rc, child, repbody);
435 mdt_object_put(info->mti_env, child);
438 mdt_create_pack_capa(info, rc, NULL, repbody);
441 mdt_object_unlock(info, parent, lh, rc);
443 mdt_object_put(info->mti_env, parent);
447 static int mdt_unlock_slaves(struct mdt_thread_info *mti,
448 struct mdt_object *obj, __u64 ibits,
449 struct mdt_lock_handle *s0_lh,
450 struct mdt_object *s0_obj,
451 struct ldlm_enqueue_info *einfo)
453 ldlm_policy_data_t *policy = &mti->mti_policy;
457 if (!S_ISDIR(obj->mot_header.loh_attr))
460 /* Unlock stripe 0 */
461 if (s0_lh != NULL && lustre_handle_is_used(&s0_lh->mlh_reg_lh)) {
462 LASSERT(s0_obj != NULL);
463 mdt_object_unlock_put(mti, s0_obj, s0_lh, 1);
466 memset(policy, 0, sizeof(*policy));
467 policy->l_inodebits.bits = ibits;
469 rc = mo_object_unlock(mti->mti_env, mdt_object_child(obj), einfo,
475 * Lock slave stripes if necessary, the lock handles of slave stripes
476 * will be stored in einfo->ei_cbdata.
478 static int mdt_lock_slaves(struct mdt_thread_info *mti, struct mdt_object *obj,
479 ldlm_mode_t mode, __u64 ibits,
480 struct mdt_lock_handle *s0_lh,
481 struct mdt_object **s0_objp,
482 struct ldlm_enqueue_info *einfo)
484 ldlm_policy_data_t *policy = &mti->mti_policy;
485 struct lu_buf *buf = &mti->mti_buf;
486 struct lmv_mds_md_v1 *lmv;
487 struct lu_fid *fid = &mti->mti_tmp_fid1;
491 if (!S_ISDIR(obj->mot_header.loh_attr))
494 buf->lb_buf = mti->mti_xattr_buf;
495 buf->lb_len = sizeof(mti->mti_xattr_buf);
496 rc = mo_xattr_get(mti->mti_env, mdt_object_child(obj), buf,
499 rc = mdt_big_xattr_get(mti, obj, XATTR_NAME_LMV);
501 buf->lb_buf = mti->mti_big_lmm;
502 buf->lb_len = mti->mti_big_lmmsize;
506 if (rc == -ENODATA || rc == -ENOENT)
513 if (le32_to_cpu(lmv->lmv_magic) != LMV_MAGIC_V1)
516 /* Sigh, 0_stripe and master object are different
517 * object, though they are in the same MDT, to avoid
518 * adding osd_object_lock here, so we will enqueue the
519 * stripe0 lock in MDT0 for now */
520 fid_le_to_cpu(fid, &lmv->lmv_stripe_fids[0]);
521 *s0_objp = mdt_object_find_lock(mti, fid, s0_lh, ibits);
522 if (IS_ERR(*s0_objp))
523 RETURN(PTR_ERR(*s0_objp));
525 memset(einfo, 0, sizeof(*einfo));
526 einfo->ei_type = LDLM_IBITS;
527 einfo->ei_mode = mode;
528 einfo->ei_cb_bl = mdt_remote_blocking_ast;
529 einfo->ei_cb_cp = ldlm_completion_ast;
530 einfo->ei_enq_slave = 1;
531 memset(policy, 0, sizeof(*policy));
532 policy->l_inodebits.bits = ibits;
534 rc = mo_object_lock(mti->mti_env, mdt_object_child(obj), NULL, einfo,
539 static int mdt_attr_set(struct mdt_thread_info *info, struct mdt_object *mo,
542 struct mdt_lock_handle *lh;
543 int do_vbr = ma->ma_attr.la_valid & (LA_MODE|LA_UID|LA_GID|LA_FLAGS);
544 __u64 lockpart = MDS_INODELOCK_UPDATE;
545 struct ldlm_enqueue_info *einfo = &info->mti_einfo;
546 struct mdt_lock_handle *s0_lh;
547 struct mdt_object *s0_obj = NULL;
551 lh = &info->mti_lh[MDT_LH_PARENT];
552 mdt_lock_reg_init(lh, LCK_PW);
554 /* Even though the new MDT will grant PERM lock to the old
555 * client, but the old client will almost ignore that during
556 * So it needs to revoke both LOOKUP and PERM lock here, so
557 * both new and old client can cancel the dcache */
558 if (ma->ma_attr.la_valid & (LA_MODE|LA_UID|LA_GID))
559 lockpart |= MDS_INODELOCK_LOOKUP | MDS_INODELOCK_PERM;
561 rc = mdt_object_lock(info, mo, lh, lockpart, MDT_LOCAL_LOCK);
565 s0_lh = &info->mti_lh[MDT_LH_LOCAL];
566 mdt_lock_reg_init(s0_lh, LCK_PW);
567 rc = mdt_lock_slaves(info, mo, LCK_PW, lockpart, s0_lh, &s0_obj, einfo);
569 GOTO(out_unlock, rc);
571 /* all attrs are packed into mti_attr in unpack_setattr */
572 mdt_fail_write(info->mti_env, info->mti_mdt->mdt_bottom,
573 OBD_FAIL_MDS_REINT_SETATTR_WRITE);
575 /* This is only for set ctime when rename's source is on remote MDS. */
576 if (unlikely(ma->ma_attr.la_valid == LA_CTIME))
577 ma->ma_attr_flags |= MDS_VTX_BYPASS;
579 /* VBR: update version if attr changed are important for recovery */
581 /* update on-disk version of changed object */
582 tgt_vbr_obj_set(info->mti_env, mdt_obj2dt(mo));
583 rc = mdt_version_get_check_save(info, mo, 0);
585 GOTO(out_unlock, rc);
588 /* Ensure constant striping during chown(). See LU-2789. */
589 if (ma->ma_attr.la_valid & (LA_UID|LA_GID))
590 mutex_lock(&mo->mot_lov_mutex);
592 /* all attrs are packed into mti_attr in unpack_setattr */
593 rc = mo_attr_set(info->mti_env, mdt_object_child(mo), ma);
595 if (ma->ma_attr.la_valid & (LA_UID|LA_GID))
596 mutex_unlock(&mo->mot_lov_mutex);
599 GOTO(out_unlock, rc);
603 mdt_unlock_slaves(info, mo, lockpart, s0_lh, s0_obj, einfo);
604 mdt_object_unlock(info, mo, lh, rc);
609 * Check HSM flags and add HS_DIRTY flag if relevant.
611 * A file could be set dirty only if it has a copy in the backend (HS_EXISTS)
612 * and is not RELEASED.
614 int mdt_add_dirty_flag(struct mdt_thread_info *info, struct mdt_object *mo,
620 /* If the file was modified, add the dirty flag */
621 ma->ma_need = MA_HSM;
622 rc = mdt_attr_get_complex(info, mo, ma);
624 CERROR("file attribute read error for "DFID": %d.\n",
625 PFID(mdt_object_fid(mo)), rc);
629 /* If an up2date copy exists in the backend, add dirty flag */
630 if ((ma->ma_valid & MA_HSM) && (ma->ma_hsm.mh_flags & HS_EXISTS)
631 && !(ma->ma_hsm.mh_flags & (HS_DIRTY|HS_RELEASED))) {
632 struct mdt_lock_handle *lh = &info->mti_lh[MDT_LH_CHILD];
634 ma->ma_hsm.mh_flags |= HS_DIRTY;
636 mdt_lock_reg_init(lh, LCK_PW);
637 rc = mdt_object_lock(info, mo, lh, MDS_INODELOCK_XATTR,
642 rc = mdt_hsm_attr_set(info, mo, &ma->ma_hsm);
644 CERROR("file attribute change error for "DFID": %d\n",
645 PFID(mdt_object_fid(mo)), rc);
646 mdt_object_unlock(info, mo, lh, rc);
652 static int mdt_reint_setattr(struct mdt_thread_info *info,
653 struct mdt_lock_handle *lhc)
655 struct md_attr *ma = &info->mti_attr;
656 struct mdt_reint_record *rr = &info->mti_rr;
657 struct ptlrpc_request *req = mdt_info_req(info);
658 struct mdt_export_data *med = &req->rq_export->exp_mdt_data;
659 struct mdt_file_data *mfd;
660 struct mdt_object *mo;
661 struct mdt_body *repbody;
665 DEBUG_REQ(D_INODE, req, "setattr "DFID" %x", PFID(rr->rr_fid1),
666 (unsigned int)ma->ma_attr.la_valid);
668 if (info->mti_dlm_req)
669 ldlm_request_cancel(req, info->mti_dlm_req, 0, LATF_SKIP);
671 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
672 mo = mdt_object_find(info->mti_env, info->mti_mdt, rr->rr_fid1);
674 GOTO(out, rc = PTR_ERR(mo));
676 if (!mdt_object_exists(mo))
677 GOTO(out_put, rc = -ENOENT);
679 if (mdt_object_remote(mo))
680 GOTO(out_put, rc = -EREMOTE);
682 /* start a log jounal handle if needed */
683 if (!(mdt_conn_flags(info) & OBD_CONNECT_SOM)) {
684 if ((ma->ma_attr.la_valid & LA_SIZE) ||
685 (rr->rr_flags & MRF_OPEN_TRUNC)) {
686 /* Check write access for the O_TRUNC case */
687 if (mdt_write_read(mo) < 0)
688 GOTO(out_put, rc = -ETXTBSY);
690 } else if (info->mti_ioepoch &&
691 (info->mti_ioepoch->flags & MF_EPOCH_OPEN)) {
692 /* Truncate case. IOEpoch is opened. */
693 rc = mdt_write_get(mo);
697 mfd = mdt_mfd_new(med);
700 GOTO(out_put, rc = -ENOMEM);
703 mdt_ioepoch_open(info, mo, 0);
704 repbody->mbo_ioepoch = mo->mot_ioepoch;
706 mdt_object_get(info->mti_env, mo);
707 mdt_mfd_set_mode(mfd, MDS_FMODE_TRUNC);
708 mfd->mfd_object = mo;
709 mfd->mfd_xid = req->rq_xid;
711 spin_lock(&med->med_open_lock);
712 list_add(&mfd->mfd_list, &med->med_open_head);
713 spin_unlock(&med->med_open_lock);
714 repbody->mbo_handle.cookie = mfd->mfd_handle.h_cookie;
717 som_au = info->mti_ioepoch && info->mti_ioepoch->flags & MF_SOM_CHANGE;
719 /* SOM Attribute update case. Find the proper mfd and update
720 * SOM attributes on the proper object. */
721 if (!(mdt_conn_flags(info) & OBD_CONNECT_SOM))
722 GOTO(out_put, rc = -EPROTO);
724 spin_lock(&med->med_open_lock);
725 mfd = mdt_handle2mfd(med, &info->mti_ioepoch->handle,
728 spin_unlock(&med->med_open_lock);
729 CDEBUG(D_INODE, "no handle for file close: "
730 "fid = "DFID": cookie = "LPX64"\n",
731 PFID(info->mti_rr.rr_fid1),
732 info->mti_ioepoch->handle.cookie);
733 GOTO(out_put, rc = -ESTALE);
736 if (mfd->mfd_mode != MDS_FMODE_SOM ||
737 (info->mti_ioepoch->flags & MF_EPOCH_CLOSE))
738 GOTO(out_put, rc = -EPROTO);
740 class_handle_unhash(&mfd->mfd_handle);
741 list_del_init(&mfd->mfd_list);
742 spin_unlock(&med->med_open_lock);
744 mdt_mfd_close(info, mfd);
745 } else if ((ma->ma_valid & MA_INODE) && ma->ma_attr.la_valid) {
746 if (ma->ma_valid & MA_LOV)
747 GOTO(out_put, rc = -EPROTO);
749 rc = mdt_attr_set(info, mo, ma);
752 } else if ((ma->ma_valid & MA_LOV) && (ma->ma_valid & MA_INODE)) {
753 struct lu_buf *buf = &info->mti_buf;
755 if (ma->ma_attr.la_valid != 0)
756 GOTO(out_put, rc = -EPROTO);
758 buf->lb_buf = ma->ma_lmm;
759 buf->lb_len = ma->ma_lmm_size;
760 rc = mo_xattr_set(info->mti_env, mdt_object_child(mo),
761 buf, XATTR_NAME_LOV, 0);
764 } else if ((ma->ma_valid & MA_LMV) && (ma->ma_valid & MA_INODE)) {
765 struct lu_buf *buf = &info->mti_buf;
767 if (ma->ma_attr.la_valid != 0)
768 GOTO(out_put, rc = -EPROTO);
770 buf->lb_buf = ma->ma_lmv;
771 buf->lb_len = ma->ma_lmv_size;
772 rc = mo_xattr_set(info->mti_env, mdt_object_child(mo),
773 buf, XATTR_NAME_DEFAULT_LMV, 0);
777 GOTO(out_put, rc = -EPROTO);
780 /* If file data is modified, add the dirty flag */
781 if (ma->ma_attr_flags & MDS_DATA_MODIFIED)
782 rc = mdt_add_dirty_flag(info, mo, ma);
784 ma->ma_need = MA_INODE;
786 rc = mdt_attr_get_complex(info, mo, ma);
790 mdt_pack_attr2body(info, repbody, &ma->ma_attr, mdt_object_fid(mo));
792 if (info->mti_mdt->mdt_lut.lut_oss_capa &&
793 exp_connect_flags(info->mti_exp) & OBD_CONNECT_OSS_CAPA &&
794 S_ISREG(lu_object_attr(&mo->mot_obj)) &&
795 (ma->ma_attr.la_valid & LA_SIZE) && !som_au) {
796 struct lustre_capa *capa;
798 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA2);
800 capa->lc_opc = CAPA_OPC_OSS_DEFAULT | CAPA_OPC_OSS_TRUNC;
801 rc = mo_capa_get(info->mti_env, mdt_object_child(mo), capa, 0);
804 repbody->mbo_valid |= OBD_MD_FLOSSCAPA;
809 mdt_object_put(info->mti_env, mo);
812 mdt_counter_incr(req, LPROC_MDT_SETATTR);
814 mdt_client_compatibility(info);
815 rc2 = mdt_fix_reply(info);
821 static int mdt_reint_create(struct mdt_thread_info *info,
822 struct mdt_lock_handle *lhc)
824 struct ptlrpc_request *req = mdt_info_req(info);
828 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_CREATE))
829 RETURN(err_serious(-ESTALE));
831 if (info->mti_dlm_req)
832 ldlm_request_cancel(mdt_info_req(info),
833 info->mti_dlm_req, 0, LATF_SKIP);
835 if (!lu_name_is_valid(&info->mti_rr.rr_name))
838 switch (info->mti_attr.ma_attr.la_mode & S_IFMT) {
840 mdt_counter_incr(req, LPROC_MDT_MKDIR);
848 /* Special file should stay on the same node as parent. */
849 mdt_counter_incr(req, LPROC_MDT_MKNOD);
852 CERROR("%s: Unsupported mode %o\n",
853 mdt_obd_name(info->mti_mdt),
854 info->mti_attr.ma_attr.la_mode);
855 RETURN(err_serious(-EOPNOTSUPP));
858 rc = mdt_md_create(info);
863 * VBR: save parent version in reply and child version getting by its name.
864 * Version of child is getting and checking during its lookup. If
866 static int mdt_reint_unlink(struct mdt_thread_info *info,
867 struct mdt_lock_handle *lhc)
869 struct mdt_reint_record *rr = &info->mti_rr;
870 struct ptlrpc_request *req = mdt_info_req(info);
871 struct md_attr *ma = &info->mti_attr;
872 struct lu_fid *child_fid = &info->mti_tmp_fid1;
873 struct mdt_object *mp;
874 struct mdt_object *mc;
875 struct mdt_lock_handle *parent_lh;
876 struct mdt_lock_handle *child_lh;
877 struct ldlm_enqueue_info *einfo = &info->mti_einfo;
878 struct mdt_lock_handle *s0_lh = NULL;
879 struct mdt_object *s0_obj = NULL;
884 DEBUG_REQ(D_INODE, req, "unlink "DFID"/"DNAME"", PFID(rr->rr_fid1),
885 PNAME(&rr->rr_name));
887 if (info->mti_dlm_req)
888 ldlm_request_cancel(req, info->mti_dlm_req, 0, LATF_SKIP);
890 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_UNLINK))
891 RETURN(err_serious(-ENOENT));
893 if (!fid_is_md_operative(rr->rr_fid1))
897 * step 1: Found the parent.
899 mp = mdt_object_find(info->mti_env, info->mti_mdt, rr->rr_fid1);
905 parent_lh = &info->mti_lh[MDT_LH_PARENT];
906 mdt_lock_pdo_init(parent_lh, LCK_PW, &rr->rr_name);
907 rc = mdt_object_lock(info, mp, parent_lh, MDS_INODELOCK_UPDATE,
910 GOTO(put_parent, rc);
912 if (!mdt_object_remote(mp)) {
913 rc = mdt_version_get_check_save(info, mp, 0);
915 GOTO(unlock_parent, rc);
918 /* step 2: find & lock the child */
919 /* lookup child object along with version checking */
921 rc = mdt_lookup_version_check(info, mp, &rr->rr_name, child_fid, 1);
923 /* Name might not be able to find during resend of
924 * remote unlink, considering following case.
925 * dir_A is a remote directory, the name entry of
926 * dir_A is on MDT0, the directory is on MDT1,
928 * 1. client sends unlink req to MDT1.
929 * 2. MDT1 sends name delete update to MDT0.
930 * 3. name entry is being deleted in MDT0 synchronously.
931 * 4. MDT1 is restarted.
932 * 5. client resends unlink req to MDT1. So it can not
933 * find the name entry on MDT0 anymore.
934 * In this case, MDT1 only needs to destory the local
937 if (mdt_object_remote(mp) && rc == -ENOENT &&
938 !fid_is_zero(rr->rr_fid2) &&
939 lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT) {
941 *child_fid = *rr->rr_fid2;
943 GOTO(unlock_parent, rc);
947 if (!fid_is_md_operative(child_fid))
948 GOTO(unlock_parent, rc = -EPERM);
950 /* We will lock the child regardless it is local or remote. No harm. */
951 mc = mdt_object_find(info->mti_env, info->mti_mdt, child_fid);
953 GOTO(unlock_parent, rc = PTR_ERR(mc));
955 child_lh = &info->mti_lh[MDT_LH_CHILD];
956 mdt_lock_reg_init(child_lh, LCK_EX);
957 if (mdt_object_remote(mc)) {
958 struct mdt_body *repbody;
960 if (!fid_is_zero(rr->rr_fid2)) {
961 CDEBUG(D_INFO, "%s: name "DNAME" cannot find "DFID"\n",
962 mdt_obd_name(info->mti_mdt),
963 PNAME(&rr->rr_name), PFID(mdt_object_fid(mc)));
964 GOTO(put_child, rc = -ENOENT);
966 CDEBUG(D_INFO, "%s: name "DNAME": "DFID" is on another MDT\n",
967 mdt_obd_name(info->mti_mdt),
968 PNAME(&rr->rr_name), PFID(mdt_object_fid(mc)));
970 if (!mdt_is_dne_client(req->rq_export))
971 /* Return -ENOTSUPP for old client */
972 GOTO(put_child, rc = -ENOTSUPP);
974 if (info->mti_spec.sp_rm_entry) {
975 struct lu_ucred *uc = mdt_ucred(info);
977 if (!md_capable(uc, CFS_CAP_SYS_ADMIN)) {
978 CERROR("%s: unlink remote entry is only "
979 "permitted for administrator: rc = %d\n",
980 mdt_obd_name(info->mti_mdt),
982 GOTO(put_child, rc = -EPERM);
985 ma->ma_need = MA_INODE;
987 mdt_set_capainfo(info, 1, child_fid, BYPASS_CAPA);
988 rc = mdo_unlink(info->mti_env, mdt_object_child(mp),
989 NULL, &rr->rr_name, ma, no_name);
992 /* Revoke the LOOKUP lock of the remote object granted by
993 * this MDT. Since the unlink will happen on another MDT,
994 * it will release the LOOKUP lock right away. Then What
995 * would happen if another client try to grab the LOOKUP
996 * lock at the same time with unlink XXX */
997 mdt_object_lock(info, mc, child_lh, MDS_INODELOCK_LOOKUP,
999 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1000 LASSERT(repbody != NULL);
1001 repbody->mbo_fid1 = *mdt_object_fid(mc);
1002 repbody->mbo_valid |= (OBD_MD_FLID | OBD_MD_MDS);
1003 GOTO(unlock_child, rc = -EREMOTE);
1004 } else if (info->mti_spec.sp_rm_entry) {
1006 CDEBUG(D_INFO, "%s: no rm_entry on local dir '"DNAME"': "
1008 mdt_obd_name(info->mti_mdt), PNAME(&rr->rr_name), rc);
1009 GOTO(put_child, rc);
1012 /* We used to acquire MDS_INODELOCK_FULL here but we can't do
1013 * this now because a running HSM restore on the child (unlink
1014 * victim) will hold the layout lock. See LU-4002. */
1015 rc = mdt_object_lock(info, mc, child_lh,
1016 MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE,
1019 GOTO(put_child, rc);
1021 * Now we can only make sure we need MA_INODE, in mdd layer, will check
1022 * whether need MA_LOV and MA_COOKIE.
1024 ma->ma_need = MA_INODE;
1027 s0_lh = &info->mti_lh[MDT_LH_LOCAL];
1028 mdt_lock_reg_init(s0_lh, LCK_EX);
1029 rc = mdt_lock_slaves(info, mc, LCK_EX, MDS_INODELOCK_UPDATE, s0_lh,
1032 GOTO(unlock_child, rc);
1034 mdt_fail_write(info->mti_env, info->mti_mdt->mdt_bottom,
1035 OBD_FAIL_MDS_REINT_UNLINK_WRITE);
1036 /* save version when object is locked */
1037 mdt_version_get_save(info, mc, 1);
1039 mdt_set_capainfo(info, 1, child_fid, BYPASS_CAPA);
1041 mutex_lock(&mc->mot_lov_mutex);
1043 rc = mdo_unlink(info->mti_env, mdt_object_child(mp),
1044 mdt_object_child(mc), &rr->rr_name, ma, no_name);
1046 mutex_unlock(&mc->mot_lov_mutex);
1048 if (rc == 0 && !lu_object_is_dying(&mc->mot_header))
1049 rc = mdt_attr_get_complex(info, mc, ma);
1051 mdt_handle_last_unlink(info, mc, ma);
1053 if (ma->ma_valid & MA_INODE) {
1054 switch (ma->ma_attr.la_mode & S_IFMT) {
1056 mdt_counter_incr(req, LPROC_MDT_RMDIR);
1064 mdt_counter_incr(req, LPROC_MDT_UNLINK);
1067 LASSERTF(0, "bad file type %o unlinking\n",
1068 ma->ma_attr.la_mode);
1075 mdt_unlock_slaves(info, mc, MDS_INODELOCK_UPDATE, s0_lh, s0_obj, einfo);
1076 mdt_object_unlock(info, mc, child_lh, rc);
1078 mdt_object_put(info->mti_env, mc);
1080 mdt_object_unlock(info, mp, parent_lh, rc);
1082 mdt_object_put(info->mti_env, mp);
1088 * VBR: save versions in reply: 0 - parent; 1 - child by fid; 2 - target by
1091 static int mdt_reint_link(struct mdt_thread_info *info,
1092 struct mdt_lock_handle *lhc)
1094 struct mdt_reint_record *rr = &info->mti_rr;
1095 struct ptlrpc_request *req = mdt_info_req(info);
1096 struct md_attr *ma = &info->mti_attr;
1097 struct mdt_object *ms;
1098 struct mdt_object *mp;
1099 struct mdt_lock_handle *lhs;
1100 struct mdt_lock_handle *lhp;
1104 DEBUG_REQ(D_INODE, req, "link "DFID" to "DFID"/"DNAME,
1105 PFID(rr->rr_fid1), PFID(rr->rr_fid2), PNAME(&rr->rr_name));
1107 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_LINK))
1108 RETURN(err_serious(-ENOENT));
1110 if (info->mti_dlm_req)
1111 ldlm_request_cancel(req, info->mti_dlm_req, 0, LATF_SKIP);
1113 /* Invalid case so return error immediately instead of
1115 if (lu_fid_eq(rr->rr_fid1, rr->rr_fid2))
1118 if (!fid_is_md_operative(rr->rr_fid1) ||
1119 !fid_is_md_operative(rr->rr_fid2))
1122 /* step 1: find & lock the target parent dir */
1123 lhp = &info->mti_lh[MDT_LH_PARENT];
1124 mdt_lock_pdo_init(lhp, LCK_PW, &rr->rr_name);
1125 mp = mdt_object_find_lock(info, rr->rr_fid2, lhp,
1126 MDS_INODELOCK_UPDATE);
1128 RETURN(PTR_ERR(mp));
1130 rc = mdt_version_get_check_save(info, mp, 0);
1132 GOTO(out_unlock_parent, rc);
1134 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RENAME3, 5);
1136 /* step 2: find & lock the source */
1137 lhs = &info->mti_lh[MDT_LH_CHILD];
1138 mdt_lock_reg_init(lhs, LCK_EX);
1140 ms = mdt_object_find(info->mti_env, info->mti_mdt, rr->rr_fid1);
1142 GOTO(out_unlock_parent, rc = PTR_ERR(ms));
1144 if (!mdt_object_exists(ms)) {
1145 mdt_object_put(info->mti_env, ms);
1146 CDEBUG(D_INFO, "%s: "DFID" does not exist.\n",
1147 mdt_obd_name(info->mti_mdt), PFID(rr->rr_fid1));
1148 GOTO(out_unlock_parent, rc = -ENOENT);
1151 if (mdt_object_remote(ms)) {
1152 mdt_object_put(info->mti_env, ms);
1153 CERROR("%s: source inode "DFID" on remote MDT from "DFID"\n",
1154 mdt_obd_name(info->mti_mdt), PFID(rr->rr_fid1),
1156 GOTO(out_unlock_parent, rc = -EXDEV);
1159 rc = mdt_object_lock(info, ms, lhs, MDS_INODELOCK_UPDATE |
1160 MDS_INODELOCK_XATTR, MDT_LOCAL_LOCK);
1162 mdt_object_put(info->mti_env, ms);
1163 GOTO(out_unlock_parent, rc);
1166 /* step 3: link it */
1167 mdt_fail_write(info->mti_env, info->mti_mdt->mdt_bottom,
1168 OBD_FAIL_MDS_REINT_LINK_WRITE);
1170 tgt_vbr_obj_set(info->mti_env, mdt_obj2dt(ms));
1171 rc = mdt_version_get_check_save(info, ms, 1);
1173 GOTO(out_unlock_child, rc);
1175 /** check target version by name during replay */
1176 rc = mdt_lookup_version_check(info, mp, &rr->rr_name,
1177 &info->mti_tmp_fid1, 2);
1178 if (rc != 0 && rc != -ENOENT)
1179 GOTO(out_unlock_child, rc);
1180 /* save version of file name for replay, it must be ENOENT here */
1181 if (!req_is_replay(mdt_info_req(info))) {
1182 if (rc != -ENOENT) {
1183 CDEBUG(D_INFO, "link target "DNAME" existed!\n",
1184 PNAME(&rr->rr_name));
1185 GOTO(out_unlock_child, rc = -EEXIST);
1187 info->mti_ver[2] = ENOENT_VERSION;
1188 mdt_version_save(mdt_info_req(info), info->mti_ver[2], 2);
1191 rc = mdo_link(info->mti_env, mdt_object_child(mp),
1192 mdt_object_child(ms), &rr->rr_name, ma);
1195 mdt_counter_incr(req, LPROC_MDT_LINK);
1199 mdt_object_unlock_put(info, ms, lhs, rc);
1201 mdt_object_unlock_put(info, mp, lhp, rc);
1205 * lock the part of the directory according to the hash of the name
1206 * (lh->mlh_pdo_hash) in parallel directory lock.
1208 static int mdt_pdir_hash_lock(struct mdt_thread_info *info,
1209 struct mdt_lock_handle *lh,
1210 struct mdt_object *obj, __u64 ibits)
1212 struct ldlm_res_id *res = &info->mti_res_id;
1213 struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
1214 ldlm_policy_data_t *policy = &info->mti_policy;
1218 * Finish res_id initializing by name hash marking part of
1219 * directory which is taking modification.
1221 LASSERT(lh->mlh_pdo_hash != 0);
1222 fid_build_pdo_res_name(mdt_object_fid(obj), lh->mlh_pdo_hash, res);
1223 memset(policy, 0, sizeof(*policy));
1224 policy->l_inodebits.bits = ibits;
1226 * Use LDLM_FL_LOCAL_ONLY for this lock. We do not know yet if it is
1227 * going to be sent to client. If it is - mdt_intent_policy() path will
1228 * fix it up and turn FL_LOCAL flag off.
1230 rc = mdt_fid_lock(ns, &lh->mlh_reg_lh, lh->mlh_reg_mode, policy,
1231 res, LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB,
1232 &info->mti_exp->exp_handle.h_cookie);
1236 enum mdt_rename_lock {
1242 * Get BFL lock for rename or migrate process, right now, it does not support
1243 * cross-MDT rename, so we only need global rename lock during migration.
1245 static int mdt_rename_lock(struct mdt_thread_info *info,
1246 struct lustre_handle *lh,
1247 enum mdt_rename_lock rename_lock)
1249 struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
1250 ldlm_policy_data_t *policy = &info->mti_policy;
1251 struct ldlm_res_id *res_id = &info->mti_res_id;
1256 /* XXX only do global rename lock for migration */
1257 if (mdt_seq_site(info->mti_mdt)->ss_node_id != 0 &&
1258 rename_lock == MRL_MIGRATE) {
1259 struct lu_fid *fid = &info->mti_tmp_fid1;
1260 struct mdt_object *obj;
1262 /* XXX, right now, it has to use object API to
1263 * enqueue lock cross MDT, so it will enqueue
1264 * rename lock(with LUSTRE_BFL_FID) by root object */
1266 obj = mdt_object_find(info->mti_env, info->mti_mdt, fid);
1268 RETURN(PTR_ERR(obj));
1270 LASSERT(mdt_object_remote(obj));
1271 rc = mdt_remote_object_lock(info, obj,
1272 &LUSTRE_BFL_FID, lh,
1274 MDS_INODELOCK_UPDATE);
1275 mdt_object_put(info->mti_env, obj);
1277 fid_build_reg_res_name(&LUSTRE_BFL_FID, res_id);
1278 memset(policy, 0, sizeof *policy);
1279 policy->l_inodebits.bits = MDS_INODELOCK_UPDATE;
1280 flags = LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB;
1281 rc = ldlm_cli_enqueue_local(ns, res_id, LDLM_IBITS, policy,
1282 LCK_EX, &flags, ldlm_blocking_ast,
1283 ldlm_completion_ast, NULL, NULL, 0,
1285 &info->mti_exp->exp_handle.h_cookie,
1292 static void mdt_rename_unlock(struct lustre_handle *lh)
1295 LASSERT(lustre_handle_is_used(lh));
1296 /* Cancel the single rename lock right away */
1297 ldlm_lock_decref_and_cancel(lh, LCK_EX);
1302 * This is is_subdir() variant, it is CMD if cmm forwards it to correct
1303 * target. Source should not be ancestor of target dir. May be other rename
1304 * checks can be moved here later.
1306 static int mdt_is_subdir(struct mdt_thread_info *info,
1307 struct mdt_object *dir,
1308 const struct lu_fid *fid)
1310 struct lu_fid dir_fid = dir->mot_header.loh_fid;
1314 /* If the source and target are in the same directory, they can not
1315 * be parent/child relationship, so subdir check is not needed */
1316 if (lu_fid_eq(&dir_fid, fid))
1319 if (!mdt_object_exists(dir))
1322 rc = mdo_is_subdir(info->mti_env, mdt_object_child(dir),
1325 CERROR("%s: failed subdir check in "DFID" for "DFID
1326 ": rc = %d\n", mdt_obd_name(info->mti_mdt),
1327 PFID(&dir_fid), PFID(fid), rc);
1328 /* Return EINVAL only if a parent is the @fid */
1332 /* check the found fid */
1333 if (lu_fid_eq(&dir_fid, fid))
1340 /* Update object linkEA */
1341 struct mdt_lock_list {
1342 struct mdt_object *mll_obj;
1343 struct mdt_lock_handle mll_lh;
1344 struct list_head mll_list;
1347 static void mdt_unlock_list(struct mdt_thread_info *info,
1348 struct list_head *list, int rc)
1350 struct mdt_lock_list *mll;
1351 struct mdt_lock_list *mll2;
1353 list_for_each_entry_safe(mll, mll2, list, mll_list) {
1354 mdt_object_unlock_put(info, mll->mll_obj, &mll->mll_lh, rc);
1355 list_del(&mll->mll_list);
1360 static int mdt_lock_objects_in_linkea(struct mdt_thread_info *info,
1361 struct mdt_object *obj,
1362 struct mdt_object *pobj,
1363 struct list_head *lock_list)
1365 struct lu_buf *buf = &info->mti_big_buf;
1366 struct linkea_data ldata = { 0 };
1371 if (S_ISDIR(lu_object_attr(&obj->mot_obj)))
1374 buf = lu_buf_check_and_alloc(buf, PATH_MAX);
1375 if (buf->lb_buf == NULL)
1379 rc = mdt_links_read(info, obj, &ldata);
1381 if (rc == -ENOENT || rc == -ENODATA)
1386 LASSERT(ldata.ld_leh != NULL);
1387 ldata.ld_lee = (struct link_ea_entry *)(ldata.ld_leh + 1);
1388 for (count = 0; count < ldata.ld_leh->leh_reccount; count++) {
1389 struct mdt_device *mdt = info->mti_mdt;
1390 struct mdt_object *mdt_pobj;
1391 struct mdt_lock_list *mll;
1392 struct lu_name name;
1395 linkea_entry_unpack(ldata.ld_lee, &ldata.ld_reclen,
1397 ldata.ld_lee = (struct link_ea_entry *)((char *)ldata.ld_lee +
1399 mdt_pobj = mdt_object_find(info->mti_env, mdt, &fid);
1400 if (IS_ERR(mdt_pobj)) {
1401 CWARN("%s: cannot find obj "DFID": rc = %ld\n",
1402 mdt_obd_name(mdt), PFID(&fid), PTR_ERR(mdt_pobj));
1406 if (!mdt_object_exists(mdt_pobj)) {
1407 CDEBUG(D_INFO, "%s: obj "DFID" does not exist\n",
1408 mdt_obd_name(mdt), PFID(&fid));
1409 mdt_object_put(info->mti_env, mdt_pobj);
1413 if (mdt_pobj == pobj) {
1414 CDEBUG(D_INFO, "%s: skipping parent obj "DFID"\n",
1415 mdt_obd_name(mdt), PFID(&fid));
1416 mdt_object_put(info->mti_env, mdt_pobj);
1422 mdt_object_put(info->mti_env, mdt_pobj);
1423 GOTO(out, rc = -ENOMEM);
1426 mdt_lock_pdo_init(&mll->mll_lh, LCK_PW, &name);
1427 rc = mdt_object_lock(info, mdt_pobj, &mll->mll_lh,
1428 MDS_INODELOCK_UPDATE,
1431 CERROR("%s: cannot lock "DFID": rc =%d\n",
1432 mdt_obd_name(mdt), PFID(&fid), rc);
1433 mdt_object_put(info->mti_env, mdt_pobj);
1438 INIT_LIST_HEAD(&mll->mll_list);
1439 mll->mll_obj = mdt_pobj;
1440 list_add_tail(&mll->mll_list, lock_list);
1444 mdt_unlock_list(info, lock_list, rc);
1448 /* migrate files from one MDT to another MDT */
1449 static int mdt_reint_migrate_internal(struct mdt_thread_info *info,
1450 struct mdt_lock_handle *lhc)
1452 struct mdt_reint_record *rr = &info->mti_rr;
1453 struct md_attr *ma = &info->mti_attr;
1454 struct mdt_object *msrcdir;
1455 struct mdt_object *mold;
1456 struct mdt_object *mnew = NULL;
1457 struct mdt_lock_handle *lh_dirp;
1458 struct mdt_lock_handle *lh_childp;
1459 struct mdt_lock_handle *lh_tgtp = NULL;
1460 struct lu_fid *old_fid = &info->mti_tmp_fid1;
1461 struct list_head lock_list;
1465 CDEBUG(D_INODE, "migrate "DFID"/"DNAME" to "DFID"\n", PFID(rr->rr_fid1),
1466 PNAME(&rr->rr_name), PFID(rr->rr_fid2));
1468 /* 1: lock the source dir. */
1469 msrcdir = mdt_object_find(info->mti_env, info->mti_mdt, rr->rr_fid1);
1470 if (IS_ERR(msrcdir)) {
1471 CERROR("%s: cannot find source dir "DFID" : rc = %d\n",
1472 mdt_obd_name(info->mti_mdt), PFID(rr->rr_fid1),
1473 (int)PTR_ERR(msrcdir));
1474 RETURN(PTR_ERR(msrcdir));
1477 lh_dirp = &info->mti_lh[MDT_LH_PARENT];
1478 mdt_lock_pdo_init(lh_dirp, LCK_PW, &rr->rr_name);
1479 rc = mdt_object_lock(info, msrcdir, lh_dirp,
1480 MDS_INODELOCK_UPDATE,
1483 GOTO(out_put_parent, rc);
1485 if (!mdt_object_remote(msrcdir)) {
1486 rc = mdt_version_get_check_save(info, msrcdir, 0);
1488 GOTO(out_unlock_parent, rc);
1491 /* 2: sanity check and find the object to be migrated. */
1493 rc = mdt_lookup_version_check(info, msrcdir, &rr->rr_name, old_fid, 2);
1495 GOTO(out_unlock_parent, rc);
1497 if (lu_fid_eq(old_fid, rr->rr_fid1) || lu_fid_eq(old_fid, rr->rr_fid2))
1498 GOTO(out_unlock_parent, rc = -EINVAL);
1500 if (!fid_is_md_operative(old_fid))
1501 GOTO(out_unlock_parent, rc = -EPERM);
1503 mold = mdt_object_find(info->mti_env, info->mti_mdt, old_fid);
1505 GOTO(out_unlock_parent, rc = PTR_ERR(mold));
1507 if (mdt_object_remote(mold)) {
1508 CERROR("%s: source "DFID" is on the remote MDT\n",
1509 mdt_obd_name(info->mti_mdt), PFID(old_fid));
1510 GOTO(out_put_child, rc = -EREMOTE);
1513 if (S_ISREG(lu_object_attr(&mold->mot_obj)) &&
1514 !mdt_object_remote(msrcdir)) {
1515 CERROR("%s: parent "DFID" is still on the same"
1516 " MDT, which should be migrated first:"
1517 " rc = %d\n", mdt_obd_name(info->mti_mdt),
1518 PFID(mdt_object_fid(msrcdir)), -EPERM);
1519 GOTO(out_put_child, rc = -EPERM);
1522 rc = mdt_remote_permission(info, msrcdir, mold);
1524 GOTO(out_put_child, rc);
1526 /* 3: iterate the linkea of the object and lock all of the objects */
1527 INIT_LIST_HEAD(&lock_list);
1528 rc = mdt_lock_objects_in_linkea(info, mold, msrcdir, &lock_list);
1530 GOTO(out_put_child, rc);
1532 /* 4: lock of the object migrated object */
1533 lh_childp = &info->mti_lh[MDT_LH_OLD];
1534 mdt_lock_reg_init(lh_childp, LCK_EX);
1535 rc = mdt_object_lock(info, mold, lh_childp,
1536 MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE |
1537 MDS_INODELOCK_LAYOUT, MDT_CROSS_LOCK);
1539 GOTO(out_unlock_list, rc);
1541 ma->ma_need = MA_LMV;
1543 ma->ma_lmv = (union lmv_mds_md *)info->mti_xattr_buf;
1544 ma->ma_lmv_size = sizeof(info->mti_xattr_buf);
1545 rc = mdt_stripe_get(info, mold, ma, XATTR_NAME_LMV);
1547 GOTO(out_unlock_list, rc);
1549 if ((ma->ma_valid & MA_LMV)) {
1550 struct lmv_mds_md_v1 *lmm1;
1552 lmv_le_to_cpu(ma->ma_lmv, ma->ma_lmv);
1553 lmm1 = &ma->ma_lmv->lmv_md_v1;
1554 if (!(lmm1->lmv_hash_type & LMV_HASH_FLAG_MIGRATION)) {
1555 CERROR("%s: can not migrate striped dir "DFID
1556 ": rc = %d\n", mdt_obd_name(info->mti_mdt),
1557 PFID(mdt_object_fid(mold)), -EPERM);
1558 GOTO(out_unlock_child, rc = -EPERM);
1561 if (!fid_is_sane(&lmm1->lmv_stripe_fids[1]))
1562 GOTO(out_unlock_child, rc = -EINVAL);
1564 mnew = mdt_object_find(info->mti_env, info->mti_mdt,
1565 &lmm1->lmv_stripe_fids[1]);
1567 GOTO(out_unlock_child, rc = PTR_ERR(mnew));
1569 if (!mdt_object_remote(mnew)) {
1570 CERROR("%s: "DFID" being migrated is on this MDT:"
1571 " rc = %d\n", mdt_obd_name(info->mti_mdt),
1572 PFID(rr->rr_fid2), -EPERM);
1573 GOTO(out_put_new, rc = -EPERM);
1576 lh_tgtp = &info->mti_lh[MDT_LH_CHILD];
1577 mdt_lock_reg_init(lh_tgtp, LCK_EX);
1578 rc = mdt_remote_object_lock(info, mnew,
1579 mdt_object_fid(mnew),
1580 &lh_tgtp->mlh_rreg_lh,
1581 lh_tgtp->mlh_rreg_mode,
1582 MDS_INODELOCK_UPDATE);
1585 GOTO(out_put_new, rc);
1588 mnew = mdt_object_find(info->mti_env, info->mti_mdt,
1591 GOTO(out_unlock_child, rc = PTR_ERR(mnew));
1592 if (!mdt_object_remote(mnew)) {
1593 CERROR("%s: Migration "DFID" is on this MDT:"
1594 " rc = %d\n", mdt_obd_name(info->mti_mdt),
1595 PFID(rr->rr_fid2), -EXDEV);
1596 GOTO(out_put_new, rc = -EXDEV);
1601 mdt_reint_init_ma(info, ma);
1603 mdt_fail_write(info->mti_env, info->mti_mdt->mdt_bottom,
1604 OBD_FAIL_MDS_REINT_RENAME_WRITE);
1606 rc = mdo_migrate(info->mti_env, mdt_object_child(msrcdir),
1607 mdt_object_child(mold), &rr->rr_name,
1608 mdt_object_child(mnew), ma);
1610 GOTO(out_unlock_new, rc);
1612 if (lh_tgtp != NULL)
1613 mdt_object_unlock(info, mnew, lh_tgtp, rc);
1616 mdt_object_put(info->mti_env, mnew);
1618 mdt_object_unlock(info, mold, lh_childp, rc);
1620 mdt_unlock_list(info, &lock_list, rc);
1622 mdt_object_put(info->mti_env, mold);
1624 mdt_object_unlock(info, msrcdir, lh_dirp, rc);
1626 mdt_object_put(info->mti_env, msrcdir);
1631 static struct mdt_object *mdt_object_find_check(struct mdt_thread_info *info,
1632 const struct lu_fid *fid,
1635 struct mdt_object *dir;
1639 dir = mdt_object_find(info->mti_env, info->mti_mdt, fid);
1643 /* check early, the real version will be saved after locking */
1644 rc = mdt_version_get_check(info, dir, idx);
1650 mdt_object_put(info->mti_env, dir);
1654 static int mdt_object_lock_save(struct mdt_thread_info *info,
1655 struct mdt_object *dir,
1656 struct mdt_lock_handle *lh,
1661 /* we lock the target dir if it is local */
1662 rc = mdt_object_lock(info, dir, lh, MDS_INODELOCK_UPDATE,
1667 /* get and save correct version after locking */
1668 mdt_version_get_save(info, dir, idx);
1673 static int mdt_rename_parents_lock(struct mdt_thread_info *info,
1674 struct mdt_object **srcp,
1675 struct mdt_object **tgtp)
1677 struct mdt_reint_record *rr = &info->mti_rr;
1678 const struct lu_fid *fid_src = rr->rr_fid1;
1679 const struct lu_fid *fid_tgt = rr->rr_fid2;
1680 struct mdt_lock_handle *lh_src = &info->mti_lh[MDT_LH_PARENT];
1681 struct mdt_lock_handle *lh_tgt = &info->mti_lh[MDT_LH_CHILD];
1682 struct mdt_object *src;
1683 struct mdt_object *tgt;
1688 /* find both parents. */
1689 src = mdt_object_find_check(info, fid_src, 0);
1691 RETURN(PTR_ERR(src));
1693 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RENAME3, 5);
1695 if (lu_fid_eq(fid_src, fid_tgt)) {
1697 mdt_object_get(info->mti_env, tgt);
1699 /* Check if the @src is not a child of the @tgt, otherwise a
1700 * reverse locking must take place. */
1701 rc = mdt_is_subdir(info, src, fid_tgt);
1705 GOTO(err_src_put, rc);
1707 tgt = mdt_object_find_check(info, fid_tgt, 1);
1709 GOTO(err_src_put, rc = PTR_ERR(tgt));
1711 if (unlikely(mdt_object_remote(tgt))) {
1712 CDEBUG(D_INFO, "Source dir "DFID" target dir "DFID
1713 "on different MDTs\n", PFID(fid_src),
1715 GOTO(err_tgt_put, rc = -EXDEV);
1719 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RENAME4, 5);
1721 /* lock parents in the proper order. */
1723 rc = mdt_object_lock_save(info, tgt, lh_tgt, 1);
1725 GOTO(err_tgt_put, rc);
1727 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RENAME, 5);
1729 rc = mdt_object_lock_save(info, src, lh_src, 0);
1731 rc = mdt_object_lock_save(info, src, lh_src, 0);
1733 GOTO(err_tgt_put, rc);
1735 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RENAME, 5);
1738 rc = mdt_object_lock_save(info, tgt, lh_tgt, 1);
1739 else if (lh_src->mlh_pdo_hash != lh_tgt->mlh_pdo_hash) {
1740 rc = mdt_pdir_hash_lock(info, lh_tgt, tgt,
1741 MDS_INODELOCK_UPDATE);
1742 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_PDO_LOCK2, 10);
1746 GOTO(err_unlock, rc);
1748 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RENAME4, 5);
1755 /* The order does not matter as the handle is checked inside,
1756 * as well as not used handle. */
1757 mdt_object_unlock(info, src, lh_src, rc);
1758 mdt_object_unlock(info, tgt, lh_tgt, rc);
1760 mdt_object_put(info->mti_env, tgt);
1762 mdt_object_put(info->mti_env, src);
1767 * VBR: rename versions in reply: 0 - src parent; 1 - tgt parent;
1768 * 2 - src child; 3 - tgt child.
1769 * Update on disk version of src child.
1772 * For DNE phase I, only these renames are allowed
1773 * mv src_p/src_c tgt_p/tgt_c
1774 * 1. src_p/src_c/tgt_p/tgt_c are in the same MDT.
1775 * 2. src_p and tgt_p are same directory, and tgt_c does not
1776 * exists. In this case, all of modification will happen
1777 * in the MDT where ithesource parent is, only one remote
1778 * update is needed, i.e. set c_time/m_time on the child.
1779 * And tgt_c will be still in the same MDT as the original
1782 static int mdt_reint_rename_internal(struct mdt_thread_info *info,
1783 struct mdt_lock_handle *lhc)
1785 struct mdt_reint_record *rr = &info->mti_rr;
1786 struct md_attr *ma = &info->mti_attr;
1787 struct ptlrpc_request *req = mdt_info_req(info);
1788 struct mdt_object *msrcdir = NULL;
1789 struct mdt_object *mtgtdir = NULL;
1790 struct mdt_object *mold;
1791 struct mdt_object *mnew = NULL;
1792 struct mdt_lock_handle *lh_srcdirp;
1793 struct mdt_lock_handle *lh_tgtdirp;
1794 struct mdt_lock_handle *lh_oldp = NULL;
1795 struct mdt_lock_handle *lh_newp = NULL;
1796 struct lu_fid *old_fid = &info->mti_tmp_fid1;
1797 struct lu_fid *new_fid = &info->mti_tmp_fid2;
1801 DEBUG_REQ(D_INODE, req, "rename "DFID"/"DNAME" to "DFID"/"DNAME,
1802 PFID(rr->rr_fid1), PNAME(&rr->rr_name),
1803 PFID(rr->rr_fid2), PNAME(&rr->rr_tgt_name));
1805 lh_srcdirp = &info->mti_lh[MDT_LH_PARENT];
1806 mdt_lock_pdo_init(lh_srcdirp, LCK_PW, &rr->rr_name);
1807 lh_tgtdirp = &info->mti_lh[MDT_LH_CHILD];
1808 mdt_lock_pdo_init(lh_tgtdirp, LCK_PW, &rr->rr_tgt_name);
1810 /* step 1&2: lock the source and target dirs. */
1811 rc = mdt_rename_parents_lock(info, &msrcdir, &mtgtdir);
1815 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RENAME2, 5);
1817 /* step 3: find & lock the old object. */
1819 rc = mdt_lookup_version_check(info, msrcdir, &rr->rr_name, old_fid, 2);
1821 GOTO(out_unlock_parents, rc);
1823 if (lu_fid_eq(old_fid, rr->rr_fid1) || lu_fid_eq(old_fid, rr->rr_fid2))
1824 GOTO(out_unlock_parents, rc = -EINVAL);
1826 if (!fid_is_md_operative(old_fid))
1827 GOTO(out_unlock_parents, rc = -EPERM);
1829 mold = mdt_object_find(info->mti_env, info->mti_mdt, old_fid);
1831 GOTO(out_unlock_parents, rc = PTR_ERR(mold));
1833 /* Check if @mtgtdir is subdir of @mold, before locking child
1834 * to avoid reverse locking. */
1835 rc = mdt_is_subdir(info, mtgtdir, old_fid);
1837 GOTO(out_put_old, rc);
1839 tgt_vbr_obj_set(info->mti_env, mdt_obj2dt(mold));
1840 /* save version after locking */
1841 mdt_version_get_save(info, mold, 2);
1842 mdt_set_capainfo(info, 2, old_fid, BYPASS_CAPA);
1844 /* step 4: find & lock the new object. */
1845 /* new target object may not exist now */
1846 /* lookup with version checking */
1848 rc = mdt_lookup_version_check(info, mtgtdir, &rr->rr_tgt_name, new_fid,
1851 /* the new_fid should have been filled at this moment */
1852 if (lu_fid_eq(old_fid, new_fid))
1853 GOTO(out_put_old, rc);
1855 if (lu_fid_eq(new_fid, rr->rr_fid1) ||
1856 lu_fid_eq(new_fid, rr->rr_fid2))
1857 GOTO(out_put_old, rc = -EINVAL);
1859 if (!fid_is_md_operative(new_fid))
1860 GOTO(out_put_old, rc = -EPERM);
1862 if (mdt_object_remote(mold)) {
1863 CDEBUG(D_INFO, "Src child "DFID" is on another MDT\n",
1865 GOTO(out_put_old, rc = -EXDEV);
1868 mnew = mdt_object_find(info->mti_env, info->mti_mdt, new_fid);
1870 GOTO(out_put_old, rc = PTR_ERR(mnew));
1872 if (mdt_object_remote(mnew)) {
1873 CDEBUG(D_INFO, "src child "DFID" is on another MDT\n",
1875 GOTO(out_put_new, rc = -EXDEV);
1878 /* Before locking the target dir, check we do not replace
1879 * a dir with a non-dir, otherwise it may deadlock with
1880 * link op which tries to create a link in this dir
1881 * back to this non-dir. */
1882 if (S_ISDIR(lu_object_attr(&mnew->mot_obj)) &&
1883 !S_ISDIR(lu_object_attr(&mold->mot_obj)))
1884 GOTO(out_put_new, rc = -EISDIR);
1886 lh_oldp = &info->mti_lh[MDT_LH_OLD];
1887 mdt_lock_reg_init(lh_oldp, LCK_EX);
1888 rc = mdt_object_lock(info, mold, lh_oldp, MDS_INODELOCK_LOOKUP |
1889 MDS_INODELOCK_XATTR, MDT_CROSS_LOCK);
1891 GOTO(out_put_new, rc);
1893 /* Check if @msrcdir is subdir of @mnew, before locking child
1894 * to avoid reverse locking. */
1895 rc = mdt_is_subdir(info, msrcdir, new_fid);
1897 GOTO(out_unlock_old, rc);
1899 /* We used to acquire MDS_INODELOCK_FULL here but we
1900 * can't do this now because a running HSM restore on
1901 * the rename onto victim will hold the layout
1902 * lock. See LU-4002. */
1904 lh_newp = &info->mti_lh[MDT_LH_NEW];
1905 mdt_lock_reg_init(lh_newp, LCK_EX);
1906 rc = mdt_object_lock(info, mnew, lh_newp,
1907 MDS_INODELOCK_LOOKUP |
1908 MDS_INODELOCK_UPDATE,
1911 GOTO(out_unlock_old, rc);
1913 /* get and save version after locking */
1914 mdt_version_get_save(info, mnew, 3);
1915 mdt_set_capainfo(info, 3, new_fid, BYPASS_CAPA);
1916 } else if (rc != -EREMOTE && rc != -ENOENT) {
1917 GOTO(out_put_old, rc);
1919 /* If mnew does not exist and mold are remote directory,
1920 * it only allows rename if they are under same directory */
1921 if (mtgtdir != msrcdir && mdt_object_remote(mold)) {
1922 CDEBUG(D_INFO, "Src child "DFID" is on another MDT\n",
1924 GOTO(out_put_old, rc = -EXDEV);
1927 lh_oldp = &info->mti_lh[MDT_LH_OLD];
1928 mdt_lock_reg_init(lh_oldp, LCK_EX);
1929 rc = mdt_object_lock(info, mold, lh_oldp, MDS_INODELOCK_LOOKUP |
1930 MDS_INODELOCK_XATTR, MDT_CROSS_LOCK);
1932 GOTO(out_put_old, rc);
1934 mdt_enoent_version_save(info, 3);
1937 /* step 5: rename it */
1938 mdt_reint_init_ma(info, ma);
1940 mdt_fail_write(info->mti_env, info->mti_mdt->mdt_bottom,
1941 OBD_FAIL_MDS_REINT_RENAME_WRITE);
1944 mutex_lock(&mnew->mot_lov_mutex);
1946 rc = mdo_rename(info->mti_env, mdt_object_child(msrcdir),
1947 mdt_object_child(mtgtdir), old_fid, &rr->rr_name,
1948 mnew != NULL ? mdt_object_child(mnew) : NULL,
1949 &rr->rr_tgt_name, ma);
1952 mutex_unlock(&mnew->mot_lov_mutex);
1954 /* handle last link of tgt object */
1956 mdt_counter_incr(req, LPROC_MDT_RENAME);
1958 mdt_handle_last_unlink(info, mnew, ma);
1960 mdt_rename_counter_tally(info, info->mti_mdt, req,
1966 mdt_object_unlock(info, mnew, lh_newp, rc);
1968 mdt_object_unlock(info, mold, lh_oldp, rc);
1971 mdt_object_put(info->mti_env, mnew);
1973 mdt_object_put(info->mti_env, mold);
1975 mdt_object_unlock_put(info, mtgtdir, lh_tgtdirp, rc);
1976 mdt_object_unlock_put(info, msrcdir, lh_srcdirp, rc);
1980 static int mdt_reint_rename_or_migrate(struct mdt_thread_info *info,
1981 struct mdt_lock_handle *lhc,
1982 enum mdt_rename_lock rename_lock)
1984 struct mdt_reint_record *rr = &info->mti_rr;
1985 struct ptlrpc_request *req = mdt_info_req(info);
1986 struct lustre_handle rename_lh = { 0 };
1990 if (info->mti_dlm_req)
1991 ldlm_request_cancel(req, info->mti_dlm_req, 0, LATF_SKIP);
1993 if (!fid_is_md_operative(rr->rr_fid1) ||
1994 !fid_is_md_operative(rr->rr_fid2))
1997 rc = mdt_rename_lock(info, &rename_lh, rename_lock);
1999 CERROR("%s: can't lock FS for rename: rc = %d\n",
2000 mdt_obd_name(info->mti_mdt), rc);
2004 if (rename_lock == MRL_RENAME)
2005 rc = mdt_reint_rename_internal(info, lhc);
2007 rc = mdt_reint_migrate_internal(info, lhc);
2009 if (lustre_handle_is_used(&rename_lh))
2010 mdt_rename_unlock(&rename_lh);
2015 static int mdt_reint_rename(struct mdt_thread_info *info,
2016 struct mdt_lock_handle *lhc)
2018 return mdt_reint_rename_or_migrate(info, lhc, MRL_RENAME);
2021 static int mdt_reint_migrate(struct mdt_thread_info *info,
2022 struct mdt_lock_handle *lhc)
2024 return mdt_reint_rename_or_migrate(info, lhc, MRL_MIGRATE);
2027 struct mdt_reinter {
2028 int (*mr_handler)(struct mdt_thread_info *, struct mdt_lock_handle *);
2029 enum lprocfs_extra_opc mr_extra_opc;
2032 static const struct mdt_reinter mdt_reinters[] = {
2034 .mr_handler = &mdt_reint_setattr,
2035 .mr_extra_opc = MDS_REINT_SETATTR,
2038 .mr_handler = &mdt_reint_create,
2039 .mr_extra_opc = MDS_REINT_CREATE,
2042 .mr_handler = &mdt_reint_link,
2043 .mr_extra_opc = MDS_REINT_LINK,
2046 .mr_handler = &mdt_reint_unlink,
2047 .mr_extra_opc = MDS_REINT_UNLINK,
2050 .mr_handler = &mdt_reint_rename,
2051 .mr_extra_opc = MDS_REINT_RENAME,
2054 .mr_handler = &mdt_reint_open,
2055 .mr_extra_opc = MDS_REINT_OPEN,
2057 [REINT_SETXATTR] = {
2058 .mr_handler = &mdt_reint_setxattr,
2059 .mr_extra_opc = MDS_REINT_SETXATTR,
2062 .mr_handler = &mdt_reint_unlink,
2063 .mr_extra_opc = MDS_REINT_UNLINK,
2066 .mr_handler = &mdt_reint_migrate,
2067 .mr_extra_opc = MDS_REINT_RENAME,
2071 int mdt_reint_rec(struct mdt_thread_info *info,
2072 struct mdt_lock_handle *lhc)
2074 const struct mdt_reinter *mr;
2078 if (!(info->mti_rr.rr_opcode < ARRAY_SIZE(mdt_reinters)))
2081 mr = &mdt_reinters[info->mti_rr.rr_opcode];
2082 if (mr->mr_handler == NULL)
2085 rc = (*mr->mr_handler)(info, lhc);
2087 lprocfs_counter_incr(ptlrpc_req2svc(mdt_info_req(info))->srv_stats,
2088 PTLRPC_LAST_CNTR + mr->mr_extra_opc);