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