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