jfs_txnmgr.c 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102
  1. /*
  2. * Copyright (C) International Business Machines Corp., 2000-2005
  3. * Portions Copyright (C) Christoph Hellwig, 2001-2002
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  13. * the GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. /*
  20. * jfs_txnmgr.c: transaction manager
  21. *
  22. * notes:
  23. * transaction starts with txBegin() and ends with txCommit()
  24. * or txAbort().
  25. *
  26. * tlock is acquired at the time of update;
  27. * (obviate scan at commit time for xtree and dtree)
  28. * tlock and mp points to each other;
  29. * (no hashlist for mp -> tlock).
  30. *
  31. * special cases:
  32. * tlock on in-memory inode:
  33. * in-place tlock in the in-memory inode itself;
  34. * converted to page lock by iWrite() at commit time.
  35. *
  36. * tlock during write()/mmap() under anonymous transaction (tid = 0):
  37. * transferred (?) to transaction at commit time.
  38. *
  39. * use the page itself to update allocation maps
  40. * (obviate intermediate replication of allocation/deallocation data)
  41. * hold on to mp+lock thru update of maps
  42. */
  43. #include <linux/fs.h>
  44. #include <linux/vmalloc.h>
  45. #include <linux/completion.h>
  46. #include <linux/freezer.h>
  47. #include <linux/module.h>
  48. #include <linux/moduleparam.h>
  49. #include <linux/kthread.h>
  50. #include <linux/seq_file.h>
  51. #include "jfs_incore.h"
  52. #include "jfs_inode.h"
  53. #include "jfs_filsys.h"
  54. #include "jfs_metapage.h"
  55. #include "jfs_dinode.h"
  56. #include "jfs_imap.h"
  57. #include "jfs_dmap.h"
  58. #include "jfs_superblock.h"
  59. #include "jfs_debug.h"
  60. /*
  61. * transaction management structures
  62. */
  63. static struct {
  64. int freetid; /* index of a free tid structure */
  65. int freelock; /* index first free lock word */
  66. wait_queue_head_t freewait; /* eventlist of free tblock */
  67. wait_queue_head_t freelockwait; /* eventlist of free tlock */
  68. wait_queue_head_t lowlockwait; /* eventlist of ample tlocks */
  69. int tlocksInUse; /* Number of tlocks in use */
  70. spinlock_t LazyLock; /* synchronize sync_queue & unlock_queue */
  71. /* struct tblock *sync_queue; * Transactions waiting for data sync */
  72. struct list_head unlock_queue; /* Txns waiting to be released */
  73. struct list_head anon_list; /* inodes having anonymous txns */
  74. struct list_head anon_list2; /* inodes having anonymous txns
  75. that couldn't be sync'ed */
  76. } TxAnchor;
  77. int jfs_tlocks_low; /* Indicates low number of available tlocks */
  78. #ifdef CONFIG_JFS_STATISTICS
  79. static struct {
  80. uint txBegin;
  81. uint txBegin_barrier;
  82. uint txBegin_lockslow;
  83. uint txBegin_freetid;
  84. uint txBeginAnon;
  85. uint txBeginAnon_barrier;
  86. uint txBeginAnon_lockslow;
  87. uint txLockAlloc;
  88. uint txLockAlloc_freelock;
  89. } TxStat;
  90. #endif
  91. static int nTxBlock = -1; /* number of transaction blocks */
  92. module_param(nTxBlock, int, 0);
  93. MODULE_PARM_DESC(nTxBlock,
  94. "Number of transaction blocks (max:65536)");
  95. static int nTxLock = -1; /* number of transaction locks */
  96. module_param(nTxLock, int, 0);
  97. MODULE_PARM_DESC(nTxLock,
  98. "Number of transaction locks (max:65536)");
  99. struct tblock *TxBlock; /* transaction block table */
  100. static int TxLockLWM; /* Low water mark for number of txLocks used */
  101. static int TxLockHWM; /* High water mark for number of txLocks used */
  102. static int TxLockVHWM; /* Very High water mark */
  103. struct tlock *TxLock; /* transaction lock table */
  104. /*
  105. * transaction management lock
  106. */
  107. static DEFINE_SPINLOCK(jfsTxnLock);
  108. #define TXN_LOCK() spin_lock(&jfsTxnLock)
  109. #define TXN_UNLOCK() spin_unlock(&jfsTxnLock)
  110. #define LAZY_LOCK_INIT() spin_lock_init(&TxAnchor.LazyLock);
  111. #define LAZY_LOCK(flags) spin_lock_irqsave(&TxAnchor.LazyLock, flags)
  112. #define LAZY_UNLOCK(flags) spin_unlock_irqrestore(&TxAnchor.LazyLock, flags)
  113. static DECLARE_WAIT_QUEUE_HEAD(jfs_commit_thread_wait);
  114. static int jfs_commit_thread_waking;
  115. /*
  116. * Retry logic exist outside these macros to protect from spurrious wakeups.
  117. */
  118. static inline void TXN_SLEEP_DROP_LOCK(wait_queue_head_t * event)
  119. {
  120. DECLARE_WAITQUEUE(wait, current);
  121. add_wait_queue(event, &wait);
  122. set_current_state(TASK_UNINTERRUPTIBLE);
  123. TXN_UNLOCK();
  124. io_schedule();
  125. __set_current_state(TASK_RUNNING);
  126. remove_wait_queue(event, &wait);
  127. }
  128. #define TXN_SLEEP(event)\
  129. {\
  130. TXN_SLEEP_DROP_LOCK(event);\
  131. TXN_LOCK();\
  132. }
  133. #define TXN_WAKEUP(event) wake_up_all(event)
  134. /*
  135. * statistics
  136. */
  137. static struct {
  138. tid_t maxtid; /* 4: biggest tid ever used */
  139. lid_t maxlid; /* 4: biggest lid ever used */
  140. int ntid; /* 4: # of transactions performed */
  141. int nlid; /* 4: # of tlocks acquired */
  142. int waitlock; /* 4: # of tlock wait */
  143. } stattx;
  144. /*
  145. * forward references
  146. */
  147. static int diLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
  148. struct tlock * tlck, struct commit * cd);
  149. static int dataLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
  150. struct tlock * tlck);
  151. static void dtLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
  152. struct tlock * tlck);
  153. static void mapLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
  154. struct tlock * tlck);
  155. static void txAllocPMap(struct inode *ip, struct maplock * maplock,
  156. struct tblock * tblk);
  157. static void txForce(struct tblock * tblk);
  158. static int txLog(struct jfs_log * log, struct tblock * tblk,
  159. struct commit * cd);
  160. static void txUpdateMap(struct tblock * tblk);
  161. static void txRelease(struct tblock * tblk);
  162. static void xtLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
  163. struct tlock * tlck);
  164. static void LogSyncRelease(struct metapage * mp);
  165. /*
  166. * transaction block/lock management
  167. * ---------------------------------
  168. */
  169. /*
  170. * Get a transaction lock from the free list. If the number in use is
  171. * greater than the high water mark, wake up the sync daemon. This should
  172. * free some anonymous transaction locks. (TXN_LOCK must be held.)
  173. */
  174. static lid_t txLockAlloc(void)
  175. {
  176. lid_t lid;
  177. INCREMENT(TxStat.txLockAlloc);
  178. if (!TxAnchor.freelock) {
  179. INCREMENT(TxStat.txLockAlloc_freelock);
  180. }
  181. while (!(lid = TxAnchor.freelock))
  182. TXN_SLEEP(&TxAnchor.freelockwait);
  183. TxAnchor.freelock = TxLock[lid].next;
  184. HIGHWATERMARK(stattx.maxlid, lid);
  185. if ((++TxAnchor.tlocksInUse > TxLockHWM) && (jfs_tlocks_low == 0)) {
  186. jfs_info("txLockAlloc tlocks low");
  187. jfs_tlocks_low = 1;
  188. wake_up_process(jfsSyncThread);
  189. }
  190. return lid;
  191. }
  192. static void txLockFree(lid_t lid)
  193. {
  194. TxLock[lid].tid = 0;
  195. TxLock[lid].next = TxAnchor.freelock;
  196. TxAnchor.freelock = lid;
  197. TxAnchor.tlocksInUse--;
  198. if (jfs_tlocks_low && (TxAnchor.tlocksInUse < TxLockLWM)) {
  199. jfs_info("txLockFree jfs_tlocks_low no more");
  200. jfs_tlocks_low = 0;
  201. TXN_WAKEUP(&TxAnchor.lowlockwait);
  202. }
  203. TXN_WAKEUP(&TxAnchor.freelockwait);
  204. }
  205. /*
  206. * NAME: txInit()
  207. *
  208. * FUNCTION: initialize transaction management structures
  209. *
  210. * RETURN:
  211. *
  212. * serialization: single thread at jfs_init()
  213. */
  214. int txInit(void)
  215. {
  216. int k, size;
  217. struct sysinfo si;
  218. /* Set defaults for nTxLock and nTxBlock if unset */
  219. if (nTxLock == -1) {
  220. if (nTxBlock == -1) {
  221. /* Base default on memory size */
  222. si_meminfo(&si);
  223. if (si.totalram > (256 * 1024)) /* 1 GB */
  224. nTxLock = 64 * 1024;
  225. else
  226. nTxLock = si.totalram >> 2;
  227. } else if (nTxBlock > (8 * 1024))
  228. nTxLock = 64 * 1024;
  229. else
  230. nTxLock = nTxBlock << 3;
  231. }
  232. if (nTxBlock == -1)
  233. nTxBlock = nTxLock >> 3;
  234. /* Verify tunable parameters */
  235. if (nTxBlock < 16)
  236. nTxBlock = 16; /* No one should set it this low */
  237. if (nTxBlock > 65536)
  238. nTxBlock = 65536;
  239. if (nTxLock < 256)
  240. nTxLock = 256; /* No one should set it this low */
  241. if (nTxLock > 65536)
  242. nTxLock = 65536;
  243. printk(KERN_INFO "JFS: nTxBlock = %d, nTxLock = %d\n",
  244. nTxBlock, nTxLock);
  245. /*
  246. * initialize transaction block (tblock) table
  247. *
  248. * transaction id (tid) = tblock index
  249. * tid = 0 is reserved.
  250. */
  251. TxLockLWM = (nTxLock * 4) / 10;
  252. TxLockHWM = (nTxLock * 7) / 10;
  253. TxLockVHWM = (nTxLock * 8) / 10;
  254. size = sizeof(struct tblock) * nTxBlock;
  255. TxBlock = vmalloc(size);
  256. if (TxBlock == NULL)
  257. return -ENOMEM;
  258. for (k = 1; k < nTxBlock - 1; k++) {
  259. TxBlock[k].next = k + 1;
  260. init_waitqueue_head(&TxBlock[k].gcwait);
  261. init_waitqueue_head(&TxBlock[k].waitor);
  262. }
  263. TxBlock[k].next = 0;
  264. init_waitqueue_head(&TxBlock[k].gcwait);
  265. init_waitqueue_head(&TxBlock[k].waitor);
  266. TxAnchor.freetid = 1;
  267. init_waitqueue_head(&TxAnchor.freewait);
  268. stattx.maxtid = 1; /* statistics */
  269. /*
  270. * initialize transaction lock (tlock) table
  271. *
  272. * transaction lock id = tlock index
  273. * tlock id = 0 is reserved.
  274. */
  275. size = sizeof(struct tlock) * nTxLock;
  276. TxLock = vmalloc(size);
  277. if (TxLock == NULL) {
  278. vfree(TxBlock);
  279. return -ENOMEM;
  280. }
  281. /* initialize tlock table */
  282. for (k = 1; k < nTxLock - 1; k++)
  283. TxLock[k].next = k + 1;
  284. TxLock[k].next = 0;
  285. init_waitqueue_head(&TxAnchor.freelockwait);
  286. init_waitqueue_head(&TxAnchor.lowlockwait);
  287. TxAnchor.freelock = 1;
  288. TxAnchor.tlocksInUse = 0;
  289. INIT_LIST_HEAD(&TxAnchor.anon_list);
  290. INIT_LIST_HEAD(&TxAnchor.anon_list2);
  291. LAZY_LOCK_INIT();
  292. INIT_LIST_HEAD(&TxAnchor.unlock_queue);
  293. stattx.maxlid = 1; /* statistics */
  294. return 0;
  295. }
  296. /*
  297. * NAME: txExit()
  298. *
  299. * FUNCTION: clean up when module is unloaded
  300. */
  301. void txExit(void)
  302. {
  303. vfree(TxLock);
  304. TxLock = NULL;
  305. vfree(TxBlock);
  306. TxBlock = NULL;
  307. }
  308. /*
  309. * NAME: txBegin()
  310. *
  311. * FUNCTION: start a transaction.
  312. *
  313. * PARAMETER: sb - superblock
  314. * flag - force for nested tx;
  315. *
  316. * RETURN: tid - transaction id
  317. *
  318. * note: flag force allows to start tx for nested tx
  319. * to prevent deadlock on logsync barrier;
  320. */
  321. tid_t txBegin(struct super_block *sb, int flag)
  322. {
  323. tid_t t;
  324. struct tblock *tblk;
  325. struct jfs_log *log;
  326. jfs_info("txBegin: flag = 0x%x", flag);
  327. log = JFS_SBI(sb)->log;
  328. TXN_LOCK();
  329. INCREMENT(TxStat.txBegin);
  330. retry:
  331. if (!(flag & COMMIT_FORCE)) {
  332. /*
  333. * synchronize with logsync barrier
  334. */
  335. if (test_bit(log_SYNCBARRIER, &log->flag) ||
  336. test_bit(log_QUIESCE, &log->flag)) {
  337. INCREMENT(TxStat.txBegin_barrier);
  338. TXN_SLEEP(&log->syncwait);
  339. goto retry;
  340. }
  341. }
  342. if (flag == 0) {
  343. /*
  344. * Don't begin transaction if we're getting starved for tlocks
  345. * unless COMMIT_FORCE or COMMIT_INODE (which may ultimately
  346. * free tlocks)
  347. */
  348. if (TxAnchor.tlocksInUse > TxLockVHWM) {
  349. INCREMENT(TxStat.txBegin_lockslow);
  350. TXN_SLEEP(&TxAnchor.lowlockwait);
  351. goto retry;
  352. }
  353. }
  354. /*
  355. * allocate transaction id/block
  356. */
  357. if ((t = TxAnchor.freetid) == 0) {
  358. jfs_info("txBegin: waiting for free tid");
  359. INCREMENT(TxStat.txBegin_freetid);
  360. TXN_SLEEP(&TxAnchor.freewait);
  361. goto retry;
  362. }
  363. tblk = tid_to_tblock(t);
  364. if ((tblk->next == 0) && !(flag & COMMIT_FORCE)) {
  365. /* Don't let a non-forced transaction take the last tblk */
  366. jfs_info("txBegin: waiting for free tid");
  367. INCREMENT(TxStat.txBegin_freetid);
  368. TXN_SLEEP(&TxAnchor.freewait);
  369. goto retry;
  370. }
  371. TxAnchor.freetid = tblk->next;
  372. /*
  373. * initialize transaction
  374. */
  375. /*
  376. * We can't zero the whole thing or we screw up another thread being
  377. * awakened after sleeping on tblk->waitor
  378. *
  379. * memset(tblk, 0, sizeof(struct tblock));
  380. */
  381. tblk->next = tblk->last = tblk->xflag = tblk->flag = tblk->lsn = 0;
  382. tblk->sb = sb;
  383. ++log->logtid;
  384. tblk->logtid = log->logtid;
  385. ++log->active;
  386. HIGHWATERMARK(stattx.maxtid, t); /* statistics */
  387. INCREMENT(stattx.ntid); /* statistics */
  388. TXN_UNLOCK();
  389. jfs_info("txBegin: returning tid = %d", t);
  390. return t;
  391. }
  392. /*
  393. * NAME: txBeginAnon()
  394. *
  395. * FUNCTION: start an anonymous transaction.
  396. * Blocks if logsync or available tlocks are low to prevent
  397. * anonymous tlocks from depleting supply.
  398. *
  399. * PARAMETER: sb - superblock
  400. *
  401. * RETURN: none
  402. */
  403. void txBeginAnon(struct super_block *sb)
  404. {
  405. struct jfs_log *log;
  406. log = JFS_SBI(sb)->log;
  407. TXN_LOCK();
  408. INCREMENT(TxStat.txBeginAnon);
  409. retry:
  410. /*
  411. * synchronize with logsync barrier
  412. */
  413. if (test_bit(log_SYNCBARRIER, &log->flag) ||
  414. test_bit(log_QUIESCE, &log->flag)) {
  415. INCREMENT(TxStat.txBeginAnon_barrier);
  416. TXN_SLEEP(&log->syncwait);
  417. goto retry;
  418. }
  419. /*
  420. * Don't begin transaction if we're getting starved for tlocks
  421. */
  422. if (TxAnchor.tlocksInUse > TxLockVHWM) {
  423. INCREMENT(TxStat.txBeginAnon_lockslow);
  424. TXN_SLEEP(&TxAnchor.lowlockwait);
  425. goto retry;
  426. }
  427. TXN_UNLOCK();
  428. }
  429. /*
  430. * txEnd()
  431. *
  432. * function: free specified transaction block.
  433. *
  434. * logsync barrier processing:
  435. *
  436. * serialization:
  437. */
  438. void txEnd(tid_t tid)
  439. {
  440. struct tblock *tblk = tid_to_tblock(tid);
  441. struct jfs_log *log;
  442. jfs_info("txEnd: tid = %d", tid);
  443. TXN_LOCK();
  444. /*
  445. * wakeup transactions waiting on the page locked
  446. * by the current transaction
  447. */
  448. TXN_WAKEUP(&tblk->waitor);
  449. log = JFS_SBI(tblk->sb)->log;
  450. /*
  451. * Lazy commit thread can't free this guy until we mark it UNLOCKED,
  452. * otherwise, we would be left with a transaction that may have been
  453. * reused.
  454. *
  455. * Lazy commit thread will turn off tblkGC_LAZY before calling this
  456. * routine.
  457. */
  458. if (tblk->flag & tblkGC_LAZY) {
  459. jfs_info("txEnd called w/lazy tid: %d, tblk = 0x%p", tid, tblk);
  460. TXN_UNLOCK();
  461. spin_lock_irq(&log->gclock); // LOGGC_LOCK
  462. tblk->flag |= tblkGC_UNLOCKED;
  463. spin_unlock_irq(&log->gclock); // LOGGC_UNLOCK
  464. return;
  465. }
  466. jfs_info("txEnd: tid: %d, tblk = 0x%p", tid, tblk);
  467. assert(tblk->next == 0);
  468. /*
  469. * insert tblock back on freelist
  470. */
  471. tblk->next = TxAnchor.freetid;
  472. TxAnchor.freetid = tid;
  473. /*
  474. * mark the tblock not active
  475. */
  476. if (--log->active == 0) {
  477. clear_bit(log_FLUSH, &log->flag);
  478. /*
  479. * synchronize with logsync barrier
  480. */
  481. if (test_bit(log_SYNCBARRIER, &log->flag)) {
  482. TXN_UNLOCK();
  483. /* write dirty metadata & forward log syncpt */
  484. jfs_syncpt(log, 1);
  485. jfs_info("log barrier off: 0x%x", log->lsn);
  486. /* enable new transactions start */
  487. clear_bit(log_SYNCBARRIER, &log->flag);
  488. /* wakeup all waitors for logsync barrier */
  489. TXN_WAKEUP(&log->syncwait);
  490. goto wakeup;
  491. }
  492. }
  493. TXN_UNLOCK();
  494. wakeup:
  495. /*
  496. * wakeup all waitors for a free tblock
  497. */
  498. TXN_WAKEUP(&TxAnchor.freewait);
  499. }
  500. /*
  501. * txLock()
  502. *
  503. * function: acquire a transaction lock on the specified <mp>
  504. *
  505. * parameter:
  506. *
  507. * return: transaction lock id
  508. *
  509. * serialization:
  510. */
  511. struct tlock *txLock(tid_t tid, struct inode *ip, struct metapage * mp,
  512. int type)
  513. {
  514. struct jfs_inode_info *jfs_ip = JFS_IP(ip);
  515. int dir_xtree = 0;
  516. lid_t lid;
  517. tid_t xtid;
  518. struct tlock *tlck;
  519. struct xtlock *xtlck;
  520. struct linelock *linelock;
  521. xtpage_t *p;
  522. struct tblock *tblk;
  523. TXN_LOCK();
  524. if (S_ISDIR(ip->i_mode) && (type & tlckXTREE) &&
  525. !(mp->xflag & COMMIT_PAGE)) {
  526. /*
  527. * Directory inode is special. It can have both an xtree tlock
  528. * and a dtree tlock associated with it.
  529. */
  530. dir_xtree = 1;
  531. lid = jfs_ip->xtlid;
  532. } else
  533. lid = mp->lid;
  534. /* is page not locked by a transaction ? */
  535. if (lid == 0)
  536. goto allocateLock;
  537. jfs_info("txLock: tid:%d ip:0x%p mp:0x%p lid:%d", tid, ip, mp, lid);
  538. /* is page locked by the requester transaction ? */
  539. tlck = lid_to_tlock(lid);
  540. if ((xtid = tlck->tid) == tid) {
  541. TXN_UNLOCK();
  542. goto grantLock;
  543. }
  544. /*
  545. * is page locked by anonymous transaction/lock ?
  546. *
  547. * (page update without transaction (i.e., file write) is
  548. * locked under anonymous transaction tid = 0:
  549. * anonymous tlocks maintained on anonymous tlock list of
  550. * the inode of the page and available to all anonymous
  551. * transactions until txCommit() time at which point
  552. * they are transferred to the transaction tlock list of
  553. * the committing transaction of the inode)
  554. */
  555. if (xtid == 0) {
  556. tlck->tid = tid;
  557. TXN_UNLOCK();
  558. tblk = tid_to_tblock(tid);
  559. /*
  560. * The order of the tlocks in the transaction is important
  561. * (during truncate, child xtree pages must be freed before
  562. * parent's tlocks change the working map).
  563. * Take tlock off anonymous list and add to tail of
  564. * transaction list
  565. *
  566. * Note: We really need to get rid of the tid & lid and
  567. * use list_head's. This code is getting UGLY!
  568. */
  569. if (jfs_ip->atlhead == lid) {
  570. if (jfs_ip->atltail == lid) {
  571. /* only anonymous txn.
  572. * Remove from anon_list
  573. */
  574. TXN_LOCK();
  575. list_del_init(&jfs_ip->anon_inode_list);
  576. TXN_UNLOCK();
  577. }
  578. jfs_ip->atlhead = tlck->next;
  579. } else {
  580. lid_t last;
  581. for (last = jfs_ip->atlhead;
  582. lid_to_tlock(last)->next != lid;
  583. last = lid_to_tlock(last)->next) {
  584. assert(last);
  585. }
  586. lid_to_tlock(last)->next = tlck->next;
  587. if (jfs_ip->atltail == lid)
  588. jfs_ip->atltail = last;
  589. }
  590. /* insert the tlock at tail of transaction tlock list */
  591. if (tblk->next)
  592. lid_to_tlock(tblk->last)->next = lid;
  593. else
  594. tblk->next = lid;
  595. tlck->next = 0;
  596. tblk->last = lid;
  597. goto grantLock;
  598. }
  599. goto waitLock;
  600. /*
  601. * allocate a tlock
  602. */
  603. allocateLock:
  604. lid = txLockAlloc();
  605. tlck = lid_to_tlock(lid);
  606. /*
  607. * initialize tlock
  608. */
  609. tlck->tid = tid;
  610. TXN_UNLOCK();
  611. /* mark tlock for meta-data page */
  612. if (mp->xflag & COMMIT_PAGE) {
  613. tlck->flag = tlckPAGELOCK;
  614. /* mark the page dirty and nohomeok */
  615. metapage_nohomeok(mp);
  616. jfs_info("locking mp = 0x%p, nohomeok = %d tid = %d tlck = 0x%p",
  617. mp, mp->nohomeok, tid, tlck);
  618. /* if anonymous transaction, and buffer is on the group
  619. * commit synclist, mark inode to show this. This will
  620. * prevent the buffer from being marked nohomeok for too
  621. * long a time.
  622. */
  623. if ((tid == 0) && mp->lsn)
  624. set_cflag(COMMIT_Synclist, ip);
  625. }
  626. /* mark tlock for in-memory inode */
  627. else
  628. tlck->flag = tlckINODELOCK;
  629. if (S_ISDIR(ip->i_mode))
  630. tlck->flag |= tlckDIRECTORY;
  631. tlck->type = 0;
  632. /* bind the tlock and the page */
  633. tlck->ip = ip;
  634. tlck->mp = mp;
  635. if (dir_xtree)
  636. jfs_ip->xtlid = lid;
  637. else
  638. mp->lid = lid;
  639. /*
  640. * enqueue transaction lock to transaction/inode
  641. */
  642. /* insert the tlock at tail of transaction tlock list */
  643. if (tid) {
  644. tblk = tid_to_tblock(tid);
  645. if (tblk->next)
  646. lid_to_tlock(tblk->last)->next = lid;
  647. else
  648. tblk->next = lid;
  649. tlck->next = 0;
  650. tblk->last = lid;
  651. }
  652. /* anonymous transaction:
  653. * insert the tlock at head of inode anonymous tlock list
  654. */
  655. else {
  656. tlck->next = jfs_ip->atlhead;
  657. jfs_ip->atlhead = lid;
  658. if (tlck->next == 0) {
  659. /* This inode's first anonymous transaction */
  660. jfs_ip->atltail = lid;
  661. TXN_LOCK();
  662. list_add_tail(&jfs_ip->anon_inode_list,
  663. &TxAnchor.anon_list);
  664. TXN_UNLOCK();
  665. }
  666. }
  667. /* initialize type dependent area for linelock */
  668. linelock = (struct linelock *) & tlck->lock;
  669. linelock->next = 0;
  670. linelock->flag = tlckLINELOCK;
  671. linelock->maxcnt = TLOCKSHORT;
  672. linelock->index = 0;
  673. switch (type & tlckTYPE) {
  674. case tlckDTREE:
  675. linelock->l2linesize = L2DTSLOTSIZE;
  676. break;
  677. case tlckXTREE:
  678. linelock->l2linesize = L2XTSLOTSIZE;
  679. xtlck = (struct xtlock *) linelock;
  680. xtlck->header.offset = 0;
  681. xtlck->header.length = 2;
  682. if (type & tlckNEW) {
  683. xtlck->lwm.offset = XTENTRYSTART;
  684. } else {
  685. if (mp->xflag & COMMIT_PAGE)
  686. p = (xtpage_t *) mp->data;
  687. else
  688. p = &jfs_ip->i_xtroot;
  689. xtlck->lwm.offset =
  690. le16_to_cpu(p->header.nextindex);
  691. }
  692. xtlck->lwm.length = 0; /* ! */
  693. xtlck->twm.offset = 0;
  694. xtlck->hwm.offset = 0;
  695. xtlck->index = 2;
  696. break;
  697. case tlckINODE:
  698. linelock->l2linesize = L2INODESLOTSIZE;
  699. break;
  700. case tlckDATA:
  701. linelock->l2linesize = L2DATASLOTSIZE;
  702. break;
  703. default:
  704. jfs_err("UFO tlock:0x%p", tlck);
  705. }
  706. /*
  707. * update tlock vector
  708. */
  709. grantLock:
  710. tlck->type |= type;
  711. return tlck;
  712. /*
  713. * page is being locked by another transaction:
  714. */
  715. waitLock:
  716. /* Only locks on ipimap or ipaimap should reach here */
  717. /* assert(jfs_ip->fileset == AGGREGATE_I); */
  718. if (jfs_ip->fileset != AGGREGATE_I) {
  719. printk(KERN_ERR "txLock: trying to lock locked page!");
  720. print_hex_dump(KERN_ERR, "ip: ", DUMP_PREFIX_ADDRESS, 16, 4,
  721. ip, sizeof(*ip), 0);
  722. print_hex_dump(KERN_ERR, "mp: ", DUMP_PREFIX_ADDRESS, 16, 4,
  723. mp, sizeof(*mp), 0);
  724. print_hex_dump(KERN_ERR, "Locker's tblock: ",
  725. DUMP_PREFIX_ADDRESS, 16, 4, tid_to_tblock(tid),
  726. sizeof(struct tblock), 0);
  727. print_hex_dump(KERN_ERR, "Tlock: ", DUMP_PREFIX_ADDRESS, 16, 4,
  728. tlck, sizeof(*tlck), 0);
  729. BUG();
  730. }
  731. INCREMENT(stattx.waitlock); /* statistics */
  732. TXN_UNLOCK();
  733. release_metapage(mp);
  734. TXN_LOCK();
  735. xtid = tlck->tid; /* reacquire after dropping TXN_LOCK */
  736. jfs_info("txLock: in waitLock, tid = %d, xtid = %d, lid = %d",
  737. tid, xtid, lid);
  738. /* Recheck everything since dropping TXN_LOCK */
  739. if (xtid && (tlck->mp == mp) && (mp->lid == lid))
  740. TXN_SLEEP_DROP_LOCK(&tid_to_tblock(xtid)->waitor);
  741. else
  742. TXN_UNLOCK();
  743. jfs_info("txLock: awakened tid = %d, lid = %d", tid, lid);
  744. return NULL;
  745. }
  746. /*
  747. * NAME: txRelease()
  748. *
  749. * FUNCTION: Release buffers associated with transaction locks, but don't
  750. * mark homeok yet. The allows other transactions to modify
  751. * buffers, but won't let them go to disk until commit record
  752. * actually gets written.
  753. *
  754. * PARAMETER:
  755. * tblk -
  756. *
  757. * RETURN: Errors from subroutines.
  758. */
  759. static void txRelease(struct tblock * tblk)
  760. {
  761. struct metapage *mp;
  762. lid_t lid;
  763. struct tlock *tlck;
  764. TXN_LOCK();
  765. for (lid = tblk->next; lid; lid = tlck->next) {
  766. tlck = lid_to_tlock(lid);
  767. if ((mp = tlck->mp) != NULL &&
  768. (tlck->type & tlckBTROOT) == 0) {
  769. assert(mp->xflag & COMMIT_PAGE);
  770. mp->lid = 0;
  771. }
  772. }
  773. /*
  774. * wakeup transactions waiting on a page locked
  775. * by the current transaction
  776. */
  777. TXN_WAKEUP(&tblk->waitor);
  778. TXN_UNLOCK();
  779. }
  780. /*
  781. * NAME: txUnlock()
  782. *
  783. * FUNCTION: Initiates pageout of pages modified by tid in journalled
  784. * objects and frees their lockwords.
  785. */
  786. static void txUnlock(struct tblock * tblk)
  787. {
  788. struct tlock *tlck;
  789. struct linelock *linelock;
  790. lid_t lid, next, llid, k;
  791. struct metapage *mp;
  792. struct jfs_log *log;
  793. int difft, diffp;
  794. unsigned long flags;
  795. jfs_info("txUnlock: tblk = 0x%p", tblk);
  796. log = JFS_SBI(tblk->sb)->log;
  797. /*
  798. * mark page under tlock homeok (its log has been written):
  799. */
  800. for (lid = tblk->next; lid; lid = next) {
  801. tlck = lid_to_tlock(lid);
  802. next = tlck->next;
  803. jfs_info("unlocking lid = %d, tlck = 0x%p", lid, tlck);
  804. /* unbind page from tlock */
  805. if ((mp = tlck->mp) != NULL &&
  806. (tlck->type & tlckBTROOT) == 0) {
  807. assert(mp->xflag & COMMIT_PAGE);
  808. /* hold buffer
  809. */
  810. hold_metapage(mp);
  811. assert(mp->nohomeok > 0);
  812. _metapage_homeok(mp);
  813. /* inherit younger/larger clsn */
  814. LOGSYNC_LOCK(log, flags);
  815. if (mp->clsn) {
  816. logdiff(difft, tblk->clsn, log);
  817. logdiff(diffp, mp->clsn, log);
  818. if (difft > diffp)
  819. mp->clsn = tblk->clsn;
  820. } else
  821. mp->clsn = tblk->clsn;
  822. LOGSYNC_UNLOCK(log, flags);
  823. assert(!(tlck->flag & tlckFREEPAGE));
  824. put_metapage(mp);
  825. }
  826. /* insert tlock, and linelock(s) of the tlock if any,
  827. * at head of freelist
  828. */
  829. TXN_LOCK();
  830. llid = ((struct linelock *) & tlck->lock)->next;
  831. while (llid) {
  832. linelock = (struct linelock *) lid_to_tlock(llid);
  833. k = linelock->next;
  834. txLockFree(llid);
  835. llid = k;
  836. }
  837. txLockFree(lid);
  838. TXN_UNLOCK();
  839. }
  840. tblk->next = tblk->last = 0;
  841. /*
  842. * remove tblock from logsynclist
  843. * (allocation map pages inherited lsn of tblk and
  844. * has been inserted in logsync list at txUpdateMap())
  845. */
  846. if (tblk->lsn) {
  847. LOGSYNC_LOCK(log, flags);
  848. log->count--;
  849. list_del(&tblk->synclist);
  850. LOGSYNC_UNLOCK(log, flags);
  851. }
  852. }
  853. /*
  854. * txMaplock()
  855. *
  856. * function: allocate a transaction lock for freed page/entry;
  857. * for freed page, maplock is used as xtlock/dtlock type;
  858. */
  859. struct tlock *txMaplock(tid_t tid, struct inode *ip, int type)
  860. {
  861. struct jfs_inode_info *jfs_ip = JFS_IP(ip);
  862. lid_t lid;
  863. struct tblock *tblk;
  864. struct tlock *tlck;
  865. struct maplock *maplock;
  866. TXN_LOCK();
  867. /*
  868. * allocate a tlock
  869. */
  870. lid = txLockAlloc();
  871. tlck = lid_to_tlock(lid);
  872. /*
  873. * initialize tlock
  874. */
  875. tlck->tid = tid;
  876. /* bind the tlock and the object */
  877. tlck->flag = tlckINODELOCK;
  878. if (S_ISDIR(ip->i_mode))
  879. tlck->flag |= tlckDIRECTORY;
  880. tlck->ip = ip;
  881. tlck->mp = NULL;
  882. tlck->type = type;
  883. /*
  884. * enqueue transaction lock to transaction/inode
  885. */
  886. /* insert the tlock at tail of transaction tlock list */
  887. if (tid) {
  888. tblk = tid_to_tblock(tid);
  889. if (tblk->next)
  890. lid_to_tlock(tblk->last)->next = lid;
  891. else
  892. tblk->next = lid;
  893. tlck->next = 0;
  894. tblk->last = lid;
  895. }
  896. /* anonymous transaction:
  897. * insert the tlock at head of inode anonymous tlock list
  898. */
  899. else {
  900. tlck->next = jfs_ip->atlhead;
  901. jfs_ip->atlhead = lid;
  902. if (tlck->next == 0) {
  903. /* This inode's first anonymous transaction */
  904. jfs_ip->atltail = lid;
  905. list_add_tail(&jfs_ip->anon_inode_list,
  906. &TxAnchor.anon_list);
  907. }
  908. }
  909. TXN_UNLOCK();
  910. /* initialize type dependent area for maplock */
  911. maplock = (struct maplock *) & tlck->lock;
  912. maplock->next = 0;
  913. maplock->maxcnt = 0;
  914. maplock->index = 0;
  915. return tlck;
  916. }
  917. /*
  918. * txLinelock()
  919. *
  920. * function: allocate a transaction lock for log vector list
  921. */
  922. struct linelock *txLinelock(struct linelock * tlock)
  923. {
  924. lid_t lid;
  925. struct tlock *tlck;
  926. struct linelock *linelock;
  927. TXN_LOCK();
  928. /* allocate a TxLock structure */
  929. lid = txLockAlloc();
  930. tlck = lid_to_tlock(lid);
  931. TXN_UNLOCK();
  932. /* initialize linelock */
  933. linelock = (struct linelock *) tlck;
  934. linelock->next = 0;
  935. linelock->flag = tlckLINELOCK;
  936. linelock->maxcnt = TLOCKLONG;
  937. linelock->index = 0;
  938. if (tlck->flag & tlckDIRECTORY)
  939. linelock->flag |= tlckDIRECTORY;
  940. /* append linelock after tlock */
  941. linelock->next = tlock->next;
  942. tlock->next = lid;
  943. return linelock;
  944. }
  945. /*
  946. * transaction commit management
  947. * -----------------------------
  948. */
  949. /*
  950. * NAME: txCommit()
  951. *
  952. * FUNCTION: commit the changes to the objects specified in
  953. * clist. For journalled segments only the
  954. * changes of the caller are committed, ie by tid.
  955. * for non-journalled segments the data are flushed to
  956. * disk and then the change to the disk inode and indirect
  957. * blocks committed (so blocks newly allocated to the
  958. * segment will be made a part of the segment atomically).
  959. *
  960. * all of the segments specified in clist must be in
  961. * one file system. no more than 6 segments are needed
  962. * to handle all unix svcs.
  963. *
  964. * if the i_nlink field (i.e. disk inode link count)
  965. * is zero, and the type of inode is a regular file or
  966. * directory, or symbolic link , the inode is truncated
  967. * to zero length. the truncation is committed but the
  968. * VM resources are unaffected until it is closed (see
  969. * iput and iclose).
  970. *
  971. * PARAMETER:
  972. *
  973. * RETURN:
  974. *
  975. * serialization:
  976. * on entry the inode lock on each segment is assumed
  977. * to be held.
  978. *
  979. * i/o error:
  980. */
  981. int txCommit(tid_t tid, /* transaction identifier */
  982. int nip, /* number of inodes to commit */
  983. struct inode **iplist, /* list of inode to commit */
  984. int flag)
  985. {
  986. int rc = 0;
  987. struct commit cd;
  988. struct jfs_log *log;
  989. struct tblock *tblk;
  990. struct lrd *lrd;
  991. int lsn;
  992. struct inode *ip;
  993. struct jfs_inode_info *jfs_ip;
  994. int k, n;
  995. ino_t top;
  996. struct super_block *sb;
  997. jfs_info("txCommit, tid = %d, flag = %d", tid, flag);
  998. /* is read-only file system ? */
  999. if (isReadOnly(iplist[0])) {
  1000. rc = -EROFS;
  1001. goto TheEnd;
  1002. }
  1003. sb = cd.sb = iplist[0]->i_sb;
  1004. cd.tid = tid;
  1005. if (tid == 0)
  1006. tid = txBegin(sb, 0);
  1007. tblk = tid_to_tblock(tid);
  1008. /*
  1009. * initialize commit structure
  1010. */
  1011. log = JFS_SBI(sb)->log;
  1012. cd.log = log;
  1013. /* initialize log record descriptor in commit */
  1014. lrd = &cd.lrd;
  1015. lrd->logtid = cpu_to_le32(tblk->logtid);
  1016. lrd->backchain = 0;
  1017. tblk->xflag |= flag;
  1018. if ((flag & (COMMIT_FORCE | COMMIT_SYNC)) == 0)
  1019. tblk->xflag |= COMMIT_LAZY;
  1020. /*
  1021. * prepare non-journaled objects for commit
  1022. *
  1023. * flush data pages of non-journaled file
  1024. * to prevent the file getting non-initialized disk blocks
  1025. * in case of crash.
  1026. * (new blocks - )
  1027. */
  1028. cd.iplist = iplist;
  1029. cd.nip = nip;
  1030. /*
  1031. * acquire transaction lock on (on-disk) inodes
  1032. *
  1033. * update on-disk inode from in-memory inode
  1034. * acquiring transaction locks for AFTER records
  1035. * on the on-disk inode of file object
  1036. *
  1037. * sort the inodes array by inode number in descending order
  1038. * to prevent deadlock when acquiring transaction lock
  1039. * of on-disk inodes on multiple on-disk inode pages by
  1040. * multiple concurrent transactions
  1041. */
  1042. for (k = 0; k < cd.nip; k++) {
  1043. top = (cd.iplist[k])->i_ino;
  1044. for (n = k + 1; n < cd.nip; n++) {
  1045. ip = cd.iplist[n];
  1046. if (ip->i_ino > top) {
  1047. top = ip->i_ino;
  1048. cd.iplist[n] = cd.iplist[k];
  1049. cd.iplist[k] = ip;
  1050. }
  1051. }
  1052. ip = cd.iplist[k];
  1053. jfs_ip = JFS_IP(ip);
  1054. /*
  1055. * BUGBUG - This code has temporarily been removed. The
  1056. * intent is to ensure that any file data is written before
  1057. * the metadata is committed to the journal. This prevents
  1058. * uninitialized data from appearing in a file after the
  1059. * journal has been replayed. (The uninitialized data
  1060. * could be sensitive data removed by another user.)
  1061. *
  1062. * The problem now is that we are holding the IWRITELOCK
  1063. * on the inode, and calling filemap_fdatawrite on an
  1064. * unmapped page will cause a deadlock in jfs_get_block.
  1065. *
  1066. * The long term solution is to pare down the use of
  1067. * IWRITELOCK. We are currently holding it too long.
  1068. * We could also be smarter about which data pages need
  1069. * to be written before the transaction is committed and
  1070. * when we don't need to worry about it at all.
  1071. *
  1072. * if ((!S_ISDIR(ip->i_mode))
  1073. * && (tblk->flag & COMMIT_DELETE) == 0)
  1074. * filemap_write_and_wait(ip->i_mapping);
  1075. */
  1076. /*
  1077. * Mark inode as not dirty. It will still be on the dirty
  1078. * inode list, but we'll know not to commit it again unless
  1079. * it gets marked dirty again
  1080. */
  1081. clear_cflag(COMMIT_Dirty, ip);
  1082. /* inherit anonymous tlock(s) of inode */
  1083. if (jfs_ip->atlhead) {
  1084. lid_to_tlock(jfs_ip->atltail)->next = tblk->next;
  1085. tblk->next = jfs_ip->atlhead;
  1086. if (!tblk->last)
  1087. tblk->last = jfs_ip->atltail;
  1088. jfs_ip->atlhead = jfs_ip->atltail = 0;
  1089. TXN_LOCK();
  1090. list_del_init(&jfs_ip->anon_inode_list);
  1091. TXN_UNLOCK();
  1092. }
  1093. /*
  1094. * acquire transaction lock on on-disk inode page
  1095. * (become first tlock of the tblk's tlock list)
  1096. */
  1097. if (((rc = diWrite(tid, ip))))
  1098. goto out;
  1099. }
  1100. /*
  1101. * write log records from transaction locks
  1102. *
  1103. * txUpdateMap() resets XAD_NEW in XAD.
  1104. */
  1105. if ((rc = txLog(log, tblk, &cd)))
  1106. goto TheEnd;
  1107. /*
  1108. * Ensure that inode isn't reused before
  1109. * lazy commit thread finishes processing
  1110. */
  1111. if (tblk->xflag & COMMIT_DELETE) {
  1112. ihold(tblk->u.ip);
  1113. /*
  1114. * Avoid a rare deadlock
  1115. *
  1116. * If the inode is locked, we may be blocked in
  1117. * jfs_commit_inode. If so, we don't want the
  1118. * lazy_commit thread doing the last iput() on the inode
  1119. * since that may block on the locked inode. Instead,
  1120. * commit the transaction synchronously, so the last iput
  1121. * will be done by the calling thread (or later)
  1122. */
  1123. /*
  1124. * I believe this code is no longer needed. Splitting I_LOCK
  1125. * into two bits, I_NEW and I_SYNC should prevent this
  1126. * deadlock as well. But since I don't have a JFS testload
  1127. * to verify this, only a trivial s/I_LOCK/I_SYNC/ was done.
  1128. * Joern
  1129. */
  1130. if (tblk->u.ip->i_state & I_SYNC)
  1131. tblk->xflag &= ~COMMIT_LAZY;
  1132. }
  1133. ASSERT((!(tblk->xflag & COMMIT_DELETE)) ||
  1134. ((tblk->u.ip->i_nlink == 0) &&
  1135. !test_cflag(COMMIT_Nolink, tblk->u.ip)));
  1136. /*
  1137. * write COMMIT log record
  1138. */
  1139. lrd->type = cpu_to_le16(LOG_COMMIT);
  1140. lrd->length = 0;
  1141. lsn = lmLog(log, tblk, lrd, NULL);
  1142. lmGroupCommit(log, tblk);
  1143. /*
  1144. * - transaction is now committed -
  1145. */
  1146. /*
  1147. * force pages in careful update
  1148. * (imap addressing structure update)
  1149. */
  1150. if (flag & COMMIT_FORCE)
  1151. txForce(tblk);
  1152. /*
  1153. * update allocation map.
  1154. *
  1155. * update inode allocation map and inode:
  1156. * free pager lock on memory object of inode if any.
  1157. * update block allocation map.
  1158. *
  1159. * txUpdateMap() resets XAD_NEW in XAD.
  1160. */
  1161. if (tblk->xflag & COMMIT_FORCE)
  1162. txUpdateMap(tblk);
  1163. /*
  1164. * free transaction locks and pageout/free pages
  1165. */
  1166. txRelease(tblk);
  1167. if ((tblk->flag & tblkGC_LAZY) == 0)
  1168. txUnlock(tblk);
  1169. /*
  1170. * reset in-memory object state
  1171. */
  1172. for (k = 0; k < cd.nip; k++) {
  1173. ip = cd.iplist[k];
  1174. jfs_ip = JFS_IP(ip);
  1175. /*
  1176. * reset in-memory inode state
  1177. */
  1178. jfs_ip->bxflag = 0;
  1179. jfs_ip->blid = 0;
  1180. }
  1181. out:
  1182. if (rc != 0)
  1183. txAbort(tid, 1);
  1184. TheEnd:
  1185. jfs_info("txCommit: tid = %d, returning %d", tid, rc);
  1186. return rc;
  1187. }
  1188. /*
  1189. * NAME: txLog()
  1190. *
  1191. * FUNCTION: Writes AFTER log records for all lines modified
  1192. * by tid for segments specified by inodes in comdata.
  1193. * Code assumes only WRITELOCKS are recorded in lockwords.
  1194. *
  1195. * PARAMETERS:
  1196. *
  1197. * RETURN :
  1198. */
  1199. static int txLog(struct jfs_log * log, struct tblock * tblk, struct commit * cd)
  1200. {
  1201. int rc = 0;
  1202. struct inode *ip;
  1203. lid_t lid;
  1204. struct tlock *tlck;
  1205. struct lrd *lrd = &cd->lrd;
  1206. /*
  1207. * write log record(s) for each tlock of transaction,
  1208. */
  1209. for (lid = tblk->next; lid; lid = tlck->next) {
  1210. tlck = lid_to_tlock(lid);
  1211. tlck->flag |= tlckLOG;
  1212. /* initialize lrd common */
  1213. ip = tlck->ip;
  1214. lrd->aggregate = cpu_to_le32(JFS_SBI(ip->i_sb)->aggregate);
  1215. lrd->log.redopage.fileset = cpu_to_le32(JFS_IP(ip)->fileset);
  1216. lrd->log.redopage.inode = cpu_to_le32(ip->i_ino);
  1217. /* write log record of page from the tlock */
  1218. switch (tlck->type & tlckTYPE) {
  1219. case tlckXTREE:
  1220. xtLog(log, tblk, lrd, tlck);
  1221. break;
  1222. case tlckDTREE:
  1223. dtLog(log, tblk, lrd, tlck);
  1224. break;
  1225. case tlckINODE:
  1226. diLog(log, tblk, lrd, tlck, cd);
  1227. break;
  1228. case tlckMAP:
  1229. mapLog(log, tblk, lrd, tlck);
  1230. break;
  1231. case tlckDATA:
  1232. dataLog(log, tblk, lrd, tlck);
  1233. break;
  1234. default:
  1235. jfs_err("UFO tlock:0x%p", tlck);
  1236. }
  1237. }
  1238. return rc;
  1239. }
  1240. /*
  1241. * diLog()
  1242. *
  1243. * function: log inode tlock and format maplock to update bmap;
  1244. */
  1245. static int diLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
  1246. struct tlock * tlck, struct commit * cd)
  1247. {
  1248. int rc = 0;
  1249. struct metapage *mp;
  1250. pxd_t *pxd;
  1251. struct pxd_lock *pxdlock;
  1252. mp = tlck->mp;
  1253. /* initialize as REDOPAGE record format */
  1254. lrd->log.redopage.type = cpu_to_le16(LOG_INODE);
  1255. lrd->log.redopage.l2linesize = cpu_to_le16(L2INODESLOTSIZE);
  1256. pxd = &lrd->log.redopage.pxd;
  1257. /*
  1258. * inode after image
  1259. */
  1260. if (tlck->type & tlckENTRY) {
  1261. /* log after-image for logredo(): */
  1262. lrd->type = cpu_to_le16(LOG_REDOPAGE);
  1263. PXDaddress(pxd, mp->index);
  1264. PXDlength(pxd,
  1265. mp->logical_size >> tblk->sb->s_blocksize_bits);
  1266. lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, tlck));
  1267. /* mark page as homeward bound */
  1268. tlck->flag |= tlckWRITEPAGE;
  1269. } else if (tlck->type & tlckFREE) {
  1270. /*
  1271. * free inode extent
  1272. *
  1273. * (pages of the freed inode extent have been invalidated and
  1274. * a maplock for free of the extent has been formatted at
  1275. * txLock() time);
  1276. *
  1277. * the tlock had been acquired on the inode allocation map page
  1278. * (iag) that specifies the freed extent, even though the map
  1279. * page is not itself logged, to prevent pageout of the map
  1280. * page before the log;
  1281. */
  1282. /* log LOG_NOREDOINOEXT of the freed inode extent for
  1283. * logredo() to start NoRedoPage filters, and to update
  1284. * imap and bmap for free of the extent;
  1285. */
  1286. lrd->type = cpu_to_le16(LOG_NOREDOINOEXT);
  1287. /*
  1288. * For the LOG_NOREDOINOEXT record, we need
  1289. * to pass the IAG number and inode extent
  1290. * index (within that IAG) from which the
  1291. * the extent being released. These have been
  1292. * passed to us in the iplist[1] and iplist[2].
  1293. */
  1294. lrd->log.noredoinoext.iagnum =
  1295. cpu_to_le32((u32) (size_t) cd->iplist[1]);
  1296. lrd->log.noredoinoext.inoext_idx =
  1297. cpu_to_le32((u32) (size_t) cd->iplist[2]);
  1298. pxdlock = (struct pxd_lock *) & tlck->lock;
  1299. *pxd = pxdlock->pxd;
  1300. lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, NULL));
  1301. /* update bmap */
  1302. tlck->flag |= tlckUPDATEMAP;
  1303. /* mark page as homeward bound */
  1304. tlck->flag |= tlckWRITEPAGE;
  1305. } else
  1306. jfs_err("diLog: UFO type tlck:0x%p", tlck);
  1307. #ifdef _JFS_WIP
  1308. /*
  1309. * alloc/free external EA extent
  1310. *
  1311. * a maplock for txUpdateMap() to update bPWMAP for alloc/free
  1312. * of the extent has been formatted at txLock() time;
  1313. */
  1314. else {
  1315. assert(tlck->type & tlckEA);
  1316. /* log LOG_UPDATEMAP for logredo() to update bmap for
  1317. * alloc of new (and free of old) external EA extent;
  1318. */
  1319. lrd->type = cpu_to_le16(LOG_UPDATEMAP);
  1320. pxdlock = (struct pxd_lock *) & tlck->lock;
  1321. nlock = pxdlock->index;
  1322. for (i = 0; i < nlock; i++, pxdlock++) {
  1323. if (pxdlock->flag & mlckALLOCPXD)
  1324. lrd->log.updatemap.type =
  1325. cpu_to_le16(LOG_ALLOCPXD);
  1326. else
  1327. lrd->log.updatemap.type =
  1328. cpu_to_le16(LOG_FREEPXD);
  1329. lrd->log.updatemap.nxd = cpu_to_le16(1);
  1330. lrd->log.updatemap.pxd = pxdlock->pxd;
  1331. lrd->backchain =
  1332. cpu_to_le32(lmLog(log, tblk, lrd, NULL));
  1333. }
  1334. /* update bmap */
  1335. tlck->flag |= tlckUPDATEMAP;
  1336. }
  1337. #endif /* _JFS_WIP */
  1338. return rc;
  1339. }
  1340. /*
  1341. * dataLog()
  1342. *
  1343. * function: log data tlock
  1344. */
  1345. static int dataLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
  1346. struct tlock * tlck)
  1347. {
  1348. struct metapage *mp;
  1349. pxd_t *pxd;
  1350. mp = tlck->mp;
  1351. /* initialize as REDOPAGE record format */
  1352. lrd->log.redopage.type = cpu_to_le16(LOG_DATA);
  1353. lrd->log.redopage.l2linesize = cpu_to_le16(L2DATASLOTSIZE);
  1354. pxd = &lrd->log.redopage.pxd;
  1355. /* log after-image for logredo(): */
  1356. lrd->type = cpu_to_le16(LOG_REDOPAGE);
  1357. if (jfs_dirtable_inline(tlck->ip)) {
  1358. /*
  1359. * The table has been truncated, we've must have deleted
  1360. * the last entry, so don't bother logging this
  1361. */
  1362. mp->lid = 0;
  1363. grab_metapage(mp);
  1364. metapage_homeok(mp);
  1365. discard_metapage(mp);
  1366. tlck->mp = NULL;
  1367. return 0;
  1368. }
  1369. PXDaddress(pxd, mp->index);
  1370. PXDlength(pxd, mp->logical_size >> tblk->sb->s_blocksize_bits);
  1371. lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, tlck));
  1372. /* mark page as homeward bound */
  1373. tlck->flag |= tlckWRITEPAGE;
  1374. return 0;
  1375. }
  1376. /*
  1377. * dtLog()
  1378. *
  1379. * function: log dtree tlock and format maplock to update bmap;
  1380. */
  1381. static void dtLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
  1382. struct tlock * tlck)
  1383. {
  1384. struct metapage *mp;
  1385. struct pxd_lock *pxdlock;
  1386. pxd_t *pxd;
  1387. mp = tlck->mp;
  1388. /* initialize as REDOPAGE/NOREDOPAGE record format */
  1389. lrd->log.redopage.type = cpu_to_le16(LOG_DTREE);
  1390. lrd->log.redopage.l2linesize = cpu_to_le16(L2DTSLOTSIZE);
  1391. pxd = &lrd->log.redopage.pxd;
  1392. if (tlck->type & tlckBTROOT)
  1393. lrd->log.redopage.type |= cpu_to_le16(LOG_BTROOT);
  1394. /*
  1395. * page extension via relocation: entry insertion;
  1396. * page extension in-place: entry insertion;
  1397. * new right page from page split, reinitialized in-line
  1398. * root from root page split: entry insertion;
  1399. */
  1400. if (tlck->type & (tlckNEW | tlckEXTEND)) {
  1401. /* log after-image of the new page for logredo():
  1402. * mark log (LOG_NEW) for logredo() to initialize
  1403. * freelist and update bmap for alloc of the new page;
  1404. */
  1405. lrd->type = cpu_to_le16(LOG_REDOPAGE);
  1406. if (tlck->type & tlckEXTEND)
  1407. lrd->log.redopage.type |= cpu_to_le16(LOG_EXTEND);
  1408. else
  1409. lrd->log.redopage.type |= cpu_to_le16(LOG_NEW);
  1410. PXDaddress(pxd, mp->index);
  1411. PXDlength(pxd,
  1412. mp->logical_size >> tblk->sb->s_blocksize_bits);
  1413. lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, tlck));
  1414. /* format a maplock for txUpdateMap() to update bPMAP for
  1415. * alloc of the new page;
  1416. */
  1417. if (tlck->type & tlckBTROOT)
  1418. return;
  1419. tlck->flag |= tlckUPDATEMAP;
  1420. pxdlock = (struct pxd_lock *) & tlck->lock;
  1421. pxdlock->flag = mlckALLOCPXD;
  1422. pxdlock->pxd = *pxd;
  1423. pxdlock->index = 1;
  1424. /* mark page as homeward bound */
  1425. tlck->flag |= tlckWRITEPAGE;
  1426. return;
  1427. }
  1428. /*
  1429. * entry insertion/deletion,
  1430. * sibling page link update (old right page before split);
  1431. */
  1432. if (tlck->type & (tlckENTRY | tlckRELINK)) {
  1433. /* log after-image for logredo(): */
  1434. lrd->type = cpu_to_le16(LOG_REDOPAGE);
  1435. PXDaddress(pxd, mp->index);
  1436. PXDlength(pxd,
  1437. mp->logical_size >> tblk->sb->s_blocksize_bits);
  1438. lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, tlck));
  1439. /* mark page as homeward bound */
  1440. tlck->flag |= tlckWRITEPAGE;
  1441. return;
  1442. }
  1443. /*
  1444. * page deletion: page has been invalidated
  1445. * page relocation: source extent
  1446. *
  1447. * a maplock for free of the page has been formatted
  1448. * at txLock() time);
  1449. */
  1450. if (tlck->type & (tlckFREE | tlckRELOCATE)) {
  1451. /* log LOG_NOREDOPAGE of the deleted page for logredo()
  1452. * to start NoRedoPage filter and to update bmap for free
  1453. * of the deletd page
  1454. */
  1455. lrd->type = cpu_to_le16(LOG_NOREDOPAGE);
  1456. pxdlock = (struct pxd_lock *) & tlck->lock;
  1457. *pxd = pxdlock->pxd;
  1458. lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, NULL));
  1459. /* a maplock for txUpdateMap() for free of the page
  1460. * has been formatted at txLock() time;
  1461. */
  1462. tlck->flag |= tlckUPDATEMAP;
  1463. }
  1464. return;
  1465. }
  1466. /*
  1467. * xtLog()
  1468. *
  1469. * function: log xtree tlock and format maplock to update bmap;
  1470. */
  1471. static void xtLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
  1472. struct tlock * tlck)
  1473. {
  1474. struct inode *ip;
  1475. struct metapage *mp;
  1476. xtpage_t *p;
  1477. struct xtlock *xtlck;
  1478. struct maplock *maplock;
  1479. struct xdlistlock *xadlock;
  1480. struct pxd_lock *pxdlock;
  1481. pxd_t *page_pxd;
  1482. int next, lwm, hwm;
  1483. ip = tlck->ip;
  1484. mp = tlck->mp;
  1485. /* initialize as REDOPAGE/NOREDOPAGE record format */
  1486. lrd->log.redopage.type = cpu_to_le16(LOG_XTREE);
  1487. lrd->log.redopage.l2linesize = cpu_to_le16(L2XTSLOTSIZE);
  1488. page_pxd = &lrd->log.redopage.pxd;
  1489. if (tlck->type & tlckBTROOT) {
  1490. lrd->log.redopage.type |= cpu_to_le16(LOG_BTROOT);
  1491. p = &JFS_IP(ip)->i_xtroot;
  1492. if (S_ISDIR(ip->i_mode))
  1493. lrd->log.redopage.type |=
  1494. cpu_to_le16(LOG_DIR_XTREE);
  1495. } else
  1496. p = (xtpage_t *) mp->data;
  1497. next = le16_to_cpu(p->header.nextindex);
  1498. xtlck = (struct xtlock *) & tlck->lock;
  1499. maplock = (struct maplock *) & tlck->lock;
  1500. xadlock = (struct xdlistlock *) maplock;
  1501. /*
  1502. * entry insertion/extension;
  1503. * sibling page link update (old right page before split);
  1504. */
  1505. if (tlck->type & (tlckNEW | tlckGROW | tlckRELINK)) {
  1506. /* log after-image for logredo():
  1507. * logredo() will update bmap for alloc of new/extended
  1508. * extents (XAD_NEW|XAD_EXTEND) of XAD[lwm:next) from
  1509. * after-image of XADlist;
  1510. * logredo() resets (XAD_NEW|XAD_EXTEND) flag when
  1511. * applying the after-image to the meta-data page.
  1512. */
  1513. lrd->type = cpu_to_le16(LOG_REDOPAGE);
  1514. PXDaddress(page_pxd, mp->index);
  1515. PXDlength(page_pxd,
  1516. mp->logical_size >> tblk->sb->s_blocksize_bits);
  1517. lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, tlck));
  1518. /* format a maplock for txUpdateMap() to update bPMAP
  1519. * for alloc of new/extended extents of XAD[lwm:next)
  1520. * from the page itself;
  1521. * txUpdateMap() resets (XAD_NEW|XAD_EXTEND) flag.
  1522. */
  1523. lwm = xtlck->lwm.offset;
  1524. if (lwm == 0)
  1525. lwm = XTPAGEMAXSLOT;
  1526. if (lwm == next)
  1527. goto out;
  1528. if (lwm > next) {
  1529. jfs_err("xtLog: lwm > next\n");
  1530. goto out;
  1531. }
  1532. tlck->flag |= tlckUPDATEMAP;
  1533. xadlock->flag = mlckALLOCXADLIST;
  1534. xadlock->count = next - lwm;
  1535. if ((xadlock->count <= 4) && (tblk->xflag & COMMIT_LAZY)) {
  1536. int i;
  1537. pxd_t *pxd;
  1538. /*
  1539. * Lazy commit may allow xtree to be modified before
  1540. * txUpdateMap runs. Copy xad into linelock to
  1541. * preserve correct data.
  1542. *
  1543. * We can fit twice as may pxd's as xads in the lock
  1544. */
  1545. xadlock->flag = mlckALLOCPXDLIST;
  1546. pxd = xadlock->xdlist = &xtlck->pxdlock;
  1547. for (i = 0; i < xadlock->count; i++) {
  1548. PXDaddress(pxd, addressXAD(&p->xad[lwm + i]));
  1549. PXDlength(pxd, lengthXAD(&p->xad[lwm + i]));
  1550. p->xad[lwm + i].flag &=
  1551. ~(XAD_NEW | XAD_EXTENDED);
  1552. pxd++;
  1553. }
  1554. } else {
  1555. /*
  1556. * xdlist will point to into inode's xtree, ensure
  1557. * that transaction is not committed lazily.
  1558. */
  1559. xadlock->flag = mlckALLOCXADLIST;
  1560. xadlock->xdlist = &p->xad[lwm];
  1561. tblk->xflag &= ~COMMIT_LAZY;
  1562. }
  1563. jfs_info("xtLog: alloc ip:0x%p mp:0x%p tlck:0x%p lwm:%d "
  1564. "count:%d", tlck->ip, mp, tlck, lwm, xadlock->count);
  1565. maplock->index = 1;
  1566. out:
  1567. /* mark page as homeward bound */
  1568. tlck->flag |= tlckWRITEPAGE;
  1569. return;
  1570. }
  1571. /*
  1572. * page deletion: file deletion/truncation (ref. xtTruncate())
  1573. *
  1574. * (page will be invalidated after log is written and bmap
  1575. * is updated from the page);
  1576. */
  1577. if (tlck->type & tlckFREE) {
  1578. /* LOG_NOREDOPAGE log for NoRedoPage filter:
  1579. * if page free from file delete, NoRedoFile filter from
  1580. * inode image of zero link count will subsume NoRedoPage
  1581. * filters for each page;
  1582. * if page free from file truncattion, write NoRedoPage
  1583. * filter;
  1584. *
  1585. * upadte of block allocation map for the page itself:
  1586. * if page free from deletion and truncation, LOG_UPDATEMAP
  1587. * log for the page itself is generated from processing
  1588. * its parent page xad entries;
  1589. */
  1590. /* if page free from file truncation, log LOG_NOREDOPAGE
  1591. * of the deleted page for logredo() to start NoRedoPage
  1592. * filter for the page;
  1593. */
  1594. if (tblk->xflag & COMMIT_TRUNCATE) {
  1595. /* write NOREDOPAGE for the page */
  1596. lrd->type = cpu_to_le16(LOG_NOREDOPAGE);
  1597. PXDaddress(page_pxd, mp->index);
  1598. PXDlength(page_pxd,
  1599. mp->logical_size >> tblk->sb->
  1600. s_blocksize_bits);
  1601. lrd->backchain =
  1602. cpu_to_le32(lmLog(log, tblk, lrd, NULL));
  1603. if (tlck->type & tlckBTROOT) {
  1604. /* Empty xtree must be logged */
  1605. lrd->type = cpu_to_le16(LOG_REDOPAGE);
  1606. lrd->backchain =
  1607. cpu_to_le32(lmLog(log, tblk, lrd, tlck));
  1608. }
  1609. }
  1610. /* init LOG_UPDATEMAP of the freed extents
  1611. * XAD[XTENTRYSTART:hwm) from the deleted page itself
  1612. * for logredo() to update bmap;
  1613. */
  1614. lrd->type = cpu_to_le16(LOG_UPDATEMAP);
  1615. lrd->log.updatemap.type = cpu_to_le16(LOG_FREEXADLIST);
  1616. xtlck = (struct xtlock *) & tlck->lock;
  1617. hwm = xtlck->hwm.offset;
  1618. lrd->log.updatemap.nxd =
  1619. cpu_to_le16(hwm - XTENTRYSTART + 1);
  1620. /* reformat linelock for lmLog() */
  1621. xtlck->header.offset = XTENTRYSTART;
  1622. xtlck->header.length = hwm - XTENTRYSTART + 1;
  1623. xtlck->index = 1;
  1624. lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, tlck));
  1625. /* format a maplock for txUpdateMap() to update bmap
  1626. * to free extents of XAD[XTENTRYSTART:hwm) from the
  1627. * deleted page itself;
  1628. */
  1629. tlck->flag |= tlckUPDATEMAP;
  1630. xadlock->count = hwm - XTENTRYSTART + 1;
  1631. if ((xadlock->count <= 4) && (tblk->xflag & COMMIT_LAZY)) {
  1632. int i;
  1633. pxd_t *pxd;
  1634. /*
  1635. * Lazy commit may allow xtree to be modified before
  1636. * txUpdateMap runs. Copy xad into linelock to
  1637. * preserve correct data.
  1638. *
  1639. * We can fit twice as may pxd's as xads in the lock
  1640. */
  1641. xadlock->flag = mlckFREEPXDLIST;
  1642. pxd = xadlock->xdlist = &xtlck->pxdlock;
  1643. for (i = 0; i < xadlock->count; i++) {
  1644. PXDaddress(pxd,
  1645. addressXAD(&p->xad[XTENTRYSTART + i]));
  1646. PXDlength(pxd,
  1647. lengthXAD(&p->xad[XTENTRYSTART + i]));
  1648. pxd++;
  1649. }
  1650. } else {
  1651. /*
  1652. * xdlist will point to into inode's xtree, ensure
  1653. * that transaction is not committed lazily.
  1654. */
  1655. xadlock->flag = mlckFREEXADLIST;
  1656. xadlock->xdlist = &p->xad[XTENTRYSTART];
  1657. tblk->xflag &= ~COMMIT_LAZY;
  1658. }
  1659. jfs_info("xtLog: free ip:0x%p mp:0x%p count:%d lwm:2",
  1660. tlck->ip, mp, xadlock->count);
  1661. maplock->index = 1;
  1662. /* mark page as invalid */
  1663. if (((tblk->xflag & COMMIT_PWMAP) || S_ISDIR(ip->i_mode))
  1664. && !(tlck->type & tlckBTROOT))
  1665. tlck->flag |= tlckFREEPAGE;
  1666. /*
  1667. else (tblk->xflag & COMMIT_PMAP)
  1668. ? release the page;
  1669. */
  1670. return;
  1671. }
  1672. /*
  1673. * page/entry truncation: file truncation (ref. xtTruncate())
  1674. *
  1675. * |----------+------+------+---------------|
  1676. * | | |
  1677. * | | hwm - hwm before truncation
  1678. * | next - truncation point
  1679. * lwm - lwm before truncation
  1680. * header ?
  1681. */
  1682. if (tlck->type & tlckTRUNCATE) {
  1683. /* This odd declaration suppresses a bogus gcc warning */
  1684. pxd_t pxd = pxd; /* truncated extent of xad */
  1685. int twm;
  1686. /*
  1687. * For truncation the entire linelock may be used, so it would
  1688. * be difficult to store xad list in linelock itself.
  1689. * Therefore, we'll just force transaction to be committed
  1690. * synchronously, so that xtree pages won't be changed before
  1691. * txUpdateMap runs.
  1692. */
  1693. tblk->xflag &= ~COMMIT_LAZY;
  1694. lwm = xtlck->lwm.offset;
  1695. if (lwm == 0)
  1696. lwm = XTPAGEMAXSLOT;
  1697. hwm = xtlck->hwm.offset;
  1698. twm = xtlck->twm.offset;
  1699. /*
  1700. * write log records
  1701. */
  1702. /* log after-image for logredo():
  1703. *
  1704. * logredo() will update bmap for alloc of new/extended
  1705. * extents (XAD_NEW|XAD_EXTEND) of XAD[lwm:next) from
  1706. * after-image of XADlist;
  1707. * logredo() resets (XAD_NEW|XAD_EXTEND) flag when
  1708. * applying the after-image to the meta-data page.
  1709. */
  1710. lrd->type = cpu_to_le16(LOG_REDOPAGE);
  1711. PXDaddress(page_pxd, mp->index);
  1712. PXDlength(page_pxd,
  1713. mp->logical_size >> tblk->sb->s_blocksize_bits);
  1714. lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, tlck));
  1715. /*
  1716. * truncate entry XAD[twm == next - 1]:
  1717. */
  1718. if (twm == next - 1) {
  1719. /* init LOG_UPDATEMAP for logredo() to update bmap for
  1720. * free of truncated delta extent of the truncated
  1721. * entry XAD[next - 1]:
  1722. * (xtlck->pxdlock = truncated delta extent);
  1723. */
  1724. pxdlock = (struct pxd_lock *) & xtlck->pxdlock;
  1725. /* assert(pxdlock->type & tlckTRUNCATE); */
  1726. lrd->type = cpu_to_le16(LOG_UPDATEMAP);
  1727. lrd->log.updatemap.type = cpu_to_le16(LOG_FREEPXD);
  1728. lrd->log.updatemap.nxd = cpu_to_le16(1);
  1729. lrd->log.updatemap.pxd = pxdlock->pxd;
  1730. pxd = pxdlock->pxd; /* save to format maplock */
  1731. lrd->backchain =
  1732. cpu_to_le32(lmLog(log, tblk, lrd, NULL));
  1733. }
  1734. /*
  1735. * free entries XAD[next:hwm]:
  1736. */
  1737. if (hwm >= next) {
  1738. /* init LOG_UPDATEMAP of the freed extents
  1739. * XAD[next:hwm] from the deleted page itself
  1740. * for logredo() to update bmap;
  1741. */
  1742. lrd->type = cpu_to_le16(LOG_UPDATEMAP);
  1743. lrd->log.updatemap.type =
  1744. cpu_to_le16(LOG_FREEXADLIST);
  1745. xtlck = (struct xtlock *) & tlck->lock;
  1746. hwm = xtlck->hwm.offset;
  1747. lrd->log.updatemap.nxd =
  1748. cpu_to_le16(hwm - next + 1);
  1749. /* reformat linelock for lmLog() */
  1750. xtlck->header.offset = next;
  1751. xtlck->header.length = hwm - next + 1;
  1752. xtlck->index = 1;
  1753. lrd->backchain =
  1754. cpu_to_le32(lmLog(log, tblk, lrd, tlck));
  1755. }
  1756. /*
  1757. * format maplock(s) for txUpdateMap() to update bmap
  1758. */
  1759. maplock->index = 0;
  1760. /*
  1761. * allocate entries XAD[lwm:next):
  1762. */
  1763. if (lwm < next) {
  1764. /* format a maplock for txUpdateMap() to update bPMAP
  1765. * for alloc of new/extended extents of XAD[lwm:next)
  1766. * from the page itself;
  1767. * txUpdateMap() resets (XAD_NEW|XAD_EXTEND) flag.
  1768. */
  1769. tlck->flag |= tlckUPDATEMAP;
  1770. xadlock->flag = mlckALLOCXADLIST;
  1771. xadlock->count = next - lwm;
  1772. xadlock->xdlist = &p->xad[lwm];
  1773. jfs_info("xtLog: alloc ip:0x%p mp:0x%p count:%d "
  1774. "lwm:%d next:%d",
  1775. tlck->ip, mp, xadlock->count, lwm, next);
  1776. maplock->index++;
  1777. xadlock++;
  1778. }
  1779. /*
  1780. * truncate entry XAD[twm == next - 1]:
  1781. */
  1782. if (twm == next - 1) {
  1783. /* format a maplock for txUpdateMap() to update bmap
  1784. * to free truncated delta extent of the truncated
  1785. * entry XAD[next - 1];
  1786. * (xtlck->pxdlock = truncated delta extent);
  1787. */
  1788. tlck->flag |= tlckUPDATEMAP;
  1789. pxdlock = (struct pxd_lock *) xadlock;
  1790. pxdlock->flag = mlckFREEPXD;
  1791. pxdlock->count = 1;
  1792. pxdlock->pxd = pxd;
  1793. jfs_info("xtLog: truncate ip:0x%p mp:0x%p count:%d "
  1794. "hwm:%d", ip, mp, pxdlock->count, hwm);
  1795. maplock->index++;
  1796. xadlock++;
  1797. }
  1798. /*
  1799. * free entries XAD[next:hwm]:
  1800. */
  1801. if (hwm >= next) {
  1802. /* format a maplock for txUpdateMap() to update bmap
  1803. * to free extents of XAD[next:hwm] from thedeleted
  1804. * page itself;
  1805. */
  1806. tlck->flag |= tlckUPDATEMAP;
  1807. xadlock->flag = mlckFREEXADLIST;
  1808. xadlock->count = hwm - next + 1;
  1809. xadlock->xdlist = &p->xad[next];
  1810. jfs_info("xtLog: free ip:0x%p mp:0x%p count:%d "
  1811. "next:%d hwm:%d",
  1812. tlck->ip, mp, xadlock->count, next, hwm);
  1813. maplock->index++;
  1814. }
  1815. /* mark page as homeward bound */
  1816. tlck->flag |= tlckWRITEPAGE;
  1817. }
  1818. return;
  1819. }
  1820. /*
  1821. * mapLog()
  1822. *
  1823. * function: log from maplock of freed data extents;
  1824. */
  1825. static void mapLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
  1826. struct tlock * tlck)
  1827. {
  1828. struct pxd_lock *pxdlock;
  1829. int i, nlock;
  1830. pxd_t *pxd;
  1831. /*
  1832. * page relocation: free the source page extent
  1833. *
  1834. * a maplock for txUpdateMap() for free of the page
  1835. * has been formatted at txLock() time saving the src
  1836. * relocated page address;
  1837. */
  1838. if (tlck->type & tlckRELOCATE) {
  1839. /* log LOG_NOREDOPAGE of the old relocated page
  1840. * for logredo() to start NoRedoPage filter;
  1841. */
  1842. lrd->type = cpu_to_le16(LOG_NOREDOPAGE);
  1843. pxdlock = (struct pxd_lock *) & tlck->lock;
  1844. pxd = &lrd->log.redopage.pxd;
  1845. *pxd = pxdlock->pxd;
  1846. lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, NULL));
  1847. /* (N.B. currently, logredo() does NOT update bmap
  1848. * for free of the page itself for (LOG_XTREE|LOG_NOREDOPAGE);
  1849. * if page free from relocation, LOG_UPDATEMAP log is
  1850. * specifically generated now for logredo()
  1851. * to update bmap for free of src relocated page;
  1852. * (new flag LOG_RELOCATE may be introduced which will
  1853. * inform logredo() to start NORedoPage filter and also
  1854. * update block allocation map at the same time, thus
  1855. * avoiding an extra log write);
  1856. */
  1857. lrd->type = cpu_to_le16(LOG_UPDATEMAP);
  1858. lrd->log.updatemap.type = cpu_to_le16(LOG_FREEPXD);
  1859. lrd->log.updatemap.nxd = cpu_to_le16(1);
  1860. lrd->log.updatemap.pxd = pxdlock->pxd;
  1861. lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, NULL));
  1862. /* a maplock for txUpdateMap() for free of the page
  1863. * has been formatted at txLock() time;
  1864. */
  1865. tlck->flag |= tlckUPDATEMAP;
  1866. return;
  1867. }
  1868. /*
  1869. * Otherwise it's not a relocate request
  1870. *
  1871. */
  1872. else {
  1873. /* log LOG_UPDATEMAP for logredo() to update bmap for
  1874. * free of truncated/relocated delta extent of the data;
  1875. * e.g.: external EA extent, relocated/truncated extent
  1876. * from xtTailgate();
  1877. */
  1878. lrd->type = cpu_to_le16(LOG_UPDATEMAP);
  1879. pxdlock = (struct pxd_lock *) & tlck->lock;
  1880. nlock = pxdlock->index;
  1881. for (i = 0; i < nlock; i++, pxdlock++) {
  1882. if (pxdlock->flag & mlckALLOCPXD)
  1883. lrd->log.updatemap.type =
  1884. cpu_to_le16(LOG_ALLOCPXD);
  1885. else
  1886. lrd->log.updatemap.type =
  1887. cpu_to_le16(LOG_FREEPXD);
  1888. lrd->log.updatemap.nxd = cpu_to_le16(1);
  1889. lrd->log.updatemap.pxd = pxdlock->pxd;
  1890. lrd->backchain =
  1891. cpu_to_le32(lmLog(log, tblk, lrd, NULL));
  1892. jfs_info("mapLog: xaddr:0x%lx xlen:0x%x",
  1893. (ulong) addressPXD(&pxdlock->pxd),
  1894. lengthPXD(&pxdlock->pxd));
  1895. }
  1896. /* update bmap */
  1897. tlck->flag |= tlckUPDATEMAP;
  1898. }
  1899. }
  1900. /*
  1901. * txEA()
  1902. *
  1903. * function: acquire maplock for EA/ACL extents or
  1904. * set COMMIT_INLINE flag;
  1905. */
  1906. void txEA(tid_t tid, struct inode *ip, dxd_t * oldea, dxd_t * newea)
  1907. {
  1908. struct tlock *tlck = NULL;
  1909. struct pxd_lock *maplock = NULL, *pxdlock = NULL;
  1910. /*
  1911. * format maplock for alloc of new EA extent
  1912. */
  1913. if (newea) {
  1914. /* Since the newea could be a completely zeroed entry we need to
  1915. * check for the two flags which indicate we should actually
  1916. * commit new EA data
  1917. */
  1918. if (newea->flag & DXD_EXTENT) {
  1919. tlck = txMaplock(tid, ip, tlckMAP);
  1920. maplock = (struct pxd_lock *) & tlck->lock;
  1921. pxdlock = (struct pxd_lock *) maplock;
  1922. pxdlock->flag = mlckALLOCPXD;
  1923. PXDaddress(&pxdlock->pxd, addressDXD(newea));
  1924. PXDlength(&pxdlock->pxd, lengthDXD(newea));
  1925. pxdlock++;
  1926. maplock->index = 1;
  1927. } else if (newea->flag & DXD_INLINE) {
  1928. tlck = NULL;
  1929. set_cflag(COMMIT_Inlineea, ip);
  1930. }
  1931. }
  1932. /*
  1933. * format maplock for free of old EA extent
  1934. */
  1935. if (!test_cflag(COMMIT_Nolink, ip) && oldea->flag & DXD_EXTENT) {
  1936. if (tlck == NULL) {
  1937. tlck = txMaplock(tid, ip, tlckMAP);
  1938. maplock = (struct pxd_lock *) & tlck->lock;
  1939. pxdlock = (struct pxd_lock *) maplock;
  1940. maplock->index = 0;
  1941. }
  1942. pxdlock->flag = mlckFREEPXD;
  1943. PXDaddress(&pxdlock->pxd, addressDXD(oldea));
  1944. PXDlength(&pxdlock->pxd, lengthDXD(oldea));
  1945. maplock->index++;
  1946. }
  1947. }
  1948. /*
  1949. * txForce()
  1950. *
  1951. * function: synchronously write pages locked by transaction
  1952. * after txLog() but before txUpdateMap();
  1953. */
  1954. static void txForce(struct tblock * tblk)
  1955. {
  1956. struct tlock *tlck;
  1957. lid_t lid, next;
  1958. struct metapage *mp;
  1959. /*
  1960. * reverse the order of transaction tlocks in
  1961. * careful update order of address index pages
  1962. * (right to left, bottom up)
  1963. */
  1964. tlck = lid_to_tlock(tblk->next);
  1965. lid = tlck->next;
  1966. tlck->next = 0;
  1967. while (lid) {
  1968. tlck = lid_to_tlock(lid);
  1969. next = tlck->next;
  1970. tlck->next = tblk->next;
  1971. tblk->next = lid;
  1972. lid = next;
  1973. }
  1974. /*
  1975. * synchronously write the page, and
  1976. * hold the page for txUpdateMap();
  1977. */
  1978. for (lid = tblk->next; lid; lid = next) {
  1979. tlck = lid_to_tlock(lid);
  1980. next = tlck->next;
  1981. if ((mp = tlck->mp) != NULL &&
  1982. (tlck->type & tlckBTROOT) == 0) {
  1983. assert(mp->xflag & COMMIT_PAGE);
  1984. if (tlck->flag & tlckWRITEPAGE) {
  1985. tlck->flag &= ~tlckWRITEPAGE;
  1986. /* do not release page to freelist */
  1987. force_metapage(mp);
  1988. #if 0
  1989. /*
  1990. * The "right" thing to do here is to
  1991. * synchronously write the metadata.
  1992. * With the current implementation this
  1993. * is hard since write_metapage requires
  1994. * us to kunmap & remap the page. If we
  1995. * have tlocks pointing into the metadata
  1996. * pages, we don't want to do this. I think
  1997. * we can get by with synchronously writing
  1998. * the pages when they are released.
  1999. */
  2000. assert(mp->nohomeok);
  2001. set_bit(META_dirty, &mp->flag);
  2002. set_bit(META_sync, &mp->flag);
  2003. #endif
  2004. }
  2005. }
  2006. }
  2007. }
  2008. /*
  2009. * txUpdateMap()
  2010. *
  2011. * function: update persistent allocation map (and working map
  2012. * if appropriate);
  2013. *
  2014. * parameter:
  2015. */
  2016. static void txUpdateMap(struct tblock * tblk)
  2017. {
  2018. struct inode *ip;
  2019. struct inode *ipimap;
  2020. lid_t lid;
  2021. struct tlock *tlck;
  2022. struct maplock *maplock;
  2023. struct pxd_lock pxdlock;
  2024. int maptype;
  2025. int k, nlock;
  2026. struct metapage *mp = NULL;
  2027. ipimap = JFS_SBI(tblk->sb)->ipimap;
  2028. maptype = (tblk->xflag & COMMIT_PMAP) ? COMMIT_PMAP : COMMIT_PWMAP;
  2029. /*
  2030. * update block allocation map
  2031. *
  2032. * update allocation state in pmap (and wmap) and
  2033. * update lsn of the pmap page;
  2034. */
  2035. /*
  2036. * scan each tlock/page of transaction for block allocation/free:
  2037. *
  2038. * for each tlock/page of transaction, update map.
  2039. * ? are there tlock for pmap and pwmap at the same time ?
  2040. */
  2041. for (lid = tblk->next; lid; lid = tlck->next) {
  2042. tlck = lid_to_tlock(lid);
  2043. if ((tlck->flag & tlckUPDATEMAP) == 0)
  2044. continue;
  2045. if (tlck->flag & tlckFREEPAGE) {
  2046. /*
  2047. * Another thread may attempt to reuse freed space
  2048. * immediately, so we want to get rid of the metapage
  2049. * before anyone else has a chance to get it.
  2050. * Lock metapage, update maps, then invalidate
  2051. * the metapage.
  2052. */
  2053. mp = tlck->mp;
  2054. ASSERT(mp->xflag & COMMIT_PAGE);
  2055. grab_metapage(mp);
  2056. }
  2057. /*
  2058. * extent list:
  2059. * . in-line PXD list:
  2060. * . out-of-line XAD list:
  2061. */
  2062. maplock = (struct maplock *) & tlck->lock;
  2063. nlock = maplock->index;
  2064. for (k = 0; k < nlock; k++, maplock++) {
  2065. /*
  2066. * allocate blocks in persistent map:
  2067. *
  2068. * blocks have been allocated from wmap at alloc time;
  2069. */
  2070. if (maplock->flag & mlckALLOC) {
  2071. txAllocPMap(ipimap, maplock, tblk);
  2072. }
  2073. /*
  2074. * free blocks in persistent and working map:
  2075. * blocks will be freed in pmap and then in wmap;
  2076. *
  2077. * ? tblock specifies the PMAP/PWMAP based upon
  2078. * transaction
  2079. *
  2080. * free blocks in persistent map:
  2081. * blocks will be freed from wmap at last reference
  2082. * release of the object for regular files;
  2083. *
  2084. * Alway free blocks from both persistent & working
  2085. * maps for directories
  2086. */
  2087. else { /* (maplock->flag & mlckFREE) */
  2088. if (tlck->flag & tlckDIRECTORY)
  2089. txFreeMap(ipimap, maplock,
  2090. tblk, COMMIT_PWMAP);
  2091. else
  2092. txFreeMap(ipimap, maplock,
  2093. tblk, maptype);
  2094. }
  2095. }
  2096. if (tlck->flag & tlckFREEPAGE) {
  2097. if (!(tblk->flag & tblkGC_LAZY)) {
  2098. /* This is equivalent to txRelease */
  2099. ASSERT(mp->lid == lid);
  2100. tlck->mp->lid = 0;
  2101. }
  2102. assert(mp->nohomeok == 1);
  2103. metapage_homeok(mp);
  2104. discard_metapage(mp);
  2105. tlck->mp = NULL;
  2106. }
  2107. }
  2108. /*
  2109. * update inode allocation map
  2110. *
  2111. * update allocation state in pmap and
  2112. * update lsn of the pmap page;
  2113. * update in-memory inode flag/state
  2114. *
  2115. * unlock mapper/write lock
  2116. */
  2117. if (tblk->xflag & COMMIT_CREATE) {
  2118. diUpdatePMap(ipimap, tblk->ino, false, tblk);
  2119. /* update persistent block allocation map
  2120. * for the allocation of inode extent;
  2121. */
  2122. pxdlock.flag = mlckALLOCPXD;
  2123. pxdlock.pxd = tblk->u.ixpxd;
  2124. pxdlock.index = 1;
  2125. txAllocPMap(ipimap, (struct maplock *) & pxdlock, tblk);
  2126. } else if (tblk->xflag & COMMIT_DELETE) {
  2127. ip = tblk->u.ip;
  2128. diUpdatePMap(ipimap, ip->i_ino, true, tblk);
  2129. iput(ip);
  2130. }
  2131. }
  2132. /*
  2133. * txAllocPMap()
  2134. *
  2135. * function: allocate from persistent map;
  2136. *
  2137. * parameter:
  2138. * ipbmap -
  2139. * malock -
  2140. * xad list:
  2141. * pxd:
  2142. *
  2143. * maptype -
  2144. * allocate from persistent map;
  2145. * free from persistent map;
  2146. * (e.g., tmp file - free from working map at releae
  2147. * of last reference);
  2148. * free from persistent and working map;
  2149. *
  2150. * lsn - log sequence number;
  2151. */
  2152. static void txAllocPMap(struct inode *ip, struct maplock * maplock,
  2153. struct tblock * tblk)
  2154. {
  2155. struct inode *ipbmap = JFS_SBI(ip->i_sb)->ipbmap;
  2156. struct xdlistlock *xadlistlock;
  2157. xad_t *xad;
  2158. s64 xaddr;
  2159. int xlen;
  2160. struct pxd_lock *pxdlock;
  2161. struct xdlistlock *pxdlistlock;
  2162. pxd_t *pxd;
  2163. int n;
  2164. /*
  2165. * allocate from persistent map;
  2166. */
  2167. if (maplock->flag & mlckALLOCXADLIST) {
  2168. xadlistlock = (struct xdlistlock *) maplock;
  2169. xad = xadlistlock->xdlist;
  2170. for (n = 0; n < xadlistlock->count; n++, xad++) {
  2171. if (xad->flag & (XAD_NEW | XAD_EXTENDED)) {
  2172. xaddr = addressXAD(xad);
  2173. xlen = lengthXAD(xad);
  2174. dbUpdatePMap(ipbmap, false, xaddr,
  2175. (s64) xlen, tblk);
  2176. xad->flag &= ~(XAD_NEW | XAD_EXTENDED);
  2177. jfs_info("allocPMap: xaddr:0x%lx xlen:%d",
  2178. (ulong) xaddr, xlen);
  2179. }
  2180. }
  2181. } else if (maplock->flag & mlckALLOCPXD) {
  2182. pxdlock = (struct pxd_lock *) maplock;
  2183. xaddr = addressPXD(&pxdlock->pxd);
  2184. xlen = lengthPXD(&pxdlock->pxd);
  2185. dbUpdatePMap(ipbmap, false, xaddr, (s64) xlen, tblk);
  2186. jfs_info("allocPMap: xaddr:0x%lx xlen:%d", (ulong) xaddr, xlen);
  2187. } else { /* (maplock->flag & mlckALLOCPXDLIST) */
  2188. pxdlistlock = (struct xdlistlock *) maplock;
  2189. pxd = pxdlistlock->xdlist;
  2190. for (n = 0; n < pxdlistlock->count; n++, pxd++) {
  2191. xaddr = addressPXD(pxd);
  2192. xlen = lengthPXD(pxd);
  2193. dbUpdatePMap(ipbmap, false, xaddr, (s64) xlen,
  2194. tblk);
  2195. jfs_info("allocPMap: xaddr:0x%lx xlen:%d",
  2196. (ulong) xaddr, xlen);
  2197. }
  2198. }
  2199. }
  2200. /*
  2201. * txFreeMap()
  2202. *
  2203. * function: free from persistent and/or working map;
  2204. *
  2205. * todo: optimization
  2206. */
  2207. void txFreeMap(struct inode *ip,
  2208. struct maplock * maplock, struct tblock * tblk, int maptype)
  2209. {
  2210. struct inode *ipbmap = JFS_SBI(ip->i_sb)->ipbmap;
  2211. struct xdlistlock *xadlistlock;
  2212. xad_t *xad;
  2213. s64 xaddr;
  2214. int xlen;
  2215. struct pxd_lock *pxdlock;
  2216. struct xdlistlock *pxdlistlock;
  2217. pxd_t *pxd;
  2218. int n;
  2219. jfs_info("txFreeMap: tblk:0x%p maplock:0x%p maptype:0x%x",
  2220. tblk, maplock, maptype);
  2221. /*
  2222. * free from persistent map;
  2223. */
  2224. if (maptype == COMMIT_PMAP || maptype == COMMIT_PWMAP) {
  2225. if (maplock->flag & mlckFREEXADLIST) {
  2226. xadlistlock = (struct xdlistlock *) maplock;
  2227. xad = xadlistlock->xdlist;
  2228. for (n = 0; n < xadlistlock->count; n++, xad++) {
  2229. if (!(xad->flag & XAD_NEW)) {
  2230. xaddr = addressXAD(xad);
  2231. xlen = lengthXAD(xad);
  2232. dbUpdatePMap(ipbmap, true, xaddr,
  2233. (s64) xlen, tblk);
  2234. jfs_info("freePMap: xaddr:0x%lx "
  2235. "xlen:%d",
  2236. (ulong) xaddr, xlen);
  2237. }
  2238. }
  2239. } else if (maplock->flag & mlckFREEPXD) {
  2240. pxdlock = (struct pxd_lock *) maplock;
  2241. xaddr = addressPXD(&pxdlock->pxd);
  2242. xlen = lengthPXD(&pxdlock->pxd);
  2243. dbUpdatePMap(ipbmap, true, xaddr, (s64) xlen,
  2244. tblk);
  2245. jfs_info("freePMap: xaddr:0x%lx xlen:%d",
  2246. (ulong) xaddr, xlen);
  2247. } else { /* (maplock->flag & mlckALLOCPXDLIST) */
  2248. pxdlistlock = (struct xdlistlock *) maplock;
  2249. pxd = pxdlistlock->xdlist;
  2250. for (n = 0; n < pxdlistlock->count; n++, pxd++) {
  2251. xaddr = addressPXD(pxd);
  2252. xlen = lengthPXD(pxd);
  2253. dbUpdatePMap(ipbmap, true, xaddr,
  2254. (s64) xlen, tblk);
  2255. jfs_info("freePMap: xaddr:0x%lx xlen:%d",
  2256. (ulong) xaddr, xlen);
  2257. }
  2258. }
  2259. }
  2260. /*
  2261. * free from working map;
  2262. */
  2263. if (maptype == COMMIT_PWMAP || maptype == COMMIT_WMAP) {
  2264. if (maplock->flag & mlckFREEXADLIST) {
  2265. xadlistlock = (struct xdlistlock *) maplock;
  2266. xad = xadlistlock->xdlist;
  2267. for (n = 0; n < xadlistlock->count; n++, xad++) {
  2268. xaddr = addressXAD(xad);
  2269. xlen = lengthXAD(xad);
  2270. dbFree(ip, xaddr, (s64) xlen);
  2271. xad->flag = 0;
  2272. jfs_info("freeWMap: xaddr:0x%lx xlen:%d",
  2273. (ulong) xaddr, xlen);
  2274. }
  2275. } else if (maplock->flag & mlckFREEPXD) {
  2276. pxdlock = (struct pxd_lock *) maplock;
  2277. xaddr = addressPXD(&pxdlock->pxd);
  2278. xlen = lengthPXD(&pxdlock->pxd);
  2279. dbFree(ip, xaddr, (s64) xlen);
  2280. jfs_info("freeWMap: xaddr:0x%lx xlen:%d",
  2281. (ulong) xaddr, xlen);
  2282. } else { /* (maplock->flag & mlckFREEPXDLIST) */
  2283. pxdlistlock = (struct xdlistlock *) maplock;
  2284. pxd = pxdlistlock->xdlist;
  2285. for (n = 0; n < pxdlistlock->count; n++, pxd++) {
  2286. xaddr = addressPXD(pxd);
  2287. xlen = lengthPXD(pxd);
  2288. dbFree(ip, xaddr, (s64) xlen);
  2289. jfs_info("freeWMap: xaddr:0x%lx xlen:%d",
  2290. (ulong) xaddr, xlen);
  2291. }
  2292. }
  2293. }
  2294. }
  2295. /*
  2296. * txFreelock()
  2297. *
  2298. * function: remove tlock from inode anonymous locklist
  2299. */
  2300. void txFreelock(struct inode *ip)
  2301. {
  2302. struct jfs_inode_info *jfs_ip = JFS_IP(ip);
  2303. struct tlock *xtlck, *tlck;
  2304. lid_t xlid = 0, lid;
  2305. if (!jfs_ip->atlhead)
  2306. return;
  2307. TXN_LOCK();
  2308. xtlck = (struct tlock *) &jfs_ip->atlhead;
  2309. while ((lid = xtlck->next) != 0) {
  2310. tlck = lid_to_tlock(lid);
  2311. if (tlck->flag & tlckFREELOCK) {
  2312. xtlck->next = tlck->next;
  2313. txLockFree(lid);
  2314. } else {
  2315. xtlck = tlck;
  2316. xlid = lid;
  2317. }
  2318. }
  2319. if (jfs_ip->atlhead)
  2320. jfs_ip->atltail = xlid;
  2321. else {
  2322. jfs_ip->atltail = 0;
  2323. /*
  2324. * If inode was on anon_list, remove it
  2325. */
  2326. list_del_init(&jfs_ip->anon_inode_list);
  2327. }
  2328. TXN_UNLOCK();
  2329. }
  2330. /*
  2331. * txAbort()
  2332. *
  2333. * function: abort tx before commit;
  2334. *
  2335. * frees line-locks and segment locks for all
  2336. * segments in comdata structure.
  2337. * Optionally sets state of file-system to FM_DIRTY in super-block.
  2338. * log age of page-frames in memory for which caller has
  2339. * are reset to 0 (to avoid logwarap).
  2340. */
  2341. void txAbort(tid_t tid, int dirty)
  2342. {
  2343. lid_t lid, next;
  2344. struct metapage *mp;
  2345. struct tblock *tblk = tid_to_tblock(tid);
  2346. struct tlock *tlck;
  2347. /*
  2348. * free tlocks of the transaction
  2349. */
  2350. for (lid = tblk->next; lid; lid = next) {
  2351. tlck = lid_to_tlock(lid);
  2352. next = tlck->next;
  2353. mp = tlck->mp;
  2354. JFS_IP(tlck->ip)->xtlid = 0;
  2355. if (mp) {
  2356. mp->lid = 0;
  2357. /*
  2358. * reset lsn of page to avoid logwarap:
  2359. *
  2360. * (page may have been previously committed by another
  2361. * transaction(s) but has not been paged, i.e.,
  2362. * it may be on logsync list even though it has not
  2363. * been logged for the current tx.)
  2364. */
  2365. if (mp->xflag & COMMIT_PAGE && mp->lsn)
  2366. LogSyncRelease(mp);
  2367. }
  2368. /* insert tlock at head of freelist */
  2369. TXN_LOCK();
  2370. txLockFree(lid);
  2371. TXN_UNLOCK();
  2372. }
  2373. /* caller will free the transaction block */
  2374. tblk->next = tblk->last = 0;
  2375. /*
  2376. * mark filesystem dirty
  2377. */
  2378. if (dirty)
  2379. jfs_error(tblk->sb, "txAbort");
  2380. return;
  2381. }
  2382. /*
  2383. * txLazyCommit(void)
  2384. *
  2385. * All transactions except those changing ipimap (COMMIT_FORCE) are
  2386. * processed by this routine. This insures that the inode and block
  2387. * allocation maps are updated in order. For synchronous transactions,
  2388. * let the user thread finish processing after txUpdateMap() is called.
  2389. */
  2390. static void txLazyCommit(struct tblock * tblk)
  2391. {
  2392. struct jfs_log *log;
  2393. while (((tblk->flag & tblkGC_READY) == 0) &&
  2394. ((tblk->flag & tblkGC_UNLOCKED) == 0)) {
  2395. /* We must have gotten ahead of the user thread
  2396. */
  2397. jfs_info("jfs_lazycommit: tblk 0x%p not unlocked", tblk);
  2398. yield();
  2399. }
  2400. jfs_info("txLazyCommit: processing tblk 0x%p", tblk);
  2401. txUpdateMap(tblk);
  2402. log = (struct jfs_log *) JFS_SBI(tblk->sb)->log;
  2403. spin_lock_irq(&log->gclock); // LOGGC_LOCK
  2404. tblk->flag |= tblkGC_COMMITTED;
  2405. if (tblk->flag & tblkGC_READY)
  2406. log->gcrtc--;
  2407. wake_up_all(&tblk->gcwait); // LOGGC_WAKEUP
  2408. /*
  2409. * Can't release log->gclock until we've tested tblk->flag
  2410. */
  2411. if (tblk->flag & tblkGC_LAZY) {
  2412. spin_unlock_irq(&log->gclock); // LOGGC_UNLOCK
  2413. txUnlock(tblk);
  2414. tblk->flag &= ~tblkGC_LAZY;
  2415. txEnd(tblk - TxBlock); /* Convert back to tid */
  2416. } else
  2417. spin_unlock_irq(&log->gclock); // LOGGC_UNLOCK
  2418. jfs_info("txLazyCommit: done: tblk = 0x%p", tblk);
  2419. }
  2420. /*
  2421. * jfs_lazycommit(void)
  2422. *
  2423. * To be run as a kernel daemon. If lbmIODone is called in an interrupt
  2424. * context, or where blocking is not wanted, this routine will process
  2425. * committed transactions from the unlock queue.
  2426. */
  2427. int jfs_lazycommit(void *arg)
  2428. {
  2429. int WorkDone;
  2430. struct tblock *tblk;
  2431. unsigned long flags;
  2432. struct jfs_sb_info *sbi;
  2433. do {
  2434. LAZY_LOCK(flags);
  2435. jfs_commit_thread_waking = 0; /* OK to wake another thread */
  2436. while (!list_empty(&TxAnchor.unlock_queue)) {
  2437. WorkDone = 0;
  2438. list_for_each_entry(tblk, &TxAnchor.unlock_queue,
  2439. cqueue) {
  2440. sbi = JFS_SBI(tblk->sb);
  2441. /*
  2442. * For each volume, the transactions must be
  2443. * handled in order. If another commit thread
  2444. * is handling a tblk for this superblock,
  2445. * skip it
  2446. */
  2447. if (sbi->commit_state & IN_LAZYCOMMIT)
  2448. continue;
  2449. sbi->commit_state |= IN_LAZYCOMMIT;
  2450. WorkDone = 1;
  2451. /*
  2452. * Remove transaction from queue
  2453. */
  2454. list_del(&tblk->cqueue);
  2455. LAZY_UNLOCK(flags);
  2456. txLazyCommit(tblk);
  2457. LAZY_LOCK(flags);
  2458. sbi->commit_state &= ~IN_LAZYCOMMIT;
  2459. /*
  2460. * Don't continue in the for loop. (We can't
  2461. * anyway, it's unsafe!) We want to go back to
  2462. * the beginning of the list.
  2463. */
  2464. break;
  2465. }
  2466. /* If there was nothing to do, don't continue */
  2467. if (!WorkDone)
  2468. break;
  2469. }
  2470. /* In case a wakeup came while all threads were active */
  2471. jfs_commit_thread_waking = 0;
  2472. if (freezing(current)) {
  2473. LAZY_UNLOCK(flags);
  2474. refrigerator();
  2475. } else {
  2476. DECLARE_WAITQUEUE(wq, current);
  2477. add_wait_queue(&jfs_commit_thread_wait, &wq);
  2478. set_current_state(TASK_INTERRUPTIBLE);
  2479. LAZY_UNLOCK(flags);
  2480. schedule();
  2481. __set_current_state(TASK_RUNNING);
  2482. remove_wait_queue(&jfs_commit_thread_wait, &wq);
  2483. }
  2484. } while (!kthread_should_stop());
  2485. if (!list_empty(&TxAnchor.unlock_queue))
  2486. jfs_err("jfs_lazycommit being killed w/pending transactions!");
  2487. else
  2488. jfs_info("jfs_lazycommit being killed\n");
  2489. return 0;
  2490. }
  2491. void txLazyUnlock(struct tblock * tblk)
  2492. {
  2493. unsigned long flags;
  2494. LAZY_LOCK(flags);
  2495. list_add_tail(&tblk->cqueue, &TxAnchor.unlock_queue);
  2496. /*
  2497. * Don't wake up a commit thread if there is already one servicing
  2498. * this superblock, or if the last one we woke up hasn't started yet.
  2499. */
  2500. if (!(JFS_SBI(tblk->sb)->commit_state & IN_LAZYCOMMIT) &&
  2501. !jfs_commit_thread_waking) {
  2502. jfs_commit_thread_waking = 1;
  2503. wake_up(&jfs_commit_thread_wait);
  2504. }
  2505. LAZY_UNLOCK(flags);
  2506. }
  2507. static void LogSyncRelease(struct metapage * mp)
  2508. {
  2509. struct jfs_log *log = mp->log;
  2510. assert(mp->nohomeok);
  2511. assert(log);
  2512. metapage_homeok(mp);
  2513. }
  2514. /*
  2515. * txQuiesce
  2516. *
  2517. * Block all new transactions and push anonymous transactions to
  2518. * completion
  2519. *
  2520. * This does almost the same thing as jfs_sync below. We don't
  2521. * worry about deadlocking when jfs_tlocks_low is set, since we would
  2522. * expect jfs_sync to get us out of that jam.
  2523. */
  2524. void txQuiesce(struct super_block *sb)
  2525. {
  2526. struct inode *ip;
  2527. struct jfs_inode_info *jfs_ip;
  2528. struct jfs_log *log = JFS_SBI(sb)->log;
  2529. tid_t tid;
  2530. set_bit(log_QUIESCE, &log->flag);
  2531. TXN_LOCK();
  2532. restart:
  2533. while (!list_empty(&TxAnchor.anon_list)) {
  2534. jfs_ip = list_entry(TxAnchor.anon_list.next,
  2535. struct jfs_inode_info,
  2536. anon_inode_list);
  2537. ip = &jfs_ip->vfs_inode;
  2538. /*
  2539. * inode will be removed from anonymous list
  2540. * when it is committed
  2541. */
  2542. TXN_UNLOCK();
  2543. tid = txBegin(ip->i_sb, COMMIT_INODE | COMMIT_FORCE);
  2544. mutex_lock(&jfs_ip->commit_mutex);
  2545. txCommit(tid, 1, &ip, 0);
  2546. txEnd(tid);
  2547. mutex_unlock(&jfs_ip->commit_mutex);
  2548. /*
  2549. * Just to be safe. I don't know how
  2550. * long we can run without blocking
  2551. */
  2552. cond_resched();
  2553. TXN_LOCK();
  2554. }
  2555. /*
  2556. * If jfs_sync is running in parallel, there could be some inodes
  2557. * on anon_list2. Let's check.
  2558. */
  2559. if (!list_empty(&TxAnchor.anon_list2)) {
  2560. list_splice(&TxAnchor.anon_list2, &TxAnchor.anon_list);
  2561. INIT_LIST_HEAD(&TxAnchor.anon_list2);
  2562. goto restart;
  2563. }
  2564. TXN_UNLOCK();
  2565. /*
  2566. * We may need to kick off the group commit
  2567. */
  2568. jfs_flush_journal(log, 0);
  2569. }
  2570. /*
  2571. * txResume()
  2572. *
  2573. * Allows transactions to start again following txQuiesce
  2574. */
  2575. void txResume(struct super_block *sb)
  2576. {
  2577. struct jfs_log *log = JFS_SBI(sb)->log;
  2578. clear_bit(log_QUIESCE, &log->flag);
  2579. TXN_WAKEUP(&log->syncwait);
  2580. }
  2581. /*
  2582. * jfs_sync(void)
  2583. *
  2584. * To be run as a kernel daemon. This is awakened when tlocks run low.
  2585. * We write any inodes that have anonymous tlocks so they will become
  2586. * available.
  2587. */
  2588. int jfs_sync(void *arg)
  2589. {
  2590. struct inode *ip;
  2591. struct jfs_inode_info *jfs_ip;
  2592. int rc;
  2593. tid_t tid;
  2594. do {
  2595. /*
  2596. * write each inode on the anonymous inode list
  2597. */
  2598. TXN_LOCK();
  2599. while (jfs_tlocks_low && !list_empty(&TxAnchor.anon_list)) {
  2600. jfs_ip = list_entry(TxAnchor.anon_list.next,
  2601. struct jfs_inode_info,
  2602. anon_inode_list);
  2603. ip = &jfs_ip->vfs_inode;
  2604. if (! igrab(ip)) {
  2605. /*
  2606. * Inode is being freed
  2607. */
  2608. list_del_init(&jfs_ip->anon_inode_list);
  2609. } else if (mutex_trylock(&jfs_ip->commit_mutex)) {
  2610. /*
  2611. * inode will be removed from anonymous list
  2612. * when it is committed
  2613. */
  2614. TXN_UNLOCK();
  2615. tid = txBegin(ip->i_sb, COMMIT_INODE);
  2616. rc = txCommit(tid, 1, &ip, 0);
  2617. txEnd(tid);
  2618. mutex_unlock(&jfs_ip->commit_mutex);
  2619. iput(ip);
  2620. /*
  2621. * Just to be safe. I don't know how
  2622. * long we can run without blocking
  2623. */
  2624. cond_resched();
  2625. TXN_LOCK();
  2626. } else {
  2627. /* We can't get the commit mutex. It may
  2628. * be held by a thread waiting for tlock's
  2629. * so let's not block here. Save it to
  2630. * put back on the anon_list.
  2631. */
  2632. /* Take off anon_list */
  2633. list_del(&jfs_ip->anon_inode_list);
  2634. /* Put on anon_list2 */
  2635. list_add(&jfs_ip->anon_inode_list,
  2636. &TxAnchor.anon_list2);
  2637. TXN_UNLOCK();
  2638. iput(ip);
  2639. TXN_LOCK();
  2640. }
  2641. }
  2642. /* Add anon_list2 back to anon_list */
  2643. list_splice_init(&TxAnchor.anon_list2, &TxAnchor.anon_list);
  2644. if (freezing(current)) {
  2645. TXN_UNLOCK();
  2646. refrigerator();
  2647. } else {
  2648. set_current_state(TASK_INTERRUPTIBLE);
  2649. TXN_UNLOCK();
  2650. schedule();
  2651. __set_current_state(TASK_RUNNING);
  2652. }
  2653. } while (!kthread_should_stop());
  2654. jfs_info("jfs_sync being killed");
  2655. return 0;
  2656. }
  2657. #if defined(CONFIG_PROC_FS) && defined(CONFIG_JFS_DEBUG)
  2658. static int jfs_txanchor_proc_show(struct seq_file *m, void *v)
  2659. {
  2660. char *freewait;
  2661. char *freelockwait;
  2662. char *lowlockwait;
  2663. freewait =
  2664. waitqueue_active(&TxAnchor.freewait) ? "active" : "empty";
  2665. freelockwait =
  2666. waitqueue_active(&TxAnchor.freelockwait) ? "active" : "empty";
  2667. lowlockwait =
  2668. waitqueue_active(&TxAnchor.lowlockwait) ? "active" : "empty";
  2669. seq_printf(m,
  2670. "JFS TxAnchor\n"
  2671. "============\n"
  2672. "freetid = %d\n"
  2673. "freewait = %s\n"
  2674. "freelock = %d\n"
  2675. "freelockwait = %s\n"
  2676. "lowlockwait = %s\n"
  2677. "tlocksInUse = %d\n"
  2678. "jfs_tlocks_low = %d\n"
  2679. "unlock_queue is %sempty\n",
  2680. TxAnchor.freetid,
  2681. freewait,
  2682. TxAnchor.freelock,
  2683. freelockwait,
  2684. lowlockwait,
  2685. TxAnchor.tlocksInUse,
  2686. jfs_tlocks_low,
  2687. list_empty(&TxAnchor.unlock_queue) ? "" : "not ");
  2688. return 0;
  2689. }
  2690. static int jfs_txanchor_proc_open(struct inode *inode, struct file *file)
  2691. {
  2692. return single_open(file, jfs_txanchor_proc_show, NULL);
  2693. }
  2694. const struct file_operations jfs_txanchor_proc_fops = {
  2695. .owner = THIS_MODULE,
  2696. .open = jfs_txanchor_proc_open,
  2697. .read = seq_read,
  2698. .llseek = seq_lseek,
  2699. .release = single_release,
  2700. };
  2701. #endif
  2702. #if defined(CONFIG_PROC_FS) && defined(CONFIG_JFS_STATISTICS)
  2703. static int jfs_txstats_proc_show(struct seq_file *m, void *v)
  2704. {
  2705. seq_printf(m,
  2706. "JFS TxStats\n"
  2707. "===========\n"
  2708. "calls to txBegin = %d\n"
  2709. "txBegin blocked by sync barrier = %d\n"
  2710. "txBegin blocked by tlocks low = %d\n"
  2711. "txBegin blocked by no free tid = %d\n"
  2712. "calls to txBeginAnon = %d\n"
  2713. "txBeginAnon blocked by sync barrier = %d\n"
  2714. "txBeginAnon blocked by tlocks low = %d\n"
  2715. "calls to txLockAlloc = %d\n"
  2716. "tLockAlloc blocked by no free lock = %d\n",
  2717. TxStat.txBegin,
  2718. TxStat.txBegin_barrier,
  2719. TxStat.txBegin_lockslow,
  2720. TxStat.txBegin_freetid,
  2721. TxStat.txBeginAnon,
  2722. TxStat.txBeginAnon_barrier,
  2723. TxStat.txBeginAnon_lockslow,
  2724. TxStat.txLockAlloc,
  2725. TxStat.txLockAlloc_freelock);
  2726. return 0;
  2727. }
  2728. static int jfs_txstats_proc_open(struct inode *inode, struct file *file)
  2729. {
  2730. return single_open(file, jfs_txstats_proc_show, NULL);
  2731. }
  2732. const struct file_operations jfs_txstats_proc_fops = {
  2733. .owner = THIS_MODULE,
  2734. .open = jfs_txstats_proc_open,
  2735. .read = seq_read,
  2736. .llseek = seq_lseek,
  2737. .release = single_release,
  2738. };
  2739. #endif