osd_client.c 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949
  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 struct kmem_cache *ceph_osd_request_cache;
  21. static const struct ceph_connection_operations osd_con_ops;
  22. static void __send_queued(struct ceph_osd_client *osdc);
  23. static int __reset_osd(struct ceph_osd_client *osdc, struct ceph_osd *osd);
  24. static void __register_request(struct ceph_osd_client *osdc,
  25. struct ceph_osd_request *req);
  26. static void __unregister_request(struct ceph_osd_client *osdc,
  27. struct ceph_osd_request *req);
  28. static void __unregister_linger_request(struct ceph_osd_client *osdc,
  29. struct ceph_osd_request *req);
  30. static void __enqueue_request(struct ceph_osd_request *req);
  31. static void __send_request(struct ceph_osd_client *osdc,
  32. struct ceph_osd_request *req);
  33. /*
  34. * Implement client access to distributed object storage cluster.
  35. *
  36. * All data objects are stored within a cluster/cloud of OSDs, or
  37. * "object storage devices." (Note that Ceph OSDs have _nothing_ to
  38. * do with the T10 OSD extensions to SCSI.) Ceph OSDs are simply
  39. * remote daemons serving up and coordinating consistent and safe
  40. * access to storage.
  41. *
  42. * Cluster membership and the mapping of data objects onto storage devices
  43. * are described by the osd map.
  44. *
  45. * We keep track of pending OSD requests (read, write), resubmit
  46. * requests to different OSDs when the cluster topology/data layout
  47. * change, or retry the affected requests when the communications
  48. * channel with an OSD is reset.
  49. */
  50. /*
  51. * calculate the mapping of a file extent onto an object, and fill out the
  52. * request accordingly. shorten extent as necessary if it crosses an
  53. * object boundary.
  54. *
  55. * fill osd op in request message.
  56. */
  57. static int calc_layout(struct ceph_file_layout *layout, u64 off, u64 *plen,
  58. u64 *objnum, u64 *objoff, u64 *objlen)
  59. {
  60. u64 orig_len = *plen;
  61. int r;
  62. /* object extent? */
  63. r = ceph_calc_file_object_mapping(layout, off, orig_len, objnum,
  64. objoff, objlen);
  65. if (r < 0)
  66. return r;
  67. if (*objlen < orig_len) {
  68. *plen = *objlen;
  69. dout(" skipping last %llu, final file extent %llu~%llu\n",
  70. orig_len - *plen, off, *plen);
  71. }
  72. dout("calc_layout objnum=%llx %llu~%llu\n", *objnum, *objoff, *objlen);
  73. return 0;
  74. }
  75. static void ceph_osd_data_init(struct ceph_osd_data *osd_data)
  76. {
  77. memset(osd_data, 0, sizeof (*osd_data));
  78. osd_data->type = CEPH_OSD_DATA_TYPE_NONE;
  79. }
  80. static void ceph_osd_data_pages_init(struct ceph_osd_data *osd_data,
  81. struct page **pages, u64 length, u32 alignment,
  82. bool pages_from_pool, bool own_pages)
  83. {
  84. osd_data->type = CEPH_OSD_DATA_TYPE_PAGES;
  85. osd_data->pages = pages;
  86. osd_data->length = length;
  87. osd_data->alignment = alignment;
  88. osd_data->pages_from_pool = pages_from_pool;
  89. osd_data->own_pages = own_pages;
  90. }
  91. static void ceph_osd_data_pagelist_init(struct ceph_osd_data *osd_data,
  92. struct ceph_pagelist *pagelist)
  93. {
  94. osd_data->type = CEPH_OSD_DATA_TYPE_PAGELIST;
  95. osd_data->pagelist = pagelist;
  96. }
  97. #ifdef CONFIG_BLOCK
  98. static void ceph_osd_data_bio_init(struct ceph_osd_data *osd_data,
  99. struct bio *bio, size_t bio_length)
  100. {
  101. osd_data->type = CEPH_OSD_DATA_TYPE_BIO;
  102. osd_data->bio = bio;
  103. osd_data->bio_length = bio_length;
  104. }
  105. #endif /* CONFIG_BLOCK */
  106. #define osd_req_op_data(oreq, whch, typ, fld) \
  107. ({ \
  108. BUG_ON(whch >= (oreq)->r_num_ops); \
  109. &(oreq)->r_ops[whch].typ.fld; \
  110. })
  111. static struct ceph_osd_data *
  112. osd_req_op_raw_data_in(struct ceph_osd_request *osd_req, unsigned int which)
  113. {
  114. BUG_ON(which >= osd_req->r_num_ops);
  115. return &osd_req->r_ops[which].raw_data_in;
  116. }
  117. struct ceph_osd_data *
  118. osd_req_op_extent_osd_data(struct ceph_osd_request *osd_req,
  119. unsigned int which)
  120. {
  121. return osd_req_op_data(osd_req, which, extent, osd_data);
  122. }
  123. EXPORT_SYMBOL(osd_req_op_extent_osd_data);
  124. struct ceph_osd_data *
  125. osd_req_op_cls_response_data(struct ceph_osd_request *osd_req,
  126. unsigned int which)
  127. {
  128. return osd_req_op_data(osd_req, which, cls, response_data);
  129. }
  130. EXPORT_SYMBOL(osd_req_op_cls_response_data); /* ??? */
  131. void osd_req_op_raw_data_in_pages(struct ceph_osd_request *osd_req,
  132. unsigned int which, struct page **pages,
  133. u64 length, u32 alignment,
  134. bool pages_from_pool, bool own_pages)
  135. {
  136. struct ceph_osd_data *osd_data;
  137. osd_data = osd_req_op_raw_data_in(osd_req, which);
  138. ceph_osd_data_pages_init(osd_data, pages, length, alignment,
  139. pages_from_pool, own_pages);
  140. }
  141. EXPORT_SYMBOL(osd_req_op_raw_data_in_pages);
  142. void osd_req_op_extent_osd_data_pages(struct ceph_osd_request *osd_req,
  143. unsigned int which, struct page **pages,
  144. u64 length, u32 alignment,
  145. bool pages_from_pool, bool own_pages)
  146. {
  147. struct ceph_osd_data *osd_data;
  148. osd_data = osd_req_op_data(osd_req, which, extent, osd_data);
  149. ceph_osd_data_pages_init(osd_data, pages, length, alignment,
  150. pages_from_pool, own_pages);
  151. }
  152. EXPORT_SYMBOL(osd_req_op_extent_osd_data_pages);
  153. void osd_req_op_extent_osd_data_pagelist(struct ceph_osd_request *osd_req,
  154. unsigned int which, struct ceph_pagelist *pagelist)
  155. {
  156. struct ceph_osd_data *osd_data;
  157. osd_data = osd_req_op_data(osd_req, which, extent, osd_data);
  158. ceph_osd_data_pagelist_init(osd_data, pagelist);
  159. }
  160. EXPORT_SYMBOL(osd_req_op_extent_osd_data_pagelist);
  161. #ifdef CONFIG_BLOCK
  162. void osd_req_op_extent_osd_data_bio(struct ceph_osd_request *osd_req,
  163. unsigned int which, struct bio *bio, size_t bio_length)
  164. {
  165. struct ceph_osd_data *osd_data;
  166. osd_data = osd_req_op_data(osd_req, which, extent, osd_data);
  167. ceph_osd_data_bio_init(osd_data, bio, bio_length);
  168. }
  169. EXPORT_SYMBOL(osd_req_op_extent_osd_data_bio);
  170. #endif /* CONFIG_BLOCK */
  171. static void osd_req_op_cls_request_info_pagelist(
  172. struct ceph_osd_request *osd_req,
  173. unsigned int which, struct ceph_pagelist *pagelist)
  174. {
  175. struct ceph_osd_data *osd_data;
  176. osd_data = osd_req_op_data(osd_req, which, cls, request_info);
  177. ceph_osd_data_pagelist_init(osd_data, pagelist);
  178. }
  179. void osd_req_op_cls_request_data_pagelist(
  180. struct ceph_osd_request *osd_req,
  181. unsigned int which, struct ceph_pagelist *pagelist)
  182. {
  183. struct ceph_osd_data *osd_data;
  184. osd_data = osd_req_op_data(osd_req, which, cls, request_data);
  185. ceph_osd_data_pagelist_init(osd_data, pagelist);
  186. }
  187. EXPORT_SYMBOL(osd_req_op_cls_request_data_pagelist);
  188. void osd_req_op_cls_request_data_pages(struct ceph_osd_request *osd_req,
  189. unsigned int which, struct page **pages, u64 length,
  190. u32 alignment, bool pages_from_pool, bool own_pages)
  191. {
  192. struct ceph_osd_data *osd_data;
  193. osd_data = osd_req_op_data(osd_req, which, cls, request_data);
  194. ceph_osd_data_pages_init(osd_data, pages, length, alignment,
  195. pages_from_pool, own_pages);
  196. }
  197. EXPORT_SYMBOL(osd_req_op_cls_request_data_pages);
  198. void osd_req_op_cls_response_data_pages(struct ceph_osd_request *osd_req,
  199. unsigned int which, struct page **pages, u64 length,
  200. u32 alignment, bool pages_from_pool, bool own_pages)
  201. {
  202. struct ceph_osd_data *osd_data;
  203. osd_data = osd_req_op_data(osd_req, which, cls, response_data);
  204. ceph_osd_data_pages_init(osd_data, pages, length, alignment,
  205. pages_from_pool, own_pages);
  206. }
  207. EXPORT_SYMBOL(osd_req_op_cls_response_data_pages);
  208. static u64 ceph_osd_data_length(struct ceph_osd_data *osd_data)
  209. {
  210. switch (osd_data->type) {
  211. case CEPH_OSD_DATA_TYPE_NONE:
  212. return 0;
  213. case CEPH_OSD_DATA_TYPE_PAGES:
  214. return osd_data->length;
  215. case CEPH_OSD_DATA_TYPE_PAGELIST:
  216. return (u64)osd_data->pagelist->length;
  217. #ifdef CONFIG_BLOCK
  218. case CEPH_OSD_DATA_TYPE_BIO:
  219. return (u64)osd_data->bio_length;
  220. #endif /* CONFIG_BLOCK */
  221. default:
  222. WARN(true, "unrecognized data type %d\n", (int)osd_data->type);
  223. return 0;
  224. }
  225. }
  226. static void ceph_osd_data_release(struct ceph_osd_data *osd_data)
  227. {
  228. if (osd_data->type == CEPH_OSD_DATA_TYPE_PAGES && osd_data->own_pages) {
  229. int num_pages;
  230. num_pages = calc_pages_for((u64)osd_data->alignment,
  231. (u64)osd_data->length);
  232. ceph_release_page_vector(osd_data->pages, num_pages);
  233. }
  234. ceph_osd_data_init(osd_data);
  235. }
  236. static void osd_req_op_data_release(struct ceph_osd_request *osd_req,
  237. unsigned int which)
  238. {
  239. struct ceph_osd_req_op *op;
  240. BUG_ON(which >= osd_req->r_num_ops);
  241. op = &osd_req->r_ops[which];
  242. switch (op->op) {
  243. case CEPH_OSD_OP_READ:
  244. case CEPH_OSD_OP_WRITE:
  245. ceph_osd_data_release(&op->extent.osd_data);
  246. break;
  247. case CEPH_OSD_OP_CALL:
  248. ceph_osd_data_release(&op->cls.request_info);
  249. ceph_osd_data_release(&op->cls.request_data);
  250. ceph_osd_data_release(&op->cls.response_data);
  251. break;
  252. default:
  253. break;
  254. }
  255. }
  256. /*
  257. * requests
  258. */
  259. static void ceph_osdc_release_request(struct kref *kref)
  260. {
  261. struct ceph_osd_request *req = container_of(kref,
  262. struct ceph_osd_request, r_kref);
  263. unsigned int which;
  264. dout("%s %p (r_request %p r_reply %p)\n", __func__, req,
  265. req->r_request, req->r_reply);
  266. WARN_ON(!RB_EMPTY_NODE(&req->r_node));
  267. WARN_ON(!list_empty(&req->r_req_lru_item));
  268. WARN_ON(!list_empty(&req->r_osd_item));
  269. WARN_ON(!list_empty(&req->r_linger_item));
  270. WARN_ON(!list_empty(&req->r_linger_osd_item));
  271. WARN_ON(req->r_osd);
  272. if (req->r_request)
  273. ceph_msg_put(req->r_request);
  274. if (req->r_reply) {
  275. ceph_msg_revoke_incoming(req->r_reply);
  276. ceph_msg_put(req->r_reply);
  277. }
  278. for (which = 0; which < req->r_num_ops; which++)
  279. osd_req_op_data_release(req, which);
  280. ceph_put_snap_context(req->r_snapc);
  281. if (req->r_mempool)
  282. mempool_free(req, req->r_osdc->req_mempool);
  283. else
  284. kmem_cache_free(ceph_osd_request_cache, req);
  285. }
  286. void ceph_osdc_get_request(struct ceph_osd_request *req)
  287. {
  288. dout("%s %p (was %d)\n", __func__, req,
  289. atomic_read(&req->r_kref.refcount));
  290. kref_get(&req->r_kref);
  291. }
  292. EXPORT_SYMBOL(ceph_osdc_get_request);
  293. void ceph_osdc_put_request(struct ceph_osd_request *req)
  294. {
  295. dout("%s %p (was %d)\n", __func__, req,
  296. atomic_read(&req->r_kref.refcount));
  297. kref_put(&req->r_kref, ceph_osdc_release_request);
  298. }
  299. EXPORT_SYMBOL(ceph_osdc_put_request);
  300. struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc,
  301. struct ceph_snap_context *snapc,
  302. unsigned int num_ops,
  303. bool use_mempool,
  304. gfp_t gfp_flags)
  305. {
  306. struct ceph_osd_request *req;
  307. struct ceph_msg *msg;
  308. size_t msg_size;
  309. BUILD_BUG_ON(CEPH_OSD_MAX_OP > U16_MAX);
  310. BUG_ON(num_ops > CEPH_OSD_MAX_OP);
  311. msg_size = 4 + 4 + 8 + 8 + 4+8;
  312. msg_size += 2 + 4 + 8 + 4 + 4; /* oloc */
  313. msg_size += 1 + 8 + 4 + 4; /* pg_t */
  314. msg_size += 4 + CEPH_MAX_OID_NAME_LEN; /* oid */
  315. msg_size += 2 + num_ops*sizeof(struct ceph_osd_op);
  316. msg_size += 8; /* snapid */
  317. msg_size += 8; /* snap_seq */
  318. msg_size += 8 * (snapc ? snapc->num_snaps : 0); /* snaps */
  319. msg_size += 4;
  320. if (use_mempool) {
  321. req = mempool_alloc(osdc->req_mempool, gfp_flags);
  322. memset(req, 0, sizeof(*req));
  323. } else {
  324. req = kmem_cache_zalloc(ceph_osd_request_cache, gfp_flags);
  325. }
  326. if (req == NULL)
  327. return NULL;
  328. req->r_osdc = osdc;
  329. req->r_mempool = use_mempool;
  330. req->r_num_ops = num_ops;
  331. kref_init(&req->r_kref);
  332. init_completion(&req->r_completion);
  333. init_completion(&req->r_safe_completion);
  334. RB_CLEAR_NODE(&req->r_node);
  335. INIT_LIST_HEAD(&req->r_unsafe_item);
  336. INIT_LIST_HEAD(&req->r_linger_item);
  337. INIT_LIST_HEAD(&req->r_linger_osd_item);
  338. INIT_LIST_HEAD(&req->r_req_lru_item);
  339. INIT_LIST_HEAD(&req->r_osd_item);
  340. req->r_base_oloc.pool = -1;
  341. req->r_target_oloc.pool = -1;
  342. /* create reply message */
  343. if (use_mempool)
  344. msg = ceph_msgpool_get(&osdc->msgpool_op_reply, 0);
  345. else
  346. msg = ceph_msg_new(CEPH_MSG_OSD_OPREPLY,
  347. OSD_OPREPLY_FRONT_LEN, gfp_flags, true);
  348. if (!msg) {
  349. ceph_osdc_put_request(req);
  350. return NULL;
  351. }
  352. req->r_reply = msg;
  353. /* create request message; allow space for oid */
  354. if (use_mempool)
  355. msg = ceph_msgpool_get(&osdc->msgpool_op, 0);
  356. else
  357. msg = ceph_msg_new(CEPH_MSG_OSD_OP, msg_size, gfp_flags, true);
  358. if (!msg) {
  359. ceph_osdc_put_request(req);
  360. return NULL;
  361. }
  362. memset(msg->front.iov_base, 0, msg->front.iov_len);
  363. req->r_request = msg;
  364. return req;
  365. }
  366. EXPORT_SYMBOL(ceph_osdc_alloc_request);
  367. static bool osd_req_opcode_valid(u16 opcode)
  368. {
  369. switch (opcode) {
  370. #define GENERATE_CASE(op, opcode, str) case CEPH_OSD_OP_##op: return true;
  371. __CEPH_FORALL_OSD_OPS(GENERATE_CASE)
  372. #undef GENERATE_CASE
  373. default:
  374. return false;
  375. }
  376. }
  377. /*
  378. * This is an osd op init function for opcodes that have no data or
  379. * other information associated with them. It also serves as a
  380. * common init routine for all the other init functions, below.
  381. */
  382. static struct ceph_osd_req_op *
  383. _osd_req_op_init(struct ceph_osd_request *osd_req, unsigned int which,
  384. u16 opcode)
  385. {
  386. struct ceph_osd_req_op *op;
  387. BUG_ON(which >= osd_req->r_num_ops);
  388. BUG_ON(!osd_req_opcode_valid(opcode));
  389. op = &osd_req->r_ops[which];
  390. memset(op, 0, sizeof (*op));
  391. op->op = opcode;
  392. return op;
  393. }
  394. void osd_req_op_init(struct ceph_osd_request *osd_req,
  395. unsigned int which, u16 opcode)
  396. {
  397. (void)_osd_req_op_init(osd_req, which, opcode);
  398. }
  399. EXPORT_SYMBOL(osd_req_op_init);
  400. void osd_req_op_extent_init(struct ceph_osd_request *osd_req,
  401. unsigned int which, u16 opcode,
  402. u64 offset, u64 length,
  403. u64 truncate_size, u32 truncate_seq)
  404. {
  405. struct ceph_osd_req_op *op = _osd_req_op_init(osd_req, which, opcode);
  406. size_t payload_len = 0;
  407. BUG_ON(opcode != CEPH_OSD_OP_READ && opcode != CEPH_OSD_OP_WRITE &&
  408. opcode != CEPH_OSD_OP_DELETE && opcode != CEPH_OSD_OP_ZERO &&
  409. opcode != CEPH_OSD_OP_TRUNCATE);
  410. op->extent.offset = offset;
  411. op->extent.length = length;
  412. op->extent.truncate_size = truncate_size;
  413. op->extent.truncate_seq = truncate_seq;
  414. if (opcode == CEPH_OSD_OP_WRITE)
  415. payload_len += length;
  416. op->payload_len = payload_len;
  417. }
  418. EXPORT_SYMBOL(osd_req_op_extent_init);
  419. void osd_req_op_extent_update(struct ceph_osd_request *osd_req,
  420. unsigned int which, u64 length)
  421. {
  422. struct ceph_osd_req_op *op;
  423. u64 previous;
  424. BUG_ON(which >= osd_req->r_num_ops);
  425. op = &osd_req->r_ops[which];
  426. previous = op->extent.length;
  427. if (length == previous)
  428. return; /* Nothing to do */
  429. BUG_ON(length > previous);
  430. op->extent.length = length;
  431. op->payload_len -= previous - length;
  432. }
  433. EXPORT_SYMBOL(osd_req_op_extent_update);
  434. void osd_req_op_cls_init(struct ceph_osd_request *osd_req, unsigned int which,
  435. u16 opcode, const char *class, const char *method)
  436. {
  437. struct ceph_osd_req_op *op = _osd_req_op_init(osd_req, which, opcode);
  438. struct ceph_pagelist *pagelist;
  439. size_t payload_len = 0;
  440. size_t size;
  441. BUG_ON(opcode != CEPH_OSD_OP_CALL);
  442. pagelist = kmalloc(sizeof (*pagelist), GFP_NOFS);
  443. BUG_ON(!pagelist);
  444. ceph_pagelist_init(pagelist);
  445. op->cls.class_name = class;
  446. size = strlen(class);
  447. BUG_ON(size > (size_t) U8_MAX);
  448. op->cls.class_len = size;
  449. ceph_pagelist_append(pagelist, class, size);
  450. payload_len += size;
  451. op->cls.method_name = method;
  452. size = strlen(method);
  453. BUG_ON(size > (size_t) U8_MAX);
  454. op->cls.method_len = size;
  455. ceph_pagelist_append(pagelist, method, size);
  456. payload_len += size;
  457. osd_req_op_cls_request_info_pagelist(osd_req, which, pagelist);
  458. op->cls.argc = 0; /* currently unused */
  459. op->payload_len = payload_len;
  460. }
  461. EXPORT_SYMBOL(osd_req_op_cls_init);
  462. void osd_req_op_watch_init(struct ceph_osd_request *osd_req,
  463. unsigned int which, u16 opcode,
  464. u64 cookie, u64 version, int flag)
  465. {
  466. struct ceph_osd_req_op *op = _osd_req_op_init(osd_req, which, opcode);
  467. BUG_ON(opcode != CEPH_OSD_OP_NOTIFY_ACK && opcode != CEPH_OSD_OP_WATCH);
  468. op->watch.cookie = cookie;
  469. op->watch.ver = version;
  470. if (opcode == CEPH_OSD_OP_WATCH && flag)
  471. op->watch.flag = (u8)1;
  472. }
  473. EXPORT_SYMBOL(osd_req_op_watch_init);
  474. void osd_req_op_alloc_hint_init(struct ceph_osd_request *osd_req,
  475. unsigned int which,
  476. u64 expected_object_size,
  477. u64 expected_write_size)
  478. {
  479. struct ceph_osd_req_op *op = _osd_req_op_init(osd_req, which,
  480. CEPH_OSD_OP_SETALLOCHINT);
  481. op->alloc_hint.expected_object_size = expected_object_size;
  482. op->alloc_hint.expected_write_size = expected_write_size;
  483. /*
  484. * CEPH_OSD_OP_SETALLOCHINT op is advisory and therefore deemed
  485. * not worth a feature bit. Set FAILOK per-op flag to make
  486. * sure older osds don't trip over an unsupported opcode.
  487. */
  488. op->flags |= CEPH_OSD_OP_FLAG_FAILOK;
  489. }
  490. EXPORT_SYMBOL(osd_req_op_alloc_hint_init);
  491. static void ceph_osdc_msg_data_add(struct ceph_msg *msg,
  492. struct ceph_osd_data *osd_data)
  493. {
  494. u64 length = ceph_osd_data_length(osd_data);
  495. if (osd_data->type == CEPH_OSD_DATA_TYPE_PAGES) {
  496. BUG_ON(length > (u64) SIZE_MAX);
  497. if (length)
  498. ceph_msg_data_add_pages(msg, osd_data->pages,
  499. length, osd_data->alignment);
  500. } else if (osd_data->type == CEPH_OSD_DATA_TYPE_PAGELIST) {
  501. BUG_ON(!length);
  502. ceph_msg_data_add_pagelist(msg, osd_data->pagelist);
  503. #ifdef CONFIG_BLOCK
  504. } else if (osd_data->type == CEPH_OSD_DATA_TYPE_BIO) {
  505. ceph_msg_data_add_bio(msg, osd_data->bio, length);
  506. #endif
  507. } else {
  508. BUG_ON(osd_data->type != CEPH_OSD_DATA_TYPE_NONE);
  509. }
  510. }
  511. static u64 osd_req_encode_op(struct ceph_osd_request *req,
  512. struct ceph_osd_op *dst, unsigned int which)
  513. {
  514. struct ceph_osd_req_op *src;
  515. struct ceph_osd_data *osd_data;
  516. u64 request_data_len = 0;
  517. u64 data_length;
  518. BUG_ON(which >= req->r_num_ops);
  519. src = &req->r_ops[which];
  520. if (WARN_ON(!osd_req_opcode_valid(src->op))) {
  521. pr_err("unrecognized osd opcode %d\n", src->op);
  522. return 0;
  523. }
  524. switch (src->op) {
  525. case CEPH_OSD_OP_STAT:
  526. osd_data = &src->raw_data_in;
  527. ceph_osdc_msg_data_add(req->r_reply, osd_data);
  528. break;
  529. case CEPH_OSD_OP_READ:
  530. case CEPH_OSD_OP_WRITE:
  531. case CEPH_OSD_OP_ZERO:
  532. case CEPH_OSD_OP_DELETE:
  533. case CEPH_OSD_OP_TRUNCATE:
  534. if (src->op == CEPH_OSD_OP_WRITE)
  535. request_data_len = src->extent.length;
  536. dst->extent.offset = cpu_to_le64(src->extent.offset);
  537. dst->extent.length = cpu_to_le64(src->extent.length);
  538. dst->extent.truncate_size =
  539. cpu_to_le64(src->extent.truncate_size);
  540. dst->extent.truncate_seq =
  541. cpu_to_le32(src->extent.truncate_seq);
  542. osd_data = &src->extent.osd_data;
  543. if (src->op == CEPH_OSD_OP_WRITE)
  544. ceph_osdc_msg_data_add(req->r_request, osd_data);
  545. else
  546. ceph_osdc_msg_data_add(req->r_reply, osd_data);
  547. break;
  548. case CEPH_OSD_OP_CALL:
  549. dst->cls.class_len = src->cls.class_len;
  550. dst->cls.method_len = src->cls.method_len;
  551. osd_data = &src->cls.request_info;
  552. ceph_osdc_msg_data_add(req->r_request, osd_data);
  553. BUG_ON(osd_data->type != CEPH_OSD_DATA_TYPE_PAGELIST);
  554. request_data_len = osd_data->pagelist->length;
  555. osd_data = &src->cls.request_data;
  556. data_length = ceph_osd_data_length(osd_data);
  557. if (data_length) {
  558. BUG_ON(osd_data->type == CEPH_OSD_DATA_TYPE_NONE);
  559. dst->cls.indata_len = cpu_to_le32(data_length);
  560. ceph_osdc_msg_data_add(req->r_request, osd_data);
  561. src->payload_len += data_length;
  562. request_data_len += data_length;
  563. }
  564. osd_data = &src->cls.response_data;
  565. ceph_osdc_msg_data_add(req->r_reply, osd_data);
  566. break;
  567. case CEPH_OSD_OP_STARTSYNC:
  568. break;
  569. case CEPH_OSD_OP_NOTIFY_ACK:
  570. case CEPH_OSD_OP_WATCH:
  571. dst->watch.cookie = cpu_to_le64(src->watch.cookie);
  572. dst->watch.ver = cpu_to_le64(src->watch.ver);
  573. dst->watch.flag = src->watch.flag;
  574. break;
  575. case CEPH_OSD_OP_SETALLOCHINT:
  576. dst->alloc_hint.expected_object_size =
  577. cpu_to_le64(src->alloc_hint.expected_object_size);
  578. dst->alloc_hint.expected_write_size =
  579. cpu_to_le64(src->alloc_hint.expected_write_size);
  580. break;
  581. default:
  582. pr_err("unsupported osd opcode %s\n",
  583. ceph_osd_op_name(src->op));
  584. WARN_ON(1);
  585. return 0;
  586. }
  587. dst->op = cpu_to_le16(src->op);
  588. dst->flags = cpu_to_le32(src->flags);
  589. dst->payload_len = cpu_to_le32(src->payload_len);
  590. return request_data_len;
  591. }
  592. /*
  593. * build new request AND message, calculate layout, and adjust file
  594. * extent as needed.
  595. *
  596. * if the file was recently truncated, we include information about its
  597. * old and new size so that the object can be updated appropriately. (we
  598. * avoid synchronously deleting truncated objects because it's slow.)
  599. *
  600. * if @do_sync, include a 'startsync' command so that the osd will flush
  601. * data quickly.
  602. */
  603. struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc,
  604. struct ceph_file_layout *layout,
  605. struct ceph_vino vino,
  606. u64 off, u64 *plen, int num_ops,
  607. int opcode, int flags,
  608. struct ceph_snap_context *snapc,
  609. u32 truncate_seq,
  610. u64 truncate_size,
  611. bool use_mempool)
  612. {
  613. struct ceph_osd_request *req;
  614. u64 objnum = 0;
  615. u64 objoff = 0;
  616. u64 objlen = 0;
  617. u32 object_size;
  618. u64 object_base;
  619. int r;
  620. BUG_ON(opcode != CEPH_OSD_OP_READ && opcode != CEPH_OSD_OP_WRITE &&
  621. opcode != CEPH_OSD_OP_DELETE && opcode != CEPH_OSD_OP_ZERO &&
  622. opcode != CEPH_OSD_OP_TRUNCATE);
  623. req = ceph_osdc_alloc_request(osdc, snapc, num_ops, use_mempool,
  624. GFP_NOFS);
  625. if (!req)
  626. return ERR_PTR(-ENOMEM);
  627. req->r_flags = flags;
  628. /* calculate max write size */
  629. r = calc_layout(layout, off, plen, &objnum, &objoff, &objlen);
  630. if (r < 0) {
  631. ceph_osdc_put_request(req);
  632. return ERR_PTR(r);
  633. }
  634. object_size = le32_to_cpu(layout->fl_object_size);
  635. object_base = off - objoff;
  636. if (!(truncate_seq == 1 && truncate_size == -1ULL)) {
  637. if (truncate_size <= object_base) {
  638. truncate_size = 0;
  639. } else {
  640. truncate_size -= object_base;
  641. if (truncate_size > object_size)
  642. truncate_size = object_size;
  643. }
  644. }
  645. osd_req_op_extent_init(req, 0, opcode, objoff, objlen,
  646. truncate_size, truncate_seq);
  647. /*
  648. * A second op in the ops array means the caller wants to
  649. * also issue a include a 'startsync' command so that the
  650. * osd will flush data quickly.
  651. */
  652. if (num_ops > 1)
  653. osd_req_op_init(req, 1, CEPH_OSD_OP_STARTSYNC);
  654. req->r_base_oloc.pool = ceph_file_layout_pg_pool(*layout);
  655. snprintf(req->r_base_oid.name, sizeof(req->r_base_oid.name),
  656. "%llx.%08llx", vino.ino, objnum);
  657. req->r_base_oid.name_len = strlen(req->r_base_oid.name);
  658. return req;
  659. }
  660. EXPORT_SYMBOL(ceph_osdc_new_request);
  661. /*
  662. * We keep osd requests in an rbtree, sorted by ->r_tid.
  663. */
  664. static void __insert_request(struct ceph_osd_client *osdc,
  665. struct ceph_osd_request *new)
  666. {
  667. struct rb_node **p = &osdc->requests.rb_node;
  668. struct rb_node *parent = NULL;
  669. struct ceph_osd_request *req = NULL;
  670. while (*p) {
  671. parent = *p;
  672. req = rb_entry(parent, struct ceph_osd_request, r_node);
  673. if (new->r_tid < req->r_tid)
  674. p = &(*p)->rb_left;
  675. else if (new->r_tid > req->r_tid)
  676. p = &(*p)->rb_right;
  677. else
  678. BUG();
  679. }
  680. rb_link_node(&new->r_node, parent, p);
  681. rb_insert_color(&new->r_node, &osdc->requests);
  682. }
  683. static struct ceph_osd_request *__lookup_request(struct ceph_osd_client *osdc,
  684. u64 tid)
  685. {
  686. struct ceph_osd_request *req;
  687. struct rb_node *n = osdc->requests.rb_node;
  688. while (n) {
  689. req = rb_entry(n, struct ceph_osd_request, r_node);
  690. if (tid < req->r_tid)
  691. n = n->rb_left;
  692. else if (tid > req->r_tid)
  693. n = n->rb_right;
  694. else
  695. return req;
  696. }
  697. return NULL;
  698. }
  699. static struct ceph_osd_request *
  700. __lookup_request_ge(struct ceph_osd_client *osdc,
  701. u64 tid)
  702. {
  703. struct ceph_osd_request *req;
  704. struct rb_node *n = osdc->requests.rb_node;
  705. while (n) {
  706. req = rb_entry(n, struct ceph_osd_request, r_node);
  707. if (tid < req->r_tid) {
  708. if (!n->rb_left)
  709. return req;
  710. n = n->rb_left;
  711. } else if (tid > req->r_tid) {
  712. n = n->rb_right;
  713. } else {
  714. return req;
  715. }
  716. }
  717. return NULL;
  718. }
  719. static void __kick_linger_request(struct ceph_osd_request *req)
  720. {
  721. struct ceph_osd_client *osdc = req->r_osdc;
  722. struct ceph_osd *osd = req->r_osd;
  723. /*
  724. * Linger requests need to be resent with a new tid to avoid
  725. * the dup op detection logic on the OSDs. Achieve this with
  726. * a re-register dance instead of open-coding.
  727. */
  728. ceph_osdc_get_request(req);
  729. if (!list_empty(&req->r_linger_item))
  730. __unregister_linger_request(osdc, req);
  731. else
  732. __unregister_request(osdc, req);
  733. __register_request(osdc, req);
  734. ceph_osdc_put_request(req);
  735. /*
  736. * Unless request has been registered as both normal and
  737. * lingering, __unregister{,_linger}_request clears r_osd.
  738. * However, here we need to preserve r_osd to make sure we
  739. * requeue on the same OSD.
  740. */
  741. WARN_ON(req->r_osd || !osd);
  742. req->r_osd = osd;
  743. dout("%s requeueing %p tid %llu\n", __func__, req, req->r_tid);
  744. __enqueue_request(req);
  745. }
  746. /*
  747. * Resubmit requests pending on the given osd.
  748. */
  749. static void __kick_osd_requests(struct ceph_osd_client *osdc,
  750. struct ceph_osd *osd)
  751. {
  752. struct ceph_osd_request *req, *nreq;
  753. LIST_HEAD(resend);
  754. LIST_HEAD(resend_linger);
  755. int err;
  756. dout("%s osd%d\n", __func__, osd->o_osd);
  757. err = __reset_osd(osdc, osd);
  758. if (err)
  759. return;
  760. /*
  761. * Build up a list of requests to resend by traversing the
  762. * osd's list of requests. Requests for a given object are
  763. * sent in tid order, and that is also the order they're
  764. * kept on this list. Therefore all requests that are in
  765. * flight will be found first, followed by all requests that
  766. * have not yet been sent. And to resend requests while
  767. * preserving this order we will want to put any sent
  768. * requests back on the front of the osd client's unsent
  769. * list.
  770. *
  771. * So we build a separate ordered list of already-sent
  772. * requests for the affected osd and splice it onto the
  773. * front of the osd client's unsent list. Once we've seen a
  774. * request that has not yet been sent we're done. Those
  775. * requests are already sitting right where they belong.
  776. */
  777. list_for_each_entry(req, &osd->o_requests, r_osd_item) {
  778. if (!req->r_sent)
  779. break;
  780. if (!req->r_linger) {
  781. dout("%s requeueing %p tid %llu\n", __func__, req,
  782. req->r_tid);
  783. list_move_tail(&req->r_req_lru_item, &resend);
  784. req->r_flags |= CEPH_OSD_FLAG_RETRY;
  785. } else {
  786. list_move_tail(&req->r_req_lru_item, &resend_linger);
  787. }
  788. }
  789. list_splice(&resend, &osdc->req_unsent);
  790. /*
  791. * Both registered and not yet registered linger requests are
  792. * enqueued with a new tid on the same OSD. We add/move them
  793. * to req_unsent/o_requests at the end to keep things in tid
  794. * order.
  795. */
  796. list_for_each_entry_safe(req, nreq, &osd->o_linger_requests,
  797. r_linger_osd_item) {
  798. WARN_ON(!list_empty(&req->r_req_lru_item));
  799. __kick_linger_request(req);
  800. }
  801. list_for_each_entry_safe(req, nreq, &resend_linger, r_req_lru_item)
  802. __kick_linger_request(req);
  803. }
  804. /*
  805. * If the osd connection drops, we need to resubmit all requests.
  806. */
  807. static void osd_reset(struct ceph_connection *con)
  808. {
  809. struct ceph_osd *osd = con->private;
  810. struct ceph_osd_client *osdc;
  811. if (!osd)
  812. return;
  813. dout("osd_reset osd%d\n", osd->o_osd);
  814. osdc = osd->o_osdc;
  815. down_read(&osdc->map_sem);
  816. mutex_lock(&osdc->request_mutex);
  817. __kick_osd_requests(osdc, osd);
  818. __send_queued(osdc);
  819. mutex_unlock(&osdc->request_mutex);
  820. up_read(&osdc->map_sem);
  821. }
  822. /*
  823. * Track open sessions with osds.
  824. */
  825. static struct ceph_osd *create_osd(struct ceph_osd_client *osdc, int onum)
  826. {
  827. struct ceph_osd *osd;
  828. osd = kzalloc(sizeof(*osd), GFP_NOFS);
  829. if (!osd)
  830. return NULL;
  831. atomic_set(&osd->o_ref, 1);
  832. osd->o_osdc = osdc;
  833. osd->o_osd = onum;
  834. RB_CLEAR_NODE(&osd->o_node);
  835. INIT_LIST_HEAD(&osd->o_requests);
  836. INIT_LIST_HEAD(&osd->o_linger_requests);
  837. INIT_LIST_HEAD(&osd->o_osd_lru);
  838. osd->o_incarnation = 1;
  839. ceph_con_init(&osd->o_con, osd, &osd_con_ops, &osdc->client->msgr);
  840. INIT_LIST_HEAD(&osd->o_keepalive_item);
  841. return osd;
  842. }
  843. static struct ceph_osd *get_osd(struct ceph_osd *osd)
  844. {
  845. if (atomic_inc_not_zero(&osd->o_ref)) {
  846. dout("get_osd %p %d -> %d\n", osd, atomic_read(&osd->o_ref)-1,
  847. atomic_read(&osd->o_ref));
  848. return osd;
  849. } else {
  850. dout("get_osd %p FAIL\n", osd);
  851. return NULL;
  852. }
  853. }
  854. static void put_osd(struct ceph_osd *osd)
  855. {
  856. dout("put_osd %p %d -> %d\n", osd, atomic_read(&osd->o_ref),
  857. atomic_read(&osd->o_ref) - 1);
  858. if (atomic_dec_and_test(&osd->o_ref) && osd->o_auth.authorizer) {
  859. struct ceph_auth_client *ac = osd->o_osdc->client->monc.auth;
  860. ceph_auth_destroy_authorizer(ac, osd->o_auth.authorizer);
  861. kfree(osd);
  862. }
  863. }
  864. /*
  865. * remove an osd from our map
  866. */
  867. static void __remove_osd(struct ceph_osd_client *osdc, struct ceph_osd *osd)
  868. {
  869. dout("%s %p osd%d\n", __func__, osd, osd->o_osd);
  870. WARN_ON(!list_empty(&osd->o_requests));
  871. WARN_ON(!list_empty(&osd->o_linger_requests));
  872. list_del_init(&osd->o_osd_lru);
  873. rb_erase(&osd->o_node, &osdc->osds);
  874. RB_CLEAR_NODE(&osd->o_node);
  875. }
  876. static void remove_osd(struct ceph_osd_client *osdc, struct ceph_osd *osd)
  877. {
  878. dout("%s %p osd%d\n", __func__, osd, osd->o_osd);
  879. if (!RB_EMPTY_NODE(&osd->o_node)) {
  880. ceph_con_close(&osd->o_con);
  881. __remove_osd(osdc, osd);
  882. put_osd(osd);
  883. }
  884. }
  885. static void remove_all_osds(struct ceph_osd_client *osdc)
  886. {
  887. dout("%s %p\n", __func__, osdc);
  888. mutex_lock(&osdc->request_mutex);
  889. while (!RB_EMPTY_ROOT(&osdc->osds)) {
  890. struct ceph_osd *osd = rb_entry(rb_first(&osdc->osds),
  891. struct ceph_osd, o_node);
  892. remove_osd(osdc, osd);
  893. }
  894. mutex_unlock(&osdc->request_mutex);
  895. }
  896. static void __move_osd_to_lru(struct ceph_osd_client *osdc,
  897. struct ceph_osd *osd)
  898. {
  899. dout("%s %p\n", __func__, osd);
  900. BUG_ON(!list_empty(&osd->o_osd_lru));
  901. list_add_tail(&osd->o_osd_lru, &osdc->osd_lru);
  902. osd->lru_ttl = jiffies + osdc->client->options->osd_idle_ttl * HZ;
  903. }
  904. static void maybe_move_osd_to_lru(struct ceph_osd_client *osdc,
  905. struct ceph_osd *osd)
  906. {
  907. dout("%s %p\n", __func__, osd);
  908. if (list_empty(&osd->o_requests) &&
  909. list_empty(&osd->o_linger_requests))
  910. __move_osd_to_lru(osdc, osd);
  911. }
  912. static void __remove_osd_from_lru(struct ceph_osd *osd)
  913. {
  914. dout("__remove_osd_from_lru %p\n", osd);
  915. if (!list_empty(&osd->o_osd_lru))
  916. list_del_init(&osd->o_osd_lru);
  917. }
  918. static void remove_old_osds(struct ceph_osd_client *osdc)
  919. {
  920. struct ceph_osd *osd, *nosd;
  921. dout("__remove_old_osds %p\n", osdc);
  922. mutex_lock(&osdc->request_mutex);
  923. list_for_each_entry_safe(osd, nosd, &osdc->osd_lru, o_osd_lru) {
  924. if (time_before(jiffies, osd->lru_ttl))
  925. break;
  926. remove_osd(osdc, osd);
  927. }
  928. mutex_unlock(&osdc->request_mutex);
  929. }
  930. /*
  931. * reset osd connect
  932. */
  933. static int __reset_osd(struct ceph_osd_client *osdc, struct ceph_osd *osd)
  934. {
  935. struct ceph_entity_addr *peer_addr;
  936. dout("__reset_osd %p osd%d\n", osd, osd->o_osd);
  937. if (list_empty(&osd->o_requests) &&
  938. list_empty(&osd->o_linger_requests)) {
  939. remove_osd(osdc, osd);
  940. return -ENODEV;
  941. }
  942. peer_addr = &osdc->osdmap->osd_addr[osd->o_osd];
  943. if (!memcmp(peer_addr, &osd->o_con.peer_addr, sizeof (*peer_addr)) &&
  944. !ceph_con_opened(&osd->o_con)) {
  945. struct ceph_osd_request *req;
  946. dout("osd addr hasn't changed and connection never opened, "
  947. "letting msgr retry\n");
  948. /* touch each r_stamp for handle_timeout()'s benfit */
  949. list_for_each_entry(req, &osd->o_requests, r_osd_item)
  950. req->r_stamp = jiffies;
  951. return -EAGAIN;
  952. }
  953. ceph_con_close(&osd->o_con);
  954. ceph_con_open(&osd->o_con, CEPH_ENTITY_TYPE_OSD, osd->o_osd, peer_addr);
  955. osd->o_incarnation++;
  956. return 0;
  957. }
  958. static void __insert_osd(struct ceph_osd_client *osdc, struct ceph_osd *new)
  959. {
  960. struct rb_node **p = &osdc->osds.rb_node;
  961. struct rb_node *parent = NULL;
  962. struct ceph_osd *osd = NULL;
  963. dout("__insert_osd %p osd%d\n", new, new->o_osd);
  964. while (*p) {
  965. parent = *p;
  966. osd = rb_entry(parent, struct ceph_osd, o_node);
  967. if (new->o_osd < osd->o_osd)
  968. p = &(*p)->rb_left;
  969. else if (new->o_osd > osd->o_osd)
  970. p = &(*p)->rb_right;
  971. else
  972. BUG();
  973. }
  974. rb_link_node(&new->o_node, parent, p);
  975. rb_insert_color(&new->o_node, &osdc->osds);
  976. }
  977. static struct ceph_osd *__lookup_osd(struct ceph_osd_client *osdc, int o)
  978. {
  979. struct ceph_osd *osd;
  980. struct rb_node *n = osdc->osds.rb_node;
  981. while (n) {
  982. osd = rb_entry(n, struct ceph_osd, o_node);
  983. if (o < osd->o_osd)
  984. n = n->rb_left;
  985. else if (o > osd->o_osd)
  986. n = n->rb_right;
  987. else
  988. return osd;
  989. }
  990. return NULL;
  991. }
  992. static void __schedule_osd_timeout(struct ceph_osd_client *osdc)
  993. {
  994. schedule_delayed_work(&osdc->timeout_work,
  995. osdc->client->options->osd_keepalive_timeout * HZ);
  996. }
  997. static void __cancel_osd_timeout(struct ceph_osd_client *osdc)
  998. {
  999. cancel_delayed_work(&osdc->timeout_work);
  1000. }
  1001. /*
  1002. * Register request, assign tid. If this is the first request, set up
  1003. * the timeout event.
  1004. */
  1005. static void __register_request(struct ceph_osd_client *osdc,
  1006. struct ceph_osd_request *req)
  1007. {
  1008. req->r_tid = ++osdc->last_tid;
  1009. req->r_request->hdr.tid = cpu_to_le64(req->r_tid);
  1010. dout("__register_request %p tid %lld\n", req, req->r_tid);
  1011. __insert_request(osdc, req);
  1012. ceph_osdc_get_request(req);
  1013. osdc->num_requests++;
  1014. if (osdc->num_requests == 1) {
  1015. dout(" first request, scheduling timeout\n");
  1016. __schedule_osd_timeout(osdc);
  1017. }
  1018. }
  1019. /*
  1020. * called under osdc->request_mutex
  1021. */
  1022. static void __unregister_request(struct ceph_osd_client *osdc,
  1023. struct ceph_osd_request *req)
  1024. {
  1025. if (RB_EMPTY_NODE(&req->r_node)) {
  1026. dout("__unregister_request %p tid %lld not registered\n",
  1027. req, req->r_tid);
  1028. return;
  1029. }
  1030. dout("__unregister_request %p tid %lld\n", req, req->r_tid);
  1031. rb_erase(&req->r_node, &osdc->requests);
  1032. RB_CLEAR_NODE(&req->r_node);
  1033. osdc->num_requests--;
  1034. if (req->r_osd) {
  1035. /* make sure the original request isn't in flight. */
  1036. ceph_msg_revoke(req->r_request);
  1037. list_del_init(&req->r_osd_item);
  1038. maybe_move_osd_to_lru(osdc, req->r_osd);
  1039. if (list_empty(&req->r_linger_osd_item))
  1040. req->r_osd = NULL;
  1041. }
  1042. list_del_init(&req->r_req_lru_item);
  1043. ceph_osdc_put_request(req);
  1044. if (osdc->num_requests == 0) {
  1045. dout(" no requests, canceling timeout\n");
  1046. __cancel_osd_timeout(osdc);
  1047. }
  1048. }
  1049. /*
  1050. * Cancel a previously queued request message
  1051. */
  1052. static void __cancel_request(struct ceph_osd_request *req)
  1053. {
  1054. if (req->r_sent && req->r_osd) {
  1055. ceph_msg_revoke(req->r_request);
  1056. req->r_sent = 0;
  1057. }
  1058. }
  1059. static void __register_linger_request(struct ceph_osd_client *osdc,
  1060. struct ceph_osd_request *req)
  1061. {
  1062. dout("%s %p tid %llu\n", __func__, req, req->r_tid);
  1063. WARN_ON(!req->r_linger);
  1064. ceph_osdc_get_request(req);
  1065. list_add_tail(&req->r_linger_item, &osdc->req_linger);
  1066. if (req->r_osd)
  1067. list_add_tail(&req->r_linger_osd_item,
  1068. &req->r_osd->o_linger_requests);
  1069. }
  1070. static void __unregister_linger_request(struct ceph_osd_client *osdc,
  1071. struct ceph_osd_request *req)
  1072. {
  1073. WARN_ON(!req->r_linger);
  1074. if (list_empty(&req->r_linger_item)) {
  1075. dout("%s %p tid %llu not registered\n", __func__, req,
  1076. req->r_tid);
  1077. return;
  1078. }
  1079. dout("%s %p tid %llu\n", __func__, req, req->r_tid);
  1080. list_del_init(&req->r_linger_item);
  1081. if (req->r_osd) {
  1082. list_del_init(&req->r_linger_osd_item);
  1083. maybe_move_osd_to_lru(osdc, req->r_osd);
  1084. if (list_empty(&req->r_osd_item))
  1085. req->r_osd = NULL;
  1086. }
  1087. ceph_osdc_put_request(req);
  1088. }
  1089. void ceph_osdc_set_request_linger(struct ceph_osd_client *osdc,
  1090. struct ceph_osd_request *req)
  1091. {
  1092. if (!req->r_linger) {
  1093. dout("set_request_linger %p\n", req);
  1094. req->r_linger = 1;
  1095. }
  1096. }
  1097. EXPORT_SYMBOL(ceph_osdc_set_request_linger);
  1098. /*
  1099. * Returns whether a request should be blocked from being sent
  1100. * based on the current osdmap and osd_client settings.
  1101. *
  1102. * Caller should hold map_sem for read.
  1103. */
  1104. static bool __req_should_be_paused(struct ceph_osd_client *osdc,
  1105. struct ceph_osd_request *req)
  1106. {
  1107. bool pauserd = ceph_osdmap_flag(osdc->osdmap, CEPH_OSDMAP_PAUSERD);
  1108. bool pausewr = ceph_osdmap_flag(osdc->osdmap, CEPH_OSDMAP_PAUSEWR) ||
  1109. ceph_osdmap_flag(osdc->osdmap, CEPH_OSDMAP_FULL);
  1110. return (req->r_flags & CEPH_OSD_FLAG_READ && pauserd) ||
  1111. (req->r_flags & CEPH_OSD_FLAG_WRITE && pausewr);
  1112. }
  1113. /*
  1114. * Calculate mapping of a request to a PG. Takes tiering into account.
  1115. */
  1116. static int __calc_request_pg(struct ceph_osdmap *osdmap,
  1117. struct ceph_osd_request *req,
  1118. struct ceph_pg *pg_out)
  1119. {
  1120. bool need_check_tiering;
  1121. need_check_tiering = false;
  1122. if (req->r_target_oloc.pool == -1) {
  1123. req->r_target_oloc = req->r_base_oloc; /* struct */
  1124. need_check_tiering = true;
  1125. }
  1126. if (req->r_target_oid.name_len == 0) {
  1127. ceph_oid_copy(&req->r_target_oid, &req->r_base_oid);
  1128. need_check_tiering = true;
  1129. }
  1130. if (need_check_tiering &&
  1131. (req->r_flags & CEPH_OSD_FLAG_IGNORE_OVERLAY) == 0) {
  1132. struct ceph_pg_pool_info *pi;
  1133. pi = ceph_pg_pool_by_id(osdmap, req->r_target_oloc.pool);
  1134. if (pi) {
  1135. if ((req->r_flags & CEPH_OSD_FLAG_READ) &&
  1136. pi->read_tier >= 0)
  1137. req->r_target_oloc.pool = pi->read_tier;
  1138. if ((req->r_flags & CEPH_OSD_FLAG_WRITE) &&
  1139. pi->write_tier >= 0)
  1140. req->r_target_oloc.pool = pi->write_tier;
  1141. }
  1142. /* !pi is caught in ceph_oloc_oid_to_pg() */
  1143. }
  1144. return ceph_oloc_oid_to_pg(osdmap, &req->r_target_oloc,
  1145. &req->r_target_oid, pg_out);
  1146. }
  1147. static void __enqueue_request(struct ceph_osd_request *req)
  1148. {
  1149. struct ceph_osd_client *osdc = req->r_osdc;
  1150. dout("%s %p tid %llu to osd%d\n", __func__, req, req->r_tid,
  1151. req->r_osd ? req->r_osd->o_osd : -1);
  1152. if (req->r_osd) {
  1153. __remove_osd_from_lru(req->r_osd);
  1154. list_add_tail(&req->r_osd_item, &req->r_osd->o_requests);
  1155. list_move_tail(&req->r_req_lru_item, &osdc->req_unsent);
  1156. } else {
  1157. list_move_tail(&req->r_req_lru_item, &osdc->req_notarget);
  1158. }
  1159. }
  1160. /*
  1161. * Pick an osd (the first 'up' osd in the pg), allocate the osd struct
  1162. * (as needed), and set the request r_osd appropriately. If there is
  1163. * no up osd, set r_osd to NULL. Move the request to the appropriate list
  1164. * (unsent, homeless) or leave on in-flight lru.
  1165. *
  1166. * Return 0 if unchanged, 1 if changed, or negative on error.
  1167. *
  1168. * Caller should hold map_sem for read and request_mutex.
  1169. */
  1170. static int __map_request(struct ceph_osd_client *osdc,
  1171. struct ceph_osd_request *req, int force_resend)
  1172. {
  1173. struct ceph_pg pgid;
  1174. int acting[CEPH_PG_MAX_SIZE];
  1175. int num, o;
  1176. int err;
  1177. bool was_paused;
  1178. dout("map_request %p tid %lld\n", req, req->r_tid);
  1179. err = __calc_request_pg(osdc->osdmap, req, &pgid);
  1180. if (err) {
  1181. list_move(&req->r_req_lru_item, &osdc->req_notarget);
  1182. return err;
  1183. }
  1184. req->r_pgid = pgid;
  1185. num = ceph_calc_pg_acting(osdc->osdmap, pgid, acting, &o);
  1186. if (num < 0)
  1187. num = 0;
  1188. was_paused = req->r_paused;
  1189. req->r_paused = __req_should_be_paused(osdc, req);
  1190. if (was_paused && !req->r_paused)
  1191. force_resend = 1;
  1192. if ((!force_resend &&
  1193. req->r_osd && req->r_osd->o_osd == o &&
  1194. req->r_sent >= req->r_osd->o_incarnation &&
  1195. req->r_num_pg_osds == num &&
  1196. memcmp(req->r_pg_osds, acting, sizeof(acting[0])*num) == 0) ||
  1197. (req->r_osd == NULL && o == -1) ||
  1198. req->r_paused)
  1199. return 0; /* no change */
  1200. dout("map_request tid %llu pgid %lld.%x osd%d (was osd%d)\n",
  1201. req->r_tid, pgid.pool, pgid.seed, o,
  1202. req->r_osd ? req->r_osd->o_osd : -1);
  1203. /* record full pg acting set */
  1204. memcpy(req->r_pg_osds, acting, sizeof(acting[0]) * num);
  1205. req->r_num_pg_osds = num;
  1206. if (req->r_osd) {
  1207. __cancel_request(req);
  1208. list_del_init(&req->r_osd_item);
  1209. list_del_init(&req->r_linger_osd_item);
  1210. req->r_osd = NULL;
  1211. }
  1212. req->r_osd = __lookup_osd(osdc, o);
  1213. if (!req->r_osd && o >= 0) {
  1214. err = -ENOMEM;
  1215. req->r_osd = create_osd(osdc, o);
  1216. if (!req->r_osd) {
  1217. list_move(&req->r_req_lru_item, &osdc->req_notarget);
  1218. goto out;
  1219. }
  1220. dout("map_request osd %p is osd%d\n", req->r_osd, o);
  1221. __insert_osd(osdc, req->r_osd);
  1222. ceph_con_open(&req->r_osd->o_con,
  1223. CEPH_ENTITY_TYPE_OSD, o,
  1224. &osdc->osdmap->osd_addr[o]);
  1225. }
  1226. __enqueue_request(req);
  1227. err = 1; /* osd or pg changed */
  1228. out:
  1229. return err;
  1230. }
  1231. /*
  1232. * caller should hold map_sem (for read) and request_mutex
  1233. */
  1234. static void __send_request(struct ceph_osd_client *osdc,
  1235. struct ceph_osd_request *req)
  1236. {
  1237. void *p;
  1238. dout("send_request %p tid %llu to osd%d flags %d pg %lld.%x\n",
  1239. req, req->r_tid, req->r_osd->o_osd, req->r_flags,
  1240. (unsigned long long)req->r_pgid.pool, req->r_pgid.seed);
  1241. /* fill in message content that changes each time we send it */
  1242. put_unaligned_le32(osdc->osdmap->epoch, req->r_request_osdmap_epoch);
  1243. put_unaligned_le32(req->r_flags, req->r_request_flags);
  1244. put_unaligned_le64(req->r_target_oloc.pool, req->r_request_pool);
  1245. p = req->r_request_pgid;
  1246. ceph_encode_64(&p, req->r_pgid.pool);
  1247. ceph_encode_32(&p, req->r_pgid.seed);
  1248. put_unaligned_le64(1, req->r_request_attempts); /* FIXME */
  1249. memcpy(req->r_request_reassert_version, &req->r_reassert_version,
  1250. sizeof(req->r_reassert_version));
  1251. req->r_stamp = jiffies;
  1252. list_move_tail(&req->r_req_lru_item, &osdc->req_lru);
  1253. ceph_msg_get(req->r_request); /* send consumes a ref */
  1254. req->r_sent = req->r_osd->o_incarnation;
  1255. ceph_con_send(&req->r_osd->o_con, req->r_request);
  1256. }
  1257. /*
  1258. * Send any requests in the queue (req_unsent).
  1259. */
  1260. static void __send_queued(struct ceph_osd_client *osdc)
  1261. {
  1262. struct ceph_osd_request *req, *tmp;
  1263. dout("__send_queued\n");
  1264. list_for_each_entry_safe(req, tmp, &osdc->req_unsent, r_req_lru_item)
  1265. __send_request(osdc, req);
  1266. }
  1267. /*
  1268. * Caller should hold map_sem for read and request_mutex.
  1269. */
  1270. static int __ceph_osdc_start_request(struct ceph_osd_client *osdc,
  1271. struct ceph_osd_request *req,
  1272. bool nofail)
  1273. {
  1274. int rc;
  1275. __register_request(osdc, req);
  1276. req->r_sent = 0;
  1277. req->r_got_reply = 0;
  1278. rc = __map_request(osdc, req, 0);
  1279. if (rc < 0) {
  1280. if (nofail) {
  1281. dout("osdc_start_request failed map, "
  1282. " will retry %lld\n", req->r_tid);
  1283. rc = 0;
  1284. } else {
  1285. __unregister_request(osdc, req);
  1286. }
  1287. return rc;
  1288. }
  1289. if (req->r_osd == NULL) {
  1290. dout("send_request %p no up osds in pg\n", req);
  1291. ceph_monc_request_next_osdmap(&osdc->client->monc);
  1292. } else {
  1293. __send_queued(osdc);
  1294. }
  1295. return 0;
  1296. }
  1297. /*
  1298. * Timeout callback, called every N seconds when 1 or more osd
  1299. * requests has been active for more than N seconds. When this
  1300. * happens, we ping all OSDs with requests who have timed out to
  1301. * ensure any communications channel reset is detected. Reset the
  1302. * request timeouts another N seconds in the future as we go.
  1303. * Reschedule the timeout event another N seconds in future (unless
  1304. * there are no open requests).
  1305. */
  1306. static void handle_timeout(struct work_struct *work)
  1307. {
  1308. struct ceph_osd_client *osdc =
  1309. container_of(work, struct ceph_osd_client, timeout_work.work);
  1310. struct ceph_osd_request *req;
  1311. struct ceph_osd *osd;
  1312. unsigned long keepalive =
  1313. osdc->client->options->osd_keepalive_timeout * HZ;
  1314. struct list_head slow_osds;
  1315. dout("timeout\n");
  1316. down_read(&osdc->map_sem);
  1317. ceph_monc_request_next_osdmap(&osdc->client->monc);
  1318. mutex_lock(&osdc->request_mutex);
  1319. /*
  1320. * ping osds that are a bit slow. this ensures that if there
  1321. * is a break in the TCP connection we will notice, and reopen
  1322. * a connection with that osd (from the fault callback).
  1323. */
  1324. INIT_LIST_HEAD(&slow_osds);
  1325. list_for_each_entry(req, &osdc->req_lru, r_req_lru_item) {
  1326. if (time_before(jiffies, req->r_stamp + keepalive))
  1327. break;
  1328. osd = req->r_osd;
  1329. BUG_ON(!osd);
  1330. dout(" tid %llu is slow, will send keepalive on osd%d\n",
  1331. req->r_tid, osd->o_osd);
  1332. list_move_tail(&osd->o_keepalive_item, &slow_osds);
  1333. }
  1334. while (!list_empty(&slow_osds)) {
  1335. osd = list_entry(slow_osds.next, struct ceph_osd,
  1336. o_keepalive_item);
  1337. list_del_init(&osd->o_keepalive_item);
  1338. ceph_con_keepalive(&osd->o_con);
  1339. }
  1340. __schedule_osd_timeout(osdc);
  1341. __send_queued(osdc);
  1342. mutex_unlock(&osdc->request_mutex);
  1343. up_read(&osdc->map_sem);
  1344. }
  1345. static void handle_osds_timeout(struct work_struct *work)
  1346. {
  1347. struct ceph_osd_client *osdc =
  1348. container_of(work, struct ceph_osd_client,
  1349. osds_timeout_work.work);
  1350. unsigned long delay =
  1351. osdc->client->options->osd_idle_ttl * HZ >> 2;
  1352. dout("osds timeout\n");
  1353. down_read(&osdc->map_sem);
  1354. remove_old_osds(osdc);
  1355. up_read(&osdc->map_sem);
  1356. schedule_delayed_work(&osdc->osds_timeout_work,
  1357. round_jiffies_relative(delay));
  1358. }
  1359. static int ceph_oloc_decode(void **p, void *end,
  1360. struct ceph_object_locator *oloc)
  1361. {
  1362. u8 struct_v, struct_cv;
  1363. u32 len;
  1364. void *struct_end;
  1365. int ret = 0;
  1366. ceph_decode_need(p, end, 1 + 1 + 4, e_inval);
  1367. struct_v = ceph_decode_8(p);
  1368. struct_cv = ceph_decode_8(p);
  1369. if (struct_v < 3) {
  1370. pr_warn("got v %d < 3 cv %d of ceph_object_locator\n",
  1371. struct_v, struct_cv);
  1372. goto e_inval;
  1373. }
  1374. if (struct_cv > 6) {
  1375. pr_warn("got v %d cv %d > 6 of ceph_object_locator\n",
  1376. struct_v, struct_cv);
  1377. goto e_inval;
  1378. }
  1379. len = ceph_decode_32(p);
  1380. ceph_decode_need(p, end, len, e_inval);
  1381. struct_end = *p + len;
  1382. oloc->pool = ceph_decode_64(p);
  1383. *p += 4; /* skip preferred */
  1384. len = ceph_decode_32(p);
  1385. if (len > 0) {
  1386. pr_warn("ceph_object_locator::key is set\n");
  1387. goto e_inval;
  1388. }
  1389. if (struct_v >= 5) {
  1390. len = ceph_decode_32(p);
  1391. if (len > 0) {
  1392. pr_warn("ceph_object_locator::nspace is set\n");
  1393. goto e_inval;
  1394. }
  1395. }
  1396. if (struct_v >= 6) {
  1397. s64 hash = ceph_decode_64(p);
  1398. if (hash != -1) {
  1399. pr_warn("ceph_object_locator::hash is set\n");
  1400. goto e_inval;
  1401. }
  1402. }
  1403. /* skip the rest */
  1404. *p = struct_end;
  1405. out:
  1406. return ret;
  1407. e_inval:
  1408. ret = -EINVAL;
  1409. goto out;
  1410. }
  1411. static int ceph_redirect_decode(void **p, void *end,
  1412. struct ceph_request_redirect *redir)
  1413. {
  1414. u8 struct_v, struct_cv;
  1415. u32 len;
  1416. void *struct_end;
  1417. int ret;
  1418. ceph_decode_need(p, end, 1 + 1 + 4, e_inval);
  1419. struct_v = ceph_decode_8(p);
  1420. struct_cv = ceph_decode_8(p);
  1421. if (struct_cv > 1) {
  1422. pr_warn("got v %d cv %d > 1 of ceph_request_redirect\n",
  1423. struct_v, struct_cv);
  1424. goto e_inval;
  1425. }
  1426. len = ceph_decode_32(p);
  1427. ceph_decode_need(p, end, len, e_inval);
  1428. struct_end = *p + len;
  1429. ret = ceph_oloc_decode(p, end, &redir->oloc);
  1430. if (ret)
  1431. goto out;
  1432. len = ceph_decode_32(p);
  1433. if (len > 0) {
  1434. pr_warn("ceph_request_redirect::object_name is set\n");
  1435. goto e_inval;
  1436. }
  1437. len = ceph_decode_32(p);
  1438. *p += len; /* skip osd_instructions */
  1439. /* skip the rest */
  1440. *p = struct_end;
  1441. out:
  1442. return ret;
  1443. e_inval:
  1444. ret = -EINVAL;
  1445. goto out;
  1446. }
  1447. static void complete_request(struct ceph_osd_request *req)
  1448. {
  1449. complete_all(&req->r_safe_completion); /* fsync waiter */
  1450. }
  1451. /*
  1452. * handle osd op reply. either call the callback if it is specified,
  1453. * or do the completion to wake up the waiting thread.
  1454. */
  1455. static void handle_reply(struct ceph_osd_client *osdc, struct ceph_msg *msg,
  1456. struct ceph_connection *con)
  1457. {
  1458. void *p, *end;
  1459. struct ceph_osd_request *req;
  1460. struct ceph_request_redirect redir;
  1461. u64 tid;
  1462. int object_len;
  1463. unsigned int numops;
  1464. int payload_len, flags;
  1465. s32 result;
  1466. s32 retry_attempt;
  1467. struct ceph_pg pg;
  1468. int err;
  1469. u32 reassert_epoch;
  1470. u64 reassert_version;
  1471. u32 osdmap_epoch;
  1472. int already_completed;
  1473. u32 bytes;
  1474. unsigned int i;
  1475. tid = le64_to_cpu(msg->hdr.tid);
  1476. dout("handle_reply %p tid %llu\n", msg, tid);
  1477. p = msg->front.iov_base;
  1478. end = p + msg->front.iov_len;
  1479. ceph_decode_need(&p, end, 4, bad);
  1480. object_len = ceph_decode_32(&p);
  1481. ceph_decode_need(&p, end, object_len, bad);
  1482. p += object_len;
  1483. err = ceph_decode_pgid(&p, end, &pg);
  1484. if (err)
  1485. goto bad;
  1486. ceph_decode_need(&p, end, 8 + 4 + 4 + 8 + 4, bad);
  1487. flags = ceph_decode_64(&p);
  1488. result = ceph_decode_32(&p);
  1489. reassert_epoch = ceph_decode_32(&p);
  1490. reassert_version = ceph_decode_64(&p);
  1491. osdmap_epoch = ceph_decode_32(&p);
  1492. /* lookup */
  1493. down_read(&osdc->map_sem);
  1494. mutex_lock(&osdc->request_mutex);
  1495. req = __lookup_request(osdc, tid);
  1496. if (req == NULL) {
  1497. dout("handle_reply tid %llu dne\n", tid);
  1498. goto bad_mutex;
  1499. }
  1500. ceph_osdc_get_request(req);
  1501. dout("handle_reply %p tid %llu req %p result %d\n", msg, tid,
  1502. req, result);
  1503. ceph_decode_need(&p, end, 4, bad_put);
  1504. numops = ceph_decode_32(&p);
  1505. if (numops > CEPH_OSD_MAX_OP)
  1506. goto bad_put;
  1507. if (numops != req->r_num_ops)
  1508. goto bad_put;
  1509. payload_len = 0;
  1510. ceph_decode_need(&p, end, numops * sizeof(struct ceph_osd_op), bad_put);
  1511. for (i = 0; i < numops; i++) {
  1512. struct ceph_osd_op *op = p;
  1513. int len;
  1514. len = le32_to_cpu(op->payload_len);
  1515. req->r_reply_op_len[i] = len;
  1516. dout(" op %d has %d bytes\n", i, len);
  1517. payload_len += len;
  1518. p += sizeof(*op);
  1519. }
  1520. bytes = le32_to_cpu(msg->hdr.data_len);
  1521. if (payload_len != bytes) {
  1522. pr_warn("sum of op payload lens %d != data_len %d\n",
  1523. payload_len, bytes);
  1524. goto bad_put;
  1525. }
  1526. ceph_decode_need(&p, end, 4 + numops * 4, bad_put);
  1527. retry_attempt = ceph_decode_32(&p);
  1528. for (i = 0; i < numops; i++)
  1529. req->r_reply_op_result[i] = ceph_decode_32(&p);
  1530. if (le16_to_cpu(msg->hdr.version) >= 6) {
  1531. p += 8 + 4; /* skip replay_version */
  1532. p += 8; /* skip user_version */
  1533. err = ceph_redirect_decode(&p, end, &redir);
  1534. if (err)
  1535. goto bad_put;
  1536. } else {
  1537. redir.oloc.pool = -1;
  1538. }
  1539. if (redir.oloc.pool != -1) {
  1540. dout("redirect pool %lld\n", redir.oloc.pool);
  1541. __unregister_request(osdc, req);
  1542. req->r_target_oloc = redir.oloc; /* struct */
  1543. /*
  1544. * Start redirect requests with nofail=true. If
  1545. * mapping fails, request will end up on the notarget
  1546. * list, waiting for the new osdmap (which can take
  1547. * a while), even though the original request mapped
  1548. * successfully. In the future we might want to follow
  1549. * original request's nofail setting here.
  1550. */
  1551. err = __ceph_osdc_start_request(osdc, req, true);
  1552. BUG_ON(err);
  1553. goto out_unlock;
  1554. }
  1555. already_completed = req->r_got_reply;
  1556. if (!req->r_got_reply) {
  1557. req->r_result = result;
  1558. dout("handle_reply result %d bytes %d\n", req->r_result,
  1559. bytes);
  1560. if (req->r_result == 0)
  1561. req->r_result = bytes;
  1562. /* in case this is a write and we need to replay, */
  1563. req->r_reassert_version.epoch = cpu_to_le32(reassert_epoch);
  1564. req->r_reassert_version.version = cpu_to_le64(reassert_version);
  1565. req->r_got_reply = 1;
  1566. } else if ((flags & CEPH_OSD_FLAG_ONDISK) == 0) {
  1567. dout("handle_reply tid %llu dup ack\n", tid);
  1568. goto out_unlock;
  1569. }
  1570. dout("handle_reply tid %llu flags %d\n", tid, flags);
  1571. if (req->r_linger && (flags & CEPH_OSD_FLAG_ONDISK))
  1572. __register_linger_request(osdc, req);
  1573. /* either this is a read, or we got the safe response */
  1574. if (result < 0 ||
  1575. (flags & CEPH_OSD_FLAG_ONDISK) ||
  1576. ((flags & CEPH_OSD_FLAG_WRITE) == 0))
  1577. __unregister_request(osdc, req);
  1578. mutex_unlock(&osdc->request_mutex);
  1579. up_read(&osdc->map_sem);
  1580. if (!already_completed) {
  1581. if (req->r_unsafe_callback &&
  1582. result >= 0 && !(flags & CEPH_OSD_FLAG_ONDISK))
  1583. req->r_unsafe_callback(req, true);
  1584. if (req->r_callback)
  1585. req->r_callback(req, msg);
  1586. else
  1587. complete_all(&req->r_completion);
  1588. }
  1589. if (flags & CEPH_OSD_FLAG_ONDISK) {
  1590. if (req->r_unsafe_callback && already_completed)
  1591. req->r_unsafe_callback(req, false);
  1592. complete_request(req);
  1593. }
  1594. out:
  1595. dout("req=%p req->r_linger=%d\n", req, req->r_linger);
  1596. ceph_osdc_put_request(req);
  1597. return;
  1598. out_unlock:
  1599. mutex_unlock(&osdc->request_mutex);
  1600. up_read(&osdc->map_sem);
  1601. goto out;
  1602. bad_put:
  1603. req->r_result = -EIO;
  1604. __unregister_request(osdc, req);
  1605. if (req->r_callback)
  1606. req->r_callback(req, msg);
  1607. else
  1608. complete_all(&req->r_completion);
  1609. complete_request(req);
  1610. ceph_osdc_put_request(req);
  1611. bad_mutex:
  1612. mutex_unlock(&osdc->request_mutex);
  1613. up_read(&osdc->map_sem);
  1614. bad:
  1615. pr_err("corrupt osd_op_reply got %d %d\n",
  1616. (int)msg->front.iov_len, le32_to_cpu(msg->hdr.front_len));
  1617. ceph_msg_dump(msg);
  1618. }
  1619. static void reset_changed_osds(struct ceph_osd_client *osdc)
  1620. {
  1621. struct rb_node *p, *n;
  1622. dout("%s %p\n", __func__, osdc);
  1623. for (p = rb_first(&osdc->osds); p; p = n) {
  1624. struct ceph_osd *osd = rb_entry(p, struct ceph_osd, o_node);
  1625. n = rb_next(p);
  1626. if (!ceph_osd_is_up(osdc->osdmap, osd->o_osd) ||
  1627. memcmp(&osd->o_con.peer_addr,
  1628. ceph_osd_addr(osdc->osdmap,
  1629. osd->o_osd),
  1630. sizeof(struct ceph_entity_addr)) != 0)
  1631. __reset_osd(osdc, osd);
  1632. }
  1633. }
  1634. /*
  1635. * Requeue requests whose mapping to an OSD has changed. If requests map to
  1636. * no osd, request a new map.
  1637. *
  1638. * Caller should hold map_sem for read.
  1639. */
  1640. static void kick_requests(struct ceph_osd_client *osdc, bool force_resend,
  1641. bool force_resend_writes)
  1642. {
  1643. struct ceph_osd_request *req, *nreq;
  1644. struct rb_node *p;
  1645. int needmap = 0;
  1646. int err;
  1647. bool force_resend_req;
  1648. dout("kick_requests %s %s\n", force_resend ? " (force resend)" : "",
  1649. force_resend_writes ? " (force resend writes)" : "");
  1650. mutex_lock(&osdc->request_mutex);
  1651. for (p = rb_first(&osdc->requests); p; ) {
  1652. req = rb_entry(p, struct ceph_osd_request, r_node);
  1653. p = rb_next(p);
  1654. /*
  1655. * For linger requests that have not yet been
  1656. * registered, move them to the linger list; they'll
  1657. * be sent to the osd in the loop below. Unregister
  1658. * the request before re-registering it as a linger
  1659. * request to ensure the __map_request() below
  1660. * will decide it needs to be sent.
  1661. */
  1662. if (req->r_linger && list_empty(&req->r_linger_item)) {
  1663. dout("%p tid %llu restart on osd%d\n",
  1664. req, req->r_tid,
  1665. req->r_osd ? req->r_osd->o_osd : -1);
  1666. ceph_osdc_get_request(req);
  1667. __unregister_request(osdc, req);
  1668. __register_linger_request(osdc, req);
  1669. ceph_osdc_put_request(req);
  1670. continue;
  1671. }
  1672. force_resend_req = force_resend ||
  1673. (force_resend_writes &&
  1674. req->r_flags & CEPH_OSD_FLAG_WRITE);
  1675. err = __map_request(osdc, req, force_resend_req);
  1676. if (err < 0)
  1677. continue; /* error */
  1678. if (req->r_osd == NULL) {
  1679. dout("%p tid %llu maps to no osd\n", req, req->r_tid);
  1680. needmap++; /* request a newer map */
  1681. } else if (err > 0) {
  1682. if (!req->r_linger) {
  1683. dout("%p tid %llu requeued on osd%d\n", req,
  1684. req->r_tid,
  1685. req->r_osd ? req->r_osd->o_osd : -1);
  1686. req->r_flags |= CEPH_OSD_FLAG_RETRY;
  1687. }
  1688. }
  1689. }
  1690. list_for_each_entry_safe(req, nreq, &osdc->req_linger,
  1691. r_linger_item) {
  1692. dout("linger req=%p req->r_osd=%p\n", req, req->r_osd);
  1693. err = __map_request(osdc, req,
  1694. force_resend || force_resend_writes);
  1695. dout("__map_request returned %d\n", err);
  1696. if (err < 0)
  1697. continue; /* hrm! */
  1698. if (req->r_osd == NULL || err > 0) {
  1699. if (req->r_osd == NULL) {
  1700. dout("lingering %p tid %llu maps to no osd\n",
  1701. req, req->r_tid);
  1702. /*
  1703. * A homeless lingering request makes
  1704. * no sense, as it's job is to keep
  1705. * a particular OSD connection open.
  1706. * Request a newer map and kick the
  1707. * request, knowing that it won't be
  1708. * resent until we actually get a map
  1709. * that can tell us where to send it.
  1710. */
  1711. needmap++;
  1712. }
  1713. dout("kicking lingering %p tid %llu osd%d\n", req,
  1714. req->r_tid, req->r_osd ? req->r_osd->o_osd : -1);
  1715. __register_request(osdc, req);
  1716. __unregister_linger_request(osdc, req);
  1717. }
  1718. }
  1719. reset_changed_osds(osdc);
  1720. mutex_unlock(&osdc->request_mutex);
  1721. if (needmap) {
  1722. dout("%d requests for down osds, need new map\n", needmap);
  1723. ceph_monc_request_next_osdmap(&osdc->client->monc);
  1724. }
  1725. }
  1726. /*
  1727. * Process updated osd map.
  1728. *
  1729. * The message contains any number of incremental and full maps, normally
  1730. * indicating some sort of topology change in the cluster. Kick requests
  1731. * off to different OSDs as needed.
  1732. */
  1733. void ceph_osdc_handle_map(struct ceph_osd_client *osdc, struct ceph_msg *msg)
  1734. {
  1735. void *p, *end, *next;
  1736. u32 nr_maps, maplen;
  1737. u32 epoch;
  1738. struct ceph_osdmap *newmap = NULL, *oldmap;
  1739. int err;
  1740. struct ceph_fsid fsid;
  1741. bool was_full;
  1742. dout("handle_map have %u\n", osdc->osdmap ? osdc->osdmap->epoch : 0);
  1743. p = msg->front.iov_base;
  1744. end = p + msg->front.iov_len;
  1745. /* verify fsid */
  1746. ceph_decode_need(&p, end, sizeof(fsid), bad);
  1747. ceph_decode_copy(&p, &fsid, sizeof(fsid));
  1748. if (ceph_check_fsid(osdc->client, &fsid) < 0)
  1749. return;
  1750. down_write(&osdc->map_sem);
  1751. was_full = ceph_osdmap_flag(osdc->osdmap, CEPH_OSDMAP_FULL);
  1752. /* incremental maps */
  1753. ceph_decode_32_safe(&p, end, nr_maps, bad);
  1754. dout(" %d inc maps\n", nr_maps);
  1755. while (nr_maps > 0) {
  1756. ceph_decode_need(&p, end, 2*sizeof(u32), bad);
  1757. epoch = ceph_decode_32(&p);
  1758. maplen = ceph_decode_32(&p);
  1759. ceph_decode_need(&p, end, maplen, bad);
  1760. next = p + maplen;
  1761. if (osdc->osdmap && osdc->osdmap->epoch+1 == epoch) {
  1762. dout("applying incremental map %u len %d\n",
  1763. epoch, maplen);
  1764. newmap = osdmap_apply_incremental(&p, next,
  1765. osdc->osdmap,
  1766. &osdc->client->msgr);
  1767. if (IS_ERR(newmap)) {
  1768. err = PTR_ERR(newmap);
  1769. goto bad;
  1770. }
  1771. BUG_ON(!newmap);
  1772. if (newmap != osdc->osdmap) {
  1773. ceph_osdmap_destroy(osdc->osdmap);
  1774. osdc->osdmap = newmap;
  1775. }
  1776. was_full = was_full ||
  1777. ceph_osdmap_flag(osdc->osdmap,
  1778. CEPH_OSDMAP_FULL);
  1779. kick_requests(osdc, 0, was_full);
  1780. } else {
  1781. dout("ignoring incremental map %u len %d\n",
  1782. epoch, maplen);
  1783. }
  1784. p = next;
  1785. nr_maps--;
  1786. }
  1787. if (newmap)
  1788. goto done;
  1789. /* full maps */
  1790. ceph_decode_32_safe(&p, end, nr_maps, bad);
  1791. dout(" %d full maps\n", nr_maps);
  1792. while (nr_maps) {
  1793. ceph_decode_need(&p, end, 2*sizeof(u32), bad);
  1794. epoch = ceph_decode_32(&p);
  1795. maplen = ceph_decode_32(&p);
  1796. ceph_decode_need(&p, end, maplen, bad);
  1797. if (nr_maps > 1) {
  1798. dout("skipping non-latest full map %u len %d\n",
  1799. epoch, maplen);
  1800. } else if (osdc->osdmap && osdc->osdmap->epoch >= epoch) {
  1801. dout("skipping full map %u len %d, "
  1802. "older than our %u\n", epoch, maplen,
  1803. osdc->osdmap->epoch);
  1804. } else {
  1805. int skipped_map = 0;
  1806. dout("taking full map %u len %d\n", epoch, maplen);
  1807. newmap = ceph_osdmap_decode(&p, p+maplen);
  1808. if (IS_ERR(newmap)) {
  1809. err = PTR_ERR(newmap);
  1810. goto bad;
  1811. }
  1812. BUG_ON(!newmap);
  1813. oldmap = osdc->osdmap;
  1814. osdc->osdmap = newmap;
  1815. if (oldmap) {
  1816. if (oldmap->epoch + 1 < newmap->epoch)
  1817. skipped_map = 1;
  1818. ceph_osdmap_destroy(oldmap);
  1819. }
  1820. was_full = was_full ||
  1821. ceph_osdmap_flag(osdc->osdmap,
  1822. CEPH_OSDMAP_FULL);
  1823. kick_requests(osdc, skipped_map, was_full);
  1824. }
  1825. p += maplen;
  1826. nr_maps--;
  1827. }
  1828. if (!osdc->osdmap)
  1829. goto bad;
  1830. done:
  1831. downgrade_write(&osdc->map_sem);
  1832. ceph_monc_got_osdmap(&osdc->client->monc, osdc->osdmap->epoch);
  1833. /*
  1834. * subscribe to subsequent osdmap updates if full to ensure
  1835. * we find out when we are no longer full and stop returning
  1836. * ENOSPC.
  1837. */
  1838. if (ceph_osdmap_flag(osdc->osdmap, CEPH_OSDMAP_FULL) ||
  1839. ceph_osdmap_flag(osdc->osdmap, CEPH_OSDMAP_PAUSERD) ||
  1840. ceph_osdmap_flag(osdc->osdmap, CEPH_OSDMAP_PAUSEWR))
  1841. ceph_monc_request_next_osdmap(&osdc->client->monc);
  1842. mutex_lock(&osdc->request_mutex);
  1843. __send_queued(osdc);
  1844. mutex_unlock(&osdc->request_mutex);
  1845. up_read(&osdc->map_sem);
  1846. wake_up_all(&osdc->client->auth_wq);
  1847. return;
  1848. bad:
  1849. pr_err("osdc handle_map corrupt msg\n");
  1850. ceph_msg_dump(msg);
  1851. up_write(&osdc->map_sem);
  1852. }
  1853. /*
  1854. * watch/notify callback event infrastructure
  1855. *
  1856. * These callbacks are used both for watch and notify operations.
  1857. */
  1858. static void __release_event(struct kref *kref)
  1859. {
  1860. struct ceph_osd_event *event =
  1861. container_of(kref, struct ceph_osd_event, kref);
  1862. dout("__release_event %p\n", event);
  1863. kfree(event);
  1864. }
  1865. static void get_event(struct ceph_osd_event *event)
  1866. {
  1867. kref_get(&event->kref);
  1868. }
  1869. void ceph_osdc_put_event(struct ceph_osd_event *event)
  1870. {
  1871. kref_put(&event->kref, __release_event);
  1872. }
  1873. EXPORT_SYMBOL(ceph_osdc_put_event);
  1874. static void __insert_event(struct ceph_osd_client *osdc,
  1875. struct ceph_osd_event *new)
  1876. {
  1877. struct rb_node **p = &osdc->event_tree.rb_node;
  1878. struct rb_node *parent = NULL;
  1879. struct ceph_osd_event *event = NULL;
  1880. while (*p) {
  1881. parent = *p;
  1882. event = rb_entry(parent, struct ceph_osd_event, node);
  1883. if (new->cookie < event->cookie)
  1884. p = &(*p)->rb_left;
  1885. else if (new->cookie > event->cookie)
  1886. p = &(*p)->rb_right;
  1887. else
  1888. BUG();
  1889. }
  1890. rb_link_node(&new->node, parent, p);
  1891. rb_insert_color(&new->node, &osdc->event_tree);
  1892. }
  1893. static struct ceph_osd_event *__find_event(struct ceph_osd_client *osdc,
  1894. u64 cookie)
  1895. {
  1896. struct rb_node **p = &osdc->event_tree.rb_node;
  1897. struct rb_node *parent = NULL;
  1898. struct ceph_osd_event *event = NULL;
  1899. while (*p) {
  1900. parent = *p;
  1901. event = rb_entry(parent, struct ceph_osd_event, node);
  1902. if (cookie < event->cookie)
  1903. p = &(*p)->rb_left;
  1904. else if (cookie > event->cookie)
  1905. p = &(*p)->rb_right;
  1906. else
  1907. return event;
  1908. }
  1909. return NULL;
  1910. }
  1911. static void __remove_event(struct ceph_osd_event *event)
  1912. {
  1913. struct ceph_osd_client *osdc = event->osdc;
  1914. if (!RB_EMPTY_NODE(&event->node)) {
  1915. dout("__remove_event removed %p\n", event);
  1916. rb_erase(&event->node, &osdc->event_tree);
  1917. ceph_osdc_put_event(event);
  1918. } else {
  1919. dout("__remove_event didn't remove %p\n", event);
  1920. }
  1921. }
  1922. int ceph_osdc_create_event(struct ceph_osd_client *osdc,
  1923. void (*event_cb)(u64, u64, u8, void *),
  1924. void *data, struct ceph_osd_event **pevent)
  1925. {
  1926. struct ceph_osd_event *event;
  1927. event = kmalloc(sizeof(*event), GFP_NOIO);
  1928. if (!event)
  1929. return -ENOMEM;
  1930. dout("create_event %p\n", event);
  1931. event->cb = event_cb;
  1932. event->one_shot = 0;
  1933. event->data = data;
  1934. event->osdc = osdc;
  1935. INIT_LIST_HEAD(&event->osd_node);
  1936. RB_CLEAR_NODE(&event->node);
  1937. kref_init(&event->kref); /* one ref for us */
  1938. kref_get(&event->kref); /* one ref for the caller */
  1939. spin_lock(&osdc->event_lock);
  1940. event->cookie = ++osdc->event_count;
  1941. __insert_event(osdc, event);
  1942. spin_unlock(&osdc->event_lock);
  1943. *pevent = event;
  1944. return 0;
  1945. }
  1946. EXPORT_SYMBOL(ceph_osdc_create_event);
  1947. void ceph_osdc_cancel_event(struct ceph_osd_event *event)
  1948. {
  1949. struct ceph_osd_client *osdc = event->osdc;
  1950. dout("cancel_event %p\n", event);
  1951. spin_lock(&osdc->event_lock);
  1952. __remove_event(event);
  1953. spin_unlock(&osdc->event_lock);
  1954. ceph_osdc_put_event(event); /* caller's */
  1955. }
  1956. EXPORT_SYMBOL(ceph_osdc_cancel_event);
  1957. static void do_event_work(struct work_struct *work)
  1958. {
  1959. struct ceph_osd_event_work *event_work =
  1960. container_of(work, struct ceph_osd_event_work, work);
  1961. struct ceph_osd_event *event = event_work->event;
  1962. u64 ver = event_work->ver;
  1963. u64 notify_id = event_work->notify_id;
  1964. u8 opcode = event_work->opcode;
  1965. dout("do_event_work completing %p\n", event);
  1966. event->cb(ver, notify_id, opcode, event->data);
  1967. dout("do_event_work completed %p\n", event);
  1968. ceph_osdc_put_event(event);
  1969. kfree(event_work);
  1970. }
  1971. /*
  1972. * Process osd watch notifications
  1973. */
  1974. static void handle_watch_notify(struct ceph_osd_client *osdc,
  1975. struct ceph_msg *msg)
  1976. {
  1977. void *p, *end;
  1978. u8 proto_ver;
  1979. u64 cookie, ver, notify_id;
  1980. u8 opcode;
  1981. struct ceph_osd_event *event;
  1982. struct ceph_osd_event_work *event_work;
  1983. p = msg->front.iov_base;
  1984. end = p + msg->front.iov_len;
  1985. ceph_decode_8_safe(&p, end, proto_ver, bad);
  1986. ceph_decode_8_safe(&p, end, opcode, bad);
  1987. ceph_decode_64_safe(&p, end, cookie, bad);
  1988. ceph_decode_64_safe(&p, end, ver, bad);
  1989. ceph_decode_64_safe(&p, end, notify_id, bad);
  1990. spin_lock(&osdc->event_lock);
  1991. event = __find_event(osdc, cookie);
  1992. if (event) {
  1993. BUG_ON(event->one_shot);
  1994. get_event(event);
  1995. }
  1996. spin_unlock(&osdc->event_lock);
  1997. dout("handle_watch_notify cookie %lld ver %lld event %p\n",
  1998. cookie, ver, event);
  1999. if (event) {
  2000. event_work = kmalloc(sizeof(*event_work), GFP_NOIO);
  2001. if (!event_work) {
  2002. pr_err("couldn't allocate event_work\n");
  2003. ceph_osdc_put_event(event);
  2004. return;
  2005. }
  2006. INIT_WORK(&event_work->work, do_event_work);
  2007. event_work->event = event;
  2008. event_work->ver = ver;
  2009. event_work->notify_id = notify_id;
  2010. event_work->opcode = opcode;
  2011. queue_work(osdc->notify_wq, &event_work->work);
  2012. }
  2013. return;
  2014. bad:
  2015. pr_err("osdc handle_watch_notify corrupt msg\n");
  2016. }
  2017. /*
  2018. * build new request AND message
  2019. *
  2020. */
  2021. void ceph_osdc_build_request(struct ceph_osd_request *req, u64 off,
  2022. struct ceph_snap_context *snapc, u64 snap_id,
  2023. struct timespec *mtime)
  2024. {
  2025. struct ceph_msg *msg = req->r_request;
  2026. void *p;
  2027. size_t msg_size;
  2028. int flags = req->r_flags;
  2029. u64 data_len;
  2030. unsigned int i;
  2031. req->r_snapid = snap_id;
  2032. req->r_snapc = ceph_get_snap_context(snapc);
  2033. /* encode request */
  2034. msg->hdr.version = cpu_to_le16(4);
  2035. p = msg->front.iov_base;
  2036. ceph_encode_32(&p, 1); /* client_inc is always 1 */
  2037. req->r_request_osdmap_epoch = p;
  2038. p += 4;
  2039. req->r_request_flags = p;
  2040. p += 4;
  2041. if (req->r_flags & CEPH_OSD_FLAG_WRITE)
  2042. ceph_encode_timespec(p, mtime);
  2043. p += sizeof(struct ceph_timespec);
  2044. req->r_request_reassert_version = p;
  2045. p += sizeof(struct ceph_eversion); /* will get filled in */
  2046. /* oloc */
  2047. ceph_encode_8(&p, 4);
  2048. ceph_encode_8(&p, 4);
  2049. ceph_encode_32(&p, 8 + 4 + 4);
  2050. req->r_request_pool = p;
  2051. p += 8;
  2052. ceph_encode_32(&p, -1); /* preferred */
  2053. ceph_encode_32(&p, 0); /* key len */
  2054. ceph_encode_8(&p, 1);
  2055. req->r_request_pgid = p;
  2056. p += 8 + 4;
  2057. ceph_encode_32(&p, -1); /* preferred */
  2058. /* oid */
  2059. ceph_encode_32(&p, req->r_base_oid.name_len);
  2060. memcpy(p, req->r_base_oid.name, req->r_base_oid.name_len);
  2061. dout("oid '%.*s' len %d\n", req->r_base_oid.name_len,
  2062. req->r_base_oid.name, req->r_base_oid.name_len);
  2063. p += req->r_base_oid.name_len;
  2064. /* ops--can imply data */
  2065. ceph_encode_16(&p, (u16)req->r_num_ops);
  2066. data_len = 0;
  2067. for (i = 0; i < req->r_num_ops; i++) {
  2068. data_len += osd_req_encode_op(req, p, i);
  2069. p += sizeof(struct ceph_osd_op);
  2070. }
  2071. /* snaps */
  2072. ceph_encode_64(&p, req->r_snapid);
  2073. ceph_encode_64(&p, req->r_snapc ? req->r_snapc->seq : 0);
  2074. ceph_encode_32(&p, req->r_snapc ? req->r_snapc->num_snaps : 0);
  2075. if (req->r_snapc) {
  2076. for (i = 0; i < snapc->num_snaps; i++) {
  2077. ceph_encode_64(&p, req->r_snapc->snaps[i]);
  2078. }
  2079. }
  2080. req->r_request_attempts = p;
  2081. p += 4;
  2082. /* data */
  2083. if (flags & CEPH_OSD_FLAG_WRITE) {
  2084. u16 data_off;
  2085. /*
  2086. * The header "data_off" is a hint to the receiver
  2087. * allowing it to align received data into its
  2088. * buffers such that there's no need to re-copy
  2089. * it before writing it to disk (direct I/O).
  2090. */
  2091. data_off = (u16) (off & 0xffff);
  2092. req->r_request->hdr.data_off = cpu_to_le16(data_off);
  2093. }
  2094. req->r_request->hdr.data_len = cpu_to_le32(data_len);
  2095. BUG_ON(p > msg->front.iov_base + msg->front.iov_len);
  2096. msg_size = p - msg->front.iov_base;
  2097. msg->front.iov_len = msg_size;
  2098. msg->hdr.front_len = cpu_to_le32(msg_size);
  2099. dout("build_request msg_size was %d\n", (int)msg_size);
  2100. }
  2101. EXPORT_SYMBOL(ceph_osdc_build_request);
  2102. /*
  2103. * Register request, send initial attempt.
  2104. */
  2105. int ceph_osdc_start_request(struct ceph_osd_client *osdc,
  2106. struct ceph_osd_request *req,
  2107. bool nofail)
  2108. {
  2109. int rc;
  2110. down_read(&osdc->map_sem);
  2111. mutex_lock(&osdc->request_mutex);
  2112. rc = __ceph_osdc_start_request(osdc, req, nofail);
  2113. mutex_unlock(&osdc->request_mutex);
  2114. up_read(&osdc->map_sem);
  2115. return rc;
  2116. }
  2117. EXPORT_SYMBOL(ceph_osdc_start_request);
  2118. /*
  2119. * Unregister a registered request. The request is not completed (i.e.
  2120. * no callbacks or wakeups) - higher layers are supposed to know what
  2121. * they are canceling.
  2122. */
  2123. void ceph_osdc_cancel_request(struct ceph_osd_request *req)
  2124. {
  2125. struct ceph_osd_client *osdc = req->r_osdc;
  2126. mutex_lock(&osdc->request_mutex);
  2127. if (req->r_linger)
  2128. __unregister_linger_request(osdc, req);
  2129. __unregister_request(osdc, req);
  2130. mutex_unlock(&osdc->request_mutex);
  2131. dout("%s %p tid %llu canceled\n", __func__, req, req->r_tid);
  2132. }
  2133. EXPORT_SYMBOL(ceph_osdc_cancel_request);
  2134. /*
  2135. * wait for a request to complete
  2136. */
  2137. int ceph_osdc_wait_request(struct ceph_osd_client *osdc,
  2138. struct ceph_osd_request *req)
  2139. {
  2140. int rc;
  2141. dout("%s %p tid %llu\n", __func__, req, req->r_tid);
  2142. rc = wait_for_completion_interruptible(&req->r_completion);
  2143. if (rc < 0) {
  2144. dout("%s %p tid %llu interrupted\n", __func__, req, req->r_tid);
  2145. ceph_osdc_cancel_request(req);
  2146. complete_request(req);
  2147. return rc;
  2148. }
  2149. dout("%s %p tid %llu result %d\n", __func__, req, req->r_tid,
  2150. req->r_result);
  2151. return req->r_result;
  2152. }
  2153. EXPORT_SYMBOL(ceph_osdc_wait_request);
  2154. /*
  2155. * sync - wait for all in-flight requests to flush. avoid starvation.
  2156. */
  2157. void ceph_osdc_sync(struct ceph_osd_client *osdc)
  2158. {
  2159. struct ceph_osd_request *req;
  2160. u64 last_tid, next_tid = 0;
  2161. mutex_lock(&osdc->request_mutex);
  2162. last_tid = osdc->last_tid;
  2163. while (1) {
  2164. req = __lookup_request_ge(osdc, next_tid);
  2165. if (!req)
  2166. break;
  2167. if (req->r_tid > last_tid)
  2168. break;
  2169. next_tid = req->r_tid + 1;
  2170. if ((req->r_flags & CEPH_OSD_FLAG_WRITE) == 0)
  2171. continue;
  2172. ceph_osdc_get_request(req);
  2173. mutex_unlock(&osdc->request_mutex);
  2174. dout("sync waiting on tid %llu (last is %llu)\n",
  2175. req->r_tid, last_tid);
  2176. wait_for_completion(&req->r_safe_completion);
  2177. mutex_lock(&osdc->request_mutex);
  2178. ceph_osdc_put_request(req);
  2179. }
  2180. mutex_unlock(&osdc->request_mutex);
  2181. dout("sync done (thru tid %llu)\n", last_tid);
  2182. }
  2183. EXPORT_SYMBOL(ceph_osdc_sync);
  2184. /*
  2185. * Call all pending notify callbacks - for use after a watch is
  2186. * unregistered, to make sure no more callbacks for it will be invoked
  2187. */
  2188. void ceph_osdc_flush_notifies(struct ceph_osd_client *osdc)
  2189. {
  2190. flush_workqueue(osdc->notify_wq);
  2191. }
  2192. EXPORT_SYMBOL(ceph_osdc_flush_notifies);
  2193. /*
  2194. * init, shutdown
  2195. */
  2196. int ceph_osdc_init(struct ceph_osd_client *osdc, struct ceph_client *client)
  2197. {
  2198. int err;
  2199. dout("init\n");
  2200. osdc->client = client;
  2201. osdc->osdmap = NULL;
  2202. init_rwsem(&osdc->map_sem);
  2203. init_completion(&osdc->map_waiters);
  2204. osdc->last_requested_map = 0;
  2205. mutex_init(&osdc->request_mutex);
  2206. osdc->last_tid = 0;
  2207. osdc->osds = RB_ROOT;
  2208. INIT_LIST_HEAD(&osdc->osd_lru);
  2209. osdc->requests = RB_ROOT;
  2210. INIT_LIST_HEAD(&osdc->req_lru);
  2211. INIT_LIST_HEAD(&osdc->req_unsent);
  2212. INIT_LIST_HEAD(&osdc->req_notarget);
  2213. INIT_LIST_HEAD(&osdc->req_linger);
  2214. osdc->num_requests = 0;
  2215. INIT_DELAYED_WORK(&osdc->timeout_work, handle_timeout);
  2216. INIT_DELAYED_WORK(&osdc->osds_timeout_work, handle_osds_timeout);
  2217. spin_lock_init(&osdc->event_lock);
  2218. osdc->event_tree = RB_ROOT;
  2219. osdc->event_count = 0;
  2220. schedule_delayed_work(&osdc->osds_timeout_work,
  2221. round_jiffies_relative(osdc->client->options->osd_idle_ttl * HZ));
  2222. err = -ENOMEM;
  2223. osdc->req_mempool = mempool_create_kmalloc_pool(10,
  2224. sizeof(struct ceph_osd_request));
  2225. if (!osdc->req_mempool)
  2226. goto out;
  2227. err = ceph_msgpool_init(&osdc->msgpool_op, CEPH_MSG_OSD_OP,
  2228. OSD_OP_FRONT_LEN, 10, true,
  2229. "osd_op");
  2230. if (err < 0)
  2231. goto out_mempool;
  2232. err = ceph_msgpool_init(&osdc->msgpool_op_reply, CEPH_MSG_OSD_OPREPLY,
  2233. OSD_OPREPLY_FRONT_LEN, 10, true,
  2234. "osd_op_reply");
  2235. if (err < 0)
  2236. goto out_msgpool;
  2237. err = -ENOMEM;
  2238. osdc->notify_wq = create_singlethread_workqueue("ceph-watch-notify");
  2239. if (!osdc->notify_wq)
  2240. goto out_msgpool_reply;
  2241. return 0;
  2242. out_msgpool_reply:
  2243. ceph_msgpool_destroy(&osdc->msgpool_op_reply);
  2244. out_msgpool:
  2245. ceph_msgpool_destroy(&osdc->msgpool_op);
  2246. out_mempool:
  2247. mempool_destroy(osdc->req_mempool);
  2248. out:
  2249. return err;
  2250. }
  2251. void ceph_osdc_stop(struct ceph_osd_client *osdc)
  2252. {
  2253. flush_workqueue(osdc->notify_wq);
  2254. destroy_workqueue(osdc->notify_wq);
  2255. cancel_delayed_work_sync(&osdc->timeout_work);
  2256. cancel_delayed_work_sync(&osdc->osds_timeout_work);
  2257. if (osdc->osdmap) {
  2258. ceph_osdmap_destroy(osdc->osdmap);
  2259. osdc->osdmap = NULL;
  2260. }
  2261. remove_all_osds(osdc);
  2262. mempool_destroy(osdc->req_mempool);
  2263. ceph_msgpool_destroy(&osdc->msgpool_op);
  2264. ceph_msgpool_destroy(&osdc->msgpool_op_reply);
  2265. }
  2266. /*
  2267. * Read some contiguous pages. If we cross a stripe boundary, shorten
  2268. * *plen. Return number of bytes read, or error.
  2269. */
  2270. int ceph_osdc_readpages(struct ceph_osd_client *osdc,
  2271. struct ceph_vino vino, struct ceph_file_layout *layout,
  2272. u64 off, u64 *plen,
  2273. u32 truncate_seq, u64 truncate_size,
  2274. struct page **pages, int num_pages, int page_align)
  2275. {
  2276. struct ceph_osd_request *req;
  2277. int rc = 0;
  2278. dout("readpages on ino %llx.%llx on %llu~%llu\n", vino.ino,
  2279. vino.snap, off, *plen);
  2280. req = ceph_osdc_new_request(osdc, layout, vino, off, plen, 1,
  2281. CEPH_OSD_OP_READ, CEPH_OSD_FLAG_READ,
  2282. NULL, truncate_seq, truncate_size,
  2283. false);
  2284. if (IS_ERR(req))
  2285. return PTR_ERR(req);
  2286. /* it may be a short read due to an object boundary */
  2287. osd_req_op_extent_osd_data_pages(req, 0,
  2288. pages, *plen, page_align, false, false);
  2289. dout("readpages final extent is %llu~%llu (%llu bytes align %d)\n",
  2290. off, *plen, *plen, page_align);
  2291. ceph_osdc_build_request(req, off, NULL, vino.snap, NULL);
  2292. rc = ceph_osdc_start_request(osdc, req, false);
  2293. if (!rc)
  2294. rc = ceph_osdc_wait_request(osdc, req);
  2295. ceph_osdc_put_request(req);
  2296. dout("readpages result %d\n", rc);
  2297. return rc;
  2298. }
  2299. EXPORT_SYMBOL(ceph_osdc_readpages);
  2300. /*
  2301. * do a synchronous write on N pages
  2302. */
  2303. int ceph_osdc_writepages(struct ceph_osd_client *osdc, struct ceph_vino vino,
  2304. struct ceph_file_layout *layout,
  2305. struct ceph_snap_context *snapc,
  2306. u64 off, u64 len,
  2307. u32 truncate_seq, u64 truncate_size,
  2308. struct timespec *mtime,
  2309. struct page **pages, int num_pages)
  2310. {
  2311. struct ceph_osd_request *req;
  2312. int rc = 0;
  2313. int page_align = off & ~PAGE_MASK;
  2314. BUG_ON(vino.snap != CEPH_NOSNAP); /* snapshots aren't writeable */
  2315. req = ceph_osdc_new_request(osdc, layout, vino, off, &len, 1,
  2316. CEPH_OSD_OP_WRITE,
  2317. CEPH_OSD_FLAG_ONDISK | CEPH_OSD_FLAG_WRITE,
  2318. snapc, truncate_seq, truncate_size,
  2319. true);
  2320. if (IS_ERR(req))
  2321. return PTR_ERR(req);
  2322. /* it may be a short write due to an object boundary */
  2323. osd_req_op_extent_osd_data_pages(req, 0, pages, len, page_align,
  2324. false, false);
  2325. dout("writepages %llu~%llu (%llu bytes)\n", off, len, len);
  2326. ceph_osdc_build_request(req, off, snapc, CEPH_NOSNAP, mtime);
  2327. rc = ceph_osdc_start_request(osdc, req, true);
  2328. if (!rc)
  2329. rc = ceph_osdc_wait_request(osdc, req);
  2330. ceph_osdc_put_request(req);
  2331. if (rc == 0)
  2332. rc = len;
  2333. dout("writepages result %d\n", rc);
  2334. return rc;
  2335. }
  2336. EXPORT_SYMBOL(ceph_osdc_writepages);
  2337. int ceph_osdc_setup(void)
  2338. {
  2339. BUG_ON(ceph_osd_request_cache);
  2340. ceph_osd_request_cache = kmem_cache_create("ceph_osd_request",
  2341. sizeof (struct ceph_osd_request),
  2342. __alignof__(struct ceph_osd_request),
  2343. 0, NULL);
  2344. return ceph_osd_request_cache ? 0 : -ENOMEM;
  2345. }
  2346. EXPORT_SYMBOL(ceph_osdc_setup);
  2347. void ceph_osdc_cleanup(void)
  2348. {
  2349. BUG_ON(!ceph_osd_request_cache);
  2350. kmem_cache_destroy(ceph_osd_request_cache);
  2351. ceph_osd_request_cache = NULL;
  2352. }
  2353. EXPORT_SYMBOL(ceph_osdc_cleanup);
  2354. /*
  2355. * handle incoming message
  2356. */
  2357. static void dispatch(struct ceph_connection *con, struct ceph_msg *msg)
  2358. {
  2359. struct ceph_osd *osd = con->private;
  2360. struct ceph_osd_client *osdc;
  2361. int type = le16_to_cpu(msg->hdr.type);
  2362. if (!osd)
  2363. goto out;
  2364. osdc = osd->o_osdc;
  2365. switch (type) {
  2366. case CEPH_MSG_OSD_MAP:
  2367. ceph_osdc_handle_map(osdc, msg);
  2368. break;
  2369. case CEPH_MSG_OSD_OPREPLY:
  2370. handle_reply(osdc, msg, con);
  2371. break;
  2372. case CEPH_MSG_WATCH_NOTIFY:
  2373. handle_watch_notify(osdc, msg);
  2374. break;
  2375. default:
  2376. pr_err("received unknown message type %d %s\n", type,
  2377. ceph_msg_type_name(type));
  2378. }
  2379. out:
  2380. ceph_msg_put(msg);
  2381. }
  2382. /*
  2383. * lookup and return message for incoming reply. set up reply message
  2384. * pages.
  2385. */
  2386. static struct ceph_msg *get_reply(struct ceph_connection *con,
  2387. struct ceph_msg_header *hdr,
  2388. int *skip)
  2389. {
  2390. struct ceph_osd *osd = con->private;
  2391. struct ceph_osd_client *osdc = osd->o_osdc;
  2392. struct ceph_msg *m;
  2393. struct ceph_osd_request *req;
  2394. int front_len = le32_to_cpu(hdr->front_len);
  2395. int data_len = le32_to_cpu(hdr->data_len);
  2396. u64 tid;
  2397. tid = le64_to_cpu(hdr->tid);
  2398. mutex_lock(&osdc->request_mutex);
  2399. req = __lookup_request(osdc, tid);
  2400. if (!req) {
  2401. *skip = 1;
  2402. m = NULL;
  2403. dout("get_reply unknown tid %llu from osd%d\n", tid,
  2404. osd->o_osd);
  2405. goto out;
  2406. }
  2407. if (req->r_reply->con)
  2408. dout("%s revoking msg %p from old con %p\n", __func__,
  2409. req->r_reply, req->r_reply->con);
  2410. ceph_msg_revoke_incoming(req->r_reply);
  2411. if (front_len > req->r_reply->front_alloc_len) {
  2412. pr_warn("get_reply front %d > preallocated %d (%u#%llu)\n",
  2413. front_len, req->r_reply->front_alloc_len,
  2414. (unsigned int)con->peer_name.type,
  2415. le64_to_cpu(con->peer_name.num));
  2416. m = ceph_msg_new(CEPH_MSG_OSD_OPREPLY, front_len, GFP_NOFS,
  2417. false);
  2418. if (!m)
  2419. goto out;
  2420. ceph_msg_put(req->r_reply);
  2421. req->r_reply = m;
  2422. }
  2423. m = ceph_msg_get(req->r_reply);
  2424. if (data_len > 0) {
  2425. struct ceph_osd_data *osd_data;
  2426. /*
  2427. * XXX This is assuming there is only one op containing
  2428. * XXX page data. Probably OK for reads, but this
  2429. * XXX ought to be done more generally.
  2430. */
  2431. osd_data = osd_req_op_extent_osd_data(req, 0);
  2432. if (osd_data->type == CEPH_OSD_DATA_TYPE_PAGES) {
  2433. if (osd_data->pages &&
  2434. unlikely(osd_data->length < data_len)) {
  2435. pr_warn("tid %lld reply has %d bytes we had only %llu bytes ready\n",
  2436. tid, data_len, osd_data->length);
  2437. *skip = 1;
  2438. ceph_msg_put(m);
  2439. m = NULL;
  2440. goto out;
  2441. }
  2442. }
  2443. }
  2444. *skip = 0;
  2445. dout("get_reply tid %lld %p\n", tid, m);
  2446. out:
  2447. mutex_unlock(&osdc->request_mutex);
  2448. return m;
  2449. }
  2450. static struct ceph_msg *alloc_msg(struct ceph_connection *con,
  2451. struct ceph_msg_header *hdr,
  2452. int *skip)
  2453. {
  2454. struct ceph_osd *osd = con->private;
  2455. int type = le16_to_cpu(hdr->type);
  2456. int front = le32_to_cpu(hdr->front_len);
  2457. *skip = 0;
  2458. switch (type) {
  2459. case CEPH_MSG_OSD_MAP:
  2460. case CEPH_MSG_WATCH_NOTIFY:
  2461. return ceph_msg_new(type, front, GFP_NOFS, false);
  2462. case CEPH_MSG_OSD_OPREPLY:
  2463. return get_reply(con, hdr, skip);
  2464. default:
  2465. pr_info("alloc_msg unexpected msg type %d from osd%d\n", type,
  2466. osd->o_osd);
  2467. *skip = 1;
  2468. return NULL;
  2469. }
  2470. }
  2471. /*
  2472. * Wrappers to refcount containing ceph_osd struct
  2473. */
  2474. static struct ceph_connection *get_osd_con(struct ceph_connection *con)
  2475. {
  2476. struct ceph_osd *osd = con->private;
  2477. if (get_osd(osd))
  2478. return con;
  2479. return NULL;
  2480. }
  2481. static void put_osd_con(struct ceph_connection *con)
  2482. {
  2483. struct ceph_osd *osd = con->private;
  2484. put_osd(osd);
  2485. }
  2486. /*
  2487. * authentication
  2488. */
  2489. /*
  2490. * Note: returned pointer is the address of a structure that's
  2491. * managed separately. Caller must *not* attempt to free it.
  2492. */
  2493. static struct ceph_auth_handshake *get_authorizer(struct ceph_connection *con,
  2494. int *proto, int force_new)
  2495. {
  2496. struct ceph_osd *o = con->private;
  2497. struct ceph_osd_client *osdc = o->o_osdc;
  2498. struct ceph_auth_client *ac = osdc->client->monc.auth;
  2499. struct ceph_auth_handshake *auth = &o->o_auth;
  2500. if (force_new && auth->authorizer) {
  2501. ceph_auth_destroy_authorizer(ac, auth->authorizer);
  2502. auth->authorizer = NULL;
  2503. }
  2504. if (!auth->authorizer) {
  2505. int ret = ceph_auth_create_authorizer(ac, CEPH_ENTITY_TYPE_OSD,
  2506. auth);
  2507. if (ret)
  2508. return ERR_PTR(ret);
  2509. } else {
  2510. int ret = ceph_auth_update_authorizer(ac, CEPH_ENTITY_TYPE_OSD,
  2511. auth);
  2512. if (ret)
  2513. return ERR_PTR(ret);
  2514. }
  2515. *proto = ac->protocol;
  2516. return auth;
  2517. }
  2518. static int verify_authorizer_reply(struct ceph_connection *con, int len)
  2519. {
  2520. struct ceph_osd *o = con->private;
  2521. struct ceph_osd_client *osdc = o->o_osdc;
  2522. struct ceph_auth_client *ac = osdc->client->monc.auth;
  2523. return ceph_auth_verify_authorizer_reply(ac, o->o_auth.authorizer, len);
  2524. }
  2525. static int invalidate_authorizer(struct ceph_connection *con)
  2526. {
  2527. struct ceph_osd *o = con->private;
  2528. struct ceph_osd_client *osdc = o->o_osdc;
  2529. struct ceph_auth_client *ac = osdc->client->monc.auth;
  2530. ceph_auth_invalidate_authorizer(ac, CEPH_ENTITY_TYPE_OSD);
  2531. return ceph_monc_validate_auth(&osdc->client->monc);
  2532. }
  2533. static const struct ceph_connection_operations osd_con_ops = {
  2534. .get = get_osd_con,
  2535. .put = put_osd_con,
  2536. .dispatch = dispatch,
  2537. .get_authorizer = get_authorizer,
  2538. .verify_authorizer_reply = verify_authorizer_reply,
  2539. .invalidate_authorizer = invalidate_authorizer,
  2540. .alloc_msg = alloc_msg,
  2541. .fault = osd_reset,
  2542. };