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, 2013, Intel Corporation.
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>
44 #define DEBUG_SUBSYSTEM S_MDS
46 #include "mdt_internal.h"
48 struct lu_buf *mdt_buf(const struct lu_env *env, void *area, ssize_t len)
51 struct mdt_thread_info *mti;
53 mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
60 const struct lu_buf *mdt_buf_const(const struct lu_env *env,
61 const void *area, ssize_t len)
64 struct mdt_thread_info *mti;
66 mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
69 buf->lb_buf = (void *)area;
74 void mdt_trans_stop(const struct lu_env *env,
75 struct mdt_device *mdt, struct thandle *th)
77 dt_trans_stop(env, mdt->mdt_bottom, th);
80 static int mdt_clients_data_init(const struct lu_env *env,
81 struct mdt_device *mdt,
82 unsigned long last_size)
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);
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++) {
103 struct obd_export *exp;
104 struct mdt_thread_info *mti;
106 off = lsd->lsd_client_start +
107 cl_idx * lsd->lsd_client_size;
109 rc = tgt_client_data_read(env, &mdt->mdt_lut, lcd, &off, cl_idx);
111 CERROR("error reading MDS %s idx %d, off %llu: rc %d\n",
112 LAST_RCVD, cl_idx, off, rc);
114 break; /* read error shouldn't cause startup to fail */
117 if (lcd->lcd_uuid[0] == '\0') {
118 CDEBUG(D_INFO, "skipping zeroed client at offset %d\n",
123 last_transno = lcd_last_transno(lcd);
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.
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,
134 exp = class_new_export(obd, (struct obd_uuid *)lcd->lcd_uuid);
136 if (PTR_ERR(exp) == -EALREADY) {
137 /* export already exists, zero out this one */
138 CERROR("Duplicate export %s!\n", lcd->lcd_uuid);
141 GOTO(err_client, rc = PTR_ERR(exp));
144 mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
145 LASSERT(mti != NULL);
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);
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);
175 static int mdt_server_data_init(const struct lu_env *env,
176 struct mdt_device *mdt,
177 struct lustre_sb_info *lsi)
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;
185 unsigned long last_rcvd_size;
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);
197 rc = server_name2index(mdt_obd_name(mdt), &index, NULL);
199 CERROR("%s: Can not get index from obd_name: rc = %d\n",
200 mdt_obd_name(mdt), rc);
204 mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
205 LASSERT(mti != NULL);
206 la = &mti->mti_attr.ma_attr;
208 obj = mdt->mdt_lut.lut_last_rcvd;
209 rc = dt_attr_get(env, obj, la, BYPASS_CAPA);
213 last_rcvd_size = (unsigned long)la->la_size;
215 if (last_rcvd_size == 0) {
216 LCONSOLE_WARN("%s: new disk, initializing\n",
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;
233 LCONSOLE_WARN("%s: used disk, loading\n", mdt_obd_name(mdt));
234 rc = tgt_server_data_read(env, &mdt->mdt_lut);
236 CERROR("error reading MDS %s: rc %d\n", LAST_RCVD, rc);
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);
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);
258 mount_count = lsd->lsd_mount_count;
260 if (lsd->lsd_feature_incompat & ~MDT_INCOMPAT_SUPP) {
261 CERROR("%s: unsupported incompat filesystem feature(s) %x\n",
263 lsd->lsd_feature_incompat & ~MDT_INCOMPAT_SUPP);
264 GOTO(out, rc = -EINVAL);
266 if (lsd->lsd_feature_rocompat & ~MDT_ROCOMPAT_SUPP) {
267 CERROR("%s: unsupported read-only filesystem feature(s) %x\n",
269 lsd->lsd_feature_rocompat & ~MDT_ROCOMPAT_SUPP);
270 /* XXX: Do something like remount filesystem read-only */
271 GOTO(out, rc = -EINVAL);
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",
279 rc = tgt_truncate_last_rcvd(env, &mdt->mdt_lut,
280 lsd->lsd_client_start);
283 last_rcvd_size = lsd->lsd_client_start;
285 /** set 2.0 flag to upgrade/downgrade between 1.8 and 2.0 */
286 lsd->lsd_feature_compat |= OBD_COMPAT_20;
289 lsd->lsd_feature_incompat |= OBD_INCOMPAT_FID;
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);
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");
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);
320 rc = mdt_clients_data_init(env, mdt, last_rcvd_size);
322 GOTO(err_client, rc);
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);
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;
334 /* save it, so mount count and last_transno is current */
335 rc = tgt_server_data_update(env, &mdt->mdt_lut, 0);
337 GOTO(err_client, rc);
342 class_disconnect_exports(obd);
348 * last_rcvd & last_committed update callbacks
350 static int mdt_last_rcvd_update(struct mdt_thread_info *mti,
353 struct mdt_device *mdt = mti->mti_mdt;
354 struct ptlrpc_request *req = mdt_info_req(mti);
355 struct tg_export_data *ted;
356 struct lsd_client_data *lcd;
359 __s32 rc = th->th_result;
363 LASSERT(req->rq_export);
365 ted = &req->rq_export->exp_target_data;
368 mutex_lock(&ted->ted_lcd_lock);
370 /* if the export has already been disconnected, we have no last_rcvd
371 * slot, update server data with latest transno then */
373 mutex_unlock(&ted->ted_lcd_lock);
374 CWARN("commit transaction for disconnected client %s: rc %d\n",
375 req->rq_export->exp_client_uuid.uuid, rc);
376 err = tgt_server_data_write(mti->mti_env, &mdt->mdt_lut, th);
380 off = ted->ted_lr_off;
381 LASSERT(ergo(mti->mti_transno == 0, rc != 0));
382 if (lustre_msg_get_opc(req->rq_reqmsg) == MDS_CLOSE ||
383 lustre_msg_get_opc(req->rq_reqmsg) == MDS_DONE_WRITING) {
384 if (mti->mti_transno != 0) {
385 if (lcd->lcd_last_close_transno > mti->mti_transno) {
386 CERROR("Trying to overwrite bigger transno:"
387 "on-disk: "LPU64", new: "LPU64" "
388 "replay: %d. see LU-617.\n",
389 lcd->lcd_last_close_transno,
390 mti->mti_transno, req_is_replay(req));
391 if (req_is_replay(req)) {
392 spin_lock(&req->rq_export->exp_lock);
393 req->rq_export->exp_vbr_failed = 1;
394 spin_unlock(&req->rq_export->exp_lock);
396 mutex_unlock(&ted->ted_lcd_lock);
397 RETURN(req_is_replay(req) ? -EOVERFLOW : 0);
399 lcd->lcd_last_close_transno = mti->mti_transno;
401 lcd->lcd_last_close_xid = req->rq_xid;
402 lcd->lcd_last_close_result = rc;
404 /* VBR: save versions in last_rcvd for reconstruct. */
405 __u64 *pre_versions = lustre_msg_get_versions(req->rq_repmsg);
407 lcd->lcd_pre_versions[0] = pre_versions[0];
408 lcd->lcd_pre_versions[1] = pre_versions[1];
409 lcd->lcd_pre_versions[2] = pre_versions[2];
410 lcd->lcd_pre_versions[3] = pre_versions[3];
412 if (mti->mti_transno != 0) {
413 if (lcd->lcd_last_transno > mti->mti_transno) {
414 CERROR("Trying to overwrite bigger transno:"
415 "on-disk: "LPU64", new: "LPU64" "
416 "replay: %d. see LU-617.\n",
417 lcd->lcd_last_transno,
418 mti->mti_transno, req_is_replay(req));
419 if (req_is_replay(req)) {
420 spin_lock(&req->rq_export->exp_lock);
421 req->rq_export->exp_vbr_failed = 1;
422 spin_unlock(&req->rq_export->exp_lock);
424 mutex_unlock(&ted->ted_lcd_lock);
425 RETURN(req_is_replay(req) ? -EOVERFLOW : 0);
427 lcd->lcd_last_transno = mti->mti_transno;
429 lcd->lcd_last_xid = req->rq_xid;
430 lcd->lcd_last_result = rc;
431 /*XXX: save intent_disposition in mdt_thread_info?
432 * also there is bug - intent_dispostion is __u64,
433 * see struct ldlm_reply->lock_policy_res1; */
434 lcd->lcd_last_data = mti->mti_opdata;
437 if (exp_connect_flags(mti->mti_exp) & OBD_CONNECT_LIGHTWEIGHT) {
438 /* Although lightweight (LW) connections have no slot in
439 * last_rcvd, we still want to maintain the in-memory
440 * lsd_client_data structure in order to properly handle reply
442 struct lu_target *tg = &mdt->mdt_lut;
445 mutex_unlock(&ted->ted_lcd_lock);
448 /* All operations performed by LW clients are synchronous and
449 * we store the committed transno in the last_rcvd header */
450 spin_lock(&tg->lut_translock);
451 if (mti->mti_transno > tg->lut_lsd.lsd_last_transno) {
452 tg->lut_lsd.lsd_last_transno = mti->mti_transno;
455 spin_unlock(&tg->lut_translock);
458 err = tgt_server_data_write(mti->mti_env, tg, th);
459 } else if (off <= 0) {
460 CERROR("%s: client idx %d has offset %lld\n",
461 mdt_obd_name(mdt), ted->ted_lr_idx, off);
462 mutex_unlock(&ted->ted_lcd_lock);
465 err = tgt_client_data_write(mti->mti_env, &mdt->mdt_lut, lcd,
467 mutex_unlock(&ted->ted_lcd_lock);
472 extern struct lu_context_key mdt_thread_key;
474 /* add credits for last_rcvd update */
475 static int mdt_txn_start_cb(const struct lu_env *env,
476 struct thandle *th, void *cookie)
478 struct mdt_device *mdt = cookie;
479 struct mdt_thread_info *mti;
483 mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
485 LASSERT(mdt->mdt_lut.lut_last_rcvd);
486 if (mti->mti_exp == NULL)
489 rc = dt_declare_record_write(env, mdt->mdt_lut.lut_last_rcvd,
490 sizeof(struct lsd_client_data),
491 mti->mti_exp->exp_target_data.ted_lr_off,
496 rc = dt_declare_record_write(env, mdt->mdt_lut.lut_last_rcvd,
497 sizeof(struct lr_server_data), 0, th);
501 /* we probably should not set local transno to the remote object
502 * on another storage, What about VBR on remote object? XXX */
503 if (mti->mti_mos != NULL && !mdt_object_remote(mti->mti_mos))
504 rc = dt_declare_version_set(env, mdt_obj2dt(mti->mti_mos), th);
509 /* Update last_rcvd records with latests transaction data */
510 static int mdt_txn_stop_cb(const struct lu_env *env,
511 struct thandle *txn, void *cookie)
513 struct mdt_device *mdt = cookie;
514 struct mdt_thread_info *mti;
515 struct ptlrpc_request *req;
517 mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
518 req = mdt_info_req(mti);
520 if (mti->mti_mdt == NULL || req == NULL)
523 if (mti->mti_has_trans) {
524 /* XXX: currently there are allowed cases, but the wrong cases
525 * are also possible, so better check is needed here */
526 CDEBUG(D_INFO, "More than one transaction "LPU64"\n",
531 mti->mti_has_trans = 1;
532 spin_lock(&mdt->mdt_lut.lut_translock);
533 if (txn->th_result != 0) {
534 if (mti->mti_transno != 0) {
535 CERROR("Replay transno "LPU64" failed: rc %d\n",
536 mti->mti_transno, txn->th_result);
537 spin_unlock(&mdt->mdt_lut.lut_translock);
540 } else if (mti->mti_transno == 0) {
541 mti->mti_transno = ++ mdt->mdt_lut.lut_last_transno;
543 /* should be replay */
544 if (mti->mti_transno > mdt->mdt_lut.lut_last_transno)
545 mdt->mdt_lut.lut_last_transno = mti->mti_transno;
547 spin_unlock(&mdt->mdt_lut.lut_translock);
548 /* sometimes the reply message has not been successfully packed */
549 LASSERT(req != NULL && req->rq_repmsg != NULL);
551 /** VBR: set new versions */
552 /* we probably should not set local transno to the remote object
553 * on another storage, What about VBR on remote object? XXX */
554 if (txn->th_result == 0 && mti->mti_mos != NULL &&
555 !mdt_object_remote(mti->mti_mos)) {
557 dt_version_set(env, mdt_obj2dt(mti->mti_mos),
558 mti->mti_transno, txn);
562 /* filling reply data */
563 CDEBUG(D_INODE, "transno = "LPU64", last_committed = "LPU64"\n",
564 mti->mti_transno, req->rq_export->exp_obd->obd_last_committed);
566 req->rq_transno = mti->mti_transno;
567 lustre_msg_set_transno(req->rq_repmsg, mti->mti_transno);
568 /* if can't add callback, do sync write */
569 txn->th_sync |= !!tgt_last_commit_cb_add(txn, &mdt->mdt_lut,
572 return mdt_last_rcvd_update(mti, txn);
575 int mdt_fs_setup(const struct lu_env *env, struct mdt_device *mdt,
576 struct obd_device *obd,
577 struct lustre_sb_info *lsi)
582 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_FS_SETUP))
585 /* prepare transactions callbacks */
586 mdt->mdt_txn_cb.dtc_txn_start = mdt_txn_start_cb;
587 mdt->mdt_txn_cb.dtc_txn_stop = mdt_txn_stop_cb;
588 mdt->mdt_txn_cb.dtc_txn_commit = NULL;
589 mdt->mdt_txn_cb.dtc_cookie = mdt;
590 mdt->mdt_txn_cb.dtc_tag = LCT_MD_THREAD;
591 CFS_INIT_LIST_HEAD(&mdt->mdt_txn_cb.dtc_linkage);
593 dt_txn_callback_add(mdt->mdt_bottom, &mdt->mdt_txn_cb);
595 rc = mdt_server_data_init(env, mdt, lsi);
600 void mdt_fs_cleanup(const struct lu_env *env, struct mdt_device *mdt)
604 /* Remove transaction callback */
605 dt_txn_callback_del(mdt->mdt_bottom, &mdt->mdt_txn_cb);
607 lu_object_put(env, &mdt->mdt_ck_obj->do_lu);
608 mdt->mdt_ck_obj = NULL;
612 /* reconstruction code */
613 static void mdt_steal_ack_locks(struct ptlrpc_request *req)
615 struct ptlrpc_service_part *svcpt;
616 struct obd_export *exp = req->rq_export;
618 struct ptlrpc_reply_state *oldrep;
621 /* CAVEAT EMPTOR: spinlock order */
622 spin_lock(&exp->exp_lock);
623 cfs_list_for_each (tmp, &exp->exp_outstanding_replies) {
624 oldrep = cfs_list_entry(tmp, struct ptlrpc_reply_state,
627 if (oldrep->rs_xid != req->rq_xid)
630 if (oldrep->rs_opc != lustre_msg_get_opc(req->rq_reqmsg))
631 CERROR ("Resent req xid "LPU64" has mismatched opc: "
632 "new %d old %d\n", req->rq_xid,
633 lustre_msg_get_opc(req->rq_reqmsg),
636 svcpt = oldrep->rs_svcpt;
637 spin_lock(&svcpt->scp_rep_lock);
639 cfs_list_del_init (&oldrep->rs_exp_list);
641 CDEBUG(D_HA, "Stealing %d locks from rs %p x"LPD64".t"LPD64
643 oldrep->rs_nlocks, oldrep,
644 oldrep->rs_xid, oldrep->rs_transno, oldrep->rs_opc,
645 libcfs_nid2str(exp->exp_connection->c_peer.nid));
647 for (i = 0; i < oldrep->rs_nlocks; i++)
648 ptlrpc_save_lock(req, &oldrep->rs_locks[i],
649 oldrep->rs_modes[i], 0);
650 oldrep->rs_nlocks = 0;
652 DEBUG_REQ(D_HA, req, "stole locks for");
653 spin_lock(&oldrep->rs_lock);
654 ptlrpc_schedule_difficult_reply(oldrep);
655 spin_unlock(&oldrep->rs_lock);
657 spin_unlock(&svcpt->scp_rep_lock);
660 spin_unlock(&exp->exp_lock);
664 * VBR: restore versions
666 void mdt_vbr_reconstruct(struct ptlrpc_request *req,
667 struct lsd_client_data *lcd)
669 __u64 pre_versions[4] = {0};
670 pre_versions[0] = lcd->lcd_pre_versions[0];
671 pre_versions[1] = lcd->lcd_pre_versions[1];
672 pre_versions[2] = lcd->lcd_pre_versions[2];
673 pre_versions[3] = lcd->lcd_pre_versions[3];
674 lustre_msg_set_versions(req->rq_repmsg, pre_versions);
677 void mdt_req_from_lcd(struct ptlrpc_request *req,
678 struct lsd_client_data *lcd)
680 DEBUG_REQ(D_HA, req, "restoring transno "LPD64"/status %d",
681 lcd->lcd_last_transno, lcd->lcd_last_result);
683 if (lustre_msg_get_opc(req->rq_reqmsg) == MDS_CLOSE ||
684 lustre_msg_get_opc(req->rq_repmsg) == MDS_DONE_WRITING) {
685 req->rq_transno = lcd->lcd_last_close_transno;
686 req->rq_status = lcd->lcd_last_close_result;
688 req->rq_transno = lcd->lcd_last_transno;
689 req->rq_status = lcd->lcd_last_result;
690 mdt_vbr_reconstruct(req, lcd);
692 if (req->rq_status != 0)
694 lustre_msg_set_transno(req->rq_repmsg, req->rq_transno);
695 lustre_msg_set_status(req->rq_repmsg, req->rq_status);
696 DEBUG_REQ(D_RPCTRACE, req, "restoring transno "LPD64"/status %d",
697 req->rq_transno, req->rq_status);
699 mdt_steal_ack_locks(req);
702 void mdt_reconstruct_generic(struct mdt_thread_info *mti,
703 struct mdt_lock_handle *lhc)
705 struct ptlrpc_request *req = mdt_info_req(mti);
706 struct tg_export_data *ted = &req->rq_export->exp_target_data;
708 return mdt_req_from_lcd(req, ted->ted_lcd);
711 static void mdt_reconstruct_create(struct mdt_thread_info *mti,
712 struct mdt_lock_handle *lhc)
714 struct ptlrpc_request *req = mdt_info_req(mti);
715 struct obd_export *exp = req->rq_export;
716 struct tg_export_data *ted = &exp->exp_target_data;
717 struct mdt_device *mdt = mti->mti_mdt;
718 struct mdt_object *child;
719 struct mdt_body *body;
722 mdt_req_from_lcd(req, ted->ted_lcd);
726 /* if no error, so child was created with requested fid */
727 child = mdt_object_find(mti->mti_env, mdt, mti->mti_rr.rr_fid2);
730 LCONSOLE_WARN("Child "DFID" lookup error %d."
731 " Evicting client %s with export %s.\n",
732 PFID(mdt_object_fid(child)), rc,
733 obd_uuid2str(&exp->exp_client_uuid),
734 obd_export_nid2str(exp));
735 mdt_export_evict(exp);
740 body = req_capsule_server_get(mti->mti_pill, &RMF_MDT_BODY);
741 mti->mti_attr.ma_need = MA_INODE;
742 mti->mti_attr.ma_valid = 0;
743 rc = mdt_attr_get_complex(mti, child, &mti->mti_attr);
744 if (rc == -EREMOTE) {
745 /* object was created on remote server */
746 if (!mdt_is_dne_client(exp))
747 /* Return -EIO for old client */
751 body->valid |= OBD_MD_MDS;
753 mdt_pack_attr2body(mti, body, &mti->mti_attr.ma_attr,
754 mdt_object_fid(child));
755 mdt_object_put(mti->mti_env, child);
758 static void mdt_reconstruct_setattr(struct mdt_thread_info *mti,
759 struct mdt_lock_handle *lhc)
761 struct ptlrpc_request *req = mdt_info_req(mti);
762 struct obd_export *exp = req->rq_export;
763 struct mdt_export_data *med = &exp->exp_mdt_data;
764 struct mdt_device *mdt = mti->mti_mdt;
765 struct mdt_object *obj;
766 struct mdt_body *body;
768 mdt_req_from_lcd(req, med->med_ted.ted_lcd);
772 body = req_capsule_server_get(mti->mti_pill, &RMF_MDT_BODY);
773 obj = mdt_object_find(mti->mti_env, mdt, mti->mti_rr.rr_fid1);
775 int rc = PTR_ERR(obj);
776 LCONSOLE_WARN(""DFID" lookup error %d."
777 " Evicting client %s with export %s.\n",
778 PFID(mdt_object_fid(obj)), rc,
779 obd_uuid2str(&exp->exp_client_uuid),
780 obd_export_nid2str(exp));
781 mdt_export_evict(exp);
785 mti->mti_attr.ma_need = MA_INODE;
786 mti->mti_attr.ma_valid = 0;
787 mdt_attr_get_complex(mti, obj, &mti->mti_attr);
788 mdt_pack_attr2body(mti, body, &mti->mti_attr.ma_attr,
789 mdt_object_fid(obj));
790 if (mti->mti_ioepoch && (mti->mti_ioepoch->flags & MF_EPOCH_OPEN)) {
791 struct mdt_file_data *mfd;
792 struct mdt_body *repbody;
794 repbody = req_capsule_server_get(mti->mti_pill, &RMF_MDT_BODY);
795 repbody->ioepoch = obj->mot_ioepoch;
796 spin_lock(&med->med_open_lock);
797 cfs_list_for_each_entry(mfd, &med->med_open_head, mfd_list) {
798 if (mfd->mfd_xid == req->rq_xid)
801 LASSERT(&mfd->mfd_list != &med->med_open_head);
802 spin_unlock(&med->med_open_lock);
803 repbody->handle.cookie = mfd->mfd_handle.h_cookie;
806 mdt_object_put(mti->mti_env, obj);
809 typedef void (*mdt_reconstructor)(struct mdt_thread_info *mti,
810 struct mdt_lock_handle *lhc);
812 static mdt_reconstructor reconstructors[REINT_MAX] = {
813 [REINT_SETATTR] = mdt_reconstruct_setattr,
814 [REINT_CREATE] = mdt_reconstruct_create,
815 [REINT_LINK] = mdt_reconstruct_generic,
816 [REINT_UNLINK] = mdt_reconstruct_generic,
817 [REINT_RENAME] = mdt_reconstruct_generic,
818 [REINT_OPEN] = mdt_reconstruct_open,
819 [REINT_SETXATTR] = mdt_reconstruct_generic
822 void mdt_reconstruct(struct mdt_thread_info *mti,
823 struct mdt_lock_handle *lhc)
826 reconstructors[mti->mti_rr.rr_opcode](mti, lhc);