osd_client.c 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378
  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. memset(&ops, 0, sizeof ops);
  512. ops[0].op = opcode;
  513. ops[0].extent.offset = objoff;
  514. ops[0].extent.length = objlen;
  515. ops[0].extent.truncate_size = truncate_size;
  516. ops[0].extent.truncate_seq = truncate_seq;
  517. if (ops[0].op == CEPH_OSD_OP_WRITE)
  518. ops[0].payload_len = *plen;
  519. if (do_sync)
  520. ops[1].op = CEPH_OSD_OP_STARTSYNC;
  521. req->r_file_layout = *layout; /* keep a copy */
  522. snprintf(req->r_oid, sizeof(req->r_oid), "%llx.%08llx",
  523. vino.ino, objnum);
  524. req->r_oid_len = strlen(req->r_oid);
  525. ceph_osdc_build_request(req, off, num_op, ops,
  526. snapc, vino.snap, mtime);
  527. return req;
  528. }
  529. EXPORT_SYMBOL(ceph_osdc_new_request);
  530. /*
  531. * We keep osd requests in an rbtree, sorted by ->r_tid.
  532. */
  533. static void __insert_request(struct ceph_osd_client *osdc,
  534. struct ceph_osd_request *new)
  535. {
  536. struct rb_node **p = &osdc->requests.rb_node;
  537. struct rb_node *parent = NULL;
  538. struct ceph_osd_request *req = NULL;
  539. while (*p) {
  540. parent = *p;
  541. req = rb_entry(parent, struct ceph_osd_request, r_node);
  542. if (new->r_tid < req->r_tid)
  543. p = &(*p)->rb_left;
  544. else if (new->r_tid > req->r_tid)
  545. p = &(*p)->rb_right;
  546. else
  547. BUG();
  548. }
  549. rb_link_node(&new->r_node, parent, p);
  550. rb_insert_color(&new->r_node, &osdc->requests);
  551. }
  552. static struct ceph_osd_request *__lookup_request(struct ceph_osd_client *osdc,
  553. u64 tid)
  554. {
  555. struct ceph_osd_request *req;
  556. struct rb_node *n = osdc->requests.rb_node;
  557. while (n) {
  558. req = rb_entry(n, struct ceph_osd_request, r_node);
  559. if (tid < req->r_tid)
  560. n = n->rb_left;
  561. else if (tid > req->r_tid)
  562. n = n->rb_right;
  563. else
  564. return req;
  565. }
  566. return NULL;
  567. }
  568. static struct ceph_osd_request *
  569. __lookup_request_ge(struct ceph_osd_client *osdc,
  570. u64 tid)
  571. {
  572. struct ceph_osd_request *req;
  573. struct rb_node *n = osdc->requests.rb_node;
  574. while (n) {
  575. req = rb_entry(n, struct ceph_osd_request, r_node);
  576. if (tid < req->r_tid) {
  577. if (!n->rb_left)
  578. return req;
  579. n = n->rb_left;
  580. } else if (tid > req->r_tid) {
  581. n = n->rb_right;
  582. } else {
  583. return req;
  584. }
  585. }
  586. return NULL;
  587. }
  588. /*
  589. * Resubmit requests pending on the given osd.
  590. */
  591. static void __kick_osd_requests(struct ceph_osd_client *osdc,
  592. struct ceph_osd *osd)
  593. {
  594. struct ceph_osd_request *req, *nreq;
  595. LIST_HEAD(resend);
  596. int err;
  597. dout("__kick_osd_requests osd%d\n", osd->o_osd);
  598. err = __reset_osd(osdc, osd);
  599. if (err)
  600. return;
  601. /*
  602. * Build up a list of requests to resend by traversing the
  603. * osd's list of requests. Requests for a given object are
  604. * sent in tid order, and that is also the order they're
  605. * kept on this list. Therefore all requests that are in
  606. * flight will be found first, followed by all requests that
  607. * have not yet been sent. And to resend requests while
  608. * preserving this order we will want to put any sent
  609. * requests back on the front of the osd client's unsent
  610. * list.
  611. *
  612. * So we build a separate ordered list of already-sent
  613. * requests for the affected osd and splice it onto the
  614. * front of the osd client's unsent list. Once we've seen a
  615. * request that has not yet been sent we're done. Those
  616. * requests are already sitting right where they belong.
  617. */
  618. list_for_each_entry(req, &osd->o_requests, r_osd_item) {
  619. if (!req->r_sent)
  620. break;
  621. list_move_tail(&req->r_req_lru_item, &resend);
  622. dout("requeueing %p tid %llu osd%d\n", req, req->r_tid,
  623. osd->o_osd);
  624. if (!req->r_linger)
  625. req->r_flags |= CEPH_OSD_FLAG_RETRY;
  626. }
  627. list_splice(&resend, &osdc->req_unsent);
  628. /*
  629. * Linger requests are re-registered before sending, which
  630. * sets up a new tid for each. We add them to the unsent
  631. * list at the end to keep things in tid order.
  632. */
  633. list_for_each_entry_safe(req, nreq, &osd->o_linger_requests,
  634. r_linger_osd) {
  635. /*
  636. * reregister request prior to unregistering linger so
  637. * that r_osd is preserved.
  638. */
  639. BUG_ON(!list_empty(&req->r_req_lru_item));
  640. __register_request(osdc, req);
  641. list_add_tail(&req->r_req_lru_item, &osdc->req_unsent);
  642. list_add_tail(&req->r_osd_item, &req->r_osd->o_requests);
  643. __unregister_linger_request(osdc, req);
  644. dout("requeued lingering %p tid %llu osd%d\n", req, req->r_tid,
  645. osd->o_osd);
  646. }
  647. }
  648. /*
  649. * If the osd connection drops, we need to resubmit all requests.
  650. */
  651. static void osd_reset(struct ceph_connection *con)
  652. {
  653. struct ceph_osd *osd = con->private;
  654. struct ceph_osd_client *osdc;
  655. if (!osd)
  656. return;
  657. dout("osd_reset osd%d\n", osd->o_osd);
  658. osdc = osd->o_osdc;
  659. down_read(&osdc->map_sem);
  660. mutex_lock(&osdc->request_mutex);
  661. __kick_osd_requests(osdc, osd);
  662. __send_queued(osdc);
  663. mutex_unlock(&osdc->request_mutex);
  664. up_read(&osdc->map_sem);
  665. }
  666. /*
  667. * Track open sessions with osds.
  668. */
  669. static struct ceph_osd *create_osd(struct ceph_osd_client *osdc, int onum)
  670. {
  671. struct ceph_osd *osd;
  672. osd = kzalloc(sizeof(*osd), GFP_NOFS);
  673. if (!osd)
  674. return NULL;
  675. atomic_set(&osd->o_ref, 1);
  676. osd->o_osdc = osdc;
  677. osd->o_osd = onum;
  678. RB_CLEAR_NODE(&osd->o_node);
  679. INIT_LIST_HEAD(&osd->o_requests);
  680. INIT_LIST_HEAD(&osd->o_linger_requests);
  681. INIT_LIST_HEAD(&osd->o_osd_lru);
  682. osd->o_incarnation = 1;
  683. ceph_con_init(&osd->o_con, osd, &osd_con_ops, &osdc->client->msgr);
  684. INIT_LIST_HEAD(&osd->o_keepalive_item);
  685. return osd;
  686. }
  687. static struct ceph_osd *get_osd(struct ceph_osd *osd)
  688. {
  689. if (atomic_inc_not_zero(&osd->o_ref)) {
  690. dout("get_osd %p %d -> %d\n", osd, atomic_read(&osd->o_ref)-1,
  691. atomic_read(&osd->o_ref));
  692. return osd;
  693. } else {
  694. dout("get_osd %p FAIL\n", osd);
  695. return NULL;
  696. }
  697. }
  698. static void put_osd(struct ceph_osd *osd)
  699. {
  700. dout("put_osd %p %d -> %d\n", osd, atomic_read(&osd->o_ref),
  701. atomic_read(&osd->o_ref) - 1);
  702. if (atomic_dec_and_test(&osd->o_ref) && osd->o_auth.authorizer) {
  703. struct ceph_auth_client *ac = osd->o_osdc->client->monc.auth;
  704. ceph_auth_destroy_authorizer(ac, osd->o_auth.authorizer);
  705. kfree(osd);
  706. }
  707. }
  708. /*
  709. * remove an osd from our map
  710. */
  711. static void __remove_osd(struct ceph_osd_client *osdc, struct ceph_osd *osd)
  712. {
  713. dout("__remove_osd %p\n", osd);
  714. BUG_ON(!list_empty(&osd->o_requests));
  715. rb_erase(&osd->o_node, &osdc->osds);
  716. list_del_init(&osd->o_osd_lru);
  717. ceph_con_close(&osd->o_con);
  718. put_osd(osd);
  719. }
  720. static void remove_all_osds(struct ceph_osd_client *osdc)
  721. {
  722. dout("%s %p\n", __func__, osdc);
  723. mutex_lock(&osdc->request_mutex);
  724. while (!RB_EMPTY_ROOT(&osdc->osds)) {
  725. struct ceph_osd *osd = rb_entry(rb_first(&osdc->osds),
  726. struct ceph_osd, o_node);
  727. __remove_osd(osdc, osd);
  728. }
  729. mutex_unlock(&osdc->request_mutex);
  730. }
  731. static void __move_osd_to_lru(struct ceph_osd_client *osdc,
  732. struct ceph_osd *osd)
  733. {
  734. dout("__move_osd_to_lru %p\n", osd);
  735. BUG_ON(!list_empty(&osd->o_osd_lru));
  736. list_add_tail(&osd->o_osd_lru, &osdc->osd_lru);
  737. osd->lru_ttl = jiffies + osdc->client->options->osd_idle_ttl * HZ;
  738. }
  739. static void __remove_osd_from_lru(struct ceph_osd *osd)
  740. {
  741. dout("__remove_osd_from_lru %p\n", osd);
  742. if (!list_empty(&osd->o_osd_lru))
  743. list_del_init(&osd->o_osd_lru);
  744. }
  745. static void remove_old_osds(struct ceph_osd_client *osdc)
  746. {
  747. struct ceph_osd *osd, *nosd;
  748. dout("__remove_old_osds %p\n", osdc);
  749. mutex_lock(&osdc->request_mutex);
  750. list_for_each_entry_safe(osd, nosd, &osdc->osd_lru, o_osd_lru) {
  751. if (time_before(jiffies, osd->lru_ttl))
  752. break;
  753. __remove_osd(osdc, osd);
  754. }
  755. mutex_unlock(&osdc->request_mutex);
  756. }
  757. /*
  758. * reset osd connect
  759. */
  760. static int __reset_osd(struct ceph_osd_client *osdc, struct ceph_osd *osd)
  761. {
  762. struct ceph_entity_addr *peer_addr;
  763. dout("__reset_osd %p osd%d\n", osd, osd->o_osd);
  764. if (list_empty(&osd->o_requests) &&
  765. list_empty(&osd->o_linger_requests)) {
  766. __remove_osd(osdc, osd);
  767. return -ENODEV;
  768. }
  769. peer_addr = &osdc->osdmap->osd_addr[osd->o_osd];
  770. if (!memcmp(peer_addr, &osd->o_con.peer_addr, sizeof (*peer_addr)) &&
  771. !ceph_con_opened(&osd->o_con)) {
  772. struct ceph_osd_request *req;
  773. dout(" osd addr hasn't changed and connection never opened,"
  774. " letting msgr retry");
  775. /* touch each r_stamp for handle_timeout()'s benfit */
  776. list_for_each_entry(req, &osd->o_requests, r_osd_item)
  777. req->r_stamp = jiffies;
  778. return -EAGAIN;
  779. }
  780. ceph_con_close(&osd->o_con);
  781. ceph_con_open(&osd->o_con, CEPH_ENTITY_TYPE_OSD, osd->o_osd, peer_addr);
  782. osd->o_incarnation++;
  783. return 0;
  784. }
  785. static void __insert_osd(struct ceph_osd_client *osdc, struct ceph_osd *new)
  786. {
  787. struct rb_node **p = &osdc->osds.rb_node;
  788. struct rb_node *parent = NULL;
  789. struct ceph_osd *osd = NULL;
  790. dout("__insert_osd %p osd%d\n", new, new->o_osd);
  791. while (*p) {
  792. parent = *p;
  793. osd = rb_entry(parent, struct ceph_osd, o_node);
  794. if (new->o_osd < osd->o_osd)
  795. p = &(*p)->rb_left;
  796. else if (new->o_osd > osd->o_osd)
  797. p = &(*p)->rb_right;
  798. else
  799. BUG();
  800. }
  801. rb_link_node(&new->o_node, parent, p);
  802. rb_insert_color(&new->o_node, &osdc->osds);
  803. }
  804. static struct ceph_osd *__lookup_osd(struct ceph_osd_client *osdc, int o)
  805. {
  806. struct ceph_osd *osd;
  807. struct rb_node *n = osdc->osds.rb_node;
  808. while (n) {
  809. osd = rb_entry(n, struct ceph_osd, o_node);
  810. if (o < osd->o_osd)
  811. n = n->rb_left;
  812. else if (o > osd->o_osd)
  813. n = n->rb_right;
  814. else
  815. return osd;
  816. }
  817. return NULL;
  818. }
  819. static void __schedule_osd_timeout(struct ceph_osd_client *osdc)
  820. {
  821. schedule_delayed_work(&osdc->timeout_work,
  822. osdc->client->options->osd_keepalive_timeout * HZ);
  823. }
  824. static void __cancel_osd_timeout(struct ceph_osd_client *osdc)
  825. {
  826. cancel_delayed_work(&osdc->timeout_work);
  827. }
  828. /*
  829. * Register request, assign tid. If this is the first request, set up
  830. * the timeout event.
  831. */
  832. static void __register_request(struct ceph_osd_client *osdc,
  833. struct ceph_osd_request *req)
  834. {
  835. req->r_tid = ++osdc->last_tid;
  836. req->r_request->hdr.tid = cpu_to_le64(req->r_tid);
  837. dout("__register_request %p tid %lld\n", req, req->r_tid);
  838. __insert_request(osdc, req);
  839. ceph_osdc_get_request(req);
  840. osdc->num_requests++;
  841. if (osdc->num_requests == 1) {
  842. dout(" first request, scheduling timeout\n");
  843. __schedule_osd_timeout(osdc);
  844. }
  845. }
  846. /*
  847. * called under osdc->request_mutex
  848. */
  849. static void __unregister_request(struct ceph_osd_client *osdc,
  850. struct ceph_osd_request *req)
  851. {
  852. if (RB_EMPTY_NODE(&req->r_node)) {
  853. dout("__unregister_request %p tid %lld not registered\n",
  854. req, req->r_tid);
  855. return;
  856. }
  857. dout("__unregister_request %p tid %lld\n", req, req->r_tid);
  858. rb_erase(&req->r_node, &osdc->requests);
  859. osdc->num_requests--;
  860. if (req->r_osd) {
  861. /* make sure the original request isn't in flight. */
  862. ceph_msg_revoke(req->r_request);
  863. list_del_init(&req->r_osd_item);
  864. if (list_empty(&req->r_osd->o_requests) &&
  865. list_empty(&req->r_osd->o_linger_requests)) {
  866. dout("moving osd to %p lru\n", req->r_osd);
  867. __move_osd_to_lru(osdc, req->r_osd);
  868. }
  869. if (list_empty(&req->r_linger_item))
  870. req->r_osd = NULL;
  871. }
  872. list_del_init(&req->r_req_lru_item);
  873. ceph_osdc_put_request(req);
  874. if (osdc->num_requests == 0) {
  875. dout(" no requests, canceling timeout\n");
  876. __cancel_osd_timeout(osdc);
  877. }
  878. }
  879. /*
  880. * Cancel a previously queued request message
  881. */
  882. static void __cancel_request(struct ceph_osd_request *req)
  883. {
  884. if (req->r_sent && req->r_osd) {
  885. ceph_msg_revoke(req->r_request);
  886. req->r_sent = 0;
  887. }
  888. }
  889. static void __register_linger_request(struct ceph_osd_client *osdc,
  890. struct ceph_osd_request *req)
  891. {
  892. dout("__register_linger_request %p\n", req);
  893. list_add_tail(&req->r_linger_item, &osdc->req_linger);
  894. if (req->r_osd)
  895. list_add_tail(&req->r_linger_osd,
  896. &req->r_osd->o_linger_requests);
  897. }
  898. static void __unregister_linger_request(struct ceph_osd_client *osdc,
  899. struct ceph_osd_request *req)
  900. {
  901. dout("__unregister_linger_request %p\n", req);
  902. list_del_init(&req->r_linger_item);
  903. if (req->r_osd) {
  904. list_del_init(&req->r_linger_osd);
  905. if (list_empty(&req->r_osd->o_requests) &&
  906. list_empty(&req->r_osd->o_linger_requests)) {
  907. dout("moving osd to %p lru\n", req->r_osd);
  908. __move_osd_to_lru(osdc, req->r_osd);
  909. }
  910. if (list_empty(&req->r_osd_item))
  911. req->r_osd = NULL;
  912. }
  913. }
  914. void ceph_osdc_unregister_linger_request(struct ceph_osd_client *osdc,
  915. struct ceph_osd_request *req)
  916. {
  917. mutex_lock(&osdc->request_mutex);
  918. if (req->r_linger) {
  919. __unregister_linger_request(osdc, req);
  920. ceph_osdc_put_request(req);
  921. }
  922. mutex_unlock(&osdc->request_mutex);
  923. }
  924. EXPORT_SYMBOL(ceph_osdc_unregister_linger_request);
  925. void ceph_osdc_set_request_linger(struct ceph_osd_client *osdc,
  926. struct ceph_osd_request *req)
  927. {
  928. if (!req->r_linger) {
  929. dout("set_request_linger %p\n", req);
  930. req->r_linger = 1;
  931. /*
  932. * caller is now responsible for calling
  933. * unregister_linger_request
  934. */
  935. ceph_osdc_get_request(req);
  936. }
  937. }
  938. EXPORT_SYMBOL(ceph_osdc_set_request_linger);
  939. /*
  940. * Pick an osd (the first 'up' osd in the pg), allocate the osd struct
  941. * (as needed), and set the request r_osd appropriately. If there is
  942. * no up osd, set r_osd to NULL. Move the request to the appropriate list
  943. * (unsent, homeless) or leave on in-flight lru.
  944. *
  945. * Return 0 if unchanged, 1 if changed, or negative on error.
  946. *
  947. * Caller should hold map_sem for read and request_mutex.
  948. */
  949. static int __map_request(struct ceph_osd_client *osdc,
  950. struct ceph_osd_request *req, int force_resend)
  951. {
  952. struct ceph_pg pgid;
  953. int acting[CEPH_PG_MAX_SIZE];
  954. int o = -1, num = 0;
  955. int err;
  956. dout("map_request %p tid %lld\n", req, req->r_tid);
  957. err = ceph_calc_ceph_pg(&pgid, req->r_oid, osdc->osdmap,
  958. ceph_file_layout_pg_pool(req->r_file_layout));
  959. if (err) {
  960. list_move(&req->r_req_lru_item, &osdc->req_notarget);
  961. return err;
  962. }
  963. req->r_pgid = pgid;
  964. err = ceph_calc_pg_acting(osdc->osdmap, pgid, acting);
  965. if (err > 0) {
  966. o = acting[0];
  967. num = err;
  968. }
  969. if ((!force_resend &&
  970. req->r_osd && req->r_osd->o_osd == o &&
  971. req->r_sent >= req->r_osd->o_incarnation &&
  972. req->r_num_pg_osds == num &&
  973. memcmp(req->r_pg_osds, acting, sizeof(acting[0])*num) == 0) ||
  974. (req->r_osd == NULL && o == -1))
  975. return 0; /* no change */
  976. dout("map_request tid %llu pgid %lld.%x osd%d (was osd%d)\n",
  977. req->r_tid, pgid.pool, pgid.seed, o,
  978. req->r_osd ? req->r_osd->o_osd : -1);
  979. /* record full pg acting set */
  980. memcpy(req->r_pg_osds, acting, sizeof(acting[0]) * num);
  981. req->r_num_pg_osds = num;
  982. if (req->r_osd) {
  983. __cancel_request(req);
  984. list_del_init(&req->r_osd_item);
  985. req->r_osd = NULL;
  986. }
  987. req->r_osd = __lookup_osd(osdc, o);
  988. if (!req->r_osd && o >= 0) {
  989. err = -ENOMEM;
  990. req->r_osd = create_osd(osdc, o);
  991. if (!req->r_osd) {
  992. list_move(&req->r_req_lru_item, &osdc->req_notarget);
  993. goto out;
  994. }
  995. dout("map_request osd %p is osd%d\n", req->r_osd, o);
  996. __insert_osd(osdc, req->r_osd);
  997. ceph_con_open(&req->r_osd->o_con,
  998. CEPH_ENTITY_TYPE_OSD, o,
  999. &osdc->osdmap->osd_addr[o]);
  1000. }
  1001. if (req->r_osd) {
  1002. __remove_osd_from_lru(req->r_osd);
  1003. list_add_tail(&req->r_osd_item, &req->r_osd->o_requests);
  1004. list_move_tail(&req->r_req_lru_item, &osdc->req_unsent);
  1005. } else {
  1006. list_move_tail(&req->r_req_lru_item, &osdc->req_notarget);
  1007. }
  1008. err = 1; /* osd or pg changed */
  1009. out:
  1010. return err;
  1011. }
  1012. /*
  1013. * caller should hold map_sem (for read) and request_mutex
  1014. */
  1015. static void __send_request(struct ceph_osd_client *osdc,
  1016. struct ceph_osd_request *req)
  1017. {
  1018. void *p;
  1019. dout("send_request %p tid %llu to osd%d flags %d pg %lld.%x\n",
  1020. req, req->r_tid, req->r_osd->o_osd, req->r_flags,
  1021. (unsigned long long)req->r_pgid.pool, req->r_pgid.seed);
  1022. /* fill in message content that changes each time we send it */
  1023. put_unaligned_le32(osdc->osdmap->epoch, req->r_request_osdmap_epoch);
  1024. put_unaligned_le32(req->r_flags, req->r_request_flags);
  1025. put_unaligned_le64(req->r_pgid.pool, req->r_request_pool);
  1026. p = req->r_request_pgid;
  1027. ceph_encode_64(&p, req->r_pgid.pool);
  1028. ceph_encode_32(&p, req->r_pgid.seed);
  1029. put_unaligned_le64(1, req->r_request_attempts); /* FIXME */
  1030. memcpy(req->r_request_reassert_version, &req->r_reassert_version,
  1031. sizeof(req->r_reassert_version));
  1032. req->r_stamp = jiffies;
  1033. list_move_tail(&req->r_req_lru_item, &osdc->req_lru);
  1034. ceph_msg_get(req->r_request); /* send consumes a ref */
  1035. ceph_con_send(&req->r_osd->o_con, req->r_request);
  1036. req->r_sent = req->r_osd->o_incarnation;
  1037. }
  1038. /*
  1039. * Send any requests in the queue (req_unsent).
  1040. */
  1041. static void __send_queued(struct ceph_osd_client *osdc)
  1042. {
  1043. struct ceph_osd_request *req, *tmp;
  1044. dout("__send_queued\n");
  1045. list_for_each_entry_safe(req, tmp, &osdc->req_unsent, r_req_lru_item)
  1046. __send_request(osdc, req);
  1047. }
  1048. /*
  1049. * Timeout callback, called every N seconds when 1 or more osd
  1050. * requests has been active for more than N seconds. When this
  1051. * happens, we ping all OSDs with requests who have timed out to
  1052. * ensure any communications channel reset is detected. Reset the
  1053. * request timeouts another N seconds in the future as we go.
  1054. * Reschedule the timeout event another N seconds in future (unless
  1055. * there are no open requests).
  1056. */
  1057. static void handle_timeout(struct work_struct *work)
  1058. {
  1059. struct ceph_osd_client *osdc =
  1060. container_of(work, struct ceph_osd_client, timeout_work.work);
  1061. struct ceph_osd_request *req;
  1062. struct ceph_osd *osd;
  1063. unsigned long keepalive =
  1064. osdc->client->options->osd_keepalive_timeout * HZ;
  1065. struct list_head slow_osds;
  1066. dout("timeout\n");
  1067. down_read(&osdc->map_sem);
  1068. ceph_monc_request_next_osdmap(&osdc->client->monc);
  1069. mutex_lock(&osdc->request_mutex);
  1070. /*
  1071. * ping osds that are a bit slow. this ensures that if there
  1072. * is a break in the TCP connection we will notice, and reopen
  1073. * a connection with that osd (from the fault callback).
  1074. */
  1075. INIT_LIST_HEAD(&slow_osds);
  1076. list_for_each_entry(req, &osdc->req_lru, r_req_lru_item) {
  1077. if (time_before(jiffies, req->r_stamp + keepalive))
  1078. break;
  1079. osd = req->r_osd;
  1080. BUG_ON(!osd);
  1081. dout(" tid %llu is slow, will send keepalive on osd%d\n",
  1082. req->r_tid, osd->o_osd);
  1083. list_move_tail(&osd->o_keepalive_item, &slow_osds);
  1084. }
  1085. while (!list_empty(&slow_osds)) {
  1086. osd = list_entry(slow_osds.next, struct ceph_osd,
  1087. o_keepalive_item);
  1088. list_del_init(&osd->o_keepalive_item);
  1089. ceph_con_keepalive(&osd->o_con);
  1090. }
  1091. __schedule_osd_timeout(osdc);
  1092. __send_queued(osdc);
  1093. mutex_unlock(&osdc->request_mutex);
  1094. up_read(&osdc->map_sem);
  1095. }
  1096. static void handle_osds_timeout(struct work_struct *work)
  1097. {
  1098. struct ceph_osd_client *osdc =
  1099. container_of(work, struct ceph_osd_client,
  1100. osds_timeout_work.work);
  1101. unsigned long delay =
  1102. osdc->client->options->osd_idle_ttl * HZ >> 2;
  1103. dout("osds timeout\n");
  1104. down_read(&osdc->map_sem);
  1105. remove_old_osds(osdc);
  1106. up_read(&osdc->map_sem);
  1107. schedule_delayed_work(&osdc->osds_timeout_work,
  1108. round_jiffies_relative(delay));
  1109. }
  1110. static void complete_request(struct ceph_osd_request *req)
  1111. {
  1112. if (req->r_safe_callback)
  1113. req->r_safe_callback(req, NULL);
  1114. complete_all(&req->r_safe_completion); /* fsync waiter */
  1115. }
  1116. static int __decode_pgid(void **p, void *end, struct ceph_pg *pgid)
  1117. {
  1118. __u8 v;
  1119. ceph_decode_need(p, end, 1 + 8 + 4 + 4, bad);
  1120. v = ceph_decode_8(p);
  1121. if (v > 1) {
  1122. pr_warning("do not understand pg encoding %d > 1", v);
  1123. return -EINVAL;
  1124. }
  1125. pgid->pool = ceph_decode_64(p);
  1126. pgid->seed = ceph_decode_32(p);
  1127. *p += 4;
  1128. return 0;
  1129. bad:
  1130. pr_warning("incomplete pg encoding");
  1131. return -EINVAL;
  1132. }
  1133. /*
  1134. * handle osd op reply. either call the callback if it is specified,
  1135. * or do the completion to wake up the waiting thread.
  1136. */
  1137. static void handle_reply(struct ceph_osd_client *osdc, struct ceph_msg *msg,
  1138. struct ceph_connection *con)
  1139. {
  1140. void *p, *end;
  1141. struct ceph_osd_request *req;
  1142. u64 tid;
  1143. int object_len;
  1144. int numops, payload_len, flags;
  1145. s32 result;
  1146. s32 retry_attempt;
  1147. struct ceph_pg pg;
  1148. int err;
  1149. u32 reassert_epoch;
  1150. u64 reassert_version;
  1151. u32 osdmap_epoch;
  1152. int already_completed;
  1153. int i;
  1154. tid = le64_to_cpu(msg->hdr.tid);
  1155. dout("handle_reply %p tid %llu\n", msg, tid);
  1156. p = msg->front.iov_base;
  1157. end = p + msg->front.iov_len;
  1158. ceph_decode_need(&p, end, 4, bad);
  1159. object_len = ceph_decode_32(&p);
  1160. ceph_decode_need(&p, end, object_len, bad);
  1161. p += object_len;
  1162. err = __decode_pgid(&p, end, &pg);
  1163. if (err)
  1164. goto bad;
  1165. ceph_decode_need(&p, end, 8 + 4 + 4 + 8 + 4, bad);
  1166. flags = ceph_decode_64(&p);
  1167. result = ceph_decode_32(&p);
  1168. reassert_epoch = ceph_decode_32(&p);
  1169. reassert_version = ceph_decode_64(&p);
  1170. osdmap_epoch = ceph_decode_32(&p);
  1171. /* lookup */
  1172. mutex_lock(&osdc->request_mutex);
  1173. req = __lookup_request(osdc, tid);
  1174. if (req == NULL) {
  1175. dout("handle_reply tid %llu dne\n", tid);
  1176. mutex_unlock(&osdc->request_mutex);
  1177. return;
  1178. }
  1179. ceph_osdc_get_request(req);
  1180. dout("handle_reply %p tid %llu req %p result %d\n", msg, tid,
  1181. req, result);
  1182. ceph_decode_need(&p, end, 4, bad);
  1183. numops = ceph_decode_32(&p);
  1184. if (numops > CEPH_OSD_MAX_OP)
  1185. goto bad_put;
  1186. if (numops != req->r_num_ops)
  1187. goto bad_put;
  1188. payload_len = 0;
  1189. ceph_decode_need(&p, end, numops * sizeof(struct ceph_osd_op), bad);
  1190. for (i = 0; i < numops; i++) {
  1191. struct ceph_osd_op *op = p;
  1192. int len;
  1193. len = le32_to_cpu(op->payload_len);
  1194. req->r_reply_op_len[i] = len;
  1195. dout(" op %d has %d bytes\n", i, len);
  1196. payload_len += len;
  1197. p += sizeof(*op);
  1198. }
  1199. if (payload_len != le32_to_cpu(msg->hdr.data_len)) {
  1200. pr_warning("sum of op payload lens %d != data_len %d",
  1201. payload_len, le32_to_cpu(msg->hdr.data_len));
  1202. goto bad_put;
  1203. }
  1204. ceph_decode_need(&p, end, 4 + numops * 4, bad);
  1205. retry_attempt = ceph_decode_32(&p);
  1206. for (i = 0; i < numops; i++)
  1207. req->r_reply_op_result[i] = ceph_decode_32(&p);
  1208. /*
  1209. * if this connection filled our message, drop our reference now, to
  1210. * avoid a (safe but slower) revoke later.
  1211. */
  1212. if (req->r_con_filling_msg == con && req->r_reply == msg) {
  1213. dout(" dropping con_filling_msg ref %p\n", con);
  1214. req->r_con_filling_msg = NULL;
  1215. con->ops->put(con);
  1216. }
  1217. if (!req->r_got_reply) {
  1218. unsigned int bytes;
  1219. req->r_result = result;
  1220. bytes = le32_to_cpu(msg->hdr.data_len);
  1221. dout("handle_reply result %d bytes %d\n", req->r_result,
  1222. bytes);
  1223. if (req->r_result == 0)
  1224. req->r_result = bytes;
  1225. /* in case this is a write and we need to replay, */
  1226. req->r_reassert_version.epoch = cpu_to_le32(reassert_epoch);
  1227. req->r_reassert_version.version = cpu_to_le64(reassert_version);
  1228. req->r_got_reply = 1;
  1229. } else if ((flags & CEPH_OSD_FLAG_ONDISK) == 0) {
  1230. dout("handle_reply tid %llu dup ack\n", tid);
  1231. mutex_unlock(&osdc->request_mutex);
  1232. goto done;
  1233. }
  1234. dout("handle_reply tid %llu flags %d\n", tid, flags);
  1235. if (req->r_linger && (flags & CEPH_OSD_FLAG_ONDISK))
  1236. __register_linger_request(osdc, req);
  1237. /* either this is a read, or we got the safe response */
  1238. if (result < 0 ||
  1239. (flags & CEPH_OSD_FLAG_ONDISK) ||
  1240. ((flags & CEPH_OSD_FLAG_WRITE) == 0))
  1241. __unregister_request(osdc, req);
  1242. already_completed = req->r_completed;
  1243. req->r_completed = 1;
  1244. mutex_unlock(&osdc->request_mutex);
  1245. if (already_completed)
  1246. goto done;
  1247. if (req->r_callback)
  1248. req->r_callback(req, msg);
  1249. else
  1250. complete_all(&req->r_completion);
  1251. if (flags & CEPH_OSD_FLAG_ONDISK)
  1252. complete_request(req);
  1253. done:
  1254. dout("req=%p req->r_linger=%d\n", req, req->r_linger);
  1255. ceph_osdc_put_request(req);
  1256. return;
  1257. bad_put:
  1258. ceph_osdc_put_request(req);
  1259. bad:
  1260. pr_err("corrupt osd_op_reply got %d %d\n",
  1261. (int)msg->front.iov_len, le32_to_cpu(msg->hdr.front_len));
  1262. ceph_msg_dump(msg);
  1263. }
  1264. static void reset_changed_osds(struct ceph_osd_client *osdc)
  1265. {
  1266. struct rb_node *p, *n;
  1267. for (p = rb_first(&osdc->osds); p; p = n) {
  1268. struct ceph_osd *osd = rb_entry(p, struct ceph_osd, o_node);
  1269. n = rb_next(p);
  1270. if (!ceph_osd_is_up(osdc->osdmap, osd->o_osd) ||
  1271. memcmp(&osd->o_con.peer_addr,
  1272. ceph_osd_addr(osdc->osdmap,
  1273. osd->o_osd),
  1274. sizeof(struct ceph_entity_addr)) != 0)
  1275. __reset_osd(osdc, osd);
  1276. }
  1277. }
  1278. /*
  1279. * Requeue requests whose mapping to an OSD has changed. If requests map to
  1280. * no osd, request a new map.
  1281. *
  1282. * Caller should hold map_sem for read.
  1283. */
  1284. static void kick_requests(struct ceph_osd_client *osdc, int force_resend)
  1285. {
  1286. struct ceph_osd_request *req, *nreq;
  1287. struct rb_node *p;
  1288. int needmap = 0;
  1289. int err;
  1290. dout("kick_requests %s\n", force_resend ? " (force resend)" : "");
  1291. mutex_lock(&osdc->request_mutex);
  1292. for (p = rb_first(&osdc->requests); p; ) {
  1293. req = rb_entry(p, struct ceph_osd_request, r_node);
  1294. p = rb_next(p);
  1295. /*
  1296. * For linger requests that have not yet been
  1297. * registered, move them to the linger list; they'll
  1298. * be sent to the osd in the loop below. Unregister
  1299. * the request before re-registering it as a linger
  1300. * request to ensure the __map_request() below
  1301. * will decide it needs to be sent.
  1302. */
  1303. if (req->r_linger && list_empty(&req->r_linger_item)) {
  1304. dout("%p tid %llu restart on osd%d\n",
  1305. req, req->r_tid,
  1306. req->r_osd ? req->r_osd->o_osd : -1);
  1307. __unregister_request(osdc, req);
  1308. __register_linger_request(osdc, req);
  1309. continue;
  1310. }
  1311. err = __map_request(osdc, req, force_resend);
  1312. if (err < 0)
  1313. continue; /* error */
  1314. if (req->r_osd == NULL) {
  1315. dout("%p tid %llu maps to no osd\n", req, req->r_tid);
  1316. needmap++; /* request a newer map */
  1317. } else if (err > 0) {
  1318. if (!req->r_linger) {
  1319. dout("%p tid %llu requeued on osd%d\n", req,
  1320. req->r_tid,
  1321. req->r_osd ? req->r_osd->o_osd : -1);
  1322. req->r_flags |= CEPH_OSD_FLAG_RETRY;
  1323. }
  1324. }
  1325. }
  1326. list_for_each_entry_safe(req, nreq, &osdc->req_linger,
  1327. r_linger_item) {
  1328. dout("linger req=%p req->r_osd=%p\n", req, req->r_osd);
  1329. err = __map_request(osdc, req, force_resend);
  1330. dout("__map_request returned %d\n", err);
  1331. if (err == 0)
  1332. continue; /* no change and no osd was specified */
  1333. if (err < 0)
  1334. continue; /* hrm! */
  1335. if (req->r_osd == NULL) {
  1336. dout("tid %llu maps to no valid osd\n", req->r_tid);
  1337. needmap++; /* request a newer map */
  1338. continue;
  1339. }
  1340. dout("kicking lingering %p tid %llu osd%d\n", req, req->r_tid,
  1341. req->r_osd ? req->r_osd->o_osd : -1);
  1342. __register_request(osdc, req);
  1343. __unregister_linger_request(osdc, req);
  1344. }
  1345. mutex_unlock(&osdc->request_mutex);
  1346. if (needmap) {
  1347. dout("%d requests for down osds, need new map\n", needmap);
  1348. ceph_monc_request_next_osdmap(&osdc->client->monc);
  1349. }
  1350. reset_changed_osds(osdc);
  1351. }
  1352. /*
  1353. * Process updated osd map.
  1354. *
  1355. * The message contains any number of incremental and full maps, normally
  1356. * indicating some sort of topology change in the cluster. Kick requests
  1357. * off to different OSDs as needed.
  1358. */
  1359. void ceph_osdc_handle_map(struct ceph_osd_client *osdc, struct ceph_msg *msg)
  1360. {
  1361. void *p, *end, *next;
  1362. u32 nr_maps, maplen;
  1363. u32 epoch;
  1364. struct ceph_osdmap *newmap = NULL, *oldmap;
  1365. int err;
  1366. struct ceph_fsid fsid;
  1367. dout("handle_map have %u\n", osdc->osdmap ? osdc->osdmap->epoch : 0);
  1368. p = msg->front.iov_base;
  1369. end = p + msg->front.iov_len;
  1370. /* verify fsid */
  1371. ceph_decode_need(&p, end, sizeof(fsid), bad);
  1372. ceph_decode_copy(&p, &fsid, sizeof(fsid));
  1373. if (ceph_check_fsid(osdc->client, &fsid) < 0)
  1374. return;
  1375. down_write(&osdc->map_sem);
  1376. /* incremental maps */
  1377. ceph_decode_32_safe(&p, end, nr_maps, bad);
  1378. dout(" %d inc maps\n", nr_maps);
  1379. while (nr_maps > 0) {
  1380. ceph_decode_need(&p, end, 2*sizeof(u32), bad);
  1381. epoch = ceph_decode_32(&p);
  1382. maplen = ceph_decode_32(&p);
  1383. ceph_decode_need(&p, end, maplen, bad);
  1384. next = p + maplen;
  1385. if (osdc->osdmap && osdc->osdmap->epoch+1 == epoch) {
  1386. dout("applying incremental map %u len %d\n",
  1387. epoch, maplen);
  1388. newmap = osdmap_apply_incremental(&p, next,
  1389. osdc->osdmap,
  1390. &osdc->client->msgr);
  1391. if (IS_ERR(newmap)) {
  1392. err = PTR_ERR(newmap);
  1393. goto bad;
  1394. }
  1395. BUG_ON(!newmap);
  1396. if (newmap != osdc->osdmap) {
  1397. ceph_osdmap_destroy(osdc->osdmap);
  1398. osdc->osdmap = newmap;
  1399. }
  1400. kick_requests(osdc, 0);
  1401. } else {
  1402. dout("ignoring incremental map %u len %d\n",
  1403. epoch, maplen);
  1404. }
  1405. p = next;
  1406. nr_maps--;
  1407. }
  1408. if (newmap)
  1409. goto done;
  1410. /* full maps */
  1411. ceph_decode_32_safe(&p, end, nr_maps, bad);
  1412. dout(" %d full maps\n", nr_maps);
  1413. while (nr_maps) {
  1414. ceph_decode_need(&p, end, 2*sizeof(u32), bad);
  1415. epoch = ceph_decode_32(&p);
  1416. maplen = ceph_decode_32(&p);
  1417. ceph_decode_need(&p, end, maplen, bad);
  1418. if (nr_maps > 1) {
  1419. dout("skipping non-latest full map %u len %d\n",
  1420. epoch, maplen);
  1421. } else if (osdc->osdmap && osdc->osdmap->epoch >= epoch) {
  1422. dout("skipping full map %u len %d, "
  1423. "older than our %u\n", epoch, maplen,
  1424. osdc->osdmap->epoch);
  1425. } else {
  1426. int skipped_map = 0;
  1427. dout("taking full map %u len %d\n", epoch, maplen);
  1428. newmap = osdmap_decode(&p, p+maplen);
  1429. if (IS_ERR(newmap)) {
  1430. err = PTR_ERR(newmap);
  1431. goto bad;
  1432. }
  1433. BUG_ON(!newmap);
  1434. oldmap = osdc->osdmap;
  1435. osdc->osdmap = newmap;
  1436. if (oldmap) {
  1437. if (oldmap->epoch + 1 < newmap->epoch)
  1438. skipped_map = 1;
  1439. ceph_osdmap_destroy(oldmap);
  1440. }
  1441. kick_requests(osdc, skipped_map);
  1442. }
  1443. p += maplen;
  1444. nr_maps--;
  1445. }
  1446. done:
  1447. downgrade_write(&osdc->map_sem);
  1448. ceph_monc_got_osdmap(&osdc->client->monc, osdc->osdmap->epoch);
  1449. /*
  1450. * subscribe to subsequent osdmap updates if full to ensure
  1451. * we find out when we are no longer full and stop returning
  1452. * ENOSPC.
  1453. */
  1454. if (ceph_osdmap_flag(osdc->osdmap, CEPH_OSDMAP_FULL))
  1455. ceph_monc_request_next_osdmap(&osdc->client->monc);
  1456. mutex_lock(&osdc->request_mutex);
  1457. __send_queued(osdc);
  1458. mutex_unlock(&osdc->request_mutex);
  1459. up_read(&osdc->map_sem);
  1460. wake_up_all(&osdc->client->auth_wq);
  1461. return;
  1462. bad:
  1463. pr_err("osdc handle_map corrupt msg\n");
  1464. ceph_msg_dump(msg);
  1465. up_write(&osdc->map_sem);
  1466. return;
  1467. }
  1468. /*
  1469. * watch/notify callback event infrastructure
  1470. *
  1471. * These callbacks are used both for watch and notify operations.
  1472. */
  1473. static void __release_event(struct kref *kref)
  1474. {
  1475. struct ceph_osd_event *event =
  1476. container_of(kref, struct ceph_osd_event, kref);
  1477. dout("__release_event %p\n", event);
  1478. kfree(event);
  1479. }
  1480. static void get_event(struct ceph_osd_event *event)
  1481. {
  1482. kref_get(&event->kref);
  1483. }
  1484. void ceph_osdc_put_event(struct ceph_osd_event *event)
  1485. {
  1486. kref_put(&event->kref, __release_event);
  1487. }
  1488. EXPORT_SYMBOL(ceph_osdc_put_event);
  1489. static void __insert_event(struct ceph_osd_client *osdc,
  1490. struct ceph_osd_event *new)
  1491. {
  1492. struct rb_node **p = &osdc->event_tree.rb_node;
  1493. struct rb_node *parent = NULL;
  1494. struct ceph_osd_event *event = NULL;
  1495. while (*p) {
  1496. parent = *p;
  1497. event = rb_entry(parent, struct ceph_osd_event, node);
  1498. if (new->cookie < event->cookie)
  1499. p = &(*p)->rb_left;
  1500. else if (new->cookie > event->cookie)
  1501. p = &(*p)->rb_right;
  1502. else
  1503. BUG();
  1504. }
  1505. rb_link_node(&new->node, parent, p);
  1506. rb_insert_color(&new->node, &osdc->event_tree);
  1507. }
  1508. static struct ceph_osd_event *__find_event(struct ceph_osd_client *osdc,
  1509. u64 cookie)
  1510. {
  1511. struct rb_node **p = &osdc->event_tree.rb_node;
  1512. struct rb_node *parent = NULL;
  1513. struct ceph_osd_event *event = NULL;
  1514. while (*p) {
  1515. parent = *p;
  1516. event = rb_entry(parent, struct ceph_osd_event, node);
  1517. if (cookie < event->cookie)
  1518. p = &(*p)->rb_left;
  1519. else if (cookie > event->cookie)
  1520. p = &(*p)->rb_right;
  1521. else
  1522. return event;
  1523. }
  1524. return NULL;
  1525. }
  1526. static void __remove_event(struct ceph_osd_event *event)
  1527. {
  1528. struct ceph_osd_client *osdc = event->osdc;
  1529. if (!RB_EMPTY_NODE(&event->node)) {
  1530. dout("__remove_event removed %p\n", event);
  1531. rb_erase(&event->node, &osdc->event_tree);
  1532. ceph_osdc_put_event(event);
  1533. } else {
  1534. dout("__remove_event didn't remove %p\n", event);
  1535. }
  1536. }
  1537. int ceph_osdc_create_event(struct ceph_osd_client *osdc,
  1538. void (*event_cb)(u64, u64, u8, void *),
  1539. void *data, struct ceph_osd_event **pevent)
  1540. {
  1541. struct ceph_osd_event *event;
  1542. event = kmalloc(sizeof(*event), GFP_NOIO);
  1543. if (!event)
  1544. return -ENOMEM;
  1545. dout("create_event %p\n", event);
  1546. event->cb = event_cb;
  1547. event->one_shot = 0;
  1548. event->data = data;
  1549. event->osdc = osdc;
  1550. INIT_LIST_HEAD(&event->osd_node);
  1551. RB_CLEAR_NODE(&event->node);
  1552. kref_init(&event->kref); /* one ref for us */
  1553. kref_get(&event->kref); /* one ref for the caller */
  1554. spin_lock(&osdc->event_lock);
  1555. event->cookie = ++osdc->event_count;
  1556. __insert_event(osdc, event);
  1557. spin_unlock(&osdc->event_lock);
  1558. *pevent = event;
  1559. return 0;
  1560. }
  1561. EXPORT_SYMBOL(ceph_osdc_create_event);
  1562. void ceph_osdc_cancel_event(struct ceph_osd_event *event)
  1563. {
  1564. struct ceph_osd_client *osdc = event->osdc;
  1565. dout("cancel_event %p\n", event);
  1566. spin_lock(&osdc->event_lock);
  1567. __remove_event(event);
  1568. spin_unlock(&osdc->event_lock);
  1569. ceph_osdc_put_event(event); /* caller's */
  1570. }
  1571. EXPORT_SYMBOL(ceph_osdc_cancel_event);
  1572. static void do_event_work(struct work_struct *work)
  1573. {
  1574. struct ceph_osd_event_work *event_work =
  1575. container_of(work, struct ceph_osd_event_work, work);
  1576. struct ceph_osd_event *event = event_work->event;
  1577. u64 ver = event_work->ver;
  1578. u64 notify_id = event_work->notify_id;
  1579. u8 opcode = event_work->opcode;
  1580. dout("do_event_work completing %p\n", event);
  1581. event->cb(ver, notify_id, opcode, event->data);
  1582. dout("do_event_work completed %p\n", event);
  1583. ceph_osdc_put_event(event);
  1584. kfree(event_work);
  1585. }
  1586. /*
  1587. * Process osd watch notifications
  1588. */
  1589. static void handle_watch_notify(struct ceph_osd_client *osdc,
  1590. struct ceph_msg *msg)
  1591. {
  1592. void *p, *end;
  1593. u8 proto_ver;
  1594. u64 cookie, ver, notify_id;
  1595. u8 opcode;
  1596. struct ceph_osd_event *event;
  1597. struct ceph_osd_event_work *event_work;
  1598. p = msg->front.iov_base;
  1599. end = p + msg->front.iov_len;
  1600. ceph_decode_8_safe(&p, end, proto_ver, bad);
  1601. ceph_decode_8_safe(&p, end, opcode, bad);
  1602. ceph_decode_64_safe(&p, end, cookie, bad);
  1603. ceph_decode_64_safe(&p, end, ver, bad);
  1604. ceph_decode_64_safe(&p, end, notify_id, bad);
  1605. spin_lock(&osdc->event_lock);
  1606. event = __find_event(osdc, cookie);
  1607. if (event) {
  1608. BUG_ON(event->one_shot);
  1609. get_event(event);
  1610. }
  1611. spin_unlock(&osdc->event_lock);
  1612. dout("handle_watch_notify cookie %lld ver %lld event %p\n",
  1613. cookie, ver, event);
  1614. if (event) {
  1615. event_work = kmalloc(sizeof(*event_work), GFP_NOIO);
  1616. if (!event_work) {
  1617. dout("ERROR: could not allocate event_work\n");
  1618. goto done_err;
  1619. }
  1620. INIT_WORK(&event_work->work, do_event_work);
  1621. event_work->event = event;
  1622. event_work->ver = ver;
  1623. event_work->notify_id = notify_id;
  1624. event_work->opcode = opcode;
  1625. if (!queue_work(osdc->notify_wq, &event_work->work)) {
  1626. dout("WARNING: failed to queue notify event work\n");
  1627. goto done_err;
  1628. }
  1629. }
  1630. return;
  1631. done_err:
  1632. ceph_osdc_put_event(event);
  1633. return;
  1634. bad:
  1635. pr_err("osdc handle_watch_notify corrupt msg\n");
  1636. return;
  1637. }
  1638. static void ceph_osdc_msg_data_set(struct ceph_msg *msg,
  1639. struct ceph_osd_data *osd_data)
  1640. {
  1641. if (osd_data->type == CEPH_OSD_DATA_TYPE_PAGES) {
  1642. BUG_ON(osd_data->length > (u64) SIZE_MAX);
  1643. if (osd_data->length)
  1644. ceph_msg_data_set_pages(msg, osd_data->pages,
  1645. osd_data->length, osd_data->alignment);
  1646. } else if (osd_data->type == CEPH_OSD_DATA_TYPE_PAGELIST) {
  1647. BUG_ON(!osd_data->pagelist->length);
  1648. ceph_msg_data_set_pagelist(msg, osd_data->pagelist);
  1649. #ifdef CONFIG_BLOCK
  1650. } else if (osd_data->type == CEPH_OSD_DATA_TYPE_BIO) {
  1651. ceph_msg_data_set_bio(msg, osd_data->bio);
  1652. #endif
  1653. } else {
  1654. BUG_ON(osd_data->type != CEPH_OSD_DATA_TYPE_NONE);
  1655. }
  1656. }
  1657. /*
  1658. * Register request, send initial attempt.
  1659. */
  1660. int ceph_osdc_start_request(struct ceph_osd_client *osdc,
  1661. struct ceph_osd_request *req,
  1662. bool nofail)
  1663. {
  1664. int rc = 0;
  1665. /* Set up response incoming data and request outgoing data fields */
  1666. ceph_osdc_msg_data_set(req->r_reply, &req->r_data_in);
  1667. ceph_osdc_msg_data_set(req->r_request, &req->r_data_out);
  1668. down_read(&osdc->map_sem);
  1669. mutex_lock(&osdc->request_mutex);
  1670. __register_request(osdc, req);
  1671. WARN_ON(req->r_sent);
  1672. rc = __map_request(osdc, req, 0);
  1673. if (rc < 0) {
  1674. if (nofail) {
  1675. dout("osdc_start_request failed map, "
  1676. " will retry %lld\n", req->r_tid);
  1677. rc = 0;
  1678. }
  1679. goto out_unlock;
  1680. }
  1681. if (req->r_osd == NULL) {
  1682. dout("send_request %p no up osds in pg\n", req);
  1683. ceph_monc_request_next_osdmap(&osdc->client->monc);
  1684. } else {
  1685. __send_queued(osdc);
  1686. }
  1687. rc = 0;
  1688. out_unlock:
  1689. mutex_unlock(&osdc->request_mutex);
  1690. up_read(&osdc->map_sem);
  1691. return rc;
  1692. }
  1693. EXPORT_SYMBOL(ceph_osdc_start_request);
  1694. /*
  1695. * wait for a request to complete
  1696. */
  1697. int ceph_osdc_wait_request(struct ceph_osd_client *osdc,
  1698. struct ceph_osd_request *req)
  1699. {
  1700. int rc;
  1701. rc = wait_for_completion_interruptible(&req->r_completion);
  1702. if (rc < 0) {
  1703. mutex_lock(&osdc->request_mutex);
  1704. __cancel_request(req);
  1705. __unregister_request(osdc, req);
  1706. mutex_unlock(&osdc->request_mutex);
  1707. complete_request(req);
  1708. dout("wait_request tid %llu canceled/timed out\n", req->r_tid);
  1709. return rc;
  1710. }
  1711. dout("wait_request tid %llu result %d\n", req->r_tid, req->r_result);
  1712. return req->r_result;
  1713. }
  1714. EXPORT_SYMBOL(ceph_osdc_wait_request);
  1715. /*
  1716. * sync - wait for all in-flight requests to flush. avoid starvation.
  1717. */
  1718. void ceph_osdc_sync(struct ceph_osd_client *osdc)
  1719. {
  1720. struct ceph_osd_request *req;
  1721. u64 last_tid, next_tid = 0;
  1722. mutex_lock(&osdc->request_mutex);
  1723. last_tid = osdc->last_tid;
  1724. while (1) {
  1725. req = __lookup_request_ge(osdc, next_tid);
  1726. if (!req)
  1727. break;
  1728. if (req->r_tid > last_tid)
  1729. break;
  1730. next_tid = req->r_tid + 1;
  1731. if ((req->r_flags & CEPH_OSD_FLAG_WRITE) == 0)
  1732. continue;
  1733. ceph_osdc_get_request(req);
  1734. mutex_unlock(&osdc->request_mutex);
  1735. dout("sync waiting on tid %llu (last is %llu)\n",
  1736. req->r_tid, last_tid);
  1737. wait_for_completion(&req->r_safe_completion);
  1738. mutex_lock(&osdc->request_mutex);
  1739. ceph_osdc_put_request(req);
  1740. }
  1741. mutex_unlock(&osdc->request_mutex);
  1742. dout("sync done (thru tid %llu)\n", last_tid);
  1743. }
  1744. EXPORT_SYMBOL(ceph_osdc_sync);
  1745. /*
  1746. * init, shutdown
  1747. */
  1748. int ceph_osdc_init(struct ceph_osd_client *osdc, struct ceph_client *client)
  1749. {
  1750. int err;
  1751. dout("init\n");
  1752. osdc->client = client;
  1753. osdc->osdmap = NULL;
  1754. init_rwsem(&osdc->map_sem);
  1755. init_completion(&osdc->map_waiters);
  1756. osdc->last_requested_map = 0;
  1757. mutex_init(&osdc->request_mutex);
  1758. osdc->last_tid = 0;
  1759. osdc->osds = RB_ROOT;
  1760. INIT_LIST_HEAD(&osdc->osd_lru);
  1761. osdc->requests = RB_ROOT;
  1762. INIT_LIST_HEAD(&osdc->req_lru);
  1763. INIT_LIST_HEAD(&osdc->req_unsent);
  1764. INIT_LIST_HEAD(&osdc->req_notarget);
  1765. INIT_LIST_HEAD(&osdc->req_linger);
  1766. osdc->num_requests = 0;
  1767. INIT_DELAYED_WORK(&osdc->timeout_work, handle_timeout);
  1768. INIT_DELAYED_WORK(&osdc->osds_timeout_work, handle_osds_timeout);
  1769. spin_lock_init(&osdc->event_lock);
  1770. osdc->event_tree = RB_ROOT;
  1771. osdc->event_count = 0;
  1772. schedule_delayed_work(&osdc->osds_timeout_work,
  1773. round_jiffies_relative(osdc->client->options->osd_idle_ttl * HZ));
  1774. err = -ENOMEM;
  1775. osdc->req_mempool = mempool_create_kmalloc_pool(10,
  1776. sizeof(struct ceph_osd_request));
  1777. if (!osdc->req_mempool)
  1778. goto out;
  1779. err = ceph_msgpool_init(&osdc->msgpool_op, CEPH_MSG_OSD_OP,
  1780. OSD_OP_FRONT_LEN, 10, true,
  1781. "osd_op");
  1782. if (err < 0)
  1783. goto out_mempool;
  1784. err = ceph_msgpool_init(&osdc->msgpool_op_reply, CEPH_MSG_OSD_OPREPLY,
  1785. OSD_OPREPLY_FRONT_LEN, 10, true,
  1786. "osd_op_reply");
  1787. if (err < 0)
  1788. goto out_msgpool;
  1789. osdc->notify_wq = create_singlethread_workqueue("ceph-watch-notify");
  1790. if (IS_ERR(osdc->notify_wq)) {
  1791. err = PTR_ERR(osdc->notify_wq);
  1792. osdc->notify_wq = NULL;
  1793. goto out_msgpool;
  1794. }
  1795. return 0;
  1796. out_msgpool:
  1797. ceph_msgpool_destroy(&osdc->msgpool_op);
  1798. out_mempool:
  1799. mempool_destroy(osdc->req_mempool);
  1800. out:
  1801. return err;
  1802. }
  1803. void ceph_osdc_stop(struct ceph_osd_client *osdc)
  1804. {
  1805. flush_workqueue(osdc->notify_wq);
  1806. destroy_workqueue(osdc->notify_wq);
  1807. cancel_delayed_work_sync(&osdc->timeout_work);
  1808. cancel_delayed_work_sync(&osdc->osds_timeout_work);
  1809. if (osdc->osdmap) {
  1810. ceph_osdmap_destroy(osdc->osdmap);
  1811. osdc->osdmap = NULL;
  1812. }
  1813. remove_all_osds(osdc);
  1814. mempool_destroy(osdc->req_mempool);
  1815. ceph_msgpool_destroy(&osdc->msgpool_op);
  1816. ceph_msgpool_destroy(&osdc->msgpool_op_reply);
  1817. }
  1818. /*
  1819. * Read some contiguous pages. If we cross a stripe boundary, shorten
  1820. * *plen. Return number of bytes read, or error.
  1821. */
  1822. int ceph_osdc_readpages(struct ceph_osd_client *osdc,
  1823. struct ceph_vino vino, struct ceph_file_layout *layout,
  1824. u64 off, u64 *plen,
  1825. u32 truncate_seq, u64 truncate_size,
  1826. struct page **pages, int num_pages, int page_align)
  1827. {
  1828. struct ceph_osd_request *req;
  1829. struct ceph_osd_data *osd_data;
  1830. int rc = 0;
  1831. dout("readpages on ino %llx.%llx on %llu~%llu\n", vino.ino,
  1832. vino.snap, off, *plen);
  1833. req = ceph_osdc_new_request(osdc, layout, vino, off, plen,
  1834. CEPH_OSD_OP_READ, CEPH_OSD_FLAG_READ,
  1835. NULL, 0, truncate_seq, truncate_size, NULL,
  1836. false);
  1837. if (IS_ERR(req))
  1838. return PTR_ERR(req);
  1839. /* it may be a short read due to an object boundary */
  1840. osd_data = &req->r_data_in;
  1841. osd_data->type = CEPH_OSD_DATA_TYPE_PAGES;
  1842. osd_data->pages = pages;
  1843. osd_data->length = *plen;
  1844. osd_data->alignment = page_align;
  1845. dout("readpages final extent is %llu~%llu (%llu bytes align %d)\n",
  1846. off, *plen, osd_data->length, page_align);
  1847. rc = ceph_osdc_start_request(osdc, req, false);
  1848. if (!rc)
  1849. rc = ceph_osdc_wait_request(osdc, req);
  1850. ceph_osdc_put_request(req);
  1851. dout("readpages result %d\n", rc);
  1852. return rc;
  1853. }
  1854. EXPORT_SYMBOL(ceph_osdc_readpages);
  1855. /*
  1856. * do a synchronous write on N pages
  1857. */
  1858. int ceph_osdc_writepages(struct ceph_osd_client *osdc, struct ceph_vino vino,
  1859. struct ceph_file_layout *layout,
  1860. struct ceph_snap_context *snapc,
  1861. u64 off, u64 len,
  1862. u32 truncate_seq, u64 truncate_size,
  1863. struct timespec *mtime,
  1864. struct page **pages, int num_pages)
  1865. {
  1866. struct ceph_osd_request *req;
  1867. struct ceph_osd_data *osd_data;
  1868. int rc = 0;
  1869. int page_align = off & ~PAGE_MASK;
  1870. BUG_ON(vino.snap != CEPH_NOSNAP);
  1871. req = ceph_osdc_new_request(osdc, layout, vino, off, &len,
  1872. CEPH_OSD_OP_WRITE,
  1873. CEPH_OSD_FLAG_ONDISK | CEPH_OSD_FLAG_WRITE,
  1874. snapc, 0,
  1875. truncate_seq, truncate_size, mtime,
  1876. true);
  1877. if (IS_ERR(req))
  1878. return PTR_ERR(req);
  1879. /* it may be a short write due to an object boundary */
  1880. osd_data = &req->r_data_out;
  1881. osd_data->type = CEPH_OSD_DATA_TYPE_PAGES;
  1882. osd_data->pages = pages;
  1883. osd_data->length = len;
  1884. osd_data->alignment = page_align;
  1885. dout("writepages %llu~%llu (%llu bytes)\n", off, len, osd_data->length);
  1886. rc = ceph_osdc_start_request(osdc, req, true);
  1887. if (!rc)
  1888. rc = ceph_osdc_wait_request(osdc, req);
  1889. ceph_osdc_put_request(req);
  1890. if (rc == 0)
  1891. rc = len;
  1892. dout("writepages result %d\n", rc);
  1893. return rc;
  1894. }
  1895. EXPORT_SYMBOL(ceph_osdc_writepages);
  1896. /*
  1897. * handle incoming message
  1898. */
  1899. static void dispatch(struct ceph_connection *con, struct ceph_msg *msg)
  1900. {
  1901. struct ceph_osd *osd = con->private;
  1902. struct ceph_osd_client *osdc;
  1903. int type = le16_to_cpu(msg->hdr.type);
  1904. if (!osd)
  1905. goto out;
  1906. osdc = osd->o_osdc;
  1907. switch (type) {
  1908. case CEPH_MSG_OSD_MAP:
  1909. ceph_osdc_handle_map(osdc, msg);
  1910. break;
  1911. case CEPH_MSG_OSD_OPREPLY:
  1912. handle_reply(osdc, msg, con);
  1913. break;
  1914. case CEPH_MSG_WATCH_NOTIFY:
  1915. handle_watch_notify(osdc, msg);
  1916. break;
  1917. default:
  1918. pr_err("received unknown message type %d %s\n", type,
  1919. ceph_msg_type_name(type));
  1920. }
  1921. out:
  1922. ceph_msg_put(msg);
  1923. }
  1924. /*
  1925. * lookup and return message for incoming reply. set up reply message
  1926. * pages.
  1927. */
  1928. static struct ceph_msg *get_reply(struct ceph_connection *con,
  1929. struct ceph_msg_header *hdr,
  1930. int *skip)
  1931. {
  1932. struct ceph_osd *osd = con->private;
  1933. struct ceph_osd_client *osdc = osd->o_osdc;
  1934. struct ceph_msg *m;
  1935. struct ceph_osd_request *req;
  1936. int front = le32_to_cpu(hdr->front_len);
  1937. int data_len = le32_to_cpu(hdr->data_len);
  1938. u64 tid;
  1939. tid = le64_to_cpu(hdr->tid);
  1940. mutex_lock(&osdc->request_mutex);
  1941. req = __lookup_request(osdc, tid);
  1942. if (!req) {
  1943. *skip = 1;
  1944. m = NULL;
  1945. dout("get_reply unknown tid %llu from osd%d\n", tid,
  1946. osd->o_osd);
  1947. goto out;
  1948. }
  1949. if (req->r_con_filling_msg) {
  1950. dout("%s revoking msg %p from old con %p\n", __func__,
  1951. req->r_reply, req->r_con_filling_msg);
  1952. ceph_msg_revoke_incoming(req->r_reply);
  1953. req->r_con_filling_msg->ops->put(req->r_con_filling_msg);
  1954. req->r_con_filling_msg = NULL;
  1955. }
  1956. if (front > req->r_reply->front.iov_len) {
  1957. pr_warning("get_reply front %d > preallocated %d\n",
  1958. front, (int)req->r_reply->front.iov_len);
  1959. m = ceph_msg_new(CEPH_MSG_OSD_OPREPLY, front, GFP_NOFS, false);
  1960. if (!m)
  1961. goto out;
  1962. ceph_msg_put(req->r_reply);
  1963. req->r_reply = m;
  1964. }
  1965. m = ceph_msg_get(req->r_reply);
  1966. if (data_len > 0) {
  1967. struct ceph_osd_data *osd_data = &req->r_data_in;
  1968. if (osd_data->type == CEPH_OSD_DATA_TYPE_PAGES) {
  1969. if (osd_data->pages &&
  1970. unlikely(osd_data->length < data_len)) {
  1971. pr_warning("tid %lld reply has %d bytes "
  1972. "we had only %llu bytes ready\n",
  1973. tid, data_len, osd_data->length);
  1974. *skip = 1;
  1975. ceph_msg_put(m);
  1976. m = NULL;
  1977. goto out;
  1978. }
  1979. }
  1980. }
  1981. *skip = 0;
  1982. req->r_con_filling_msg = con->ops->get(con);
  1983. dout("get_reply tid %lld %p\n", tid, m);
  1984. out:
  1985. mutex_unlock(&osdc->request_mutex);
  1986. return m;
  1987. }
  1988. static struct ceph_msg *alloc_msg(struct ceph_connection *con,
  1989. struct ceph_msg_header *hdr,
  1990. int *skip)
  1991. {
  1992. struct ceph_osd *osd = con->private;
  1993. int type = le16_to_cpu(hdr->type);
  1994. int front = le32_to_cpu(hdr->front_len);
  1995. *skip = 0;
  1996. switch (type) {
  1997. case CEPH_MSG_OSD_MAP:
  1998. case CEPH_MSG_WATCH_NOTIFY:
  1999. return ceph_msg_new(type, front, GFP_NOFS, false);
  2000. case CEPH_MSG_OSD_OPREPLY:
  2001. return get_reply(con, hdr, skip);
  2002. default:
  2003. pr_info("alloc_msg unexpected msg type %d from osd%d\n", type,
  2004. osd->o_osd);
  2005. *skip = 1;
  2006. return NULL;
  2007. }
  2008. }
  2009. /*
  2010. * Wrappers to refcount containing ceph_osd struct
  2011. */
  2012. static struct ceph_connection *get_osd_con(struct ceph_connection *con)
  2013. {
  2014. struct ceph_osd *osd = con->private;
  2015. if (get_osd(osd))
  2016. return con;
  2017. return NULL;
  2018. }
  2019. static void put_osd_con(struct ceph_connection *con)
  2020. {
  2021. struct ceph_osd *osd = con->private;
  2022. put_osd(osd);
  2023. }
  2024. /*
  2025. * authentication
  2026. */
  2027. /*
  2028. * Note: returned pointer is the address of a structure that's
  2029. * managed separately. Caller must *not* attempt to free it.
  2030. */
  2031. static struct ceph_auth_handshake *get_authorizer(struct ceph_connection *con,
  2032. int *proto, int force_new)
  2033. {
  2034. struct ceph_osd *o = con->private;
  2035. struct ceph_osd_client *osdc = o->o_osdc;
  2036. struct ceph_auth_client *ac = osdc->client->monc.auth;
  2037. struct ceph_auth_handshake *auth = &o->o_auth;
  2038. if (force_new && auth->authorizer) {
  2039. ceph_auth_destroy_authorizer(ac, auth->authorizer);
  2040. auth->authorizer = NULL;
  2041. }
  2042. if (!auth->authorizer) {
  2043. int ret = ceph_auth_create_authorizer(ac, CEPH_ENTITY_TYPE_OSD,
  2044. auth);
  2045. if (ret)
  2046. return ERR_PTR(ret);
  2047. } else {
  2048. int ret = ceph_auth_update_authorizer(ac, CEPH_ENTITY_TYPE_OSD,
  2049. auth);
  2050. if (ret)
  2051. return ERR_PTR(ret);
  2052. }
  2053. *proto = ac->protocol;
  2054. return auth;
  2055. }
  2056. static int verify_authorizer_reply(struct ceph_connection *con, int len)
  2057. {
  2058. struct ceph_osd *o = con->private;
  2059. struct ceph_osd_client *osdc = o->o_osdc;
  2060. struct ceph_auth_client *ac = osdc->client->monc.auth;
  2061. return ceph_auth_verify_authorizer_reply(ac, o->o_auth.authorizer, len);
  2062. }
  2063. static int invalidate_authorizer(struct ceph_connection *con)
  2064. {
  2065. struct ceph_osd *o = con->private;
  2066. struct ceph_osd_client *osdc = o->o_osdc;
  2067. struct ceph_auth_client *ac = osdc->client->monc.auth;
  2068. ceph_auth_invalidate_authorizer(ac, CEPH_ENTITY_TYPE_OSD);
  2069. return ceph_monc_validate_auth(&osdc->client->monc);
  2070. }
  2071. static const struct ceph_connection_operations osd_con_ops = {
  2072. .get = get_osd_con,
  2073. .put = put_osd_con,
  2074. .dispatch = dispatch,
  2075. .get_authorizer = get_authorizer,
  2076. .verify_authorizer_reply = verify_authorizer_reply,
  2077. .invalidate_authorizer = invalidate_authorizer,
  2078. .alloc_msg = alloc_msg,
  2079. .fault = osd_reset,
  2080. };