libceph: behave in mon_fault() if cur_mon < 0
[linux-2.6-block.git] / net / ceph / mon_client.c
index fd1cf408fd899ab790d2bcea4a1514190f513a9e..cf638c009cfabe9e95d114c1e187785db46f958c 100644 (file)
@@ -171,6 +171,7 @@ static void __open_session(struct ceph_mon_client *monc)
 
        pick_new_mon(monc);
 
+       monc->hunting = true;
        if (monc->had_a_connection) {
                monc->hunt_mult *= CEPH_MONC_HUNT_BACKOFF;
                if (monc->hunt_mult > CEPH_MONC_HUNT_MAX_MULT)
@@ -198,6 +199,16 @@ static void __open_session(struct ceph_mon_client *monc)
        __send_prepared_auth_request(monc, ret);
 }
 
+static void reopen_session(struct ceph_mon_client *monc)
+{
+       if (!monc->hunting)
+               pr_info("mon%d %s session lost, hunting for new mon\n",
+                   monc->cur_mon, ceph_pr_addr(&monc->con.peer_addr.in_addr));
+
+       __close_session(monc);
+       __open_session(monc);
+}
+
 /*
  * Reschedule delayed work timer.
  */
@@ -211,8 +222,8 @@ static void __schedule_delayed(struct ceph_mon_client *monc)
                delay = CEPH_MONC_PING_INTERVAL;
 
        dout("__schedule_delayed after %lu\n", delay);
-       schedule_delayed_work(&monc->delayed_work,
-                             round_jiffies_relative(delay));
+       mod_delayed_work(system_wq, &monc->delayed_work,
+                        round_jiffies_relative(delay));
 }
 
 const char *ceph_sub_str[] = {
@@ -788,17 +799,15 @@ static void delayed_work(struct work_struct *work)
        dout("monc delayed_work\n");
        mutex_lock(&monc->mutex);
        if (monc->hunting) {
-               __close_session(monc);
-               __open_session(monc);  /* continue hunting */
+               dout("%s continuing hunt\n", __func__);
+               reopen_session(monc);
        } else {
                int is_auth = ceph_auth_is_authenticated(monc->auth);
                if (ceph_con_keepalive_expired(&monc->con,
                                               CEPH_MONC_PING_TIMEOUT)) {
                        dout("monc keepalive timeout\n");
                        is_auth = 0;
-                       __close_session(monc);
-                       monc->hunting = true;
-                       __open_session(monc);
+                       reopen_session(monc);
                }
 
                if (!monc->hunting) {
@@ -900,9 +909,6 @@ int ceph_monc_init(struct ceph_mon_client *monc, struct ceph_client *cl)
                      &monc->client->msgr);
 
        monc->cur_mon = -1;
-       monc->hunting = true;
-       monc->sub_renew_after = jiffies;
-       monc->sub_renew_sent = 0;
        monc->had_a_connection = false;
        monc->hunt_mult = 1;
 
@@ -1149,29 +1155,17 @@ static void mon_fault(struct ceph_connection *con)
 {
        struct ceph_mon_client *monc = con->private;
 
-       if (!monc)
-               return;
-
-       dout("mon_fault\n");
        mutex_lock(&monc->mutex);
-       if (!con->private)
-               goto out;
-
-       if (!monc->hunting)
-               pr_info("mon%d %s session lost, "
-                       "hunting for new mon\n", monc->cur_mon,
-                       ceph_pr_addr(&monc->con.peer_addr.in_addr));
-
-       __close_session(monc);
-       if (!monc->hunting) {
-               /* start hunting */
-               monc->hunting = true;
-               __open_session(monc);
-       } else {
-               /* already hunting, let's wait a bit */
-               __schedule_delayed(monc);
+       dout("%s mon%d\n", __func__, monc->cur_mon);
+       if (monc->cur_mon >= 0) {
+               if (!monc->hunting) {
+                       dout("%s hunting for new mon\n", __func__);
+                       reopen_session(monc);
+                       __schedule_delayed(monc);
+               } else {
+                       dout("%s already hunting\n", __func__);
+               }
        }
-out:
        mutex_unlock(&monc->mutex);
 }