- struct ptlrpc_request *request;
- struct list_head *tmp;
- int rc = -EINVAL;
-
- /* XXX c_lock semantics! */
- conn->c_level = LUSTRE_CONN_CON;
-
- /* XXX this code MUST be shared with class_obd_connect! */
- list_for_each(tmp, &conn->c_imports) {
- struct obd_import *imp = list_entry(tmp, struct obd_import,
- imp_chain);
- struct obd_device *obd = imp->imp_obd;
- struct client_obd *cli = &obd->u.cli;
- int rq_opc = (obd->obd_type->typ_ops->o_brw)
- ? OST_CONNECT : MDS_CONNECT;
- int size[] = { sizeof(cli->cl_target_uuid),
- sizeof(obd->obd_uuid) };
- char *tmp[] = {cli->cl_target_uuid, obd->obd_uuid };
- struct lustre_handle old_hdl;
-
- LASSERT(imp->imp_connection == conn);
- request = ptlrpc_prep_req(imp, rq_opc, 2, size, tmp);
- request->rq_level = LUSTRE_CONN_NEW;
- request->rq_replen = lustre_msg_size(0, NULL);
- /* XXX are (addr, cookie) right? */
- request->rq_reqmsg->addr = imp->imp_handle.addr;
- request->rq_reqmsg->cookie = imp->imp_handle.cookie;
- rc = ptlrpc_queue_wait(request);
- rc = ptlrpc_check_status(request, rc);
- if (rc) {
- CERROR("cannot connect to %s@%s: rc = %d\n",
- cli->cl_target_uuid, conn->c_remote_uuid, rc);
- ptlrpc_free_req(request);
- GOTO(out_disc, rc = -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;
+ struct list_head *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.
+ */
+ spin_lock(&imp->imp_lock);
+ imp->imp_last_transno_checked = 0;
+ ptlrpc_free_committed(imp);
+ last_transno = imp->imp_last_replay_transno;
+ 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...
+ */
+ list_for_each_safe(tmp, pos, &imp->imp_replay_list) {
+ req = 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 (imp->imp_resend_replay &&
+ req->rq_transno == last_transno) {
+ lustre_msg_add_flags(req->rq_reqmsg, MSG_RESENT);
+ break;