1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * linux/mdt/mdt_reint.c
5 * Lustre Metadata Target (mdt) reintegration routines
7 * Copyright (C) 2002-2006 Cluster File Systems, Inc.
8 * Author: Peter Braam <braam@clusterfs.com>
9 * Author: Andreas Dilger <adilger@clusterfs.com>
10 * Author: Phil Schwan <phil@clusterfs.com>
11 * Author: Huang Hua <huanghua@clusterfs.com>
13 * This file is part of the Lustre file system, http://www.lustre.org
14 * Lustre is a trademark of Cluster File Systems, Inc.
16 * You may have signed or agreed to another license before downloading
17 * this software. If so, you are bound by the terms and conditions
18 * of that agreement, and the following does not apply to you. See the
19 * LICENSE file included with this distribution for more information.
21 * If you did not agree to a different license, then this copy of Lustre
22 * is open source software; you can redistribute it and/or modify it
23 * under the terms of version 2 of the GNU General Public License as
24 * published by the Free Software Foundation.
26 * In either case, Lustre is distributed in the hope that it will be
27 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
28 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * license text for more details.
33 # define EXPORT_SYMTAB
35 #define DEBUG_SUBSYSTEM S_MDS
37 #include "mdt_internal.h"
39 static int mdt_md_create(struct mdt_thread_info *info)
41 struct mdt_device *mdt = info->mti_mdt;
42 struct mdt_object *parent;
43 struct mdt_object *child;
44 struct mdt_lock_handle *lh;
45 struct mdt_body *repbody;
46 struct md_attr *ma = &info->mti_attr;
47 struct mdt_reint_record *rr = &info->mti_rr;
51 repbody = req_capsule_server_get(&info->mti_pill, &RMF_MDT_BODY);
53 lh = &info->mti_lh[MDT_LH_PARENT];
54 lh->mlh_mode = LCK_EX;
56 parent = mdt_object_find_lock(info, rr->rr_fid1,
57 lh, MDS_INODELOCK_UPDATE,
60 RETURN(PTR_ERR(parent));
62 child = mdt_object_find(info->mti_env, mdt, rr->rr_fid2, BYPASS_CAPA);
64 struct md_object *next = mdt_object_child(parent);
66 ma->ma_need = MA_INODE;
67 mdt_fail_write(info->mti_env, info->mti_mdt->mdt_bottom,
68 OBD_FAIL_MDS_REINT_CREATE_WRITE);
70 rc = mdo_create(info->mti_env, next, rr->rr_name,
71 mdt_object_child(child),
72 &info->mti_spec, ma, &info->mti_uc);
74 /* return fid & attr to client. */
75 if (ma->ma_valid & MA_INODE)
76 mdt_pack_attr2body(repbody, &ma->ma_attr,
77 mdt_object_fid(child));
78 mdt_body_reverse_idmap(info, repbody);
80 mdt_object_put(info->mti_env, child);
83 mdt_object_unlock_put(info, parent, lh, rc);
87 /* partial request to create object only */
88 static int mdt_md_mkobj(struct mdt_thread_info *info)
90 struct mdt_device *mdt = info->mti_mdt;
92 struct mdt_body *repbody;
93 struct md_attr *ma = &info->mti_attr;
97 repbody = req_capsule_server_get(&info->mti_pill, &RMF_MDT_BODY);
99 o = mdt_object_find(info->mti_env, mdt, info->mti_rr.rr_fid2,
102 struct md_object *next = mdt_object_child(o);
104 ma->ma_need = MA_INODE;
105 rc = mo_object_create(info->mti_env, next, &info->mti_spec,
108 /* return fid & attr to client. */
109 if (ma->ma_valid & MA_INODE)
110 mdt_pack_attr2body(repbody, &ma->ma_attr,
112 mdt_body_reverse_idmap(info, repbody);
114 mdt_object_put(info->mti_env, o);
121 /* In the raw-setattr case, we lock the child inode.
122 * In the write-back case or if being called from open,
123 * the client holds a lock already.
124 * We use the ATTR_FROM_OPEN (translated into MRF_SETATTR_LOCKED by
125 * mdt_setattr_unpack()) flag to tell these cases apart. */
126 int mdt_attr_set(struct mdt_thread_info *info, struct mdt_object *mo, int flags)
128 struct md_attr *ma = &info->mti_attr;
129 struct mdt_lock_handle *lh;
135 som_update = (info->mti_epoch->flags & MF_SOM_CHANGE);
137 /* Try to avoid object_lock if another epoch has been started
139 if (som_update && (info->mti_epoch->ioepoch != mo->mot_ioepoch))
142 lh = &info->mti_lh[MDT_LH_PARENT];
143 lh->mlh_mode = LCK_EX;
145 if (!(flags & MRF_SETATTR_LOCKED)) {
146 __u64 lockpart = MDS_INODELOCK_UPDATE;
147 if (ma->ma_attr.la_valid & (LA_MODE|LA_UID|LA_GID))
148 lockpart |= MDS_INODELOCK_LOOKUP;
150 rc = mdt_object_lock(info, mo, lh, lockpart);
155 /* Setattrs are syncronized through dlm lock taken above. If another
156 * epoch started, its attributes may be already flushed on disk,
158 if (som_update && (info->mti_epoch->ioepoch != mo->mot_ioepoch))
161 if (lu_object_assert_not_exists(&mo->mot_obj.mo_lu))
162 GOTO(out, rc = -ENOENT);
164 /* all attrs are packed into mti_attr in unpack_setattr */
165 mdt_fail_write(info->mti_env, info->mti_mdt->mdt_bottom,
166 OBD_FAIL_MDS_REINT_SETATTR_WRITE);
168 /* all attrs are packed into mti_attr in unpack_setattr */
169 rc = mo_attr_set(info->mti_env, mdt_object_child(mo), ma,
174 /* Re-enable SIZEONMDS. */
176 CDEBUG(D_INODE, "Closing epoch "LPU64" on "DFID". Count %d\n",
177 mo->mot_ioepoch, PFID(mdt_object_fid(mo)),
180 mdt_sizeonmds_enable(info, mo);
185 mdt_object_unlock(info, mo, lh, rc);
189 static int mdt_reint_setattr(struct mdt_thread_info *info,
190 struct mdt_lock_handle *lhc)
192 struct mdt_device *mdt = info->mti_mdt;
193 struct md_attr *ma = &info->mti_attr;
194 struct mdt_reint_record *rr = &info->mti_rr;
195 struct ptlrpc_request *req = mdt_info_req(info);
196 struct mdt_export_data *med = &req->rq_export->exp_mdt_data;
197 struct mdt_file_data *mfd;
198 struct mdt_object *mo;
199 struct md_object *next;
200 struct mdt_body *repbody;
205 DEBUG_REQ(D_INODE, req, "setattr "DFID" %x", PFID(rr->rr_fid1),
206 (unsigned int)ma->ma_attr.la_valid);
208 repbody = req_capsule_server_get(&info->mti_pill, &RMF_MDT_BODY);
209 mo = mdt_object_find(info->mti_env, info->mti_mdt, rr->rr_fid1,
212 RETURN(rc = PTR_ERR(mo));
214 if (info->mti_epoch && (info->mti_epoch->flags & MF_EPOCH_OPEN)) {
216 rc = mdt_write_get(info->mti_mdt, mo);
222 GOTO(out, rc = -ENOMEM);
224 /* FIXME: in recovery, need to pass old epoch here */
225 mdt_epoch_open(info, mo, 0);
226 repbody->ioepoch = mo->mot_ioepoch;
228 mdt_object_get(info->mti_env, mo);
229 mfd->mfd_mode = FMODE_EPOCHLCK;
230 mfd->mfd_object = mo;
231 mfd->mfd_xid = req->rq_xid;
233 spin_lock(&med->med_open_lock);
234 list_add(&mfd->mfd_list, &med->med_open_head);
235 spin_unlock(&med->med_open_lock);
236 repbody->handle.cookie = mfd->mfd_handle.h_cookie;
239 rc = mdt_attr_set(info, mo, rr->rr_flags);
243 if (info->mti_epoch && (info->mti_epoch->flags & MF_SOM_CHANGE)) {
244 LASSERT(info->mti_epoch);
246 /* Size-on-MDS Update. Find and free mfd. */
247 spin_lock(&med->med_open_lock);
248 mfd = mdt_handle2mfd(&(info->mti_epoch->handle));
250 spin_unlock(&med->med_open_lock);
251 CDEBUG(D_INODE, "no handle for file close: "
252 "fid = "DFID": cookie = "LPX64"\n",
253 PFID(info->mti_rr.rr_fid1),
254 info->mti_epoch->handle.cookie);
255 GOTO(out, rc = -ESTALE);
258 LASSERT(mfd->mfd_mode == FMODE_SOM);
259 LASSERT(ma->ma_attr.la_valid & LA_SIZE);
260 LASSERT(!(info->mti_epoch->flags & MF_EPOCH_CLOSE));
262 class_handle_unhash(&mfd->mfd_handle);
263 list_del_init(&mfd->mfd_list);
264 spin_unlock(&med->med_open_lock);
265 mdt_mfd_close(info, mfd);
268 ma->ma_need = MA_INODE;
269 next = mdt_object_child(mo);
270 rc = mo_attr_get(info->mti_env, next, ma, NULL);
274 mdt_pack_attr2body(repbody, &ma->ma_attr, mdt_object_fid(mo));
276 if (mdt->mdt_opts.mo_oss_capa) {
277 struct lustre_capa *capa;
279 capa = req_capsule_server_get(&info->mti_pill, &RMF_CAPA1);
281 capa->lc_opc = CAPA_OPC_OSS_DEFAULT | CAPA_OPC_OSS_TRUNC;
282 rc = mo_capa_get(info->mti_env, mdt_object_child(mo), capa);
285 repbody->valid |= OBD_MD_FLOSSCAPA;
288 mdt_body_reverse_idmap(info, repbody);
291 mdt_object_put(info->mti_env, mo);
295 static int mdt_reint_create(struct mdt_thread_info *info,
296 struct mdt_lock_handle *lhc)
301 if (MDT_FAIL_CHECK(OBD_FAIL_MDS_REINT_CREATE))
304 switch (info->mti_attr.ma_attr.la_mode & S_IFMT) {
307 if (strlen(info->mti_rr.rr_name) == 0) {
308 rc = mdt_md_mkobj(info);
317 /* special file should stay on the same node as parent */
318 LASSERT(strlen(info->mti_rr.rr_name) > 0);
319 rc = mdt_md_create(info);
329 static int mdt_reint_unlink(struct mdt_thread_info *info,
330 struct mdt_lock_handle *lhc)
332 struct mdt_reint_record *rr = &info->mti_rr;
333 struct ptlrpc_request *req = mdt_info_req(info);
334 struct md_attr *ma = &info->mti_attr;
335 struct lu_fid *child_fid = &info->mti_tmp_fid1;
336 struct mdt_object *mp;
337 struct mdt_object *mc;
338 struct mdt_lock_handle *parent_lh;
339 struct mdt_lock_handle *child_lh;
343 DEBUG_REQ(D_INODE, req, "unlink "DFID"/%s\n", PFID(rr->rr_fid1),
346 if (MDT_FAIL_CHECK(OBD_FAIL_MDS_REINT_UNLINK))
347 GOTO(out, rc = -ENOENT);
349 /* step 1: lock the parent */
350 parent_lh = &info->mti_lh[MDT_LH_PARENT];
351 parent_lh->mlh_mode = LCK_EX;
352 mp = mdt_object_find_lock(info, rr->rr_fid1, parent_lh,
353 MDS_INODELOCK_UPDATE, rr->rr_capa1);
355 GOTO(out, rc = PTR_ERR(mp));
357 ma->ma_lmm = req_capsule_server_get(&info->mti_pill, &RMF_MDT_MD);
358 ma->ma_lmm_size = req_capsule_get_size(&info->mti_pill,
359 &RMF_MDT_MD, RCL_SERVER);
361 ma->ma_cookie = req_capsule_server_get(&info->mti_pill,
363 ma->ma_cookie_size = req_capsule_get_size(&info->mti_pill,
366 ma->ma_need = MA_INODE | MA_LOV | MA_COOKIE;
368 if (!ma->ma_lmm || !ma->ma_cookie)
369 GOTO(out_unlock_parent, rc = -EINVAL);
371 if (strlen(rr->rr_name) == 0) {
372 /* remote partial operation */
373 rc = mo_ref_del(info->mti_env, mdt_object_child(mp), ma,
375 GOTO(out_unlock_parent, rc);
378 /* step 2: find & lock the child */
379 rc = mdo_lookup(info->mti_env, mdt_object_child(mp),
380 rr->rr_name, child_fid, &info->mti_uc);
382 GOTO(out_unlock_parent, rc);
384 /* we will lock the child regardless it is local or remote. No harm. */
385 mc = mdt_object_find(info->mti_env, info->mti_mdt, child_fid,
388 GOTO(out_unlock_parent, rc = PTR_ERR(mc));
389 child_lh = &info->mti_lh[MDT_LH_CHILD];
390 child_lh->mlh_mode = LCK_EX;
391 rc = mdt_object_cr_lock(info, mc, child_lh, MDS_INODELOCK_FULL);
393 GOTO(out_put_child, rc);
395 mdt_fail_write(info->mti_env, info->mti_mdt->mdt_bottom,
396 OBD_FAIL_MDS_REINT_UNLINK_WRITE);
399 * Now we can only make sure we need MA_INODE, in mdd layer, will check
400 * whether need MA_LOV and MA_COOKIE.
402 ma->ma_need = MA_INODE;
403 rc = mdo_unlink(info->mti_env, mdt_object_child(mp),
404 mdt_object_child(mc), rr->rr_name, ma, &info->mti_uc);
406 GOTO(out_unlock_child, rc);
408 mdt_handle_last_unlink(info, mc, ma);
410 GOTO(out_unlock_child, rc);
412 mdt_object_unlock(info, mc, child_lh, rc);
414 mdt_object_put(info->mti_env, mc);
416 mdt_object_unlock_put(info, mp, parent_lh, rc);
418 mdt_shrink_reply(info, REPLY_REC_OFF + 1, 0, 0);
422 static int mdt_reint_link(struct mdt_thread_info *info,
423 struct mdt_lock_handle *lhc)
425 struct mdt_reint_record *rr = &info->mti_rr;
426 struct ptlrpc_request *req = mdt_info_req(info);
427 struct md_attr *ma = &info->mti_attr;
428 struct mdt_object *ms;
429 struct mdt_object *mp;
430 struct mdt_lock_handle *lhs;
431 struct mdt_lock_handle *lhp;
436 DEBUG_REQ(D_INODE, req, "link original "DFID" to "DFID" %s",
437 PFID(rr->rr_fid1), PFID(rr->rr_fid2), rr->rr_name);
439 if (MDT_FAIL_CHECK(OBD_FAIL_MDS_REINT_LINK))
442 /* step 1: lock the source */
443 lhs = &info->mti_lh[MDT_LH_PARENT];
444 lhs->mlh_mode = LCK_EX;
445 ms = mdt_object_find_lock(info, rr->rr_fid1, lhs,
446 MDS_INODELOCK_UPDATE, rr->rr_capa1);
450 if (strlen(rr->rr_name) == 0) {
451 /* remote partial operation */
452 rc = mo_ref_add(info->mti_env, mdt_object_child(ms),
454 GOTO(out_unlock_source, rc);
456 /*step 2: find & lock the target parent dir*/
457 lhp = &info->mti_lh[MDT_LH_CHILD];
458 lhp->mlh_mode = LCK_EX;
459 mp = mdt_object_find_lock(info, rr->rr_fid2, lhp,
460 MDS_INODELOCK_UPDATE, rr->rr_capa2);
462 GOTO(out_unlock_source, rc = PTR_ERR(mp));
464 /* step 4: link it */
466 mdt_fail_write(info->mti_env, info->mti_mdt->mdt_bottom,
467 OBD_FAIL_MDS_REINT_LINK_WRITE);
469 rc = mdo_link(info->mti_env, mdt_object_child(mp),
470 mdt_object_child(ms), rr->rr_name, ma, &info->mti_uc);
471 GOTO(out_unlock_target, rc);
474 mdt_object_unlock_put(info, mp, lhp, rc);
476 mdt_object_unlock_put(info, ms, lhs, rc);
480 /* partial operation for rename */
481 static int mdt_reint_rename_tgt(struct mdt_thread_info *info)
483 struct mdt_reint_record *rr = &info->mti_rr;
484 struct ptlrpc_request *req = mdt_info_req(info);
485 struct md_attr *ma = &info->mti_attr;
486 struct mdt_object *mtgtdir;
487 struct mdt_object *mtgt = NULL;
488 struct mdt_lock_handle *lh_tgtdir;
489 struct mdt_lock_handle *lh_tgt;
490 struct lu_fid *tgt_fid = &info->mti_tmp_fid1;
495 DEBUG_REQ(D_INODE, req, "rename_tgt "DFID" to "DFID" %s",
497 PFID(rr->rr_fid1), rr->rr_tgt);
499 /* step 1: lookup & lock the tgt dir */
500 lh_tgt = &info->mti_lh[MDT_LH_CHILD];
501 lh_tgtdir = &info->mti_lh[MDT_LH_PARENT];
502 lh_tgtdir->mlh_mode = LCK_EX;
503 mtgtdir = mdt_object_find_lock(info, rr->rr_fid1, lh_tgtdir,
504 MDS_INODELOCK_UPDATE, rr->rr_capa1);
506 GOTO(out, rc = PTR_ERR(mtgtdir));
508 /*step 2: find & lock the target object if exists*/
509 rc = mdo_lookup(info->mti_env, mdt_object_child(mtgtdir),
510 rr->rr_tgt, tgt_fid, &info->mti_uc);
511 if (rc != 0 && rc != -ENOENT) {
512 GOTO(out_unlock_tgtdir, rc);
513 } else if (rc == 0) {
514 lh_tgt->mlh_mode = LCK_EX;
516 mtgt = mdt_object_find_lock(info, tgt_fid, lh_tgt,
517 MDS_INODELOCK_LOOKUP, BYPASS_CAPA);
519 GOTO(out_unlock_tgtdir, rc = PTR_ERR(mtgt));
521 rc = mdo_rename_tgt(info->mti_env, mdt_object_child(mtgtdir),
522 mdt_object_child(mtgt), rr->rr_fid2,
523 rr->rr_tgt, ma, &info->mti_uc);
524 } else /* -ENOENT */ {
525 rc = mdo_name_insert(info->mti_env, mdt_object_child(mtgtdir),
526 rr->rr_tgt, rr->rr_fid2,
527 S_ISDIR(ma->ma_attr.la_mode),
531 /* handle last link of tgt object */
533 mdt_handle_last_unlink(info, mtgt, ma);
537 mdt_object_unlock_put(info, mtgt, lh_tgt, rc);
540 mdt_object_unlock_put(info, mtgtdir, lh_tgtdir, rc);
542 mdt_shrink_reply(info, REPLY_REC_OFF + 1, 0, 0);
546 static int mdt_rename_lock(struct mdt_thread_info *info,
547 struct lustre_handle *lh)
549 ldlm_policy_data_t policy = { .l_inodebits = { MDS_INODELOCK_UPDATE } };
550 struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
551 int flags = LDLM_FL_ATOMIC_CB;
552 struct ldlm_res_id res_id;
557 ls = info->mti_mdt->mdt_md_dev.md_lu_dev.ld_site;
558 fid_build_res_name(&LUSTRE_BFL_FID, &res_id);
560 if (ls->ls_control_exp == NULL) {
562 * Current node is controller, that is mdt0 where we should take
565 rc = ldlm_cli_enqueue_local(ns, res_id, LDLM_IBITS, &policy,
566 LCK_EX, &flags, ldlm_blocking_ast,
567 ldlm_completion_ast, NULL, NULL, 0,
571 * This is the case mdt0 is remote node, issue DLM lock like
574 rc = ldlm_cli_enqueue(ls->ls_control_exp, NULL, res_id,
575 LDLM_IBITS, &policy, LCK_EX, &flags,
576 ldlm_blocking_ast, ldlm_completion_ast,
577 NULL, NULL, NULL, 0, NULL, lh, 0);
583 static void mdt_rename_unlock(struct lustre_handle *lh)
586 ldlm_lock_decref(lh, LCK_EX);
591 * This is is_subdir() variant, it is CMD is cmm forwards it to correct
592 * target. Source should not be ancestor of target dir. May be other rename
593 * checks can be moved here later.
595 static int mdt_rename_check(struct mdt_thread_info *info, struct lu_fid *fid)
597 struct mdt_reint_record *rr = &info->mti_rr;
598 struct lu_fid dst_fid = *rr->rr_fid2;
599 struct mdt_object *dst;
604 dst = mdt_object_find(info->mti_env, info->mti_mdt, &dst_fid,
607 rc = mdo_is_subdir(info->mti_env,
608 mdt_object_child(dst),
609 fid, &dst_fid, NULL);
610 mdt_object_put(info->mti_env, dst);
612 CERROR("Error while doing mdo_is_subdir(), rc %d\n",
614 } else if (rc == 1) {
620 } while (rc == EREMOTE);
625 static int mdt_reint_rename(struct mdt_thread_info *info,
626 struct mdt_lock_handle *lhc)
628 struct mdt_reint_record *rr = &info->mti_rr;
629 struct req_capsule *pill = &info->mti_pill;
630 struct ptlrpc_request *req = mdt_info_req(info);
631 struct md_attr *ma = &info->mti_attr;
632 struct mdt_object *msrcdir;
633 struct mdt_object *mtgtdir;
634 struct mdt_object *mold;
635 struct mdt_object *mnew = NULL;
636 struct mdt_lock_handle *lh_srcdirp;
637 struct mdt_lock_handle *lh_tgtdirp;
638 struct mdt_lock_handle *lh_oldp;
639 struct mdt_lock_handle *lh_newp;
640 struct lu_fid *old_fid = &info->mti_tmp_fid1;
641 struct lu_fid *new_fid = &info->mti_tmp_fid2;
642 struct lustre_handle rename_lh = { 0 };
648 DEBUG_REQ(D_INODE, req, "rename "DFID"/%s to "DFID"/%s",
649 PFID(rr->rr_fid1), rr->rr_name,
650 PFID(rr->rr_fid2), rr->rr_tgt);
653 rc = req_capsule_get_size(pill, &RMF_NAME, RCL_CLIENT);
655 /* if (rr->rr_name[0] == 0) {*/
656 rc = mdt_reint_rename_tgt(info);
660 rc = mdt_rename_lock(info, &rename_lh);
662 CERROR("can't lock FS for rename, rc %d\n", rc);
666 lh_newp = &info->mti_lh[MDT_LH_NEW];
668 /* step 1: lock the source dir */
669 lh_srcdirp = &info->mti_lh[MDT_LH_PARENT];
670 lh_srcdirp->mlh_mode = LCK_EX;
671 msrcdir = mdt_object_find_lock(info, rr->rr_fid1, lh_srcdirp,
672 MDS_INODELOCK_UPDATE, rr->rr_capa1);
674 GOTO(out, rc = PTR_ERR(msrcdir));
676 /*step 2: find & lock the target dir*/
677 lh_tgtdirp = &info->mti_lh[MDT_LH_CHILD];
678 lh_tgtdirp->mlh_mode = LCK_EX;
679 if (lu_fid_eq(rr->rr_fid1, rr->rr_fid2)) {
680 mdt_object_get(info->mti_env, msrcdir);
683 mtgtdir = mdt_object_find(info->mti_env, info->mti_mdt,
684 rr->rr_fid2, rr->rr_capa2);
686 GOTO(out_unlock_source, rc = PTR_ERR(mtgtdir));
688 rc = mdt_object_cr_lock(info, mtgtdir, lh_tgtdirp,
689 MDS_INODELOCK_UPDATE);
691 mdt_object_put(info->mti_env, mtgtdir);
692 GOTO(out_unlock_source, rc);
697 /*step 3: find & lock the old object*/
698 rc = mdo_lookup(info->mti_env, mdt_object_child(msrcdir),
699 rr->rr_name, old_fid, &info->mti_uc);
701 GOTO(out_unlock_target, rc);
703 if (lu_fid_eq(old_fid, rr->rr_fid1) || lu_fid_eq(old_fid, rr->rr_fid2))
704 GOTO(out_unlock_target, rc = -EINVAL);
706 lh_oldp = &info->mti_lh[MDT_LH_OLD];
707 lh_oldp->mlh_mode = LCK_EX;
708 mold = mdt_object_find_lock(info, old_fid, lh_oldp,
709 MDS_INODELOCK_LOOKUP, BYPASS_CAPA);
711 GOTO(out_unlock_target, rc = PTR_ERR(mold));
713 /*step 4: find & lock the new object*/
714 /* new target object may not exist now */
715 rc = mdo_lookup(info->mti_env, mdt_object_child(mtgtdir),
716 rr->rr_tgt, new_fid, &info->mti_uc);
718 /* the new_fid should have been filled at this moment*/
719 if (lu_fid_eq(old_fid, new_fid))
720 GOTO(out_unlock_old, rc);
722 if (lu_fid_eq(new_fid, rr->rr_fid1) ||
723 lu_fid_eq(new_fid, rr->rr_fid2))
724 GOTO(out_unlock_old, rc = -EINVAL);
726 lh_newp->mlh_mode = LCK_EX;
727 mnew = mdt_object_find(info->mti_env, info->mti_mdt, new_fid,
730 GOTO(out_unlock_old, rc = PTR_ERR(mnew));
732 rc = mdt_object_cr_lock(info, mnew, lh_newp,
735 mdt_object_put(info->mti_env, mnew);
736 GOTO(out_unlock_old, rc);
738 } else if (rc != -EREMOTE && rc != -ENOENT)
739 GOTO(out_unlock_old, rc);
741 /* step 5: dome some checking ...*/
742 /* step 6: rename it */
743 ma->ma_lmm = req_capsule_server_get(&info->mti_pill, &RMF_MDT_MD);
744 ma->ma_lmm_size = req_capsule_get_size(&info->mti_pill,
745 &RMF_MDT_MD, RCL_SERVER);
747 ma->ma_cookie = req_capsule_server_get(&info->mti_pill,
749 ma->ma_cookie_size = req_capsule_get_size(&info->mti_pill,
750 &RMF_LOGCOOKIES, RCL_SERVER);
752 if (!ma->ma_lmm || !ma->ma_cookie)
753 GOTO(out_unlock_new, rc = -EINVAL);
755 ma->ma_need = MA_INODE | MA_LOV | MA_COOKIE;
757 mdt_fail_write(info->mti_env, info->mti_mdt->mdt_bottom,
758 OBD_FAIL_MDS_REINT_RENAME_WRITE);
760 /* Check if @dst is subdir of @src. */
761 rc = mdt_rename_check(info, old_fid);
763 GOTO(out_unlock_new, rc);
765 rc = mdo_rename(info->mti_env, mdt_object_child(msrcdir),
766 mdt_object_child(mtgtdir), old_fid, rr->rr_name,
767 (mnew ? mdt_object_child(mnew) : NULL),
768 rr->rr_tgt, ma, &info->mti_uc);
770 /* handle last link of tgt object */
772 mdt_handle_last_unlink(info, mnew, ma);
776 mdt_object_unlock_put(info, mnew, lh_newp, rc);
779 mdt_object_unlock_put(info, mold, lh_oldp, rc);
781 mdt_object_unlock_put(info, mtgtdir, lh_tgtdirp, rc);
783 mdt_object_unlock_put(info, msrcdir, lh_srcdirp, rc);
785 mdt_rename_unlock(&rename_lh);
786 mdt_shrink_reply(info, REPLY_REC_OFF + 1, 0, 0);
790 typedef int (*mdt_reinter)(struct mdt_thread_info *info,
791 struct mdt_lock_handle *lhc);
793 static mdt_reinter reinters[REINT_MAX] = {
794 [REINT_SETATTR] = mdt_reint_setattr,
795 [REINT_CREATE] = mdt_reint_create,
796 [REINT_LINK] = mdt_reint_link,
797 [REINT_UNLINK] = mdt_reint_unlink,
798 [REINT_RENAME] = mdt_reint_rename,
799 [REINT_OPEN] = mdt_reint_open
802 int mdt_reint_rec(struct mdt_thread_info *info,
803 struct mdt_lock_handle *lhc)
808 rc = reinters[info->mti_rr.rr_opcode](info, lhc);