mds_client.c 76 KB

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