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. epoch = ceph_decode_32(&p);
  41. num_mon = ceph_decode_32(&p);
  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. dout("monmap_decode epoch %d, num_mon %d\n", m->epoch,
  53. m->num_mon);
  54. for (i = 0; i < m->num_mon; i++)
  55. dout("monmap_decode mon%d is %s\n", i,
  56. pr_addr(&m->mon_inst[i].addr.in_addr));
  57. return m;
  58. bad:
  59. dout("monmap_decode failed with %d\n", err);
  60. kfree(m);
  61. return ERR_PTR(err);
  62. }
  63. /*
  64. * return true if *addr is included in the monmap.
  65. */
  66. int ceph_monmap_contains(struct ceph_monmap *m, struct ceph_entity_addr *addr)
  67. {
  68. int i;
  69. for (i = 0; i < m->num_mon; i++)
  70. if (ceph_entity_addr_equal(addr, &m->mon_inst[i].addr))
  71. return 1;
  72. return 0;
  73. }
  74. /*
  75. * Close monitor session, if any.
  76. */
  77. static void __close_session(struct ceph_mon_client *monc)
  78. {
  79. if (monc->con) {
  80. dout("__close_session closing mon%d\n", monc->cur_mon);
  81. ceph_con_close(monc->con);
  82. monc->cur_mon = -1;
  83. }
  84. }
  85. /*
  86. * Open a session with a (new) monitor.
  87. */
  88. static int __open_session(struct ceph_mon_client *monc)
  89. {
  90. char r;
  91. if (monc->cur_mon < 0) {
  92. get_random_bytes(&r, 1);
  93. monc->cur_mon = r % monc->monmap->num_mon;
  94. dout("open_session num=%d r=%d -> mon%d\n",
  95. monc->monmap->num_mon, r, monc->cur_mon);
  96. monc->sub_sent = 0;
  97. monc->sub_renew_after = jiffies; /* i.e., expired */
  98. monc->want_next_osdmap = !!monc->want_next_osdmap;
  99. dout("open_session mon%d opening\n", monc->cur_mon);
  100. monc->con->peer_name.type = CEPH_ENTITY_TYPE_MON;
  101. monc->con->peer_name.num = cpu_to_le64(monc->cur_mon);
  102. ceph_con_open(monc->con,
  103. &monc->monmap->mon_inst[monc->cur_mon].addr);
  104. } else {
  105. dout("open_session mon%d already open\n", monc->cur_mon);
  106. }
  107. return 0;
  108. }
  109. static bool __sub_expired(struct ceph_mon_client *monc)
  110. {
  111. return time_after_eq(jiffies, monc->sub_renew_after);
  112. }
  113. /*
  114. * Reschedule delayed work timer.
  115. */
  116. static void __schedule_delayed(struct ceph_mon_client *monc)
  117. {
  118. unsigned delay;
  119. if (monc->cur_mon < 0 || monc->want_mount || __sub_expired(monc))
  120. delay = 10 * HZ;
  121. else
  122. delay = 20 * HZ;
  123. dout("__schedule_delayed after %u\n", delay);
  124. schedule_delayed_work(&monc->delayed_work, delay);
  125. }
  126. /*
  127. * Send subscribe request for mdsmap and/or osdmap.
  128. */
  129. static void __send_subscribe(struct ceph_mon_client *monc)
  130. {
  131. dout("__send_subscribe sub_sent=%u exp=%u want_osd=%d\n",
  132. (unsigned)monc->sub_sent, __sub_expired(monc),
  133. monc->want_next_osdmap);
  134. if ((__sub_expired(monc) && !monc->sub_sent) ||
  135. monc->want_next_osdmap == 1) {
  136. struct ceph_msg *msg;
  137. struct ceph_mon_subscribe_item *i;
  138. void *p, *end;
  139. msg = ceph_msg_new(CEPH_MSG_MON_SUBSCRIBE, 64, 0, 0, NULL);
  140. if (!msg)
  141. return;
  142. p = msg->front.iov_base;
  143. end = p + msg->front.iov_len;
  144. dout("__send_subscribe to 'mdsmap' %u+\n",
  145. (unsigned)monc->have_mdsmap);
  146. if (monc->want_next_osdmap) {
  147. dout("__send_subscribe to 'osdmap' %u\n",
  148. (unsigned)monc->have_osdmap);
  149. ceph_encode_32(&p, 2);
  150. ceph_encode_string(&p, end, "osdmap", 6);
  151. i = p;
  152. i->have = cpu_to_le64(monc->have_osdmap);
  153. i->onetime = 1;
  154. p += sizeof(*i);
  155. monc->want_next_osdmap = 2; /* requested */
  156. } else {
  157. ceph_encode_32(&p, 1);
  158. }
  159. ceph_encode_string(&p, end, "mdsmap", 6);
  160. i = p;
  161. i->have = cpu_to_le64(monc->have_mdsmap);
  162. i->onetime = 0;
  163. p += sizeof(*i);
  164. msg->front.iov_len = p - msg->front.iov_base;
  165. msg->hdr.front_len = cpu_to_le32(msg->front.iov_len);
  166. ceph_con_send(monc->con, msg);
  167. monc->sub_sent = jiffies | 1; /* never 0 */
  168. }
  169. }
  170. static void handle_subscribe_ack(struct ceph_mon_client *monc,
  171. struct ceph_msg *msg)
  172. {
  173. unsigned seconds;
  174. struct ceph_mon_subscribe_ack *h = msg->front.iov_base;
  175. if (msg->front.iov_len < sizeof(*h))
  176. goto bad;
  177. seconds = le32_to_cpu(h->duration);
  178. mutex_lock(&monc->mutex);
  179. if (monc->hunting) {
  180. pr_info("mon%d %s session established\n",
  181. monc->cur_mon, pr_addr(&monc->con->peer_addr.in_addr));
  182. monc->hunting = false;
  183. }
  184. dout("handle_subscribe_ack after %d seconds\n", seconds);
  185. monc->sub_renew_after = monc->sub_sent + (seconds >> 1)*HZ - 1;
  186. monc->sub_sent = 0;
  187. mutex_unlock(&monc->mutex);
  188. return;
  189. bad:
  190. pr_err("got corrupt subscribe-ack msg\n");
  191. }
  192. /*
  193. * Keep track of which maps we have
  194. */
  195. int ceph_monc_got_mdsmap(struct ceph_mon_client *monc, u32 got)
  196. {
  197. mutex_lock(&monc->mutex);
  198. monc->have_mdsmap = got;
  199. mutex_unlock(&monc->mutex);
  200. return 0;
  201. }
  202. int ceph_monc_got_osdmap(struct ceph_mon_client *monc, u32 got)
  203. {
  204. mutex_lock(&monc->mutex);
  205. monc->have_osdmap = got;
  206. monc->want_next_osdmap = 0;
  207. mutex_unlock(&monc->mutex);
  208. return 0;
  209. }
  210. /*
  211. * Register interest in the next osdmap
  212. */
  213. void ceph_monc_request_next_osdmap(struct ceph_mon_client *monc)
  214. {
  215. dout("request_next_osdmap have %u\n", monc->have_osdmap);
  216. mutex_lock(&monc->mutex);
  217. if (!monc->want_next_osdmap)
  218. monc->want_next_osdmap = 1;
  219. if (monc->want_next_osdmap < 2)
  220. __send_subscribe(monc);
  221. mutex_unlock(&monc->mutex);
  222. }
  223. /*
  224. * mount
  225. */
  226. static void __request_mount(struct ceph_mon_client *monc)
  227. {
  228. struct ceph_msg *msg;
  229. struct ceph_client_mount *h;
  230. int err;
  231. dout("__request_mount\n");
  232. err = __open_session(monc);
  233. if (err)
  234. return;
  235. msg = ceph_msg_new(CEPH_MSG_CLIENT_MOUNT, sizeof(*h), 0, 0, NULL);
  236. if (IS_ERR(msg))
  237. return;
  238. h = msg->front.iov_base;
  239. h->monhdr.have_version = 0;
  240. h->monhdr.session_mon = cpu_to_le16(-1);
  241. h->monhdr.session_mon_tid = 0;
  242. ceph_con_send(monc->con, msg);
  243. }
  244. int ceph_monc_request_mount(struct ceph_mon_client *monc)
  245. {
  246. if (!monc->con) {
  247. monc->con = kmalloc(sizeof(*monc->con), GFP_KERNEL);
  248. if (!monc->con)
  249. return -ENOMEM;
  250. ceph_con_init(monc->client->msgr, monc->con);
  251. monc->con->private = monc;
  252. monc->con->ops = &mon_con_ops;
  253. }
  254. mutex_lock(&monc->mutex);
  255. __request_mount(monc);
  256. __schedule_delayed(monc);
  257. mutex_unlock(&monc->mutex);
  258. return 0;
  259. }
  260. /*
  261. * The monitor responds with mount ack indicate mount success. The
  262. * included client ticket allows the client to talk to MDSs and OSDs.
  263. */
  264. static void handle_mount_ack(struct ceph_mon_client *monc, struct ceph_msg *msg)
  265. {
  266. struct ceph_client *client = monc->client;
  267. struct ceph_monmap *monmap = NULL, *old = monc->monmap;
  268. void *p, *end;
  269. s32 result;
  270. u32 len;
  271. s64 cnum;
  272. int err = -EINVAL;
  273. if (client->whoami >= 0) {
  274. dout("handle_mount_ack - already mounted\n");
  275. return;
  276. }
  277. mutex_lock(&monc->mutex);
  278. dout("handle_mount_ack\n");
  279. p = msg->front.iov_base;
  280. end = p + msg->front.iov_len;
  281. ceph_decode_64_safe(&p, end, cnum, bad);
  282. ceph_decode_32_safe(&p, end, result, bad);
  283. ceph_decode_32_safe(&p, end, len, bad);
  284. if (result) {
  285. pr_err("mount denied: %.*s (%d)\n", len, (char *)p,
  286. result);
  287. err = result;
  288. goto out;
  289. }
  290. p += len;
  291. ceph_decode_32_safe(&p, end, len, bad);
  292. ceph_decode_need(&p, end, len, bad);
  293. monmap = ceph_monmap_decode(p, p + len);
  294. if (IS_ERR(monmap)) {
  295. pr_err("problem decoding monmap, %d\n",
  296. (int)PTR_ERR(monmap));
  297. err = -EINVAL;
  298. goto out;
  299. }
  300. p += len;
  301. client->monc.monmap = monmap;
  302. kfree(old);
  303. client->signed_ticket = NULL;
  304. client->signed_ticket_len = 0;
  305. monc->want_mount = false;
  306. client->whoami = cnum;
  307. client->msgr->inst.name.type = CEPH_ENTITY_TYPE_CLIENT;
  308. client->msgr->inst.name.num = cpu_to_le64(cnum);
  309. pr_info("client%lld fsid " FSID_FORMAT "\n",
  310. client->whoami, PR_FSID(&client->monc.monmap->fsid));
  311. ceph_debugfs_client_init(client);
  312. __send_subscribe(monc);
  313. err = 0;
  314. goto out;
  315. bad:
  316. pr_err("error decoding mount_ack message\n");
  317. out:
  318. client->mount_err = err;
  319. mutex_unlock(&monc->mutex);
  320. wake_up(&client->mount_wq);
  321. }
  322. /*
  323. * statfs
  324. */
  325. static void handle_statfs_reply(struct ceph_mon_client *monc,
  326. struct ceph_msg *msg)
  327. {
  328. struct ceph_mon_statfs_request *req;
  329. struct ceph_mon_statfs_reply *reply = msg->front.iov_base;
  330. u64 tid;
  331. if (msg->front.iov_len != sizeof(*reply))
  332. goto bad;
  333. tid = le64_to_cpu(reply->tid);
  334. dout("handle_statfs_reply %p tid %llu\n", msg, tid);
  335. mutex_lock(&monc->mutex);
  336. req = radix_tree_lookup(&monc->statfs_request_tree, tid);
  337. if (req) {
  338. *req->buf = reply->st;
  339. req->result = 0;
  340. }
  341. mutex_unlock(&monc->mutex);
  342. if (req)
  343. complete(&req->completion);
  344. return;
  345. bad:
  346. pr_err("corrupt statfs reply, no tid\n");
  347. }
  348. /*
  349. * (re)send a statfs request
  350. */
  351. static int send_statfs(struct ceph_mon_client *monc,
  352. struct ceph_mon_statfs_request *req)
  353. {
  354. struct ceph_msg *msg;
  355. struct ceph_mon_statfs *h;
  356. int err;
  357. dout("send_statfs tid %llu\n", req->tid);
  358. err = __open_session(monc);
  359. if (err)
  360. return err;
  361. msg = ceph_msg_new(CEPH_MSG_STATFS, sizeof(*h), 0, 0, NULL);
  362. if (IS_ERR(msg))
  363. return PTR_ERR(msg);
  364. req->request = msg;
  365. h = msg->front.iov_base;
  366. h->monhdr.have_version = 0;
  367. h->monhdr.session_mon = cpu_to_le16(-1);
  368. h->monhdr.session_mon_tid = 0;
  369. h->fsid = monc->monmap->fsid;
  370. h->tid = cpu_to_le64(req->tid);
  371. ceph_con_send(monc->con, msg);
  372. return 0;
  373. }
  374. /*
  375. * Do a synchronous statfs().
  376. */
  377. int ceph_monc_do_statfs(struct ceph_mon_client *monc, struct ceph_statfs *buf)
  378. {
  379. struct ceph_mon_statfs_request req;
  380. int err;
  381. req.buf = buf;
  382. init_completion(&req.completion);
  383. /* allocate memory for reply */
  384. err = ceph_msgpool_resv(&monc->msgpool_statfs_reply, 1);
  385. if (err)
  386. return err;
  387. /* register request */
  388. mutex_lock(&monc->mutex);
  389. req.tid = ++monc->last_tid;
  390. req.last_attempt = jiffies;
  391. req.delay = BASE_DELAY_INTERVAL;
  392. if (radix_tree_insert(&monc->statfs_request_tree, req.tid, &req) < 0) {
  393. mutex_unlock(&monc->mutex);
  394. pr_err("ENOMEM in do_statfs\n");
  395. return -ENOMEM;
  396. }
  397. monc->num_statfs_requests++;
  398. mutex_unlock(&monc->mutex);
  399. /* send request and wait */
  400. err = send_statfs(monc, &req);
  401. if (!err)
  402. err = wait_for_completion_interruptible(&req.completion);
  403. mutex_lock(&monc->mutex);
  404. radix_tree_delete(&monc->statfs_request_tree, req.tid);
  405. monc->num_statfs_requests--;
  406. ceph_msgpool_resv(&monc->msgpool_statfs_reply, -1);
  407. mutex_unlock(&monc->mutex);
  408. if (!err)
  409. err = req.result;
  410. return err;
  411. }
  412. /*
  413. * Resend pending statfs requests.
  414. */
  415. static void __resend_statfs(struct ceph_mon_client *monc)
  416. {
  417. u64 next_tid = 0;
  418. int got;
  419. int did = 0;
  420. struct ceph_mon_statfs_request *req;
  421. while (1) {
  422. got = radix_tree_gang_lookup(&monc->statfs_request_tree,
  423. (void **)&req,
  424. next_tid, 1);
  425. if (got == 0)
  426. break;
  427. did++;
  428. next_tid = req->tid + 1;
  429. send_statfs(monc, req);
  430. }
  431. }
  432. /*
  433. * Delayed work. If we haven't mounted yet, retry. Otherwise,
  434. * renew/retry subscription as needed (in case it is timing out, or we
  435. * got an ENOMEM). And keep the monitor connection alive.
  436. */
  437. static void delayed_work(struct work_struct *work)
  438. {
  439. struct ceph_mon_client *monc =
  440. container_of(work, struct ceph_mon_client, delayed_work.work);
  441. dout("monc delayed_work\n");
  442. mutex_lock(&monc->mutex);
  443. if (monc->want_mount) {
  444. __request_mount(monc);
  445. } else {
  446. if (monc->hunting) {
  447. __close_session(monc);
  448. __open_session(monc); /* continue hunting */
  449. } else {
  450. ceph_con_keepalive(monc->con);
  451. }
  452. }
  453. __send_subscribe(monc);
  454. __schedule_delayed(monc);
  455. mutex_unlock(&monc->mutex);
  456. }
  457. int ceph_monc_init(struct ceph_mon_client *monc, struct ceph_client *cl)
  458. {
  459. int err = 0;
  460. dout("init\n");
  461. memset(monc, 0, sizeof(*monc));
  462. monc->client = cl;
  463. monc->monmap = NULL;
  464. mutex_init(&monc->mutex);
  465. monc->con = NULL;
  466. /* msg pools */
  467. err = ceph_msgpool_init(&monc->msgpool_mount_ack, 4096, 1, false);
  468. if (err < 0)
  469. goto out;
  470. err = ceph_msgpool_init(&monc->msgpool_subscribe_ack,
  471. sizeof(struct ceph_mon_subscribe_ack), 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. };