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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * Lustre Unified Target
33 * These are common function to work with last_received file
35 * Author: Mikhail Pershin <mike.pershin@intel.com>
38 #include <obd_class.h>
39 #include <lustre_fid.h>
41 #include "tgt_internal.h"
43 /** version recovery epoch */
44 #define LR_EPOCH_BITS 32
46 /* Allocate a bitmap for a chunk of reply data slots */
47 static int tgt_bitmap_chunk_alloc(struct lu_target *lut, int chunk)
51 OBD_ALLOC_LARGE(bm, BITS_TO_LONGS(LUT_REPLY_SLOTS_PER_CHUNK) *
56 spin_lock(&lut->lut_client_bitmap_lock);
58 if (lut->lut_reply_bitmap[chunk] != NULL) {
59 /* someone else already allocated the bitmap for this chunk */
60 spin_unlock(&lut->lut_client_bitmap_lock);
61 OBD_FREE_LARGE(bm, BITS_TO_LONGS(LUT_REPLY_SLOTS_PER_CHUNK) *
66 lut->lut_reply_bitmap[chunk] = bm;
68 spin_unlock(&lut->lut_client_bitmap_lock);
73 /* Look for an available reply data slot in the bitmap
75 * Allocate bitmap chunk when first used
76 * XXX algo could be improved if this routine limits performance
78 static int tgt_find_free_reply_slot(struct lu_target *lut)
85 for (chunk = 0; chunk < LUT_REPLY_SLOTS_MAX_CHUNKS; chunk++) {
86 /* allocate the bitmap chunk if necessary */
87 if (unlikely(lut->lut_reply_bitmap[chunk] == NULL)) {
88 rc = tgt_bitmap_chunk_alloc(lut, chunk);
92 bmp = lut->lut_reply_bitmap[chunk];
94 /* look for an available slot in this chunk */
96 b = find_first_zero_bit(bmp, LUT_REPLY_SLOTS_PER_CHUNK);
97 if (b >= LUT_REPLY_SLOTS_PER_CHUNK)
101 if (test_and_set_bit(b, bmp) == 0)
102 return chunk * LUT_REPLY_SLOTS_PER_CHUNK + b;
109 /* Mark the reply data slot @idx 'used' in the corresponding bitmap chunk
111 * Allocate the bitmap chunk if necessary
113 static int tgt_set_reply_slot(struct lu_target *lut, int idx)
119 chunk = idx / LUT_REPLY_SLOTS_PER_CHUNK;
120 b = idx % LUT_REPLY_SLOTS_PER_CHUNK;
122 LASSERT(chunk < LUT_REPLY_SLOTS_MAX_CHUNKS);
123 LASSERT(b < LUT_REPLY_SLOTS_PER_CHUNK);
125 /* allocate the bitmap chunk if necessary */
126 if (unlikely(lut->lut_reply_bitmap[chunk] == NULL)) {
127 rc = tgt_bitmap_chunk_alloc(lut, chunk);
132 /* mark the slot 'used' in this chunk */
133 if (test_and_set_bit(b, lut->lut_reply_bitmap[chunk]) != 0) {
134 CERROR("%s: slot %d already set in bitmap\n",
143 /* Mark the reply data slot @idx 'unused' in the corresponding bitmap chunk
146 static int tgt_clear_reply_slot(struct lu_target *lut, int idx)
151 if (lut->lut_obd->obd_stopping)
153 * in case of failover keep the bit set in order to
154 * avoid overwriting slots in reply_data which might
155 * be required by resent rpcs
158 chunk = idx / LUT_REPLY_SLOTS_PER_CHUNK;
159 b = idx % LUT_REPLY_SLOTS_PER_CHUNK;
161 LASSERT(chunk < LUT_REPLY_SLOTS_MAX_CHUNKS);
162 LASSERT(b < LUT_REPLY_SLOTS_PER_CHUNK);
164 if (lut->lut_reply_bitmap[chunk] == NULL) {
165 CERROR("%s: slot %d not allocated\n",
170 if (test_and_clear_bit(b, lut->lut_reply_bitmap[chunk]) == 0) {
171 CERROR("%s: slot %d already clear in bitmap\n",
180 /* Read header of reply_data file of target @tgt into structure @lrh */
181 static int tgt_reply_header_read(const struct lu_env *env,
182 struct lu_target *tgt,
183 struct lsd_reply_header *lrh)
186 struct lsd_reply_header buf;
187 struct tgt_thread_info *tti = tgt_th_info(env);
190 tti->tti_buf.lb_buf = &buf;
191 tti->tti_buf.lb_len = sizeof(buf);
193 rc = dt_record_read(env, tgt->lut_reply_data, &tti->tti_buf,
198 lrh->lrh_magic = le32_to_cpu(buf.lrh_magic);
199 lrh->lrh_header_size = le32_to_cpu(buf.lrh_header_size);
200 lrh->lrh_reply_size = le32_to_cpu(buf.lrh_reply_size);
202 CDEBUG(D_HA, "%s: read %s header. magic=0x%08x "
203 "header_size=%d reply_size=%d\n",
204 tgt->lut_obd->obd_name, REPLY_DATA,
205 lrh->lrh_magic, lrh->lrh_header_size, lrh->lrh_reply_size);
210 /* Write header into replay_data file of target @tgt from structure @lrh */
211 static int tgt_reply_header_write(const struct lu_env *env,
212 struct lu_target *tgt,
213 struct lsd_reply_header *lrh)
216 struct lsd_reply_header buf;
217 struct tgt_thread_info *tti = tgt_th_info(env);
219 struct dt_object *dto;
221 CDEBUG(D_HA, "%s: write %s header. magic=0x%08x "
222 "header_size=%d reply_size=%d\n",
223 tgt->lut_obd->obd_name, REPLY_DATA,
224 lrh->lrh_magic, lrh->lrh_header_size, lrh->lrh_reply_size);
226 if (tgt->lut_bottom->dd_rdonly)
229 buf.lrh_magic = cpu_to_le32(lrh->lrh_magic);
230 buf.lrh_header_size = cpu_to_le32(lrh->lrh_header_size);
231 buf.lrh_reply_size = cpu_to_le32(lrh->lrh_reply_size);
233 th = dt_trans_create(env, tgt->lut_bottom);
239 tti->tti_buf.lb_buf = &buf;
240 tti->tti_buf.lb_len = sizeof(buf);
242 rc = dt_declare_record_write(env, tgt->lut_reply_data,
243 &tti->tti_buf, tti->tti_off, th);
247 rc = dt_trans_start(env, tgt->lut_bottom, th);
251 dto = dt_object_locate(tgt->lut_reply_data, th->th_dev);
252 rc = dt_record_write(env, dto, &tti->tti_buf, &tti->tti_off, th);
254 dt_trans_stop(env, tgt->lut_bottom, th);
258 /* Write the reply data @lrd into reply_data file of target @tgt
261 static int tgt_reply_data_write(const struct lu_env *env, struct lu_target *tgt,
262 struct lsd_reply_data *lrd, loff_t off,
265 struct tgt_thread_info *tti = tgt_th_info(env);
266 struct dt_object *dto;
267 struct lsd_reply_data *buf = &tti->tti_lrd;
269 lrd->lrd_result = ptlrpc_status_hton(lrd->lrd_result);
271 buf->lrd_transno = cpu_to_le64(lrd->lrd_transno);
272 buf->lrd_xid = cpu_to_le64(lrd->lrd_xid);
273 buf->lrd_data = cpu_to_le64(lrd->lrd_data);
274 buf->lrd_result = cpu_to_le32(lrd->lrd_result);
275 buf->lrd_client_gen = cpu_to_le32(lrd->lrd_client_gen);
277 lrd->lrd_result = ptlrpc_status_ntoh(lrd->lrd_result);
280 tti->tti_buf.lb_buf = buf;
281 tti->tti_buf.lb_len = sizeof(*buf);
283 dto = dt_object_locate(tgt->lut_reply_data, th->th_dev);
284 return dt_record_write(env, dto, &tti->tti_buf, &tti->tti_off, th);
287 /* Read the reply data from reply_data file of target @tgt at offset @off
288 * into structure @lrd
290 static int tgt_reply_data_read(const struct lu_env *env, struct lu_target *tgt,
291 struct lsd_reply_data *lrd, loff_t off)
294 struct tgt_thread_info *tti = tgt_th_info(env);
295 struct lsd_reply_data *buf = &tti->tti_lrd;
298 tti->tti_buf.lb_buf = buf;
299 tti->tti_buf.lb_len = sizeof(*buf);
301 rc = dt_record_read(env, tgt->lut_reply_data, &tti->tti_buf,
306 lrd->lrd_transno = le64_to_cpu(buf->lrd_transno);
307 lrd->lrd_xid = le64_to_cpu(buf->lrd_xid);
308 lrd->lrd_data = le64_to_cpu(buf->lrd_data);
309 lrd->lrd_result = le32_to_cpu(buf->lrd_result);
310 lrd->lrd_client_gen = le32_to_cpu(buf->lrd_client_gen);
316 /* Free the in-memory reply data structure @trd and release
317 * the corresponding slot in the reply_data file of target @lut
318 * Called with ted_lcd_lock held
320 static void tgt_free_reply_data(struct lu_target *lut,
321 struct tg_export_data *ted,
322 struct tg_reply_data *trd)
324 CDEBUG(D_TRACE, "%s: free reply data %p: xid %llu, transno %llu, "
325 "client gen %u, slot idx %d\n",
326 lut == NULL ? "" : tgt_name(lut), trd, trd->trd_reply.lrd_xid,
327 trd->trd_reply.lrd_transno, trd->trd_reply.lrd_client_gen,
330 LASSERT(mutex_is_locked(&ted->ted_lcd_lock));
332 list_del(&trd->trd_list);
333 ted->ted_reply_cnt--;
334 if (lut != NULL && trd->trd_index != TRD_INDEX_MEMORY)
335 tgt_clear_reply_slot(lut, trd->trd_index);
339 /* Release the reply data @trd from target @lut
340 * The reply data with the highest transno for this export
341 * is retained to ensure correctness of target recovery
342 * Called with ted_lcd_lock held
344 static void tgt_release_reply_data(struct lu_target *lut,
345 struct tg_export_data *ted,
346 struct tg_reply_data *trd)
348 CDEBUG(D_TRACE, "%s: release reply data %p: xid %llu, transno %llu, "
349 "client gen %u, slot idx %d\n",
350 lut == NULL ? "" : tgt_name(lut), trd, trd->trd_reply.lrd_xid,
351 trd->trd_reply.lrd_transno, trd->trd_reply.lrd_client_gen,
354 LASSERT(mutex_is_locked(&ted->ted_lcd_lock));
356 /* Do not free the reply data corresponding to the
357 * highest transno of this export.
358 * This ensures on-disk reply data is kept and
359 * last committed transno can be restored from disk in case
362 if (trd->trd_reply.lrd_transno == ted->ted_lcd->lcd_last_transno) {
363 /* free previous retained reply */
364 if (ted->ted_reply_last != NULL)
365 tgt_free_reply_data(lut, ted, ted->ted_reply_last);
366 /* retain the reply */
367 list_del_init(&trd->trd_list);
368 ted->ted_reply_last = trd;
370 tgt_free_reply_data(lut, ted, trd);
374 static inline struct lu_buf *tti_buf_lsd(struct tgt_thread_info *tti)
376 tti->tti_buf.lb_buf = &tti->tti_lsd;
377 tti->tti_buf.lb_len = sizeof(tti->tti_lsd);
378 return &tti->tti_buf;
381 static inline struct lu_buf *tti_buf_lcd(struct tgt_thread_info *tti)
383 tti->tti_buf.lb_buf = &tti->tti_lcd;
384 tti->tti_buf.lb_len = sizeof(tti->tti_lcd);
385 return &tti->tti_buf;
389 * Allocate in-memory data for client slot related to export.
391 int tgt_client_alloc(struct obd_export *exp)
394 LASSERT(exp != exp->exp_obd->obd_self_export);
396 spin_lock_init(&exp->exp_target_data.ted_nodemap_lock);
397 INIT_LIST_HEAD(&exp->exp_target_data.ted_nodemap_member);
398 spin_lock_init(&exp->exp_target_data.ted_fmd_lock);
399 INIT_LIST_HEAD(&exp->exp_target_data.ted_fmd_list);
401 OBD_ALLOC_PTR(exp->exp_target_data.ted_lcd);
402 if (exp->exp_target_data.ted_lcd == NULL)
404 /* Mark that slot is not yet valid, 0 doesn't work here */
405 exp->exp_target_data.ted_lr_idx = -1;
406 INIT_LIST_HEAD(&exp->exp_target_data.ted_reply_list);
407 mutex_init(&exp->exp_target_data.ted_lcd_lock);
410 EXPORT_SYMBOL(tgt_client_alloc);
413 * Free in-memory data for client slot related to export.
415 void tgt_client_free(struct obd_export *exp)
417 struct tg_export_data *ted = &exp->exp_target_data;
418 struct lu_target *lut = class_exp2tgt(exp);
419 struct tg_reply_data *trd, *tmp;
421 LASSERT(exp != exp->exp_obd->obd_self_export);
423 tgt_fmd_cleanup(exp);
425 /* free reply data */
426 mutex_lock(&ted->ted_lcd_lock);
427 list_for_each_entry_safe(trd, tmp, &ted->ted_reply_list, trd_list) {
428 tgt_release_reply_data(lut, ted, trd);
430 if (ted->ted_reply_last != NULL) {
431 tgt_free_reply_data(lut, ted, ted->ted_reply_last);
432 ted->ted_reply_last = NULL;
434 mutex_unlock(&ted->ted_lcd_lock);
436 if (!hlist_unhashed(&exp->exp_gen_hash))
437 cfs_hash_del(exp->exp_obd->obd_gen_hash,
438 &ted->ted_lcd->lcd_generation,
441 OBD_FREE_PTR(ted->ted_lcd);
444 /* Target may have been freed (see LU-7430)
445 * Slot may be not yet assigned */
446 if (exp->exp_obd->u.obt.obt_magic != OBT_MAGIC ||
450 /* Clear bit when lcd is freed */
451 LASSERT(lut && lut->lut_client_bitmap);
452 if (!test_and_clear_bit(ted->ted_lr_idx, lut->lut_client_bitmap)) {
453 CERROR("%s: client %u bit already clear in bitmap\n",
454 exp->exp_obd->obd_name, ted->ted_lr_idx);
458 if (tgt_is_multimodrpcs_client(exp) && !exp->exp_obd->obd_stopping)
459 atomic_dec(&lut->lut_num_clients);
461 EXPORT_SYMBOL(tgt_client_free);
463 static inline void tgt_check_lcd(const char *obd_name, int index,
464 struct lsd_client_data *lcd)
466 size_t uuid_size = sizeof(lcd->lcd_uuid);
468 if (strnlen((char*)lcd->lcd_uuid, uuid_size) == uuid_size) {
469 lcd->lcd_uuid[uuid_size - 1] = '\0';
471 LCONSOLE_ERROR("the client UUID (%s) on %s for exports stored in last_rcvd(index = %d) is bad!\n",
472 lcd->lcd_uuid, obd_name, index);
476 static int tgt_client_data_read(const struct lu_env *env, struct lu_target *tgt,
477 struct lsd_client_data *lcd,
478 loff_t *off, int index)
480 struct tgt_thread_info *tti = tgt_th_info(env);
484 rc = dt_record_read(env, tgt->lut_last_rcvd, &tti->tti_buf, off);
486 tgt_check_lcd(tgt->lut_obd->obd_name, index, &tti->tti_lcd);
487 lcd_le_to_cpu(&tti->tti_lcd, lcd);
488 lcd->lcd_last_result = ptlrpc_status_ntoh(lcd->lcd_last_result);
489 lcd->lcd_last_close_result =
490 ptlrpc_status_ntoh(lcd->lcd_last_close_result);
493 CDEBUG(D_INFO, "%s: read lcd @%lld uuid = %s, last_transno = %llu"
494 ", last_xid = %llu, last_result = %u, last_data = %u, "
495 "last_close_transno = %llu, last_close_xid = %llu, "
496 "last_close_result = %u, rc = %d\n", tgt->lut_obd->obd_name,
497 *off, lcd->lcd_uuid, lcd->lcd_last_transno, lcd->lcd_last_xid,
498 lcd->lcd_last_result, lcd->lcd_last_data,
499 lcd->lcd_last_close_transno, lcd->lcd_last_close_xid,
500 lcd->lcd_last_close_result, rc);
504 static int tgt_client_data_write(const struct lu_env *env,
505 struct lu_target *tgt,
506 struct lsd_client_data *lcd,
507 loff_t *off, struct thandle *th)
509 struct tgt_thread_info *tti = tgt_th_info(env);
510 struct dt_object *dto;
512 lcd->lcd_last_result = ptlrpc_status_hton(lcd->lcd_last_result);
513 lcd->lcd_last_close_result =
514 ptlrpc_status_hton(lcd->lcd_last_close_result);
515 lcd_cpu_to_le(lcd, &tti->tti_lcd);
518 dto = dt_object_locate(tgt->lut_last_rcvd, th->th_dev);
519 return dt_record_write(env, dto, &tti->tti_buf, off, th);
522 struct tgt_new_client_callback {
523 struct dt_txn_commit_cb lncc_cb;
524 struct obd_export *lncc_exp;
527 static void tgt_cb_new_client(struct lu_env *env, struct thandle *th,
528 struct dt_txn_commit_cb *cb, int err)
530 struct tgt_new_client_callback *ccb;
532 ccb = container_of0(cb, struct tgt_new_client_callback, lncc_cb);
534 LASSERT(ccb->lncc_exp->exp_obd);
536 CDEBUG(D_RPCTRACE, "%s: committing for initial connect of %s\n",
537 ccb->lncc_exp->exp_obd->obd_name,
538 ccb->lncc_exp->exp_client_uuid.uuid);
540 spin_lock(&ccb->lncc_exp->exp_lock);
542 ccb->lncc_exp->exp_need_sync = 0;
544 spin_unlock(&ccb->lncc_exp->exp_lock);
545 class_export_cb_put(ccb->lncc_exp);
550 int tgt_new_client_cb_add(struct thandle *th, struct obd_export *exp)
552 struct tgt_new_client_callback *ccb;
553 struct dt_txn_commit_cb *dcb;
560 ccb->lncc_exp = class_export_cb_get(exp);
563 dcb->dcb_func = tgt_cb_new_client;
564 INIT_LIST_HEAD(&dcb->dcb_linkage);
565 strlcpy(dcb->dcb_name, "tgt_cb_new_client", sizeof(dcb->dcb_name));
567 rc = dt_trans_cb_add(th, dcb);
569 class_export_cb_put(exp);
576 * Update client data in last_rcvd
578 static int tgt_client_data_update(const struct lu_env *env,
579 struct obd_export *exp)
581 struct tg_export_data *ted = &exp->exp_target_data;
582 struct lu_target *tgt = class_exp2tgt(exp);
583 struct tgt_thread_info *tti = tgt_th_info(env);
589 if (unlikely(tgt == NULL)) {
590 CDEBUG(D_ERROR, "%s: No target for connected export\n",
591 class_exp2obd(exp)->obd_name);
595 if (tgt->lut_bottom->dd_rdonly)
598 th = dt_trans_create(env, tgt->lut_bottom);
603 rc = dt_declare_record_write(env, tgt->lut_last_rcvd,
605 ted->ted_lr_off, th);
609 rc = dt_trans_start_local(env, tgt->lut_bottom, th);
613 mutex_lock(&ted->ted_lcd_lock);
616 * Until this operations will be committed the sync is needed
617 * for this export. This should be done _after_ starting the
618 * transaction so that many connecting clients will not bring
619 * server down with lots of sync writes.
621 rc = tgt_new_client_cb_add(th, exp);
623 /* can't add callback, do sync now */
626 spin_lock(&exp->exp_lock);
627 exp->exp_need_sync = 1;
628 spin_unlock(&exp->exp_lock);
631 tti->tti_off = ted->ted_lr_off;
632 rc = tgt_client_data_write(env, tgt, ted->ted_lcd, &tti->tti_off, th);
634 mutex_unlock(&ted->ted_lcd_lock);
638 dt_trans_stop(env, tgt->lut_bottom, th);
639 CDEBUG(D_INFO, "%s: update last_rcvd client data for UUID = %s, "
640 "last_transno = %llu: rc = %d\n", tgt->lut_obd->obd_name,
641 tgt->lut_lsd.lsd_uuid, tgt->lut_lsd.lsd_last_transno, rc);
646 static int tgt_server_data_read(const struct lu_env *env, struct lu_target *tgt)
648 struct tgt_thread_info *tti = tgt_th_info(env);
653 rc = dt_record_read(env, tgt->lut_last_rcvd, &tti->tti_buf,
656 lsd_le_to_cpu(&tti->tti_lsd, &tgt->lut_lsd);
658 CDEBUG(D_INFO, "%s: read last_rcvd server data for UUID = %s, "
659 "last_transno = %llu: rc = %d\n", tgt->lut_obd->obd_name,
660 tgt->lut_lsd.lsd_uuid, tgt->lut_lsd.lsd_last_transno, rc);
664 static int tgt_server_data_write(const struct lu_env *env,
665 struct lu_target *tgt, struct thandle *th)
667 struct tgt_thread_info *tti = tgt_th_info(env);
668 struct dt_object *dto;
675 lsd_cpu_to_le(&tgt->lut_lsd, &tti->tti_lsd);
677 dto = dt_object_locate(tgt->lut_last_rcvd, th->th_dev);
678 rc = dt_record_write(env, dto, &tti->tti_buf, &tti->tti_off, th);
680 CDEBUG(D_INFO, "%s: write last_rcvd server data for UUID = %s, "
681 "last_transno = %llu: rc = %d\n", tgt->lut_obd->obd_name,
682 tgt->lut_lsd.lsd_uuid, tgt->lut_lsd.lsd_last_transno, rc);
688 * Update server data in last_rcvd
690 int tgt_server_data_update(const struct lu_env *env, struct lu_target *tgt,
693 struct tgt_thread_info *tti = tgt_th_info(env);
700 "%s: mount_count is %llu, last_transno is %llu\n",
701 tgt->lut_lsd.lsd_uuid, tgt->lut_obd->u.obt.obt_mount_count,
702 tgt->lut_last_transno);
704 /* Always save latest transno to keep it fresh */
705 spin_lock(&tgt->lut_translock);
706 tgt->lut_lsd.lsd_last_transno = tgt->lut_last_transno;
707 spin_unlock(&tgt->lut_translock);
709 if (tgt->lut_bottom->dd_rdonly)
712 th = dt_trans_create(env, tgt->lut_bottom);
719 rc = dt_declare_record_write(env, tgt->lut_last_rcvd,
720 &tti->tti_buf, tti->tti_off, th);
724 rc = dt_trans_start(env, tgt->lut_bottom, th);
728 rc = tgt_server_data_write(env, tgt, th);
730 dt_trans_stop(env, tgt->lut_bottom, th);
732 CDEBUG(D_INFO, "%s: update last_rcvd server data for UUID = %s, "
733 "last_transno = %llu: rc = %d\n", tgt->lut_obd->obd_name,
734 tgt->lut_lsd.lsd_uuid, tgt->lut_lsd.lsd_last_transno, rc);
737 EXPORT_SYMBOL(tgt_server_data_update);
739 static int tgt_truncate_last_rcvd(const struct lu_env *env,
740 struct lu_target *tgt, loff_t size)
742 struct dt_object *dt = tgt->lut_last_rcvd;
749 if (tgt->lut_bottom->dd_rdonly)
753 attr.la_valid = LA_SIZE;
755 th = dt_trans_create(env, tgt->lut_bottom);
758 rc = dt_declare_punch(env, dt, size, OBD_OBJECT_EOF, th);
761 rc = dt_declare_attr_set(env, dt, &attr, th);
764 rc = dt_trans_start_local(env, tgt->lut_bottom, th);
768 rc = dt_punch(env, dt, size, OBD_OBJECT_EOF, th);
770 rc = dt_attr_set(env, dt, &attr, th);
773 dt_trans_stop(env, tgt->lut_bottom, th);
778 static void tgt_client_epoch_update(const struct lu_env *env,
779 struct obd_export *exp)
781 struct lsd_client_data *lcd = exp->exp_target_data.ted_lcd;
782 struct lu_target *tgt = class_exp2tgt(exp);
784 LASSERT(tgt && tgt->lut_bottom);
785 /** VBR: set client last_epoch to current epoch */
786 if (lcd->lcd_last_epoch >= tgt->lut_lsd.lsd_start_epoch)
788 lcd->lcd_last_epoch = tgt->lut_lsd.lsd_start_epoch;
789 tgt_client_data_update(env, exp);
793 * Update boot epoch when recovery ends
795 void tgt_boot_epoch_update(struct lu_target *tgt)
798 struct ptlrpc_request *req;
800 LIST_HEAD(client_list);
803 if (tgt->lut_obd->obd_stopping)
806 rc = lu_env_init(&env, LCT_DT_THREAD);
808 CERROR("%s: can't initialize environment: rc = %d\n",
809 tgt->lut_obd->obd_name, rc);
813 spin_lock(&tgt->lut_translock);
814 start_epoch = (tgt->lut_last_transno >> LR_EPOCH_BITS) + 1;
815 tgt->lut_last_transno = (__u64)start_epoch << LR_EPOCH_BITS;
816 tgt->lut_lsd.lsd_start_epoch = start_epoch;
817 spin_unlock(&tgt->lut_translock);
820 * The recovery is not yet finished and final queue can still be updated
821 * with resend requests. Move final list to separate one for processing
823 spin_lock(&tgt->lut_obd->obd_recovery_task_lock);
824 list_splice_init(&tgt->lut_obd->obd_final_req_queue, &client_list);
825 spin_unlock(&tgt->lut_obd->obd_recovery_task_lock);
828 * go through list of exports participated in recovery and
829 * set new epoch for them
831 list_for_each_entry(req, &client_list, rq_list) {
832 LASSERT(!req->rq_export->exp_delayed);
833 if (!req->rq_export->exp_vbr_failed)
834 tgt_client_epoch_update(&env, req->rq_export);
836 /** return list back at once */
837 spin_lock(&tgt->lut_obd->obd_recovery_task_lock);
838 list_splice_init(&client_list, &tgt->lut_obd->obd_final_req_queue);
839 spin_unlock(&tgt->lut_obd->obd_recovery_task_lock);
841 /** Clear MULTI RPCS incompatibility flag if
842 * - target is MDT and
843 * - there is no client to recover or the recovery was aborted
845 if (!strncmp(tgt->lut_obd->obd_type->typ_name, LUSTRE_MDT_NAME, 3) &&
846 (atomic_read(&tgt->lut_obd->obd_max_recoverable_clients) == 0 ||
847 tgt->lut_obd->obd_abort_recovery))
848 tgt->lut_lsd.lsd_feature_incompat &= ~OBD_INCOMPAT_MULTI_RPCS;
850 /** update server epoch */
851 tgt_server_data_update(&env, tgt, 1);
856 * commit callback, need to update last_committed value
858 struct tgt_last_committed_callback {
859 struct dt_txn_commit_cb llcc_cb;
860 struct lu_target *llcc_tgt;
861 struct obd_export *llcc_exp;
865 static void tgt_cb_last_committed(struct lu_env *env, struct thandle *th,
866 struct dt_txn_commit_cb *cb, int err)
868 struct tgt_last_committed_callback *ccb;
870 ccb = container_of0(cb, struct tgt_last_committed_callback, llcc_cb);
872 LASSERT(ccb->llcc_exp);
873 LASSERT(ccb->llcc_tgt != NULL);
874 LASSERT(ccb->llcc_exp->exp_obd == ccb->llcc_tgt->lut_obd);
876 /* error hit, don't update last committed to provide chance to
877 * replay data after fail */
881 /* Fast path w/o spinlock, if exp_last_committed was updated
882 * with higher transno, no need to take spinlock and check,
883 * also no need to update obd_last_committed. */
884 if (ccb->llcc_transno <= ccb->llcc_exp->exp_last_committed)
886 spin_lock(&ccb->llcc_tgt->lut_translock);
887 if (ccb->llcc_transno > ccb->llcc_tgt->lut_obd->obd_last_committed)
888 ccb->llcc_tgt->lut_obd->obd_last_committed = ccb->llcc_transno;
890 if (ccb->llcc_transno > ccb->llcc_exp->exp_last_committed) {
891 ccb->llcc_exp->exp_last_committed = ccb->llcc_transno;
892 spin_unlock(&ccb->llcc_tgt->lut_translock);
894 ptlrpc_commit_replies(ccb->llcc_exp);
895 tgt_cancel_slc_locks(ccb->llcc_tgt, ccb->llcc_transno);
897 spin_unlock(&ccb->llcc_tgt->lut_translock);
900 CDEBUG(D_HA, "%s: transno %lld is committed\n",
901 ccb->llcc_tgt->lut_obd->obd_name, ccb->llcc_transno);
904 class_export_cb_put(ccb->llcc_exp);
909 * Add commit callback function, it returns a non-zero value to inform
910 * caller to use sync transaction if necessary.
912 static int tgt_last_commit_cb_add(struct thandle *th, struct lu_target *tgt,
913 struct obd_export *exp, __u64 transno)
915 struct tgt_last_committed_callback *ccb;
916 struct dt_txn_commit_cb *dcb;
924 ccb->llcc_exp = class_export_cb_get(exp);
925 ccb->llcc_transno = transno;
928 dcb->dcb_func = tgt_cb_last_committed;
929 INIT_LIST_HEAD(&dcb->dcb_linkage);
930 strlcpy(dcb->dcb_name, "tgt_cb_last_committed", sizeof(dcb->dcb_name));
932 rc = dt_trans_cb_add(th, dcb);
934 class_export_cb_put(exp);
938 if (exp_connect_flags(exp) & OBD_CONNECT_LIGHTWEIGHT)
939 /* report failure to force synchronous operation */
942 /* if exp_need_sync is set, return non-zero value to force
943 * a sync transaction. */
944 return rc ? rc : exp->exp_need_sync;
948 * Add new client to the last_rcvd upon new connection.
950 * We use a bitmap to locate a free space in the last_rcvd file and initialize
953 int tgt_client_new(const struct lu_env *env, struct obd_export *exp)
955 struct tg_export_data *ted = &exp->exp_target_data;
956 struct lu_target *tgt = class_exp2tgt(exp);
961 LASSERT(tgt && tgt->lut_client_bitmap != NULL);
962 if (!strcmp(ted->ted_lcd->lcd_uuid, tgt->lut_obd->obd_uuid.uuid))
965 if (exp_connect_flags(exp) & OBD_CONNECT_LIGHTWEIGHT)
968 /* the bitmap operations can handle cl_idx > sizeof(long) * 8, so
969 * there's no need for extra complication here
971 idx = find_first_zero_bit(tgt->lut_client_bitmap, LR_MAX_CLIENTS);
973 if (idx >= LR_MAX_CLIENTS ||
974 OBD_FAIL_CHECK(OBD_FAIL_MDS_CLIENT_ADD)) {
975 CERROR("%s: no room for %u clients - fix LR_MAX_CLIENTS\n",
976 tgt->lut_obd->obd_name, idx);
979 if (test_and_set_bit(idx, tgt->lut_client_bitmap)) {
980 idx = find_next_zero_bit(tgt->lut_client_bitmap,
981 LR_MAX_CLIENTS, idx);
985 ted->ted_lr_idx = idx;
986 ted->ted_lr_off = tgt->lut_lsd.lsd_client_start +
987 idx * tgt->lut_lsd.lsd_client_size;
989 LASSERTF(ted->ted_lr_off > 0, "ted_lr_off = %llu\n", ted->ted_lr_off);
991 if (tgt_is_multimodrpcs_client(exp)) {
992 /* Set MULTI RPCS incompatibility flag to prevent previous
993 * Lustre versions to mount a target with reply_data file */
994 atomic_inc(&tgt->lut_num_clients);
995 if (!(tgt->lut_lsd.lsd_feature_incompat &
996 OBD_INCOMPAT_MULTI_RPCS)) {
997 tgt->lut_lsd.lsd_feature_incompat |=
998 OBD_INCOMPAT_MULTI_RPCS;
999 rc = tgt_server_data_update(env, tgt, 1);
1001 CERROR("%s: unable to set MULTI RPCS "
1002 "incompatibility flag\n",
1003 exp->exp_obd->obd_name);
1008 /* assign client slot generation */
1009 ted->ted_lcd->lcd_generation =
1010 atomic_inc_return(&tgt->lut_client_generation);
1012 ted->ted_lcd->lcd_generation = 0;
1015 CDEBUG(D_INFO, "%s: new client at index %d (%llu) with UUID '%s' "
1017 tgt->lut_obd->obd_name, ted->ted_lr_idx, ted->ted_lr_off,
1018 ted->ted_lcd->lcd_uuid, ted->ted_lcd->lcd_generation);
1020 if (OBD_FAIL_CHECK(OBD_FAIL_TGT_CLIENT_ADD))
1023 rc = tgt_client_data_update(env, exp);
1025 CERROR("%s: Failed to write client lcd at idx %d, rc %d\n",
1026 tgt->lut_obd->obd_name, idx, rc);
1030 EXPORT_SYMBOL(tgt_client_new);
1032 /* Add an existing client to the MDS in-memory state based on
1033 * a client that was previously found in the last_rcvd file and
1034 * already has an assigned slot (idx >= 0).
1036 * It should not be possible to fail adding an existing client - otherwise
1037 * mdt_init_server_data() callsite needs to be fixed.
1039 int tgt_client_add(const struct lu_env *env, struct obd_export *exp, int idx)
1041 struct tg_export_data *ted = &exp->exp_target_data;
1042 struct lu_target *tgt = class_exp2tgt(exp);
1046 LASSERT(tgt && tgt->lut_client_bitmap != NULL);
1047 LASSERTF(idx >= 0, "%d\n", idx);
1049 if (!strcmp(ted->ted_lcd->lcd_uuid, tgt->lut_obd->obd_uuid.uuid) ||
1050 exp_connect_flags(exp) & OBD_CONNECT_LIGHTWEIGHT)
1053 if (test_and_set_bit(idx, tgt->lut_client_bitmap)) {
1054 CERROR("%s: client %d: bit already set in bitmap!!\n",
1055 tgt->lut_obd->obd_name, idx);
1058 atomic_inc(&tgt->lut_num_clients);
1060 CDEBUG(D_INFO, "%s: client at idx %d with UUID '%s' added, "
1062 tgt->lut_obd->obd_name, idx, ted->ted_lcd->lcd_uuid,
1063 ted->ted_lcd->lcd_generation);
1065 ted->ted_lr_idx = idx;
1066 ted->ted_lr_off = tgt->lut_lsd.lsd_client_start +
1067 idx * tgt->lut_lsd.lsd_client_size;
1069 mutex_init(&ted->ted_lcd_lock);
1071 LASSERTF(ted->ted_lr_off > 0, "ted_lr_off = %llu\n", ted->ted_lr_off);
1076 int tgt_client_del(const struct lu_env *env, struct obd_export *exp)
1078 struct tg_export_data *ted = &exp->exp_target_data;
1079 struct lu_target *tgt = class_exp2tgt(exp);
1084 LASSERT(ted->ted_lcd);
1086 if (unlikely(tgt == NULL)) {
1087 CDEBUG(D_ERROR, "%s: No target for connected export\n",
1088 class_exp2obd(exp)->obd_name);
1092 /* XXX if lcd_uuid were a real obd_uuid, I could use obd_uuid_equals */
1093 if (!strcmp((char *)ted->ted_lcd->lcd_uuid,
1094 (char *)tgt->lut_obd->obd_uuid.uuid) ||
1095 exp_connect_flags(exp) & OBD_CONNECT_LIGHTWEIGHT)
1098 /* Slot may be not yet assigned, use case is race between Client
1099 * reconnect and forced eviction */
1100 if (ted->ted_lr_idx < 0) {
1101 CWARN("%s: client with UUID '%s' not in bitmap\n",
1102 tgt->lut_obd->obd_name, ted->ted_lcd->lcd_uuid);
1106 CDEBUG(D_INFO, "%s: del client at idx %u, off %lld, UUID '%s'\n",
1107 tgt->lut_obd->obd_name, ted->ted_lr_idx, ted->ted_lr_off,
1108 ted->ted_lcd->lcd_uuid);
1110 /* Clear the bit _after_ zeroing out the client so we don't
1111 race with filter_client_add and zero out new clients.*/
1112 if (!test_bit(ted->ted_lr_idx, tgt->lut_client_bitmap)) {
1113 CERROR("%s: client %u: bit already clear in bitmap!!\n",
1114 tgt->lut_obd->obd_name, ted->ted_lr_idx);
1118 /* Do not erase record for recoverable client. */
1119 if (exp->exp_flags & OBD_OPT_FAILOVER)
1122 if (OBD_FAIL_CHECK(OBD_FAIL_TGT_CLIENT_DEL))
1125 /* Make sure the server's last_transno is up to date.
1126 * This should be done before zeroing client slot so last_transno will
1127 * be in server data or in client data in case of failure */
1128 rc = tgt_server_data_update(env, tgt, 0);
1130 CERROR("%s: failed to update server data, skip client %s "
1131 "zeroing, rc %d\n", tgt->lut_obd->obd_name,
1132 ted->ted_lcd->lcd_uuid, rc);
1136 memset(ted->ted_lcd->lcd_uuid, 0, sizeof ted->ted_lcd->lcd_uuid);
1137 rc = tgt_client_data_update(env, exp);
1139 CDEBUG(rc == 0 ? D_INFO : D_ERROR,
1140 "%s: zeroing out client %s at idx %u (%llu), rc %d\n",
1141 tgt->lut_obd->obd_name, ted->ted_lcd->lcd_uuid,
1142 ted->ted_lr_idx, ted->ted_lr_off, rc);
1145 EXPORT_SYMBOL(tgt_client_del);
1147 static void tgt_clean_by_tag(struct obd_export *exp, __u64 xid, __u16 tag)
1149 struct tg_export_data *ted = &exp->exp_target_data;
1150 struct lu_target *lut = class_exp2tgt(exp);
1151 struct tg_reply_data *trd, *tmp;
1156 list_for_each_entry_safe(trd, tmp, &ted->ted_reply_list, trd_list) {
1157 if (trd->trd_tag != tag)
1160 LASSERT(ergo(tgt_is_increasing_xid_client(exp),
1161 trd->trd_reply.lrd_xid <= xid));
1163 ted->ted_release_tag++;
1164 tgt_release_reply_data(lut, ted, trd);
1168 static int tgt_add_reply_data(const struct lu_env *env, struct lu_target *tgt,
1169 struct tg_export_data *ted, struct tg_reply_data *trd,
1170 struct ptlrpc_request *req,
1171 struct thandle *th, bool update_lrd_file)
1173 struct lsd_reply_data *lrd;
1176 lrd = &trd->trd_reply;
1177 /* update export last transno */
1178 mutex_lock(&ted->ted_lcd_lock);
1179 if (lrd->lrd_transno > ted->ted_lcd->lcd_last_transno)
1180 ted->ted_lcd->lcd_last_transno = lrd->lrd_transno;
1181 mutex_unlock(&ted->ted_lcd_lock);
1184 /* find a empty slot */
1185 i = tgt_find_free_reply_slot(tgt);
1186 if (unlikely(i < 0)) {
1187 CERROR("%s: couldn't find a slot for reply data: "
1188 "rc = %d\n", tgt_name(tgt), i);
1193 if (update_lrd_file) {
1197 /* write reply data to disk */
1198 off = sizeof(struct lsd_reply_header) + sizeof(*lrd) * i;
1199 rc = tgt_reply_data_write(env, tgt, lrd, off, th);
1200 if (unlikely(rc != 0)) {
1201 CERROR("%s: can't update %s file: rc = %d\n",
1202 tgt_name(tgt), REPLY_DATA, rc);
1207 trd->trd_index = TRD_INDEX_MEMORY;
1210 /* add reply data to target export's reply list */
1211 mutex_lock(&ted->ted_lcd_lock);
1213 int exclude = tgt_is_increasing_xid_client(req->rq_export) ?
1214 MSG_REPLAY : MSG_REPLAY|MSG_RESENT;
1216 if (req->rq_obsolete) {
1217 mutex_unlock(&ted->ted_lcd_lock);
1221 if (!(lustre_msg_get_flags(req->rq_reqmsg) & exclude))
1222 tgt_clean_by_tag(req->rq_export, req->rq_xid,
1225 list_add(&trd->trd_list, &ted->ted_reply_list);
1226 ted->ted_reply_cnt++;
1227 if (ted->ted_reply_cnt > ted->ted_reply_max)
1228 ted->ted_reply_max = ted->ted_reply_cnt;
1229 mutex_unlock(&ted->ted_lcd_lock);
1231 CDEBUG(D_TRACE, "add reply %p: xid %llu, transno %llu, "
1232 "tag %hu, client gen %u, slot idx %d\n",
1233 trd, lrd->lrd_xid, lrd->lrd_transno,
1234 trd->trd_tag, lrd->lrd_client_gen, trd->trd_index);
1239 int tgt_mk_reply_data(const struct lu_env *env,
1240 struct lu_target *tgt,
1241 struct tg_export_data *ted,
1242 struct ptlrpc_request *req,
1248 struct tg_reply_data *trd;
1249 struct lsd_reply_data *lrd;
1250 __u64 *pre_versions = NULL;
1254 if (unlikely(trd == NULL))
1257 /* fill reply data information */
1258 lrd = &trd->trd_reply;
1259 lrd->lrd_transno = transno;
1261 lrd->lrd_xid = req->rq_xid;
1262 trd->trd_tag = lustre_msg_get_tag(req->rq_reqmsg);
1263 lrd->lrd_client_gen = ted->ted_lcd->lcd_generation;
1265 pre_versions = lustre_msg_get_versions(req->rq_repmsg);
1266 lrd->lrd_result = th->th_result;
1269 struct tgt_session_info *tsi;
1271 LASSERT(env != NULL);
1272 tsi = tgt_ses_info(env);
1273 LASSERT(tsi->tsi_xid != 0);
1275 lrd->lrd_xid = tsi->tsi_xid;
1276 lrd->lrd_result = tsi->tsi_result;
1277 lrd->lrd_client_gen = tsi->tsi_client_gen;
1280 lrd->lrd_data = opdata;
1282 trd->trd_pre_versions[0] = pre_versions[0];
1283 trd->trd_pre_versions[1] = pre_versions[1];
1284 trd->trd_pre_versions[2] = pre_versions[2];
1285 trd->trd_pre_versions[3] = pre_versions[3];
1288 rc = tgt_add_reply_data(env, tgt, ted, trd, req,
1295 EXPORT_SYMBOL(tgt_mk_reply_data);
1298 * last_rcvd & last_committed update callbacks
1300 static int tgt_last_rcvd_update(const struct lu_env *env, struct lu_target *tgt,
1301 struct dt_object *obj, __u64 opdata,
1302 struct thandle *th, struct ptlrpc_request *req)
1304 struct tgt_thread_info *tti = tgt_th_info(env);
1305 struct tgt_session_info *tsi = tgt_ses_info(env);
1306 struct obd_export *exp = tsi->tsi_exp;
1307 struct tg_export_data *ted;
1315 LASSERT(exp != NULL);
1316 ted = &exp->exp_target_data;
1318 lw_client = exp_connect_flags(exp) & OBD_CONNECT_LIGHTWEIGHT;
1319 if (ted->ted_lr_idx < 0 && !lw_client)
1320 /* ofd connect may cause transaction before export has
1325 tti->tti_transno = lustre_msg_get_transno(req->rq_reqmsg);
1327 /* From update replay, tti_transno should be set already */
1328 LASSERT(tti->tti_transno != 0);
1330 spin_lock(&tgt->lut_translock);
1331 if (th->th_result != 0) {
1332 if (tti->tti_transno != 0) {
1333 CERROR("%s: replay transno %llu failed: rc = %d\n",
1334 tgt_name(tgt), tti->tti_transno, th->th_result);
1336 } else if (tti->tti_transno == 0) {
1337 tti->tti_transno = ++tgt->lut_last_transno;
1339 /* should be replay */
1340 if (tti->tti_transno > tgt->lut_last_transno)
1341 tgt->lut_last_transno = tti->tti_transno;
1343 spin_unlock(&tgt->lut_translock);
1345 /** VBR: set new versions */
1346 if (th->th_result == 0 && obj != NULL) {
1347 struct dt_object *dto = dt_object_locate(obj, th->th_dev);
1348 dt_version_set(env, dto, tti->tti_transno, th);
1351 /* filling reply data */
1352 CDEBUG(D_INODE, "transno = %llu, last_committed = %llu\n",
1353 tti->tti_transno, tgt->lut_obd->obd_last_committed);
1356 req->rq_transno = tti->tti_transno;
1357 lustre_msg_set_transno(req->rq_repmsg, tti->tti_transno);
1360 /* if can't add callback, do sync write */
1361 th->th_sync |= !!tgt_last_commit_cb_add(th, tgt, exp, tti->tti_transno);
1364 /* All operations performed by LW clients are synchronous and
1365 * we store the committed transno in the last_rcvd header */
1366 spin_lock(&tgt->lut_translock);
1367 if (tti->tti_transno > tgt->lut_lsd.lsd_last_transno) {
1368 tgt->lut_lsd.lsd_last_transno = tti->tti_transno;
1369 spin_unlock(&tgt->lut_translock);
1370 /* Although lightweight (LW) connections have no slot
1371 * in the last_rcvd, we still want to maintain
1372 * the in-memory lsd_client_data structure in order to
1373 * properly handle reply reconstruction. */
1374 rc = tgt_server_data_write(env, tgt, th);
1376 spin_unlock(&tgt->lut_translock);
1378 } else if (ted->ted_lr_off == 0) {
1379 CERROR("%s: client idx %d has offset %lld\n",
1380 tgt_name(tgt), ted->ted_lr_idx, ted->ted_lr_off);
1384 /* Target that supports multiple reply data */
1385 if (tgt_is_multimodrpcs_client(exp)) {
1386 return tgt_mk_reply_data(env, tgt, ted, req, opdata, th,
1387 !!(req != NULL), tti->tti_transno);
1390 /* Enough for update replay, let's return */
1394 mutex_lock(&ted->ted_lcd_lock);
1395 LASSERT(ergo(tti->tti_transno == 0, th->th_result != 0));
1396 if (lustre_msg_get_opc(req->rq_reqmsg) == MDS_CLOSE) {
1397 transno_p = &ted->ted_lcd->lcd_last_close_transno;
1398 ted->ted_lcd->lcd_last_close_xid = req->rq_xid;
1399 ted->ted_lcd->lcd_last_close_result = th->th_result;
1401 /* VBR: save versions in last_rcvd for reconstruct. */
1402 __u64 *pre_versions = lustre_msg_get_versions(req->rq_repmsg);
1405 ted->ted_lcd->lcd_pre_versions[0] = pre_versions[0];
1406 ted->ted_lcd->lcd_pre_versions[1] = pre_versions[1];
1407 ted->ted_lcd->lcd_pre_versions[2] = pre_versions[2];
1408 ted->ted_lcd->lcd_pre_versions[3] = pre_versions[3];
1410 transno_p = &ted->ted_lcd->lcd_last_transno;
1411 ted->ted_lcd->lcd_last_xid = req->rq_xid;
1412 ted->ted_lcd->lcd_last_result = th->th_result;
1413 /* XXX: lcd_last_data is __u32 but intent_dispostion is __u64,
1414 * see struct ldlm_reply->lock_policy_res1; */
1415 ted->ted_lcd->lcd_last_data = opdata;
1418 /* Update transno in slot only if non-zero number, i.e. no errors */
1419 if (likely(tti->tti_transno != 0)) {
1420 /* Don't overwrite bigger transaction number with lower one.
1421 * That is not sign of problem in all cases, but in any case
1422 * this value should be monotonically increased only. */
1423 if (*transno_p > tti->tti_transno) {
1424 if (!tgt->lut_no_reconstruct) {
1425 CERROR("%s: trying to overwrite bigger transno:"
1426 "on-disk: %llu, new: %llu replay: "
1427 "%d. See LU-617.\n", tgt_name(tgt),
1428 *transno_p, tti->tti_transno,
1429 req_is_replay(req));
1430 if (req_is_replay(req)) {
1431 spin_lock(&req->rq_export->exp_lock);
1432 req->rq_export->exp_vbr_failed = 1;
1433 spin_unlock(&req->rq_export->exp_lock);
1435 mutex_unlock(&ted->ted_lcd_lock);
1436 RETURN(req_is_replay(req) ? -EOVERFLOW : 0);
1439 *transno_p = tti->tti_transno;
1444 tti->tti_off = ted->ted_lr_off;
1445 if (CFS_FAIL_CHECK(OBD_FAIL_TGT_RCVD_EIO))
1448 rc = tgt_client_data_write(env, tgt, ted->ted_lcd,
1451 mutex_unlock(&ted->ted_lcd_lock);
1455 mutex_unlock(&ted->ted_lcd_lock);
1460 * last_rcvd update for echo client simulation.
1461 * It updates last_rcvd client slot and version of object in
1462 * simple way but with all locks to simulate all drawbacks
1464 static int tgt_last_rcvd_update_echo(const struct lu_env *env,
1465 struct lu_target *tgt,
1466 struct dt_object *obj,
1468 struct obd_export *exp)
1470 struct tgt_thread_info *tti = tgt_th_info(env);
1471 struct tg_export_data *ted = &exp->exp_target_data;
1476 tti->tti_transno = 0;
1478 spin_lock(&tgt->lut_translock);
1479 if (th->th_result == 0)
1480 tti->tti_transno = ++tgt->lut_last_transno;
1481 spin_unlock(&tgt->lut_translock);
1483 /** VBR: set new versions */
1484 if (th->th_result == 0 && obj != NULL)
1485 dt_version_set(env, obj, tti->tti_transno, th);
1487 /* if can't add callback, do sync write */
1488 th->th_sync |= !!tgt_last_commit_cb_add(th, tgt, exp,
1491 LASSERT(ted->ted_lr_off > 0);
1493 mutex_lock(&ted->ted_lcd_lock);
1494 LASSERT(ergo(tti->tti_transno == 0, th->th_result != 0));
1495 ted->ted_lcd->lcd_last_transno = tti->tti_transno;
1496 ted->ted_lcd->lcd_last_result = th->th_result;
1498 tti->tti_off = ted->ted_lr_off;
1499 rc = tgt_client_data_write(env, tgt, ted->ted_lcd, &tti->tti_off, th);
1500 mutex_unlock(&ted->ted_lcd_lock);
1504 static int tgt_clients_data_init(const struct lu_env *env,
1505 struct lu_target *tgt,
1506 unsigned long last_size)
1508 struct obd_device *obd = tgt->lut_obd;
1509 struct lr_server_data *lsd = &tgt->lut_lsd;
1510 struct lsd_client_data *lcd = NULL;
1511 struct tg_export_data *ted;
1514 loff_t off = lsd->lsd_client_start;
1515 __u32 generation = 0;
1516 struct cfs_hash *hash = NULL;
1520 if (tgt->lut_bottom->dd_rdonly)
1523 BUILD_BUG_ON(offsetof(struct lsd_client_data, lcd_padding) +
1524 sizeof(lcd->lcd_padding) != LR_CLIENT_SIZE);
1530 hash = cfs_hash_getref(tgt->lut_obd->obd_gen_hash);
1532 GOTO(err_out, rc = -ENODEV);
1534 for (cl_idx = 0; off < last_size; cl_idx++) {
1535 struct obd_export *exp;
1538 /* Don't assume off is incremented properly by
1539 * read_record(), in case sizeof(*lcd)
1540 * isn't the same as fsd->lsd_client_size. */
1541 off = lsd->lsd_client_start + cl_idx * lsd->lsd_client_size;
1542 rc = tgt_client_data_read(env, tgt, lcd, &off, cl_idx);
1544 CERROR("%s: error reading last_rcvd %s idx %d off "
1545 "%llu: rc = %d\n", tgt_name(tgt), LAST_RCVD,
1548 break; /* read error shouldn't cause startup to fail */
1551 if (lcd->lcd_uuid[0] == '\0') {
1552 CDEBUG(D_INFO, "skipping zeroed client at offset %d\n",
1557 last_transno = lcd_last_transno(lcd);
1559 /* These exports are cleaned up by disconnect, so they
1560 * need to be set up like real exports as connect does.
1562 CDEBUG(D_HA, "RCVRNG CLIENT uuid: %s idx: %d lr: %llu"
1563 " srv lr: %llu lx: %llu gen %u\n", lcd->lcd_uuid,
1564 cl_idx, last_transno, lsd->lsd_last_transno,
1565 lcd_last_xid(lcd), lcd->lcd_generation);
1567 exp = class_new_export(obd, (struct obd_uuid *)lcd->lcd_uuid);
1569 if (PTR_ERR(exp) == -EALREADY) {
1570 /* export already exists, zero out this one */
1571 CERROR("%s: Duplicate export %s!\n",
1572 tgt_name(tgt), lcd->lcd_uuid);
1575 GOTO(err_out, rc = PTR_ERR(exp));
1578 ted = &exp->exp_target_data;
1579 *ted->ted_lcd = *lcd;
1581 rc = tgt_client_add(env, exp, cl_idx);
1582 LASSERTF(rc == 0, "rc = %d\n", rc); /* can't fail existing */
1583 /* VBR: set export last committed version */
1584 exp->exp_last_committed = last_transno;
1585 spin_lock(&exp->exp_lock);
1586 exp->exp_connecting = 0;
1587 exp->exp_in_recovery = 0;
1588 spin_unlock(&exp->exp_lock);
1589 atomic_inc(&obd->obd_max_recoverable_clients);
1591 if (tgt->lut_lsd.lsd_feature_incompat &
1592 OBD_INCOMPAT_MULTI_RPCS &&
1593 lcd->lcd_generation != 0) {
1594 /* compute the highest valid client generation */
1595 generation = max(generation, lcd->lcd_generation);
1596 /* fill client_generation <-> export hash table */
1597 rc = cfs_hash_add_unique(hash, &lcd->lcd_generation,
1598 &exp->exp_gen_hash);
1600 CERROR("%s: duplicate export for client "
1602 tgt_name(tgt), lcd->lcd_generation);
1603 class_export_put(exp);
1608 class_export_put(exp);
1610 rc = rev_import_init(exp);
1612 class_unlink_export(exp);
1616 /* Need to check last_rcvd even for duplicated exports. */
1617 CDEBUG(D_OTHER, "client at idx %d has last_transno = %llu\n",
1618 cl_idx, last_transno);
1620 spin_lock(&tgt->lut_translock);
1621 tgt->lut_last_transno = max(last_transno,
1622 tgt->lut_last_transno);
1623 spin_unlock(&tgt->lut_translock);
1626 /* record highest valid client generation */
1627 atomic_set(&tgt->lut_client_generation, generation);
1631 cfs_hash_putref(hash);
1636 struct server_compat_data {
1643 static struct server_compat_data tgt_scd[] = {
1644 [LDD_F_SV_TYPE_MDT] = {
1645 .rocompat = OBD_ROCOMPAT_LOVOBJID,
1646 .incompat = OBD_INCOMPAT_MDT | OBD_INCOMPAT_COMMON_LR |
1647 OBD_INCOMPAT_FID | OBD_INCOMPAT_IAM_DIR |
1648 OBD_INCOMPAT_LMM_VER | OBD_INCOMPAT_MULTI_OI |
1649 OBD_INCOMPAT_MULTI_RPCS,
1650 .rocinit = OBD_ROCOMPAT_LOVOBJID,
1651 .incinit = OBD_INCOMPAT_MDT | OBD_INCOMPAT_COMMON_LR |
1652 OBD_INCOMPAT_MULTI_OI,
1654 [LDD_F_SV_TYPE_OST] = {
1655 .rocompat = OBD_ROCOMPAT_IDX_IN_IDIF,
1656 .incompat = OBD_INCOMPAT_OST | OBD_INCOMPAT_COMMON_LR |
1658 .rocinit = OBD_ROCOMPAT_IDX_IN_IDIF,
1659 .incinit = OBD_INCOMPAT_OST | OBD_INCOMPAT_COMMON_LR,
1663 int tgt_server_data_init(const struct lu_env *env, struct lu_target *tgt)
1665 struct tgt_thread_info *tti = tgt_th_info(env);
1666 struct lr_server_data *lsd = &tgt->lut_lsd;
1667 unsigned long last_rcvd_size;
1671 rc = dt_attr_get(env, tgt->lut_last_rcvd, &tti->tti_attr);
1675 last_rcvd_size = (unsigned long)tti->tti_attr.la_size;
1677 /* ensure padding in the struct is the correct size */
1678 BUILD_BUG_ON(offsetof(struct lr_server_data, lsd_padding) +
1679 sizeof(lsd->lsd_padding) != LR_SERVER_SIZE);
1681 rc = server_name2index(tgt_name(tgt), &index, NULL);
1683 CERROR("%s: Can not get index from name: rc = %d\n",
1687 /* server_name2index() returns type */
1689 if (type != LDD_F_SV_TYPE_MDT && type != LDD_F_SV_TYPE_OST) {
1690 CERROR("%s: unknown target type %x\n", tgt_name(tgt), type);
1694 /* last_rcvd on OST doesn't provide reconstruct support because there
1695 * may be up to 8 in-flight write requests per single slot in
1696 * last_rcvd client data
1698 tgt->lut_no_reconstruct = (type == LDD_F_SV_TYPE_OST);
1700 if (last_rcvd_size == 0) {
1701 LCONSOLE_WARN("%s: new disk, initializing\n", tgt_name(tgt));
1703 memcpy(lsd->lsd_uuid, tgt->lut_obd->obd_uuid.uuid,
1704 sizeof(lsd->lsd_uuid));
1705 lsd->lsd_last_transno = 0;
1706 lsd->lsd_mount_count = 0;
1707 lsd->lsd_server_size = LR_SERVER_SIZE;
1708 lsd->lsd_client_start = LR_CLIENT_START;
1709 lsd->lsd_client_size = LR_CLIENT_SIZE;
1710 lsd->lsd_subdir_count = OBJ_SUBDIR_COUNT;
1711 lsd->lsd_osd_index = index;
1712 lsd->lsd_feature_rocompat = tgt_scd[type].rocinit;
1713 lsd->lsd_feature_incompat = tgt_scd[type].incinit;
1715 rc = tgt_server_data_read(env, tgt);
1717 CERROR("%s: error reading LAST_RCVD: rc= %d\n",
1721 if (strcmp(lsd->lsd_uuid, tgt->lut_obd->obd_uuid.uuid)) {
1722 if (tgt->lut_bottom->dd_rdonly) {
1723 /* Such difference may be caused by mounting
1724 * up snapshot with new fsname under rd_only
1725 * mode. But even if it was NOT, it will not
1726 * damage the system because of "rd_only". */
1727 memcpy(lsd->lsd_uuid,
1728 tgt->lut_obd->obd_uuid.uuid,
1729 sizeof(lsd->lsd_uuid));
1731 LCONSOLE_ERROR_MSG(0x157, "Trying to start "
1732 "OBD %s using the wrong "
1733 "disk %s. Were the /dev/ "
1734 "assignments rearranged?\n",
1735 tgt->lut_obd->obd_uuid.uuid,
1741 if (lsd->lsd_osd_index != index) {
1742 LCONSOLE_ERROR_MSG(0x157,
1743 "%s: index %d in last rcvd is different with the index %d in config log, It might be disk corruption!\n",
1745 lsd->lsd_osd_index, index);
1750 if (lsd->lsd_feature_incompat & ~tgt_scd[type].incompat) {
1751 CERROR("%s: unsupported incompat filesystem feature(s) %x\n",
1753 lsd->lsd_feature_incompat & ~tgt_scd[type].incompat);
1757 if (type == LDD_F_SV_TYPE_MDT)
1758 lsd->lsd_feature_incompat |= OBD_INCOMPAT_FID;
1760 if (lsd->lsd_feature_rocompat & ~tgt_scd[type].rocompat) {
1761 CERROR("%s: unsupported read-only filesystem feature(s) %x\n",
1763 lsd->lsd_feature_rocompat & ~tgt_scd[type].rocompat);
1766 /** Interop: evict all clients at first boot with 1.8 last_rcvd */
1767 if (type == LDD_F_SV_TYPE_MDT &&
1768 !(lsd->lsd_feature_compat & OBD_COMPAT_20)) {
1769 if (last_rcvd_size > lsd->lsd_client_start) {
1770 LCONSOLE_WARN("%s: mounting at first time on 1.8 FS, "
1771 "remove all clients for interop needs\n",
1773 rc = tgt_truncate_last_rcvd(env, tgt,
1774 lsd->lsd_client_start);
1777 last_rcvd_size = lsd->lsd_client_start;
1779 /** set 2.0 flag to upgrade/downgrade between 1.8 and 2.0 */
1780 lsd->lsd_feature_compat |= OBD_COMPAT_20;
1783 spin_lock(&tgt->lut_translock);
1784 tgt->lut_last_transno = lsd->lsd_last_transno;
1785 spin_unlock(&tgt->lut_translock);
1787 lsd->lsd_mount_count++;
1789 CDEBUG(D_INODE, "=======,=BEGIN DUMPING LAST_RCVD========\n");
1790 CDEBUG(D_INODE, "%s: server last_transno: %llu\n",
1791 tgt_name(tgt), tgt->lut_last_transno);
1792 CDEBUG(D_INODE, "%s: server mount_count: %llu\n",
1793 tgt_name(tgt), lsd->lsd_mount_count);
1794 CDEBUG(D_INODE, "%s: server data size: %u\n",
1795 tgt_name(tgt), lsd->lsd_server_size);
1796 CDEBUG(D_INODE, "%s: per-client data start: %u\n",
1797 tgt_name(tgt), lsd->lsd_client_start);
1798 CDEBUG(D_INODE, "%s: per-client data size: %u\n",
1799 tgt_name(tgt), lsd->lsd_client_size);
1800 CDEBUG(D_INODE, "%s: last_rcvd size: %lu\n",
1801 tgt_name(tgt), last_rcvd_size);
1802 CDEBUG(D_INODE, "%s: server subdir_count: %u\n",
1803 tgt_name(tgt), lsd->lsd_subdir_count);
1804 CDEBUG(D_INODE, "%s: last_rcvd clients: %lu\n", tgt_name(tgt),
1805 last_rcvd_size <= lsd->lsd_client_start ? 0 :
1806 (last_rcvd_size - lsd->lsd_client_start) /
1807 lsd->lsd_client_size);
1808 CDEBUG(D_INODE, "========END DUMPING LAST_RCVD========\n");
1810 if (lsd->lsd_server_size == 0 || lsd->lsd_client_start == 0 ||
1811 lsd->lsd_client_size == 0) {
1812 CERROR("%s: bad last_rcvd contents!\n", tgt_name(tgt));
1816 if (!tgt->lut_obd->obd_replayable)
1817 CWARN("%s: recovery support OFF\n", tgt_name(tgt));
1819 rc = tgt_clients_data_init(env, tgt, last_rcvd_size);
1821 GOTO(err_client, rc);
1823 spin_lock(&tgt->lut_translock);
1824 /* obd_last_committed is used for compatibility
1825 * with other lustre recovery code */
1826 tgt->lut_obd->obd_last_committed = tgt->lut_last_transno;
1827 spin_unlock(&tgt->lut_translock);
1829 tgt->lut_obd->u.obt.obt_mount_count = lsd->lsd_mount_count;
1830 tgt->lut_obd->u.obt.obt_instance = (__u32)lsd->lsd_mount_count;
1832 /* save it, so mount count and last_transno is current */
1833 rc = tgt_server_data_update(env, tgt, 0);
1835 GOTO(err_client, rc);
1840 class_disconnect_exports(tgt->lut_obd);
1844 /* add credits for last_rcvd update */
1845 int tgt_txn_start_cb(const struct lu_env *env, struct thandle *th,
1848 struct lu_target *tgt = cookie;
1849 struct tgt_session_info *tsi;
1850 struct tgt_thread_info *tti = tgt_th_info(env);
1851 struct dt_object *dto;
1854 /* For readonly case, the caller should have got failure
1855 * when start the transaction. If the logic comes here,
1856 * there must be something wrong. */
1857 if (unlikely(tgt->lut_bottom->dd_rdonly)) {
1862 /* if there is no session, then this transaction is not result of
1863 * request processing but some local operation */
1864 if (env->le_ses == NULL)
1867 LASSERT(tgt->lut_last_rcvd);
1868 tsi = tgt_ses_info(env);
1869 /* OFD may start transaction without export assigned */
1870 if (tsi->tsi_exp == NULL)
1873 if (tgt_is_multimodrpcs_client(tsi->tsi_exp)) {
1875 * Use maximum possible file offset for declaration to ensure
1876 * ZFS will reserve enough credits for a write anywhere in this
1877 * file, since we don't know where in the file the write will be
1878 * because a replay slot has not been assigned. This should be
1879 * replaced by dmu_tx_hold_append() when available.
1881 tti->tti_buf.lb_buf = NULL;
1882 tti->tti_buf.lb_len = sizeof(struct lsd_reply_data);
1883 dto = dt_object_locate(tgt->lut_reply_data, th->th_dev);
1884 rc = dt_declare_record_write(env, dto, &tti->tti_buf, -1, th);
1888 dto = dt_object_locate(tgt->lut_last_rcvd, th->th_dev);
1890 tti->tti_off = tsi->tsi_exp->exp_target_data.ted_lr_off;
1891 rc = dt_declare_record_write(env, dto, &tti->tti_buf,
1897 if (tsi->tsi_vbr_obj != NULL &&
1898 !lu_object_remote(&tsi->tsi_vbr_obj->do_lu)) {
1899 dto = dt_object_locate(tsi->tsi_vbr_obj, th->th_dev);
1900 rc = dt_declare_version_set(env, dto, th);
1906 /* Update last_rcvd records with latests transaction data */
1907 int tgt_txn_stop_cb(const struct lu_env *env, struct thandle *th,
1910 struct lu_target *tgt = cookie;
1911 struct tgt_session_info *tsi;
1912 struct tgt_thread_info *tti = tgt_th_info(env);
1913 struct dt_object *obj = NULL;
1917 if (env->le_ses == NULL)
1920 tsi = tgt_ses_info(env);
1921 /* OFD may start transaction without export assigned */
1922 if (tsi->tsi_exp == NULL)
1925 echo_client = (tgt_ses_req(tsi) == NULL && tsi->tsi_xid == 0);
1927 if (tti->tti_has_trans && !echo_client) {
1928 if (tti->tti_mult_trans == 0) {
1929 CDEBUG(D_HA, "More than one transaction %llu\n",
1933 /* we need another transno to be assigned */
1934 tti->tti_transno = 0;
1935 } else if (th->th_result == 0) {
1936 tti->tti_has_trans = 1;
1939 if (tsi->tsi_vbr_obj != NULL &&
1940 !lu_object_remote(&tsi->tsi_vbr_obj->do_lu)) {
1941 obj = tsi->tsi_vbr_obj;
1944 if (unlikely(echo_client)) /* echo client special case */
1945 rc = tgt_last_rcvd_update_echo(env, tgt, obj, th,
1948 rc = tgt_last_rcvd_update(env, tgt, obj, tsi->tsi_opdata, th,
1953 int tgt_reply_data_init(const struct lu_env *env, struct lu_target *tgt)
1955 struct tgt_thread_info *tti = tgt_th_info(env);
1956 struct lsd_reply_data *lrd = &tti->tti_lrd;
1957 unsigned long reply_data_size;
1959 struct lsd_reply_header *lrh = NULL;
1960 struct tg_reply_data *trd = NULL;
1963 struct cfs_hash *hash = NULL;
1964 struct obd_export *exp;
1965 struct tg_export_data *ted;
1966 int reply_data_recovered = 0;
1968 rc = dt_attr_get(env, tgt->lut_reply_data, &tti->tti_attr);
1971 reply_data_size = (unsigned long)tti->tti_attr.la_size;
1975 GOTO(out, rc = -ENOMEM);
1977 if (reply_data_size == 0) {
1978 CDEBUG(D_INFO, "%s: new reply_data file, initializing\n",
1980 lrh->lrh_magic = LRH_MAGIC;
1981 lrh->lrh_header_size = sizeof(struct lsd_reply_header);
1982 lrh->lrh_reply_size = sizeof(struct lsd_reply_data);
1983 rc = tgt_reply_header_write(env, tgt, lrh);
1985 CERROR("%s: error writing %s: rc = %d\n",
1986 tgt_name(tgt), REPLY_DATA, rc);
1990 rc = tgt_reply_header_read(env, tgt, lrh);
1992 CERROR("%s: error reading %s: rc = %d\n",
1993 tgt_name(tgt), REPLY_DATA, rc);
1996 if (lrh->lrh_magic != LRH_MAGIC ||
1997 lrh->lrh_header_size != sizeof(struct lsd_reply_header) ||
1998 lrh->lrh_reply_size != sizeof(struct lsd_reply_data)) {
1999 CERROR("%s: invalid header in %s\n",
2000 tgt_name(tgt), REPLY_DATA);
2001 GOTO(out, rc = -EINVAL);
2004 hash = cfs_hash_getref(tgt->lut_obd->obd_gen_hash);
2006 GOTO(out, rc = -ENODEV);
2010 GOTO(out, rc = -ENOMEM);
2012 /* Load reply_data from disk */
2013 for (idx = 0, off = sizeof(struct lsd_reply_header);
2014 off < reply_data_size;
2015 idx++, off += sizeof(struct lsd_reply_data)) {
2016 rc = tgt_reply_data_read(env, tgt, lrd, off);
2018 CERROR("%s: error reading %s: rc = %d\n",
2019 tgt_name(tgt), REPLY_DATA, rc);
2023 exp = cfs_hash_lookup(hash, &lrd->lrd_client_gen);
2025 /* old reply data from a disconnected client */
2028 ted = &exp->exp_target_data;
2029 mutex_lock(&ted->ted_lcd_lock);
2031 /* create in-memory reply_data and link it to
2032 * target export's reply list */
2033 rc = tgt_set_reply_slot(tgt, idx);
2035 mutex_unlock(&ted->ted_lcd_lock);
2038 trd->trd_reply = *lrd;
2039 trd->trd_pre_versions[0] = 0;
2040 trd->trd_pre_versions[1] = 0;
2041 trd->trd_pre_versions[2] = 0;
2042 trd->trd_pre_versions[3] = 0;
2043 trd->trd_index = idx;
2045 list_add(&trd->trd_list, &ted->ted_reply_list);
2046 ted->ted_reply_cnt++;
2047 if (ted->ted_reply_cnt > ted->ted_reply_max)
2048 ted->ted_reply_max = ted->ted_reply_cnt;
2050 CDEBUG(D_HA, "%s: restore reply %p: xid %llu, "
2051 "transno %llu, client gen %u, slot idx %d\n",
2052 tgt_name(tgt), trd, lrd->lrd_xid,
2053 lrd->lrd_transno, lrd->lrd_client_gen,
2056 /* update export last committed transation */
2057 exp->exp_last_committed = max(exp->exp_last_committed,
2059 /* Update lcd_last_transno as well for check in
2060 * tgt_release_reply_data() or the latest client
2061 * transno can be lost.
2063 ted->ted_lcd->lcd_last_transno =
2064 max(ted->ted_lcd->lcd_last_transno,
2065 exp->exp_last_committed);
2067 mutex_unlock(&ted->ted_lcd_lock);
2068 class_export_put(exp);
2070 /* update target last committed transaction */
2071 spin_lock(&tgt->lut_translock);
2072 tgt->lut_last_transno = max(tgt->lut_last_transno,
2074 spin_unlock(&tgt->lut_translock);
2076 reply_data_recovered++;
2080 GOTO(out, rc = -ENOMEM);
2082 CDEBUG(D_INFO, "%s: %d reply data have been recovered\n",
2083 tgt_name(tgt), reply_data_recovered);
2086 spin_lock(&tgt->lut_translock);
2087 /* obd_last_committed is used for compatibility
2088 * with other lustre recovery code */
2089 tgt->lut_obd->obd_last_committed = tgt->lut_last_transno;
2090 spin_unlock(&tgt->lut_translock);
2096 cfs_hash_putref(hash);
2104 static int tgt_check_lookup_req(struct ptlrpc_request *req, int lookup,
2105 struct tg_reply_data *trd)
2107 struct tg_export_data *ted = &req->rq_export->exp_target_data;
2108 struct lu_target *lut = class_exp2tgt(req->rq_export);
2109 __u16 tag = lustre_msg_get_tag(req->rq_reqmsg);
2111 struct tg_reply_data *reply;
2112 bool check_increasing;
2117 check_increasing = tgt_is_increasing_xid_client(req->rq_export) &&
2118 !(lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY);
2119 if (!lookup && !check_increasing)
2122 list_for_each_entry(reply, &ted->ted_reply_list, trd_list) {
2123 if (lookup && reply->trd_reply.lrd_xid == req->rq_xid) {
2128 } else if (check_increasing && reply->trd_tag == tag &&
2129 reply->trd_reply.lrd_xid > req->rq_xid) {
2131 CERROR("%s: busy tag=%u req_xid=%llu, trd=%p: xid=%llu transno=%llu client_gen=%u slot_idx=%d: rc = %d\n",
2132 tgt_name(lut), tag, req->rq_xid, trd,
2133 reply->trd_reply.lrd_xid,
2134 reply->trd_reply.lrd_transno,
2135 reply->trd_reply.lrd_client_gen,
2136 reply->trd_index, rc);
2144 /* Look for a reply data matching specified request @req
2145 * A copy is returned in @trd if the pointer is not NULL
2147 int tgt_lookup_reply(struct ptlrpc_request *req, struct tg_reply_data *trd)
2149 struct tg_export_data *ted = &req->rq_export->exp_target_data;
2151 bool not_replay = !(lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY);
2153 mutex_lock(&ted->ted_lcd_lock);
2154 if (not_replay && req->rq_xid <= req->rq_export->exp_last_xid) {
2155 /* A check for the last_xid is needed here in case there is
2156 * no reply data is left in the list. It may happen if another
2157 * RPC on another slot increased the last_xid between our
2158 * process_req_last_xid & tgt_lookup_reply calls */
2161 found = tgt_check_lookup_req(req, 1, trd);
2163 mutex_unlock(&ted->ted_lcd_lock);
2165 CDEBUG(D_TRACE, "%s: lookup reply xid %llu, found %d last_xid %llu\n",
2166 tgt_name(class_exp2tgt(req->rq_export)), req->rq_xid, found,
2167 req->rq_export->exp_last_xid);
2171 EXPORT_SYMBOL(tgt_lookup_reply);
2173 int tgt_handle_received_xid(struct obd_export *exp, __u64 rcvd_xid)
2175 struct tg_export_data *ted = &exp->exp_target_data;
2176 struct lu_target *lut = class_exp2tgt(exp);
2177 struct tg_reply_data *trd, *tmp;
2180 list_for_each_entry_safe(trd, tmp, &ted->ted_reply_list, trd_list) {
2181 if (trd->trd_reply.lrd_xid > rcvd_xid)
2183 ted->ted_release_xid++;
2184 tgt_release_reply_data(lut, ted, trd);
2190 int tgt_handle_tag(struct ptlrpc_request *req)
2192 return tgt_check_lookup_req(req, 0, NULL);