1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * linux/mds/mds_reint.c
5 * Lustre Metadata Server (mds) reintegration routines
7 * Copyright (C) 2002 Cluster File Systems, Inc.
9 * This file is part of Lustre, http://www.lustre.org.
11 * Lustre is free software; you can redistribute it and/or
12 * modify it under the terms of version 2 of the GNU General Public
13 * License as published by the Free Software Foundation.
15 * Lustre is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with Lustre; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 * Author: Peter Braam <braam@clusterfs.com>
25 * Author: Andreas Dilger <adilger@clusterfs.com>
29 #define DEBUG_SUBSYSTEM S_MDS
31 #include <linux/obd_support.h>
32 #include <linux/obd_class.h>
33 #include <linux/obd.h>
34 #include <linux/lustre_lib.h>
35 #include <linux/lustre_idl.h>
36 #include <linux/lustre_mds.h>
37 #include <linux/lustre_dlm.h>
38 #include <linux/obd_class.h>
40 extern inline struct mds_obd *mds_req2mds(struct ptlrpc_request *req);
42 void mds_start_transno(struct mds_obd *mds)
45 down(&mds->mds_transno_sem);
48 /* Assumes caller has already pushed us into the kernel context. */
49 int mds_finish_transno(struct mds_obd *mds, void *handle,
50 struct ptlrpc_request *req, int rc)
52 struct mds_export_data *med = &req->rq_export->exp_mds_data;
53 struct mds_client_data *mcd = med->med_mcd;
58 /* Propagate error code. */
62 /* we don't allocate new transnos for replayed requests */
63 if (req->rq_level == LUSTRE_CONN_RECOVD) {
68 off = MDS_LR_CLIENT + med->med_off * MDS_LR_SIZE;
70 last_rcvd = ++mds->mds_last_rcvd;
71 req->rq_repmsg->transno = HTON__u64(last_rcvd);
72 mcd->mcd_last_rcvd = cpu_to_le64(last_rcvd);
73 mcd->mcd_mount_count = cpu_to_le64(mds->mds_mount_count);
74 mcd->mcd_last_xid = cpu_to_le64(req->rq_xid);
76 mds_fs_set_last_rcvd(mds, handle);
77 written = lustre_fwrite(mds->mds_rcvd_filp, (char *)mcd, sizeof(*mcd),
79 CDEBUG(D_INODE, "wrote trans #"LPD64" for client %s at #%d: written = "
80 "%d\n", last_rcvd, mcd->mcd_uuid, med->med_off, written);
82 if (written == sizeof(*mcd))
84 CERROR("error writing to last_rcvd file: rc = %d\n", rc);
92 up(&mds->mds_transno_sem);
96 /* In the write-back case, the client holds a lock on a subtree.
97 * In the intent case, the client holds a lock on the child inode.
98 * In the pathname case, the client (may) hold a lock on the child inode. */
99 static int mds_reint_setattr(struct mds_update_record *rec, int offset,
100 struct ptlrpc_request *req)
102 struct mds_obd *mds = mds_req2mds(req);
103 struct obd_device *obd = req->rq_export->exp_obd;
104 struct mds_body *body;
108 struct lustre_handle child_lockh;
111 if (req->rq_reqmsg->bufcount > offset + 1) {
113 struct lustre_handle dir_lockh;
117 /* a name was supplied by the client; fid1 is the directory */
118 dir = mds_fid2locked_dentry(obd, rec->ur_fid1, NULL, LCK_PR,
122 GOTO(out_setattr, rc = PTR_ERR(dir));
125 name = lustre_msg_buf(req->rq_reqmsg, offset + 1);
126 namelen = req->rq_reqmsg->buflens[offset + 1] - 1;
127 de = mds_name2locked_dentry(obd, dir, NULL, name, namelen,
128 0, &child_lockh, LCK_PR);
132 GOTO(out_setattr_de, rc = PTR_ERR(de));
135 de = mds_fid2dentry(mds, rec->ur_fid1, NULL);
136 if (!de || IS_ERR(de)) {
137 GOTO(out_setattr_de, rc = PTR_ERR(de));
141 CDEBUG(D_INODE, "ino %ld\n", inode->i_ino);
143 OBD_FAIL_WRITE(OBD_FAIL_MDS_REINT_SETATTR_WRITE,
144 to_kdev_t(inode->i_sb->s_dev));
146 mds_start_transno(mds);
147 handle = mds_fs_start(mds, inode, MDS_FSOP_SETATTR);
148 if (IS_ERR(handle)) {
149 rc = PTR_ERR(handle);
150 (void)mds_finish_transno(mds, handle, req, rc);
151 GOTO(out_setattr_de, rc);
154 rc = mds_fs_setattr(mds, de, handle, &rec->ur_iattr);
157 body = lustre_msg_buf(req->rq_repmsg, 1);
158 mds_pack_inode2fid(&body->fid1, inode);
159 mds_pack_inode2body(body, inode);
162 rc = mds_finish_transno(mds, handle, req, rc);
164 err = mds_fs_commit(mds, de->d_inode, handle);
166 CERROR("error on commit: err = %d\n", err);
179 static int mds_reint_create(struct mds_update_record *rec, int offset,
180 struct ptlrpc_request *req)
182 struct dentry *de = NULL;
183 struct mds_obd *mds = mds_req2mds(req);
184 struct obd_device *obd = req->rq_export->exp_obd;
185 struct dentry *dchild = NULL;
188 struct lustre_handle lockh;
189 int rc = 0, err, lock_mode, type = rec->ur_mode & S_IFMT;
192 /* requests were at offset 2, replies go back at 1 */
196 LASSERT(!strcmp(req->rq_export->exp_obd->obd_type->typ_name, "mds"));
198 lock_mode = (req->rq_reqmsg->opc == MDS_REINT) ? LCK_CW : LCK_PW;
200 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_CREATE))
201 GOTO(out_create, rc = -ESTALE);
203 de = mds_fid2locked_dentry(obd, rec->ur_fid1, NULL, lock_mode, &lockh);
206 CERROR("parent lookup error %d\n", rc);
208 GOTO(out_create, rc);
211 CDEBUG(D_INODE, "parent ino %ld name %s mode %o\n",
212 dir->i_ino, rec->ur_name, rec->ur_mode);
214 ldlm_lock_dump((void *)(unsigned long)lockh.addr);
217 dchild = lookup_one_len(rec->ur_name, de, rec->ur_namelen - 1);
218 if (IS_ERR(dchild)) {
219 CERROR("child lookup error %ld\n", PTR_ERR(dchild));
221 GOTO(out_create_de, rc = -ESTALE);
224 if (dchild->d_inode) {
225 struct mds_body *body;
226 struct inode *inode = dchild->d_inode;
228 CDEBUG(D_INODE, "child exists (dir %ld, name %s, ino %ld)\n",
229 dir->i_ino, rec->ur_name, dchild->d_inode->i_ino);
231 /* XXX check that mode is correct? */
233 body = lustre_msg_buf(req->rq_repmsg, offset);
234 mds_pack_inode2fid(&body->fid1, inode);
235 mds_pack_inode2body(body, inode);
236 if (S_ISREG(inode->i_mode))
237 rc = mds_pack_md(mds, req, offset + 1, body, inode);
239 /* This isn't an error for RECREATE. */
240 if (rec->ur_opcode & REINT_REPLAYING) {
241 CDEBUG(D_INODE, "EEXIST suppressed for REPLAYING\n");
246 GOTO(out_create_dchild, rc);
249 OBD_FAIL_WRITE(OBD_FAIL_MDS_REINT_CREATE_WRITE,
250 to_kdev_t(dir->i_sb->s_dev));
252 if (dir->i_mode & S_ISGID) {
253 rec->ur_gid = dir->i_gid;
254 if (S_ISDIR(rec->ur_mode))
255 rec->ur_mode |= S_ISGID;
258 /* From here on, we must exit via a path that calls mds_finish_transno,
259 * so that we release the mds_transno_sem (and, in the case of success,
260 * update the transno correctly). out_create_commit and
261 * out_transno_dchild are good candidates.
263 mds_start_transno(mds);
267 handle = mds_fs_start(mds, dir, MDS_FSOP_CREATE);
269 GOTO(out_transno_dchild, rc = PTR_ERR(handle));
270 rc = vfs_create(dir, dchild, rec->ur_mode);
275 handle = mds_fs_start(mds, dir, MDS_FSOP_MKDIR);
277 GOTO(out_transno_dchild, rc = PTR_ERR(handle));
278 rc = vfs_mkdir(dir, dchild, rec->ur_mode);
283 handle = mds_fs_start(mds, dir, MDS_FSOP_SYMLINK);
285 GOTO(out_transno_dchild, rc = PTR_ERR(handle));
286 rc = vfs_symlink(dir, dchild, rec->ur_name);
294 int rdev = rec->ur_rdev;
295 handle = mds_fs_start(mds, dir, MDS_FSOP_MKNOD);
297 GOTO(out_transno_dchild, rc = PTR_ERR(handle));
298 rc = vfs_mknod(dir, dchild, rec->ur_mode, rdev);
303 CERROR("bad file type %o creating %s\n", type, rec->ur_name);
304 handle = NULL; /* quell uninitialized warning */
305 GOTO(out_transno_dchild, rc = -EINVAL);
309 CDEBUG(D_INODE, "error during create: %d\n", rc);
310 GOTO(out_create_commit, rc);
313 struct inode *inode = dchild->d_inode;
314 struct mds_body *body;
316 iattr.ia_atime = rec->ur_time;
317 iattr.ia_ctime = rec->ur_time;
318 iattr.ia_mtime = rec->ur_time;
319 iattr.ia_uid = rec->ur_uid;
320 iattr.ia_gid = rec->ur_gid;
321 iattr.ia_valid = ATTR_UID | ATTR_GID | ATTR_ATIME |
322 ATTR_MTIME | ATTR_CTIME;
324 if (rec->ur_fid2->id) {
325 LASSERT(rec->ur_opcode & REINT_REPLAYING);
326 inode->i_generation = rec->ur_fid2->generation;
327 /* Dirtied and committed by the upcoming setattr. */
328 CDEBUG(D_INODE, "recreated ino %ld with gen %ld\n",
329 inode->i_ino, inode->i_generation);
331 CDEBUG(D_INODE, "created ino %ld\n", inode->i_ino);
334 rc = mds_fs_setattr(mds, dchild, handle, &iattr);
336 CERROR("error on setattr: rc = %d\n", rc);
337 /* XXX should we abort here in case of error? */
340 body = lustre_msg_buf(req->rq_repmsg, offset);
341 mds_pack_inode2fid(&body->fid1, inode);
342 mds_pack_inode2body(body, inode);
347 rc = mds_finish_transno(mds, handle, req, rc);
349 rc = mds_finish_transno(mds, handle, req, rc);
351 GOTO(out_create_unlink, rc);
353 err = mds_fs_commit(mds, dir, handle);
355 CERROR("error on commit: err = %d\n", err);
361 ldlm_lock_decref(&lockh, lock_mode);
370 /* Need to release the transno lock, and then put the dchild. */
372 mds_finish_transno(mds, handle, req, rc);
373 goto out_create_dchild;
376 /* Destroy the file we just created. This should not need extra
377 * journal credits, as we have already modified all of the blocks
378 * needed in order to create the file in the first place.
382 err = vfs_rmdir(dir, dchild);
384 CERROR("failed rmdir in error path: rc = %d\n", err);
387 err = vfs_unlink(dir, dchild);
389 CERROR("failed unlink in error path: rc = %d\n", err);
393 goto out_create_commit;
396 static int mds_reint_unlink(struct mds_update_record *rec, int offset,
397 struct ptlrpc_request *req)
399 struct dentry *de = NULL;
400 struct dentry *dchild = NULL;
401 struct mds_obd *mds = mds_req2mds(req);
402 struct obd_device *obd = req->rq_export->exp_obd;
403 struct mds_body *body = NULL;
405 struct inode *dir, *inode;
406 struct lustre_handle lockh, child_lockh;
408 int namelen, lock_mode, err, rc = 0;
411 /* a name was supplied by the client; fid1 is the directory */
412 lock_mode = (req->rq_reqmsg->opc == MDS_REINT) ? LCK_PW : LCK_PW;
413 de = mds_fid2locked_dentry(obd, rec->ur_fid1, NULL, lock_mode, &lockh);
419 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_UNLINK))
420 GOTO(out_unlink, rc = -ENOENT);
422 name = lustre_msg_buf(req->rq_reqmsg, offset + 1);
423 namelen = req->rq_reqmsg->buflens[offset + 1] - 1;
424 #warning "FIXME: if mds_name2locked_dentry decrefs this lock, we must not"
425 memcpy(&child_lockh, &lockh, sizeof(child_lockh));
426 dchild = mds_name2locked_dentry(obd, de, NULL, name, namelen,
427 LCK_EX, &child_lockh, lock_mode);
429 if (IS_ERR(dchild)) {
431 GOTO(out_unlink, rc = PTR_ERR(dchild));
435 inode = dchild->d_inode;
436 CDEBUG(D_INODE, "parent ino %ld\n", dir->i_ino);
439 if (rec->ur_opcode & REINT_REPLAYING) {
441 "child missing (%ld/%s); OK for REPLAYING\n",
442 dir->i_ino, rec->ur_name);
446 "child doesn't exist (dir %ld, name %s)\n",
447 dir->i_ino, rec->ur_name);
450 /* going to out_unlink_cancel causes an LBUG, don't know why */
451 GOTO(out_unlink_dchild, rc);
458 body = lustre_msg_buf(req->rq_repmsg, offset);
459 mds_pack_inode2fid(&body->fid1, inode);
460 mds_pack_inode2body(body, inode);
463 OBD_FAIL_WRITE(OBD_FAIL_MDS_REINT_UNLINK_WRITE,
464 to_kdev_t(dir->i_sb->s_dev));
466 mds_start_transno(mds);
467 switch (rec->ur_mode /* & S_IFMT ? */) {
469 handle = mds_fs_start(mds, dir, MDS_FSOP_RMDIR);
471 GOTO(out_unlink_cancel_transno, rc = PTR_ERR(handle));
472 rc = vfs_rmdir(dir, dchild);
475 /* get OBD EA data first so client can also destroy object */
476 if ((inode->i_mode & S_IFMT) == S_IFREG && offset)
477 rc = mds_pack_md(mds, req, offset + 1, body, inode);
484 handle = mds_fs_start(mds, dir, MDS_FSOP_UNLINK);
486 GOTO(out_unlink_cancel_transno, rc = PTR_ERR(handle));
487 rc = vfs_unlink(dir, dchild);
490 CERROR("bad file type %o unlinking %s\n", rec->ur_mode, name);
493 GOTO(out_unlink_cancel_transno, rc = -EINVAL);
496 rc = mds_finish_transno(mds, handle, req, rc);
497 err = mds_fs_commit(mds, dir, handle);
499 CERROR("error on commit: err = %d\n", err);
507 ldlm_lock_decref(&child_lockh, LCK_EX);
508 err = ldlm_cli_cancel(&child_lockh);
510 CERROR("failed to cancel child inode lock: err = %d\n", err);
512 rc = -ENOLCK; /*XXX translate LDLM lock error */
518 ldlm_lock_decref(&lockh, lock_mode);
523 out_unlink_cancel_transno:
524 rc = mds_finish_transno(mds, handle, req, rc);
525 goto out_unlink_cancel;
528 static int mds_reint_link(struct mds_update_record *rec, int offset,
529 struct ptlrpc_request *req)
531 struct obd_device *obd = req->rq_export->exp_obd;
532 struct dentry *de_src = NULL;
533 struct dentry *de_tgt_dir = NULL;
534 struct dentry *dchild = NULL;
535 struct mds_obd *mds = mds_req2mds(req);
536 struct lustre_handle *handle, tgtlockh, srclockh;
538 __u64 res_id[3] = { 0 };
543 de_src = mds_fid2dentry(mds, rec->ur_fid1, NULL);
544 if (IS_ERR(de_src) || OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_LINK)) {
545 GOTO(out_link, rc = -ESTALE);
548 /* plan to change the link count on this inode: write lock */
549 lock_mode = (req->rq_reqmsg->opc == MDS_REINT) ? LCK_PW : LCK_PW;
550 res_id[0] = de_src->d_inode->i_ino;
551 res_id[1] = de_src->d_inode->i_generation;
553 rc = ldlm_lock_match(obd->obd_namespace, res_id, LDLM_PLAIN,
554 NULL, 0, lock_mode, &srclockh);
556 LDLM_DEBUG_NOLOCK("enqueue res "LPU64, res_id[0]);
557 rc = ldlm_cli_enqueue(NULL, NULL, obd->obd_namespace, NULL,
558 res_id, LDLM_PLAIN, NULL, 0, lock_mode,
559 &flags, ldlm_completion_ast,
560 mds_blocking_ast, NULL, 0, &srclockh);
561 if (rc != ELDLM_OK) {
562 CERROR("lock enqueue: err: %d\n", rc);
563 GOTO(out_link_src_put, rc = -EIO);
566 ldlm_lock_dump((void *)(unsigned long)srclockh.addr);
568 de_tgt_dir = mds_fid2dentry(mds, rec->ur_fid2, NULL);
569 if (IS_ERR(de_tgt_dir)) {
570 GOTO(out_link_src, rc = -ESTALE);
573 lock_mode = (req->rq_reqmsg->opc == MDS_REINT) ? LCK_PW : LCK_PW;
574 res_id[0] = de_tgt_dir->d_inode->i_ino;
575 res_id[1] = de_tgt_dir->d_inode->i_generation;
577 rc = ldlm_lock_match(obd->obd_namespace, res_id, LDLM_PLAIN,
578 NULL, 0, lock_mode, &tgtlockh);
580 LDLM_DEBUG_NOLOCK("enqueue res "LPU64, res_id[0]);
581 rc = ldlm_cli_enqueue(NULL, NULL, obd->obd_namespace, NULL,
582 res_id, LDLM_PLAIN, NULL, 0, lock_mode,
583 &flags, ldlm_completion_ast,
584 mds_blocking_ast, NULL, 0, &tgtlockh);
585 if (rc != ELDLM_OK) {
586 CERROR("lock enqueue: err: %d\n", rc);
587 GOTO(out_link_tgt_dir_put, rc = -EIO);
590 ldlm_lock_dump((void *)(unsigned long)tgtlockh.addr);
592 down(&de_tgt_dir->d_inode->i_sem);
593 dchild = lookup_one_len(rec->ur_name, de_tgt_dir, rec->ur_namelen - 1);
594 if (IS_ERR(dchild)) {
595 CERROR("child lookup error %ld\n", PTR_ERR(dchild));
596 GOTO(out_link_tgt_dir, rc = -ESTALE);
599 if (dchild->d_inode) {
600 struct inode *inode = dchild->d_inode;
601 /* in intent case ship back attributes to client */
603 struct mds_body *body =
604 lustre_msg_buf(req->rq_repmsg, 1);
606 mds_pack_inode2fid(&body->fid1, inode);
607 mds_pack_inode2body(body, inode);
608 if (S_ISREG(inode->i_mode))
609 rc = mds_pack_md(mds, req, 2, body, inode);
611 if (rec->ur_opcode & REINT_REPLAYING) {
612 /* XXX verify that the link is to the the right file? */
615 "child exists (dir %ld, name %s) (REPLAYING)\n",
616 de_tgt_dir->d_inode->i_ino, rec->ur_name);
619 CERROR("child exists (dir %ld, name %s)\n",
620 de_tgt_dir->d_inode->i_ino, rec->ur_name);
622 GOTO(out_link_dchild, rc);
625 OBD_FAIL_WRITE(OBD_FAIL_MDS_REINT_LINK_WRITE,
626 to_kdev_t(de_src->d_inode->i_sb->s_dev));
628 mds_start_transno(mds);
629 handle = mds_fs_start(mds, de_tgt_dir->d_inode, MDS_FSOP_LINK);
630 if (IS_ERR(handle)) {
631 rc = PTR_ERR(handle);
632 mds_finish_transno(mds, handle, req, rc);
633 GOTO(out_link_dchild, rc);
636 rc = vfs_link(de_src, de_tgt_dir->d_inode, dchild);
638 CERROR("link error %d\n", rc);
639 rc = mds_finish_transno(mds, handle, req, rc);
641 err = mds_fs_commit(mds, de_tgt_dir->d_inode, handle);
643 CERROR("error on commit: err = %d\n", err);
652 ldlm_lock_decref(&tgtlockh, lock_mode);
653 out_link_tgt_dir_put:
654 up(&de_tgt_dir->d_inode->i_sem);
657 ldlm_lock_decref(&srclockh, lock_mode);
665 static int mds_reint_rename(struct mds_update_record *rec, int offset,
666 struct ptlrpc_request *req)
668 struct obd_device *obd = req->rq_export->exp_obd;
669 struct dentry *de_srcdir = NULL;
670 struct dentry *de_tgtdir = NULL;
671 struct dentry *de_old = NULL;
672 struct dentry *de_new = NULL;
673 struct mds_obd *mds = mds_req2mds(req);
674 struct lustre_handle tgtlockh, srclockh, oldhandle;
675 int flags = 0, lock_mode, rc = 0, err;
677 __u64 res_id[3] = { 0 };
680 de_srcdir = mds_fid2dentry(mds, rec->ur_fid1, NULL);
681 if (IS_ERR(de_srcdir))
682 GOTO(out_rename, rc = -ESTALE);
684 lock_mode = (req->rq_reqmsg->opc == MDS_REINT) ? LCK_PW : LCK_PW;
685 res_id[0] = de_srcdir->d_inode->i_ino;
686 res_id[1] = de_srcdir->d_inode->i_generation;
688 rc = ldlm_lock_match(obd->obd_namespace, res_id, LDLM_PLAIN,
689 NULL, 0, lock_mode, &srclockh);
691 LDLM_DEBUG_NOLOCK("enqueue res "LPU64, res_id[0]);
692 rc = ldlm_cli_enqueue(NULL, NULL, obd->obd_namespace, NULL,
693 res_id, LDLM_PLAIN, NULL, 0, lock_mode,
694 &flags, ldlm_completion_ast,
695 mds_blocking_ast, NULL, 0, &srclockh);
696 if (rc != ELDLM_OK) {
697 CERROR("lock enqueue: err: %d\n", rc);
698 GOTO(out_rename_srcput, rc = -EIO);
701 ldlm_lock_dump((void *)(unsigned long)srclockh.addr);
703 de_tgtdir = mds_fid2dentry(mds, rec->ur_fid2, NULL);
704 if (IS_ERR(de_tgtdir))
705 GOTO(out_rename_srcdir, rc = -ESTALE);
707 lock_mode = (req->rq_reqmsg->opc == MDS_REINT) ? LCK_PW : LCK_PW;
708 res_id[0] = de_tgtdir->d_inode->i_ino;
709 res_id[1] = de_tgtdir->d_inode->i_generation;
711 rc = ldlm_lock_match(obd->obd_namespace, res_id, LDLM_PLAIN,
712 NULL, 0, lock_mode, &tgtlockh);
715 LDLM_DEBUG_NOLOCK("enqueue res "LPU64, res_id[0]);
716 rc = ldlm_cli_enqueue(NULL, NULL, obd->obd_namespace, NULL,
717 res_id, LDLM_PLAIN, NULL, 0, lock_mode,
718 &flags, ldlm_completion_ast,
719 mds_blocking_ast, NULL, 0, &tgtlockh);
720 if (rc != ELDLM_OK) {
721 CERROR("lock enqueue: err: %d\n", rc);
722 GOTO(out_rename_tgtput, rc = -EIO);
725 ldlm_lock_dump((void *)(unsigned long)tgtlockh.addr);
727 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
728 double_lock(de_tgtdir, de_srcdir);
730 de_old = lookup_one_len(rec->ur_name, de_srcdir, rec->ur_namelen - 1);
731 if (IS_ERR(de_old)) {
732 CERROR("old child lookup error (%*s): %ld\n",
733 rec->ur_namelen - 1, rec->ur_name, PTR_ERR(de_old));
734 GOTO(out_rename_tgtdir, rc = -ENOENT);
737 de_new = lookup_one_len(rec->ur_tgt, de_tgtdir, rec->ur_tgtlen - 1);
738 if (IS_ERR(de_new)) {
739 CERROR("new child lookup error (%*s): %ld\n",
740 rec->ur_tgtlen - 1, rec->ur_tgt, PTR_ERR(de_new));
741 GOTO(out_rename_deold, rc = -ENOENT);
744 /* in intent case ship back attributes to client */
746 struct mds_body *body = lustre_msg_buf(req->rq_repmsg, 1);
747 struct inode *inode = de_new->d_inode;
752 mds_pack_inode2fid(&body->fid1, inode);
753 mds_pack_inode2body(body, inode);
754 if (S_ISREG(inode->i_mode))
755 rc = mds_pack_md(mds, req, 2, body, inode);
759 OBD_FAIL_WRITE(OBD_FAIL_MDS_REINT_RENAME_WRITE,
760 to_kdev_t(de_srcdir->d_inode->i_sb->s_dev));
762 mds_start_transno(mds);
763 handle = mds_fs_start(mds, de_tgtdir->d_inode, MDS_FSOP_RENAME);
764 if (IS_ERR(handle)) {
765 rc = PTR_ERR(handle);
766 mds_finish_transno(mds, handle, req, rc);
767 GOTO(out_rename_denew, rc);
771 rc = vfs_rename(de_srcdir->d_inode, de_old, de_tgtdir->d_inode, de_new,
775 rc = mds_finish_transno(mds, handle, req, rc);
777 err = mds_fs_commit(mds, de_tgtdir->d_inode, handle);
779 CERROR("error on commit: err = %d\n", err);
789 res_id[0] = de_old->d_inode->i_ino;
790 res_id[1] = de_old->d_inode->i_generation;
792 /* Take an exclusive lock on the resource that we're
793 * about to free, to force everyone to drop their
795 LDLM_DEBUG_NOLOCK("getting EX lock res "LPU64, res_id[0]);
796 rc = ldlm_cli_enqueue(NULL, NULL, obd->obd_namespace, NULL,
797 res_id, LDLM_PLAIN, NULL, 0, LCK_EX,
798 &flags, ldlm_completion_ast,
799 mds_blocking_ast, NULL, 0, &oldhandle);
801 CERROR("failed to get child inode lock (child ino "
802 LPD64" dir ino %ld)\n",
803 res_id[0], de_old->d_inode->i_ino);
809 ldlm_lock_decref(&oldhandle, LCK_EX);
810 rc = ldlm_cli_cancel(&oldhandle);
812 CERROR("failed to cancel child inode lock ino "
813 LPD64": %d\n", res_id[0], rc);
816 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
817 double_up(&de_srcdir->d_inode->i_sem, &de_tgtdir->d_inode->i_sem);
819 ldlm_lock_decref(&tgtlockh, lock_mode);
823 ldlm_lock_decref(&srclockh, lock_mode);
831 typedef int (*mds_reinter) (struct mds_update_record *, int offset,
832 struct ptlrpc_request *);
834 static mds_reinter reinters[REINT_MAX + 1] = {
835 [REINT_SETATTR] mds_reint_setattr,
836 [REINT_CREATE] mds_reint_create,
837 [REINT_UNLINK] mds_reint_unlink,
838 [REINT_LINK] mds_reint_link,
839 [REINT_RENAME] mds_reint_rename,
842 int mds_reint_rec(struct mds_update_record *rec, int offset,
843 struct ptlrpc_request *req)
845 struct mds_obd *mds = mds_req2mds(req);
846 struct obd_run_ctxt saved;
848 int realop = rec->ur_opcode & REINT_OPCODE_MASK;
851 if (realop < 1 || realop > REINT_MAX) {
852 CERROR("opcode %d not valid (%sREPLAYING)\n", realop,
853 rec->ur_opcode & REINT_REPLAYING ? "" : "not ");
854 rc = req->rq_status = -EINVAL;
858 uc.ouc_fsuid = rec->ur_fsuid;
859 uc.ouc_fsgid = rec->ur_fsgid;
860 uc.ouc_cap = rec->ur_cap;
862 push_ctxt(&saved, &mds->mds_ctxt, &uc);
863 rc = reinters[realop] (rec, offset, req);