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 "mdt_internal.h"
51 static inline void mdt_reint_init_ma(struct mdt_thread_info *info,
54 ma->ma_need = MA_INODE;
58 static int mdt_create_pack_capa(struct mdt_thread_info *info, int rc,
59 struct mdt_object *object,
60 struct mdt_body *repbody)
64 /* for cross-ref mkdir, mds capa has been fetched from remote obj, then
65 * we won't go to below*/
66 if (repbody->valid & OBD_MD_FLMDSCAPA)
69 if (rc == 0 && info->mti_mdt->mdt_lut.lut_mds_capa &&
70 exp_connect_flags(info->mti_exp) & OBD_CONNECT_MDS_CAPA) {
71 struct lustre_capa *capa;
73 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA1);
75 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
76 rc = mo_capa_get(info->mti_env, mdt_object_child(object), capa,
79 repbody->valid |= OBD_MD_FLMDSCAPA;
86 * Get version of object by fid.
88 * Return real version or ENOENT_VERSION if object doesn't exist
90 static void mdt_obj_version_get(struct mdt_thread_info *info,
91 struct mdt_object *o, __u64 *version)
94 if (mdt_object_exists(o) && !mdt_object_remote(o) &&
95 !fid_is_obf(mdt_object_fid(o)))
96 *version = dt_version_get(info->mti_env, mdt_obj2dt(o));
98 *version = ENOENT_VERSION;
99 CDEBUG(D_INODE, "FID "DFID" version is "LPX64"\n",
100 PFID(mdt_object_fid(o)), *version);
104 * Check version is correct.
106 * Should be called only during replay.
108 static int mdt_version_check(struct ptlrpc_request *req,
109 __u64 version, int idx)
111 __u64 *pre_ver = lustre_msg_get_versions(req->rq_reqmsg);
114 if (!exp_connect_vbr(req->rq_export))
117 LASSERT(req_is_replay(req));
118 /** VBR: version is checked always because costs nothing */
119 LASSERT(idx < PTLRPC_NUM_VERSIONS);
120 /** Sanity check for malformed buffers */
121 if (pre_ver == NULL) {
122 CERROR("No versions in request buffer\n");
123 spin_lock(&req->rq_export->exp_lock);
124 req->rq_export->exp_vbr_failed = 1;
125 spin_unlock(&req->rq_export->exp_lock);
127 } else if (pre_ver[idx] != version) {
128 CDEBUG(D_INODE, "Version mismatch "LPX64" != "LPX64"\n",
129 pre_ver[idx], version);
130 spin_lock(&req->rq_export->exp_lock);
131 req->rq_export->exp_vbr_failed = 1;
132 spin_unlock(&req->rq_export->exp_lock);
139 * Save pre-versions in reply.
141 static void mdt_version_save(struct ptlrpc_request *req, __u64 version,
146 if (!exp_connect_vbr(req->rq_export))
149 LASSERT(!req_is_replay(req));
150 LASSERT(req->rq_repmsg != NULL);
151 reply_ver = lustre_msg_get_versions(req->rq_repmsg);
153 reply_ver[idx] = version;
157 * Save enoent version, it is needed when it is obvious that object doesn't
158 * exist, e.g. child during create.
160 static void mdt_enoent_version_save(struct mdt_thread_info *info, int idx)
162 /* save version of file name for replay, it must be ENOENT here */
163 if (!req_is_replay(mdt_info_req(info))) {
164 info->mti_ver[idx] = ENOENT_VERSION;
165 mdt_version_save(mdt_info_req(info), info->mti_ver[idx], idx);
170 * Get version from disk and save in reply buffer.
172 * Versions are saved in reply only during normal operations not replays.
174 void mdt_version_get_save(struct mdt_thread_info *info,
175 struct mdt_object *mto, int idx)
177 /* don't save versions during replay */
178 if (!req_is_replay(mdt_info_req(info))) {
179 mdt_obj_version_get(info, mto, &info->mti_ver[idx]);
180 mdt_version_save(mdt_info_req(info), info->mti_ver[idx], idx);
185 * Get version from disk and check it, no save in reply.
187 int mdt_version_get_check(struct mdt_thread_info *info,
188 struct mdt_object *mto, int idx)
190 /* only check versions during replay */
191 if (!req_is_replay(mdt_info_req(info)))
194 mdt_obj_version_get(info, mto, &info->mti_ver[idx]);
195 return mdt_version_check(mdt_info_req(info), info->mti_ver[idx], idx);
199 * Get version from disk and check if recovery or just save.
201 int mdt_version_get_check_save(struct mdt_thread_info *info,
202 struct mdt_object *mto, int idx)
206 mdt_obj_version_get(info, mto, &info->mti_ver[idx]);
207 if (req_is_replay(mdt_info_req(info)))
208 rc = mdt_version_check(mdt_info_req(info), info->mti_ver[idx],
211 mdt_version_save(mdt_info_req(info), info->mti_ver[idx], idx);
216 * Lookup with version checking.
218 * This checks version of 'name'. Many reint functions uses 'name' for child not
219 * FID, therefore we need to get object by name and check its version.
221 int mdt_lookup_version_check(struct mdt_thread_info *info,
222 struct mdt_object *p, const struct lu_name *lname,
223 struct lu_fid *fid, int idx)
227 rc = mdo_lookup(info->mti_env, mdt_object_child(p), lname, fid,
229 /* Check version only during replay */
230 if (!req_is_replay(mdt_info_req(info)))
233 info->mti_ver[idx] = ENOENT_VERSION;
235 struct mdt_object *child;
236 child = mdt_object_find(info->mti_env, info->mti_mdt, fid);
237 if (likely(!IS_ERR(child))) {
238 mdt_obj_version_get(info, child, &info->mti_ver[idx]);
239 mdt_object_put(info->mti_env, child);
242 vbrc = mdt_version_check(mdt_info_req(info), info->mti_ver[idx], idx);
243 return vbrc ? vbrc : rc;
248 * VBR: we save three versions in reply:
249 * 0 - parent. Check that parent version is the same during replay.
250 * 1 - name. Version of 'name' if file exists with the same name or
251 * ENOENT_VERSION, it is needed because file may appear due to missed replays.
252 * 2 - child. Version of child by FID. Must be ENOENT. It is mostly sanity
255 static int mdt_md_create(struct mdt_thread_info *info)
257 struct mdt_device *mdt = info->mti_mdt;
258 struct mdt_object *parent;
259 struct mdt_object *child;
260 struct mdt_lock_handle *lh;
261 struct mdt_body *repbody;
262 struct md_attr *ma = &info->mti_attr;
263 struct mdt_reint_record *rr = &info->mti_rr;
267 DEBUG_REQ(D_INODE, mdt_info_req(info), "Create ("DNAME"->"DFID") "
269 PNAME(&rr->rr_name), PFID(rr->rr_fid2), PFID(rr->rr_fid1));
271 if (fid_is_obf(rr->rr_fid1) || fid_is_dot_lustre(rr->rr_fid1))
274 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
276 lh = &info->mti_lh[MDT_LH_PARENT];
277 mdt_lock_pdo_init(lh, LCK_PW, &rr->rr_name);
279 parent = mdt_object_find(info->mti_env, info->mti_mdt, rr->rr_fid1);
281 RETURN(PTR_ERR(parent));
283 if (!mdt_object_exists(parent))
284 GOTO(put_parent, rc = -ENOENT);
286 lh = &info->mti_lh[MDT_LH_PARENT];
287 if (mdt_object_remote(parent)) {
288 mdt_lock_reg_init(lh, LCK_EX);
289 rc = mdt_remote_object_lock(info, parent, &lh->mlh_rreg_lh,
291 MDS_INODELOCK_UPDATE);
293 GOTO(put_parent, rc);
296 mdt_lock_pdo_init(lh, LCK_PW, &rr->rr_name);
297 rc = mdt_object_lock(info, parent, lh, MDS_INODELOCK_UPDATE,
300 GOTO(put_parent, rc);
302 rc = mdt_version_get_check_save(info, parent, 0);
304 GOTO(unlock_parent, rc);
308 * Check child name version during replay.
309 * During create replay a file may exist with same name.
311 rc = mdt_lookup_version_check(info, parent, &rr->rr_name,
312 &info->mti_tmp_fid1, 1);
314 GOTO(unlock_parent, rc = -EEXIST);
316 /* -ENOENT is expected here */
318 GOTO(unlock_parent, rc);
320 /* save version of file name for replay, it must be ENOENT here */
321 mdt_enoent_version_save(info, 1);
323 child = mdt_object_new(info->mti_env, mdt, rr->rr_fid2);
324 if (likely(!IS_ERR(child))) {
325 struct md_object *next = mdt_object_child(parent);
327 if (mdt_object_remote(child)) {
328 struct seq_server_site *ss;
329 struct lu_ucred *uc = mdt_ucred(info);
331 if (!md_capable(uc, CFS_CAP_SYS_ADMIN)) {
333 mdt->mdt_enable_remote_dir_gid &&
334 mdt->mdt_enable_remote_dir_gid != -1) {
335 CERROR("%s: Creating remote dir is only"
336 " permitted for administrator or"
337 " set mdt_enable_remote_dir_gid:"
339 mdt_obd_name(mdt), -EPERM);
340 GOTO(out_put_child, rc = -EPERM);
344 ss = mdt_seq_site(mdt);
345 if (ss->ss_node_id != 0 &&
346 mdt->mdt_enable_remote_dir == 0) {
347 CERROR("%s: remote dir is only permitted on"
349 " mdt.*.enable_remote_dir=1\n",
351 GOTO(out_put_child, rc = -EPERM);
353 if (!mdt_is_dne_client(mdt_info_req(info)->rq_export)) {
354 /* Return -EIO for old client */
355 GOTO(out_put_child, rc = -EIO);
359 ma->ma_need = MA_INODE;
361 /* capa for cross-ref will be stored here */
362 ma->ma_capa = req_capsule_server_get(info->mti_pill,
364 LASSERT(ma->ma_capa);
366 mdt_fail_write(info->mti_env, info->mti_mdt->mdt_bottom,
367 OBD_FAIL_MDS_REINT_CREATE_WRITE);
369 /* Version of child will be updated on disk. */
370 tgt_vbr_obj_set(info->mti_env, mdt_obj2dt(child));
371 rc = mdt_version_get_check_save(info, child, 2);
373 GOTO(out_put_child, rc);
375 /* Let lower layer know current lock mode. */
376 info->mti_spec.sp_cr_mode =
377 mdt_dlm_mode2mdl_mode(lh->mlh_pdo_mode);
380 * Do not perform lookup sanity check. We know that name does
383 info->mti_spec.sp_cr_lookup = 0;
384 info->mti_spec.sp_feat = &dt_directory_features;
386 rc = mdo_create(info->mti_env, next, &rr->rr_name,
387 mdt_object_child(child), &info->mti_spec, ma);
389 rc = mdt_attr_get_complex(info, child, ma);
392 /* Return fid & attr to client. */
393 if (ma->ma_valid & MA_INODE)
394 mdt_pack_attr2body(info, repbody, &ma->ma_attr,
395 mdt_object_fid(child));
398 mdt_object_put(info->mti_env, child);
402 mdt_create_pack_capa(info, rc, child, repbody);
404 mdt_object_unlock(info, parent, lh, rc);
406 mdt_object_put(info->mti_env, parent);
410 int mdt_attr_set(struct mdt_thread_info *info, struct mdt_object *mo,
411 struct md_attr *ma, int flags)
413 struct mdt_lock_handle *lh;
414 int do_vbr = ma->ma_attr.la_valid & (LA_MODE|LA_UID|LA_GID|LA_FLAGS);
415 __u64 lockpart = MDS_INODELOCK_UPDATE;
419 /* attr shouldn't be set on remote object */
420 LASSERT(!mdt_object_remote(mo));
422 lh = &info->mti_lh[MDT_LH_PARENT];
423 mdt_lock_reg_init(lh, LCK_PW);
425 /* Even though the new MDT will grant PERM lock to the old
426 * client, but the old client will almost ignore that during
427 * So it needs to revoke both LOOKUP and PERM lock here, so
428 * both new and old client can cancel the dcache */
429 if (ma->ma_attr.la_valid & (LA_MODE|LA_UID|LA_GID))
430 lockpart |= MDS_INODELOCK_LOOKUP | MDS_INODELOCK_PERM;
432 rc = mdt_object_lock(info, mo, lh, lockpart, MDT_LOCAL_LOCK);
436 if (mdt_object_exists(mo) == 0)
437 GOTO(out_unlock, rc = -ENOENT);
439 /* all attrs are packed into mti_attr in unpack_setattr */
440 mdt_fail_write(info->mti_env, info->mti_mdt->mdt_bottom,
441 OBD_FAIL_MDS_REINT_SETATTR_WRITE);
443 /* This is only for set ctime when rename's source is on remote MDS. */
444 if (unlikely(ma->ma_attr.la_valid == LA_CTIME))
445 ma->ma_attr_flags |= MDS_VTX_BYPASS;
447 /* VBR: update version if attr changed are important for recovery */
449 /* update on-disk version of changed object */
450 tgt_vbr_obj_set(info->mti_env, mdt_obj2dt(mo));
451 rc = mdt_version_get_check_save(info, mo, 0);
453 GOTO(out_unlock, rc);
456 /* Ensure constant striping during chown(). See LU-2789. */
457 if (ma->ma_attr.la_valid & (LA_UID|LA_GID))
458 mutex_lock(&mo->mot_lov_mutex);
460 /* all attrs are packed into mti_attr in unpack_setattr */
461 rc = mo_attr_set(info->mti_env, mdt_object_child(mo), ma);
463 if (ma->ma_attr.la_valid & (LA_UID|LA_GID))
464 mutex_unlock(&mo->mot_lov_mutex);
467 GOTO(out_unlock, rc);
471 mdt_object_unlock(info, mo, lh, rc);
476 * Check HSM flags and add HS_DIRTY flag if relevant.
478 * A file could be set dirty only if it has a copy in the backend (HS_EXISTS)
479 * and is not RELEASED.
481 int mdt_add_dirty_flag(struct mdt_thread_info *info, struct mdt_object *mo,
487 /* If the file was modified, add the dirty flag */
488 ma->ma_need = MA_HSM;
489 rc = mdt_attr_get_complex(info, mo, ma);
491 CERROR("file attribute read error for "DFID": %d.\n",
492 PFID(mdt_object_fid(mo)), rc);
496 /* If an up2date copy exists in the backend, add dirty flag */
497 if ((ma->ma_valid & MA_HSM) && (ma->ma_hsm.mh_flags & HS_EXISTS)
498 && !(ma->ma_hsm.mh_flags & (HS_DIRTY|HS_RELEASED))) {
499 struct mdt_lock_handle *lh = &info->mti_lh[MDT_LH_CHILD];
501 ma->ma_hsm.mh_flags |= HS_DIRTY;
503 mdt_lock_reg_init(lh, LCK_PW);
504 rc = mdt_object_lock(info, mo, lh, MDS_INODELOCK_XATTR,
509 rc = mdt_hsm_attr_set(info, mo, &ma->ma_hsm);
511 CERROR("file attribute change error for "DFID": %d\n",
512 PFID(mdt_object_fid(mo)), rc);
513 mdt_object_unlock(info, mo, lh, rc);
519 static int mdt_reint_setattr(struct mdt_thread_info *info,
520 struct mdt_lock_handle *lhc)
522 struct md_attr *ma = &info->mti_attr;
523 struct mdt_reint_record *rr = &info->mti_rr;
524 struct ptlrpc_request *req = mdt_info_req(info);
525 struct mdt_export_data *med = &req->rq_export->exp_mdt_data;
526 struct mdt_file_data *mfd;
527 struct mdt_object *mo;
528 struct mdt_body *repbody;
532 DEBUG_REQ(D_INODE, req, "setattr "DFID" %x", PFID(rr->rr_fid1),
533 (unsigned int)ma->ma_attr.la_valid);
535 if (info->mti_dlm_req)
536 ldlm_request_cancel(req, info->mti_dlm_req, 0);
538 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
539 mo = mdt_object_find(info->mti_env, info->mti_mdt, rr->rr_fid1);
541 GOTO(out, rc = PTR_ERR(mo));
543 /* start a log jounal handle if needed */
544 if (!(mdt_conn_flags(info) & OBD_CONNECT_SOM)) {
545 if ((ma->ma_attr.la_valid & LA_SIZE) ||
546 (rr->rr_flags & MRF_OPEN_TRUNC)) {
547 /* Check write access for the O_TRUNC case */
548 if (mdt_write_read(mo) < 0)
549 GOTO(out_put, rc = -ETXTBSY);
551 } else if (info->mti_ioepoch &&
552 (info->mti_ioepoch->flags & MF_EPOCH_OPEN)) {
553 /* Truncate case. IOEpoch is opened. */
554 rc = mdt_write_get(mo);
558 mfd = mdt_mfd_new(med);
561 GOTO(out_put, rc = -ENOMEM);
564 mdt_ioepoch_open(info, mo, 0);
565 repbody->ioepoch = mo->mot_ioepoch;
567 mdt_object_get(info->mti_env, mo);
568 mdt_mfd_set_mode(mfd, MDS_FMODE_TRUNC);
569 mfd->mfd_object = mo;
570 mfd->mfd_xid = req->rq_xid;
572 spin_lock(&med->med_open_lock);
573 cfs_list_add(&mfd->mfd_list, &med->med_open_head);
574 spin_unlock(&med->med_open_lock);
575 repbody->handle.cookie = mfd->mfd_handle.h_cookie;
578 som_au = info->mti_ioepoch && info->mti_ioepoch->flags & MF_SOM_CHANGE;
580 /* SOM Attribute update case. Find the proper mfd and update
581 * SOM attributes on the proper object. */
582 LASSERT(mdt_conn_flags(info) & OBD_CONNECT_SOM);
583 LASSERT(info->mti_ioepoch);
585 spin_lock(&med->med_open_lock);
586 mfd = mdt_handle2mfd(med, &info->mti_ioepoch->handle,
589 spin_unlock(&med->med_open_lock);
590 CDEBUG(D_INODE, "no handle for file close: "
591 "fid = "DFID": cookie = "LPX64"\n",
592 PFID(info->mti_rr.rr_fid1),
593 info->mti_ioepoch->handle.cookie);
594 GOTO(out_put, rc = -ESTALE);
596 LASSERT(mfd->mfd_mode == MDS_FMODE_SOM);
597 LASSERT(!(info->mti_ioepoch->flags & MF_EPOCH_CLOSE));
599 class_handle_unhash(&mfd->mfd_handle);
600 cfs_list_del_init(&mfd->mfd_list);
601 spin_unlock(&med->med_open_lock);
603 mdt_mfd_close(info, mfd);
604 } else if ((ma->ma_valid & MA_INODE) && ma->ma_attr.la_valid) {
605 LASSERT((ma->ma_valid & MA_LOV) == 0);
606 rc = mdt_attr_set(info, mo, ma, rr->rr_flags);
609 } else if ((ma->ma_valid & MA_LOV) && (ma->ma_valid & MA_INODE)) {
610 struct lu_buf *buf = &info->mti_buf;
611 LASSERT(ma->ma_attr.la_valid == 0);
612 buf->lb_buf = ma->ma_lmm;
613 buf->lb_len = ma->ma_lmm_size;
614 rc = mo_xattr_set(info->mti_env, mdt_object_child(mo),
615 buf, XATTR_NAME_LOV, 0);
618 } else if ((ma->ma_valid & MA_LMV) && (ma->ma_valid & MA_INODE)) {
619 struct lu_buf *buf = &info->mti_buf;
621 LASSERT(ma->ma_attr.la_valid == 0);
622 buf->lb_buf = ma->ma_lmv;
623 buf->lb_len = ma->ma_lmv_size;
624 rc = mo_xattr_set(info->mti_env, mdt_object_child(mo),
625 buf, XATTR_NAME_DEFAULT_LMV, 0);
631 /* If file data is modified, add the dirty flag */
632 if (ma->ma_attr_flags & MDS_DATA_MODIFIED)
633 rc = mdt_add_dirty_flag(info, mo, ma);
635 ma->ma_need = MA_INODE;
637 rc = mdt_attr_get_complex(info, mo, ma);
641 mdt_pack_attr2body(info, repbody, &ma->ma_attr, mdt_object_fid(mo));
643 if (info->mti_mdt->mdt_lut.lut_oss_capa &&
644 exp_connect_flags(info->mti_exp) & OBD_CONNECT_OSS_CAPA &&
645 S_ISREG(lu_object_attr(&mo->mot_obj)) &&
646 (ma->ma_attr.la_valid & LA_SIZE) && !som_au) {
647 struct lustre_capa *capa;
649 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA2);
651 capa->lc_opc = CAPA_OPC_OSS_DEFAULT | CAPA_OPC_OSS_TRUNC;
652 rc = mo_capa_get(info->mti_env, mdt_object_child(mo), capa, 0);
655 repbody->valid |= OBD_MD_FLOSSCAPA;
660 mdt_object_put(info->mti_env, mo);
663 mdt_counter_incr(req, LPROC_MDT_SETATTR);
665 mdt_client_compatibility(info);
666 rc2 = mdt_fix_reply(info);
672 static int mdt_reint_create(struct mdt_thread_info *info,
673 struct mdt_lock_handle *lhc)
675 struct ptlrpc_request *req = mdt_info_req(info);
679 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_CREATE))
680 RETURN(err_serious(-ESTALE));
682 if (info->mti_dlm_req)
683 ldlm_request_cancel(mdt_info_req(info), info->mti_dlm_req, 0);
685 if (!lu_name_is_valid(&info->mti_rr.rr_name))
688 switch (info->mti_attr.ma_attr.la_mode & S_IFMT) {
690 mdt_counter_incr(req, LPROC_MDT_MKDIR);
698 /* Special file should stay on the same node as parent. */
699 mdt_counter_incr(req, LPROC_MDT_MKNOD);
702 CERROR("%s: Unsupported mode %o\n",
703 mdt_obd_name(info->mti_mdt),
704 info->mti_attr.ma_attr.la_mode);
705 RETURN(err_serious(-EOPNOTSUPP));
708 rc = mdt_md_create(info);
713 * VBR: save parent version in reply and child version getting by its name.
714 * Version of child is getting and checking during its lookup. If
716 static int mdt_reint_unlink(struct mdt_thread_info *info,
717 struct mdt_lock_handle *lhc)
719 struct mdt_reint_record *rr = &info->mti_rr;
720 struct ptlrpc_request *req = mdt_info_req(info);
721 struct md_attr *ma = &info->mti_attr;
722 struct lu_fid *child_fid = &info->mti_tmp_fid1;
723 struct mdt_object *mp;
724 struct mdt_object *mc;
725 struct mdt_lock_handle *parent_lh;
726 struct mdt_lock_handle *child_lh;
731 DEBUG_REQ(D_INODE, req, "unlink "DFID"/"DNAME"", PFID(rr->rr_fid1),
732 PNAME(&rr->rr_name));
734 if (info->mti_dlm_req)
735 ldlm_request_cancel(req, info->mti_dlm_req, 0);
737 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_UNLINK))
738 RETURN(err_serious(-ENOENT));
740 if (fid_is_obf(rr->rr_fid1) || fid_is_dot_lustre(rr->rr_fid1))
743 * step 1: Found the parent.
745 mp = mdt_object_find(info->mti_env, info->mti_mdt, rr->rr_fid1);
751 parent_lh = &info->mti_lh[MDT_LH_PARENT];
753 if (mdt_object_remote(mp)) {
754 mdt_lock_reg_init(parent_lh, LCK_EX);
755 rc = mdt_remote_object_lock(info, mp, &parent_lh->mlh_rreg_lh,
756 parent_lh->mlh_rreg_mode,
757 MDS_INODELOCK_UPDATE);
759 GOTO(put_parent, rc);
762 mdt_lock_pdo_init(parent_lh, LCK_PW, &rr->rr_name);
763 rc = mdt_object_lock(info, mp, parent_lh, MDS_INODELOCK_UPDATE,
766 GOTO(put_parent, rc);
768 rc = mdt_version_get_check_save(info, mp, 0);
770 GOTO(unlock_parent, rc);
773 /* step 2: find & lock the child */
774 /* lookup child object along with version checking */
776 rc = mdt_lookup_version_check(info, mp, &rr->rr_name, child_fid, 1);
778 /* Name might not be able to find during resend of
779 * remote unlink, considering following case.
780 * dir_A is a remote directory, the name entry of
781 * dir_A is on MDT0, the directory is on MDT1,
783 * 1. client sends unlink req to MDT1.
784 * 2. MDT1 sends name delete update to MDT0.
785 * 3. name entry is being deleted in MDT0 synchronously.
786 * 4. MDT1 is restarted.
787 * 5. client resends unlink req to MDT1. So it can not
788 * find the name entry on MDT0 anymore.
789 * In this case, MDT1 only needs to destory the local
792 if (mdt_object_remote(mp) && rc == -ENOENT &&
793 !fid_is_zero(rr->rr_fid2) &&
794 lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT) {
796 *child_fid = *rr->rr_fid2;
798 GOTO(unlock_parent, rc);
802 if (fid_is_obf(child_fid) || fid_is_dot_lustre(child_fid))
803 GOTO(unlock_parent, rc = -EPERM);
805 mdt_reint_init_ma(info, ma);
807 /* We will lock the child regardless it is local or remote. No harm. */
808 mc = mdt_object_find(info->mti_env, info->mti_mdt, child_fid);
810 GOTO(unlock_parent, rc = PTR_ERR(mc));
812 child_lh = &info->mti_lh[MDT_LH_CHILD];
813 mdt_lock_reg_init(child_lh, LCK_EX);
814 if (mdt_object_remote(mc)) {
815 struct mdt_body *repbody;
817 if (!fid_is_zero(rr->rr_fid2)) {
818 CDEBUG(D_INFO, "%s: name "DNAME" cannot find "DFID"\n",
819 mdt_obd_name(info->mti_mdt),
820 PNAME(&rr->rr_name), PFID(mdt_object_fid(mc)));
821 GOTO(put_child, rc = -ENOENT);
823 CDEBUG(D_INFO, "%s: name "DNAME": "DFID" is on another MDT\n",
824 mdt_obd_name(info->mti_mdt),
825 PNAME(&rr->rr_name), PFID(mdt_object_fid(mc)));
827 if (!mdt_is_dne_client(req->rq_export))
828 /* Return -EIO for old client */
829 GOTO(put_child, rc = -EIO);
831 if (info->mti_spec.sp_rm_entry) {
832 struct lu_ucred *uc = mdt_ucred(info);
834 if (!md_capable(uc, CFS_CAP_SYS_ADMIN)) {
835 CERROR("%s: unlink remote entry is only "
836 "permitted for administrator: rc = %d\n",
837 mdt_obd_name(info->mti_mdt),
839 GOTO(put_child, rc = -EPERM);
842 ma->ma_need = MA_INODE;
844 mdt_set_capainfo(info, 1, child_fid, BYPASS_CAPA);
845 rc = mdo_unlink(info->mti_env, mdt_object_child(mp),
846 NULL, &rr->rr_name, ma, no_name);
849 /* Revoke the LOOKUP lock of the remote object granted by
850 * this MDT. Since the unlink will happen on another MDT,
851 * it will release the LOOKUP lock right away. Then What
852 * would happen if another client try to grab the LOOKUP
853 * lock at the same time with unlink XXX */
854 mdt_object_lock(info, mc, child_lh, MDS_INODELOCK_LOOKUP,
856 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
857 LASSERT(repbody != NULL);
858 repbody->fid1 = *mdt_object_fid(mc);
859 repbody->valid |= (OBD_MD_FLID | OBD_MD_MDS);
860 GOTO(unlock_child, rc = -EREMOTE);
861 } else if (info->mti_spec.sp_rm_entry) {
863 CDEBUG(D_INFO, "%s: no rm_entry on local dir '"DNAME"': "
865 mdt_obd_name(info->mti_mdt), PNAME(&rr->rr_name), rc);
869 /* We used to acquire MDS_INODELOCK_FULL here but we can't do
870 * this now because a running HSM restore on the child (unlink
871 * victim) will hold the layout lock. See LU-4002. */
872 rc = mdt_object_lock(info, mc, child_lh,
873 MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE,
878 mdt_fail_write(info->mti_env, info->mti_mdt->mdt_bottom,
879 OBD_FAIL_MDS_REINT_UNLINK_WRITE);
880 /* save version when object is locked */
881 mdt_version_get_save(info, mc, 1);
883 * Now we can only make sure we need MA_INODE, in mdd layer, will check
884 * whether need MA_LOV and MA_COOKIE.
886 ma->ma_need = MA_INODE;
888 mdt_set_capainfo(info, 1, child_fid, BYPASS_CAPA);
890 mutex_lock(&mc->mot_lov_mutex);
892 rc = mdo_unlink(info->mti_env, mdt_object_child(mp),
893 mdt_object_child(mc), &rr->rr_name, ma, no_name);
895 mutex_unlock(&mc->mot_lov_mutex);
897 if (rc == 0 && !lu_object_is_dying(&mc->mot_header))
898 rc = mdt_attr_get_complex(info, mc, ma);
900 mdt_handle_last_unlink(info, mc, ma);
902 if (ma->ma_valid & MA_INODE) {
903 switch (ma->ma_attr.la_mode & S_IFMT) {
905 mdt_counter_incr(req, LPROC_MDT_RMDIR);
913 mdt_counter_incr(req, LPROC_MDT_UNLINK);
916 LASSERTF(0, "bad file type %o unlinking\n",
917 ma->ma_attr.la_mode);
923 mdt_object_unlock(info, mc, child_lh, rc);
925 mdt_object_put(info->mti_env, mc);
927 mdt_object_unlock(info, mp, parent_lh, rc);
929 mdt_object_put(info->mti_env, mp);
935 * VBR: save versions in reply: 0 - parent; 1 - child by fid; 2 - target by
938 static int mdt_reint_link(struct mdt_thread_info *info,
939 struct mdt_lock_handle *lhc)
941 struct mdt_reint_record *rr = &info->mti_rr;
942 struct ptlrpc_request *req = mdt_info_req(info);
943 struct md_attr *ma = &info->mti_attr;
944 struct mdt_object *ms;
945 struct mdt_object *mp;
946 struct mdt_lock_handle *lhs;
947 struct mdt_lock_handle *lhp;
951 DEBUG_REQ(D_INODE, req, "link "DFID" to "DFID"/"DNAME,
952 PFID(rr->rr_fid1), PFID(rr->rr_fid2), PNAME(&rr->rr_name));
954 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_LINK))
955 RETURN(err_serious(-ENOENT));
957 if (info->mti_dlm_req)
958 ldlm_request_cancel(req, info->mti_dlm_req, 0);
960 /* Invalid case so return error immediately instead of
962 if (lu_fid_eq(rr->rr_fid1, rr->rr_fid2))
965 if (fid_is_obf(rr->rr_fid1) || fid_is_dot_lustre(rr->rr_fid1) ||
966 fid_is_obf(rr->rr_fid2) || fid_is_dot_lustre(rr->rr_fid2))
969 /* step 1: find & lock the target parent dir */
970 lhp = &info->mti_lh[MDT_LH_PARENT];
971 mdt_lock_pdo_init(lhp, LCK_PW, &rr->rr_name);
972 mp = mdt_object_find_lock(info, rr->rr_fid2, lhp,
973 MDS_INODELOCK_UPDATE);
977 rc = mdt_version_get_check_save(info, mp, 0);
979 GOTO(out_unlock_parent, rc);
981 /* step 2: find & lock the source */
982 lhs = &info->mti_lh[MDT_LH_CHILD];
983 mdt_lock_reg_init(lhs, LCK_EX);
985 ms = mdt_object_find(info->mti_env, info->mti_mdt, rr->rr_fid1);
987 GOTO(out_unlock_parent, rc = PTR_ERR(ms));
989 if (!mdt_object_exists(ms)) {
990 mdt_object_put(info->mti_env, ms);
991 CDEBUG(D_INFO, "%s: "DFID" does not exist.\n",
992 mdt_obd_name(info->mti_mdt), PFID(rr->rr_fid1));
993 GOTO(out_unlock_parent, rc = -ENOENT);
996 if (mdt_object_remote(ms)) {
997 mdt_object_put(info->mti_env, ms);
998 CERROR("%s: source inode "DFID" on remote MDT from "DFID"\n",
999 mdt_obd_name(info->mti_mdt), PFID(rr->rr_fid1),
1001 GOTO(out_unlock_parent, rc = -EXDEV);
1004 rc = mdt_object_lock(info, ms, lhs, MDS_INODELOCK_UPDATE |
1005 MDS_INODELOCK_XATTR, MDT_CROSS_LOCK);
1007 mdt_object_put(info->mti_env, ms);
1008 GOTO(out_unlock_parent, rc);
1011 /* step 3: link it */
1012 mdt_fail_write(info->mti_env, info->mti_mdt->mdt_bottom,
1013 OBD_FAIL_MDS_REINT_LINK_WRITE);
1015 tgt_vbr_obj_set(info->mti_env, mdt_obj2dt(ms));
1016 rc = mdt_version_get_check_save(info, ms, 1);
1018 GOTO(out_unlock_child, rc);
1020 /** check target version by name during replay */
1021 rc = mdt_lookup_version_check(info, mp, &rr->rr_name,
1022 &info->mti_tmp_fid1, 2);
1023 if (rc != 0 && rc != -ENOENT)
1024 GOTO(out_unlock_child, rc);
1025 /* save version of file name for replay, it must be ENOENT here */
1026 if (!req_is_replay(mdt_info_req(info))) {
1027 if (rc != -ENOENT) {
1028 CDEBUG(D_INFO, "link target "DNAME" existed!\n",
1029 PNAME(&rr->rr_name));
1030 GOTO(out_unlock_child, rc = -EEXIST);
1032 info->mti_ver[2] = ENOENT_VERSION;
1033 mdt_version_save(mdt_info_req(info), info->mti_ver[2], 2);
1036 rc = mdo_link(info->mti_env, mdt_object_child(mp),
1037 mdt_object_child(ms), &rr->rr_name, ma);
1040 mdt_counter_incr(req, LPROC_MDT_LINK);
1044 mdt_object_unlock_put(info, ms, lhs, rc);
1046 mdt_object_unlock_put(info, mp, lhp, rc);
1050 * lock the part of the directory according to the hash of the name
1051 * (lh->mlh_pdo_hash) in parallel directory lock.
1053 static int mdt_pdir_hash_lock(struct mdt_thread_info *info,
1054 struct mdt_lock_handle *lh,
1055 struct mdt_object *obj, __u64 ibits)
1057 struct ldlm_res_id *res = &info->mti_res_id;
1058 struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
1059 ldlm_policy_data_t *policy = &info->mti_policy;
1063 * Finish res_id initializing by name hash marking part of
1064 * directory which is taking modification.
1066 LASSERT(lh->mlh_pdo_hash != 0);
1067 fid_build_pdo_res_name(mdt_object_fid(obj), lh->mlh_pdo_hash, res);
1068 memset(policy, 0, sizeof(*policy));
1069 policy->l_inodebits.bits = ibits;
1071 * Use LDLM_FL_LOCAL_ONLY for this lock. We do not know yet if it is
1072 * going to be sent to client. If it is - mdt_intent_policy() path will
1073 * fix it up and turn FL_LOCAL flag off.
1075 rc = mdt_fid_lock(ns, &lh->mlh_reg_lh, lh->mlh_reg_mode, policy,
1076 res, LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB,
1077 &info->mti_exp->exp_handle.h_cookie);
1081 static int mdt_rename_lock(struct mdt_thread_info *info,
1082 struct lustre_handle *lh)
1084 struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
1085 ldlm_policy_data_t *policy = &info->mti_policy;
1086 struct ldlm_res_id *res_id = &info->mti_res_id;
1091 fid_build_reg_res_name(&LUSTRE_BFL_FID, res_id);
1093 memset(policy, 0, sizeof *policy);
1094 policy->l_inodebits.bits = MDS_INODELOCK_UPDATE;
1095 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 6, 53, 0)
1096 /* In phase I, we will not do cross-rename, so local BFL lock would
1099 flags = LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB;
1101 * Current node is controller, that is mdt0, where we should
1104 rc = ldlm_cli_enqueue_local(ns, res_id, LDLM_IBITS, policy,
1105 LCK_EX, &flags, ldlm_blocking_ast,
1106 ldlm_completion_ast, NULL, NULL, 0,
1108 &info->mti_exp->exp_handle.h_cookie,
1111 #warning "Local rename lock is invalid for DNE phase II."
1116 static void mdt_rename_unlock(struct lustre_handle *lh)
1119 LASSERT(lustre_handle_is_used(lh));
1120 ldlm_lock_decref(lh, LCK_EX);
1125 * This is is_subdir() variant, it is CMD if cmm forwards it to correct
1126 * target. Source should not be ancestor of target dir. May be other rename
1127 * checks can be moved here later.
1129 static int mdt_rename_sanity(struct mdt_thread_info *info, struct lu_fid *fid)
1131 struct mdt_reint_record *rr = &info->mti_rr;
1132 struct lu_fid dst_fid = *rr->rr_fid2;
1133 struct mdt_object *dst;
1138 LASSERT(fid_is_sane(&dst_fid));
1139 dst = mdt_object_find(info->mti_env, info->mti_mdt, &dst_fid);
1141 rc = mdo_is_subdir(info->mti_env,
1142 mdt_object_child(dst), fid,
1144 mdt_object_put(info->mti_env, dst);
1145 if (rc != -EREMOTE && rc < 0) {
1146 CERROR("Failed mdo_is_subdir(), rc %d\n", rc);
1148 /* check the found fid */
1149 if (lu_fid_eq(&dst_fid, fid))
1155 } while (rc == -EREMOTE);
1161 * VBR: rename versions in reply: 0 - src parent; 1 - tgt parent;
1162 * 2 - src child; 3 - tgt child.
1163 * Update on disk version of src child.
1166 * For DNE phase I, only these renames are allowed
1167 * mv src_p/src_c tgt_p/tgt_c
1168 * 1. src_p/src_c/tgt_p/tgt_c are in the same MDT.
1169 * 2. src_p and tgt_p are same directory, and tgt_c does not
1170 * exists. In this case, all of modification will happen
1171 * in the MDT where ithesource parent is, only one remote
1172 * update is needed, i.e. set c_time/m_time on the child.
1173 * And tgt_c will be still in the same MDT as the original
1176 static int mdt_reint_rename(struct mdt_thread_info *info,
1177 struct mdt_lock_handle *lhc)
1179 struct mdt_reint_record *rr = &info->mti_rr;
1180 struct md_attr *ma = &info->mti_attr;
1181 struct ptlrpc_request *req = mdt_info_req(info);
1182 struct mdt_object *msrcdir;
1183 struct mdt_object *mtgtdir;
1184 struct mdt_object *mold;
1185 struct mdt_object *mnew = NULL;
1186 struct mdt_lock_handle *lh_srcdirp;
1187 struct mdt_lock_handle *lh_tgtdirp;
1188 struct mdt_lock_handle *lh_oldp;
1189 struct mdt_lock_handle *lh_newp;
1190 struct lu_fid *old_fid = &info->mti_tmp_fid1;
1191 struct lu_fid *new_fid = &info->mti_tmp_fid2;
1192 struct lustre_handle rename_lh = { 0 };
1196 if (info->mti_dlm_req)
1197 ldlm_request_cancel(req, info->mti_dlm_req, 0);
1199 DEBUG_REQ(D_INODE, req, "rename "DFID"/"DNAME" to "DFID"/"DNAME,
1200 PFID(rr->rr_fid1), PNAME(&rr->rr_name),
1201 PFID(rr->rr_fid2), PNAME(&rr->rr_tgt_name));
1203 if (fid_is_obf(rr->rr_fid1) || fid_is_dot_lustre(rr->rr_fid1) ||
1204 fid_is_obf(rr->rr_fid2) || fid_is_dot_lustre(rr->rr_fid2))
1207 rc = mdt_rename_lock(info, &rename_lh);
1209 CERROR("Can't lock FS for rename, rc %d\n", rc);
1213 lh_newp = &info->mti_lh[MDT_LH_NEW];
1215 /* step 1: lock the source dir. */
1216 lh_srcdirp = &info->mti_lh[MDT_LH_PARENT];
1217 mdt_lock_pdo_init(lh_srcdirp, LCK_PW, &rr->rr_name);
1218 msrcdir = mdt_object_find_lock(info, rr->rr_fid1, lh_srcdirp,
1219 MDS_INODELOCK_UPDATE);
1220 if (IS_ERR(msrcdir))
1221 GOTO(out_rename_lock, rc = PTR_ERR(msrcdir));
1223 rc = mdt_version_get_check_save(info, msrcdir, 0);
1225 GOTO(out_unlock_source, rc);
1227 /* step 2: find & lock the target dir. */
1228 lh_tgtdirp = &info->mti_lh[MDT_LH_CHILD];
1229 mdt_lock_pdo_init(lh_tgtdirp, LCK_PW, &rr->rr_tgt_name);
1230 if (lu_fid_eq(rr->rr_fid1, rr->rr_fid2)) {
1231 mdt_object_get(info->mti_env, msrcdir);
1233 if (lh_tgtdirp->mlh_pdo_hash != lh_srcdirp->mlh_pdo_hash) {
1234 rc = mdt_pdir_hash_lock(info, lh_tgtdirp, mtgtdir,
1235 MDS_INODELOCK_UPDATE);
1237 GOTO(out_unlock_source, rc);
1238 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_PDO_LOCK2, 10);
1241 mtgtdir = mdt_object_find(info->mti_env, info->mti_mdt,
1243 if (IS_ERR(mtgtdir))
1244 GOTO(out_unlock_source, rc = PTR_ERR(mtgtdir));
1246 /* check early, the real version will be saved after locking */
1247 rc = mdt_version_get_check(info, mtgtdir, 1);
1249 GOTO(out_put_target, rc);
1251 if (unlikely(mdt_object_remote(mtgtdir))) {
1252 CDEBUG(D_INFO, "Source dir "DFID" target dir "DFID
1253 "on different MDTs\n", PFID(rr->rr_fid1),
1255 GOTO(out_put_target, rc = -EXDEV);
1257 if (likely(mdt_object_exists(mtgtdir))) {
1258 /* we lock the target dir if it is local */
1259 rc = mdt_object_lock(info, mtgtdir, lh_tgtdirp,
1260 MDS_INODELOCK_UPDATE,
1263 GOTO(out_put_target, rc);
1264 /* get and save correct version after locking */
1265 mdt_version_get_save(info, mtgtdir, 1);
1267 GOTO(out_put_target, rc = -ESTALE);
1272 /* step 3: find & lock the old object. */
1274 rc = mdt_lookup_version_check(info, msrcdir, &rr->rr_name, old_fid, 2);
1276 GOTO(out_unlock_target, rc);
1278 if (lu_fid_eq(old_fid, rr->rr_fid1) || lu_fid_eq(old_fid, rr->rr_fid2))
1279 GOTO(out_unlock_target, rc = -EINVAL);
1281 if (fid_is_obf(old_fid) || fid_is_dot_lustre(old_fid))
1282 GOTO(out_unlock_target, rc = -EPERM);
1284 mold = mdt_object_find(info->mti_env, info->mti_mdt, old_fid);
1286 GOTO(out_unlock_target, rc = PTR_ERR(mold));
1288 lh_oldp = &info->mti_lh[MDT_LH_OLD];
1289 mdt_lock_reg_init(lh_oldp, LCK_EX);
1290 rc = mdt_object_lock(info, mold, lh_oldp, MDS_INODELOCK_LOOKUP |
1291 MDS_INODELOCK_XATTR, MDT_CROSS_LOCK);
1293 mdt_object_put(info->mti_env, mold);
1294 GOTO(out_unlock_target, rc);
1297 tgt_vbr_obj_set(info->mti_env, mdt_obj2dt(mold));
1298 /* save version after locking */
1299 mdt_version_get_save(info, mold, 2);
1300 mdt_set_capainfo(info, 2, old_fid, BYPASS_CAPA);
1302 /* step 4: find & lock the new object. */
1303 /* new target object may not exist now */
1304 /* lookup with version checking */
1306 rc = mdt_lookup_version_check(info, mtgtdir, &rr->rr_tgt_name, new_fid,
1309 /* the new_fid should have been filled at this moment */
1310 if (lu_fid_eq(old_fid, new_fid))
1311 GOTO(out_unlock_old, rc);
1313 if (lu_fid_eq(new_fid, rr->rr_fid1) ||
1314 lu_fid_eq(new_fid, rr->rr_fid2))
1315 GOTO(out_unlock_old, rc = -EINVAL);
1317 if (fid_is_obf(new_fid) || fid_is_dot_lustre(new_fid))
1318 GOTO(out_unlock_old, rc = -EPERM);
1320 if (mdt_object_remote(mold)) {
1321 CDEBUG(D_INFO, "Src child "DFID" is on another MDT\n",
1323 GOTO(out_unlock_old, rc = -EXDEV);
1326 mdt_lock_reg_init(lh_newp, LCK_EX);
1327 mnew = mdt_object_find(info->mti_env, info->mti_mdt, new_fid);
1329 GOTO(out_unlock_old, rc = PTR_ERR(mnew));
1331 if (mdt_object_remote(mnew)) {
1332 mdt_object_put(info->mti_env, mnew);
1333 CDEBUG(D_INFO, "src child "DFID" is on another MDT\n",
1335 GOTO(out_unlock_old, rc = -EXDEV);
1338 /* We used to acquire MDS_INODELOCK_FULL here but we
1339 * can't do this now because a running HSM restore on
1340 * the rename onto victim will hold the layout
1341 * lock. See LU-4002. */
1342 rc = mdt_object_lock(info, mnew, lh_newp,
1343 MDS_INODELOCK_LOOKUP |
1344 MDS_INODELOCK_UPDATE,
1347 mdt_object_put(info->mti_env, mnew);
1348 GOTO(out_unlock_old, rc);
1350 /* get and save version after locking */
1351 mdt_version_get_save(info, mnew, 3);
1352 mdt_set_capainfo(info, 3, new_fid, BYPASS_CAPA);
1353 } else if (rc != -EREMOTE && rc != -ENOENT) {
1354 GOTO(out_unlock_old, rc);
1356 /* If mnew does not exist and mold are remote directory,
1357 * it only allows rename if they are under same directory */
1358 if (mtgtdir != msrcdir && mdt_object_remote(mold)) {
1359 CDEBUG(D_INFO, "Src child "DFID" is on another MDT\n",
1361 GOTO(out_unlock_old, rc = -EXDEV);
1363 mdt_enoent_version_save(info, 3);
1366 /* step 5: rename it */
1367 mdt_reint_init_ma(info, ma);
1369 mdt_fail_write(info->mti_env, info->mti_mdt->mdt_bottom,
1370 OBD_FAIL_MDS_REINT_RENAME_WRITE);
1372 /* Check if @dst is subdir of @src. */
1373 rc = mdt_rename_sanity(info, old_fid);
1375 GOTO(out_unlock_new, rc);
1378 mutex_lock(&mnew->mot_lov_mutex);
1380 rc = mdo_rename(info->mti_env, mdt_object_child(msrcdir),
1381 mdt_object_child(mtgtdir), old_fid, &rr->rr_name,
1382 mnew != NULL ? mdt_object_child(mnew) : NULL,
1383 &rr->rr_tgt_name, ma);
1386 mutex_unlock(&mnew->mot_lov_mutex);
1388 /* handle last link of tgt object */
1390 mdt_counter_incr(req, LPROC_MDT_RENAME);
1392 mdt_handle_last_unlink(info, mnew, ma);
1394 mdt_rename_counter_tally(info, info->mti_mdt, req,
1401 mdt_object_unlock_put(info, mnew, lh_newp, rc);
1403 mdt_object_unlock_put(info, mold, lh_oldp, rc);
1405 mdt_object_unlock(info, mtgtdir, lh_tgtdirp, rc);
1407 mdt_object_put(info->mti_env, mtgtdir);
1409 mdt_object_unlock_put(info, msrcdir, lh_srcdirp, rc);
1411 if (lustre_handle_is_used(&rename_lh))
1412 mdt_rename_unlock(&rename_lh);
1416 typedef int (*mdt_reinter)(struct mdt_thread_info *info,
1417 struct mdt_lock_handle *lhc);
1419 static mdt_reinter reinters[REINT_MAX] = {
1420 [REINT_SETATTR] = mdt_reint_setattr,
1421 [REINT_CREATE] = mdt_reint_create,
1422 [REINT_LINK] = mdt_reint_link,
1423 [REINT_UNLINK] = mdt_reint_unlink,
1424 [REINT_RENAME] = mdt_reint_rename,
1425 [REINT_OPEN] = mdt_reint_open,
1426 [REINT_SETXATTR] = mdt_reint_setxattr,
1427 [REINT_RMENTRY] = mdt_reint_unlink
1430 int mdt_reint_rec(struct mdt_thread_info *info,
1431 struct mdt_lock_handle *lhc)
1436 rc = reinters[info->mti_rr.rr_opcode](info, lhc);