mds_client.c 76 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042
  1. #include "ceph_debug.h"
  2. #include <linux/wait.h>
  3. #include <linux/sched.h>
  4. #include "mds_client.h"
  5. #include "mon_client.h"
  6. #include "super.h"
  7. #include "messenger.h"
  8. #include "decode.h"
  9. #include "auth.h"
  10. #include "pagelist.h"
  11. /*
  12. * A cluster of MDS (metadata server) daemons is responsible for
  13. * managing the file system namespace (the directory hierarchy and
  14. * inodes) and for coordinating shared access to storage. Metadata is
  15. * partitioning hierarchically across a number of servers, and that
  16. * partition varies over time as the cluster adjusts the distribution
  17. * in order to balance load.
  18. *
  19. * The MDS client is primarily responsible to managing synchronous
  20. * metadata requests for operations like open, unlink, and so forth.
  21. * If there is a MDS failure, we find out about it when we (possibly
  22. * request and) receive a new MDS map, and can resubmit affected
  23. * requests.
  24. *
  25. * For the most part, though, we take advantage of a lossless
  26. * communications channel to the MDS, and do not need to worry about
  27. * timing out or resubmitting requests.
  28. *
  29. * We maintain a stateful "session" with each MDS we interact with.
  30. * Within each session, we sent periodic heartbeat messages to ensure
  31. * any capabilities or leases we have been issues remain valid. If
  32. * the session times out and goes stale, our leases and capabilities
  33. * are no longer valid.
  34. */
  35. static void __wake_requests(struct ceph_mds_client *mdsc,
  36. struct list_head *head);
  37. const static struct ceph_connection_operations mds_con_ops;
  38. /*
  39. * mds reply parsing
  40. */
  41. /*
  42. * parse individual inode info
  43. */
  44. static int parse_reply_info_in(void **p, void *end,
  45. struct ceph_mds_reply_info_in *info)
  46. {
  47. int err = -EIO;
  48. info->in = *p;
  49. *p += sizeof(struct ceph_mds_reply_inode) +
  50. sizeof(*info->in->fragtree.splits) *
  51. le32_to_cpu(info->in->fragtree.nsplits);
  52. ceph_decode_32_safe(p, end, info->symlink_len, bad);
  53. ceph_decode_need(p, end, info->symlink_len, bad);
  54. info->symlink = *p;
  55. *p += info->symlink_len;
  56. ceph_decode_32_safe(p, end, info->xattr_len, bad);
  57. ceph_decode_need(p, end, info->xattr_len, bad);
  58. info->xattr_data = *p;
  59. *p += info->xattr_len;
  60. return 0;
  61. bad:
  62. return err;
  63. }
  64. /*
  65. * parse a normal reply, which may contain a (dir+)dentry and/or a
  66. * target inode.
  67. */
  68. static int parse_reply_info_trace(void **p, void *end,
  69. struct ceph_mds_reply_info_parsed *info)
  70. {
  71. int err;
  72. if (info->head->is_dentry) {
  73. err = parse_reply_info_in(p, end, &info->diri);
  74. if (err < 0)
  75. goto out_bad;
  76. if (unlikely(*p + sizeof(*info->dirfrag) > end))
  77. goto bad;
  78. info->dirfrag = *p;
  79. *p += sizeof(*info->dirfrag) +
  80. sizeof(u32)*le32_to_cpu(info->dirfrag->ndist);
  81. if (unlikely(*p > end))
  82. goto bad;
  83. ceph_decode_32_safe(p, end, info->dname_len, bad);
  84. ceph_decode_need(p, end, info->dname_len, bad);
  85. info->dname = *p;
  86. *p += info->dname_len;
  87. info->dlease = *p;
  88. *p += sizeof(*info->dlease);
  89. }
  90. if (info->head->is_target) {
  91. err = parse_reply_info_in(p, end, &info->targeti);
  92. if (err < 0)
  93. goto out_bad;
  94. }
  95. if (unlikely(*p != end))
  96. goto bad;
  97. return 0;
  98. bad:
  99. err = -EIO;
  100. out_bad:
  101. pr_err("problem parsing mds trace %d\n", err);
  102. return err;
  103. }
  104. /*
  105. * parse readdir results
  106. */
  107. static int parse_reply_info_dir(void **p, void *end,
  108. struct ceph_mds_reply_info_parsed *info)
  109. {
  110. u32 num, i = 0;
  111. int err;
  112. info->dir_dir = *p;
  113. if (*p + sizeof(*info->dir_dir) > end)
  114. goto bad;
  115. *p += sizeof(*info->dir_dir) +
  116. sizeof(u32)*le32_to_cpu(info->dir_dir->ndist);
  117. if (*p > end)
  118. goto bad;
  119. ceph_decode_need(p, end, sizeof(num) + 2, bad);
  120. num = ceph_decode_32(p);
  121. info->dir_end = ceph_decode_8(p);
  122. info->dir_complete = ceph_decode_8(p);
  123. if (num == 0)
  124. goto done;
  125. /* alloc large array */
  126. info->dir_nr = num;
  127. info->dir_in = kcalloc(num, sizeof(*info->dir_in) +
  128. sizeof(*info->dir_dname) +
  129. sizeof(*info->dir_dname_len) +
  130. sizeof(*info->dir_dlease),
  131. GFP_NOFS);
  132. if (info->dir_in == NULL) {
  133. err = -ENOMEM;
  134. goto out_bad;
  135. }
  136. info->dir_dname = (void *)(info->dir_in + num);
  137. info->dir_dname_len = (void *)(info->dir_dname + num);
  138. info->dir_dlease = (void *)(info->dir_dname_len + num);
  139. while (num) {
  140. /* dentry */
  141. ceph_decode_need(p, end, sizeof(u32)*2, bad);
  142. info->dir_dname_len[i] = ceph_decode_32(p);
  143. ceph_decode_need(p, end, info->dir_dname_len[i], bad);
  144. info->dir_dname[i] = *p;
  145. *p += info->dir_dname_len[i];
  146. dout("parsed dir dname '%.*s'\n", info->dir_dname_len[i],
  147. info->dir_dname[i]);
  148. info->dir_dlease[i] = *p;
  149. *p += sizeof(struct ceph_mds_reply_lease);
  150. /* inode */
  151. err = parse_reply_info_in(p, end, &info->dir_in[i]);
  152. if (err < 0)
  153. goto out_bad;
  154. i++;
  155. num--;
  156. }
  157. done:
  158. if (*p != end)
  159. goto bad;
  160. return 0;
  161. bad:
  162. err = -EIO;
  163. out_bad:
  164. pr_err("problem parsing dir contents %d\n", err);
  165. return err;
  166. }
  167. /*
  168. * parse entire mds reply
  169. */
  170. static int parse_reply_info(struct ceph_msg *msg,
  171. struct ceph_mds_reply_info_parsed *info)
  172. {
  173. void *p, *end;
  174. u32 len;
  175. int err;
  176. info->head = msg->front.iov_base;
  177. p = msg->front.iov_base + sizeof(struct ceph_mds_reply_head);
  178. end = p + msg->front.iov_len - sizeof(struct ceph_mds_reply_head);
  179. /* trace */
  180. ceph_decode_32_safe(&p, end, len, bad);
  181. if (len > 0) {
  182. err = parse_reply_info_trace(&p, p+len, info);
  183. if (err < 0)
  184. goto out_bad;
  185. }
  186. /* dir content */
  187. ceph_decode_32_safe(&p, end, len, bad);
  188. if (len > 0) {
  189. err = parse_reply_info_dir(&p, p+len, info);
  190. if (err < 0)
  191. goto out_bad;
  192. }
  193. /* snap blob */
  194. ceph_decode_32_safe(&p, end, len, bad);
  195. info->snapblob_len = len;
  196. info->snapblob = p;
  197. p += len;
  198. if (p != end)
  199. goto bad;
  200. return 0;
  201. bad:
  202. err = -EIO;
  203. out_bad:
  204. pr_err("mds parse_reply err %d\n", err);
  205. return err;
  206. }
  207. static void destroy_reply_info(struct ceph_mds_reply_info_parsed *info)
  208. {
  209. kfree(info->dir_in);
  210. }
  211. /*
  212. * sessions
  213. */
  214. static const char *session_state_name(int s)
  215. {
  216. switch (s) {
  217. case CEPH_MDS_SESSION_NEW: return "new";
  218. case CEPH_MDS_SESSION_OPENING: return "opening";
  219. case CEPH_MDS_SESSION_OPEN: return "open";
  220. case CEPH_MDS_SESSION_HUNG: return "hung";
  221. case CEPH_MDS_SESSION_CLOSING: return "closing";
  222. case CEPH_MDS_SESSION_RESTARTING: return "restarting";
  223. case CEPH_MDS_SESSION_RECONNECTING: return "reconnecting";
  224. default: return "???";
  225. }
  226. }
  227. static struct ceph_mds_session *get_session(struct ceph_mds_session *s)
  228. {
  229. if (atomic_inc_not_zero(&s->s_ref)) {
  230. dout("mdsc get_session %p %d -> %d\n", s,
  231. atomic_read(&s->s_ref)-1, atomic_read(&s->s_ref));
  232. return s;
  233. } else {
  234. dout("mdsc get_session %p 0 -- FAIL", s);
  235. return NULL;
  236. }
  237. }
  238. void ceph_put_mds_session(struct ceph_mds_session *s)
  239. {
  240. dout("mdsc put_session %p %d -> %d\n", s,
  241. atomic_read(&s->s_ref), atomic_read(&s->s_ref)-1);
  242. if (atomic_dec_and_test(&s->s_ref)) {
  243. if (s->s_authorizer)
  244. s->s_mdsc->client->monc.auth->ops->destroy_authorizer(
  245. s->s_mdsc->client->monc.auth, s->s_authorizer);
  246. kfree(s);
  247. }
  248. }
  249. /*
  250. * called under mdsc->mutex
  251. */
  252. struct ceph_mds_session *__ceph_lookup_mds_session(struct ceph_mds_client *mdsc,
  253. int mds)
  254. {
  255. struct ceph_mds_session *session;
  256. if (mds >= mdsc->max_sessions || mdsc->sessions[mds] == NULL)
  257. return NULL;
  258. session = mdsc->sessions[mds];
  259. dout("lookup_mds_session %p %d\n", session,
  260. atomic_read(&session->s_ref));
  261. get_session(session);
  262. return session;
  263. }
  264. static bool __have_session(struct ceph_mds_client *mdsc, int mds)
  265. {
  266. if (mds >= mdsc->max_sessions)
  267. return false;
  268. return mdsc->sessions[mds];
  269. }
  270. static int __verify_registered_session(struct ceph_mds_client *mdsc,
  271. struct ceph_mds_session *s)
  272. {
  273. if (s->s_mds >= mdsc->max_sessions ||
  274. mdsc->sessions[s->s_mds] != s)
  275. return -ENOENT;
  276. return 0;
  277. }
  278. /*
  279. * create+register a new session for given mds.
  280. * called under mdsc->mutex.
  281. */
  282. static struct ceph_mds_session *register_session(struct ceph_mds_client *mdsc,
  283. int mds)
  284. {
  285. struct ceph_mds_session *s;
  286. s = kzalloc(sizeof(*s), GFP_NOFS);
  287. if (!s)
  288. return ERR_PTR(-ENOMEM);
  289. s->s_mdsc = mdsc;
  290. s->s_mds = mds;
  291. s->s_state = CEPH_MDS_SESSION_NEW;
  292. s->s_ttl = 0;
  293. s->s_seq = 0;
  294. mutex_init(&s->s_mutex);
  295. ceph_con_init(mdsc->client->msgr, &s->s_con);
  296. s->s_con.private = s;
  297. s->s_con.ops = &mds_con_ops;
  298. s->s_con.peer_name.type = CEPH_ENTITY_TYPE_MDS;
  299. s->s_con.peer_name.num = cpu_to_le64(mds);
  300. spin_lock_init(&s->s_cap_lock);
  301. s->s_cap_gen = 0;
  302. s->s_cap_ttl = 0;
  303. s->s_renew_requested = 0;
  304. s->s_renew_seq = 0;
  305. INIT_LIST_HEAD(&s->s_caps);
  306. s->s_nr_caps = 0;
  307. s->s_trim_caps = 0;
  308. atomic_set(&s->s_ref, 1);
  309. INIT_LIST_HEAD(&s->s_waiting);
  310. INIT_LIST_HEAD(&s->s_unsafe);
  311. s->s_num_cap_releases = 0;
  312. s->s_cap_iterator = NULL;
  313. INIT_LIST_HEAD(&s->s_cap_releases);
  314. INIT_LIST_HEAD(&s->s_cap_releases_done);
  315. INIT_LIST_HEAD(&s->s_cap_flushing);
  316. INIT_LIST_HEAD(&s->s_cap_snaps_flushing);
  317. dout("register_session mds%d\n", mds);
  318. if (mds >= mdsc->max_sessions) {
  319. int newmax = 1 << get_count_order(mds+1);
  320. struct ceph_mds_session **sa;
  321. dout("register_session realloc to %d\n", newmax);
  322. sa = kcalloc(newmax, sizeof(void *), GFP_NOFS);
  323. if (sa == NULL)
  324. goto fail_realloc;
  325. if (mdsc->sessions) {
  326. memcpy(sa, mdsc->sessions,
  327. mdsc->max_sessions * sizeof(void *));
  328. kfree(mdsc->sessions);
  329. }
  330. mdsc->sessions = sa;
  331. mdsc->max_sessions = newmax;
  332. }
  333. mdsc->sessions[mds] = s;
  334. atomic_inc(&s->s_ref); /* one ref to sessions[], one to caller */
  335. ceph_con_open(&s->s_con, ceph_mdsmap_get_addr(mdsc->mdsmap, mds));
  336. return s;
  337. fail_realloc:
  338. kfree(s);
  339. return ERR_PTR(-ENOMEM);
  340. }
  341. /*
  342. * called under mdsc->mutex
  343. */
  344. static void __unregister_session(struct ceph_mds_client *mdsc,
  345. struct ceph_mds_session *s)
  346. {
  347. dout("__unregister_session mds%d %p\n", s->s_mds, s);
  348. BUG_ON(mdsc->sessions[s->s_mds] != s);
  349. mdsc->sessions[s->s_mds] = NULL;
  350. ceph_con_close(&s->s_con);
  351. ceph_put_mds_session(s);
  352. }
  353. /*
  354. * drop session refs in request.
  355. *
  356. * should be last request ref, or hold mdsc->mutex
  357. */
  358. static void put_request_session(struct ceph_mds_request *req)
  359. {
  360. if (req->r_session) {
  361. ceph_put_mds_session(req->r_session);
  362. req->r_session = NULL;
  363. }
  364. }
  365. void ceph_mdsc_release_request(struct kref *kref)
  366. {
  367. struct ceph_mds_request *req = container_of(kref,
  368. struct ceph_mds_request,
  369. r_kref);
  370. if (req->r_request)
  371. ceph_msg_put(req->r_request);
  372. if (req->r_reply) {
  373. ceph_msg_put(req->r_reply);
  374. destroy_reply_info(&req->r_reply_info);
  375. }
  376. if (req->r_inode) {
  377. ceph_put_cap_refs(ceph_inode(req->r_inode),
  378. CEPH_CAP_PIN);
  379. iput(req->r_inode);
  380. }
  381. if (req->r_locked_dir)
  382. ceph_put_cap_refs(ceph_inode(req->r_locked_dir),
  383. CEPH_CAP_PIN);
  384. if (req->r_target_inode)
  385. iput(req->r_target_inode);
  386. if (req->r_dentry)
  387. dput(req->r_dentry);
  388. if (req->r_old_dentry) {
  389. ceph_put_cap_refs(
  390. ceph_inode(req->r_old_dentry->d_parent->d_inode),
  391. CEPH_CAP_PIN);
  392. dput(req->r_old_dentry);
  393. }
  394. kfree(req->r_path1);
  395. kfree(req->r_path2);
  396. put_request_session(req);
  397. ceph_unreserve_caps(&req->r_caps_reservation);
  398. kfree(req);
  399. }
  400. /*
  401. * lookup session, bump ref if found.
  402. *
  403. * called under mdsc->mutex.
  404. */
  405. static struct ceph_mds_request *__lookup_request(struct ceph_mds_client *mdsc,
  406. u64 tid)
  407. {
  408. struct ceph_mds_request *req;
  409. struct rb_node *n = mdsc->request_tree.rb_node;
  410. while (n) {
  411. req = rb_entry(n, struct ceph_mds_request, r_node);
  412. if (tid < req->r_tid)
  413. n = n->rb_left;
  414. else if (tid > req->r_tid)
  415. n = n->rb_right;
  416. else {
  417. ceph_mdsc_get_request(req);
  418. return req;
  419. }
  420. }
  421. return NULL;
  422. }
  423. static void __insert_request(struct ceph_mds_client *mdsc,
  424. struct ceph_mds_request *new)
  425. {
  426. struct rb_node **p = &mdsc->request_tree.rb_node;
  427. struct rb_node *parent = NULL;
  428. struct ceph_mds_request *req = NULL;
  429. while (*p) {
  430. parent = *p;
  431. req = rb_entry(parent, struct ceph_mds_request, r_node);
  432. if (new->r_tid < req->r_tid)
  433. p = &(*p)->rb_left;
  434. else if (new->r_tid > req->r_tid)
  435. p = &(*p)->rb_right;
  436. else
  437. BUG();
  438. }
  439. rb_link_node(&new->r_node, parent, p);
  440. rb_insert_color(&new->r_node, &mdsc->request_tree);
  441. }
  442. /*
  443. * Register an in-flight request, and assign a tid. Link to directory
  444. * are modifying (if any).
  445. *
  446. * Called under mdsc->mutex.
  447. */
  448. static void __register_request(struct ceph_mds_client *mdsc,
  449. struct ceph_mds_request *req,
  450. struct inode *dir)
  451. {
  452. req->r_tid = ++mdsc->last_tid;
  453. if (req->r_num_caps)
  454. ceph_reserve_caps(&req->r_caps_reservation, req->r_num_caps);
  455. dout("__register_request %p tid %lld\n", req, req->r_tid);
  456. ceph_mdsc_get_request(req);
  457. __insert_request(mdsc, req);
  458. if (dir) {
  459. struct ceph_inode_info *ci = ceph_inode(dir);
  460. spin_lock(&ci->i_unsafe_lock);
  461. req->r_unsafe_dir = dir;
  462. list_add_tail(&req->r_unsafe_dir_item, &ci->i_unsafe_dirops);
  463. spin_unlock(&ci->i_unsafe_lock);
  464. }
  465. }
  466. static void __unregister_request(struct ceph_mds_client *mdsc,
  467. struct ceph_mds_request *req)
  468. {
  469. dout("__unregister_request %p tid %lld\n", req, req->r_tid);
  470. rb_erase(&req->r_node, &mdsc->request_tree);
  471. RB_CLEAR_NODE(&req->r_node);
  472. if (req->r_unsafe_dir) {
  473. struct ceph_inode_info *ci = ceph_inode(req->r_unsafe_dir);
  474. spin_lock(&ci->i_unsafe_lock);
  475. list_del_init(&req->r_unsafe_dir_item);
  476. spin_unlock(&ci->i_unsafe_lock);
  477. }
  478. ceph_mdsc_put_request(req);
  479. }
  480. /*
  481. * Choose mds to send request to next. If there is a hint set in the
  482. * request (e.g., due to a prior forward hint from the mds), use that.
  483. * Otherwise, consult frag tree and/or caps to identify the
  484. * appropriate mds. If all else fails, choose randomly.
  485. *
  486. * Called under mdsc->mutex.
  487. */
  488. static int __choose_mds(struct ceph_mds_client *mdsc,
  489. struct ceph_mds_request *req)
  490. {
  491. struct inode *inode;
  492. struct ceph_inode_info *ci;
  493. struct ceph_cap *cap;
  494. int mode = req->r_direct_mode;
  495. int mds = -1;
  496. u32 hash = req->r_direct_hash;
  497. bool is_hash = req->r_direct_is_hash;
  498. /*
  499. * is there a specific mds we should try? ignore hint if we have
  500. * no session and the mds is not up (active or recovering).
  501. */
  502. if (req->r_resend_mds >= 0 &&
  503. (__have_session(mdsc, req->r_resend_mds) ||
  504. ceph_mdsmap_get_state(mdsc->mdsmap, req->r_resend_mds) > 0)) {
  505. dout("choose_mds using resend_mds mds%d\n",
  506. req->r_resend_mds);
  507. return req->r_resend_mds;
  508. }
  509. if (mode == USE_RANDOM_MDS)
  510. goto random;
  511. inode = NULL;
  512. if (req->r_inode) {
  513. inode = req->r_inode;
  514. } else if (req->r_dentry) {
  515. if (req->r_dentry->d_inode) {
  516. inode = req->r_dentry->d_inode;
  517. } else {
  518. inode = req->r_dentry->d_parent->d_inode;
  519. hash = req->r_dentry->d_name.hash;
  520. is_hash = true;
  521. }
  522. }
  523. dout("__choose_mds %p is_hash=%d (%d) mode %d\n", inode, (int)is_hash,
  524. (int)hash, mode);
  525. if (!inode)
  526. goto random;
  527. ci = ceph_inode(inode);
  528. if (is_hash && S_ISDIR(inode->i_mode)) {
  529. struct ceph_inode_frag frag;
  530. int found;
  531. ceph_choose_frag(ci, hash, &frag, &found);
  532. if (found) {
  533. if (mode == USE_ANY_MDS && frag.ndist > 0) {
  534. u8 r;
  535. /* choose a random replica */
  536. get_random_bytes(&r, 1);
  537. r %= frag.ndist;
  538. mds = frag.dist[r];
  539. dout("choose_mds %p %llx.%llx "
  540. "frag %u mds%d (%d/%d)\n",
  541. inode, ceph_vinop(inode),
  542. frag.frag, frag.mds,
  543. (int)r, frag.ndist);
  544. return mds;
  545. }
  546. /* since this file/dir wasn't known to be
  547. * replicated, then we want to look for the
  548. * authoritative mds. */
  549. mode = USE_AUTH_MDS;
  550. if (frag.mds >= 0) {
  551. /* choose auth mds */
  552. mds = frag.mds;
  553. dout("choose_mds %p %llx.%llx "
  554. "frag %u mds%d (auth)\n",
  555. inode, ceph_vinop(inode), frag.frag, mds);
  556. return mds;
  557. }
  558. }
  559. }
  560. spin_lock(&inode->i_lock);
  561. cap = NULL;
  562. if (mode == USE_AUTH_MDS)
  563. cap = ci->i_auth_cap;
  564. if (!cap && !RB_EMPTY_ROOT(&ci->i_caps))
  565. cap = rb_entry(rb_first(&ci->i_caps), struct ceph_cap, ci_node);
  566. if (!cap) {
  567. spin_unlock(&inode->i_lock);
  568. goto random;
  569. }
  570. mds = cap->session->s_mds;
  571. dout("choose_mds %p %llx.%llx mds%d (%scap %p)\n",
  572. inode, ceph_vinop(inode), mds,
  573. cap == ci->i_auth_cap ? "auth " : "", cap);
  574. spin_unlock(&inode->i_lock);
  575. return mds;
  576. random:
  577. mds = ceph_mdsmap_get_random_mds(mdsc->mdsmap);
  578. dout("choose_mds chose random mds%d\n", mds);
  579. return mds;
  580. }
  581. /*
  582. * session messages
  583. */
  584. static struct ceph_msg *create_session_msg(u32 op, u64 seq)
  585. {
  586. struct ceph_msg *msg;
  587. struct ceph_mds_session_head *h;
  588. msg = ceph_msg_new(CEPH_MSG_CLIENT_SESSION, sizeof(*h), 0, 0, NULL);
  589. if (IS_ERR(msg)) {
  590. pr_err("create_session_msg ENOMEM creating msg\n");
  591. return ERR_PTR(PTR_ERR(msg));
  592. }
  593. h = msg->front.iov_base;
  594. h->op = cpu_to_le32(op);
  595. h->seq = cpu_to_le64(seq);
  596. return msg;
  597. }
  598. /*
  599. * send session open request.
  600. *
  601. * called under mdsc->mutex
  602. */
  603. static int __open_session(struct ceph_mds_client *mdsc,
  604. struct ceph_mds_session *session)
  605. {
  606. struct ceph_msg *msg;
  607. int mstate;
  608. int mds = session->s_mds;
  609. int err = 0;
  610. /* wait for mds to go active? */
  611. mstate = ceph_mdsmap_get_state(mdsc->mdsmap, mds);
  612. dout("open_session to mds%d (%s)\n", mds,
  613. ceph_mds_state_name(mstate));
  614. session->s_state = CEPH_MDS_SESSION_OPENING;
  615. session->s_renew_requested = jiffies;
  616. /* send connect message */
  617. msg = create_session_msg(CEPH_SESSION_REQUEST_OPEN, session->s_seq);
  618. if (IS_ERR(msg)) {
  619. err = PTR_ERR(msg);
  620. goto out;
  621. }
  622. ceph_con_send(&session->s_con, msg);
  623. out:
  624. return 0;
  625. }
  626. /*
  627. * session caps
  628. */
  629. /*
  630. * Free preallocated cap messages assigned to this session
  631. */
  632. static void cleanup_cap_releases(struct ceph_mds_session *session)
  633. {
  634. struct ceph_msg *msg;
  635. spin_lock(&session->s_cap_lock);
  636. while (!list_empty(&session->s_cap_releases)) {
  637. msg = list_first_entry(&session->s_cap_releases,
  638. struct ceph_msg, list_head);
  639. list_del_init(&msg->list_head);
  640. ceph_msg_put(msg);
  641. }
  642. while (!list_empty(&session->s_cap_releases_done)) {
  643. msg = list_first_entry(&session->s_cap_releases_done,
  644. struct ceph_msg, list_head);
  645. list_del_init(&msg->list_head);
  646. ceph_msg_put(msg);
  647. }
  648. spin_unlock(&session->s_cap_lock);
  649. }
  650. /*
  651. * Helper to safely iterate over all caps associated with a session.
  652. *
  653. * caller must hold session s_mutex
  654. */
  655. static int iterate_session_caps(struct ceph_mds_session *session,
  656. int (*cb)(struct inode *, struct ceph_cap *,
  657. void *), void *arg)
  658. {
  659. struct list_head *p;
  660. struct ceph_cap *cap;
  661. struct inode *inode, *last_inode = NULL;
  662. struct ceph_cap *old_cap = NULL;
  663. int ret;
  664. dout("iterate_session_caps %p mds%d\n", session, session->s_mds);
  665. spin_lock(&session->s_cap_lock);
  666. p = session->s_caps.next;
  667. while (p != &session->s_caps) {
  668. cap = list_entry(p, struct ceph_cap, session_caps);
  669. inode = igrab(&cap->ci->vfs_inode);
  670. if (!inode) {
  671. p = p->next;
  672. continue;
  673. }
  674. session->s_cap_iterator = cap;
  675. spin_unlock(&session->s_cap_lock);
  676. if (last_inode) {
  677. iput(last_inode);
  678. last_inode = NULL;
  679. }
  680. if (old_cap) {
  681. ceph_put_cap(old_cap);
  682. old_cap = NULL;
  683. }
  684. ret = cb(inode, cap, arg);
  685. last_inode = inode;
  686. spin_lock(&session->s_cap_lock);
  687. p = p->next;
  688. if (cap->ci == NULL) {
  689. dout("iterate_session_caps finishing cap %p removal\n",
  690. cap);
  691. BUG_ON(cap->session != session);
  692. list_del_init(&cap->session_caps);
  693. session->s_nr_caps--;
  694. cap->session = NULL;
  695. old_cap = cap; /* put_cap it w/o locks held */
  696. }
  697. if (ret < 0)
  698. goto out;
  699. }
  700. ret = 0;
  701. out:
  702. session->s_cap_iterator = NULL;
  703. spin_unlock(&session->s_cap_lock);
  704. if (last_inode)
  705. iput(last_inode);
  706. if (old_cap)
  707. ceph_put_cap(old_cap);
  708. return ret;
  709. }
  710. static int remove_session_caps_cb(struct inode *inode, struct ceph_cap *cap,
  711. void *arg)
  712. {
  713. struct ceph_inode_info *ci = ceph_inode(inode);
  714. dout("removing cap %p, ci is %p, inode is %p\n",
  715. cap, ci, &ci->vfs_inode);
  716. ceph_remove_cap(cap);
  717. return 0;
  718. }
  719. /*
  720. * caller must hold session s_mutex
  721. */
  722. static void remove_session_caps(struct ceph_mds_session *session)
  723. {
  724. dout("remove_session_caps on %p\n", session);
  725. iterate_session_caps(session, remove_session_caps_cb, NULL);
  726. BUG_ON(session->s_nr_caps > 0);
  727. cleanup_cap_releases(session);
  728. }
  729. /*
  730. * wake up any threads waiting on this session's caps. if the cap is
  731. * old (didn't get renewed on the client reconnect), remove it now.
  732. *
  733. * caller must hold s_mutex.
  734. */
  735. static int wake_up_session_cb(struct inode *inode, struct ceph_cap *cap,
  736. void *arg)
  737. {
  738. struct ceph_inode_info *ci = ceph_inode(inode);
  739. wake_up(&ci->i_cap_wq);
  740. if (arg) {
  741. spin_lock(&inode->i_lock);
  742. ci->i_wanted_max_size = 0;
  743. ci->i_requested_max_size = 0;
  744. spin_unlock(&inode->i_lock);
  745. }
  746. return 0;
  747. }
  748. static void wake_up_session_caps(struct ceph_mds_session *session,
  749. int reconnect)
  750. {
  751. dout("wake_up_session_caps %p mds%d\n", session, session->s_mds);
  752. iterate_session_caps(session, wake_up_session_cb,
  753. (void *)(unsigned long)reconnect);
  754. }
  755. /*
  756. * Send periodic message to MDS renewing all currently held caps. The
  757. * ack will reset the expiration for all caps from this session.
  758. *
  759. * caller holds s_mutex
  760. */
  761. static int send_renew_caps(struct ceph_mds_client *mdsc,
  762. struct ceph_mds_session *session)
  763. {
  764. struct ceph_msg *msg;
  765. int state;
  766. if (time_after_eq(jiffies, session->s_cap_ttl) &&
  767. time_after_eq(session->s_cap_ttl, session->s_renew_requested))
  768. pr_info("mds%d caps stale\n", session->s_mds);
  769. session->s_renew_requested = jiffies;
  770. /* do not try to renew caps until a recovering mds has reconnected
  771. * with its clients. */
  772. state = ceph_mdsmap_get_state(mdsc->mdsmap, session->s_mds);
  773. if (state < CEPH_MDS_STATE_RECONNECT) {
  774. dout("send_renew_caps ignoring mds%d (%s)\n",
  775. session->s_mds, ceph_mds_state_name(state));
  776. return 0;
  777. }
  778. dout("send_renew_caps to mds%d (%s)\n", session->s_mds,
  779. ceph_mds_state_name(state));
  780. msg = create_session_msg(CEPH_SESSION_REQUEST_RENEWCAPS,
  781. ++session->s_renew_seq);
  782. if (IS_ERR(msg))
  783. return PTR_ERR(msg);
  784. ceph_con_send(&session->s_con, msg);
  785. return 0;
  786. }
  787. /*
  788. * Note new cap ttl, and any transition from stale -> not stale (fresh?).
  789. *
  790. * Called under session->s_mutex
  791. */
  792. static void renewed_caps(struct ceph_mds_client *mdsc,
  793. struct ceph_mds_session *session, int is_renew)
  794. {
  795. int was_stale;
  796. int wake = 0;
  797. spin_lock(&session->s_cap_lock);
  798. was_stale = is_renew && (session->s_cap_ttl == 0 ||
  799. time_after_eq(jiffies, session->s_cap_ttl));
  800. session->s_cap_ttl = session->s_renew_requested +
  801. mdsc->mdsmap->m_session_timeout*HZ;
  802. if (was_stale) {
  803. if (time_before(jiffies, session->s_cap_ttl)) {
  804. pr_info("mds%d caps renewed\n", session->s_mds);
  805. wake = 1;
  806. } else {
  807. pr_info("mds%d caps still stale\n", session->s_mds);
  808. }
  809. }
  810. dout("renewed_caps mds%d ttl now %lu, was %s, now %s\n",
  811. session->s_mds, session->s_cap_ttl, was_stale ? "stale" : "fresh",
  812. time_before(jiffies, session->s_cap_ttl) ? "stale" : "fresh");
  813. spin_unlock(&session->s_cap_lock);
  814. if (wake)
  815. wake_up_session_caps(session, 0);
  816. }
  817. /*
  818. * send a session close request
  819. */
  820. static int request_close_session(struct ceph_mds_client *mdsc,
  821. struct ceph_mds_session *session)
  822. {
  823. struct ceph_msg *msg;
  824. int err = 0;
  825. dout("request_close_session mds%d state %s seq %lld\n",
  826. session->s_mds, session_state_name(session->s_state),
  827. session->s_seq);
  828. msg = create_session_msg(CEPH_SESSION_REQUEST_CLOSE, session->s_seq);
  829. if (IS_ERR(msg))
  830. err = PTR_ERR(msg);
  831. else
  832. ceph_con_send(&session->s_con, msg);
  833. return err;
  834. }
  835. /*
  836. * Called with s_mutex held.
  837. */
  838. static int __close_session(struct ceph_mds_client *mdsc,
  839. struct ceph_mds_session *session)
  840. {
  841. if (session->s_state >= CEPH_MDS_SESSION_CLOSING)
  842. return 0;
  843. session->s_state = CEPH_MDS_SESSION_CLOSING;
  844. return request_close_session(mdsc, session);
  845. }
  846. /*
  847. * Trim old(er) caps.
  848. *
  849. * Because we can't cache an inode without one or more caps, we do
  850. * this indirectly: if a cap is unused, we prune its aliases, at which
  851. * point the inode will hopefully get dropped to.
  852. *
  853. * Yes, this is a bit sloppy. Our only real goal here is to respond to
  854. * memory pressure from the MDS, though, so it needn't be perfect.
  855. */
  856. static int trim_caps_cb(struct inode *inode, struct ceph_cap *cap, void *arg)
  857. {
  858. struct ceph_mds_session *session = arg;
  859. struct ceph_inode_info *ci = ceph_inode(inode);
  860. int used, oissued, mine;
  861. if (session->s_trim_caps <= 0)
  862. return -1;
  863. spin_lock(&inode->i_lock);
  864. mine = cap->issued | cap->implemented;
  865. used = __ceph_caps_used(ci);
  866. oissued = __ceph_caps_issued_other(ci, cap);
  867. dout("trim_caps_cb %p cap %p mine %s oissued %s used %s\n",
  868. inode, cap, ceph_cap_string(mine), ceph_cap_string(oissued),
  869. ceph_cap_string(used));
  870. if (ci->i_dirty_caps)
  871. goto out; /* dirty caps */
  872. if ((used & ~oissued) & mine)
  873. goto out; /* we need these caps */
  874. session->s_trim_caps--;
  875. if (oissued) {
  876. /* we aren't the only cap.. just remove us */
  877. __ceph_remove_cap(cap);
  878. } else {
  879. /* try to drop referring dentries */
  880. spin_unlock(&inode->i_lock);
  881. d_prune_aliases(inode);
  882. dout("trim_caps_cb %p cap %p pruned, count now %d\n",
  883. inode, cap, atomic_read(&inode->i_count));
  884. return 0;
  885. }
  886. out:
  887. spin_unlock(&inode->i_lock);
  888. return 0;
  889. }
  890. /*
  891. * Trim session cap count down to some max number.
  892. */
  893. static int trim_caps(struct ceph_mds_client *mdsc,
  894. struct ceph_mds_session *session,
  895. int max_caps)
  896. {
  897. int trim_caps = session->s_nr_caps - max_caps;
  898. dout("trim_caps mds%d start: %d / %d, trim %d\n",
  899. session->s_mds, session->s_nr_caps, max_caps, trim_caps);
  900. if (trim_caps > 0) {
  901. session->s_trim_caps = trim_caps;
  902. iterate_session_caps(session, trim_caps_cb, session);
  903. dout("trim_caps mds%d done: %d / %d, trimmed %d\n",
  904. session->s_mds, session->s_nr_caps, max_caps,
  905. trim_caps - session->s_trim_caps);
  906. session->s_trim_caps = 0;
  907. }
  908. return 0;
  909. }
  910. /*
  911. * Allocate cap_release messages. If there is a partially full message
  912. * in the queue, try to allocate enough to cover it's remainder, so that
  913. * we can send it immediately.
  914. *
  915. * Called under s_mutex.
  916. */
  917. static int add_cap_releases(struct ceph_mds_client *mdsc,
  918. struct ceph_mds_session *session,
  919. int extra)
  920. {
  921. struct ceph_msg *msg;
  922. struct ceph_mds_cap_release *head;
  923. int err = -ENOMEM;
  924. if (extra < 0)
  925. extra = mdsc->client->mount_args->cap_release_safety;
  926. spin_lock(&session->s_cap_lock);
  927. if (!list_empty(&session->s_cap_releases)) {
  928. msg = list_first_entry(&session->s_cap_releases,
  929. struct ceph_msg,
  930. list_head);
  931. head = msg->front.iov_base;
  932. extra += CEPH_CAPS_PER_RELEASE - le32_to_cpu(head->num);
  933. }
  934. while (session->s_num_cap_releases < session->s_nr_caps + extra) {
  935. spin_unlock(&session->s_cap_lock);
  936. msg = ceph_msg_new(CEPH_MSG_CLIENT_CAPRELEASE, PAGE_CACHE_SIZE,
  937. 0, 0, NULL);
  938. if (!msg)
  939. goto out_unlocked;
  940. dout("add_cap_releases %p msg %p now %d\n", session, msg,
  941. (int)msg->front.iov_len);
  942. head = msg->front.iov_base;
  943. head->num = cpu_to_le32(0);
  944. msg->front.iov_len = sizeof(*head);
  945. spin_lock(&session->s_cap_lock);
  946. list_add(&msg->list_head, &session->s_cap_releases);
  947. session->s_num_cap_releases += CEPH_CAPS_PER_RELEASE;
  948. }
  949. if (!list_empty(&session->s_cap_releases)) {
  950. msg = list_first_entry(&session->s_cap_releases,
  951. struct ceph_msg,
  952. list_head);
  953. head = msg->front.iov_base;
  954. if (head->num) {
  955. dout(" queueing non-full %p (%d)\n", msg,
  956. le32_to_cpu(head->num));
  957. list_move_tail(&msg->list_head,
  958. &session->s_cap_releases_done);
  959. session->s_num_cap_releases -=
  960. CEPH_CAPS_PER_RELEASE - le32_to_cpu(head->num);
  961. }
  962. }
  963. err = 0;
  964. spin_unlock(&session->s_cap_lock);
  965. out_unlocked:
  966. return err;
  967. }
  968. /*
  969. * flush all dirty inode data to disk.
  970. *
  971. * returns true if we've flushed through want_flush_seq
  972. */
  973. static int check_cap_flush(struct ceph_mds_client *mdsc, u64 want_flush_seq)
  974. {
  975. int mds, ret = 1;
  976. dout("check_cap_flush want %lld\n", want_flush_seq);
  977. mutex_lock(&mdsc->mutex);
  978. for (mds = 0; ret && mds < mdsc->max_sessions; mds++) {
  979. struct ceph_mds_session *session = mdsc->sessions[mds];
  980. if (!session)
  981. continue;
  982. get_session(session);
  983. mutex_unlock(&mdsc->mutex);
  984. mutex_lock(&session->s_mutex);
  985. if (!list_empty(&session->s_cap_flushing)) {
  986. struct ceph_inode_info *ci =
  987. list_entry(session->s_cap_flushing.next,
  988. struct ceph_inode_info,
  989. i_flushing_item);
  990. struct inode *inode = &ci->vfs_inode;
  991. spin_lock(&inode->i_lock);
  992. if (ci->i_cap_flush_seq <= want_flush_seq) {
  993. dout("check_cap_flush still flushing %p "
  994. "seq %lld <= %lld to mds%d\n", inode,
  995. ci->i_cap_flush_seq, want_flush_seq,
  996. session->s_mds);
  997. ret = 0;
  998. }
  999. spin_unlock(&inode->i_lock);
  1000. }
  1001. mutex_unlock(&session->s_mutex);
  1002. ceph_put_mds_session(session);
  1003. if (!ret)
  1004. return ret;
  1005. mutex_lock(&mdsc->mutex);
  1006. }
  1007. mutex_unlock(&mdsc->mutex);
  1008. dout("check_cap_flush ok, flushed thru %lld\n", want_flush_seq);
  1009. return ret;
  1010. }
  1011. /*
  1012. * called under s_mutex
  1013. */
  1014. static void send_cap_releases(struct ceph_mds_client *mdsc,
  1015. struct ceph_mds_session *session)
  1016. {
  1017. struct ceph_msg *msg;
  1018. dout("send_cap_releases mds%d\n", session->s_mds);
  1019. while (1) {
  1020. spin_lock(&session->s_cap_lock);
  1021. if (list_empty(&session->s_cap_releases_done))
  1022. break;
  1023. msg = list_first_entry(&session->s_cap_releases_done,
  1024. struct ceph_msg, list_head);
  1025. list_del_init(&msg->list_head);
  1026. spin_unlock(&session->s_cap_lock);
  1027. msg->hdr.front_len = cpu_to_le32(msg->front.iov_len);
  1028. dout("send_cap_releases mds%d %p\n", session->s_mds, msg);
  1029. ceph_con_send(&session->s_con, msg);
  1030. }
  1031. spin_unlock(&session->s_cap_lock);
  1032. }
  1033. /*
  1034. * requests
  1035. */
  1036. /*
  1037. * Create an mds request.
  1038. */
  1039. struct ceph_mds_request *
  1040. ceph_mdsc_create_request(struct ceph_mds_client *mdsc, int op, int mode)
  1041. {
  1042. struct ceph_mds_request *req = kzalloc(sizeof(*req), GFP_NOFS);
  1043. if (!req)
  1044. return ERR_PTR(-ENOMEM);
  1045. req->r_started = jiffies;
  1046. req->r_resend_mds = -1;
  1047. INIT_LIST_HEAD(&req->r_unsafe_dir_item);
  1048. req->r_fmode = -1;
  1049. kref_init(&req->r_kref);
  1050. INIT_LIST_HEAD(&req->r_wait);
  1051. init_completion(&req->r_completion);
  1052. init_completion(&req->r_safe_completion);
  1053. INIT_LIST_HEAD(&req->r_unsafe_item);
  1054. req->r_op = op;
  1055. req->r_direct_mode = mode;
  1056. return req;
  1057. }
  1058. /*
  1059. * return oldest (lowest) request, tid in request tree, 0 if none.
  1060. *
  1061. * called under mdsc->mutex.
  1062. */
  1063. static struct ceph_mds_request *__get_oldest_req(struct ceph_mds_client *mdsc)
  1064. {
  1065. if (RB_EMPTY_ROOT(&mdsc->request_tree))
  1066. return NULL;
  1067. return rb_entry(rb_first(&mdsc->request_tree),
  1068. struct ceph_mds_request, r_node);
  1069. }
  1070. static u64 __get_oldest_tid(struct ceph_mds_client *mdsc)
  1071. {
  1072. struct ceph_mds_request *req = __get_oldest_req(mdsc);
  1073. if (req)
  1074. return req->r_tid;
  1075. return 0;
  1076. }
  1077. /*
  1078. * Build a dentry's path. Allocate on heap; caller must kfree. Based
  1079. * on build_path_from_dentry in fs/cifs/dir.c.
  1080. *
  1081. * If @stop_on_nosnap, generate path relative to the first non-snapped
  1082. * inode.
  1083. *
  1084. * Encode hidden .snap dirs as a double /, i.e.
  1085. * foo/.snap/bar -> foo//bar
  1086. */
  1087. char *ceph_mdsc_build_path(struct dentry *dentry, int *plen, u64 *base,
  1088. int stop_on_nosnap)
  1089. {
  1090. struct dentry *temp;
  1091. char *path;
  1092. int len, pos;
  1093. if (dentry == NULL)
  1094. return ERR_PTR(-EINVAL);
  1095. retry:
  1096. len = 0;
  1097. for (temp = dentry; !IS_ROOT(temp);) {
  1098. struct inode *inode = temp->d_inode;
  1099. if (inode && ceph_snap(inode) == CEPH_SNAPDIR)
  1100. len++; /* slash only */
  1101. else if (stop_on_nosnap && inode &&
  1102. ceph_snap(inode) == CEPH_NOSNAP)
  1103. break;
  1104. else
  1105. len += 1 + temp->d_name.len;
  1106. temp = temp->d_parent;
  1107. if (temp == NULL) {
  1108. pr_err("build_path_dentry corrupt dentry %p\n", dentry);
  1109. return ERR_PTR(-EINVAL);
  1110. }
  1111. }
  1112. if (len)
  1113. len--; /* no leading '/' */
  1114. path = kmalloc(len+1, GFP_NOFS);
  1115. if (path == NULL)
  1116. return ERR_PTR(-ENOMEM);
  1117. pos = len;
  1118. path[pos] = 0; /* trailing null */
  1119. for (temp = dentry; !IS_ROOT(temp) && pos != 0; ) {
  1120. struct inode *inode = temp->d_inode;
  1121. if (inode && ceph_snap(inode) == CEPH_SNAPDIR) {
  1122. dout("build_path_dentry path+%d: %p SNAPDIR\n",
  1123. pos, temp);
  1124. } else if (stop_on_nosnap && inode &&
  1125. ceph_snap(inode) == CEPH_NOSNAP) {
  1126. break;
  1127. } else {
  1128. pos -= temp->d_name.len;
  1129. if (pos < 0)
  1130. break;
  1131. strncpy(path + pos, temp->d_name.name,
  1132. temp->d_name.len);
  1133. dout("build_path_dentry path+%d: %p '%.*s'\n",
  1134. pos, temp, temp->d_name.len, path + pos);
  1135. }
  1136. if (pos)
  1137. path[--pos] = '/';
  1138. temp = temp->d_parent;
  1139. if (temp == NULL) {
  1140. pr_err("build_path_dentry corrupt dentry\n");
  1141. kfree(path);
  1142. return ERR_PTR(-EINVAL);
  1143. }
  1144. }
  1145. if (pos != 0) {
  1146. pr_err("build_path_dentry did not end path lookup where "
  1147. "expected, namelen is %d, pos is %d\n", len, pos);
  1148. /* presumably this is only possible if racing with a
  1149. rename of one of the parent directories (we can not
  1150. lock the dentries above us to prevent this, but
  1151. retrying should be harmless) */
  1152. kfree(path);
  1153. goto retry;
  1154. }
  1155. *base = ceph_ino(temp->d_inode);
  1156. *plen = len;
  1157. dout("build_path_dentry on %p %d built %llx '%.*s'\n",
  1158. dentry, atomic_read(&dentry->d_count), *base, len, path);
  1159. return path;
  1160. }
  1161. static int build_dentry_path(struct dentry *dentry,
  1162. const char **ppath, int *ppathlen, u64 *pino,
  1163. int *pfreepath)
  1164. {
  1165. char *path;
  1166. if (ceph_snap(dentry->d_parent->d_inode) == CEPH_NOSNAP) {
  1167. *pino = ceph_ino(dentry->d_parent->d_inode);
  1168. *ppath = dentry->d_name.name;
  1169. *ppathlen = dentry->d_name.len;
  1170. return 0;
  1171. }
  1172. path = ceph_mdsc_build_path(dentry, ppathlen, pino, 1);
  1173. if (IS_ERR(path))
  1174. return PTR_ERR(path);
  1175. *ppath = path;
  1176. *pfreepath = 1;
  1177. return 0;
  1178. }
  1179. static int build_inode_path(struct inode *inode,
  1180. const char **ppath, int *ppathlen, u64 *pino,
  1181. int *pfreepath)
  1182. {
  1183. struct dentry *dentry;
  1184. char *path;
  1185. if (ceph_snap(inode) == CEPH_NOSNAP) {
  1186. *pino = ceph_ino(inode);
  1187. *ppathlen = 0;
  1188. return 0;
  1189. }
  1190. dentry = d_find_alias(inode);
  1191. path = ceph_mdsc_build_path(dentry, ppathlen, pino, 1);
  1192. dput(dentry);
  1193. if (IS_ERR(path))
  1194. return PTR_ERR(path);
  1195. *ppath = path;
  1196. *pfreepath = 1;
  1197. return 0;
  1198. }
  1199. /*
  1200. * request arguments may be specified via an inode *, a dentry *, or
  1201. * an explicit ino+path.
  1202. */
  1203. static int set_request_path_attr(struct inode *rinode, struct dentry *rdentry,
  1204. const char *rpath, u64 rino,
  1205. const char **ppath, int *pathlen,
  1206. u64 *ino, int *freepath)
  1207. {
  1208. int r = 0;
  1209. if (rinode) {
  1210. r = build_inode_path(rinode, ppath, pathlen, ino, freepath);
  1211. dout(" inode %p %llx.%llx\n", rinode, ceph_ino(rinode),
  1212. ceph_snap(rinode));
  1213. } else if (rdentry) {
  1214. r = build_dentry_path(rdentry, ppath, pathlen, ino, freepath);
  1215. dout(" dentry %p %llx/%.*s\n", rdentry, *ino, *pathlen,
  1216. *ppath);
  1217. } else if (rpath) {
  1218. *ino = rino;
  1219. *ppath = rpath;
  1220. *pathlen = strlen(rpath);
  1221. dout(" path %.*s\n", *pathlen, rpath);
  1222. }
  1223. return r;
  1224. }
  1225. /*
  1226. * called under mdsc->mutex
  1227. */
  1228. static struct ceph_msg *create_request_message(struct ceph_mds_client *mdsc,
  1229. struct ceph_mds_request *req,
  1230. int mds)
  1231. {
  1232. struct ceph_msg *msg;
  1233. struct ceph_mds_request_head *head;
  1234. const char *path1 = NULL;
  1235. const char *path2 = NULL;
  1236. u64 ino1 = 0, ino2 = 0;
  1237. int pathlen1 = 0, pathlen2 = 0;
  1238. int freepath1 = 0, freepath2 = 0;
  1239. int len;
  1240. u16 releases;
  1241. void *p, *end;
  1242. int ret;
  1243. ret = set_request_path_attr(req->r_inode, req->r_dentry,
  1244. req->r_path1, req->r_ino1.ino,
  1245. &path1, &pathlen1, &ino1, &freepath1);
  1246. if (ret < 0) {
  1247. msg = ERR_PTR(ret);
  1248. goto out;
  1249. }
  1250. ret = set_request_path_attr(NULL, req->r_old_dentry,
  1251. req->r_path2, req->r_ino2.ino,
  1252. &path2, &pathlen2, &ino2, &freepath2);
  1253. if (ret < 0) {
  1254. msg = ERR_PTR(ret);
  1255. goto out_free1;
  1256. }
  1257. len = sizeof(*head) +
  1258. pathlen1 + pathlen2 + 2*(1 + sizeof(u32) + sizeof(u64));
  1259. /* calculate (max) length for cap releases */
  1260. len += sizeof(struct ceph_mds_request_release) *
  1261. (!!req->r_inode_drop + !!req->r_dentry_drop +
  1262. !!req->r_old_inode_drop + !!req->r_old_dentry_drop);
  1263. if (req->r_dentry_drop)
  1264. len += req->r_dentry->d_name.len;
  1265. if (req->r_old_dentry_drop)
  1266. len += req->r_old_dentry->d_name.len;
  1267. msg = ceph_msg_new(CEPH_MSG_CLIENT_REQUEST, len, 0, 0, NULL);
  1268. if (IS_ERR(msg))
  1269. goto out_free2;
  1270. msg->hdr.tid = cpu_to_le64(req->r_tid);
  1271. head = msg->front.iov_base;
  1272. p = msg->front.iov_base + sizeof(*head);
  1273. end = msg->front.iov_base + msg->front.iov_len;
  1274. head->mdsmap_epoch = cpu_to_le32(mdsc->mdsmap->m_epoch);
  1275. head->op = cpu_to_le32(req->r_op);
  1276. head->caller_uid = cpu_to_le32(current_fsuid());
  1277. head->caller_gid = cpu_to_le32(current_fsgid());
  1278. head->args = req->r_args;
  1279. ceph_encode_filepath(&p, end, ino1, path1);
  1280. ceph_encode_filepath(&p, end, ino2, path2);
  1281. /* cap releases */
  1282. releases = 0;
  1283. if (req->r_inode_drop)
  1284. releases += ceph_encode_inode_release(&p,
  1285. req->r_inode ? req->r_inode : req->r_dentry->d_inode,
  1286. mds, req->r_inode_drop, req->r_inode_unless, 0);
  1287. if (req->r_dentry_drop)
  1288. releases += ceph_encode_dentry_release(&p, req->r_dentry,
  1289. mds, req->r_dentry_drop, req->r_dentry_unless);
  1290. if (req->r_old_dentry_drop)
  1291. releases += ceph_encode_dentry_release(&p, req->r_old_dentry,
  1292. mds, req->r_old_dentry_drop, req->r_old_dentry_unless);
  1293. if (req->r_old_inode_drop)
  1294. releases += ceph_encode_inode_release(&p,
  1295. req->r_old_dentry->d_inode,
  1296. mds, req->r_old_inode_drop, req->r_old_inode_unless, 0);
  1297. head->num_releases = cpu_to_le16(releases);
  1298. BUG_ON(p > end);
  1299. msg->front.iov_len = p - msg->front.iov_base;
  1300. msg->hdr.front_len = cpu_to_le32(msg->front.iov_len);
  1301. msg->pages = req->r_pages;
  1302. msg->nr_pages = req->r_num_pages;
  1303. msg->hdr.data_len = cpu_to_le32(req->r_data_len);
  1304. msg->hdr.data_off = cpu_to_le16(0);
  1305. out_free2:
  1306. if (freepath2)
  1307. kfree((char *)path2);
  1308. out_free1:
  1309. if (freepath1)
  1310. kfree((char *)path1);
  1311. out:
  1312. return msg;
  1313. }
  1314. /*
  1315. * called under mdsc->mutex if error, under no mutex if
  1316. * success.
  1317. */
  1318. static void complete_request(struct ceph_mds_client *mdsc,
  1319. struct ceph_mds_request *req)
  1320. {
  1321. if (req->r_callback)
  1322. req->r_callback(mdsc, req);
  1323. else
  1324. complete(&req->r_completion);
  1325. }
  1326. /*
  1327. * called under mdsc->mutex
  1328. */
  1329. static int __prepare_send_request(struct ceph_mds_client *mdsc,
  1330. struct ceph_mds_request *req,
  1331. int mds)
  1332. {
  1333. struct ceph_mds_request_head *rhead;
  1334. struct ceph_msg *msg;
  1335. int flags = 0;
  1336. req->r_mds = mds;
  1337. req->r_attempts++;
  1338. dout("prepare_send_request %p tid %lld %s (attempt %d)\n", req,
  1339. req->r_tid, ceph_mds_op_name(req->r_op), req->r_attempts);
  1340. if (req->r_request) {
  1341. ceph_msg_put(req->r_request);
  1342. req->r_request = NULL;
  1343. }
  1344. msg = create_request_message(mdsc, req, mds);
  1345. if (IS_ERR(msg)) {
  1346. req->r_reply = ERR_PTR(PTR_ERR(msg));
  1347. complete_request(mdsc, req);
  1348. return -PTR_ERR(msg);
  1349. }
  1350. req->r_request = msg;
  1351. rhead = msg->front.iov_base;
  1352. rhead->oldest_client_tid = cpu_to_le64(__get_oldest_tid(mdsc));
  1353. if (req->r_got_unsafe)
  1354. flags |= CEPH_MDS_FLAG_REPLAY;
  1355. if (req->r_locked_dir)
  1356. flags |= CEPH_MDS_FLAG_WANT_DENTRY;
  1357. rhead->flags = cpu_to_le32(flags);
  1358. rhead->num_fwd = req->r_num_fwd;
  1359. rhead->num_retry = req->r_attempts - 1;
  1360. dout(" r_locked_dir = %p\n", req->r_locked_dir);
  1361. if (req->r_target_inode && req->r_got_unsafe)
  1362. rhead->ino = cpu_to_le64(ceph_ino(req->r_target_inode));
  1363. else
  1364. rhead->ino = 0;
  1365. return 0;
  1366. }
  1367. /*
  1368. * send request, or put it on the appropriate wait list.
  1369. */
  1370. static int __do_request(struct ceph_mds_client *mdsc,
  1371. struct ceph_mds_request *req)
  1372. {
  1373. struct ceph_mds_session *session = NULL;
  1374. int mds = -1;
  1375. int err = -EAGAIN;
  1376. if (req->r_reply)
  1377. goto out;
  1378. if (req->r_timeout &&
  1379. time_after_eq(jiffies, req->r_started + req->r_timeout)) {
  1380. dout("do_request timed out\n");
  1381. err = -EIO;
  1382. goto finish;
  1383. }
  1384. mds = __choose_mds(mdsc, req);
  1385. if (mds < 0 ||
  1386. ceph_mdsmap_get_state(mdsc->mdsmap, mds) < CEPH_MDS_STATE_ACTIVE) {
  1387. dout("do_request no mds or not active, waiting for map\n");
  1388. list_add(&req->r_wait, &mdsc->waiting_for_map);
  1389. goto out;
  1390. }
  1391. /* get, open session */
  1392. session = __ceph_lookup_mds_session(mdsc, mds);
  1393. if (!session) {
  1394. session = register_session(mdsc, mds);
  1395. if (IS_ERR(session)) {
  1396. err = PTR_ERR(session);
  1397. goto finish;
  1398. }
  1399. }
  1400. dout("do_request mds%d session %p state %s\n", mds, session,
  1401. session_state_name(session->s_state));
  1402. if (session->s_state != CEPH_MDS_SESSION_OPEN &&
  1403. session->s_state != CEPH_MDS_SESSION_HUNG) {
  1404. if (session->s_state == CEPH_MDS_SESSION_NEW ||
  1405. session->s_state == CEPH_MDS_SESSION_CLOSING)
  1406. __open_session(mdsc, session);
  1407. list_add(&req->r_wait, &session->s_waiting);
  1408. goto out_session;
  1409. }
  1410. /* send request */
  1411. req->r_session = get_session(session);
  1412. req->r_resend_mds = -1; /* forget any previous mds hint */
  1413. if (req->r_request_started == 0) /* note request start time */
  1414. req->r_request_started = jiffies;
  1415. err = __prepare_send_request(mdsc, req, mds);
  1416. if (!err) {
  1417. ceph_msg_get(req->r_request);
  1418. ceph_con_send(&session->s_con, req->r_request);
  1419. }
  1420. out_session:
  1421. ceph_put_mds_session(session);
  1422. out:
  1423. return err;
  1424. finish:
  1425. req->r_reply = ERR_PTR(err);
  1426. complete_request(mdsc, req);
  1427. goto out;
  1428. }
  1429. /*
  1430. * called under mdsc->mutex
  1431. */
  1432. static void __wake_requests(struct ceph_mds_client *mdsc,
  1433. struct list_head *head)
  1434. {
  1435. struct ceph_mds_request *req, *nreq;
  1436. list_for_each_entry_safe(req, nreq, head, r_wait) {
  1437. list_del_init(&req->r_wait);
  1438. __do_request(mdsc, req);
  1439. }
  1440. }
  1441. /*
  1442. * Wake up threads with requests pending for @mds, so that they can
  1443. * resubmit their requests to a possibly different mds. If @all is set,
  1444. * wake up if their requests has been forwarded to @mds, too.
  1445. */
  1446. static void kick_requests(struct ceph_mds_client *mdsc, int mds, int all)
  1447. {
  1448. struct ceph_mds_request *req;
  1449. struct rb_node *p;
  1450. dout("kick_requests mds%d\n", mds);
  1451. for (p = rb_first(&mdsc->request_tree); p; p = rb_next(p)) {
  1452. req = rb_entry(p, struct ceph_mds_request, r_node);
  1453. if (req->r_got_unsafe)
  1454. continue;
  1455. if (req->r_session &&
  1456. req->r_session->s_mds == mds) {
  1457. dout(" kicking tid %llu\n", req->r_tid);
  1458. put_request_session(req);
  1459. __do_request(mdsc, req);
  1460. }
  1461. }
  1462. }
  1463. void ceph_mdsc_submit_request(struct ceph_mds_client *mdsc,
  1464. struct ceph_mds_request *req)
  1465. {
  1466. dout("submit_request on %p\n", req);
  1467. mutex_lock(&mdsc->mutex);
  1468. __register_request(mdsc, req, NULL);
  1469. __do_request(mdsc, req);
  1470. mutex_unlock(&mdsc->mutex);
  1471. }
  1472. /*
  1473. * Synchrously perform an mds request. Take care of all of the
  1474. * session setup, forwarding, retry details.
  1475. */
  1476. int ceph_mdsc_do_request(struct ceph_mds_client *mdsc,
  1477. struct inode *dir,
  1478. struct ceph_mds_request *req)
  1479. {
  1480. int err;
  1481. dout("do_request on %p\n", req);
  1482. /* take CAP_PIN refs for r_inode, r_locked_dir, r_old_dentry */
  1483. if (req->r_inode)
  1484. ceph_get_cap_refs(ceph_inode(req->r_inode), CEPH_CAP_PIN);
  1485. if (req->r_locked_dir)
  1486. ceph_get_cap_refs(ceph_inode(req->r_locked_dir), CEPH_CAP_PIN);
  1487. if (req->r_old_dentry)
  1488. ceph_get_cap_refs(
  1489. ceph_inode(req->r_old_dentry->d_parent->d_inode),
  1490. CEPH_CAP_PIN);
  1491. /* issue */
  1492. mutex_lock(&mdsc->mutex);
  1493. __register_request(mdsc, req, dir);
  1494. __do_request(mdsc, req);
  1495. /* wait */
  1496. if (!req->r_reply) {
  1497. mutex_unlock(&mdsc->mutex);
  1498. if (req->r_timeout) {
  1499. err = (long)wait_for_completion_interruptible_timeout(
  1500. &req->r_completion, req->r_timeout);
  1501. if (err == 0)
  1502. req->r_reply = ERR_PTR(-EIO);
  1503. else if (err < 0)
  1504. req->r_reply = ERR_PTR(err);
  1505. } else {
  1506. err = wait_for_completion_interruptible(
  1507. &req->r_completion);
  1508. if (err)
  1509. req->r_reply = ERR_PTR(err);
  1510. }
  1511. mutex_lock(&mdsc->mutex);
  1512. }
  1513. if (IS_ERR(req->r_reply)) {
  1514. err = PTR_ERR(req->r_reply);
  1515. req->r_reply = NULL;
  1516. if (err == -ERESTARTSYS) {
  1517. /* aborted */
  1518. req->r_aborted = true;
  1519. if (req->r_locked_dir &&
  1520. (req->r_op & CEPH_MDS_OP_WRITE)) {
  1521. struct ceph_inode_info *ci =
  1522. ceph_inode(req->r_locked_dir);
  1523. dout("aborted, clearing I_COMPLETE on %p\n",
  1524. req->r_locked_dir);
  1525. spin_lock(&req->r_locked_dir->i_lock);
  1526. ci->i_ceph_flags &= ~CEPH_I_COMPLETE;
  1527. ci->i_release_count++;
  1528. spin_unlock(&req->r_locked_dir->i_lock);
  1529. }
  1530. } else {
  1531. /* clean up this request */
  1532. __unregister_request(mdsc, req);
  1533. if (!list_empty(&req->r_unsafe_item))
  1534. list_del_init(&req->r_unsafe_item);
  1535. complete(&req->r_safe_completion);
  1536. }
  1537. } else if (req->r_err) {
  1538. err = req->r_err;
  1539. } else {
  1540. err = le32_to_cpu(req->r_reply_info.head->result);
  1541. }
  1542. mutex_unlock(&mdsc->mutex);
  1543. dout("do_request %p done, result %d\n", req, err);
  1544. return err;
  1545. }
  1546. /*
  1547. * Handle mds reply.
  1548. *
  1549. * We take the session mutex and parse and process the reply immediately.
  1550. * This preserves the logical ordering of replies, capabilities, etc., sent
  1551. * by the MDS as they are applied to our local cache.
  1552. */
  1553. static void handle_reply(struct ceph_mds_session *session, struct ceph_msg *msg)
  1554. {
  1555. struct ceph_mds_client *mdsc = session->s_mdsc;
  1556. struct ceph_mds_request *req;
  1557. struct ceph_mds_reply_head *head = msg->front.iov_base;
  1558. struct ceph_mds_reply_info_parsed *rinfo; /* parsed reply info */
  1559. u64 tid;
  1560. int err, result;
  1561. int mds = session->s_mds;
  1562. if (msg->front.iov_len < sizeof(*head)) {
  1563. pr_err("mdsc_handle_reply got corrupt (short) reply\n");
  1564. ceph_msg_dump(msg);
  1565. return;
  1566. }
  1567. /* get request, session */
  1568. tid = le64_to_cpu(msg->hdr.tid);
  1569. mutex_lock(&mdsc->mutex);
  1570. req = __lookup_request(mdsc, tid);
  1571. if (!req) {
  1572. dout("handle_reply on unknown tid %llu\n", tid);
  1573. mutex_unlock(&mdsc->mutex);
  1574. return;
  1575. }
  1576. dout("handle_reply %p\n", req);
  1577. /* correct session? */
  1578. if (req->r_session != session) {
  1579. pr_err("mdsc_handle_reply got %llu on session mds%d"
  1580. " not mds%d\n", tid, session->s_mds,
  1581. req->r_session ? req->r_session->s_mds : -1);
  1582. mutex_unlock(&mdsc->mutex);
  1583. goto out;
  1584. }
  1585. /* dup? */
  1586. if ((req->r_got_unsafe && !head->safe) ||
  1587. (req->r_got_safe && head->safe)) {
  1588. pr_warning("got a dup %s reply on %llu from mds%d\n",
  1589. head->safe ? "safe" : "unsafe", tid, mds);
  1590. mutex_unlock(&mdsc->mutex);
  1591. goto out;
  1592. }
  1593. result = le32_to_cpu(head->result);
  1594. /*
  1595. * Tolerate 2 consecutive ESTALEs from the same mds.
  1596. * FIXME: we should be looking at the cap migrate_seq.
  1597. */
  1598. if (result == -ESTALE) {
  1599. req->r_direct_mode = USE_AUTH_MDS;
  1600. req->r_num_stale++;
  1601. if (req->r_num_stale <= 2) {
  1602. __do_request(mdsc, req);
  1603. mutex_unlock(&mdsc->mutex);
  1604. goto out;
  1605. }
  1606. } else {
  1607. req->r_num_stale = 0;
  1608. }
  1609. if (head->safe) {
  1610. req->r_got_safe = true;
  1611. __unregister_request(mdsc, req);
  1612. complete(&req->r_safe_completion);
  1613. if (req->r_got_unsafe) {
  1614. /*
  1615. * We already handled the unsafe response, now do the
  1616. * cleanup. No need to examine the response; the MDS
  1617. * doesn't include any result info in the safe
  1618. * response. And even if it did, there is nothing
  1619. * useful we could do with a revised return value.
  1620. */
  1621. dout("got safe reply %llu, mds%d\n", tid, mds);
  1622. list_del_init(&req->r_unsafe_item);
  1623. /* last unsafe request during umount? */
  1624. if (mdsc->stopping && !__get_oldest_req(mdsc))
  1625. complete(&mdsc->safe_umount_waiters);
  1626. mutex_unlock(&mdsc->mutex);
  1627. goto out;
  1628. }
  1629. }
  1630. BUG_ON(req->r_reply);
  1631. if (!head->safe) {
  1632. req->r_got_unsafe = true;
  1633. list_add_tail(&req->r_unsafe_item, &req->r_session->s_unsafe);
  1634. }
  1635. dout("handle_reply tid %lld result %d\n", tid, result);
  1636. rinfo = &req->r_reply_info;
  1637. err = parse_reply_info(msg, rinfo);
  1638. mutex_unlock(&mdsc->mutex);
  1639. mutex_lock(&session->s_mutex);
  1640. if (err < 0) {
  1641. pr_err("mdsc_handle_reply got corrupt reply mds%d\n", mds);
  1642. ceph_msg_dump(msg);
  1643. goto out_err;
  1644. }
  1645. /* snap trace */
  1646. if (rinfo->snapblob_len) {
  1647. down_write(&mdsc->snap_rwsem);
  1648. ceph_update_snap_trace(mdsc, rinfo->snapblob,
  1649. rinfo->snapblob + rinfo->snapblob_len,
  1650. le32_to_cpu(head->op) == CEPH_MDS_OP_RMSNAP);
  1651. downgrade_write(&mdsc->snap_rwsem);
  1652. } else {
  1653. down_read(&mdsc->snap_rwsem);
  1654. }
  1655. /* insert trace into our cache */
  1656. err = ceph_fill_trace(mdsc->client->sb, req, req->r_session);
  1657. if (err == 0) {
  1658. if (result == 0 && rinfo->dir_nr)
  1659. ceph_readdir_prepopulate(req, req->r_session);
  1660. ceph_unreserve_caps(&req->r_caps_reservation);
  1661. }
  1662. up_read(&mdsc->snap_rwsem);
  1663. out_err:
  1664. if (err) {
  1665. req->r_err = err;
  1666. } else {
  1667. req->r_reply = msg;
  1668. ceph_msg_get(msg);
  1669. }
  1670. add_cap_releases(mdsc, req->r_session, -1);
  1671. mutex_unlock(&session->s_mutex);
  1672. /* kick calling process */
  1673. complete_request(mdsc, req);
  1674. out:
  1675. ceph_mdsc_put_request(req);
  1676. return;
  1677. }
  1678. /*
  1679. * handle mds notification that our request has been forwarded.
  1680. */
  1681. static void handle_forward(struct ceph_mds_client *mdsc,
  1682. struct ceph_mds_session *session,
  1683. struct ceph_msg *msg)
  1684. {
  1685. struct ceph_mds_request *req;
  1686. u64 tid = le64_to_cpu(msg->hdr.tid);
  1687. u32 next_mds;
  1688. u32 fwd_seq;
  1689. int err = -EINVAL;
  1690. void *p = msg->front.iov_base;
  1691. void *end = p + msg->front.iov_len;
  1692. ceph_decode_need(&p, end, 2*sizeof(u32), bad);
  1693. next_mds = ceph_decode_32(&p);
  1694. fwd_seq = ceph_decode_32(&p);
  1695. mutex_lock(&mdsc->mutex);
  1696. req = __lookup_request(mdsc, tid);
  1697. if (!req) {
  1698. dout("forward %llu to mds%d - req dne\n", tid, next_mds);
  1699. goto out; /* dup reply? */
  1700. }
  1701. if (fwd_seq <= req->r_num_fwd) {
  1702. dout("forward %llu to mds%d - old seq %d <= %d\n",
  1703. tid, next_mds, req->r_num_fwd, fwd_seq);
  1704. } else {
  1705. /* resend. forward race not possible; mds would drop */
  1706. dout("forward %llu to mds%d (we resend)\n", tid, next_mds);
  1707. req->r_num_fwd = fwd_seq;
  1708. req->r_resend_mds = next_mds;
  1709. put_request_session(req);
  1710. __do_request(mdsc, req);
  1711. }
  1712. ceph_mdsc_put_request(req);
  1713. out:
  1714. mutex_unlock(&mdsc->mutex);
  1715. return;
  1716. bad:
  1717. pr_err("mdsc_handle_forward decode error err=%d\n", err);
  1718. }
  1719. /*
  1720. * handle a mds session control message
  1721. */
  1722. static void handle_session(struct ceph_mds_session *session,
  1723. struct ceph_msg *msg)
  1724. {
  1725. struct ceph_mds_client *mdsc = session->s_mdsc;
  1726. u32 op;
  1727. u64 seq;
  1728. int mds = session->s_mds;
  1729. struct ceph_mds_session_head *h = msg->front.iov_base;
  1730. int wake = 0;
  1731. /* decode */
  1732. if (msg->front.iov_len != sizeof(*h))
  1733. goto bad;
  1734. op = le32_to_cpu(h->op);
  1735. seq = le64_to_cpu(h->seq);
  1736. mutex_lock(&mdsc->mutex);
  1737. if (op == CEPH_SESSION_CLOSE)
  1738. __unregister_session(mdsc, session);
  1739. /* FIXME: this ttl calculation is generous */
  1740. session->s_ttl = jiffies + HZ*mdsc->mdsmap->m_session_autoclose;
  1741. mutex_unlock(&mdsc->mutex);
  1742. mutex_lock(&session->s_mutex);
  1743. dout("handle_session mds%d %s %p state %s seq %llu\n",
  1744. mds, ceph_session_op_name(op), session,
  1745. session_state_name(session->s_state), seq);
  1746. if (session->s_state == CEPH_MDS_SESSION_HUNG) {
  1747. session->s_state = CEPH_MDS_SESSION_OPEN;
  1748. pr_info("mds%d came back\n", session->s_mds);
  1749. }
  1750. switch (op) {
  1751. case CEPH_SESSION_OPEN:
  1752. session->s_state = CEPH_MDS_SESSION_OPEN;
  1753. renewed_caps(mdsc, session, 0);
  1754. wake = 1;
  1755. if (mdsc->stopping)
  1756. __close_session(mdsc, session);
  1757. break;
  1758. case CEPH_SESSION_RENEWCAPS:
  1759. if (session->s_renew_seq == seq)
  1760. renewed_caps(mdsc, session, 1);
  1761. break;
  1762. case CEPH_SESSION_CLOSE:
  1763. remove_session_caps(session);
  1764. wake = 1; /* for good measure */
  1765. complete(&mdsc->session_close_waiters);
  1766. kick_requests(mdsc, mds, 0); /* cur only */
  1767. break;
  1768. case CEPH_SESSION_STALE:
  1769. pr_info("mds%d caps went stale, renewing\n",
  1770. session->s_mds);
  1771. spin_lock(&session->s_cap_lock);
  1772. session->s_cap_gen++;
  1773. session->s_cap_ttl = 0;
  1774. spin_unlock(&session->s_cap_lock);
  1775. send_renew_caps(mdsc, session);
  1776. break;
  1777. case CEPH_SESSION_RECALL_STATE:
  1778. trim_caps(mdsc, session, le32_to_cpu(h->max_caps));
  1779. break;
  1780. default:
  1781. pr_err("mdsc_handle_session bad op %d mds%d\n", op, mds);
  1782. WARN_ON(1);
  1783. }
  1784. mutex_unlock(&session->s_mutex);
  1785. if (wake) {
  1786. mutex_lock(&mdsc->mutex);
  1787. __wake_requests(mdsc, &session->s_waiting);
  1788. mutex_unlock(&mdsc->mutex);
  1789. }
  1790. return;
  1791. bad:
  1792. pr_err("mdsc_handle_session corrupt message mds%d len %d\n", mds,
  1793. (int)msg->front.iov_len);
  1794. ceph_msg_dump(msg);
  1795. return;
  1796. }
  1797. /*
  1798. * called under session->mutex.
  1799. */
  1800. static void replay_unsafe_requests(struct ceph_mds_client *mdsc,
  1801. struct ceph_mds_session *session)
  1802. {
  1803. struct ceph_mds_request *req, *nreq;
  1804. int err;
  1805. dout("replay_unsafe_requests mds%d\n", session->s_mds);
  1806. mutex_lock(&mdsc->mutex);
  1807. list_for_each_entry_safe(req, nreq, &session->s_unsafe, r_unsafe_item) {
  1808. err = __prepare_send_request(mdsc, req, session->s_mds);
  1809. if (!err) {
  1810. ceph_msg_get(req->r_request);
  1811. ceph_con_send(&session->s_con, req->r_request);
  1812. }
  1813. }
  1814. mutex_unlock(&mdsc->mutex);
  1815. }
  1816. /*
  1817. * Encode information about a cap for a reconnect with the MDS.
  1818. */
  1819. static int encode_caps_cb(struct inode *inode, struct ceph_cap *cap,
  1820. void *arg)
  1821. {
  1822. struct ceph_mds_cap_reconnect rec;
  1823. struct ceph_inode_info *ci;
  1824. struct ceph_pagelist *pagelist = arg;
  1825. char *path;
  1826. int pathlen, err;
  1827. u64 pathbase;
  1828. struct dentry *dentry;
  1829. ci = cap->ci;
  1830. dout(" adding %p ino %llx.%llx cap %p %lld %s\n",
  1831. inode, ceph_vinop(inode), cap, cap->cap_id,
  1832. ceph_cap_string(cap->issued));
  1833. err = ceph_pagelist_encode_64(pagelist, ceph_ino(inode));
  1834. if (err)
  1835. return err;
  1836. dentry = d_find_alias(inode);
  1837. if (dentry) {
  1838. path = ceph_mdsc_build_path(dentry, &pathlen, &pathbase, 0);
  1839. if (IS_ERR(path)) {
  1840. err = PTR_ERR(path);
  1841. BUG_ON(err);
  1842. }
  1843. } else {
  1844. path = NULL;
  1845. pathlen = 0;
  1846. }
  1847. err = ceph_pagelist_encode_string(pagelist, path, pathlen);
  1848. if (err)
  1849. goto out;
  1850. spin_lock(&inode->i_lock);
  1851. cap->seq = 0; /* reset cap seq */
  1852. cap->issue_seq = 0; /* and issue_seq */
  1853. rec.cap_id = cpu_to_le64(cap->cap_id);
  1854. rec.pathbase = cpu_to_le64(pathbase);
  1855. rec.wanted = cpu_to_le32(__ceph_caps_wanted(ci));
  1856. rec.issued = cpu_to_le32(cap->issued);
  1857. rec.size = cpu_to_le64(inode->i_size);
  1858. ceph_encode_timespec(&rec.mtime, &inode->i_mtime);
  1859. ceph_encode_timespec(&rec.atime, &inode->i_atime);
  1860. rec.snaprealm = cpu_to_le64(ci->i_snap_realm->ino);
  1861. spin_unlock(&inode->i_lock);
  1862. err = ceph_pagelist_append(pagelist, &rec, sizeof(rec));
  1863. out:
  1864. kfree(path);
  1865. dput(dentry);
  1866. return err;
  1867. }
  1868. /*
  1869. * If an MDS fails and recovers, clients need to reconnect in order to
  1870. * reestablish shared state. This includes all caps issued through
  1871. * this session _and_ the snap_realm hierarchy. Because it's not
  1872. * clear which snap realms the mds cares about, we send everything we
  1873. * know about.. that ensures we'll then get any new info the
  1874. * recovering MDS might have.
  1875. *
  1876. * This is a relatively heavyweight operation, but it's rare.
  1877. *
  1878. * called with mdsc->mutex held.
  1879. */
  1880. static void send_mds_reconnect(struct ceph_mds_client *mdsc, int mds)
  1881. {
  1882. struct ceph_mds_session *session = NULL;
  1883. struct ceph_msg *reply;
  1884. struct rb_node *p;
  1885. int err;
  1886. struct ceph_pagelist *pagelist;
  1887. pr_info("reconnect to recovering mds%d\n", mds);
  1888. pagelist = kmalloc(sizeof(*pagelist), GFP_NOFS);
  1889. if (!pagelist)
  1890. goto fail_nopagelist;
  1891. ceph_pagelist_init(pagelist);
  1892. reply = ceph_msg_new(CEPH_MSG_CLIENT_RECONNECT, 0, 0, 0, NULL);
  1893. if (IS_ERR(reply)) {
  1894. err = PTR_ERR(reply);
  1895. goto fail_nomsg;
  1896. }
  1897. /* find session */
  1898. session = __ceph_lookup_mds_session(mdsc, mds);
  1899. mutex_unlock(&mdsc->mutex); /* drop lock for duration */
  1900. if (session) {
  1901. mutex_lock(&session->s_mutex);
  1902. session->s_state = CEPH_MDS_SESSION_RECONNECTING;
  1903. session->s_seq = 0;
  1904. ceph_con_open(&session->s_con,
  1905. ceph_mdsmap_get_addr(mdsc->mdsmap, mds));
  1906. /* replay unsafe requests */
  1907. replay_unsafe_requests(mdsc, session);
  1908. } else {
  1909. dout("no session for mds%d, will send short reconnect\n",
  1910. mds);
  1911. }
  1912. down_read(&mdsc->snap_rwsem);
  1913. if (!session)
  1914. goto send;
  1915. dout("session %p state %s\n", session,
  1916. session_state_name(session->s_state));
  1917. /* traverse this session's caps */
  1918. err = ceph_pagelist_encode_32(pagelist, session->s_nr_caps);
  1919. if (err)
  1920. goto fail;
  1921. err = iterate_session_caps(session, encode_caps_cb, pagelist);
  1922. if (err < 0)
  1923. goto out;
  1924. /*
  1925. * snaprealms. we provide mds with the ino, seq (version), and
  1926. * parent for all of our realms. If the mds has any newer info,
  1927. * it will tell us.
  1928. */
  1929. for (p = rb_first(&mdsc->snap_realms); p; p = rb_next(p)) {
  1930. struct ceph_snap_realm *realm =
  1931. rb_entry(p, struct ceph_snap_realm, node);
  1932. struct ceph_mds_snaprealm_reconnect sr_rec;
  1933. dout(" adding snap realm %llx seq %lld parent %llx\n",
  1934. realm->ino, realm->seq, realm->parent_ino);
  1935. sr_rec.ino = cpu_to_le64(realm->ino);
  1936. sr_rec.seq = cpu_to_le64(realm->seq);
  1937. sr_rec.parent = cpu_to_le64(realm->parent_ino);
  1938. err = ceph_pagelist_append(pagelist, &sr_rec, sizeof(sr_rec));
  1939. if (err)
  1940. goto fail;
  1941. }
  1942. send:
  1943. reply->pagelist = pagelist;
  1944. reply->hdr.data_len = cpu_to_le32(pagelist->length);
  1945. reply->nr_pages = calc_pages_for(0, pagelist->length);
  1946. ceph_con_send(&session->s_con, reply);
  1947. if (session) {
  1948. session->s_state = CEPH_MDS_SESSION_OPEN;
  1949. __wake_requests(mdsc, &session->s_waiting);
  1950. }
  1951. out:
  1952. up_read(&mdsc->snap_rwsem);
  1953. if (session) {
  1954. mutex_unlock(&session->s_mutex);
  1955. ceph_put_mds_session(session);
  1956. }
  1957. mutex_lock(&mdsc->mutex);
  1958. return;
  1959. fail:
  1960. ceph_msg_put(reply);
  1961. fail_nomsg:
  1962. ceph_pagelist_release(pagelist);
  1963. kfree(pagelist);
  1964. fail_nopagelist:
  1965. pr_err("ENOMEM preparing reconnect for mds%d\n", mds);
  1966. goto out;
  1967. }
  1968. /*
  1969. * compare old and new mdsmaps, kicking requests
  1970. * and closing out old connections as necessary
  1971. *
  1972. * called under mdsc->mutex.
  1973. */
  1974. static void check_new_map(struct ceph_mds_client *mdsc,
  1975. struct ceph_mdsmap *newmap,
  1976. struct ceph_mdsmap *oldmap)
  1977. {
  1978. int i;
  1979. int oldstate, newstate;
  1980. struct ceph_mds_session *s;
  1981. dout("check_new_map new %u old %u\n",
  1982. newmap->m_epoch, oldmap->m_epoch);
  1983. for (i = 0; i < oldmap->m_max_mds && i < mdsc->max_sessions; i++) {
  1984. if (mdsc->sessions[i] == NULL)
  1985. continue;
  1986. s = mdsc->sessions[i];
  1987. oldstate = ceph_mdsmap_get_state(oldmap, i);
  1988. newstate = ceph_mdsmap_get_state(newmap, i);
  1989. dout("check_new_map mds%d state %s -> %s (session %s)\n",
  1990. i, ceph_mds_state_name(oldstate),
  1991. ceph_mds_state_name(newstate),
  1992. session_state_name(s->s_state));
  1993. if (memcmp(ceph_mdsmap_get_addr(oldmap, i),
  1994. ceph_mdsmap_get_addr(newmap, i),
  1995. sizeof(struct ceph_entity_addr))) {
  1996. if (s->s_state == CEPH_MDS_SESSION_OPENING) {
  1997. /* the session never opened, just close it
  1998. * out now */
  1999. __wake_requests(mdsc, &s->s_waiting);
  2000. __unregister_session(mdsc, s);
  2001. } else {
  2002. /* just close it */
  2003. mutex_unlock(&mdsc->mutex);
  2004. mutex_lock(&s->s_mutex);
  2005. mutex_lock(&mdsc->mutex);
  2006. ceph_con_close(&s->s_con);
  2007. mutex_unlock(&s->s_mutex);
  2008. s->s_state = CEPH_MDS_SESSION_RESTARTING;
  2009. }
  2010. /* kick any requests waiting on the recovering mds */
  2011. kick_requests(mdsc, i, 1);
  2012. } else if (oldstate == newstate) {
  2013. continue; /* nothing new with this mds */
  2014. }
  2015. /*
  2016. * send reconnect?
  2017. */
  2018. if (s->s_state == CEPH_MDS_SESSION_RESTARTING &&
  2019. newstate >= CEPH_MDS_STATE_RECONNECT)
  2020. send_mds_reconnect(mdsc, i);
  2021. /*
  2022. * kick requests on any mds that has gone active.
  2023. *
  2024. * kick requests on cur or forwarder: we may have sent
  2025. * the request to mds1, mds1 told us it forwarded it
  2026. * to mds2, but then we learn mds1 failed and can't be
  2027. * sure it successfully forwarded our request before
  2028. * it died.
  2029. */
  2030. if (oldstate < CEPH_MDS_STATE_ACTIVE &&
  2031. newstate >= CEPH_MDS_STATE_ACTIVE) {
  2032. pr_info("mds%d reconnect completed\n", s->s_mds);
  2033. kick_requests(mdsc, i, 1);
  2034. ceph_kick_flushing_caps(mdsc, s);
  2035. wake_up_session_caps(s, 1);
  2036. }
  2037. }
  2038. }
  2039. /*
  2040. * leases
  2041. */
  2042. /*
  2043. * caller must hold session s_mutex, dentry->d_lock
  2044. */
  2045. void __ceph_mdsc_drop_dentry_lease(struct dentry *dentry)
  2046. {
  2047. struct ceph_dentry_info *di = ceph_dentry(dentry);
  2048. ceph_put_mds_session(di->lease_session);
  2049. di->lease_session = NULL;
  2050. }
  2051. static void handle_lease(struct ceph_mds_client *mdsc,
  2052. struct ceph_mds_session *session,
  2053. struct ceph_msg *msg)
  2054. {
  2055. struct super_block *sb = mdsc->client->sb;
  2056. struct inode *inode;
  2057. struct ceph_inode_info *ci;
  2058. struct dentry *parent, *dentry;
  2059. struct ceph_dentry_info *di;
  2060. int mds = session->s_mds;
  2061. struct ceph_mds_lease *h = msg->front.iov_base;
  2062. struct ceph_vino vino;
  2063. int mask;
  2064. struct qstr dname;
  2065. int release = 0;
  2066. dout("handle_lease from mds%d\n", mds);
  2067. /* decode */
  2068. if (msg->front.iov_len < sizeof(*h) + sizeof(u32))
  2069. goto bad;
  2070. vino.ino = le64_to_cpu(h->ino);
  2071. vino.snap = CEPH_NOSNAP;
  2072. mask = le16_to_cpu(h->mask);
  2073. dname.name = (void *)h + sizeof(*h) + sizeof(u32);
  2074. dname.len = msg->front.iov_len - sizeof(*h) - sizeof(u32);
  2075. if (dname.len != get_unaligned_le32(h+1))
  2076. goto bad;
  2077. mutex_lock(&session->s_mutex);
  2078. session->s_seq++;
  2079. /* lookup inode */
  2080. inode = ceph_find_inode(sb, vino);
  2081. dout("handle_lease '%s', mask %d, ino %llx %p\n",
  2082. ceph_lease_op_name(h->action), mask, vino.ino, inode);
  2083. if (inode == NULL) {
  2084. dout("handle_lease no inode %llx\n", vino.ino);
  2085. goto release;
  2086. }
  2087. ci = ceph_inode(inode);
  2088. /* dentry */
  2089. parent = d_find_alias(inode);
  2090. if (!parent) {
  2091. dout("no parent dentry on inode %p\n", inode);
  2092. WARN_ON(1);
  2093. goto release; /* hrm... */
  2094. }
  2095. dname.hash = full_name_hash(dname.name, dname.len);
  2096. dentry = d_lookup(parent, &dname);
  2097. dput(parent);
  2098. if (!dentry)
  2099. goto release;
  2100. spin_lock(&dentry->d_lock);
  2101. di = ceph_dentry(dentry);
  2102. switch (h->action) {
  2103. case CEPH_MDS_LEASE_REVOKE:
  2104. if (di && di->lease_session == session) {
  2105. h->seq = cpu_to_le32(di->lease_seq);
  2106. __ceph_mdsc_drop_dentry_lease(dentry);
  2107. }
  2108. release = 1;
  2109. break;
  2110. case CEPH_MDS_LEASE_RENEW:
  2111. if (di && di->lease_session == session &&
  2112. di->lease_gen == session->s_cap_gen &&
  2113. di->lease_renew_from &&
  2114. di->lease_renew_after == 0) {
  2115. unsigned long duration =
  2116. le32_to_cpu(h->duration_ms) * HZ / 1000;
  2117. di->lease_seq = le32_to_cpu(h->seq);
  2118. dentry->d_time = di->lease_renew_from + duration;
  2119. di->lease_renew_after = di->lease_renew_from +
  2120. (duration >> 1);
  2121. di->lease_renew_from = 0;
  2122. }
  2123. break;
  2124. }
  2125. spin_unlock(&dentry->d_lock);
  2126. dput(dentry);
  2127. if (!release)
  2128. goto out;
  2129. release:
  2130. /* let's just reuse the same message */
  2131. h->action = CEPH_MDS_LEASE_REVOKE_ACK;
  2132. ceph_msg_get(msg);
  2133. ceph_con_send(&session->s_con, msg);
  2134. out:
  2135. iput(inode);
  2136. mutex_unlock(&session->s_mutex);
  2137. return;
  2138. bad:
  2139. pr_err("corrupt lease message\n");
  2140. ceph_msg_dump(msg);
  2141. }
  2142. void ceph_mdsc_lease_send_msg(struct ceph_mds_session *session,
  2143. struct inode *inode,
  2144. struct dentry *dentry, char action,
  2145. u32 seq)
  2146. {
  2147. struct ceph_msg *msg;
  2148. struct ceph_mds_lease *lease;
  2149. int len = sizeof(*lease) + sizeof(u32);
  2150. int dnamelen = 0;
  2151. dout("lease_send_msg inode %p dentry %p %s to mds%d\n",
  2152. inode, dentry, ceph_lease_op_name(action), session->s_mds);
  2153. dnamelen = dentry->d_name.len;
  2154. len += dnamelen;
  2155. msg = ceph_msg_new(CEPH_MSG_CLIENT_LEASE, len, 0, 0, NULL);
  2156. if (IS_ERR(msg))
  2157. return;
  2158. lease = msg->front.iov_base;
  2159. lease->action = action;
  2160. lease->mask = cpu_to_le16(CEPH_LOCK_DN);
  2161. lease->ino = cpu_to_le64(ceph_vino(inode).ino);
  2162. lease->first = lease->last = cpu_to_le64(ceph_vino(inode).snap);
  2163. lease->seq = cpu_to_le32(seq);
  2164. put_unaligned_le32(dnamelen, lease + 1);
  2165. memcpy((void *)(lease + 1) + 4, dentry->d_name.name, dnamelen);
  2166. /*
  2167. * if this is a preemptive lease RELEASE, no need to
  2168. * flush request stream, since the actual request will
  2169. * soon follow.
  2170. */
  2171. msg->more_to_follow = (action == CEPH_MDS_LEASE_RELEASE);
  2172. ceph_con_send(&session->s_con, msg);
  2173. }
  2174. /*
  2175. * Preemptively release a lease we expect to invalidate anyway.
  2176. * Pass @inode always, @dentry is optional.
  2177. */
  2178. void ceph_mdsc_lease_release(struct ceph_mds_client *mdsc, struct inode *inode,
  2179. struct dentry *dentry, int mask)
  2180. {
  2181. struct ceph_dentry_info *di;
  2182. struct ceph_mds_session *session;
  2183. u32 seq;
  2184. BUG_ON(inode == NULL);
  2185. BUG_ON(dentry == NULL);
  2186. BUG_ON(mask != CEPH_LOCK_DN);
  2187. /* is dentry lease valid? */
  2188. spin_lock(&dentry->d_lock);
  2189. di = ceph_dentry(dentry);
  2190. if (!di || !di->lease_session ||
  2191. di->lease_session->s_mds < 0 ||
  2192. di->lease_gen != di->lease_session->s_cap_gen ||
  2193. !time_before(jiffies, dentry->d_time)) {
  2194. dout("lease_release inode %p dentry %p -- "
  2195. "no lease on %d\n",
  2196. inode, dentry, mask);
  2197. spin_unlock(&dentry->d_lock);
  2198. return;
  2199. }
  2200. /* we do have a lease on this dentry; note mds and seq */
  2201. session = ceph_get_mds_session(di->lease_session);
  2202. seq = di->lease_seq;
  2203. __ceph_mdsc_drop_dentry_lease(dentry);
  2204. spin_unlock(&dentry->d_lock);
  2205. dout("lease_release inode %p dentry %p mask %d to mds%d\n",
  2206. inode, dentry, mask, session->s_mds);
  2207. ceph_mdsc_lease_send_msg(session, inode, dentry,
  2208. CEPH_MDS_LEASE_RELEASE, seq);
  2209. ceph_put_mds_session(session);
  2210. }
  2211. /*
  2212. * drop all leases (and dentry refs) in preparation for umount
  2213. */
  2214. static void drop_leases(struct ceph_mds_client *mdsc)
  2215. {
  2216. int i;
  2217. dout("drop_leases\n");
  2218. mutex_lock(&mdsc->mutex);
  2219. for (i = 0; i < mdsc->max_sessions; i++) {
  2220. struct ceph_mds_session *s = __ceph_lookup_mds_session(mdsc, i);
  2221. if (!s)
  2222. continue;
  2223. mutex_unlock(&mdsc->mutex);
  2224. mutex_lock(&s->s_mutex);
  2225. mutex_unlock(&s->s_mutex);
  2226. ceph_put_mds_session(s);
  2227. mutex_lock(&mdsc->mutex);
  2228. }
  2229. mutex_unlock(&mdsc->mutex);
  2230. }
  2231. /*
  2232. * delayed work -- periodically trim expired leases, renew caps with mds
  2233. */
  2234. static void schedule_delayed(struct ceph_mds_client *mdsc)
  2235. {
  2236. int delay = 5;
  2237. unsigned hz = round_jiffies_relative(HZ * delay);
  2238. schedule_delayed_work(&mdsc->delayed_work, hz);
  2239. }
  2240. static void delayed_work(struct work_struct *work)
  2241. {
  2242. int i;
  2243. struct ceph_mds_client *mdsc =
  2244. container_of(work, struct ceph_mds_client, delayed_work.work);
  2245. int renew_interval;
  2246. int renew_caps;
  2247. dout("mdsc delayed_work\n");
  2248. ceph_check_delayed_caps(mdsc);
  2249. mutex_lock(&mdsc->mutex);
  2250. renew_interval = mdsc->mdsmap->m_session_timeout >> 2;
  2251. renew_caps = time_after_eq(jiffies, HZ*renew_interval +
  2252. mdsc->last_renew_caps);
  2253. if (renew_caps)
  2254. mdsc->last_renew_caps = jiffies;
  2255. for (i = 0; i < mdsc->max_sessions; i++) {
  2256. struct ceph_mds_session *s = __ceph_lookup_mds_session(mdsc, i);
  2257. if (s == NULL)
  2258. continue;
  2259. if (s->s_state == CEPH_MDS_SESSION_CLOSING) {
  2260. dout("resending session close request for mds%d\n",
  2261. s->s_mds);
  2262. request_close_session(mdsc, s);
  2263. ceph_put_mds_session(s);
  2264. continue;
  2265. }
  2266. if (s->s_ttl && time_after(jiffies, s->s_ttl)) {
  2267. if (s->s_state == CEPH_MDS_SESSION_OPEN) {
  2268. s->s_state = CEPH_MDS_SESSION_HUNG;
  2269. pr_info("mds%d hung\n", s->s_mds);
  2270. }
  2271. }
  2272. if (s->s_state < CEPH_MDS_SESSION_OPEN) {
  2273. /* this mds is failed or recovering, just wait */
  2274. ceph_put_mds_session(s);
  2275. continue;
  2276. }
  2277. mutex_unlock(&mdsc->mutex);
  2278. mutex_lock(&s->s_mutex);
  2279. if (renew_caps)
  2280. send_renew_caps(mdsc, s);
  2281. else
  2282. ceph_con_keepalive(&s->s_con);
  2283. add_cap_releases(mdsc, s, -1);
  2284. send_cap_releases(mdsc, s);
  2285. mutex_unlock(&s->s_mutex);
  2286. ceph_put_mds_session(s);
  2287. mutex_lock(&mdsc->mutex);
  2288. }
  2289. mutex_unlock(&mdsc->mutex);
  2290. schedule_delayed(mdsc);
  2291. }
  2292. int ceph_mdsc_init(struct ceph_mds_client *mdsc, struct ceph_client *client)
  2293. {
  2294. mdsc->client = client;
  2295. mutex_init(&mdsc->mutex);
  2296. mdsc->mdsmap = kzalloc(sizeof(*mdsc->mdsmap), GFP_NOFS);
  2297. init_completion(&mdsc->safe_umount_waiters);
  2298. init_completion(&mdsc->session_close_waiters);
  2299. INIT_LIST_HEAD(&mdsc->waiting_for_map);
  2300. mdsc->sessions = NULL;
  2301. mdsc->max_sessions = 0;
  2302. mdsc->stopping = 0;
  2303. init_rwsem(&mdsc->snap_rwsem);
  2304. mdsc->snap_realms = RB_ROOT;
  2305. INIT_LIST_HEAD(&mdsc->snap_empty);
  2306. spin_lock_init(&mdsc->snap_empty_lock);
  2307. mdsc->last_tid = 0;
  2308. mdsc->request_tree = RB_ROOT;
  2309. INIT_DELAYED_WORK(&mdsc->delayed_work, delayed_work);
  2310. mdsc->last_renew_caps = jiffies;
  2311. INIT_LIST_HEAD(&mdsc->cap_delay_list);
  2312. spin_lock_init(&mdsc->cap_delay_lock);
  2313. INIT_LIST_HEAD(&mdsc->snap_flush_list);
  2314. spin_lock_init(&mdsc->snap_flush_lock);
  2315. mdsc->cap_flush_seq = 0;
  2316. INIT_LIST_HEAD(&mdsc->cap_dirty);
  2317. mdsc->num_cap_flushing = 0;
  2318. spin_lock_init(&mdsc->cap_dirty_lock);
  2319. init_waitqueue_head(&mdsc->cap_flushing_wq);
  2320. spin_lock_init(&mdsc->dentry_lru_lock);
  2321. INIT_LIST_HEAD(&mdsc->dentry_lru);
  2322. return 0;
  2323. }
  2324. /*
  2325. * Wait for safe replies on open mds requests. If we time out, drop
  2326. * all requests from the tree to avoid dangling dentry refs.
  2327. */
  2328. static void wait_requests(struct ceph_mds_client *mdsc)
  2329. {
  2330. struct ceph_mds_request *req;
  2331. struct ceph_client *client = mdsc->client;
  2332. mutex_lock(&mdsc->mutex);
  2333. if (__get_oldest_req(mdsc)) {
  2334. mutex_unlock(&mdsc->mutex);
  2335. dout("wait_requests waiting for requests\n");
  2336. wait_for_completion_timeout(&mdsc->safe_umount_waiters,
  2337. client->mount_args->mount_timeout * HZ);
  2338. /* tear down remaining requests */
  2339. mutex_lock(&mdsc->mutex);
  2340. while ((req = __get_oldest_req(mdsc))) {
  2341. dout("wait_requests timed out on tid %llu\n",
  2342. req->r_tid);
  2343. __unregister_request(mdsc, req);
  2344. }
  2345. }
  2346. mutex_unlock(&mdsc->mutex);
  2347. dout("wait_requests done\n");
  2348. }
  2349. /*
  2350. * called before mount is ro, and before dentries are torn down.
  2351. * (hmm, does this still race with new lookups?)
  2352. */
  2353. void ceph_mdsc_pre_umount(struct ceph_mds_client *mdsc)
  2354. {
  2355. dout("pre_umount\n");
  2356. mdsc->stopping = 1;
  2357. drop_leases(mdsc);
  2358. ceph_flush_dirty_caps(mdsc);
  2359. wait_requests(mdsc);
  2360. }
  2361. /*
  2362. * wait for all write mds requests to flush.
  2363. */
  2364. static void wait_unsafe_requests(struct ceph_mds_client *mdsc, u64 want_tid)
  2365. {
  2366. struct ceph_mds_request *req = NULL, *nextreq;
  2367. struct rb_node *n;
  2368. mutex_lock(&mdsc->mutex);
  2369. dout("wait_unsafe_requests want %lld\n", want_tid);
  2370. restart:
  2371. req = __get_oldest_req(mdsc);
  2372. while (req && req->r_tid <= want_tid) {
  2373. /* find next request */
  2374. n = rb_next(&req->r_node);
  2375. if (n)
  2376. nextreq = rb_entry(n, struct ceph_mds_request, r_node);
  2377. else
  2378. nextreq = NULL;
  2379. if ((req->r_op & CEPH_MDS_OP_WRITE)) {
  2380. /* write op */
  2381. ceph_mdsc_get_request(req);
  2382. if (nextreq)
  2383. ceph_mdsc_get_request(nextreq);
  2384. mutex_unlock(&mdsc->mutex);
  2385. dout("wait_unsafe_requests wait on %llu (want %llu)\n",
  2386. req->r_tid, want_tid);
  2387. wait_for_completion(&req->r_safe_completion);
  2388. mutex_lock(&mdsc->mutex);
  2389. ceph_mdsc_put_request(req);
  2390. if (!nextreq)
  2391. break; /* next dne before, so we're done! */
  2392. if (RB_EMPTY_NODE(&nextreq->r_node)) {
  2393. /* next request was removed from tree */
  2394. ceph_mdsc_put_request(nextreq);
  2395. goto restart;
  2396. }
  2397. ceph_mdsc_put_request(nextreq); /* won't go away */
  2398. }
  2399. req = nextreq;
  2400. }
  2401. mutex_unlock(&mdsc->mutex);
  2402. dout("wait_unsafe_requests done\n");
  2403. }
  2404. void ceph_mdsc_sync(struct ceph_mds_client *mdsc)
  2405. {
  2406. u64 want_tid, want_flush;
  2407. dout("sync\n");
  2408. mutex_lock(&mdsc->mutex);
  2409. want_tid = mdsc->last_tid;
  2410. want_flush = mdsc->cap_flush_seq;
  2411. mutex_unlock(&mdsc->mutex);
  2412. dout("sync want tid %lld flush_seq %lld\n", want_tid, want_flush);
  2413. ceph_flush_dirty_caps(mdsc);
  2414. wait_unsafe_requests(mdsc, want_tid);
  2415. wait_event(mdsc->cap_flushing_wq, check_cap_flush(mdsc, want_flush));
  2416. }
  2417. /*
  2418. * called after sb is ro.
  2419. */
  2420. void ceph_mdsc_close_sessions(struct ceph_mds_client *mdsc)
  2421. {
  2422. struct ceph_mds_session *session;
  2423. int i;
  2424. int n;
  2425. struct ceph_client *client = mdsc->client;
  2426. unsigned long started, timeout = client->mount_args->mount_timeout * HZ;
  2427. dout("close_sessions\n");
  2428. mutex_lock(&mdsc->mutex);
  2429. /* close sessions */
  2430. started = jiffies;
  2431. while (time_before(jiffies, started + timeout)) {
  2432. dout("closing sessions\n");
  2433. n = 0;
  2434. for (i = 0; i < mdsc->max_sessions; i++) {
  2435. session = __ceph_lookup_mds_session(mdsc, i);
  2436. if (!session)
  2437. continue;
  2438. mutex_unlock(&mdsc->mutex);
  2439. mutex_lock(&session->s_mutex);
  2440. __close_session(mdsc, session);
  2441. mutex_unlock(&session->s_mutex);
  2442. ceph_put_mds_session(session);
  2443. mutex_lock(&mdsc->mutex);
  2444. n++;
  2445. }
  2446. if (n == 0)
  2447. break;
  2448. if (client->mount_state == CEPH_MOUNT_SHUTDOWN)
  2449. break;
  2450. dout("waiting for sessions to close\n");
  2451. mutex_unlock(&mdsc->mutex);
  2452. wait_for_completion_timeout(&mdsc->session_close_waiters,
  2453. timeout);
  2454. mutex_lock(&mdsc->mutex);
  2455. }
  2456. /* tear down remaining sessions */
  2457. for (i = 0; i < mdsc->max_sessions; i++) {
  2458. if (mdsc->sessions[i]) {
  2459. session = get_session(mdsc->sessions[i]);
  2460. __unregister_session(mdsc, session);
  2461. mutex_unlock(&mdsc->mutex);
  2462. mutex_lock(&session->s_mutex);
  2463. remove_session_caps(session);
  2464. mutex_unlock(&session->s_mutex);
  2465. ceph_put_mds_session(session);
  2466. mutex_lock(&mdsc->mutex);
  2467. }
  2468. }
  2469. WARN_ON(!list_empty(&mdsc->cap_delay_list));
  2470. mutex_unlock(&mdsc->mutex);
  2471. ceph_cleanup_empty_realms(mdsc);
  2472. cancel_delayed_work_sync(&mdsc->delayed_work); /* cancel timer */
  2473. dout("stopped\n");
  2474. }
  2475. void ceph_mdsc_stop(struct ceph_mds_client *mdsc)
  2476. {
  2477. dout("stop\n");
  2478. cancel_delayed_work_sync(&mdsc->delayed_work); /* cancel timer */
  2479. if (mdsc->mdsmap)
  2480. ceph_mdsmap_destroy(mdsc->mdsmap);
  2481. kfree(mdsc->sessions);
  2482. }
  2483. /*
  2484. * handle mds map update.
  2485. */
  2486. void ceph_mdsc_handle_map(struct ceph_mds_client *mdsc, struct ceph_msg *msg)
  2487. {
  2488. u32 epoch;
  2489. u32 maplen;
  2490. void *p = msg->front.iov_base;
  2491. void *end = p + msg->front.iov_len;
  2492. struct ceph_mdsmap *newmap, *oldmap;
  2493. struct ceph_fsid fsid;
  2494. int err = -EINVAL;
  2495. ceph_decode_need(&p, end, sizeof(fsid)+2*sizeof(u32), bad);
  2496. ceph_decode_copy(&p, &fsid, sizeof(fsid));
  2497. if (ceph_check_fsid(mdsc->client, &fsid) < 0)
  2498. return;
  2499. epoch = ceph_decode_32(&p);
  2500. maplen = ceph_decode_32(&p);
  2501. dout("handle_map epoch %u len %d\n", epoch, (int)maplen);
  2502. /* do we need it? */
  2503. ceph_monc_got_mdsmap(&mdsc->client->monc, epoch);
  2504. mutex_lock(&mdsc->mutex);
  2505. if (mdsc->mdsmap && epoch <= mdsc->mdsmap->m_epoch) {
  2506. dout("handle_map epoch %u <= our %u\n",
  2507. epoch, mdsc->mdsmap->m_epoch);
  2508. mutex_unlock(&mdsc->mutex);
  2509. return;
  2510. }
  2511. newmap = ceph_mdsmap_decode(&p, end);
  2512. if (IS_ERR(newmap)) {
  2513. err = PTR_ERR(newmap);
  2514. goto bad_unlock;
  2515. }
  2516. /* swap into place */
  2517. if (mdsc->mdsmap) {
  2518. oldmap = mdsc->mdsmap;
  2519. mdsc->mdsmap = newmap;
  2520. check_new_map(mdsc, newmap, oldmap);
  2521. ceph_mdsmap_destroy(oldmap);
  2522. } else {
  2523. mdsc->mdsmap = newmap; /* first mds map */
  2524. }
  2525. mdsc->client->sb->s_maxbytes = mdsc->mdsmap->m_max_file_size;
  2526. __wake_requests(mdsc, &mdsc->waiting_for_map);
  2527. mutex_unlock(&mdsc->mutex);
  2528. schedule_delayed(mdsc);
  2529. return;
  2530. bad_unlock:
  2531. mutex_unlock(&mdsc->mutex);
  2532. bad:
  2533. pr_err("error decoding mdsmap %d\n", err);
  2534. return;
  2535. }
  2536. static struct ceph_connection *con_get(struct ceph_connection *con)
  2537. {
  2538. struct ceph_mds_session *s = con->private;
  2539. if (get_session(s)) {
  2540. dout("mdsc con_get %p ok (%d)\n", s, atomic_read(&s->s_ref));
  2541. return con;
  2542. }
  2543. dout("mdsc con_get %p FAIL\n", s);
  2544. return NULL;
  2545. }
  2546. static void con_put(struct ceph_connection *con)
  2547. {
  2548. struct ceph_mds_session *s = con->private;
  2549. ceph_put_mds_session(s);
  2550. dout("mdsc con_put %p (%d)\n", s, atomic_read(&s->s_ref));
  2551. }
  2552. /*
  2553. * if the client is unresponsive for long enough, the mds will kill
  2554. * the session entirely.
  2555. */
  2556. static void peer_reset(struct ceph_connection *con)
  2557. {
  2558. struct ceph_mds_session *s = con->private;
  2559. pr_err("mds%d gave us the boot. IMPLEMENT RECONNECT.\n",
  2560. s->s_mds);
  2561. }
  2562. static void dispatch(struct ceph_connection *con, struct ceph_msg *msg)
  2563. {
  2564. struct ceph_mds_session *s = con->private;
  2565. struct ceph_mds_client *mdsc = s->s_mdsc;
  2566. int type = le16_to_cpu(msg->hdr.type);
  2567. mutex_lock(&mdsc->mutex);
  2568. if (__verify_registered_session(mdsc, s) < 0) {
  2569. mutex_unlock(&mdsc->mutex);
  2570. goto out;
  2571. }
  2572. mutex_unlock(&mdsc->mutex);
  2573. switch (type) {
  2574. case CEPH_MSG_MDS_MAP:
  2575. ceph_mdsc_handle_map(mdsc, msg);
  2576. break;
  2577. case CEPH_MSG_CLIENT_SESSION:
  2578. handle_session(s, msg);
  2579. break;
  2580. case CEPH_MSG_CLIENT_REPLY:
  2581. handle_reply(s, msg);
  2582. break;
  2583. case CEPH_MSG_CLIENT_REQUEST_FORWARD:
  2584. handle_forward(mdsc, s, msg);
  2585. break;
  2586. case CEPH_MSG_CLIENT_CAPS:
  2587. ceph_handle_caps(s, msg);
  2588. break;
  2589. case CEPH_MSG_CLIENT_SNAP:
  2590. ceph_handle_snap(mdsc, s, msg);
  2591. break;
  2592. case CEPH_MSG_CLIENT_LEASE:
  2593. handle_lease(mdsc, s, msg);
  2594. break;
  2595. default:
  2596. pr_err("received unknown message type %d %s\n", type,
  2597. ceph_msg_type_name(type));
  2598. }
  2599. out:
  2600. ceph_msg_put(msg);
  2601. }
  2602. /*
  2603. * authentication
  2604. */
  2605. static int get_authorizer(struct ceph_connection *con,
  2606. void **buf, int *len, int *proto,
  2607. void **reply_buf, int *reply_len, int force_new)
  2608. {
  2609. struct ceph_mds_session *s = con->private;
  2610. struct ceph_mds_client *mdsc = s->s_mdsc;
  2611. struct ceph_auth_client *ac = mdsc->client->monc.auth;
  2612. int ret = 0;
  2613. if (force_new && s->s_authorizer) {
  2614. ac->ops->destroy_authorizer(ac, s->s_authorizer);
  2615. s->s_authorizer = NULL;
  2616. }
  2617. if (s->s_authorizer == NULL) {
  2618. if (ac->ops->create_authorizer) {
  2619. ret = ac->ops->create_authorizer(
  2620. ac, CEPH_ENTITY_TYPE_MDS,
  2621. &s->s_authorizer,
  2622. &s->s_authorizer_buf,
  2623. &s->s_authorizer_buf_len,
  2624. &s->s_authorizer_reply_buf,
  2625. &s->s_authorizer_reply_buf_len);
  2626. if (ret)
  2627. return ret;
  2628. }
  2629. }
  2630. *proto = ac->protocol;
  2631. *buf = s->s_authorizer_buf;
  2632. *len = s->s_authorizer_buf_len;
  2633. *reply_buf = s->s_authorizer_reply_buf;
  2634. *reply_len = s->s_authorizer_reply_buf_len;
  2635. return 0;
  2636. }
  2637. static int verify_authorizer_reply(struct ceph_connection *con, int len)
  2638. {
  2639. struct ceph_mds_session *s = con->private;
  2640. struct ceph_mds_client *mdsc = s->s_mdsc;
  2641. struct ceph_auth_client *ac = mdsc->client->monc.auth;
  2642. return ac->ops->verify_authorizer_reply(ac, s->s_authorizer, len);
  2643. }
  2644. static int invalidate_authorizer(struct ceph_connection *con)
  2645. {
  2646. struct ceph_mds_session *s = con->private;
  2647. struct ceph_mds_client *mdsc = s->s_mdsc;
  2648. struct ceph_auth_client *ac = mdsc->client->monc.auth;
  2649. if (ac->ops->invalidate_authorizer)
  2650. ac->ops->invalidate_authorizer(ac, CEPH_ENTITY_TYPE_MDS);
  2651. return ceph_monc_validate_auth(&mdsc->client->monc);
  2652. }
  2653. const static struct ceph_connection_operations mds_con_ops = {
  2654. .get = con_get,
  2655. .put = con_put,
  2656. .dispatch = dispatch,
  2657. .get_authorizer = get_authorizer,
  2658. .verify_authorizer_reply = verify_authorizer_reply,
  2659. .invalidate_authorizer = invalidate_authorizer,
  2660. .peer_reset = peer_reset,
  2661. };
  2662. /* eof */