mds_client.c 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055
  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. mutex_init(&req->r_fill_mutex);
  1048. req->r_started = jiffies;
  1049. req->r_resend_mds = -1;
  1050. INIT_LIST_HEAD(&req->r_unsafe_dir_item);
  1051. req->r_fmode = -1;
  1052. kref_init(&req->r_kref);
  1053. INIT_LIST_HEAD(&req->r_wait);
  1054. init_completion(&req->r_completion);
  1055. init_completion(&req->r_safe_completion);
  1056. INIT_LIST_HEAD(&req->r_unsafe_item);
  1057. req->r_op = op;
  1058. req->r_direct_mode = mode;
  1059. return req;
  1060. }
  1061. /*
  1062. * return oldest (lowest) request, tid in request tree, 0 if none.
  1063. *
  1064. * called under mdsc->mutex.
  1065. */
  1066. static struct ceph_mds_request *__get_oldest_req(struct ceph_mds_client *mdsc)
  1067. {
  1068. if (RB_EMPTY_ROOT(&mdsc->request_tree))
  1069. return NULL;
  1070. return rb_entry(rb_first(&mdsc->request_tree),
  1071. struct ceph_mds_request, r_node);
  1072. }
  1073. static u64 __get_oldest_tid(struct ceph_mds_client *mdsc)
  1074. {
  1075. struct ceph_mds_request *req = __get_oldest_req(mdsc);
  1076. if (req)
  1077. return req->r_tid;
  1078. return 0;
  1079. }
  1080. /*
  1081. * Build a dentry's path. Allocate on heap; caller must kfree. Based
  1082. * on build_path_from_dentry in fs/cifs/dir.c.
  1083. *
  1084. * If @stop_on_nosnap, generate path relative to the first non-snapped
  1085. * inode.
  1086. *
  1087. * Encode hidden .snap dirs as a double /, i.e.
  1088. * foo/.snap/bar -> foo//bar
  1089. */
  1090. char *ceph_mdsc_build_path(struct dentry *dentry, int *plen, u64 *base,
  1091. int stop_on_nosnap)
  1092. {
  1093. struct dentry *temp;
  1094. char *path;
  1095. int len, pos;
  1096. if (dentry == NULL)
  1097. return ERR_PTR(-EINVAL);
  1098. retry:
  1099. len = 0;
  1100. for (temp = dentry; !IS_ROOT(temp);) {
  1101. struct inode *inode = temp->d_inode;
  1102. if (inode && ceph_snap(inode) == CEPH_SNAPDIR)
  1103. len++; /* slash only */
  1104. else if (stop_on_nosnap && inode &&
  1105. ceph_snap(inode) == CEPH_NOSNAP)
  1106. break;
  1107. else
  1108. len += 1 + temp->d_name.len;
  1109. temp = temp->d_parent;
  1110. if (temp == NULL) {
  1111. pr_err("build_path_dentry corrupt dentry %p\n", dentry);
  1112. return ERR_PTR(-EINVAL);
  1113. }
  1114. }
  1115. if (len)
  1116. len--; /* no leading '/' */
  1117. path = kmalloc(len+1, GFP_NOFS);
  1118. if (path == NULL)
  1119. return ERR_PTR(-ENOMEM);
  1120. pos = len;
  1121. path[pos] = 0; /* trailing null */
  1122. for (temp = dentry; !IS_ROOT(temp) && pos != 0; ) {
  1123. struct inode *inode = temp->d_inode;
  1124. if (inode && ceph_snap(inode) == CEPH_SNAPDIR) {
  1125. dout("build_path_dentry path+%d: %p SNAPDIR\n",
  1126. pos, temp);
  1127. } else if (stop_on_nosnap && inode &&
  1128. ceph_snap(inode) == CEPH_NOSNAP) {
  1129. break;
  1130. } else {
  1131. pos -= temp->d_name.len;
  1132. if (pos < 0)
  1133. break;
  1134. strncpy(path + pos, temp->d_name.name,
  1135. temp->d_name.len);
  1136. dout("build_path_dentry path+%d: %p '%.*s'\n",
  1137. pos, temp, temp->d_name.len, path + pos);
  1138. }
  1139. if (pos)
  1140. path[--pos] = '/';
  1141. temp = temp->d_parent;
  1142. if (temp == NULL) {
  1143. pr_err("build_path_dentry corrupt dentry\n");
  1144. kfree(path);
  1145. return ERR_PTR(-EINVAL);
  1146. }
  1147. }
  1148. if (pos != 0) {
  1149. pr_err("build_path_dentry did not end path lookup where "
  1150. "expected, namelen is %d, pos is %d\n", len, pos);
  1151. /* presumably this is only possible if racing with a
  1152. rename of one of the parent directories (we can not
  1153. lock the dentries above us to prevent this, but
  1154. retrying should be harmless) */
  1155. kfree(path);
  1156. goto retry;
  1157. }
  1158. *base = ceph_ino(temp->d_inode);
  1159. *plen = len;
  1160. dout("build_path_dentry on %p %d built %llx '%.*s'\n",
  1161. dentry, atomic_read(&dentry->d_count), *base, len, path);
  1162. return path;
  1163. }
  1164. static int build_dentry_path(struct dentry *dentry,
  1165. const char **ppath, int *ppathlen, u64 *pino,
  1166. int *pfreepath)
  1167. {
  1168. char *path;
  1169. if (ceph_snap(dentry->d_parent->d_inode) == CEPH_NOSNAP) {
  1170. *pino = ceph_ino(dentry->d_parent->d_inode);
  1171. *ppath = dentry->d_name.name;
  1172. *ppathlen = dentry->d_name.len;
  1173. return 0;
  1174. }
  1175. path = ceph_mdsc_build_path(dentry, ppathlen, pino, 1);
  1176. if (IS_ERR(path))
  1177. return PTR_ERR(path);
  1178. *ppath = path;
  1179. *pfreepath = 1;
  1180. return 0;
  1181. }
  1182. static int build_inode_path(struct inode *inode,
  1183. const char **ppath, int *ppathlen, u64 *pino,
  1184. int *pfreepath)
  1185. {
  1186. struct dentry *dentry;
  1187. char *path;
  1188. if (ceph_snap(inode) == CEPH_NOSNAP) {
  1189. *pino = ceph_ino(inode);
  1190. *ppathlen = 0;
  1191. return 0;
  1192. }
  1193. dentry = d_find_alias(inode);
  1194. path = ceph_mdsc_build_path(dentry, ppathlen, pino, 1);
  1195. dput(dentry);
  1196. if (IS_ERR(path))
  1197. return PTR_ERR(path);
  1198. *ppath = path;
  1199. *pfreepath = 1;
  1200. return 0;
  1201. }
  1202. /*
  1203. * request arguments may be specified via an inode *, a dentry *, or
  1204. * an explicit ino+path.
  1205. */
  1206. static int set_request_path_attr(struct inode *rinode, struct dentry *rdentry,
  1207. const char *rpath, u64 rino,
  1208. const char **ppath, int *pathlen,
  1209. u64 *ino, int *freepath)
  1210. {
  1211. int r = 0;
  1212. if (rinode) {
  1213. r = build_inode_path(rinode, ppath, pathlen, ino, freepath);
  1214. dout(" inode %p %llx.%llx\n", rinode, ceph_ino(rinode),
  1215. ceph_snap(rinode));
  1216. } else if (rdentry) {
  1217. r = build_dentry_path(rdentry, ppath, pathlen, ino, freepath);
  1218. dout(" dentry %p %llx/%.*s\n", rdentry, *ino, *pathlen,
  1219. *ppath);
  1220. } else if (rpath) {
  1221. *ino = rino;
  1222. *ppath = rpath;
  1223. *pathlen = strlen(rpath);
  1224. dout(" path %.*s\n", *pathlen, rpath);
  1225. }
  1226. return r;
  1227. }
  1228. /*
  1229. * called under mdsc->mutex
  1230. */
  1231. static struct ceph_msg *create_request_message(struct ceph_mds_client *mdsc,
  1232. struct ceph_mds_request *req,
  1233. int mds)
  1234. {
  1235. struct ceph_msg *msg;
  1236. struct ceph_mds_request_head *head;
  1237. const char *path1 = NULL;
  1238. const char *path2 = NULL;
  1239. u64 ino1 = 0, ino2 = 0;
  1240. int pathlen1 = 0, pathlen2 = 0;
  1241. int freepath1 = 0, freepath2 = 0;
  1242. int len;
  1243. u16 releases;
  1244. void *p, *end;
  1245. int ret;
  1246. ret = set_request_path_attr(req->r_inode, req->r_dentry,
  1247. req->r_path1, req->r_ino1.ino,
  1248. &path1, &pathlen1, &ino1, &freepath1);
  1249. if (ret < 0) {
  1250. msg = ERR_PTR(ret);
  1251. goto out;
  1252. }
  1253. ret = set_request_path_attr(NULL, req->r_old_dentry,
  1254. req->r_path2, req->r_ino2.ino,
  1255. &path2, &pathlen2, &ino2, &freepath2);
  1256. if (ret < 0) {
  1257. msg = ERR_PTR(ret);
  1258. goto out_free1;
  1259. }
  1260. len = sizeof(*head) +
  1261. pathlen1 + pathlen2 + 2*(1 + sizeof(u32) + sizeof(u64));
  1262. /* calculate (max) length for cap releases */
  1263. len += sizeof(struct ceph_mds_request_release) *
  1264. (!!req->r_inode_drop + !!req->r_dentry_drop +
  1265. !!req->r_old_inode_drop + !!req->r_old_dentry_drop);
  1266. if (req->r_dentry_drop)
  1267. len += req->r_dentry->d_name.len;
  1268. if (req->r_old_dentry_drop)
  1269. len += req->r_old_dentry->d_name.len;
  1270. msg = ceph_msg_new(CEPH_MSG_CLIENT_REQUEST, len, 0, 0, NULL);
  1271. if (IS_ERR(msg))
  1272. goto out_free2;
  1273. msg->hdr.tid = cpu_to_le64(req->r_tid);
  1274. head = msg->front.iov_base;
  1275. p = msg->front.iov_base + sizeof(*head);
  1276. end = msg->front.iov_base + msg->front.iov_len;
  1277. head->mdsmap_epoch = cpu_to_le32(mdsc->mdsmap->m_epoch);
  1278. head->op = cpu_to_le32(req->r_op);
  1279. head->caller_uid = cpu_to_le32(current_fsuid());
  1280. head->caller_gid = cpu_to_le32(current_fsgid());
  1281. head->args = req->r_args;
  1282. ceph_encode_filepath(&p, end, ino1, path1);
  1283. ceph_encode_filepath(&p, end, ino2, path2);
  1284. /* cap releases */
  1285. releases = 0;
  1286. if (req->r_inode_drop)
  1287. releases += ceph_encode_inode_release(&p,
  1288. req->r_inode ? req->r_inode : req->r_dentry->d_inode,
  1289. mds, req->r_inode_drop, req->r_inode_unless, 0);
  1290. if (req->r_dentry_drop)
  1291. releases += ceph_encode_dentry_release(&p, req->r_dentry,
  1292. mds, req->r_dentry_drop, req->r_dentry_unless);
  1293. if (req->r_old_dentry_drop)
  1294. releases += ceph_encode_dentry_release(&p, req->r_old_dentry,
  1295. mds, req->r_old_dentry_drop, req->r_old_dentry_unless);
  1296. if (req->r_old_inode_drop)
  1297. releases += ceph_encode_inode_release(&p,
  1298. req->r_old_dentry->d_inode,
  1299. mds, req->r_old_inode_drop, req->r_old_inode_unless, 0);
  1300. head->num_releases = cpu_to_le16(releases);
  1301. BUG_ON(p > end);
  1302. msg->front.iov_len = p - msg->front.iov_base;
  1303. msg->hdr.front_len = cpu_to_le32(msg->front.iov_len);
  1304. msg->pages = req->r_pages;
  1305. msg->nr_pages = req->r_num_pages;
  1306. msg->hdr.data_len = cpu_to_le32(req->r_data_len);
  1307. msg->hdr.data_off = cpu_to_le16(0);
  1308. out_free2:
  1309. if (freepath2)
  1310. kfree((char *)path2);
  1311. out_free1:
  1312. if (freepath1)
  1313. kfree((char *)path1);
  1314. out:
  1315. return msg;
  1316. }
  1317. /*
  1318. * called under mdsc->mutex if error, under no mutex if
  1319. * success.
  1320. */
  1321. static void complete_request(struct ceph_mds_client *mdsc,
  1322. struct ceph_mds_request *req)
  1323. {
  1324. if (req->r_callback)
  1325. req->r_callback(mdsc, req);
  1326. else
  1327. complete(&req->r_completion);
  1328. }
  1329. /*
  1330. * called under mdsc->mutex
  1331. */
  1332. static int __prepare_send_request(struct ceph_mds_client *mdsc,
  1333. struct ceph_mds_request *req,
  1334. int mds)
  1335. {
  1336. struct ceph_mds_request_head *rhead;
  1337. struct ceph_msg *msg;
  1338. int flags = 0;
  1339. req->r_mds = mds;
  1340. req->r_attempts++;
  1341. dout("prepare_send_request %p tid %lld %s (attempt %d)\n", req,
  1342. req->r_tid, ceph_mds_op_name(req->r_op), req->r_attempts);
  1343. if (req->r_request) {
  1344. ceph_msg_put(req->r_request);
  1345. req->r_request = NULL;
  1346. }
  1347. msg = create_request_message(mdsc, req, mds);
  1348. if (IS_ERR(msg)) {
  1349. req->r_err = PTR_ERR(msg);
  1350. complete_request(mdsc, req);
  1351. return -PTR_ERR(msg);
  1352. }
  1353. req->r_request = msg;
  1354. rhead = msg->front.iov_base;
  1355. rhead->oldest_client_tid = cpu_to_le64(__get_oldest_tid(mdsc));
  1356. if (req->r_got_unsafe)
  1357. flags |= CEPH_MDS_FLAG_REPLAY;
  1358. if (req->r_locked_dir)
  1359. flags |= CEPH_MDS_FLAG_WANT_DENTRY;
  1360. rhead->flags = cpu_to_le32(flags);
  1361. rhead->num_fwd = req->r_num_fwd;
  1362. rhead->num_retry = req->r_attempts - 1;
  1363. dout(" r_locked_dir = %p\n", req->r_locked_dir);
  1364. if (req->r_target_inode && req->r_got_unsafe)
  1365. rhead->ino = cpu_to_le64(ceph_ino(req->r_target_inode));
  1366. else
  1367. rhead->ino = 0;
  1368. return 0;
  1369. }
  1370. /*
  1371. * send request, or put it on the appropriate wait list.
  1372. */
  1373. static int __do_request(struct ceph_mds_client *mdsc,
  1374. struct ceph_mds_request *req)
  1375. {
  1376. struct ceph_mds_session *session = NULL;
  1377. int mds = -1;
  1378. int err = -EAGAIN;
  1379. if (req->r_err || req->r_got_result)
  1380. goto out;
  1381. if (req->r_timeout &&
  1382. time_after_eq(jiffies, req->r_started + req->r_timeout)) {
  1383. dout("do_request timed out\n");
  1384. err = -EIO;
  1385. goto finish;
  1386. }
  1387. mds = __choose_mds(mdsc, req);
  1388. if (mds < 0 ||
  1389. ceph_mdsmap_get_state(mdsc->mdsmap, mds) < CEPH_MDS_STATE_ACTIVE) {
  1390. dout("do_request no mds or not active, waiting for map\n");
  1391. list_add(&req->r_wait, &mdsc->waiting_for_map);
  1392. goto out;
  1393. }
  1394. /* get, open session */
  1395. session = __ceph_lookup_mds_session(mdsc, mds);
  1396. if (!session) {
  1397. session = register_session(mdsc, mds);
  1398. if (IS_ERR(session)) {
  1399. err = PTR_ERR(session);
  1400. goto finish;
  1401. }
  1402. }
  1403. dout("do_request mds%d session %p state %s\n", mds, session,
  1404. session_state_name(session->s_state));
  1405. if (session->s_state != CEPH_MDS_SESSION_OPEN &&
  1406. session->s_state != CEPH_MDS_SESSION_HUNG) {
  1407. if (session->s_state == CEPH_MDS_SESSION_NEW ||
  1408. session->s_state == CEPH_MDS_SESSION_CLOSING)
  1409. __open_session(mdsc, session);
  1410. list_add(&req->r_wait, &session->s_waiting);
  1411. goto out_session;
  1412. }
  1413. /* send request */
  1414. req->r_session = get_session(session);
  1415. req->r_resend_mds = -1; /* forget any previous mds hint */
  1416. if (req->r_request_started == 0) /* note request start time */
  1417. req->r_request_started = jiffies;
  1418. err = __prepare_send_request(mdsc, req, mds);
  1419. if (!err) {
  1420. ceph_msg_get(req->r_request);
  1421. ceph_con_send(&session->s_con, req->r_request);
  1422. }
  1423. out_session:
  1424. ceph_put_mds_session(session);
  1425. out:
  1426. return err;
  1427. finish:
  1428. req->r_err = err;
  1429. complete_request(mdsc, req);
  1430. goto out;
  1431. }
  1432. /*
  1433. * called under mdsc->mutex
  1434. */
  1435. static void __wake_requests(struct ceph_mds_client *mdsc,
  1436. struct list_head *head)
  1437. {
  1438. struct ceph_mds_request *req, *nreq;
  1439. list_for_each_entry_safe(req, nreq, head, r_wait) {
  1440. list_del_init(&req->r_wait);
  1441. __do_request(mdsc, req);
  1442. }
  1443. }
  1444. /*
  1445. * Wake up threads with requests pending for @mds, so that they can
  1446. * resubmit their requests to a possibly different mds. If @all is set,
  1447. * wake up if their requests has been forwarded to @mds, too.
  1448. */
  1449. static void kick_requests(struct ceph_mds_client *mdsc, int mds, int all)
  1450. {
  1451. struct ceph_mds_request *req;
  1452. struct rb_node *p;
  1453. dout("kick_requests mds%d\n", mds);
  1454. for (p = rb_first(&mdsc->request_tree); p; p = rb_next(p)) {
  1455. req = rb_entry(p, struct ceph_mds_request, r_node);
  1456. if (req->r_got_unsafe)
  1457. continue;
  1458. if (req->r_session &&
  1459. req->r_session->s_mds == mds) {
  1460. dout(" kicking tid %llu\n", req->r_tid);
  1461. put_request_session(req);
  1462. __do_request(mdsc, req);
  1463. }
  1464. }
  1465. }
  1466. void ceph_mdsc_submit_request(struct ceph_mds_client *mdsc,
  1467. struct ceph_mds_request *req)
  1468. {
  1469. dout("submit_request on %p\n", req);
  1470. mutex_lock(&mdsc->mutex);
  1471. __register_request(mdsc, req, NULL);
  1472. __do_request(mdsc, req);
  1473. mutex_unlock(&mdsc->mutex);
  1474. }
  1475. /*
  1476. * Synchrously perform an mds request. Take care of all of the
  1477. * session setup, forwarding, retry details.
  1478. */
  1479. int ceph_mdsc_do_request(struct ceph_mds_client *mdsc,
  1480. struct inode *dir,
  1481. struct ceph_mds_request *req)
  1482. {
  1483. int err;
  1484. dout("do_request on %p\n", req);
  1485. /* take CAP_PIN refs for r_inode, r_locked_dir, r_old_dentry */
  1486. if (req->r_inode)
  1487. ceph_get_cap_refs(ceph_inode(req->r_inode), CEPH_CAP_PIN);
  1488. if (req->r_locked_dir)
  1489. ceph_get_cap_refs(ceph_inode(req->r_locked_dir), CEPH_CAP_PIN);
  1490. if (req->r_old_dentry)
  1491. ceph_get_cap_refs(
  1492. ceph_inode(req->r_old_dentry->d_parent->d_inode),
  1493. CEPH_CAP_PIN);
  1494. /* issue */
  1495. mutex_lock(&mdsc->mutex);
  1496. __register_request(mdsc, req, dir);
  1497. __do_request(mdsc, req);
  1498. if (req->r_err) {
  1499. err = req->r_err;
  1500. __unregister_request(mdsc, req);
  1501. dout("do_request early error %d\n", err);
  1502. goto out;
  1503. }
  1504. /* wait */
  1505. mutex_unlock(&mdsc->mutex);
  1506. dout("do_request waiting\n");
  1507. if (req->r_timeout) {
  1508. err = (long)wait_for_completion_interruptible_timeout(
  1509. &req->r_completion, req->r_timeout);
  1510. if (err == 0)
  1511. err = -EIO;
  1512. } else {
  1513. err = wait_for_completion_interruptible(&req->r_completion);
  1514. }
  1515. dout("do_request waited, got %d\n", err);
  1516. mutex_lock(&mdsc->mutex);
  1517. /* only abort if we didn't race with a real reply */
  1518. if (req->r_got_result) {
  1519. err = le32_to_cpu(req->r_reply_info.head->result);
  1520. } else if (err < 0) {
  1521. dout("aborted request %lld with %d\n", req->r_tid, err);
  1522. /*
  1523. * ensure we aren't running concurrently with
  1524. * ceph_fill_trace or ceph_readdir_prepopulate, which
  1525. * rely on locks (dir mutex) held by our caller.
  1526. */
  1527. mutex_lock(&req->r_fill_mutex);
  1528. req->r_err = err;
  1529. req->r_aborted = true;
  1530. mutex_unlock(&req->r_fill_mutex);
  1531. if (req->r_locked_dir &&
  1532. (req->r_op & CEPH_MDS_OP_WRITE)) {
  1533. struct ceph_inode_info *ci =
  1534. ceph_inode(req->r_locked_dir);
  1535. dout("aborted, clearing I_COMPLETE on %p\n",
  1536. req->r_locked_dir);
  1537. spin_lock(&req->r_locked_dir->i_lock);
  1538. ci->i_ceph_flags &= ~CEPH_I_COMPLETE;
  1539. ci->i_release_count++;
  1540. spin_unlock(&req->r_locked_dir->i_lock);
  1541. }
  1542. } else {
  1543. err = req->r_err;
  1544. }
  1545. out:
  1546. mutex_unlock(&mdsc->mutex);
  1547. dout("do_request %p done, result %d\n", req, err);
  1548. return err;
  1549. }
  1550. /*
  1551. * Handle mds reply.
  1552. *
  1553. * We take the session mutex and parse and process the reply immediately.
  1554. * This preserves the logical ordering of replies, capabilities, etc., sent
  1555. * by the MDS as they are applied to our local cache.
  1556. */
  1557. static void handle_reply(struct ceph_mds_session *session, struct ceph_msg *msg)
  1558. {
  1559. struct ceph_mds_client *mdsc = session->s_mdsc;
  1560. struct ceph_mds_request *req;
  1561. struct ceph_mds_reply_head *head = msg->front.iov_base;
  1562. struct ceph_mds_reply_info_parsed *rinfo; /* parsed reply info */
  1563. u64 tid;
  1564. int err, result;
  1565. int mds = session->s_mds;
  1566. if (msg->front.iov_len < sizeof(*head)) {
  1567. pr_err("mdsc_handle_reply got corrupt (short) reply\n");
  1568. ceph_msg_dump(msg);
  1569. return;
  1570. }
  1571. /* get request, session */
  1572. tid = le64_to_cpu(msg->hdr.tid);
  1573. mutex_lock(&mdsc->mutex);
  1574. req = __lookup_request(mdsc, tid);
  1575. if (!req) {
  1576. dout("handle_reply on unknown tid %llu\n", tid);
  1577. mutex_unlock(&mdsc->mutex);
  1578. return;
  1579. }
  1580. dout("handle_reply %p\n", req);
  1581. /* correct session? */
  1582. if (req->r_session != session) {
  1583. pr_err("mdsc_handle_reply got %llu on session mds%d"
  1584. " not mds%d\n", tid, session->s_mds,
  1585. req->r_session ? req->r_session->s_mds : -1);
  1586. mutex_unlock(&mdsc->mutex);
  1587. goto out;
  1588. }
  1589. /* dup? */
  1590. if ((req->r_got_unsafe && !head->safe) ||
  1591. (req->r_got_safe && head->safe)) {
  1592. pr_warning("got a dup %s reply on %llu from mds%d\n",
  1593. head->safe ? "safe" : "unsafe", tid, mds);
  1594. mutex_unlock(&mdsc->mutex);
  1595. goto out;
  1596. }
  1597. result = le32_to_cpu(head->result);
  1598. /*
  1599. * Tolerate 2 consecutive ESTALEs from the same mds.
  1600. * FIXME: we should be looking at the cap migrate_seq.
  1601. */
  1602. if (result == -ESTALE) {
  1603. req->r_direct_mode = USE_AUTH_MDS;
  1604. req->r_num_stale++;
  1605. if (req->r_num_stale <= 2) {
  1606. __do_request(mdsc, req);
  1607. mutex_unlock(&mdsc->mutex);
  1608. goto out;
  1609. }
  1610. } else {
  1611. req->r_num_stale = 0;
  1612. }
  1613. if (head->safe) {
  1614. req->r_got_safe = true;
  1615. __unregister_request(mdsc, req);
  1616. complete(&req->r_safe_completion);
  1617. if (req->r_got_unsafe) {
  1618. /*
  1619. * We already handled the unsafe response, now do the
  1620. * cleanup. No need to examine the response; the MDS
  1621. * doesn't include any result info in the safe
  1622. * response. And even if it did, there is nothing
  1623. * useful we could do with a revised return value.
  1624. */
  1625. dout("got safe reply %llu, mds%d\n", tid, mds);
  1626. list_del_init(&req->r_unsafe_item);
  1627. /* last unsafe request during umount? */
  1628. if (mdsc->stopping && !__get_oldest_req(mdsc))
  1629. complete(&mdsc->safe_umount_waiters);
  1630. mutex_unlock(&mdsc->mutex);
  1631. goto out;
  1632. }
  1633. } else {
  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. mutex_lock(&req->r_fill_mutex);
  1659. err = ceph_fill_trace(mdsc->client->sb, req, req->r_session);
  1660. if (err == 0) {
  1661. if (result == 0 && rinfo->dir_nr)
  1662. ceph_readdir_prepopulate(req, req->r_session);
  1663. ceph_unreserve_caps(&req->r_caps_reservation);
  1664. }
  1665. mutex_unlock(&req->r_fill_mutex);
  1666. up_read(&mdsc->snap_rwsem);
  1667. out_err:
  1668. mutex_lock(&mdsc->mutex);
  1669. if (!req->r_aborted) {
  1670. if (err) {
  1671. req->r_err = err;
  1672. } else {
  1673. req->r_reply = msg;
  1674. ceph_msg_get(msg);
  1675. req->r_got_result = true;
  1676. }
  1677. } else {
  1678. dout("reply arrived after request %lld was aborted\n", tid);
  1679. }
  1680. mutex_unlock(&mdsc->mutex);
  1681. add_cap_releases(mdsc, req->r_session, -1);
  1682. mutex_unlock(&session->s_mutex);
  1683. /* kick calling process */
  1684. complete_request(mdsc, req);
  1685. out:
  1686. ceph_mdsc_put_request(req);
  1687. return;
  1688. }
  1689. /*
  1690. * handle mds notification that our request has been forwarded.
  1691. */
  1692. static void handle_forward(struct ceph_mds_client *mdsc,
  1693. struct ceph_mds_session *session,
  1694. struct ceph_msg *msg)
  1695. {
  1696. struct ceph_mds_request *req;
  1697. u64 tid = le64_to_cpu(msg->hdr.tid);
  1698. u32 next_mds;
  1699. u32 fwd_seq;
  1700. int err = -EINVAL;
  1701. void *p = msg->front.iov_base;
  1702. void *end = p + msg->front.iov_len;
  1703. ceph_decode_need(&p, end, 2*sizeof(u32), bad);
  1704. next_mds = ceph_decode_32(&p);
  1705. fwd_seq = ceph_decode_32(&p);
  1706. mutex_lock(&mdsc->mutex);
  1707. req = __lookup_request(mdsc, tid);
  1708. if (!req) {
  1709. dout("forward %llu to mds%d - req dne\n", tid, next_mds);
  1710. goto out; /* dup reply? */
  1711. }
  1712. if (fwd_seq <= req->r_num_fwd) {
  1713. dout("forward %llu to mds%d - old seq %d <= %d\n",
  1714. tid, next_mds, req->r_num_fwd, fwd_seq);
  1715. } else {
  1716. /* resend. forward race not possible; mds would drop */
  1717. dout("forward %llu to mds%d (we resend)\n", tid, next_mds);
  1718. req->r_num_fwd = fwd_seq;
  1719. req->r_resend_mds = next_mds;
  1720. put_request_session(req);
  1721. __do_request(mdsc, req);
  1722. }
  1723. ceph_mdsc_put_request(req);
  1724. out:
  1725. mutex_unlock(&mdsc->mutex);
  1726. return;
  1727. bad:
  1728. pr_err("mdsc_handle_forward decode error err=%d\n", err);
  1729. }
  1730. /*
  1731. * handle a mds session control message
  1732. */
  1733. static void handle_session(struct ceph_mds_session *session,
  1734. struct ceph_msg *msg)
  1735. {
  1736. struct ceph_mds_client *mdsc = session->s_mdsc;
  1737. u32 op;
  1738. u64 seq;
  1739. int mds = session->s_mds;
  1740. struct ceph_mds_session_head *h = msg->front.iov_base;
  1741. int wake = 0;
  1742. /* decode */
  1743. if (msg->front.iov_len != sizeof(*h))
  1744. goto bad;
  1745. op = le32_to_cpu(h->op);
  1746. seq = le64_to_cpu(h->seq);
  1747. mutex_lock(&mdsc->mutex);
  1748. if (op == CEPH_SESSION_CLOSE)
  1749. __unregister_session(mdsc, session);
  1750. /* FIXME: this ttl calculation is generous */
  1751. session->s_ttl = jiffies + HZ*mdsc->mdsmap->m_session_autoclose;
  1752. mutex_unlock(&mdsc->mutex);
  1753. mutex_lock(&session->s_mutex);
  1754. dout("handle_session mds%d %s %p state %s seq %llu\n",
  1755. mds, ceph_session_op_name(op), session,
  1756. session_state_name(session->s_state), seq);
  1757. if (session->s_state == CEPH_MDS_SESSION_HUNG) {
  1758. session->s_state = CEPH_MDS_SESSION_OPEN;
  1759. pr_info("mds%d came back\n", session->s_mds);
  1760. }
  1761. switch (op) {
  1762. case CEPH_SESSION_OPEN:
  1763. session->s_state = CEPH_MDS_SESSION_OPEN;
  1764. renewed_caps(mdsc, session, 0);
  1765. wake = 1;
  1766. if (mdsc->stopping)
  1767. __close_session(mdsc, session);
  1768. break;
  1769. case CEPH_SESSION_RENEWCAPS:
  1770. if (session->s_renew_seq == seq)
  1771. renewed_caps(mdsc, session, 1);
  1772. break;
  1773. case CEPH_SESSION_CLOSE:
  1774. remove_session_caps(session);
  1775. wake = 1; /* for good measure */
  1776. complete(&mdsc->session_close_waiters);
  1777. kick_requests(mdsc, mds, 0); /* cur only */
  1778. break;
  1779. case CEPH_SESSION_STALE:
  1780. pr_info("mds%d caps went stale, renewing\n",
  1781. session->s_mds);
  1782. spin_lock(&session->s_cap_lock);
  1783. session->s_cap_gen++;
  1784. session->s_cap_ttl = 0;
  1785. spin_unlock(&session->s_cap_lock);
  1786. send_renew_caps(mdsc, session);
  1787. break;
  1788. case CEPH_SESSION_RECALL_STATE:
  1789. trim_caps(mdsc, session, le32_to_cpu(h->max_caps));
  1790. break;
  1791. default:
  1792. pr_err("mdsc_handle_session bad op %d mds%d\n", op, mds);
  1793. WARN_ON(1);
  1794. }
  1795. mutex_unlock(&session->s_mutex);
  1796. if (wake) {
  1797. mutex_lock(&mdsc->mutex);
  1798. __wake_requests(mdsc, &session->s_waiting);
  1799. mutex_unlock(&mdsc->mutex);
  1800. }
  1801. return;
  1802. bad:
  1803. pr_err("mdsc_handle_session corrupt message mds%d len %d\n", mds,
  1804. (int)msg->front.iov_len);
  1805. ceph_msg_dump(msg);
  1806. return;
  1807. }
  1808. /*
  1809. * called under session->mutex.
  1810. */
  1811. static void replay_unsafe_requests(struct ceph_mds_client *mdsc,
  1812. struct ceph_mds_session *session)
  1813. {
  1814. struct ceph_mds_request *req, *nreq;
  1815. int err;
  1816. dout("replay_unsafe_requests mds%d\n", session->s_mds);
  1817. mutex_lock(&mdsc->mutex);
  1818. list_for_each_entry_safe(req, nreq, &session->s_unsafe, r_unsafe_item) {
  1819. err = __prepare_send_request(mdsc, req, session->s_mds);
  1820. if (!err) {
  1821. ceph_msg_get(req->r_request);
  1822. ceph_con_send(&session->s_con, req->r_request);
  1823. }
  1824. }
  1825. mutex_unlock(&mdsc->mutex);
  1826. }
  1827. /*
  1828. * Encode information about a cap for a reconnect with the MDS.
  1829. */
  1830. static int encode_caps_cb(struct inode *inode, struct ceph_cap *cap,
  1831. void *arg)
  1832. {
  1833. struct ceph_mds_cap_reconnect rec;
  1834. struct ceph_inode_info *ci;
  1835. struct ceph_pagelist *pagelist = arg;
  1836. char *path;
  1837. int pathlen, err;
  1838. u64 pathbase;
  1839. struct dentry *dentry;
  1840. ci = cap->ci;
  1841. dout(" adding %p ino %llx.%llx cap %p %lld %s\n",
  1842. inode, ceph_vinop(inode), cap, cap->cap_id,
  1843. ceph_cap_string(cap->issued));
  1844. err = ceph_pagelist_encode_64(pagelist, ceph_ino(inode));
  1845. if (err)
  1846. return err;
  1847. dentry = d_find_alias(inode);
  1848. if (dentry) {
  1849. path = ceph_mdsc_build_path(dentry, &pathlen, &pathbase, 0);
  1850. if (IS_ERR(path)) {
  1851. err = PTR_ERR(path);
  1852. BUG_ON(err);
  1853. }
  1854. } else {
  1855. path = NULL;
  1856. pathlen = 0;
  1857. }
  1858. err = ceph_pagelist_encode_string(pagelist, path, pathlen);
  1859. if (err)
  1860. goto out;
  1861. spin_lock(&inode->i_lock);
  1862. cap->seq = 0; /* reset cap seq */
  1863. cap->issue_seq = 0; /* and issue_seq */
  1864. rec.cap_id = cpu_to_le64(cap->cap_id);
  1865. rec.pathbase = cpu_to_le64(pathbase);
  1866. rec.wanted = cpu_to_le32(__ceph_caps_wanted(ci));
  1867. rec.issued = cpu_to_le32(cap->issued);
  1868. rec.size = cpu_to_le64(inode->i_size);
  1869. ceph_encode_timespec(&rec.mtime, &inode->i_mtime);
  1870. ceph_encode_timespec(&rec.atime, &inode->i_atime);
  1871. rec.snaprealm = cpu_to_le64(ci->i_snap_realm->ino);
  1872. spin_unlock(&inode->i_lock);
  1873. err = ceph_pagelist_append(pagelist, &rec, sizeof(rec));
  1874. out:
  1875. kfree(path);
  1876. dput(dentry);
  1877. return err;
  1878. }
  1879. /*
  1880. * If an MDS fails and recovers, clients need to reconnect in order to
  1881. * reestablish shared state. This includes all caps issued through
  1882. * this session _and_ the snap_realm hierarchy. Because it's not
  1883. * clear which snap realms the mds cares about, we send everything we
  1884. * know about.. that ensures we'll then get any new info the
  1885. * recovering MDS might have.
  1886. *
  1887. * This is a relatively heavyweight operation, but it's rare.
  1888. *
  1889. * called with mdsc->mutex held.
  1890. */
  1891. static void send_mds_reconnect(struct ceph_mds_client *mdsc, int mds)
  1892. {
  1893. struct ceph_mds_session *session = NULL;
  1894. struct ceph_msg *reply;
  1895. struct rb_node *p;
  1896. int err = -ENOMEM;
  1897. struct ceph_pagelist *pagelist;
  1898. pr_info("reconnect to recovering mds%d\n", mds);
  1899. pagelist = kmalloc(sizeof(*pagelist), GFP_NOFS);
  1900. if (!pagelist)
  1901. goto fail_nopagelist;
  1902. ceph_pagelist_init(pagelist);
  1903. reply = ceph_msg_new(CEPH_MSG_CLIENT_RECONNECT, 0, 0, 0, NULL);
  1904. if (IS_ERR(reply)) {
  1905. err = PTR_ERR(reply);
  1906. goto fail_nomsg;
  1907. }
  1908. /* find session */
  1909. session = __ceph_lookup_mds_session(mdsc, mds);
  1910. mutex_unlock(&mdsc->mutex); /* drop lock for duration */
  1911. if (session) {
  1912. mutex_lock(&session->s_mutex);
  1913. session->s_state = CEPH_MDS_SESSION_RECONNECTING;
  1914. session->s_seq = 0;
  1915. ceph_con_open(&session->s_con,
  1916. ceph_mdsmap_get_addr(mdsc->mdsmap, mds));
  1917. /* replay unsafe requests */
  1918. replay_unsafe_requests(mdsc, session);
  1919. } else {
  1920. dout("no session for mds%d, will send short reconnect\n",
  1921. mds);
  1922. }
  1923. down_read(&mdsc->snap_rwsem);
  1924. if (!session)
  1925. goto send;
  1926. dout("session %p state %s\n", session,
  1927. session_state_name(session->s_state));
  1928. /* traverse this session's caps */
  1929. err = ceph_pagelist_encode_32(pagelist, session->s_nr_caps);
  1930. if (err)
  1931. goto fail;
  1932. err = iterate_session_caps(session, encode_caps_cb, pagelist);
  1933. if (err < 0)
  1934. goto fail;
  1935. /*
  1936. * snaprealms. we provide mds with the ino, seq (version), and
  1937. * parent for all of our realms. If the mds has any newer info,
  1938. * it will tell us.
  1939. */
  1940. for (p = rb_first(&mdsc->snap_realms); p; p = rb_next(p)) {
  1941. struct ceph_snap_realm *realm =
  1942. rb_entry(p, struct ceph_snap_realm, node);
  1943. struct ceph_mds_snaprealm_reconnect sr_rec;
  1944. dout(" adding snap realm %llx seq %lld parent %llx\n",
  1945. realm->ino, realm->seq, realm->parent_ino);
  1946. sr_rec.ino = cpu_to_le64(realm->ino);
  1947. sr_rec.seq = cpu_to_le64(realm->seq);
  1948. sr_rec.parent = cpu_to_le64(realm->parent_ino);
  1949. err = ceph_pagelist_append(pagelist, &sr_rec, sizeof(sr_rec));
  1950. if (err)
  1951. goto fail;
  1952. }
  1953. send:
  1954. reply->pagelist = pagelist;
  1955. reply->hdr.data_len = cpu_to_le32(pagelist->length);
  1956. reply->nr_pages = calc_pages_for(0, pagelist->length);
  1957. ceph_con_send(&session->s_con, reply);
  1958. session->s_state = CEPH_MDS_SESSION_OPEN;
  1959. mutex_unlock(&session->s_mutex);
  1960. mutex_lock(&mdsc->mutex);
  1961. __wake_requests(mdsc, &session->s_waiting);
  1962. mutex_unlock(&mdsc->mutex);
  1963. ceph_put_mds_session(session);
  1964. up_read(&mdsc->snap_rwsem);
  1965. mutex_lock(&mdsc->mutex);
  1966. return;
  1967. fail:
  1968. ceph_msg_put(reply);
  1969. up_read(&mdsc->snap_rwsem);
  1970. mutex_unlock(&session->s_mutex);
  1971. ceph_put_mds_session(session);
  1972. fail_nomsg:
  1973. ceph_pagelist_release(pagelist);
  1974. kfree(pagelist);
  1975. fail_nopagelist:
  1976. pr_err("error %d preparing reconnect for mds%d\n", err, mds);
  1977. mutex_lock(&mdsc->mutex);
  1978. return;
  1979. }
  1980. /*
  1981. * compare old and new mdsmaps, kicking requests
  1982. * and closing out old connections as necessary
  1983. *
  1984. * called under mdsc->mutex.
  1985. */
  1986. static void check_new_map(struct ceph_mds_client *mdsc,
  1987. struct ceph_mdsmap *newmap,
  1988. struct ceph_mdsmap *oldmap)
  1989. {
  1990. int i;
  1991. int oldstate, newstate;
  1992. struct ceph_mds_session *s;
  1993. dout("check_new_map new %u old %u\n",
  1994. newmap->m_epoch, oldmap->m_epoch);
  1995. for (i = 0; i < oldmap->m_max_mds && i < mdsc->max_sessions; i++) {
  1996. if (mdsc->sessions[i] == NULL)
  1997. continue;
  1998. s = mdsc->sessions[i];
  1999. oldstate = ceph_mdsmap_get_state(oldmap, i);
  2000. newstate = ceph_mdsmap_get_state(newmap, i);
  2001. dout("check_new_map mds%d state %s -> %s (session %s)\n",
  2002. i, ceph_mds_state_name(oldstate),
  2003. ceph_mds_state_name(newstate),
  2004. session_state_name(s->s_state));
  2005. if (memcmp(ceph_mdsmap_get_addr(oldmap, i),
  2006. ceph_mdsmap_get_addr(newmap, i),
  2007. sizeof(struct ceph_entity_addr))) {
  2008. if (s->s_state == CEPH_MDS_SESSION_OPENING) {
  2009. /* the session never opened, just close it
  2010. * out now */
  2011. __wake_requests(mdsc, &s->s_waiting);
  2012. __unregister_session(mdsc, s);
  2013. } else {
  2014. /* just close it */
  2015. mutex_unlock(&mdsc->mutex);
  2016. mutex_lock(&s->s_mutex);
  2017. mutex_lock(&mdsc->mutex);
  2018. ceph_con_close(&s->s_con);
  2019. mutex_unlock(&s->s_mutex);
  2020. s->s_state = CEPH_MDS_SESSION_RESTARTING;
  2021. }
  2022. /* kick any requests waiting on the recovering mds */
  2023. kick_requests(mdsc, i, 1);
  2024. } else if (oldstate == newstate) {
  2025. continue; /* nothing new with this mds */
  2026. }
  2027. /*
  2028. * send reconnect?
  2029. */
  2030. if (s->s_state == CEPH_MDS_SESSION_RESTARTING &&
  2031. newstate >= CEPH_MDS_STATE_RECONNECT)
  2032. send_mds_reconnect(mdsc, i);
  2033. /*
  2034. * kick requests on any mds that has gone active.
  2035. *
  2036. * kick requests on cur or forwarder: we may have sent
  2037. * the request to mds1, mds1 told us it forwarded it
  2038. * to mds2, but then we learn mds1 failed and can't be
  2039. * sure it successfully forwarded our request before
  2040. * it died.
  2041. */
  2042. if (oldstate < CEPH_MDS_STATE_ACTIVE &&
  2043. newstate >= CEPH_MDS_STATE_ACTIVE) {
  2044. pr_info("mds%d reconnect completed\n", s->s_mds);
  2045. kick_requests(mdsc, i, 1);
  2046. ceph_kick_flushing_caps(mdsc, s);
  2047. wake_up_session_caps(s, 1);
  2048. }
  2049. }
  2050. }
  2051. /*
  2052. * leases
  2053. */
  2054. /*
  2055. * caller must hold session s_mutex, dentry->d_lock
  2056. */
  2057. void __ceph_mdsc_drop_dentry_lease(struct dentry *dentry)
  2058. {
  2059. struct ceph_dentry_info *di = ceph_dentry(dentry);
  2060. ceph_put_mds_session(di->lease_session);
  2061. di->lease_session = NULL;
  2062. }
  2063. static void handle_lease(struct ceph_mds_client *mdsc,
  2064. struct ceph_mds_session *session,
  2065. struct ceph_msg *msg)
  2066. {
  2067. struct super_block *sb = mdsc->client->sb;
  2068. struct inode *inode;
  2069. struct ceph_inode_info *ci;
  2070. struct dentry *parent, *dentry;
  2071. struct ceph_dentry_info *di;
  2072. int mds = session->s_mds;
  2073. struct ceph_mds_lease *h = msg->front.iov_base;
  2074. struct ceph_vino vino;
  2075. int mask;
  2076. struct qstr dname;
  2077. int release = 0;
  2078. dout("handle_lease from mds%d\n", mds);
  2079. /* decode */
  2080. if (msg->front.iov_len < sizeof(*h) + sizeof(u32))
  2081. goto bad;
  2082. vino.ino = le64_to_cpu(h->ino);
  2083. vino.snap = CEPH_NOSNAP;
  2084. mask = le16_to_cpu(h->mask);
  2085. dname.name = (void *)h + sizeof(*h) + sizeof(u32);
  2086. dname.len = msg->front.iov_len - sizeof(*h) - sizeof(u32);
  2087. if (dname.len != get_unaligned_le32(h+1))
  2088. goto bad;
  2089. mutex_lock(&session->s_mutex);
  2090. session->s_seq++;
  2091. /* lookup inode */
  2092. inode = ceph_find_inode(sb, vino);
  2093. dout("handle_lease '%s', mask %d, ino %llx %p\n",
  2094. ceph_lease_op_name(h->action), mask, vino.ino, inode);
  2095. if (inode == NULL) {
  2096. dout("handle_lease no inode %llx\n", vino.ino);
  2097. goto release;
  2098. }
  2099. ci = ceph_inode(inode);
  2100. /* dentry */
  2101. parent = d_find_alias(inode);
  2102. if (!parent) {
  2103. dout("no parent dentry on inode %p\n", inode);
  2104. WARN_ON(1);
  2105. goto release; /* hrm... */
  2106. }
  2107. dname.hash = full_name_hash(dname.name, dname.len);
  2108. dentry = d_lookup(parent, &dname);
  2109. dput(parent);
  2110. if (!dentry)
  2111. goto release;
  2112. spin_lock(&dentry->d_lock);
  2113. di = ceph_dentry(dentry);
  2114. switch (h->action) {
  2115. case CEPH_MDS_LEASE_REVOKE:
  2116. if (di && di->lease_session == session) {
  2117. h->seq = cpu_to_le32(di->lease_seq);
  2118. __ceph_mdsc_drop_dentry_lease(dentry);
  2119. }
  2120. release = 1;
  2121. break;
  2122. case CEPH_MDS_LEASE_RENEW:
  2123. if (di && di->lease_session == session &&
  2124. di->lease_gen == session->s_cap_gen &&
  2125. di->lease_renew_from &&
  2126. di->lease_renew_after == 0) {
  2127. unsigned long duration =
  2128. le32_to_cpu(h->duration_ms) * HZ / 1000;
  2129. di->lease_seq = le32_to_cpu(h->seq);
  2130. dentry->d_time = di->lease_renew_from + duration;
  2131. di->lease_renew_after = di->lease_renew_from +
  2132. (duration >> 1);
  2133. di->lease_renew_from = 0;
  2134. }
  2135. break;
  2136. }
  2137. spin_unlock(&dentry->d_lock);
  2138. dput(dentry);
  2139. if (!release)
  2140. goto out;
  2141. release:
  2142. /* let's just reuse the same message */
  2143. h->action = CEPH_MDS_LEASE_REVOKE_ACK;
  2144. ceph_msg_get(msg);
  2145. ceph_con_send(&session->s_con, msg);
  2146. out:
  2147. iput(inode);
  2148. mutex_unlock(&session->s_mutex);
  2149. return;
  2150. bad:
  2151. pr_err("corrupt lease message\n");
  2152. ceph_msg_dump(msg);
  2153. }
  2154. void ceph_mdsc_lease_send_msg(struct ceph_mds_session *session,
  2155. struct inode *inode,
  2156. struct dentry *dentry, char action,
  2157. u32 seq)
  2158. {
  2159. struct ceph_msg *msg;
  2160. struct ceph_mds_lease *lease;
  2161. int len = sizeof(*lease) + sizeof(u32);
  2162. int dnamelen = 0;
  2163. dout("lease_send_msg inode %p dentry %p %s to mds%d\n",
  2164. inode, dentry, ceph_lease_op_name(action), session->s_mds);
  2165. dnamelen = dentry->d_name.len;
  2166. len += dnamelen;
  2167. msg = ceph_msg_new(CEPH_MSG_CLIENT_LEASE, len, 0, 0, NULL);
  2168. if (IS_ERR(msg))
  2169. return;
  2170. lease = msg->front.iov_base;
  2171. lease->action = action;
  2172. lease->mask = cpu_to_le16(CEPH_LOCK_DN);
  2173. lease->ino = cpu_to_le64(ceph_vino(inode).ino);
  2174. lease->first = lease->last = cpu_to_le64(ceph_vino(inode).snap);
  2175. lease->seq = cpu_to_le32(seq);
  2176. put_unaligned_le32(dnamelen, lease + 1);
  2177. memcpy((void *)(lease + 1) + 4, dentry->d_name.name, dnamelen);
  2178. /*
  2179. * if this is a preemptive lease RELEASE, no need to
  2180. * flush request stream, since the actual request will
  2181. * soon follow.
  2182. */
  2183. msg->more_to_follow = (action == CEPH_MDS_LEASE_RELEASE);
  2184. ceph_con_send(&session->s_con, msg);
  2185. }
  2186. /*
  2187. * Preemptively release a lease we expect to invalidate anyway.
  2188. * Pass @inode always, @dentry is optional.
  2189. */
  2190. void ceph_mdsc_lease_release(struct ceph_mds_client *mdsc, struct inode *inode,
  2191. struct dentry *dentry, int mask)
  2192. {
  2193. struct ceph_dentry_info *di;
  2194. struct ceph_mds_session *session;
  2195. u32 seq;
  2196. BUG_ON(inode == NULL);
  2197. BUG_ON(dentry == NULL);
  2198. BUG_ON(mask != CEPH_LOCK_DN);
  2199. /* is dentry lease valid? */
  2200. spin_lock(&dentry->d_lock);
  2201. di = ceph_dentry(dentry);
  2202. if (!di || !di->lease_session ||
  2203. di->lease_session->s_mds < 0 ||
  2204. di->lease_gen != di->lease_session->s_cap_gen ||
  2205. !time_before(jiffies, dentry->d_time)) {
  2206. dout("lease_release inode %p dentry %p -- "
  2207. "no lease on %d\n",
  2208. inode, dentry, mask);
  2209. spin_unlock(&dentry->d_lock);
  2210. return;
  2211. }
  2212. /* we do have a lease on this dentry; note mds and seq */
  2213. session = ceph_get_mds_session(di->lease_session);
  2214. seq = di->lease_seq;
  2215. __ceph_mdsc_drop_dentry_lease(dentry);
  2216. spin_unlock(&dentry->d_lock);
  2217. dout("lease_release inode %p dentry %p mask %d to mds%d\n",
  2218. inode, dentry, mask, session->s_mds);
  2219. ceph_mdsc_lease_send_msg(session, inode, dentry,
  2220. CEPH_MDS_LEASE_RELEASE, seq);
  2221. ceph_put_mds_session(session);
  2222. }
  2223. /*
  2224. * drop all leases (and dentry refs) in preparation for umount
  2225. */
  2226. static void drop_leases(struct ceph_mds_client *mdsc)
  2227. {
  2228. int i;
  2229. dout("drop_leases\n");
  2230. mutex_lock(&mdsc->mutex);
  2231. for (i = 0; i < mdsc->max_sessions; i++) {
  2232. struct ceph_mds_session *s = __ceph_lookup_mds_session(mdsc, i);
  2233. if (!s)
  2234. continue;
  2235. mutex_unlock(&mdsc->mutex);
  2236. mutex_lock(&s->s_mutex);
  2237. mutex_unlock(&s->s_mutex);
  2238. ceph_put_mds_session(s);
  2239. mutex_lock(&mdsc->mutex);
  2240. }
  2241. mutex_unlock(&mdsc->mutex);
  2242. }
  2243. /*
  2244. * delayed work -- periodically trim expired leases, renew caps with mds
  2245. */
  2246. static void schedule_delayed(struct ceph_mds_client *mdsc)
  2247. {
  2248. int delay = 5;
  2249. unsigned hz = round_jiffies_relative(HZ * delay);
  2250. schedule_delayed_work(&mdsc->delayed_work, hz);
  2251. }
  2252. static void delayed_work(struct work_struct *work)
  2253. {
  2254. int i;
  2255. struct ceph_mds_client *mdsc =
  2256. container_of(work, struct ceph_mds_client, delayed_work.work);
  2257. int renew_interval;
  2258. int renew_caps;
  2259. dout("mdsc delayed_work\n");
  2260. ceph_check_delayed_caps(mdsc);
  2261. mutex_lock(&mdsc->mutex);
  2262. renew_interval = mdsc->mdsmap->m_session_timeout >> 2;
  2263. renew_caps = time_after_eq(jiffies, HZ*renew_interval +
  2264. mdsc->last_renew_caps);
  2265. if (renew_caps)
  2266. mdsc->last_renew_caps = jiffies;
  2267. for (i = 0; i < mdsc->max_sessions; i++) {
  2268. struct ceph_mds_session *s = __ceph_lookup_mds_session(mdsc, i);
  2269. if (s == NULL)
  2270. continue;
  2271. if (s->s_state == CEPH_MDS_SESSION_CLOSING) {
  2272. dout("resending session close request for mds%d\n",
  2273. s->s_mds);
  2274. request_close_session(mdsc, s);
  2275. ceph_put_mds_session(s);
  2276. continue;
  2277. }
  2278. if (s->s_ttl && time_after(jiffies, s->s_ttl)) {
  2279. if (s->s_state == CEPH_MDS_SESSION_OPEN) {
  2280. s->s_state = CEPH_MDS_SESSION_HUNG;
  2281. pr_info("mds%d hung\n", s->s_mds);
  2282. }
  2283. }
  2284. if (s->s_state < CEPH_MDS_SESSION_OPEN) {
  2285. /* this mds is failed or recovering, just wait */
  2286. ceph_put_mds_session(s);
  2287. continue;
  2288. }
  2289. mutex_unlock(&mdsc->mutex);
  2290. mutex_lock(&s->s_mutex);
  2291. if (renew_caps)
  2292. send_renew_caps(mdsc, s);
  2293. else
  2294. ceph_con_keepalive(&s->s_con);
  2295. add_cap_releases(mdsc, s, -1);
  2296. send_cap_releases(mdsc, s);
  2297. mutex_unlock(&s->s_mutex);
  2298. ceph_put_mds_session(s);
  2299. mutex_lock(&mdsc->mutex);
  2300. }
  2301. mutex_unlock(&mdsc->mutex);
  2302. schedule_delayed(mdsc);
  2303. }
  2304. int ceph_mdsc_init(struct ceph_mds_client *mdsc, struct ceph_client *client)
  2305. {
  2306. mdsc->client = client;
  2307. mutex_init(&mdsc->mutex);
  2308. mdsc->mdsmap = kzalloc(sizeof(*mdsc->mdsmap), GFP_NOFS);
  2309. init_completion(&mdsc->safe_umount_waiters);
  2310. init_completion(&mdsc->session_close_waiters);
  2311. INIT_LIST_HEAD(&mdsc->waiting_for_map);
  2312. mdsc->sessions = NULL;
  2313. mdsc->max_sessions = 0;
  2314. mdsc->stopping = 0;
  2315. init_rwsem(&mdsc->snap_rwsem);
  2316. mdsc->snap_realms = RB_ROOT;
  2317. INIT_LIST_HEAD(&mdsc->snap_empty);
  2318. spin_lock_init(&mdsc->snap_empty_lock);
  2319. mdsc->last_tid = 0;
  2320. mdsc->request_tree = RB_ROOT;
  2321. INIT_DELAYED_WORK(&mdsc->delayed_work, delayed_work);
  2322. mdsc->last_renew_caps = jiffies;
  2323. INIT_LIST_HEAD(&mdsc->cap_delay_list);
  2324. spin_lock_init(&mdsc->cap_delay_lock);
  2325. INIT_LIST_HEAD(&mdsc->snap_flush_list);
  2326. spin_lock_init(&mdsc->snap_flush_lock);
  2327. mdsc->cap_flush_seq = 0;
  2328. INIT_LIST_HEAD(&mdsc->cap_dirty);
  2329. mdsc->num_cap_flushing = 0;
  2330. spin_lock_init(&mdsc->cap_dirty_lock);
  2331. init_waitqueue_head(&mdsc->cap_flushing_wq);
  2332. spin_lock_init(&mdsc->dentry_lru_lock);
  2333. INIT_LIST_HEAD(&mdsc->dentry_lru);
  2334. return 0;
  2335. }
  2336. /*
  2337. * Wait for safe replies on open mds requests. If we time out, drop
  2338. * all requests from the tree to avoid dangling dentry refs.
  2339. */
  2340. static void wait_requests(struct ceph_mds_client *mdsc)
  2341. {
  2342. struct ceph_mds_request *req;
  2343. struct ceph_client *client = mdsc->client;
  2344. mutex_lock(&mdsc->mutex);
  2345. if (__get_oldest_req(mdsc)) {
  2346. mutex_unlock(&mdsc->mutex);
  2347. dout("wait_requests waiting for requests\n");
  2348. wait_for_completion_timeout(&mdsc->safe_umount_waiters,
  2349. client->mount_args->mount_timeout * HZ);
  2350. /* tear down remaining requests */
  2351. mutex_lock(&mdsc->mutex);
  2352. while ((req = __get_oldest_req(mdsc))) {
  2353. dout("wait_requests timed out on tid %llu\n",
  2354. req->r_tid);
  2355. __unregister_request(mdsc, req);
  2356. }
  2357. }
  2358. mutex_unlock(&mdsc->mutex);
  2359. dout("wait_requests done\n");
  2360. }
  2361. /*
  2362. * called before mount is ro, and before dentries are torn down.
  2363. * (hmm, does this still race with new lookups?)
  2364. */
  2365. void ceph_mdsc_pre_umount(struct ceph_mds_client *mdsc)
  2366. {
  2367. dout("pre_umount\n");
  2368. mdsc->stopping = 1;
  2369. drop_leases(mdsc);
  2370. ceph_flush_dirty_caps(mdsc);
  2371. wait_requests(mdsc);
  2372. }
  2373. /*
  2374. * wait for all write mds requests to flush.
  2375. */
  2376. static void wait_unsafe_requests(struct ceph_mds_client *mdsc, u64 want_tid)
  2377. {
  2378. struct ceph_mds_request *req = NULL, *nextreq;
  2379. struct rb_node *n;
  2380. mutex_lock(&mdsc->mutex);
  2381. dout("wait_unsafe_requests want %lld\n", want_tid);
  2382. restart:
  2383. req = __get_oldest_req(mdsc);
  2384. while (req && req->r_tid <= want_tid) {
  2385. /* find next request */
  2386. n = rb_next(&req->r_node);
  2387. if (n)
  2388. nextreq = rb_entry(n, struct ceph_mds_request, r_node);
  2389. else
  2390. nextreq = NULL;
  2391. if ((req->r_op & CEPH_MDS_OP_WRITE)) {
  2392. /* write op */
  2393. ceph_mdsc_get_request(req);
  2394. if (nextreq)
  2395. ceph_mdsc_get_request(nextreq);
  2396. mutex_unlock(&mdsc->mutex);
  2397. dout("wait_unsafe_requests wait on %llu (want %llu)\n",
  2398. req->r_tid, want_tid);
  2399. wait_for_completion(&req->r_safe_completion);
  2400. mutex_lock(&mdsc->mutex);
  2401. ceph_mdsc_put_request(req);
  2402. if (!nextreq)
  2403. break; /* next dne before, so we're done! */
  2404. if (RB_EMPTY_NODE(&nextreq->r_node)) {
  2405. /* next request was removed from tree */
  2406. ceph_mdsc_put_request(nextreq);
  2407. goto restart;
  2408. }
  2409. ceph_mdsc_put_request(nextreq); /* won't go away */
  2410. }
  2411. req = nextreq;
  2412. }
  2413. mutex_unlock(&mdsc->mutex);
  2414. dout("wait_unsafe_requests done\n");
  2415. }
  2416. void ceph_mdsc_sync(struct ceph_mds_client *mdsc)
  2417. {
  2418. u64 want_tid, want_flush;
  2419. dout("sync\n");
  2420. mutex_lock(&mdsc->mutex);
  2421. want_tid = mdsc->last_tid;
  2422. want_flush = mdsc->cap_flush_seq;
  2423. mutex_unlock(&mdsc->mutex);
  2424. dout("sync want tid %lld flush_seq %lld\n", want_tid, want_flush);
  2425. ceph_flush_dirty_caps(mdsc);
  2426. wait_unsafe_requests(mdsc, want_tid);
  2427. wait_event(mdsc->cap_flushing_wq, check_cap_flush(mdsc, want_flush));
  2428. }
  2429. /*
  2430. * called after sb is ro.
  2431. */
  2432. void ceph_mdsc_close_sessions(struct ceph_mds_client *mdsc)
  2433. {
  2434. struct ceph_mds_session *session;
  2435. int i;
  2436. int n;
  2437. struct ceph_client *client = mdsc->client;
  2438. unsigned long started, timeout = client->mount_args->mount_timeout * HZ;
  2439. dout("close_sessions\n");
  2440. mutex_lock(&mdsc->mutex);
  2441. /* close sessions */
  2442. started = jiffies;
  2443. while (time_before(jiffies, started + timeout)) {
  2444. dout("closing sessions\n");
  2445. n = 0;
  2446. for (i = 0; i < mdsc->max_sessions; i++) {
  2447. session = __ceph_lookup_mds_session(mdsc, i);
  2448. if (!session)
  2449. continue;
  2450. mutex_unlock(&mdsc->mutex);
  2451. mutex_lock(&session->s_mutex);
  2452. __close_session(mdsc, session);
  2453. mutex_unlock(&session->s_mutex);
  2454. ceph_put_mds_session(session);
  2455. mutex_lock(&mdsc->mutex);
  2456. n++;
  2457. }
  2458. if (n == 0)
  2459. break;
  2460. if (client->mount_state == CEPH_MOUNT_SHUTDOWN)
  2461. break;
  2462. dout("waiting for sessions to close\n");
  2463. mutex_unlock(&mdsc->mutex);
  2464. wait_for_completion_timeout(&mdsc->session_close_waiters,
  2465. timeout);
  2466. mutex_lock(&mdsc->mutex);
  2467. }
  2468. /* tear down remaining sessions */
  2469. for (i = 0; i < mdsc->max_sessions; i++) {
  2470. if (mdsc->sessions[i]) {
  2471. session = get_session(mdsc->sessions[i]);
  2472. __unregister_session(mdsc, session);
  2473. mutex_unlock(&mdsc->mutex);
  2474. mutex_lock(&session->s_mutex);
  2475. remove_session_caps(session);
  2476. mutex_unlock(&session->s_mutex);
  2477. ceph_put_mds_session(session);
  2478. mutex_lock(&mdsc->mutex);
  2479. }
  2480. }
  2481. WARN_ON(!list_empty(&mdsc->cap_delay_list));
  2482. mutex_unlock(&mdsc->mutex);
  2483. ceph_cleanup_empty_realms(mdsc);
  2484. cancel_delayed_work_sync(&mdsc->delayed_work); /* cancel timer */
  2485. dout("stopped\n");
  2486. }
  2487. void ceph_mdsc_stop(struct ceph_mds_client *mdsc)
  2488. {
  2489. dout("stop\n");
  2490. cancel_delayed_work_sync(&mdsc->delayed_work); /* cancel timer */
  2491. if (mdsc->mdsmap)
  2492. ceph_mdsmap_destroy(mdsc->mdsmap);
  2493. kfree(mdsc->sessions);
  2494. }
  2495. /*
  2496. * handle mds map update.
  2497. */
  2498. void ceph_mdsc_handle_map(struct ceph_mds_client *mdsc, struct ceph_msg *msg)
  2499. {
  2500. u32 epoch;
  2501. u32 maplen;
  2502. void *p = msg->front.iov_base;
  2503. void *end = p + msg->front.iov_len;
  2504. struct ceph_mdsmap *newmap, *oldmap;
  2505. struct ceph_fsid fsid;
  2506. int err = -EINVAL;
  2507. ceph_decode_need(&p, end, sizeof(fsid)+2*sizeof(u32), bad);
  2508. ceph_decode_copy(&p, &fsid, sizeof(fsid));
  2509. if (ceph_check_fsid(mdsc->client, &fsid) < 0)
  2510. return;
  2511. epoch = ceph_decode_32(&p);
  2512. maplen = ceph_decode_32(&p);
  2513. dout("handle_map epoch %u len %d\n", epoch, (int)maplen);
  2514. /* do we need it? */
  2515. ceph_monc_got_mdsmap(&mdsc->client->monc, epoch);
  2516. mutex_lock(&mdsc->mutex);
  2517. if (mdsc->mdsmap && epoch <= mdsc->mdsmap->m_epoch) {
  2518. dout("handle_map epoch %u <= our %u\n",
  2519. epoch, mdsc->mdsmap->m_epoch);
  2520. mutex_unlock(&mdsc->mutex);
  2521. return;
  2522. }
  2523. newmap = ceph_mdsmap_decode(&p, end);
  2524. if (IS_ERR(newmap)) {
  2525. err = PTR_ERR(newmap);
  2526. goto bad_unlock;
  2527. }
  2528. /* swap into place */
  2529. if (mdsc->mdsmap) {
  2530. oldmap = mdsc->mdsmap;
  2531. mdsc->mdsmap = newmap;
  2532. check_new_map(mdsc, newmap, oldmap);
  2533. ceph_mdsmap_destroy(oldmap);
  2534. } else {
  2535. mdsc->mdsmap = newmap; /* first mds map */
  2536. }
  2537. mdsc->client->sb->s_maxbytes = mdsc->mdsmap->m_max_file_size;
  2538. __wake_requests(mdsc, &mdsc->waiting_for_map);
  2539. mutex_unlock(&mdsc->mutex);
  2540. schedule_delayed(mdsc);
  2541. return;
  2542. bad_unlock:
  2543. mutex_unlock(&mdsc->mutex);
  2544. bad:
  2545. pr_err("error decoding mdsmap %d\n", err);
  2546. return;
  2547. }
  2548. static struct ceph_connection *con_get(struct ceph_connection *con)
  2549. {
  2550. struct ceph_mds_session *s = con->private;
  2551. if (get_session(s)) {
  2552. dout("mdsc con_get %p ok (%d)\n", s, atomic_read(&s->s_ref));
  2553. return con;
  2554. }
  2555. dout("mdsc con_get %p FAIL\n", s);
  2556. return NULL;
  2557. }
  2558. static void con_put(struct ceph_connection *con)
  2559. {
  2560. struct ceph_mds_session *s = con->private;
  2561. ceph_put_mds_session(s);
  2562. dout("mdsc con_put %p (%d)\n", s, atomic_read(&s->s_ref));
  2563. }
  2564. /*
  2565. * if the client is unresponsive for long enough, the mds will kill
  2566. * the session entirely.
  2567. */
  2568. static void peer_reset(struct ceph_connection *con)
  2569. {
  2570. struct ceph_mds_session *s = con->private;
  2571. pr_err("mds%d gave us the boot. IMPLEMENT RECONNECT.\n",
  2572. s->s_mds);
  2573. }
  2574. static void dispatch(struct ceph_connection *con, struct ceph_msg *msg)
  2575. {
  2576. struct ceph_mds_session *s = con->private;
  2577. struct ceph_mds_client *mdsc = s->s_mdsc;
  2578. int type = le16_to_cpu(msg->hdr.type);
  2579. mutex_lock(&mdsc->mutex);
  2580. if (__verify_registered_session(mdsc, s) < 0) {
  2581. mutex_unlock(&mdsc->mutex);
  2582. goto out;
  2583. }
  2584. mutex_unlock(&mdsc->mutex);
  2585. switch (type) {
  2586. case CEPH_MSG_MDS_MAP:
  2587. ceph_mdsc_handle_map(mdsc, msg);
  2588. break;
  2589. case CEPH_MSG_CLIENT_SESSION:
  2590. handle_session(s, msg);
  2591. break;
  2592. case CEPH_MSG_CLIENT_REPLY:
  2593. handle_reply(s, msg);
  2594. break;
  2595. case CEPH_MSG_CLIENT_REQUEST_FORWARD:
  2596. handle_forward(mdsc, s, msg);
  2597. break;
  2598. case CEPH_MSG_CLIENT_CAPS:
  2599. ceph_handle_caps(s, msg);
  2600. break;
  2601. case CEPH_MSG_CLIENT_SNAP:
  2602. ceph_handle_snap(mdsc, s, msg);
  2603. break;
  2604. case CEPH_MSG_CLIENT_LEASE:
  2605. handle_lease(mdsc, s, msg);
  2606. break;
  2607. default:
  2608. pr_err("received unknown message type %d %s\n", type,
  2609. ceph_msg_type_name(type));
  2610. }
  2611. out:
  2612. ceph_msg_put(msg);
  2613. }
  2614. /*
  2615. * authentication
  2616. */
  2617. static int get_authorizer(struct ceph_connection *con,
  2618. void **buf, int *len, int *proto,
  2619. void **reply_buf, int *reply_len, int force_new)
  2620. {
  2621. struct ceph_mds_session *s = con->private;
  2622. struct ceph_mds_client *mdsc = s->s_mdsc;
  2623. struct ceph_auth_client *ac = mdsc->client->monc.auth;
  2624. int ret = 0;
  2625. if (force_new && s->s_authorizer) {
  2626. ac->ops->destroy_authorizer(ac, s->s_authorizer);
  2627. s->s_authorizer = NULL;
  2628. }
  2629. if (s->s_authorizer == NULL) {
  2630. if (ac->ops->create_authorizer) {
  2631. ret = ac->ops->create_authorizer(
  2632. ac, CEPH_ENTITY_TYPE_MDS,
  2633. &s->s_authorizer,
  2634. &s->s_authorizer_buf,
  2635. &s->s_authorizer_buf_len,
  2636. &s->s_authorizer_reply_buf,
  2637. &s->s_authorizer_reply_buf_len);
  2638. if (ret)
  2639. return ret;
  2640. }
  2641. }
  2642. *proto = ac->protocol;
  2643. *buf = s->s_authorizer_buf;
  2644. *len = s->s_authorizer_buf_len;
  2645. *reply_buf = s->s_authorizer_reply_buf;
  2646. *reply_len = s->s_authorizer_reply_buf_len;
  2647. return 0;
  2648. }
  2649. static int verify_authorizer_reply(struct ceph_connection *con, int len)
  2650. {
  2651. struct ceph_mds_session *s = con->private;
  2652. struct ceph_mds_client *mdsc = s->s_mdsc;
  2653. struct ceph_auth_client *ac = mdsc->client->monc.auth;
  2654. return ac->ops->verify_authorizer_reply(ac, s->s_authorizer, len);
  2655. }
  2656. static int invalidate_authorizer(struct ceph_connection *con)
  2657. {
  2658. struct ceph_mds_session *s = con->private;
  2659. struct ceph_mds_client *mdsc = s->s_mdsc;
  2660. struct ceph_auth_client *ac = mdsc->client->monc.auth;
  2661. if (ac->ops->invalidate_authorizer)
  2662. ac->ops->invalidate_authorizer(ac, CEPH_ENTITY_TYPE_MDS);
  2663. return ceph_monc_validate_auth(&mdsc->client->monc);
  2664. }
  2665. const static struct ceph_connection_operations mds_con_ops = {
  2666. .get = con_get,
  2667. .put = con_put,
  2668. .dispatch = dispatch,
  2669. .get_authorizer = get_authorizer,
  2670. .verify_authorizer_reply = verify_authorizer_reply,
  2671. .invalidate_authorizer = invalidate_authorizer,
  2672. .peer_reset = peer_reset,
  2673. };
  2674. /* eof */