1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * linux/mds/mds_reint.c
6 * Lustre Metadata Server (mds) reintegration routines
8 * Copyright (C) 2002 Cluster File Systems, Inc.
9 * author: Peter Braam <braam@clusterfs.com>
11 * This code is issued under the GNU General Public License.
12 * See the file COPYING in this distribution
16 // XXX - add transaction sequence numbers
19 #define DEBUG_SUBSYSTEM S_MDS
21 #include <linux/obd_support.h>
22 #include <linux/obd_class.h>
23 #include <linux/obd.h>
24 #include <linux/lustre_lib.h>
25 #include <linux/lustre_idl.h>
26 #include <linux/lustre_mds.h>
27 #include <linux/lustre_dlm.h>
28 #include <linux/obd_class.h>
30 extern inline struct mds_obd *mds_req2mds(struct ptlrpc_request *req);
32 struct mds_client_info *mds_uuid_to_mci(struct mds_obd *mds, __u8 *uuid)
39 list_for_each(p, &mds->mds_client_info) {
40 struct mds_client_info *mci;
42 mci = list_entry(p, struct mds_client_info, mci_list);
43 CDEBUG(D_INFO, "checking client UUID '%s'\n",
44 mci->mci_mcd->mcd_uuid);
45 if (!strncmp(mci->mci_mcd->mcd_uuid, uuid,
46 sizeof(mci->mci_mcd->mcd_uuid)))
49 CDEBUG(D_INFO, "no mds client info found for UUID '%s'\n", uuid);
53 /* Assumes caller has already pushed us into the kernel context. */
54 int mds_update_last_rcvd(struct mds_obd *mds, void *handle,
55 struct ptlrpc_request *req)
57 /* get from req->rq_connection-> or req->rq_client */
58 struct mds_client_info *mci;
62 mci = mds_uuid_to_mci(mds, req->rq_connection->c_remote_uuid);
64 CERROR("unable to locate MDS client data for UUID '%s'\n",
65 ptlrpc_req_to_uuid(req));
66 /* This will be a real error once everything is working */
71 off = MDS_LR_CLIENT + mci->mci_off * MDS_LR_SIZE;
73 ++mds->mds_last_rcvd; /* lock this, or make it an LDLM function? */
74 req->rq_repmsg->transno = HTON__u64(mds->mds_last_rcvd);
75 mci->mci_mcd->mcd_last_rcvd = cpu_to_le64(mds->mds_last_rcvd);
76 mci->mci_mcd->mcd_mount_count = cpu_to_le64(mds->mds_mount_count);
77 mci->mci_mcd->mcd_last_xid = cpu_to_le64(req->rq_xid);
79 mds_fs_set_last_rcvd(mds, handle);
80 rc = lustre_fwrite(mds->mds_rcvd_filp, (char *)mci->mci_mcd,
81 sizeof(*mci->mci_mcd), &off);
82 CDEBUG(D_INODE, "wrote trans #%Ld for client '%s' at #%d: rc = %d\n",
83 mds->mds_last_rcvd, mci->mci_mcd->mcd_uuid, mci->mci_off, rc);
84 // store new value and last committed value in req struct
86 if (rc == sizeof(*mci->mci_mcd))
89 CERROR("error writing to last_rcvd file: rc = %d\n", rc);
97 /* In the write-back case, the client holds a lock on a subtree.
98 * In the intent case, the client holds a lock on the child inode.
99 * In the pathname case, the client (may) hold a lock on the child inode. */
100 static int mds_reint_setattr(struct mds_update_record *rec, int offset,
101 struct ptlrpc_request *req)
103 struct mds_obd *mds = mds_req2mds(req);
106 struct lustre_handle child_lockh;
109 if (req->rq_reqmsg->bufcount > offset + 1) {
111 struct lustre_handle dir_lockh;
114 /* a name was supplied by the client; fid1 is the directory */
116 name = lustre_msg_buf(req->rq_reqmsg, offset + 1);
117 namelen = req->rq_reqmsg->buflens[offset + 1] - 1;
118 dir = mds_fid2locked_dentry(mds, rec->ur_fid1, NULL, LCK_PR,
120 if (!dir || IS_ERR(dir)) {
123 GOTO(out_setattr, rc = -ESTALE);
126 de = mds_name2locked_dentry(mds, dir, NULL, name, namelen,
129 if (!de || IS_ERR(de)) {
131 GOTO(out_setattr_de, rc = -ESTALE);
134 de = mds_fid2dentry(mds, rec->ur_fid1, NULL);
135 if (!de || IS_ERR(de)) {
137 GOTO(out_setattr_de, rc = -ESTALE);
140 CDEBUG(D_INODE, "ino %ld\n", de->d_inode->i_ino);
142 OBD_FAIL_WRITE(OBD_FAIL_MDS_REINT_SETATTR_WRITE,
143 de->d_inode->i_sb->s_dev);
146 handle = mds_fs_start(mds, de->d_inode, MDS_FSOP_SETATTR);
148 GOTO(out_unlock, rc = PTR_ERR(handle));
149 rc = mds_fs_setattr(mds, de, handle, &rec->ur_iattr);
152 rc = mds_update_last_rcvd(mds, handle, req);
154 err = mds_fs_commit(mds, de->d_inode, handle);
156 CERROR("error on commit: err = %d\n", err);
171 static int mds_reint_recreate(struct mds_update_record *rec, int offset,
172 struct ptlrpc_request *req)
174 struct dentry *de = NULL;
175 struct mds_obd *mds = mds_req2mds(req);
176 struct dentry *dchild = NULL;
181 de = mds_fid2dentry(mds, rec->ur_fid1, NULL);
182 if (IS_ERR(de) || OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_CREATE)) {
184 GOTO(out_create_de, rc = -ESTALE);
187 CDEBUG(D_INODE, "parent ino %ld\n", dir->i_ino);
190 dchild = lookup_one_len(rec->ur_name, de, rec->ur_namelen - 1);
191 if (IS_ERR(dchild)) {
192 CERROR("child lookup error %ld\n", PTR_ERR(dchild));
195 GOTO(out_create_dchild, rc = -ESTALE);
198 if (dchild->d_inode) {
199 struct mds_body *body;
201 body = lustre_msg_buf(req->rq_repmsg, 0);
202 body->ino = dchild->d_inode->i_ino;
203 body->generation = dchild->d_inode->i_generation;
205 CERROR("child doesn't exist (dir %ld, name %s)\n",
206 dir->i_ino, rec->ur_name);
220 static int mds_reint_create(struct mds_update_record *rec, int offset,
221 struct ptlrpc_request *req)
223 struct dentry *de = NULL;
224 struct mds_obd *mds = mds_req2mds(req);
225 struct dentry *dchild = NULL;
228 struct lustre_handle lockh;
229 int rc = 0, err, flags, lock_mode, type = rec->ur_mode & S_IFMT;
230 __u64 res_id[3] = {0,0,0};
233 /* requests were at offset 2, replies go back at 1 */
237 if (strcmp(req->rq_export->export_obd->obd_type->typ_name, "mds") != 0)
240 de = mds_fid2dentry(mds, rec->ur_fid1, NULL);
241 if (IS_ERR(de) || OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_CREATE)) {
243 GOTO(out_create_de, rc = -ESTALE);
246 CDEBUG(D_INODE, "parent ino %ld name %s mode %o\n",
247 dir->i_ino, rec->ur_name, rec->ur_mode);
249 lock_mode = (req->rq_reqmsg->opc == MDS_REINT) ? LCK_CW : LCK_PW;
250 res_id[0] = dir->i_ino;
252 rc = ldlm_lock_match(mds->mds_local_namespace, res_id, LDLM_PLAIN,
253 NULL, 0, lock_mode, &lockh);
255 LDLM_DEBUG_NOLOCK("enqueue res %Lu", res_id[0]);
256 rc = ldlm_cli_enqueue(mds->mds_ldlm_client, mds->mds_ldlm_conn,
257 (struct lustre_handle *)&mds->mds_connh,
258 NULL, mds->mds_local_namespace, NULL,
259 res_id, LDLM_PLAIN, NULL, 0, lock_mode,
260 &flags, (void *)mds_lock_callback, NULL,
262 if (rc != ELDLM_OK) {
263 CERROR("lock enqueue: err: %d\n", rc);
264 GOTO(out_create_de, rc = -EIO);
267 ldlm_lock_dump((void *)(unsigned long)lockh.addr);
270 dchild = lookup_one_len(rec->ur_name, de, rec->ur_namelen - 1);
271 if (IS_ERR(dchild)) {
272 CERROR("child lookup error %ld\n", PTR_ERR(dchild));
275 GOTO(out_create_dchild, rc = -ESTALE);
278 if (dchild->d_inode) {
279 struct mds_body *body;
281 struct inode *inode = dchild->d_inode;
282 CDEBUG(D_INODE, "child exists (dir %ld, name %s, ino %ld)\n",
283 dir->i_ino, rec->ur_name, dchild->d_inode->i_ino);
285 body = lustre_msg_buf(req->rq_repmsg, offset);
286 mds_pack_inode2fid(&body->fid1, inode);
287 mds_pack_inode2body(body, inode);
288 #warning FIXME: This ext3/N-specific code does not belong here
289 /* If i_file_acl is set, this inode has an EA */
290 if (S_ISREG(inode->i_mode) && inode->u.ext3_i.i_file_acl) {
291 obdo = lustre_msg_buf(req->rq_repmsg, offset + 1);
292 mds_fs_get_obdo(mds, inode, obdo);
294 /* now a normal case for intent locking */
295 GOTO(out_create_dchild, rc = -EEXIST);
298 OBD_FAIL_WRITE(OBD_FAIL_MDS_REINT_CREATE_WRITE, dir->i_sb->s_dev);
300 if (dir->i_mode & S_ISGID) {
301 rec->ur_gid = dir->i_gid;
302 if (S_ISDIR(rec->ur_mode))
303 rec->ur_mode |= S_ISGID;
308 handle = mds_fs_start(mds, dir, MDS_FSOP_CREATE);
310 GOTO(out_create_dchild, PTR_ERR(handle));
311 rc = vfs_create(dir, dchild, rec->ur_mode);
316 handle = mds_fs_start(mds, dir, MDS_FSOP_MKDIR);
318 GOTO(out_create_dchild, PTR_ERR(handle));
319 rc = vfs_mkdir(dir, dchild, rec->ur_mode);
324 handle = mds_fs_start(mds, dir, MDS_FSOP_SYMLINK);
326 GOTO(out_create_dchild, PTR_ERR(handle));
327 rc = vfs_symlink(dir, dchild, rec->ur_tgt);
335 int rdev = rec->ur_rdev;
336 handle = mds_fs_start(mds, dir, MDS_FSOP_MKNOD);
338 GOTO(out_create_dchild, PTR_ERR(handle));
339 rc = vfs_mknod(dir, dchild, rec->ur_mode, rdev);
344 CERROR("bad file type %d for create of %s\n",type,rec->ur_name);
345 GOTO(out_create_dchild, rc = -EINVAL);
349 CERROR("error during create: %d\n", rc);
352 GOTO(out_create_commit, rc);
355 struct inode *inode = dchild->d_inode;
356 struct mds_body *body;
358 CDEBUG(D_INODE, "created ino %ld\n", dchild->d_inode->i_ino);
359 if (!offset && type == S_IFREG) {
361 obdo = lustre_msg_buf(req->rq_reqmsg, 2);
362 rc = mds_fs_set_obdo(mds, inode, handle, obdo);
364 CERROR("error %d setting obdo for %ld\n",
366 GOTO(out_create_unlink, rc);
370 iattr.ia_atime = rec->ur_time;
371 iattr.ia_ctime = rec->ur_time;
372 iattr.ia_mtime = rec->ur_time;
373 iattr.ia_uid = rec->ur_uid;
374 iattr.ia_gid = rec->ur_gid;
375 iattr.ia_valid = ATTR_UID | ATTR_GID | ATTR_ATIME |
376 ATTR_MTIME | ATTR_CTIME;
378 rc = mds_fs_setattr(mds, dchild, handle, &iattr);
380 CERROR("error on setattr: rc = %d\n", rc);
381 /* XXX should we abort here in case of error? */
384 rc = mds_update_last_rcvd(mds, handle, req);
386 CERROR("error on update_last_rcvd: rc = %d\n", rc);
387 /* XXX should we abort here in case of error? */
390 body = lustre_msg_buf(req->rq_repmsg, offset);
391 body->ino = inode->i_ino;
392 body->generation = inode->i_generation;
396 err = mds_fs_commit(mds, dir, handle);
398 CERROR("error on commit: err = %d\n", err);
405 ldlm_lock_decref(&lockh, lock_mode);
412 /* Destroy the file we just created. This should not need extra
413 * journal credits, as we have already modified all of the blocks
414 * needed in order to create the file in the first place.
418 err = vfs_rmdir(dir, dchild);
420 CERROR("failed rmdir in error path: rc = %d\n", err);
423 err = vfs_unlink(dir, dchild);
425 CERROR("failed unlink in error path: rc = %d\n", err);
428 goto out_create_commit;
431 static int mds_reint_unlink(struct mds_update_record *rec, int offset,
432 struct ptlrpc_request *req)
434 struct dentry *de = NULL;
435 struct dentry *dchild = NULL;
436 struct mds_obd *mds = mds_req2mds(req);
438 struct inode *dir, *inode;
439 int lock_mode, flags;
440 __u64 res_id[3] = {0};
441 struct lustre_handle lockh;
447 de = mds_fid2dentry(mds, rec->ur_fid1, NULL);
448 if (IS_ERR(de) || OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_UNLINK)) {
450 GOTO(out_unlink, rc = -ESTALE);
454 CDEBUG(D_INODE, "parent ino %ld\n", dir->i_ino);
455 lock_mode = (req->rq_reqmsg->opc == MDS_REINT) ? LCK_CW : LCK_PW;
456 res_id[0] = dir->i_ino;
458 rc = ldlm_lock_match(mds->mds_local_namespace, res_id, LDLM_PLAIN,
459 NULL, 0, lock_mode, &lockh);
461 LDLM_DEBUG_NOLOCK("enqueue res %Lu", res_id[0]);
462 rc = ldlm_cli_enqueue(mds->mds_ldlm_client, mds->mds_ldlm_conn,
463 (struct lustre_handle *)&mds->mds_connh,
464 NULL, mds->mds_local_namespace, NULL,
465 res_id, LDLM_PLAIN, NULL, 0, lock_mode,
466 &flags, (void *)mds_lock_callback, NULL,
468 if (rc != ELDLM_OK) {
469 CERROR("lock enqueue: err: %d\n", rc);
470 GOTO(out_unlink_de, rc = -EIO);
473 ldlm_lock_dump((void *)(unsigned long)lockh.addr);
476 dchild = lookup_one_len(rec->ur_name, de, rec->ur_namelen - 1);
477 if (IS_ERR(dchild)) {
478 CERROR("child lookup error %ld\n", PTR_ERR(dchild));
480 GOTO(out_unlink_de, rc = -ESTALE);
483 inode = dchild->d_inode;
485 CERROR("child doesn't exist (dir %ld, name %s\n",
486 dir->i_ino, rec->ur_name);
487 GOTO(out_unlink_dchild, rc = -ENOENT);
490 #if 0 /* in intent case the client doesn't have the inode */
491 if (inode->i_ino != rec->ur_fid2->id) {
492 CERROR("inode and FID ID do not match (%ld != %Ld)\n",
493 inode->i_ino, rec->ur_fid2->id);
495 GOTO(out_unlink_dchild, rc = -ESTALE);
497 if (inode->i_generation != rec->ur_fid2->generation) {
498 CERROR("inode and FID GENERATION do not match (%d != %d)\n",
499 inode->i_generation, rec->ur_fid2->generation);
501 GOTO(out_unlink_dchild, rc = -ESTALE);
505 OBD_FAIL_WRITE(OBD_FAIL_MDS_REINT_UNLINK_WRITE, dir->i_sb->s_dev);
507 switch (inode->i_mode & S_IFMT) {
509 handle = mds_fs_start(mds, dir, MDS_FSOP_RMDIR);
511 GOTO(out_unlink_dchild, rc = PTR_ERR(handle));
512 rc = vfs_rmdir(dir, dchild);
516 obdo = lustre_msg_buf(req->rq_repmsg, 1);
517 rc = mds_fs_get_obdo(mds, inode, obdo);
519 CDEBUG(D_INFO, "No obdo for ino %ld err %d\n",
523 handle = mds_fs_start(mds, dir, MDS_FSOP_UNLINK);
525 GOTO(out_unlink_dchild, rc = PTR_ERR(handle));
526 rc = vfs_unlink(dir, dchild);
531 rc = mds_update_last_rcvd(mds, handle, req);
532 err = mds_fs_commit(mds, dir, handle);
534 CERROR("error on commit: err = %d\n", err);
542 res_id[0] = inode->i_ino;
546 ldlm_lock_decref(&lockh, lock_mode);
548 /* Take an exclusive lock on the resource that we're
549 * about to free, to force everyone to drop their
551 LDLM_DEBUG_NOLOCK("getting EX lock res %Lu", res_id[0]);
552 rc = ldlm_cli_enqueue(mds->mds_ldlm_client, mds->mds_ldlm_conn,
553 (struct lustre_handle *)&mds->mds_connh,
554 NULL, mds->mds_local_namespace, NULL,
556 LDLM_PLAIN, NULL, 0, LCK_EX, &flags,
557 (void *)mds_lock_callback, NULL, 0,
560 CERROR("failed to get child inode lock (child ino %Ld, "
562 res_id[0], de->d_inode->i_ino);
568 ldlm_lock_decref(&lockh, LCK_EX);
569 rc = ldlm_cli_cancel(&lockh);
571 CERROR("failed to cancel child inode lock ino "
572 "%Ld: %d\n", res_id[0], rc);
580 static int mds_reint_link(struct mds_update_record *rec, int offset,
581 struct ptlrpc_request *req)
583 struct dentry *de_src = NULL;
584 struct dentry *de_tgt_dir = NULL;
585 struct dentry *dchild = NULL;
586 struct mds_obd *mds = mds_req2mds(req);
592 de_src = mds_fid2dentry(mds, rec->ur_fid1, NULL);
593 if (IS_ERR(de_src) || OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_LINK)) {
594 GOTO(out_link, rc = -ESTALE);
597 de_tgt_dir = mds_fid2dentry(mds, rec->ur_fid2, NULL);
598 if (IS_ERR(de_tgt_dir)) {
599 GOTO(out_link_de_src, rc = -ESTALE);
602 down(&de_tgt_dir->d_inode->i_sem);
603 dchild = lookup_one_len(rec->ur_name, de_tgt_dir, rec->ur_namelen - 1);
604 if (IS_ERR(dchild)) {
605 CERROR("child lookup error %ld\n", PTR_ERR(dchild));
606 GOTO(out_link_de_tgt_dir, rc = -ESTALE);
609 if (dchild->d_inode) {
610 CERROR("child exists (dir %ld, name %s\n",
611 de_tgt_dir->d_inode->i_ino, rec->ur_name);
612 GOTO(out_link_dchild, rc = -EEXIST);
615 OBD_FAIL_WRITE(OBD_FAIL_MDS_REINT_LINK_WRITE,
616 de_src->d_inode->i_sb->s_dev);
618 handle = mds_fs_start(mds, de_tgt_dir->d_inode, MDS_FSOP_LINK);
620 GOTO(out_link_dchild, rc = PTR_ERR(handle));
622 rc = vfs_link(de_src, de_tgt_dir->d_inode, dchild);
625 rc = mds_update_last_rcvd(mds, handle, req);
627 err = mds_fs_commit(mds, de_tgt_dir->d_inode, handle);
629 CERROR("error on commit: err = %d\n", err);
638 up(&de_tgt_dir->d_inode->i_sem);
647 static int mds_reint_rename(struct mds_update_record *rec, int offset,
648 struct ptlrpc_request *req)
650 struct dentry *de_srcdir = NULL;
651 struct dentry *de_tgtdir = NULL;
652 struct dentry *de_old = NULL;
653 struct dentry *de_new = NULL;
654 struct mds_obd *mds = mds_req2mds(req);
655 struct lustre_handle tgtlockh, srclockh, oldhandle;
656 int flags, lock_mode, rc = 0, err;
658 __u64 res_id[3] = {0};
661 de_srcdir = mds_fid2dentry(mds, rec->ur_fid1, NULL);
662 if (IS_ERR(de_srcdir))
663 GOTO(out_rename, rc = -ESTALE);
665 lock_mode = (req->rq_reqmsg->opc == MDS_REINT) ? LCK_CW : LCK_PW;
666 res_id[0] = de_srcdir->d_inode->i_ino;
668 rc = ldlm_lock_match(mds->mds_local_namespace, res_id, LDLM_PLAIN,
669 NULL, 0, lock_mode, &srclockh);
671 LDLM_DEBUG_NOLOCK("enqueue res %Lu", res_id[0]);
672 rc = ldlm_cli_enqueue(mds->mds_ldlm_client, mds->mds_ldlm_conn,
673 (struct lustre_handle *)&mds->mds_connh,
674 NULL, mds->mds_local_namespace, NULL,
675 res_id, LDLM_PLAIN, NULL, 0, lock_mode,
676 &flags, (void *)mds_lock_callback, NULL,
678 if (rc != ELDLM_OK) {
679 CERROR("lock enqueue: err: %d\n", rc);
680 GOTO(out_rename_srcput, rc = -EIO);
683 ldlm_lock_dump((void *)(unsigned long)srclockh.addr);
685 de_tgtdir = mds_fid2dentry(mds, rec->ur_fid2, NULL);
686 if (IS_ERR(de_tgtdir))
687 GOTO(out_rename_srcdir, rc = -ESTALE);
689 lock_mode = (req->rq_reqmsg->opc == MDS_REINT) ? LCK_CW : LCK_PW;
690 res_id[0] = de_tgtdir->d_inode->i_ino;
692 rc = ldlm_lock_match(mds->mds_local_namespace, res_id, LDLM_PLAIN,
693 NULL, 0, lock_mode, &tgtlockh);
695 LDLM_DEBUG_NOLOCK("enqueue res %Lu", res_id[0]);
696 rc = ldlm_cli_enqueue(mds->mds_ldlm_client, mds->mds_ldlm_conn,
697 (struct lustre_handle *)&mds->mds_connh,
698 NULL, mds->mds_local_namespace, NULL,
699 res_id, LDLM_PLAIN, NULL, 0, lock_mode,
700 &flags, (void *)mds_lock_callback, NULL,
702 if (rc != ELDLM_OK) {
703 CERROR("lock enqueue: err: %d\n", rc);
704 GOTO(out_rename_tgtput, rc = -EIO);
707 ldlm_lock_dump((void *)(unsigned long)tgtlockh.addr);
709 double_lock(de_tgtdir, de_srcdir);
711 de_old = lookup_one_len(rec->ur_name, de_srcdir, rec->ur_namelen - 1);
712 if (IS_ERR(de_old)) {
713 CERROR("old child lookup error (%*s): %ld\n",
714 rec->ur_namelen - 1, rec->ur_name, PTR_ERR(de_old));
715 GOTO(out_rename_tgtdir, rc = -ENOENT);
718 de_new = lookup_one_len(rec->ur_tgt, de_tgtdir, rec->ur_tgtlen - 1);
719 if (IS_ERR(de_new)) {
720 CERROR("new child lookup error (%*s): %ld\n",
721 rec->ur_tgtlen - 1, rec->ur_tgt, PTR_ERR(de_new));
722 GOTO(out_rename_deold, rc = -ENOENT);
725 OBD_FAIL_WRITE(OBD_FAIL_MDS_REINT_RENAME_WRITE,
726 de_srcdir->d_inode->i_sb->s_dev);
728 handle = mds_fs_start(mds, de_tgtdir->d_inode, MDS_FSOP_RENAME);
730 GOTO(out_rename_denew, rc = PTR_ERR(handle));
732 rc = vfs_rename(de_srcdir->d_inode, de_old, de_tgtdir->d_inode, de_new,
737 rc = mds_update_last_rcvd(mds, handle, req);
739 err = mds_fs_commit(mds, de_tgtdir->d_inode, handle);
741 CERROR("error on commit: err = %d\n", err);
751 res_id[0] = de_old->d_inode->i_ino;
752 /* Take an exclusive lock on the resource that we're
753 * about to free, to force everyone to drop their
755 LDLM_DEBUG_NOLOCK("getting EX lock res %Lu", res_id[0]);
756 rc = ldlm_cli_enqueue(mds->mds_ldlm_client, mds->mds_ldlm_conn,
757 (struct lustre_handle *)&mds->mds_connh,
758 NULL, mds->mds_local_namespace, NULL,
760 LDLM_PLAIN, NULL, 0, LCK_EX, &flags,
761 (void *)mds_lock_callback, NULL, 0,
764 CERROR("failed to get child inode lock (child ino %Ld, "
766 res_id[0], de_old->d_inode->i_ino);
772 ldlm_lock_decref(&oldhandle, LCK_EX);
773 rc = ldlm_cli_cancel(&oldhandle);
775 CERROR("failed to cancel child inode lock ino "
776 "%Ld: %d\n", res_id[0], rc);
779 double_up(&de_srcdir->d_inode->i_sem, &de_tgtdir->d_inode->i_sem);
780 ldlm_lock_decref(&tgtlockh, lock_mode);
784 ldlm_lock_decref(&srclockh, lock_mode);
792 typedef int (*mds_reinter)(struct mds_update_record *, int offset,
793 struct ptlrpc_request *);
795 static mds_reinter reinters[REINT_MAX+1] = {
796 [REINT_SETATTR] mds_reint_setattr,
797 [REINT_CREATE] mds_reint_create,
798 [REINT_UNLINK] mds_reint_unlink,
799 [REINT_LINK] mds_reint_link,
800 [REINT_RENAME] mds_reint_rename,
801 [REINT_RECREATE] mds_reint_recreate,
804 int mds_reint_rec(struct mds_update_record *rec, int offset,
805 struct ptlrpc_request *req)
807 struct mds_obd *mds = mds_req2mds(req);
808 struct obd_run_ctxt saved;
812 if (rec->ur_opcode < 1 || rec->ur_opcode > REINT_MAX) {
813 CERROR("opcode %d not valid\n", rec->ur_opcode);
814 rc = req->rq_status = -EINVAL;
818 push_ctxt(&saved, &mds->mds_ctxt);
819 rc = reinters[rec->ur_opcode](rec, offset, req);