mds_client.c 76 KB

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