- struct ll_fid rootfid;
- __u64 last_committed;
- __u64 last_xid;
- int err;
- struct ptlrpc_request *request;
- struct ptlrpc_connection *conn = sbi2mdc(sbi)->cl_import.imp_connection;
-
- ptlrpc_readdress_connection(conn, "mds");
-
- conn->c_level = LUSTRE_CONN_CON;
-
- /* XXX: need to store the last_* values somewhere */
- err = mdc_getstatus(&sbi->ll_mdc_conn, &rootfid, &last_committed,
- &last_xid, &request);
- if (err) {
- CERROR("cannot mds_connect: rc = %d\n", err);
- GOTO(out_disc, err = -ENOTCONN);
+ ENTRY;
+
+ CDEBUG(D_HA, "%s: starting recovery\n", obd2cli_tgt(imp->imp_obd));
+ ptlrpc_connect_import(imp, NULL);
+
+ EXIT;
+}
+
+int ptlrpc_replay_next(struct obd_import *imp, int *inflight)
+{
+ int rc = 0;
+ cfs_list_t *tmp, *pos;
+ struct ptlrpc_request *req = NULL;
+ __u64 last_transno;
+ ENTRY;
+
+ *inflight = 0;
+
+ /* It might have committed some after we last spoke, so make sure we
+ * get rid of them now.
+ */
+ cfs_spin_lock(&imp->imp_lock);
+ imp->imp_last_transno_checked = 0;
+ ptlrpc_free_committed(imp);
+ last_transno = imp->imp_last_replay_transno;
+ cfs_spin_unlock(&imp->imp_lock);
+
+ CDEBUG(D_HA, "import %p from %s committed "LPU64" last "LPU64"\n",
+ imp, obd2cli_tgt(imp->imp_obd),
+ imp->imp_peer_committed_transno, last_transno);
+
+ /* Do I need to hold a lock across this iteration? We shouldn't be
+ * racing with any additions to the list, because we're in recovery
+ * and are therefore not processing additional requests to add. Calls
+ * to ptlrpc_free_committed might commit requests, but nothing "newer"
+ * than the one we're replaying (it can't be committed until it's
+ * replayed, and we're doing that here). l_f_e_safe protects against
+ * problems with the current request being committed, in the unlikely
+ * event of that race. So, in conclusion, I think that it's safe to
+ * perform this list-walk without the imp_lock held.
+ *
+ * But, the {mdc,osc}_replay_open callbacks both iterate
+ * request lists, and have comments saying they assume the
+ * imp_lock is being held by ptlrpc_replay, but it's not. it's
+ * just a little race...
+ */
+ cfs_list_for_each_safe(tmp, pos, &imp->imp_replay_list) {
+ req = cfs_list_entry(tmp, struct ptlrpc_request,
+ rq_replay_list);
+
+ /* If need to resend the last sent transno (because a
+ reconnect has occurred), then stop on the matching
+ req and send it again. If, however, the last sent
+ transno has been committed then we continue replay
+ from the next request. */
+ if (req->rq_transno > last_transno) {
+ if (imp->imp_resend_replay)
+ lustre_msg_add_flags(req->rq_reqmsg,
+ MSG_RESENT);
+ break;
+ }
+ req = NULL;