osd_client.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294
  1. #include "ceph_debug.h"
  2. #include <linux/err.h>
  3. #include <linux/highmem.h>
  4. #include <linux/mm.h>
  5. #include <linux/pagemap.h>
  6. #include <linux/slab.h>
  7. #include <linux/uaccess.h>
  8. #include "super.h"
  9. #include "osd_client.h"
  10. #include "messenger.h"
  11. #include "decode.h"
  12. const static struct ceph_connection_operations osd_con_ops;
  13. static void kick_requests(struct ceph_osd_client *osdc, struct ceph_osd *osd);
  14. /*
  15. * Implement client access to distributed object storage cluster.
  16. *
  17. * All data objects are stored within a cluster/cloud of OSDs, or
  18. * "object storage devices." (Note that Ceph OSDs have _nothing_ to
  19. * do with the T10 OSD extensions to SCSI.) Ceph OSDs are simply
  20. * remote daemons serving up and coordinating consistent and safe
  21. * access to storage.
  22. *
  23. * Cluster membership and the mapping of data objects onto storage devices
  24. * are described by the osd map.
  25. *
  26. * We keep track of pending OSD requests (read, write), resubmit
  27. * requests to different OSDs when the cluster topology/data layout
  28. * change, or retry the affected requests when the communications
  29. * channel with an OSD is reset.
  30. */
  31. /*
  32. * calculate the mapping of a file extent onto an object, and fill out the
  33. * request accordingly. shorten extent as necessary if it crosses an
  34. * object boundary.
  35. *
  36. * fill osd op in request message.
  37. */
  38. static void calc_layout(struct ceph_osd_client *osdc,
  39. struct ceph_vino vino, struct ceph_file_layout *layout,
  40. u64 off, u64 *plen,
  41. struct ceph_osd_request *req)
  42. {
  43. struct ceph_osd_request_head *reqhead = req->r_request->front.iov_base;
  44. struct ceph_osd_op *op = (void *)(reqhead + 1);
  45. u64 orig_len = *plen;
  46. u64 objoff, objlen; /* extent in object */
  47. u64 bno;
  48. reqhead->snapid = cpu_to_le64(vino.snap);
  49. /* object extent? */
  50. ceph_calc_file_object_mapping(layout, off, plen, &bno,
  51. &objoff, &objlen);
  52. if (*plen < orig_len)
  53. dout(" skipping last %llu, final file extent %llu~%llu\n",
  54. orig_len - *plen, off, *plen);
  55. sprintf(req->r_oid, "%llx.%08llx", vino.ino, bno);
  56. req->r_oid_len = strlen(req->r_oid);
  57. op->extent.offset = cpu_to_le64(objoff);
  58. op->extent.length = cpu_to_le64(objlen);
  59. req->r_num_pages = calc_pages_for(off, *plen);
  60. dout("calc_layout %s (%d) %llu~%llu (%d pages)\n",
  61. req->r_oid, req->r_oid_len, objoff, objlen, req->r_num_pages);
  62. }
  63. /*
  64. * requests
  65. */
  66. void ceph_osdc_put_request(struct ceph_osd_request *req)
  67. {
  68. dout("osdc put_request %p %d -> %d\n", req, atomic_read(&req->r_ref),
  69. atomic_read(&req->r_ref)-1);
  70. BUG_ON(atomic_read(&req->r_ref) <= 0);
  71. if (atomic_dec_and_test(&req->r_ref)) {
  72. if (req->r_request)
  73. ceph_msg_put(req->r_request);
  74. if (req->r_reply)
  75. ceph_msg_put(req->r_reply);
  76. if (req->r_own_pages)
  77. ceph_release_page_vector(req->r_pages,
  78. req->r_num_pages);
  79. ceph_put_snap_context(req->r_snapc);
  80. if (req->r_mempool)
  81. mempool_free(req, req->r_osdc->req_mempool);
  82. else
  83. kfree(req);
  84. }
  85. }
  86. /*
  87. * build new request AND message, calculate layout, and adjust file
  88. * extent as needed.
  89. *
  90. * if the file was recently truncated, we include information about its
  91. * old and new size so that the object can be updated appropriately. (we
  92. * avoid synchronously deleting truncated objects because it's slow.)
  93. *
  94. * if @do_sync, include a 'startsync' command so that the osd will flush
  95. * data quickly.
  96. */
  97. struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc,
  98. struct ceph_file_layout *layout,
  99. struct ceph_vino vino,
  100. u64 off, u64 *plen,
  101. int opcode, int flags,
  102. struct ceph_snap_context *snapc,
  103. int do_sync,
  104. u32 truncate_seq,
  105. u64 truncate_size,
  106. struct timespec *mtime,
  107. bool use_mempool, int num_reply)
  108. {
  109. struct ceph_osd_request *req;
  110. struct ceph_msg *msg;
  111. struct ceph_osd_request_head *head;
  112. struct ceph_osd_op *op;
  113. void *p;
  114. int do_trunc = truncate_seq && (off + *plen > truncate_size);
  115. int num_op = 1 + do_sync + do_trunc;
  116. size_t msg_size = sizeof(*head) + num_op*sizeof(*op);
  117. int err, i;
  118. u64 prevofs;
  119. if (use_mempool) {
  120. req = mempool_alloc(osdc->req_mempool, GFP_NOFS);
  121. memset(req, 0, sizeof(*req));
  122. } else {
  123. req = kzalloc(sizeof(*req), GFP_NOFS);
  124. }
  125. if (req == NULL)
  126. return ERR_PTR(-ENOMEM);
  127. err = ceph_msgpool_resv(&osdc->msgpool_op_reply, num_reply);
  128. if (err) {
  129. ceph_osdc_put_request(req);
  130. return ERR_PTR(-ENOMEM);
  131. }
  132. req->r_osdc = osdc;
  133. req->r_mempool = use_mempool;
  134. atomic_set(&req->r_ref, 1);
  135. init_completion(&req->r_completion);
  136. init_completion(&req->r_safe_completion);
  137. INIT_LIST_HEAD(&req->r_unsafe_item);
  138. req->r_flags = flags;
  139. WARN_ON((flags & (CEPH_OSD_FLAG_READ|CEPH_OSD_FLAG_WRITE)) == 0);
  140. /* create message; allow space for oid */
  141. msg_size += 40;
  142. if (snapc)
  143. msg_size += sizeof(u64) * snapc->num_snaps;
  144. if (use_mempool)
  145. msg = ceph_msgpool_get(&osdc->msgpool_op);
  146. else
  147. msg = ceph_msg_new(CEPH_MSG_OSD_OP, msg_size, 0, 0, NULL);
  148. if (IS_ERR(msg)) {
  149. ceph_msgpool_resv(&osdc->msgpool_op_reply, num_reply);
  150. ceph_osdc_put_request(req);
  151. return ERR_PTR(PTR_ERR(msg));
  152. }
  153. msg->hdr.type = cpu_to_le16(CEPH_MSG_OSD_OP);
  154. memset(msg->front.iov_base, 0, msg->front.iov_len);
  155. head = msg->front.iov_base;
  156. op = (void *)(head + 1);
  157. p = (void *)(op + num_op);
  158. req->r_request = msg;
  159. req->r_snapc = ceph_get_snap_context(snapc);
  160. head->client_inc = cpu_to_le32(1); /* always, for now. */
  161. head->flags = cpu_to_le32(flags);
  162. if (flags & CEPH_OSD_FLAG_WRITE)
  163. ceph_encode_timespec(&head->mtime, mtime);
  164. head->num_ops = cpu_to_le16(num_op);
  165. op->op = cpu_to_le16(opcode);
  166. /* calculate max write size */
  167. calc_layout(osdc, vino, layout, off, plen, req);
  168. req->r_file_layout = *layout; /* keep a copy */
  169. if (flags & CEPH_OSD_FLAG_WRITE) {
  170. req->r_request->hdr.data_off = cpu_to_le16(off);
  171. req->r_request->hdr.data_len = cpu_to_le32(*plen);
  172. op->payload_len = cpu_to_le32(*plen);
  173. }
  174. /* fill in oid */
  175. head->object_len = cpu_to_le32(req->r_oid_len);
  176. memcpy(p, req->r_oid, req->r_oid_len);
  177. p += req->r_oid_len;
  178. /* additional ops */
  179. if (do_trunc) {
  180. op++;
  181. op->op = cpu_to_le16(opcode == CEPH_OSD_OP_READ ?
  182. CEPH_OSD_OP_MASKTRUNC : CEPH_OSD_OP_SETTRUNC);
  183. op->trunc.truncate_seq = cpu_to_le32(truncate_seq);
  184. prevofs = le64_to_cpu((op-1)->extent.offset);
  185. op->trunc.truncate_size = cpu_to_le64(truncate_size -
  186. (off-prevofs));
  187. }
  188. if (do_sync) {
  189. op++;
  190. op->op = cpu_to_le16(CEPH_OSD_OP_STARTSYNC);
  191. }
  192. if (snapc) {
  193. head->snap_seq = cpu_to_le64(snapc->seq);
  194. head->num_snaps = cpu_to_le32(snapc->num_snaps);
  195. for (i = 0; i < snapc->num_snaps; i++) {
  196. put_unaligned_le64(snapc->snaps[i], p);
  197. p += sizeof(u64);
  198. }
  199. }
  200. BUG_ON(p > msg->front.iov_base + msg->front.iov_len);
  201. return req;
  202. }
  203. /*
  204. * We keep osd requests in an rbtree, sorted by ->r_tid.
  205. */
  206. static void __insert_request(struct ceph_osd_client *osdc,
  207. struct ceph_osd_request *new)
  208. {
  209. struct rb_node **p = &osdc->requests.rb_node;
  210. struct rb_node *parent = NULL;
  211. struct ceph_osd_request *req = NULL;
  212. while (*p) {
  213. parent = *p;
  214. req = rb_entry(parent, struct ceph_osd_request, r_node);
  215. if (new->r_tid < req->r_tid)
  216. p = &(*p)->rb_left;
  217. else if (new->r_tid > req->r_tid)
  218. p = &(*p)->rb_right;
  219. else
  220. BUG();
  221. }
  222. rb_link_node(&new->r_node, parent, p);
  223. rb_insert_color(&new->r_node, &osdc->requests);
  224. }
  225. static struct ceph_osd_request *__lookup_request(struct ceph_osd_client *osdc,
  226. u64 tid)
  227. {
  228. struct ceph_osd_request *req;
  229. struct rb_node *n = osdc->requests.rb_node;
  230. while (n) {
  231. req = rb_entry(n, struct ceph_osd_request, r_node);
  232. if (tid < req->r_tid)
  233. n = n->rb_left;
  234. else if (tid > req->r_tid)
  235. n = n->rb_right;
  236. else
  237. return req;
  238. }
  239. return NULL;
  240. }
  241. static struct ceph_osd_request *
  242. __lookup_request_ge(struct ceph_osd_client *osdc,
  243. u64 tid)
  244. {
  245. struct ceph_osd_request *req;
  246. struct rb_node *n = osdc->requests.rb_node;
  247. while (n) {
  248. req = rb_entry(n, struct ceph_osd_request, r_node);
  249. if (tid < req->r_tid) {
  250. if (!n->rb_left)
  251. return req;
  252. n = n->rb_left;
  253. } else if (tid > req->r_tid) {
  254. n = n->rb_right;
  255. } else {
  256. return req;
  257. }
  258. }
  259. return NULL;
  260. }
  261. /*
  262. * The messaging layer will reconnect to the osd as needed. If the
  263. * session has dropped, the OSD will have dropped the session state,
  264. * and we'll get notified by the messaging layer. If that happens, we
  265. * need to resubmit all requests for that osd.
  266. */
  267. static void osd_reset(struct ceph_connection *con)
  268. {
  269. struct ceph_osd *osd = con->private;
  270. struct ceph_osd_client *osdc;
  271. if (!osd)
  272. return;
  273. dout("osd_reset osd%d\n", osd->o_osd);
  274. osdc = osd->o_osdc;
  275. osd->o_incarnation++;
  276. down_read(&osdc->map_sem);
  277. kick_requests(osdc, osd);
  278. up_read(&osdc->map_sem);
  279. }
  280. /*
  281. * Track open sessions with osds.
  282. */
  283. static struct ceph_osd *create_osd(struct ceph_osd_client *osdc)
  284. {
  285. struct ceph_osd *osd;
  286. osd = kzalloc(sizeof(*osd), GFP_NOFS);
  287. if (!osd)
  288. return NULL;
  289. atomic_set(&osd->o_ref, 1);
  290. osd->o_osdc = osdc;
  291. INIT_LIST_HEAD(&osd->o_requests);
  292. osd->o_incarnation = 1;
  293. ceph_con_init(osdc->client->msgr, &osd->o_con);
  294. osd->o_con.private = osd;
  295. osd->o_con.ops = &osd_con_ops;
  296. osd->o_con.peer_name.type = CEPH_ENTITY_TYPE_OSD;
  297. return osd;
  298. }
  299. static struct ceph_osd *get_osd(struct ceph_osd *osd)
  300. {
  301. if (atomic_inc_not_zero(&osd->o_ref)) {
  302. dout("get_osd %p %d -> %d\n", osd, atomic_read(&osd->o_ref)-1,
  303. atomic_read(&osd->o_ref));
  304. return osd;
  305. } else {
  306. dout("get_osd %p FAIL\n", osd);
  307. return NULL;
  308. }
  309. }
  310. static void put_osd(struct ceph_osd *osd)
  311. {
  312. dout("put_osd %p %d -> %d\n", osd, atomic_read(&osd->o_ref),
  313. atomic_read(&osd->o_ref) - 1);
  314. if (atomic_dec_and_test(&osd->o_ref)) {
  315. ceph_con_shutdown(&osd->o_con);
  316. kfree(osd);
  317. }
  318. }
  319. /*
  320. * remove an osd from our map
  321. */
  322. static void remove_osd(struct ceph_osd_client *osdc, struct ceph_osd *osd)
  323. {
  324. dout("remove_osd %p\n", osd);
  325. BUG_ON(!list_empty(&osd->o_requests));
  326. rb_erase(&osd->o_node, &osdc->osds);
  327. ceph_con_close(&osd->o_con);
  328. put_osd(osd);
  329. }
  330. /*
  331. * reset osd connect
  332. */
  333. static int reset_osd(struct ceph_osd_client *osdc, struct ceph_osd *osd)
  334. {
  335. int ret = 0;
  336. dout("reset_osd %p osd%d\n", osd, osd->o_osd);
  337. if (list_empty(&osd->o_requests)) {
  338. remove_osd(osdc, osd);
  339. } else {
  340. ceph_con_close(&osd->o_con);
  341. ceph_con_open(&osd->o_con, &osdc->osdmap->osd_addr[osd->o_osd]);
  342. osd->o_incarnation++;
  343. }
  344. return ret;
  345. }
  346. static void __insert_osd(struct ceph_osd_client *osdc, struct ceph_osd *new)
  347. {
  348. struct rb_node **p = &osdc->osds.rb_node;
  349. struct rb_node *parent = NULL;
  350. struct ceph_osd *osd = NULL;
  351. while (*p) {
  352. parent = *p;
  353. osd = rb_entry(parent, struct ceph_osd, o_node);
  354. if (new->o_osd < osd->o_osd)
  355. p = &(*p)->rb_left;
  356. else if (new->o_osd > osd->o_osd)
  357. p = &(*p)->rb_right;
  358. else
  359. BUG();
  360. }
  361. rb_link_node(&new->o_node, parent, p);
  362. rb_insert_color(&new->o_node, &osdc->osds);
  363. }
  364. static struct ceph_osd *__lookup_osd(struct ceph_osd_client *osdc, int o)
  365. {
  366. struct ceph_osd *osd;
  367. struct rb_node *n = osdc->osds.rb_node;
  368. while (n) {
  369. osd = rb_entry(n, struct ceph_osd, o_node);
  370. if (o < osd->o_osd)
  371. n = n->rb_left;
  372. else if (o > osd->o_osd)
  373. n = n->rb_right;
  374. else
  375. return osd;
  376. }
  377. return NULL;
  378. }
  379. /*
  380. * Register request, assign tid. If this is the first request, set up
  381. * the timeout event.
  382. */
  383. static void register_request(struct ceph_osd_client *osdc,
  384. struct ceph_osd_request *req)
  385. {
  386. struct ceph_osd_request_head *head = req->r_request->front.iov_base;
  387. mutex_lock(&osdc->request_mutex);
  388. req->r_tid = ++osdc->last_tid;
  389. head->tid = cpu_to_le64(req->r_tid);
  390. dout("register_request %p tid %lld\n", req, req->r_tid);
  391. __insert_request(osdc, req);
  392. ceph_osdc_get_request(req);
  393. osdc->num_requests++;
  394. req->r_timeout_stamp =
  395. jiffies + osdc->client->mount_args.osd_timeout*HZ;
  396. if (osdc->num_requests == 1) {
  397. osdc->timeout_tid = req->r_tid;
  398. dout(" timeout on tid %llu at %lu\n", req->r_tid,
  399. req->r_timeout_stamp);
  400. schedule_delayed_work(&osdc->timeout_work,
  401. round_jiffies_relative(req->r_timeout_stamp - jiffies));
  402. }
  403. mutex_unlock(&osdc->request_mutex);
  404. }
  405. /*
  406. * called under osdc->request_mutex
  407. */
  408. static void __unregister_request(struct ceph_osd_client *osdc,
  409. struct ceph_osd_request *req)
  410. {
  411. dout("__unregister_request %p tid %lld\n", req, req->r_tid);
  412. rb_erase(&req->r_node, &osdc->requests);
  413. osdc->num_requests--;
  414. list_del_init(&req->r_osd_item);
  415. if (list_empty(&req->r_osd->o_requests))
  416. remove_osd(osdc, req->r_osd);
  417. req->r_osd = NULL;
  418. ceph_osdc_put_request(req);
  419. if (req->r_tid == osdc->timeout_tid) {
  420. if (osdc->num_requests == 0) {
  421. dout("no requests, canceling timeout\n");
  422. osdc->timeout_tid = 0;
  423. cancel_delayed_work(&osdc->timeout_work);
  424. } else {
  425. req = rb_entry(rb_first(&osdc->requests),
  426. struct ceph_osd_request, r_node);
  427. osdc->timeout_tid = req->r_tid;
  428. dout("rescheduled timeout on tid %llu at %lu\n",
  429. req->r_tid, req->r_timeout_stamp);
  430. schedule_delayed_work(&osdc->timeout_work,
  431. round_jiffies_relative(req->r_timeout_stamp -
  432. jiffies));
  433. }
  434. }
  435. }
  436. /*
  437. * Cancel a previously queued request message
  438. */
  439. static void __cancel_request(struct ceph_osd_request *req)
  440. {
  441. if (req->r_sent) {
  442. ceph_con_revoke(&req->r_osd->o_con, req->r_request);
  443. req->r_sent = 0;
  444. }
  445. }
  446. /*
  447. * Pick an osd (the first 'up' osd in the pg), allocate the osd struct
  448. * (as needed), and set the request r_osd appropriately. If there is
  449. * no up osd, set r_osd to NULL.
  450. *
  451. * Return 0 if unchanged, 1 if changed, or negative on error.
  452. *
  453. * Caller should hold map_sem for read and request_mutex.
  454. */
  455. static int __map_osds(struct ceph_osd_client *osdc,
  456. struct ceph_osd_request *req)
  457. {
  458. struct ceph_osd_request_head *reqhead = req->r_request->front.iov_base;
  459. union ceph_pg pgid;
  460. int o = -1;
  461. int err;
  462. struct ceph_osd *newosd = NULL;
  463. dout("map_osds %p tid %lld\n", req, req->r_tid);
  464. err = ceph_calc_object_layout(&reqhead->layout, req->r_oid,
  465. &req->r_file_layout, osdc->osdmap);
  466. if (err)
  467. return err;
  468. pgid.pg64 = le64_to_cpu(reqhead->layout.ol_pgid);
  469. o = ceph_calc_pg_primary(osdc->osdmap, pgid);
  470. if ((req->r_osd && req->r_osd->o_osd == o &&
  471. req->r_sent >= req->r_osd->o_incarnation) ||
  472. (req->r_osd == NULL && o == -1))
  473. return 0; /* no change */
  474. dout("map_osds tid %llu pgid %llx pool %d osd%d (was osd%d)\n",
  475. req->r_tid, pgid.pg64, pgid.pg.pool, o,
  476. req->r_osd ? req->r_osd->o_osd : -1);
  477. if (req->r_osd) {
  478. __cancel_request(req);
  479. list_del_init(&req->r_osd_item);
  480. if (list_empty(&req->r_osd->o_requests)) {
  481. /* try to re-use r_osd if possible */
  482. newosd = get_osd(req->r_osd);
  483. remove_osd(osdc, newosd);
  484. }
  485. req->r_osd = NULL;
  486. }
  487. req->r_osd = __lookup_osd(osdc, o);
  488. if (!req->r_osd && o >= 0) {
  489. if (newosd) {
  490. req->r_osd = newosd;
  491. newosd = NULL;
  492. } else {
  493. err = -ENOMEM;
  494. req->r_osd = create_osd(osdc);
  495. if (!req->r_osd)
  496. goto out;
  497. }
  498. dout("map_osds osd %p is osd%d\n", req->r_osd, o);
  499. req->r_osd->o_osd = o;
  500. req->r_osd->o_con.peer_name.num = cpu_to_le64(o);
  501. __insert_osd(osdc, req->r_osd);
  502. ceph_con_open(&req->r_osd->o_con, &osdc->osdmap->osd_addr[o]);
  503. }
  504. if (req->r_osd)
  505. list_add(&req->r_osd_item, &req->r_osd->o_requests);
  506. err = 1; /* osd changed */
  507. out:
  508. if (newosd)
  509. put_osd(newosd);
  510. return err;
  511. }
  512. /*
  513. * caller should hold map_sem (for read) and request_mutex
  514. */
  515. static int __send_request(struct ceph_osd_client *osdc,
  516. struct ceph_osd_request *req)
  517. {
  518. struct ceph_osd_request_head *reqhead;
  519. int err;
  520. err = __map_osds(osdc, req);
  521. if (err < 0)
  522. return err;
  523. if (req->r_osd == NULL) {
  524. dout("send_request %p no up osds in pg\n", req);
  525. ceph_monc_request_next_osdmap(&osdc->client->monc);
  526. return 0;
  527. }
  528. dout("send_request %p tid %llu to osd%d flags %d\n",
  529. req, req->r_tid, req->r_osd->o_osd, req->r_flags);
  530. reqhead = req->r_request->front.iov_base;
  531. reqhead->osdmap_epoch = cpu_to_le32(osdc->osdmap->epoch);
  532. reqhead->flags |= cpu_to_le32(req->r_flags); /* e.g., RETRY */
  533. reqhead->reassert_version = req->r_reassert_version;
  534. req->r_timeout_stamp = jiffies+osdc->client->mount_args.osd_timeout*HZ;
  535. ceph_msg_get(req->r_request); /* send consumes a ref */
  536. ceph_con_send(&req->r_osd->o_con, req->r_request);
  537. req->r_sent = req->r_osd->o_incarnation;
  538. return 0;
  539. }
  540. /*
  541. * Timeout callback, called every N seconds when 1 or more osd
  542. * requests has been active for more than N seconds. When this
  543. * happens, we ping all OSDs with requests who have timed out to
  544. * ensure any communications channel reset is detected. Reset the
  545. * request timeouts another N seconds in the future as we go.
  546. * Reschedule the timeout event another N seconds in future (unless
  547. * there are no open requests).
  548. */
  549. static void handle_timeout(struct work_struct *work)
  550. {
  551. struct ceph_osd_client *osdc =
  552. container_of(work, struct ceph_osd_client, timeout_work.work);
  553. struct ceph_osd_request *req;
  554. struct ceph_osd *osd;
  555. unsigned long timeout = osdc->client->mount_args.osd_timeout * HZ;
  556. unsigned long next_timeout = timeout + jiffies;
  557. struct rb_node *p;
  558. dout("timeout\n");
  559. down_read(&osdc->map_sem);
  560. ceph_monc_request_next_osdmap(&osdc->client->monc);
  561. mutex_lock(&osdc->request_mutex);
  562. for (p = rb_first(&osdc->requests); p; p = rb_next(p)) {
  563. req = rb_entry(p, struct ceph_osd_request, r_node);
  564. if (req->r_resend) {
  565. int err;
  566. dout("osdc resending prev failed %lld\n", req->r_tid);
  567. err = __send_request(osdc, req);
  568. if (err)
  569. dout("osdc failed again on %lld\n", req->r_tid);
  570. else
  571. req->r_resend = false;
  572. continue;
  573. }
  574. }
  575. for (p = rb_first(&osdc->osds); p; p = rb_next(p)) {
  576. osd = rb_entry(p, struct ceph_osd, o_node);
  577. if (list_empty(&osd->o_requests))
  578. continue;
  579. req = list_first_entry(&osd->o_requests,
  580. struct ceph_osd_request, r_osd_item);
  581. if (time_before(jiffies, req->r_timeout_stamp))
  582. continue;
  583. dout(" tid %llu (at least) timed out on osd%d\n",
  584. req->r_tid, osd->o_osd);
  585. req->r_timeout_stamp = next_timeout;
  586. ceph_con_keepalive(&osd->o_con);
  587. }
  588. if (osdc->timeout_tid)
  589. schedule_delayed_work(&osdc->timeout_work,
  590. round_jiffies_relative(timeout));
  591. mutex_unlock(&osdc->request_mutex);
  592. up_read(&osdc->map_sem);
  593. }
  594. /*
  595. * handle osd op reply. either call the callback if it is specified,
  596. * or do the completion to wake up the waiting thread.
  597. */
  598. static void handle_reply(struct ceph_osd_client *osdc, struct ceph_msg *msg)
  599. {
  600. struct ceph_osd_reply_head *rhead = msg->front.iov_base;
  601. struct ceph_osd_request *req;
  602. u64 tid;
  603. int numops, object_len, flags;
  604. if (msg->front.iov_len < sizeof(*rhead))
  605. goto bad;
  606. tid = le64_to_cpu(rhead->tid);
  607. numops = le32_to_cpu(rhead->num_ops);
  608. object_len = le32_to_cpu(rhead->object_len);
  609. if (msg->front.iov_len != sizeof(*rhead) + object_len +
  610. numops * sizeof(struct ceph_osd_op))
  611. goto bad;
  612. dout("handle_reply %p tid %llu\n", msg, tid);
  613. /* lookup */
  614. mutex_lock(&osdc->request_mutex);
  615. req = __lookup_request(osdc, tid);
  616. if (req == NULL) {
  617. dout("handle_reply tid %llu dne\n", tid);
  618. mutex_unlock(&osdc->request_mutex);
  619. return;
  620. }
  621. ceph_osdc_get_request(req);
  622. flags = le32_to_cpu(rhead->flags);
  623. if (req->r_reply) {
  624. /*
  625. * once we see the message has been received, we don't
  626. * need a ref (which is only needed for revoking
  627. * pages)
  628. */
  629. ceph_msg_put(req->r_reply);
  630. req->r_reply = NULL;
  631. }
  632. if (!req->r_got_reply) {
  633. unsigned bytes;
  634. req->r_result = le32_to_cpu(rhead->result);
  635. bytes = le32_to_cpu(msg->hdr.data_len);
  636. dout("handle_reply result %d bytes %d\n", req->r_result,
  637. bytes);
  638. if (req->r_result == 0)
  639. req->r_result = bytes;
  640. /* in case this is a write and we need to replay, */
  641. req->r_reassert_version = rhead->reassert_version;
  642. req->r_got_reply = 1;
  643. } else if ((flags & CEPH_OSD_FLAG_ONDISK) == 0) {
  644. dout("handle_reply tid %llu dup ack\n", tid);
  645. goto done;
  646. }
  647. dout("handle_reply tid %llu flags %d\n", tid, flags);
  648. /* either this is a read, or we got the safe response */
  649. if ((flags & CEPH_OSD_FLAG_ONDISK) ||
  650. ((flags & CEPH_OSD_FLAG_WRITE) == 0))
  651. __unregister_request(osdc, req);
  652. mutex_unlock(&osdc->request_mutex);
  653. if (req->r_callback)
  654. req->r_callback(req, msg);
  655. else
  656. complete(&req->r_completion);
  657. if (flags & CEPH_OSD_FLAG_ONDISK) {
  658. if (req->r_safe_callback)
  659. req->r_safe_callback(req, msg);
  660. complete(&req->r_safe_completion); /* fsync waiter */
  661. }
  662. done:
  663. ceph_osdc_put_request(req);
  664. return;
  665. bad:
  666. pr_err("corrupt osd_op_reply got %d %d expected %d\n",
  667. (int)msg->front.iov_len, le32_to_cpu(msg->hdr.front_len),
  668. (int)sizeof(*rhead));
  669. }
  670. /*
  671. * Resubmit osd requests whose osd or osd address has changed. Request
  672. * a new osd map if osds are down, or we are otherwise unable to determine
  673. * how to direct a request.
  674. *
  675. * Close connections to down osds.
  676. *
  677. * If @who is specified, resubmit requests for that specific osd.
  678. *
  679. * Caller should hold map_sem for read and request_mutex.
  680. */
  681. static void kick_requests(struct ceph_osd_client *osdc,
  682. struct ceph_osd *kickosd)
  683. {
  684. struct ceph_osd_request *req;
  685. struct rb_node *p, *n;
  686. int needmap = 0;
  687. int err;
  688. dout("kick_requests osd%d\n", kickosd ? kickosd->o_osd : -1);
  689. mutex_lock(&osdc->request_mutex);
  690. if (!kickosd) {
  691. for (p = rb_first(&osdc->osds); p; p = n) {
  692. struct ceph_osd *osd =
  693. rb_entry(p, struct ceph_osd, o_node);
  694. n = rb_next(p);
  695. if (!ceph_osd_is_up(osdc->osdmap, osd->o_osd) ||
  696. !ceph_entity_addr_equal(&osd->o_con.peer_addr,
  697. ceph_osd_addr(osdc->osdmap,
  698. osd->o_osd)))
  699. reset_osd(osdc, osd);
  700. }
  701. }
  702. for (p = rb_first(&osdc->requests); p; p = rb_next(p)) {
  703. req = rb_entry(p, struct ceph_osd_request, r_node);
  704. if (req->r_resend) {
  705. dout(" r_resend set on tid %llu\n", req->r_tid);
  706. goto kick;
  707. }
  708. if (req->r_osd && kickosd == req->r_osd)
  709. goto kick;
  710. err = __map_osds(osdc, req);
  711. if (err == 0)
  712. continue; /* no change */
  713. if (err < 0) {
  714. /*
  715. * FIXME: really, we should set the request
  716. * error and fail if this isn't a 'nofail'
  717. * request, but that's a fair bit more
  718. * complicated to do. So retry!
  719. */
  720. dout(" setting r_resend on %llu\n", req->r_tid);
  721. req->r_resend = true;
  722. continue;
  723. }
  724. if (req->r_osd == NULL) {
  725. dout("tid %llu maps to no valid osd\n", req->r_tid);
  726. needmap++; /* request a newer map */
  727. continue;
  728. }
  729. kick:
  730. dout("kicking tid %llu osd%d\n", req->r_tid, req->r_osd->o_osd);
  731. req->r_flags |= CEPH_OSD_FLAG_RETRY;
  732. err = __send_request(osdc, req);
  733. if (err) {
  734. dout(" setting r_resend on %llu\n", req->r_tid);
  735. req->r_resend = true;
  736. }
  737. }
  738. mutex_unlock(&osdc->request_mutex);
  739. if (needmap) {
  740. dout("%d requests for down osds, need new map\n", needmap);
  741. ceph_monc_request_next_osdmap(&osdc->client->monc);
  742. }
  743. }
  744. /*
  745. * Process updated osd map.
  746. *
  747. * The message contains any number of incremental and full maps, normally
  748. * indicating some sort of topology change in the cluster. Kick requests
  749. * off to different OSDs as needed.
  750. */
  751. void ceph_osdc_handle_map(struct ceph_osd_client *osdc, struct ceph_msg *msg)
  752. {
  753. void *p, *end, *next;
  754. u32 nr_maps, maplen;
  755. u32 epoch;
  756. struct ceph_osdmap *newmap = NULL, *oldmap;
  757. int err;
  758. struct ceph_fsid fsid;
  759. dout("handle_map have %u\n", osdc->osdmap ? osdc->osdmap->epoch : 0);
  760. p = msg->front.iov_base;
  761. end = p + msg->front.iov_len;
  762. /* verify fsid */
  763. ceph_decode_need(&p, end, sizeof(fsid), bad);
  764. ceph_decode_copy(&p, &fsid, sizeof(fsid));
  765. if (ceph_fsid_compare(&fsid, &osdc->client->monc.monmap->fsid)) {
  766. pr_err("got osdmap with wrong fsid, ignoring\n");
  767. return;
  768. }
  769. down_write(&osdc->map_sem);
  770. /* incremental maps */
  771. ceph_decode_32_safe(&p, end, nr_maps, bad);
  772. dout(" %d inc maps\n", nr_maps);
  773. while (nr_maps > 0) {
  774. ceph_decode_need(&p, end, 2*sizeof(u32), bad);
  775. ceph_decode_32(&p, epoch);
  776. ceph_decode_32(&p, maplen);
  777. ceph_decode_need(&p, end, maplen, bad);
  778. next = p + maplen;
  779. if (osdc->osdmap && osdc->osdmap->epoch+1 == epoch) {
  780. dout("applying incremental map %u len %d\n",
  781. epoch, maplen);
  782. newmap = osdmap_apply_incremental(&p, next,
  783. osdc->osdmap,
  784. osdc->client->msgr);
  785. if (IS_ERR(newmap)) {
  786. err = PTR_ERR(newmap);
  787. goto bad;
  788. }
  789. if (newmap != osdc->osdmap) {
  790. ceph_osdmap_destroy(osdc->osdmap);
  791. osdc->osdmap = newmap;
  792. }
  793. } else {
  794. dout("ignoring incremental map %u len %d\n",
  795. epoch, maplen);
  796. }
  797. p = next;
  798. nr_maps--;
  799. }
  800. if (newmap)
  801. goto done;
  802. /* full maps */
  803. ceph_decode_32_safe(&p, end, nr_maps, bad);
  804. dout(" %d full maps\n", nr_maps);
  805. while (nr_maps) {
  806. ceph_decode_need(&p, end, 2*sizeof(u32), bad);
  807. ceph_decode_32(&p, epoch);
  808. ceph_decode_32(&p, maplen);
  809. ceph_decode_need(&p, end, maplen, bad);
  810. if (nr_maps > 1) {
  811. dout("skipping non-latest full map %u len %d\n",
  812. epoch, maplen);
  813. } else if (osdc->osdmap && osdc->osdmap->epoch >= epoch) {
  814. dout("skipping full map %u len %d, "
  815. "older than our %u\n", epoch, maplen,
  816. osdc->osdmap->epoch);
  817. } else {
  818. dout("taking full map %u len %d\n", epoch, maplen);
  819. newmap = osdmap_decode(&p, p+maplen);
  820. if (IS_ERR(newmap)) {
  821. err = PTR_ERR(newmap);
  822. goto bad;
  823. }
  824. oldmap = osdc->osdmap;
  825. osdc->osdmap = newmap;
  826. if (oldmap)
  827. ceph_osdmap_destroy(oldmap);
  828. }
  829. p += maplen;
  830. nr_maps--;
  831. }
  832. done:
  833. downgrade_write(&osdc->map_sem);
  834. ceph_monc_got_osdmap(&osdc->client->monc, osdc->osdmap->epoch);
  835. if (newmap)
  836. kick_requests(osdc, NULL);
  837. up_read(&osdc->map_sem);
  838. return;
  839. bad:
  840. pr_err("osdc handle_map corrupt msg\n");
  841. up_write(&osdc->map_sem);
  842. return;
  843. }
  844. /*
  845. * A read request prepares specific pages that data is to be read into.
  846. * When a message is being read off the wire, we call prepare_pages to
  847. * find those pages.
  848. * 0 = success, -1 failure.
  849. */
  850. static int prepare_pages(struct ceph_connection *con, struct ceph_msg *m,
  851. int want)
  852. {
  853. struct ceph_osd *osd = con->private;
  854. struct ceph_osd_client *osdc;
  855. struct ceph_osd_reply_head *rhead = m->front.iov_base;
  856. struct ceph_osd_request *req;
  857. u64 tid;
  858. int ret = -1;
  859. int type = le16_to_cpu(m->hdr.type);
  860. if (!osd)
  861. return -1;
  862. osdc = osd->o_osdc;
  863. dout("prepare_pages on msg %p want %d\n", m, want);
  864. if (unlikely(type != CEPH_MSG_OSD_OPREPLY))
  865. return -1; /* hmm! */
  866. tid = le64_to_cpu(rhead->tid);
  867. mutex_lock(&osdc->request_mutex);
  868. req = __lookup_request(osdc, tid);
  869. if (!req) {
  870. dout("prepare_pages unknown tid %llu\n", tid);
  871. goto out;
  872. }
  873. dout("prepare_pages tid %llu has %d pages, want %d\n",
  874. tid, req->r_num_pages, want);
  875. if (likely(req->r_num_pages >= want && !req->r_prepared_pages)) {
  876. m->pages = req->r_pages;
  877. m->nr_pages = req->r_num_pages;
  878. req->r_reply = m; /* only for duration of read over socket */
  879. ceph_msg_get(m);
  880. req->r_prepared_pages = 1;
  881. ret = 0; /* success */
  882. }
  883. out:
  884. mutex_unlock(&osdc->request_mutex);
  885. return ret;
  886. }
  887. /*
  888. * Register request, send initial attempt.
  889. */
  890. int ceph_osdc_start_request(struct ceph_osd_client *osdc,
  891. struct ceph_osd_request *req,
  892. bool nofail)
  893. {
  894. int rc;
  895. req->r_request->pages = req->r_pages;
  896. req->r_request->nr_pages = req->r_num_pages;
  897. register_request(osdc, req);
  898. down_read(&osdc->map_sem);
  899. mutex_lock(&osdc->request_mutex);
  900. rc = __send_request(osdc, req);
  901. if (rc) {
  902. if (nofail) {
  903. dout("osdc_start_request failed send, marking %lld\n",
  904. req->r_tid);
  905. req->r_resend = true;
  906. rc = 0;
  907. } else {
  908. __unregister_request(osdc, req);
  909. }
  910. }
  911. mutex_unlock(&osdc->request_mutex);
  912. up_read(&osdc->map_sem);
  913. return rc;
  914. }
  915. /*
  916. * wait for a request to complete
  917. */
  918. int ceph_osdc_wait_request(struct ceph_osd_client *osdc,
  919. struct ceph_osd_request *req)
  920. {
  921. int rc;
  922. rc = wait_for_completion_interruptible(&req->r_completion);
  923. if (rc < 0) {
  924. mutex_lock(&osdc->request_mutex);
  925. __cancel_request(req);
  926. mutex_unlock(&osdc->request_mutex);
  927. dout("wait_request tid %llu timed out\n", req->r_tid);
  928. return rc;
  929. }
  930. dout("wait_request tid %llu result %d\n", req->r_tid, req->r_result);
  931. return req->r_result;
  932. }
  933. /*
  934. * sync - wait for all in-flight requests to flush. avoid starvation.
  935. */
  936. void ceph_osdc_sync(struct ceph_osd_client *osdc)
  937. {
  938. struct ceph_osd_request *req;
  939. u64 last_tid, next_tid = 0;
  940. mutex_lock(&osdc->request_mutex);
  941. last_tid = osdc->last_tid;
  942. while (1) {
  943. req = __lookup_request_ge(osdc, next_tid);
  944. if (!req)
  945. break;
  946. if (req->r_tid > last_tid)
  947. break;
  948. next_tid = req->r_tid + 1;
  949. if ((req->r_flags & CEPH_OSD_FLAG_WRITE) == 0)
  950. continue;
  951. ceph_osdc_get_request(req);
  952. mutex_unlock(&osdc->request_mutex);
  953. dout("sync waiting on tid %llu (last is %llu)\n",
  954. req->r_tid, last_tid);
  955. wait_for_completion(&req->r_safe_completion);
  956. mutex_lock(&osdc->request_mutex);
  957. ceph_osdc_put_request(req);
  958. }
  959. mutex_unlock(&osdc->request_mutex);
  960. dout("sync done (thru tid %llu)\n", last_tid);
  961. }
  962. /*
  963. * init, shutdown
  964. */
  965. int ceph_osdc_init(struct ceph_osd_client *osdc, struct ceph_client *client)
  966. {
  967. int err;
  968. dout("init\n");
  969. osdc->client = client;
  970. osdc->osdmap = NULL;
  971. init_rwsem(&osdc->map_sem);
  972. init_completion(&osdc->map_waiters);
  973. osdc->last_requested_map = 0;
  974. mutex_init(&osdc->request_mutex);
  975. osdc->timeout_tid = 0;
  976. osdc->last_tid = 0;
  977. osdc->osds = RB_ROOT;
  978. osdc->requests = RB_ROOT;
  979. osdc->num_requests = 0;
  980. INIT_DELAYED_WORK(&osdc->timeout_work, handle_timeout);
  981. osdc->req_mempool = mempool_create_kmalloc_pool(10,
  982. sizeof(struct ceph_osd_request));
  983. if (!osdc->req_mempool)
  984. return -ENOMEM;
  985. err = ceph_msgpool_init(&osdc->msgpool_op, 4096, 10, true);
  986. if (err < 0)
  987. return -ENOMEM;
  988. err = ceph_msgpool_init(&osdc->msgpool_op_reply, 512, 0, false);
  989. if (err < 0)
  990. return -ENOMEM;
  991. return 0;
  992. }
  993. void ceph_osdc_stop(struct ceph_osd_client *osdc)
  994. {
  995. cancel_delayed_work_sync(&osdc->timeout_work);
  996. if (osdc->osdmap) {
  997. ceph_osdmap_destroy(osdc->osdmap);
  998. osdc->osdmap = NULL;
  999. }
  1000. mempool_destroy(osdc->req_mempool);
  1001. ceph_msgpool_destroy(&osdc->msgpool_op);
  1002. ceph_msgpool_destroy(&osdc->msgpool_op_reply);
  1003. }
  1004. /*
  1005. * Read some contiguous pages. If we cross a stripe boundary, shorten
  1006. * *plen. Return number of bytes read, or error.
  1007. */
  1008. int ceph_osdc_readpages(struct ceph_osd_client *osdc,
  1009. struct ceph_vino vino, struct ceph_file_layout *layout,
  1010. u64 off, u64 *plen,
  1011. u32 truncate_seq, u64 truncate_size,
  1012. struct page **pages, int num_pages)
  1013. {
  1014. struct ceph_osd_request *req;
  1015. int rc = 0;
  1016. dout("readpages on ino %llx.%llx on %llu~%llu\n", vino.ino,
  1017. vino.snap, off, *plen);
  1018. req = ceph_osdc_new_request(osdc, layout, vino, off, plen,
  1019. CEPH_OSD_OP_READ, CEPH_OSD_FLAG_READ,
  1020. NULL, 0, truncate_seq, truncate_size, NULL,
  1021. false, 1);
  1022. if (IS_ERR(req))
  1023. return PTR_ERR(req);
  1024. /* it may be a short read due to an object boundary */
  1025. req->r_pages = pages;
  1026. num_pages = calc_pages_for(off, *plen);
  1027. req->r_num_pages = num_pages;
  1028. dout("readpages final extent is %llu~%llu (%d pages)\n",
  1029. off, *plen, req->r_num_pages);
  1030. rc = ceph_osdc_start_request(osdc, req, false);
  1031. if (!rc)
  1032. rc = ceph_osdc_wait_request(osdc, req);
  1033. ceph_osdc_put_request(req);
  1034. dout("readpages result %d\n", rc);
  1035. return rc;
  1036. }
  1037. /*
  1038. * do a synchronous write on N pages
  1039. */
  1040. int ceph_osdc_writepages(struct ceph_osd_client *osdc, struct ceph_vino vino,
  1041. struct ceph_file_layout *layout,
  1042. struct ceph_snap_context *snapc,
  1043. u64 off, u64 len,
  1044. u32 truncate_seq, u64 truncate_size,
  1045. struct timespec *mtime,
  1046. struct page **pages, int num_pages,
  1047. int flags, int do_sync, bool nofail)
  1048. {
  1049. struct ceph_osd_request *req;
  1050. int rc = 0;
  1051. BUG_ON(vino.snap != CEPH_NOSNAP);
  1052. req = ceph_osdc_new_request(osdc, layout, vino, off, &len,
  1053. CEPH_OSD_OP_WRITE,
  1054. flags | CEPH_OSD_FLAG_ONDISK |
  1055. CEPH_OSD_FLAG_WRITE,
  1056. snapc, do_sync,
  1057. truncate_seq, truncate_size, mtime,
  1058. nofail, 1);
  1059. if (IS_ERR(req))
  1060. return PTR_ERR(req);
  1061. /* it may be a short write due to an object boundary */
  1062. req->r_pages = pages;
  1063. req->r_num_pages = calc_pages_for(off, len);
  1064. dout("writepages %llu~%llu (%d pages)\n", off, len,
  1065. req->r_num_pages);
  1066. rc = ceph_osdc_start_request(osdc, req, nofail);
  1067. if (!rc)
  1068. rc = ceph_osdc_wait_request(osdc, req);
  1069. ceph_osdc_put_request(req);
  1070. if (rc == 0)
  1071. rc = len;
  1072. dout("writepages result %d\n", rc);
  1073. return rc;
  1074. }
  1075. /*
  1076. * handle incoming message
  1077. */
  1078. static void dispatch(struct ceph_connection *con, struct ceph_msg *msg)
  1079. {
  1080. struct ceph_osd *osd = con->private;
  1081. struct ceph_osd_client *osdc = osd->o_osdc;
  1082. int type = le16_to_cpu(msg->hdr.type);
  1083. if (!osd)
  1084. return;
  1085. switch (type) {
  1086. case CEPH_MSG_OSD_MAP:
  1087. ceph_osdc_handle_map(osdc, msg);
  1088. break;
  1089. case CEPH_MSG_OSD_OPREPLY:
  1090. handle_reply(osdc, msg);
  1091. break;
  1092. default:
  1093. pr_err("received unknown message type %d %s\n", type,
  1094. ceph_msg_type_name(type));
  1095. }
  1096. ceph_msg_put(msg);
  1097. }
  1098. static struct ceph_msg *alloc_msg(struct ceph_connection *con,
  1099. struct ceph_msg_header *hdr)
  1100. {
  1101. struct ceph_osd *osd = con->private;
  1102. struct ceph_osd_client *osdc = osd->o_osdc;
  1103. int type = le16_to_cpu(hdr->type);
  1104. switch (type) {
  1105. case CEPH_MSG_OSD_OPREPLY:
  1106. return ceph_msgpool_get(&osdc->msgpool_op_reply);
  1107. }
  1108. return ceph_alloc_msg(con, hdr);
  1109. }
  1110. /*
  1111. * Wrappers to refcount containing ceph_osd struct
  1112. */
  1113. static struct ceph_connection *get_osd_con(struct ceph_connection *con)
  1114. {
  1115. struct ceph_osd *osd = con->private;
  1116. if (get_osd(osd))
  1117. return con;
  1118. return NULL;
  1119. }
  1120. static void put_osd_con(struct ceph_connection *con)
  1121. {
  1122. struct ceph_osd *osd = con->private;
  1123. put_osd(osd);
  1124. }
  1125. const static struct ceph_connection_operations osd_con_ops = {
  1126. .get = get_osd_con,
  1127. .put = put_osd_con,
  1128. .dispatch = dispatch,
  1129. .alloc_msg = alloc_msg,
  1130. .peer_reset = osd_reset,
  1131. .alloc_middle = ceph_alloc_middle,
  1132. .prepare_pages = prepare_pages,
  1133. };