mon_client.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. #include "ceph_debug.h"
  2. #include <linux/types.h>
  3. #include <linux/random.h>
  4. #include <linux/sched.h>
  5. #include "mon_client.h"
  6. #include "super.h"
  7. #include "decode.h"
  8. /*
  9. * Interact with Ceph monitor cluster. Handle requests for new map
  10. * versions, and periodically resend as needed. Also implement
  11. * statfs() and umount().
  12. *
  13. * A small cluster of Ceph "monitors" are responsible for managing critical
  14. * cluster configuration and state information. An odd number (e.g., 3, 5)
  15. * of cmon daemons use a modified version of the Paxos part-time parliament
  16. * algorithm to manage the MDS map (mds cluster membership), OSD map, and
  17. * list of clients who have mounted the file system.
  18. *
  19. * We maintain an open, active session with a monitor at all times in order to
  20. * receive timely MDSMap updates. We periodically send a keepalive byte on the
  21. * TCP socket to ensure we detect a failure. If the connection does break, we
  22. * randomly hunt for a new monitor. Once the connection is reestablished, we
  23. * resend any outstanding requests.
  24. */
  25. const static struct ceph_connection_operations mon_con_ops;
  26. /*
  27. * Decode a monmap blob (e.g., during mount).
  28. */
  29. struct ceph_monmap *ceph_monmap_decode(void *p, void *end)
  30. {
  31. struct ceph_monmap *m = NULL;
  32. int i, err = -EINVAL;
  33. struct ceph_fsid fsid;
  34. u32 epoch, num_mon;
  35. u16 version;
  36. dout("monmap_decode %p %p len %d\n", p, end, (int)(end-p));
  37. ceph_decode_16_safe(&p, end, version, bad);
  38. ceph_decode_need(&p, end, sizeof(fsid) + 2*sizeof(u32), bad);
  39. ceph_decode_copy(&p, &fsid, sizeof(fsid));
  40. ceph_decode_32(&p, epoch);
  41. ceph_decode_32(&p, num_mon);
  42. ceph_decode_need(&p, end, num_mon*sizeof(m->mon_inst[0]), bad);
  43. if (num_mon >= CEPH_MAX_MON)
  44. goto bad;
  45. m = kmalloc(sizeof(*m) + sizeof(m->mon_inst[0])*num_mon, GFP_NOFS);
  46. if (m == NULL)
  47. return ERR_PTR(-ENOMEM);
  48. m->fsid = fsid;
  49. m->epoch = epoch;
  50. m->num_mon = num_mon;
  51. ceph_decode_copy(&p, m->mon_inst, num_mon*sizeof(m->mon_inst[0]));
  52. if (p != end)
  53. goto bad;
  54. dout("monmap_decode epoch %d, num_mon %d\n", m->epoch,
  55. m->num_mon);
  56. for (i = 0; i < m->num_mon; i++)
  57. dout("monmap_decode mon%d is %s\n", i,
  58. pr_addr(&m->mon_inst[i].addr.in_addr));
  59. return m;
  60. bad:
  61. dout("monmap_decode failed with %d\n", err);
  62. kfree(m);
  63. return ERR_PTR(err);
  64. }
  65. /*
  66. * return true if *addr is included in the monmap.
  67. */
  68. int ceph_monmap_contains(struct ceph_monmap *m, struct ceph_entity_addr *addr)
  69. {
  70. int i;
  71. for (i = 0; i < m->num_mon; i++)
  72. if (ceph_entity_addr_equal(addr, &m->mon_inst[i].addr))
  73. return 1;
  74. return 0;
  75. }
  76. /*
  77. * Close monitor session, if any.
  78. */
  79. static void __close_session(struct ceph_mon_client *monc)
  80. {
  81. if (monc->con) {
  82. dout("__close_session closing mon%d\n", monc->cur_mon);
  83. ceph_con_close(monc->con);
  84. monc->cur_mon = -1;
  85. }
  86. }
  87. /*
  88. * Open a session with a (new) monitor.
  89. */
  90. static int __open_session(struct ceph_mon_client *monc)
  91. {
  92. char r;
  93. if (monc->cur_mon < 0) {
  94. get_random_bytes(&r, 1);
  95. monc->cur_mon = r % monc->monmap->num_mon;
  96. dout("open_session num=%d r=%d -> mon%d\n",
  97. monc->monmap->num_mon, r, monc->cur_mon);
  98. monc->sub_sent = 0;
  99. monc->sub_renew_after = jiffies; /* i.e., expired */
  100. monc->want_next_osdmap = !!monc->want_next_osdmap;
  101. dout("open_session mon%d opening\n", monc->cur_mon);
  102. monc->con->peer_name.type = CEPH_ENTITY_TYPE_MON;
  103. monc->con->peer_name.num = cpu_to_le64(monc->cur_mon);
  104. ceph_con_open(monc->con,
  105. &monc->monmap->mon_inst[monc->cur_mon].addr);
  106. } else {
  107. dout("open_session mon%d already open\n", monc->cur_mon);
  108. }
  109. return 0;
  110. }
  111. static bool __sub_expired(struct ceph_mon_client *monc)
  112. {
  113. return time_after_eq(jiffies, monc->sub_renew_after);
  114. }
  115. /*
  116. * Reschedule delayed work timer.
  117. */
  118. static void __schedule_delayed(struct ceph_mon_client *monc)
  119. {
  120. unsigned delay;
  121. if (monc->cur_mon < 0 || monc->want_mount || __sub_expired(monc))
  122. delay = 10 * HZ;
  123. else
  124. delay = 20 * HZ;
  125. dout("__schedule_delayed after %u\n", delay);
  126. schedule_delayed_work(&monc->delayed_work, delay);
  127. }
  128. /*
  129. * Send subscribe request for mdsmap and/or osdmap.
  130. */
  131. static void __send_subscribe(struct ceph_mon_client *monc)
  132. {
  133. dout("__send_subscribe sub_sent=%u exp=%u want_osd=%d\n",
  134. (unsigned)monc->sub_sent, __sub_expired(monc),
  135. monc->want_next_osdmap);
  136. if ((__sub_expired(monc) && !monc->sub_sent) ||
  137. monc->want_next_osdmap == 1) {
  138. struct ceph_msg *msg;
  139. struct ceph_mon_subscribe_item *i;
  140. void *p, *end;
  141. msg = ceph_msg_new(CEPH_MSG_MON_SUBSCRIBE, 64, 0, 0, NULL);
  142. if (!msg)
  143. return;
  144. p = msg->front.iov_base;
  145. end = p + msg->front.iov_len;
  146. dout("__send_subscribe to 'mdsmap' %u+\n",
  147. (unsigned)monc->have_mdsmap);
  148. if (monc->want_next_osdmap) {
  149. dout("__send_subscribe to 'osdmap' %u\n",
  150. (unsigned)monc->have_osdmap);
  151. ceph_encode_32(&p, 2);
  152. ceph_encode_string(&p, end, "osdmap", 6);
  153. i = p;
  154. i->have = cpu_to_le64(monc->have_osdmap);
  155. i->onetime = 1;
  156. p += sizeof(*i);
  157. monc->want_next_osdmap = 2; /* requested */
  158. } else {
  159. ceph_encode_32(&p, 1);
  160. }
  161. ceph_encode_string(&p, end, "mdsmap", 6);
  162. i = p;
  163. i->have = cpu_to_le64(monc->have_mdsmap);
  164. i->onetime = 0;
  165. p += sizeof(*i);
  166. msg->front.iov_len = p - msg->front.iov_base;
  167. msg->hdr.front_len = cpu_to_le32(msg->front.iov_len);
  168. ceph_con_send(monc->con, msg);
  169. monc->sub_sent = jiffies | 1; /* never 0 */
  170. }
  171. }
  172. static void handle_subscribe_ack(struct ceph_mon_client *monc,
  173. struct ceph_msg *msg)
  174. {
  175. unsigned seconds;
  176. void *p = msg->front.iov_base;
  177. void *end = p + msg->front.iov_len;
  178. ceph_decode_32_safe(&p, end, seconds, bad);
  179. mutex_lock(&monc->mutex);
  180. if (monc->hunting) {
  181. pr_info("mon%d %s session established\n",
  182. monc->cur_mon, pr_addr(&monc->con->peer_addr.in_addr));
  183. monc->hunting = false;
  184. }
  185. dout("handle_subscribe_ack after %d seconds\n", seconds);
  186. monc->sub_renew_after = monc->sub_sent + (seconds >> 1)*HZ - 1;
  187. monc->sub_sent = 0;
  188. mutex_unlock(&monc->mutex);
  189. return;
  190. bad:
  191. pr_err("got corrupt subscribe-ack msg\n");
  192. }
  193. /*
  194. * Keep track of which maps we have
  195. */
  196. int ceph_monc_got_mdsmap(struct ceph_mon_client *monc, u32 got)
  197. {
  198. mutex_lock(&monc->mutex);
  199. monc->have_mdsmap = got;
  200. mutex_unlock(&monc->mutex);
  201. return 0;
  202. }
  203. int ceph_monc_got_osdmap(struct ceph_mon_client *monc, u32 got)
  204. {
  205. mutex_lock(&monc->mutex);
  206. monc->have_osdmap = got;
  207. monc->want_next_osdmap = 0;
  208. mutex_unlock(&monc->mutex);
  209. return 0;
  210. }
  211. /*
  212. * Register interest in the next osdmap
  213. */
  214. void ceph_monc_request_next_osdmap(struct ceph_mon_client *monc)
  215. {
  216. dout("request_next_osdmap have %u\n", monc->have_osdmap);
  217. mutex_lock(&monc->mutex);
  218. if (!monc->want_next_osdmap)
  219. monc->want_next_osdmap = 1;
  220. if (monc->want_next_osdmap < 2)
  221. __send_subscribe(monc);
  222. mutex_unlock(&monc->mutex);
  223. }
  224. /*
  225. * mount
  226. */
  227. static void __request_mount(struct ceph_mon_client *monc)
  228. {
  229. struct ceph_msg *msg;
  230. struct ceph_client_mount *h;
  231. int err;
  232. dout("__request_mount\n");
  233. err = __open_session(monc);
  234. if (err)
  235. return;
  236. msg = ceph_msg_new(CEPH_MSG_CLIENT_MOUNT, sizeof(*h), 0, 0, NULL);
  237. if (IS_ERR(msg))
  238. return;
  239. h = msg->front.iov_base;
  240. h->monhdr.have_version = 0;
  241. h->monhdr.session_mon = cpu_to_le16(-1);
  242. h->monhdr.session_mon_tid = 0;
  243. ceph_con_send(monc->con, msg);
  244. }
  245. int ceph_monc_request_mount(struct ceph_mon_client *monc)
  246. {
  247. if (!monc->con) {
  248. monc->con = kmalloc(sizeof(*monc->con), GFP_KERNEL);
  249. if (!monc->con)
  250. return -ENOMEM;
  251. ceph_con_init(monc->client->msgr, monc->con);
  252. monc->con->private = monc;
  253. monc->con->ops = &mon_con_ops;
  254. }
  255. mutex_lock(&monc->mutex);
  256. __request_mount(monc);
  257. __schedule_delayed(monc);
  258. mutex_unlock(&monc->mutex);
  259. return 0;
  260. }
  261. /*
  262. * The monitor responds with mount ack indicate mount success. The
  263. * included client ticket allows the client to talk to MDSs and OSDs.
  264. */
  265. static void handle_mount_ack(struct ceph_mon_client *monc, struct ceph_msg *msg)
  266. {
  267. struct ceph_client *client = monc->client;
  268. struct ceph_monmap *monmap = NULL, *old = monc->monmap;
  269. void *p, *end;
  270. s32 result;
  271. u32 len;
  272. s64 cnum;
  273. int err = -EINVAL;
  274. if (client->whoami >= 0) {
  275. dout("handle_mount_ack - already mounted\n");
  276. return;
  277. }
  278. mutex_lock(&monc->mutex);
  279. dout("handle_mount_ack\n");
  280. p = msg->front.iov_base;
  281. end = p + msg->front.iov_len;
  282. ceph_decode_64_safe(&p, end, cnum, bad);
  283. ceph_decode_32_safe(&p, end, result, bad);
  284. ceph_decode_32_safe(&p, end, len, bad);
  285. if (result) {
  286. pr_err("mount denied: %.*s (%d)\n", len, (char *)p,
  287. result);
  288. err = result;
  289. goto out;
  290. }
  291. p += len;
  292. ceph_decode_32_safe(&p, end, len, bad);
  293. ceph_decode_need(&p, end, len, bad);
  294. monmap = ceph_monmap_decode(p, p + len);
  295. if (IS_ERR(monmap)) {
  296. pr_err("problem decoding monmap, %d\n",
  297. (int)PTR_ERR(monmap));
  298. err = -EINVAL;
  299. goto out;
  300. }
  301. p += len;
  302. client->monc.monmap = monmap;
  303. kfree(old);
  304. client->signed_ticket = NULL;
  305. client->signed_ticket_len = 0;
  306. monc->want_mount = false;
  307. client->whoami = cnum;
  308. client->msgr->inst.name.type = CEPH_ENTITY_TYPE_CLIENT;
  309. client->msgr->inst.name.num = cpu_to_le64(cnum);
  310. pr_info("client%lld fsid " FSID_FORMAT "\n",
  311. client->whoami, PR_FSID(&client->monc.monmap->fsid));
  312. ceph_debugfs_client_init(client);
  313. __send_subscribe(monc);
  314. err = 0;
  315. goto out;
  316. bad:
  317. pr_err("error decoding mount_ack message\n");
  318. out:
  319. client->mount_err = err;
  320. mutex_unlock(&monc->mutex);
  321. wake_up(&client->mount_wq);
  322. }
  323. /*
  324. * statfs
  325. */
  326. static void handle_statfs_reply(struct ceph_mon_client *monc,
  327. struct ceph_msg *msg)
  328. {
  329. struct ceph_mon_statfs_request *req;
  330. struct ceph_mon_statfs_reply *reply = msg->front.iov_base;
  331. u64 tid;
  332. if (msg->front.iov_len != sizeof(*reply))
  333. goto bad;
  334. tid = le64_to_cpu(reply->tid);
  335. dout("handle_statfs_reply %p tid %llu\n", msg, tid);
  336. mutex_lock(&monc->mutex);
  337. req = radix_tree_lookup(&monc->statfs_request_tree, tid);
  338. if (req) {
  339. *req->buf = reply->st;
  340. req->result = 0;
  341. }
  342. mutex_unlock(&monc->mutex);
  343. if (req)
  344. complete(&req->completion);
  345. return;
  346. bad:
  347. pr_err("corrupt statfs reply, no tid\n");
  348. }
  349. /*
  350. * (re)send a statfs request
  351. */
  352. static int send_statfs(struct ceph_mon_client *monc,
  353. struct ceph_mon_statfs_request *req)
  354. {
  355. struct ceph_msg *msg;
  356. struct ceph_mon_statfs *h;
  357. int err;
  358. dout("send_statfs tid %llu\n", req->tid);
  359. err = __open_session(monc);
  360. if (err)
  361. return err;
  362. msg = ceph_msg_new(CEPH_MSG_STATFS, sizeof(*h), 0, 0, NULL);
  363. if (IS_ERR(msg))
  364. return PTR_ERR(msg);
  365. req->request = msg;
  366. h = msg->front.iov_base;
  367. h->monhdr.have_version = 0;
  368. h->monhdr.session_mon = cpu_to_le16(-1);
  369. h->monhdr.session_mon_tid = 0;
  370. h->fsid = monc->monmap->fsid;
  371. h->tid = cpu_to_le64(req->tid);
  372. ceph_con_send(monc->con, msg);
  373. return 0;
  374. }
  375. /*
  376. * Do a synchronous statfs().
  377. */
  378. int ceph_monc_do_statfs(struct ceph_mon_client *monc, struct ceph_statfs *buf)
  379. {
  380. struct ceph_mon_statfs_request req;
  381. int err;
  382. req.buf = buf;
  383. init_completion(&req.completion);
  384. /* allocate memory for reply */
  385. err = ceph_msgpool_resv(&monc->msgpool_statfs_reply, 1);
  386. if (err)
  387. return err;
  388. /* register request */
  389. mutex_lock(&monc->mutex);
  390. req.tid = ++monc->last_tid;
  391. req.last_attempt = jiffies;
  392. req.delay = BASE_DELAY_INTERVAL;
  393. if (radix_tree_insert(&monc->statfs_request_tree, req.tid, &req) < 0) {
  394. mutex_unlock(&monc->mutex);
  395. pr_err("ENOMEM in do_statfs\n");
  396. return -ENOMEM;
  397. }
  398. monc->num_statfs_requests++;
  399. mutex_unlock(&monc->mutex);
  400. /* send request and wait */
  401. err = send_statfs(monc, &req);
  402. if (!err)
  403. err = wait_for_completion_interruptible(&req.completion);
  404. mutex_lock(&monc->mutex);
  405. radix_tree_delete(&monc->statfs_request_tree, req.tid);
  406. monc->num_statfs_requests--;
  407. ceph_msgpool_resv(&monc->msgpool_statfs_reply, -1);
  408. mutex_unlock(&monc->mutex);
  409. if (!err)
  410. err = req.result;
  411. return err;
  412. }
  413. /*
  414. * Resend pending statfs requests.
  415. */
  416. static void __resend_statfs(struct ceph_mon_client *monc)
  417. {
  418. u64 next_tid = 0;
  419. int got;
  420. int did = 0;
  421. struct ceph_mon_statfs_request *req;
  422. while (1) {
  423. got = radix_tree_gang_lookup(&monc->statfs_request_tree,
  424. (void **)&req,
  425. next_tid, 1);
  426. if (got == 0)
  427. break;
  428. did++;
  429. next_tid = req->tid + 1;
  430. send_statfs(monc, req);
  431. }
  432. }
  433. /*
  434. * Delayed work. If we haven't mounted yet, retry. Otherwise,
  435. * renew/retry subscription as needed (in case it is timing out, or we
  436. * got an ENOMEM). And keep the monitor connection alive.
  437. */
  438. static void delayed_work(struct work_struct *work)
  439. {
  440. struct ceph_mon_client *monc =
  441. container_of(work, struct ceph_mon_client, delayed_work.work);
  442. dout("monc delayed_work\n");
  443. mutex_lock(&monc->mutex);
  444. if (monc->want_mount) {
  445. __request_mount(monc);
  446. } else {
  447. if (monc->hunting) {
  448. __close_session(monc);
  449. __open_session(monc); /* continue hunting */
  450. } else {
  451. ceph_con_keepalive(monc->con);
  452. }
  453. }
  454. __send_subscribe(monc);
  455. __schedule_delayed(monc);
  456. mutex_unlock(&monc->mutex);
  457. }
  458. int ceph_monc_init(struct ceph_mon_client *monc, struct ceph_client *cl)
  459. {
  460. int err = 0;
  461. dout("init\n");
  462. memset(monc, 0, sizeof(*monc));
  463. monc->client = cl;
  464. monc->monmap = NULL;
  465. mutex_init(&monc->mutex);
  466. monc->con = NULL;
  467. /* msg pools */
  468. err = ceph_msgpool_init(&monc->msgpool_mount_ack, 4096, 1, false);
  469. if (err < 0)
  470. goto out;
  471. err = ceph_msgpool_init(&monc->msgpool_subscribe_ack, 8, 1, false);
  472. if (err < 0)
  473. goto out;
  474. err = ceph_msgpool_init(&monc->msgpool_statfs_reply,
  475. sizeof(struct ceph_mon_statfs_reply), 0, false);
  476. if (err < 0)
  477. goto out;
  478. monc->cur_mon = -1;
  479. monc->hunting = false; /* not really */
  480. monc->sub_renew_after = jiffies;
  481. monc->sub_sent = 0;
  482. INIT_DELAYED_WORK(&monc->delayed_work, delayed_work);
  483. INIT_RADIX_TREE(&monc->statfs_request_tree, GFP_NOFS);
  484. monc->num_statfs_requests = 0;
  485. monc->last_tid = 0;
  486. monc->have_mdsmap = 0;
  487. monc->have_osdmap = 0;
  488. monc->want_next_osdmap = 1;
  489. monc->want_mount = true;
  490. out:
  491. return err;
  492. }
  493. void ceph_monc_stop(struct ceph_mon_client *monc)
  494. {
  495. dout("stop\n");
  496. cancel_delayed_work_sync(&monc->delayed_work);
  497. mutex_lock(&monc->mutex);
  498. __close_session(monc);
  499. if (monc->con) {
  500. monc->con->private = NULL;
  501. monc->con->ops->put(monc->con);
  502. monc->con = NULL;
  503. }
  504. mutex_unlock(&monc->mutex);
  505. ceph_msgpool_destroy(&monc->msgpool_mount_ack);
  506. ceph_msgpool_destroy(&monc->msgpool_subscribe_ack);
  507. ceph_msgpool_destroy(&monc->msgpool_statfs_reply);
  508. kfree(monc->monmap);
  509. }
  510. /*
  511. * handle incoming message
  512. */
  513. static void dispatch(struct ceph_connection *con, struct ceph_msg *msg)
  514. {
  515. struct ceph_mon_client *monc = con->private;
  516. int type = le16_to_cpu(msg->hdr.type);
  517. if (!monc)
  518. return;
  519. switch (type) {
  520. case CEPH_MSG_CLIENT_MOUNT_ACK:
  521. handle_mount_ack(monc, msg);
  522. break;
  523. case CEPH_MSG_MON_SUBSCRIBE_ACK:
  524. handle_subscribe_ack(monc, msg);
  525. break;
  526. case CEPH_MSG_STATFS_REPLY:
  527. handle_statfs_reply(monc, msg);
  528. break;
  529. case CEPH_MSG_MDS_MAP:
  530. ceph_mdsc_handle_map(&monc->client->mdsc, msg);
  531. break;
  532. case CEPH_MSG_OSD_MAP:
  533. ceph_osdc_handle_map(&monc->client->osdc, msg);
  534. break;
  535. default:
  536. pr_err("received unknown message type %d %s\n", type,
  537. ceph_msg_type_name(type));
  538. }
  539. ceph_msg_put(msg);
  540. }
  541. /*
  542. * Allocate memory for incoming message
  543. */
  544. static struct ceph_msg *mon_alloc_msg(struct ceph_connection *con,
  545. struct ceph_msg_header *hdr)
  546. {
  547. struct ceph_mon_client *monc = con->private;
  548. int type = le16_to_cpu(hdr->type);
  549. switch (type) {
  550. case CEPH_MSG_CLIENT_MOUNT_ACK:
  551. return ceph_msgpool_get(&monc->msgpool_mount_ack);
  552. case CEPH_MSG_MON_SUBSCRIBE_ACK:
  553. return ceph_msgpool_get(&monc->msgpool_subscribe_ack);
  554. case CEPH_MSG_STATFS_REPLY:
  555. return ceph_msgpool_get(&monc->msgpool_statfs_reply);
  556. }
  557. return ceph_alloc_msg(con, hdr);
  558. }
  559. /*
  560. * If the monitor connection resets, pick a new monitor and resubmit
  561. * any pending requests.
  562. */
  563. static void mon_fault(struct ceph_connection *con)
  564. {
  565. struct ceph_mon_client *monc = con->private;
  566. if (!monc)
  567. return;
  568. dout("mon_fault\n");
  569. mutex_lock(&monc->mutex);
  570. if (!con->private)
  571. goto out;
  572. if (monc->con && !monc->hunting)
  573. pr_info("mon%d %s session lost, "
  574. "hunting for new mon\n", monc->cur_mon,
  575. pr_addr(&monc->con->peer_addr.in_addr));
  576. __close_session(monc);
  577. if (!monc->hunting) {
  578. /* start hunting */
  579. monc->hunting = true;
  580. if (__open_session(monc) == 0) {
  581. __send_subscribe(monc);
  582. __resend_statfs(monc);
  583. }
  584. } else {
  585. /* already hunting, let's wait a bit */
  586. __schedule_delayed(monc);
  587. }
  588. out:
  589. mutex_unlock(&monc->mutex);
  590. }
  591. const static struct ceph_connection_operations mon_con_ops = {
  592. .get = ceph_con_get,
  593. .put = ceph_con_put,
  594. .dispatch = dispatch,
  595. .fault = mon_fault,
  596. .alloc_msg = mon_alloc_msg,
  597. .alloc_middle = ceph_alloc_middle,
  598. };