4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
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
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2012, Whamcloud, Inc.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/mdt/mdt_recovery.c
38 * Lustre Metadata Target (mdt) recovery-related methods
40 * Author: Huang Hua <huanghua@clusterfs.com>
41 * Author: Pershin Mike <tappro@clusterfs.com>
45 # define EXPORT_SYMTAB
47 #define DEBUG_SUBSYSTEM S_MDS
49 #include "mdt_internal.h"
51 struct lu_buf *mdt_buf(const struct lu_env *env, void *area, ssize_t len)
54 struct mdt_thread_info *mti;
56 mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
63 const struct lu_buf *mdt_buf_const(const struct lu_env *env,
64 const void *area, ssize_t len)
67 struct mdt_thread_info *mti;
69 mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
72 buf->lb_buf = (void *)area;
77 void mdt_trans_stop(const struct lu_env *env,
78 struct mdt_device *mdt, struct thandle *th)
80 dt_trans_stop(env, mdt->mdt_bottom, th);
83 static int mdt_clients_data_init(const struct lu_env *env,
84 struct mdt_device *mdt,
85 unsigned long last_size)
87 struct lr_server_data *lsd = &mdt->mdt_lut.lut_lsd;
88 struct lsd_client_data *lcd;
89 struct obd_device *obd = mdt2obd_dev(mdt);
99 /* When we do a clean MDS shutdown, we save the last_transno into
100 * the header. If we find clients with higher last_transno values
101 * then those clients may need recovery done. */
102 LASSERT(cfs_atomic_read(&obd->obd_req_replay_clients) == 0);
103 for (cl_idx = 0, off = lsd->lsd_client_start;
104 off < last_size; cl_idx++) {
106 struct obd_export *exp;
107 struct mdt_thread_info *mti;
109 off = lsd->lsd_client_start +
110 cl_idx * lsd->lsd_client_size;
112 rc = lut_client_data_read(env, &mdt->mdt_lut, lcd, &off, cl_idx);
114 CERROR("error reading MDS %s idx %d, off %llu: rc %d\n",
115 LAST_RCVD, cl_idx, off, rc);
117 break; /* read error shouldn't cause startup to fail */
120 if (lcd->lcd_uuid[0] == '\0') {
121 CDEBUG(D_INFO, "skipping zeroed client at offset %d\n",
126 last_transno = lcd_last_transno(lcd);
128 /* These exports are cleaned up by mdt_obd_disconnect(), so
129 * they need to be set up like real exports as
130 * mdt_obd_connect() does.
132 CDEBUG(D_HA, "RCVRNG CLIENT uuid: %s idx: %d lr: "LPU64
133 " srv lr: "LPU64" lx: "LPU64"\n", lcd->lcd_uuid, cl_idx,
134 last_transno, lsd->lsd_last_transno,
137 exp = class_new_export(obd, (struct obd_uuid *)lcd->lcd_uuid);
139 if (PTR_ERR(exp) == -EALREADY) {
140 /* export already exists, zero out this one */
141 CERROR("Duplicate export %s!\n", lcd->lcd_uuid);
144 GOTO(err_client, rc = PTR_ERR(exp));
147 mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
148 LASSERT(mti != NULL);
150 /* copy on-disk lcd to the export */
151 *exp->exp_target_data.ted_lcd = *lcd;
152 rc = lut_client_add(env, exp, cl_idx);
153 /* can't fail existing */
154 LASSERTF(rc == 0, "rc = %d\n", rc);
155 /* VBR: set export last committed version */
156 exp->exp_last_committed = last_transno;
157 cfs_spin_lock(&exp->exp_lock);
158 exp->exp_connecting = 0;
159 exp->exp_in_recovery = 0;
160 cfs_spin_unlock(&exp->exp_lock);
161 obd->obd_max_recoverable_clients++;
162 class_export_put(exp);
164 CDEBUG(D_OTHER, "client at idx %d has last_transno="LPU64"\n",
165 cl_idx, last_transno);
166 /* protect __u64 value update */
167 cfs_spin_lock(&mdt->mdt_lut.lut_translock);
168 mdt->mdt_lut.lut_last_transno = max(last_transno,
169 mdt->mdt_lut.lut_last_transno);
170 cfs_spin_unlock(&mdt->mdt_lut.lut_translock);
178 static int mdt_server_data_init(const struct lu_env *env,
179 struct mdt_device *mdt,
180 struct lustre_sb_info *lsi)
182 struct lr_server_data *lsd = &mdt->mdt_lut.lut_lsd;
183 struct lsd_client_data *lcd = NULL;
184 struct obd_device *obd = mdt2obd_dev(mdt);
185 struct mdt_thread_info *mti;
186 struct dt_object *obj;
188 unsigned long last_rcvd_size;
193 /* ensure padding in the struct is the correct size */
194 CLASSERT(offsetof(struct lr_server_data, lsd_padding) +
195 sizeof(lsd->lsd_padding) == LR_SERVER_SIZE);
196 CLASSERT(offsetof(struct lsd_client_data, lcd_padding) +
197 sizeof(lcd->lcd_padding) == LR_CLIENT_SIZE);
199 mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
200 LASSERT(mti != NULL);
201 la = &mti->mti_attr.ma_attr;
203 obj = mdt->mdt_lut.lut_last_rcvd;
204 rc = dt_attr_get(env, obj, la, BYPASS_CAPA);
208 last_rcvd_size = (unsigned long)la->la_size;
210 if (last_rcvd_size == 0) {
211 LCONSOLE_WARN("%s: new disk, initializing\n", obd->obd_name);
213 memcpy(lsd->lsd_uuid, obd->obd_uuid.uuid,
214 sizeof(lsd->lsd_uuid));
215 lsd->lsd_last_transno = 0;
216 lsd->lsd_mount_count = 0;
217 lsd->lsd_server_size = LR_SERVER_SIZE;
218 lsd->lsd_client_start = LR_CLIENT_START;
219 lsd->lsd_client_size = LR_CLIENT_SIZE;
220 lsd->lsd_feature_compat = OBD_COMPAT_MDT;
221 lsd->lsd_feature_rocompat = OBD_ROCOMPAT_LOVOBJID;
222 lsd->lsd_feature_incompat = OBD_INCOMPAT_MDT |
223 OBD_INCOMPAT_COMMON_LR |
224 OBD_INCOMPAT_MULTI_OI;
226 LCONSOLE_WARN("%s: used disk, loading\n", obd->obd_name);
227 rc = lut_server_data_read(env, &mdt->mdt_lut);
229 CERROR("error reading MDS %s: rc %d\n", LAST_RCVD, rc);
232 if (strcmp(lsd->lsd_uuid, obd->obd_uuid.uuid) != 0) {
233 LCONSOLE_ERROR_MSG(0x157, "Trying to start OBD %s using"
234 "the wrong disk %s. Were the /dev/ "
235 "assignments rearranged?\n",
236 obd->obd_uuid.uuid, lsd->lsd_uuid);
237 GOTO(out, rc = -EINVAL);
239 lsd->lsd_feature_compat |= OBD_COMPAT_MDT;
240 lsd->lsd_feature_incompat |= OBD_INCOMPAT_MDT |
241 OBD_INCOMPAT_COMMON_LR;
243 mount_count = lsd->lsd_mount_count;
245 if (lsd->lsd_feature_incompat & ~MDT_INCOMPAT_SUPP) {
246 CERROR("%s: unsupported incompat filesystem feature(s) %x\n",
248 lsd->lsd_feature_incompat & ~MDT_INCOMPAT_SUPP);
249 GOTO(out, rc = -EINVAL);
251 if (lsd->lsd_feature_rocompat & ~MDT_ROCOMPAT_SUPP) {
252 CERROR("%s: unsupported read-only filesystem feature(s) %x\n",
254 lsd->lsd_feature_rocompat & ~MDT_ROCOMPAT_SUPP);
255 /* XXX: Do something like remount filesystem read-only */
256 GOTO(out, rc = -EINVAL);
258 /** Interop: evict all clients at first boot with 1.8 last_rcvd */
259 if (!(lsd->lsd_feature_compat & OBD_COMPAT_20)) {
260 if (last_rcvd_size > lsd->lsd_client_start) {
261 LCONSOLE_WARN("Mounting %s at first time on 1.8 FS, "
262 "remove all clients for interop needs\n",
264 rc = lut_truncate_last_rcvd(env, &mdt->mdt_lut,
265 lsd->lsd_client_start);
268 last_rcvd_size = lsd->lsd_client_start;
270 /** set 2.0 flag to upgrade/downgrade between 1.8 and 2.0 */
271 lsd->lsd_feature_compat |= OBD_COMPAT_20;
274 if (lsi->lsi_ldd->ldd_flags & LDD_F_IAM_DIR)
275 lsd->lsd_feature_incompat |= OBD_INCOMPAT_IAM_DIR;
277 lsd->lsd_feature_incompat |= OBD_INCOMPAT_FID;
279 cfs_spin_lock(&mdt->mdt_lut.lut_translock);
280 mdt->mdt_lut.lut_last_transno = lsd->lsd_last_transno;
281 cfs_spin_unlock(&mdt->mdt_lut.lut_translock);
283 CDEBUG(D_INODE, "========BEGIN DUMPING LAST_RCVD========\n");
284 CDEBUG(D_INODE, "%s: server last_transno: "LPU64"\n",
285 obd->obd_name, mdt->mdt_lut.lut_last_transno);
286 CDEBUG(D_INODE, "%s: server mount_count: "LPU64"\n",
287 obd->obd_name, mount_count + 1);
288 CDEBUG(D_INODE, "%s: server data size: %u\n",
289 obd->obd_name, lsd->lsd_server_size);
290 CDEBUG(D_INODE, "%s: per-client data start: %u\n",
291 obd->obd_name, lsd->lsd_client_start);
292 CDEBUG(D_INODE, "%s: per-client data size: %u\n",
293 obd->obd_name, lsd->lsd_client_size);
294 CDEBUG(D_INODE, "%s: last_rcvd size: %lu\n",
295 obd->obd_name, last_rcvd_size);
296 CDEBUG(D_INODE, "%s: last_rcvd clients: %lu\n", obd->obd_name,
297 last_rcvd_size <= lsd->lsd_client_start ? 0 :
298 (last_rcvd_size - lsd->lsd_client_start) /
299 lsd->lsd_client_size);
300 CDEBUG(D_INODE, "========END DUMPING LAST_RCVD========\n");
302 if (!lsd->lsd_server_size || !lsd->lsd_client_start ||
303 !lsd->lsd_client_size) {
304 CERROR("Bad last_rcvd contents!\n");
305 GOTO(out, rc = -EINVAL);
308 rc = mdt_clients_data_init(env, mdt, last_rcvd_size);
310 GOTO(err_client, rc);
312 cfs_spin_lock(&mdt->mdt_lut.lut_translock);
313 /* obd_last_committed is used for compatibility
314 * with other lustre recovery code */
315 obd->obd_last_committed = mdt->mdt_lut.lut_last_transno;
316 cfs_spin_unlock(&mdt->mdt_lut.lut_translock);
318 obd->u.obt.obt_mount_count = mount_count + 1;
319 obd->u.obt.obt_instance = (__u32)obd->u.obt.obt_mount_count;
320 lsd->lsd_mount_count = obd->u.obt.obt_mount_count;
322 /* save it, so mount count and last_transno is current */
323 rc = lut_server_data_update(env, &mdt->mdt_lut, 0);
325 GOTO(err_client, rc);
330 class_disconnect_exports(obd);
336 * last_rcvd & last_committed update callbacks
338 static int mdt_last_rcvd_update(struct mdt_thread_info *mti,
341 struct mdt_device *mdt = mti->mti_mdt;
342 struct ptlrpc_request *req = mdt_info_req(mti);
343 struct tg_export_data *ted;
344 struct lsd_client_data *lcd;
347 __s32 rc = th->th_result;
351 LASSERT(req->rq_export);
353 ted = &req->rq_export->exp_target_data;
356 cfs_mutex_lock(&ted->ted_lcd_lock);
358 /* if the export has already been disconnected, we have no last_rcvd slot,
359 * update server data with latest transno then */
361 cfs_mutex_unlock(&ted->ted_lcd_lock);
362 CWARN("commit transaction for disconnected client %s: rc %d\n",
363 req->rq_export->exp_client_uuid.uuid, rc);
364 err = lut_server_data_write(mti->mti_env, &mdt->mdt_lut, th);
368 off = ted->ted_lr_off;
369 LASSERT(ergo(mti->mti_transno == 0, rc != 0));
370 if (lustre_msg_get_opc(req->rq_reqmsg) == MDS_CLOSE ||
371 lustre_msg_get_opc(req->rq_reqmsg) == MDS_DONE_WRITING) {
372 if (mti->mti_transno != 0) {
373 if (lcd->lcd_last_close_transno > mti->mti_transno) {
374 CERROR("Trying to overwrite bigger transno:"
375 "on-disk: "LPU64", new: "LPU64" "
376 "replay: %d. see LU-617.\n",
377 lcd->lcd_last_close_transno,
378 mti->mti_transno, req_is_replay(req));
379 if (req_is_replay(req)) {
380 cfs_spin_lock(&req->rq_export->exp_lock);
381 req->rq_export->exp_vbr_failed = 1;
382 cfs_spin_unlock(&req->rq_export->exp_lock);
384 cfs_mutex_unlock(&ted->ted_lcd_lock);
385 RETURN(req_is_replay(req) ? -EOVERFLOW : 0);
387 lcd->lcd_last_close_transno = mti->mti_transno;
389 lcd->lcd_last_close_xid = req->rq_xid;
390 lcd->lcd_last_close_result = rc;
392 /* VBR: save versions in last_rcvd for reconstruct. */
393 __u64 *pre_versions = lustre_msg_get_versions(req->rq_repmsg);
395 lcd->lcd_pre_versions[0] = pre_versions[0];
396 lcd->lcd_pre_versions[1] = pre_versions[1];
397 lcd->lcd_pre_versions[2] = pre_versions[2];
398 lcd->lcd_pre_versions[3] = pre_versions[3];
400 if (mti->mti_transno != 0) {
401 if (lcd->lcd_last_transno > mti->mti_transno) {
402 CERROR("Trying to overwrite bigger transno:"
403 "on-disk: "LPU64", new: "LPU64" "
404 "replay: %d. see LU-617.\n",
405 lcd->lcd_last_transno,
406 mti->mti_transno, req_is_replay(req));
407 if (req_is_replay(req)) {
408 cfs_spin_lock(&req->rq_export->exp_lock);
409 req->rq_export->exp_vbr_failed = 1;
410 cfs_spin_unlock(&req->rq_export->exp_lock);
412 cfs_mutex_unlock(&ted->ted_lcd_lock);
413 RETURN(req_is_replay(req) ? -EOVERFLOW : 0);
415 lcd->lcd_last_transno = mti->mti_transno;
417 lcd->lcd_last_xid = req->rq_xid;
418 lcd->lcd_last_result = rc;
419 /*XXX: save intent_disposition in mdt_thread_info?
420 * also there is bug - intent_dispostion is __u64,
421 * see struct ldlm_reply->lock_policy_res1; */
422 lcd->lcd_last_data = mti->mti_opdata;
426 CERROR("client idx %d has offset %lld\n", ted->ted_lr_idx, off);
429 err = lut_client_data_write(mti->mti_env, &mdt->mdt_lut, lcd,
432 cfs_mutex_unlock(&ted->ted_lcd_lock);
436 extern struct lu_context_key mdt_thread_key;
438 /* add credits for last_rcvd update */
439 static int mdt_txn_start_cb(const struct lu_env *env,
440 struct thandle *th, void *cookie)
442 struct mdt_device *mdt = cookie;
443 struct mdt_thread_info *mti;
447 mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
449 LASSERT(mdt->mdt_lut.lut_last_rcvd);
450 if (mti->mti_exp == NULL)
453 rc = dt_declare_record_write(env, mdt->mdt_lut.lut_last_rcvd,
454 sizeof(struct lsd_client_data),
455 mti->mti_exp->exp_target_data.ted_lr_off,
460 rc = dt_declare_record_write(env, mdt->mdt_lut.lut_last_rcvd,
461 sizeof(struct lr_server_data), 0, th);
465 if (mti->mti_mos != NULL)
466 rc = dt_declare_version_set(env, mdt_obj2dt(mti->mti_mos), th);
471 /* Update last_rcvd records with latests transaction data */
472 static int mdt_txn_stop_cb(const struct lu_env *env,
473 struct thandle *txn, void *cookie)
475 struct mdt_device *mdt = cookie;
476 struct mdt_thread_info *mti;
477 struct ptlrpc_request *req;
479 mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
480 req = mdt_info_req(mti);
482 if (mti->mti_mdt == NULL || req == NULL || mti->mti_no_need_trans) {
483 mti->mti_no_need_trans = 0;
487 if (mti->mti_has_trans) {
488 /* XXX: currently there are allowed cases, but the wrong cases
489 * are also possible, so better check is needed here */
490 CDEBUG(D_INFO, "More than one transaction "LPU64"\n",
495 mti->mti_has_trans = 1;
496 cfs_spin_lock(&mdt->mdt_lut.lut_translock);
497 if (txn->th_result != 0) {
498 if (mti->mti_transno != 0) {
499 CERROR("Replay transno "LPU64" failed: rc %d\n",
500 mti->mti_transno, txn->th_result);
502 } else if (mti->mti_transno == 0) {
503 mti->mti_transno = ++ mdt->mdt_lut.lut_last_transno;
505 /* should be replay */
506 if (mti->mti_transno > mdt->mdt_lut.lut_last_transno)
507 mdt->mdt_lut.lut_last_transno = mti->mti_transno;
509 cfs_spin_unlock(&mdt->mdt_lut.lut_translock);
510 /* sometimes the reply message has not been successfully packed */
511 LASSERT(req != NULL && req->rq_repmsg != NULL);
513 /** VBR: set new versions */
514 if (txn->th_result == 0 && mti->mti_mos != NULL) {
515 dt_version_set(env, mdt_obj2dt(mti->mti_mos),
516 mti->mti_transno, txn);
520 /* filling reply data */
521 CDEBUG(D_INODE, "transno = "LPU64", last_committed = "LPU64"\n",
522 mti->mti_transno, req->rq_export->exp_obd->obd_last_committed);
524 req->rq_transno = mti->mti_transno;
525 lustre_msg_set_transno(req->rq_repmsg, mti->mti_transno);
526 /* if can't add callback, do sync write */
527 txn->th_sync |= !!lut_last_commit_cb_add(txn, &mdt->mdt_lut,
530 return mdt_last_rcvd_update(mti, txn);
533 int mdt_fs_setup(const struct lu_env *env, struct mdt_device *mdt,
534 struct obd_device *obd,
535 struct lustre_sb_info *lsi)
542 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_FS_SETUP))
545 /* prepare transactions callbacks */
546 mdt->mdt_txn_cb.dtc_txn_start = mdt_txn_start_cb;
547 mdt->mdt_txn_cb.dtc_txn_stop = mdt_txn_stop_cb;
548 mdt->mdt_txn_cb.dtc_txn_commit = NULL;
549 mdt->mdt_txn_cb.dtc_cookie = mdt;
550 mdt->mdt_txn_cb.dtc_tag = LCT_MD_THREAD;
551 CFS_INIT_LIST_HEAD(&mdt->mdt_txn_cb.dtc_linkage);
553 dt_txn_callback_add(mdt->mdt_bottom, &mdt->mdt_txn_cb);
555 rc = mdt_server_data_init(env, mdt, lsi);
559 o = dt_store_open(env, mdt->mdt_bottom, "", CAPA_KEYS, &fid);
562 rc = mdt_capa_keys_init(env, mdt);
564 GOTO(put_ck_object, rc);
567 CERROR("cannot open %s: rc = %d\n", CAPA_KEYS, rc);
568 GOTO(disconnect_exports, rc);
573 lu_object_put(env, &o->do_lu);
574 mdt->mdt_ck_obj = NULL;
576 class_disconnect_exports(obd);
580 void mdt_fs_cleanup(const struct lu_env *env, struct mdt_device *mdt)
584 /* Remove transaction callback */
585 dt_txn_callback_del(mdt->mdt_bottom, &mdt->mdt_txn_cb);
587 lu_object_put(env, &mdt->mdt_ck_obj->do_lu);
588 mdt->mdt_ck_obj = NULL;
592 /* reconstruction code */
593 static void mdt_steal_ack_locks(struct ptlrpc_request *req)
595 struct obd_export *exp = req->rq_export;
597 struct ptlrpc_reply_state *oldrep;
598 struct ptlrpc_service *svc;
601 /* CAVEAT EMPTOR: spinlock order */
602 cfs_spin_lock(&exp->exp_lock);
603 cfs_list_for_each (tmp, &exp->exp_outstanding_replies) {
604 oldrep = cfs_list_entry(tmp, struct ptlrpc_reply_state,
607 if (oldrep->rs_xid != req->rq_xid)
610 if (oldrep->rs_opc != lustre_msg_get_opc(req->rq_reqmsg))
611 CERROR ("Resent req xid "LPU64" has mismatched opc: "
612 "new %d old %d\n", req->rq_xid,
613 lustre_msg_get_opc(req->rq_reqmsg),
616 svc = oldrep->rs_service;
617 cfs_spin_lock (&svc->srv_rs_lock);
619 cfs_list_del_init (&oldrep->rs_exp_list);
621 CWARN("Stealing %d locks from rs %p x"LPD64".t"LPD64
623 oldrep->rs_nlocks, oldrep,
624 oldrep->rs_xid, oldrep->rs_transno, oldrep->rs_opc,
625 libcfs_nid2str(exp->exp_connection->c_peer.nid));
627 for (i = 0; i < oldrep->rs_nlocks; i++)
628 ptlrpc_save_lock(req, &oldrep->rs_locks[i],
629 oldrep->rs_modes[i], 0);
630 oldrep->rs_nlocks = 0;
632 DEBUG_REQ(D_HA, req, "stole locks for");
633 cfs_spin_lock(&oldrep->rs_lock);
634 ptlrpc_schedule_difficult_reply (oldrep);
635 cfs_spin_unlock(&oldrep->rs_lock);
637 cfs_spin_unlock (&svc->srv_rs_lock);
640 cfs_spin_unlock(&exp->exp_lock);
644 * VBR: restore versions
646 void mdt_vbr_reconstruct(struct ptlrpc_request *req,
647 struct lsd_client_data *lcd)
649 __u64 pre_versions[4] = {0};
650 pre_versions[0] = lcd->lcd_pre_versions[0];
651 pre_versions[1] = lcd->lcd_pre_versions[1];
652 pre_versions[2] = lcd->lcd_pre_versions[2];
653 pre_versions[3] = lcd->lcd_pre_versions[3];
654 lustre_msg_set_versions(req->rq_repmsg, pre_versions);
657 void mdt_req_from_lcd(struct ptlrpc_request *req,
658 struct lsd_client_data *lcd)
660 DEBUG_REQ(D_HA, req, "restoring transno "LPD64"/status %d",
661 lcd->lcd_last_transno, lcd->lcd_last_result);
663 if (lustre_msg_get_opc(req->rq_reqmsg) == MDS_CLOSE ||
664 lustre_msg_get_opc(req->rq_repmsg) == MDS_DONE_WRITING) {
665 req->rq_transno = lcd->lcd_last_close_transno;
666 req->rq_status = lcd->lcd_last_close_result;
668 req->rq_transno = lcd->lcd_last_transno;
669 req->rq_status = lcd->lcd_last_result;
670 mdt_vbr_reconstruct(req, lcd);
672 if (req->rq_status != 0)
674 lustre_msg_set_transno(req->rq_repmsg, req->rq_transno);
675 lustre_msg_set_status(req->rq_repmsg, req->rq_status);
676 DEBUG_REQ(D_RPCTRACE, req, "restoring transno "LPD64"/status %d",
677 req->rq_transno, req->rq_status);
679 mdt_steal_ack_locks(req);
682 void mdt_reconstruct_generic(struct mdt_thread_info *mti,
683 struct mdt_lock_handle *lhc)
685 struct ptlrpc_request *req = mdt_info_req(mti);
686 struct tg_export_data *ted = &req->rq_export->exp_target_data;
688 return mdt_req_from_lcd(req, ted->ted_lcd);
691 static void mdt_reconstruct_create(struct mdt_thread_info *mti,
692 struct mdt_lock_handle *lhc)
694 struct ptlrpc_request *req = mdt_info_req(mti);
695 struct obd_export *exp = req->rq_export;
696 struct tg_export_data *ted = &exp->exp_target_data;
697 struct mdt_device *mdt = mti->mti_mdt;
698 struct mdt_object *child;
699 struct mdt_body *body;
702 mdt_req_from_lcd(req, ted->ted_lcd);
706 /* if no error, so child was created with requested fid */
707 child = mdt_object_find(mti->mti_env, mdt, mti->mti_rr.rr_fid2);
710 LCONSOLE_WARN("Child "DFID" lookup error %d."
711 " Evicting client %s with export %s.\n",
712 PFID(mdt_object_fid(child)), rc,
713 obd_uuid2str(&exp->exp_client_uuid),
714 obd_export_nid2str(exp));
715 mdt_export_evict(exp);
720 body = req_capsule_server_get(mti->mti_pill, &RMF_MDT_BODY);
721 mti->mti_attr.ma_need = MA_INODE;
722 mti->mti_attr.ma_valid = 0;
723 rc = mo_attr_get(mti->mti_env, mdt_object_child(child), &mti->mti_attr);
724 if (rc == -EREMOTE) {
725 /* object was created on remote server */
727 body->valid |= OBD_MD_MDS;
729 mdt_pack_attr2body(mti, body, &mti->mti_attr.ma_attr,
730 mdt_object_fid(child));
731 mdt_object_put(mti->mti_env, child);
734 static void mdt_reconstruct_setattr(struct mdt_thread_info *mti,
735 struct mdt_lock_handle *lhc)
737 struct ptlrpc_request *req = mdt_info_req(mti);
738 struct obd_export *exp = req->rq_export;
739 struct mdt_export_data *med = &exp->exp_mdt_data;
740 struct mdt_device *mdt = mti->mti_mdt;
741 struct mdt_object *obj;
742 struct mdt_body *body;
744 mdt_req_from_lcd(req, med->med_ted.ted_lcd);
748 body = req_capsule_server_get(mti->mti_pill, &RMF_MDT_BODY);
749 obj = mdt_object_find(mti->mti_env, mdt, mti->mti_rr.rr_fid1);
751 int rc = PTR_ERR(obj);
752 LCONSOLE_WARN(""DFID" lookup error %d."
753 " Evicting client %s with export %s.\n",
754 PFID(mdt_object_fid(obj)), rc,
755 obd_uuid2str(&exp->exp_client_uuid),
756 obd_export_nid2str(exp));
757 mdt_export_evict(exp);
761 mti->mti_attr.ma_need = MA_INODE;
762 mti->mti_attr.ma_valid = 0;
763 mo_attr_get(mti->mti_env, mdt_object_child(obj), &mti->mti_attr);
764 mdt_pack_attr2body(mti, body, &mti->mti_attr.ma_attr,
765 mdt_object_fid(obj));
766 if (mti->mti_ioepoch && (mti->mti_ioepoch->flags & MF_EPOCH_OPEN)) {
767 struct mdt_file_data *mfd;
768 struct mdt_body *repbody;
770 repbody = req_capsule_server_get(mti->mti_pill, &RMF_MDT_BODY);
771 repbody->ioepoch = obj->mot_ioepoch;
772 cfs_spin_lock(&med->med_open_lock);
773 cfs_list_for_each_entry(mfd, &med->med_open_head, mfd_list) {
774 if (mfd->mfd_xid == req->rq_xid)
777 LASSERT(&mfd->mfd_list != &med->med_open_head);
778 cfs_spin_unlock(&med->med_open_lock);
779 repbody->handle.cookie = mfd->mfd_handle.h_cookie;
782 mdt_object_put(mti->mti_env, obj);
785 typedef void (*mdt_reconstructor)(struct mdt_thread_info *mti,
786 struct mdt_lock_handle *lhc);
788 static mdt_reconstructor reconstructors[REINT_MAX] = {
789 [REINT_SETATTR] = mdt_reconstruct_setattr,
790 [REINT_CREATE] = mdt_reconstruct_create,
791 [REINT_LINK] = mdt_reconstruct_generic,
792 [REINT_UNLINK] = mdt_reconstruct_generic,
793 [REINT_RENAME] = mdt_reconstruct_generic,
794 [REINT_OPEN] = mdt_reconstruct_open,
795 [REINT_SETXATTR] = mdt_reconstruct_generic
798 void mdt_reconstruct(struct mdt_thread_info *mti,
799 struct mdt_lock_handle *lhc)
802 reconstructors[mti->mti_rr.rr_opcode](mti, lhc);