jfs_txnmgr.c 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100
  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. struct inode *ip;
  992. struct jfs_inode_info *jfs_ip;
  993. int k, n;
  994. ino_t top;
  995. struct super_block *sb;
  996. jfs_info("txCommit, tid = %d, flag = %d", tid, flag);
  997. /* is read-only file system ? */
  998. if (isReadOnly(iplist[0])) {
  999. rc = -EROFS;
  1000. goto TheEnd;
  1001. }
  1002. sb = cd.sb = iplist[0]->i_sb;
  1003. cd.tid = tid;
  1004. if (tid == 0)
  1005. tid = txBegin(sb, 0);
  1006. tblk = tid_to_tblock(tid);
  1007. /*
  1008. * initialize commit structure
  1009. */
  1010. log = JFS_SBI(sb)->log;
  1011. cd.log = log;
  1012. /* initialize log record descriptor in commit */
  1013. lrd = &cd.lrd;
  1014. lrd->logtid = cpu_to_le32(tblk->logtid);
  1015. lrd->backchain = 0;
  1016. tblk->xflag |= flag;
  1017. if ((flag & (COMMIT_FORCE | COMMIT_SYNC)) == 0)
  1018. tblk->xflag |= COMMIT_LAZY;
  1019. /*
  1020. * prepare non-journaled objects for commit
  1021. *
  1022. * flush data pages of non-journaled file
  1023. * to prevent the file getting non-initialized disk blocks
  1024. * in case of crash.
  1025. * (new blocks - )
  1026. */
  1027. cd.iplist = iplist;
  1028. cd.nip = nip;
  1029. /*
  1030. * acquire transaction lock on (on-disk) inodes
  1031. *
  1032. * update on-disk inode from in-memory inode
  1033. * acquiring transaction locks for AFTER records
  1034. * on the on-disk inode of file object
  1035. *
  1036. * sort the inodes array by inode number in descending order
  1037. * to prevent deadlock when acquiring transaction lock
  1038. * of on-disk inodes on multiple on-disk inode pages by
  1039. * multiple concurrent transactions
  1040. */
  1041. for (k = 0; k < cd.nip; k++) {
  1042. top = (cd.iplist[k])->i_ino;
  1043. for (n = k + 1; n < cd.nip; n++) {
  1044. ip = cd.iplist[n];
  1045. if (ip->i_ino > top) {
  1046. top = ip->i_ino;
  1047. cd.iplist[n] = cd.iplist[k];
  1048. cd.iplist[k] = ip;
  1049. }
  1050. }
  1051. ip = cd.iplist[k];
  1052. jfs_ip = JFS_IP(ip);
  1053. /*
  1054. * BUGBUG - This code has temporarily been removed. The
  1055. * intent is to ensure that any file data is written before
  1056. * the metadata is committed to the journal. This prevents
  1057. * uninitialized data from appearing in a file after the
  1058. * journal has been replayed. (The uninitialized data
  1059. * could be sensitive data removed by another user.)
  1060. *
  1061. * The problem now is that we are holding the IWRITELOCK
  1062. * on the inode, and calling filemap_fdatawrite on an
  1063. * unmapped page will cause a deadlock in jfs_get_block.
  1064. *
  1065. * The long term solution is to pare down the use of
  1066. * IWRITELOCK. We are currently holding it too long.
  1067. * We could also be smarter about which data pages need
  1068. * to be written before the transaction is committed and
  1069. * when we don't need to worry about it at all.
  1070. *
  1071. * if ((!S_ISDIR(ip->i_mode))
  1072. * && (tblk->flag & COMMIT_DELETE) == 0)
  1073. * filemap_write_and_wait(ip->i_mapping);
  1074. */
  1075. /*
  1076. * Mark inode as not dirty. It will still be on the dirty
  1077. * inode list, but we'll know not to commit it again unless
  1078. * it gets marked dirty again
  1079. */
  1080. clear_cflag(COMMIT_Dirty, ip);
  1081. /* inherit anonymous tlock(s) of inode */
  1082. if (jfs_ip->atlhead) {
  1083. lid_to_tlock(jfs_ip->atltail)->next = tblk->next;
  1084. tblk->next = jfs_ip->atlhead;
  1085. if (!tblk->last)
  1086. tblk->last = jfs_ip->atltail;
  1087. jfs_ip->atlhead = jfs_ip->atltail = 0;
  1088. TXN_LOCK();
  1089. list_del_init(&jfs_ip->anon_inode_list);
  1090. TXN_UNLOCK();
  1091. }
  1092. /*
  1093. * acquire transaction lock on on-disk inode page
  1094. * (become first tlock of the tblk's tlock list)
  1095. */
  1096. if (((rc = diWrite(tid, ip))))
  1097. goto out;
  1098. }
  1099. /*
  1100. * write log records from transaction locks
  1101. *
  1102. * txUpdateMap() resets XAD_NEW in XAD.
  1103. */
  1104. if ((rc = txLog(log, tblk, &cd)))
  1105. goto TheEnd;
  1106. /*
  1107. * Ensure that inode isn't reused before
  1108. * lazy commit thread finishes processing
  1109. */
  1110. if (tblk->xflag & COMMIT_DELETE) {
  1111. ihold(tblk->u.ip);
  1112. /*
  1113. * Avoid a rare deadlock
  1114. *
  1115. * If the inode is locked, we may be blocked in
  1116. * jfs_commit_inode. If so, we don't want the
  1117. * lazy_commit thread doing the last iput() on the inode
  1118. * since that may block on the locked inode. Instead,
  1119. * commit the transaction synchronously, so the last iput
  1120. * will be done by the calling thread (or later)
  1121. */
  1122. /*
  1123. * I believe this code is no longer needed. Splitting I_LOCK
  1124. * into two bits, I_NEW and I_SYNC should prevent this
  1125. * deadlock as well. But since I don't have a JFS testload
  1126. * to verify this, only a trivial s/I_LOCK/I_SYNC/ was done.
  1127. * Joern
  1128. */
  1129. if (tblk->u.ip->i_state & I_SYNC)
  1130. tblk->xflag &= ~COMMIT_LAZY;
  1131. }
  1132. ASSERT((!(tblk->xflag & COMMIT_DELETE)) ||
  1133. ((tblk->u.ip->i_nlink == 0) &&
  1134. !test_cflag(COMMIT_Nolink, tblk->u.ip)));
  1135. /*
  1136. * write COMMIT log record
  1137. */
  1138. lrd->type = cpu_to_le16(LOG_COMMIT);
  1139. lrd->length = 0;
  1140. lmLog(log, tblk, lrd, NULL);
  1141. lmGroupCommit(log, tblk);
  1142. /*
  1143. * - transaction is now committed -
  1144. */
  1145. /*
  1146. * force pages in careful update
  1147. * (imap addressing structure update)
  1148. */
  1149. if (flag & COMMIT_FORCE)
  1150. txForce(tblk);
  1151. /*
  1152. * update allocation map.
  1153. *
  1154. * update inode allocation map and inode:
  1155. * free pager lock on memory object of inode if any.
  1156. * update block allocation map.
  1157. *
  1158. * txUpdateMap() resets XAD_NEW in XAD.
  1159. */
  1160. if (tblk->xflag & COMMIT_FORCE)
  1161. txUpdateMap(tblk);
  1162. /*
  1163. * free transaction locks and pageout/free pages
  1164. */
  1165. txRelease(tblk);
  1166. if ((tblk->flag & tblkGC_LAZY) == 0)
  1167. txUnlock(tblk);
  1168. /*
  1169. * reset in-memory object state
  1170. */
  1171. for (k = 0; k < cd.nip; k++) {
  1172. ip = cd.iplist[k];
  1173. jfs_ip = JFS_IP(ip);
  1174. /*
  1175. * reset in-memory inode state
  1176. */
  1177. jfs_ip->bxflag = 0;
  1178. jfs_ip->blid = 0;
  1179. }
  1180. out:
  1181. if (rc != 0)
  1182. txAbort(tid, 1);
  1183. TheEnd:
  1184. jfs_info("txCommit: tid = %d, returning %d", tid, rc);
  1185. return rc;
  1186. }
  1187. /*
  1188. * NAME: txLog()
  1189. *
  1190. * FUNCTION: Writes AFTER log records for all lines modified
  1191. * by tid for segments specified by inodes in comdata.
  1192. * Code assumes only WRITELOCKS are recorded in lockwords.
  1193. *
  1194. * PARAMETERS:
  1195. *
  1196. * RETURN :
  1197. */
  1198. static int txLog(struct jfs_log * log, struct tblock * tblk, struct commit * cd)
  1199. {
  1200. int rc = 0;
  1201. struct inode *ip;
  1202. lid_t lid;
  1203. struct tlock *tlck;
  1204. struct lrd *lrd = &cd->lrd;
  1205. /*
  1206. * write log record(s) for each tlock of transaction,
  1207. */
  1208. for (lid = tblk->next; lid; lid = tlck->next) {
  1209. tlck = lid_to_tlock(lid);
  1210. tlck->flag |= tlckLOG;
  1211. /* initialize lrd common */
  1212. ip = tlck->ip;
  1213. lrd->aggregate = cpu_to_le32(JFS_SBI(ip->i_sb)->aggregate);
  1214. lrd->log.redopage.fileset = cpu_to_le32(JFS_IP(ip)->fileset);
  1215. lrd->log.redopage.inode = cpu_to_le32(ip->i_ino);
  1216. /* write log record of page from the tlock */
  1217. switch (tlck->type & tlckTYPE) {
  1218. case tlckXTREE:
  1219. xtLog(log, tblk, lrd, tlck);
  1220. break;
  1221. case tlckDTREE:
  1222. dtLog(log, tblk, lrd, tlck);
  1223. break;
  1224. case tlckINODE:
  1225. diLog(log, tblk, lrd, tlck, cd);
  1226. break;
  1227. case tlckMAP:
  1228. mapLog(log, tblk, lrd, tlck);
  1229. break;
  1230. case tlckDATA:
  1231. dataLog(log, tblk, lrd, tlck);
  1232. break;
  1233. default:
  1234. jfs_err("UFO tlock:0x%p", tlck);
  1235. }
  1236. }
  1237. return rc;
  1238. }
  1239. /*
  1240. * diLog()
  1241. *
  1242. * function: log inode tlock and format maplock to update bmap;
  1243. */
  1244. static int diLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
  1245. struct tlock * tlck, struct commit * cd)
  1246. {
  1247. int rc = 0;
  1248. struct metapage *mp;
  1249. pxd_t *pxd;
  1250. struct pxd_lock *pxdlock;
  1251. mp = tlck->mp;
  1252. /* initialize as REDOPAGE record format */
  1253. lrd->log.redopage.type = cpu_to_le16(LOG_INODE);
  1254. lrd->log.redopage.l2linesize = cpu_to_le16(L2INODESLOTSIZE);
  1255. pxd = &lrd->log.redopage.pxd;
  1256. /*
  1257. * inode after image
  1258. */
  1259. if (tlck->type & tlckENTRY) {
  1260. /* log after-image for logredo(): */
  1261. lrd->type = cpu_to_le16(LOG_REDOPAGE);
  1262. PXDaddress(pxd, mp->index);
  1263. PXDlength(pxd,
  1264. mp->logical_size >> tblk->sb->s_blocksize_bits);
  1265. lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, tlck));
  1266. /* mark page as homeward bound */
  1267. tlck->flag |= tlckWRITEPAGE;
  1268. } else if (tlck->type & tlckFREE) {
  1269. /*
  1270. * free inode extent
  1271. *
  1272. * (pages of the freed inode extent have been invalidated and
  1273. * a maplock for free of the extent has been formatted at
  1274. * txLock() time);
  1275. *
  1276. * the tlock had been acquired on the inode allocation map page
  1277. * (iag) that specifies the freed extent, even though the map
  1278. * page is not itself logged, to prevent pageout of the map
  1279. * page before the log;
  1280. */
  1281. /* log LOG_NOREDOINOEXT of the freed inode extent for
  1282. * logredo() to start NoRedoPage filters, and to update
  1283. * imap and bmap for free of the extent;
  1284. */
  1285. lrd->type = cpu_to_le16(LOG_NOREDOINOEXT);
  1286. /*
  1287. * For the LOG_NOREDOINOEXT record, we need
  1288. * to pass the IAG number and inode extent
  1289. * index (within that IAG) from which the
  1290. * the extent being released. These have been
  1291. * passed to us in the iplist[1] and iplist[2].
  1292. */
  1293. lrd->log.noredoinoext.iagnum =
  1294. cpu_to_le32((u32) (size_t) cd->iplist[1]);
  1295. lrd->log.noredoinoext.inoext_idx =
  1296. cpu_to_le32((u32) (size_t) cd->iplist[2]);
  1297. pxdlock = (struct pxd_lock *) & tlck->lock;
  1298. *pxd = pxdlock->pxd;
  1299. lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, NULL));
  1300. /* update bmap */
  1301. tlck->flag |= tlckUPDATEMAP;
  1302. /* mark page as homeward bound */
  1303. tlck->flag |= tlckWRITEPAGE;
  1304. } else
  1305. jfs_err("diLog: UFO type tlck:0x%p", tlck);
  1306. #ifdef _JFS_WIP
  1307. /*
  1308. * alloc/free external EA extent
  1309. *
  1310. * a maplock for txUpdateMap() to update bPWMAP for alloc/free
  1311. * of the extent has been formatted at txLock() time;
  1312. */
  1313. else {
  1314. assert(tlck->type & tlckEA);
  1315. /* log LOG_UPDATEMAP for logredo() to update bmap for
  1316. * alloc of new (and free of old) external EA extent;
  1317. */
  1318. lrd->type = cpu_to_le16(LOG_UPDATEMAP);
  1319. pxdlock = (struct pxd_lock *) & tlck->lock;
  1320. nlock = pxdlock->index;
  1321. for (i = 0; i < nlock; i++, pxdlock++) {
  1322. if (pxdlock->flag & mlckALLOCPXD)
  1323. lrd->log.updatemap.type =
  1324. cpu_to_le16(LOG_ALLOCPXD);
  1325. else
  1326. lrd->log.updatemap.type =
  1327. cpu_to_le16(LOG_FREEPXD);
  1328. lrd->log.updatemap.nxd = cpu_to_le16(1);
  1329. lrd->log.updatemap.pxd = pxdlock->pxd;
  1330. lrd->backchain =
  1331. cpu_to_le32(lmLog(log, tblk, lrd, NULL));
  1332. }
  1333. /* update bmap */
  1334. tlck->flag |= tlckUPDATEMAP;
  1335. }
  1336. #endif /* _JFS_WIP */
  1337. return rc;
  1338. }
  1339. /*
  1340. * dataLog()
  1341. *
  1342. * function: log data tlock
  1343. */
  1344. static int dataLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
  1345. struct tlock * tlck)
  1346. {
  1347. struct metapage *mp;
  1348. pxd_t *pxd;
  1349. mp = tlck->mp;
  1350. /* initialize as REDOPAGE record format */
  1351. lrd->log.redopage.type = cpu_to_le16(LOG_DATA);
  1352. lrd->log.redopage.l2linesize = cpu_to_le16(L2DATASLOTSIZE);
  1353. pxd = &lrd->log.redopage.pxd;
  1354. /* log after-image for logredo(): */
  1355. lrd->type = cpu_to_le16(LOG_REDOPAGE);
  1356. if (jfs_dirtable_inline(tlck->ip)) {
  1357. /*
  1358. * The table has been truncated, we've must have deleted
  1359. * the last entry, so don't bother logging this
  1360. */
  1361. mp->lid = 0;
  1362. grab_metapage(mp);
  1363. metapage_homeok(mp);
  1364. discard_metapage(mp);
  1365. tlck->mp = NULL;
  1366. return 0;
  1367. }
  1368. PXDaddress(pxd, mp->index);
  1369. PXDlength(pxd, mp->logical_size >> tblk->sb->s_blocksize_bits);
  1370. lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, tlck));
  1371. /* mark page as homeward bound */
  1372. tlck->flag |= tlckWRITEPAGE;
  1373. return 0;
  1374. }
  1375. /*
  1376. * dtLog()
  1377. *
  1378. * function: log dtree tlock and format maplock to update bmap;
  1379. */
  1380. static void dtLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
  1381. struct tlock * tlck)
  1382. {
  1383. struct metapage *mp;
  1384. struct pxd_lock *pxdlock;
  1385. pxd_t *pxd;
  1386. mp = tlck->mp;
  1387. /* initialize as REDOPAGE/NOREDOPAGE record format */
  1388. lrd->log.redopage.type = cpu_to_le16(LOG_DTREE);
  1389. lrd->log.redopage.l2linesize = cpu_to_le16(L2DTSLOTSIZE);
  1390. pxd = &lrd->log.redopage.pxd;
  1391. if (tlck->type & tlckBTROOT)
  1392. lrd->log.redopage.type |= cpu_to_le16(LOG_BTROOT);
  1393. /*
  1394. * page extension via relocation: entry insertion;
  1395. * page extension in-place: entry insertion;
  1396. * new right page from page split, reinitialized in-line
  1397. * root from root page split: entry insertion;
  1398. */
  1399. if (tlck->type & (tlckNEW | tlckEXTEND)) {
  1400. /* log after-image of the new page for logredo():
  1401. * mark log (LOG_NEW) for logredo() to initialize
  1402. * freelist and update bmap for alloc of the new page;
  1403. */
  1404. lrd->type = cpu_to_le16(LOG_REDOPAGE);
  1405. if (tlck->type & tlckEXTEND)
  1406. lrd->log.redopage.type |= cpu_to_le16(LOG_EXTEND);
  1407. else
  1408. lrd->log.redopage.type |= cpu_to_le16(LOG_NEW);
  1409. PXDaddress(pxd, mp->index);
  1410. PXDlength(pxd,
  1411. mp->logical_size >> tblk->sb->s_blocksize_bits);
  1412. lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, tlck));
  1413. /* format a maplock for txUpdateMap() to update bPMAP for
  1414. * alloc of the new page;
  1415. */
  1416. if (tlck->type & tlckBTROOT)
  1417. return;
  1418. tlck->flag |= tlckUPDATEMAP;
  1419. pxdlock = (struct pxd_lock *) & tlck->lock;
  1420. pxdlock->flag = mlckALLOCPXD;
  1421. pxdlock->pxd = *pxd;
  1422. pxdlock->index = 1;
  1423. /* mark page as homeward bound */
  1424. tlck->flag |= tlckWRITEPAGE;
  1425. return;
  1426. }
  1427. /*
  1428. * entry insertion/deletion,
  1429. * sibling page link update (old right page before split);
  1430. */
  1431. if (tlck->type & (tlckENTRY | tlckRELINK)) {
  1432. /* log after-image for logredo(): */
  1433. lrd->type = cpu_to_le16(LOG_REDOPAGE);
  1434. PXDaddress(pxd, mp->index);
  1435. PXDlength(pxd,
  1436. mp->logical_size >> tblk->sb->s_blocksize_bits);
  1437. lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, tlck));
  1438. /* mark page as homeward bound */
  1439. tlck->flag |= tlckWRITEPAGE;
  1440. return;
  1441. }
  1442. /*
  1443. * page deletion: page has been invalidated
  1444. * page relocation: source extent
  1445. *
  1446. * a maplock for free of the page has been formatted
  1447. * at txLock() time);
  1448. */
  1449. if (tlck->type & (tlckFREE | tlckRELOCATE)) {
  1450. /* log LOG_NOREDOPAGE of the deleted page for logredo()
  1451. * to start NoRedoPage filter and to update bmap for free
  1452. * of the deletd page
  1453. */
  1454. lrd->type = cpu_to_le16(LOG_NOREDOPAGE);
  1455. pxdlock = (struct pxd_lock *) & tlck->lock;
  1456. *pxd = pxdlock->pxd;
  1457. lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, NULL));
  1458. /* a maplock for txUpdateMap() for free of the page
  1459. * has been formatted at txLock() time;
  1460. */
  1461. tlck->flag |= tlckUPDATEMAP;
  1462. }
  1463. return;
  1464. }
  1465. /*
  1466. * xtLog()
  1467. *
  1468. * function: log xtree tlock and format maplock to update bmap;
  1469. */
  1470. static void xtLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
  1471. struct tlock * tlck)
  1472. {
  1473. struct inode *ip;
  1474. struct metapage *mp;
  1475. xtpage_t *p;
  1476. struct xtlock *xtlck;
  1477. struct maplock *maplock;
  1478. struct xdlistlock *xadlock;
  1479. struct pxd_lock *pxdlock;
  1480. pxd_t *page_pxd;
  1481. int next, lwm, hwm;
  1482. ip = tlck->ip;
  1483. mp = tlck->mp;
  1484. /* initialize as REDOPAGE/NOREDOPAGE record format */
  1485. lrd->log.redopage.type = cpu_to_le16(LOG_XTREE);
  1486. lrd->log.redopage.l2linesize = cpu_to_le16(L2XTSLOTSIZE);
  1487. page_pxd = &lrd->log.redopage.pxd;
  1488. if (tlck->type & tlckBTROOT) {
  1489. lrd->log.redopage.type |= cpu_to_le16(LOG_BTROOT);
  1490. p = &JFS_IP(ip)->i_xtroot;
  1491. if (S_ISDIR(ip->i_mode))
  1492. lrd->log.redopage.type |=
  1493. cpu_to_le16(LOG_DIR_XTREE);
  1494. } else
  1495. p = (xtpage_t *) mp->data;
  1496. next = le16_to_cpu(p->header.nextindex);
  1497. xtlck = (struct xtlock *) & tlck->lock;
  1498. maplock = (struct maplock *) & tlck->lock;
  1499. xadlock = (struct xdlistlock *) maplock;
  1500. /*
  1501. * entry insertion/extension;
  1502. * sibling page link update (old right page before split);
  1503. */
  1504. if (tlck->type & (tlckNEW | tlckGROW | tlckRELINK)) {
  1505. /* log after-image for logredo():
  1506. * logredo() will update bmap for alloc of new/extended
  1507. * extents (XAD_NEW|XAD_EXTEND) of XAD[lwm:next) from
  1508. * after-image of XADlist;
  1509. * logredo() resets (XAD_NEW|XAD_EXTEND) flag when
  1510. * applying the after-image to the meta-data page.
  1511. */
  1512. lrd->type = cpu_to_le16(LOG_REDOPAGE);
  1513. PXDaddress(page_pxd, mp->index);
  1514. PXDlength(page_pxd,
  1515. mp->logical_size >> tblk->sb->s_blocksize_bits);
  1516. lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, tlck));
  1517. /* format a maplock for txUpdateMap() to update bPMAP
  1518. * for alloc of new/extended extents of XAD[lwm:next)
  1519. * from the page itself;
  1520. * txUpdateMap() resets (XAD_NEW|XAD_EXTEND) flag.
  1521. */
  1522. lwm = xtlck->lwm.offset;
  1523. if (lwm == 0)
  1524. lwm = XTPAGEMAXSLOT;
  1525. if (lwm == next)
  1526. goto out;
  1527. if (lwm > next) {
  1528. jfs_err("xtLog: lwm > next\n");
  1529. goto out;
  1530. }
  1531. tlck->flag |= tlckUPDATEMAP;
  1532. xadlock->flag = mlckALLOCXADLIST;
  1533. xadlock->count = next - lwm;
  1534. if ((xadlock->count <= 4) && (tblk->xflag & COMMIT_LAZY)) {
  1535. int i;
  1536. pxd_t *pxd;
  1537. /*
  1538. * Lazy commit may allow xtree to be modified before
  1539. * txUpdateMap runs. Copy xad into linelock to
  1540. * preserve correct data.
  1541. *
  1542. * We can fit twice as may pxd's as xads in the lock
  1543. */
  1544. xadlock->flag = mlckALLOCPXDLIST;
  1545. pxd = xadlock->xdlist = &xtlck->pxdlock;
  1546. for (i = 0; i < xadlock->count; i++) {
  1547. PXDaddress(pxd, addressXAD(&p->xad[lwm + i]));
  1548. PXDlength(pxd, lengthXAD(&p->xad[lwm + i]));
  1549. p->xad[lwm + i].flag &=
  1550. ~(XAD_NEW | XAD_EXTENDED);
  1551. pxd++;
  1552. }
  1553. } else {
  1554. /*
  1555. * xdlist will point to into inode's xtree, ensure
  1556. * that transaction is not committed lazily.
  1557. */
  1558. xadlock->flag = mlckALLOCXADLIST;
  1559. xadlock->xdlist = &p->xad[lwm];
  1560. tblk->xflag &= ~COMMIT_LAZY;
  1561. }
  1562. jfs_info("xtLog: alloc ip:0x%p mp:0x%p tlck:0x%p lwm:%d "
  1563. "count:%d", tlck->ip, mp, tlck, lwm, xadlock->count);
  1564. maplock->index = 1;
  1565. out:
  1566. /* mark page as homeward bound */
  1567. tlck->flag |= tlckWRITEPAGE;
  1568. return;
  1569. }
  1570. /*
  1571. * page deletion: file deletion/truncation (ref. xtTruncate())
  1572. *
  1573. * (page will be invalidated after log is written and bmap
  1574. * is updated from the page);
  1575. */
  1576. if (tlck->type & tlckFREE) {
  1577. /* LOG_NOREDOPAGE log for NoRedoPage filter:
  1578. * if page free from file delete, NoRedoFile filter from
  1579. * inode image of zero link count will subsume NoRedoPage
  1580. * filters for each page;
  1581. * if page free from file truncattion, write NoRedoPage
  1582. * filter;
  1583. *
  1584. * upadte of block allocation map for the page itself:
  1585. * if page free from deletion and truncation, LOG_UPDATEMAP
  1586. * log for the page itself is generated from processing
  1587. * its parent page xad entries;
  1588. */
  1589. /* if page free from file truncation, log LOG_NOREDOPAGE
  1590. * of the deleted page for logredo() to start NoRedoPage
  1591. * filter for the page;
  1592. */
  1593. if (tblk->xflag & COMMIT_TRUNCATE) {
  1594. /* write NOREDOPAGE for the page */
  1595. lrd->type = cpu_to_le16(LOG_NOREDOPAGE);
  1596. PXDaddress(page_pxd, mp->index);
  1597. PXDlength(page_pxd,
  1598. mp->logical_size >> tblk->sb->
  1599. s_blocksize_bits);
  1600. lrd->backchain =
  1601. cpu_to_le32(lmLog(log, tblk, lrd, NULL));
  1602. if (tlck->type & tlckBTROOT) {
  1603. /* Empty xtree must be logged */
  1604. lrd->type = cpu_to_le16(LOG_REDOPAGE);
  1605. lrd->backchain =
  1606. cpu_to_le32(lmLog(log, tblk, lrd, tlck));
  1607. }
  1608. }
  1609. /* init LOG_UPDATEMAP of the freed extents
  1610. * XAD[XTENTRYSTART:hwm) from the deleted page itself
  1611. * for logredo() to update bmap;
  1612. */
  1613. lrd->type = cpu_to_le16(LOG_UPDATEMAP);
  1614. lrd->log.updatemap.type = cpu_to_le16(LOG_FREEXADLIST);
  1615. xtlck = (struct xtlock *) & tlck->lock;
  1616. hwm = xtlck->hwm.offset;
  1617. lrd->log.updatemap.nxd =
  1618. cpu_to_le16(hwm - XTENTRYSTART + 1);
  1619. /* reformat linelock for lmLog() */
  1620. xtlck->header.offset = XTENTRYSTART;
  1621. xtlck->header.length = hwm - XTENTRYSTART + 1;
  1622. xtlck->index = 1;
  1623. lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, tlck));
  1624. /* format a maplock for txUpdateMap() to update bmap
  1625. * to free extents of XAD[XTENTRYSTART:hwm) from the
  1626. * deleted page itself;
  1627. */
  1628. tlck->flag |= tlckUPDATEMAP;
  1629. xadlock->count = hwm - XTENTRYSTART + 1;
  1630. if ((xadlock->count <= 4) && (tblk->xflag & COMMIT_LAZY)) {
  1631. int i;
  1632. pxd_t *pxd;
  1633. /*
  1634. * Lazy commit may allow xtree to be modified before
  1635. * txUpdateMap runs. Copy xad into linelock to
  1636. * preserve correct data.
  1637. *
  1638. * We can fit twice as may pxd's as xads in the lock
  1639. */
  1640. xadlock->flag = mlckFREEPXDLIST;
  1641. pxd = xadlock->xdlist = &xtlck->pxdlock;
  1642. for (i = 0; i < xadlock->count; i++) {
  1643. PXDaddress(pxd,
  1644. addressXAD(&p->xad[XTENTRYSTART + i]));
  1645. PXDlength(pxd,
  1646. lengthXAD(&p->xad[XTENTRYSTART + i]));
  1647. pxd++;
  1648. }
  1649. } else {
  1650. /*
  1651. * xdlist will point to into inode's xtree, ensure
  1652. * that transaction is not committed lazily.
  1653. */
  1654. xadlock->flag = mlckFREEXADLIST;
  1655. xadlock->xdlist = &p->xad[XTENTRYSTART];
  1656. tblk->xflag &= ~COMMIT_LAZY;
  1657. }
  1658. jfs_info("xtLog: free ip:0x%p mp:0x%p count:%d lwm:2",
  1659. tlck->ip, mp, xadlock->count);
  1660. maplock->index = 1;
  1661. /* mark page as invalid */
  1662. if (((tblk->xflag & COMMIT_PWMAP) || S_ISDIR(ip->i_mode))
  1663. && !(tlck->type & tlckBTROOT))
  1664. tlck->flag |= tlckFREEPAGE;
  1665. /*
  1666. else (tblk->xflag & COMMIT_PMAP)
  1667. ? release the page;
  1668. */
  1669. return;
  1670. }
  1671. /*
  1672. * page/entry truncation: file truncation (ref. xtTruncate())
  1673. *
  1674. * |----------+------+------+---------------|
  1675. * | | |
  1676. * | | hwm - hwm before truncation
  1677. * | next - truncation point
  1678. * lwm - lwm before truncation
  1679. * header ?
  1680. */
  1681. if (tlck->type & tlckTRUNCATE) {
  1682. /* This odd declaration suppresses a bogus gcc warning */
  1683. pxd_t pxd = pxd; /* truncated extent of xad */
  1684. int twm;
  1685. /*
  1686. * For truncation the entire linelock may be used, so it would
  1687. * be difficult to store xad list in linelock itself.
  1688. * Therefore, we'll just force transaction to be committed
  1689. * synchronously, so that xtree pages won't be changed before
  1690. * txUpdateMap runs.
  1691. */
  1692. tblk->xflag &= ~COMMIT_LAZY;
  1693. lwm = xtlck->lwm.offset;
  1694. if (lwm == 0)
  1695. lwm = XTPAGEMAXSLOT;
  1696. hwm = xtlck->hwm.offset;
  1697. twm = xtlck->twm.offset;
  1698. /*
  1699. * write log records
  1700. */
  1701. /* log after-image for logredo():
  1702. *
  1703. * logredo() will update bmap for alloc of new/extended
  1704. * extents (XAD_NEW|XAD_EXTEND) of XAD[lwm:next) from
  1705. * after-image of XADlist;
  1706. * logredo() resets (XAD_NEW|XAD_EXTEND) flag when
  1707. * applying the after-image to the meta-data page.
  1708. */
  1709. lrd->type = cpu_to_le16(LOG_REDOPAGE);
  1710. PXDaddress(page_pxd, mp->index);
  1711. PXDlength(page_pxd,
  1712. mp->logical_size >> tblk->sb->s_blocksize_bits);
  1713. lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, tlck));
  1714. /*
  1715. * truncate entry XAD[twm == next - 1]:
  1716. */
  1717. if (twm == next - 1) {
  1718. /* init LOG_UPDATEMAP for logredo() to update bmap for
  1719. * free of truncated delta extent of the truncated
  1720. * entry XAD[next - 1]:
  1721. * (xtlck->pxdlock = truncated delta extent);
  1722. */
  1723. pxdlock = (struct pxd_lock *) & xtlck->pxdlock;
  1724. /* assert(pxdlock->type & tlckTRUNCATE); */
  1725. lrd->type = cpu_to_le16(LOG_UPDATEMAP);
  1726. lrd->log.updatemap.type = cpu_to_le16(LOG_FREEPXD);
  1727. lrd->log.updatemap.nxd = cpu_to_le16(1);
  1728. lrd->log.updatemap.pxd = pxdlock->pxd;
  1729. pxd = pxdlock->pxd; /* save to format maplock */
  1730. lrd->backchain =
  1731. cpu_to_le32(lmLog(log, tblk, lrd, NULL));
  1732. }
  1733. /*
  1734. * free entries XAD[next:hwm]:
  1735. */
  1736. if (hwm >= next) {
  1737. /* init LOG_UPDATEMAP of the freed extents
  1738. * XAD[next:hwm] from the deleted page itself
  1739. * for logredo() to update bmap;
  1740. */
  1741. lrd->type = cpu_to_le16(LOG_UPDATEMAP);
  1742. lrd->log.updatemap.type =
  1743. cpu_to_le16(LOG_FREEXADLIST);
  1744. xtlck = (struct xtlock *) & tlck->lock;
  1745. hwm = xtlck->hwm.offset;
  1746. lrd->log.updatemap.nxd =
  1747. cpu_to_le16(hwm - next + 1);
  1748. /* reformat linelock for lmLog() */
  1749. xtlck->header.offset = next;
  1750. xtlck->header.length = hwm - next + 1;
  1751. xtlck->index = 1;
  1752. lrd->backchain =
  1753. cpu_to_le32(lmLog(log, tblk, lrd, tlck));
  1754. }
  1755. /*
  1756. * format maplock(s) for txUpdateMap() to update bmap
  1757. */
  1758. maplock->index = 0;
  1759. /*
  1760. * allocate entries XAD[lwm:next):
  1761. */
  1762. if (lwm < next) {
  1763. /* format a maplock for txUpdateMap() to update bPMAP
  1764. * for alloc of new/extended extents of XAD[lwm:next)
  1765. * from the page itself;
  1766. * txUpdateMap() resets (XAD_NEW|XAD_EXTEND) flag.
  1767. */
  1768. tlck->flag |= tlckUPDATEMAP;
  1769. xadlock->flag = mlckALLOCXADLIST;
  1770. xadlock->count = next - lwm;
  1771. xadlock->xdlist = &p->xad[lwm];
  1772. jfs_info("xtLog: alloc ip:0x%p mp:0x%p count:%d "
  1773. "lwm:%d next:%d",
  1774. tlck->ip, mp, xadlock->count, lwm, next);
  1775. maplock->index++;
  1776. xadlock++;
  1777. }
  1778. /*
  1779. * truncate entry XAD[twm == next - 1]:
  1780. */
  1781. if (twm == next - 1) {
  1782. /* format a maplock for txUpdateMap() to update bmap
  1783. * to free truncated delta extent of the truncated
  1784. * entry XAD[next - 1];
  1785. * (xtlck->pxdlock = truncated delta extent);
  1786. */
  1787. tlck->flag |= tlckUPDATEMAP;
  1788. pxdlock = (struct pxd_lock *) xadlock;
  1789. pxdlock->flag = mlckFREEPXD;
  1790. pxdlock->count = 1;
  1791. pxdlock->pxd = pxd;
  1792. jfs_info("xtLog: truncate ip:0x%p mp:0x%p count:%d "
  1793. "hwm:%d", ip, mp, pxdlock->count, hwm);
  1794. maplock->index++;
  1795. xadlock++;
  1796. }
  1797. /*
  1798. * free entries XAD[next:hwm]:
  1799. */
  1800. if (hwm >= next) {
  1801. /* format a maplock for txUpdateMap() to update bmap
  1802. * to free extents of XAD[next:hwm] from thedeleted
  1803. * page itself;
  1804. */
  1805. tlck->flag |= tlckUPDATEMAP;
  1806. xadlock->flag = mlckFREEXADLIST;
  1807. xadlock->count = hwm - next + 1;
  1808. xadlock->xdlist = &p->xad[next];
  1809. jfs_info("xtLog: free ip:0x%p mp:0x%p count:%d "
  1810. "next:%d hwm:%d",
  1811. tlck->ip, mp, xadlock->count, next, hwm);
  1812. maplock->index++;
  1813. }
  1814. /* mark page as homeward bound */
  1815. tlck->flag |= tlckWRITEPAGE;
  1816. }
  1817. return;
  1818. }
  1819. /*
  1820. * mapLog()
  1821. *
  1822. * function: log from maplock of freed data extents;
  1823. */
  1824. static void mapLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
  1825. struct tlock * tlck)
  1826. {
  1827. struct pxd_lock *pxdlock;
  1828. int i, nlock;
  1829. pxd_t *pxd;
  1830. /*
  1831. * page relocation: free the source page extent
  1832. *
  1833. * a maplock for txUpdateMap() for free of the page
  1834. * has been formatted at txLock() time saving the src
  1835. * relocated page address;
  1836. */
  1837. if (tlck->type & tlckRELOCATE) {
  1838. /* log LOG_NOREDOPAGE of the old relocated page
  1839. * for logredo() to start NoRedoPage filter;
  1840. */
  1841. lrd->type = cpu_to_le16(LOG_NOREDOPAGE);
  1842. pxdlock = (struct pxd_lock *) & tlck->lock;
  1843. pxd = &lrd->log.redopage.pxd;
  1844. *pxd = pxdlock->pxd;
  1845. lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, NULL));
  1846. /* (N.B. currently, logredo() does NOT update bmap
  1847. * for free of the page itself for (LOG_XTREE|LOG_NOREDOPAGE);
  1848. * if page free from relocation, LOG_UPDATEMAP log is
  1849. * specifically generated now for logredo()
  1850. * to update bmap for free of src relocated page;
  1851. * (new flag LOG_RELOCATE may be introduced which will
  1852. * inform logredo() to start NORedoPage filter and also
  1853. * update block allocation map at the same time, thus
  1854. * avoiding an extra log write);
  1855. */
  1856. lrd->type = cpu_to_le16(LOG_UPDATEMAP);
  1857. lrd->log.updatemap.type = cpu_to_le16(LOG_FREEPXD);
  1858. lrd->log.updatemap.nxd = cpu_to_le16(1);
  1859. lrd->log.updatemap.pxd = pxdlock->pxd;
  1860. lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, NULL));
  1861. /* a maplock for txUpdateMap() for free of the page
  1862. * has been formatted at txLock() time;
  1863. */
  1864. tlck->flag |= tlckUPDATEMAP;
  1865. return;
  1866. }
  1867. /*
  1868. * Otherwise it's not a relocate request
  1869. *
  1870. */
  1871. else {
  1872. /* log LOG_UPDATEMAP for logredo() to update bmap for
  1873. * free of truncated/relocated delta extent of the data;
  1874. * e.g.: external EA extent, relocated/truncated extent
  1875. * from xtTailgate();
  1876. */
  1877. lrd->type = cpu_to_le16(LOG_UPDATEMAP);
  1878. pxdlock = (struct pxd_lock *) & tlck->lock;
  1879. nlock = pxdlock->index;
  1880. for (i = 0; i < nlock; i++, pxdlock++) {
  1881. if (pxdlock->flag & mlckALLOCPXD)
  1882. lrd->log.updatemap.type =
  1883. cpu_to_le16(LOG_ALLOCPXD);
  1884. else
  1885. lrd->log.updatemap.type =
  1886. cpu_to_le16(LOG_FREEPXD);
  1887. lrd->log.updatemap.nxd = cpu_to_le16(1);
  1888. lrd->log.updatemap.pxd = pxdlock->pxd;
  1889. lrd->backchain =
  1890. cpu_to_le32(lmLog(log, tblk, lrd, NULL));
  1891. jfs_info("mapLog: xaddr:0x%lx xlen:0x%x",
  1892. (ulong) addressPXD(&pxdlock->pxd),
  1893. lengthPXD(&pxdlock->pxd));
  1894. }
  1895. /* update bmap */
  1896. tlck->flag |= tlckUPDATEMAP;
  1897. }
  1898. }
  1899. /*
  1900. * txEA()
  1901. *
  1902. * function: acquire maplock for EA/ACL extents or
  1903. * set COMMIT_INLINE flag;
  1904. */
  1905. void txEA(tid_t tid, struct inode *ip, dxd_t * oldea, dxd_t * newea)
  1906. {
  1907. struct tlock *tlck = NULL;
  1908. struct pxd_lock *maplock = NULL, *pxdlock = NULL;
  1909. /*
  1910. * format maplock for alloc of new EA extent
  1911. */
  1912. if (newea) {
  1913. /* Since the newea could be a completely zeroed entry we need to
  1914. * check for the two flags which indicate we should actually
  1915. * commit new EA data
  1916. */
  1917. if (newea->flag & DXD_EXTENT) {
  1918. tlck = txMaplock(tid, ip, tlckMAP);
  1919. maplock = (struct pxd_lock *) & tlck->lock;
  1920. pxdlock = (struct pxd_lock *) maplock;
  1921. pxdlock->flag = mlckALLOCPXD;
  1922. PXDaddress(&pxdlock->pxd, addressDXD(newea));
  1923. PXDlength(&pxdlock->pxd, lengthDXD(newea));
  1924. pxdlock++;
  1925. maplock->index = 1;
  1926. } else if (newea->flag & DXD_INLINE) {
  1927. tlck = NULL;
  1928. set_cflag(COMMIT_Inlineea, ip);
  1929. }
  1930. }
  1931. /*
  1932. * format maplock for free of old EA extent
  1933. */
  1934. if (!test_cflag(COMMIT_Nolink, ip) && oldea->flag & DXD_EXTENT) {
  1935. if (tlck == NULL) {
  1936. tlck = txMaplock(tid, ip, tlckMAP);
  1937. maplock = (struct pxd_lock *) & tlck->lock;
  1938. pxdlock = (struct pxd_lock *) maplock;
  1939. maplock->index = 0;
  1940. }
  1941. pxdlock->flag = mlckFREEPXD;
  1942. PXDaddress(&pxdlock->pxd, addressDXD(oldea));
  1943. PXDlength(&pxdlock->pxd, lengthDXD(oldea));
  1944. maplock->index++;
  1945. }
  1946. }
  1947. /*
  1948. * txForce()
  1949. *
  1950. * function: synchronously write pages locked by transaction
  1951. * after txLog() but before txUpdateMap();
  1952. */
  1953. static void txForce(struct tblock * tblk)
  1954. {
  1955. struct tlock *tlck;
  1956. lid_t lid, next;
  1957. struct metapage *mp;
  1958. /*
  1959. * reverse the order of transaction tlocks in
  1960. * careful update order of address index pages
  1961. * (right to left, bottom up)
  1962. */
  1963. tlck = lid_to_tlock(tblk->next);
  1964. lid = tlck->next;
  1965. tlck->next = 0;
  1966. while (lid) {
  1967. tlck = lid_to_tlock(lid);
  1968. next = tlck->next;
  1969. tlck->next = tblk->next;
  1970. tblk->next = lid;
  1971. lid = next;
  1972. }
  1973. /*
  1974. * synchronously write the page, and
  1975. * hold the page for txUpdateMap();
  1976. */
  1977. for (lid = tblk->next; lid; lid = next) {
  1978. tlck = lid_to_tlock(lid);
  1979. next = tlck->next;
  1980. if ((mp = tlck->mp) != NULL &&
  1981. (tlck->type & tlckBTROOT) == 0) {
  1982. assert(mp->xflag & COMMIT_PAGE);
  1983. if (tlck->flag & tlckWRITEPAGE) {
  1984. tlck->flag &= ~tlckWRITEPAGE;
  1985. /* do not release page to freelist */
  1986. force_metapage(mp);
  1987. #if 0
  1988. /*
  1989. * The "right" thing to do here is to
  1990. * synchronously write the metadata.
  1991. * With the current implementation this
  1992. * is hard since write_metapage requires
  1993. * us to kunmap & remap the page. If we
  1994. * have tlocks pointing into the metadata
  1995. * pages, we don't want to do this. I think
  1996. * we can get by with synchronously writing
  1997. * the pages when they are released.
  1998. */
  1999. assert(mp->nohomeok);
  2000. set_bit(META_dirty, &mp->flag);
  2001. set_bit(META_sync, &mp->flag);
  2002. #endif
  2003. }
  2004. }
  2005. }
  2006. }
  2007. /*
  2008. * txUpdateMap()
  2009. *
  2010. * function: update persistent allocation map (and working map
  2011. * if appropriate);
  2012. *
  2013. * parameter:
  2014. */
  2015. static void txUpdateMap(struct tblock * tblk)
  2016. {
  2017. struct inode *ip;
  2018. struct inode *ipimap;
  2019. lid_t lid;
  2020. struct tlock *tlck;
  2021. struct maplock *maplock;
  2022. struct pxd_lock pxdlock;
  2023. int maptype;
  2024. int k, nlock;
  2025. struct metapage *mp = NULL;
  2026. ipimap = JFS_SBI(tblk->sb)->ipimap;
  2027. maptype = (tblk->xflag & COMMIT_PMAP) ? COMMIT_PMAP : COMMIT_PWMAP;
  2028. /*
  2029. * update block allocation map
  2030. *
  2031. * update allocation state in pmap (and wmap) and
  2032. * update lsn of the pmap page;
  2033. */
  2034. /*
  2035. * scan each tlock/page of transaction for block allocation/free:
  2036. *
  2037. * for each tlock/page of transaction, update map.
  2038. * ? are there tlock for pmap and pwmap at the same time ?
  2039. */
  2040. for (lid = tblk->next; lid; lid = tlck->next) {
  2041. tlck = lid_to_tlock(lid);
  2042. if ((tlck->flag & tlckUPDATEMAP) == 0)
  2043. continue;
  2044. if (tlck->flag & tlckFREEPAGE) {
  2045. /*
  2046. * Another thread may attempt to reuse freed space
  2047. * immediately, so we want to get rid of the metapage
  2048. * before anyone else has a chance to get it.
  2049. * Lock metapage, update maps, then invalidate
  2050. * the metapage.
  2051. */
  2052. mp = tlck->mp;
  2053. ASSERT(mp->xflag & COMMIT_PAGE);
  2054. grab_metapage(mp);
  2055. }
  2056. /*
  2057. * extent list:
  2058. * . in-line PXD list:
  2059. * . out-of-line XAD list:
  2060. */
  2061. maplock = (struct maplock *) & tlck->lock;
  2062. nlock = maplock->index;
  2063. for (k = 0; k < nlock; k++, maplock++) {
  2064. /*
  2065. * allocate blocks in persistent map:
  2066. *
  2067. * blocks have been allocated from wmap at alloc time;
  2068. */
  2069. if (maplock->flag & mlckALLOC) {
  2070. txAllocPMap(ipimap, maplock, tblk);
  2071. }
  2072. /*
  2073. * free blocks in persistent and working map:
  2074. * blocks will be freed in pmap and then in wmap;
  2075. *
  2076. * ? tblock specifies the PMAP/PWMAP based upon
  2077. * transaction
  2078. *
  2079. * free blocks in persistent map:
  2080. * blocks will be freed from wmap at last reference
  2081. * release of the object for regular files;
  2082. *
  2083. * Alway free blocks from both persistent & working
  2084. * maps for directories
  2085. */
  2086. else { /* (maplock->flag & mlckFREE) */
  2087. if (tlck->flag & tlckDIRECTORY)
  2088. txFreeMap(ipimap, maplock,
  2089. tblk, COMMIT_PWMAP);
  2090. else
  2091. txFreeMap(ipimap, maplock,
  2092. tblk, maptype);
  2093. }
  2094. }
  2095. if (tlck->flag & tlckFREEPAGE) {
  2096. if (!(tblk->flag & tblkGC_LAZY)) {
  2097. /* This is equivalent to txRelease */
  2098. ASSERT(mp->lid == lid);
  2099. tlck->mp->lid = 0;
  2100. }
  2101. assert(mp->nohomeok == 1);
  2102. metapage_homeok(mp);
  2103. discard_metapage(mp);
  2104. tlck->mp = NULL;
  2105. }
  2106. }
  2107. /*
  2108. * update inode allocation map
  2109. *
  2110. * update allocation state in pmap and
  2111. * update lsn of the pmap page;
  2112. * update in-memory inode flag/state
  2113. *
  2114. * unlock mapper/write lock
  2115. */
  2116. if (tblk->xflag & COMMIT_CREATE) {
  2117. diUpdatePMap(ipimap, tblk->ino, false, tblk);
  2118. /* update persistent block allocation map
  2119. * for the allocation of inode extent;
  2120. */
  2121. pxdlock.flag = mlckALLOCPXD;
  2122. pxdlock.pxd = tblk->u.ixpxd;
  2123. pxdlock.index = 1;
  2124. txAllocPMap(ipimap, (struct maplock *) & pxdlock, tblk);
  2125. } else if (tblk->xflag & COMMIT_DELETE) {
  2126. ip = tblk->u.ip;
  2127. diUpdatePMap(ipimap, ip->i_ino, true, tblk);
  2128. iput(ip);
  2129. }
  2130. }
  2131. /*
  2132. * txAllocPMap()
  2133. *
  2134. * function: allocate from persistent map;
  2135. *
  2136. * parameter:
  2137. * ipbmap -
  2138. * malock -
  2139. * xad list:
  2140. * pxd:
  2141. *
  2142. * maptype -
  2143. * allocate from persistent map;
  2144. * free from persistent map;
  2145. * (e.g., tmp file - free from working map at releae
  2146. * of last reference);
  2147. * free from persistent and working map;
  2148. *
  2149. * lsn - log sequence number;
  2150. */
  2151. static void txAllocPMap(struct inode *ip, struct maplock * maplock,
  2152. struct tblock * tblk)
  2153. {
  2154. struct inode *ipbmap = JFS_SBI(ip->i_sb)->ipbmap;
  2155. struct xdlistlock *xadlistlock;
  2156. xad_t *xad;
  2157. s64 xaddr;
  2158. int xlen;
  2159. struct pxd_lock *pxdlock;
  2160. struct xdlistlock *pxdlistlock;
  2161. pxd_t *pxd;
  2162. int n;
  2163. /*
  2164. * allocate from persistent map;
  2165. */
  2166. if (maplock->flag & mlckALLOCXADLIST) {
  2167. xadlistlock = (struct xdlistlock *) maplock;
  2168. xad = xadlistlock->xdlist;
  2169. for (n = 0; n < xadlistlock->count; n++, xad++) {
  2170. if (xad->flag & (XAD_NEW | XAD_EXTENDED)) {
  2171. xaddr = addressXAD(xad);
  2172. xlen = lengthXAD(xad);
  2173. dbUpdatePMap(ipbmap, false, xaddr,
  2174. (s64) xlen, tblk);
  2175. xad->flag &= ~(XAD_NEW | XAD_EXTENDED);
  2176. jfs_info("allocPMap: xaddr:0x%lx xlen:%d",
  2177. (ulong) xaddr, xlen);
  2178. }
  2179. }
  2180. } else if (maplock->flag & mlckALLOCPXD) {
  2181. pxdlock = (struct pxd_lock *) maplock;
  2182. xaddr = addressPXD(&pxdlock->pxd);
  2183. xlen = lengthPXD(&pxdlock->pxd);
  2184. dbUpdatePMap(ipbmap, false, xaddr, (s64) xlen, tblk);
  2185. jfs_info("allocPMap: xaddr:0x%lx xlen:%d", (ulong) xaddr, xlen);
  2186. } else { /* (maplock->flag & mlckALLOCPXDLIST) */
  2187. pxdlistlock = (struct xdlistlock *) maplock;
  2188. pxd = pxdlistlock->xdlist;
  2189. for (n = 0; n < pxdlistlock->count; n++, pxd++) {
  2190. xaddr = addressPXD(pxd);
  2191. xlen = lengthPXD(pxd);
  2192. dbUpdatePMap(ipbmap, false, xaddr, (s64) xlen,
  2193. tblk);
  2194. jfs_info("allocPMap: xaddr:0x%lx xlen:%d",
  2195. (ulong) xaddr, xlen);
  2196. }
  2197. }
  2198. }
  2199. /*
  2200. * txFreeMap()
  2201. *
  2202. * function: free from persistent and/or working map;
  2203. *
  2204. * todo: optimization
  2205. */
  2206. void txFreeMap(struct inode *ip,
  2207. struct maplock * maplock, struct tblock * tblk, int maptype)
  2208. {
  2209. struct inode *ipbmap = JFS_SBI(ip->i_sb)->ipbmap;
  2210. struct xdlistlock *xadlistlock;
  2211. xad_t *xad;
  2212. s64 xaddr;
  2213. int xlen;
  2214. struct pxd_lock *pxdlock;
  2215. struct xdlistlock *pxdlistlock;
  2216. pxd_t *pxd;
  2217. int n;
  2218. jfs_info("txFreeMap: tblk:0x%p maplock:0x%p maptype:0x%x",
  2219. tblk, maplock, maptype);
  2220. /*
  2221. * free from persistent map;
  2222. */
  2223. if (maptype == COMMIT_PMAP || maptype == COMMIT_PWMAP) {
  2224. if (maplock->flag & mlckFREEXADLIST) {
  2225. xadlistlock = (struct xdlistlock *) maplock;
  2226. xad = xadlistlock->xdlist;
  2227. for (n = 0; n < xadlistlock->count; n++, xad++) {
  2228. if (!(xad->flag & XAD_NEW)) {
  2229. xaddr = addressXAD(xad);
  2230. xlen = lengthXAD(xad);
  2231. dbUpdatePMap(ipbmap, true, xaddr,
  2232. (s64) xlen, tblk);
  2233. jfs_info("freePMap: xaddr:0x%lx "
  2234. "xlen:%d",
  2235. (ulong) xaddr, xlen);
  2236. }
  2237. }
  2238. } else if (maplock->flag & mlckFREEPXD) {
  2239. pxdlock = (struct pxd_lock *) maplock;
  2240. xaddr = addressPXD(&pxdlock->pxd);
  2241. xlen = lengthPXD(&pxdlock->pxd);
  2242. dbUpdatePMap(ipbmap, true, xaddr, (s64) xlen,
  2243. tblk);
  2244. jfs_info("freePMap: xaddr:0x%lx xlen:%d",
  2245. (ulong) xaddr, xlen);
  2246. } else { /* (maplock->flag & mlckALLOCPXDLIST) */
  2247. pxdlistlock = (struct xdlistlock *) maplock;
  2248. pxd = pxdlistlock->xdlist;
  2249. for (n = 0; n < pxdlistlock->count; n++, pxd++) {
  2250. xaddr = addressPXD(pxd);
  2251. xlen = lengthPXD(pxd);
  2252. dbUpdatePMap(ipbmap, true, xaddr,
  2253. (s64) xlen, tblk);
  2254. jfs_info("freePMap: xaddr:0x%lx xlen:%d",
  2255. (ulong) xaddr, xlen);
  2256. }
  2257. }
  2258. }
  2259. /*
  2260. * free from working map;
  2261. */
  2262. if (maptype == COMMIT_PWMAP || maptype == COMMIT_WMAP) {
  2263. if (maplock->flag & mlckFREEXADLIST) {
  2264. xadlistlock = (struct xdlistlock *) maplock;
  2265. xad = xadlistlock->xdlist;
  2266. for (n = 0; n < xadlistlock->count; n++, xad++) {
  2267. xaddr = addressXAD(xad);
  2268. xlen = lengthXAD(xad);
  2269. dbFree(ip, xaddr, (s64) xlen);
  2270. xad->flag = 0;
  2271. jfs_info("freeWMap: xaddr:0x%lx xlen:%d",
  2272. (ulong) xaddr, xlen);
  2273. }
  2274. } else if (maplock->flag & mlckFREEPXD) {
  2275. pxdlock = (struct pxd_lock *) maplock;
  2276. xaddr = addressPXD(&pxdlock->pxd);
  2277. xlen = lengthPXD(&pxdlock->pxd);
  2278. dbFree(ip, xaddr, (s64) xlen);
  2279. jfs_info("freeWMap: xaddr:0x%lx xlen:%d",
  2280. (ulong) xaddr, xlen);
  2281. } else { /* (maplock->flag & mlckFREEPXDLIST) */
  2282. pxdlistlock = (struct xdlistlock *) maplock;
  2283. pxd = pxdlistlock->xdlist;
  2284. for (n = 0; n < pxdlistlock->count; n++, pxd++) {
  2285. xaddr = addressPXD(pxd);
  2286. xlen = lengthPXD(pxd);
  2287. dbFree(ip, xaddr, (s64) xlen);
  2288. jfs_info("freeWMap: xaddr:0x%lx xlen:%d",
  2289. (ulong) xaddr, xlen);
  2290. }
  2291. }
  2292. }
  2293. }
  2294. /*
  2295. * txFreelock()
  2296. *
  2297. * function: remove tlock from inode anonymous locklist
  2298. */
  2299. void txFreelock(struct inode *ip)
  2300. {
  2301. struct jfs_inode_info *jfs_ip = JFS_IP(ip);
  2302. struct tlock *xtlck, *tlck;
  2303. lid_t xlid = 0, lid;
  2304. if (!jfs_ip->atlhead)
  2305. return;
  2306. TXN_LOCK();
  2307. xtlck = (struct tlock *) &jfs_ip->atlhead;
  2308. while ((lid = xtlck->next) != 0) {
  2309. tlck = lid_to_tlock(lid);
  2310. if (tlck->flag & tlckFREELOCK) {
  2311. xtlck->next = tlck->next;
  2312. txLockFree(lid);
  2313. } else {
  2314. xtlck = tlck;
  2315. xlid = lid;
  2316. }
  2317. }
  2318. if (jfs_ip->atlhead)
  2319. jfs_ip->atltail = xlid;
  2320. else {
  2321. jfs_ip->atltail = 0;
  2322. /*
  2323. * If inode was on anon_list, remove it
  2324. */
  2325. list_del_init(&jfs_ip->anon_inode_list);
  2326. }
  2327. TXN_UNLOCK();
  2328. }
  2329. /*
  2330. * txAbort()
  2331. *
  2332. * function: abort tx before commit;
  2333. *
  2334. * frees line-locks and segment locks for all
  2335. * segments in comdata structure.
  2336. * Optionally sets state of file-system to FM_DIRTY in super-block.
  2337. * log age of page-frames in memory for which caller has
  2338. * are reset to 0 (to avoid logwarap).
  2339. */
  2340. void txAbort(tid_t tid, int dirty)
  2341. {
  2342. lid_t lid, next;
  2343. struct metapage *mp;
  2344. struct tblock *tblk = tid_to_tblock(tid);
  2345. struct tlock *tlck;
  2346. /*
  2347. * free tlocks of the transaction
  2348. */
  2349. for (lid = tblk->next; lid; lid = next) {
  2350. tlck = lid_to_tlock(lid);
  2351. next = tlck->next;
  2352. mp = tlck->mp;
  2353. JFS_IP(tlck->ip)->xtlid = 0;
  2354. if (mp) {
  2355. mp->lid = 0;
  2356. /*
  2357. * reset lsn of page to avoid logwarap:
  2358. *
  2359. * (page may have been previously committed by another
  2360. * transaction(s) but has not been paged, i.e.,
  2361. * it may be on logsync list even though it has not
  2362. * been logged for the current tx.)
  2363. */
  2364. if (mp->xflag & COMMIT_PAGE && mp->lsn)
  2365. LogSyncRelease(mp);
  2366. }
  2367. /* insert tlock at head of freelist */
  2368. TXN_LOCK();
  2369. txLockFree(lid);
  2370. TXN_UNLOCK();
  2371. }
  2372. /* caller will free the transaction block */
  2373. tblk->next = tblk->last = 0;
  2374. /*
  2375. * mark filesystem dirty
  2376. */
  2377. if (dirty)
  2378. jfs_error(tblk->sb, "txAbort");
  2379. return;
  2380. }
  2381. /*
  2382. * txLazyCommit(void)
  2383. *
  2384. * All transactions except those changing ipimap (COMMIT_FORCE) are
  2385. * processed by this routine. This insures that the inode and block
  2386. * allocation maps are updated in order. For synchronous transactions,
  2387. * let the user thread finish processing after txUpdateMap() is called.
  2388. */
  2389. static void txLazyCommit(struct tblock * tblk)
  2390. {
  2391. struct jfs_log *log;
  2392. while (((tblk->flag & tblkGC_READY) == 0) &&
  2393. ((tblk->flag & tblkGC_UNLOCKED) == 0)) {
  2394. /* We must have gotten ahead of the user thread
  2395. */
  2396. jfs_info("jfs_lazycommit: tblk 0x%p not unlocked", tblk);
  2397. yield();
  2398. }
  2399. jfs_info("txLazyCommit: processing tblk 0x%p", tblk);
  2400. txUpdateMap(tblk);
  2401. log = (struct jfs_log *) JFS_SBI(tblk->sb)->log;
  2402. spin_lock_irq(&log->gclock); // LOGGC_LOCK
  2403. tblk->flag |= tblkGC_COMMITTED;
  2404. if (tblk->flag & tblkGC_READY)
  2405. log->gcrtc--;
  2406. wake_up_all(&tblk->gcwait); // LOGGC_WAKEUP
  2407. /*
  2408. * Can't release log->gclock until we've tested tblk->flag
  2409. */
  2410. if (tblk->flag & tblkGC_LAZY) {
  2411. spin_unlock_irq(&log->gclock); // LOGGC_UNLOCK
  2412. txUnlock(tblk);
  2413. tblk->flag &= ~tblkGC_LAZY;
  2414. txEnd(tblk - TxBlock); /* Convert back to tid */
  2415. } else
  2416. spin_unlock_irq(&log->gclock); // LOGGC_UNLOCK
  2417. jfs_info("txLazyCommit: done: tblk = 0x%p", tblk);
  2418. }
  2419. /*
  2420. * jfs_lazycommit(void)
  2421. *
  2422. * To be run as a kernel daemon. If lbmIODone is called in an interrupt
  2423. * context, or where blocking is not wanted, this routine will process
  2424. * committed transactions from the unlock queue.
  2425. */
  2426. int jfs_lazycommit(void *arg)
  2427. {
  2428. int WorkDone;
  2429. struct tblock *tblk;
  2430. unsigned long flags;
  2431. struct jfs_sb_info *sbi;
  2432. do {
  2433. LAZY_LOCK(flags);
  2434. jfs_commit_thread_waking = 0; /* OK to wake another thread */
  2435. while (!list_empty(&TxAnchor.unlock_queue)) {
  2436. WorkDone = 0;
  2437. list_for_each_entry(tblk, &TxAnchor.unlock_queue,
  2438. cqueue) {
  2439. sbi = JFS_SBI(tblk->sb);
  2440. /*
  2441. * For each volume, the transactions must be
  2442. * handled in order. If another commit thread
  2443. * is handling a tblk for this superblock,
  2444. * skip it
  2445. */
  2446. if (sbi->commit_state & IN_LAZYCOMMIT)
  2447. continue;
  2448. sbi->commit_state |= IN_LAZYCOMMIT;
  2449. WorkDone = 1;
  2450. /*
  2451. * Remove transaction from queue
  2452. */
  2453. list_del(&tblk->cqueue);
  2454. LAZY_UNLOCK(flags);
  2455. txLazyCommit(tblk);
  2456. LAZY_LOCK(flags);
  2457. sbi->commit_state &= ~IN_LAZYCOMMIT;
  2458. /*
  2459. * Don't continue in the for loop. (We can't
  2460. * anyway, it's unsafe!) We want to go back to
  2461. * the beginning of the list.
  2462. */
  2463. break;
  2464. }
  2465. /* If there was nothing to do, don't continue */
  2466. if (!WorkDone)
  2467. break;
  2468. }
  2469. /* In case a wakeup came while all threads were active */
  2470. jfs_commit_thread_waking = 0;
  2471. if (freezing(current)) {
  2472. LAZY_UNLOCK(flags);
  2473. try_to_freeze();
  2474. } else {
  2475. DECLARE_WAITQUEUE(wq, current);
  2476. add_wait_queue(&jfs_commit_thread_wait, &wq);
  2477. set_current_state(TASK_INTERRUPTIBLE);
  2478. LAZY_UNLOCK(flags);
  2479. schedule();
  2480. __set_current_state(TASK_RUNNING);
  2481. remove_wait_queue(&jfs_commit_thread_wait, &wq);
  2482. }
  2483. } while (!kthread_should_stop());
  2484. if (!list_empty(&TxAnchor.unlock_queue))
  2485. jfs_err("jfs_lazycommit being killed w/pending transactions!");
  2486. else
  2487. jfs_info("jfs_lazycommit being killed\n");
  2488. return 0;
  2489. }
  2490. void txLazyUnlock(struct tblock * tblk)
  2491. {
  2492. unsigned long flags;
  2493. LAZY_LOCK(flags);
  2494. list_add_tail(&tblk->cqueue, &TxAnchor.unlock_queue);
  2495. /*
  2496. * Don't wake up a commit thread if there is already one servicing
  2497. * this superblock, or if the last one we woke up hasn't started yet.
  2498. */
  2499. if (!(JFS_SBI(tblk->sb)->commit_state & IN_LAZYCOMMIT) &&
  2500. !jfs_commit_thread_waking) {
  2501. jfs_commit_thread_waking = 1;
  2502. wake_up(&jfs_commit_thread_wait);
  2503. }
  2504. LAZY_UNLOCK(flags);
  2505. }
  2506. static void LogSyncRelease(struct metapage * mp)
  2507. {
  2508. struct jfs_log *log = mp->log;
  2509. assert(mp->nohomeok);
  2510. assert(log);
  2511. metapage_homeok(mp);
  2512. }
  2513. /*
  2514. * txQuiesce
  2515. *
  2516. * Block all new transactions and push anonymous transactions to
  2517. * completion
  2518. *
  2519. * This does almost the same thing as jfs_sync below. We don't
  2520. * worry about deadlocking when jfs_tlocks_low is set, since we would
  2521. * expect jfs_sync to get us out of that jam.
  2522. */
  2523. void txQuiesce(struct super_block *sb)
  2524. {
  2525. struct inode *ip;
  2526. struct jfs_inode_info *jfs_ip;
  2527. struct jfs_log *log = JFS_SBI(sb)->log;
  2528. tid_t tid;
  2529. set_bit(log_QUIESCE, &log->flag);
  2530. TXN_LOCK();
  2531. restart:
  2532. while (!list_empty(&TxAnchor.anon_list)) {
  2533. jfs_ip = list_entry(TxAnchor.anon_list.next,
  2534. struct jfs_inode_info,
  2535. anon_inode_list);
  2536. ip = &jfs_ip->vfs_inode;
  2537. /*
  2538. * inode will be removed from anonymous list
  2539. * when it is committed
  2540. */
  2541. TXN_UNLOCK();
  2542. tid = txBegin(ip->i_sb, COMMIT_INODE | COMMIT_FORCE);
  2543. mutex_lock(&jfs_ip->commit_mutex);
  2544. txCommit(tid, 1, &ip, 0);
  2545. txEnd(tid);
  2546. mutex_unlock(&jfs_ip->commit_mutex);
  2547. /*
  2548. * Just to be safe. I don't know how
  2549. * long we can run without blocking
  2550. */
  2551. cond_resched();
  2552. TXN_LOCK();
  2553. }
  2554. /*
  2555. * If jfs_sync is running in parallel, there could be some inodes
  2556. * on anon_list2. Let's check.
  2557. */
  2558. if (!list_empty(&TxAnchor.anon_list2)) {
  2559. list_splice(&TxAnchor.anon_list2, &TxAnchor.anon_list);
  2560. INIT_LIST_HEAD(&TxAnchor.anon_list2);
  2561. goto restart;
  2562. }
  2563. TXN_UNLOCK();
  2564. /*
  2565. * We may need to kick off the group commit
  2566. */
  2567. jfs_flush_journal(log, 0);
  2568. }
  2569. /*
  2570. * txResume()
  2571. *
  2572. * Allows transactions to start again following txQuiesce
  2573. */
  2574. void txResume(struct super_block *sb)
  2575. {
  2576. struct jfs_log *log = JFS_SBI(sb)->log;
  2577. clear_bit(log_QUIESCE, &log->flag);
  2578. TXN_WAKEUP(&log->syncwait);
  2579. }
  2580. /*
  2581. * jfs_sync(void)
  2582. *
  2583. * To be run as a kernel daemon. This is awakened when tlocks run low.
  2584. * We write any inodes that have anonymous tlocks so they will become
  2585. * available.
  2586. */
  2587. int jfs_sync(void *arg)
  2588. {
  2589. struct inode *ip;
  2590. struct jfs_inode_info *jfs_ip;
  2591. tid_t tid;
  2592. do {
  2593. /*
  2594. * write each inode on the anonymous inode list
  2595. */
  2596. TXN_LOCK();
  2597. while (jfs_tlocks_low && !list_empty(&TxAnchor.anon_list)) {
  2598. jfs_ip = list_entry(TxAnchor.anon_list.next,
  2599. struct jfs_inode_info,
  2600. anon_inode_list);
  2601. ip = &jfs_ip->vfs_inode;
  2602. if (! igrab(ip)) {
  2603. /*
  2604. * Inode is being freed
  2605. */
  2606. list_del_init(&jfs_ip->anon_inode_list);
  2607. } else if (mutex_trylock(&jfs_ip->commit_mutex)) {
  2608. /*
  2609. * inode will be removed from anonymous list
  2610. * when it is committed
  2611. */
  2612. TXN_UNLOCK();
  2613. tid = txBegin(ip->i_sb, COMMIT_INODE);
  2614. txCommit(tid, 1, &ip, 0);
  2615. txEnd(tid);
  2616. mutex_unlock(&jfs_ip->commit_mutex);
  2617. iput(ip);
  2618. /*
  2619. * Just to be safe. I don't know how
  2620. * long we can run without blocking
  2621. */
  2622. cond_resched();
  2623. TXN_LOCK();
  2624. } else {
  2625. /* We can't get the commit mutex. It may
  2626. * be held by a thread waiting for tlock's
  2627. * so let's not block here. Save it to
  2628. * put back on the anon_list.
  2629. */
  2630. /* Take off anon_list */
  2631. list_del(&jfs_ip->anon_inode_list);
  2632. /* Put on anon_list2 */
  2633. list_add(&jfs_ip->anon_inode_list,
  2634. &TxAnchor.anon_list2);
  2635. TXN_UNLOCK();
  2636. iput(ip);
  2637. TXN_LOCK();
  2638. }
  2639. }
  2640. /* Add anon_list2 back to anon_list */
  2641. list_splice_init(&TxAnchor.anon_list2, &TxAnchor.anon_list);
  2642. if (freezing(current)) {
  2643. TXN_UNLOCK();
  2644. try_to_freeze();
  2645. } else {
  2646. set_current_state(TASK_INTERRUPTIBLE);
  2647. TXN_UNLOCK();
  2648. schedule();
  2649. __set_current_state(TASK_RUNNING);
  2650. }
  2651. } while (!kthread_should_stop());
  2652. jfs_info("jfs_sync being killed");
  2653. return 0;
  2654. }
  2655. #if defined(CONFIG_PROC_FS) && defined(CONFIG_JFS_DEBUG)
  2656. static int jfs_txanchor_proc_show(struct seq_file *m, void *v)
  2657. {
  2658. char *freewait;
  2659. char *freelockwait;
  2660. char *lowlockwait;
  2661. freewait =
  2662. waitqueue_active(&TxAnchor.freewait) ? "active" : "empty";
  2663. freelockwait =
  2664. waitqueue_active(&TxAnchor.freelockwait) ? "active" : "empty";
  2665. lowlockwait =
  2666. waitqueue_active(&TxAnchor.lowlockwait) ? "active" : "empty";
  2667. seq_printf(m,
  2668. "JFS TxAnchor\n"
  2669. "============\n"
  2670. "freetid = %d\n"
  2671. "freewait = %s\n"
  2672. "freelock = %d\n"
  2673. "freelockwait = %s\n"
  2674. "lowlockwait = %s\n"
  2675. "tlocksInUse = %d\n"
  2676. "jfs_tlocks_low = %d\n"
  2677. "unlock_queue is %sempty\n",
  2678. TxAnchor.freetid,
  2679. freewait,
  2680. TxAnchor.freelock,
  2681. freelockwait,
  2682. lowlockwait,
  2683. TxAnchor.tlocksInUse,
  2684. jfs_tlocks_low,
  2685. list_empty(&TxAnchor.unlock_queue) ? "" : "not ");
  2686. return 0;
  2687. }
  2688. static int jfs_txanchor_proc_open(struct inode *inode, struct file *file)
  2689. {
  2690. return single_open(file, jfs_txanchor_proc_show, NULL);
  2691. }
  2692. const struct file_operations jfs_txanchor_proc_fops = {
  2693. .owner = THIS_MODULE,
  2694. .open = jfs_txanchor_proc_open,
  2695. .read = seq_read,
  2696. .llseek = seq_lseek,
  2697. .release = single_release,
  2698. };
  2699. #endif
  2700. #if defined(CONFIG_PROC_FS) && defined(CONFIG_JFS_STATISTICS)
  2701. static int jfs_txstats_proc_show(struct seq_file *m, void *v)
  2702. {
  2703. seq_printf(m,
  2704. "JFS TxStats\n"
  2705. "===========\n"
  2706. "calls to txBegin = %d\n"
  2707. "txBegin blocked by sync barrier = %d\n"
  2708. "txBegin blocked by tlocks low = %d\n"
  2709. "txBegin blocked by no free tid = %d\n"
  2710. "calls to txBeginAnon = %d\n"
  2711. "txBeginAnon blocked by sync barrier = %d\n"
  2712. "txBeginAnon blocked by tlocks low = %d\n"
  2713. "calls to txLockAlloc = %d\n"
  2714. "tLockAlloc blocked by no free lock = %d\n",
  2715. TxStat.txBegin,
  2716. TxStat.txBegin_barrier,
  2717. TxStat.txBegin_lockslow,
  2718. TxStat.txBegin_freetid,
  2719. TxStat.txBeginAnon,
  2720. TxStat.txBeginAnon_barrier,
  2721. TxStat.txBeginAnon_lockslow,
  2722. TxStat.txLockAlloc,
  2723. TxStat.txLockAlloc_freelock);
  2724. return 0;
  2725. }
  2726. static int jfs_txstats_proc_open(struct inode *inode, struct file *file)
  2727. {
  2728. return single_open(file, jfs_txstats_proc_show, NULL);
  2729. }
  2730. const struct file_operations jfs_txstats_proc_fops = {
  2731. .owner = THIS_MODULE,
  2732. .open = jfs_txstats_proc_open,
  2733. .read = seq_read,
  2734. .llseek = seq_lseek,
  2735. .release = single_release,
  2736. };
  2737. #endif