osd_client.c 61 KB

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