Whamcloud - gitweb
LU-2700 mdt: serializing the rename
[fs/lustre-release.git] / lustre / mdt / mdt_reint.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
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.
9  *
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).
15  *
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
19  *
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
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 2012, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lustre/mdt/mdt_reint.c
37  *
38  * Lustre Metadata Target (mdt) reintegration routines
39  *
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>
45  */
46
47 #define DEBUG_SUBSYSTEM S_MDS
48
49 #include "mdt_internal.h"
50
51 static inline void mdt_reint_init_ma(struct mdt_thread_info *info,
52                                      struct md_attr *ma)
53 {
54         ma->ma_need = MA_INODE;
55         ma->ma_valid = 0;
56 }
57
58 static int mdt_create_pack_capa(struct mdt_thread_info *info, int rc,
59                                 struct mdt_object *object,
60                                 struct mdt_body *repbody)
61 {
62         ENTRY;
63
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)
67                 RETURN(rc);
68
69         if (rc == 0 && info->mti_mdt->mdt_opts.mo_mds_capa &&
70             info->mti_exp->exp_connect_flags & OBD_CONNECT_MDS_CAPA) {
71                 struct lustre_capa *capa;
72
73                 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA1);
74                 LASSERT(capa);
75                 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
76                 rc = mo_capa_get(info->mti_env, mdt_object_child(object), capa,
77                                  0);
78                 if (rc == 0)
79                         repbody->valid |= OBD_MD_FLMDSCAPA;
80         }
81
82         RETURN(rc);
83 }
84
85 /**
86  * Get version of object by fid.
87  *
88  * Return real version or ENOENT_VERSION if object doesn't exist
89  */
90 static void mdt_obj_version_get(struct mdt_thread_info *info,
91                                 struct mdt_object *o, __u64 *version)
92 {
93         LASSERT(o);
94         LASSERT(mdt_object_exists(o) >= 0);
95         if (mdt_object_exists(o) > 0 && !mdt_object_obf(o))
96                 *version = dt_version_get(info->mti_env, mdt_obj2dt(o));
97         else
98                 *version = ENOENT_VERSION;
99         CDEBUG(D_INODE, "FID "DFID" version is "LPX64"\n",
100                PFID(mdt_object_fid(o)), *version);
101 }
102
103 /**
104  * Check version is correct.
105  *
106  * Should be called only during replay.
107  */
108 static int mdt_version_check(struct ptlrpc_request *req,
109                              __u64 version, int idx)
110 {
111         __u64 *pre_ver = lustre_msg_get_versions(req->rq_reqmsg);
112         ENTRY;
113
114         if (!exp_connect_vbr(req->rq_export))
115                 RETURN(0);
116
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);
126                 RETURN(-EOVERFLOW);
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);
133                 RETURN(-EOVERFLOW);
134         }
135         RETURN(0);
136 }
137
138 /**
139  * Save pre-versions in reply.
140  */
141 static void mdt_version_save(struct ptlrpc_request *req, __u64 version,
142                              int idx)
143 {
144         __u64 *reply_ver;
145
146         if (!exp_connect_vbr(req->rq_export))
147                 return;
148
149         LASSERT(!req_is_replay(req));
150         LASSERT(req->rq_repmsg != NULL);
151         reply_ver = lustre_msg_get_versions(req->rq_repmsg);
152         if (reply_ver)
153                 reply_ver[idx] = version;
154 }
155
156 /**
157  * Save enoent version, it is needed when it is obvious that object doesn't
158  * exist, e.g. child during create.
159  */
160 static void mdt_enoent_version_save(struct mdt_thread_info *info, int idx)
161 {
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);
166         }
167 }
168
169 /**
170  * Get version from disk and save in reply buffer.
171  *
172  * Versions are saved in reply only during normal operations not replays.
173  */
174 void mdt_version_get_save(struct mdt_thread_info *info,
175                           struct mdt_object *mto, int idx)
176 {
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);
181         }
182 }
183
184 /**
185  * Get version from disk and check it, no save in reply.
186  */
187 int mdt_version_get_check(struct mdt_thread_info *info,
188                           struct mdt_object *mto, int idx)
189 {
190         /* only check versions during replay */
191         if (!req_is_replay(mdt_info_req(info)))
192                 return 0;
193
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);
196 }
197
198 /**
199  * Get version from disk and check if recovery or just save.
200  */
201 int mdt_version_get_check_save(struct mdt_thread_info *info,
202                                struct mdt_object *mto, int idx)
203 {
204         int rc = 0;
205
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],
209                                        idx);
210         else
211                 mdt_version_save(mdt_info_req(info), info->mti_ver[idx], idx);
212         return rc;
213 }
214
215 /**
216  * Lookup with version checking.
217  *
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.
220  */
221 int mdt_lookup_version_check(struct mdt_thread_info *info,
222                              struct mdt_object *p, struct lu_name *lname,
223                              struct lu_fid *fid, int idx)
224 {
225         int rc, vbrc;
226
227         rc = mdo_lookup(info->mti_env, mdt_object_child(p), lname, fid,
228                         &info->mti_spec);
229         /* Check version only during replay */
230         if (!req_is_replay(mdt_info_req(info)))
231                 return rc;
232
233         info->mti_ver[idx] = ENOENT_VERSION;
234         if (rc == 0) {
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);
240                 }
241         }
242         vbrc = mdt_version_check(mdt_info_req(info), info->mti_ver[idx], idx);
243         return vbrc ? vbrc : rc;
244
245 }
246
247 /*
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
253  * check.
254  */
255 static int mdt_md_create(struct mdt_thread_info *info)
256 {
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;
264         struct lu_name          *lname;
265         int rc;
266         ENTRY;
267
268         DEBUG_REQ(D_INODE, mdt_info_req(info), "Create  (%s->"DFID") in "DFID,
269                   rr->rr_name, PFID(rr->rr_fid2), PFID(rr->rr_fid1));
270
271         repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
272
273         lh = &info->mti_lh[MDT_LH_PARENT];
274         mdt_lock_pdo_init(lh, LCK_PW, rr->rr_name, rr->rr_namelen);
275
276         parent = mdt_object_find_lock(info, rr->rr_fid1, lh,
277                                       MDS_INODELOCK_UPDATE);
278         if (IS_ERR(parent))
279                 RETURN(PTR_ERR(parent));
280
281         if (mdt_object_obf(parent))
282                 GOTO(out_put_parent, rc = -EPERM);
283
284         rc = mdt_version_get_check_save(info, parent, 0);
285         if (rc)
286                 GOTO(out_put_parent, rc);
287
288         /*
289          * Check child name version during replay.
290          * During create replay a file may exist with same name.
291          */
292         lname = mdt_name(info->mti_env, (char *)rr->rr_name, rr->rr_namelen);
293         rc = mdt_lookup_version_check(info, parent, lname,
294                                       &info->mti_tmp_fid1, 1);
295         if (rc == 0)
296                 GOTO(out_put_parent, rc = -EEXIST);
297
298         /* -ENOENT is expected here */
299         if (rc != -ENOENT)
300                 GOTO(out_put_parent, rc);
301
302         /* save version of file name for replay, it must be ENOENT here */
303         mdt_enoent_version_save(info, 1);
304
305         child = mdt_object_new(info->mti_env, mdt, rr->rr_fid2);
306         if (likely(!IS_ERR(child))) {
307                 struct md_object *next = mdt_object_child(parent);
308
309                 ma->ma_need = MA_INODE;
310                 ma->ma_valid = 0;
311                 /* capa for cross-ref will be stored here */
312                 ma->ma_capa = req_capsule_server_get(info->mti_pill,
313                                                      &RMF_CAPA1);
314                 LASSERT(ma->ma_capa);
315
316                 mdt_fail_write(info->mti_env, info->mti_mdt->mdt_bottom,
317                                OBD_FAIL_MDS_REINT_CREATE_WRITE);
318
319                 /* Version of child will be updated on disk. */
320                 info->mti_mos = child;
321                 rc = mdt_version_get_check_save(info, child, 2);
322                 if (rc)
323                         GOTO(out_put_child, rc);
324
325                 /* Let lower layer know current lock mode. */
326                 info->mti_spec.sp_cr_mode =
327                         mdt_dlm_mode2mdl_mode(lh->mlh_pdo_mode);
328
329                 /*
330                  * Do not perform lookup sanity check. We know that name does
331                  * not exist.
332                  */
333                 info->mti_spec.sp_cr_lookup = 0;
334                 info->mti_spec.sp_feat = &dt_directory_features;
335
336                 rc = mdo_create(info->mti_env, next, lname,
337                                 mdt_object_child(child),
338                                 &info->mti_spec, ma);
339                 if (rc == 0)
340                         rc = mdt_attr_get_complex(info, child, ma);
341
342                 if (rc == 0) {
343                         /* Return fid & attr to client. */
344                         if (ma->ma_valid & MA_INODE)
345                                 mdt_pack_attr2body(info, repbody, &ma->ma_attr,
346                                                    mdt_object_fid(child));
347                 }
348 out_put_child:
349                 mdt_object_put(info->mti_env, child);
350         } else {
351                 rc = PTR_ERR(child);
352         }
353         mdt_create_pack_capa(info, rc, child, repbody);
354 out_put_parent:
355         mdt_object_unlock_put(info, parent, lh, rc);
356         RETURN(rc);
357 }
358
359 int mdt_attr_set(struct mdt_thread_info *info, struct mdt_object *mo,
360                  struct md_attr *ma, int flags)
361 {
362         struct mdt_lock_handle  *lh;
363         int do_vbr = ma->ma_attr.la_valid & (LA_MODE|LA_UID|LA_GID|LA_FLAGS);
364         __u64 lockpart = MDS_INODELOCK_UPDATE;
365         int rc;
366         ENTRY;
367
368         /* attr shouldn't be set on remote object */
369         LASSERT(mdt_object_exists(mo) >= 0);
370
371         lh = &info->mti_lh[MDT_LH_PARENT];
372         mdt_lock_reg_init(lh, LCK_PW);
373
374         if (ma->ma_attr.la_valid & (LA_MODE|LA_UID|LA_GID))
375                 lockpart |= MDS_INODELOCK_LOOKUP;
376
377         rc = mdt_object_lock(info, mo, lh, lockpart, MDT_LOCAL_LOCK);
378         if (rc != 0)
379                 RETURN(rc);
380
381         if (mdt_object_exists(mo) == 0)
382                 GOTO(out_unlock, rc = -ENOENT);
383
384         /* all attrs are packed into mti_attr in unpack_setattr */
385         mdt_fail_write(info->mti_env, info->mti_mdt->mdt_bottom,
386                        OBD_FAIL_MDS_REINT_SETATTR_WRITE);
387
388         /* This is only for set ctime when rename's source is on remote MDS. */
389         if (unlikely(ma->ma_attr.la_valid == LA_CTIME))
390                 ma->ma_attr_flags |= MDS_VTX_BYPASS;
391
392         /* VBR: update version if attr changed are important for recovery */
393         if (do_vbr) {
394                 /* update on-disk version of changed object */
395                 info->mti_mos = mo;
396                 rc = mdt_version_get_check_save(info, mo, 0);
397                 if (rc)
398                         GOTO(out_unlock, rc);
399         }
400
401         /* all attrs are packed into mti_attr in unpack_setattr */
402         rc = mo_attr_set(info->mti_env, mdt_object_child(mo), ma);
403         if (rc != 0)
404                 GOTO(out_unlock, rc);
405
406         EXIT;
407 out_unlock:
408         mdt_object_unlock(info, mo, lh, rc);
409         return rc;
410 }
411
412 /**
413  * Check HSM flags and add HS_DIRTY flag if relevant.
414  *
415  * A file could be set dirty only if it has a copy in the backend (HS_EXISTS)
416  * and is not RELEASED.
417  */
418 int mdt_add_dirty_flag(struct mdt_thread_info *info, struct mdt_object *mo,
419                         struct md_attr *ma)
420 {
421         int rc;
422         ENTRY;
423
424         /* If the file was modified, add the dirty flag */
425         ma->ma_need = MA_HSM;
426         rc = mdt_attr_get_complex(info, mo, ma);
427         if (rc) {
428                 CERROR("file attribute read error for "DFID": %d.\n",
429                         PFID(lu_object_fid(&mo->mot_obj.mo_lu)), rc);
430                 RETURN(rc);
431         }
432
433         /* If an up2date copy exists in the backend, add dirty flag */
434         if ((ma->ma_valid & MA_HSM) && (ma->ma_hsm.mh_flags & HS_EXISTS)
435             && !(ma->ma_hsm.mh_flags & (HS_DIRTY|HS_RELEASED))) {
436
437                 ma->ma_hsm.mh_flags |= HS_DIRTY;
438                 rc = mdt_hsm_attr_set(info, mo, &ma->ma_hsm);
439                 if (rc) {
440                         CERROR("file attribute change error for "DFID": %d\n",
441                                 PFID(lu_object_fid(&mo->mot_obj.mo_lu)), rc);
442                         RETURN(rc);
443                 }
444         }
445
446         RETURN(rc);
447 }
448
449 static int mdt_reint_setattr(struct mdt_thread_info *info,
450                              struct mdt_lock_handle *lhc)
451 {
452         struct md_attr          *ma = &info->mti_attr;
453         struct mdt_reint_record *rr = &info->mti_rr;
454         struct ptlrpc_request   *req = mdt_info_req(info);
455         struct mdt_export_data  *med = &req->rq_export->exp_mdt_data;
456         struct mdt_file_data    *mfd;
457         struct mdt_object       *mo;
458         struct mdt_body         *repbody;
459         int                      som_au, rc, rc2;
460         ENTRY;
461
462         DEBUG_REQ(D_INODE, req, "setattr "DFID" %x", PFID(rr->rr_fid1),
463                   (unsigned int)ma->ma_attr.la_valid);
464
465         if (info->mti_dlm_req)
466                 ldlm_request_cancel(req, info->mti_dlm_req, 0);
467
468         repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
469         mo = mdt_object_find(info->mti_env, info->mti_mdt, rr->rr_fid1);
470         if (IS_ERR(mo))
471                 GOTO(out, rc = PTR_ERR(mo));
472
473         if (mdt_object_obf(mo))
474                 GOTO(out_put, rc = -EPERM);
475
476         /* start a log jounal handle if needed */
477         if (!(mdt_conn_flags(info) & OBD_CONNECT_SOM)) {
478                 if ((ma->ma_attr.la_valid & LA_SIZE) ||
479                     (rr->rr_flags & MRF_OPEN_TRUNC)) {
480                         /* Check write access for the O_TRUNC case */
481                         if (mdt_write_read(mo) < 0)
482                                 GOTO(out_put, rc = -ETXTBSY);
483                 }
484         } else if (info->mti_ioepoch &&
485                    (info->mti_ioepoch->flags & MF_EPOCH_OPEN)) {
486                 /* Truncate case. IOEpoch is opened. */
487                 rc = mdt_write_get(mo);
488                 if (rc)
489                         GOTO(out_put, rc);
490
491                 mfd = mdt_mfd_new();
492                 if (mfd == NULL) {
493                         mdt_write_put(mo);
494                         GOTO(out_put, rc = -ENOMEM);
495                 }
496
497                 mdt_ioepoch_open(info, mo, 0);
498                 repbody->ioepoch = mo->mot_ioepoch;
499
500                 mdt_object_get(info->mti_env, mo);
501                 mdt_mfd_set_mode(mfd, MDS_FMODE_TRUNC);
502                 mfd->mfd_object = mo;
503                 mfd->mfd_xid = req->rq_xid;
504
505                 spin_lock(&med->med_open_lock);
506                 cfs_list_add(&mfd->mfd_list, &med->med_open_head);
507                 spin_unlock(&med->med_open_lock);
508                 repbody->handle.cookie = mfd->mfd_handle.h_cookie;
509         }
510
511         som_au = info->mti_ioepoch && info->mti_ioepoch->flags & MF_SOM_CHANGE;
512         if (som_au) {
513                 /* SOM Attribute update case. Find the proper mfd and update
514                  * SOM attributes on the proper object. */
515                 LASSERT(mdt_conn_flags(info) & OBD_CONNECT_SOM);
516                 LASSERT(info->mti_ioepoch);
517
518                 spin_lock(&med->med_open_lock);
519                 mfd = mdt_handle2mfd(info, &info->mti_ioepoch->handle);
520                 if (mfd == NULL) {
521                         spin_unlock(&med->med_open_lock);
522                         CDEBUG(D_INODE, "no handle for file close: "
523                                "fid = "DFID": cookie = "LPX64"\n",
524                                PFID(info->mti_rr.rr_fid1),
525                                info->mti_ioepoch->handle.cookie);
526                         GOTO(out_put, rc = -ESTALE);
527                 }
528                 LASSERT(mfd->mfd_mode == MDS_FMODE_SOM);
529                 LASSERT(!(info->mti_ioepoch->flags & MF_EPOCH_CLOSE));
530
531                 class_handle_unhash(&mfd->mfd_handle);
532                 cfs_list_del_init(&mfd->mfd_list);
533                 spin_unlock(&med->med_open_lock);
534
535                 mdt_mfd_close(info, mfd);
536         } else if ((ma->ma_valid & MA_INODE) && ma->ma_attr.la_valid) {
537                 LASSERT((ma->ma_valid & MA_LOV) == 0);
538                 rc = mdt_attr_set(info, mo, ma, rr->rr_flags);
539                 if (rc)
540                         GOTO(out_put, rc);
541         } else if ((ma->ma_valid & MA_LOV) && (ma->ma_valid & MA_INODE)) {
542                 struct lu_buf *buf  = &info->mti_buf;
543                 LASSERT(ma->ma_attr.la_valid == 0);
544                 buf->lb_buf = ma->ma_lmm;
545                 buf->lb_len = ma->ma_lmm_size;
546                 rc = mo_xattr_set(info->mti_env, mdt_object_child(mo),
547                                   buf, XATTR_NAME_LOV, 0);
548                 if (rc)
549                         GOTO(out_put, rc);
550         } else
551                 LBUG();
552
553         /* If file data is modified, add the dirty flag */
554         if (ma->ma_attr_flags & MDS_DATA_MODIFIED)
555                 rc = mdt_add_dirty_flag(info, mo, ma);
556
557         ma->ma_need = MA_INODE;
558         ma->ma_valid = 0;
559         rc = mdt_attr_get_complex(info, mo, ma);
560         if (rc != 0)
561                 GOTO(out_put, rc);
562
563         mdt_pack_attr2body(info, repbody, &ma->ma_attr, mdt_object_fid(mo));
564
565         if (info->mti_mdt->mdt_opts.mo_oss_capa &&
566             info->mti_exp->exp_connect_flags & OBD_CONNECT_OSS_CAPA &&
567             S_ISREG(lu_object_attr(&mo->mot_obj.mo_lu)) &&
568             (ma->ma_attr.la_valid & LA_SIZE) && !som_au) {
569                 struct lustre_capa *capa;
570
571                 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA2);
572                 LASSERT(capa);
573                 capa->lc_opc = CAPA_OPC_OSS_DEFAULT | CAPA_OPC_OSS_TRUNC;
574                 rc = mo_capa_get(info->mti_env, mdt_object_child(mo), capa, 0);
575                 if (rc)
576                         GOTO(out_put, rc);
577                 repbody->valid |= OBD_MD_FLOSSCAPA;
578         }
579
580         EXIT;
581 out_put:
582         mdt_object_put(info->mti_env, mo);
583 out:
584         if (rc == 0)
585                 mdt_counter_incr(req, LPROC_MDT_SETATTR);
586
587         mdt_client_compatibility(info);
588         rc2 = mdt_fix_reply(info);
589         if (rc == 0)
590                 rc = rc2;
591         return rc;
592 }
593
594 static int mdt_reint_create(struct mdt_thread_info *info,
595                             struct mdt_lock_handle *lhc)
596 {
597         struct ptlrpc_request   *req = mdt_info_req(info);
598         int                     rc;
599         ENTRY;
600
601         if (OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_CREATE))
602                 RETURN(err_serious(-ESTALE));
603
604         if (info->mti_dlm_req)
605                 ldlm_request_cancel(mdt_info_req(info), info->mti_dlm_req, 0);
606
607         LASSERT(info->mti_rr.rr_namelen > 0);
608         switch (info->mti_attr.ma_attr.la_mode & S_IFMT) {
609         case S_IFDIR:
610                 mdt_counter_incr(req, LPROC_MDT_MKDIR);
611                 break;
612         case S_IFREG:
613         case S_IFLNK:
614         case S_IFCHR:
615         case S_IFBLK:
616         case S_IFIFO:
617         case S_IFSOCK:
618                 /* Special file should stay on the same node as parent. */
619                 mdt_counter_incr(req, LPROC_MDT_MKNOD);
620                 break;
621         default:
622                 CERROR("%s: Unsupported mode %o\n",
623                        mdt2obd_dev(info->mti_mdt)->obd_name,
624                        info->mti_attr.ma_attr.la_mode);
625                 RETURN(err_serious(-EOPNOTSUPP));
626         }
627
628         rc = mdt_md_create(info);
629         RETURN(rc);
630 }
631
632 /*
633  * VBR: save parent version in reply and child version getting by its name.
634  * Version of child is getting and checking during its lookup. If
635  */
636 static int mdt_reint_unlink(struct mdt_thread_info *info,
637                             struct mdt_lock_handle *lhc)
638 {
639         struct mdt_reint_record *rr = &info->mti_rr;
640         struct ptlrpc_request   *req = mdt_info_req(info);
641         struct md_attr          *ma = &info->mti_attr;
642         struct lu_fid           *child_fid = &info->mti_tmp_fid1;
643         struct mdt_object       *mp;
644         struct mdt_object       *mc;
645         struct mdt_lock_handle  *parent_lh;
646         struct mdt_lock_handle  *child_lh;
647         struct lu_name          *lname;
648         int                      rc;
649         ENTRY;
650
651         DEBUG_REQ(D_INODE, req, "unlink "DFID"/%s", PFID(rr->rr_fid1),
652                   rr->rr_name);
653
654         if (info->mti_dlm_req)
655                 ldlm_request_cancel(req, info->mti_dlm_req, 0);
656
657         if (OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_UNLINK))
658                 RETURN(err_serious(-ENOENT));
659
660         /*
661          * step 1: lock the parent.
662          */
663         parent_lh = &info->mti_lh[MDT_LH_PARENT];
664         mdt_lock_pdo_init(parent_lh, LCK_PW, rr->rr_name,
665                           rr->rr_namelen);
666
667         mp = mdt_object_find_lock(info, rr->rr_fid1, parent_lh,
668                                   MDS_INODELOCK_UPDATE);
669         if (IS_ERR(mp))
670                 GOTO(out, rc = PTR_ERR(mp));
671
672         if (mdt_object_obf(mp))
673                 GOTO(out_unlock_parent, rc = -EPERM);
674
675         rc = mdt_version_get_check_save(info, mp, 0);
676         if (rc)
677                 GOTO(out_unlock_parent, rc);
678
679         mdt_reint_init_ma(info, ma);
680
681         /* step 2: find & lock the child */
682         lname = mdt_name(info->mti_env, (char *)rr->rr_name, rr->rr_namelen);
683         /* lookup child object along with version checking */
684         fid_zero(child_fid);
685         rc = mdt_lookup_version_check(info, mp, lname, child_fid, 1);
686         if (rc != 0)
687                  GOTO(out_unlock_parent, rc);
688
689         /* We will lock the child regardless it is local or remote. No harm. */
690         mc = mdt_object_find(info->mti_env, info->mti_mdt, child_fid);
691         if (IS_ERR(mc))
692                 GOTO(out_unlock_parent, rc = PTR_ERR(mc));
693         child_lh = &info->mti_lh[MDT_LH_CHILD];
694         mdt_lock_reg_init(child_lh, LCK_EX);
695         rc = mdt_object_lock(info, mc, child_lh, MDS_INODELOCK_FULL,
696                              MDT_CROSS_LOCK);
697         if (rc != 0) {
698                 mdt_object_put(info->mti_env, mc);
699                 GOTO(out_unlock_parent, rc);
700         }
701
702         mdt_fail_write(info->mti_env, info->mti_mdt->mdt_bottom,
703                        OBD_FAIL_MDS_REINT_UNLINK_WRITE);
704         /* save version when object is locked */
705         mdt_version_get_save(info, mc, 1);
706         /*
707          * Now we can only make sure we need MA_INODE, in mdd layer, will check
708          * whether need MA_LOV and MA_COOKIE.
709          */
710         ma->ma_need = MA_INODE;
711         ma->ma_valid = 0;
712         mdt_set_capainfo(info, 1, child_fid, BYPASS_CAPA);
713         rc = mdo_unlink(info->mti_env, mdt_object_child(mp),
714                         mdt_object_child(mc), lname, ma);
715         if (rc == 0 && !lu_object_is_dying(&mc->mot_header))
716                 rc = mdt_attr_get_complex(info, mc, ma);
717         if (rc == 0)
718                 mdt_handle_last_unlink(info, mc, ma);
719
720         if (ma->ma_valid & MA_INODE) {
721                 switch (ma->ma_attr.la_mode & S_IFMT) {
722                 case S_IFDIR:
723                         mdt_counter_incr(req, LPROC_MDT_RMDIR);
724                         break;
725                 case S_IFREG:
726                 case S_IFLNK:
727                 case S_IFCHR:
728                 case S_IFBLK:
729                 case S_IFIFO:
730                 case S_IFSOCK:
731                         mdt_counter_incr(req, LPROC_MDT_UNLINK);
732                         break;
733                 default:
734                         LASSERTF(0, "bad file type %o unlinking\n",
735                                  ma->ma_attr.la_mode);
736                 }
737         }
738
739         EXIT;
740
741         mdt_object_unlock_put(info, mc, child_lh, rc);
742 out_unlock_parent:
743         mdt_object_unlock_put(info, mp, parent_lh, rc);
744 out:
745         return rc;
746 }
747
748 /*
749  * VBR: save versions in reply: 0 - parent; 1 - child by fid; 2 - target by
750  * name.
751  */
752 static int mdt_reint_link(struct mdt_thread_info *info,
753                           struct mdt_lock_handle *lhc)
754 {
755         struct mdt_reint_record *rr = &info->mti_rr;
756         struct ptlrpc_request   *req = mdt_info_req(info);
757         struct md_attr          *ma = &info->mti_attr;
758         struct mdt_object       *ms;
759         struct mdt_object       *mp;
760         struct mdt_lock_handle  *lhs;
761         struct mdt_lock_handle  *lhp;
762         struct lu_name          *lname;
763         int rc;
764         ENTRY;
765
766         DEBUG_REQ(D_INODE, req, "link "DFID" to "DFID"/%s",
767                   PFID(rr->rr_fid1), PFID(rr->rr_fid2), rr->rr_name);
768
769         if (OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_LINK))
770                 RETURN(err_serious(-ENOENT));
771
772         if (info->mti_dlm_req)
773                 ldlm_request_cancel(req, info->mti_dlm_req, 0);
774
775         /* Invalid case so return error immediately instead of
776          * processing it */
777         if (lu_fid_eq(rr->rr_fid1, rr->rr_fid2))
778                 RETURN(-EPERM);
779
780         /* step 1: find & lock the target parent dir */
781         lhp = &info->mti_lh[MDT_LH_PARENT];
782         mdt_lock_pdo_init(lhp, LCK_PW, rr->rr_name,
783                           rr->rr_namelen);
784         mp = mdt_object_find_lock(info, rr->rr_fid2, lhp,
785                                   MDS_INODELOCK_UPDATE);
786         if (IS_ERR(mp))
787                 RETURN(PTR_ERR(mp));
788
789         if (mdt_object_obf(mp))
790                 GOTO(out_unlock_parent, rc = -EPERM);
791
792         rc = mdt_version_get_check_save(info, mp, 0);
793         if (rc)
794                 GOTO(out_unlock_parent, rc);
795
796         /* step 2: find & lock the source */
797         lhs = &info->mti_lh[MDT_LH_CHILD];
798         mdt_lock_reg_init(lhs, LCK_EX);
799
800         ms = mdt_object_find(info->mti_env, info->mti_mdt, rr->rr_fid1);
801         if (IS_ERR(ms))
802                 GOTO(out_unlock_parent, rc = PTR_ERR(ms));
803
804         rc = mdt_object_lock(info, ms, lhs, MDS_INODELOCK_UPDATE,
805                             MDT_CROSS_LOCK);
806         if (rc != 0) {
807                 mdt_object_put(info->mti_env, ms);
808                 GOTO(out_unlock_parent, rc);
809         }
810
811         /* step 3: link it */
812         mdt_fail_write(info->mti_env, info->mti_mdt->mdt_bottom,
813                        OBD_FAIL_MDS_REINT_LINK_WRITE);
814
815         info->mti_mos = ms;
816         rc = mdt_version_get_check_save(info, ms, 1);
817         if (rc)
818                 GOTO(out_unlock_child, rc);
819
820         lname = mdt_name(info->mti_env, (char *)rr->rr_name, rr->rr_namelen);
821         /** check target version by name during replay */
822         rc = mdt_lookup_version_check(info, mp, lname, &info->mti_tmp_fid1, 2);
823         if (rc != 0 && rc != -ENOENT)
824                 GOTO(out_unlock_child, rc);
825         /* save version of file name for replay, it must be ENOENT here */
826         if (!req_is_replay(mdt_info_req(info))) {
827                 info->mti_ver[2] = ENOENT_VERSION;
828                 mdt_version_save(mdt_info_req(info), info->mti_ver[2], 2);
829         }
830
831         rc = mdo_link(info->mti_env, mdt_object_child(mp),
832                       mdt_object_child(ms), lname, ma);
833
834         if (rc == 0)
835                 mdt_counter_incr(req, LPROC_MDT_LINK);
836
837         EXIT;
838 out_unlock_child:
839         mdt_object_unlock_put(info, ms, lhs, rc);
840 out_unlock_parent:
841         mdt_object_unlock_put(info, mp, lhp, rc);
842         return rc;
843 }
844 /**
845  * lock the part of the directory according to the hash of the name
846  * (lh->mlh_pdo_hash) in parallel directory lock.
847  */
848 static int mdt_pdir_hash_lock(struct mdt_thread_info *info,
849                        struct mdt_lock_handle *lh,
850                        struct mdt_object *obj, __u64 ibits)
851 {
852         struct ldlm_res_id *res_id = &info->mti_res_id;
853         struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
854         ldlm_policy_data_t *policy = &info->mti_policy;
855         int rc;
856
857         /*
858          * Finish res_id initializing by name hash marking part of
859          * directory which is taking modification.
860          */
861         LASSERT(lh->mlh_pdo_hash != 0);
862         fid_build_pdo_res_name(mdt_object_fid(obj), lh->mlh_pdo_hash, res_id);
863         memset(policy, 0, sizeof(*policy));
864         policy->l_inodebits.bits = ibits;
865         /*
866          * Use LDLM_FL_LOCAL_ONLY for this lock. We do not know yet if it is
867          * going to be sent to client. If it is - mdt_intent_policy() path will
868          * fix it up and turn FL_LOCAL flag off.
869          */
870         rc = mdt_fid_lock(ns, &lh->mlh_reg_lh, lh->mlh_reg_mode, policy,
871                           res_id, LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB,
872                           &info->mti_exp->exp_handle.h_cookie);
873         return rc;
874 }
875
876 static int mdt_rename_lock(struct mdt_thread_info *info,
877                            struct lustre_handle *lh)
878 {
879         struct ldlm_namespace   *ns = info->mti_mdt->mdt_namespace;
880         ldlm_policy_data_t      *policy = &info->mti_policy;
881         struct ldlm_res_id      *res_id = &info->mti_res_id;
882         __u64                   flags = 0;
883         int rc;
884         ENTRY;
885
886         fid_build_reg_res_name(&LUSTRE_BFL_FID, res_id);
887
888         memset(policy, 0, sizeof *policy);
889         policy->l_inodebits.bits = MDS_INODELOCK_UPDATE;
890 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 4, 53, 0)
891         /* In phase I, we will not do cross-rename, so local BFL lock would
892          * be enough
893          */
894         flags = LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB;
895         /*
896          * Current node is controller, that is mdt0, where we should
897          * take BFL lock.
898          */
899         rc = ldlm_cli_enqueue_local(ns, res_id, LDLM_IBITS, policy,
900                                     LCK_EX, &flags, ldlm_blocking_ast,
901                                     ldlm_completion_ast, NULL, NULL, 0,
902                                     LVB_T_NONE,
903                                     &info->mti_exp->exp_handle.h_cookie,
904                                     lh);
905 #else
906 #warning "Local rename lock is invalid for DNE phase II."
907 #endif
908         RETURN(rc);
909 }
910
911 static void mdt_rename_unlock(struct lustre_handle *lh)
912 {
913         ENTRY;
914         LASSERT(lustre_handle_is_used(lh));
915         ldlm_lock_decref(lh, LCK_EX);
916         EXIT;
917 }
918
919 /*
920  * This is is_subdir() variant, it is CMD if cmm forwards it to correct
921  * target. Source should not be ancestor of target dir. May be other rename
922  * checks can be moved here later.
923  */
924 static int mdt_rename_sanity(struct mdt_thread_info *info, struct lu_fid *fid)
925 {
926         struct mdt_reint_record *rr = &info->mti_rr;
927         struct lu_fid dst_fid = *rr->rr_fid2;
928         struct mdt_object *dst;
929         int rc = 0;
930         ENTRY;
931
932         do {
933                 LASSERT(fid_is_sane(&dst_fid));
934                 dst = mdt_object_find(info->mti_env, info->mti_mdt, &dst_fid);
935                 if (!IS_ERR(dst)) {
936                         rc = mdo_is_subdir(info->mti_env,
937                                            mdt_object_child(dst), fid,
938                                            &dst_fid);
939                         mdt_object_put(info->mti_env, dst);
940                         if (rc != -EREMOTE && rc < 0) {
941                                 CERROR("Failed mdo_is_subdir(), rc %d\n", rc);
942                         } else {
943                                 /* check the found fid */
944                                 if (lu_fid_eq(&dst_fid, fid))
945                                         rc = -EINVAL;
946                         }
947                 } else {
948                         rc = PTR_ERR(dst);
949                 }
950         } while (rc == -EREMOTE);
951
952         RETURN(rc);
953 }
954
955 /*
956  * VBR: rename versions in reply: 0 - src parent; 1 - tgt parent;
957  * 2 - src child; 3 - tgt child.
958  * Update on disk version of src child.
959  */
960 static int mdt_reint_rename(struct mdt_thread_info *info,
961                             struct mdt_lock_handle *lhc)
962 {
963         struct mdt_reint_record *rr = &info->mti_rr;
964         struct md_attr          *ma = &info->mti_attr;
965         struct ptlrpc_request   *req = mdt_info_req(info);
966         struct mdt_object       *msrcdir;
967         struct mdt_object       *mtgtdir;
968         struct mdt_object       *mold;
969         struct mdt_object       *mnew = NULL;
970         struct mdt_lock_handle  *lh_srcdirp;
971         struct mdt_lock_handle  *lh_tgtdirp;
972         struct mdt_lock_handle  *lh_oldp;
973         struct mdt_lock_handle  *lh_newp;
974         struct lu_fid           *old_fid = &info->mti_tmp_fid1;
975         struct lu_fid           *new_fid = &info->mti_tmp_fid2;
976         struct lustre_handle     rename_lh = { 0 };
977         struct lu_name           slname = { 0 };
978         struct lu_name          *lname;
979         int                      rc;
980         ENTRY;
981
982         if (info->mti_dlm_req)
983                 ldlm_request_cancel(req, info->mti_dlm_req, 0);
984
985         DEBUG_REQ(D_INODE, req, "rename "DFID"/%s to "DFID"/%s",
986                   PFID(rr->rr_fid1), rr->rr_name,
987                   PFID(rr->rr_fid2), rr->rr_tgt);
988
989         rc = mdt_rename_lock(info, &rename_lh);
990         if (rc) {
991                 CERROR("Can't lock FS for rename, rc %d\n", rc);
992                 RETURN(rc);
993         }
994
995         lh_newp = &info->mti_lh[MDT_LH_NEW];
996
997         /* step 1: lock the source dir. */
998         lh_srcdirp = &info->mti_lh[MDT_LH_PARENT];
999         mdt_lock_pdo_init(lh_srcdirp, LCK_PW, rr->rr_name,
1000                           rr->rr_namelen);
1001         msrcdir = mdt_object_find_lock(info, rr->rr_fid1, lh_srcdirp,
1002                                        MDS_INODELOCK_UPDATE);
1003         if (IS_ERR(msrcdir))
1004                 GOTO(out_rename_lock, rc = PTR_ERR(msrcdir));
1005
1006         if (mdt_object_obf(msrcdir))
1007                 GOTO(out_unlock_source, rc = -EPERM);
1008
1009         rc = mdt_version_get_check_save(info, msrcdir, 0);
1010         if (rc)
1011                 GOTO(out_unlock_source, rc);
1012
1013         /* step 2: find & lock the target dir. */
1014         lh_tgtdirp = &info->mti_lh[MDT_LH_CHILD];
1015         mdt_lock_pdo_init(lh_tgtdirp, LCK_PW, rr->rr_tgt,
1016                           rr->rr_tgtlen);
1017         if (lu_fid_eq(rr->rr_fid1, rr->rr_fid2)) {
1018                 mdt_object_get(info->mti_env, msrcdir);
1019                 mtgtdir = msrcdir;
1020                 if (lh_tgtdirp->mlh_pdo_hash != lh_srcdirp->mlh_pdo_hash) {
1021                          rc = mdt_pdir_hash_lock(info, lh_tgtdirp, mtgtdir,
1022                                                  MDS_INODELOCK_UPDATE);
1023                          if (rc)
1024                                  GOTO(out_unlock_source, rc);
1025                          OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_PDO_LOCK2, 10);
1026                 }
1027         } else {
1028                 mtgtdir = mdt_object_find(info->mti_env, info->mti_mdt,
1029                                           rr->rr_fid2);
1030                 if (IS_ERR(mtgtdir))
1031                         GOTO(out_unlock_source, rc = PTR_ERR(mtgtdir));
1032
1033                 if (mdt_object_obf(mtgtdir))
1034                         GOTO(out_put_target, rc = -EPERM);
1035
1036                 /* check early, the real version will be saved after locking */
1037                 rc = mdt_version_get_check(info, mtgtdir, 1);
1038                 if (rc)
1039                         GOTO(out_put_target, rc);
1040
1041                 rc = mdt_object_exists(mtgtdir);
1042                 if (rc == 0) {
1043                         GOTO(out_put_target, rc = -ESTALE);
1044                 } else if (rc > 0) {
1045                         /* we lock the target dir if it is local */
1046                         rc = mdt_object_lock(info, mtgtdir, lh_tgtdirp,
1047                                              MDS_INODELOCK_UPDATE,
1048                                              MDT_LOCAL_LOCK);
1049                         if (rc != 0)
1050                                 GOTO(out_put_target, rc);
1051                         /* get and save correct version after locking */
1052                         mdt_version_get_save(info, mtgtdir, 1);
1053                 }
1054         }
1055
1056         /* step 3: find & lock the old object. */
1057         lname = mdt_name(info->mti_env, (char *)rr->rr_name, rr->rr_namelen);
1058         mdt_name_copy(&slname, lname);
1059         fid_zero(old_fid);
1060         rc = mdt_lookup_version_check(info, msrcdir, &slname, old_fid, 2);
1061         if (rc != 0)
1062                 GOTO(out_unlock_target, rc);
1063
1064         if (lu_fid_eq(old_fid, rr->rr_fid1) || lu_fid_eq(old_fid, rr->rr_fid2))
1065                 GOTO(out_unlock_target, rc = -EINVAL);
1066
1067         mold = mdt_object_find(info->mti_env, info->mti_mdt, old_fid);
1068         if (IS_ERR(mold))
1069                 GOTO(out_unlock_target, rc = PTR_ERR(mold));
1070
1071         if (mdt_object_obf(mold)) {
1072                 mdt_object_put(info->mti_env, mold);
1073                 GOTO(out_unlock_target, rc = -EPERM);
1074         }
1075
1076         lh_oldp = &info->mti_lh[MDT_LH_OLD];
1077         mdt_lock_reg_init(lh_oldp, LCK_EX);
1078         rc = mdt_object_lock(info, mold, lh_oldp, MDS_INODELOCK_LOOKUP,
1079                              MDT_CROSS_LOCK);
1080         if (rc != 0) {
1081                 mdt_object_put(info->mti_env, mold);
1082                 GOTO(out_unlock_target, rc);
1083         }
1084
1085         info->mti_mos = mold;
1086         /* save version after locking */
1087         mdt_version_get_save(info, mold, 2);
1088         mdt_set_capainfo(info, 2, old_fid, BYPASS_CAPA);
1089
1090         /* step 4: find & lock the new object. */
1091         /* new target object may not exist now */
1092         lname = mdt_name(info->mti_env, (char *)rr->rr_tgt, rr->rr_tgtlen);
1093         /* lookup with version checking */
1094         fid_zero(new_fid);
1095         rc = mdt_lookup_version_check(info, mtgtdir, lname, new_fid, 3);
1096         if (rc == 0) {
1097                 /* the new_fid should have been filled at this moment */
1098                 if (lu_fid_eq(old_fid, new_fid))
1099                        GOTO(out_unlock_old, rc);
1100
1101                 if (lu_fid_eq(new_fid, rr->rr_fid1) ||
1102                     lu_fid_eq(new_fid, rr->rr_fid2))
1103                         GOTO(out_unlock_old, rc = -EINVAL);
1104
1105                 mdt_lock_reg_init(lh_newp, LCK_EX);
1106                 mnew = mdt_object_find(info->mti_env, info->mti_mdt, new_fid);
1107                 if (IS_ERR(mnew))
1108                         GOTO(out_unlock_old, rc = PTR_ERR(mnew));
1109
1110                 if (mdt_object_obf(mnew)) {
1111                         mdt_object_put(info->mti_env, mnew);
1112                         GOTO(out_unlock_old, rc = -EPERM);
1113                 }
1114
1115                 rc = mdt_object_lock(info, mnew, lh_newp,
1116                                      MDS_INODELOCK_FULL, MDT_CROSS_LOCK);
1117                 if (rc != 0) {
1118                         mdt_object_put(info->mti_env, mnew);
1119                         GOTO(out_unlock_old, rc);
1120                 }
1121                 /* get and save version after locking */
1122                 mdt_version_get_save(info, mnew, 3);
1123                 mdt_set_capainfo(info, 3, new_fid, BYPASS_CAPA);
1124         } else if (rc != -EREMOTE && rc != -ENOENT) {
1125                 GOTO(out_unlock_old, rc);
1126         } else {
1127                 mdt_enoent_version_save(info, 3);
1128         }
1129
1130         /* step 5: rename it */
1131         mdt_reint_init_ma(info, ma);
1132
1133         mdt_fail_write(info->mti_env, info->mti_mdt->mdt_bottom,
1134                        OBD_FAIL_MDS_REINT_RENAME_WRITE);
1135
1136
1137         /* Check if @dst is subdir of @src. */
1138         rc = mdt_rename_sanity(info, old_fid);
1139         if (rc)
1140                 GOTO(out_unlock_new, rc);
1141
1142         rc = mdo_rename(info->mti_env, mdt_object_child(msrcdir),
1143                         mdt_object_child(mtgtdir), old_fid, &slname,
1144                         (mnew ? mdt_object_child(mnew) : NULL),
1145                         lname, ma);
1146
1147         /* handle last link of tgt object */
1148         if (rc == 0) {
1149                 mdt_counter_incr(req, LPROC_MDT_RENAME);
1150                 if (mnew)
1151                         mdt_handle_last_unlink(info, mnew, ma);
1152
1153                 mdt_rename_counter_tally(info, info->mti_mdt, req,
1154                                          msrcdir, mtgtdir);
1155         }
1156
1157         EXIT;
1158 out_unlock_new:
1159         if (mnew)
1160                 mdt_object_unlock_put(info, mnew, lh_newp, rc);
1161 out_unlock_old:
1162         mdt_object_unlock_put(info, mold, lh_oldp, rc);
1163 out_unlock_target:
1164         mdt_object_unlock(info, mtgtdir, lh_tgtdirp, rc);
1165 out_put_target:
1166         mdt_object_put(info->mti_env, mtgtdir);
1167 out_unlock_source:
1168         mdt_object_unlock_put(info, msrcdir, lh_srcdirp, rc);
1169 out_rename_lock:
1170         if (lustre_handle_is_used(&rename_lh))
1171                 mdt_rename_unlock(&rename_lh);
1172         return rc;
1173 }
1174
1175 typedef int (*mdt_reinter)(struct mdt_thread_info *info,
1176                            struct mdt_lock_handle *lhc);
1177
1178 static mdt_reinter reinters[REINT_MAX] = {
1179         [REINT_SETATTR]  = mdt_reint_setattr,
1180         [REINT_CREATE]   = mdt_reint_create,
1181         [REINT_LINK]     = mdt_reint_link,
1182         [REINT_UNLINK]   = mdt_reint_unlink,
1183         [REINT_RENAME]   = mdt_reint_rename,
1184         [REINT_OPEN]     = mdt_reint_open,
1185         [REINT_SETXATTR] = mdt_reint_setxattr
1186 };
1187
1188 int mdt_reint_rec(struct mdt_thread_info *info,
1189                   struct mdt_lock_handle *lhc)
1190 {
1191         int rc;
1192         ENTRY;
1193
1194         rc = reinters[info->mti_rr.rr_opcode](info, lhc);
1195
1196         RETURN(rc);
1197 }