dlmglue.c 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919
  1. /* -*- mode: c; c-basic-offset: 8; -*-
  2. * vim: noexpandtab sw=8 ts=8 sts=0:
  3. *
  4. * dlmglue.c
  5. *
  6. * Code which implements an OCFS2 specific interface to our DLM.
  7. *
  8. * Copyright (C) 2003, 2004 Oracle. All rights reserved.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2 of the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public
  21. * License along with this program; if not, write to the
  22. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  23. * Boston, MA 021110-1307, USA.
  24. */
  25. #include <linux/types.h>
  26. #include <linux/slab.h>
  27. #include <linux/highmem.h>
  28. #include <linux/mm.h>
  29. #include <linux/smp_lock.h>
  30. #include <linux/crc32.h>
  31. #include <linux/kthread.h>
  32. #include <linux/pagemap.h>
  33. #include <linux/debugfs.h>
  34. #include <linux/seq_file.h>
  35. #include <cluster/heartbeat.h>
  36. #include <cluster/nodemanager.h>
  37. #include <cluster/tcp.h>
  38. #include <dlm/dlmapi.h>
  39. #define MLOG_MASK_PREFIX ML_DLM_GLUE
  40. #include <cluster/masklog.h>
  41. #include "ocfs2.h"
  42. #include "alloc.h"
  43. #include "dcache.h"
  44. #include "dlmglue.h"
  45. #include "extent_map.h"
  46. #include "heartbeat.h"
  47. #include "inode.h"
  48. #include "journal.h"
  49. #include "slot_map.h"
  50. #include "super.h"
  51. #include "uptodate.h"
  52. #include "vote.h"
  53. #include "buffer_head_io.h"
  54. struct ocfs2_mask_waiter {
  55. struct list_head mw_item;
  56. int mw_status;
  57. struct completion mw_complete;
  58. unsigned long mw_mask;
  59. unsigned long mw_goal;
  60. };
  61. static struct ocfs2_super *ocfs2_get_dentry_osb(struct ocfs2_lock_res *lockres);
  62. static struct ocfs2_super *ocfs2_get_inode_osb(struct ocfs2_lock_res *lockres);
  63. /*
  64. * Return value from ->downconvert_worker functions.
  65. *
  66. * These control the precise actions of ocfs2_unblock_lock()
  67. * and ocfs2_process_blocked_lock()
  68. *
  69. */
  70. enum ocfs2_unblock_action {
  71. UNBLOCK_CONTINUE = 0, /* Continue downconvert */
  72. UNBLOCK_CONTINUE_POST = 1, /* Continue downconvert, fire
  73. * ->post_unlock callback */
  74. UNBLOCK_STOP_POST = 2, /* Do not downconvert, fire
  75. * ->post_unlock() callback. */
  76. };
  77. struct ocfs2_unblock_ctl {
  78. int requeue;
  79. enum ocfs2_unblock_action unblock_action;
  80. };
  81. static int ocfs2_check_meta_downconvert(struct ocfs2_lock_res *lockres,
  82. int new_level);
  83. static void ocfs2_set_meta_lvb(struct ocfs2_lock_res *lockres);
  84. static int ocfs2_data_convert_worker(struct ocfs2_lock_res *lockres,
  85. int blocking);
  86. static int ocfs2_dentry_convert_worker(struct ocfs2_lock_res *lockres,
  87. int blocking);
  88. static void ocfs2_dentry_post_unlock(struct ocfs2_super *osb,
  89. struct ocfs2_lock_res *lockres);
  90. /*
  91. * OCFS2 Lock Resource Operations
  92. *
  93. * These fine tune the behavior of the generic dlmglue locking infrastructure.
  94. *
  95. * The most basic of lock types can point ->l_priv to their respective
  96. * struct ocfs2_super and allow the default actions to manage things.
  97. *
  98. * Right now, each lock type also needs to implement an init function,
  99. * and trivial lock/unlock wrappers. ocfs2_simple_drop_lockres()
  100. * should be called when the lock is no longer needed (i.e., object
  101. * destruction time).
  102. */
  103. struct ocfs2_lock_res_ops {
  104. /*
  105. * Translate an ocfs2_lock_res * into an ocfs2_super *. Define
  106. * this callback if ->l_priv is not an ocfs2_super pointer
  107. */
  108. struct ocfs2_super * (*get_osb)(struct ocfs2_lock_res *);
  109. /*
  110. * Optionally called in the downconvert (or "vote") thread
  111. * after a successful downconvert. The lockres will not be
  112. * referenced after this callback is called, so it is safe to
  113. * free memory, etc.
  114. *
  115. * The exact semantics of when this is called are controlled
  116. * by ->downconvert_worker()
  117. */
  118. void (*post_unlock)(struct ocfs2_super *, struct ocfs2_lock_res *);
  119. /*
  120. * Allow a lock type to add checks to determine whether it is
  121. * safe to downconvert a lock. Return 0 to re-queue the
  122. * downconvert at a later time, nonzero to continue.
  123. *
  124. * For most locks, the default checks that there are no
  125. * incompatible holders are sufficient.
  126. *
  127. * Called with the lockres spinlock held.
  128. */
  129. int (*check_downconvert)(struct ocfs2_lock_res *, int);
  130. /*
  131. * Allows a lock type to populate the lock value block. This
  132. * is called on downconvert, and when we drop a lock.
  133. *
  134. * Locks that want to use this should set LOCK_TYPE_USES_LVB
  135. * in the flags field.
  136. *
  137. * Called with the lockres spinlock held.
  138. */
  139. void (*set_lvb)(struct ocfs2_lock_res *);
  140. /*
  141. * Called from the downconvert thread when it is determined
  142. * that a lock will be downconverted. This is called without
  143. * any locks held so the function can do work that might
  144. * schedule (syncing out data, etc).
  145. *
  146. * This should return any one of the ocfs2_unblock_action
  147. * values, depending on what it wants the thread to do.
  148. */
  149. int (*downconvert_worker)(struct ocfs2_lock_res *, int);
  150. /*
  151. * LOCK_TYPE_* flags which describe the specific requirements
  152. * of a lock type. Descriptions of each individual flag follow.
  153. */
  154. int flags;
  155. };
  156. /*
  157. * Some locks want to "refresh" potentially stale data when a
  158. * meaningful (PRMODE or EXMODE) lock level is first obtained. If this
  159. * flag is set, the OCFS2_LOCK_NEEDS_REFRESH flag will be set on the
  160. * individual lockres l_flags member from the ast function. It is
  161. * expected that the locking wrapper will clear the
  162. * OCFS2_LOCK_NEEDS_REFRESH flag when done.
  163. */
  164. #define LOCK_TYPE_REQUIRES_REFRESH 0x1
  165. /*
  166. * Indicate that a lock type makes use of the lock value block. The
  167. * ->set_lvb lock type callback must be defined.
  168. */
  169. #define LOCK_TYPE_USES_LVB 0x2
  170. static struct ocfs2_lock_res_ops ocfs2_inode_rw_lops = {
  171. .get_osb = ocfs2_get_inode_osb,
  172. .flags = 0,
  173. };
  174. static struct ocfs2_lock_res_ops ocfs2_inode_meta_lops = {
  175. .get_osb = ocfs2_get_inode_osb,
  176. .check_downconvert = ocfs2_check_meta_downconvert,
  177. .set_lvb = ocfs2_set_meta_lvb,
  178. .flags = LOCK_TYPE_REQUIRES_REFRESH|LOCK_TYPE_USES_LVB,
  179. };
  180. static struct ocfs2_lock_res_ops ocfs2_inode_data_lops = {
  181. .get_osb = ocfs2_get_inode_osb,
  182. .downconvert_worker = ocfs2_data_convert_worker,
  183. .flags = 0,
  184. };
  185. static struct ocfs2_lock_res_ops ocfs2_super_lops = {
  186. .flags = LOCK_TYPE_REQUIRES_REFRESH,
  187. };
  188. static struct ocfs2_lock_res_ops ocfs2_rename_lops = {
  189. .flags = 0,
  190. };
  191. static struct ocfs2_lock_res_ops ocfs2_dentry_lops = {
  192. .get_osb = ocfs2_get_dentry_osb,
  193. .post_unlock = ocfs2_dentry_post_unlock,
  194. .downconvert_worker = ocfs2_dentry_convert_worker,
  195. .flags = 0,
  196. };
  197. static inline int ocfs2_is_inode_lock(struct ocfs2_lock_res *lockres)
  198. {
  199. return lockres->l_type == OCFS2_LOCK_TYPE_META ||
  200. lockres->l_type == OCFS2_LOCK_TYPE_DATA ||
  201. lockres->l_type == OCFS2_LOCK_TYPE_RW;
  202. }
  203. static inline struct inode *ocfs2_lock_res_inode(struct ocfs2_lock_res *lockres)
  204. {
  205. BUG_ON(!ocfs2_is_inode_lock(lockres));
  206. return (struct inode *) lockres->l_priv;
  207. }
  208. static inline struct ocfs2_dentry_lock *ocfs2_lock_res_dl(struct ocfs2_lock_res *lockres)
  209. {
  210. BUG_ON(lockres->l_type != OCFS2_LOCK_TYPE_DENTRY);
  211. return (struct ocfs2_dentry_lock *)lockres->l_priv;
  212. }
  213. static inline struct ocfs2_super *ocfs2_get_lockres_osb(struct ocfs2_lock_res *lockres)
  214. {
  215. if (lockres->l_ops->get_osb)
  216. return lockres->l_ops->get_osb(lockres);
  217. return (struct ocfs2_super *)lockres->l_priv;
  218. }
  219. static int ocfs2_lock_create(struct ocfs2_super *osb,
  220. struct ocfs2_lock_res *lockres,
  221. int level,
  222. int dlm_flags);
  223. static inline int ocfs2_may_continue_on_blocked_lock(struct ocfs2_lock_res *lockres,
  224. int wanted);
  225. static void ocfs2_cluster_unlock(struct ocfs2_super *osb,
  226. struct ocfs2_lock_res *lockres,
  227. int level);
  228. static inline void ocfs2_generic_handle_downconvert_action(struct ocfs2_lock_res *lockres);
  229. static inline void ocfs2_generic_handle_convert_action(struct ocfs2_lock_res *lockres);
  230. static inline void ocfs2_generic_handle_attach_action(struct ocfs2_lock_res *lockres);
  231. static int ocfs2_generic_handle_bast(struct ocfs2_lock_res *lockres, int level);
  232. static void ocfs2_schedule_blocked_lock(struct ocfs2_super *osb,
  233. struct ocfs2_lock_res *lockres);
  234. static inline void ocfs2_recover_from_dlm_error(struct ocfs2_lock_res *lockres,
  235. int convert);
  236. #define ocfs2_log_dlm_error(_func, _stat, _lockres) do { \
  237. mlog(ML_ERROR, "Dlm error \"%s\" while calling %s on " \
  238. "resource %s: %s\n", dlm_errname(_stat), _func, \
  239. _lockres->l_name, dlm_errmsg(_stat)); \
  240. } while (0)
  241. static void ocfs2_vote_on_unlock(struct ocfs2_super *osb,
  242. struct ocfs2_lock_res *lockres);
  243. static int ocfs2_meta_lock_update(struct inode *inode,
  244. struct buffer_head **bh);
  245. static void ocfs2_drop_osb_locks(struct ocfs2_super *osb);
  246. static inline int ocfs2_highest_compat_lock_level(int level);
  247. static void ocfs2_build_lock_name(enum ocfs2_lock_type type,
  248. u64 blkno,
  249. u32 generation,
  250. char *name)
  251. {
  252. int len;
  253. mlog_entry_void();
  254. BUG_ON(type >= OCFS2_NUM_LOCK_TYPES);
  255. len = snprintf(name, OCFS2_LOCK_ID_MAX_LEN, "%c%s%016llx%08x",
  256. ocfs2_lock_type_char(type), OCFS2_LOCK_ID_PAD,
  257. (long long)blkno, generation);
  258. BUG_ON(len != (OCFS2_LOCK_ID_MAX_LEN - 1));
  259. mlog(0, "built lock resource with name: %s\n", name);
  260. mlog_exit_void();
  261. }
  262. static DEFINE_SPINLOCK(ocfs2_dlm_tracking_lock);
  263. static void ocfs2_add_lockres_tracking(struct ocfs2_lock_res *res,
  264. struct ocfs2_dlm_debug *dlm_debug)
  265. {
  266. mlog(0, "Add tracking for lockres %s\n", res->l_name);
  267. spin_lock(&ocfs2_dlm_tracking_lock);
  268. list_add(&res->l_debug_list, &dlm_debug->d_lockres_tracking);
  269. spin_unlock(&ocfs2_dlm_tracking_lock);
  270. }
  271. static void ocfs2_remove_lockres_tracking(struct ocfs2_lock_res *res)
  272. {
  273. spin_lock(&ocfs2_dlm_tracking_lock);
  274. if (!list_empty(&res->l_debug_list))
  275. list_del_init(&res->l_debug_list);
  276. spin_unlock(&ocfs2_dlm_tracking_lock);
  277. }
  278. static void ocfs2_lock_res_init_common(struct ocfs2_super *osb,
  279. struct ocfs2_lock_res *res,
  280. enum ocfs2_lock_type type,
  281. struct ocfs2_lock_res_ops *ops,
  282. void *priv)
  283. {
  284. res->l_type = type;
  285. res->l_ops = ops;
  286. res->l_priv = priv;
  287. res->l_level = LKM_IVMODE;
  288. res->l_requested = LKM_IVMODE;
  289. res->l_blocking = LKM_IVMODE;
  290. res->l_action = OCFS2_AST_INVALID;
  291. res->l_unlock_action = OCFS2_UNLOCK_INVALID;
  292. res->l_flags = OCFS2_LOCK_INITIALIZED;
  293. ocfs2_add_lockres_tracking(res, osb->osb_dlm_debug);
  294. }
  295. void ocfs2_lock_res_init_once(struct ocfs2_lock_res *res)
  296. {
  297. /* This also clears out the lock status block */
  298. memset(res, 0, sizeof(struct ocfs2_lock_res));
  299. spin_lock_init(&res->l_lock);
  300. init_waitqueue_head(&res->l_event);
  301. INIT_LIST_HEAD(&res->l_blocked_list);
  302. INIT_LIST_HEAD(&res->l_mask_waiters);
  303. }
  304. void ocfs2_inode_lock_res_init(struct ocfs2_lock_res *res,
  305. enum ocfs2_lock_type type,
  306. unsigned int generation,
  307. struct inode *inode)
  308. {
  309. struct ocfs2_lock_res_ops *ops;
  310. switch(type) {
  311. case OCFS2_LOCK_TYPE_RW:
  312. ops = &ocfs2_inode_rw_lops;
  313. break;
  314. case OCFS2_LOCK_TYPE_META:
  315. ops = &ocfs2_inode_meta_lops;
  316. break;
  317. case OCFS2_LOCK_TYPE_DATA:
  318. ops = &ocfs2_inode_data_lops;
  319. break;
  320. default:
  321. mlog_bug_on_msg(1, "type: %d\n", type);
  322. ops = NULL; /* thanks, gcc */
  323. break;
  324. };
  325. ocfs2_build_lock_name(type, OCFS2_I(inode)->ip_blkno,
  326. generation, res->l_name);
  327. ocfs2_lock_res_init_common(OCFS2_SB(inode->i_sb), res, type, ops, inode);
  328. }
  329. static struct ocfs2_super *ocfs2_get_inode_osb(struct ocfs2_lock_res *lockres)
  330. {
  331. struct inode *inode = ocfs2_lock_res_inode(lockres);
  332. return OCFS2_SB(inode->i_sb);
  333. }
  334. static __u64 ocfs2_get_dentry_lock_ino(struct ocfs2_lock_res *lockres)
  335. {
  336. __be64 inode_blkno_be;
  337. memcpy(&inode_blkno_be, &lockres->l_name[OCFS2_DENTRY_LOCK_INO_START],
  338. sizeof(__be64));
  339. return be64_to_cpu(inode_blkno_be);
  340. }
  341. static struct ocfs2_super *ocfs2_get_dentry_osb(struct ocfs2_lock_res *lockres)
  342. {
  343. struct ocfs2_dentry_lock *dl = lockres->l_priv;
  344. return OCFS2_SB(dl->dl_inode->i_sb);
  345. }
  346. void ocfs2_dentry_lock_res_init(struct ocfs2_dentry_lock *dl,
  347. u64 parent, struct inode *inode)
  348. {
  349. int len;
  350. u64 inode_blkno = OCFS2_I(inode)->ip_blkno;
  351. __be64 inode_blkno_be = cpu_to_be64(inode_blkno);
  352. struct ocfs2_lock_res *lockres = &dl->dl_lockres;
  353. ocfs2_lock_res_init_once(lockres);
  354. /*
  355. * Unfortunately, the standard lock naming scheme won't work
  356. * here because we have two 16 byte values to use. Instead,
  357. * we'll stuff the inode number as a binary value. We still
  358. * want error prints to show something without garbling the
  359. * display, so drop a null byte in there before the inode
  360. * number. A future version of OCFS2 will likely use all
  361. * binary lock names. The stringified names have been a
  362. * tremendous aid in debugging, but now that the debugfs
  363. * interface exists, we can mangle things there if need be.
  364. *
  365. * NOTE: We also drop the standard "pad" value (the total lock
  366. * name size stays the same though - the last part is all
  367. * zeros due to the memset in ocfs2_lock_res_init_once()
  368. */
  369. len = snprintf(lockres->l_name, OCFS2_DENTRY_LOCK_INO_START,
  370. "%c%016llx",
  371. ocfs2_lock_type_char(OCFS2_LOCK_TYPE_DENTRY),
  372. (long long)parent);
  373. BUG_ON(len != (OCFS2_DENTRY_LOCK_INO_START - 1));
  374. memcpy(&lockres->l_name[OCFS2_DENTRY_LOCK_INO_START], &inode_blkno_be,
  375. sizeof(__be64));
  376. ocfs2_lock_res_init_common(OCFS2_SB(inode->i_sb), lockres,
  377. OCFS2_LOCK_TYPE_DENTRY, &ocfs2_dentry_lops,
  378. dl);
  379. }
  380. static void ocfs2_super_lock_res_init(struct ocfs2_lock_res *res,
  381. struct ocfs2_super *osb)
  382. {
  383. /* Superblock lockres doesn't come from a slab so we call init
  384. * once on it manually. */
  385. ocfs2_lock_res_init_once(res);
  386. ocfs2_build_lock_name(OCFS2_LOCK_TYPE_SUPER, OCFS2_SUPER_BLOCK_BLKNO,
  387. 0, res->l_name);
  388. ocfs2_lock_res_init_common(osb, res, OCFS2_LOCK_TYPE_SUPER,
  389. &ocfs2_super_lops, osb);
  390. }
  391. static void ocfs2_rename_lock_res_init(struct ocfs2_lock_res *res,
  392. struct ocfs2_super *osb)
  393. {
  394. /* Rename lockres doesn't come from a slab so we call init
  395. * once on it manually. */
  396. ocfs2_lock_res_init_once(res);
  397. ocfs2_build_lock_name(OCFS2_LOCK_TYPE_RENAME, 0, 0, res->l_name);
  398. ocfs2_lock_res_init_common(osb, res, OCFS2_LOCK_TYPE_RENAME,
  399. &ocfs2_rename_lops, osb);
  400. }
  401. void ocfs2_lock_res_free(struct ocfs2_lock_res *res)
  402. {
  403. mlog_entry_void();
  404. if (!(res->l_flags & OCFS2_LOCK_INITIALIZED))
  405. return;
  406. ocfs2_remove_lockres_tracking(res);
  407. mlog_bug_on_msg(!list_empty(&res->l_blocked_list),
  408. "Lockres %s is on the blocked list\n",
  409. res->l_name);
  410. mlog_bug_on_msg(!list_empty(&res->l_mask_waiters),
  411. "Lockres %s has mask waiters pending\n",
  412. res->l_name);
  413. mlog_bug_on_msg(spin_is_locked(&res->l_lock),
  414. "Lockres %s is locked\n",
  415. res->l_name);
  416. mlog_bug_on_msg(res->l_ro_holders,
  417. "Lockres %s has %u ro holders\n",
  418. res->l_name, res->l_ro_holders);
  419. mlog_bug_on_msg(res->l_ex_holders,
  420. "Lockres %s has %u ex holders\n",
  421. res->l_name, res->l_ex_holders);
  422. /* Need to clear out the lock status block for the dlm */
  423. memset(&res->l_lksb, 0, sizeof(res->l_lksb));
  424. res->l_flags = 0UL;
  425. mlog_exit_void();
  426. }
  427. static inline void ocfs2_inc_holders(struct ocfs2_lock_res *lockres,
  428. int level)
  429. {
  430. mlog_entry_void();
  431. BUG_ON(!lockres);
  432. switch(level) {
  433. case LKM_EXMODE:
  434. lockres->l_ex_holders++;
  435. break;
  436. case LKM_PRMODE:
  437. lockres->l_ro_holders++;
  438. break;
  439. default:
  440. BUG();
  441. }
  442. mlog_exit_void();
  443. }
  444. static inline void ocfs2_dec_holders(struct ocfs2_lock_res *lockres,
  445. int level)
  446. {
  447. mlog_entry_void();
  448. BUG_ON(!lockres);
  449. switch(level) {
  450. case LKM_EXMODE:
  451. BUG_ON(!lockres->l_ex_holders);
  452. lockres->l_ex_holders--;
  453. break;
  454. case LKM_PRMODE:
  455. BUG_ON(!lockres->l_ro_holders);
  456. lockres->l_ro_holders--;
  457. break;
  458. default:
  459. BUG();
  460. }
  461. mlog_exit_void();
  462. }
  463. /* WARNING: This function lives in a world where the only three lock
  464. * levels are EX, PR, and NL. It *will* have to be adjusted when more
  465. * lock types are added. */
  466. static inline int ocfs2_highest_compat_lock_level(int level)
  467. {
  468. int new_level = LKM_EXMODE;
  469. if (level == LKM_EXMODE)
  470. new_level = LKM_NLMODE;
  471. else if (level == LKM_PRMODE)
  472. new_level = LKM_PRMODE;
  473. return new_level;
  474. }
  475. static void lockres_set_flags(struct ocfs2_lock_res *lockres,
  476. unsigned long newflags)
  477. {
  478. struct list_head *pos, *tmp;
  479. struct ocfs2_mask_waiter *mw;
  480. assert_spin_locked(&lockres->l_lock);
  481. lockres->l_flags = newflags;
  482. list_for_each_safe(pos, tmp, &lockres->l_mask_waiters) {
  483. mw = list_entry(pos, struct ocfs2_mask_waiter, mw_item);
  484. if ((lockres->l_flags & mw->mw_mask) != mw->mw_goal)
  485. continue;
  486. list_del_init(&mw->mw_item);
  487. mw->mw_status = 0;
  488. complete(&mw->mw_complete);
  489. }
  490. }
  491. static void lockres_or_flags(struct ocfs2_lock_res *lockres, unsigned long or)
  492. {
  493. lockres_set_flags(lockres, lockres->l_flags | or);
  494. }
  495. static void lockres_clear_flags(struct ocfs2_lock_res *lockres,
  496. unsigned long clear)
  497. {
  498. lockres_set_flags(lockres, lockres->l_flags & ~clear);
  499. }
  500. static inline void ocfs2_generic_handle_downconvert_action(struct ocfs2_lock_res *lockres)
  501. {
  502. mlog_entry_void();
  503. BUG_ON(!(lockres->l_flags & OCFS2_LOCK_BUSY));
  504. BUG_ON(!(lockres->l_flags & OCFS2_LOCK_ATTACHED));
  505. BUG_ON(!(lockres->l_flags & OCFS2_LOCK_BLOCKED));
  506. BUG_ON(lockres->l_blocking <= LKM_NLMODE);
  507. lockres->l_level = lockres->l_requested;
  508. if (lockres->l_level <=
  509. ocfs2_highest_compat_lock_level(lockres->l_blocking)) {
  510. lockres->l_blocking = LKM_NLMODE;
  511. lockres_clear_flags(lockres, OCFS2_LOCK_BLOCKED);
  512. }
  513. lockres_clear_flags(lockres, OCFS2_LOCK_BUSY);
  514. mlog_exit_void();
  515. }
  516. static inline void ocfs2_generic_handle_convert_action(struct ocfs2_lock_res *lockres)
  517. {
  518. mlog_entry_void();
  519. BUG_ON(!(lockres->l_flags & OCFS2_LOCK_BUSY));
  520. BUG_ON(!(lockres->l_flags & OCFS2_LOCK_ATTACHED));
  521. /* Convert from RO to EX doesn't really need anything as our
  522. * information is already up to data. Convert from NL to
  523. * *anything* however should mark ourselves as needing an
  524. * update */
  525. if (lockres->l_level == LKM_NLMODE &&
  526. lockres->l_ops->flags & LOCK_TYPE_REQUIRES_REFRESH)
  527. lockres_or_flags(lockres, OCFS2_LOCK_NEEDS_REFRESH);
  528. lockres->l_level = lockres->l_requested;
  529. lockres_clear_flags(lockres, OCFS2_LOCK_BUSY);
  530. mlog_exit_void();
  531. }
  532. static inline void ocfs2_generic_handle_attach_action(struct ocfs2_lock_res *lockres)
  533. {
  534. mlog_entry_void();
  535. BUG_ON((!lockres->l_flags & OCFS2_LOCK_BUSY));
  536. BUG_ON(lockres->l_flags & OCFS2_LOCK_ATTACHED);
  537. if (lockres->l_requested > LKM_NLMODE &&
  538. !(lockres->l_flags & OCFS2_LOCK_LOCAL) &&
  539. lockres->l_ops->flags & LOCK_TYPE_REQUIRES_REFRESH)
  540. lockres_or_flags(lockres, OCFS2_LOCK_NEEDS_REFRESH);
  541. lockres->l_level = lockres->l_requested;
  542. lockres_or_flags(lockres, OCFS2_LOCK_ATTACHED);
  543. lockres_clear_flags(lockres, OCFS2_LOCK_BUSY);
  544. mlog_exit_void();
  545. }
  546. static int ocfs2_generic_handle_bast(struct ocfs2_lock_res *lockres,
  547. int level)
  548. {
  549. int needs_downconvert = 0;
  550. mlog_entry_void();
  551. assert_spin_locked(&lockres->l_lock);
  552. lockres_or_flags(lockres, OCFS2_LOCK_BLOCKED);
  553. if (level > lockres->l_blocking) {
  554. /* only schedule a downconvert if we haven't already scheduled
  555. * one that goes low enough to satisfy the level we're
  556. * blocking. this also catches the case where we get
  557. * duplicate BASTs */
  558. if (ocfs2_highest_compat_lock_level(level) <
  559. ocfs2_highest_compat_lock_level(lockres->l_blocking))
  560. needs_downconvert = 1;
  561. lockres->l_blocking = level;
  562. }
  563. mlog_exit(needs_downconvert);
  564. return needs_downconvert;
  565. }
  566. static void ocfs2_blocking_ast(void *opaque, int level)
  567. {
  568. struct ocfs2_lock_res *lockres = opaque;
  569. struct ocfs2_super *osb = ocfs2_get_lockres_osb(lockres);
  570. int needs_downconvert;
  571. unsigned long flags;
  572. BUG_ON(level <= LKM_NLMODE);
  573. mlog(0, "BAST fired for lockres %s, blocking %d, level %d type %s\n",
  574. lockres->l_name, level, lockres->l_level,
  575. ocfs2_lock_type_string(lockres->l_type));
  576. spin_lock_irqsave(&lockres->l_lock, flags);
  577. needs_downconvert = ocfs2_generic_handle_bast(lockres, level);
  578. if (needs_downconvert)
  579. ocfs2_schedule_blocked_lock(osb, lockres);
  580. spin_unlock_irqrestore(&lockres->l_lock, flags);
  581. wake_up(&lockres->l_event);
  582. ocfs2_kick_vote_thread(osb);
  583. }
  584. static void ocfs2_locking_ast(void *opaque)
  585. {
  586. struct ocfs2_lock_res *lockres = opaque;
  587. struct dlm_lockstatus *lksb = &lockres->l_lksb;
  588. unsigned long flags;
  589. spin_lock_irqsave(&lockres->l_lock, flags);
  590. if (lksb->status != DLM_NORMAL) {
  591. mlog(ML_ERROR, "lockres %s: lksb status value of %u!\n",
  592. lockres->l_name, lksb->status);
  593. spin_unlock_irqrestore(&lockres->l_lock, flags);
  594. return;
  595. }
  596. switch(lockres->l_action) {
  597. case OCFS2_AST_ATTACH:
  598. ocfs2_generic_handle_attach_action(lockres);
  599. lockres_clear_flags(lockres, OCFS2_LOCK_LOCAL);
  600. break;
  601. case OCFS2_AST_CONVERT:
  602. ocfs2_generic_handle_convert_action(lockres);
  603. break;
  604. case OCFS2_AST_DOWNCONVERT:
  605. ocfs2_generic_handle_downconvert_action(lockres);
  606. break;
  607. default:
  608. mlog(ML_ERROR, "lockres %s: ast fired with invalid action: %u "
  609. "lockres flags = 0x%lx, unlock action: %u\n",
  610. lockres->l_name, lockres->l_action, lockres->l_flags,
  611. lockres->l_unlock_action);
  612. BUG();
  613. }
  614. /* set it to something invalid so if we get called again we
  615. * can catch it. */
  616. lockres->l_action = OCFS2_AST_INVALID;
  617. wake_up(&lockres->l_event);
  618. spin_unlock_irqrestore(&lockres->l_lock, flags);
  619. }
  620. static inline void ocfs2_recover_from_dlm_error(struct ocfs2_lock_res *lockres,
  621. int convert)
  622. {
  623. unsigned long flags;
  624. mlog_entry_void();
  625. spin_lock_irqsave(&lockres->l_lock, flags);
  626. lockres_clear_flags(lockres, OCFS2_LOCK_BUSY);
  627. if (convert)
  628. lockres->l_action = OCFS2_AST_INVALID;
  629. else
  630. lockres->l_unlock_action = OCFS2_UNLOCK_INVALID;
  631. spin_unlock_irqrestore(&lockres->l_lock, flags);
  632. wake_up(&lockres->l_event);
  633. mlog_exit_void();
  634. }
  635. /* Note: If we detect another process working on the lock (i.e.,
  636. * OCFS2_LOCK_BUSY), we'll bail out returning 0. It's up to the caller
  637. * to do the right thing in that case.
  638. */
  639. static int ocfs2_lock_create(struct ocfs2_super *osb,
  640. struct ocfs2_lock_res *lockres,
  641. int level,
  642. int dlm_flags)
  643. {
  644. int ret = 0;
  645. enum dlm_status status;
  646. unsigned long flags;
  647. mlog_entry_void();
  648. mlog(0, "lock %s, level = %d, flags = %d\n", lockres->l_name, level,
  649. dlm_flags);
  650. spin_lock_irqsave(&lockres->l_lock, flags);
  651. if ((lockres->l_flags & OCFS2_LOCK_ATTACHED) ||
  652. (lockres->l_flags & OCFS2_LOCK_BUSY)) {
  653. spin_unlock_irqrestore(&lockres->l_lock, flags);
  654. goto bail;
  655. }
  656. lockres->l_action = OCFS2_AST_ATTACH;
  657. lockres->l_requested = level;
  658. lockres_or_flags(lockres, OCFS2_LOCK_BUSY);
  659. spin_unlock_irqrestore(&lockres->l_lock, flags);
  660. status = dlmlock(osb->dlm,
  661. level,
  662. &lockres->l_lksb,
  663. dlm_flags,
  664. lockres->l_name,
  665. OCFS2_LOCK_ID_MAX_LEN - 1,
  666. ocfs2_locking_ast,
  667. lockres,
  668. ocfs2_blocking_ast);
  669. if (status != DLM_NORMAL) {
  670. ocfs2_log_dlm_error("dlmlock", status, lockres);
  671. ret = -EINVAL;
  672. ocfs2_recover_from_dlm_error(lockres, 1);
  673. }
  674. mlog(0, "lock %s, successfull return from dlmlock\n", lockres->l_name);
  675. bail:
  676. mlog_exit(ret);
  677. return ret;
  678. }
  679. static inline int ocfs2_check_wait_flag(struct ocfs2_lock_res *lockres,
  680. int flag)
  681. {
  682. unsigned long flags;
  683. int ret;
  684. spin_lock_irqsave(&lockres->l_lock, flags);
  685. ret = lockres->l_flags & flag;
  686. spin_unlock_irqrestore(&lockres->l_lock, flags);
  687. return ret;
  688. }
  689. static inline void ocfs2_wait_on_busy_lock(struct ocfs2_lock_res *lockres)
  690. {
  691. wait_event(lockres->l_event,
  692. !ocfs2_check_wait_flag(lockres, OCFS2_LOCK_BUSY));
  693. }
  694. static inline void ocfs2_wait_on_refreshing_lock(struct ocfs2_lock_res *lockres)
  695. {
  696. wait_event(lockres->l_event,
  697. !ocfs2_check_wait_flag(lockres, OCFS2_LOCK_REFRESHING));
  698. }
  699. /* predict what lock level we'll be dropping down to on behalf
  700. * of another node, and return true if the currently wanted
  701. * level will be compatible with it. */
  702. static inline int ocfs2_may_continue_on_blocked_lock(struct ocfs2_lock_res *lockres,
  703. int wanted)
  704. {
  705. BUG_ON(!(lockres->l_flags & OCFS2_LOCK_BLOCKED));
  706. return wanted <= ocfs2_highest_compat_lock_level(lockres->l_blocking);
  707. }
  708. static void ocfs2_init_mask_waiter(struct ocfs2_mask_waiter *mw)
  709. {
  710. INIT_LIST_HEAD(&mw->mw_item);
  711. init_completion(&mw->mw_complete);
  712. }
  713. static int ocfs2_wait_for_mask(struct ocfs2_mask_waiter *mw)
  714. {
  715. wait_for_completion(&mw->mw_complete);
  716. /* Re-arm the completion in case we want to wait on it again */
  717. INIT_COMPLETION(mw->mw_complete);
  718. return mw->mw_status;
  719. }
  720. static void lockres_add_mask_waiter(struct ocfs2_lock_res *lockres,
  721. struct ocfs2_mask_waiter *mw,
  722. unsigned long mask,
  723. unsigned long goal)
  724. {
  725. BUG_ON(!list_empty(&mw->mw_item));
  726. assert_spin_locked(&lockres->l_lock);
  727. list_add_tail(&mw->mw_item, &lockres->l_mask_waiters);
  728. mw->mw_mask = mask;
  729. mw->mw_goal = goal;
  730. }
  731. /* returns 0 if the mw that was removed was already satisfied, -EBUSY
  732. * if the mask still hadn't reached its goal */
  733. static int lockres_remove_mask_waiter(struct ocfs2_lock_res *lockres,
  734. struct ocfs2_mask_waiter *mw)
  735. {
  736. unsigned long flags;
  737. int ret = 0;
  738. spin_lock_irqsave(&lockres->l_lock, flags);
  739. if (!list_empty(&mw->mw_item)) {
  740. if ((lockres->l_flags & mw->mw_mask) != mw->mw_goal)
  741. ret = -EBUSY;
  742. list_del_init(&mw->mw_item);
  743. init_completion(&mw->mw_complete);
  744. }
  745. spin_unlock_irqrestore(&lockres->l_lock, flags);
  746. return ret;
  747. }
  748. static int ocfs2_cluster_lock(struct ocfs2_super *osb,
  749. struct ocfs2_lock_res *lockres,
  750. int level,
  751. int lkm_flags,
  752. int arg_flags)
  753. {
  754. struct ocfs2_mask_waiter mw;
  755. enum dlm_status status;
  756. int wait, catch_signals = !(osb->s_mount_opt & OCFS2_MOUNT_NOINTR);
  757. int ret = 0; /* gcc doesn't realize wait = 1 guarantees ret is set */
  758. unsigned long flags;
  759. mlog_entry_void();
  760. ocfs2_init_mask_waiter(&mw);
  761. if (lockres->l_ops->flags & LOCK_TYPE_USES_LVB)
  762. lkm_flags |= LKM_VALBLK;
  763. again:
  764. wait = 0;
  765. if (catch_signals && signal_pending(current)) {
  766. ret = -ERESTARTSYS;
  767. goto out;
  768. }
  769. spin_lock_irqsave(&lockres->l_lock, flags);
  770. mlog_bug_on_msg(lockres->l_flags & OCFS2_LOCK_FREEING,
  771. "Cluster lock called on freeing lockres %s! flags "
  772. "0x%lx\n", lockres->l_name, lockres->l_flags);
  773. /* We only compare against the currently granted level
  774. * here. If the lock is blocked waiting on a downconvert,
  775. * we'll get caught below. */
  776. if (lockres->l_flags & OCFS2_LOCK_BUSY &&
  777. level > lockres->l_level) {
  778. /* is someone sitting in dlm_lock? If so, wait on
  779. * them. */
  780. lockres_add_mask_waiter(lockres, &mw, OCFS2_LOCK_BUSY, 0);
  781. wait = 1;
  782. goto unlock;
  783. }
  784. if (!(lockres->l_flags & OCFS2_LOCK_ATTACHED)) {
  785. /* lock has not been created yet. */
  786. spin_unlock_irqrestore(&lockres->l_lock, flags);
  787. ret = ocfs2_lock_create(osb, lockres, LKM_NLMODE, 0);
  788. if (ret < 0) {
  789. mlog_errno(ret);
  790. goto out;
  791. }
  792. goto again;
  793. }
  794. if (lockres->l_flags & OCFS2_LOCK_BLOCKED &&
  795. !ocfs2_may_continue_on_blocked_lock(lockres, level)) {
  796. /* is the lock is currently blocked on behalf of
  797. * another node */
  798. lockres_add_mask_waiter(lockres, &mw, OCFS2_LOCK_BLOCKED, 0);
  799. wait = 1;
  800. goto unlock;
  801. }
  802. if (level > lockres->l_level) {
  803. if (lockres->l_action != OCFS2_AST_INVALID)
  804. mlog(ML_ERROR, "lockres %s has action %u pending\n",
  805. lockres->l_name, lockres->l_action);
  806. lockres->l_action = OCFS2_AST_CONVERT;
  807. lockres->l_requested = level;
  808. lockres_or_flags(lockres, OCFS2_LOCK_BUSY);
  809. spin_unlock_irqrestore(&lockres->l_lock, flags);
  810. BUG_ON(level == LKM_IVMODE);
  811. BUG_ON(level == LKM_NLMODE);
  812. mlog(0, "lock %s, convert from %d to level = %d\n",
  813. lockres->l_name, lockres->l_level, level);
  814. /* call dlm_lock to upgrade lock now */
  815. status = dlmlock(osb->dlm,
  816. level,
  817. &lockres->l_lksb,
  818. lkm_flags|LKM_CONVERT,
  819. lockres->l_name,
  820. OCFS2_LOCK_ID_MAX_LEN - 1,
  821. ocfs2_locking_ast,
  822. lockres,
  823. ocfs2_blocking_ast);
  824. if (status != DLM_NORMAL) {
  825. if ((lkm_flags & LKM_NOQUEUE) &&
  826. (status == DLM_NOTQUEUED))
  827. ret = -EAGAIN;
  828. else {
  829. ocfs2_log_dlm_error("dlmlock", status,
  830. lockres);
  831. ret = -EINVAL;
  832. }
  833. ocfs2_recover_from_dlm_error(lockres, 1);
  834. goto out;
  835. }
  836. mlog(0, "lock %s, successfull return from dlmlock\n",
  837. lockres->l_name);
  838. /* At this point we've gone inside the dlm and need to
  839. * complete our work regardless. */
  840. catch_signals = 0;
  841. /* wait for busy to clear and carry on */
  842. goto again;
  843. }
  844. /* Ok, if we get here then we're good to go. */
  845. ocfs2_inc_holders(lockres, level);
  846. ret = 0;
  847. unlock:
  848. spin_unlock_irqrestore(&lockres->l_lock, flags);
  849. out:
  850. /*
  851. * This is helping work around a lock inversion between the page lock
  852. * and dlm locks. One path holds the page lock while calling aops
  853. * which block acquiring dlm locks. The voting thread holds dlm
  854. * locks while acquiring page locks while down converting data locks.
  855. * This block is helping an aop path notice the inversion and back
  856. * off to unlock its page lock before trying the dlm lock again.
  857. */
  858. if (wait && arg_flags & OCFS2_LOCK_NONBLOCK &&
  859. mw.mw_mask & (OCFS2_LOCK_BUSY|OCFS2_LOCK_BLOCKED)) {
  860. wait = 0;
  861. if (lockres_remove_mask_waiter(lockres, &mw))
  862. ret = -EAGAIN;
  863. else
  864. goto again;
  865. }
  866. if (wait) {
  867. ret = ocfs2_wait_for_mask(&mw);
  868. if (ret == 0)
  869. goto again;
  870. mlog_errno(ret);
  871. }
  872. mlog_exit(ret);
  873. return ret;
  874. }
  875. static void ocfs2_cluster_unlock(struct ocfs2_super *osb,
  876. struct ocfs2_lock_res *lockres,
  877. int level)
  878. {
  879. unsigned long flags;
  880. mlog_entry_void();
  881. spin_lock_irqsave(&lockres->l_lock, flags);
  882. ocfs2_dec_holders(lockres, level);
  883. ocfs2_vote_on_unlock(osb, lockres);
  884. spin_unlock_irqrestore(&lockres->l_lock, flags);
  885. mlog_exit_void();
  886. }
  887. int ocfs2_create_new_lock(struct ocfs2_super *osb,
  888. struct ocfs2_lock_res *lockres,
  889. int ex,
  890. int local)
  891. {
  892. int level = ex ? LKM_EXMODE : LKM_PRMODE;
  893. unsigned long flags;
  894. int lkm_flags = local ? LKM_LOCAL : 0;
  895. spin_lock_irqsave(&lockres->l_lock, flags);
  896. BUG_ON(lockres->l_flags & OCFS2_LOCK_ATTACHED);
  897. lockres_or_flags(lockres, OCFS2_LOCK_LOCAL);
  898. spin_unlock_irqrestore(&lockres->l_lock, flags);
  899. return ocfs2_lock_create(osb, lockres, level, lkm_flags);
  900. }
  901. /* Grants us an EX lock on the data and metadata resources, skipping
  902. * the normal cluster directory lookup. Use this ONLY on newly created
  903. * inodes which other nodes can't possibly see, and which haven't been
  904. * hashed in the inode hash yet. This can give us a good performance
  905. * increase as it'll skip the network broadcast normally associated
  906. * with creating a new lock resource. */
  907. int ocfs2_create_new_inode_locks(struct inode *inode)
  908. {
  909. int ret;
  910. struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
  911. BUG_ON(!inode);
  912. BUG_ON(!ocfs2_inode_is_new(inode));
  913. mlog_entry_void();
  914. mlog(0, "Inode %llu\n", (unsigned long long)OCFS2_I(inode)->ip_blkno);
  915. /* NOTE: That we don't increment any of the holder counts, nor
  916. * do we add anything to a journal handle. Since this is
  917. * supposed to be a new inode which the cluster doesn't know
  918. * about yet, there is no need to. As far as the LVB handling
  919. * is concerned, this is basically like acquiring an EX lock
  920. * on a resource which has an invalid one -- we'll set it
  921. * valid when we release the EX. */
  922. ret = ocfs2_create_new_lock(osb, &OCFS2_I(inode)->ip_rw_lockres, 1, 1);
  923. if (ret) {
  924. mlog_errno(ret);
  925. goto bail;
  926. }
  927. /*
  928. * We don't want to use LKM_LOCAL on a meta data lock as they
  929. * don't use a generation in their lock names.
  930. */
  931. ret = ocfs2_create_new_lock(osb, &OCFS2_I(inode)->ip_meta_lockres, 1, 0);
  932. if (ret) {
  933. mlog_errno(ret);
  934. goto bail;
  935. }
  936. ret = ocfs2_create_new_lock(osb, &OCFS2_I(inode)->ip_data_lockres, 1, 1);
  937. if (ret) {
  938. mlog_errno(ret);
  939. goto bail;
  940. }
  941. bail:
  942. mlog_exit(ret);
  943. return ret;
  944. }
  945. int ocfs2_rw_lock(struct inode *inode, int write)
  946. {
  947. int status, level;
  948. struct ocfs2_lock_res *lockres;
  949. BUG_ON(!inode);
  950. mlog_entry_void();
  951. mlog(0, "inode %llu take %s RW lock\n",
  952. (unsigned long long)OCFS2_I(inode)->ip_blkno,
  953. write ? "EXMODE" : "PRMODE");
  954. lockres = &OCFS2_I(inode)->ip_rw_lockres;
  955. level = write ? LKM_EXMODE : LKM_PRMODE;
  956. status = ocfs2_cluster_lock(OCFS2_SB(inode->i_sb), lockres, level, 0,
  957. 0);
  958. if (status < 0)
  959. mlog_errno(status);
  960. mlog_exit(status);
  961. return status;
  962. }
  963. void ocfs2_rw_unlock(struct inode *inode, int write)
  964. {
  965. int level = write ? LKM_EXMODE : LKM_PRMODE;
  966. struct ocfs2_lock_res *lockres = &OCFS2_I(inode)->ip_rw_lockres;
  967. mlog_entry_void();
  968. mlog(0, "inode %llu drop %s RW lock\n",
  969. (unsigned long long)OCFS2_I(inode)->ip_blkno,
  970. write ? "EXMODE" : "PRMODE");
  971. ocfs2_cluster_unlock(OCFS2_SB(inode->i_sb), lockres, level);
  972. mlog_exit_void();
  973. }
  974. int ocfs2_data_lock_full(struct inode *inode,
  975. int write,
  976. int arg_flags)
  977. {
  978. int status = 0, level;
  979. struct ocfs2_lock_res *lockres;
  980. BUG_ON(!inode);
  981. mlog_entry_void();
  982. mlog(0, "inode %llu take %s DATA lock\n",
  983. (unsigned long long)OCFS2_I(inode)->ip_blkno,
  984. write ? "EXMODE" : "PRMODE");
  985. /* We'll allow faking a readonly data lock for
  986. * rodevices. */
  987. if (ocfs2_is_hard_readonly(OCFS2_SB(inode->i_sb))) {
  988. if (write) {
  989. status = -EROFS;
  990. mlog_errno(status);
  991. }
  992. goto out;
  993. }
  994. lockres = &OCFS2_I(inode)->ip_data_lockres;
  995. level = write ? LKM_EXMODE : LKM_PRMODE;
  996. status = ocfs2_cluster_lock(OCFS2_SB(inode->i_sb), lockres, level,
  997. 0, arg_flags);
  998. if (status < 0 && status != -EAGAIN)
  999. mlog_errno(status);
  1000. out:
  1001. mlog_exit(status);
  1002. return status;
  1003. }
  1004. /* see ocfs2_meta_lock_with_page() */
  1005. int ocfs2_data_lock_with_page(struct inode *inode,
  1006. int write,
  1007. struct page *page)
  1008. {
  1009. int ret;
  1010. ret = ocfs2_data_lock_full(inode, write, OCFS2_LOCK_NONBLOCK);
  1011. if (ret == -EAGAIN) {
  1012. unlock_page(page);
  1013. if (ocfs2_data_lock(inode, write) == 0)
  1014. ocfs2_data_unlock(inode, write);
  1015. ret = AOP_TRUNCATED_PAGE;
  1016. }
  1017. return ret;
  1018. }
  1019. static void ocfs2_vote_on_unlock(struct ocfs2_super *osb,
  1020. struct ocfs2_lock_res *lockres)
  1021. {
  1022. int kick = 0;
  1023. mlog_entry_void();
  1024. /* If we know that another node is waiting on our lock, kick
  1025. * the vote thread * pre-emptively when we reach a release
  1026. * condition. */
  1027. if (lockres->l_flags & OCFS2_LOCK_BLOCKED) {
  1028. switch(lockres->l_blocking) {
  1029. case LKM_EXMODE:
  1030. if (!lockres->l_ex_holders && !lockres->l_ro_holders)
  1031. kick = 1;
  1032. break;
  1033. case LKM_PRMODE:
  1034. if (!lockres->l_ex_holders)
  1035. kick = 1;
  1036. break;
  1037. default:
  1038. BUG();
  1039. }
  1040. }
  1041. if (kick)
  1042. ocfs2_kick_vote_thread(osb);
  1043. mlog_exit_void();
  1044. }
  1045. void ocfs2_data_unlock(struct inode *inode,
  1046. int write)
  1047. {
  1048. int level = write ? LKM_EXMODE : LKM_PRMODE;
  1049. struct ocfs2_lock_res *lockres = &OCFS2_I(inode)->ip_data_lockres;
  1050. mlog_entry_void();
  1051. mlog(0, "inode %llu drop %s DATA lock\n",
  1052. (unsigned long long)OCFS2_I(inode)->ip_blkno,
  1053. write ? "EXMODE" : "PRMODE");
  1054. if (!ocfs2_is_hard_readonly(OCFS2_SB(inode->i_sb)))
  1055. ocfs2_cluster_unlock(OCFS2_SB(inode->i_sb), lockres, level);
  1056. mlog_exit_void();
  1057. }
  1058. #define OCFS2_SEC_BITS 34
  1059. #define OCFS2_SEC_SHIFT (64 - 34)
  1060. #define OCFS2_NSEC_MASK ((1ULL << OCFS2_SEC_SHIFT) - 1)
  1061. /* LVB only has room for 64 bits of time here so we pack it for
  1062. * now. */
  1063. static u64 ocfs2_pack_timespec(struct timespec *spec)
  1064. {
  1065. u64 res;
  1066. u64 sec = spec->tv_sec;
  1067. u32 nsec = spec->tv_nsec;
  1068. res = (sec << OCFS2_SEC_SHIFT) | (nsec & OCFS2_NSEC_MASK);
  1069. return res;
  1070. }
  1071. /* Call this with the lockres locked. I am reasonably sure we don't
  1072. * need ip_lock in this function as anyone who would be changing those
  1073. * values is supposed to be blocked in ocfs2_meta_lock right now. */
  1074. static void __ocfs2_stuff_meta_lvb(struct inode *inode)
  1075. {
  1076. struct ocfs2_inode_info *oi = OCFS2_I(inode);
  1077. struct ocfs2_lock_res *lockres = &oi->ip_meta_lockres;
  1078. struct ocfs2_meta_lvb *lvb;
  1079. mlog_entry_void();
  1080. lvb = (struct ocfs2_meta_lvb *) lockres->l_lksb.lvb;
  1081. /*
  1082. * Invalidate the LVB of a deleted inode - this way other
  1083. * nodes are forced to go to disk and discover the new inode
  1084. * status.
  1085. */
  1086. if (oi->ip_flags & OCFS2_INODE_DELETED) {
  1087. lvb->lvb_version = 0;
  1088. goto out;
  1089. }
  1090. lvb->lvb_version = OCFS2_LVB_VERSION;
  1091. lvb->lvb_isize = cpu_to_be64(i_size_read(inode));
  1092. lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
  1093. lvb->lvb_iuid = cpu_to_be32(inode->i_uid);
  1094. lvb->lvb_igid = cpu_to_be32(inode->i_gid);
  1095. lvb->lvb_imode = cpu_to_be16(inode->i_mode);
  1096. lvb->lvb_inlink = cpu_to_be16(inode->i_nlink);
  1097. lvb->lvb_iatime_packed =
  1098. cpu_to_be64(ocfs2_pack_timespec(&inode->i_atime));
  1099. lvb->lvb_ictime_packed =
  1100. cpu_to_be64(ocfs2_pack_timespec(&inode->i_ctime));
  1101. lvb->lvb_imtime_packed =
  1102. cpu_to_be64(ocfs2_pack_timespec(&inode->i_mtime));
  1103. lvb->lvb_iattr = cpu_to_be32(oi->ip_attr);
  1104. lvb->lvb_igeneration = cpu_to_be32(inode->i_generation);
  1105. out:
  1106. mlog_meta_lvb(0, lockres);
  1107. mlog_exit_void();
  1108. }
  1109. static void ocfs2_unpack_timespec(struct timespec *spec,
  1110. u64 packed_time)
  1111. {
  1112. spec->tv_sec = packed_time >> OCFS2_SEC_SHIFT;
  1113. spec->tv_nsec = packed_time & OCFS2_NSEC_MASK;
  1114. }
  1115. static void ocfs2_refresh_inode_from_lvb(struct inode *inode)
  1116. {
  1117. struct ocfs2_inode_info *oi = OCFS2_I(inode);
  1118. struct ocfs2_lock_res *lockres = &oi->ip_meta_lockres;
  1119. struct ocfs2_meta_lvb *lvb;
  1120. mlog_entry_void();
  1121. mlog_meta_lvb(0, lockres);
  1122. lvb = (struct ocfs2_meta_lvb *) lockres->l_lksb.lvb;
  1123. /* We're safe here without the lockres lock... */
  1124. spin_lock(&oi->ip_lock);
  1125. oi->ip_clusters = be32_to_cpu(lvb->lvb_iclusters);
  1126. i_size_write(inode, be64_to_cpu(lvb->lvb_isize));
  1127. oi->ip_attr = be32_to_cpu(lvb->lvb_iattr);
  1128. ocfs2_set_inode_flags(inode);
  1129. /* fast-symlinks are a special case */
  1130. if (S_ISLNK(inode->i_mode) && !oi->ip_clusters)
  1131. inode->i_blocks = 0;
  1132. else
  1133. inode->i_blocks =
  1134. ocfs2_align_bytes_to_sectors(i_size_read(inode));
  1135. inode->i_uid = be32_to_cpu(lvb->lvb_iuid);
  1136. inode->i_gid = be32_to_cpu(lvb->lvb_igid);
  1137. inode->i_mode = be16_to_cpu(lvb->lvb_imode);
  1138. inode->i_nlink = be16_to_cpu(lvb->lvb_inlink);
  1139. ocfs2_unpack_timespec(&inode->i_atime,
  1140. be64_to_cpu(lvb->lvb_iatime_packed));
  1141. ocfs2_unpack_timespec(&inode->i_mtime,
  1142. be64_to_cpu(lvb->lvb_imtime_packed));
  1143. ocfs2_unpack_timespec(&inode->i_ctime,
  1144. be64_to_cpu(lvb->lvb_ictime_packed));
  1145. spin_unlock(&oi->ip_lock);
  1146. mlog_exit_void();
  1147. }
  1148. static inline int ocfs2_meta_lvb_is_trustable(struct inode *inode,
  1149. struct ocfs2_lock_res *lockres)
  1150. {
  1151. struct ocfs2_meta_lvb *lvb = (struct ocfs2_meta_lvb *) lockres->l_lksb.lvb;
  1152. if (lvb->lvb_version == OCFS2_LVB_VERSION
  1153. && be32_to_cpu(lvb->lvb_igeneration) == inode->i_generation)
  1154. return 1;
  1155. return 0;
  1156. }
  1157. /* Determine whether a lock resource needs to be refreshed, and
  1158. * arbitrate who gets to refresh it.
  1159. *
  1160. * 0 means no refresh needed.
  1161. *
  1162. * > 0 means you need to refresh this and you MUST call
  1163. * ocfs2_complete_lock_res_refresh afterwards. */
  1164. static int ocfs2_should_refresh_lock_res(struct ocfs2_lock_res *lockres)
  1165. {
  1166. unsigned long flags;
  1167. int status = 0;
  1168. mlog_entry_void();
  1169. refresh_check:
  1170. spin_lock_irqsave(&lockres->l_lock, flags);
  1171. if (!(lockres->l_flags & OCFS2_LOCK_NEEDS_REFRESH)) {
  1172. spin_unlock_irqrestore(&lockres->l_lock, flags);
  1173. goto bail;
  1174. }
  1175. if (lockres->l_flags & OCFS2_LOCK_REFRESHING) {
  1176. spin_unlock_irqrestore(&lockres->l_lock, flags);
  1177. ocfs2_wait_on_refreshing_lock(lockres);
  1178. goto refresh_check;
  1179. }
  1180. /* Ok, I'll be the one to refresh this lock. */
  1181. lockres_or_flags(lockres, OCFS2_LOCK_REFRESHING);
  1182. spin_unlock_irqrestore(&lockres->l_lock, flags);
  1183. status = 1;
  1184. bail:
  1185. mlog_exit(status);
  1186. return status;
  1187. }
  1188. /* If status is non zero, I'll mark it as not being in refresh
  1189. * anymroe, but i won't clear the needs refresh flag. */
  1190. static inline void ocfs2_complete_lock_res_refresh(struct ocfs2_lock_res *lockres,
  1191. int status)
  1192. {
  1193. unsigned long flags;
  1194. mlog_entry_void();
  1195. spin_lock_irqsave(&lockres->l_lock, flags);
  1196. lockres_clear_flags(lockres, OCFS2_LOCK_REFRESHING);
  1197. if (!status)
  1198. lockres_clear_flags(lockres, OCFS2_LOCK_NEEDS_REFRESH);
  1199. spin_unlock_irqrestore(&lockres->l_lock, flags);
  1200. wake_up(&lockres->l_event);
  1201. mlog_exit_void();
  1202. }
  1203. /* may or may not return a bh if it went to disk. */
  1204. static int ocfs2_meta_lock_update(struct inode *inode,
  1205. struct buffer_head **bh)
  1206. {
  1207. int status = 0;
  1208. struct ocfs2_inode_info *oi = OCFS2_I(inode);
  1209. struct ocfs2_lock_res *lockres;
  1210. struct ocfs2_dinode *fe;
  1211. mlog_entry_void();
  1212. spin_lock(&oi->ip_lock);
  1213. if (oi->ip_flags & OCFS2_INODE_DELETED) {
  1214. mlog(0, "Orphaned inode %llu was deleted while we "
  1215. "were waiting on a lock. ip_flags = 0x%x\n",
  1216. (unsigned long long)oi->ip_blkno, oi->ip_flags);
  1217. spin_unlock(&oi->ip_lock);
  1218. status = -ENOENT;
  1219. goto bail;
  1220. }
  1221. spin_unlock(&oi->ip_lock);
  1222. lockres = &oi->ip_meta_lockres;
  1223. if (!ocfs2_should_refresh_lock_res(lockres))
  1224. goto bail;
  1225. /* This will discard any caching information we might have had
  1226. * for the inode metadata. */
  1227. ocfs2_metadata_cache_purge(inode);
  1228. /* will do nothing for inode types that don't use the extent
  1229. * map (directories, bitmap files, etc) */
  1230. ocfs2_extent_map_trunc(inode, 0);
  1231. if (ocfs2_meta_lvb_is_trustable(inode, lockres)) {
  1232. mlog(0, "Trusting LVB on inode %llu\n",
  1233. (unsigned long long)oi->ip_blkno);
  1234. ocfs2_refresh_inode_from_lvb(inode);
  1235. } else {
  1236. /* Boo, we have to go to disk. */
  1237. /* read bh, cast, ocfs2_refresh_inode */
  1238. status = ocfs2_read_block(OCFS2_SB(inode->i_sb), oi->ip_blkno,
  1239. bh, OCFS2_BH_CACHED, inode);
  1240. if (status < 0) {
  1241. mlog_errno(status);
  1242. goto bail_refresh;
  1243. }
  1244. fe = (struct ocfs2_dinode *) (*bh)->b_data;
  1245. /* This is a good chance to make sure we're not
  1246. * locking an invalid object.
  1247. *
  1248. * We bug on a stale inode here because we checked
  1249. * above whether it was wiped from disk. The wiping
  1250. * node provides a guarantee that we receive that
  1251. * message and can mark the inode before dropping any
  1252. * locks associated with it. */
  1253. if (!OCFS2_IS_VALID_DINODE(fe)) {
  1254. OCFS2_RO_ON_INVALID_DINODE(inode->i_sb, fe);
  1255. status = -EIO;
  1256. goto bail_refresh;
  1257. }
  1258. mlog_bug_on_msg(inode->i_generation !=
  1259. le32_to_cpu(fe->i_generation),
  1260. "Invalid dinode %llu disk generation: %u "
  1261. "inode->i_generation: %u\n",
  1262. (unsigned long long)oi->ip_blkno,
  1263. le32_to_cpu(fe->i_generation),
  1264. inode->i_generation);
  1265. mlog_bug_on_msg(le64_to_cpu(fe->i_dtime) ||
  1266. !(fe->i_flags & cpu_to_le32(OCFS2_VALID_FL)),
  1267. "Stale dinode %llu dtime: %llu flags: 0x%x\n",
  1268. (unsigned long long)oi->ip_blkno,
  1269. (unsigned long long)le64_to_cpu(fe->i_dtime),
  1270. le32_to_cpu(fe->i_flags));
  1271. ocfs2_refresh_inode(inode, fe);
  1272. }
  1273. status = 0;
  1274. bail_refresh:
  1275. ocfs2_complete_lock_res_refresh(lockres, status);
  1276. bail:
  1277. mlog_exit(status);
  1278. return status;
  1279. }
  1280. static int ocfs2_assign_bh(struct inode *inode,
  1281. struct buffer_head **ret_bh,
  1282. struct buffer_head *passed_bh)
  1283. {
  1284. int status;
  1285. if (passed_bh) {
  1286. /* Ok, the update went to disk for us, use the
  1287. * returned bh. */
  1288. *ret_bh = passed_bh;
  1289. get_bh(*ret_bh);
  1290. return 0;
  1291. }
  1292. status = ocfs2_read_block(OCFS2_SB(inode->i_sb),
  1293. OCFS2_I(inode)->ip_blkno,
  1294. ret_bh,
  1295. OCFS2_BH_CACHED,
  1296. inode);
  1297. if (status < 0)
  1298. mlog_errno(status);
  1299. return status;
  1300. }
  1301. /*
  1302. * returns < 0 error if the callback will never be called, otherwise
  1303. * the result of the lock will be communicated via the callback.
  1304. */
  1305. int ocfs2_meta_lock_full(struct inode *inode,
  1306. struct ocfs2_journal_handle *handle,
  1307. struct buffer_head **ret_bh,
  1308. int ex,
  1309. int arg_flags)
  1310. {
  1311. int status, level, dlm_flags, acquired;
  1312. struct ocfs2_lock_res *lockres;
  1313. struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
  1314. struct buffer_head *local_bh = NULL;
  1315. BUG_ON(!inode);
  1316. mlog_entry_void();
  1317. mlog(0, "inode %llu, take %s META lock\n",
  1318. (unsigned long long)OCFS2_I(inode)->ip_blkno,
  1319. ex ? "EXMODE" : "PRMODE");
  1320. status = 0;
  1321. acquired = 0;
  1322. /* We'll allow faking a readonly metadata lock for
  1323. * rodevices. */
  1324. if (ocfs2_is_hard_readonly(osb)) {
  1325. if (ex)
  1326. status = -EROFS;
  1327. goto bail;
  1328. }
  1329. if (!(arg_flags & OCFS2_META_LOCK_RECOVERY))
  1330. wait_event(osb->recovery_event,
  1331. ocfs2_node_map_is_empty(osb, &osb->recovery_map));
  1332. acquired = 0;
  1333. lockres = &OCFS2_I(inode)->ip_meta_lockres;
  1334. level = ex ? LKM_EXMODE : LKM_PRMODE;
  1335. dlm_flags = 0;
  1336. if (arg_flags & OCFS2_META_LOCK_NOQUEUE)
  1337. dlm_flags |= LKM_NOQUEUE;
  1338. status = ocfs2_cluster_lock(osb, lockres, level, dlm_flags, arg_flags);
  1339. if (status < 0) {
  1340. if (status != -EAGAIN && status != -EIOCBRETRY)
  1341. mlog_errno(status);
  1342. goto bail;
  1343. }
  1344. /* Notify the error cleanup path to drop the cluster lock. */
  1345. acquired = 1;
  1346. /* We wait twice because a node may have died while we were in
  1347. * the lower dlm layers. The second time though, we've
  1348. * committed to owning this lock so we don't allow signals to
  1349. * abort the operation. */
  1350. if (!(arg_flags & OCFS2_META_LOCK_RECOVERY))
  1351. wait_event(osb->recovery_event,
  1352. ocfs2_node_map_is_empty(osb, &osb->recovery_map));
  1353. /*
  1354. * We only see this flag if we're being called from
  1355. * ocfs2_read_locked_inode(). It means we're locking an inode
  1356. * which hasn't been populated yet, so clear the refresh flag
  1357. * and let the caller handle it.
  1358. */
  1359. if (inode->i_state & I_NEW) {
  1360. status = 0;
  1361. ocfs2_complete_lock_res_refresh(lockres, 0);
  1362. goto bail;
  1363. }
  1364. /* This is fun. The caller may want a bh back, or it may
  1365. * not. ocfs2_meta_lock_update definitely wants one in, but
  1366. * may or may not read one, depending on what's in the
  1367. * LVB. The result of all of this is that we've *only* gone to
  1368. * disk if we have to, so the complexity is worthwhile. */
  1369. status = ocfs2_meta_lock_update(inode, &local_bh);
  1370. if (status < 0) {
  1371. if (status != -ENOENT)
  1372. mlog_errno(status);
  1373. goto bail;
  1374. }
  1375. if (ret_bh) {
  1376. status = ocfs2_assign_bh(inode, ret_bh, local_bh);
  1377. if (status < 0) {
  1378. mlog_errno(status);
  1379. goto bail;
  1380. }
  1381. }
  1382. if (handle) {
  1383. status = ocfs2_handle_add_lock(handle, inode);
  1384. if (status < 0)
  1385. mlog_errno(status);
  1386. }
  1387. bail:
  1388. if (status < 0) {
  1389. if (ret_bh && (*ret_bh)) {
  1390. brelse(*ret_bh);
  1391. *ret_bh = NULL;
  1392. }
  1393. if (acquired)
  1394. ocfs2_meta_unlock(inode, ex);
  1395. }
  1396. if (local_bh)
  1397. brelse(local_bh);
  1398. mlog_exit(status);
  1399. return status;
  1400. }
  1401. /*
  1402. * This is working around a lock inversion between tasks acquiring DLM locks
  1403. * while holding a page lock and the vote thread which blocks dlm lock acquiry
  1404. * while acquiring page locks.
  1405. *
  1406. * ** These _with_page variantes are only intended to be called from aop
  1407. * methods that hold page locks and return a very specific *positive* error
  1408. * code that aop methods pass up to the VFS -- test for errors with != 0. **
  1409. *
  1410. * The DLM is called such that it returns -EAGAIN if it would have blocked
  1411. * waiting for the vote thread. In that case we unlock our page so the vote
  1412. * thread can make progress. Once we've done this we have to return
  1413. * AOP_TRUNCATED_PAGE so the aop method that called us can bubble that back up
  1414. * into the VFS who will then immediately retry the aop call.
  1415. *
  1416. * We do a blocking lock and immediate unlock before returning, though, so that
  1417. * the lock has a great chance of being cached on this node by the time the VFS
  1418. * calls back to retry the aop. This has a potential to livelock as nodes
  1419. * ping locks back and forth, but that's a risk we're willing to take to avoid
  1420. * the lock inversion simply.
  1421. */
  1422. int ocfs2_meta_lock_with_page(struct inode *inode,
  1423. struct ocfs2_journal_handle *handle,
  1424. struct buffer_head **ret_bh,
  1425. int ex,
  1426. struct page *page)
  1427. {
  1428. int ret;
  1429. ret = ocfs2_meta_lock_full(inode, handle, ret_bh, ex,
  1430. OCFS2_LOCK_NONBLOCK);
  1431. if (ret == -EAGAIN) {
  1432. unlock_page(page);
  1433. if (ocfs2_meta_lock(inode, handle, ret_bh, ex) == 0)
  1434. ocfs2_meta_unlock(inode, ex);
  1435. ret = AOP_TRUNCATED_PAGE;
  1436. }
  1437. return ret;
  1438. }
  1439. void ocfs2_meta_unlock(struct inode *inode,
  1440. int ex)
  1441. {
  1442. int level = ex ? LKM_EXMODE : LKM_PRMODE;
  1443. struct ocfs2_lock_res *lockres = &OCFS2_I(inode)->ip_meta_lockres;
  1444. mlog_entry_void();
  1445. mlog(0, "inode %llu drop %s META lock\n",
  1446. (unsigned long long)OCFS2_I(inode)->ip_blkno,
  1447. ex ? "EXMODE" : "PRMODE");
  1448. if (!ocfs2_is_hard_readonly(OCFS2_SB(inode->i_sb)))
  1449. ocfs2_cluster_unlock(OCFS2_SB(inode->i_sb), lockres, level);
  1450. mlog_exit_void();
  1451. }
  1452. int ocfs2_super_lock(struct ocfs2_super *osb,
  1453. int ex)
  1454. {
  1455. int status;
  1456. int level = ex ? LKM_EXMODE : LKM_PRMODE;
  1457. struct ocfs2_lock_res *lockres = &osb->osb_super_lockres;
  1458. struct buffer_head *bh;
  1459. struct ocfs2_slot_info *si = osb->slot_info;
  1460. mlog_entry_void();
  1461. if (ocfs2_is_hard_readonly(osb))
  1462. return -EROFS;
  1463. status = ocfs2_cluster_lock(osb, lockres, level, 0, 0);
  1464. if (status < 0) {
  1465. mlog_errno(status);
  1466. goto bail;
  1467. }
  1468. /* The super block lock path is really in the best position to
  1469. * know when resources covered by the lock need to be
  1470. * refreshed, so we do it here. Of course, making sense of
  1471. * everything is up to the caller :) */
  1472. status = ocfs2_should_refresh_lock_res(lockres);
  1473. if (status < 0) {
  1474. mlog_errno(status);
  1475. goto bail;
  1476. }
  1477. if (status) {
  1478. bh = si->si_bh;
  1479. status = ocfs2_read_block(osb, bh->b_blocknr, &bh, 0,
  1480. si->si_inode);
  1481. if (status == 0)
  1482. ocfs2_update_slot_info(si);
  1483. ocfs2_complete_lock_res_refresh(lockres, status);
  1484. if (status < 0)
  1485. mlog_errno(status);
  1486. }
  1487. bail:
  1488. mlog_exit(status);
  1489. return status;
  1490. }
  1491. void ocfs2_super_unlock(struct ocfs2_super *osb,
  1492. int ex)
  1493. {
  1494. int level = ex ? LKM_EXMODE : LKM_PRMODE;
  1495. struct ocfs2_lock_res *lockres = &osb->osb_super_lockres;
  1496. ocfs2_cluster_unlock(osb, lockres, level);
  1497. }
  1498. int ocfs2_rename_lock(struct ocfs2_super *osb)
  1499. {
  1500. int status;
  1501. struct ocfs2_lock_res *lockres = &osb->osb_rename_lockres;
  1502. if (ocfs2_is_hard_readonly(osb))
  1503. return -EROFS;
  1504. status = ocfs2_cluster_lock(osb, lockres, LKM_EXMODE, 0, 0);
  1505. if (status < 0)
  1506. mlog_errno(status);
  1507. return status;
  1508. }
  1509. void ocfs2_rename_unlock(struct ocfs2_super *osb)
  1510. {
  1511. struct ocfs2_lock_res *lockres = &osb->osb_rename_lockres;
  1512. ocfs2_cluster_unlock(osb, lockres, LKM_EXMODE);
  1513. }
  1514. int ocfs2_dentry_lock(struct dentry *dentry, int ex)
  1515. {
  1516. int ret;
  1517. int level = ex ? LKM_EXMODE : LKM_PRMODE;
  1518. struct ocfs2_dentry_lock *dl = dentry->d_fsdata;
  1519. struct ocfs2_super *osb = OCFS2_SB(dentry->d_sb);
  1520. BUG_ON(!dl);
  1521. if (ocfs2_is_hard_readonly(osb))
  1522. return -EROFS;
  1523. ret = ocfs2_cluster_lock(osb, &dl->dl_lockres, level, 0, 0);
  1524. if (ret < 0)
  1525. mlog_errno(ret);
  1526. return ret;
  1527. }
  1528. void ocfs2_dentry_unlock(struct dentry *dentry, int ex)
  1529. {
  1530. int level = ex ? LKM_EXMODE : LKM_PRMODE;
  1531. struct ocfs2_dentry_lock *dl = dentry->d_fsdata;
  1532. struct ocfs2_super *osb = OCFS2_SB(dentry->d_sb);
  1533. ocfs2_cluster_unlock(osb, &dl->dl_lockres, level);
  1534. }
  1535. /* Reference counting of the dlm debug structure. We want this because
  1536. * open references on the debug inodes can live on after a mount, so
  1537. * we can't rely on the ocfs2_super to always exist. */
  1538. static void ocfs2_dlm_debug_free(struct kref *kref)
  1539. {
  1540. struct ocfs2_dlm_debug *dlm_debug;
  1541. dlm_debug = container_of(kref, struct ocfs2_dlm_debug, d_refcnt);
  1542. kfree(dlm_debug);
  1543. }
  1544. void ocfs2_put_dlm_debug(struct ocfs2_dlm_debug *dlm_debug)
  1545. {
  1546. if (dlm_debug)
  1547. kref_put(&dlm_debug->d_refcnt, ocfs2_dlm_debug_free);
  1548. }
  1549. static void ocfs2_get_dlm_debug(struct ocfs2_dlm_debug *debug)
  1550. {
  1551. kref_get(&debug->d_refcnt);
  1552. }
  1553. struct ocfs2_dlm_debug *ocfs2_new_dlm_debug(void)
  1554. {
  1555. struct ocfs2_dlm_debug *dlm_debug;
  1556. dlm_debug = kmalloc(sizeof(struct ocfs2_dlm_debug), GFP_KERNEL);
  1557. if (!dlm_debug) {
  1558. mlog_errno(-ENOMEM);
  1559. goto out;
  1560. }
  1561. kref_init(&dlm_debug->d_refcnt);
  1562. INIT_LIST_HEAD(&dlm_debug->d_lockres_tracking);
  1563. dlm_debug->d_locking_state = NULL;
  1564. out:
  1565. return dlm_debug;
  1566. }
  1567. /* Access to this is arbitrated for us via seq_file->sem. */
  1568. struct ocfs2_dlm_seq_priv {
  1569. struct ocfs2_dlm_debug *p_dlm_debug;
  1570. struct ocfs2_lock_res p_iter_res;
  1571. struct ocfs2_lock_res p_tmp_res;
  1572. };
  1573. static struct ocfs2_lock_res *ocfs2_dlm_next_res(struct ocfs2_lock_res *start,
  1574. struct ocfs2_dlm_seq_priv *priv)
  1575. {
  1576. struct ocfs2_lock_res *iter, *ret = NULL;
  1577. struct ocfs2_dlm_debug *dlm_debug = priv->p_dlm_debug;
  1578. assert_spin_locked(&ocfs2_dlm_tracking_lock);
  1579. list_for_each_entry(iter, &start->l_debug_list, l_debug_list) {
  1580. /* discover the head of the list */
  1581. if (&iter->l_debug_list == &dlm_debug->d_lockres_tracking) {
  1582. mlog(0, "End of list found, %p\n", ret);
  1583. break;
  1584. }
  1585. /* We track our "dummy" iteration lockres' by a NULL
  1586. * l_ops field. */
  1587. if (iter->l_ops != NULL) {
  1588. ret = iter;
  1589. break;
  1590. }
  1591. }
  1592. return ret;
  1593. }
  1594. static void *ocfs2_dlm_seq_start(struct seq_file *m, loff_t *pos)
  1595. {
  1596. struct ocfs2_dlm_seq_priv *priv = m->private;
  1597. struct ocfs2_lock_res *iter;
  1598. spin_lock(&ocfs2_dlm_tracking_lock);
  1599. iter = ocfs2_dlm_next_res(&priv->p_iter_res, priv);
  1600. if (iter) {
  1601. /* Since lockres' have the lifetime of their container
  1602. * (which can be inodes, ocfs2_supers, etc) we want to
  1603. * copy this out to a temporary lockres while still
  1604. * under the spinlock. Obviously after this we can't
  1605. * trust any pointers on the copy returned, but that's
  1606. * ok as the information we want isn't typically held
  1607. * in them. */
  1608. priv->p_tmp_res = *iter;
  1609. iter = &priv->p_tmp_res;
  1610. }
  1611. spin_unlock(&ocfs2_dlm_tracking_lock);
  1612. return iter;
  1613. }
  1614. static void ocfs2_dlm_seq_stop(struct seq_file *m, void *v)
  1615. {
  1616. }
  1617. static void *ocfs2_dlm_seq_next(struct seq_file *m, void *v, loff_t *pos)
  1618. {
  1619. struct ocfs2_dlm_seq_priv *priv = m->private;
  1620. struct ocfs2_lock_res *iter = v;
  1621. struct ocfs2_lock_res *dummy = &priv->p_iter_res;
  1622. spin_lock(&ocfs2_dlm_tracking_lock);
  1623. iter = ocfs2_dlm_next_res(iter, priv);
  1624. list_del_init(&dummy->l_debug_list);
  1625. if (iter) {
  1626. list_add(&dummy->l_debug_list, &iter->l_debug_list);
  1627. priv->p_tmp_res = *iter;
  1628. iter = &priv->p_tmp_res;
  1629. }
  1630. spin_unlock(&ocfs2_dlm_tracking_lock);
  1631. return iter;
  1632. }
  1633. /* So that debugfs.ocfs2 can determine which format is being used */
  1634. #define OCFS2_DLM_DEBUG_STR_VERSION 1
  1635. static int ocfs2_dlm_seq_show(struct seq_file *m, void *v)
  1636. {
  1637. int i;
  1638. char *lvb;
  1639. struct ocfs2_lock_res *lockres = v;
  1640. if (!lockres)
  1641. return -EINVAL;
  1642. seq_printf(m, "0x%x\t", OCFS2_DLM_DEBUG_STR_VERSION);
  1643. if (lockres->l_type == OCFS2_LOCK_TYPE_DENTRY)
  1644. seq_printf(m, "%.*s%08x\t", OCFS2_DENTRY_LOCK_INO_START - 1,
  1645. lockres->l_name,
  1646. (unsigned int)ocfs2_get_dentry_lock_ino(lockres));
  1647. else
  1648. seq_printf(m, "%.*s\t", OCFS2_LOCK_ID_MAX_LEN, lockres->l_name);
  1649. seq_printf(m, "%d\t"
  1650. "0x%lx\t"
  1651. "0x%x\t"
  1652. "0x%x\t"
  1653. "%u\t"
  1654. "%u\t"
  1655. "%d\t"
  1656. "%d\t",
  1657. lockres->l_level,
  1658. lockres->l_flags,
  1659. lockres->l_action,
  1660. lockres->l_unlock_action,
  1661. lockres->l_ro_holders,
  1662. lockres->l_ex_holders,
  1663. lockres->l_requested,
  1664. lockres->l_blocking);
  1665. /* Dump the raw LVB */
  1666. lvb = lockres->l_lksb.lvb;
  1667. for(i = 0; i < DLM_LVB_LEN; i++)
  1668. seq_printf(m, "0x%x\t", lvb[i]);
  1669. /* End the line */
  1670. seq_printf(m, "\n");
  1671. return 0;
  1672. }
  1673. static struct seq_operations ocfs2_dlm_seq_ops = {
  1674. .start = ocfs2_dlm_seq_start,
  1675. .stop = ocfs2_dlm_seq_stop,
  1676. .next = ocfs2_dlm_seq_next,
  1677. .show = ocfs2_dlm_seq_show,
  1678. };
  1679. static int ocfs2_dlm_debug_release(struct inode *inode, struct file *file)
  1680. {
  1681. struct seq_file *seq = (struct seq_file *) file->private_data;
  1682. struct ocfs2_dlm_seq_priv *priv = seq->private;
  1683. struct ocfs2_lock_res *res = &priv->p_iter_res;
  1684. ocfs2_remove_lockres_tracking(res);
  1685. ocfs2_put_dlm_debug(priv->p_dlm_debug);
  1686. return seq_release_private(inode, file);
  1687. }
  1688. static int ocfs2_dlm_debug_open(struct inode *inode, struct file *file)
  1689. {
  1690. int ret;
  1691. struct ocfs2_dlm_seq_priv *priv;
  1692. struct seq_file *seq;
  1693. struct ocfs2_super *osb;
  1694. priv = kzalloc(sizeof(struct ocfs2_dlm_seq_priv), GFP_KERNEL);
  1695. if (!priv) {
  1696. ret = -ENOMEM;
  1697. mlog_errno(ret);
  1698. goto out;
  1699. }
  1700. osb = inode->i_private;
  1701. ocfs2_get_dlm_debug(osb->osb_dlm_debug);
  1702. priv->p_dlm_debug = osb->osb_dlm_debug;
  1703. INIT_LIST_HEAD(&priv->p_iter_res.l_debug_list);
  1704. ret = seq_open(file, &ocfs2_dlm_seq_ops);
  1705. if (ret) {
  1706. kfree(priv);
  1707. mlog_errno(ret);
  1708. goto out;
  1709. }
  1710. seq = (struct seq_file *) file->private_data;
  1711. seq->private = priv;
  1712. ocfs2_add_lockres_tracking(&priv->p_iter_res,
  1713. priv->p_dlm_debug);
  1714. out:
  1715. return ret;
  1716. }
  1717. static const struct file_operations ocfs2_dlm_debug_fops = {
  1718. .open = ocfs2_dlm_debug_open,
  1719. .release = ocfs2_dlm_debug_release,
  1720. .read = seq_read,
  1721. .llseek = seq_lseek,
  1722. };
  1723. static int ocfs2_dlm_init_debug(struct ocfs2_super *osb)
  1724. {
  1725. int ret = 0;
  1726. struct ocfs2_dlm_debug *dlm_debug = osb->osb_dlm_debug;
  1727. dlm_debug->d_locking_state = debugfs_create_file("locking_state",
  1728. S_IFREG|S_IRUSR,
  1729. osb->osb_debug_root,
  1730. osb,
  1731. &ocfs2_dlm_debug_fops);
  1732. if (!dlm_debug->d_locking_state) {
  1733. ret = -EINVAL;
  1734. mlog(ML_ERROR,
  1735. "Unable to create locking state debugfs file.\n");
  1736. goto out;
  1737. }
  1738. ocfs2_get_dlm_debug(dlm_debug);
  1739. out:
  1740. return ret;
  1741. }
  1742. static void ocfs2_dlm_shutdown_debug(struct ocfs2_super *osb)
  1743. {
  1744. struct ocfs2_dlm_debug *dlm_debug = osb->osb_dlm_debug;
  1745. if (dlm_debug) {
  1746. debugfs_remove(dlm_debug->d_locking_state);
  1747. ocfs2_put_dlm_debug(dlm_debug);
  1748. }
  1749. }
  1750. int ocfs2_dlm_init(struct ocfs2_super *osb)
  1751. {
  1752. int status;
  1753. u32 dlm_key;
  1754. struct dlm_ctxt *dlm;
  1755. mlog_entry_void();
  1756. status = ocfs2_dlm_init_debug(osb);
  1757. if (status < 0) {
  1758. mlog_errno(status);
  1759. goto bail;
  1760. }
  1761. /* launch vote thread */
  1762. osb->vote_task = kthread_run(ocfs2_vote_thread, osb, "ocfs2vote");
  1763. if (IS_ERR(osb->vote_task)) {
  1764. status = PTR_ERR(osb->vote_task);
  1765. osb->vote_task = NULL;
  1766. mlog_errno(status);
  1767. goto bail;
  1768. }
  1769. /* used by the dlm code to make message headers unique, each
  1770. * node in this domain must agree on this. */
  1771. dlm_key = crc32_le(0, osb->uuid_str, strlen(osb->uuid_str));
  1772. /* for now, uuid == domain */
  1773. dlm = dlm_register_domain(osb->uuid_str, dlm_key);
  1774. if (IS_ERR(dlm)) {
  1775. status = PTR_ERR(dlm);
  1776. mlog_errno(status);
  1777. goto bail;
  1778. }
  1779. ocfs2_super_lock_res_init(&osb->osb_super_lockres, osb);
  1780. ocfs2_rename_lock_res_init(&osb->osb_rename_lockres, osb);
  1781. dlm_register_eviction_cb(dlm, &osb->osb_eviction_cb);
  1782. osb->dlm = dlm;
  1783. status = 0;
  1784. bail:
  1785. if (status < 0) {
  1786. ocfs2_dlm_shutdown_debug(osb);
  1787. if (osb->vote_task)
  1788. kthread_stop(osb->vote_task);
  1789. }
  1790. mlog_exit(status);
  1791. return status;
  1792. }
  1793. void ocfs2_dlm_shutdown(struct ocfs2_super *osb)
  1794. {
  1795. mlog_entry_void();
  1796. dlm_unregister_eviction_cb(&osb->osb_eviction_cb);
  1797. ocfs2_drop_osb_locks(osb);
  1798. if (osb->vote_task) {
  1799. kthread_stop(osb->vote_task);
  1800. osb->vote_task = NULL;
  1801. }
  1802. ocfs2_lock_res_free(&osb->osb_super_lockres);
  1803. ocfs2_lock_res_free(&osb->osb_rename_lockres);
  1804. dlm_unregister_domain(osb->dlm);
  1805. osb->dlm = NULL;
  1806. ocfs2_dlm_shutdown_debug(osb);
  1807. mlog_exit_void();
  1808. }
  1809. static void ocfs2_unlock_ast(void *opaque, enum dlm_status status)
  1810. {
  1811. struct ocfs2_lock_res *lockres = opaque;
  1812. unsigned long flags;
  1813. mlog_entry_void();
  1814. mlog(0, "UNLOCK AST called on lock %s, action = %d\n", lockres->l_name,
  1815. lockres->l_unlock_action);
  1816. spin_lock_irqsave(&lockres->l_lock, flags);
  1817. /* We tried to cancel a convert request, but it was already
  1818. * granted. All we want to do here is clear our unlock
  1819. * state. The wake_up call done at the bottom is redundant
  1820. * (ocfs2_prepare_cancel_convert doesn't sleep on this) but doesn't
  1821. * hurt anything anyway */
  1822. if (status == DLM_CANCELGRANT &&
  1823. lockres->l_unlock_action == OCFS2_UNLOCK_CANCEL_CONVERT) {
  1824. mlog(0, "Got cancelgrant for %s\n", lockres->l_name);
  1825. /* We don't clear the busy flag in this case as it
  1826. * should have been cleared by the ast which the dlm
  1827. * has called. */
  1828. goto complete_unlock;
  1829. }
  1830. if (status != DLM_NORMAL) {
  1831. mlog(ML_ERROR, "Dlm passes status %d for lock %s, "
  1832. "unlock_action %d\n", status, lockres->l_name,
  1833. lockres->l_unlock_action);
  1834. spin_unlock_irqrestore(&lockres->l_lock, flags);
  1835. return;
  1836. }
  1837. switch(lockres->l_unlock_action) {
  1838. case OCFS2_UNLOCK_CANCEL_CONVERT:
  1839. mlog(0, "Cancel convert success for %s\n", lockres->l_name);
  1840. lockres->l_action = OCFS2_AST_INVALID;
  1841. break;
  1842. case OCFS2_UNLOCK_DROP_LOCK:
  1843. lockres->l_level = LKM_IVMODE;
  1844. break;
  1845. default:
  1846. BUG();
  1847. }
  1848. lockres_clear_flags(lockres, OCFS2_LOCK_BUSY);
  1849. complete_unlock:
  1850. lockres->l_unlock_action = OCFS2_UNLOCK_INVALID;
  1851. spin_unlock_irqrestore(&lockres->l_lock, flags);
  1852. wake_up(&lockres->l_event);
  1853. mlog_exit_void();
  1854. }
  1855. static int ocfs2_drop_lock(struct ocfs2_super *osb,
  1856. struct ocfs2_lock_res *lockres)
  1857. {
  1858. enum dlm_status status;
  1859. unsigned long flags;
  1860. int lkm_flags = 0;
  1861. /* We didn't get anywhere near actually using this lockres. */
  1862. if (!(lockres->l_flags & OCFS2_LOCK_INITIALIZED))
  1863. goto out;
  1864. if (lockres->l_ops->flags & LOCK_TYPE_USES_LVB)
  1865. lkm_flags |= LKM_VALBLK;
  1866. spin_lock_irqsave(&lockres->l_lock, flags);
  1867. mlog_bug_on_msg(!(lockres->l_flags & OCFS2_LOCK_FREEING),
  1868. "lockres %s, flags 0x%lx\n",
  1869. lockres->l_name, lockres->l_flags);
  1870. while (lockres->l_flags & OCFS2_LOCK_BUSY) {
  1871. mlog(0, "waiting on busy lock \"%s\": flags = %lx, action = "
  1872. "%u, unlock_action = %u\n",
  1873. lockres->l_name, lockres->l_flags, lockres->l_action,
  1874. lockres->l_unlock_action);
  1875. spin_unlock_irqrestore(&lockres->l_lock, flags);
  1876. /* XXX: Today we just wait on any busy
  1877. * locks... Perhaps we need to cancel converts in the
  1878. * future? */
  1879. ocfs2_wait_on_busy_lock(lockres);
  1880. spin_lock_irqsave(&lockres->l_lock, flags);
  1881. }
  1882. if (lockres->l_ops->flags & LOCK_TYPE_USES_LVB) {
  1883. if (lockres->l_flags & OCFS2_LOCK_ATTACHED &&
  1884. lockres->l_level == LKM_EXMODE &&
  1885. !(lockres->l_flags & OCFS2_LOCK_NEEDS_REFRESH))
  1886. lockres->l_ops->set_lvb(lockres);
  1887. }
  1888. if (lockres->l_flags & OCFS2_LOCK_BUSY)
  1889. mlog(ML_ERROR, "destroying busy lock: \"%s\"\n",
  1890. lockres->l_name);
  1891. if (lockres->l_flags & OCFS2_LOCK_BLOCKED)
  1892. mlog(0, "destroying blocked lock: \"%s\"\n", lockres->l_name);
  1893. if (!(lockres->l_flags & OCFS2_LOCK_ATTACHED)) {
  1894. spin_unlock_irqrestore(&lockres->l_lock, flags);
  1895. goto out;
  1896. }
  1897. lockres_clear_flags(lockres, OCFS2_LOCK_ATTACHED);
  1898. /* make sure we never get here while waiting for an ast to
  1899. * fire. */
  1900. BUG_ON(lockres->l_action != OCFS2_AST_INVALID);
  1901. /* is this necessary? */
  1902. lockres_or_flags(lockres, OCFS2_LOCK_BUSY);
  1903. lockres->l_unlock_action = OCFS2_UNLOCK_DROP_LOCK;
  1904. spin_unlock_irqrestore(&lockres->l_lock, flags);
  1905. mlog(0, "lock %s\n", lockres->l_name);
  1906. status = dlmunlock(osb->dlm, &lockres->l_lksb, lkm_flags,
  1907. ocfs2_unlock_ast, lockres);
  1908. if (status != DLM_NORMAL) {
  1909. ocfs2_log_dlm_error("dlmunlock", status, lockres);
  1910. mlog(ML_ERROR, "lockres flags: %lu\n", lockres->l_flags);
  1911. dlm_print_one_lock(lockres->l_lksb.lockid);
  1912. BUG();
  1913. }
  1914. mlog(0, "lock %s, successfull return from dlmunlock\n",
  1915. lockres->l_name);
  1916. ocfs2_wait_on_busy_lock(lockres);
  1917. out:
  1918. mlog_exit(0);
  1919. return 0;
  1920. }
  1921. /* Mark the lockres as being dropped. It will no longer be
  1922. * queued if blocking, but we still may have to wait on it
  1923. * being dequeued from the vote thread before we can consider
  1924. * it safe to drop.
  1925. *
  1926. * You can *not* attempt to call cluster_lock on this lockres anymore. */
  1927. void ocfs2_mark_lockres_freeing(struct ocfs2_lock_res *lockres)
  1928. {
  1929. int status;
  1930. struct ocfs2_mask_waiter mw;
  1931. unsigned long flags;
  1932. ocfs2_init_mask_waiter(&mw);
  1933. spin_lock_irqsave(&lockres->l_lock, flags);
  1934. lockres->l_flags |= OCFS2_LOCK_FREEING;
  1935. while (lockres->l_flags & OCFS2_LOCK_QUEUED) {
  1936. lockres_add_mask_waiter(lockres, &mw, OCFS2_LOCK_QUEUED, 0);
  1937. spin_unlock_irqrestore(&lockres->l_lock, flags);
  1938. mlog(0, "Waiting on lockres %s\n", lockres->l_name);
  1939. status = ocfs2_wait_for_mask(&mw);
  1940. if (status)
  1941. mlog_errno(status);
  1942. spin_lock_irqsave(&lockres->l_lock, flags);
  1943. }
  1944. spin_unlock_irqrestore(&lockres->l_lock, flags);
  1945. }
  1946. void ocfs2_simple_drop_lockres(struct ocfs2_super *osb,
  1947. struct ocfs2_lock_res *lockres)
  1948. {
  1949. int ret;
  1950. ocfs2_mark_lockres_freeing(lockres);
  1951. ret = ocfs2_drop_lock(osb, lockres);
  1952. if (ret)
  1953. mlog_errno(ret);
  1954. }
  1955. static void ocfs2_drop_osb_locks(struct ocfs2_super *osb)
  1956. {
  1957. ocfs2_simple_drop_lockres(osb, &osb->osb_super_lockres);
  1958. ocfs2_simple_drop_lockres(osb, &osb->osb_rename_lockres);
  1959. }
  1960. int ocfs2_drop_inode_locks(struct inode *inode)
  1961. {
  1962. int status, err;
  1963. mlog_entry_void();
  1964. /* No need to call ocfs2_mark_lockres_freeing here -
  1965. * ocfs2_clear_inode has done it for us. */
  1966. err = ocfs2_drop_lock(OCFS2_SB(inode->i_sb),
  1967. &OCFS2_I(inode)->ip_data_lockres);
  1968. if (err < 0)
  1969. mlog_errno(err);
  1970. status = err;
  1971. err = ocfs2_drop_lock(OCFS2_SB(inode->i_sb),
  1972. &OCFS2_I(inode)->ip_meta_lockres);
  1973. if (err < 0)
  1974. mlog_errno(err);
  1975. if (err < 0 && !status)
  1976. status = err;
  1977. err = ocfs2_drop_lock(OCFS2_SB(inode->i_sb),
  1978. &OCFS2_I(inode)->ip_rw_lockres);
  1979. if (err < 0)
  1980. mlog_errno(err);
  1981. if (err < 0 && !status)
  1982. status = err;
  1983. mlog_exit(status);
  1984. return status;
  1985. }
  1986. static void ocfs2_prepare_downconvert(struct ocfs2_lock_res *lockres,
  1987. int new_level)
  1988. {
  1989. assert_spin_locked(&lockres->l_lock);
  1990. BUG_ON(lockres->l_blocking <= LKM_NLMODE);
  1991. if (lockres->l_level <= new_level) {
  1992. mlog(ML_ERROR, "lockres->l_level (%u) <= new_level (%u)\n",
  1993. lockres->l_level, new_level);
  1994. BUG();
  1995. }
  1996. mlog(0, "lock %s, new_level = %d, l_blocking = %d\n",
  1997. lockres->l_name, new_level, lockres->l_blocking);
  1998. lockres->l_action = OCFS2_AST_DOWNCONVERT;
  1999. lockres->l_requested = new_level;
  2000. lockres_or_flags(lockres, OCFS2_LOCK_BUSY);
  2001. }
  2002. static int ocfs2_downconvert_lock(struct ocfs2_super *osb,
  2003. struct ocfs2_lock_res *lockres,
  2004. int new_level,
  2005. int lvb)
  2006. {
  2007. int ret, dlm_flags = LKM_CONVERT;
  2008. enum dlm_status status;
  2009. mlog_entry_void();
  2010. if (lvb)
  2011. dlm_flags |= LKM_VALBLK;
  2012. status = dlmlock(osb->dlm,
  2013. new_level,
  2014. &lockres->l_lksb,
  2015. dlm_flags,
  2016. lockres->l_name,
  2017. OCFS2_LOCK_ID_MAX_LEN - 1,
  2018. ocfs2_locking_ast,
  2019. lockres,
  2020. ocfs2_blocking_ast);
  2021. if (status != DLM_NORMAL) {
  2022. ocfs2_log_dlm_error("dlmlock", status, lockres);
  2023. ret = -EINVAL;
  2024. ocfs2_recover_from_dlm_error(lockres, 1);
  2025. goto bail;
  2026. }
  2027. ret = 0;
  2028. bail:
  2029. mlog_exit(ret);
  2030. return ret;
  2031. }
  2032. /* returns 1 when the caller should unlock and call dlmunlock */
  2033. static int ocfs2_prepare_cancel_convert(struct ocfs2_super *osb,
  2034. struct ocfs2_lock_res *lockres)
  2035. {
  2036. assert_spin_locked(&lockres->l_lock);
  2037. mlog_entry_void();
  2038. mlog(0, "lock %s\n", lockres->l_name);
  2039. if (lockres->l_unlock_action == OCFS2_UNLOCK_CANCEL_CONVERT) {
  2040. /* If we're already trying to cancel a lock conversion
  2041. * then just drop the spinlock and allow the caller to
  2042. * requeue this lock. */
  2043. mlog(0, "Lockres %s, skip convert\n", lockres->l_name);
  2044. return 0;
  2045. }
  2046. /* were we in a convert when we got the bast fire? */
  2047. BUG_ON(lockres->l_action != OCFS2_AST_CONVERT &&
  2048. lockres->l_action != OCFS2_AST_DOWNCONVERT);
  2049. /* set things up for the unlockast to know to just
  2050. * clear out the ast_action and unset busy, etc. */
  2051. lockres->l_unlock_action = OCFS2_UNLOCK_CANCEL_CONVERT;
  2052. mlog_bug_on_msg(!(lockres->l_flags & OCFS2_LOCK_BUSY),
  2053. "lock %s, invalid flags: 0x%lx\n",
  2054. lockres->l_name, lockres->l_flags);
  2055. return 1;
  2056. }
  2057. static int ocfs2_cancel_convert(struct ocfs2_super *osb,
  2058. struct ocfs2_lock_res *lockres)
  2059. {
  2060. int ret;
  2061. enum dlm_status status;
  2062. mlog_entry_void();
  2063. mlog(0, "lock %s\n", lockres->l_name);
  2064. ret = 0;
  2065. status = dlmunlock(osb->dlm,
  2066. &lockres->l_lksb,
  2067. LKM_CANCEL,
  2068. ocfs2_unlock_ast,
  2069. lockres);
  2070. if (status != DLM_NORMAL) {
  2071. ocfs2_log_dlm_error("dlmunlock", status, lockres);
  2072. ret = -EINVAL;
  2073. ocfs2_recover_from_dlm_error(lockres, 0);
  2074. }
  2075. mlog(0, "lock %s return from dlmunlock\n", lockres->l_name);
  2076. mlog_exit(ret);
  2077. return ret;
  2078. }
  2079. static int ocfs2_unblock_lock(struct ocfs2_super *osb,
  2080. struct ocfs2_lock_res *lockres,
  2081. struct ocfs2_unblock_ctl *ctl)
  2082. {
  2083. unsigned long flags;
  2084. int blocking;
  2085. int new_level;
  2086. int ret = 0;
  2087. int set_lvb = 0;
  2088. mlog_entry_void();
  2089. spin_lock_irqsave(&lockres->l_lock, flags);
  2090. BUG_ON(!(lockres->l_flags & OCFS2_LOCK_BLOCKED));
  2091. recheck:
  2092. if (lockres->l_flags & OCFS2_LOCK_BUSY) {
  2093. ctl->requeue = 1;
  2094. ret = ocfs2_prepare_cancel_convert(osb, lockres);
  2095. spin_unlock_irqrestore(&lockres->l_lock, flags);
  2096. if (ret) {
  2097. ret = ocfs2_cancel_convert(osb, lockres);
  2098. if (ret < 0)
  2099. mlog_errno(ret);
  2100. }
  2101. goto leave;
  2102. }
  2103. /* if we're blocking an exclusive and we have *any* holders,
  2104. * then requeue. */
  2105. if ((lockres->l_blocking == LKM_EXMODE)
  2106. && (lockres->l_ex_holders || lockres->l_ro_holders))
  2107. goto leave_requeue;
  2108. /* If it's a PR we're blocking, then only
  2109. * requeue if we've got any EX holders */
  2110. if (lockres->l_blocking == LKM_PRMODE &&
  2111. lockres->l_ex_holders)
  2112. goto leave_requeue;
  2113. /*
  2114. * Can we get a lock in this state if the holder counts are
  2115. * zero? The meta data unblock code used to check this.
  2116. */
  2117. if ((lockres->l_ops->flags & LOCK_TYPE_REQUIRES_REFRESH)
  2118. && (lockres->l_flags & OCFS2_LOCK_REFRESHING))
  2119. goto leave_requeue;
  2120. new_level = ocfs2_highest_compat_lock_level(lockres->l_blocking);
  2121. if (lockres->l_ops->check_downconvert
  2122. && !lockres->l_ops->check_downconvert(lockres, new_level))
  2123. goto leave_requeue;
  2124. /* If we get here, then we know that there are no more
  2125. * incompatible holders (and anyone asking for an incompatible
  2126. * lock is blocked). We can now downconvert the lock */
  2127. if (!lockres->l_ops->downconvert_worker)
  2128. goto downconvert;
  2129. /* Some lockres types want to do a bit of work before
  2130. * downconverting a lock. Allow that here. The worker function
  2131. * may sleep, so we save off a copy of what we're blocking as
  2132. * it may change while we're not holding the spin lock. */
  2133. blocking = lockres->l_blocking;
  2134. spin_unlock_irqrestore(&lockres->l_lock, flags);
  2135. ctl->unblock_action = lockres->l_ops->downconvert_worker(lockres, blocking);
  2136. if (ctl->unblock_action == UNBLOCK_STOP_POST)
  2137. goto leave;
  2138. spin_lock_irqsave(&lockres->l_lock, flags);
  2139. if (blocking != lockres->l_blocking) {
  2140. /* If this changed underneath us, then we can't drop
  2141. * it just yet. */
  2142. goto recheck;
  2143. }
  2144. downconvert:
  2145. ctl->requeue = 0;
  2146. if (lockres->l_ops->flags & LOCK_TYPE_USES_LVB) {
  2147. if (lockres->l_level == LKM_EXMODE)
  2148. set_lvb = 1;
  2149. /*
  2150. * We only set the lvb if the lock has been fully
  2151. * refreshed - otherwise we risk setting stale
  2152. * data. Otherwise, there's no need to actually clear
  2153. * out the lvb here as it's value is still valid.
  2154. */
  2155. if (set_lvb && !(lockres->l_flags & OCFS2_LOCK_NEEDS_REFRESH))
  2156. lockres->l_ops->set_lvb(lockres);
  2157. }
  2158. ocfs2_prepare_downconvert(lockres, new_level);
  2159. spin_unlock_irqrestore(&lockres->l_lock, flags);
  2160. ret = ocfs2_downconvert_lock(osb, lockres, new_level, set_lvb);
  2161. leave:
  2162. mlog_exit(ret);
  2163. return ret;
  2164. leave_requeue:
  2165. spin_unlock_irqrestore(&lockres->l_lock, flags);
  2166. ctl->requeue = 1;
  2167. mlog_exit(0);
  2168. return 0;
  2169. }
  2170. static int ocfs2_data_convert_worker(struct ocfs2_lock_res *lockres,
  2171. int blocking)
  2172. {
  2173. struct inode *inode;
  2174. struct address_space *mapping;
  2175. inode = ocfs2_lock_res_inode(lockres);
  2176. mapping = inode->i_mapping;
  2177. if (filemap_fdatawrite(mapping)) {
  2178. mlog(ML_ERROR, "Could not sync inode %llu for downconvert!",
  2179. (unsigned long long)OCFS2_I(inode)->ip_blkno);
  2180. }
  2181. sync_mapping_buffers(mapping);
  2182. if (blocking == LKM_EXMODE) {
  2183. truncate_inode_pages(mapping, 0);
  2184. unmap_mapping_range(mapping, 0, 0, 0);
  2185. } else {
  2186. /* We only need to wait on the I/O if we're not also
  2187. * truncating pages because truncate_inode_pages waits
  2188. * for us above. We don't truncate pages if we're
  2189. * blocking anything < EXMODE because we want to keep
  2190. * them around in that case. */
  2191. filemap_fdatawait(mapping);
  2192. }
  2193. return UNBLOCK_CONTINUE;
  2194. }
  2195. static int ocfs2_check_meta_downconvert(struct ocfs2_lock_res *lockres,
  2196. int new_level)
  2197. {
  2198. struct inode *inode = ocfs2_lock_res_inode(lockres);
  2199. int checkpointed = ocfs2_inode_fully_checkpointed(inode);
  2200. BUG_ON(new_level != LKM_NLMODE && new_level != LKM_PRMODE);
  2201. BUG_ON(lockres->l_level != LKM_EXMODE && !checkpointed);
  2202. if (checkpointed)
  2203. return 1;
  2204. ocfs2_start_checkpoint(OCFS2_SB(inode->i_sb));
  2205. return 0;
  2206. }
  2207. static void ocfs2_set_meta_lvb(struct ocfs2_lock_res *lockres)
  2208. {
  2209. struct inode *inode = ocfs2_lock_res_inode(lockres);
  2210. __ocfs2_stuff_meta_lvb(inode);
  2211. }
  2212. /*
  2213. * Does the final reference drop on our dentry lock. Right now this
  2214. * happens in the vote thread, but we could choose to simplify the
  2215. * dlmglue API and push these off to the ocfs2_wq in the future.
  2216. */
  2217. static void ocfs2_dentry_post_unlock(struct ocfs2_super *osb,
  2218. struct ocfs2_lock_res *lockres)
  2219. {
  2220. struct ocfs2_dentry_lock *dl = ocfs2_lock_res_dl(lockres);
  2221. ocfs2_dentry_lock_put(osb, dl);
  2222. }
  2223. /*
  2224. * d_delete() matching dentries before the lock downconvert.
  2225. *
  2226. * At this point, any process waiting to destroy the
  2227. * dentry_lock due to last ref count is stopped by the
  2228. * OCFS2_LOCK_QUEUED flag.
  2229. *
  2230. * We have two potential problems
  2231. *
  2232. * 1) If we do the last reference drop on our dentry_lock (via dput)
  2233. * we'll wind up in ocfs2_release_dentry_lock(), waiting on
  2234. * the downconvert to finish. Instead we take an elevated
  2235. * reference and push the drop until after we've completed our
  2236. * unblock processing.
  2237. *
  2238. * 2) There might be another process with a final reference,
  2239. * waiting on us to finish processing. If this is the case, we
  2240. * detect it and exit out - there's no more dentries anyway.
  2241. */
  2242. static int ocfs2_dentry_convert_worker(struct ocfs2_lock_res *lockres,
  2243. int blocking)
  2244. {
  2245. struct ocfs2_dentry_lock *dl = ocfs2_lock_res_dl(lockres);
  2246. struct ocfs2_inode_info *oi = OCFS2_I(dl->dl_inode);
  2247. struct dentry *dentry;
  2248. unsigned long flags;
  2249. int extra_ref = 0;
  2250. /*
  2251. * This node is blocking another node from getting a read
  2252. * lock. This happens when we've renamed within a
  2253. * directory. We've forced the other nodes to d_delete(), but
  2254. * we never actually dropped our lock because it's still
  2255. * valid. The downconvert code will retain a PR for this node,
  2256. * so there's no further work to do.
  2257. */
  2258. if (blocking == LKM_PRMODE)
  2259. return UNBLOCK_CONTINUE;
  2260. /*
  2261. * Mark this inode as potentially orphaned. The code in
  2262. * ocfs2_delete_inode() will figure out whether it actually
  2263. * needs to be freed or not.
  2264. */
  2265. spin_lock(&oi->ip_lock);
  2266. oi->ip_flags |= OCFS2_INODE_MAYBE_ORPHANED;
  2267. spin_unlock(&oi->ip_lock);
  2268. /*
  2269. * Yuck. We need to make sure however that the check of
  2270. * OCFS2_LOCK_FREEING and the extra reference are atomic with
  2271. * respect to a reference decrement or the setting of that
  2272. * flag.
  2273. */
  2274. spin_lock_irqsave(&lockres->l_lock, flags);
  2275. spin_lock(&dentry_attach_lock);
  2276. if (!(lockres->l_flags & OCFS2_LOCK_FREEING)
  2277. && dl->dl_count) {
  2278. dl->dl_count++;
  2279. extra_ref = 1;
  2280. }
  2281. spin_unlock(&dentry_attach_lock);
  2282. spin_unlock_irqrestore(&lockres->l_lock, flags);
  2283. mlog(0, "extra_ref = %d\n", extra_ref);
  2284. /*
  2285. * We have a process waiting on us in ocfs2_dentry_iput(),
  2286. * which means we can't have any more outstanding
  2287. * aliases. There's no need to do any more work.
  2288. */
  2289. if (!extra_ref)
  2290. return UNBLOCK_CONTINUE;
  2291. spin_lock(&dentry_attach_lock);
  2292. while (1) {
  2293. dentry = ocfs2_find_local_alias(dl->dl_inode,
  2294. dl->dl_parent_blkno, 1);
  2295. if (!dentry)
  2296. break;
  2297. spin_unlock(&dentry_attach_lock);
  2298. mlog(0, "d_delete(%.*s);\n", dentry->d_name.len,
  2299. dentry->d_name.name);
  2300. /*
  2301. * The following dcache calls may do an
  2302. * iput(). Normally we don't want that from the
  2303. * downconverting thread, but in this case it's ok
  2304. * because the requesting node already has an
  2305. * exclusive lock on the inode, so it can't be queued
  2306. * for a downconvert.
  2307. */
  2308. d_delete(dentry);
  2309. dput(dentry);
  2310. spin_lock(&dentry_attach_lock);
  2311. }
  2312. spin_unlock(&dentry_attach_lock);
  2313. /*
  2314. * If we are the last holder of this dentry lock, there is no
  2315. * reason to downconvert so skip straight to the unlock.
  2316. */
  2317. if (dl->dl_count == 1)
  2318. return UNBLOCK_STOP_POST;
  2319. return UNBLOCK_CONTINUE_POST;
  2320. }
  2321. void ocfs2_process_blocked_lock(struct ocfs2_super *osb,
  2322. struct ocfs2_lock_res *lockres)
  2323. {
  2324. int status;
  2325. struct ocfs2_unblock_ctl ctl = {0, 0,};
  2326. unsigned long flags;
  2327. /* Our reference to the lockres in this function can be
  2328. * considered valid until we remove the OCFS2_LOCK_QUEUED
  2329. * flag. */
  2330. mlog_entry_void();
  2331. BUG_ON(!lockres);
  2332. BUG_ON(!lockres->l_ops);
  2333. mlog(0, "lockres %s blocked.\n", lockres->l_name);
  2334. /* Detect whether a lock has been marked as going away while
  2335. * the vote thread was processing other things. A lock can
  2336. * still be marked with OCFS2_LOCK_FREEING after this check,
  2337. * but short circuiting here will still save us some
  2338. * performance. */
  2339. spin_lock_irqsave(&lockres->l_lock, flags);
  2340. if (lockres->l_flags & OCFS2_LOCK_FREEING)
  2341. goto unqueue;
  2342. spin_unlock_irqrestore(&lockres->l_lock, flags);
  2343. status = ocfs2_unblock_lock(osb, lockres, &ctl);
  2344. if (status < 0)
  2345. mlog_errno(status);
  2346. spin_lock_irqsave(&lockres->l_lock, flags);
  2347. unqueue:
  2348. if (lockres->l_flags & OCFS2_LOCK_FREEING || !ctl.requeue) {
  2349. lockres_clear_flags(lockres, OCFS2_LOCK_QUEUED);
  2350. } else
  2351. ocfs2_schedule_blocked_lock(osb, lockres);
  2352. mlog(0, "lockres %s, requeue = %s.\n", lockres->l_name,
  2353. ctl.requeue ? "yes" : "no");
  2354. spin_unlock_irqrestore(&lockres->l_lock, flags);
  2355. if (ctl.unblock_action != UNBLOCK_CONTINUE
  2356. && lockres->l_ops->post_unlock)
  2357. lockres->l_ops->post_unlock(osb, lockres);
  2358. mlog_exit_void();
  2359. }
  2360. static void ocfs2_schedule_blocked_lock(struct ocfs2_super *osb,
  2361. struct ocfs2_lock_res *lockres)
  2362. {
  2363. mlog_entry_void();
  2364. assert_spin_locked(&lockres->l_lock);
  2365. if (lockres->l_flags & OCFS2_LOCK_FREEING) {
  2366. /* Do not schedule a lock for downconvert when it's on
  2367. * the way to destruction - any nodes wanting access
  2368. * to the resource will get it soon. */
  2369. mlog(0, "Lockres %s won't be scheduled: flags 0x%lx\n",
  2370. lockres->l_name, lockres->l_flags);
  2371. return;
  2372. }
  2373. lockres_or_flags(lockres, OCFS2_LOCK_QUEUED);
  2374. spin_lock(&osb->vote_task_lock);
  2375. if (list_empty(&lockres->l_blocked_list)) {
  2376. list_add_tail(&lockres->l_blocked_list,
  2377. &osb->blocked_lock_list);
  2378. osb->blocked_lock_count++;
  2379. }
  2380. spin_unlock(&osb->vote_task_lock);
  2381. mlog_exit_void();
  2382. }
  2383. /* This aids in debugging situations where a bad LVB might be involved. */
  2384. void ocfs2_dump_meta_lvb_info(u64 level,
  2385. const char *function,
  2386. unsigned int line,
  2387. struct ocfs2_lock_res *lockres)
  2388. {
  2389. struct ocfs2_meta_lvb *lvb = (struct ocfs2_meta_lvb *) lockres->l_lksb.lvb;
  2390. mlog(level, "LVB information for %s (called from %s:%u):\n",
  2391. lockres->l_name, function, line);
  2392. mlog(level, "version: %u, clusters: %u, generation: 0x%x\n",
  2393. lvb->lvb_version, be32_to_cpu(lvb->lvb_iclusters),
  2394. be32_to_cpu(lvb->lvb_igeneration));
  2395. mlog(level, "size: %llu, uid %u, gid %u, mode 0x%x\n",
  2396. (unsigned long long)be64_to_cpu(lvb->lvb_isize),
  2397. be32_to_cpu(lvb->lvb_iuid), be32_to_cpu(lvb->lvb_igid),
  2398. be16_to_cpu(lvb->lvb_imode));
  2399. mlog(level, "nlink %u, atime_packed 0x%llx, ctime_packed 0x%llx, "
  2400. "mtime_packed 0x%llx iattr 0x%x\n", be16_to_cpu(lvb->lvb_inlink),
  2401. (long long)be64_to_cpu(lvb->lvb_iatime_packed),
  2402. (long long)be64_to_cpu(lvb->lvb_ictime_packed),
  2403. (long long)be64_to_cpu(lvb->lvb_imtime_packed),
  2404. be32_to_cpu(lvb->lvb_iattr));
  2405. }