+int tgt_add_reply_data(const struct lu_env *env, struct lu_target *tgt,
+ struct tg_export_data *ted, struct tg_reply_data *trd,
+ struct thandle *th, bool update_lrd_file)
+{
+ struct lsd_reply_data *lrd;
+ int i;
+
+ lrd = &trd->trd_reply;
+ /* update export last transno */
+ mutex_lock(&ted->ted_lcd_lock);
+ if (lrd->lrd_transno > ted->ted_lcd->lcd_last_transno)
+ ted->ted_lcd->lcd_last_transno = lrd->lrd_transno;
+ mutex_unlock(&ted->ted_lcd_lock);
+
+ /* find a empty slot */
+ i = tgt_find_free_reply_slot(tgt);
+ if (unlikely(i < 0)) {
+ CERROR("%s: couldn't find a slot for reply data: "
+ "rc = %d\n", tgt_name(tgt), i);
+ RETURN(i);
+ }
+ trd->trd_index = i;
+
+ if (update_lrd_file) {
+ loff_t off;
+ int rc;
+
+ /* write reply data to disk */
+ off = sizeof(struct lsd_reply_header) + sizeof(*lrd) * i;
+ rc = tgt_reply_data_write(env, tgt, lrd, off, th);
+ if (unlikely(rc != 0)) {
+ CERROR("%s: can't update %s file: rc = %d\n",
+ tgt_name(tgt), REPLY_DATA, rc);
+ RETURN(rc);
+ }
+ }
+ /* add reply data to target export's reply list */
+ mutex_lock(&ted->ted_lcd_lock);
+ list_add(&trd->trd_list, &ted->ted_reply_list);
+ ted->ted_reply_cnt++;
+ if (ted->ted_reply_cnt > ted->ted_reply_max)
+ ted->ted_reply_max = ted->ted_reply_cnt;
+ mutex_unlock(&ted->ted_lcd_lock);
+
+ CDEBUG(D_TRACE, "add reply %p: xid %llu, transno %llu, "
+ "tag %hu, client gen %u, slot idx %d\n",
+ trd, lrd->lrd_xid, lrd->lrd_transno,
+ trd->trd_tag, lrd->lrd_client_gen, i);
+ RETURN(0);
+}
+EXPORT_SYMBOL(tgt_add_reply_data);
+