osd_client.c 62 KB

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