osd_client.c 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372
  1. #include <linux/ceph/ceph_debug.h>
  2. #include <linux/module.h>
  3. #include <linux/err.h>
  4. #include <linux/highmem.h>
  5. #include <linux/mm.h>
  6. #include <linux/pagemap.h>
  7. #include <linux/slab.h>
  8. #include <linux/uaccess.h>
  9. #ifdef CONFIG_BLOCK
  10. #include <linux/bio.h>
  11. #endif
  12. #include <linux/ceph/libceph.h>
  13. #include <linux/ceph/osd_client.h>
  14. #include <linux/ceph/messenger.h>
  15. #include <linux/ceph/decode.h>
  16. #include <linux/ceph/auth.h>
  17. #include <linux/ceph/pagelist.h>
  18. #define OSD_OP_FRONT_LEN 4096
  19. #define OSD_OPREPLY_FRONT_LEN 512
  20. static const struct ceph_connection_operations osd_con_ops;
  21. static void __send_queued(struct ceph_osd_client *osdc);
  22. static int __reset_osd(struct ceph_osd_client *osdc, struct ceph_osd *osd);
  23. static void __register_request(struct ceph_osd_client *osdc,
  24. struct ceph_osd_request *req);
  25. static void __unregister_linger_request(struct ceph_osd_client *osdc,
  26. struct ceph_osd_request *req);
  27. static void __send_request(struct ceph_osd_client *osdc,
  28. struct ceph_osd_request *req);
  29. /*
  30. * Implement client access to distributed object storage cluster.
  31. *
  32. * All data objects are stored within a cluster/cloud of OSDs, or
  33. * "object storage devices." (Note that Ceph OSDs have _nothing_ to
  34. * do with the T10 OSD extensions to SCSI.) Ceph OSDs are simply
  35. * remote daemons serving up and coordinating consistent and safe
  36. * access to storage.
  37. *
  38. * Cluster membership and the mapping of data objects onto storage devices
  39. * are described by the osd map.
  40. *
  41. * We keep track of pending OSD requests (read, write), resubmit
  42. * requests to different OSDs when the cluster topology/data layout
  43. * change, or retry the affected requests when the communications
  44. * channel with an OSD is reset.
  45. */
  46. /*
  47. * calculate the mapping of a file extent onto an object, and fill out the
  48. * request accordingly. shorten extent as necessary if it crosses an
  49. * object boundary.
  50. *
  51. * fill osd op in request message.
  52. */
  53. static int calc_layout(struct ceph_file_layout *layout, u64 off, u64 *plen,
  54. u64 *objnum, u64 *objoff, u64 *objlen)
  55. {
  56. u64 orig_len = *plen;
  57. int r;
  58. /* object extent? */
  59. r = ceph_calc_file_object_mapping(layout, off, orig_len, objnum,
  60. objoff, objlen);
  61. if (r < 0)
  62. return r;
  63. if (*objlen < orig_len) {
  64. *plen = *objlen;
  65. dout(" skipping last %llu, final file extent %llu~%llu\n",
  66. orig_len - *plen, off, *plen);
  67. }
  68. dout("calc_layout objnum=%llx %llu~%llu\n", *objnum, *objoff, *objlen);
  69. return 0;
  70. }
  71. /*
  72. * requests
  73. */
  74. void ceph_osdc_release_request(struct kref *kref)
  75. {
  76. int num_pages;
  77. struct ceph_osd_request *req = container_of(kref,
  78. struct ceph_osd_request,
  79. r_kref);
  80. if (req->r_request)
  81. ceph_msg_put(req->r_request);
  82. if (req->r_con_filling_msg) {
  83. dout("%s revoking msg %p from con %p\n", __func__,
  84. req->r_reply, req->r_con_filling_msg);
  85. ceph_msg_revoke_incoming(req->r_reply);
  86. req->r_con_filling_msg->ops->put(req->r_con_filling_msg);
  87. req->r_con_filling_msg = NULL;
  88. }
  89. if (req->r_reply)
  90. ceph_msg_put(req->r_reply);
  91. if (req->r_data_in.type == CEPH_OSD_DATA_TYPE_PAGES &&
  92. req->r_data_in.own_pages) {
  93. num_pages = calc_pages_for((u64)req->r_data_in.alignment,
  94. (u64)req->r_data_in.length);
  95. ceph_release_page_vector(req->r_data_in.pages, num_pages);
  96. }
  97. if (req->r_data_out.type == CEPH_OSD_DATA_TYPE_PAGES &&
  98. req->r_data_out.own_pages) {
  99. num_pages = calc_pages_for((u64)req->r_data_out.alignment,
  100. (u64)req->r_data_out.length);
  101. ceph_release_page_vector(req->r_data_out.pages, num_pages);
  102. }
  103. ceph_put_snap_context(req->r_snapc);
  104. if (req->r_mempool)
  105. mempool_free(req, req->r_osdc->req_mempool);
  106. else
  107. kfree(req);
  108. }
  109. EXPORT_SYMBOL(ceph_osdc_release_request);
  110. struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc,
  111. struct ceph_snap_context *snapc,
  112. unsigned int num_ops,
  113. bool use_mempool,
  114. gfp_t gfp_flags)
  115. {
  116. struct ceph_osd_request *req;
  117. struct ceph_msg *msg;
  118. size_t msg_size;
  119. msg_size = 4 + 4 + 8 + 8 + 4+8;
  120. msg_size += 2 + 4 + 8 + 4 + 4; /* oloc */
  121. msg_size += 1 + 8 + 4 + 4; /* pg_t */
  122. msg_size += 4 + MAX_OBJ_NAME_SIZE;
  123. msg_size += 2 + num_ops*sizeof(struct ceph_osd_op);
  124. msg_size += 8; /* snapid */
  125. msg_size += 8; /* snap_seq */
  126. msg_size += 8 * (snapc ? snapc->num_snaps : 0); /* snaps */
  127. msg_size += 4;
  128. if (use_mempool) {
  129. req = mempool_alloc(osdc->req_mempool, gfp_flags);
  130. memset(req, 0, sizeof(*req));
  131. } else {
  132. req = kzalloc(sizeof(*req), gfp_flags);
  133. }
  134. if (req == NULL)
  135. return NULL;
  136. req->r_osdc = osdc;
  137. req->r_mempool = use_mempool;
  138. kref_init(&req->r_kref);
  139. init_completion(&req->r_completion);
  140. init_completion(&req->r_safe_completion);
  141. RB_CLEAR_NODE(&req->r_node);
  142. INIT_LIST_HEAD(&req->r_unsafe_item);
  143. INIT_LIST_HEAD(&req->r_linger_item);
  144. INIT_LIST_HEAD(&req->r_linger_osd);
  145. INIT_LIST_HEAD(&req->r_req_lru_item);
  146. INIT_LIST_HEAD(&req->r_osd_item);
  147. /* create reply message */
  148. if (use_mempool)
  149. msg = ceph_msgpool_get(&osdc->msgpool_op_reply, 0);
  150. else
  151. msg = ceph_msg_new(CEPH_MSG_OSD_OPREPLY,
  152. OSD_OPREPLY_FRONT_LEN, gfp_flags, true);
  153. if (!msg) {
  154. ceph_osdc_put_request(req);
  155. return NULL;
  156. }
  157. req->r_reply = msg;
  158. req->r_data_in.type = CEPH_OSD_DATA_TYPE_NONE;
  159. req->r_data_out.type = CEPH_OSD_DATA_TYPE_NONE;
  160. /* create request message; allow space for oid */
  161. if (use_mempool)
  162. msg = ceph_msgpool_get(&osdc->msgpool_op, 0);
  163. else
  164. msg = ceph_msg_new(CEPH_MSG_OSD_OP, msg_size, gfp_flags, true);
  165. if (!msg) {
  166. ceph_osdc_put_request(req);
  167. return NULL;
  168. }
  169. memset(msg->front.iov_base, 0, msg->front.iov_len);
  170. req->r_request = msg;
  171. return req;
  172. }
  173. EXPORT_SYMBOL(ceph_osdc_alloc_request);
  174. static bool osd_req_opcode_valid(u16 opcode)
  175. {
  176. switch (opcode) {
  177. case CEPH_OSD_OP_READ:
  178. case CEPH_OSD_OP_STAT:
  179. case CEPH_OSD_OP_MAPEXT:
  180. case CEPH_OSD_OP_MASKTRUNC:
  181. case CEPH_OSD_OP_SPARSE_READ:
  182. case CEPH_OSD_OP_NOTIFY:
  183. case CEPH_OSD_OP_NOTIFY_ACK:
  184. case CEPH_OSD_OP_ASSERT_VER:
  185. case CEPH_OSD_OP_WRITE:
  186. case CEPH_OSD_OP_WRITEFULL:
  187. case CEPH_OSD_OP_TRUNCATE:
  188. case CEPH_OSD_OP_ZERO:
  189. case CEPH_OSD_OP_DELETE:
  190. case CEPH_OSD_OP_APPEND:
  191. case CEPH_OSD_OP_STARTSYNC:
  192. case CEPH_OSD_OP_SETTRUNC:
  193. case CEPH_OSD_OP_TRIMTRUNC:
  194. case CEPH_OSD_OP_TMAPUP:
  195. case CEPH_OSD_OP_TMAPPUT:
  196. case CEPH_OSD_OP_TMAPGET:
  197. case CEPH_OSD_OP_CREATE:
  198. case CEPH_OSD_OP_ROLLBACK:
  199. case CEPH_OSD_OP_WATCH:
  200. case CEPH_OSD_OP_OMAPGETKEYS:
  201. case CEPH_OSD_OP_OMAPGETVALS:
  202. case CEPH_OSD_OP_OMAPGETHEADER:
  203. case CEPH_OSD_OP_OMAPGETVALSBYKEYS:
  204. case CEPH_OSD_OP_OMAPSETVALS:
  205. case CEPH_OSD_OP_OMAPSETHEADER:
  206. case CEPH_OSD_OP_OMAPCLEAR:
  207. case CEPH_OSD_OP_OMAPRMKEYS:
  208. case CEPH_OSD_OP_OMAP_CMP:
  209. case CEPH_OSD_OP_CLONERANGE:
  210. case CEPH_OSD_OP_ASSERT_SRC_VERSION:
  211. case CEPH_OSD_OP_SRC_CMPXATTR:
  212. case CEPH_OSD_OP_GETXATTR:
  213. case CEPH_OSD_OP_GETXATTRS:
  214. case CEPH_OSD_OP_CMPXATTR:
  215. case CEPH_OSD_OP_SETXATTR:
  216. case CEPH_OSD_OP_SETXATTRS:
  217. case CEPH_OSD_OP_RESETXATTRS:
  218. case CEPH_OSD_OP_RMXATTR:
  219. case CEPH_OSD_OP_PULL:
  220. case CEPH_OSD_OP_PUSH:
  221. case CEPH_OSD_OP_BALANCEREADS:
  222. case CEPH_OSD_OP_UNBALANCEREADS:
  223. case CEPH_OSD_OP_SCRUB:
  224. case CEPH_OSD_OP_SCRUB_RESERVE:
  225. case CEPH_OSD_OP_SCRUB_UNRESERVE:
  226. case CEPH_OSD_OP_SCRUB_STOP:
  227. case CEPH_OSD_OP_SCRUB_MAP:
  228. case CEPH_OSD_OP_WRLOCK:
  229. case CEPH_OSD_OP_WRUNLOCK:
  230. case CEPH_OSD_OP_RDLOCK:
  231. case CEPH_OSD_OP_RDUNLOCK:
  232. case CEPH_OSD_OP_UPLOCK:
  233. case CEPH_OSD_OP_DNLOCK:
  234. case CEPH_OSD_OP_CALL:
  235. case CEPH_OSD_OP_PGLS:
  236. case CEPH_OSD_OP_PGLS_FILTER:
  237. return true;
  238. default:
  239. return false;
  240. }
  241. }
  242. /*
  243. * This is an osd op init function for opcodes that have no data or
  244. * other information associated with them. It also serves as a
  245. * common init routine for all the other init functions, below.
  246. */
  247. void osd_req_op_init(struct ceph_osd_req_op *op, u16 opcode)
  248. {
  249. BUG_ON(!osd_req_opcode_valid(opcode));
  250. memset(op, 0, sizeof (*op));
  251. op->op = opcode;
  252. }
  253. void osd_req_op_extent_init(struct ceph_osd_req_op *op, u16 opcode,
  254. u64 offset, u64 length,
  255. u64 truncate_size, u32 truncate_seq)
  256. {
  257. size_t payload_len = 0;
  258. BUG_ON(opcode != CEPH_OSD_OP_READ && opcode != CEPH_OSD_OP_WRITE);
  259. osd_req_op_init(op, opcode);
  260. op->extent.offset = offset;
  261. op->extent.length = length;
  262. op->extent.truncate_size = truncate_size;
  263. op->extent.truncate_seq = truncate_seq;
  264. if (opcode == CEPH_OSD_OP_WRITE)
  265. payload_len += length;
  266. op->payload_len = payload_len;
  267. }
  268. EXPORT_SYMBOL(osd_req_op_extent_init);
  269. void osd_req_op_cls_init(struct ceph_osd_req_op *op, u16 opcode,
  270. const char *class, const char *method,
  271. const void *request_data, size_t request_data_size)
  272. {
  273. size_t payload_len = 0;
  274. size_t size;
  275. BUG_ON(opcode != CEPH_OSD_OP_CALL);
  276. osd_req_op_init(op, opcode);
  277. op->cls.class_name = class;
  278. size = strlen(class);
  279. BUG_ON(size > (size_t) U8_MAX);
  280. op->cls.class_len = size;
  281. payload_len += size;
  282. op->cls.method_name = method;
  283. size = strlen(method);
  284. BUG_ON(size > (size_t) U8_MAX);
  285. op->cls.method_len = size;
  286. payload_len += size;
  287. op->cls.indata = request_data;
  288. BUG_ON(request_data_size > (size_t) U32_MAX);
  289. op->cls.indata_len = (u32) request_data_size;
  290. payload_len += request_data_size;
  291. op->cls.argc = 0; /* currently unused */
  292. op->payload_len = payload_len;
  293. }
  294. EXPORT_SYMBOL(osd_req_op_cls_init);
  295. void osd_req_op_watch_init(struct ceph_osd_req_op *op, u16 opcode,
  296. u64 cookie, u64 version, int flag)
  297. {
  298. BUG_ON(opcode != CEPH_OSD_OP_NOTIFY_ACK && opcode != CEPH_OSD_OP_WATCH);
  299. osd_req_op_init(op, opcode);
  300. op->watch.cookie = cookie;
  301. /* op->watch.ver = version; */ /* XXX 3847 */
  302. op->watch.ver = cpu_to_le64(version);
  303. if (opcode == CEPH_OSD_OP_WATCH && flag)
  304. op->watch.flag = (u8) 1;
  305. }
  306. EXPORT_SYMBOL(osd_req_op_watch_init);
  307. static u64 osd_req_encode_op(struct ceph_osd_request *req,
  308. struct ceph_osd_op *dst,
  309. struct ceph_osd_req_op *src)
  310. {
  311. u64 out_data_len = 0;
  312. struct ceph_pagelist *pagelist;
  313. if (WARN_ON(!osd_req_opcode_valid(src->op))) {
  314. pr_err("unrecognized osd opcode %d\n", src->op);
  315. return 0;
  316. }
  317. switch (src->op) {
  318. case CEPH_OSD_OP_STAT:
  319. break;
  320. case CEPH_OSD_OP_READ:
  321. case CEPH_OSD_OP_WRITE:
  322. if (src->op == CEPH_OSD_OP_WRITE)
  323. out_data_len = src->extent.length;
  324. dst->extent.offset = cpu_to_le64(src->extent.offset);
  325. dst->extent.length = cpu_to_le64(src->extent.length);
  326. dst->extent.truncate_size =
  327. cpu_to_le64(src->extent.truncate_size);
  328. dst->extent.truncate_seq =
  329. cpu_to_le32(src->extent.truncate_seq);
  330. break;
  331. case CEPH_OSD_OP_CALL:
  332. pagelist = kmalloc(sizeof (*pagelist), GFP_NOFS);
  333. BUG_ON(!pagelist);
  334. ceph_pagelist_init(pagelist);
  335. dst->cls.class_len = src->cls.class_len;
  336. dst->cls.method_len = src->cls.method_len;
  337. dst->cls.indata_len = cpu_to_le32(src->cls.indata_len);
  338. ceph_pagelist_append(pagelist, src->cls.class_name,
  339. src->cls.class_len);
  340. ceph_pagelist_append(pagelist, src->cls.method_name,
  341. src->cls.method_len);
  342. ceph_pagelist_append(pagelist, src->cls.indata,
  343. src->cls.indata_len);
  344. req->r_data_out.type = CEPH_OSD_DATA_TYPE_PAGELIST;
  345. req->r_data_out.pagelist = pagelist;
  346. out_data_len = pagelist->length;
  347. break;
  348. case CEPH_OSD_OP_STARTSYNC:
  349. break;
  350. case CEPH_OSD_OP_NOTIFY_ACK:
  351. case CEPH_OSD_OP_WATCH:
  352. dst->watch.cookie = cpu_to_le64(src->watch.cookie);
  353. dst->watch.ver = cpu_to_le64(src->watch.ver);
  354. dst->watch.flag = src->watch.flag;
  355. break;
  356. default:
  357. pr_err("unsupported osd opcode %s\n",
  358. ceph_osd_op_name(src->op));
  359. WARN_ON(1);
  360. return 0;
  361. }
  362. dst->op = cpu_to_le16(src->op);
  363. dst->payload_len = cpu_to_le32(src->payload_len);
  364. return out_data_len;
  365. }
  366. /*
  367. * build new request AND message
  368. *
  369. */
  370. void ceph_osdc_build_request(struct ceph_osd_request *req,
  371. u64 off, unsigned int num_ops,
  372. struct ceph_osd_req_op *src_ops,
  373. struct ceph_snap_context *snapc, u64 snap_id,
  374. struct timespec *mtime)
  375. {
  376. struct ceph_msg *msg = req->r_request;
  377. struct ceph_osd_req_op *src_op;
  378. void *p;
  379. size_t msg_size;
  380. int flags = req->r_flags;
  381. u64 data_len;
  382. int i;
  383. req->r_num_ops = num_ops;
  384. req->r_snapid = snap_id;
  385. req->r_snapc = ceph_get_snap_context(snapc);
  386. /* encode request */
  387. msg->hdr.version = cpu_to_le16(4);
  388. p = msg->front.iov_base;
  389. ceph_encode_32(&p, 1); /* client_inc is always 1 */
  390. req->r_request_osdmap_epoch = p;
  391. p += 4;
  392. req->r_request_flags = p;
  393. p += 4;
  394. if (req->r_flags & CEPH_OSD_FLAG_WRITE)
  395. ceph_encode_timespec(p, mtime);
  396. p += sizeof(struct ceph_timespec);
  397. req->r_request_reassert_version = p;
  398. p += sizeof(struct ceph_eversion); /* will get filled in */
  399. /* oloc */
  400. ceph_encode_8(&p, 4);
  401. ceph_encode_8(&p, 4);
  402. ceph_encode_32(&p, 8 + 4 + 4);
  403. req->r_request_pool = p;
  404. p += 8;
  405. ceph_encode_32(&p, -1); /* preferred */
  406. ceph_encode_32(&p, 0); /* key len */
  407. ceph_encode_8(&p, 1);
  408. req->r_request_pgid = p;
  409. p += 8 + 4;
  410. ceph_encode_32(&p, -1); /* preferred */
  411. /* oid */
  412. ceph_encode_32(&p, req->r_oid_len);
  413. memcpy(p, req->r_oid, req->r_oid_len);
  414. dout("oid '%.*s' len %d\n", req->r_oid_len, req->r_oid, req->r_oid_len);
  415. p += req->r_oid_len;
  416. /* ops--can imply data */
  417. ceph_encode_16(&p, num_ops);
  418. src_op = src_ops;
  419. req->r_request_ops = p;
  420. data_len = 0;
  421. for (i = 0; i < num_ops; i++, src_op++) {
  422. data_len += osd_req_encode_op(req, p, src_op);
  423. p += sizeof(struct ceph_osd_op);
  424. }
  425. /* snaps */
  426. ceph_encode_64(&p, req->r_snapid);
  427. ceph_encode_64(&p, req->r_snapc ? req->r_snapc->seq : 0);
  428. ceph_encode_32(&p, req->r_snapc ? req->r_snapc->num_snaps : 0);
  429. if (req->r_snapc) {
  430. for (i = 0; i < snapc->num_snaps; i++) {
  431. ceph_encode_64(&p, req->r_snapc->snaps[i]);
  432. }
  433. }
  434. req->r_request_attempts = p;
  435. p += 4;
  436. /* data */
  437. if (flags & CEPH_OSD_FLAG_WRITE) {
  438. u16 data_off;
  439. /*
  440. * The header "data_off" is a hint to the receiver
  441. * allowing it to align received data into its
  442. * buffers such that there's no need to re-copy
  443. * it before writing it to disk (direct I/O).
  444. */
  445. data_off = (u16) (off & 0xffff);
  446. req->r_request->hdr.data_off = cpu_to_le16(data_off);
  447. }
  448. req->r_request->hdr.data_len = cpu_to_le32(data_len);
  449. BUG_ON(p > msg->front.iov_base + msg->front.iov_len);
  450. msg_size = p - msg->front.iov_base;
  451. msg->front.iov_len = msg_size;
  452. msg->hdr.front_len = cpu_to_le32(msg_size);
  453. dout("build_request msg_size was %d num_ops %d\n", (int)msg_size,
  454. num_ops);
  455. return;
  456. }
  457. EXPORT_SYMBOL(ceph_osdc_build_request);
  458. /*
  459. * build new request AND message, calculate layout, and adjust file
  460. * extent as needed.
  461. *
  462. * if the file was recently truncated, we include information about its
  463. * old and new size so that the object can be updated appropriately. (we
  464. * avoid synchronously deleting truncated objects because it's slow.)
  465. *
  466. * if @do_sync, include a 'startsync' command so that the osd will flush
  467. * data quickly.
  468. */
  469. struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc,
  470. struct ceph_file_layout *layout,
  471. struct ceph_vino vino,
  472. u64 off, u64 *plen,
  473. int opcode, int flags,
  474. struct ceph_snap_context *snapc,
  475. int do_sync,
  476. u32 truncate_seq,
  477. u64 truncate_size,
  478. struct timespec *mtime,
  479. bool use_mempool)
  480. {
  481. struct ceph_osd_req_op ops[2];
  482. struct ceph_osd_request *req;
  483. unsigned int num_op = do_sync ? 2 : 1;
  484. u64 objnum = 0;
  485. u64 objoff = 0;
  486. u64 objlen = 0;
  487. u32 object_size;
  488. u64 object_base;
  489. int r;
  490. BUG_ON(opcode != CEPH_OSD_OP_READ && opcode != CEPH_OSD_OP_WRITE);
  491. req = ceph_osdc_alloc_request(osdc, snapc, num_op, use_mempool,
  492. GFP_NOFS);
  493. if (!req)
  494. return ERR_PTR(-ENOMEM);
  495. req->r_flags = flags;
  496. /* calculate max write size */
  497. r = calc_layout(layout, off, plen, &objnum, &objoff, &objlen);
  498. if (r < 0) {
  499. ceph_osdc_put_request(req);
  500. return ERR_PTR(r);
  501. }
  502. object_size = le32_to_cpu(layout->fl_object_size);
  503. object_base = off - objoff;
  504. if (truncate_size <= object_base) {
  505. truncate_size = 0;
  506. } else {
  507. truncate_size -= object_base;
  508. if (truncate_size > object_size)
  509. truncate_size = object_size;
  510. }
  511. osd_req_op_extent_init(&ops[0], opcode, objoff, objlen,
  512. truncate_size, truncate_seq);
  513. if (do_sync)
  514. osd_req_op_init(&ops[1], CEPH_OSD_OP_STARTSYNC);
  515. req->r_file_layout = *layout; /* keep a copy */
  516. snprintf(req->r_oid, sizeof(req->r_oid), "%llx.%08llx",
  517. vino.ino, objnum);
  518. req->r_oid_len = strlen(req->r_oid);
  519. ceph_osdc_build_request(req, off, num_op, ops,
  520. snapc, vino.snap, mtime);
  521. return req;
  522. }
  523. EXPORT_SYMBOL(ceph_osdc_new_request);
  524. /*
  525. * We keep osd requests in an rbtree, sorted by ->r_tid.
  526. */
  527. static void __insert_request(struct ceph_osd_client *osdc,
  528. struct ceph_osd_request *new)
  529. {
  530. struct rb_node **p = &osdc->requests.rb_node;
  531. struct rb_node *parent = NULL;
  532. struct ceph_osd_request *req = NULL;
  533. while (*p) {
  534. parent = *p;
  535. req = rb_entry(parent, struct ceph_osd_request, r_node);
  536. if (new->r_tid < req->r_tid)
  537. p = &(*p)->rb_left;
  538. else if (new->r_tid > req->r_tid)
  539. p = &(*p)->rb_right;
  540. else
  541. BUG();
  542. }
  543. rb_link_node(&new->r_node, parent, p);
  544. rb_insert_color(&new->r_node, &osdc->requests);
  545. }
  546. static struct ceph_osd_request *__lookup_request(struct ceph_osd_client *osdc,
  547. u64 tid)
  548. {
  549. struct ceph_osd_request *req;
  550. struct rb_node *n = osdc->requests.rb_node;
  551. while (n) {
  552. req = rb_entry(n, struct ceph_osd_request, r_node);
  553. if (tid < req->r_tid)
  554. n = n->rb_left;
  555. else if (tid > req->r_tid)
  556. n = n->rb_right;
  557. else
  558. return req;
  559. }
  560. return NULL;
  561. }
  562. static struct ceph_osd_request *
  563. __lookup_request_ge(struct ceph_osd_client *osdc,
  564. u64 tid)
  565. {
  566. struct ceph_osd_request *req;
  567. struct rb_node *n = osdc->requests.rb_node;
  568. while (n) {
  569. req = rb_entry(n, struct ceph_osd_request, r_node);
  570. if (tid < req->r_tid) {
  571. if (!n->rb_left)
  572. return req;
  573. n = n->rb_left;
  574. } else if (tid > req->r_tid) {
  575. n = n->rb_right;
  576. } else {
  577. return req;
  578. }
  579. }
  580. return NULL;
  581. }
  582. /*
  583. * Resubmit requests pending on the given osd.
  584. */
  585. static void __kick_osd_requests(struct ceph_osd_client *osdc,
  586. struct ceph_osd *osd)
  587. {
  588. struct ceph_osd_request *req, *nreq;
  589. LIST_HEAD(resend);
  590. int err;
  591. dout("__kick_osd_requests osd%d\n", osd->o_osd);
  592. err = __reset_osd(osdc, osd);
  593. if (err)
  594. return;
  595. /*
  596. * Build up a list of requests to resend by traversing the
  597. * osd's list of requests. Requests for a given object are
  598. * sent in tid order, and that is also the order they're
  599. * kept on this list. Therefore all requests that are in
  600. * flight will be found first, followed by all requests that
  601. * have not yet been sent. And to resend requests while
  602. * preserving this order we will want to put any sent
  603. * requests back on the front of the osd client's unsent
  604. * list.
  605. *
  606. * So we build a separate ordered list of already-sent
  607. * requests for the affected osd and splice it onto the
  608. * front of the osd client's unsent list. Once we've seen a
  609. * request that has not yet been sent we're done. Those
  610. * requests are already sitting right where they belong.
  611. */
  612. list_for_each_entry(req, &osd->o_requests, r_osd_item) {
  613. if (!req->r_sent)
  614. break;
  615. list_move_tail(&req->r_req_lru_item, &resend);
  616. dout("requeueing %p tid %llu osd%d\n", req, req->r_tid,
  617. osd->o_osd);
  618. if (!req->r_linger)
  619. req->r_flags |= CEPH_OSD_FLAG_RETRY;
  620. }
  621. list_splice(&resend, &osdc->req_unsent);
  622. /*
  623. * Linger requests are re-registered before sending, which
  624. * sets up a new tid for each. We add them to the unsent
  625. * list at the end to keep things in tid order.
  626. */
  627. list_for_each_entry_safe(req, nreq, &osd->o_linger_requests,
  628. r_linger_osd) {
  629. /*
  630. * reregister request prior to unregistering linger so
  631. * that r_osd is preserved.
  632. */
  633. BUG_ON(!list_empty(&req->r_req_lru_item));
  634. __register_request(osdc, req);
  635. list_add_tail(&req->r_req_lru_item, &osdc->req_unsent);
  636. list_add_tail(&req->r_osd_item, &req->r_osd->o_requests);
  637. __unregister_linger_request(osdc, req);
  638. dout("requeued lingering %p tid %llu osd%d\n", req, req->r_tid,
  639. osd->o_osd);
  640. }
  641. }
  642. /*
  643. * If the osd connection drops, we need to resubmit all requests.
  644. */
  645. static void osd_reset(struct ceph_connection *con)
  646. {
  647. struct ceph_osd *osd = con->private;
  648. struct ceph_osd_client *osdc;
  649. if (!osd)
  650. return;
  651. dout("osd_reset osd%d\n", osd->o_osd);
  652. osdc = osd->o_osdc;
  653. down_read(&osdc->map_sem);
  654. mutex_lock(&osdc->request_mutex);
  655. __kick_osd_requests(osdc, osd);
  656. __send_queued(osdc);
  657. mutex_unlock(&osdc->request_mutex);
  658. up_read(&osdc->map_sem);
  659. }
  660. /*
  661. * Track open sessions with osds.
  662. */
  663. static struct ceph_osd *create_osd(struct ceph_osd_client *osdc, int onum)
  664. {
  665. struct ceph_osd *osd;
  666. osd = kzalloc(sizeof(*osd), GFP_NOFS);
  667. if (!osd)
  668. return NULL;
  669. atomic_set(&osd->o_ref, 1);
  670. osd->o_osdc = osdc;
  671. osd->o_osd = onum;
  672. RB_CLEAR_NODE(&osd->o_node);
  673. INIT_LIST_HEAD(&osd->o_requests);
  674. INIT_LIST_HEAD(&osd->o_linger_requests);
  675. INIT_LIST_HEAD(&osd->o_osd_lru);
  676. osd->o_incarnation = 1;
  677. ceph_con_init(&osd->o_con, osd, &osd_con_ops, &osdc->client->msgr);
  678. INIT_LIST_HEAD(&osd->o_keepalive_item);
  679. return osd;
  680. }
  681. static struct ceph_osd *get_osd(struct ceph_osd *osd)
  682. {
  683. if (atomic_inc_not_zero(&osd->o_ref)) {
  684. dout("get_osd %p %d -> %d\n", osd, atomic_read(&osd->o_ref)-1,
  685. atomic_read(&osd->o_ref));
  686. return osd;
  687. } else {
  688. dout("get_osd %p FAIL\n", osd);
  689. return NULL;
  690. }
  691. }
  692. static void put_osd(struct ceph_osd *osd)
  693. {
  694. dout("put_osd %p %d -> %d\n", osd, atomic_read(&osd->o_ref),
  695. atomic_read(&osd->o_ref) - 1);
  696. if (atomic_dec_and_test(&osd->o_ref) && osd->o_auth.authorizer) {
  697. struct ceph_auth_client *ac = osd->o_osdc->client->monc.auth;
  698. ceph_auth_destroy_authorizer(ac, osd->o_auth.authorizer);
  699. kfree(osd);
  700. }
  701. }
  702. /*
  703. * remove an osd from our map
  704. */
  705. static void __remove_osd(struct ceph_osd_client *osdc, struct ceph_osd *osd)
  706. {
  707. dout("__remove_osd %p\n", osd);
  708. BUG_ON(!list_empty(&osd->o_requests));
  709. rb_erase(&osd->o_node, &osdc->osds);
  710. list_del_init(&osd->o_osd_lru);
  711. ceph_con_close(&osd->o_con);
  712. put_osd(osd);
  713. }
  714. static void remove_all_osds(struct ceph_osd_client *osdc)
  715. {
  716. dout("%s %p\n", __func__, osdc);
  717. mutex_lock(&osdc->request_mutex);
  718. while (!RB_EMPTY_ROOT(&osdc->osds)) {
  719. struct ceph_osd *osd = rb_entry(rb_first(&osdc->osds),
  720. struct ceph_osd, o_node);
  721. __remove_osd(osdc, osd);
  722. }
  723. mutex_unlock(&osdc->request_mutex);
  724. }
  725. static void __move_osd_to_lru(struct ceph_osd_client *osdc,
  726. struct ceph_osd *osd)
  727. {
  728. dout("__move_osd_to_lru %p\n", osd);
  729. BUG_ON(!list_empty(&osd->o_osd_lru));
  730. list_add_tail(&osd->o_osd_lru, &osdc->osd_lru);
  731. osd->lru_ttl = jiffies + osdc->client->options->osd_idle_ttl * HZ;
  732. }
  733. static void __remove_osd_from_lru(struct ceph_osd *osd)
  734. {
  735. dout("__remove_osd_from_lru %p\n", osd);
  736. if (!list_empty(&osd->o_osd_lru))
  737. list_del_init(&osd->o_osd_lru);
  738. }
  739. static void remove_old_osds(struct ceph_osd_client *osdc)
  740. {
  741. struct ceph_osd *osd, *nosd;
  742. dout("__remove_old_osds %p\n", osdc);
  743. mutex_lock(&osdc->request_mutex);
  744. list_for_each_entry_safe(osd, nosd, &osdc->osd_lru, o_osd_lru) {
  745. if (time_before(jiffies, osd->lru_ttl))
  746. break;
  747. __remove_osd(osdc, osd);
  748. }
  749. mutex_unlock(&osdc->request_mutex);
  750. }
  751. /*
  752. * reset osd connect
  753. */
  754. static int __reset_osd(struct ceph_osd_client *osdc, struct ceph_osd *osd)
  755. {
  756. struct ceph_entity_addr *peer_addr;
  757. dout("__reset_osd %p osd%d\n", osd, osd->o_osd);
  758. if (list_empty(&osd->o_requests) &&
  759. list_empty(&osd->o_linger_requests)) {
  760. __remove_osd(osdc, osd);
  761. return -ENODEV;
  762. }
  763. peer_addr = &osdc->osdmap->osd_addr[osd->o_osd];
  764. if (!memcmp(peer_addr, &osd->o_con.peer_addr, sizeof (*peer_addr)) &&
  765. !ceph_con_opened(&osd->o_con)) {
  766. struct ceph_osd_request *req;
  767. dout(" osd addr hasn't changed and connection never opened,"
  768. " letting msgr retry");
  769. /* touch each r_stamp for handle_timeout()'s benfit */
  770. list_for_each_entry(req, &osd->o_requests, r_osd_item)
  771. req->r_stamp = jiffies;
  772. return -EAGAIN;
  773. }
  774. ceph_con_close(&osd->o_con);
  775. ceph_con_open(&osd->o_con, CEPH_ENTITY_TYPE_OSD, osd->o_osd, peer_addr);
  776. osd->o_incarnation++;
  777. return 0;
  778. }
  779. static void __insert_osd(struct ceph_osd_client *osdc, struct ceph_osd *new)
  780. {
  781. struct rb_node **p = &osdc->osds.rb_node;
  782. struct rb_node *parent = NULL;
  783. struct ceph_osd *osd = NULL;
  784. dout("__insert_osd %p osd%d\n", new, new->o_osd);
  785. while (*p) {
  786. parent = *p;
  787. osd = rb_entry(parent, struct ceph_osd, o_node);
  788. if (new->o_osd < osd->o_osd)
  789. p = &(*p)->rb_left;
  790. else if (new->o_osd > osd->o_osd)
  791. p = &(*p)->rb_right;
  792. else
  793. BUG();
  794. }
  795. rb_link_node(&new->o_node, parent, p);
  796. rb_insert_color(&new->o_node, &osdc->osds);
  797. }
  798. static struct ceph_osd *__lookup_osd(struct ceph_osd_client *osdc, int o)
  799. {
  800. struct ceph_osd *osd;
  801. struct rb_node *n = osdc->osds.rb_node;
  802. while (n) {
  803. osd = rb_entry(n, struct ceph_osd, o_node);
  804. if (o < osd->o_osd)
  805. n = n->rb_left;
  806. else if (o > osd->o_osd)
  807. n = n->rb_right;
  808. else
  809. return osd;
  810. }
  811. return NULL;
  812. }
  813. static void __schedule_osd_timeout(struct ceph_osd_client *osdc)
  814. {
  815. schedule_delayed_work(&osdc->timeout_work,
  816. osdc->client->options->osd_keepalive_timeout * HZ);
  817. }
  818. static void __cancel_osd_timeout(struct ceph_osd_client *osdc)
  819. {
  820. cancel_delayed_work(&osdc->timeout_work);
  821. }
  822. /*
  823. * Register request, assign tid. If this is the first request, set up
  824. * the timeout event.
  825. */
  826. static void __register_request(struct ceph_osd_client *osdc,
  827. struct ceph_osd_request *req)
  828. {
  829. req->r_tid = ++osdc->last_tid;
  830. req->r_request->hdr.tid = cpu_to_le64(req->r_tid);
  831. dout("__register_request %p tid %lld\n", req, req->r_tid);
  832. __insert_request(osdc, req);
  833. ceph_osdc_get_request(req);
  834. osdc->num_requests++;
  835. if (osdc->num_requests == 1) {
  836. dout(" first request, scheduling timeout\n");
  837. __schedule_osd_timeout(osdc);
  838. }
  839. }
  840. /*
  841. * called under osdc->request_mutex
  842. */
  843. static void __unregister_request(struct ceph_osd_client *osdc,
  844. struct ceph_osd_request *req)
  845. {
  846. if (RB_EMPTY_NODE(&req->r_node)) {
  847. dout("__unregister_request %p tid %lld not registered\n",
  848. req, req->r_tid);
  849. return;
  850. }
  851. dout("__unregister_request %p tid %lld\n", req, req->r_tid);
  852. rb_erase(&req->r_node, &osdc->requests);
  853. osdc->num_requests--;
  854. if (req->r_osd) {
  855. /* make sure the original request isn't in flight. */
  856. ceph_msg_revoke(req->r_request);
  857. list_del_init(&req->r_osd_item);
  858. if (list_empty(&req->r_osd->o_requests) &&
  859. list_empty(&req->r_osd->o_linger_requests)) {
  860. dout("moving osd to %p lru\n", req->r_osd);
  861. __move_osd_to_lru(osdc, req->r_osd);
  862. }
  863. if (list_empty(&req->r_linger_item))
  864. req->r_osd = NULL;
  865. }
  866. list_del_init(&req->r_req_lru_item);
  867. ceph_osdc_put_request(req);
  868. if (osdc->num_requests == 0) {
  869. dout(" no requests, canceling timeout\n");
  870. __cancel_osd_timeout(osdc);
  871. }
  872. }
  873. /*
  874. * Cancel a previously queued request message
  875. */
  876. static void __cancel_request(struct ceph_osd_request *req)
  877. {
  878. if (req->r_sent && req->r_osd) {
  879. ceph_msg_revoke(req->r_request);
  880. req->r_sent = 0;
  881. }
  882. }
  883. static void __register_linger_request(struct ceph_osd_client *osdc,
  884. struct ceph_osd_request *req)
  885. {
  886. dout("__register_linger_request %p\n", req);
  887. list_add_tail(&req->r_linger_item, &osdc->req_linger);
  888. if (req->r_osd)
  889. list_add_tail(&req->r_linger_osd,
  890. &req->r_osd->o_linger_requests);
  891. }
  892. static void __unregister_linger_request(struct ceph_osd_client *osdc,
  893. struct ceph_osd_request *req)
  894. {
  895. dout("__unregister_linger_request %p\n", req);
  896. list_del_init(&req->r_linger_item);
  897. if (req->r_osd) {
  898. list_del_init(&req->r_linger_osd);
  899. if (list_empty(&req->r_osd->o_requests) &&
  900. list_empty(&req->r_osd->o_linger_requests)) {
  901. dout("moving osd to %p lru\n", req->r_osd);
  902. __move_osd_to_lru(osdc, req->r_osd);
  903. }
  904. if (list_empty(&req->r_osd_item))
  905. req->r_osd = NULL;
  906. }
  907. }
  908. void ceph_osdc_unregister_linger_request(struct ceph_osd_client *osdc,
  909. struct ceph_osd_request *req)
  910. {
  911. mutex_lock(&osdc->request_mutex);
  912. if (req->r_linger) {
  913. __unregister_linger_request(osdc, req);
  914. ceph_osdc_put_request(req);
  915. }
  916. mutex_unlock(&osdc->request_mutex);
  917. }
  918. EXPORT_SYMBOL(ceph_osdc_unregister_linger_request);
  919. void ceph_osdc_set_request_linger(struct ceph_osd_client *osdc,
  920. struct ceph_osd_request *req)
  921. {
  922. if (!req->r_linger) {
  923. dout("set_request_linger %p\n", req);
  924. req->r_linger = 1;
  925. /*
  926. * caller is now responsible for calling
  927. * unregister_linger_request
  928. */
  929. ceph_osdc_get_request(req);
  930. }
  931. }
  932. EXPORT_SYMBOL(ceph_osdc_set_request_linger);
  933. /*
  934. * Pick an osd (the first 'up' osd in the pg), allocate the osd struct
  935. * (as needed), and set the request r_osd appropriately. If there is
  936. * no up osd, set r_osd to NULL. Move the request to the appropriate list
  937. * (unsent, homeless) or leave on in-flight lru.
  938. *
  939. * Return 0 if unchanged, 1 if changed, or negative on error.
  940. *
  941. * Caller should hold map_sem for read and request_mutex.
  942. */
  943. static int __map_request(struct ceph_osd_client *osdc,
  944. struct ceph_osd_request *req, int force_resend)
  945. {
  946. struct ceph_pg pgid;
  947. int acting[CEPH_PG_MAX_SIZE];
  948. int o = -1, num = 0;
  949. int err;
  950. dout("map_request %p tid %lld\n", req, req->r_tid);
  951. err = ceph_calc_ceph_pg(&pgid, req->r_oid, osdc->osdmap,
  952. ceph_file_layout_pg_pool(req->r_file_layout));
  953. if (err) {
  954. list_move(&req->r_req_lru_item, &osdc->req_notarget);
  955. return err;
  956. }
  957. req->r_pgid = pgid;
  958. err = ceph_calc_pg_acting(osdc->osdmap, pgid, acting);
  959. if (err > 0) {
  960. o = acting[0];
  961. num = err;
  962. }
  963. if ((!force_resend &&
  964. req->r_osd && req->r_osd->o_osd == o &&
  965. req->r_sent >= req->r_osd->o_incarnation &&
  966. req->r_num_pg_osds == num &&
  967. memcmp(req->r_pg_osds, acting, sizeof(acting[0])*num) == 0) ||
  968. (req->r_osd == NULL && o == -1))
  969. return 0; /* no change */
  970. dout("map_request tid %llu pgid %lld.%x osd%d (was osd%d)\n",
  971. req->r_tid, pgid.pool, pgid.seed, o,
  972. req->r_osd ? req->r_osd->o_osd : -1);
  973. /* record full pg acting set */
  974. memcpy(req->r_pg_osds, acting, sizeof(acting[0]) * num);
  975. req->r_num_pg_osds = num;
  976. if (req->r_osd) {
  977. __cancel_request(req);
  978. list_del_init(&req->r_osd_item);
  979. req->r_osd = NULL;
  980. }
  981. req->r_osd = __lookup_osd(osdc, o);
  982. if (!req->r_osd && o >= 0) {
  983. err = -ENOMEM;
  984. req->r_osd = create_osd(osdc, o);
  985. if (!req->r_osd) {
  986. list_move(&req->r_req_lru_item, &osdc->req_notarget);
  987. goto out;
  988. }
  989. dout("map_request osd %p is osd%d\n", req->r_osd, o);
  990. __insert_osd(osdc, req->r_osd);
  991. ceph_con_open(&req->r_osd->o_con,
  992. CEPH_ENTITY_TYPE_OSD, o,
  993. &osdc->osdmap->osd_addr[o]);
  994. }
  995. if (req->r_osd) {
  996. __remove_osd_from_lru(req->r_osd);
  997. list_add_tail(&req->r_osd_item, &req->r_osd->o_requests);
  998. list_move_tail(&req->r_req_lru_item, &osdc->req_unsent);
  999. } else {
  1000. list_move_tail(&req->r_req_lru_item, &osdc->req_notarget);
  1001. }
  1002. err = 1; /* osd or pg changed */
  1003. out:
  1004. return err;
  1005. }
  1006. /*
  1007. * caller should hold map_sem (for read) and request_mutex
  1008. */
  1009. static void __send_request(struct ceph_osd_client *osdc,
  1010. struct ceph_osd_request *req)
  1011. {
  1012. void *p;
  1013. dout("send_request %p tid %llu to osd%d flags %d pg %lld.%x\n",
  1014. req, req->r_tid, req->r_osd->o_osd, req->r_flags,
  1015. (unsigned long long)req->r_pgid.pool, req->r_pgid.seed);
  1016. /* fill in message content that changes each time we send it */
  1017. put_unaligned_le32(osdc->osdmap->epoch, req->r_request_osdmap_epoch);
  1018. put_unaligned_le32(req->r_flags, req->r_request_flags);
  1019. put_unaligned_le64(req->r_pgid.pool, req->r_request_pool);
  1020. p = req->r_request_pgid;
  1021. ceph_encode_64(&p, req->r_pgid.pool);
  1022. ceph_encode_32(&p, req->r_pgid.seed);
  1023. put_unaligned_le64(1, req->r_request_attempts); /* FIXME */
  1024. memcpy(req->r_request_reassert_version, &req->r_reassert_version,
  1025. sizeof(req->r_reassert_version));
  1026. req->r_stamp = jiffies;
  1027. list_move_tail(&req->r_req_lru_item, &osdc->req_lru);
  1028. ceph_msg_get(req->r_request); /* send consumes a ref */
  1029. ceph_con_send(&req->r_osd->o_con, req->r_request);
  1030. req->r_sent = req->r_osd->o_incarnation;
  1031. }
  1032. /*
  1033. * Send any requests in the queue (req_unsent).
  1034. */
  1035. static void __send_queued(struct ceph_osd_client *osdc)
  1036. {
  1037. struct ceph_osd_request *req, *tmp;
  1038. dout("__send_queued\n");
  1039. list_for_each_entry_safe(req, tmp, &osdc->req_unsent, r_req_lru_item)
  1040. __send_request(osdc, req);
  1041. }
  1042. /*
  1043. * Timeout callback, called every N seconds when 1 or more osd
  1044. * requests has been active for more than N seconds. When this
  1045. * happens, we ping all OSDs with requests who have timed out to
  1046. * ensure any communications channel reset is detected. Reset the
  1047. * request timeouts another N seconds in the future as we go.
  1048. * Reschedule the timeout event another N seconds in future (unless
  1049. * there are no open requests).
  1050. */
  1051. static void handle_timeout(struct work_struct *work)
  1052. {
  1053. struct ceph_osd_client *osdc =
  1054. container_of(work, struct ceph_osd_client, timeout_work.work);
  1055. struct ceph_osd_request *req;
  1056. struct ceph_osd *osd;
  1057. unsigned long keepalive =
  1058. osdc->client->options->osd_keepalive_timeout * HZ;
  1059. struct list_head slow_osds;
  1060. dout("timeout\n");
  1061. down_read(&osdc->map_sem);
  1062. ceph_monc_request_next_osdmap(&osdc->client->monc);
  1063. mutex_lock(&osdc->request_mutex);
  1064. /*
  1065. * ping osds that are a bit slow. this ensures that if there
  1066. * is a break in the TCP connection we will notice, and reopen
  1067. * a connection with that osd (from the fault callback).
  1068. */
  1069. INIT_LIST_HEAD(&slow_osds);
  1070. list_for_each_entry(req, &osdc->req_lru, r_req_lru_item) {
  1071. if (time_before(jiffies, req->r_stamp + keepalive))
  1072. break;
  1073. osd = req->r_osd;
  1074. BUG_ON(!osd);
  1075. dout(" tid %llu is slow, will send keepalive on osd%d\n",
  1076. req->r_tid, osd->o_osd);
  1077. list_move_tail(&osd->o_keepalive_item, &slow_osds);
  1078. }
  1079. while (!list_empty(&slow_osds)) {
  1080. osd = list_entry(slow_osds.next, struct ceph_osd,
  1081. o_keepalive_item);
  1082. list_del_init(&osd->o_keepalive_item);
  1083. ceph_con_keepalive(&osd->o_con);
  1084. }
  1085. __schedule_osd_timeout(osdc);
  1086. __send_queued(osdc);
  1087. mutex_unlock(&osdc->request_mutex);
  1088. up_read(&osdc->map_sem);
  1089. }
  1090. static void handle_osds_timeout(struct work_struct *work)
  1091. {
  1092. struct ceph_osd_client *osdc =
  1093. container_of(work, struct ceph_osd_client,
  1094. osds_timeout_work.work);
  1095. unsigned long delay =
  1096. osdc->client->options->osd_idle_ttl * HZ >> 2;
  1097. dout("osds timeout\n");
  1098. down_read(&osdc->map_sem);
  1099. remove_old_osds(osdc);
  1100. up_read(&osdc->map_sem);
  1101. schedule_delayed_work(&osdc->osds_timeout_work,
  1102. round_jiffies_relative(delay));
  1103. }
  1104. static void complete_request(struct ceph_osd_request *req)
  1105. {
  1106. if (req->r_safe_callback)
  1107. req->r_safe_callback(req, NULL);
  1108. complete_all(&req->r_safe_completion); /* fsync waiter */
  1109. }
  1110. static int __decode_pgid(void **p, void *end, struct ceph_pg *pgid)
  1111. {
  1112. __u8 v;
  1113. ceph_decode_need(p, end, 1 + 8 + 4 + 4, bad);
  1114. v = ceph_decode_8(p);
  1115. if (v > 1) {
  1116. pr_warning("do not understand pg encoding %d > 1", v);
  1117. return -EINVAL;
  1118. }
  1119. pgid->pool = ceph_decode_64(p);
  1120. pgid->seed = ceph_decode_32(p);
  1121. *p += 4;
  1122. return 0;
  1123. bad:
  1124. pr_warning("incomplete pg encoding");
  1125. return -EINVAL;
  1126. }
  1127. /*
  1128. * handle osd op reply. either call the callback if it is specified,
  1129. * or do the completion to wake up the waiting thread.
  1130. */
  1131. static void handle_reply(struct ceph_osd_client *osdc, struct ceph_msg *msg,
  1132. struct ceph_connection *con)
  1133. {
  1134. void *p, *end;
  1135. struct ceph_osd_request *req;
  1136. u64 tid;
  1137. int object_len;
  1138. int numops, payload_len, flags;
  1139. s32 result;
  1140. s32 retry_attempt;
  1141. struct ceph_pg pg;
  1142. int err;
  1143. u32 reassert_epoch;
  1144. u64 reassert_version;
  1145. u32 osdmap_epoch;
  1146. int already_completed;
  1147. int i;
  1148. tid = le64_to_cpu(msg->hdr.tid);
  1149. dout("handle_reply %p tid %llu\n", msg, tid);
  1150. p = msg->front.iov_base;
  1151. end = p + msg->front.iov_len;
  1152. ceph_decode_need(&p, end, 4, bad);
  1153. object_len = ceph_decode_32(&p);
  1154. ceph_decode_need(&p, end, object_len, bad);
  1155. p += object_len;
  1156. err = __decode_pgid(&p, end, &pg);
  1157. if (err)
  1158. goto bad;
  1159. ceph_decode_need(&p, end, 8 + 4 + 4 + 8 + 4, bad);
  1160. flags = ceph_decode_64(&p);
  1161. result = ceph_decode_32(&p);
  1162. reassert_epoch = ceph_decode_32(&p);
  1163. reassert_version = ceph_decode_64(&p);
  1164. osdmap_epoch = ceph_decode_32(&p);
  1165. /* lookup */
  1166. mutex_lock(&osdc->request_mutex);
  1167. req = __lookup_request(osdc, tid);
  1168. if (req == NULL) {
  1169. dout("handle_reply tid %llu dne\n", tid);
  1170. goto bad_mutex;
  1171. }
  1172. ceph_osdc_get_request(req);
  1173. dout("handle_reply %p tid %llu req %p result %d\n", msg, tid,
  1174. req, result);
  1175. ceph_decode_need(&p, end, 4, bad);
  1176. numops = ceph_decode_32(&p);
  1177. if (numops > CEPH_OSD_MAX_OP)
  1178. goto bad_put;
  1179. if (numops != req->r_num_ops)
  1180. goto bad_put;
  1181. payload_len = 0;
  1182. ceph_decode_need(&p, end, numops * sizeof(struct ceph_osd_op), bad);
  1183. for (i = 0; i < numops; i++) {
  1184. struct ceph_osd_op *op = p;
  1185. int len;
  1186. len = le32_to_cpu(op->payload_len);
  1187. req->r_reply_op_len[i] = len;
  1188. dout(" op %d has %d bytes\n", i, len);
  1189. payload_len += len;
  1190. p += sizeof(*op);
  1191. }
  1192. if (payload_len != le32_to_cpu(msg->hdr.data_len)) {
  1193. pr_warning("sum of op payload lens %d != data_len %d",
  1194. payload_len, le32_to_cpu(msg->hdr.data_len));
  1195. goto bad_put;
  1196. }
  1197. ceph_decode_need(&p, end, 4 + numops * 4, bad);
  1198. retry_attempt = ceph_decode_32(&p);
  1199. for (i = 0; i < numops; i++)
  1200. req->r_reply_op_result[i] = ceph_decode_32(&p);
  1201. /*
  1202. * if this connection filled our message, drop our reference now, to
  1203. * avoid a (safe but slower) revoke later.
  1204. */
  1205. if (req->r_con_filling_msg == con && req->r_reply == msg) {
  1206. dout(" dropping con_filling_msg ref %p\n", con);
  1207. req->r_con_filling_msg = NULL;
  1208. con->ops->put(con);
  1209. }
  1210. if (!req->r_got_reply) {
  1211. unsigned int bytes;
  1212. req->r_result = result;
  1213. bytes = le32_to_cpu(msg->hdr.data_len);
  1214. dout("handle_reply result %d bytes %d\n", req->r_result,
  1215. bytes);
  1216. if (req->r_result == 0)
  1217. req->r_result = bytes;
  1218. /* in case this is a write and we need to replay, */
  1219. req->r_reassert_version.epoch = cpu_to_le32(reassert_epoch);
  1220. req->r_reassert_version.version = cpu_to_le64(reassert_version);
  1221. req->r_got_reply = 1;
  1222. } else if ((flags & CEPH_OSD_FLAG_ONDISK) == 0) {
  1223. dout("handle_reply tid %llu dup ack\n", tid);
  1224. mutex_unlock(&osdc->request_mutex);
  1225. goto done;
  1226. }
  1227. dout("handle_reply tid %llu flags %d\n", tid, flags);
  1228. if (req->r_linger && (flags & CEPH_OSD_FLAG_ONDISK))
  1229. __register_linger_request(osdc, req);
  1230. /* either this is a read, or we got the safe response */
  1231. if (result < 0 ||
  1232. (flags & CEPH_OSD_FLAG_ONDISK) ||
  1233. ((flags & CEPH_OSD_FLAG_WRITE) == 0))
  1234. __unregister_request(osdc, req);
  1235. already_completed = req->r_completed;
  1236. req->r_completed = 1;
  1237. mutex_unlock(&osdc->request_mutex);
  1238. if (already_completed)
  1239. goto done;
  1240. if (req->r_callback)
  1241. req->r_callback(req, msg);
  1242. else
  1243. complete_all(&req->r_completion);
  1244. if (flags & CEPH_OSD_FLAG_ONDISK)
  1245. complete_request(req);
  1246. done:
  1247. dout("req=%p req->r_linger=%d\n", req, req->r_linger);
  1248. ceph_osdc_put_request(req);
  1249. return;
  1250. bad_put:
  1251. ceph_osdc_put_request(req);
  1252. bad_mutex:
  1253. mutex_unlock(&osdc->request_mutex);
  1254. bad:
  1255. pr_err("corrupt osd_op_reply got %d %d\n",
  1256. (int)msg->front.iov_len, le32_to_cpu(msg->hdr.front_len));
  1257. ceph_msg_dump(msg);
  1258. }
  1259. static void reset_changed_osds(struct ceph_osd_client *osdc)
  1260. {
  1261. struct rb_node *p, *n;
  1262. for (p = rb_first(&osdc->osds); p; p = n) {
  1263. struct ceph_osd *osd = rb_entry(p, struct ceph_osd, o_node);
  1264. n = rb_next(p);
  1265. if (!ceph_osd_is_up(osdc->osdmap, osd->o_osd) ||
  1266. memcmp(&osd->o_con.peer_addr,
  1267. ceph_osd_addr(osdc->osdmap,
  1268. osd->o_osd),
  1269. sizeof(struct ceph_entity_addr)) != 0)
  1270. __reset_osd(osdc, osd);
  1271. }
  1272. }
  1273. /*
  1274. * Requeue requests whose mapping to an OSD has changed. If requests map to
  1275. * no osd, request a new map.
  1276. *
  1277. * Caller should hold map_sem for read.
  1278. */
  1279. static void kick_requests(struct ceph_osd_client *osdc, int force_resend)
  1280. {
  1281. struct ceph_osd_request *req, *nreq;
  1282. struct rb_node *p;
  1283. int needmap = 0;
  1284. int err;
  1285. dout("kick_requests %s\n", force_resend ? " (force resend)" : "");
  1286. mutex_lock(&osdc->request_mutex);
  1287. for (p = rb_first(&osdc->requests); p; ) {
  1288. req = rb_entry(p, struct ceph_osd_request, r_node);
  1289. p = rb_next(p);
  1290. /*
  1291. * For linger requests that have not yet been
  1292. * registered, move them to the linger list; they'll
  1293. * be sent to the osd in the loop below. Unregister
  1294. * the request before re-registering it as a linger
  1295. * request to ensure the __map_request() below
  1296. * will decide it needs to be sent.
  1297. */
  1298. if (req->r_linger && list_empty(&req->r_linger_item)) {
  1299. dout("%p tid %llu restart on osd%d\n",
  1300. req, req->r_tid,
  1301. req->r_osd ? req->r_osd->o_osd : -1);
  1302. __unregister_request(osdc, req);
  1303. __register_linger_request(osdc, req);
  1304. continue;
  1305. }
  1306. err = __map_request(osdc, req, force_resend);
  1307. if (err < 0)
  1308. continue; /* error */
  1309. if (req->r_osd == NULL) {
  1310. dout("%p tid %llu maps to no osd\n", req, req->r_tid);
  1311. needmap++; /* request a newer map */
  1312. } else if (err > 0) {
  1313. if (!req->r_linger) {
  1314. dout("%p tid %llu requeued on osd%d\n", req,
  1315. req->r_tid,
  1316. req->r_osd ? req->r_osd->o_osd : -1);
  1317. req->r_flags |= CEPH_OSD_FLAG_RETRY;
  1318. }
  1319. }
  1320. }
  1321. list_for_each_entry_safe(req, nreq, &osdc->req_linger,
  1322. r_linger_item) {
  1323. dout("linger req=%p req->r_osd=%p\n", req, req->r_osd);
  1324. err = __map_request(osdc, req, force_resend);
  1325. dout("__map_request returned %d\n", err);
  1326. if (err == 0)
  1327. continue; /* no change and no osd was specified */
  1328. if (err < 0)
  1329. continue; /* hrm! */
  1330. if (req->r_osd == NULL) {
  1331. dout("tid %llu maps to no valid osd\n", req->r_tid);
  1332. needmap++; /* request a newer map */
  1333. continue;
  1334. }
  1335. dout("kicking lingering %p tid %llu osd%d\n", req, req->r_tid,
  1336. req->r_osd ? req->r_osd->o_osd : -1);
  1337. __register_request(osdc, req);
  1338. __unregister_linger_request(osdc, req);
  1339. }
  1340. mutex_unlock(&osdc->request_mutex);
  1341. if (needmap) {
  1342. dout("%d requests for down osds, need new map\n", needmap);
  1343. ceph_monc_request_next_osdmap(&osdc->client->monc);
  1344. }
  1345. reset_changed_osds(osdc);
  1346. }
  1347. /*
  1348. * Process updated osd map.
  1349. *
  1350. * The message contains any number of incremental and full maps, normally
  1351. * indicating some sort of topology change in the cluster. Kick requests
  1352. * off to different OSDs as needed.
  1353. */
  1354. void ceph_osdc_handle_map(struct ceph_osd_client *osdc, struct ceph_msg *msg)
  1355. {
  1356. void *p, *end, *next;
  1357. u32 nr_maps, maplen;
  1358. u32 epoch;
  1359. struct ceph_osdmap *newmap = NULL, *oldmap;
  1360. int err;
  1361. struct ceph_fsid fsid;
  1362. dout("handle_map have %u\n", osdc->osdmap ? osdc->osdmap->epoch : 0);
  1363. p = msg->front.iov_base;
  1364. end = p + msg->front.iov_len;
  1365. /* verify fsid */
  1366. ceph_decode_need(&p, end, sizeof(fsid), bad);
  1367. ceph_decode_copy(&p, &fsid, sizeof(fsid));
  1368. if (ceph_check_fsid(osdc->client, &fsid) < 0)
  1369. return;
  1370. down_write(&osdc->map_sem);
  1371. /* incremental maps */
  1372. ceph_decode_32_safe(&p, end, nr_maps, bad);
  1373. dout(" %d inc maps\n", nr_maps);
  1374. while (nr_maps > 0) {
  1375. ceph_decode_need(&p, end, 2*sizeof(u32), bad);
  1376. epoch = ceph_decode_32(&p);
  1377. maplen = ceph_decode_32(&p);
  1378. ceph_decode_need(&p, end, maplen, bad);
  1379. next = p + maplen;
  1380. if (osdc->osdmap && osdc->osdmap->epoch+1 == epoch) {
  1381. dout("applying incremental map %u len %d\n",
  1382. epoch, maplen);
  1383. newmap = osdmap_apply_incremental(&p, next,
  1384. osdc->osdmap,
  1385. &osdc->client->msgr);
  1386. if (IS_ERR(newmap)) {
  1387. err = PTR_ERR(newmap);
  1388. goto bad;
  1389. }
  1390. BUG_ON(!newmap);
  1391. if (newmap != osdc->osdmap) {
  1392. ceph_osdmap_destroy(osdc->osdmap);
  1393. osdc->osdmap = newmap;
  1394. }
  1395. kick_requests(osdc, 0);
  1396. } else {
  1397. dout("ignoring incremental map %u len %d\n",
  1398. epoch, maplen);
  1399. }
  1400. p = next;
  1401. nr_maps--;
  1402. }
  1403. if (newmap)
  1404. goto done;
  1405. /* full maps */
  1406. ceph_decode_32_safe(&p, end, nr_maps, bad);
  1407. dout(" %d full maps\n", nr_maps);
  1408. while (nr_maps) {
  1409. ceph_decode_need(&p, end, 2*sizeof(u32), bad);
  1410. epoch = ceph_decode_32(&p);
  1411. maplen = ceph_decode_32(&p);
  1412. ceph_decode_need(&p, end, maplen, bad);
  1413. if (nr_maps > 1) {
  1414. dout("skipping non-latest full map %u len %d\n",
  1415. epoch, maplen);
  1416. } else if (osdc->osdmap && osdc->osdmap->epoch >= epoch) {
  1417. dout("skipping full map %u len %d, "
  1418. "older than our %u\n", epoch, maplen,
  1419. osdc->osdmap->epoch);
  1420. } else {
  1421. int skipped_map = 0;
  1422. dout("taking full map %u len %d\n", epoch, maplen);
  1423. newmap = osdmap_decode(&p, p+maplen);
  1424. if (IS_ERR(newmap)) {
  1425. err = PTR_ERR(newmap);
  1426. goto bad;
  1427. }
  1428. BUG_ON(!newmap);
  1429. oldmap = osdc->osdmap;
  1430. osdc->osdmap = newmap;
  1431. if (oldmap) {
  1432. if (oldmap->epoch + 1 < newmap->epoch)
  1433. skipped_map = 1;
  1434. ceph_osdmap_destroy(oldmap);
  1435. }
  1436. kick_requests(osdc, skipped_map);
  1437. }
  1438. p += maplen;
  1439. nr_maps--;
  1440. }
  1441. done:
  1442. downgrade_write(&osdc->map_sem);
  1443. ceph_monc_got_osdmap(&osdc->client->monc, osdc->osdmap->epoch);
  1444. /*
  1445. * subscribe to subsequent osdmap updates if full to ensure
  1446. * we find out when we are no longer full and stop returning
  1447. * ENOSPC.
  1448. */
  1449. if (ceph_osdmap_flag(osdc->osdmap, CEPH_OSDMAP_FULL))
  1450. ceph_monc_request_next_osdmap(&osdc->client->monc);
  1451. mutex_lock(&osdc->request_mutex);
  1452. __send_queued(osdc);
  1453. mutex_unlock(&osdc->request_mutex);
  1454. up_read(&osdc->map_sem);
  1455. wake_up_all(&osdc->client->auth_wq);
  1456. return;
  1457. bad:
  1458. pr_err("osdc handle_map corrupt msg\n");
  1459. ceph_msg_dump(msg);
  1460. up_write(&osdc->map_sem);
  1461. return;
  1462. }
  1463. /*
  1464. * watch/notify callback event infrastructure
  1465. *
  1466. * These callbacks are used both for watch and notify operations.
  1467. */
  1468. static void __release_event(struct kref *kref)
  1469. {
  1470. struct ceph_osd_event *event =
  1471. container_of(kref, struct ceph_osd_event, kref);
  1472. dout("__release_event %p\n", event);
  1473. kfree(event);
  1474. }
  1475. static void get_event(struct ceph_osd_event *event)
  1476. {
  1477. kref_get(&event->kref);
  1478. }
  1479. void ceph_osdc_put_event(struct ceph_osd_event *event)
  1480. {
  1481. kref_put(&event->kref, __release_event);
  1482. }
  1483. EXPORT_SYMBOL(ceph_osdc_put_event);
  1484. static void __insert_event(struct ceph_osd_client *osdc,
  1485. struct ceph_osd_event *new)
  1486. {
  1487. struct rb_node **p = &osdc->event_tree.rb_node;
  1488. struct rb_node *parent = NULL;
  1489. struct ceph_osd_event *event = NULL;
  1490. while (*p) {
  1491. parent = *p;
  1492. event = rb_entry(parent, struct ceph_osd_event, node);
  1493. if (new->cookie < event->cookie)
  1494. p = &(*p)->rb_left;
  1495. else if (new->cookie > event->cookie)
  1496. p = &(*p)->rb_right;
  1497. else
  1498. BUG();
  1499. }
  1500. rb_link_node(&new->node, parent, p);
  1501. rb_insert_color(&new->node, &osdc->event_tree);
  1502. }
  1503. static struct ceph_osd_event *__find_event(struct ceph_osd_client *osdc,
  1504. u64 cookie)
  1505. {
  1506. struct rb_node **p = &osdc->event_tree.rb_node;
  1507. struct rb_node *parent = NULL;
  1508. struct ceph_osd_event *event = NULL;
  1509. while (*p) {
  1510. parent = *p;
  1511. event = rb_entry(parent, struct ceph_osd_event, node);
  1512. if (cookie < event->cookie)
  1513. p = &(*p)->rb_left;
  1514. else if (cookie > event->cookie)
  1515. p = &(*p)->rb_right;
  1516. else
  1517. return event;
  1518. }
  1519. return NULL;
  1520. }
  1521. static void __remove_event(struct ceph_osd_event *event)
  1522. {
  1523. struct ceph_osd_client *osdc = event->osdc;
  1524. if (!RB_EMPTY_NODE(&event->node)) {
  1525. dout("__remove_event removed %p\n", event);
  1526. rb_erase(&event->node, &osdc->event_tree);
  1527. ceph_osdc_put_event(event);
  1528. } else {
  1529. dout("__remove_event didn't remove %p\n", event);
  1530. }
  1531. }
  1532. int ceph_osdc_create_event(struct ceph_osd_client *osdc,
  1533. void (*event_cb)(u64, u64, u8, void *),
  1534. void *data, struct ceph_osd_event **pevent)
  1535. {
  1536. struct ceph_osd_event *event;
  1537. event = kmalloc(sizeof(*event), GFP_NOIO);
  1538. if (!event)
  1539. return -ENOMEM;
  1540. dout("create_event %p\n", event);
  1541. event->cb = event_cb;
  1542. event->one_shot = 0;
  1543. event->data = data;
  1544. event->osdc = osdc;
  1545. INIT_LIST_HEAD(&event->osd_node);
  1546. RB_CLEAR_NODE(&event->node);
  1547. kref_init(&event->kref); /* one ref for us */
  1548. kref_get(&event->kref); /* one ref for the caller */
  1549. spin_lock(&osdc->event_lock);
  1550. event->cookie = ++osdc->event_count;
  1551. __insert_event(osdc, event);
  1552. spin_unlock(&osdc->event_lock);
  1553. *pevent = event;
  1554. return 0;
  1555. }
  1556. EXPORT_SYMBOL(ceph_osdc_create_event);
  1557. void ceph_osdc_cancel_event(struct ceph_osd_event *event)
  1558. {
  1559. struct ceph_osd_client *osdc = event->osdc;
  1560. dout("cancel_event %p\n", event);
  1561. spin_lock(&osdc->event_lock);
  1562. __remove_event(event);
  1563. spin_unlock(&osdc->event_lock);
  1564. ceph_osdc_put_event(event); /* caller's */
  1565. }
  1566. EXPORT_SYMBOL(ceph_osdc_cancel_event);
  1567. static void do_event_work(struct work_struct *work)
  1568. {
  1569. struct ceph_osd_event_work *event_work =
  1570. container_of(work, struct ceph_osd_event_work, work);
  1571. struct ceph_osd_event *event = event_work->event;
  1572. u64 ver = event_work->ver;
  1573. u64 notify_id = event_work->notify_id;
  1574. u8 opcode = event_work->opcode;
  1575. dout("do_event_work completing %p\n", event);
  1576. event->cb(ver, notify_id, opcode, event->data);
  1577. dout("do_event_work completed %p\n", event);
  1578. ceph_osdc_put_event(event);
  1579. kfree(event_work);
  1580. }
  1581. /*
  1582. * Process osd watch notifications
  1583. */
  1584. static void handle_watch_notify(struct ceph_osd_client *osdc,
  1585. struct ceph_msg *msg)
  1586. {
  1587. void *p, *end;
  1588. u8 proto_ver;
  1589. u64 cookie, ver, notify_id;
  1590. u8 opcode;
  1591. struct ceph_osd_event *event;
  1592. struct ceph_osd_event_work *event_work;
  1593. p = msg->front.iov_base;
  1594. end = p + msg->front.iov_len;
  1595. ceph_decode_8_safe(&p, end, proto_ver, bad);
  1596. ceph_decode_8_safe(&p, end, opcode, bad);
  1597. ceph_decode_64_safe(&p, end, cookie, bad);
  1598. ceph_decode_64_safe(&p, end, ver, bad);
  1599. ceph_decode_64_safe(&p, end, notify_id, bad);
  1600. spin_lock(&osdc->event_lock);
  1601. event = __find_event(osdc, cookie);
  1602. if (event) {
  1603. BUG_ON(event->one_shot);
  1604. get_event(event);
  1605. }
  1606. spin_unlock(&osdc->event_lock);
  1607. dout("handle_watch_notify cookie %lld ver %lld event %p\n",
  1608. cookie, ver, event);
  1609. if (event) {
  1610. event_work = kmalloc(sizeof(*event_work), GFP_NOIO);
  1611. if (!event_work) {
  1612. dout("ERROR: could not allocate event_work\n");
  1613. goto done_err;
  1614. }
  1615. INIT_WORK(&event_work->work, do_event_work);
  1616. event_work->event = event;
  1617. event_work->ver = ver;
  1618. event_work->notify_id = notify_id;
  1619. event_work->opcode = opcode;
  1620. if (!queue_work(osdc->notify_wq, &event_work->work)) {
  1621. dout("WARNING: failed to queue notify event work\n");
  1622. goto done_err;
  1623. }
  1624. }
  1625. return;
  1626. done_err:
  1627. ceph_osdc_put_event(event);
  1628. return;
  1629. bad:
  1630. pr_err("osdc handle_watch_notify corrupt msg\n");
  1631. return;
  1632. }
  1633. static void ceph_osdc_msg_data_set(struct ceph_msg *msg,
  1634. struct ceph_osd_data *osd_data)
  1635. {
  1636. if (osd_data->type == CEPH_OSD_DATA_TYPE_PAGES) {
  1637. BUG_ON(osd_data->length > (u64) SIZE_MAX);
  1638. if (osd_data->length)
  1639. ceph_msg_data_set_pages(msg, osd_data->pages,
  1640. osd_data->length, osd_data->alignment);
  1641. } else if (osd_data->type == CEPH_OSD_DATA_TYPE_PAGELIST) {
  1642. BUG_ON(!osd_data->pagelist->length);
  1643. ceph_msg_data_set_pagelist(msg, osd_data->pagelist);
  1644. #ifdef CONFIG_BLOCK
  1645. } else if (osd_data->type == CEPH_OSD_DATA_TYPE_BIO) {
  1646. ceph_msg_data_set_bio(msg, osd_data->bio);
  1647. #endif
  1648. } else {
  1649. BUG_ON(osd_data->type != CEPH_OSD_DATA_TYPE_NONE);
  1650. }
  1651. }
  1652. /*
  1653. * Register request, send initial attempt.
  1654. */
  1655. int ceph_osdc_start_request(struct ceph_osd_client *osdc,
  1656. struct ceph_osd_request *req,
  1657. bool nofail)
  1658. {
  1659. int rc = 0;
  1660. /* Set up response incoming data and request outgoing data fields */
  1661. ceph_osdc_msg_data_set(req->r_reply, &req->r_data_in);
  1662. ceph_osdc_msg_data_set(req->r_request, &req->r_data_out);
  1663. down_read(&osdc->map_sem);
  1664. mutex_lock(&osdc->request_mutex);
  1665. __register_request(osdc, req);
  1666. WARN_ON(req->r_sent);
  1667. rc = __map_request(osdc, req, 0);
  1668. if (rc < 0) {
  1669. if (nofail) {
  1670. dout("osdc_start_request failed map, "
  1671. " will retry %lld\n", req->r_tid);
  1672. rc = 0;
  1673. }
  1674. goto out_unlock;
  1675. }
  1676. if (req->r_osd == NULL) {
  1677. dout("send_request %p no up osds in pg\n", req);
  1678. ceph_monc_request_next_osdmap(&osdc->client->monc);
  1679. } else {
  1680. __send_queued(osdc);
  1681. }
  1682. rc = 0;
  1683. out_unlock:
  1684. mutex_unlock(&osdc->request_mutex);
  1685. up_read(&osdc->map_sem);
  1686. return rc;
  1687. }
  1688. EXPORT_SYMBOL(ceph_osdc_start_request);
  1689. /*
  1690. * wait for a request to complete
  1691. */
  1692. int ceph_osdc_wait_request(struct ceph_osd_client *osdc,
  1693. struct ceph_osd_request *req)
  1694. {
  1695. int rc;
  1696. rc = wait_for_completion_interruptible(&req->r_completion);
  1697. if (rc < 0) {
  1698. mutex_lock(&osdc->request_mutex);
  1699. __cancel_request(req);
  1700. __unregister_request(osdc, req);
  1701. mutex_unlock(&osdc->request_mutex);
  1702. complete_request(req);
  1703. dout("wait_request tid %llu canceled/timed out\n", req->r_tid);
  1704. return rc;
  1705. }
  1706. dout("wait_request tid %llu result %d\n", req->r_tid, req->r_result);
  1707. return req->r_result;
  1708. }
  1709. EXPORT_SYMBOL(ceph_osdc_wait_request);
  1710. /*
  1711. * sync - wait for all in-flight requests to flush. avoid starvation.
  1712. */
  1713. void ceph_osdc_sync(struct ceph_osd_client *osdc)
  1714. {
  1715. struct ceph_osd_request *req;
  1716. u64 last_tid, next_tid = 0;
  1717. mutex_lock(&osdc->request_mutex);
  1718. last_tid = osdc->last_tid;
  1719. while (1) {
  1720. req = __lookup_request_ge(osdc, next_tid);
  1721. if (!req)
  1722. break;
  1723. if (req->r_tid > last_tid)
  1724. break;
  1725. next_tid = req->r_tid + 1;
  1726. if ((req->r_flags & CEPH_OSD_FLAG_WRITE) == 0)
  1727. continue;
  1728. ceph_osdc_get_request(req);
  1729. mutex_unlock(&osdc->request_mutex);
  1730. dout("sync waiting on tid %llu (last is %llu)\n",
  1731. req->r_tid, last_tid);
  1732. wait_for_completion(&req->r_safe_completion);
  1733. mutex_lock(&osdc->request_mutex);
  1734. ceph_osdc_put_request(req);
  1735. }
  1736. mutex_unlock(&osdc->request_mutex);
  1737. dout("sync done (thru tid %llu)\n", last_tid);
  1738. }
  1739. EXPORT_SYMBOL(ceph_osdc_sync);
  1740. /*
  1741. * init, shutdown
  1742. */
  1743. int ceph_osdc_init(struct ceph_osd_client *osdc, struct ceph_client *client)
  1744. {
  1745. int err;
  1746. dout("init\n");
  1747. osdc->client = client;
  1748. osdc->osdmap = NULL;
  1749. init_rwsem(&osdc->map_sem);
  1750. init_completion(&osdc->map_waiters);
  1751. osdc->last_requested_map = 0;
  1752. mutex_init(&osdc->request_mutex);
  1753. osdc->last_tid = 0;
  1754. osdc->osds = RB_ROOT;
  1755. INIT_LIST_HEAD(&osdc->osd_lru);
  1756. osdc->requests = RB_ROOT;
  1757. INIT_LIST_HEAD(&osdc->req_lru);
  1758. INIT_LIST_HEAD(&osdc->req_unsent);
  1759. INIT_LIST_HEAD(&osdc->req_notarget);
  1760. INIT_LIST_HEAD(&osdc->req_linger);
  1761. osdc->num_requests = 0;
  1762. INIT_DELAYED_WORK(&osdc->timeout_work, handle_timeout);
  1763. INIT_DELAYED_WORK(&osdc->osds_timeout_work, handle_osds_timeout);
  1764. spin_lock_init(&osdc->event_lock);
  1765. osdc->event_tree = RB_ROOT;
  1766. osdc->event_count = 0;
  1767. schedule_delayed_work(&osdc->osds_timeout_work,
  1768. round_jiffies_relative(osdc->client->options->osd_idle_ttl * HZ));
  1769. err = -ENOMEM;
  1770. osdc->req_mempool = mempool_create_kmalloc_pool(10,
  1771. sizeof(struct ceph_osd_request));
  1772. if (!osdc->req_mempool)
  1773. goto out;
  1774. err = ceph_msgpool_init(&osdc->msgpool_op, CEPH_MSG_OSD_OP,
  1775. OSD_OP_FRONT_LEN, 10, true,
  1776. "osd_op");
  1777. if (err < 0)
  1778. goto out_mempool;
  1779. err = ceph_msgpool_init(&osdc->msgpool_op_reply, CEPH_MSG_OSD_OPREPLY,
  1780. OSD_OPREPLY_FRONT_LEN, 10, true,
  1781. "osd_op_reply");
  1782. if (err < 0)
  1783. goto out_msgpool;
  1784. osdc->notify_wq = create_singlethread_workqueue("ceph-watch-notify");
  1785. if (IS_ERR(osdc->notify_wq)) {
  1786. err = PTR_ERR(osdc->notify_wq);
  1787. osdc->notify_wq = NULL;
  1788. goto out_msgpool;
  1789. }
  1790. return 0;
  1791. out_msgpool:
  1792. ceph_msgpool_destroy(&osdc->msgpool_op);
  1793. out_mempool:
  1794. mempool_destroy(osdc->req_mempool);
  1795. out:
  1796. return err;
  1797. }
  1798. void ceph_osdc_stop(struct ceph_osd_client *osdc)
  1799. {
  1800. flush_workqueue(osdc->notify_wq);
  1801. destroy_workqueue(osdc->notify_wq);
  1802. cancel_delayed_work_sync(&osdc->timeout_work);
  1803. cancel_delayed_work_sync(&osdc->osds_timeout_work);
  1804. if (osdc->osdmap) {
  1805. ceph_osdmap_destroy(osdc->osdmap);
  1806. osdc->osdmap = NULL;
  1807. }
  1808. remove_all_osds(osdc);
  1809. mempool_destroy(osdc->req_mempool);
  1810. ceph_msgpool_destroy(&osdc->msgpool_op);
  1811. ceph_msgpool_destroy(&osdc->msgpool_op_reply);
  1812. }
  1813. /*
  1814. * Read some contiguous pages. If we cross a stripe boundary, shorten
  1815. * *plen. Return number of bytes read, or error.
  1816. */
  1817. int ceph_osdc_readpages(struct ceph_osd_client *osdc,
  1818. struct ceph_vino vino, struct ceph_file_layout *layout,
  1819. u64 off, u64 *plen,
  1820. u32 truncate_seq, u64 truncate_size,
  1821. struct page **pages, int num_pages, int page_align)
  1822. {
  1823. struct ceph_osd_request *req;
  1824. struct ceph_osd_data *osd_data;
  1825. int rc = 0;
  1826. dout("readpages on ino %llx.%llx on %llu~%llu\n", vino.ino,
  1827. vino.snap, off, *plen);
  1828. req = ceph_osdc_new_request(osdc, layout, vino, off, plen,
  1829. CEPH_OSD_OP_READ, CEPH_OSD_FLAG_READ,
  1830. NULL, 0, truncate_seq, truncate_size, NULL,
  1831. false);
  1832. if (IS_ERR(req))
  1833. return PTR_ERR(req);
  1834. /* it may be a short read due to an object boundary */
  1835. osd_data = &req->r_data_in;
  1836. osd_data->type = CEPH_OSD_DATA_TYPE_PAGES;
  1837. osd_data->pages = pages;
  1838. osd_data->length = *plen;
  1839. osd_data->alignment = page_align;
  1840. dout("readpages final extent is %llu~%llu (%llu bytes align %d)\n",
  1841. off, *plen, osd_data->length, page_align);
  1842. rc = ceph_osdc_start_request(osdc, req, false);
  1843. if (!rc)
  1844. rc = ceph_osdc_wait_request(osdc, req);
  1845. ceph_osdc_put_request(req);
  1846. dout("readpages result %d\n", rc);
  1847. return rc;
  1848. }
  1849. EXPORT_SYMBOL(ceph_osdc_readpages);
  1850. /*
  1851. * do a synchronous write on N pages
  1852. */
  1853. int ceph_osdc_writepages(struct ceph_osd_client *osdc, struct ceph_vino vino,
  1854. struct ceph_file_layout *layout,
  1855. struct ceph_snap_context *snapc,
  1856. u64 off, u64 len,
  1857. u32 truncate_seq, u64 truncate_size,
  1858. struct timespec *mtime,
  1859. struct page **pages, int num_pages)
  1860. {
  1861. struct ceph_osd_request *req;
  1862. struct ceph_osd_data *osd_data;
  1863. int rc = 0;
  1864. int page_align = off & ~PAGE_MASK;
  1865. BUG_ON(vino.snap != CEPH_NOSNAP);
  1866. req = ceph_osdc_new_request(osdc, layout, vino, off, &len,
  1867. CEPH_OSD_OP_WRITE,
  1868. CEPH_OSD_FLAG_ONDISK | CEPH_OSD_FLAG_WRITE,
  1869. snapc, 0,
  1870. truncate_seq, truncate_size, mtime,
  1871. true);
  1872. if (IS_ERR(req))
  1873. return PTR_ERR(req);
  1874. /* it may be a short write due to an object boundary */
  1875. osd_data = &req->r_data_out;
  1876. osd_data->type = CEPH_OSD_DATA_TYPE_PAGES;
  1877. osd_data->pages = pages;
  1878. osd_data->length = len;
  1879. osd_data->alignment = page_align;
  1880. dout("writepages %llu~%llu (%llu bytes)\n", off, len, osd_data->length);
  1881. rc = ceph_osdc_start_request(osdc, req, true);
  1882. if (!rc)
  1883. rc = ceph_osdc_wait_request(osdc, req);
  1884. ceph_osdc_put_request(req);
  1885. if (rc == 0)
  1886. rc = len;
  1887. dout("writepages result %d\n", rc);
  1888. return rc;
  1889. }
  1890. EXPORT_SYMBOL(ceph_osdc_writepages);
  1891. /*
  1892. * handle incoming message
  1893. */
  1894. static void dispatch(struct ceph_connection *con, struct ceph_msg *msg)
  1895. {
  1896. struct ceph_osd *osd = con->private;
  1897. struct ceph_osd_client *osdc;
  1898. int type = le16_to_cpu(msg->hdr.type);
  1899. if (!osd)
  1900. goto out;
  1901. osdc = osd->o_osdc;
  1902. switch (type) {
  1903. case CEPH_MSG_OSD_MAP:
  1904. ceph_osdc_handle_map(osdc, msg);
  1905. break;
  1906. case CEPH_MSG_OSD_OPREPLY:
  1907. handle_reply(osdc, msg, con);
  1908. break;
  1909. case CEPH_MSG_WATCH_NOTIFY:
  1910. handle_watch_notify(osdc, msg);
  1911. break;
  1912. default:
  1913. pr_err("received unknown message type %d %s\n", type,
  1914. ceph_msg_type_name(type));
  1915. }
  1916. out:
  1917. ceph_msg_put(msg);
  1918. }
  1919. /*
  1920. * lookup and return message for incoming reply. set up reply message
  1921. * pages.
  1922. */
  1923. static struct ceph_msg *get_reply(struct ceph_connection *con,
  1924. struct ceph_msg_header *hdr,
  1925. int *skip)
  1926. {
  1927. struct ceph_osd *osd = con->private;
  1928. struct ceph_osd_client *osdc = osd->o_osdc;
  1929. struct ceph_msg *m;
  1930. struct ceph_osd_request *req;
  1931. int front = le32_to_cpu(hdr->front_len);
  1932. int data_len = le32_to_cpu(hdr->data_len);
  1933. u64 tid;
  1934. tid = le64_to_cpu(hdr->tid);
  1935. mutex_lock(&osdc->request_mutex);
  1936. req = __lookup_request(osdc, tid);
  1937. if (!req) {
  1938. *skip = 1;
  1939. m = NULL;
  1940. dout("get_reply unknown tid %llu from osd%d\n", tid,
  1941. osd->o_osd);
  1942. goto out;
  1943. }
  1944. if (req->r_con_filling_msg) {
  1945. dout("%s revoking msg %p from old con %p\n", __func__,
  1946. req->r_reply, req->r_con_filling_msg);
  1947. ceph_msg_revoke_incoming(req->r_reply);
  1948. req->r_con_filling_msg->ops->put(req->r_con_filling_msg);
  1949. req->r_con_filling_msg = NULL;
  1950. }
  1951. if (front > req->r_reply->front.iov_len) {
  1952. pr_warning("get_reply front %d > preallocated %d\n",
  1953. front, (int)req->r_reply->front.iov_len);
  1954. m = ceph_msg_new(CEPH_MSG_OSD_OPREPLY, front, GFP_NOFS, false);
  1955. if (!m)
  1956. goto out;
  1957. ceph_msg_put(req->r_reply);
  1958. req->r_reply = m;
  1959. }
  1960. m = ceph_msg_get(req->r_reply);
  1961. if (data_len > 0) {
  1962. struct ceph_osd_data *osd_data = &req->r_data_in;
  1963. if (osd_data->type == CEPH_OSD_DATA_TYPE_PAGES) {
  1964. if (osd_data->pages &&
  1965. unlikely(osd_data->length < data_len)) {
  1966. pr_warning("tid %lld reply has %d bytes "
  1967. "we had only %llu bytes ready\n",
  1968. tid, data_len, osd_data->length);
  1969. *skip = 1;
  1970. ceph_msg_put(m);
  1971. m = NULL;
  1972. goto out;
  1973. }
  1974. }
  1975. }
  1976. *skip = 0;
  1977. req->r_con_filling_msg = con->ops->get(con);
  1978. dout("get_reply tid %lld %p\n", tid, m);
  1979. out:
  1980. mutex_unlock(&osdc->request_mutex);
  1981. return m;
  1982. }
  1983. static struct ceph_msg *alloc_msg(struct ceph_connection *con,
  1984. struct ceph_msg_header *hdr,
  1985. int *skip)
  1986. {
  1987. struct ceph_osd *osd = con->private;
  1988. int type = le16_to_cpu(hdr->type);
  1989. int front = le32_to_cpu(hdr->front_len);
  1990. *skip = 0;
  1991. switch (type) {
  1992. case CEPH_MSG_OSD_MAP:
  1993. case CEPH_MSG_WATCH_NOTIFY:
  1994. return ceph_msg_new(type, front, GFP_NOFS, false);
  1995. case CEPH_MSG_OSD_OPREPLY:
  1996. return get_reply(con, hdr, skip);
  1997. default:
  1998. pr_info("alloc_msg unexpected msg type %d from osd%d\n", type,
  1999. osd->o_osd);
  2000. *skip = 1;
  2001. return NULL;
  2002. }
  2003. }
  2004. /*
  2005. * Wrappers to refcount containing ceph_osd struct
  2006. */
  2007. static struct ceph_connection *get_osd_con(struct ceph_connection *con)
  2008. {
  2009. struct ceph_osd *osd = con->private;
  2010. if (get_osd(osd))
  2011. return con;
  2012. return NULL;
  2013. }
  2014. static void put_osd_con(struct ceph_connection *con)
  2015. {
  2016. struct ceph_osd *osd = con->private;
  2017. put_osd(osd);
  2018. }
  2019. /*
  2020. * authentication
  2021. */
  2022. /*
  2023. * Note: returned pointer is the address of a structure that's
  2024. * managed separately. Caller must *not* attempt to free it.
  2025. */
  2026. static struct ceph_auth_handshake *get_authorizer(struct ceph_connection *con,
  2027. int *proto, int force_new)
  2028. {
  2029. struct ceph_osd *o = con->private;
  2030. struct ceph_osd_client *osdc = o->o_osdc;
  2031. struct ceph_auth_client *ac = osdc->client->monc.auth;
  2032. struct ceph_auth_handshake *auth = &o->o_auth;
  2033. if (force_new && auth->authorizer) {
  2034. ceph_auth_destroy_authorizer(ac, auth->authorizer);
  2035. auth->authorizer = NULL;
  2036. }
  2037. if (!auth->authorizer) {
  2038. int ret = ceph_auth_create_authorizer(ac, CEPH_ENTITY_TYPE_OSD,
  2039. auth);
  2040. if (ret)
  2041. return ERR_PTR(ret);
  2042. } else {
  2043. int ret = ceph_auth_update_authorizer(ac, CEPH_ENTITY_TYPE_OSD,
  2044. auth);
  2045. if (ret)
  2046. return ERR_PTR(ret);
  2047. }
  2048. *proto = ac->protocol;
  2049. return auth;
  2050. }
  2051. static int verify_authorizer_reply(struct ceph_connection *con, int len)
  2052. {
  2053. struct ceph_osd *o = con->private;
  2054. struct ceph_osd_client *osdc = o->o_osdc;
  2055. struct ceph_auth_client *ac = osdc->client->monc.auth;
  2056. return ceph_auth_verify_authorizer_reply(ac, o->o_auth.authorizer, len);
  2057. }
  2058. static int invalidate_authorizer(struct ceph_connection *con)
  2059. {
  2060. struct ceph_osd *o = con->private;
  2061. struct ceph_osd_client *osdc = o->o_osdc;
  2062. struct ceph_auth_client *ac = osdc->client->monc.auth;
  2063. ceph_auth_invalidate_authorizer(ac, CEPH_ENTITY_TYPE_OSD);
  2064. return ceph_monc_validate_auth(&osdc->client->monc);
  2065. }
  2066. static const struct ceph_connection_operations osd_con_ops = {
  2067. .get = get_osd_con,
  2068. .put = put_osd_con,
  2069. .dispatch = dispatch,
  2070. .get_authorizer = get_authorizer,
  2071. .verify_authorizer_reply = verify_authorizer_reply,
  2072. .invalidate_authorizer = invalidate_authorizer,
  2073. .alloc_msg = alloc_msg,
  2074. .fault = osd_reset,
  2075. };