Whamcloud - gitweb
LU-3467 target: move OUT to the unified target code
[fs/lustre-release.git] / lustre / mdt / mdt_recovery.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, 2013, 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_recovery.c
37  *
38  * Lustre Metadata Target (mdt) recovery-related methods
39  *
40  * Author: Huang Hua <huanghua@clusterfs.com>
41  * Author: Pershin Mike <tappro@clusterfs.com>
42  */
43
44 #define DEBUG_SUBSYSTEM S_MDS
45
46 #include "mdt_internal.h"
47
48 struct lu_buf *mdt_buf(const struct lu_env *env, void *area, ssize_t len)
49 {
50         struct lu_buf *buf;
51         struct mdt_thread_info *mti;
52
53         mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
54         buf = &mti->mti_buf;
55         buf->lb_buf = area;
56         buf->lb_len = len;
57         return buf;
58 }
59
60 const struct lu_buf *mdt_buf_const(const struct lu_env *env,
61                                    const void *area, ssize_t len)
62 {
63         struct lu_buf *buf;
64         struct mdt_thread_info *mti;
65
66         mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
67         buf = &mti->mti_buf;
68
69         buf->lb_buf = (void *)area;
70         buf->lb_len = len;
71         return buf;
72 }
73
74 void mdt_trans_stop(const struct lu_env *env,
75                     struct mdt_device *mdt, struct thandle *th)
76 {
77         dt_trans_stop(env, mdt->mdt_bottom, th);
78 }
79
80 static int mdt_clients_data_init(const struct lu_env *env,
81                                  struct mdt_device *mdt,
82                                  unsigned long last_size)
83 {
84         struct lr_server_data  *lsd = &mdt->mdt_lut.lut_lsd;
85         struct lsd_client_data *lcd;
86         struct obd_device      *obd = mdt2obd_dev(mdt);
87         loff_t off;
88         int cl_idx;
89         int rc = 0;
90         ENTRY;
91
92         OBD_ALLOC_PTR(lcd);
93         if (!lcd)
94                 RETURN(-ENOMEM);
95
96         /* When we do a clean MDS shutdown, we save the last_transno into
97          * the header.  If we find clients with higher last_transno values
98          * then those clients may need recovery done. */
99         LASSERT(cfs_atomic_read(&obd->obd_req_replay_clients) == 0);
100         for (cl_idx = 0, off = lsd->lsd_client_start;
101              off < last_size; cl_idx++) {
102                 __u64 last_transno;
103                 struct obd_export *exp;
104                 struct mdt_thread_info *mti;
105
106                 off = lsd->lsd_client_start +
107                         cl_idx * lsd->lsd_client_size;
108
109                 rc = tgt_client_data_read(env, &mdt->mdt_lut, lcd, &off, cl_idx);
110                 if (rc) {
111                         CERROR("error reading MDS %s idx %d, off %llu: rc %d\n",
112                                LAST_RCVD, cl_idx, off, rc);
113                         rc = 0;
114                         break; /* read error shouldn't cause startup to fail */
115                 }
116
117                 if (lcd->lcd_uuid[0] == '\0') {
118                         CDEBUG(D_INFO, "skipping zeroed client at offset %d\n",
119                                cl_idx);
120                         continue;
121                 }
122
123                 last_transno = lcd_last_transno(lcd);
124
125                 /* These exports are cleaned up by mdt_obd_disconnect(), so
126                  * they need to be set up like real exports as
127                  * mdt_obd_connect() does.
128                  */
129                 CDEBUG(D_HA, "RCVRNG CLIENT uuid: %s idx: %d lr: "LPU64
130                        " srv lr: "LPU64" lx: "LPU64"\n", lcd->lcd_uuid, cl_idx,
131                        last_transno, lsd->lsd_last_transno,
132                        lcd_last_xid(lcd));
133
134                 exp = class_new_export(obd, (struct obd_uuid *)lcd->lcd_uuid);
135                 if (IS_ERR(exp)) {
136                         if (PTR_ERR(exp) == -EALREADY) {
137                                 /* export already exists, zero out this one */
138                                 CERROR("Duplicate export %s!\n", lcd->lcd_uuid);
139                                 continue;
140                         }
141                         GOTO(err_client, rc = PTR_ERR(exp));
142                 }
143
144                 mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
145                 LASSERT(mti != NULL);
146                 mti->mti_exp = exp;
147                 /* copy on-disk lcd to the export */
148                 *exp->exp_target_data.ted_lcd = *lcd;
149                 rc = tgt_client_add(env, exp, cl_idx);
150                 /* can't fail existing */
151                 LASSERTF(rc == 0, "rc = %d\n", rc);
152                 /* VBR: set export last committed version */
153                 exp->exp_last_committed = last_transno;
154                 spin_lock(&exp->exp_lock);
155                 exp->exp_connecting = 0;
156                 exp->exp_in_recovery = 0;
157                 spin_unlock(&exp->exp_lock);
158                 obd->obd_max_recoverable_clients++;
159                 class_export_put(exp);
160
161                 CDEBUG(D_OTHER, "client at idx %d has last_transno ="LPU64"\n",
162                        cl_idx, last_transno);
163                 /* protect __u64 value update */
164                 spin_lock(&mdt->mdt_lut.lut_translock);
165                 mdt->mdt_lut.lut_last_transno = max(last_transno,
166                                                 mdt->mdt_lut.lut_last_transno);
167                 spin_unlock(&mdt->mdt_lut.lut_translock);
168         }
169
170 err_client:
171         OBD_FREE_PTR(lcd);
172         RETURN(rc);
173 }
174
175 static int mdt_server_data_init(const struct lu_env *env,
176                                 struct mdt_device *mdt,
177                                 struct lustre_sb_info *lsi)
178 {
179         struct lr_server_data  *lsd = &mdt->mdt_lut.lut_lsd;
180         struct lsd_client_data *lcd = NULL;
181         struct obd_device      *obd = mdt2obd_dev(mdt);
182         struct mdt_thread_info *mti;
183         struct dt_object       *obj;
184         struct lu_attr         *la;
185         unsigned long last_rcvd_size;
186         __u32                   index;
187         __u64 mount_count;
188         int rc;
189         ENTRY;
190
191         /* ensure padding in the struct is the correct size */
192         CLASSERT(offsetof(struct lr_server_data, lsd_padding) +
193                 sizeof(lsd->lsd_padding) == LR_SERVER_SIZE);
194         CLASSERT(offsetof(struct lsd_client_data, lcd_padding) +
195                 sizeof(lcd->lcd_padding) == LR_CLIENT_SIZE);
196
197         rc = server_name2index(mdt_obd_name(mdt), &index, NULL);
198         if (rc < 0) {
199                 CERROR("%s: Can not get index from obd_name: rc = %d\n",
200                        mdt_obd_name(mdt), rc);
201                 RETURN(rc);
202         }
203
204         mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
205         LASSERT(mti != NULL);
206         la = &mti->mti_attr.ma_attr;
207
208         obj = mdt->mdt_lut.lut_last_rcvd;
209         rc = dt_attr_get(env, obj, la, BYPASS_CAPA);
210         if (rc)
211                 RETURN(rc);
212
213         last_rcvd_size = (unsigned long)la->la_size;
214
215         if (last_rcvd_size == 0) {
216                 LCONSOLE_WARN("%s: new disk, initializing\n",
217                               mdt_obd_name(mdt));
218
219                 memcpy(lsd->lsd_uuid, obd->obd_uuid.uuid,
220                        sizeof(lsd->lsd_uuid));
221                 lsd->lsd_last_transno = 0;
222                 lsd->lsd_mount_count = 0;
223                 lsd->lsd_server_size = LR_SERVER_SIZE;
224                 lsd->lsd_client_start = LR_CLIENT_START;
225                 lsd->lsd_client_size = LR_CLIENT_SIZE;
226                 lsd->lsd_feature_compat = OBD_COMPAT_MDT;
227                 lsd->lsd_feature_rocompat = OBD_ROCOMPAT_LOVOBJID;
228                 lsd->lsd_feature_incompat = OBD_INCOMPAT_MDT |
229                                             OBD_INCOMPAT_COMMON_LR |
230                                             OBD_INCOMPAT_MULTI_OI;
231                 lsd->lsd_osd_index = index;
232         } else {
233                 LCONSOLE_WARN("%s: used disk, loading\n", mdt_obd_name(mdt));
234                 rc = tgt_server_data_read(env, &mdt->mdt_lut);
235                 if (rc) {
236                         CERROR("error reading MDS %s: rc %d\n", LAST_RCVD, rc);
237                         GOTO(out, rc);
238                 }
239                 if (strcmp(lsd->lsd_uuid, obd->obd_uuid.uuid) != 0) {
240                         LCONSOLE_ERROR_MSG(0x157, "Trying to start OBD %s using"
241                                            "the wrong disk %s. Were the /dev/ "
242                                            "assignments rearranged?\n",
243                                            obd->obd_uuid.uuid, lsd->lsd_uuid);
244                         GOTO(out, rc = -EINVAL);
245                 }
246                 lsd->lsd_feature_compat |= OBD_COMPAT_MDT;
247                 lsd->lsd_feature_incompat |= OBD_INCOMPAT_MDT |
248                                                 OBD_INCOMPAT_COMMON_LR;
249                 if (lsd->lsd_osd_index != index) {
250                         LCONSOLE_ERROR_MSG(0x157, "%s: index %d in last rcvd is"
251                                            "different with the index %d in"
252                                            "config log, It might be disk"
253                                            "corruption!\n", mdt_obd_name(mdt),
254                                            lsd->lsd_osd_index, index);
255                         GOTO(out, rc = -EINVAL);
256                 }
257         }
258         mount_count = lsd->lsd_mount_count;
259
260         if (lsd->lsd_feature_incompat & ~MDT_INCOMPAT_SUPP) {
261                 CERROR("%s: unsupported incompat filesystem feature(s) %x\n",
262                        mdt_obd_name(mdt),
263                        lsd->lsd_feature_incompat & ~MDT_INCOMPAT_SUPP);
264                 GOTO(out, rc = -EINVAL);
265         }
266         if (lsd->lsd_feature_rocompat & ~MDT_ROCOMPAT_SUPP) {
267                 CERROR("%s: unsupported read-only filesystem feature(s) %x\n",
268                        mdt_obd_name(mdt),
269                        lsd->lsd_feature_rocompat & ~MDT_ROCOMPAT_SUPP);
270                 /* XXX: Do something like remount filesystem read-only */
271                 GOTO(out, rc = -EINVAL);
272         }
273         /** Interop: evict all clients at first boot with 1.8 last_rcvd */
274         if (!(lsd->lsd_feature_compat & OBD_COMPAT_20)) {
275                 if (last_rcvd_size > lsd->lsd_client_start) {
276                         LCONSOLE_WARN("Mounting %s at first time on 1.8 FS, "
277                                       "remove all clients for interop needs\n",
278                                       mdt_obd_name(mdt));
279                         rc = tgt_truncate_last_rcvd(env, &mdt->mdt_lut,
280                                                     lsd->lsd_client_start);
281                         if (rc)
282                                 GOTO(out, rc);
283                         last_rcvd_size = lsd->lsd_client_start;
284                 }
285                 /** set 2.0 flag to upgrade/downgrade between 1.8 and 2.0 */
286                 lsd->lsd_feature_compat |= OBD_COMPAT_20;
287         }
288
289         lsd->lsd_feature_incompat |= OBD_INCOMPAT_FID;
290
291         spin_lock(&mdt->mdt_lut.lut_translock);
292         mdt->mdt_lut.lut_last_transno = lsd->lsd_last_transno;
293         spin_unlock(&mdt->mdt_lut.lut_translock);
294
295         CDEBUG(D_INODE, "=======,=BEGIN DUMPING LAST_RCVD========\n");
296         CDEBUG(D_INODE, "%s: server last_transno: "LPU64"\n",
297                mdt_obd_name(mdt), mdt->mdt_lut.lut_last_transno);
298         CDEBUG(D_INODE, "%s: server mount_count: "LPU64"\n",
299                mdt_obd_name(mdt), mount_count + 1);
300         CDEBUG(D_INODE, "%s: server data size: %u\n",
301                mdt_obd_name(mdt), lsd->lsd_server_size);
302         CDEBUG(D_INODE, "%s: per-client data start: %u\n",
303                mdt_obd_name(mdt), lsd->lsd_client_start);
304         CDEBUG(D_INODE, "%s: per-client data size: %u\n",
305                mdt_obd_name(mdt), lsd->lsd_client_size);
306         CDEBUG(D_INODE, "%s: last_rcvd size: %lu\n",
307                mdt_obd_name(mdt), last_rcvd_size);
308         CDEBUG(D_INODE, "%s: last_rcvd clients: %lu\n", mdt_obd_name(mdt),
309                last_rcvd_size <= lsd->lsd_client_start ? 0 :
310                (last_rcvd_size - lsd->lsd_client_start) /
311                 lsd->lsd_client_size);
312         CDEBUG(D_INODE, "========END DUMPING LAST_RCVD========\n");
313
314         if (!lsd->lsd_server_size || !lsd->lsd_client_start ||
315             !lsd->lsd_client_size) {
316                 CERROR("Bad last_rcvd contents!\n");
317                 GOTO(out, rc = -EINVAL);
318         }
319
320         rc = mdt_clients_data_init(env, mdt, last_rcvd_size);
321         if (rc)
322                 GOTO(err_client, rc);
323
324         spin_lock(&mdt->mdt_lut.lut_translock);
325         /* obd_last_committed is used for compatibility
326          * with other lustre recovery code */
327         obd->obd_last_committed = mdt->mdt_lut.lut_last_transno;
328         spin_unlock(&mdt->mdt_lut.lut_translock);
329
330         obd->u.obt.obt_mount_count = mount_count + 1;
331         obd->u.obt.obt_instance = (__u32)obd->u.obt.obt_mount_count;
332         lsd->lsd_mount_count = obd->u.obt.obt_mount_count;
333
334         /* save it, so mount count and last_transno is current */
335         rc = tgt_server_data_update(env, &mdt->mdt_lut, 0);
336         if (rc)
337                 GOTO(err_client, rc);
338
339         RETURN(0);
340
341 err_client:
342         class_disconnect_exports(obd);
343 out:
344         return rc;
345 }
346
347 /*
348  * last_rcvd & last_committed update callbacks
349  */
350 extern struct lu_context_key mdt_thread_key;
351
352 /* add credits for last_rcvd update */
353 static int mdt_txn_start_cb(const struct lu_env *env,
354                             struct thandle *th, void *cookie)
355 {
356         struct lu_target        *tgt = cookie;
357         struct mdt_thread_info  *mti;
358         int                      rc;
359
360         /* if there is no session, then this transaction is not result of
361          * request processing but some local operation or echo client */
362         if (env->le_ses == NULL)
363                 return 0;
364
365         mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
366
367         LASSERT(tgt->lut_last_rcvd);
368         if (mti->mti_exp == NULL)
369                 return 0;
370
371         rc = dt_declare_record_write(env, tgt->lut_last_rcvd,
372                                      sizeof(struct lsd_client_data),
373                                      mti->mti_exp->exp_target_data.ted_lr_off,
374                                      th);
375         if (rc)
376                 return rc;
377
378         rc = dt_declare_record_write(env, tgt->lut_last_rcvd,
379                                      sizeof(struct lr_server_data), 0, th);
380         if (rc)
381                 return rc;
382
383         /* we probably should not set local transno to the remote object
384          * on another storage, What about VBR on remote object? XXX */
385         if (mti->mti_mos != NULL && !mdt_object_remote(mti->mti_mos))
386                 rc = dt_declare_version_set(env, mdt_obj2dt(mti->mti_mos), th);
387
388         return rc;
389 }
390
391 /* Update last_rcvd records with latests transaction data */
392 static int mdt_txn_stop_cb(const struct lu_env *env,
393                            struct thandle *txn, void *cookie)
394 {
395         struct lu_target        *tgt = cookie;
396         struct mdt_thread_info  *mti;
397         struct dt_object        *obj = NULL;
398         int                      rc;
399
400         if (env->le_ses == NULL)
401                 return 0;
402
403         mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
404         LASSERT(mti);
405         if (mti->mti_has_trans) {
406                 /* XXX: currently there are allowed cases, but the wrong cases
407                  * are also possible, so better check is needed here */
408                 CDEBUG(D_INFO, "More than one transaction "LPU64"\n",
409                        mti->mti_transno);
410                 return 0;
411         }
412
413         mti->mti_has_trans = 1;
414
415         if (mti->mti_mos != NULL &&
416             mdt_object_remote(mti->mti_mos)) {
417                 obj = mdt_obj2dt(mti->mti_mos);
418         }
419
420         rc = tgt_last_rcvd_update(env, tgt, obj, mti->mti_opdata, txn,
421                                   mdt_info_req(mti));
422         return rc;
423 }
424
425 int mdt_fs_setup(const struct lu_env *env, struct mdt_device *mdt,
426                  struct obd_device *obd,
427                  struct lustre_sb_info *lsi)
428 {
429         int rc = 0;
430         ENTRY;
431
432         if (OBD_FAIL_CHECK(OBD_FAIL_MDS_FS_SETUP))
433                 RETURN(-ENOENT);
434
435         /* prepare transactions callbacks */
436         mdt->mdt_txn_cb.dtc_txn_start = mdt_txn_start_cb;
437         mdt->mdt_txn_cb.dtc_txn_stop = mdt_txn_stop_cb;
438         mdt->mdt_txn_cb.dtc_txn_commit = NULL;
439         mdt->mdt_txn_cb.dtc_cookie = &mdt->mdt_lut;
440         mdt->mdt_txn_cb.dtc_tag = LCT_MD_THREAD;
441         CFS_INIT_LIST_HEAD(&mdt->mdt_txn_cb.dtc_linkage);
442
443         rc = mdt_server_data_init(env, mdt, lsi);
444         if (rc != 0)
445                 RETURN(rc);
446
447         dt_txn_callback_add(mdt->mdt_bottom, &mdt->mdt_txn_cb);
448
449         RETURN(rc);
450 }
451
452 void mdt_fs_cleanup(const struct lu_env *env, struct mdt_device *mdt)
453 {
454         ENTRY;
455
456         /* Remove transaction callback */
457         dt_txn_callback_del(mdt->mdt_bottom, &mdt->mdt_txn_cb);
458         if (mdt->mdt_ck_obj)
459                 lu_object_put(env, &mdt->mdt_ck_obj->do_lu);
460         mdt->mdt_ck_obj = NULL;
461         EXIT;
462 }
463
464 /* reconstruction code */
465 static void mdt_steal_ack_locks(struct ptlrpc_request *req)
466 {
467         struct ptlrpc_service_part *svcpt;
468         struct obd_export         *exp = req->rq_export;
469         cfs_list_t                *tmp;
470         struct ptlrpc_reply_state *oldrep;
471         int                        i;
472
473         /* CAVEAT EMPTOR: spinlock order */
474         spin_lock(&exp->exp_lock);
475         cfs_list_for_each (tmp, &exp->exp_outstanding_replies) {
476                 oldrep = cfs_list_entry(tmp, struct ptlrpc_reply_state,
477                                         rs_exp_list);
478
479                 if (oldrep->rs_xid != req->rq_xid)
480                         continue;
481
482                 if (oldrep->rs_opc != lustre_msg_get_opc(req->rq_reqmsg))
483                         CERROR ("Resent req xid "LPU64" has mismatched opc: "
484                                 "new %d old %d\n", req->rq_xid,
485                                 lustre_msg_get_opc(req->rq_reqmsg),
486                                 oldrep->rs_opc);
487
488                 svcpt = oldrep->rs_svcpt;
489                 spin_lock(&svcpt->scp_rep_lock);
490
491                 cfs_list_del_init (&oldrep->rs_exp_list);
492
493                 CDEBUG(D_HA, "Stealing %d locks from rs %p x"LPD64".t"LPD64
494                        " o%d NID %s\n",
495                        oldrep->rs_nlocks, oldrep,
496                        oldrep->rs_xid, oldrep->rs_transno, oldrep->rs_opc,
497                        libcfs_nid2str(exp->exp_connection->c_peer.nid));
498
499                 for (i = 0; i < oldrep->rs_nlocks; i++)
500                         ptlrpc_save_lock(req, &oldrep->rs_locks[i],
501                                          oldrep->rs_modes[i], 0);
502                 oldrep->rs_nlocks = 0;
503
504                 DEBUG_REQ(D_HA, req, "stole locks for");
505                 spin_lock(&oldrep->rs_lock);
506                 ptlrpc_schedule_difficult_reply(oldrep);
507                 spin_unlock(&oldrep->rs_lock);
508
509                 spin_unlock(&svcpt->scp_rep_lock);
510                 break;
511         }
512         spin_unlock(&exp->exp_lock);
513 }
514
515 /**
516  * VBR: restore versions
517  */
518 void mdt_vbr_reconstruct(struct ptlrpc_request *req,
519                          struct lsd_client_data *lcd)
520 {
521         __u64 pre_versions[4] = {0};
522         pre_versions[0] = lcd->lcd_pre_versions[0];
523         pre_versions[1] = lcd->lcd_pre_versions[1];
524         pre_versions[2] = lcd->lcd_pre_versions[2];
525         pre_versions[3] = lcd->lcd_pre_versions[3];
526         lustre_msg_set_versions(req->rq_repmsg, pre_versions);
527 }
528
529 void mdt_req_from_lcd(struct ptlrpc_request *req,
530                       struct lsd_client_data *lcd)
531 {
532         DEBUG_REQ(D_HA, req, "restoring transno "LPD64"/status %d",
533                   lcd->lcd_last_transno, lcd->lcd_last_result);
534
535         if (lustre_msg_get_opc(req->rq_reqmsg) == MDS_CLOSE ||
536             lustre_msg_get_opc(req->rq_repmsg) == MDS_DONE_WRITING) {
537                 req->rq_transno = lcd->lcd_last_close_transno;
538                 req->rq_status = lcd->lcd_last_close_result;
539         } else {
540                 req->rq_transno = lcd->lcd_last_transno;
541                 req->rq_status = lcd->lcd_last_result;
542                 mdt_vbr_reconstruct(req, lcd);
543         }
544         if (req->rq_status != 0)
545                 req->rq_transno = 0;
546         lustre_msg_set_transno(req->rq_repmsg, req->rq_transno);
547         lustre_msg_set_status(req->rq_repmsg, req->rq_status);
548         DEBUG_REQ(D_RPCTRACE, req, "restoring transno "LPD64"/status %d",
549                   req->rq_transno, req->rq_status);
550
551         mdt_steal_ack_locks(req);
552 }
553
554 void mdt_reconstruct_generic(struct mdt_thread_info *mti,
555                              struct mdt_lock_handle *lhc)
556 {
557         struct ptlrpc_request *req = mdt_info_req(mti);
558         struct tg_export_data *ted = &req->rq_export->exp_target_data;
559
560         return mdt_req_from_lcd(req, ted->ted_lcd);
561 }
562
563 static void mdt_reconstruct_create(struct mdt_thread_info *mti,
564                                    struct mdt_lock_handle *lhc)
565 {
566         struct ptlrpc_request  *req = mdt_info_req(mti);
567         struct obd_export *exp = req->rq_export;
568         struct tg_export_data *ted = &exp->exp_target_data;
569         struct mdt_device *mdt = mti->mti_mdt;
570         struct mdt_object *child;
571         struct mdt_body *body;
572         int rc;
573
574         mdt_req_from_lcd(req, ted->ted_lcd);
575         if (req->rq_status)
576                 return;
577
578         /* if no error, so child was created with requested fid */
579         child = mdt_object_find(mti->mti_env, mdt, mti->mti_rr.rr_fid2);
580         if (IS_ERR(child)) {
581                 rc = PTR_ERR(child);
582                 LCONSOLE_WARN("Child "DFID" lookup error %d."
583                               " Evicting client %s with export %s.\n",
584                               PFID(mdt_object_fid(child)), rc,
585                               obd_uuid2str(&exp->exp_client_uuid),
586                               obd_export_nid2str(exp));
587                 mdt_export_evict(exp);
588                 EXIT;
589                 return;
590         }
591
592         body = req_capsule_server_get(mti->mti_pill, &RMF_MDT_BODY);
593         mti->mti_attr.ma_need = MA_INODE;
594         mti->mti_attr.ma_valid = 0;
595         rc = mdt_attr_get_complex(mti, child, &mti->mti_attr);
596         if (rc == -EREMOTE) {
597                 /* object was created on remote server */
598                 if (!mdt_is_dne_client(exp))
599                         /* Return -EIO for old client */
600                         rc = -EIO;
601
602                 req->rq_status = rc;
603                 body->valid |= OBD_MD_MDS;
604         }
605         mdt_pack_attr2body(mti, body, &mti->mti_attr.ma_attr,
606                            mdt_object_fid(child));
607         mdt_object_put(mti->mti_env, child);
608 }
609
610 static void mdt_reconstruct_setattr(struct mdt_thread_info *mti,
611                                     struct mdt_lock_handle *lhc)
612 {
613         struct ptlrpc_request  *req = mdt_info_req(mti);
614         struct obd_export *exp = req->rq_export;
615         struct mdt_export_data *med = &exp->exp_mdt_data;
616         struct mdt_device *mdt = mti->mti_mdt;
617         struct mdt_object *obj;
618         struct mdt_body *body;
619
620         mdt_req_from_lcd(req, med->med_ted.ted_lcd);
621         if (req->rq_status)
622                 return;
623
624         body = req_capsule_server_get(mti->mti_pill, &RMF_MDT_BODY);
625         obj = mdt_object_find(mti->mti_env, mdt, mti->mti_rr.rr_fid1);
626         if (IS_ERR(obj)) {
627                 int rc = PTR_ERR(obj);
628                 LCONSOLE_WARN(""DFID" lookup error %d."
629                               " Evicting client %s with export %s.\n",
630                               PFID(mdt_object_fid(obj)), rc,
631                               obd_uuid2str(&exp->exp_client_uuid),
632                               obd_export_nid2str(exp));
633                 mdt_export_evict(exp);
634                 EXIT;
635                 return;
636         }
637         mti->mti_attr.ma_need = MA_INODE;
638         mti->mti_attr.ma_valid = 0;
639         mdt_attr_get_complex(mti, obj, &mti->mti_attr);
640         mdt_pack_attr2body(mti, body, &mti->mti_attr.ma_attr,
641                            mdt_object_fid(obj));
642         if (mti->mti_ioepoch && (mti->mti_ioepoch->flags & MF_EPOCH_OPEN)) {
643                 struct mdt_file_data *mfd;
644                 struct mdt_body *repbody;
645
646                 repbody = req_capsule_server_get(mti->mti_pill, &RMF_MDT_BODY);
647                 repbody->ioepoch = obj->mot_ioepoch;
648                 spin_lock(&med->med_open_lock);
649                 cfs_list_for_each_entry(mfd, &med->med_open_head, mfd_list) {
650                         if (mfd->mfd_xid == req->rq_xid)
651                                 break;
652                 }
653                 LASSERT(&mfd->mfd_list != &med->med_open_head);
654                 spin_unlock(&med->med_open_lock);
655                 repbody->handle.cookie = mfd->mfd_handle.h_cookie;
656         }
657
658         mdt_object_put(mti->mti_env, obj);
659 }
660
661 typedef void (*mdt_reconstructor)(struct mdt_thread_info *mti,
662                                   struct mdt_lock_handle *lhc);
663
664 static mdt_reconstructor reconstructors[REINT_MAX] = {
665         [REINT_SETATTR]  = mdt_reconstruct_setattr,
666         [REINT_CREATE]   = mdt_reconstruct_create,
667         [REINT_LINK]     = mdt_reconstruct_generic,
668         [REINT_UNLINK]   = mdt_reconstruct_generic,
669         [REINT_RENAME]   = mdt_reconstruct_generic,
670         [REINT_OPEN]     = mdt_reconstruct_open,
671         [REINT_SETXATTR] = mdt_reconstruct_generic
672 };
673
674 void mdt_reconstruct(struct mdt_thread_info *mti,
675                      struct mdt_lock_handle *lhc)
676 {
677         ENTRY;
678         reconstructors[mti->mti_rr.rr_opcode](mti, lhc);
679         EXIT;
680 }